also use SWC for extensions transpile

pull/160274/head
Johannes 2022-09-07 11:18:53 +02:00
parent 87e54a0759
commit d6f5727021
No known key found for this signature in database
GPG Key ID: 6DEF802A22264FCA
3 changed files with 50 additions and 5 deletions

View File

@ -110,7 +110,7 @@ const tasks = compilations.map(function (tsconfigFile) {
overrideOptions.inlineSources = Boolean(build);
overrideOptions.base = path.dirname(absolutePath);
const compilation = tsb.create(absolutePath, overrideOptions, { verbose: false, transpileOnly, transpileOnlyIncludesDts: transpileOnly }, err => reporter(err.toString()));
const compilation = tsb.create(absolutePath, overrideOptions, { verbose: false, transpileOnly, transpileOnlyIncludesDts: transpileOnly, transpileWithSwc: true }, err => reporter(err.toString()));
const pipeline = function () {
const input = es.through();

View File

@ -245,9 +245,23 @@ class SwcTranspiler {
return;
}
const tsSrc = String(file.contents);
const isAmd = /\n(import|export)/m.test(tsSrc);
const t1 = Date.now();
this._jobs.push(swc.transform(tsSrc, isAmd ? SwcTranspiler._swcrcAmd : SwcTranspiler._swcrcEsm).then(output => {
let options = SwcTranspiler._swcrcEsm;
if (this._cmdLine.options.module === ts.ModuleKind.AMD) {
const isAmd = /\n(import|export)/m.test(tsSrc);
if (isAmd) {
options = SwcTranspiler._swcrcAmd;
}
}
else if (this._cmdLine.options.module === ts.ModuleKind.CommonJS) {
options = SwcTranspiler._swcrcCommonJS;
}
this._jobs.push(swc.transform(tsSrc, options).then(output => {
// check if output of a DTS-files isn't just "empty" and iff so
// skip this file
if (file.path.endsWith('.d.ts') && _isDefaultEmpty(output.code)) {
return;
}
const outBase = this._cmdLine.options.outDir ?? file.base;
const outPath = this._outputFileNames.getOutputFileName(file.path);
this.onOutfile(new Vinyl({
@ -285,6 +299,13 @@ SwcTranspiler._swcrcAmd = {
},
minify: false,
};
SwcTranspiler._swcrcCommonJS = {
..._a._swcrcAmd,
module: {
type: 'commonjs',
importInterop: 'none'
}
};
SwcTranspiler._swcrcEsm = {
..._a._swcrcAmd,
module: {

View File

@ -329,9 +329,25 @@ export class SwcTranspiler implements ITranspiler {
}
const tsSrc = String(file.contents);
const isAmd = /\n(import|export)/m.test(tsSrc);
const t1 = Date.now();
this._jobs.push(swc.transform(tsSrc, isAmd ? SwcTranspiler._swcrcAmd : SwcTranspiler._swcrcEsm).then(output => {
let options: swc.Options = SwcTranspiler._swcrcEsm;
if (this._cmdLine.options.module === ts.ModuleKind.AMD) {
const isAmd = /\n(import|export)/m.test(tsSrc);
if (isAmd) {
options = SwcTranspiler._swcrcAmd;
}
} else if (this._cmdLine.options.module === ts.ModuleKind.CommonJS) {
options = SwcTranspiler._swcrcCommonJS;
}
this._jobs.push(swc.transform(tsSrc, options).then(output => {
// check if output of a DTS-files isn't just "empty" and iff so
// skip this file
if (file.path.endsWith('.d.ts') && _isDefaultEmpty(output.code)) {
return;
}
const outBase = this._cmdLine.options.outDir ?? file.base;
const outPath = this._outputFileNames.getOutputFileName(file.path);
@ -374,6 +390,14 @@ export class SwcTranspiler implements ITranspiler {
minify: false,
};
private static readonly _swcrcCommonJS: swc.Options = {
...this._swcrcAmd,
module: {
type: 'commonjs',
importInterop: 'none'
}
};
private static readonly _swcrcEsm: swc.Options = {
...this._swcrcAmd,
module: {