提交 542a8275 编写于 作者: M Martin Aeschlimann

yarn watch: save errors in separate files, make error regex multiline aware

上级 1273299f
......@@ -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
......
......@@ -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);
......
......@@ -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<string>();
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<string>();
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<string, ErrorLog>();
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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册