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 CHANGED
@@ -1,3 +1,19 @@
1
+ ## v0.2.10
2
+ * Fix #80 "Cannot read property 'getLineAndCharacterOfPosition' of undefined"
3
+ * Fix #76 "TypeError: Cannot read property '0' of undefined"
4
+
5
+ ## v0.2.9
6
+ * Make errors formatting closer to `ts-loader` style
7
+ * Handle tslint exclude option
8
+
9
+ ## v0.2.8
10
+ * Add `checkSyntacticErrors` option
11
+ * Fix `process.env` pass to the child process
12
+ * Add `fork-ts-checker-service-before-start` hook
13
+
14
+ ## v0.2.7
15
+ * Fix service is not killed when webpack watch is done
16
+
1
17
  ## v0.2.6
2
18
  * Add diagnostics/lints formatters - `formatter` and `formatterOptions` option
3
19
 
package/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  Webpack plugin that runs typescript type checker on a separate process.
6
6
 
7
7
  ## Installation
8
- This plugin requires minimum **webpack 2**, **typescript 2.1** and optionally **tslint 5.0**
8
+ This plugin requires minimum **webpack 2.3**, **typescript 2.1** and optionally **tslint 5.0**
9
9
  ```sh
10
10
  npm install --save-dev fork-ts-checker-webpack-plugin
11
11
  ```
@@ -82,9 +82,9 @@ If `false`, disables built-in colors in logger messages. Default: `true`.
82
82
  * **logger** `object`:
83
83
  Logger instance. It should be object that implements method: `error`, `warn`, `info`. Default: `console`.
84
84
 
85
- * **formatter** `'default' | 'codeframe' | Function`:
85
+ * **formatter** `'default' | 'codeframe' | ((message: NormalizedMessage, useColors: boolean) => string)`:
86
86
  Formatter for diagnostics and lints. By default uses `default` formatter. You can also pass your own formatter as a function
87
- (see `lib/NormalizedMessage.js` and `lib/formatter/` for api reference).
87
+ (see `src/NormalizedMessage.js` and `src/formatter/` for api reference).
88
88
 
89
89
  * **formatterOptions** `object`:
90
90
  Options passed to formatters (currently only `codeframe` - see [available options](https://www.npmjs.com/package/babel-code-frame#options))
@@ -92,6 +92,9 @@ Options passed to formatters (currently only `codeframe` - see [available option
92
92
  * **silent** `boolean`:
93
93
  If `true`, logger will not be used. Default: `false`.
94
94
 
95
+ * **checkSyntacticErrors** `boolean`:
96
+ This option is useful if you're using ts-loader in `happyPackMode` with [HappyPack](https://github.com/amireh/happypack) or [thread-loader](https://github.com/webpack-contrib/thread-loader) to parallelise your builds. It will ensure that the plugin checks for both syntactic errors (eg `const array = [{} {}];`) and semantic errors (eg `const x: number = '1';`). By default the plugin only checks for semantic errors. This is because when ts-loader is used in `transpileOnly` mode, ts-loader will still report syntactic errors. When used in `happyPackMode` it does not. Default: `false`.
97
+
95
98
  * **memoryLimit** `number`:
96
99
  Memory limit for service process in MB. If service exits with allocation failed error, increase this number. Default: `2048`.
97
100
 
@@ -107,6 +110,22 @@ number **can increase checking time**. Default: `ForkTsCheckerWebpackPlugin.ONE_
107
110
  * `ForkTsCheckerWebpackPlugin.ONE_CPU_FREE` - leave only one CPU for build (probably will increase build time)
108
111
  * `ForkTsCheckerWebpackPlugin.TWO_CPUS_FREE` - **recommended** - leave two CPUs free (one for build, one for system)
109
112
 
113
+ ## Different behaviour in watch mode
114
+
115
+ If you turn on [webpacks watch mode](https://webpack.js.org/configuration/watch/#watch) the `fork-ts-checker-notifier-webpack-plugin` will take care of logging type errors, _not_ webpack itself. That means if you set `silent: true` you won't see type errors in your console in watch mode.
116
+
117
+ You can either set `silent: false` to show the logging from `fork-ts-checker-notifier-webpack-plugin` _or_ set `async: false`. Now webpack itself will log type errors again, but note that this can slow down your builds depending on the size of your project.
118
+
119
+ ## Notifier
120
+
121
+ You may already be using the excellent [webpack-notifier](https://github.com/Turbo87/webpack-notifier) plugin to make build failures more obvious in the form of system notifications. There's an equivalent notifier plugin designed to work with the `fork-ts-checker-webpack-plugin`. It is the `fork-ts-checker-notifier-webpack-plugin` and can be found [here](https://github.com/johnnyreilly/fork-ts-checker-notifier-webpack-plugin). This notifier deliberately has a similar API as the `webpack-notifier` plugin to make migration easier.
122
+
123
+ ## Known Issue Watching Non-Emitting Files
124
+
125
+ At present there is an issue with the plugin regarding the triggering of type-checking when a change is made in a source file that will not emit js. If you have a file which contains only `interface`s and / or `type`s then changes to it will **not** trigger the type checker whilst in watch mode. Sorry about that.
126
+
127
+ We hope this will be resolved in future; the issue can be tracked [here](https://github.com/Realytics/fork-ts-checker-webpack-plugin/issues/36).
128
+
110
129
  ## Plugin Hooks
111
130
  This plugin provides some custom webpack hooks (all are sync):
112
131
 
@@ -114,6 +133,7 @@ This plugin provides some custom webpack hooks (all are sync):
114
133
  |------------|-------------|--------|
115
134
  |`fork-ts-checker-cancel`| Cancellation has been requested | `cancellationToken` |
116
135
  |`fork-ts-checker-waiting`| Waiting for results | `hasTsLint` |
136
+ |`fork-ts-checker-service-before-start`| Async plugin that can be used for delaying `fork-ts-checker-service-start` | - |
117
137
  |`fork-ts-checker-service-start`| Service will be started | `tsconfigPath`, `tslintPath`, `watchPaths`, `workersNumber`, `memoryLimit` |
118
138
  |`fork-ts-checker-service-start-error` | Cannot start service | `error` |
119
139
  |`fork-ts-checker-service-out-of-memory`| Service is out of memory | - |
@@ -1,65 +1,55 @@
1
- var ts = require('typescript');
2
- var fs = require('fs');
3
- var os = require('os');
4
- var path = require('path');
5
- var crypto = require('crypto');
6
-
7
- function CancellationToken (cancellationFileName, isCancelled) {
8
- this.isCancelled = !!isCancelled;
9
- this.cancellationFileName = cancellationFileName || crypto.randomBytes(64).toString('hex');
10
- this.lastCancellationCheckTime = 0;
11
- }
1
+ "use strict";
2
+ var crypto = require("crypto");
3
+ var fs = require("fs");
4
+ var os = require("os");
5
+ var path = require("path");
6
+ var ts = require("typescript");
7
+ var CancellationToken = /** @class */ (function () {
8
+ function CancellationToken(cancellationFileName, isCancelled) {
9
+ this.isCancelled = !!isCancelled;
10
+ this.cancellationFileName = cancellationFileName || crypto.randomBytes(64).toString('hex');
11
+ this.lastCancellationCheckTime = 0;
12
+ }
13
+ CancellationToken.createFromJSON = function (json) {
14
+ return new CancellationToken(json.cancellationFileName, json.isCancelled);
15
+ };
16
+ CancellationToken.prototype.toJSON = function () {
17
+ return {
18
+ cancellationFileName: this.cancellationFileName,
19
+ isCancelled: this.isCancelled
20
+ };
21
+ };
22
+ CancellationToken.prototype.getCancellationFilePath = function () {
23
+ return path.join(os.tmpdir(), this.cancellationFileName);
24
+ };
25
+ CancellationToken.prototype.isCancellationRequested = function () {
26
+ if (this.isCancelled) {
27
+ return true;
28
+ }
29
+ var time = Date.now();
30
+ var duration = Math.abs(time - this.lastCancellationCheckTime);
31
+ if (duration > 10) {
32
+ // check no more than once every 10ms
33
+ this.lastCancellationCheckTime = time;
34
+ this.isCancelled = fs.existsSync(this.getCancellationFilePath());
35
+ }
36
+ return this.isCancelled;
37
+ };
38
+ CancellationToken.prototype.throwIfCancellationRequested = function () {
39
+ if (this.isCancellationRequested()) {
40
+ throw new ts.OperationCanceledException();
41
+ }
42
+ };
43
+ CancellationToken.prototype.requestCancellation = function () {
44
+ fs.writeFileSync(this.getCancellationFilePath(), '');
45
+ this.isCancelled = true;
46
+ };
47
+ CancellationToken.prototype.cleanupCancellation = function () {
48
+ if (this.isCancelled && fs.existsSync(this.getCancellationFilePath())) {
49
+ fs.unlinkSync(this.getCancellationFilePath());
50
+ this.isCancelled = false;
51
+ }
52
+ };
53
+ return CancellationToken;
54
+ }());
12
55
  module.exports = CancellationToken;
13
-
14
- CancellationToken.createFromJSON = function (json) {
15
- return new CancellationToken(
16
- json.cancellationFileName,
17
- json.isCancelled
18
- );
19
- };
20
-
21
- CancellationToken.prototype.toJSON = function () {
22
- return {
23
- cancellationFileName: this.cancellationFileName,
24
- isCancelled: this.isCancelled
25
- };
26
- };
27
-
28
- CancellationToken.prototype.getCancellationFilePath = function () {
29
- return path.join(os.tmpdir(), this.cancellationFileName);
30
- };
31
-
32
- CancellationToken.prototype.isCancellationRequested = function () {
33
- if (this.isCancelled) {
34
- return true;
35
- }
36
-
37
- var time = Date.now();
38
- var duration = Math.abs(time - this.lastCancellationCheckTime);
39
-
40
- if (duration > 10) {
41
- // check no more than once every 10ms
42
- this.lastCancellationCheckTime = time;
43
- this.isCancelled = fs.existsSync(this.getCancellationFilePath());
44
- }
45
-
46
- return this.isCancelled;
47
- };
48
-
49
- CancellationToken.prototype.throwIfCancellationRequested = function () {
50
- if (this.isCancellationRequested()) {
51
- throw new ts.OperationCanceledException();
52
- }
53
- };
54
-
55
- CancellationToken.prototype.requestCancellation = function () {
56
- fs.writeFileSync(this.getCancellationFilePath(), '');
57
- this.isCancelled = true;
58
- };
59
-
60
- CancellationToken.prototype.cleanupCancellation = function () {
61
- if (this.isCancelled && fs.existsSync(this.getCancellationFilePath())) {
62
- fs.unlinkSync(this.getCancellationFilePath());
63
- this.isCancelled = false;
64
- }
65
- };
@@ -1,65 +1,55 @@
1
-
2
- function FilesRegister (dataFactory) {
3
- this.files = {};
4
- this.dataFactory = dataFactory;
5
- }
1
+ "use strict";
2
+ var FilesRegister = /** @class */ (function () {
3
+ function FilesRegister(dataFactory) {
4
+ this.files = {};
5
+ this.dataFactory = dataFactory;
6
+ }
7
+ FilesRegister.prototype.keys = function () {
8
+ return Object.keys(this.files);
9
+ };
10
+ FilesRegister.prototype.add = function (filePath) {
11
+ this.files[filePath] = {
12
+ mtime: undefined,
13
+ data: this.dataFactory(undefined)
14
+ };
15
+ };
16
+ FilesRegister.prototype.remove = function (filePath) {
17
+ if (this.has(filePath)) {
18
+ delete this.files[filePath];
19
+ }
20
+ };
21
+ FilesRegister.prototype.has = function (filePath) {
22
+ return this.files.hasOwnProperty(filePath);
23
+ };
24
+ FilesRegister.prototype.get = function (filePath) {
25
+ if (!this.has(filePath)) {
26
+ throw new Error('File "' + filePath + '" not found in register.');
27
+ }
28
+ return this.files[filePath];
29
+ };
30
+ FilesRegister.prototype.ensure = function (filePath) {
31
+ if (!this.has(filePath)) {
32
+ this.add(filePath);
33
+ }
34
+ };
35
+ FilesRegister.prototype.getData = function (filePath) {
36
+ return this.get(filePath).data;
37
+ };
38
+ FilesRegister.prototype.mutateData = function (filePath, mutator) {
39
+ this.ensure(filePath);
40
+ mutator(this.files[filePath].data);
41
+ };
42
+ FilesRegister.prototype.getMtime = function (filePath) {
43
+ return this.get(filePath).mtime;
44
+ };
45
+ FilesRegister.prototype.setMtime = function (filePath, mtime) {
46
+ this.ensure(filePath);
47
+ if (this.files[filePath].mtime !== mtime) {
48
+ this.files[filePath].mtime = mtime;
49
+ // file has been changed - we have to reset data
50
+ this.files[filePath].data = this.dataFactory(this.files[filePath].data);
51
+ }
52
+ };
53
+ return FilesRegister;
54
+ }());
6
55
  module.exports = FilesRegister;
7
-
8
- FilesRegister.prototype.keys = function () {
9
- return Object.keys(this.files);
10
- };
11
-
12
- FilesRegister.prototype.add = function (filePath) {
13
- this.files[filePath] = {
14
- mtime: undefined,
15
- data: this.dataFactory(undefined)
16
- };
17
- };
18
-
19
- FilesRegister.prototype.remove = function (filePath) {
20
- if (this.has(filePath)) {
21
- delete this.files[filePath];
22
- }
23
- };
24
-
25
- FilesRegister.prototype.has = function (filePath) {
26
- return this.files.hasOwnProperty(filePath);
27
- };
28
-
29
- FilesRegister.prototype.get = function (filePath) {
30
- if (!this.has(filePath)) {
31
- throw new Error('File "' + filePath + '" not found in register.');
32
- }
33
-
34
- return this.files[filePath];
35
- };
36
-
37
- FilesRegister.prototype.ensure = function (filePath) {
38
- if (!this.has(filePath)) {
39
- this.add(filePath);
40
- }
41
- };
42
-
43
- FilesRegister.prototype.getData = function (filePath) {
44
- return this.get(filePath).data;
45
- };
46
-
47
- FilesRegister.prototype.mutateData = function (filePath, mutator) {
48
- this.ensure(filePath);
49
-
50
- mutator(this.files[filePath].data);
51
- };
52
-
53
- FilesRegister.prototype.getMtime = function (filePath) {
54
- return this.get(filePath).mtime;
55
- };
56
-
57
- FilesRegister.prototype.setMtime = function (filePath, mtime) {
58
- this.ensure(filePath);
59
-
60
- if (this.files[filePath].mtime !== mtime) {
61
- this.files[filePath].mtime = mtime;
62
- // file has been changed - we have to reset data
63
- this.files[filePath].data = this.dataFactory(this.files[filePath].data);
64
- }
65
- };
@@ -1,72 +1,59 @@
1
- var chokidar = require('chokidar');
2
- var path = require('path');
3
- var startsWith = require('lodash.startswith');
4
-
5
- function FilesWatcher (watchPaths, watchExtensions) {
6
- this.watchPaths = watchPaths;
7
- this.watchExtensions = watchExtensions;
8
- this.watchers = [];
9
- this.listeners = {};
10
- }
11
- module.exports = FilesWatcher;
12
-
13
- FilesWatcher.prototype.isFileSupported = function (filePath) {
14
- return this.watchExtensions.indexOf(path.extname(filePath)) !== -1;
15
- };
16
-
17
- FilesWatcher.prototype.watch = function () {
18
- if (this.isWatching()) {
19
- throw new Error('Cannot watch again - already watching.');
20
- }
21
-
22
- this.watchers = this.watchPaths.map(function (watchPath) {
23
- return chokidar.watch(
24
- watchPath,
25
- { persistent: true, alwaysStat: true }
26
- )
27
- .on('change', function (filePath, stats) {
28
- if (this.isFileSupported(filePath)) {
29
- (this.listeners['change'] || []).forEach(function (changeListener) {
30
- changeListener(filePath, stats);
31
- });
32
- }
33
- }.bind(this))
34
- .on('unlink', function (filePath) {
35
- if (this.isFileSupported(filePath)) {
36
- (this.listeners['unlink'] || []).forEach(function (unlinkListener) {
37
- unlinkListener(filePath);
1
+ "use strict";
2
+ var chokidar = require("chokidar");
3
+ var path = require("path");
4
+ var startsWith = require("lodash.startswith");
5
+ var FilesWatcher = /** @class */ (function () {
6
+ function FilesWatcher(watchPaths, watchExtensions) {
7
+ this.watchPaths = watchPaths;
8
+ this.watchExtensions = watchExtensions;
9
+ this.watchers = [];
10
+ this.listeners = {};
11
+ }
12
+ FilesWatcher.prototype.isFileSupported = function (filePath) {
13
+ return this.watchExtensions.indexOf(path.extname(filePath)) !== -1;
14
+ };
15
+ FilesWatcher.prototype.watch = function () {
16
+ var _this = this;
17
+ if (this.isWatching()) {
18
+ throw new Error('Cannot watch again - already watching.');
19
+ }
20
+ this.watchers = this.watchPaths.map(function (watchPath) {
21
+ return chokidar.watch(watchPath, { persistent: true, alwaysStat: true })
22
+ .on('change', function (filePath, stats) {
23
+ if (_this.isFileSupported(filePath)) {
24
+ (_this.listeners['change'] || []).forEach(function (changeListener) {
25
+ changeListener(filePath, stats);
26
+ });
27
+ }
28
+ })
29
+ .on('unlink', function (filePath) {
30
+ if (_this.isFileSupported(filePath)) {
31
+ (_this.listeners['unlink'] || []).forEach(function (unlinkListener) {
32
+ unlinkListener(filePath);
33
+ });
34
+ }
35
+ });
38
36
  });
39
- }
40
- }.bind(this));
41
- }.bind(this));
42
- };
43
-
44
- FilesWatcher.prototype.isWatchingFile = function (filePath) {
45
- return (
46
- this.isWatching() &&
47
- this.isFileSupported(filePath) &&
48
- this.watchPaths.some(function (watchPath) {
49
- return startsWith(filePath, watchPath);
50
- })
51
- );
52
- };
53
-
54
- FilesWatcher.prototype.isWatching = function () {
55
- return this.watchers.length > 0;
56
- };
57
-
58
- FilesWatcher.prototype.on = function (event, listener) {
59
- if (!this.listeners[event]) {
60
- this.listeners[event] = [];
61
- }
62
-
63
- this.listeners[event].push(listener);
64
- };
65
-
66
- FilesWatcher.prototype.off = function (event, listener) {
67
- if (this.listeners[event]) {
68
- this.listeners[event] = this.listeners[event].filter(function (oldListener) {
69
- return oldListener !== listener;
70
- });
71
- }
72
- };
37
+ };
38
+ FilesWatcher.prototype.isWatchingFile = function (filePath) {
39
+ return (this.isWatching() &&
40
+ this.isFileSupported(filePath) &&
41
+ this.watchPaths.some(function (watchPath) { return startsWith(filePath, watchPath); }));
42
+ };
43
+ FilesWatcher.prototype.isWatching = function () {
44
+ return this.watchers.length > 0;
45
+ };
46
+ FilesWatcher.prototype.on = function (event, listener) {
47
+ if (!this.listeners[event]) {
48
+ this.listeners[event] = [];
49
+ }
50
+ this.listeners[event].push(listener);
51
+ };
52
+ FilesWatcher.prototype.off = function (event, listener) {
53
+ if (this.listeners[event]) {
54
+ this.listeners[event] = this.listeners[event].filter(function (oldListener) { return oldListener !== listener; });
55
+ }
56
+ };
57
+ return FilesWatcher;
58
+ }());
59
+ module.exports = FilesWatcher;