From d7030583c964031ee63720246f500258fa3239d3 Mon Sep 17 00:00:00 2001 From: Blake Embrey Date: Fri, 11 Sep 2015 22:57:33 -0700 Subject: [PATCH] Add ability to `ignoreAll` TypeScript errors Closes #5 --- src/bin/ts-node.ts | 10 +++++++--- src/typescript-node.spec.ts | 8 ++++++++ src/typescript-node.ts | 9 +++++---- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/bin/ts-node.ts b/src/bin/ts-node.ts index 42de0c589..1183b2cc8 100644 --- a/src/bin/ts-node.ts +++ b/src/bin/ts-node.ts @@ -17,20 +17,22 @@ interface Argv { compiler: string configFile: string ignoreWarnings: string + ignoreAll: boolean _: string[] } const argv = minimist(process.argv.slice(2), { stopEarly: true, string: ['eval', 'print', 'compiler', 'configFile', 'ignoreWarnings'], - boolean: ['help', 'version'], + boolean: ['help', 'version', 'ignoreAll'], alias: { v: ['version'], e: ['eval'], p: ['print'], c: ['compiler'], f: ['configFile'], - i: ['ignoreWarnings'] + i: ['ignoreWarnings'], + a: ['ignoreAll'] } }) @@ -48,8 +50,9 @@ if (argv.help) { -e, --eval [code] Evaluate code -p, --print [code] Evaluate code and print result -c, --compiler [name] Specify a custom TypeScript compiler - -i, --ignoreWarnings [codes] Ignore TypeScript warnings by code -f, --configFile [path] Specify the path to \`tsconfig.json\` + -i, --ignoreWarnings [codes] Ignore TypeScript warnings by diagnostic code + -a, --ignoreAll Ignore every TypeScript warning `) process.exit(0) } @@ -65,6 +68,7 @@ const compile = register({ compiler: argv.compiler, ignoreWarnings: list(argv.ignoreWarnings), configFile: argv.configFile, + ignoreAll: argv.ignoreAll, isEval: isEval }) diff --git a/src/typescript-node.spec.ts b/src/typescript-node.spec.ts index 65a050ad8..f2edd4ebf 100644 --- a/src/typescript-node.spec.ts +++ b/src/typescript-node.spec.ts @@ -103,4 +103,12 @@ describe('ts-node', function () { expect(m.example()).to.equal('hello') }) + + it('should ignore all warnings', function (done) { + exec(`node ${BIN_PATH} -a -p "x"`, function (err) { + expect(err.message).to.contain('ReferenceError: x is not defined') + + return done() + }) + }) }) diff --git a/src/typescript-node.ts b/src/typescript-node.ts index f8c24da2c..29e8fa1a1 100644 --- a/src/typescript-node.ts +++ b/src/typescript-node.ts @@ -27,6 +27,7 @@ export interface Options { configFile?: string ignoreWarnings?: string[] isEval?: boolean + ignoreAll?: boolean getFile?: (fileName: string) => string getVersion?: (fileName: string) => string } @@ -58,7 +59,7 @@ function readConfig (fileName: string, ts: typeof TS) { */ export function register (opts?: Options) { const cwd = process.cwd() - const options = extend({ getFile, getVersion, isEval: false }, opts) + const options = extend({ getFile, getVersion }, opts) const files: { [fileName: string]: boolean } = {} @@ -75,7 +76,7 @@ export function register (opts?: Options) { const config = readConfig(options.configFile, ts) // Render the configuration errors and exit the script. - if (config.errors.length) { + if (!options.ignoreAll && config.errors.length) { console.error(formatDiagnostics(config.errors, ts)) process.exit(1) } @@ -128,10 +129,10 @@ export function register (opts?: Options) { const diagnostics = getDiagnostics(service, fileName, options) - if (diagnostics.length) { + if (!options.ignoreAll && diagnostics.length) { const message = formatDiagnostics(diagnostics, ts) - if (opts.isEval) { + if (options.isEval) { throw new TypeScriptError(message) }