Skip to content

Commit

Permalink
Add ability to ignoreAll TypeScript errors
Browse files Browse the repository at this point in the history
Closes #5
  • Loading branch information
blakeembrey committed Sep 12, 2015
1 parent 48af1af commit d703058
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
10 changes: 7 additions & 3 deletions src/bin/ts-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,22 @@ interface Argv {
compiler: string
configFile: string
ignoreWarnings: string
ignoreAll: boolean
_: string[]
}

const argv = <Argv> <any> 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']
}
})

Expand All @@ -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)
}
Expand All @@ -65,6 +68,7 @@ const compile = register({
compiler: argv.compiler,
ignoreWarnings: list(argv.ignoreWarnings),
configFile: argv.configFile,
ignoreAll: argv.ignoreAll,
isEval: isEval
})

Expand Down
8 changes: 8 additions & 0 deletions src/typescript-node.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
})
})
9 changes: 5 additions & 4 deletions src/typescript-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface Options {
configFile?: string
ignoreWarnings?: string[]
isEval?: boolean
ignoreAll?: boolean
getFile?: (fileName: string) => string
getVersion?: (fileName: string) => string
}
Expand Down Expand Up @@ -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 } = {}

Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
}

Expand Down

0 comments on commit d703058

Please sign in to comment.