diff --git a/build/gulpfile.extensions.ts b/build/gulpfile.extensions.ts index d77b2931d9b..a310fbbe548 100644 --- a/build/gulpfile.extensions.ts +++ b/build/gulpfile.extensions.ts @@ -166,7 +166,7 @@ const tasks = compilations.map(function (tsconfigFile) { const compileTask = task.define(`compile-extension:${name}`, task.series(cleanTask, async () => { const nonts = gulp.src(src, srcOpts).pipe(filter(['**', '!**/*.ts'], { dot: true })); const copyNonTs = util.streamToPromise(nonts.pipe(gulp.dest(out))); - const tsgo = spawnTsgo(absolutePath, () => rewriteTsgoSourceMappingUrlsIfNeeded(false, out, baseUrl)); + const tsgo = spawnTsgo(absolutePath, { reporterId: 'extensions' }, () => rewriteTsgoSourceMappingUrlsIfNeeded(false, out, baseUrl)); await Promise.all([copyNonTs, tsgo]); })); @@ -175,7 +175,7 @@ const tasks = compilations.map(function (tsconfigFile) { const nonts = gulp.src(src, srcOpts).pipe(filter(['**', '!**/*.ts'], { dot: true })); const watchInput = watcher(src, { ...srcOpts, ...{ readDelay: 200 } }); const watchNonTs = watchInput.pipe(filter(['**', '!**/*.ts'], { dot: true })).pipe(gulp.dest(out)); - const tsgoStream = watchInput.pipe(util.debounce(() => createTsgoStream(absolutePath, () => rewriteTsgoSourceMappingUrlsIfNeeded(false, out, baseUrl)), 200)); + const tsgoStream = watchInput.pipe(util.debounce(() => createTsgoStream(absolutePath, { reporterId: 'extensions' }, () => rewriteTsgoSourceMappingUrlsIfNeeded(false, out, baseUrl)), 200)); const watchStream = es.merge(nonts.pipe(gulp.dest(out)), watchNonTs, tsgoStream); return watchStream; diff --git a/build/lib/tsgo.ts b/build/lib/tsgo.ts index c6422deded4..3a245fe5cb6 100644 --- a/build/lib/tsgo.ts +++ b/build/lib/tsgo.ts @@ -12,8 +12,8 @@ const root = path.dirname(path.dirname(import.meta.dirname)); const npx = process.platform === 'win32' ? 'npx.cmd' : 'npx'; const ansiRegex = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g; -export function spawnTsgo(projectPath: string, onComplete?: () => Promise | void): Promise { - const reporter = createReporter('extensions'); +export function spawnTsgo(projectPath: string, config: { reporterId: string }, onComplete?: () => Promise | void): Promise { + const reporter = createReporter(config.reporterId); let report: NodeJS.ReadWriteStream | undefined; const beginReport = (emitError: boolean) => { @@ -31,10 +31,9 @@ export function spawnTsgo(projectPath: string, onComplete?: () => Promise report = undefined; }; - const args = ['tsgo', '--project', projectPath, '--pretty', 'false', '--sourceMap', '--inlineSources']; - beginReport(false); + const args = ['tsgo', '--project', projectPath, '--pretty', 'false', '--sourceMap', '--inlineSources']; const child = cp.spawn(npx, args, { cwd: root, stdio: ['ignore', 'pipe', 'pipe'], @@ -79,7 +78,7 @@ export function spawnTsgo(projectPath: string, onComplete?: () => Promise child.stdout?.on('data', handleData); child.stderr?.on('data', handleData); - const done = new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { child.on('exit', code => { if (buffer.trim()) { handleLine(buffer); @@ -88,23 +87,22 @@ export function spawnTsgo(projectPath: string, onComplete?: () => Promise endReport(); if (code === 0) { Promise.resolve(onComplete?.()).then(() => resolve(), reject); - return; + } else { + reject(new Error(`tsgo exited with code ${code ?? 'unknown'}`)); } - reject(new Error(`tsgo exited with code ${code ?? 'unknown'}`)); }); + child.on('error', err => { endReport(); reject(err); }); }); - - return done; } -export function createTsgoStream(projectPath: string, onComplete?: () => Promise | void): NodeJS.ReadWriteStream { +export function createTsgoStream(projectPath: string, config: { reporterId: string }, onComplete?: () => Promise | void): NodeJS.ReadWriteStream { const stream = es.through(); - spawnTsgo(projectPath, onComplete).then(() => { + spawnTsgo(projectPath, config, onComplete).then(() => { stream.emit('end'); }).catch(() => { // Errors are already reported by spawnTsgo via the reporter.