Skip to content

Commit bc6c12c

Browse files
committed
handle ts-node's --ignore option
1 parent 06d2fe3 commit bc6c12c

File tree

6 files changed

+130
-12
lines changed

6 files changed

+130
-12
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ Also there is additional options specific to `ts-node-dev`:
3232
- `--compile-timeout` (default: 10000 ms) - for how long to wait before report the error that something went wrong with compilation of a file.
3333
- `--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.
3434
- `--ignore-watch` (default: []) - files/folders to be [ignored by `node-dev`](https://github.com/fgnass/node-dev#ignore-paths).
35+
36+
NB! `--ignore-watch` will NOT affect files ignored by TS compilation. Use `--ignore` option (or `TS_NODE_IGNORE`) to pass **regExp strings** (string values for `new RegExp(..)`) for filtering files that should not be compiled, by default `/node_modules/` are ignored by compiler.
37+
3538
**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.
3639
So, to ignore everthing in `node_modules`, just pass `--ignore-watch node_modules`
3740

lib/cfg.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ module.exports = function (main, opts) {
3030
if (opts.notify === false) c.notify = false;
3131
}
3232

33-
var ignoreWatch = (c.ignore || []).concat(opts && opts['ignore-watch'] || []);
33+
var ignoreWatch = ([]).concat(opts && opts['ignore-watch'] || []);
3434
ignoreWatch.length && console.log('Ignore watch:', ignoreWatch)
3535
var ignore = ignoreWatch.concat(ignoreWatch.map(resolvePath));
36-
36+
3737
return {
3838
vm: c.vm !== false,
3939
fork: c.fork !== false,

lib/child-require-hook.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var timeThreshold = 10000
66
var allowJs = false
77
var compiledDir
88
var preferTs = false
9-
var ignore = /node_modules/
9+
var ignore = [/node_modules/]
1010

1111
var compile = (code, fileName) => {
1212
var compiledPath = getCompiledPath(code, fileName, compiledDir)
@@ -62,7 +62,7 @@ function registerJsExtension() {
6262
}
6363
}
6464
var _compile = m._compile
65-
var isIgnored = ignore && ignore.test(fileName)
65+
var isIgnored = ignore && ignore.reduce((res, ignore) => res || ignore.test(fileName), false)
6666
if (tsCode !== undefined || (allowJs && !isIgnored)) {
6767
m._compile = function (code, fileName) {
6868
if (tsCode !== undefined) {

lib/compiler.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,21 @@ var compiler = {
3939
if (options['prefer-ts']) {
4040
fileData = fileData.replace('preferTs = false', 'preferTs = true')
4141
}
42-
if (options['ignore']) {
42+
if (options['ignore'] !== undefined) {
4343
var ignore = options['ignore']
44-
var ignoreVal = ignore === 'false' ? 'false' : 'new RegExp("' + ignore + '")'
45-
fileData = fileData.replace(/var ignore = .*$/, 'var ignore = ' + ignoreVal)
44+
var ignoreVal = !ignore || ignore === 'false'
45+
? 'false'
46+
: '[' + (Array.isArray(ignore) ? ignore : ignore.split(/, /))
47+
.map(ignore => 'new RegExp("' + ignore + '")').join(', ') + ']'
48+
fileData = fileData.replace('var ignore = [/node_modules/]', 'var ignore = ' + ignoreVal)
4649
}
4750
fileData = fileData.replace('var compiledDir', 'var compiledDir = "' + compiler.getCompiledDir() + '"')
4851
fileData = fileData.replace('./get-compiled-path', path.join(__dirname, 'get-compiled-path').replace(/\\/g, '/'))
4952
fs.writeFileSync(compiler.getChildHookPath(), fileData)
5053
},
5154
init: function (options) {
5255
var project = options['project']
53-
compiler.tsConfigPath = resolveSync(cwd, typeof project === 'string' ? project : undefined)
56+
compiler.tsConfigPath = resolveSync(cwd, typeof project === 'string' ? project : undefined) || ''
5457

5558
var originalJsHandler = require.extensions['.js']
5659
require.extensions['.ts'] = empty
@@ -66,7 +69,7 @@ var compiler = {
6669
cacheDirectory: options['cache-directory'] || path.join(tmpDir, 'cache'),
6770
compiler: options['compiler'],
6871
project: options['project'],
69-
ignore: options['ignore'],
72+
ignore: options['ignore'] || process.env['TS_NODE_IGNORE'],
7073
ignoreWarnings: options['ignoreWarnings'],
7174
disableWarnings: options['disableWarnings'],
7275
compilerOptions: options['compilerOptions']

package.json

Lines changed: 2 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.9",
3+
"version": "1.0.0-pre.10",
44
"description": "Compiles your TS app and restarts when files are modified.",
55
"keywords": [
66
"restart",
@@ -33,7 +33,7 @@
3333
},
3434
"scripts": {
3535
"test-node-dev": "tap test/*.js",
36-
"test": "node ./bin/ts-node-dev -r ./test/ts/add-require.js --cache --respawn --ignore-watch lib --ignore-watch bin --prefer-ts --cache-directory .ts-node test/ts/test-script test-arg --fd"
36+
"test": "node ./bin/ts-node-dev -r ./test/ts/add-require.js --cache --respawn --ignore-watch 'lib' --ignore-watch bin --ignore '/some/' --ignore '/other/' --prefer-ts --cache-directory .ts-node test/ts/test-script test-arg --fd"
3737
},
3838
"dependencies": {
3939
"ts-node": "*",

yarn.lock

Lines changed: 113 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@
66
version "8.0.4"
77
resolved "https://registry.yarnpkg.com/@types/node/-/node-8.0.4.tgz#d0ca03fa4a3d7ab66c1f4e78a0fd06e30e46a7a9"
88

9+
"@types/strip-bom@^3.0.0":
10+
version "3.0.0"
11+
resolved "https://registry.yarnpkg.com/@types/strip-bom/-/strip-bom-3.0.0.tgz#14a8ec3956c2e81edb7520790aecf21c290aebd2"
12+
13+
14+
version "0.0.30"
15+
resolved "https://registry.yarnpkg.com/@types/strip-json-comments/-/strip-json-comments-0.0.30.tgz#9aa30c04db212a9a0649d6ae6fd50accc40748a1"
16+
917
abbrev@1:
1018
version "1.1.0"
1119
resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.1.0.tgz#d0554c2256636e2f56e7c2e5ad183f859428d81f"
@@ -63,6 +71,12 @@ ansi-styles@^2.2.1:
6371
version "2.2.1"
6472
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-2.2.1.tgz#b432dd3358b634cf75e1e4664368240533c1ddbe"
6573

74+
ansi-styles@^3.1.0:
75+
version "3.2.0"
76+
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.2.0.tgz#c159b8d5be0f9e5a6f346dab94f16ce022161b88"
77+
dependencies:
78+
color-convert "^1.9.0"
79+
6680
ansicolors@~0.2.1:
6781
version "0.2.1"
6882
resolved "https://registry.yarnpkg.com/ansicolors/-/ansicolors-0.2.1.tgz#be089599097b74a5c9c4a84a0cdbcdb62bd87aef"
@@ -275,6 +289,14 @@ chalk@^1.0.0, chalk@^1.1.1, chalk@^1.1.3:
275289
strip-ansi "^3.0.0"
276290
supports-color "^2.0.0"
277291

292+
chalk@^2.3.0:
293+
version "2.3.0"
294+
resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.3.0.tgz#b5ea48efc9c1793dccc9b4767c93914d3f2d52ba"
295+
dependencies:
296+
ansi-styles "^3.1.0"
297+
escape-string-regexp "^1.0.5"
298+
supports-color "^4.0.0"
299+
278300
circular-json@^0.3.1:
279301
version "0.3.1"
280302
resolved "https://registry.yarnpkg.com/circular-json/-/circular-json-0.3.1.tgz#be8b36aefccde8b3ca7aa2d6afc07a37242c0d2d"
@@ -341,6 +363,16 @@ coffee-script@^1.8.0:
341363
version "1.12.6"
342364
resolved "https://registry.yarnpkg.com/coffee-script/-/coffee-script-1.12.6.tgz#285a3f7115689065064d6bf9ef4572db66695cbf"
343365

366+
color-convert@^1.9.0:
367+
version "1.9.1"
368+
resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-1.9.1.tgz#c1261107aeb2f294ebffec9ed9ecad529a6097ed"
369+
dependencies:
370+
color-name "^1.1.1"
371+
372+
color-name@^1.1.1:
373+
version "1.1.3"
374+
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.3.tgz#a7d0558bd89c42f795dd42328f740831ca53bc25"
375+
344376
color-support@^1.1.0:
345377
version "1.1.3"
346378
resolved "https://registry.yarnpkg.com/color-support/-/color-support-1.1.3.tgz#93834379a1cc9a0c61f82f52f0d04322251bd5a2"
@@ -513,6 +545,10 @@ diff@^1.3.2:
513545
version "1.4.0"
514546
resolved "https://registry.yarnpkg.com/diff/-/diff-1.4.0.tgz#7f28d2eb9ee7b15a97efd89ce63dcfdaa3ccbabf"
515547

548+
diff@^3.1.0:
549+
version "3.4.0"
550+
resolved "https://registry.yarnpkg.com/diff/-/diff-3.4.0.tgz#b1d85507daf3964828de54b37d0d73ba67dda56c"
551+
516552
517553
version "1.3.0"
518554
resolved "https://registry.yarnpkg.com/doctrine/-/doctrine-1.3.0.tgz#13e75682b55518424276f7c173783456ef913d26"
@@ -1008,6 +1044,10 @@ has-flag@^1.0.0:
10081044
version "1.0.0"
10091045
resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-1.0.0.tgz#9d9e793165ce017a00f00418c43f942a7b1d11fa"
10101046

1047+
has-flag@^2.0.0:
1048+
version "2.0.0"
1049+
resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-2.0.0.tgz#e8207af1cc7b30d446cc70b734b5e8be18f88d51"
1050+
10111051
has@^1.0.1:
10121052
version "1.0.1"
10131053
resolved "https://registry.yarnpkg.com/has/-/has-1.0.1.tgz#8461733f538b0837c9361e39a9ab9e9704dc2f28"
@@ -1040,6 +1080,12 @@ [email protected]:
10401080
version "2.16.3"
10411081
resolved "https://registry.yarnpkg.com/hoek/-/hoek-2.16.3.tgz#20bb7403d3cea398e91dc4710a8ff1b8274a25ed"
10421082

1083+
homedir-polyfill@^1.0.1:
1084+
version "1.0.1"
1085+
resolved "https://registry.yarnpkg.com/homedir-polyfill/-/homedir-polyfill-1.0.1.tgz#4c2bbc8a758998feebf5ed68580f76d46768b4bc"
1086+
dependencies:
1087+
parse-passwd "^1.0.0"
1088+
10431089
hosted-git-info@^2.1.4:
10441090
version "2.4.2"
10451091
resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.4.2.tgz#0076b9f46a270506ddbaaea56496897460612a67"
@@ -1484,6 +1530,10 @@ lru-cache@^4.0.1:
14841530
pseudomap "^1.0.2"
14851531
yallist "^2.1.2"
14861532

1533+
make-error@^1.1.1:
1534+
version "1.3.3"
1535+
resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.3.tgz#a97ae14ffd98b05f543e83ddc395e1b2b6e4cc6a"
1536+
14871537
map-obj@^1.0.0, map-obj@^1.0.1:
14881538
version "1.0.1"
14891539
resolved "https://registry.yarnpkg.com/map-obj/-/map-obj-1.0.1.tgz#d933ceb9205d82bdcf4886f6742bdc2b4dea146d"
@@ -1573,7 +1623,7 @@ [email protected], minimist@~0.0.1:
15731623
version "0.0.8"
15741624
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d"
15751625

1576-
[email protected], minimist@^1.1.1, minimist@^1.1.3:
1626+
[email protected], minimist@^1.1.1, minimist@^1.1.3, minimist@^1.2.0:
15771627
version "1.2.0"
15781628
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.0.tgz#a35008b20f41383eec1fb914f4cd5df79a264284"
15791629

@@ -1758,6 +1808,10 @@ parse-json@^2.2.0:
17581808
dependencies:
17591809
error-ex "^1.2.0"
17601810

1811+
parse-passwd@^1.0.0:
1812+
version "1.0.0"
1813+
resolved "https://registry.yarnpkg.com/parse-passwd/-/parse-passwd-1.0.0.tgz#6d5b934a456993b23d37f40a382d6f1666a8e5c6"
1814+
17611815
path-exists@^2.0.0:
17621816
version "2.1.0"
17631817
resolved "https://registry.yarnpkg.com/path-exists/-/path-exists-2.1.0.tgz#0feb6c64f0fc518d9a754dd5efb62c7022761f4b"
@@ -2106,6 +2160,12 @@ [email protected]:
21062160
dependencies:
21072161
hoek "2.x.x"
21082162

2163+
source-map-support@^0.5.0:
2164+
version "0.5.3"
2165+
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.3.tgz#2b3d5fff298cfa4d1afd7d4352d569e9a0158e76"
2166+
dependencies:
2167+
source-map "^0.6.0"
2168+
21092169
source-map@^0.4.4:
21102170
version "0.4.4"
21112171
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.4.4.tgz#eba4f5da9c0dc999de68032d8b4f76173652036b"
@@ -2116,6 +2176,10 @@ source-map@^0.5.3, source-map@~0.5.1:
21162176
version "0.5.6"
21172177
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.6.tgz#75ce38f52bf0733c5a7f0c118d81334a2bb5f412"
21182178

2179+
source-map@^0.6.0:
2180+
version "0.6.1"
2181+
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
2182+
21192183
source-map@~0.2.0:
21202184
version "0.2.0"
21212185
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.2.0.tgz#dab73fbcfc2ba819b4de03bd6f6eaa48164b3f9d"
@@ -2226,12 +2290,20 @@ strip-bom@^2.0.0:
22262290
dependencies:
22272291
is-utf8 "^0.2.0"
22282292

2293+
strip-bom@^3.0.0:
2294+
version "3.0.0"
2295+
resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-3.0.0.tgz#2334c18e9c759f7bdd56fdef7e9ae3d588e68ed3"
2296+
22292297
strip-indent@^1.0.1:
22302298
version "1.0.1"
22312299
resolved "https://registry.yarnpkg.com/strip-indent/-/strip-indent-1.0.1.tgz#0c7962a6adefa7bbd4ac366460a638552ae1a0a2"
22322300
dependencies:
22332301
get-stdin "^4.0.1"
22342302

2303+
strip-json-comments@^2.0.0:
2304+
version "2.0.1"
2305+
resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a"
2306+
22352307
strip-json-comments@~1.0.1:
22362308
version "1.0.4"
22372309
resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-1.0.4.tgz#1e15fbcac97d3ee99bf2d73b4c656b082bbafb91"
@@ -2250,6 +2322,12 @@ supports-color@^3.1.0:
22502322
dependencies:
22512323
has-flag "^1.0.0"
22522324

2325+
supports-color@^4.0.0:
2326+
version "4.5.0"
2327+
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-4.5.0.tgz#be7a0de484dec5c5cddf8b3d59125044912f635b"
2328+
dependencies:
2329+
has-flag "^2.0.0"
2330+
22532331
table@^3.7.8:
22542332
version "3.8.3"
22552333
resolved "https://registry.yarnpkg.com/table/-/table-3.8.3.tgz#2bbc542f0fda9861a755d3947fefd8b3f513855f"
@@ -2365,6 +2443,30 @@ tryit@^1.0.1:
23652443
version "1.0.3"
23662444
resolved "https://registry.yarnpkg.com/tryit/-/tryit-1.0.3.tgz#393be730a9446fd1ead6da59a014308f36c289cb"
23672445

2446+
ts-node@*:
2447+
version "4.1.0"
2448+
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-4.1.0.tgz#36d9529c7b90bb993306c408cd07f7743de20712"
2449+
dependencies:
2450+
arrify "^1.0.0"
2451+
chalk "^2.3.0"
2452+
diff "^3.1.0"
2453+
make-error "^1.1.1"
2454+
minimist "^1.2.0"
2455+
mkdirp "^0.5.1"
2456+
source-map-support "^0.5.0"
2457+
tsconfig "^7.0.0"
2458+
v8flags "^3.0.0"
2459+
yn "^2.0.0"
2460+
2461+
tsconfig@^7.0.0:
2462+
version "7.0.0"
2463+
resolved "https://registry.yarnpkg.com/tsconfig/-/tsconfig-7.0.0.tgz#84538875a4dc216e5c4a5432b3a4dec3d54e91b7"
2464+
dependencies:
2465+
"@types/strip-bom" "^3.0.0"
2466+
"@types/strip-json-comments" "0.0.30"
2467+
strip-bom "^3.0.0"
2468+
strip-json-comments "^2.0.0"
2469+
23682470
tunnel-agent@~0.4.0, tunnel-agent@~0.4.1:
23692471
version "0.4.3"
23702472
resolved "https://registry.yarnpkg.com/tunnel-agent/-/tunnel-agent-0.4.3.tgz#6373db76909fe570e08d73583365ed828a74eeeb"
@@ -2427,6 +2529,12 @@ uuid@^3.0.0:
24272529
version "3.1.0"
24282530
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.1.0.tgz#3dd3d3e790abc24d7b0d3a034ffababe28ebbc04"
24292531

2532+
v8flags@^3.0.0:
2533+
version "3.0.1"
2534+
resolved "https://registry.yarnpkg.com/v8flags/-/v8flags-3.0.1.tgz#dce8fc379c17d9f2c9e9ed78d89ce00052b1b76b"
2535+
dependencies:
2536+
homedir-polyfill "^1.0.1"
2537+
24302538
validate-npm-package-license@^3.0.1:
24312539
version "3.0.1"
24322540
resolved "https://registry.yarnpkg.com/validate-npm-package-license/-/validate-npm-package-license-3.0.1.tgz#2804babe712ad3379459acfbe24746ab2c303fbc"
@@ -2548,3 +2656,7 @@ yargs@~3.10.0:
25482656
cliui "^2.1.0"
25492657
decamelize "^1.0.0"
25502658
window-size "0.1.0"
2659+
2660+
yn@^2.0.0:
2661+
version "2.0.0"
2662+
resolved "https://registry.yarnpkg.com/yn/-/yn-2.0.0.tgz#e5adabc8acf408f6385fc76495684c88e6af689a"

0 commit comments

Comments
 (0)