mirror of
https://github.com/microsoft/vscode.git
synced 2026-02-15 07:28:05 +00:00
* tweak createSwcClientStream to have async exec
* add `transpileClientSWC` and corresponding gulp task
This commit is contained in:
@@ -11,7 +11,7 @@ require('events').EventEmitter.defaultMaxListeners = 100;
|
||||
const gulp = require('gulp');
|
||||
const util = require('./lib/util');
|
||||
const task = require('./lib/task');
|
||||
const { transpileTask, compileTask, watchTask, compileApiProposalNamesTask, watchApiProposalNamesTask } = require('./lib/compilation');
|
||||
const { transpileClientSWC, transpileTask, compileTask, watchTask, compileApiProposalNamesTask, watchApiProposalNamesTask } = require('./lib/compilation');
|
||||
const { monacoTypecheckTask/* , monacoTypecheckWatchTask */ } = require('./gulpfile.editor');
|
||||
const { compileExtensionsTask, watchExtensionsTask, compileExtensionMediaTask } = require('./gulpfile.extensions');
|
||||
|
||||
@@ -19,6 +19,10 @@ const { compileExtensionsTask, watchExtensionsTask, compileExtensionMediaTask }
|
||||
gulp.task(compileApiProposalNamesTask);
|
||||
gulp.task(watchApiProposalNamesTask);
|
||||
|
||||
// SWC Client Transpile
|
||||
const transpileClientSWCTask = task.define('transpile-client-swc', task.series(util.rimraf('out'), transpileClientSWC('src', 'out')));
|
||||
gulp.task(transpileClientSWCTask);
|
||||
|
||||
// Transpile only
|
||||
const transpileClientTask = task.define('transpile-client', task.series(util.rimraf('out'), util.buildWebNodePaths('out'), transpileTask('src', 'out')));
|
||||
gulp.task(transpileClientTask);
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.watchApiProposalNamesTask = exports.compileApiProposalNamesTask = exports.watchTask = exports.compileTask = exports.transpileTask = void 0;
|
||||
exports.watchApiProposalNamesTask = exports.compileApiProposalNamesTask = exports.watchTask = exports.compileTask = exports.transpileTask = exports.transpileClientSWC = void 0;
|
||||
const es = require("event-stream");
|
||||
const fs = require("fs");
|
||||
const gulp = require("gulp");
|
||||
@@ -18,7 +18,29 @@ const ansiColors = require("ansi-colors");
|
||||
const os = require("os");
|
||||
const File = require("vinyl");
|
||||
const task = require("./task");
|
||||
const swc_1 = require("./swc");
|
||||
const watch = require('./watch');
|
||||
// --- SWC: transpile -------------------------------------
|
||||
function transpileClientSWC(src, out) {
|
||||
return function () {
|
||||
// run SWC sync and put files straight onto the disk
|
||||
const swcPromise = (0, swc_1.createSwcClientStream)().exec();
|
||||
// copy none TS resources, like CSS, images, onto the disk
|
||||
const bom = require('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]);
|
||||
};
|
||||
}
|
||||
exports.transpileClientSWC = transpileClientSWC;
|
||||
// --- gulp-tsb: compile and transpile --------------------------------
|
||||
const reporter = (0, reporter_1.createReporter)();
|
||||
function getTypeScriptCompilerOptions(src) {
|
||||
const rootDir = path.join(__dirname, `../../${src}`);
|
||||
|
||||
@@ -17,9 +17,40 @@ 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();
|
||||
|
||||
function getTypeScriptCompilerOptions(src: string): ts.CompilerOptions {
|
||||
|
||||
@@ -8,8 +8,11 @@ exports.createSwcClientStream = void 0;
|
||||
const child_process_1 = require("child_process");
|
||||
const stream_1 = require("stream");
|
||||
const path_1 = require("path");
|
||||
const util = require("util");
|
||||
const gulp = require("gulp");
|
||||
function createSwcClientStream() {
|
||||
const execAsync = util.promisify(child_process_1.exec);
|
||||
const cwd = (0, path_1.join)(__dirname, '../../../');
|
||||
const srcDir = (0, path_1.join)(__dirname, '../../../src');
|
||||
const outDir = (0, path_1.join)(__dirname, '../../../out');
|
||||
const pathConfigAmd = (0, path_1.join)(__dirname, '.swcrc-amd');
|
||||
@@ -19,19 +22,27 @@ function createSwcClientStream() {
|
||||
super({ objectMode: true, highWaterMark: Number.MAX_SAFE_INTEGER });
|
||||
this._isStarted = false;
|
||||
}
|
||||
exec() {
|
||||
async exec(print) {
|
||||
const t1 = Date.now();
|
||||
const errors = [];
|
||||
try {
|
||||
const out1 = (0, child_process_1.execSync)(`npx swc --config-file ${pathConfigAmd} ${srcDir}/ --out-dir ${outDir}`, { encoding: 'utf-8' });
|
||||
console.log(out1);
|
||||
const out2 = (0, child_process_1.execSync)(`npx swc --config-file ${pathConfigNoModule} ${srcDir}/vs/base/worker/workerMain.ts --out-dir ${outDir}`, { encoding: 'utf-8' });
|
||||
console.log(out2);
|
||||
const data1 = await execAsync(`npx swc --config-file ${pathConfigAmd} ${srcDir}/ --out-dir ${outDir}`, { encoding: 'utf-8', cwd });
|
||||
errors.push(data1.stderr);
|
||||
const data2 = await execAsync(`npx swc --config-file ${pathConfigNoModule} ${srcDir}/vs/base/worker/workerMain.ts --out-dir ${outDir}`, { encoding: 'utf-8', cwd });
|
||||
errors.push(data2.stderr);
|
||||
return true;
|
||||
}
|
||||
catch (error) {
|
||||
console.error();
|
||||
console.error(errors);
|
||||
console.error(error);
|
||||
this.destroy(error);
|
||||
return false;
|
||||
}
|
||||
finally {
|
||||
if (print) {
|
||||
console.log(`DONE with SWC after ${Date.now() - t1}ms`);
|
||||
}
|
||||
}
|
||||
}
|
||||
async _read(_size) {
|
||||
if (this._isStarted) {
|
||||
@@ -51,5 +62,5 @@ function createSwcClientStream() {
|
||||
}
|
||||
exports.createSwcClientStream = createSwcClientStream;
|
||||
if (process.argv[1] === __filename) {
|
||||
createSwcClientStream().exec();
|
||||
createSwcClientStream().exec(true);
|
||||
}
|
||||
|
||||
@@ -3,13 +3,17 @@
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { execSync } from 'child_process';
|
||||
import { exec } from 'child_process';
|
||||
import { Readable } from 'stream';
|
||||
import { join } from 'path';
|
||||
import * as util from 'util';
|
||||
import * as gulp from 'gulp';
|
||||
|
||||
export function createSwcClientStream() {
|
||||
export function createSwcClientStream(): Readable & { exec(print?: boolean): Promise<boolean> } {
|
||||
|
||||
const execAsync = util.promisify(exec);
|
||||
|
||||
const cwd = join(__dirname, '../../../');
|
||||
const srcDir = join(__dirname, '../../../src');
|
||||
const outDir = join(__dirname, '../../../out');
|
||||
|
||||
@@ -24,18 +28,25 @@ export function createSwcClientStream() {
|
||||
super({ objectMode: true, highWaterMark: Number.MAX_SAFE_INTEGER });
|
||||
}
|
||||
|
||||
exec() {
|
||||
async exec(print?: boolean) {
|
||||
const t1 = Date.now();
|
||||
const errors: string[] = [];
|
||||
try {
|
||||
const out1 = execSync(`npx swc --config-file ${pathConfigAmd} ${srcDir}/ --out-dir ${outDir}`, { encoding: 'utf-8' });
|
||||
console.log(out1);
|
||||
const data1 = await execAsync(`npx swc --config-file ${pathConfigAmd} ${srcDir}/ --out-dir ${outDir}`, { encoding: 'utf-8', cwd });
|
||||
errors.push(data1.stderr);
|
||||
|
||||
const out2 = execSync(`npx swc --config-file ${pathConfigNoModule} ${srcDir}/vs/base/worker/workerMain.ts --out-dir ${outDir}`, { encoding: 'utf-8' });
|
||||
console.log(out2);
|
||||
const data2 = await execAsync(`npx swc --config-file ${pathConfigNoModule} ${srcDir}/vs/base/worker/workerMain.ts --out-dir ${outDir}`, { encoding: 'utf-8', cwd });
|
||||
errors.push(data2.stderr);
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error();
|
||||
console.error(errors);
|
||||
console.error(error);
|
||||
this.destroy(error);
|
||||
return false;
|
||||
} finally {
|
||||
if (print) {
|
||||
console.log(`DONE with SWC after ${Date.now() - t1}ms`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,5 +68,5 @@ export function createSwcClientStream() {
|
||||
}
|
||||
|
||||
if (process.argv[1] === __filename) {
|
||||
createSwcClientStream().exec();
|
||||
createSwcClientStream().exec(true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user