Skip to content

Commit d498c0f

Browse files
committed
fix child fork override
1 parent 4415b6f commit d498c0f

File tree

7 files changed

+49
-25
lines changed

7 files changed

+49
-25
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
### Yalc changelog
22

3-
## 1.0.0-pre.60 (2020-08-26)
3+
## 1.0.0-pre.62 (2020-09-22)
4+
5+
- fix child fork override
6+
7+
## 1.0.0-pre.61 (2020-08-26)
48

59
- fix terminal clear
610

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ts-node-dev",
3-
"version": "1.0.0-pre.61",
3+
"version": "1.0.0-pre.62",
44
"description": "Compiles your TS app and restarts when files are modified.",
55
"keywords": [
66
"restart",

src/bin.ts

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env node
22

3-
const dev = require('.')
3+
import { runDev } from '.'
44
import minimist from 'minimist'
55

66
const nodeArgs: string[] = []
@@ -71,6 +71,7 @@ const devFlags = {
7171
'deps',
7272
'all-deps',
7373
'dedupe',
74+
'fork',
7475
'exec-check',
7576
'debug',
7677
'poll',
@@ -96,24 +97,25 @@ const devFlags = {
9697

9798
type DevOptions = {
9899
poll: boolean
99-
debug: boolean,
100+
debug: boolean
101+
fork: boolean
100102
watch: string
101103
interval: string
102104
rs: boolean
103-
deps: boolean,
104-
dedupe: boolean,
105-
respawn: boolean,
106-
notify: boolean,
107-
clear: boolean,
108-
cls: boolean,
109-
'ignore-watch': string,
110-
'all-deps': boolean,
105+
deps: boolean
106+
dedupe: boolean
107+
respawn: boolean
108+
notify: boolean
109+
clear: boolean
110+
cls: boolean
111+
'ignore-watch': string
112+
'all-deps': boolean
111113
['deps-level']: string
112114
'compile-timeout': string
113115
'exec-check': boolean
114116
'exit-child': boolean
115117
'cache-directory': string
116-
'error-recompile': boolean,
118+
'error-recompile': boolean
117119
'tree-kill': boolean
118120
}
119121

@@ -130,8 +132,10 @@ const opts = minimist(devArgs, {
130132
alias: {
131133
...tsNodeAlias,
132134
'prefer-ts-exts': 'prefer-ts',
135+
},
136+
default: {
137+
fork: true
133138
},
134-
default: {},
135139
unknown: function (arg) {
136140
unknown.push(arg)
137141
return true
@@ -163,8 +167,11 @@ unknown.forEach(function (arg) {
163167
})
164168

165169
if (!script) {
170+
// eslint-disable-next-line no-console
171+
console.log('ts-node-dev: no script to run provided')
172+
// eslint-disable-next-line no-console
166173
console.log('Usage: ts-node-dev [options] script [arguments]\n')
167174
process.exit(1)
168175
}
169176

170-
dev(script, scriptArgs, nodeArgs, opts)
177+
runDev(script, scriptArgs, nodeArgs, opts)

src/cfg.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export const makeCfg = (main: string, opts: Partial<Options>): Config => {
4141
if (opts.respawn) c.respawn = true
4242
if (opts.notify === false) c.notify = false
4343
if (opts.clear || opts.cls) c.clear = true
44+
c.fork = opts.fork
4445
}
4546

4647
const ignoreWatchItems: string[] = opts['ignore-watch']

src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ const version = require('../package.json').version
1717
const tsNodeVersion = require('ts-node').VERSION
1818
const tsVersion = require('typescript').version
1919

20-
module.exports = function (
20+
export const runDev = (
2121
script: string,
2222
scriptArgs: string[],
2323
nodeArgs: string[],
2424
opts: Options
25-
) {
25+
) => {
2626
if (typeof script !== 'string' || script.length === 0) {
2727
throw new TypeError('`script` must be a string')
2828
}
@@ -216,9 +216,9 @@ module.exports = function (
216216
compiler.init()
217217
}
218218
compiler.clearErrorCompile()
219-
219+
220220
//if (cfg.clear) process.stdout.write("\u001b[2J\u001b[0;0H")
221-
if (cfg.clear) process.stdout.write("\u001bc")
221+
if (cfg.clear) process.stdout.write('\u001bc')
222222
if (isManualRestart === true) {
223223
notify('Restarting', 'manual restart from user')
224224
} else {

src/wrap.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,15 @@ process.on('SIGTERM', function () {
3030
})
3131

3232
if (cfg.fork) {
33+
const oldFork = fork
3334
// Overwrite child_process.fork() so that we can hook into forked processes
3435
// too. We also need to relay messages about required files to the parent.
3536
const newFork = function (
3637
modulePath: string,
3738
args: string[],
3839
options: ForkOptions
39-
) {
40-
const child = fork(__filename, [modulePath].concat(args), options)
40+
) {
41+
const child = oldFork(__filename, [modulePath].concat(args), options)
4142
ipc.relay(child)
4243
return child
4344
}

test/tsnd.test.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ const waitFor = (timeout: number) => {
3939
fs.ensureDirSync(tmpDir)
4040
fs.removeSync(join(tmpDir, 'fixture'))
4141
fs.copySync(join(__dirname, 'fixture'), scriptsDir)
42-
describe('ts-node-dev', () => {
42+
describe('ts-node-dev', function () {
43+
this.timeout(5000)
4344
it('It should restart on file change', async () => {
4445
const ps = spawnTsNodeDev('--respawn --poll simple.ts')
4546
await ps.waitForLine(/v1/)
@@ -113,9 +114,9 @@ describe('ts-node-dev', () => {
113114
})
114115

115116
const notFoundSource = `export const fn = (x: number) => {
116-
return 'v1'
117-
}
118-
`
117+
return 'v1'
118+
}
119+
`
119120
it('It recompiles file on error and restarts', async () => {
120121
const ps = spawnTsNodeDev('--respawn --error-recompile with-not-found.ts', {
121122
//stdout: true,
@@ -336,4 +337,14 @@ describe('ts-node-dev', () => {
336337
await ps.exit()
337338
t.ok(true)
338339
})
340+
341+
it.skip('It error on wrong cli flag', async () => {
342+
const ps = spawnTsNodeDev([`--transpileOnly`, `req-package`].join(' '))
343+
344+
await ps.waitForLine(/bad option/)
345+
346+
await ps.waitForLine(/CHANGED PACKAGE/)
347+
await ps.exit()
348+
t.ok(true)
349+
})
339350
})

0 commit comments

Comments
 (0)