diff --git a/build/gulpfile.editor.js b/build/gulpfile.editor.js index aa0282bff5755..118fe6e81135c 100644 --- a/build/gulpfile.editor.js +++ b/build/gulpfile.editor.js @@ -434,7 +434,7 @@ function createTscCompileTask(watch) { // stdio: [null, 'pipe', 'inherit'] }); let errors = []; - let reporter = createReporter(); + let reporter = createReporter('monaco'); let report; // eslint-disable-next-line no-control-regex let magic = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g; // https://stackoverflow.com/questions/25245716/remove-all-ansi-colors-styles-from-strings diff --git a/build/gulpfile.extensions.js b/build/gulpfile.extensions.js index 6ae72e4cf0631..c204e84fd8cfe 100644 --- a/build/gulpfile.extensions.js +++ b/build/gulpfile.extensions.js @@ -64,7 +64,7 @@ const tasks = compilations.map(function (tsconfigFile) { } function createPipeline(build, emitError) { - const reporter = createReporter(); + const reporter = createReporter('extensions'); overrideOptions.inlineSources = Boolean(build); overrideOptions.base = path.dirname(absolutePath); diff --git a/build/lib/reporter.ts b/build/lib/reporter.ts index ec90881751819..f875fce908a21 100644 --- a/build/lib/reporter.ts +++ b/build/lib/reporter.ts @@ -12,61 +12,76 @@ import * as ansiColors from 'ansi-colors'; import * as fs from 'fs'; import * as path from 'path'; -const allErrors: string[][] = []; -let startTime: number | null = null; -let count = 0; +class ErrorLog { + constructor(public id: string) { + } + allErrors: string[][] = []; + startTime: number | null = null; + count = 0; + + onStart(): void { + if (this.count++ > 0) { + return; + } -function onStart(): void { - if (count++ > 0) { - return; + this.startTime = new Date().getTime(); + fancyLog(`Starting ${ansiColors.green('compilation')}${this.id ? ansiColors.blue(` ${this.id}`) : ''}...`); } - startTime = new Date().getTime(); - fancyLog(`Starting ${ansiColors.green('compilation')}...`); -} + onEnd(): void { + if (--this.count > 0) { + return; + } -function onEnd(): void { - if (--count > 0) { - return; + this.log(); } - log(); -} + log(): void { + const errors = _.flatten(this.allErrors); + const seen = new Set(); -const buildLogPath = path.join(path.dirname(path.dirname(__dirname)), '.build', 'log'); + errors.map(err => { + if (!seen.has(err)) { + seen.add(err); + fancyLog(`${ansiColors.red('Error')}: ${err}`); + } + }); -try { - fs.mkdirSync(path.dirname(buildLogPath)); -} catch (err) { - // ignore -} + fancyLog(`Finished ${ansiColors.green('compilation')}${this.id ? ansiColors.blue(` ${this.id}`) : ''} with ${errors.length} errors after ${ansiColors.magenta((new Date().getTime() - this.startTime!) + ' ms')}`); -function log(): void { - const errors = _.flatten(allErrors); - const seen = new Set(); + const regex = /^([^(]+)\((\d+),(\d+)\): (.*)$/s; + const messages = errors + .map(err => regex.exec(err)) + .filter(match => !!match) + .map(x => x as string[]) + .map(([, path, line, column, message]) => ({ path, line: parseInt(line), column: parseInt(column), message })); - errors.map(err => { - if (!seen.has(err)) { - seen.add(err); - fancyLog(`${ansiColors.red('Error')}: ${err}`); + try { + const logFileName = 'log' + (this.id ? `_${this.id}` : ''); + fs.writeFileSync(path.join(buildLogFolder, logFileName), JSON.stringify(messages)); + } catch (err) { + //noop } - }); - - const regex = /^([^(]+)\((\d+),(\d+)\): (.*)$/; - const messages = errors - .map(err => regex.exec(err)) - .filter(match => !!match) - .map(x => x as string[]) - .map(([, path, line, column, message]) => ({ path, line: parseInt(line), column: parseInt(column), message })); + } - try { +} - fs.writeFileSync(buildLogPath, JSON.stringify(messages)); - } catch (err) { - //noop +const errorLogsById = new Map(); +function getErrorLog(id: string = '') { + let errorLog = errorLogsById.get(id); + if (!errorLog) { + errorLog = new ErrorLog(id); + errorLogsById.set(id, errorLog); } + return errorLog; +} - fancyLog(`Finished ${ansiColors.green('compilation')} with ${errors.length} errors after ${ansiColors.magenta((new Date().getTime() - startTime!) + ' ms')}`); +const buildLogFolder = path.join(path.dirname(path.dirname(__dirname)), '.build'); + +try { + fs.mkdirSync(buildLogFolder); +} catch (err) { + // ignore } export interface IReporter { @@ -75,9 +90,11 @@ export interface IReporter { end(emitError: boolean): NodeJS.ReadWriteStream; } -export function createReporter(): IReporter { +export function createReporter(id?: string): IReporter { + const errorLog = getErrorLog(id); + const errors: string[] = []; - allErrors.push(errors); + errorLog.allErrors.push(errors); const result = (err: string) => errors.push(err); @@ -85,14 +102,14 @@ export function createReporter(): IReporter { result.end = (emitError: boolean): NodeJS.ReadWriteStream => { errors.length = 0; - onStart(); + errorLog.onStart(); return es.through(undefined, function () { - onEnd(); + errorLog.onEnd(); if (emitError && errors.length > 0) { if (!(errors as any).__logged__) { - log(); + errorLog.log(); } (errors as any).__logged__ = true;