Skip to content

Commit 99c3bb9

Browse files
committed
add priorNodeArgs, fix esm support
1 parent 6c4619b commit 99c3bb9

File tree

7 files changed

+22
-12
lines changed

7 files changed

+22
-12
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ tsnd --respawn server.ts
3838

3939
- `--prefer-ts` (default: false) - for each `.js` file (that is not in `node_modules`) will try to check if corresponding `.ts` version exists and require it.
4040
- `--ignore-watch` (default: []) - files/folders to be [ignored by `node-dev`](https://github.com/fgnass/node-dev#ignore-paths). **But also this behaviour enhanced:** it will also make up `new RegExp` of passed ignore string and check absolute paths of required files for match.
41-
So, to ignore everthing in `node_modules`, just pass `--ignore-watch node_modules`.
41+
So, to ignore everything in `node_modules`, just pass `--ignore-watch node_modules`.
4242

4343
- `--debug` - some additional debug output.
4444
- `--interval` Polling interval (ms)
4545
- `--debounce` Debounce file change events (ms, non-polling mode)
4646

4747
**Caveats and points of notice:**
4848

49-
- Especially for large code bases always consider running with `--transpileOnly` flag which is normal for dev workflow and will speed up things greatly. Note, that `ts-node-dev` will not put watch handlers on TS files that contain only types/interfaces (used only for type checking) - this is current limitation by design.
49+
- Especially for large code bases always consider running with `--transpile-only` flag which is normal for dev workflow and will speed up things greatly. Note, that `ts-node-dev` will not put watch handlers on TS files that contain only types/interfaces (used only for type checking) - this is current limitation by design.
5050

5151
- `--ignore-watch` will NOT affect files ignored by TS compilation. Use `--ignore` option (or `TS_NODE_IGNORE` env variable) to pass **RegExp strings** for filtering files that should not be compiled, by default `/node_modules/` are ignored.
5252

@@ -58,6 +58,8 @@ tsnd --respawn server.ts
5858

5959
- The good thing is that `ts-node-dev` watches used `tsconfig.json` file, and will reinitialize compilation on its change, but you have to restart the process manually when you update used version of `typescript` or make any other changes that may effect compilation results.
6060

61+
- In some rare cases `ts-node-dev` may fail to terminate an application by sending `SIGTERM` signal, this maybe caused by the app having running heavy child process or something. But the app should get the signal anyway and it can be explicitly processed there: `process.on('SIGTERM', () => process.exit())`.
62+
6163
## License
6264

6365
WTF.

bin/ts-node-dev

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ var opts = minimist(devArgs, {
6666

6767
var script = opts._[0]
6868
var scriptArgs = opts._.slice(1)
69-
var loadEsm = false
69+
70+
opts.priorNodeArgs = []
7071

7172
unknown.forEach(function(arg) {
7273
if (arg === script || nodeArgs.indexOf(arg) >= 0) return
@@ -75,9 +76,8 @@ unknown.forEach(function(arg) {
7576
var argOpts = opts[argName]
7677
var argValues = Array.isArray(argOpts) ? argOpts : [argOpts]
7778
argValues.forEach(function(argValue) {
78-
console.log('argValue', argValue, 'arg', arg)
7979
if ((arg === '-r' || arg === '--require') && argValue === 'esm') {
80-
loadEsm = true
80+
opts.priorNodeArgs.push(arg, argValue)
8181
return false
8282
}
8383
nodeArgs.push(arg)
@@ -87,10 +87,6 @@ unknown.forEach(function(arg) {
8787
})
8888
})
8989

90-
if (loadEsm) {
91-
require('esm')
92-
}
93-
9490
if (!script) {
9591
console.log('Usage: ts-node-dev [options] script [arguments]\n')
9692
process.exit(1)

lib/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ module.exports = function(script, scriptArgs, nodeArgs, opts) {
8787
)
8888
var cmd = nodeArgs.concat(wrapper, script, scriptArgs)
8989
var childHookPath = compiler.getChildHookPath()
90-
cmd = ['-r', childHookPath].concat(cmd)
90+
91+
cmd = (opts.priorNodeArgs || []).concat(['-r', childHookPath]).concat(cmd)
9192
log.debug('Starting child process %s', cmd.join(' '))
9293
child = fork(cmd[0], cmd.slice(1), {
9394
cwd: process.cwd(),

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ts-node-dev",
3-
"version": "1.0.0-pre.36",
3+
"version": "1.0.0-pre.38",
44
"description": "Compiles your TS app and restarts when files are modified.",
55
"keywords": [
66
"restart",
@@ -39,7 +39,7 @@
3939
"scripts": {
4040
"ts-node-dev": "node ./bin/ts-node-dev",
4141
"test-node-dev": "tap test/*.js",
42-
"test": "node ./bin/ts-node-dev --tree-kill -r tsconfig-paths/register -r ./test/ts/add-require.js -r ./test/ts/add-require-2.js -O \"{\\\"module\\\": \\\"commonjs\\\"}\" --preserve-symlinks --respawn --ignore-watch 'lib' --ignore-watch bin --prefer-ts --debug --poll --interval 1000 --cache-directory .ts-node --inspect -- test/ts/test-script test-arg --fd",
42+
"test": "node ./bin/ts-node-dev --tree-kill -r tsconfig-paths/register -r ./test/ts/add-require.js -r ./test/ts/add-require-2.js -r esm -O \"{\\\"module\\\": \\\"es6\\\"}\" --preserve-symlinks --respawn --ignore-watch 'lib' --ignore-watch bin --prefer-ts --debug --poll --interval 1000 --cache-directory .ts-node --inspect -- test/ts/test-script test-arg --fd",
4343
"test-docker": "docker run --rm -v ${PWD}:/app mhart/alpine-node:8.7.0 sh -c 'cd app && node ./bin/ts-node-dev --cache-directory .ts-node test/ts/big'"
4444
},
4545
"dependencies": {
@@ -61,6 +61,7 @@
6161
"eslint": "^2.0.0",
6262
"eslint-config-airbnb-base": "^3.0.1",
6363
"eslint-plugin-import": "^1.8.1",
64+
"esm": "^3.2.22",
6465
"tap": "^5.2.0",
6566
"touch": "^1.0.0",
6667
"tsconfig-paths": "^3.3.1",

test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { readFileSync } from 'fs'
2+
3+
readFileSync('./test.js')

test/ts/test-script.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ const obj: A = {
55
a: '1',
66
b: 2
77
}
8+
9+
fn(1)
810
console.log('test', str)
911

1012

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,11 @@ eslint@^2.0.0:
689689
text-table "~0.2.0"
690690
user-home "^2.0.0"
691691

692+
esm@^3.2.22:
693+
version "3.2.22"
694+
resolved "https://registry.yarnpkg.com/esm/-/esm-3.2.22.tgz#5062c2e22fee3ccfee4e8f20da768330da90d6e3"
695+
integrity sha512-z8YG7U44L82j1XrdEJcqZOLUnjxco8pO453gKOlaMD1/md1n/5QrscAmYG+oKUspsmDLuBFZrpbxI6aQ67yRxA==
696+
692697
espree@^3.1.6:
693698
version "3.4.3"
694699
resolved "https://registry.yarnpkg.com/espree/-/espree-3.4.3.tgz#2910b5ccd49ce893c2ffffaab4fd8b3a31b82374"

0 commit comments

Comments
 (0)