diff --git a/package.json b/package.json index 6b589de..373a7f3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ts-node-dev", - "version": "1.1.8", + "version": "2.0.0", "description": "Compiles your TS app and restarts when files are modified.", "keywords": [ "restart", @@ -50,7 +50,7 @@ "rimraf": "^2.6.1", "source-map-support": "^0.5.12", "tree-kill": "^1.2.2", - "ts-node": "^9.0.0", + "ts-node": "^10.4.0", "tsconfig": "^7.0.0" }, "devDependencies": { diff --git a/src/bin.ts b/src/bin.ts index 0f3ef47..abe42cc 100644 --- a/src/bin.ts +++ b/src/bin.ts @@ -30,6 +30,8 @@ const tsNodeFlags = { 'ignore', 'ignore-diagnostics', 'compiler-options', + 'scopeDir', + 'transpiler' ], } @@ -58,6 +60,8 @@ type TSNodeOptions = { 'transpile-only': boolean pretty: boolean scope: boolean + scopeDir: string, + transpiler: string 'log-error': boolean 'skip-project': boolean 'skip-ignore': boolean diff --git a/src/compiler.ts b/src/compiler.ts index 378c837..79dc354 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -27,6 +27,16 @@ export type CompileParams = { compiledPath: string } +const parse = (value: string | undefined): object | undefined => { + return typeof value === 'string' ? JSON.parse(value) : undefined +} + +function split(value: string | undefined) { + return typeof value === 'string' + ? value.split(/ *, */g).filter((v) => v !== '') + : undefined +} + export const makeCompiler = ( options: Options, { @@ -185,30 +195,28 @@ export const makeCompiler = ( ? path.resolve(cwd, options._[0]) : undefined - const DEFAULTS = tsNode.DEFAULTS - tsNode.register({ // --dir does not work (it gives a boolean only) so we only check for script-mode dir: getCwd(options['dir'], options['script-mode'], scriptPath), - scope: options['scope'] || DEFAULTS.scope, - emit: options['emit'] || DEFAULTS.emit, - files: options['files'] || DEFAULTS.files, - pretty: options['pretty'] || DEFAULTS.pretty, - transpileOnly: options['transpile-only'] || DEFAULTS.transpileOnly, - ignore: options['ignore'] - ? tsNode.split(options['ignore']) - : DEFAULTS.ignore, - preferTsExts: options['prefer-ts-exts'] || DEFAULTS.preferTsExts, - logError: options['log-error'] || DEFAULTS.logError, + scope: options['scope'], + scopeDir: options['scopeDir'], + emit: options['emit'], + files: options['files'], + pretty: options['pretty'], + transpileOnly: options['transpile-only'], + ignore: options['ignore'] ? split(options['ignore']) : undefined, + preferTsExts: options['prefer-ts-exts'], + logError: options['log-error'], project: options['project'], skipProject: options['skip-project'], + transpiler: options['transpiler'], skipIgnore: options['skip-ignore'], - compiler: options['compiler'] || DEFAULTS.compiler, - compilerHost: options['compiler-host'] || DEFAULTS.compilerHost, + compiler: options['compiler'], + compilerHost: options['compiler-host'], ignoreDiagnostics: options['ignore-diagnostics'] - ? tsNode.split(options['ignore-diagnostics']) - : DEFAULTS.ignoreDiagnostics, - compilerOptions: tsNode.parse(options['compiler-options']), + ? split(options['ignore-diagnostics']) + : undefined, + compilerOptions: parse(options['compiler-options']), }) } @@ -237,13 +245,13 @@ export const makeCompiler = ( const fileName = params.compile const code = fs.readFileSync(fileName, 'utf-8') const compiledPath = params.compiledPath - + // Prevent occasional duplicate compilation requests if (compiledPathsHash[compiledPath]) { return - } + } compiledPathsHash[compiledPath] = true - + function writeCompiled(code: string, fileName?: string) { fs.writeFile(compiledPath, code, (err) => { err && log.error(err) @@ -277,7 +285,11 @@ export const makeCompiler = ( } catch (e) { console.error('Compilation error in', fileName) const errorCode = - 'throw ' + 'new Error(' + JSON.stringify(e.message) + ')' + ';' + 'throw ' + + 'new Error(' + + JSON.stringify((e as Error).message) + + ')' + + ';' writeCompiled(errorCode) // reinitialize ts-node compilation to clean up state after error diff --git a/tsconfig.json b/tsconfig.json index 3538fd0..3e63a84 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { "target": "es5", - "lib": ["es2015"], + "lib": ["es2017"], "module": "commonjs", "declaration": false, "skipLibCheck": true, diff --git a/yarn.lock b/yarn.lock index 935fccf..6ab0ef4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -23,6 +23,18 @@ chalk "^2.0.0" js-tokens "^4.0.0" +"@cspotcode/source-map-consumer@0.8.0": + version "0.8.0" + resolved "https://registry.yarnpkg.com/@cspotcode/source-map-consumer/-/source-map-consumer-0.8.0.tgz#33bf4b7b39c178821606f669bbc447a6a629786b" + integrity sha512-41qniHzTU8yAGbCp04ohlmSrZf8bkf/iJsl3V0dRGsQN/5GFfx+LbCSsCpp2gqrqjTVg/K6O8ycoV35JIwAzAg== + +"@cspotcode/source-map-support@0.7.0": + version "0.7.0" + resolved "https://registry.yarnpkg.com/@cspotcode/source-map-support/-/source-map-support-0.7.0.tgz#4789840aa859e46d2f3173727ab707c66bf344f5" + integrity sha512-X4xqRHqN8ACt2aHVe51OxeA2HjbcL4MqFqXkrmQszJ1NOUuUu5u6Vqx/0lZSVNku7velL5FC/s5uEAj1lsBMhA== + dependencies: + "@cspotcode/source-map-consumer" "0.8.0" + "@samverschueren/stream-to-observable@^0.3.0": version "0.3.1" resolved "https://registry.yarnpkg.com/@samverschueren/stream-to-observable/-/stream-to-observable-0.3.1.tgz#a21117b19ee9be70c379ec1877537ef2e1c63301" @@ -76,6 +88,26 @@ "@ts-nameof/common" "^4.2.0" "@ts-nameof/transforms-common" "^4.2.1" +"@tsconfig/node10@^1.0.7": + version "1.0.8" + resolved "https://registry.yarnpkg.com/@tsconfig/node10/-/node10-1.0.8.tgz#c1e4e80d6f964fbecb3359c43bd48b40f7cadad9" + integrity sha512-6XFfSQmMgq0CFLY1MslA/CPUfhIL919M1rMsa5lP2P097N2Wd1sSX0tx1u4olM16fLNhtHZpRhedZJphNJqmZg== + +"@tsconfig/node12@^1.0.7": + version "1.0.9" + resolved "https://registry.yarnpkg.com/@tsconfig/node12/-/node12-1.0.9.tgz#62c1f6dee2ebd9aead80dc3afa56810e58e1a04c" + integrity sha512-/yBMcem+fbvhSREH+s14YJi18sp7J9jpuhYByADT2rypfajMZZN4WQ6zBGgBKp53NKmqI36wFYDb3yaMPurITw== + +"@tsconfig/node14@^1.0.0": + version "1.0.1" + resolved "https://registry.yarnpkg.com/@tsconfig/node14/-/node14-1.0.1.tgz#95f2d167ffb9b8d2068b0b235302fafd4df711f2" + integrity sha512-509r2+yARFfHHE7T6Puu2jjkoycftovhXRqW328PDXTVGKihlb1P8Z9mMZH04ebyajfRY7dedfGynlrFHJUQCg== + +"@tsconfig/node16@^1.0.2": + version "1.0.2" + resolved "https://registry.yarnpkg.com/@tsconfig/node16/-/node16-1.0.2.tgz#423c77877d0569db20e1fc80885ac4118314010e" + integrity sha512-eZxlbI8GZscaGS7kkc/trHTT5xgrjH3/1n2JDwusC9iahPKWMRvRjJSAN5mCXviuTGQ/lHnhvv8Q1YTpnfz9gA== + "@types/cacheable-request@^6.0.1": version "6.0.1" resolved "https://registry.yarnpkg.com/@types/cacheable-request/-/cacheable-request-6.0.1.tgz#5d22f3dded1fd3a84c0bbeb5039a7419c2c91976" @@ -293,11 +325,21 @@ acorn-jsx@^5.2.0: resolved "https://registry.yarnpkg.com/acorn-jsx/-/acorn-jsx-5.2.0.tgz#4c66069173d6fdd68ed85239fc256226182b2ebe" integrity sha512-HiUX/+K2YpkpJ+SzBffkM/AQ2YE03S0U1kjTLVpoJdhZMOWy8qvXVN9JdLqv2QsaQ6MPYQIuNmwD8zOiYUofLQ== +acorn-walk@^8.1.1: + version "8.2.0" + resolved "https://registry.yarnpkg.com/acorn-walk/-/acorn-walk-8.2.0.tgz#741210f2e2426454508853a2f44d0ab83b7f69c1" + integrity sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA== + acorn@^7.3.1: version "7.4.0" resolved "https://registry.yarnpkg.com/acorn/-/acorn-7.4.0.tgz#e1ad486e6c54501634c6c397c5c121daa383607c" integrity sha512-+G7P8jJmCHr+S+cLfQxygbWhXy+8YTVGzAkpEbcLo2mLoL7tij/VG41QSHACSf5QgYRhMZYHuNc6drJaO0Da+w== +acorn@^8.4.1: + version "8.5.0" + resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.5.0.tgz#4512ccb99b3698c752591e9bb4472e38ad43cee2" + integrity sha512-yXbYeFy+jUuYd3/CDcg2NkIYE991XYX/bje7LmjJigUciaeO1JR4XxXgCIV1/Zc/dRuFEyw1L0pbA+qynJkW5Q== + aggregate-error@^3.0.0: version "3.1.0" resolved "https://registry.yarnpkg.com/aggregate-error/-/aggregate-error-3.1.0.tgz#92670ff50f5359bdb7a3e0d40d0ec30c5737687a" @@ -986,6 +1028,11 @@ coveralls@^2.11.2: minimist "1.2.0" request "2.79.0" +create-require@^1.1.0: + version "1.1.1" + resolved "https://registry.yarnpkg.com/create-require/-/create-require-1.1.1.tgz#c1d7e8f1e5f6cfc9ff65f9cd352d37348756c333" + integrity sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ== + cross-spawn@^4: version "4.0.2" resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-4.0.2.tgz#7b9247621c23adfdd3856004a823cbe397424d41" @@ -4116,14 +4163,6 @@ source-map-support@^0.5.12: buffer-from "^1.0.0" source-map "^0.6.0" -source-map-support@^0.5.17: - version "0.5.19" - resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.19.tgz#a98b62f86dcaf4f67399648c085291ab9e8fed61" - integrity sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw== - dependencies: - buffer-from "^1.0.0" - source-map "^0.6.0" - source-map@^0.5.3: version "0.5.6" resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.6.tgz#75ce38f52bf0733c5a7f0c118d81334a2bb5f412" @@ -4593,15 +4632,22 @@ ts-nameof@^5.0.0: "@ts-nameof/transforms-ts" "^4.2.1" glob "^7.1.6" -ts-node@^9.0.0: - version "9.0.0" - resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-9.0.0.tgz#e7699d2a110cc8c0d3b831715e417688683460b3" - integrity sha512-/TqB4SnererCDR/vb4S/QvSZvzQMJN8daAslg7MeaiHvD8rDZsSfXmNeNumyZZzMned72Xoq/isQljYSt8Ynfg== - dependencies: +ts-node@^10.4.0: + version "10.4.0" + resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-10.4.0.tgz#680f88945885f4e6cf450e7f0d6223dd404895f7" + integrity sha512-g0FlPvvCXSIO1JDF6S232P5jPYqBkRL9qly81ZgAOSU7rwI0stphCgd2kLiCrU9DjQCrJMWEqcNSjQL02s6d8A== + dependencies: + "@cspotcode/source-map-support" "0.7.0" + "@tsconfig/node10" "^1.0.7" + "@tsconfig/node12" "^1.0.7" + "@tsconfig/node14" "^1.0.0" + "@tsconfig/node16" "^1.0.2" + acorn "^8.4.1" + acorn-walk "^8.1.1" arg "^4.1.0" + create-require "^1.1.0" diff "^4.0.1" make-error "^1.1.1" - source-map-support "^0.5.17" yn "3.1.1" tsconfig-paths@^3.3.1: