Skip to content

Commit 2357394

Browse files
committed
--deps flag and tests
1 parent bcbdf13 commit 2357394

File tree

11 files changed

+84
-64
lines changed

11 files changed

+84
-64
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.DS_Store
2-
node_modules
2+
/node_modules
33
*.log
44
.ts-node
55
.tmp

CHANGELOG.md

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

3+
## 1.0.0-pre.57
4+
5+
- fix `--deps` flag
6+
- add `--deps-level` flag
7+
38
## 1.0.0-pre.56 (2020-07-24)
49

510
- add `node-notifier` from `peerDependencies` make optional

bin/ts-node-dev

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ var nodeArgs = []
77

88
var devArgs = process.argv.slice(2, 100)
99
var unknown = []
10-
var opts = minimist(devArgs, {
11-
stopEarly: true,
10+
var opts = minimist(devArgs, {
11+
stopEarly: true,
1212
boolean: [
13+
'deps',
1314
'all-deps',
14-
'deps',
1515
'dedupe',
1616
'poll',
1717
'respawn',
@@ -37,9 +37,10 @@ var opts = minimist(devArgs, {
3737
'compiler-host',
3838
'script-mode',
3939
'rs'
40-
],
41-
string: [
40+
],
41+
string: [
4242
'dir',
43+
'deps-level',
4344
'compile-timeout',
4445
'ignore-watch',
4546
'interval',

lib/cfg.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,19 @@ module.exports = function (main, opts) {
1616
var c = read(dir)
1717
|| read(process.cwd())
1818
|| read(process.env.HOME || process.env.USERPROFILE) || {};
19-
20-
// Truthy == --all-deps, false: one level of deps
21-
if (typeof c.deps !== 'number') c.deps = c.deps ? -1 : 1;
22-
19+
20+
c.deps = parseInt(opts['deps-level']) || 0
21+
if (typeof c.depsLevel === 'number') c.deps = c.depsLevel
22+
2323
if (opts) {
2424
// Overwrite with CLI opts ...
25-
if (opts.allDeps) c.deps = -1;
26-
if (!opts.deps) c.deps = 0;
25+
if (opts['deps'] || opts['all-deps']) c.deps = -1;
2726
if (opts.dedupe) c.dedupe = true;
2827
if (opts.respawn) c.respawn = true;
2928
if (opts.notify === false) c.notify = false;
3029
if (opts.clear || opts.cls) c.clear = true;
3130
}
32-
31+
console.log('c.deps', c.deps)
3332
var ignoreWatch = ([]).concat(opts && opts['ignore-watch'] || []).concat(c.ignore || []);
3433
opts.debug && console.log('Ignore watch:', ignoreWatch)
3534
var ignore = ignoreWatch.concat(ignoreWatch.map(resolvePath));

lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ module.exports = function (script, scriptArgs, nodeArgs, opts) {
157157
}
158158

159159
// Listen for `required` messages and watch the required file.
160-
ipc.on(child, 'required', function (m) {
160+
ipc.on(child, 'required', function (m) {
161161
var isIgnored =
162162
cfg.ignore.some(isPrefixOf(m.required)) ||
163163
cfg.ignore.some(isRegExpMatch(m.required))

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"ts-node-dev": "node ./bin/ts-node-dev",
3737
"tsnd": "yarn ts-node-dev",
3838
"test": "ts-node -T test/index.ts",
39-
"test-dev": "ts-node-dev -T --respawn test/index.ts",
39+
"test-dev": "ts-node-dev -T --respawn test/index.ts --output",
4040
"test-docker": "docker-compose up",
4141
"ci": "yarn test",
4242
"ci-local": "docker run --name travis-debug -dit quay.io/travisci/ci-nodejs",
@@ -57,6 +57,7 @@
5757
},
5858
"devDependencies": {
5959
"@types/fs-extra": "^9.0.1",
60+
"@types/minimist": "^1.2.0",
6061
"@types/node": "^8.0.4",
6162
"@types/tape": "^4.13.0",
6263
"@types/touch": "^3.1.1",
@@ -76,8 +77,8 @@
7677
"typescript": "^3.9.5"
7778
},
7879
"peerDependencies": {
79-
"typescript": "*",
80-
"node-notifier": "*"
80+
"node-notifier": "*",
81+
"typescript": "*"
8182
},
8283
"peerDependenciesMeta": {
8384
"node-notifier": {

test/fixture/node_modules/package/index.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixture/node_modules/package/node_modules/level2-package/index.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/index.ts

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import * as test from 'tape'
2-
import { spawnTsNodeDev, scriptsDir, tmpDir } from './spawn'
2+
import { spawnTsNodeDev, scriptsDir, tmpDir, turnOnOutput } from './spawn'
33
import * as fs from 'fs-extra'
44
import { join } from 'path'
55
import touch = require('touch')
66

7+
if (process.argv.slice(2)[0] === '--output') {
8+
turnOnOutput()
9+
}
10+
711
export const replaceText = async (
812
script: string,
913
pattern: string | RegExp,
@@ -44,7 +48,7 @@ test('It should restart on file change', async (t) => {
4448
})
4549

4650
test('It allow watch arbitrary folder/file', async (t) => {
47-
const ps = spawnTsNodeDev('--respawn --watch folder,folder2 simple.ts') //.turnOnOutput()
51+
const ps = spawnTsNodeDev('--respawn --watch folder,folder2 simple.ts')
4852
await ps.waitForLine(/Using/)
4953
setTimeout(() => touch(join(scriptsDir, 'folder/some-file')), 250)
5054
await ps.waitForLine(/Restarting.*some-file/)
@@ -53,7 +57,7 @@ test('It allow watch arbitrary folder/file', async (t) => {
5357
})
5458

5559
test('It should report an error on start', async (t) => {
56-
const ps = spawnTsNodeDev('--respawn with-error.ts') //.turnOnOutput()
60+
const ps = spawnTsNodeDev('--respawn with-error.ts')
5761
await ps.waitForLine(/[ERROR]/)
5862
const out = ps.getStdout()
5963
t.ok(/Compilation error in/.test(out), 'Reports error file')
@@ -72,7 +76,7 @@ test('It should report an error on start', async (t) => {
7276
})
7377

7478
test('It should report an error with --log-error and continue to work', async (t) => {
75-
const ps = spawnTsNodeDev('--respawn --log-error with-error.ts') //.turnOnOutput()
79+
const ps = spawnTsNodeDev('--respawn --log-error with-error.ts')
7680
await ps.waitForErrorLine(/error/)
7781

7882
const out = ps.getStderr()
@@ -134,7 +138,7 @@ test('It handles allowJs option and loads JS modules', async (t) => {
134138
`--compiler-options=${JSON.stringify(cOptions)}`,
135139
`js-module.js`,
136140
].join(' ')
137-
) //.turnOnOutput()
141+
)
138142
await ps.waitForLine(/JS MODULE/)
139143
t.pass('ok')
140144
await ps.exit()
@@ -149,7 +153,7 @@ test('It handles resolveJsonModule option and loads JSON modules', async (t) =>
149153
`--compiler-options=${JSON.stringify(cOptions)}`,
150154
`import-json`,
151155
].join(' ')
152-
) //.turnOnOutput()
156+
)
153157
await ps.waitForLine(/JSON DATA: { file: 'json' }/)
154158
t.pass('ok')
155159
await ps.exit()
@@ -158,21 +162,21 @@ test('It handles resolveJsonModule option and loads JSON modules', async (t) =>
158162
test('It should not allow --script-mode and --dir together', async (t) => {
159163
const ps = spawnTsNodeDev(
160164
[`--script-mode`, `--dir folder`, `simple.ts`].join(' ')
161-
) //.turnOnOutput()
165+
)
162166
await ps.waitForLine(/TypeError: Script mode cannot be combined with `--dir`/)
163167
t.pass('ok')
164168
await ps.exit()
165169
})
166170

167171
test('It should use the tsconfig at --dir when defined', async (t) => {
168-
const ps = spawnTsNodeDev([`--dir dir-test`, `dir-test/index.ts`].join(' ')) //.turnOnOutput()
172+
const ps = spawnTsNodeDev([`--dir dir-test`, `dir-test/index.ts`].join(' '))
169173
await ps.waitForLine(/\{ hello: 'world' \}/)
170174
t.pass('ok')
171175
await ps.exit()
172176
})
173177

174178
test('It should use the tsconfig at --script-mode when defined', async (t) => {
175-
const ps = spawnTsNodeDev([`-s`, `dir-test/index.ts`].join(' ')) //.turnOnOutput()
179+
const ps = spawnTsNodeDev([`-s`, `dir-test/index.ts`].join(' '))
176180
await ps.waitForLine(/\{ hello: 'world' \}/)
177181
t.pass('ok')
178182
await ps.exit()
@@ -185,7 +189,7 @@ test('It should fail if not using --dir or --script-mode on dir-test/index.ts',
185189
`--compiler-options=${JSON.stringify(cOptions)}`,
186190
`dir-test/index.ts`,
187191
].join(' ')
188-
) //.turnOnOutput()
192+
)
189193
await ps.waitForLine(/has no default export./)
190194
t.pass('ok')
191195
await ps.exit()
@@ -200,7 +204,7 @@ test('It allows to use TS Transformers', async (t) => {
200204
`--compiler-options=${JSON.stringify(cOptions)}`,
201205
`nameof.ts`,
202206
].join(' ')
203-
) //.turnOnOutput()
207+
)
204208
await ps.waitForLine(/console/)
205209

206210
await ps.exit()
@@ -215,7 +219,7 @@ test('It allows to use custom TS Transformers', async (t) => {
215219
`--compiler-options=${JSON.stringify(cOptions)}`,
216220
`to-transform.ts`,
217221
].join(' ')
218-
) //.turnOnOutput()
222+
)
219223
await ps.waitForLine(/transformed/)
220224
t.pass('ok')
221225
await ps.exit()
@@ -229,13 +233,13 @@ test('It should --prefer-ts', async (t) => {
229233
//`--prefer-ts-exts`,
230234
`prefer/prefer.js`,
231235
].join(' ')
232-
) //.turnOnOutput()
236+
)
233237
await ps.waitForLine(/PREFER DEP JS/)
234238
await ps.waitForLine(/PREFER JS/)
235239
await ps.exit()
236240
t.pass()
237241
})
238-
t.test('SHould require JS deps by default', async (t) => {
242+
t.test('Should require JS deps by default', async (t) => {
239243
const ps = spawnTsNodeDev(
240244
[
241245
`--respawn`,
@@ -273,7 +277,7 @@ test.skip('It should add require with -r flag', async (t) => {
273277
//`--debug`,
274278
`simple`,
275279
].join(' ')
276-
) //.turnOnOutput()
280+
)
277281
await ps.waitForLine(/added --require/)
278282
await ps.waitForLine(/v1/)
279283

@@ -286,7 +290,7 @@ test.skip('It should add require with -r flag', async (t) => {
286290
})
287291

288292
test('It should handle --deps flag', async (t) => {
289-
const ps = spawnTsNodeDev([`--deps`, `--respawn`, `req-package`].join(' ')) //.turnOnOutput()
293+
const ps = spawnTsNodeDev([`--deps`, `--respawn`, `req-package`].join(' '))
290294

291295
await ps.waitForLine(/PACKAGE/)
292296

@@ -305,3 +309,25 @@ test('It should handle --deps flag', async (t) => {
305309
t.pass()
306310
t.end()
307311
})
312+
313+
314+
test('It should handle deep deps with --deps flag', async (t) => {
315+
const ps = spawnTsNodeDev([`--all-deps`, `--respawn`, `req-package`].join(' '))
316+
317+
await ps.waitForLine(/PACKAGE/)
318+
319+
setTimeout(
320+
() =>
321+
replaceText(
322+
'node_modules/package/node_modules/level2-package/index.js',
323+
'PACKAGE',
324+
'CHANGED PACKAGE'
325+
),
326+
100
327+
)
328+
329+
await ps.waitForLine(/CHANGED PACKAGE/)
330+
await ps.exit()
331+
t.pass()
332+
t.end()
333+
})

test/spawn.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ const bin = path.join(__dirname, '/../bin/ts-node-dev')
55
export const tmpDir = path.join(__dirname, '../.tmp')
66
export const scriptsDir = path.join(tmpDir, 'fixture')
77

8+
let outputTurnedOn = false
9+
10+
export const turnOnOutput = () => {
11+
outputTurnedOn = true
12+
}
13+
814
export const spawnTsNodeDev = (
915
cmd: string,
1016
options: { stdout?: boolean; stderr?: boolean; env?: any } = {}
@@ -20,15 +26,15 @@ export const spawnTsNodeDev = (
2026
})
2127
var out = ''
2228
var err = ''
23-
29+
2430
ps.stderr.on('data', function (data) {
25-
if (opts.stderr) {
31+
if (opts.stderr || outputTurnedOn) {
2632
console.log('STDERR:', data.toString())
2733
}
2834
err += data.toString()
2935
})
3036
ps.stdout.on('data', function (data) {
31-
if (opts.stdout) {
37+
if (opts.stdout || outputTurnedOn) {
3238
console.log('STDOUT:', data.toString())
3339
}
3440
out += data.toString()

0 commit comments

Comments
 (0)