@@ -59,6 +59,7 @@ export interface Options {
5959 pretty ?: boolean | null
6060 typeCheck ?: boolean | null
6161 transpileOnly ?: boolean | null
62+ logError ?: boolean | null
6263 files ?: boolean | null
6364 compiler ?: string
6465 ignore ?: string [ ]
@@ -106,7 +107,8 @@ export const DEFAULTS: Options = {
106107 skipProject : yn ( process . env [ 'TS_NODE_SKIP_PROJECT' ] ) ,
107108 ignoreDiagnostics : split ( process . env [ 'TS_NODE_IGNORE_DIAGNOSTICS' ] ) ,
108109 typeCheck : yn ( process . env [ 'TS_NODE_TYPE_CHECK' ] ) ,
109- transpileOnly : yn ( process . env [ 'TS_NODE_TRANSPILE_ONLY' ] )
110+ transpileOnly : yn ( process . env [ 'TS_NODE_TRANSPILE_ONLY' ] ) ,
111+ logError : yn ( process . env [ 'TS_NODE_LOG_ERROR' ] )
110112}
111113
112114/**
@@ -226,8 +228,19 @@ export function register (opts: Options = {}): Register {
226228 return new TSError ( diagnosticText , diagnosticCodes )
227229 }
228230
229- // Render the configuration errors and exit the script.
230- if ( configDiagnosticList . length ) throw createTSError ( configDiagnosticList )
231+ function reportTSError ( configDiagnosticList : _ts . Diagnostic [ ] ) {
232+ const error = createTSError ( configDiagnosticList )
233+ if ( options . logError ) {
234+ // Print error in red color and continue execution.
235+ console . error ( '\x1b[31m%s\x1b[0m' , error )
236+ } else {
237+ // Throw error and exit the script.
238+ throw error
239+ }
240+ }
241+
242+ // Render the configuration errors.
243+ if ( configDiagnosticList . length ) reportTSError ( configDiagnosticList )
231244
232245 // Enable additional extensions when JSX or `allowJs` is enabled.
233246 if ( config . options . jsx ) extensions . push ( '.tsx' )
@@ -256,7 +269,7 @@ export function register (opts: Options = {}): Register {
256269 filterDiagnostics ( result . diagnostics , ignoreDiagnostics ) :
257270 [ ]
258271
259- if ( diagnosticList . length ) throw createTSError ( diagnosticList )
272+ if ( diagnosticList . length ) reportTSError ( configDiagnosticList )
260273
261274 return [ result . outputText , result . sourceMapText as string ]
262275 }
@@ -332,7 +345,7 @@ export function register (opts: Options = {}): Register {
332345
333346 const diagnosticList = filterDiagnostics ( diagnostics , ignoreDiagnostics )
334347
335- if ( diagnosticList . length ) throw createTSError ( diagnosticList )
348+ if ( diagnosticList . length ) reportTSError ( diagnosticList )
336349
337350 if ( output . emitSkipped ) {
338351 throw new TypeError ( `${ relative ( cwd , fileName ) } : Emit skipped` )
0 commit comments