Skip to content

Commit 4a5fdb2

Browse files
committed
some more esbuild trickery
1 parent 2a96e0d commit 4a5fdb2

File tree

2 files changed

+53
-22
lines changed

2 files changed

+53
-22
lines changed

build/lib/tsb/transpiler.js

+25-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/lib/tsb/transpiler.ts

+28-11
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,8 @@ export class ESBuildTranspiler implements ITranspiler {
299299

300300
onOutfile?: ((file: Vinyl) => void) | undefined;
301301

302+
private readonly _transformOpts: esbuild.TransformOptions;
303+
302304
constructor(
303305
private readonly _logFn: (topic: string, message: string) => void,
304306
private readonly _onError: (err: any) => void,
@@ -307,6 +309,29 @@ export class ESBuildTranspiler implements ITranspiler {
307309
) {
308310
_logFn('Transpile', `will use ESBuild to transpile source files`);
309311
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+
};
310335
}
311336

312337
async join(): Promise<void> {
@@ -321,21 +346,13 @@ export class ESBuildTranspiler implements ITranspiler {
321346
}
322347
const t1 = Date.now();
323348
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,
334351
}).then(result => {
335352

336353
// check if output of a DTS-files isn't just "empty" and iff so
337354
// skip this file
338-
if (file.path.endsWith('.d.ts') || _isDefaultEmpty(result.code)) {
355+
if (file.path.endsWith('.d.ts') && _isDefaultEmpty(result.code)) {
339356
return;
340357
}
341358

0 commit comments

Comments
 (0)