From 9d15a728653f2c0c6eff00d6628947dd5d956e01 Mon Sep 17 00:00:00 2001 From: Blake Embrey Date: Sun, 7 Oct 2018 10:24:54 -0700 Subject: [PATCH] Remove support for custom `compiler` option (#699) --- README.md | 3 +- package-lock.json | 178 ++++++++++++++++++++++++++-------------------- package.json | 10 +-- src/index.ts | 44 +++--------- 4 files changed, 118 insertions(+), 117 deletions(-) diff --git a/README.md b/README.md index 9dad209f1..30d638655 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,7 @@ Create a new node.js configuration, add `-r ts-node/register` to node args and m You can set options by passing them before the script path, via programmatic usage or via environment variables. ```sh -ts-node --compiler ntypescript --project src/tsconfig.json hello-world.ts +ts-node --project src/tsconfig.json hello-world.ts ``` ### CLI Options @@ -127,7 +127,6 @@ _Environment variable denoted in parentheses._ * `--cacheDirectory` Configure the output file cache directory (`TS_NODE_CACHE_DIRECTORY`) * `-I, --ignore [pattern]` Override the path patterns to skip compilation (`TS_NODE_IGNORE`, default: `/node_modules/`) * `-P, --project [path]` Path to TypeScript JSON project file (`TS_NODE_PROJECT`) -* `-C, --compiler [name]` Specify a custom TypeScript compiler (`TS_NODE_COMPILER`, default: `typescript`) * `-D, --ignoreDiagnostics [code]` Ignore TypeScript warnings by diagnostic code (`TS_NODE_IGNORE_DIAGNOSTICS`) * `-O, --compilerOptions [opts]` JSON object to merge with compiler options (`TS_NODE_COMPILER_OPTIONS`) * `--files` Load files from `tsconfig.json` on startup (`TS_NODE_FILES`, default: `false`) diff --git a/package-lock.json b/package-lock.json index 4b12e15cb..b9d9c3672 100644 --- a/package-lock.json +++ b/package-lock.json @@ -120,13 +120,10 @@ "dev": true }, "ansi-styles": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.0.tgz", - "integrity": "sha512-NnSOmMEYtVR2JVMIGTzynRkkaxtiq1xnFBcdQD/DnNCYPoEPsVJhM98BDyaoNOQIi7p4okdi3E27eN7GQbsUug==", - "dev": true, - "requires": { - "color-convert": "^1.9.0" - } + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz", + "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=", + "dev": true }, "argparse": { "version": "1.0.9", @@ -171,15 +168,9 @@ "js-tokens": "^3.0.2" }, "dependencies": { - "ansi-styles": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz", - "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=", - "dev": true - }, "chalk": { "version": "1.1.3", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", + "resolved": "http://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=", "dev": true, "requires": { @@ -189,12 +180,6 @@ "strip-ansi": "^3.0.0", "supports-color": "^2.0.0" } - }, - "supports-color": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz", - "integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=", - "dev": true } } }, @@ -264,14 +249,40 @@ } }, "chalk": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.3.0.tgz", - "integrity": "sha512-Az5zJR2CBujap2rqXGaJKaPHyJ0IrUimvYNX+ncCy8PJP4ltOGTrHUIo097ZaL2zMeKYpiCdqDvS6zdrTFok3Q==", + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.1.tgz", + "integrity": "sha512-ObN6h1v2fTJSmUXoS3nMQ92LbDK9be4TV+6G+omQlGJFdcUX5heKi1LZ1YnRMIgwTLEj3E24bT6tYni50rlCfQ==", "dev": true, "requires": { - "ansi-styles": "^3.1.0", + "ansi-styles": "^3.2.1", "escape-string-regexp": "^1.0.5", - "supports-color": "^4.0.0" + "supports-color": "^5.3.0" + }, + "dependencies": { + "ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "dev": true, + "requires": { + "color-convert": "^1.9.0" + } + }, + "has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", + "dev": true + }, + "supports-color": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", + "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", + "dev": true, + "requires": { + "has-flag": "^3.0.0" + } + } } }, "check-error": { @@ -302,12 +313,12 @@ } }, "color-convert": { - "version": "1.9.1", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.1.tgz", - "integrity": "sha512-mjGanIiwQJskCC18rPR6OmrZ6fm2Lc7PeGFYwCmy5J34wC6F1PzdGL6xeMfmgicfYcNLGuVFA3WzXtIDCQSZxQ==", + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", + "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", "dev": true, "requires": { - "color-name": "^1.1.1" + "color-name": "1.1.3" } }, "color-name": { @@ -904,9 +915,9 @@ "dev": true }, "path-parse": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.5.tgz", - "integrity": "sha1-PBrfhx6pzWyUMbbqK9dKD/BVxME=", + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz", + "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==", "dev": true }, "pathval": { @@ -1045,7 +1056,7 @@ }, "strip-ansi": { "version": "3.0.1", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", + "resolved": "http://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", "dev": true, "requires": { @@ -1053,43 +1064,47 @@ } }, "supports-color": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-4.5.0.tgz", - "integrity": "sha1-vnoN5ITexcXN34s9WRJQRJEvY1s=", - "dev": true, - "requires": { - "has-flag": "^2.0.0" - } + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz", + "integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=", + "dev": true }, "tslib": { - "version": "1.8.1", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.8.1.tgz", - "integrity": "sha1-aUavLR1lGnsYY7Ux1uWvpBqkTqw=", + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.9.3.tgz", + "integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ==", "dev": true }, "tslint": { - "version": "5.8.0", - "resolved": "https://registry.npmjs.org/tslint/-/tslint-5.8.0.tgz", - "integrity": "sha1-H0mtWy53x2w69N3K5VKuTjYS6xM=", + "version": "5.11.0", + "resolved": "https://registry.npmjs.org/tslint/-/tslint-5.11.0.tgz", + "integrity": "sha1-mPMMAurjzecAYgHkwzywi0hYHu0=", "dev": true, "requires": { "babel-code-frame": "^6.22.0", "builtin-modules": "^1.1.1", - "chalk": "^2.1.0", - "commander": "^2.9.0", + "chalk": "^2.3.0", + "commander": "^2.12.1", "diff": "^3.2.0", "glob": "^7.1.1", + "js-yaml": "^3.7.0", "minimatch": "^3.0.4", "resolve": "^1.3.2", "semver": "^5.3.0", - "tslib": "^1.7.1", - "tsutils": "^2.12.1" + "tslib": "^1.8.0", + "tsutils": "^2.27.2" }, "dependencies": { + "commander": { + "version": "2.18.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.18.0.tgz", + "integrity": "sha512-6CYPa+JP2ftfRU2qkDK+UTVeQYosOg/2GbcjIcKPHfinyOLPVGXu/ovN86RP49Re5ndJK1N0kuiidFFuepc4ZQ==", + "dev": true + }, "glob": { - "version": "7.1.2", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", - "integrity": "sha1-wZyd+aAocC1nhhI4SmVSQExjbRU=", + "version": "7.1.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.3.tgz", + "integrity": "sha512-vcfuiIxogLV4DlGBHIUOwI0IbrJ8HWPc4MU7HzviGeNho/UJDfi6B5p3sHeWIQ0KGIU0Jpxi5ZHxemQfLkkAwQ==", "dev": true, "requires": { "fs.realpath": "^1.0.0", @@ -1101,9 +1116,9 @@ } }, "resolve": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.5.0.tgz", - "integrity": "sha512-hgoSGrc3pjzAPHNBg+KnFcK2HwlHTs/YrAGUr6qgTVUZmXv1UEXXl0bZNBKMA9fud6lRYFdPGz0xXxycPzmmiw==", + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.8.1.tgz", + "integrity": "sha512-AicPrAC7Qu1JxPCZ9ZgCZlY35QgFnNqc+0LtbRNxnVw4TXvjQ72wnuL9JQcEBgXkI9JM8MsT9kaQoHcpCRJOYA==", "dev": true, "requires": { "path-parse": "^1.0.5" @@ -1112,40 +1127,49 @@ } }, "tslint-config-standard": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/tslint-config-standard/-/tslint-config-standard-7.0.0.tgz", - "integrity": "sha512-QCrLt8WwiRgZpRSgRsk6cExy8/Vipa/5fHespm4Q1ly90EB6Lni04Ub8dkEW10bV3fPN3SkxEwj41ZOe/knCZA==", + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/tslint-config-standard/-/tslint-config-standard-8.0.1.tgz", + "integrity": "sha512-OWG+NblgjQlVuUS/Dmq3ax2v5QDZwRx4L0kEuDi7qFY9UI6RJhhNfoCV1qI4el8Fw1c5a5BTrjQJP0/jhGXY/Q==", "dev": true, "requires": { - "tslint-eslint-rules": "^4.1.1" + "tslint-eslint-rules": "^5.3.1" } }, "tslint-eslint-rules": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/tslint-eslint-rules/-/tslint-eslint-rules-4.1.1.tgz", - "integrity": "sha1-fDDniC8mvCdr/5HSOEl1xp2viLo=", + "version": "5.4.0", + "resolved": "https://registry.npmjs.org/tslint-eslint-rules/-/tslint-eslint-rules-5.4.0.tgz", + "integrity": "sha512-WlSXE+J2vY/VPgIcqQuijMQiel+UtmXS+4nvK4ZzlDiqBfXse8FAvkNnTcYhnQyOTW5KFM+uRRGXxYhFpuBc6w==", "dev": true, "requires": { - "doctrine": "^0.7.2", - "tslib": "^1.0.0", - "tsutils": "^1.4.0" + "doctrine": "0.7.2", + "tslib": "1.9.0", + "tsutils": "^3.0.0" }, "dependencies": { - "tsutils": { - "version": "1.9.1", - "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-1.9.1.tgz", - "integrity": "sha1-ufmrROVa+WgYMdXyjQrur1x1DLA=", + "tslib": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.9.0.tgz", + "integrity": "sha512-f/qGG2tUkrISBlQZEjEqoZ3B2+npJjIf04H1wuAv9iA8i04Icp+61KRXxFdha22670NJopsZCIjhC3SnjPRKrQ==", "dev": true + }, + "tsutils": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.0.0.tgz", + "integrity": "sha512-LjHBWR0vWAUHWdIAoTjoqi56Kz+FDKBgVEuL+gVPG/Pv7QW5IdaDDeK9Txlr6U0Cmckp5EgCIq1T25qe3J6hyw==", + "dev": true, + "requires": { + "tslib": "^1.8.1" + } } } }, "tsutils": { - "version": "2.14.0", - "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-2.14.0.tgz", - "integrity": "sha512-f6axSMV0RoUufiKiRQgmRlN1c+Ag+mDaZjcd6bHdvplT/zyhuMCGqw3pJS8s3+0x4EVkdoQajs9PchdDZlguvw==", + "version": "2.29.0", + "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-2.29.0.tgz", + "integrity": "sha512-g5JVHCIJwzfISaXpXE1qvNalca5Jwob6FjI4AoPlqMusJ6ftFE7IkkFoMhVLRgK+4Kx3gkzb8UZK5t5yTTvEmA==", "dev": true, "requires": { - "tslib": "^1.8.0" + "tslib": "^1.8.1" } }, "type-check": { @@ -1164,9 +1188,9 @@ "dev": true }, "typescript": { - "version": "2.8.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-2.8.3.tgz", - "integrity": "sha512-K7g15Bb6Ra4lKf7Iq2l/I5/En+hLIHmxWZGq3D4DIRNFxMNV6j2SHSvDOqs2tGd4UvD/fJvrwopzQXjLrT7Itw==", + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.1.1.tgz", + "integrity": "sha512-Veu0w4dTc/9wlWNf2jeRInNodKlcdLgemvPsrNpfu5Pq39sgfFjvIIgTsvUHCoLBnMhPoUA+tFxsXjU6VexVRQ==", "dev": true }, "ua-parser-js": { diff --git a/package.json b/package.json index aa3ecea1a..1df53c328 100644 --- a/package.json +++ b/package.json @@ -64,14 +64,16 @@ "chai": "^4.0.1", "istanbul": "^0.4.0", "mocha": "^5.0.1", - "ntypescript": "^1.201507091536.1", "proxyquire": "^2.0.0", "react": "^16.0.0", "rimraf": "^2.5.4", "semver": "^5.1.0", - "tslint": "^5.0.0", - "tslint-config-standard": "^7.0.0", - "typescript": "^2.8.3" + "tslint": "^5.11.0", + "tslint-config-standard": "^8.0.1", + "typescript": "^3.1.1" + }, + "peerDependencies": { + "typescript": ">=2.0" }, "dependencies": { "arrify": "^1.0.0", diff --git a/src/index.ts b/src/index.ts index c69a8fece..f04d025b4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,7 +9,7 @@ import arrify = require('arrify') import bufferFrom = require('buffer-from') import { BaseError } from 'make-error' import * as util from 'util' -import * as _ts from 'typescript' +import * as ts from 'typescript' /** * @internal @@ -30,28 +30,6 @@ const debugFn = shouldDebug ? } : (_: string, fn: (arg: T) => U) => fn -/** - * Common TypeScript interfaces between versions. - */ -export interface TSCommon { - version: typeof _ts.version - sys: typeof _ts.sys - ScriptSnapshot: typeof _ts.ScriptSnapshot - displayPartsToString: typeof _ts.displayPartsToString - createLanguageService: typeof _ts.createLanguageService - getDefaultLibFilePath: typeof _ts.getDefaultLibFilePath - getPreEmitDiagnostics: typeof _ts.getPreEmitDiagnostics - flattenDiagnosticMessageText: typeof _ts.flattenDiagnosticMessageText - transpileModule: typeof _ts.transpileModule - ModuleKind: typeof _ts.ModuleKind - ScriptTarget: typeof _ts.ScriptTarget - findConfigFile: typeof _ts.findConfigFile - readConfigFile: typeof _ts.readConfigFile - parseJsonConfigFileContent: typeof _ts.parseJsonConfigFileContent - formatDiagnostics: typeof _ts.formatDiagnostics - formatDiagnosticsWithColorAndContext: typeof _ts.formatDiagnosticsWithColorAndContext -} - /** * Export the current version. */ @@ -76,7 +54,7 @@ export interface Options { ignoreDiagnostics?: number | string | Array readFile?: (path: string) => string | undefined fileExists?: (path: string) => boolean - transformers?: _ts.CustomTransformers + transformers?: ts.CustomTransformers } /** @@ -173,7 +151,7 @@ export interface Register { cwd: string extensions: string[] cachedir: string - ts: TSCommon + ts: typeof ts compile (code: string, fileName: string, lineOffset?: number): string getTypeInfo (code: string, fileName: string, position: number): TypeInfo } @@ -224,11 +202,10 @@ export function register (opts: Options = {}): Register { const { compilerOptions, project, skipProject } = options const compiler = options.compiler || 'typescript' const typeCheck = options.typeCheck === true || options.transpileOnly !== true - const ts: typeof _ts = require(compiler) const transformers = options.transformers || undefined const readFile = options.readFile || ts.sys.readFile const fileExists = options.fileExists || ts.sys.fileExists - const config = readConfig(cwd, ts, fileExists, readFile, compilerOptions, project, skipProject) + const config = readConfig(cwd, fileExists, readFile, compilerOptions, project, skipProject) const configDiagnosticList = filterDiagnostics(config.errors, ignoreDiagnostics) const extensions = ['.ts', '.tsx'] const fileNames = options.files ? config.fileNames : [] @@ -245,7 +222,7 @@ export function register (opts: Options = {}): Register { }) ) - const diagnosticHost: _ts.FormatDiagnosticsHost = { + const diagnosticHost: ts.FormatDiagnosticsHost = { getNewLine: () => EOL, getCurrentDirectory: () => cwd, getCanonicalFileName: (path) => path @@ -255,7 +232,7 @@ export function register (opts: Options = {}): Register { ? ts.formatDiagnosticsWithColorAndContext : ts.formatDiagnostics - function createTSError (diagnostics: ReadonlyArray<_ts.Diagnostic>) { + function createTSError (diagnostics: ReadonlyArray) { const diagnosticText = formatDiagnostics(diagnostics, diagnosticHost) const diagnosticCodes = diagnostics.map(x => x.code) return new TSError(diagnosticText, diagnosticCodes) @@ -446,7 +423,7 @@ function registerExtension ( /** * Do post-processing on config options to support `ts-node`. */ -function fixConfig (ts: TSCommon, config: _ts.ParsedCommandLine) { +function fixConfig (config: ts.ParsedCommandLine) { // Delete options that *should not* be passed through. delete config.options.out delete config.options.outFile @@ -473,13 +450,12 @@ function fixConfig (ts: TSCommon, config: _ts.ParsedCommandLine) { */ function readConfig ( cwd: string, - ts: TSCommon, fileExists: (path: string) => boolean, readFile: (path: string) => string | undefined, compilerOptions?: object, project?: string | null, noProject?: boolean | null -): _ts.ParsedCommandLine { +): ts.ParsedCommandLine { let config = { compilerOptions: {} } let basePath = normalizeSlashes(cwd) let configFileName: string | undefined = undefined @@ -506,7 +482,7 @@ function readConfig ( // Override default configuration options `ts-node` requires. config.compilerOptions = Object.assign({}, config.compilerOptions, compilerOptions, DEFAULT_COMPILER_OPTIONS) - return fixConfig(ts, ts.parseJsonConfigFileContent(config, ts.sys, basePath, undefined, configFileName)) + return fixConfig(ts.parseJsonConfigFileContent(config, ts.sys, basePath, undefined, configFileName)) } /** @@ -616,6 +592,6 @@ function getCompilerDigest (obj: object) { /** * Filter diagnostics. */ -function filterDiagnostics (diagnostics: _ts.Diagnostic[], ignore: number[]) { +function filterDiagnostics (diagnostics: ts.Diagnostic[], ignore: number[]) { return diagnostics.filter(x => ignore.indexOf(x.code) === -1) }