From c1fb7325bdca83f9ee9b95c2b3d5572ac800436d Mon Sep 17 00:00:00 2001 From: Johannes Date: Tue, 1 Oct 2024 16:26:50 +0200 Subject: [PATCH 1/6] add esbuild transpiler for fast CI --- build/lib/tsb/index.js | 4 +-- build/lib/tsb/index.ts | 4 +-- build/lib/tsb/transpiler.js | 49 ++++++++++++++++++++++++++++++++- build/lib/tsb/transpiler.ts | 55 +++++++++++++++++++++++++++++++++++++ 4 files changed, 107 insertions(+), 5 deletions(-) diff --git a/build/lib/tsb/index.js b/build/lib/tsb/index.js index 8b8116d5a495..204c06e80ac9 100644 --- a/build/lib/tsb/index.js +++ b/build/lib/tsb/index.js @@ -14,8 +14,8 @@ const path_1 = require("path"); const utils_1 = require("./utils"); const fs_1 = require("fs"); const log = require("fancy-log"); -const colors = require("ansi-colors"); const transpiler_1 = require("./transpiler"); +const colors = require("ansi-colors"); class EmptyDuplex extends stream_1.Duplex { _write(_chunk, _encoding, callback) { callback(); } _read() { this.push(null); } @@ -97,7 +97,7 @@ function create(projectPath, existingOptions, config, onError = _defaultOnError) if (config.transpileOnly) { const transpiler = !config.transpileWithSwc ? new transpiler_1.TscTranspiler(logFn, printDiagnostic, projectPath, cmdLine) - : new transpiler_1.SwcTranspiler(logFn, printDiagnostic, projectPath, cmdLine); + : new transpiler_1.ESBuildTranspiler(logFn, printDiagnostic, projectPath, cmdLine); result = (() => createTranspileStream(transpiler)); } else { diff --git a/build/lib/tsb/index.ts b/build/lib/tsb/index.ts index 670ac6542e77..53c752d2655a 100644 --- a/build/lib/tsb/index.ts +++ b/build/lib/tsb/index.ts @@ -12,8 +12,8 @@ import { dirname } from 'path'; import { strings } from './utils'; import { readFileSync, statSync } from 'fs'; import * as log from 'fancy-log'; +import { ESBuildTranspiler, ITranspiler, TscTranspiler } from './transpiler'; import colors = require('ansi-colors'); -import { ITranspiler, SwcTranspiler, TscTranspiler } from './transpiler'; export interface IncrementalCompiler { (token?: any): Readable & Writable; @@ -130,7 +130,7 @@ export function create( if (config.transpileOnly) { const transpiler = !config.transpileWithSwc ? new TscTranspiler(logFn, printDiagnostic, projectPath, cmdLine) - : new SwcTranspiler(logFn, printDiagnostic, projectPath, cmdLine); + : new ESBuildTranspiler(logFn, printDiagnostic, projectPath, cmdLine); result = (() => createTranspileStream(transpiler)); } else { const _builder = builder.createTypeScriptBuilder({ logFn }, projectPath, cmdLine); diff --git a/build/lib/tsb/transpiler.js b/build/lib/tsb/transpiler.js index 100b1bac972a..7b8ffab888df 100644 --- a/build/lib/tsb/transpiler.js +++ b/build/lib/tsb/transpiler.js @@ -4,8 +4,9 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ Object.defineProperty(exports, "__esModule", { value: true }); -exports.SwcTranspiler = exports.TscTranspiler = void 0; +exports.SwcTranspiler = exports.ESBuildTranspiler = exports.TscTranspiler = void 0; const swc = require("@swc/core"); +const esbuild = require("esbuild"); const ts = require("typescript"); const threads = require("node:worker_threads"); const Vinyl = require("vinyl"); @@ -224,6 +225,52 @@ class TscTranspiler { } } exports.TscTranspiler = TscTranspiler; +class ESBuildTranspiler { + _logFn; + _onError; + _cmdLine; + _outputFileNames; + _jobs = []; + onOutfile; + constructor(_logFn, _onError, configFilePath, _cmdLine) { + this._logFn = _logFn; + this._onError = _onError; + this._cmdLine = _cmdLine; + _logFn('Transpile', `will use ESBuild to transpile source files`); + this._outputFileNames = new OutputFileNameOracle(_cmdLine, configFilePath); + } + async join() { + const jobs = this._jobs.slice(); + this._jobs.length = 0; + await Promise.allSettled(jobs); + } + transpile(file) { + if (!(file.contents instanceof Buffer)) { + throw Error('file.contents must be a Buffer'); + } + const t1 = Date.now(); + this._jobs.push(esbuild.transform(file.contents, { + target: ['es2022'], + loader: 'ts', + tsconfigRaw: JSON.stringify({ compilerOptions: this._cmdLine.options }), + supported: { + 'class-static-blocks': false // SEE https://github.com/evanw/esbuild/issues/3823 + } + }).then(result => { + const outBase = this._cmdLine.options.outDir ?? file.base; + const outPath = this._outputFileNames.getOutputFileName(file.path); + this.onOutfile(new Vinyl({ + path: outPath, + base: outBase, + contents: Buffer.from(result.code), + })); + this._logFn('Transpile', `esbuild took ${Date.now() - t1}ms for ${file.path}`); + }).catch(err => { + this._onError(err); + })); + } +} +exports.ESBuildTranspiler = ESBuildTranspiler; function _isDefaultEmpty(src) { return src .replace('"use strict";', '') diff --git a/build/lib/tsb/transpiler.ts b/build/lib/tsb/transpiler.ts index b6a9deeb3c76..20eb915d67a0 100644 --- a/build/lib/tsb/transpiler.ts +++ b/build/lib/tsb/transpiler.ts @@ -4,6 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import * as swc from '@swc/core'; +import * as esbuild from 'esbuild'; import * as ts from 'typescript'; import * as threads from 'node:worker_threads'; import * as Vinyl from 'vinyl'; @@ -291,6 +292,60 @@ export class TscTranspiler implements ITranspiler { } } +export class ESBuildTranspiler implements ITranspiler { + + private readonly _outputFileNames: OutputFileNameOracle; + private _jobs: Promise[] = []; + + onOutfile?: ((file: Vinyl) => void) | undefined; + + constructor( + private readonly _logFn: (topic: string, message: string) => void, + private readonly _onError: (err: any) => void, + configFilePath: string, + private readonly _cmdLine: ts.ParsedCommandLine + ) { + _logFn('Transpile', `will use ESBuild to transpile source files`); + this._outputFileNames = new OutputFileNameOracle(_cmdLine, configFilePath); + } + + async join(): Promise { + const jobs = this._jobs.slice(); + this._jobs.length = 0; + await Promise.allSettled(jobs); + } + + transpile(file: Vinyl): void { + if (!(file.contents instanceof Buffer)) { + throw Error('file.contents must be a Buffer'); + } + const t1 = Date.now(); + this._jobs.push(esbuild.transform(file.contents, { + target: ['es2022'], + loader: 'ts', + tsconfigRaw: JSON.stringify({ compilerOptions: this._cmdLine.options }), + supported: { + 'class-static-blocks': false // SEE https://github.com/evanw/esbuild/issues/3823 + } + }).then(result => { + + const outBase = this._cmdLine.options.outDir ?? file.base; + const outPath = this._outputFileNames.getOutputFileName(file.path); + + this.onOutfile!(new Vinyl({ + path: outPath, + base: outBase, + contents: Buffer.from(result.code), + })); + + this._logFn('Transpile', `esbuild took ${Date.now() - t1}ms for ${file.path}`); + + }).catch(err => { + this._onError(err); + })); + } +} + function _isDefaultEmpty(src: string): boolean { return src .replace('"use strict";', '') From 3ae94fbae4707824fab8e0d47e27f1441a4b481a Mon Sep 17 00:00:00 2001 From: Johannes Date: Wed, 2 Oct 2024 10:04:41 +0200 Subject: [PATCH 2/6] more transpile tweaks --- build/lib/tsb/transpiler.js | 10 +++++++++- build/lib/tsb/transpiler.ts | 11 ++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/build/lib/tsb/transpiler.js b/build/lib/tsb/transpiler.js index 7b8ffab888df..c002f299e7a6 100644 --- a/build/lib/tsb/transpiler.js +++ b/build/lib/tsb/transpiler.js @@ -251,12 +251,20 @@ class ESBuildTranspiler { const t1 = Date.now(); this._jobs.push(esbuild.transform(file.contents, { target: ['es2022'], + format: this._cmdLine.options.module === ts.ModuleKind.CommonJS ? 'cjs' : 'esm', loader: 'ts', - tsconfigRaw: JSON.stringify({ compilerOptions: this._cmdLine.options }), + tsconfigRaw: JSON.stringify({ + compilerOptions: this._cmdLine.options + }), supported: { 'class-static-blocks': false // SEE https://github.com/evanw/esbuild/issues/3823 } }).then(result => { + // check if output of a DTS-files isn't just "empty" and iff so + // skip this file + if (file.path.endsWith('.d.ts') && _isDefaultEmpty(result.code)) { + return; + } const outBase = this._cmdLine.options.outDir ?? file.base; const outPath = this._outputFileNames.getOutputFileName(file.path); this.onOutfile(new Vinyl({ diff --git a/build/lib/tsb/transpiler.ts b/build/lib/tsb/transpiler.ts index 20eb915d67a0..23c7c9d5875d 100644 --- a/build/lib/tsb/transpiler.ts +++ b/build/lib/tsb/transpiler.ts @@ -322,13 +322,22 @@ export class ESBuildTranspiler implements ITranspiler { const t1 = Date.now(); this._jobs.push(esbuild.transform(file.contents, { target: ['es2022'], + format: this._cmdLine.options.module === ts.ModuleKind.CommonJS ? 'cjs' : 'esm', loader: 'ts', - tsconfigRaw: JSON.stringify({ compilerOptions: this._cmdLine.options }), + tsconfigRaw: JSON.stringify({ + compilerOptions: this._cmdLine.options + }), supported: { 'class-static-blocks': false // SEE https://github.com/evanw/esbuild/issues/3823 } }).then(result => { + // check if output of a DTS-files isn't just "empty" and iff so + // skip this file + if (file.path.endsWith('.d.ts') && _isDefaultEmpty(result.code)) { + return; + } + const outBase = this._cmdLine.options.outDir ?? file.base; const outPath = this._outputFileNames.getOutputFileName(file.path); From c4093a5112d1554b91f902258d3f0781deb7913d Mon Sep 17 00:00:00 2001 From: Johannes Date: Wed, 2 Oct 2024 10:30:35 +0200 Subject: [PATCH 3/6] tweak transpile and pasteUrl.test --- build/lib/tsb/transpiler.js | 4 +++- build/lib/tsb/transpiler.ts | 4 +++- .../markdown-language-features/src/test/pasteUrl.test.ts | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/build/lib/tsb/transpiler.js b/build/lib/tsb/transpiler.js index c002f299e7a6..cee0c7e3c3c2 100644 --- a/build/lib/tsb/transpiler.js +++ b/build/lib/tsb/transpiler.js @@ -253,6 +253,7 @@ class ESBuildTranspiler { target: ['es2022'], format: this._cmdLine.options.module === ts.ModuleKind.CommonJS ? 'cjs' : 'esm', loader: 'ts', + sourcemap: 'inline', tsconfigRaw: JSON.stringify({ compilerOptions: this._cmdLine.options }), @@ -262,7 +263,7 @@ class ESBuildTranspiler { }).then(result => { // check if output of a DTS-files isn't just "empty" and iff so // skip this file - if (file.path.endsWith('.d.ts') && _isDefaultEmpty(result.code)) { + if (file.path.endsWith('.d.ts') || _isDefaultEmpty(result.code)) { return; } const outBase = this._cmdLine.options.outDir ?? file.base; @@ -282,6 +283,7 @@ exports.ESBuildTranspiler = ESBuildTranspiler; function _isDefaultEmpty(src) { return src .replace('"use strict";', '') + .replace(/\/\/# sourceMappingURL.*^/, '') .replace(/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm, '$1') .trim().length === 0; } diff --git a/build/lib/tsb/transpiler.ts b/build/lib/tsb/transpiler.ts index 23c7c9d5875d..a9e1ecaa25d4 100644 --- a/build/lib/tsb/transpiler.ts +++ b/build/lib/tsb/transpiler.ts @@ -324,6 +324,7 @@ export class ESBuildTranspiler implements ITranspiler { target: ['es2022'], format: this._cmdLine.options.module === ts.ModuleKind.CommonJS ? 'cjs' : 'esm', loader: 'ts', + sourcemap: 'inline', tsconfigRaw: JSON.stringify({ compilerOptions: this._cmdLine.options }), @@ -334,7 +335,7 @@ export class ESBuildTranspiler implements ITranspiler { // check if output of a DTS-files isn't just "empty" and iff so // skip this file - if (file.path.endsWith('.d.ts') && _isDefaultEmpty(result.code)) { + if (file.path.endsWith('.d.ts') || _isDefaultEmpty(result.code)) { return; } @@ -358,6 +359,7 @@ export class ESBuildTranspiler implements ITranspiler { function _isDefaultEmpty(src: string): boolean { return src .replace('"use strict";', '') + .replace(/\/\/# sourceMappingURL.*^/, '') .replace(/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm, '$1') .trim().length === 0; } diff --git a/extensions/markdown-language-features/src/test/pasteUrl.test.ts b/extensions/markdown-language-features/src/test/pasteUrl.test.ts index ea4a3f868af0..336971227b51 100644 --- a/extensions/markdown-language-features/src/test/pasteUrl.test.ts +++ b/extensions/markdown-language-features/src/test/pasteUrl.test.ts @@ -181,7 +181,7 @@ suite('createEditAddingLinksForUriList', () => { }); test('Smart should be disabled in math blocks', async () => { - const katex = (await import('@vscode/markdown-it-katex')).default; + const katex = ((await import('@vscode/markdown-it-katex')).default).default; const engine = createNewMarkdownEngine(); (await engine.getEngine(undefined)).use(katex); assert.strictEqual( From 1d86d98ccaeb55c22719114e5f1ec2d76d75e1d8 Mon Sep 17 00:00:00 2001 From: Johannes Date: Wed, 2 Oct 2024 10:49:35 +0200 Subject: [PATCH 4/6] more test tweaks --- .../markdown-language-features/src/test/pasteUrl.test.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/extensions/markdown-language-features/src/test/pasteUrl.test.ts b/extensions/markdown-language-features/src/test/pasteUrl.test.ts index 336971227b51..fdb6e6c2f717 100644 --- a/extensions/markdown-language-features/src/test/pasteUrl.test.ts +++ b/extensions/markdown-language-features/src/test/pasteUrl.test.ts @@ -181,7 +181,12 @@ suite('createEditAddingLinksForUriList', () => { }); test('Smart should be disabled in math blocks', async () => { - const katex = ((await import('@vscode/markdown-it-katex')).default).default; + + let katex: any = (await import('@vscode/markdown-it-katex')).default; + if (typeof katex === 'object') { + katex = katex.default; + } + const engine = createNewMarkdownEngine(); (await engine.getEngine(undefined)).use(katex); assert.strictEqual( From 4a5fdb2ff123c57e2eaba777b0994a0bf49d3758 Mon Sep 17 00:00:00 2001 From: Johannes Date: Thu, 3 Oct 2024 18:39:45 +0200 Subject: [PATCH 5/6] some more esbuild trickery --- build/lib/tsb/transpiler.js | 36 +++++++++++++++++++++++----------- build/lib/tsb/transpiler.ts | 39 ++++++++++++++++++++++++++----------- 2 files changed, 53 insertions(+), 22 deletions(-) diff --git a/build/lib/tsb/transpiler.js b/build/lib/tsb/transpiler.js index 0ebd05b57503..d56cf0638fb4 100644 --- a/build/lib/tsb/transpiler.js +++ b/build/lib/tsb/transpiler.js @@ -232,12 +232,34 @@ class ESBuildTranspiler { _outputFileNames; _jobs = []; onOutfile; + _transformOpts; constructor(_logFn, _onError, configFilePath, _cmdLine) { this._logFn = _logFn; this._onError = _onError; this._cmdLine = _cmdLine; _logFn('Transpile', `will use ESBuild to transpile source files`); this._outputFileNames = new OutputFileNameOracle(_cmdLine, configFilePath); + const isExtension = configFilePath.includes('extensions'); + this._transformOpts = { + target: ['es2022'], + format: isExtension ? 'cjs' : 'esm', + platform: isExtension ? 'node' : undefined, + loader: 'ts', + sourcemap: 'inline', + tsconfigRaw: JSON.stringify({ + compilerOptions: { + ...this._cmdLine.options, + ...{ + module: isExtension ? ts.ModuleKind.CommonJS : undefined + } + } + }), + supported: { + 'class-static-blocks': false, // SEE https://github.com/evanw/esbuild/issues/3823, + 'dynamic-import': !isExtension, // see https://github.com/evanw/esbuild/issues/1281 + 'class-field': !isExtension + } + }; } async join() { const jobs = this._jobs.slice(); @@ -250,20 +272,12 @@ class ESBuildTranspiler { } const t1 = Date.now(); this._jobs.push(esbuild.transform(file.contents, { - target: ['es2022'], - format: this._cmdLine.options.module === ts.ModuleKind.CommonJS ? 'cjs' : 'esm', - loader: 'ts', - sourcemap: 'inline', - tsconfigRaw: JSON.stringify({ - compilerOptions: this._cmdLine.options - }), - supported: { - 'class-static-blocks': false // SEE https://github.com/evanw/esbuild/issues/3823 - } + ...this._transformOpts, + sourcefile: file.path, }).then(result => { // check if output of a DTS-files isn't just "empty" and iff so // skip this file - if (file.path.endsWith('.d.ts') || _isDefaultEmpty(result.code)) { + if (file.path.endsWith('.d.ts') && _isDefaultEmpty(result.code)) { return; } const outBase = this._cmdLine.options.outDir ?? file.base; diff --git a/build/lib/tsb/transpiler.ts b/build/lib/tsb/transpiler.ts index 0247e7ada15c..30f0654cd274 100644 --- a/build/lib/tsb/transpiler.ts +++ b/build/lib/tsb/transpiler.ts @@ -299,6 +299,8 @@ export class ESBuildTranspiler implements ITranspiler { onOutfile?: ((file: Vinyl) => void) | undefined; + private readonly _transformOpts: esbuild.TransformOptions; + constructor( private readonly _logFn: (topic: string, message: string) => void, private readonly _onError: (err: any) => void, @@ -307,6 +309,29 @@ export class ESBuildTranspiler implements ITranspiler { ) { _logFn('Transpile', `will use ESBuild to transpile source files`); this._outputFileNames = new OutputFileNameOracle(_cmdLine, configFilePath); + + const isExtension = configFilePath.includes('extensions'); + + this._transformOpts = { + target: ['es2022'], + format: isExtension ? 'cjs' : 'esm', + platform: isExtension ? 'node' : undefined, + loader: 'ts', + sourcemap: 'inline', + tsconfigRaw: JSON.stringify({ + compilerOptions: { + ...this._cmdLine.options, + ...{ + module: isExtension ? ts.ModuleKind.CommonJS : undefined + } satisfies ts.CompilerOptions + } + }), + supported: { + 'class-static-blocks': false, // SEE https://github.com/evanw/esbuild/issues/3823, + 'dynamic-import': !isExtension, // see https://github.com/evanw/esbuild/issues/1281 + 'class-field': !isExtension + } + }; } async join(): Promise { @@ -321,21 +346,13 @@ export class ESBuildTranspiler implements ITranspiler { } const t1 = Date.now(); this._jobs.push(esbuild.transform(file.contents, { - target: ['es2022'], - format: this._cmdLine.options.module === ts.ModuleKind.CommonJS ? 'cjs' : 'esm', - loader: 'ts', - sourcemap: 'inline', - tsconfigRaw: JSON.stringify({ - compilerOptions: this._cmdLine.options - }), - supported: { - 'class-static-blocks': false // SEE https://github.com/evanw/esbuild/issues/3823 - } + ...this._transformOpts, + sourcefile: file.path, }).then(result => { // check if output of a DTS-files isn't just "empty" and iff so // skip this file - if (file.path.endsWith('.d.ts') || _isDefaultEmpty(result.code)) { + if (file.path.endsWith('.d.ts') && _isDefaultEmpty(result.code)) { return; } From 6e4221f0ece6b85cc20444d2c9601c7098b13ace Mon Sep 17 00:00:00 2001 From: Johannes Date: Fri, 4 Oct 2024 11:23:51 +0200 Subject: [PATCH 6/6] remove swc --- .../darwin/product-build-darwin.yml | 2 +- .../linux/product-build-linux.yml | 2 +- .../win32/product-build-win32.yml | 2 +- build/gulpfile.js | 2 +- build/lib/compilation.js | 8 +- build/lib/compilation.ts | 10 +- build/lib/tsb/transpiler.js | 97 +-------- build/lib/tsb/transpiler.ts | 112 ---------- package-lock.json | 195 ------------------ package.json | 1 - 10 files changed, 14 insertions(+), 417 deletions(-) diff --git a/build/azure-pipelines/darwin/product-build-darwin.yml b/build/azure-pipelines/darwin/product-build-darwin.yml index c863c60d5027..f6ce75c02a15 100644 --- a/build/azure-pipelines/darwin/product-build-darwin.yml +++ b/build/azure-pipelines/darwin/product-build-darwin.yml @@ -161,7 +161,7 @@ steps: displayName: Build server (web) - ${{ else }}: - - script: npm run gulp transpile-client-swc transpile-extensions + - script: npm run gulp transpile-client-esbuild transpile-extensions env: GITHUB_TOKEN: "$(github-distro-mixin-password)" displayName: Transpile diff --git a/build/azure-pipelines/linux/product-build-linux.yml b/build/azure-pipelines/linux/product-build-linux.yml index 3fb7b4fe679f..69967e6f933e 100644 --- a/build/azure-pipelines/linux/product-build-linux.yml +++ b/build/azure-pipelines/linux/product-build-linux.yml @@ -275,7 +275,7 @@ steps: displayName: Check GLIBC and GLIBCXX dependencies in server archive - ${{ else }}: - - script: npm run gulp "transpile-client-swc" "transpile-extensions" + - script: npm run gulp "transpile-client-esbuild" "transpile-extensions" env: GITHUB_TOKEN: "$(github-distro-mixin-password)" displayName: Transpile client and extensions diff --git a/build/azure-pipelines/win32/product-build-win32.yml b/build/azure-pipelines/win32/product-build-win32.yml index a30d4ca8029b..28eef9e01c68 100644 --- a/build/azure-pipelines/win32/product-build-win32.yml +++ b/build/azure-pipelines/win32/product-build-win32.yml @@ -129,7 +129,7 @@ steps: retryCountOnTaskFailure: 3 - ${{ if eq(parameters.VSCODE_QUALITY, 'oss') }}: - - powershell: npm run gulp "transpile-client-swc" "transpile-extensions" + - powershell: npm run gulp "transpile-client-esbuild" "transpile-extensions" env: GITHUB_TOKEN: "$(github-distro-mixin-password)" displayName: Transpile client and extensions diff --git a/build/gulpfile.js b/build/gulpfile.js index 73f7f23cc0b1..7894398c2ea9 100644 --- a/build/gulpfile.js +++ b/build/gulpfile.js @@ -20,7 +20,7 @@ gulp.task(compileApiProposalNamesTask); gulp.task(watchApiProposalNamesTask); // SWC Client Transpile -const transpileClientSWCTask = task.define('transpile-client-swc', task.series(util.rimraf('out'), transpileTask('src', 'out', true))); +const transpileClientSWCTask = task.define('transpile-client-esbuild', task.series(util.rimraf('out'), transpileTask('src', 'out', true))); gulp.task(transpileClientSWCTask); // Transpile only diff --git a/build/lib/compilation.js b/build/lib/compilation.js index e6fe4b592a66..7b9d73facbbd 100644 --- a/build/lib/compilation.js +++ b/build/lib/compilation.js @@ -19,11 +19,11 @@ const util = require("./util"); const fancyLog = require("fancy-log"); const ansiColors = require("ansi-colors"); const os = require("os"); -const ts = require("typescript"); const File = require("vinyl"); const task = require("./task"); const index_1 = require("./mangle/index"); const postcss_1 = require("./postcss"); +const ts = require("typescript"); const watch = require('./watch'); // --- gulp-tsb: compile and transpile -------------------------------- const reporter = (0, reporter_1.createReporter)(); @@ -52,7 +52,7 @@ function createCompile(src, { build, emitError, transpileOnly, preserveEnglish } const compilation = tsb.create(projectPath, overrideOptions, { verbose: false, transpileOnly: Boolean(transpileOnly), - transpileWithSwc: typeof transpileOnly !== 'boolean' && transpileOnly.swc + transpileWithSwc: typeof transpileOnly !== 'boolean' && transpileOnly.esbuild }, err => reporter(err)); function pipeline(token) { const bom = require('gulp-bom'); @@ -88,9 +88,9 @@ function createCompile(src, { build, emitError, transpileOnly, preserveEnglish } pipeline.projectPath = projectPath; return pipeline; } -function transpileTask(src, out, swc) { +function transpileTask(src, out, esbuild) { const task = () => { - const transpile = createCompile(src, { build: false, emitError: true, transpileOnly: { swc }, preserveEnglish: false }); + const transpile = createCompile(src, { build: false, emitError: true, transpileOnly: { esbuild }, preserveEnglish: false }); const srcPipe = gulp.src(`${src}/**`, { base: `${src}` }); return srcPipe .pipe(transpile()) diff --git a/build/lib/compilation.ts b/build/lib/compilation.ts index 978fb15df9e8..124bcc17c17c 100644 --- a/build/lib/compilation.ts +++ b/build/lib/compilation.ts @@ -14,12 +14,12 @@ import * as util from './util'; import * as fancyLog from 'fancy-log'; import * as ansiColors from 'ansi-colors'; import * as os from 'os'; -import ts = require('typescript'); import * as File from 'vinyl'; import * as task from './task'; import { Mangler } from './mangle/index'; import { RawSourceMap } from 'source-map'; import { gulpPostcss } from './postcss'; +import ts = require('typescript'); const watch = require('./watch'); @@ -45,7 +45,7 @@ function getTypeScriptCompilerOptions(src: string): ts.CompilerOptions { interface ICompileTaskOptions { readonly build: boolean; readonly emitError: boolean; - readonly transpileOnly: boolean | { swc: boolean }; + readonly transpileOnly: boolean | { esbuild: boolean }; readonly preserveEnglish: boolean; } @@ -63,7 +63,7 @@ function createCompile(src: string, { build, emitError, transpileOnly, preserveE const compilation = tsb.create(projectPath, overrideOptions, { verbose: false, transpileOnly: Boolean(transpileOnly), - transpileWithSwc: typeof transpileOnly !== 'boolean' && transpileOnly.swc + transpileWithSwc: typeof transpileOnly !== 'boolean' && transpileOnly.esbuild }, err => reporter(err)); function pipeline(token?: util.ICancellationToken) { @@ -105,11 +105,11 @@ function createCompile(src: string, { build, emitError, transpileOnly, preserveE return pipeline; } -export function transpileTask(src: string, out: string, swc: boolean): task.StreamTask { +export function transpileTask(src: string, out: string, esbuild: boolean): task.StreamTask { const task = () => { - const transpile = createCompile(src, { build: false, emitError: true, transpileOnly: { swc }, preserveEnglish: false }); + const transpile = createCompile(src, { build: false, emitError: true, transpileOnly: { esbuild }, preserveEnglish: false }); const srcPipe = gulp.src(`${src}/**`, { base: `${src}` }); return srcPipe diff --git a/build/lib/tsb/transpiler.js b/build/lib/tsb/transpiler.js index d56cf0638fb4..a4439b8d7aeb 100644 --- a/build/lib/tsb/transpiler.js +++ b/build/lib/tsb/transpiler.js @@ -4,8 +4,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ Object.defineProperty(exports, "__esModule", { value: true }); -exports.SwcTranspiler = exports.ESBuildTranspiler = exports.TscTranspiler = void 0; -const swc = require("@swc/core"); +exports.ESBuildTranspiler = exports.TscTranspiler = void 0; const esbuild = require("esbuild"); const ts = require("typescript"); const threads = require("node:worker_threads"); @@ -301,98 +300,4 @@ function _isDefaultEmpty(src) { .replace(/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm, '$1') .trim().length === 0; } -class SwcTranspiler { - _logFn; - _onError; - _cmdLine; - onOutfile; - _outputFileNames; - _jobs = []; - constructor(_logFn, _onError, configFilePath, _cmdLine) { - this._logFn = _logFn; - this._onError = _onError; - this._cmdLine = _cmdLine; - _logFn('Transpile', `will use SWC to transpile source files`); - this._outputFileNames = new OutputFileNameOracle(_cmdLine, configFilePath); - } - async join() { - const jobs = this._jobs.slice(); - this._jobs.length = 0; - await Promise.allSettled(jobs); - } - transpile(file) { - if (this._cmdLine.options.noEmit) { - // not doing ANYTHING here - return; - } - const tsSrc = String(file.contents); - const t1 = Date.now(); - 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 || this._cmdLine.options.module === ts.ModuleKind.Node16) { - 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({ - path: outPath, - base: outBase, - contents: Buffer.from(output.code), - })); - this._logFn('Transpile', `swc took ${Date.now() - t1}ms for ${file.path}`); - }).catch(err => { - this._onError(err); - })); - } - // --- .swcrc - static _swcrcAmd = { - exclude: '\.js$', - jsc: { - parser: { - syntax: 'typescript', - tsx: false, - decorators: true - }, - target: 'es2022', - loose: false, - minify: { - compress: false, - mangle: false - }, - transform: { - useDefineForClassFields: false, - }, - }, - module: { - type: 'amd', - noInterop: false - }, - minify: false, - }; - static _swcrcCommonJS = { - ...this._swcrcAmd, - module: { - type: 'commonjs', - importInterop: 'swc' - } - }; - static _swcrcEsm = { - ...this._swcrcAmd, - module: { - type: 'es6' - } - }; -} -exports.SwcTranspiler = SwcTranspiler; //# sourceMappingURL=transpiler.js.map \ No newline at end of file diff --git a/build/lib/tsb/transpiler.ts b/build/lib/tsb/transpiler.ts index 30f0654cd274..ae841dcf88b7 100644 --- a/build/lib/tsb/transpiler.ts +++ b/build/lib/tsb/transpiler.ts @@ -3,7 +3,6 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import * as swc from '@swc/core'; import * as esbuild from 'esbuild'; import * as ts from 'typescript'; import * as threads from 'node:worker_threads'; @@ -380,114 +379,3 @@ function _isDefaultEmpty(src: string): boolean { .replace(/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm, '$1') .trim().length === 0; } - - -export class SwcTranspiler implements ITranspiler { - - onOutfile?: ((file: Vinyl) => void) | undefined; - - private readonly _outputFileNames: OutputFileNameOracle; - private _jobs: Promise[] = []; - - constructor( - private readonly _logFn: (topic: string, message: string) => void, - private readonly _onError: (err: any) => void, - configFilePath: string, - private readonly _cmdLine: ts.ParsedCommandLine - ) { - _logFn('Transpile', `will use SWC to transpile source files`); - this._outputFileNames = new OutputFileNameOracle(_cmdLine, configFilePath); - } - - async join(): Promise { - const jobs = this._jobs.slice(); - this._jobs.length = 0; - await Promise.allSettled(jobs); - } - - transpile(file: Vinyl): void { - if (this._cmdLine.options.noEmit) { - // not doing ANYTHING here - return; - } - - const tsSrc = String(file.contents); - const t1 = Date.now(); - - 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 || this._cmdLine.options.module === ts.ModuleKind.Node16) { - 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({ - path: outPath, - base: outBase, - contents: Buffer.from(output.code), - })); - - this._logFn('Transpile', `swc took ${Date.now() - t1}ms for ${file.path}`); - - }).catch(err => { - this._onError(err); - })); - } - - // --- .swcrc - - - private static readonly _swcrcAmd: swc.Options = { - exclude: '\.js$', - jsc: { - parser: { - syntax: 'typescript', - tsx: false, - decorators: true - }, - target: 'es2022', - loose: false, - minify: { - compress: false, - mangle: false - }, - transform: { - useDefineForClassFields: false, - }, - }, - module: { - type: 'amd', - noInterop: false - }, - minify: false, - }; - - private static readonly _swcrcCommonJS: swc.Options = { - ...this._swcrcAmd, - module: { - type: 'commonjs', - importInterop: 'swc' - } - }; - - private static readonly _swcrcEsm: swc.Options = { - ...this._swcrcAmd, - module: { - type: 'es6' - } - }; -} diff --git a/package-lock.json b/package-lock.json index 0770fcbad181..05992f09933b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -54,7 +54,6 @@ }, "devDependencies": { "@playwright/test": "^1.46.1", - "@swc/core": "1.3.62", "@types/cookie": "^0.3.3", "@types/debug": "^4.1.5", "@types/eslint": "^8.56.10", @@ -1794,200 +1793,6 @@ "integrity": "sha512-+iTbntw2IZPb/anVDbypzfQa+ay64MW0Zo8aJ8gZPWMMK6/OubMVb6lUPMagqjOPnmtauXnFCACVl3O7ogjeqQ==", "dev": true }, - "node_modules/@swc/core": { - "version": "1.3.62", - "resolved": "https://registry.npmjs.org/@swc/core/-/core-1.3.62.tgz", - "integrity": "sha512-J58hWY+/G8vOr4J6ZH9hLg0lMSijZtqIIf4HofZezGog/pVX6sJyBJ40dZ1ploFkDIlWTWvJyqtpesBKS73gkQ==", - "dev": true, - "hasInstallScript": true, - "engines": { - "node": ">=10" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/swc" - }, - "optionalDependencies": { - "@swc/core-darwin-arm64": "1.3.62", - "@swc/core-darwin-x64": "1.3.62", - "@swc/core-linux-arm-gnueabihf": "1.3.62", - "@swc/core-linux-arm64-gnu": "1.3.62", - "@swc/core-linux-arm64-musl": "1.3.62", - "@swc/core-linux-x64-gnu": "1.3.62", - "@swc/core-linux-x64-musl": "1.3.62", - "@swc/core-win32-arm64-msvc": "1.3.62", - "@swc/core-win32-ia32-msvc": "1.3.62", - "@swc/core-win32-x64-msvc": "1.3.62" - }, - "peerDependencies": { - "@swc/helpers": "^0.5.0" - }, - "peerDependenciesMeta": { - "@swc/helpers": { - "optional": true - } - } - }, - "node_modules/@swc/core-darwin-arm64": { - "version": "1.3.62", - "resolved": "https://registry.npmjs.org/@swc/core-darwin-arm64/-/core-darwin-arm64-1.3.62.tgz", - "integrity": "sha512-MmGilibITz68LEje6vJlKzc2gUUSgzvB3wGLSjEORikTNeM7P8jXVxE4A8fgZqDeudJUm9HVWrxCV+pHDSwXhA==", - "cpu": [ - "arm64" - ], - "dev": true, - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">=10" - } - }, - "node_modules/@swc/core-darwin-x64": { - "version": "1.3.62", - "resolved": "https://registry.npmjs.org/@swc/core-darwin-x64/-/core-darwin-x64-1.3.62.tgz", - "integrity": "sha512-Xl93MMB3sCWVlYWuQIB+v6EQgzoiuQYK5tNt9lsHoIEVu2zLdkQjae+5FUHZb1VYqCXIiWcULFfVz0R4Sjb7JQ==", - "cpu": [ - "x64" - ], - "dev": true, - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">=10" - } - }, - "node_modules/@swc/core-linux-arm-gnueabihf": { - "version": "1.3.62", - "resolved": "https://registry.npmjs.org/@swc/core-linux-arm-gnueabihf/-/core-linux-arm-gnueabihf-1.3.62.tgz", - "integrity": "sha512-nJsp6O7kCtAjTTMcIjVB0g5y1JNiYAa5q630eiwrnaHUusEFoANDdORI3Z9vXeikMkng+6yIv9/V8Rb093xLjQ==", - "cpu": [ - "arm" - ], - "dev": true, - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=10" - } - }, - "node_modules/@swc/core-linux-arm64-gnu": { - "version": "1.3.62", - "resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-gnu/-/core-linux-arm64-gnu-1.3.62.tgz", - "integrity": "sha512-XGsV93vpUAopDt5y6vPwbK1Nc/MlL55L77bAZUPIiosWD1cWWPHNtNSpriE6+I+JiMHe0pqtfS/SSTk6ZkFQVw==", - "cpu": [ - "arm64" - ], - "dev": true, - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=10" - } - }, - "node_modules/@swc/core-linux-arm64-musl": { - "version": "1.3.62", - "resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-musl/-/core-linux-arm64-musl-1.3.62.tgz", - "integrity": "sha512-ESUmJjSlTTkoBy9dMG49opcNn8BmviqStMhwyeD1G8XRnmRVCZZgoBOKdvCXmJhw8bQXDhZumeaTUB+OFUKVXg==", - "cpu": [ - "arm64" - ], - "dev": true, - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=10" - } - }, - "node_modules/@swc/core-linux-x64-gnu": { - "version": "1.3.62", - "resolved": "https://registry.npmjs.org/@swc/core-linux-x64-gnu/-/core-linux-x64-gnu-1.3.62.tgz", - "integrity": "sha512-wnHJkt3ZBrax3SFnUHDcncG6mrSg9ZZjMhQV9Mc3JL1x1s1Gy9rGZCoBNnV/BUZWTemxIBcQbANRSDut/WO+9A==", - "cpu": [ - "x64" - ], - "dev": true, - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=10" - } - }, - "node_modules/@swc/core-linux-x64-musl": { - "version": "1.3.62", - "resolved": "https://registry.npmjs.org/@swc/core-linux-x64-musl/-/core-linux-x64-musl-1.3.62.tgz", - "integrity": "sha512-9oRbuTC/VshB66Rgwi3pTq3sPxSTIb8k9L1vJjES+dDMKa29DAjPtWCXG/pyZ00ufpFZgkGEuAHH5uqUcr1JQg==", - "cpu": [ - "x64" - ], - "dev": true, - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=10" - } - }, - "node_modules/@swc/core-win32-arm64-msvc": { - "version": "1.3.62", - "resolved": "https://registry.npmjs.org/@swc/core-win32-arm64-msvc/-/core-win32-arm64-msvc-1.3.62.tgz", - "integrity": "sha512-zv14vlF2VRrxS061XkfzGjCYnOrEo5glKJjLK5PwUKysIoVrx/L8nAbFxjkX5cObdlyoqo+ekelyBPAO+4bS0w==", - "cpu": [ - "arm64" - ], - "dev": true, - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">=10" - } - }, - "node_modules/@swc/core-win32-ia32-msvc": { - "version": "1.3.62", - "resolved": "https://registry.npmjs.org/@swc/core-win32-ia32-msvc/-/core-win32-ia32-msvc-1.3.62.tgz", - "integrity": "sha512-8MC/PZQSsOP2iA/81tAfNRqMWyEqTS/8zKUI67vPuLvpx6NAjRn3E9qBv7iFqH79iqZNzqSMo3awnLrKZyFbcw==", - "cpu": [ - "ia32" - ], - "dev": true, - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">=10" - } - }, - "node_modules/@swc/core-win32-x64-msvc": { - "version": "1.3.62", - "resolved": "https://registry.npmjs.org/@swc/core-win32-x64-msvc/-/core-win32-x64-msvc-1.3.62.tgz", - "integrity": "sha512-GJSmUJ95HKHZXAxiuPUmrcm/S3ivQvEzXhOZaIqYBIwUsm02vFZkClsV7eIKzWjso1t0+I/8MjrnUNaSWqh1rQ==", - "cpu": [ - "x64" - ], - "dev": true, - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">=10" - } - }, "node_modules/@szmarczak/http-timer": { "version": "4.0.6", "resolved": "https://registry.npmjs.org/@szmarczak/http-timer/-/http-timer-4.0.6.tgz", diff --git a/package.json b/package.json index b9d34543ce2e..14be64618136 100644 --- a/package.json +++ b/package.json @@ -112,7 +112,6 @@ }, "devDependencies": { "@playwright/test": "^1.46.1", - "@swc/core": "1.3.62", "@types/cookie": "^0.3.3", "@types/debug": "^4.1.5", "@types/eslint": "^8.56.10",