@@ -299,6 +299,8 @@ export class ESBuildTranspiler implements ITranspiler {
299
299
300
300
onOutfile ?: ( ( file : Vinyl ) => void ) | undefined ;
301
301
302
+ private readonly _transformOpts : esbuild . TransformOptions ;
303
+
302
304
constructor (
303
305
private readonly _logFn : ( topic : string , message : string ) => void ,
304
306
private readonly _onError : ( err : any ) => void ,
@@ -307,6 +309,29 @@ export class ESBuildTranspiler implements ITranspiler {
307
309
) {
308
310
_logFn ( 'Transpile' , `will use ESBuild to transpile source files` ) ;
309
311
this . _outputFileNames = new OutputFileNameOracle ( _cmdLine , configFilePath ) ;
312
+
313
+ const isExtension = configFilePath . includes ( 'extensions' ) ;
314
+
315
+ this . _transformOpts = {
316
+ target : [ 'es2022' ] ,
317
+ format : isExtension ? 'cjs' : 'esm' ,
318
+ platform : isExtension ? 'node' : undefined ,
319
+ loader : 'ts' ,
320
+ sourcemap : 'inline' ,
321
+ tsconfigRaw : JSON . stringify ( {
322
+ compilerOptions : {
323
+ ...this . _cmdLine . options ,
324
+ ...{
325
+ module : isExtension ? ts . ModuleKind . CommonJS : undefined
326
+ } satisfies ts . CompilerOptions
327
+ }
328
+ } ) ,
329
+ supported : {
330
+ 'class-static-blocks' : false , // SEE https://github.com/evanw/esbuild/issues/3823,
331
+ 'dynamic-import' : ! isExtension , // see https://github.com/evanw/esbuild/issues/1281
332
+ 'class-field' : ! isExtension
333
+ }
334
+ } ;
310
335
}
311
336
312
337
async join ( ) : Promise < void > {
@@ -321,21 +346,13 @@ export class ESBuildTranspiler implements ITranspiler {
321
346
}
322
347
const t1 = Date . now ( ) ;
323
348
this . _jobs . push ( esbuild . transform ( file . contents , {
324
- target : [ 'es2022' ] ,
325
- format : this . _cmdLine . options . module === ts . ModuleKind . CommonJS ? 'cjs' : 'esm' ,
326
- loader : 'ts' ,
327
- sourcemap : 'inline' ,
328
- tsconfigRaw : JSON . stringify ( {
329
- compilerOptions : this . _cmdLine . options
330
- } ) ,
331
- supported : {
332
- 'class-static-blocks' : false // SEE https://github.com/evanw/esbuild/issues/3823
333
- }
349
+ ...this . _transformOpts ,
350
+ sourcefile : file . path ,
334
351
} ) . then ( result => {
335
352
336
353
// check if output of a DTS-files isn't just "empty" and iff so
337
354
// skip this file
338
- if ( file . path . endsWith ( '.d.ts' ) || _isDefaultEmpty ( result . code ) ) {
355
+ if ( file . path . endsWith ( '.d.ts' ) && _isDefaultEmpty ( result . code ) ) {
339
356
return ;
340
357
}
341
358
0 commit comments