Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/build/lib/reporter.js
3520 views
1
"use strict";
2
var __importDefault = (this && this.__importDefault) || function (mod) {
3
return (mod && mod.__esModule) ? mod : { "default": mod };
4
};
5
Object.defineProperty(exports, "__esModule", { value: true });
6
exports.createReporter = createReporter;
7
/*---------------------------------------------------------------------------------------------
8
* Copyright (c) Microsoft Corporation. All rights reserved.
9
* Licensed under the MIT License. See License.txt in the project root for license information.
10
*--------------------------------------------------------------------------------------------*/
11
const event_stream_1 = __importDefault(require("event-stream"));
12
const fancy_log_1 = __importDefault(require("fancy-log"));
13
const ansi_colors_1 = __importDefault(require("ansi-colors"));
14
const fs_1 = __importDefault(require("fs"));
15
const path_1 = __importDefault(require("path"));
16
class ErrorLog {
17
id;
18
constructor(id) {
19
this.id = id;
20
}
21
allErrors = [];
22
startTime = null;
23
count = 0;
24
onStart() {
25
if (this.count++ > 0) {
26
return;
27
}
28
this.startTime = new Date().getTime();
29
(0, fancy_log_1.default)(`Starting ${ansi_colors_1.default.green('compilation')}${this.id ? ansi_colors_1.default.blue(` ${this.id}`) : ''}...`);
30
}
31
onEnd() {
32
if (--this.count > 0) {
33
return;
34
}
35
this.log();
36
}
37
log() {
38
const errors = this.allErrors.flat();
39
const seen = new Set();
40
errors.map(err => {
41
if (!seen.has(err)) {
42
seen.add(err);
43
(0, fancy_log_1.default)(`${ansi_colors_1.default.red('Error')}: ${err}`);
44
}
45
});
46
(0, fancy_log_1.default)(`Finished ${ansi_colors_1.default.green('compilation')}${this.id ? ansi_colors_1.default.blue(` ${this.id}`) : ''} with ${errors.length} errors after ${ansi_colors_1.default.magenta((new Date().getTime() - this.startTime) + ' ms')}`);
47
const regex = /^([^(]+)\((\d+),(\d+)\): (.*)$/s;
48
const messages = errors
49
.map(err => regex.exec(err))
50
.filter(match => !!match)
51
.map(x => x)
52
.map(([, path, line, column, message]) => ({ path, line: parseInt(line), column: parseInt(column), message }));
53
try {
54
const logFileName = 'log' + (this.id ? `_${this.id}` : '');
55
fs_1.default.writeFileSync(path_1.default.join(buildLogFolder, logFileName), JSON.stringify(messages));
56
}
57
catch (err) {
58
//noop
59
}
60
}
61
}
62
const errorLogsById = new Map();
63
function getErrorLog(id = '') {
64
let errorLog = errorLogsById.get(id);
65
if (!errorLog) {
66
errorLog = new ErrorLog(id);
67
errorLogsById.set(id, errorLog);
68
}
69
return errorLog;
70
}
71
const buildLogFolder = path_1.default.join(path_1.default.dirname(path_1.default.dirname(__dirname)), '.build');
72
try {
73
fs_1.default.mkdirSync(buildLogFolder);
74
}
75
catch (err) {
76
// ignore
77
}
78
function createReporter(id) {
79
const errorLog = getErrorLog(id);
80
const errors = [];
81
errorLog.allErrors.push(errors);
82
const result = (err) => errors.push(err);
83
result.hasErrors = () => errors.length > 0;
84
result.end = (emitError) => {
85
errors.length = 0;
86
errorLog.onStart();
87
return event_stream_1.default.through(undefined, function () {
88
errorLog.onEnd();
89
if (emitError && errors.length > 0) {
90
if (!errors.__logged__) {
91
errorLog.log();
92
}
93
errors.__logged__ = true;
94
const err = new Error(`Found ${errors.length} errors`);
95
err.__reporter__ = true;
96
this.emit('error', err);
97
}
98
else {
99
this.emit('end');
100
}
101
});
102
};
103
return result;
104
}
105
//# sourceMappingURL=reporter.js.map
106