Skip to content

Commit d45cf52

Browse files
committed
update to ts-node 10
1 parent 6cf0fec commit d45cf52

File tree

5 files changed

+100
-38
lines changed

5 files changed

+100
-38
lines changed

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ts-node-dev",
3-
"version": "1.1.8",
3+
"version": "2.0.0",
44
"description": "Compiles your TS app and restarts when files are modified.",
55
"keywords": [
66
"restart",
@@ -50,7 +50,7 @@
5050
"rimraf": "^2.6.1",
5151
"source-map-support": "^0.5.12",
5252
"tree-kill": "^1.2.2",
53-
"ts-node": "^9.0.0",
53+
"ts-node": "^10.4.0",
5454
"tsconfig": "^7.0.0"
5555
},
5656
"devDependencies": {

src/bin.ts

+4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ const tsNodeFlags = {
3030
'ignore',
3131
'ignore-diagnostics',
3232
'compiler-options',
33+
'scopeDir',
34+
'transpiler'
3335
],
3436
}
3537

@@ -58,6 +60,8 @@ type TSNodeOptions = {
5860
'transpile-only': boolean
5961
pretty: boolean
6062
scope: boolean
63+
scopeDir: string,
64+
transpiler: string
6165
'log-error': boolean
6266
'skip-project': boolean
6367
'skip-ignore': boolean

src/compiler.ts

+33-21
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ export type CompileParams = {
2727
compiledPath: string
2828
}
2929

30+
const parse = (value: string | undefined): object | undefined => {
31+
return typeof value === 'string' ? JSON.parse(value) : undefined
32+
}
33+
34+
function split(value: string | undefined) {
35+
return typeof value === 'string'
36+
? value.split(/ *, */g).filter((v) => v !== '')
37+
: undefined
38+
}
39+
3040
export const makeCompiler = (
3141
options: Options,
3242
{
@@ -185,30 +195,28 @@ export const makeCompiler = (
185195
? path.resolve(cwd, options._[0])
186196
: undefined
187197

188-
const DEFAULTS = tsNode.DEFAULTS
189-
190198
tsNode.register({
191199
// --dir does not work (it gives a boolean only) so we only check for script-mode
192200
dir: getCwd(options['dir'], options['script-mode'], scriptPath),
193-
scope: options['scope'] || DEFAULTS.scope,
194-
emit: options['emit'] || DEFAULTS.emit,
195-
files: options['files'] || DEFAULTS.files,
196-
pretty: options['pretty'] || DEFAULTS.pretty,
197-
transpileOnly: options['transpile-only'] || DEFAULTS.transpileOnly,
198-
ignore: options['ignore']
199-
? tsNode.split(options['ignore'])
200-
: DEFAULTS.ignore,
201-
preferTsExts: options['prefer-ts-exts'] || DEFAULTS.preferTsExts,
202-
logError: options['log-error'] || DEFAULTS.logError,
201+
scope: options['scope'],
202+
scopeDir: options['scopeDir'],
203+
emit: options['emit'],
204+
files: options['files'],
205+
pretty: options['pretty'],
206+
transpileOnly: options['transpile-only'],
207+
ignore: options['ignore'] ? split(options['ignore']) : undefined,
208+
preferTsExts: options['prefer-ts-exts'],
209+
logError: options['log-error'],
203210
project: options['project'],
204211
skipProject: options['skip-project'],
212+
transpiler: options['transpiler'],
205213
skipIgnore: options['skip-ignore'],
206-
compiler: options['compiler'] || DEFAULTS.compiler,
207-
compilerHost: options['compiler-host'] || DEFAULTS.compilerHost,
214+
compiler: options['compiler'],
215+
compilerHost: options['compiler-host'],
208216
ignoreDiagnostics: options['ignore-diagnostics']
209-
? tsNode.split(options['ignore-diagnostics'])
210-
: DEFAULTS.ignoreDiagnostics,
211-
compilerOptions: tsNode.parse(options['compiler-options']),
217+
? split(options['ignore-diagnostics'])
218+
: undefined,
219+
compilerOptions: parse(options['compiler-options']),
212220
})
213221
}
214222

@@ -237,13 +245,13 @@ export const makeCompiler = (
237245
const fileName = params.compile
238246
const code = fs.readFileSync(fileName, 'utf-8')
239247
const compiledPath = params.compiledPath
240-
248+
241249
// Prevent occasional duplicate compilation requests
242250
if (compiledPathsHash[compiledPath]) {
243251
return
244-
}
252+
}
245253
compiledPathsHash[compiledPath] = true
246-
254+
247255
function writeCompiled(code: string, fileName?: string) {
248256
fs.writeFile(compiledPath, code, (err) => {
249257
err && log.error(err)
@@ -277,7 +285,11 @@ export const makeCompiler = (
277285
} catch (e) {
278286
console.error('Compilation error in', fileName)
279287
const errorCode =
280-
'throw ' + 'new Error(' + JSON.stringify(e.message) + ')' + ';'
288+
'throw ' +
289+
'new Error(' +
290+
JSON.stringify((e as Error).message) +
291+
')' +
292+
';'
281293
writeCompiled(errorCode)
282294

283295
// reinitialize ts-node compilation to clean up state after error

tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"compilerOptions": {
33
"target": "es5",
4-
"lib": ["es2015"],
4+
"lib": ["es2017"],
55
"module": "commonjs",
66
"declaration": false,
77
"skipLibCheck": true,

yarn.lock

+60-14
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@
2323
chalk "^2.0.0"
2424
js-tokens "^4.0.0"
2525

26+
"@cspotcode/[email protected]":
27+
version "0.8.0"
28+
resolved "https://registry.yarnpkg.com/@cspotcode/source-map-consumer/-/source-map-consumer-0.8.0.tgz#33bf4b7b39c178821606f669bbc447a6a629786b"
29+
integrity sha512-41qniHzTU8yAGbCp04ohlmSrZf8bkf/iJsl3V0dRGsQN/5GFfx+LbCSsCpp2gqrqjTVg/K6O8ycoV35JIwAzAg==
30+
31+
"@cspotcode/[email protected]":
32+
version "0.7.0"
33+
resolved "https://registry.yarnpkg.com/@cspotcode/source-map-support/-/source-map-support-0.7.0.tgz#4789840aa859e46d2f3173727ab707c66bf344f5"
34+
integrity sha512-X4xqRHqN8ACt2aHVe51OxeA2HjbcL4MqFqXkrmQszJ1NOUuUu5u6Vqx/0lZSVNku7velL5FC/s5uEAj1lsBMhA==
35+
dependencies:
36+
"@cspotcode/source-map-consumer" "0.8.0"
37+
2638
"@samverschueren/stream-to-observable@^0.3.0":
2739
version "0.3.1"
2840
resolved "https://registry.yarnpkg.com/@samverschueren/stream-to-observable/-/stream-to-observable-0.3.1.tgz#a21117b19ee9be70c379ec1877537ef2e1c63301"
@@ -76,6 +88,26 @@
7688
"@ts-nameof/common" "^4.2.0"
7789
"@ts-nameof/transforms-common" "^4.2.1"
7890

91+
"@tsconfig/node10@^1.0.7":
92+
version "1.0.8"
93+
resolved "https://registry.yarnpkg.com/@tsconfig/node10/-/node10-1.0.8.tgz#c1e4e80d6f964fbecb3359c43bd48b40f7cadad9"
94+
integrity sha512-6XFfSQmMgq0CFLY1MslA/CPUfhIL919M1rMsa5lP2P097N2Wd1sSX0tx1u4olM16fLNhtHZpRhedZJphNJqmZg==
95+
96+
"@tsconfig/node12@^1.0.7":
97+
version "1.0.9"
98+
resolved "https://registry.yarnpkg.com/@tsconfig/node12/-/node12-1.0.9.tgz#62c1f6dee2ebd9aead80dc3afa56810e58e1a04c"
99+
integrity sha512-/yBMcem+fbvhSREH+s14YJi18sp7J9jpuhYByADT2rypfajMZZN4WQ6zBGgBKp53NKmqI36wFYDb3yaMPurITw==
100+
101+
"@tsconfig/node14@^1.0.0":
102+
version "1.0.1"
103+
resolved "https://registry.yarnpkg.com/@tsconfig/node14/-/node14-1.0.1.tgz#95f2d167ffb9b8d2068b0b235302fafd4df711f2"
104+
integrity sha512-509r2+yARFfHHE7T6Puu2jjkoycftovhXRqW328PDXTVGKihlb1P8Z9mMZH04ebyajfRY7dedfGynlrFHJUQCg==
105+
106+
"@tsconfig/node16@^1.0.2":
107+
version "1.0.2"
108+
resolved "https://registry.yarnpkg.com/@tsconfig/node16/-/node16-1.0.2.tgz#423c77877d0569db20e1fc80885ac4118314010e"
109+
integrity sha512-eZxlbI8GZscaGS7kkc/trHTT5xgrjH3/1n2JDwusC9iahPKWMRvRjJSAN5mCXviuTGQ/lHnhvv8Q1YTpnfz9gA==
110+
79111
"@types/cacheable-request@^6.0.1":
80112
version "6.0.1"
81113
resolved "https://registry.yarnpkg.com/@types/cacheable-request/-/cacheable-request-6.0.1.tgz#5d22f3dded1fd3a84c0bbeb5039a7419c2c91976"
@@ -293,11 +325,21 @@ acorn-jsx@^5.2.0:
293325
resolved "https://registry.yarnpkg.com/acorn-jsx/-/acorn-jsx-5.2.0.tgz#4c66069173d6fdd68ed85239fc256226182b2ebe"
294326
integrity sha512-HiUX/+K2YpkpJ+SzBffkM/AQ2YE03S0U1kjTLVpoJdhZMOWy8qvXVN9JdLqv2QsaQ6MPYQIuNmwD8zOiYUofLQ==
295327

328+
acorn-walk@^8.1.1:
329+
version "8.2.0"
330+
resolved "https://registry.yarnpkg.com/acorn-walk/-/acorn-walk-8.2.0.tgz#741210f2e2426454508853a2f44d0ab83b7f69c1"
331+
integrity sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==
332+
296333
acorn@^7.3.1:
297334
version "7.4.0"
298335
resolved "https://registry.yarnpkg.com/acorn/-/acorn-7.4.0.tgz#e1ad486e6c54501634c6c397c5c121daa383607c"
299336
integrity sha512-+G7P8jJmCHr+S+cLfQxygbWhXy+8YTVGzAkpEbcLo2mLoL7tij/VG41QSHACSf5QgYRhMZYHuNc6drJaO0Da+w==
300337

338+
acorn@^8.4.1:
339+
version "8.5.0"
340+
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.5.0.tgz#4512ccb99b3698c752591e9bb4472e38ad43cee2"
341+
integrity sha512-yXbYeFy+jUuYd3/CDcg2NkIYE991XYX/bje7LmjJigUciaeO1JR4XxXgCIV1/Zc/dRuFEyw1L0pbA+qynJkW5Q==
342+
301343
aggregate-error@^3.0.0:
302344
version "3.1.0"
303345
resolved "https://registry.yarnpkg.com/aggregate-error/-/aggregate-error-3.1.0.tgz#92670ff50f5359bdb7a3e0d40d0ec30c5737687a"
@@ -986,6 +1028,11 @@ coveralls@^2.11.2:
9861028
minimist "1.2.0"
9871029
request "2.79.0"
9881030

1031+
create-require@^1.1.0:
1032+
version "1.1.1"
1033+
resolved "https://registry.yarnpkg.com/create-require/-/create-require-1.1.1.tgz#c1d7e8f1e5f6cfc9ff65f9cd352d37348756c333"
1034+
integrity sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==
1035+
9891036
cross-spawn@^4:
9901037
version "4.0.2"
9911038
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-4.0.2.tgz#7b9247621c23adfdd3856004a823cbe397424d41"
@@ -4116,14 +4163,6 @@ source-map-support@^0.5.12:
41164163
buffer-from "^1.0.0"
41174164
source-map "^0.6.0"
41184165

4119-
source-map-support@^0.5.17:
4120-
version "0.5.19"
4121-
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.19.tgz#a98b62f86dcaf4f67399648c085291ab9e8fed61"
4122-
integrity sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw==
4123-
dependencies:
4124-
buffer-from "^1.0.0"
4125-
source-map "^0.6.0"
4126-
41274166
source-map@^0.5.3:
41284167
version "0.5.6"
41294168
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.6.tgz#75ce38f52bf0733c5a7f0c118d81334a2bb5f412"
@@ -4593,15 +4632,22 @@ ts-nameof@^5.0.0:
45934632
"@ts-nameof/transforms-ts" "^4.2.1"
45944633
glob "^7.1.6"
45954634

4596-
ts-node@^9.0.0:
4597-
version "9.0.0"
4598-
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-9.0.0.tgz#e7699d2a110cc8c0d3b831715e417688683460b3"
4599-
integrity sha512-/TqB4SnererCDR/vb4S/QvSZvzQMJN8daAslg7MeaiHvD8rDZsSfXmNeNumyZZzMned72Xoq/isQljYSt8Ynfg==
4600-
dependencies:
4635+
ts-node@^10.4.0:
4636+
version "10.4.0"
4637+
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-10.4.0.tgz#680f88945885f4e6cf450e7f0d6223dd404895f7"
4638+
integrity sha512-g0FlPvvCXSIO1JDF6S232P5jPYqBkRL9qly81ZgAOSU7rwI0stphCgd2kLiCrU9DjQCrJMWEqcNSjQL02s6d8A==
4639+
dependencies:
4640+
"@cspotcode/source-map-support" "0.7.0"
4641+
"@tsconfig/node10" "^1.0.7"
4642+
"@tsconfig/node12" "^1.0.7"
4643+
"@tsconfig/node14" "^1.0.0"
4644+
"@tsconfig/node16" "^1.0.2"
4645+
acorn "^8.4.1"
4646+
acorn-walk "^8.1.1"
46014647
arg "^4.1.0"
4648+
create-require "^1.1.0"
46024649
diff "^4.0.1"
46034650
make-error "^1.1.1"
4604-
source-map-support "^0.5.17"
46054651
yn "3.1.1"
46064652

46074653
tsconfig-paths@^3.3.1:

0 commit comments

Comments
 (0)