Skip to content

Commit 1fdb470

Browse files
committed
compiler error type + exit code
1 parent 1c4c840 commit 1fdb470

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

src/command/command.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export class Command {
101101
options.commandType = 'info'
102102
return options
103103
}
104-
104+
105105
// Resolve inputFile and inputFileType
106106
options.commandType = 'bundle'
107107
options.inFile = resolve(next)
@@ -191,7 +191,7 @@ export class Command {
191191
options.errorText = `expected <global>=<module> pair for --importAs.`
192192
return options
193193
}
194-
const pattern = /([a-zA-Z0-9]+)=([a-zA-Z0-9]+)/
194+
const pattern = /([a-zA-Z0-9-_$]+)=([a-zA-Z0-9-_$]+)/
195195
const match = next.match(pattern)
196196
if(!match) {
197197
options.commandType = 'error'

src/compiler/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ THE SOFTWARE.
2727
---------------------------------------------------------------------------*/
2828

2929
export { TypeScriptConfiguration } from './config'
30+
export { TypeScriptCompilerError } from './typescript'
3031
export { TypeScriptOptions } from './typescript'
3132
export { TypeScript } from './typescript'
3233
export { Watcher } from './watcher'

src/compiler/typescript.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ import { readFileSync } from 'fs'
4747
//
4848
// --------------------------------------------------------------------------
4949

50+
export class TypeScriptCompilerError extends Error {
51+
constructor(public exitcode: number) {
52+
super(`TypeScript ended with exit code ${exitcode}`)
53+
}
54+
}
55+
5056
export type ESTarget = 'unknown' | 'es3' | 'es5' | 'es6' | 'es2015' | 'es2016' | 'es2017' | 'es2018' | 'esnext'
5157

5258
export interface TypeScriptOptions {
@@ -110,7 +116,7 @@ export class TypeScript {
110116
if (exitcode === 0) {
111117
return resolve(exitcode)
112118
}
113-
reject(new Error(`exitcode ${exitcode}`))
119+
reject(new TypeScriptCompilerError(exitcode))
114120
})
115121
})
116122
}

src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { TypeScriptConfiguration } from './compiler/index'
3030
import { Command, CommandOptions } from './command/index'
3131
import { Bundler, BundlerOptions } from './bundler/index'
3232
import { TypeScript, TypeScriptOptions } from './compiler/index'
33+
import { TypeScriptCompilerError } from './compiler/index'
3334
import { writeFileSync } from 'fs'
3435

3536
/** Writes usage information */
@@ -137,7 +138,7 @@ async function bundle(commandOptions: CommandOptions) {
137138
})
138139
} catch(error) {
139140
fatal(error.message)
140-
process.exit(2)
141+
process.exit((error as TypeScriptCompilerError).exitcode)
141142
}
142143
}
143144

0 commit comments

Comments
 (0)