mirror of
https://github.com/microsoft/vscode.git
synced 2026-02-15 07:28:05 +00:00
consume swc as libaray and wire up into the existing transpiler logic
This commit is contained in:
@@ -17,38 +17,9 @@ import * as os from 'os';
|
||||
import ts = require('typescript');
|
||||
import * as File from 'vinyl';
|
||||
import * as task from './task';
|
||||
import { createSwcClientStream } from './swc';
|
||||
const watch = require('./watch');
|
||||
|
||||
|
||||
// --- SWC: transpile -------------------------------------
|
||||
|
||||
export function transpileClientSWC(src: string, out: string) {
|
||||
|
||||
return function () {
|
||||
|
||||
// run SWC sync and put files straight onto the disk
|
||||
const swcPromise = createSwcClientStream().exec();
|
||||
|
||||
// copy none TS resources, like CSS, images, onto the disk
|
||||
const bom = require('gulp-bom') as typeof import('gulp-bom');
|
||||
const utf8Filter = util.filter(data => /(\/|\\)test(\/|\\).*utf8/.test(data.path));
|
||||
const tsFilter = util.filter(data => !/\.ts$/.test(data.path));
|
||||
const srcStream = gulp.src(`${src}/**`, { base: `${src}` });
|
||||
|
||||
const copyStream = srcStream
|
||||
.pipe(utf8Filter)
|
||||
.pipe(bom()) // this is required to preserve BOM in test files that loose it otherwise
|
||||
.pipe(utf8Filter.restore)
|
||||
.pipe(tsFilter);
|
||||
|
||||
const copyPromise = util.streamToPromise(copyStream.pipe(gulp.dest(out)));
|
||||
|
||||
return Promise.all([swcPromise, copyPromise]);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
// --- gulp-tsb: compile and transpile --------------------------------
|
||||
|
||||
const reporter = createReporter();
|
||||
@@ -68,7 +39,7 @@ function getTypeScriptCompilerOptions(src: string): ts.CompilerOptions {
|
||||
return options;
|
||||
}
|
||||
|
||||
function createCompile(src: string, build: boolean, emitError: boolean, transpileOnly: boolean) {
|
||||
function createCompile(src: string, build: boolean, emitError: boolean, transpileOnly: boolean | { swc: boolean }) {
|
||||
const tsb = require('./tsb') as typeof import('./tsb');
|
||||
const sourcemaps = require('gulp-sourcemaps') as typeof import('gulp-sourcemaps');
|
||||
|
||||
@@ -79,7 +50,11 @@ function createCompile(src: string, build: boolean, emitError: boolean, transpil
|
||||
overrideOptions.inlineSourceMap = true;
|
||||
}
|
||||
|
||||
const compilation = tsb.create(projectPath, overrideOptions, { verbose: false, transpileOnly }, err => reporter(err));
|
||||
const compilation = tsb.create(projectPath, overrideOptions, {
|
||||
verbose: false,
|
||||
transpileOnly: Boolean(transpileOnly),
|
||||
transpileWithSwc: typeof transpileOnly !== 'boolean' && transpileOnly.swc
|
||||
}, err => reporter(err));
|
||||
|
||||
function pipeline(token?: util.ICancellationToken) {
|
||||
const bom = require('gulp-bom') as typeof import('gulp-bom');
|
||||
@@ -115,11 +90,11 @@ function createCompile(src: string, build: boolean, emitError: boolean, transpil
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
export function transpileTask(src: string, out: string): () => NodeJS.ReadWriteStream {
|
||||
export function transpileTask(src: string, out: string, swc: boolean): () => NodeJS.ReadWriteStream {
|
||||
|
||||
return function () {
|
||||
|
||||
const transpile = createCompile(src, false, true, true);
|
||||
const transpile = createCompile(src, false, true, { swc });
|
||||
const srcPipe = gulp.src(`${src}/**`, { base: `${src}` });
|
||||
|
||||
return srcPipe
|
||||
|
||||
Reference in New Issue
Block a user