fork-ts-checker-webpack-plugin 0.2.6 → 0.2.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/README.md +23 -3
- package/lib/CancellationToken.js +54 -64
- package/lib/FilesRegister.js +54 -64
- package/lib/FilesWatcher.js +58 -71
- package/lib/IncrementalChecker.js +172 -188
- package/lib/Message.js +2 -0
- package/lib/NormalizedMessage.js +162 -183
- package/lib/WorkResult.js +39 -44
- package/lib/WorkSet.js +21 -20
- package/lib/cluster.js +57 -78
- package/lib/formatter/codeframeFormatter.js +21 -37
- package/lib/formatter/defaultFormatter.js +15 -21
- package/lib/index.js +343 -414
- package/lib/service.js +34 -44
- package/package.json +17 -5
package/lib/NormalizedMessage.js
CHANGED
|
@@ -1,184 +1,163 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var NormalizedMessage = /** @class */ (function () {
|
|
3
|
+
function NormalizedMessage(data) {
|
|
4
|
+
this.type = data.type;
|
|
5
|
+
this.code = data.code;
|
|
6
|
+
this.severity = data.severity;
|
|
7
|
+
this.content = data.content;
|
|
8
|
+
this.file = data.file;
|
|
9
|
+
this.line = data.line;
|
|
10
|
+
this.character = data.character;
|
|
11
|
+
}
|
|
12
|
+
// message types
|
|
13
|
+
NormalizedMessage.createFromDiagnostic = function (diagnostic) {
|
|
14
|
+
var ts = require('typescript');
|
|
15
|
+
var file;
|
|
16
|
+
var line;
|
|
17
|
+
var character;
|
|
18
|
+
if (diagnostic.file) {
|
|
19
|
+
file = diagnostic.file.fileName;
|
|
20
|
+
var position = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
|
|
21
|
+
line = position.line + 1;
|
|
22
|
+
character = position.character + 1;
|
|
23
|
+
}
|
|
24
|
+
return new NormalizedMessage({
|
|
25
|
+
type: NormalizedMessage.TYPE_DIAGNOSTIC,
|
|
26
|
+
code: diagnostic.code,
|
|
27
|
+
severity: ts.DiagnosticCategory[diagnostic.category].toLowerCase(),
|
|
28
|
+
content: ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'),
|
|
29
|
+
file: file,
|
|
30
|
+
line: line,
|
|
31
|
+
character: character
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
NormalizedMessage.createFromLint = function (lint) {
|
|
35
|
+
var position = lint.getStartPosition().getLineAndCharacter();
|
|
36
|
+
return new NormalizedMessage({
|
|
37
|
+
type: NormalizedMessage.TYPE_LINT,
|
|
38
|
+
code: lint.getRuleName(),
|
|
39
|
+
severity: lint.getRuleSeverity(),
|
|
40
|
+
content: lint.getFailure(),
|
|
41
|
+
file: lint.getFileName(),
|
|
42
|
+
line: position.line + 1,
|
|
43
|
+
character: position.character + 1
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
NormalizedMessage.createFromJSON = function (json) {
|
|
47
|
+
return new NormalizedMessage(json);
|
|
48
|
+
};
|
|
49
|
+
NormalizedMessage.compare = function (messageA, messageB) {
|
|
50
|
+
if (!(messageA instanceof NormalizedMessage)) {
|
|
51
|
+
return -1;
|
|
52
|
+
}
|
|
53
|
+
if (!(messageB instanceof NormalizedMessage)) {
|
|
54
|
+
return 1;
|
|
55
|
+
}
|
|
56
|
+
return (NormalizedMessage.compareTypes(messageA.getType(), messageB.getType()) ||
|
|
57
|
+
NormalizedMessage.compareOptionalStrings(messageA.getFile(), messageB.getFile()) ||
|
|
58
|
+
NormalizedMessage.compareSeverities(messageA.getSeverity(), messageB.getSeverity()) ||
|
|
59
|
+
NormalizedMessage.compareNumbers(messageA.getLine(), messageB.getLine()) ||
|
|
60
|
+
NormalizedMessage.compareNumbers(messageA.getCharacter(), messageB.getCharacter()) ||
|
|
61
|
+
// code can be string (lint failure) or number (typescript error) - should the following line cater for this in some way?
|
|
62
|
+
NormalizedMessage.compareOptionalStrings(messageA.getCode(), messageB.getCode()) ||
|
|
63
|
+
NormalizedMessage.compareOptionalStrings(messageA.getContent(), messageB.getContent()) ||
|
|
64
|
+
0 /* EqualTo */);
|
|
65
|
+
};
|
|
66
|
+
NormalizedMessage.equals = function (messageA, messageB) {
|
|
67
|
+
return this.compare(messageA, messageB) === 0;
|
|
68
|
+
};
|
|
69
|
+
NormalizedMessage.deduplicate = function (messages) {
|
|
70
|
+
return messages
|
|
71
|
+
.sort(NormalizedMessage.compare)
|
|
72
|
+
.filter(function (message, index) {
|
|
73
|
+
return index === 0 || !NormalizedMessage.equals(message, messages[index - 1]);
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
NormalizedMessage.compareTypes = function (typeA, typeB) {
|
|
77
|
+
var priorities = [typeA, typeB].map(function (type) {
|
|
78
|
+
return [
|
|
79
|
+
NormalizedMessage.TYPE_LINT /* 0 */,
|
|
80
|
+
NormalizedMessage.TYPE_DIAGNOSTIC /* 1 */
|
|
81
|
+
].indexOf(type);
|
|
82
|
+
});
|
|
83
|
+
return priorities[0] - priorities[1];
|
|
84
|
+
};
|
|
85
|
+
NormalizedMessage.compareSeverities = function (severityA, severityB) {
|
|
86
|
+
var priorities = [severityA, severityB].map(function (type) {
|
|
87
|
+
return [
|
|
88
|
+
NormalizedMessage.SEVERITY_WARNING /* 0 */,
|
|
89
|
+
NormalizedMessage.SEVERITY_ERROR /* 1 */
|
|
90
|
+
].indexOf(type);
|
|
91
|
+
});
|
|
92
|
+
return priorities[0] - priorities[1];
|
|
93
|
+
};
|
|
94
|
+
NormalizedMessage.compareOptionalStrings = function (stringA, stringB) {
|
|
95
|
+
if (stringA === stringB) {
|
|
96
|
+
return 0;
|
|
97
|
+
}
|
|
98
|
+
if (stringA === undefined || stringA === null) {
|
|
99
|
+
return -1;
|
|
100
|
+
}
|
|
101
|
+
if (stringB === undefined || stringB === null) {
|
|
102
|
+
return 1;
|
|
103
|
+
}
|
|
104
|
+
return stringA.toString().localeCompare(stringB.toString());
|
|
105
|
+
};
|
|
106
|
+
NormalizedMessage.compareNumbers = function (numberA, numberB) {
|
|
107
|
+
return numberA - numberB;
|
|
108
|
+
};
|
|
109
|
+
NormalizedMessage.prototype.toJSON = function () {
|
|
110
|
+
return {
|
|
111
|
+
type: this.type,
|
|
112
|
+
code: this.code,
|
|
113
|
+
severity: this.severity,
|
|
114
|
+
content: this.content,
|
|
115
|
+
file: this.file,
|
|
116
|
+
line: this.line,
|
|
117
|
+
character: this.character
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
NormalizedMessage.prototype.getType = function () {
|
|
121
|
+
return this.type;
|
|
122
|
+
};
|
|
123
|
+
NormalizedMessage.prototype.isDiagnosticType = function () {
|
|
124
|
+
return NormalizedMessage.TYPE_DIAGNOSTIC === this.getType();
|
|
125
|
+
};
|
|
126
|
+
NormalizedMessage.prototype.isLintType = function () {
|
|
127
|
+
return NormalizedMessage.TYPE_LINT === this.getType();
|
|
128
|
+
};
|
|
129
|
+
NormalizedMessage.prototype.getCode = function () {
|
|
130
|
+
return this.code;
|
|
131
|
+
};
|
|
132
|
+
NormalizedMessage.prototype.getFormattedCode = function () {
|
|
133
|
+
return this.isDiagnosticType() ? 'TS' + this.getCode() : this.getCode();
|
|
134
|
+
};
|
|
135
|
+
NormalizedMessage.prototype.getSeverity = function () {
|
|
136
|
+
return this.severity;
|
|
137
|
+
};
|
|
138
|
+
NormalizedMessage.prototype.isErrorSeverity = function () {
|
|
139
|
+
return this.getSeverity() === NormalizedMessage.SEVERITY_ERROR;
|
|
140
|
+
};
|
|
141
|
+
NormalizedMessage.prototype.isWarningSeverity = function () {
|
|
142
|
+
return this.getSeverity() === NormalizedMessage.SEVERITY_WARNING;
|
|
143
|
+
};
|
|
144
|
+
NormalizedMessage.prototype.getContent = function () {
|
|
145
|
+
return this.content;
|
|
146
|
+
};
|
|
147
|
+
NormalizedMessage.prototype.getFile = function () {
|
|
148
|
+
return this.file;
|
|
149
|
+
};
|
|
150
|
+
NormalizedMessage.prototype.getLine = function () {
|
|
151
|
+
return this.line;
|
|
152
|
+
};
|
|
153
|
+
NormalizedMessage.prototype.getCharacter = function () {
|
|
154
|
+
return this.character;
|
|
155
|
+
};
|
|
156
|
+
NormalizedMessage.TYPE_DIAGNOSTIC = 'diagnostic';
|
|
157
|
+
NormalizedMessage.TYPE_LINT = 'lint';
|
|
158
|
+
// severity types
|
|
159
|
+
NormalizedMessage.SEVERITY_ERROR = 'error';
|
|
160
|
+
NormalizedMessage.SEVERITY_WARNING = 'warning';
|
|
161
|
+
return NormalizedMessage;
|
|
162
|
+
}());
|
|
11
163
|
module.exports = NormalizedMessage;
|
|
12
|
-
|
|
13
|
-
// message types
|
|
14
|
-
NormalizedMessage.TYPE_DIAGNOSTIC = 'diagnostic';
|
|
15
|
-
NormalizedMessage.TYPE_LINT = 'lint';
|
|
16
|
-
|
|
17
|
-
// severity types
|
|
18
|
-
NormalizedMessage.SEVERITY_ERROR = 'error';
|
|
19
|
-
NormalizedMessage.SEVERITY_WARNING = 'warning';
|
|
20
|
-
|
|
21
|
-
NormalizedMessage.createFromDiagnostic = function (diagnostic) {
|
|
22
|
-
var ts = require('typescript');
|
|
23
|
-
var position = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
|
|
24
|
-
|
|
25
|
-
return new NormalizedMessage({
|
|
26
|
-
type: NormalizedMessage.TYPE_DIAGNOSTIC,
|
|
27
|
-
code: diagnostic.code,
|
|
28
|
-
severity: ts.DiagnosticCategory[diagnostic.category].toLowerCase(),
|
|
29
|
-
content: ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'),
|
|
30
|
-
file: diagnostic.file.fileName,
|
|
31
|
-
line: position.line + 1,
|
|
32
|
-
character: position.character + 1
|
|
33
|
-
});
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
NormalizedMessage.createFromLint = function (lint) {
|
|
37
|
-
var position = lint.getStartPosition().getLineAndCharacter();
|
|
38
|
-
|
|
39
|
-
return new NormalizedMessage({
|
|
40
|
-
type: NormalizedMessage.TYPE_LINT,
|
|
41
|
-
code: lint.getRuleName(),
|
|
42
|
-
severity: lint.getRuleSeverity(),
|
|
43
|
-
content: lint.getFailure(),
|
|
44
|
-
file: lint.getFileName(),
|
|
45
|
-
line: position.line + 1,
|
|
46
|
-
character: position.character + 1
|
|
47
|
-
});
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
NormalizedMessage.createFromJSON = function (json) {
|
|
51
|
-
return new NormalizedMessage(json);
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
NormalizedMessage.compare = function (messageA, messageB) {
|
|
55
|
-
if (!(messageA instanceof NormalizedMessage)) {
|
|
56
|
-
return -1;
|
|
57
|
-
}
|
|
58
|
-
if (!(messageB instanceof NormalizedMessage)) {
|
|
59
|
-
return 1;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return (
|
|
63
|
-
NormalizedMessage.compareTypes(messageA.getType(), messageB.getType()) ||
|
|
64
|
-
NormalizedMessage.compareOptionalStrings(messageA.getFile(), messageB.getFile()) ||
|
|
65
|
-
NormalizedMessage.compareSeverities(messageA.getSeverity(), messageB.getSeverity()) ||
|
|
66
|
-
NormalizedMessage.compareNumbers(messageA.getLine(), messageB.getLine()) ||
|
|
67
|
-
NormalizedMessage.compareNumbers(messageA.getCharacter(), messageB.getCharacter()) ||
|
|
68
|
-
NormalizedMessage.compareOptionalStrings(messageA.getCode(), messageB.getCode()) ||
|
|
69
|
-
NormalizedMessage.compareOptionalStrings(messageA.getContent(), messageB.getContent()) ||
|
|
70
|
-
0 /* EqualTo */
|
|
71
|
-
);
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
NormalizedMessage.equals = function (messageA, messageB) {
|
|
75
|
-
return NormalizedMessage.compare(messageA, messageB) === 0;
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
NormalizedMessage.deduplicate = function (messages) {
|
|
79
|
-
return messages
|
|
80
|
-
.sort(NormalizedMessage.compare)
|
|
81
|
-
.filter(function (message, index) {
|
|
82
|
-
return index === 0 || !NormalizedMessage.equals(message, messages[index - 1]);
|
|
83
|
-
});
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
NormalizedMessage.compareTypes = function (typeA, typeB) {
|
|
87
|
-
var priorities = [typeA, typeB].map(function (type) {
|
|
88
|
-
return [
|
|
89
|
-
NormalizedMessage.TYPE_LINT /* 0 */,
|
|
90
|
-
NormalizedMessage.TYPE_DIAGNOSTIC /* 1 */
|
|
91
|
-
].indexOf(type);
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
return priorities[0] - priorities[1];
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
NormalizedMessage.compareSeverities = function (severityA, severityB) {
|
|
98
|
-
var priorities = [severityA, severityB].map(function (type) {
|
|
99
|
-
return [
|
|
100
|
-
NormalizedMessage.SEVERITY_WARNING /* 0 */,
|
|
101
|
-
NormalizedMessage.SEVERITY_ERROR /* 1 */
|
|
102
|
-
].indexOf(type);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
return priorities[0] - priorities[1];
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
NormalizedMessage.compareOptionalStrings = function (stringA, stringB) {
|
|
109
|
-
if (stringA === stringB) {
|
|
110
|
-
return 0;
|
|
111
|
-
}
|
|
112
|
-
if (stringA === undefined || stringA === null) {
|
|
113
|
-
return -1;
|
|
114
|
-
}
|
|
115
|
-
if (stringB === undefined || stringB === null) {
|
|
116
|
-
return 1;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
return stringA.toString().localeCompare(stringB.toString());
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
NormalizedMessage.compareNumbers = function (numberA, numberB) {
|
|
123
|
-
return numberA - numberB;
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
NormalizedMessage.prototype.toJSON = function () {
|
|
127
|
-
return {
|
|
128
|
-
type: this.type,
|
|
129
|
-
code: this.code,
|
|
130
|
-
severity: this.severity,
|
|
131
|
-
content: this.content,
|
|
132
|
-
file: this.file,
|
|
133
|
-
line: this.line,
|
|
134
|
-
character: this.character
|
|
135
|
-
};
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
NormalizedMessage.prototype.getType = function () {
|
|
139
|
-
return this.type;
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
NormalizedMessage.prototype.isDiagnosticType = function () {
|
|
143
|
-
return NormalizedMessage.TYPE_DIAGNOSTIC === this.getType();
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
NormalizedMessage.prototype.isLintType = function () {
|
|
147
|
-
return NormalizedMessage.TYPE_LINT === this.getType();
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
NormalizedMessage.prototype.getCode = function () {
|
|
151
|
-
return this.code;
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
NormalizedMessage.prototype.getFormattedCode = function () {
|
|
155
|
-
return this.isDiagnosticType() ? 'TS' + this.getCode() : this.getCode();
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
NormalizedMessage.prototype.getSeverity = function () {
|
|
159
|
-
return this.severity;
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
NormalizedMessage.prototype.isErrorSeverity = function () {
|
|
163
|
-
return this.getSeverity() === NormalizedMessage.SEVERITY_ERROR;
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
NormalizedMessage.prototype.isWarningSeverity = function () {
|
|
167
|
-
return this.getSeverity() === NormalizedMessage.SEVERITY_WARNING;
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
NormalizedMessage.prototype.getContent = function () {
|
|
171
|
-
return this.content;
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
NormalizedMessage.prototype.getFile = function () {
|
|
175
|
-
return this.file;
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
NormalizedMessage.prototype.getLine = function () {
|
|
179
|
-
return this.line;
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
NormalizedMessage.prototype.getCharacter = function () {
|
|
183
|
-
return this.character;
|
|
184
|
-
};
|
package/lib/WorkResult.js
CHANGED
|
@@ -1,45 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
var WorkResult = /** @class */ (function () {
|
|
3
|
+
function WorkResult(workDomain) {
|
|
4
|
+
this.workResult = {};
|
|
5
|
+
this.workDomain = workDomain;
|
|
6
|
+
}
|
|
7
|
+
WorkResult.prototype.supports = function (workName) {
|
|
8
|
+
return -1 !== this.workDomain.indexOf(workName);
|
|
9
|
+
};
|
|
10
|
+
WorkResult.prototype.set = function (workName, result) {
|
|
11
|
+
if (!this.supports(workName)) {
|
|
12
|
+
throw new Error('Cannot set result - work "' + workName + '" is not supported.');
|
|
13
|
+
}
|
|
14
|
+
this.workResult[workName] = result;
|
|
15
|
+
};
|
|
16
|
+
WorkResult.prototype.has = function (workName) {
|
|
17
|
+
return this.supports(workName) && undefined !== this.workResult[workName];
|
|
18
|
+
};
|
|
19
|
+
WorkResult.prototype.get = function (workName) {
|
|
20
|
+
if (!this.supports(workName)) {
|
|
21
|
+
throw new Error('Cannot get result - work "' + workName + '" is not supported.');
|
|
22
|
+
}
|
|
23
|
+
return this.workResult[workName];
|
|
24
|
+
};
|
|
25
|
+
WorkResult.prototype.hasAll = function () {
|
|
26
|
+
var _this = this;
|
|
27
|
+
return this.workDomain.every(function (key) { return _this.has(key); });
|
|
28
|
+
};
|
|
29
|
+
WorkResult.prototype.clear = function () {
|
|
30
|
+
this.workResult = {};
|
|
31
|
+
};
|
|
32
|
+
WorkResult.prototype.reduce = function (reducer, initial) {
|
|
33
|
+
var _this = this;
|
|
34
|
+
return this.workDomain.reduce(function (reduced, workName) {
|
|
35
|
+
return reducer(reduced, _this.workResult[workName]);
|
|
36
|
+
}, initial);
|
|
37
|
+
};
|
|
38
|
+
return WorkResult;
|
|
39
|
+
}());
|
|
5
40
|
module.exports = WorkResult;
|
|
6
|
-
|
|
7
|
-
WorkResult.prototype.supports = function (workName) {
|
|
8
|
-
return -1 !== this.workDomain.indexOf(workName);
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
WorkResult.prototype.set = function (workName, result) {
|
|
12
|
-
if (!this.supports(workName)) {
|
|
13
|
-
throw new Error('Cannot set result - work "' + workName + '" is not supported.');
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
this.workResult[workName] = result;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
WorkResult.prototype.has = function (workName) {
|
|
20
|
-
return this.supports(workName) && undefined !== this.workResult[workName];
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
WorkResult.prototype.get = function (workName) {
|
|
24
|
-
if (!this.supports(workName)) {
|
|
25
|
-
throw new Error('Cannot get result - work "' + workName + '" is not supported.');
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return this.workResult[workName];
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
WorkResult.prototype.hasAll = function () {
|
|
32
|
-
return this.workDomain.every(function (key) {
|
|
33
|
-
return this.has(key);
|
|
34
|
-
}.bind(this));
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
WorkResult.prototype.clear = function () {
|
|
38
|
-
this.workResult = {};
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
WorkResult.prototype.reduce = function (reducer, initial) {
|
|
42
|
-
return this.workDomain.reduce(function (reduced, workName) {
|
|
43
|
-
return reducer(reduced, this.workResult[workName]);
|
|
44
|
-
}.bind(this), initial);
|
|
45
|
-
};
|
package/lib/WorkSet.js
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
var WorkSet = /** @class */ (function () {
|
|
3
|
+
function WorkSet(workDomain, workNumber, workDivision) {
|
|
4
|
+
this.workDomain = workDomain;
|
|
5
|
+
this.workNumber = workNumber;
|
|
6
|
+
this.workDivision = workDivision;
|
|
7
|
+
this.workSize = Math.floor(this.workDomain.length / this.workDivision);
|
|
8
|
+
this.workBegin = this.workNumber * this.workSize;
|
|
9
|
+
this.workEnd = this.workBegin + this.workSize;
|
|
10
|
+
// be sure that we will process all work for odd workSize.
|
|
11
|
+
if (this.workNumber === this.workDivision - 1) {
|
|
12
|
+
this.workEnd = this.workDomain.length;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
WorkSet.prototype.forEach = function (callback) {
|
|
16
|
+
for (var i = this.workBegin; i < this.workEnd; ++i) {
|
|
17
|
+
callback(this.workDomain[i], i);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
return WorkSet;
|
|
21
|
+
}());
|
|
15
22
|
module.exports = WorkSet;
|
|
16
|
-
|
|
17
|
-
WorkSet.prototype.forEach = function (callback) {
|
|
18
|
-
for (var i = this.workBegin; i < this.workEnd; ++i) {
|
|
19
|
-
callback(this.workDomain[i], i);
|
|
20
|
-
}
|
|
21
|
-
};
|
package/lib/cluster.js
CHANGED
|
@@ -1,93 +1,72 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var childProcess = require("child_process");
|
|
4
|
+
var path = require("path");
|
|
5
|
+
var process = require("process");
|
|
6
|
+
var WorkResult = require("./WorkResult");
|
|
7
|
+
var NormalizedMessage = require("./NormalizedMessage");
|
|
8
8
|
// fork workers...
|
|
9
|
-
var division = parseInt(process.env.WORK_DIVISION);
|
|
9
|
+
var division = parseInt(process.env.WORK_DIVISION, 10);
|
|
10
10
|
var workers = [];
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
workers.push(
|
|
14
|
-
childProcess.fork(
|
|
15
|
-
path.resolve(__dirname, './service.js'),
|
|
16
|
-
[],
|
|
17
|
-
{
|
|
11
|
+
for (var num = 0; num < division; num++) {
|
|
12
|
+
workers.push(childProcess.fork(path.resolve(__dirname, './service.js'), [], {
|
|
18
13
|
execArgv: ['--max-old-space-size=' + process.env.MEMORY_LIMIT],
|
|
19
|
-
env: Object.assign({}, process.env, { WORK_NUMBER:
|
|
14
|
+
env: Object.assign({}, process.env, { WORK_NUMBER: num }),
|
|
20
15
|
stdio: ['inherit', 'inherit', 'inherit', 'ipc']
|
|
21
|
-
|
|
22
|
-
)
|
|
23
|
-
);
|
|
16
|
+
}));
|
|
24
17
|
}
|
|
25
|
-
|
|
26
18
|
var pids = workers.map(function (worker) { return worker.pid; });
|
|
27
19
|
var result = new WorkResult(pids);
|
|
28
|
-
|
|
29
20
|
process.on('message', function (message) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
21
|
+
// broadcast message to all workers
|
|
22
|
+
workers.forEach(function (worker) {
|
|
23
|
+
try {
|
|
24
|
+
worker.send(message);
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
// channel closed - something went wrong - close cluster...
|
|
28
|
+
process.exit();
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
// clear previous result set
|
|
32
|
+
result.clear();
|
|
42
33
|
});
|
|
43
|
-
|
|
44
34
|
// listen to all workers
|
|
45
35
|
workers.forEach(function (worker) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
merged.lints = NormalizedMessage.deduplicate(merged.lints);
|
|
70
|
-
|
|
71
|
-
try {
|
|
72
|
-
process.send(merged);
|
|
73
|
-
} catch (e) {
|
|
74
|
-
// channel closed...
|
|
75
|
-
process.exit();
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
});
|
|
36
|
+
worker.on('message', function (message) {
|
|
37
|
+
// set result from worker
|
|
38
|
+
result.set(worker.pid, {
|
|
39
|
+
diagnostics: message.diagnostics.map(NormalizedMessage.createFromJSON),
|
|
40
|
+
lints: message.lints.map(NormalizedMessage.createFromJSON)
|
|
41
|
+
});
|
|
42
|
+
// if we have result from all workers, send merged
|
|
43
|
+
if (result.hasAll()) {
|
|
44
|
+
var merged = result.reduce(function (innerMerged, innerResult) { return ({
|
|
45
|
+
diagnostics: innerMerged.diagnostics.concat(innerResult.diagnostics),
|
|
46
|
+
lints: innerMerged.lints.concat(innerResult.lints)
|
|
47
|
+
}); }, { diagnostics: [], lints: [] });
|
|
48
|
+
merged.diagnostics = NormalizedMessage.deduplicate(merged.diagnostics);
|
|
49
|
+
merged.lints = NormalizedMessage.deduplicate(merged.lints);
|
|
50
|
+
try {
|
|
51
|
+
process.send(merged);
|
|
52
|
+
}
|
|
53
|
+
catch (e) {
|
|
54
|
+
// channel closed...
|
|
55
|
+
process.exit();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
});
|
|
79
59
|
});
|
|
80
|
-
|
|
81
60
|
process.on('SIGINT', function () {
|
|
82
|
-
|
|
61
|
+
process.exit();
|
|
83
62
|
});
|
|
84
|
-
|
|
85
63
|
process.on('exit', function () {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
});
|
|
64
|
+
workers.forEach(function (worker) {
|
|
65
|
+
try {
|
|
66
|
+
worker.kill();
|
|
67
|
+
}
|
|
68
|
+
catch (e) {
|
|
69
|
+
// do nothing...
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
});
|
|
@@ -1,39 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Create new code frame formatter.
|
|
8
|
-
*
|
|
9
|
-
* @param options Options for babel-code-frame - see https://www.npmjs.com/package/babel-code-frame
|
|
10
|
-
* @returns {codeframeFormatter}
|
|
11
|
-
*/
|
|
1
|
+
"use strict";
|
|
2
|
+
var os = require("os");
|
|
3
|
+
var codeFrame = require("babel-code-frame");
|
|
4
|
+
var chalk = require("chalk");
|
|
5
|
+
var fs = require("fs");
|
|
12
6
|
module.exports = function createCodeframeFormatter(options) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
message.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
.map(function (str) { return ' ' + str; })
|
|
30
|
-
.join(os.EOL);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return (
|
|
34
|
-
messageColor(message.getSeverity().toUpperCase() + ' at ' + message.getFile()) + os.EOL +
|
|
35
|
-
positionColor(message.getLine() + ':' + message.getCharacter()) + ' ' + message.getContent() +
|
|
36
|
-
(frame ? os.EOL + frame : '')
|
|
37
|
-
);
|
|
38
|
-
};
|
|
7
|
+
return function codeframeFormatter(message, useColors) {
|
|
8
|
+
var colors = new chalk.constructor({ enabled: useColors });
|
|
9
|
+
var messageColor = message.isWarningSeverity() ? colors.bold.yellow : colors.bold.red;
|
|
10
|
+
var positionColor = colors.dim;
|
|
11
|
+
var source = message.getFile() && fs.existsSync(message.getFile()) && fs.readFileSync(message.getFile(), 'utf-8');
|
|
12
|
+
var frame = '';
|
|
13
|
+
if (source) {
|
|
14
|
+
frame = codeFrame(source, message.line, message.character, Object.assign({}, options || {}, { highlightCode: useColors }))
|
|
15
|
+
.split('\n')
|
|
16
|
+
.map(function (str) { return ' ' + str; })
|
|
17
|
+
.join(os.EOL);
|
|
18
|
+
}
|
|
19
|
+
return (messageColor(message.getSeverity().toUpperCase() + ' in ' + message.getFile()) + os.EOL +
|
|
20
|
+
positionColor(message.getLine() + ':' + message.getCharacter()) + ' ' + message.getContent() +
|
|
21
|
+
(frame ? os.EOL + frame : ''));
|
|
22
|
+
};
|
|
39
23
|
};
|