@@ -22,21 +22,15 @@ import {
22
22
patchOptions ,
23
23
} from './get-esbuild-options.js' ;
24
24
25
- const handleEsbuildError = (
25
+ const formatEsbuildError = (
26
26
error : TransformFailure ,
27
27
) => {
28
- const [ firstError ] = error . errors ;
29
- let errorMessage = `[esbuild Error]: ${ firstError . text } ` ;
30
-
31
- if ( firstError . location ) {
32
- const { file, line, column } = firstError . location ;
33
- errorMessage += `\n at ${ file } :${ line } :${ column } ` ;
34
- }
35
-
36
- console . error ( errorMessage ) ;
37
-
38
- // eslint-disable-next-line n/no-process-exit
39
- process . exit ( 1 ) ;
28
+ error . name = 'TransformError' ;
29
+ // @ts -expect-error deleting non-option property
30
+ delete error . errors ;
31
+ // @ts -expect-error deleting non-option property
32
+ delete error . warnings ;
33
+ throw error ;
40
34
} ;
41
35
42
36
// Used by cjs-loader
@@ -76,19 +70,14 @@ export const transformSync = (
76
70
[
77
71
// eslint-disable-next-line @typescript-eslint/no-shadow
78
72
( _filePath , code ) => {
79
- const patchResults = patchOptions ( esbuildOptions ) ;
73
+ const patchResult = patchOptions ( esbuildOptions ) ;
74
+ let result ;
80
75
try {
81
- return patchResults (
82
- esbuildTransformSync ( code , esbuildOptions ) ,
83
- ) ;
76
+ result = esbuildTransformSync ( code , esbuildOptions ) ;
84
77
} catch ( error ) {
85
- handleEsbuildError ( error as TransformFailure ) ;
86
-
87
- /**
88
- * esbuild warnings are ignored because they're usually caught
89
- * at runtime by Node.js with better errors + stack traces
90
- */
78
+ throw formatEsbuildError ( error as TransformFailure ) ;
91
79
}
80
+ return patchResult ( result ) ;
92
81
} ,
93
82
transformDynamicImport ,
94
83
] ,
@@ -128,19 +117,14 @@ export const transform = async (
128
117
[
129
118
// eslint-disable-next-line @typescript-eslint/no-shadow
130
119
async ( _filePath , code ) => {
131
- const patchResults = patchOptions ( esbuildOptions ) ;
120
+ const patchResult = patchOptions ( esbuildOptions ) ;
121
+ let result ;
132
122
try {
133
- return patchResults (
134
- await esbuildTransform ( code , esbuildOptions ) ,
135
- ) ;
123
+ result = await esbuildTransform ( code , esbuildOptions ) ;
136
124
} catch ( error ) {
137
- handleEsbuildError ( error as TransformFailure ) ;
138
-
139
- /**
140
- * esbuild warnings are ignored because they're usually caught
141
- * at runtime by Node.js with better errors + stack traces
142
- */
125
+ throw formatEsbuildError ( error as TransformFailure ) ;
143
126
}
127
+ return patchResult ( result ) ;
144
128
} ,
145
129
transformDynamicImport ,
146
130
] ,
0 commit comments