gilamran / tsc-watch Goto Github PK
View Code? Open in Web Editor NEWThe TypeScript compiler with --watch and a new onSuccess argument
License: MIT License
The TypeScript compiler with --watch and a new onSuccess argument
License: MIT License
Is it possible to use tsconfig-paths with tsc-watch?
Hi, please add a compatible OSS license, thanks!
This seems like a nice lib and I will give it a try :-).
I'm using vscode integrated terminal with solarized light settings. The colors of the output is not the same of regular tsc --watch
and tsc-watch
, see below. The colors output by tsc-watch
is very hard to read with my settings.
$ yarn tsc --watch
$ yarn tsc-watch
This is related to #28. That one was closed when the author saw that yarn was giving tsc-watch
its own private copy of typescript (of a different version).
However, yarn's choice to do so was valid (and npm may do the same thing), as tsc-watch
declares a direct dependency on typescript.
peerDependencies
is a better model for what tsc-watch
is trying to do -- i.e., "I will take the copy of typescript that you've already installed, and run it for you".
Hi,
I observe the ERR_IPC_CHANNEL_CLOSED
error happening from time to time, which abruptly quits my watch script leaving all spawned child processes active. (using tsc-watch v2.1.1
)
Do you have any ideas to why that may be happening?
Error [ERR_IPC_CHANNEL_CLOSED]: Channel closed
at process.target.send (internal/child_process.js:644:16)
at Object.Signal.send.process.send.function.e [as send] (~/app/node_modules/tsc-watch/lib/tsc-watch.js:77:64)
at Object.emitSuccess (~/app/node_modules/tsc-watch/lib/tsc-watch.js:80:12)
at killProcesses.then (~/app/node_modules/tsc-watch/lib/tsc-watch.js:64:16)
at process.internalTickCallback (internal/process/next_tick.js:77:7)
That's my watch script:
https://github.com/mullvad/mullvadvpn-app/blob/master/gui/packages/desktop/scripts/serve.js
In windows there are to many empty line in the console output. This can be fixed by replacing the manipulate function in stdout-manipulator.js to this:
function manipulate(buffer) {
const lines = buffer
.toString()
.split(/\r\n|\n|\r/gm)
.filter(a => a.length > 0)
.map(a => a.replace(tscUsageSyntaxRegex, newAdditionToSyntax));
return lines;
}
Web Server is running
09:37:14 - Starting compilation in watch mode...
09:37:15 - Found 0 errors. Watching for file changes.
Running webpack...
Webpack done!
Web Server is running
09:44:17 - Starting compilation in watch mode...
09:44:18 - Found 0 errors. Watching for file changes.
Running webpack...
Webpack done!
Hoop you can change that in a future release.
Looks like something broke in 1.0.28.
Look at:
Lines 71 to 78 in ae2f5a8
I think you either want:
const args = parts.splice(0, 1);
return spawn(exec, parts, {
or
const args = parts.slice(1);
return spawn(exec, args, {
I have all the sources in the src
folder when I execute tsc-watch
the root folder tsconfig.json isn't used.
Any suggestions?
Previously with v1.0.7, the following command would work:
tsc-watch --onSuccess \"node -r dotenv/config dist/index.js\"
As of 1.0.8 it fails with the following error message:
yarn dev v0.27.5
$ tsc-watch --onSuccess "node -r dotenv/config dist/index.js"
env: node\r: No such file or directory
error Command failed with exit code 127.
I'm using tsc-watch like so:
tsc-watch --onFirstSuccess "webpack-dev-server"
I'd like to keep the dev server running, as it monitors the output of tsc-watch.
A few minor issues with the formatting of the terminal output :-)
After initial build:
[
is colored. It would be better to color the whole line, except for the gray timestamp.After rebuilding:
[
is colored.I'm on macOS by the way.
tsc-watch is based on compiler messages regular expressions wich fail when you use --locale typescript option.
My application is a monorepo with multiple packages where each package have it's own tsconfig.json. I would like to restart my server on a change to any of the packages. So for example I want to to this:
tsc-watch -p ./packages/foo-server -p ./packages/foo-utils --onSuccess 'node ./packages/foo-server/lib/server.js' -
So the request is to support multiple instances of the -p
. The regular tsc --watch
only supports one instance.
This would allow for notification/sounds to be played via cli in case of failure which can be pretty helpful.
Is there way to send signal into process when code has been updatet? Something like:
tsc-watch --onFirstSuccess "node ./dist/main.js" --onSuccess SIGINT
I am using tsc watch with nrest js application and i have a module which uploads a file. However when i upload a file, tsc watch restarts the nestjs application
Client fails on unresolved path:
Error: Cannot find module '/Users/#USER/$PROJECT_ROOT/lib/tsc-watch.js'
The tsc-watch i awesome but has a hard-written compiler name:
File lib/tsc-watch.js Line 129:
const bin = require.resolve('typescript/bin/tsc');
but there are other compilers compatible with typescript for example ntypescript, ttypescript.
Webpack plugin - awesome-typescript-loader allows you to choose a compiler by an optional parameter:
--compiler (string) (default='typescript')
Could you have parameterized tsc-watch in a similar way?
Hi!
I was wondering if it would be possible to tag releases? I wanted to peek at a diff between two old versions was bummed to see only a single tagged release.
Future versions were tagged that would be helpful going forward, but I think it might not be too difficult to tag old releases assuming your changelog commits are accurate.
Since I can't propose tags via the PR process, a contributor would have to check out each of the dozen version refs from the changelog and run git tag 1.x.x
and then push tags. It's PITA but it's 5mins for much better transparency.
Thanks in advance!
When running tsc-watch, on my Windows machine, the CPU usage for the Node.js process alone spikes to 50%-60%. With the other apps that I have running on my laptop, it basically spikes the total CPU usage to 100%.
This is how tsc-watch is being invoked:
./node_modules/.bin/tsc-watch --onSuccess node build/server.js
Is it correct to assume that the constant checking for file changes is what is causing the CPU usage spike?
Is there a polling option to configure how often tsc-watch checks for changes, or other way to resolve this issue?
Thanks!
When using TypeScript 2.9.2, the onSuccess callback is never called.
Hi,
Currently tsc-watch/client
exports a singleton. It makes it impossible to run multiple tsc-watch side by side. This is especially critical in the workspace configuration. Would it be possible to export the class itself instead of an instance?
I'm trying to use tsc-watch to compile a specific subdirectory with its own tsconfig.json
and then run a compiled file in node but I'm getting that error.
My start script is
"tsc-watch -p ./server onSuccess \"cross-env NODE_ENV=development node dist/server/server.js\""
./server
has a server.ts
, a tsconfig.json
and a bunch of other folders and ts files.
So how can I use tsc-watch to compile a specific directory with its tsconfig.json if I cannot make use of the -p option?
The following doesn't work properly:
tsc-watch --onSuccess 'concurrently -n http,queue "node dist/server.js" "node dist/queue.ts"'
At a guess, this looks like the culprit: https://github.com/gilamran/tsc-watch/blob/master/lib/tsc-watch.js#L71
I'm not sure why this is being done in the first place to know how to approach fixing it though.
After updating to 1.0.29, I'm not getting any recompiles when I change files, even if I run something short-lived, as below:
tsc-watch --preserveWatchOutput --onSuccess 'echo hello'
tsc-watch
does not seem to properly quit on ctrl+c. then at some point if I change some file, it randomly prints stuff like this to console:
----------------------
1:16:00 PM - File change detected. Starting incremental compilation...
1:16:00 PM - Found 0 errors. Watching for file changes.
Error [ERR_IPC_CHANNEL_CLOSED]: Channel closed
at process.target.send (internal/child_process.js:678:16)
at Object.Signal.send (~/gui/node_modules/tsc-watch/lib/tsc-watch.js:81:64)
at Object.emitSuccess (~/gui/node_modules/tsc-watch/lib/tsc-watch.js:84:12)
at ~/gui/node_modules/tsc-watch/lib/tsc-watch.js:68:16
at processTicksAndRejections (internal/process/task_queues.js:89:5)
Running tsc-watch
programmatically by creating an instance of TscWatchClient
.
You think I need to kill it manually on exit
? i.e:
process.on('SIGINT', () => {
watch.kill();
process.exit();
});
An attacker gained control of the event-stream
repository and injected malicious code. This package must be upgraded to the latest version of ps-tree
to remove the malicious code.
The latest version of this package installs flatmap-stream
thanks to this dependency chain ps-tree 1.1.0 > event-stream 3.3.6 > flatmap-stream 0.1.1
.
This attack was a targetted attack at anyone who was using the copay-dash
package, and would attempt to steal your BTC or BCH wallet keys.
When running the onFailure process the onSuccess run previously doesn't get closed and vice versa.
The use case is I want to always run same node server on either success or failure, and apparently, the process is not killed.
One problem is this doesn't kill the old process it ran, so if you start a node server it will just start more, not terminating the old ones
As the TypeScript compiler changes (the output messages), it would be nice to be able to run the unit tests with different version of tsc.
The error regex is wrong.
In my package.json
I have the following script defined:
"scripts": {
"build": "cd someSubFolder && tsc-watch --onSuccess \"echo Success\" --onFailure \"echo Failure\""
}
When I run npm run build
the TypeScript compilation seems to work along with the watch mode, however none of the two callbacks gets fired. What am I missing?
I am using typescript 2.7.2 and tsc-watch 2.2.1
Do not show Compilation complete. Watching for file changes
in green if the compilation had errors.
Is it confusing.
Caused by 6c3de28
hadErrors
is no longer being checked
Probably need
killAllSuccessProcesses().then(() => {
if (hadErrors) return;
Signal.emitSuccess();
.
killFailureProcess().then(() => {
if (!hadErrors) return;
Signal.emitFail();
I suggest adding the following line to tsc-watch
:
process.on('SIGTERM', () => tscProcess.kill(0));
running:
tsc-watch --onSuccess "./scripts/start:dev.sh" --onFailure "echo 'Beep! Compilation Failed'"
1.1.34
[3:40:54 PM] Starting compilation in watch mode...
[3:41:05 PM] Compilation complete. Watching for file changes.
+ ./scripts/db:migrate.sh
Local redis port 9089
+ migrate_cmd='node ./dist/src/migrate.js'
+ '[' -z '' ']'
...
1.1.35
[3:48:22 PM] Starting compilation in watch mode...
[3:48:32 PM] Compilation complete. Watching for file changes.
[hangs indefinitely, and server never starts]
OSX
I'm trying to use this module, but it's giving the error described here: ifrost/afterwriting-labs#69
My temporary work around is to run
dos2unix node_modules/tsc-watch/tsc-watch.js
As a permanent fix can you republish with core.autocrlf = false
as described above?
I have yarn commands like so...
"copy-dangling": "copyfiles -u 1 src/**/*.json src/**/*.pug src/**/*.sql dist/",
"dev": "yarn clean-dist && tsc-watch --onSuccess \"yarn copy-dangling && node --require dotenv/config dist/index.js\"",
because the onSuccess is running multiple commands, it seems to incorrectly parse out the ampersands &&
and turns it into something like this:
copyfiles -u 1 src/**/*.json src/**/*.pug src/**/*.sql dist/ '&&' node --require dotenv/config dist/index.js
(notice the quotes around the ampersands)
Since upgrading from v1.0.18
to v1.0.19
I've noticed two things.
--onSuccess
hook never gets called when a compilation error occurs. Maybe look up the noEmitOnError
field in the project's tsconfig.json
.Hope you're OK with hearing constructive criticism. I absolutely love the work you've done on this project and I use it every single day. Cheers mate! :D
Hello,
we are developing a nest app (inside a docker container). Everything works fine with tsc-watch but when code is being changed, dist is being rebuilt, the node process is not restarted.
The relevant code is package.json
is
"scripts": {
"start": "ts-node -r tsconfig-paths/register src/main.ts",
"start:dev": "tsc-watch -p tsconfig.build.json --onSuccess 'node dist/main.js'",
},
we are using start:dev
.
We have tracked down the problem to the killer.js
source file issueing a SIGUSR2
signal to node. Our basic node app does not handle this signal so it just ignores the signal, and does not die.
Maybe it's because nest
handles SIGUSR2
in its own way. We don't know.
We have solved the issue in two ways:
killer.js
(killer.js) to have let KILL_SIGNAL = 'SIGTERM';
process.on('SIGUSR2', () => { process.exit();});
to our main.ts
app file.Either way makes the tsc-watch
work as expected
But we are wondering why you put SIGUSR instead of SIGTERM, or what are we missing, since nobody seems to have our problem.
Could you help us better understand the basic issue here? Thanks.
Anyway thanks for your work for the node community,
regards
Hi there, im using this plugin to get the success callback and start my node server after the compiler is done. For dev its ok, because i need the --watch flag, but for building purposes, i don
t need to watch, just need the success callback, would be great to have the option to disable --watch, do you plan to do that?
I'm having this error:
ReferenceError: killer is not defined
at kill (node_modules/tsc-watch/lib/runner.js:20:20)
at killProcesses (node_modules/tsc-watch/lib/tsc-watch.js:24:21)
at Socket.tscProcess.stdout.on.buffer (node_modules/tsc-watch/lib/tsc-watch.js:51:5)
at Socket.emit (events.js:189:13)
at addChunk (_stream_readable.js:284:12)
at readableAddChunk (_stream_readable.js:265:11)
at Socket.Readable.push (_stream_readable.js:220:10)
at Pipe.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
node_modules/tsc-watch/lib/runner.js:20
return Promise.all([killer(process), exitPromise]);
The file: tsc-watch/lib/runner.js
is missing this line, perhaps?
const killer = require('./killer')
It'd be great to be able to specify additional files, outside of those included by tsc
that are watched by this process.
E.g., if I make changes to a .graphql
file somewhere in my directory tree, I'd like to have the watch process restart node without having tsc
try to compile the file.
I have a feeling this will require integrating the better part of nodemon in order to get queued file system events across OS platforms. Sorry, no pull request today. Just recording the feature request for now.
Not sure but when I use regular tsc
compare to tsc-watch
it compiles differently.
Also I have these:
"noUnusedLocals": true,
"noUnusedParameters": true
When I run regular tsc
it fails if it meets these rules but with tsc-watch
it succeeds even with these rules which makes me assume that it's ignoring the tsconfig.json
file
Hi,
I run tsc-watch with the following command:
tsc-watch --sourceMap --onFirstSuccess "node run-my-app-that-does-hot-reload.js"
Changing any file kills the node process. How do you circumvent this?
Workaround: Used a programmatic API via tsc-watch/client
to prevent the node process from being killed
after Starting compilation in watch mode. it exits xD
Hello,
Firstly, thanks for writing this package, it's been super useful!
I have a question, as it seems it's not been asked before, and I could not find anything about it in the docs:
Is it possible to set the path of the tsconfig.json
? For my build process needs I have to use a specific tsconfig.build.json
and I was looking at how to use ts-watch with this file instead of the default.
I see there is compiler option, but no option to set a custom tsconfig file. (-p
flag to it)
Would this be feasible ?
Cheers!
I upgraded a project to typescript 2.9.1 and encountered a strange behavior. It seems tsc-watch is still using typescript 2.8.3 but I don't understand where it finds it. This is on Windows 10.
Some output:
$ tsc-watch --version
Version 2.6.2
$ tsc --version
Version 2.9.1
$ yarn tsc-watch --version
yarn run v1.7.0
$ C:\code\XXX\node_modules\.bin\tsc-watch --version
Version 2.8.3
$ yarn tsc --version
yarn run v1.7.0
$ C:\code\XXX\node_modules\.bin\tsc --version
Version 2.9.1
$ which tsc
/c/Users/jonkel.DIVID/AppData/Roaming/npm/tsc
$ /c/Users/jonkel.DIVID/AppData/Roaming/npm/tsc --version
Version 2.9.1
$ yarn which tsc
yarn run v1.7.0
$ C:\code\XXX\node_modules\.bin\which tsc
C:\code\XXX\node_modules\.bin\tsc.CMD
I'm trying to find out where tsc-watch
is finding the old tsc
binary. It seems it is not looking at the global path or at the path yarn sets.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.