fork-ts-checker-webpack-plugin 0.4.10 → 0.4.11
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 +4 -0
- package/lib/CancellationToken.js +2 -1
- package/lib/FilesWatcher.js +2 -1
- package/lib/IncrementalChecker.js +27 -11
- package/lib/NormalizedMessage.js +2 -4
- package/lib/VueProgram.js +26 -15
- package/lib/formatter/codeframeFormatter.js +11 -5
- package/lib/formatter/defaultFormatter.js +3 -2
- package/lib/index.js +113 -55
- package/lib/types/index.d.ts +2 -1
- package/package.json +32 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
## v0.4.11
|
|
2
|
+
|
|
3
|
+
* [Fix os.cpus is not a function](https://github.com/Realytics/fork-ts-checker-webpack-plugin/pull/172) (#172)
|
|
4
|
+
|
|
1
5
|
## v0.4.10
|
|
2
6
|
|
|
3
7
|
* [Allow fork-ts-checker-webpack-plugin to be imported in .ts files using ESM import syntax](https://github.com/Realytics/fork-ts-checker-webpack-plugin/pull/163) (#163)
|
package/lib/CancellationToken.js
CHANGED
|
@@ -8,7 +8,8 @@ var ts = require("typescript");
|
|
|
8
8
|
var CancellationToken = /** @class */ (function () {
|
|
9
9
|
function CancellationToken(cancellationFileName, isCancelled) {
|
|
10
10
|
this.isCancelled = !!isCancelled;
|
|
11
|
-
this.cancellationFileName =
|
|
11
|
+
this.cancellationFileName =
|
|
12
|
+
cancellationFileName || crypto.randomBytes(64).toString('hex');
|
|
12
13
|
this.lastCancellationCheckTime = 0;
|
|
13
14
|
}
|
|
14
15
|
CancellationToken.createFromJSON = function (json) {
|
package/lib/FilesWatcher.js
CHANGED
|
@@ -19,7 +19,8 @@ var FilesWatcher = /** @class */ (function () {
|
|
|
19
19
|
throw new Error('Cannot watch again - already watching.');
|
|
20
20
|
}
|
|
21
21
|
this.watchers = this.watchPaths.map(function (watchPath) {
|
|
22
|
-
return chokidar
|
|
22
|
+
return chokidar
|
|
23
|
+
.watch(watchPath, { persistent: true, alwaysStat: true })
|
|
23
24
|
.on('change', function (filePath, stats) {
|
|
24
25
|
if (_this.isFileSupported(filePath)) {
|
|
25
26
|
(_this.listeners['change'] || []).forEach(function (changeListener) {
|
|
@@ -33,7 +33,9 @@ var IncrementalChecker = /** @class */ (function () {
|
|
|
33
33
|
IncrementalChecker.loadProgramConfig = function (configFile) {
|
|
34
34
|
return ts.parseJsonConfigFileContent(
|
|
35
35
|
// Regardless of the setting in the tsconfig.json we want isolatedModules to be false
|
|
36
|
-
Object.assign(ts.readConfigFile(configFile, ts.sys.readFile).config, {
|
|
36
|
+
Object.assign(ts.readConfigFile(configFile, ts.sys.readFile).config, {
|
|
37
|
+
isolatedModules: false
|
|
38
|
+
}), ts.sys, path.dirname(configFile));
|
|
37
39
|
};
|
|
38
40
|
IncrementalChecker.loadLinterConfig = function (configFile) {
|
|
39
41
|
var tslint = require('tslint');
|
|
@@ -70,12 +72,15 @@ var IncrementalChecker = /** @class */ (function () {
|
|
|
70
72
|
return new tslint.Linter({ fix: false }, program);
|
|
71
73
|
};
|
|
72
74
|
IncrementalChecker.isFileExcluded = function (filePath, linterExclusions) {
|
|
73
|
-
return endsWith(filePath, '.d.ts') ||
|
|
75
|
+
return (endsWith(filePath, '.d.ts') ||
|
|
76
|
+
linterExclusions.some(function (matcher) { return matcher.match(filePath); }));
|
|
74
77
|
};
|
|
75
78
|
IncrementalChecker.prototype.nextIteration = function () {
|
|
76
79
|
var _this = this;
|
|
77
80
|
if (!this.watcher) {
|
|
78
|
-
var watchExtensions = this.vue
|
|
81
|
+
var watchExtensions = this.vue
|
|
82
|
+
? ['.ts', '.tsx', '.vue']
|
|
83
|
+
: ['.ts', '.tsx'];
|
|
79
84
|
this.watcher = new FilesWatcher_1.FilesWatcher(this.watchPaths, watchExtensions);
|
|
80
85
|
// connect watcher with register
|
|
81
86
|
this.watcher.on('change', function (filePath, stats) {
|
|
@@ -88,7 +93,8 @@ var IncrementalChecker = /** @class */ (function () {
|
|
|
88
93
|
}
|
|
89
94
|
if (!this.linterConfig && this.linterConfigFile) {
|
|
90
95
|
this.linterConfig = IncrementalChecker.loadLinterConfig(this.linterConfigFile);
|
|
91
|
-
if (this.linterConfig.linterOptions &&
|
|
96
|
+
if (this.linterConfig.linterOptions &&
|
|
97
|
+
this.linterConfig.linterOptions.exclude) {
|
|
92
98
|
// Pre-build minimatch patterns to avoid additional overhead later on.
|
|
93
99
|
// Note: Resolving the path is required to properly match against the full file paths,
|
|
94
100
|
// and also deals with potential cross-platform problems regarding path separators.
|
|
@@ -101,11 +107,15 @@ var IncrementalChecker = /** @class */ (function () {
|
|
|
101
107
|
}
|
|
102
108
|
};
|
|
103
109
|
IncrementalChecker.prototype.loadVueProgram = function () {
|
|
104
|
-
this.programConfig =
|
|
110
|
+
this.programConfig =
|
|
111
|
+
this.programConfig ||
|
|
112
|
+
VueProgram_1.VueProgram.loadProgramConfig(this.programConfigFile);
|
|
105
113
|
return VueProgram_1.VueProgram.createProgram(this.programConfig, path.dirname(this.programConfigFile), this.files, this.watcher, this.program);
|
|
106
114
|
};
|
|
107
115
|
IncrementalChecker.prototype.loadDefaultProgram = function () {
|
|
108
|
-
this.programConfig =
|
|
116
|
+
this.programConfig =
|
|
117
|
+
this.programConfig ||
|
|
118
|
+
IncrementalChecker.loadProgramConfig(this.programConfigFile);
|
|
109
119
|
return IncrementalChecker.createProgram(this.programConfig, this.files, this.watcher, this.program);
|
|
110
120
|
};
|
|
111
121
|
IncrementalChecker.prototype.hasLinter = function () {
|
|
@@ -123,7 +133,8 @@ var IncrementalChecker = /** @class */ (function () {
|
|
|
123
133
|
if (cancellationToken) {
|
|
124
134
|
cancellationToken.throwIfCancellationRequested();
|
|
125
135
|
}
|
|
126
|
-
var diagnosticsToRegister = _this
|
|
136
|
+
var diagnosticsToRegister = _this
|
|
137
|
+
.checkSyntacticErrors
|
|
127
138
|
? []
|
|
128
139
|
.concat(_this.program.getSemanticDiagnostics(sourceFile, cancellationToken))
|
|
129
140
|
.concat(_this.program.getSyntacticDiagnostics(sourceFile, cancellationToken))
|
|
@@ -139,8 +150,11 @@ var IncrementalChecker = /** @class */ (function () {
|
|
|
139
150
|
throw new Error('Cannot get lints - checker has no linter.');
|
|
140
151
|
}
|
|
141
152
|
// select files to lint
|
|
142
|
-
var filesToLint = this.files
|
|
143
|
-
|
|
153
|
+
var filesToLint = this.files
|
|
154
|
+
.keys()
|
|
155
|
+
.filter(function (filePath) {
|
|
156
|
+
return !_this.files.getData(filePath).linted &&
|
|
157
|
+
!IncrementalChecker.isFileExcluded(filePath, _this.linterExclusions);
|
|
144
158
|
});
|
|
145
159
|
// calculate subset of work to do
|
|
146
160
|
var workSet = new WorkSet_1.WorkSet(filesToLint, this.workNumber, this.workDivision);
|
|
@@ -155,7 +169,7 @@ var IncrementalChecker = /** @class */ (function () {
|
|
|
155
169
|
// check the error type due to file system lag
|
|
156
170
|
!(e instanceof Error) &&
|
|
157
171
|
!(e.constructor.name === 'FatalError') &&
|
|
158
|
-
!(e.message && e.message.trim().startsWith(
|
|
172
|
+
!(e.message && e.message.trim().startsWith('Invalid source file'))) {
|
|
159
173
|
// it's not because file doesn't exist - throw error
|
|
160
174
|
throw e;
|
|
161
175
|
}
|
|
@@ -176,7 +190,9 @@ var IncrementalChecker = /** @class */ (function () {
|
|
|
176
190
|
});
|
|
177
191
|
});
|
|
178
192
|
// get all lints
|
|
179
|
-
var lints = this.files
|
|
193
|
+
var lints = this.files
|
|
194
|
+
.keys()
|
|
195
|
+
.reduce(function (innerLints, filePath) {
|
|
180
196
|
return innerLints.concat(_this.files.getData(filePath).lints);
|
|
181
197
|
}, []);
|
|
182
198
|
// normalize and deduplicate lints
|
package/lib/NormalizedMessage.js
CHANGED
|
@@ -68,10 +68,8 @@ var NormalizedMessage = /** @class */ (function () {
|
|
|
68
68
|
return this.compare(messageA, messageB) === 0;
|
|
69
69
|
};
|
|
70
70
|
NormalizedMessage.deduplicate = function (messages) {
|
|
71
|
-
return messages
|
|
72
|
-
|
|
73
|
-
.filter(function (message, index) {
|
|
74
|
-
return index === 0 || !NormalizedMessage.equals(message, messages[index - 1]);
|
|
71
|
+
return messages.sort(NormalizedMessage.compare).filter(function (message, index) {
|
|
72
|
+
return (index === 0 || !NormalizedMessage.equals(message, messages[index - 1]));
|
|
75
73
|
});
|
|
76
74
|
};
|
|
77
75
|
NormalizedMessage.compareTypes = function (typeA, typeB) {
|
package/lib/VueProgram.js
CHANGED
|
@@ -18,7 +18,9 @@ var VueProgram = /** @class */ (function () {
|
|
|
18
18
|
};
|
|
19
19
|
var parsed = ts.parseJsonConfigFileContent(
|
|
20
20
|
// Regardless of the setting in the tsconfig.json we want isolatedModules to be false
|
|
21
|
-
Object.assign(ts.readConfigFile(configFile, ts.sys.readFile).config, {
|
|
21
|
+
Object.assign(ts.readConfigFile(configFile, ts.sys.readFile).config, {
|
|
22
|
+
isolatedModules: false
|
|
23
|
+
}), parseConfigHost, path.dirname(configFile));
|
|
22
24
|
parsed.options.allowNonTsExtensions = true;
|
|
23
25
|
return parsed;
|
|
24
26
|
};
|
|
@@ -35,7 +37,8 @@ var VueProgram = /** @class */ (function () {
|
|
|
35
37
|
if (options.paths) {
|
|
36
38
|
Object.keys(options.paths).forEach(function (key) {
|
|
37
39
|
var pathSymbol = key[0];
|
|
38
|
-
if (discardedSymbols.indexOf(pathSymbol) < 0 &&
|
|
40
|
+
if (discardedSymbols.indexOf(pathSymbol) < 0 &&
|
|
41
|
+
wildcards.indexOf(pathSymbol) < 0) {
|
|
39
42
|
wildcards.push(pathSymbol);
|
|
40
43
|
}
|
|
41
44
|
});
|
|
@@ -51,8 +54,12 @@ var VueProgram = /** @class */ (function () {
|
|
|
51
54
|
}
|
|
52
55
|
});
|
|
53
56
|
if (correctWildcard) {
|
|
54
|
-
var pattern = options.paths
|
|
55
|
-
|
|
57
|
+
var pattern = options.paths
|
|
58
|
+
? options.paths[correctWildcard + "/*"]
|
|
59
|
+
: undefined;
|
|
60
|
+
var substitution = pattern
|
|
61
|
+
? options.paths[correctWildcard + "/*"][0].replace('*', '')
|
|
62
|
+
: 'src';
|
|
56
63
|
moduleName = path.resolve(baseUrl, substitution, moduleName.substr(2));
|
|
57
64
|
}
|
|
58
65
|
else if (isRelative) {
|
|
@@ -102,7 +109,8 @@ var VueProgram = /** @class */ (function () {
|
|
|
102
109
|
var resolvedModule = ts.resolveModuleName(moduleName, containingFile, programConfig.options, {
|
|
103
110
|
fileExists: function (fileName) {
|
|
104
111
|
if (fileName.endsWith('.vue.ts')) {
|
|
105
|
-
return host.fileExists(fileName.slice(0, -3)) ||
|
|
112
|
+
return (host.fileExists(fileName.slice(0, -3)) ||
|
|
113
|
+
host.fileExists(fileName));
|
|
106
114
|
}
|
|
107
115
|
else {
|
|
108
116
|
return host.fileExists(fileName);
|
|
@@ -119,7 +127,8 @@ var VueProgram = /** @class */ (function () {
|
|
|
119
127
|
}
|
|
120
128
|
}).resolvedModule;
|
|
121
129
|
if (resolvedModule) {
|
|
122
|
-
if (resolvedModule.resolvedFileName.endsWith('.vue.ts') &&
|
|
130
|
+
if (resolvedModule.resolvedFileName.endsWith('.vue.ts') &&
|
|
131
|
+
!host.fileExists(resolvedModule.resolvedFileName)) {
|
|
123
132
|
resolvedModule.resolvedFileName = resolvedModule.resolvedFileName.slice(0, -3);
|
|
124
133
|
}
|
|
125
134
|
resolvedModules.push(resolvedModule);
|
|
@@ -136,7 +145,9 @@ var VueProgram = /** @class */ (function () {
|
|
|
136
145
|
else {
|
|
137
146
|
resolvedModules.push({
|
|
138
147
|
// If the file does exist, return an empty string (because we assume user has provided a ".d.ts" file for it).
|
|
139
|
-
resolvedFileName: host.fileExists(absolutePath)
|
|
148
|
+
resolvedFileName: host.fileExists(absolutePath)
|
|
149
|
+
? ''
|
|
150
|
+
: absolutePath,
|
|
140
151
|
extension: '.ts'
|
|
141
152
|
});
|
|
142
153
|
}
|
|
@@ -148,13 +159,13 @@ var VueProgram = /** @class */ (function () {
|
|
|
148
159
|
);
|
|
149
160
|
};
|
|
150
161
|
VueProgram.getScriptKindByLang = function (lang) {
|
|
151
|
-
if (lang ===
|
|
162
|
+
if (lang === 'ts') {
|
|
152
163
|
return ts.ScriptKind.TS;
|
|
153
164
|
}
|
|
154
|
-
else if (lang ===
|
|
165
|
+
else if (lang === 'tsx') {
|
|
155
166
|
return ts.ScriptKind.TSX;
|
|
156
167
|
}
|
|
157
|
-
else if (lang ===
|
|
168
|
+
else if (lang === 'jsx') {
|
|
158
169
|
return ts.ScriptKind.JSX;
|
|
159
170
|
}
|
|
160
171
|
else {
|
|
@@ -195,11 +206,11 @@ var VueProgram = /** @class */ (function () {
|
|
|
195
206
|
// For now, ignore the error when the src file is not found
|
|
196
207
|
// since it will produce incorrect code location.
|
|
197
208
|
// It's not a large problem since it's handled on webpack side.
|
|
198
|
-
content: '/* tslint:disable */\n'
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
209
|
+
content: '/* tslint:disable */\n' +
|
|
210
|
+
'// @ts-ignore\n' +
|
|
211
|
+
("export { default } from '" + src + "';\n") +
|
|
212
|
+
'// @ts-ignore\n' +
|
|
213
|
+
("export * from '" + src + "';\n")
|
|
203
214
|
};
|
|
204
215
|
}
|
|
205
216
|
// Pad blank lines to retain diagnostics location
|
|
@@ -13,9 +13,13 @@ var fs = require("fs");
|
|
|
13
13
|
function createCodeframeFormatter(options) {
|
|
14
14
|
return function codeframeFormatter(message, useColors) {
|
|
15
15
|
var colors = new chalk_1.default.constructor({ enabled: useColors });
|
|
16
|
-
var messageColor = message.isWarningSeverity()
|
|
16
|
+
var messageColor = message.isWarningSeverity()
|
|
17
|
+
? colors.bold.yellow
|
|
18
|
+
: colors.bold.red;
|
|
17
19
|
var positionColor = colors.dim;
|
|
18
|
-
var source = message.getFile() &&
|
|
20
|
+
var source = message.getFile() &&
|
|
21
|
+
fs.existsSync(message.getFile()) &&
|
|
22
|
+
fs.readFileSync(message.getFile(), 'utf-8');
|
|
19
23
|
var frame = '';
|
|
20
24
|
if (source) {
|
|
21
25
|
frame = codeFrame(source, message.line, message.character, Object.assign({}, options || {}, { highlightCode: useColors }))
|
|
@@ -23,10 +27,12 @@ function createCodeframeFormatter(options) {
|
|
|
23
27
|
.map(function (str) { return ' ' + str; })
|
|
24
28
|
.join(os.EOL);
|
|
25
29
|
}
|
|
26
|
-
return (messageColor(message.getSeverity().toUpperCase() + ' in ' + message.getFile()) +
|
|
27
|
-
|
|
30
|
+
return (messageColor(message.getSeverity().toUpperCase() + ' in ' + message.getFile()) +
|
|
31
|
+
os.EOL +
|
|
32
|
+
positionColor(message.getLine() + ':' + message.getCharacter()) +
|
|
33
|
+
' ' +
|
|
34
|
+
message.getContent() +
|
|
28
35
|
(frame ? os.EOL + frame : ''));
|
|
29
36
|
};
|
|
30
37
|
}
|
|
31
38
|
exports.createCodeframeFormatter = createCodeframeFormatter;
|
|
32
|
-
;
|
|
@@ -10,7 +10,9 @@ var os = require("os");
|
|
|
10
10
|
function createDefaultFormatter() {
|
|
11
11
|
return function defaultFormatter(message, useColors) {
|
|
12
12
|
var colors = new chalk_1.default.constructor({ enabled: useColors });
|
|
13
|
-
var messageColor = message.isWarningSeverity()
|
|
13
|
+
var messageColor = message.isWarningSeverity()
|
|
14
|
+
? colors.bold.yellow
|
|
15
|
+
: colors.bold.red;
|
|
14
16
|
var fileAndNumberColor = colors.bold.cyan;
|
|
15
17
|
var codeColor = colors.grey;
|
|
16
18
|
return [
|
|
@@ -22,4 +24,3 @@ function createDefaultFormatter() {
|
|
|
22
24
|
};
|
|
23
25
|
}
|
|
24
26
|
exports.createDefaultFormatter = createDefaultFormatter;
|
|
25
|
-
;
|
package/lib/index.js
CHANGED
|
@@ -12,7 +12,6 @@ var NormalizedMessage_1 = require("./NormalizedMessage");
|
|
|
12
12
|
var defaultFormatter_1 = require("./formatter/defaultFormatter");
|
|
13
13
|
var codeframeFormatter_1 = require("./formatter/codeframeFormatter");
|
|
14
14
|
var tapable_1 = require("tapable");
|
|
15
|
-
var tapable_2 = require("tapable");
|
|
16
15
|
var checkerPluginName = 'fork-ts-checker-webpack-plugin';
|
|
17
16
|
var customHooks = {
|
|
18
17
|
forkTsCheckerServiceBeforeStart: 'fork-ts-checker-service-before-start',
|
|
@@ -37,9 +36,14 @@ var ForkTsCheckerWebpackPlugin = /** @class */ (function () {
|
|
|
37
36
|
options = options || {};
|
|
38
37
|
this.options = Object.assign({}, options);
|
|
39
38
|
this.tsconfig = options.tsconfig || './tsconfig.json';
|
|
40
|
-
this.tslint = options.tslint
|
|
41
|
-
options.tslint === true
|
|
42
|
-
|
|
39
|
+
this.tslint = options.tslint
|
|
40
|
+
? options.tslint === true
|
|
41
|
+
? './tslint.json'
|
|
42
|
+
: options.tslint
|
|
43
|
+
: undefined;
|
|
44
|
+
this.watch = isString(options.watch)
|
|
45
|
+
? [options.watch]
|
|
46
|
+
: options.watch || [];
|
|
43
47
|
this.ignoreDiagnostics = options.ignoreDiagnostics || [];
|
|
44
48
|
this.ignoreLints = options.ignoreLints || [];
|
|
45
49
|
this.logger = options.logger || console;
|
|
@@ -47,12 +51,14 @@ var ForkTsCheckerWebpackPlugin = /** @class */ (function () {
|
|
|
47
51
|
this.async = options.async !== false; // default true
|
|
48
52
|
this.checkSyntacticErrors = options.checkSyntacticErrors === true; // default false
|
|
49
53
|
this.workersNumber = options.workers || ForkTsCheckerWebpackPlugin.ONE_CPU;
|
|
50
|
-
this.memoryLimit =
|
|
54
|
+
this.memoryLimit =
|
|
55
|
+
options.memoryLimit || ForkTsCheckerWebpackPlugin.DEFAULT_MEMORY_LIMIT;
|
|
51
56
|
this.useColors = options.colors !== false; // default true
|
|
52
57
|
this.colors = new chalk_1.default.constructor({ enabled: this.useColors });
|
|
53
|
-
this.formatter =
|
|
54
|
-
|
|
55
|
-
|
|
58
|
+
this.formatter =
|
|
59
|
+
options.formatter && isFunction(options.formatter)
|
|
60
|
+
? options.formatter
|
|
61
|
+
: ForkTsCheckerWebpackPlugin.createFormatter(options.formatter || 'default', options.formatterOptions || {});
|
|
56
62
|
this.tsconfigPath = undefined;
|
|
57
63
|
this.tslintPath = undefined;
|
|
58
64
|
this.watchPaths = [];
|
|
@@ -68,7 +74,9 @@ var ForkTsCheckerWebpackPlugin = /** @class */ (function () {
|
|
|
68
74
|
this.emitCallback = this.createNoopEmitCallback();
|
|
69
75
|
this.doneCallback = this.createDoneCallback();
|
|
70
76
|
this.typescriptVersion = require('typescript').version;
|
|
71
|
-
this.tslintVersion = this.tslint
|
|
77
|
+
this.tslintVersion = this.tslint
|
|
78
|
+
? require('tslint').Linter.VERSION
|
|
79
|
+
: undefined;
|
|
72
80
|
this.vue = options.vue === true; // default false
|
|
73
81
|
}
|
|
74
82
|
ForkTsCheckerWebpackPlugin.createFormatter = function (type, options) {
|
|
@@ -84,7 +92,9 @@ var ForkTsCheckerWebpackPlugin = /** @class */ (function () {
|
|
|
84
92
|
ForkTsCheckerWebpackPlugin.prototype.apply = function (compiler) {
|
|
85
93
|
this.compiler = compiler;
|
|
86
94
|
this.tsconfigPath = this.computeContextPath(this.tsconfig);
|
|
87
|
-
this.tslintPath = this.tslint
|
|
95
|
+
this.tslintPath = this.tslint
|
|
96
|
+
? this.computeContextPath(this.tslint)
|
|
97
|
+
: null;
|
|
88
98
|
this.watchPaths = this.watch.map(this.computeContextPath.bind(this));
|
|
89
99
|
// validate config
|
|
90
100
|
var tsconfigOk = fs.existsSync(this.tsconfigPath);
|
|
@@ -92,7 +102,7 @@ var ForkTsCheckerWebpackPlugin = /** @class */ (function () {
|
|
|
92
102
|
// validate logger
|
|
93
103
|
if (this.logger) {
|
|
94
104
|
if (!this.logger.error || !this.logger.warn || !this.logger.info) {
|
|
95
|
-
throw new Error(
|
|
105
|
+
throw new Error("Invalid logger object - doesn't provide `error`, `warn` or `info` method.");
|
|
96
106
|
}
|
|
97
107
|
}
|
|
98
108
|
if (tsconfigOk && tslintOk) {
|
|
@@ -107,7 +117,9 @@ var ForkTsCheckerWebpackPlugin = /** @class */ (function () {
|
|
|
107
117
|
}
|
|
108
118
|
else {
|
|
109
119
|
if (!tsconfigOk) {
|
|
110
|
-
throw new Error('Cannot find "' +
|
|
120
|
+
throw new Error('Cannot find "' +
|
|
121
|
+
this.tsconfigPath +
|
|
122
|
+
'" file. Please check webpack and ForkTsCheckerWebpackPlugin configuration. \n' +
|
|
111
123
|
'Possible errors: \n' +
|
|
112
124
|
' - wrong `context` directory in webpack configuration' +
|
|
113
125
|
' (if `tsconfig` is not set or is a relative path in fork plugin configuration)\n' +
|
|
@@ -115,7 +127,9 @@ var ForkTsCheckerWebpackPlugin = /** @class */ (function () {
|
|
|
115
127
|
' (should be a relative or absolute path)');
|
|
116
128
|
}
|
|
117
129
|
if (!tslintOk) {
|
|
118
|
-
throw new Error('Cannot find "' +
|
|
130
|
+
throw new Error('Cannot find "' +
|
|
131
|
+
this.tslintPath +
|
|
132
|
+
'" file. Please check webpack and ForkTsCheckerWebpackPlugin configuration. \n' +
|
|
119
133
|
'Possible errors: \n' +
|
|
120
134
|
' - wrong `context` directory in webpack configuration' +
|
|
121
135
|
' (if `tslint` is not set or is a relative path in fork plugin configuration)\n' +
|
|
@@ -127,7 +141,9 @@ var ForkTsCheckerWebpackPlugin = /** @class */ (function () {
|
|
|
127
141
|
}
|
|
128
142
|
};
|
|
129
143
|
ForkTsCheckerWebpackPlugin.prototype.computeContextPath = function (filePath) {
|
|
130
|
-
return path.isAbsolute(filePath)
|
|
144
|
+
return path.isAbsolute(filePath)
|
|
145
|
+
? filePath
|
|
146
|
+
: path.resolve(this.compiler.options.context, filePath);
|
|
131
147
|
};
|
|
132
148
|
ForkTsCheckerWebpackPlugin.prototype.pluginStart = function () {
|
|
133
149
|
var _this = this;
|
|
@@ -175,26 +191,47 @@ var ForkTsCheckerWebpackPlugin = /** @class */ (function () {
|
|
|
175
191
|
});
|
|
176
192
|
};
|
|
177
193
|
ForkTsCheckerWebpackPlugin.prototype.registerCustomHooks = function () {
|
|
178
|
-
if (this.compiler.hooks.forkTsCheckerServiceBeforeStart
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
194
|
+
if (this.compiler.hooks.forkTsCheckerServiceBeforeStart ||
|
|
195
|
+
this.compiler.hooks.forkTsCheckerCancel ||
|
|
196
|
+
this.compiler.hooks.forkTsCheckerServiceStartError ||
|
|
197
|
+
this.compiler.hooks.forkTsCheckerWaiting ||
|
|
198
|
+
this.compiler.hooks.forkTsCheckerServiceStart ||
|
|
199
|
+
this.compiler.hooks.forkTsCheckerReceive ||
|
|
200
|
+
this.compiler.hooks.forkTsCheckerServiceOutOfMemory ||
|
|
201
|
+
this.compiler.hooks.forkTsCheckerDone ||
|
|
202
|
+
this.compiler.hooks.forkTsCheckerEmit) {
|
|
187
203
|
throw new Error('fork-ts-checker-webpack-plugin hooks are already in use');
|
|
188
204
|
}
|
|
189
205
|
this.compiler.hooks.forkTsCheckerServiceBeforeStart = new tapable_1.AsyncSeriesHook([]);
|
|
190
|
-
this.compiler.hooks.forkTsCheckerCancel = new
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
this.compiler.hooks.
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
this.compiler.hooks.
|
|
197
|
-
this.compiler.hooks.
|
|
206
|
+
this.compiler.hooks.forkTsCheckerCancel = new tapable_1.SyncHook([
|
|
207
|
+
'cancellationToken'
|
|
208
|
+
]);
|
|
209
|
+
this.compiler.hooks.forkTsCheckerServiceStartError = new tapable_1.SyncHook([
|
|
210
|
+
'error'
|
|
211
|
+
]);
|
|
212
|
+
this.compiler.hooks.forkTsCheckerWaiting = new tapable_1.SyncHook(['hasTsLint']);
|
|
213
|
+
this.compiler.hooks.forkTsCheckerServiceStart = new tapable_1.SyncHook([
|
|
214
|
+
'tsconfigPath',
|
|
215
|
+
'tslintPath',
|
|
216
|
+
'watchPaths',
|
|
217
|
+
'workersNumber',
|
|
218
|
+
'memoryLimit'
|
|
219
|
+
]);
|
|
220
|
+
this.compiler.hooks.forkTsCheckerReceive = new tapable_1.SyncHook([
|
|
221
|
+
'diagnostics',
|
|
222
|
+
'lints'
|
|
223
|
+
]);
|
|
224
|
+
this.compiler.hooks.forkTsCheckerServiceOutOfMemory = new tapable_1.SyncHook([]);
|
|
225
|
+
this.compiler.hooks.forkTsCheckerEmit = new tapable_1.SyncHook([
|
|
226
|
+
'diagnostics',
|
|
227
|
+
'lints',
|
|
228
|
+
'elapsed'
|
|
229
|
+
]);
|
|
230
|
+
this.compiler.hooks.forkTsCheckerDone = new tapable_1.SyncHook([
|
|
231
|
+
'diagnostics',
|
|
232
|
+
'lints',
|
|
233
|
+
'elapsed'
|
|
234
|
+
]);
|
|
198
235
|
// for backwards compatibility
|
|
199
236
|
this.compiler._pluginCompat.tap(checkerPluginName, function (options) {
|
|
200
237
|
switch (options.name) {
|
|
@@ -238,7 +275,8 @@ var ForkTsCheckerWebpackPlugin = /** @class */ (function () {
|
|
|
238
275
|
}
|
|
239
276
|
catch (error) {
|
|
240
277
|
if (!_this.silent && _this.logger) {
|
|
241
|
-
_this.logger.error(_this.colors.red('Cannot start checker service: ' +
|
|
278
|
+
_this.logger.error(_this.colors.red('Cannot start checker service: ' +
|
|
279
|
+
(error ? error.toString() : 'Unknown error')));
|
|
242
280
|
}
|
|
243
281
|
_this.compiler.hooks.forkTsCheckerServiceStartError.call(error);
|
|
244
282
|
}
|
|
@@ -267,7 +305,8 @@ var ForkTsCheckerWebpackPlugin = /** @class */ (function () {
|
|
|
267
305
|
}
|
|
268
306
|
catch (error) {
|
|
269
307
|
if (!_this.silent && _this.logger) {
|
|
270
|
-
_this.logger.error(_this.colors.red('Cannot start checker service: ' +
|
|
308
|
+
_this.logger.error(_this.colors.red('Cannot start checker service: ' +
|
|
309
|
+
(error ? error.toString() : 'Unknown error')));
|
|
271
310
|
}
|
|
272
311
|
_this.compiler.applyPlugins('fork-ts-checker-service-start-error', error);
|
|
273
312
|
}
|
|
@@ -347,7 +386,9 @@ var ForkTsCheckerWebpackPlugin = /** @class */ (function () {
|
|
|
347
386
|
ForkTsCheckerWebpackPlugin.prototype.spawnService = function () {
|
|
348
387
|
var _this = this;
|
|
349
388
|
this.service = childProcess.fork(path.resolve(__dirname, this.workersNumber > 1 ? './cluster.js' : './service.js'), [], {
|
|
350
|
-
execArgv: this.workersNumber > 1
|
|
389
|
+
execArgv: this.workersNumber > 1
|
|
390
|
+
? []
|
|
391
|
+
: ['--max-old-space-size=' + this.memoryLimit],
|
|
351
392
|
env: Object.assign({}, process.env, {
|
|
352
393
|
TSCONFIG: this.tsconfigPath,
|
|
353
394
|
TSLINT: this.tslintPath || '',
|
|
@@ -368,19 +409,28 @@ var ForkTsCheckerWebpackPlugin = /** @class */ (function () {
|
|
|
368
409
|
this.compiler.applyPlugins('fork-ts-checker-service-start', this.tsconfigPath, this.tslintPath, this.watchPaths, this.workersNumber, this.memoryLimit);
|
|
369
410
|
}
|
|
370
411
|
if (!this.silent && this.logger) {
|
|
371
|
-
this.logger.info('Starting type checking' +
|
|
372
|
-
|
|
373
|
-
'
|
|
412
|
+
this.logger.info('Starting type checking' +
|
|
413
|
+
(this.tslint ? ' and linting' : '') +
|
|
414
|
+
' service...');
|
|
415
|
+
this.logger.info('Using ' +
|
|
416
|
+
this.colors.bold(this.workersNumber === 1
|
|
417
|
+
? '1 worker'
|
|
418
|
+
: this.workersNumber + ' workers') +
|
|
419
|
+
' with ' +
|
|
420
|
+
this.colors.bold(this.memoryLimit + 'MB') +
|
|
421
|
+
' memory limit');
|
|
374
422
|
if (this.watchPaths.length && this.isWatching) {
|
|
375
423
|
this.logger.info('Watching:' +
|
|
376
424
|
(this.watchPaths.length > 1 ? '\n' : ' ') +
|
|
377
|
-
this.watchPaths
|
|
378
|
-
.map(function (wpath) { return _this.colors.grey(wpath); })
|
|
379
|
-
.join('\n'));
|
|
425
|
+
this.watchPaths.map(function (wpath) { return _this.colors.grey(wpath); }).join('\n'));
|
|
380
426
|
}
|
|
381
427
|
}
|
|
382
|
-
this.service.on('message', function (message) {
|
|
383
|
-
|
|
428
|
+
this.service.on('message', function (message) {
|
|
429
|
+
return _this.handleServiceMessage(message);
|
|
430
|
+
});
|
|
431
|
+
this.service.on('exit', function (code, signal) {
|
|
432
|
+
return _this.handleServiceExit(code, signal);
|
|
433
|
+
});
|
|
384
434
|
};
|
|
385
435
|
ForkTsCheckerWebpackPlugin.prototype.killService = function () {
|
|
386
436
|
if (this.service) {
|
|
@@ -415,9 +465,7 @@ var ForkTsCheckerWebpackPlugin = /** @class */ (function () {
|
|
|
415
465
|
});
|
|
416
466
|
}
|
|
417
467
|
if (this.ignoreLints.length) {
|
|
418
|
-
this.lints = this.lints.filter(function (lint) {
|
|
419
|
-
return _this.ignoreLints.indexOf(lint.getCode()) === -1;
|
|
420
|
-
});
|
|
468
|
+
this.lints = this.lints.filter(function (lint) { return _this.ignoreLints.indexOf(lint.getCode()) === -1; });
|
|
421
469
|
}
|
|
422
470
|
if ('hooks' in this.compiler) {
|
|
423
471
|
// webpack 4
|
|
@@ -428,7 +476,7 @@ var ForkTsCheckerWebpackPlugin = /** @class */ (function () {
|
|
|
428
476
|
this.compiler.applyPlugins('fork-ts-checker-receive', this.diagnostics, this.lints);
|
|
429
477
|
}
|
|
430
478
|
if (this.compilationDone) {
|
|
431
|
-
|
|
479
|
+
this.isWatching && this.async ? this.doneCallback() : this.emitCallback();
|
|
432
480
|
}
|
|
433
481
|
};
|
|
434
482
|
ForkTsCheckerWebpackPlugin.prototype.handleServiceExit = function (_code, signal) {
|
|
@@ -453,7 +501,7 @@ var ForkTsCheckerWebpackPlugin = /** @class */ (function () {
|
|
|
453
501
|
ForkTsCheckerWebpackPlugin.prototype.createEmitCallback = function (compilation, callback) {
|
|
454
502
|
return function emitCallback() {
|
|
455
503
|
var _this = this;
|
|
456
|
-
var elapsed = Math.round(this.elapsed[0] *
|
|
504
|
+
var elapsed = Math.round(this.elapsed[0] * 1e9 + this.elapsed[1]);
|
|
457
505
|
if ('hooks' in this.compiler) {
|
|
458
506
|
// webpack 4
|
|
459
507
|
this.compiler.hooks.forkTsCheckerEmit.call(this.diagnostics, this.lints, elapsed);
|
|
@@ -465,8 +513,11 @@ var ForkTsCheckerWebpackPlugin = /** @class */ (function () {
|
|
|
465
513
|
this.diagnostics.concat(this.lints).forEach(function (message) {
|
|
466
514
|
// webpack message format
|
|
467
515
|
var formatted = {
|
|
468
|
-
rawMessage:
|
|
469
|
-
|
|
516
|
+
rawMessage: message.getSeverity().toUpperCase() +
|
|
517
|
+
' ' +
|
|
518
|
+
message.getFormattedCode() +
|
|
519
|
+
': ' +
|
|
520
|
+
message.getContent(),
|
|
470
521
|
message: _this.formatter(message, _this.useColors),
|
|
471
522
|
location: {
|
|
472
523
|
line: message.getLine(),
|
|
@@ -491,7 +542,7 @@ var ForkTsCheckerWebpackPlugin = /** @class */ (function () {
|
|
|
491
542
|
ForkTsCheckerWebpackPlugin.prototype.createDoneCallback = function () {
|
|
492
543
|
return function doneCallback() {
|
|
493
544
|
var _this = this;
|
|
494
|
-
var elapsed = Math.round(this.elapsed[0] *
|
|
545
|
+
var elapsed = Math.round(this.elapsed[0] * 1e9 + this.elapsed[1]);
|
|
495
546
|
if (this.compiler) {
|
|
496
547
|
if ('hooks' in this.compiler) {
|
|
497
548
|
// webpack 4
|
|
@@ -506,7 +557,9 @@ var ForkTsCheckerWebpackPlugin = /** @class */ (function () {
|
|
|
506
557
|
if (this.diagnostics.length || this.lints.length) {
|
|
507
558
|
(this.lints || []).concat(this.diagnostics).forEach(function (message) {
|
|
508
559
|
var formattedMessage = _this.formatter(message, _this.useColors);
|
|
509
|
-
message.isWarningSeverity()
|
|
560
|
+
message.isWarningSeverity()
|
|
561
|
+
? _this.logger.warn(formattedMessage)
|
|
562
|
+
: _this.logger.error(formattedMessage);
|
|
510
563
|
});
|
|
511
564
|
}
|
|
512
565
|
if (!this.diagnostics.length) {
|
|
@@ -515,15 +568,20 @@ var ForkTsCheckerWebpackPlugin = /** @class */ (function () {
|
|
|
515
568
|
if (this.tslint && !this.lints.length) {
|
|
516
569
|
this.logger.info(this.colors.green('No lint errors found'));
|
|
517
570
|
}
|
|
518
|
-
this.logger.info('Version: typescript ' +
|
|
519
|
-
|
|
520
|
-
|
|
571
|
+
this.logger.info('Version: typescript ' +
|
|
572
|
+
this.colors.bold(this.typescriptVersion) +
|
|
573
|
+
(this.tslint
|
|
574
|
+
? ', tslint ' + this.colors.bold(this.tslintVersion)
|
|
575
|
+
: ''));
|
|
576
|
+
this.logger.info('Time: ' +
|
|
577
|
+
this.colors.bold(Math.round(elapsed / 1e6).toString()) +
|
|
578
|
+
'ms');
|
|
521
579
|
}
|
|
522
580
|
};
|
|
523
581
|
};
|
|
524
582
|
ForkTsCheckerWebpackPlugin.DEFAULT_MEMORY_LIMIT = 2048;
|
|
525
583
|
ForkTsCheckerWebpackPlugin.ONE_CPU = 1;
|
|
526
|
-
ForkTsCheckerWebpackPlugin.ALL_CPUS = os.cpus() ? os.cpus().length : 1;
|
|
584
|
+
ForkTsCheckerWebpackPlugin.ALL_CPUS = os.cpus && os.cpus() ? os.cpus().length : 1;
|
|
527
585
|
ForkTsCheckerWebpackPlugin.ONE_CPU_FREE = Math.max(1, ForkTsCheckerWebpackPlugin.ALL_CPUS - 1);
|
|
528
586
|
ForkTsCheckerWebpackPlugin.TWO_CPUS_FREE = Math.max(1, ForkTsCheckerWebpackPlugin.ALL_CPUS - 2);
|
|
529
587
|
return ForkTsCheckerWebpackPlugin;
|
package/lib/types/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fork-ts-checker-webpack-plugin",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.11",
|
|
4
4
|
"description": "Runs typescript type checker and linter on separate process.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/types/index.d.ts",
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"test": "npm run build && npm run test:unit && npm run test:integration",
|
|
15
15
|
"test:watch": "mocha -R spec --watch ./test/unit",
|
|
16
16
|
"test:coverage": "rimraf coverage && istanbul cover -root lib --include-all-sources mocha -- -R spec ./test/unit ./test/integration",
|
|
17
|
-
"lint": "eslint ./
|
|
18
|
-
"lint:fix": "eslint ./
|
|
17
|
+
"lint": "tslint --project src/tsconfig.json && eslint ./test",
|
|
18
|
+
"lint:fix": "tslint --project src/tsconfig.json --fix && eslint ./test --fix"
|
|
19
19
|
},
|
|
20
20
|
"repository": {
|
|
21
21
|
"url": "https://github.com/Realytics/fork-ts-checker-webpack-plugin.git",
|
|
@@ -61,21 +61,25 @@
|
|
|
61
61
|
"@types/webpack": "^4.4.9",
|
|
62
62
|
"chai": "^3.5.0",
|
|
63
63
|
"css-loader": "^0.28.7",
|
|
64
|
-
"eslint": "^
|
|
64
|
+
"eslint": "^5.7.0",
|
|
65
|
+
"husky": "^1.1.2",
|
|
65
66
|
"istanbul": "^0.4.5",
|
|
67
|
+
"lint-staged": "^7.3.0",
|
|
66
68
|
"mocha": "^3.4.1",
|
|
67
69
|
"mock-fs": "^4.3.0",
|
|
68
70
|
"mock-require": "^2.0.2",
|
|
71
|
+
"prettier": "^1.14.3",
|
|
69
72
|
"rimraf": "^2.5.4",
|
|
70
73
|
"sinon": "^2.3.1",
|
|
71
|
-
"ts-loader": "^3.
|
|
72
|
-
"tslint": "^5.
|
|
74
|
+
"ts-loader": "^4.3.0",
|
|
75
|
+
"tslint": "^5.11.0",
|
|
76
|
+
"tslint-config-prettier": "^1.15.0",
|
|
73
77
|
"typescript": "^3.0.1",
|
|
74
78
|
"vue": "^2.5.16",
|
|
75
79
|
"vue-class-component": "^6.1.1",
|
|
76
|
-
"vue-loader": "^
|
|
80
|
+
"vue-loader": "^15.2.4",
|
|
77
81
|
"vue-template-compiler": "^2.5.16",
|
|
78
|
-
"webpack": "^
|
|
82
|
+
"webpack": "^4.0.0"
|
|
79
83
|
},
|
|
80
84
|
"peerDependencies": {
|
|
81
85
|
"tslint": "^4.0.0 || ^5.0.0",
|
|
@@ -93,5 +97,25 @@
|
|
|
93
97
|
"minimatch": "^3.0.4",
|
|
94
98
|
"resolve": "^1.5.0",
|
|
95
99
|
"tapable": "^1.0.0"
|
|
100
|
+
},
|
|
101
|
+
"husky": {
|
|
102
|
+
"hooks": {
|
|
103
|
+
"pre-commit": "lint-staged"
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
"lint-staged": {
|
|
107
|
+
"concurrent": false,
|
|
108
|
+
"linters": {
|
|
109
|
+
"*.js": [
|
|
110
|
+
"eslint --fix"
|
|
111
|
+
],
|
|
112
|
+
"*.ts": [
|
|
113
|
+
"tslint --fix"
|
|
114
|
+
],
|
|
115
|
+
"*.{js,ts}": [
|
|
116
|
+
"prettier --write",
|
|
117
|
+
"git add"
|
|
118
|
+
]
|
|
119
|
+
}
|
|
96
120
|
}
|
|
97
121
|
}
|