Skip to content

Commit af91b09

Browse files
authored
Merge pull request #30 from Realytics/feature/add-async-flag
Add async flag in options + v0.2.5 release
2 parents 18a5152 + 9d8619f commit af91b09

File tree

5 files changed

+26
-7
lines changed

5 files changed

+26
-7
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## v0.2.5
2+
* Add `async` option - more information in `README.md`
3+
14
## v0.2.4
25
* Fix `ESLint: "fork-ts-checker-webpack-plugin" is not published.` issue
36

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ Path to *tslint.json* file or `true`. If `true`, uses `path.resolve(compiler.opt
6565

6666
* **watch** `string | string[]`:
6767
Directories or files to watch by service. Not necessary but improves performance (reduces number of `fs.stat` calls).
68-
68+
69+
* **async** `boolean`:
70+
True by default - `async: false` can block webpack's emit to wait for type checker/linter and to add errors to the webpack's compilation.
71+
We recommend to use it in projects where type checking is faster than webpack's build - it's better for integration with other plugins.
72+
6973
* **ignoreDiagnostics** `number[]`:
7074
List of typescript diagnostic codes to ignore.
7175

lib/index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ function ForkTsCheckerWebpackPlugin (options) {
2626
this.ignoreDiagnostics = options.ignoreDiagnostics || [];
2727
this.ignoreLints = options.ignoreLints || [];
2828
this.logger = options.logger || console;
29-
this.silent = !!options.silent;
29+
this.silent = options.silent === true; // default false
30+
this.async = options.async !== false; // default true
3031
this.workersNumber = options.workers || ForkTsCheckerWebpackPlugin.ONE_CPU;
3132
this.memoryLimit = options.memoryLimit || ForkTsCheckerWebpackPlugin.DEFAULT_MEMORY_LIMIT;
3233
this.colors = new chalk.constructor({ enabled: options.colors === undefined ? true : !!options.colors });
@@ -171,7 +172,7 @@ ForkTsCheckerWebpackPlugin.prototype.pluginCompile = function () {
171172

172173
ForkTsCheckerWebpackPlugin.prototype.pluginEmit = function () {
173174
this.compiler.plugin('emit', function (compilation, callback) {
174-
if (this.isWatching) {
175+
if (this.isWatching && this.async) {
175176
callback();
176177
return;
177178
}
@@ -188,7 +189,7 @@ ForkTsCheckerWebpackPlugin.prototype.pluginEmit = function () {
188189

189190
ForkTsCheckerWebpackPlugin.prototype.pluginDone = function () {
190191
this.compiler.plugin('done', function () {
191-
if (!this.isWatching) {
192+
if (!this.isWatching || !this.async) {
192193
return;
193194
}
194195

@@ -306,7 +307,7 @@ ForkTsCheckerWebpackPlugin.prototype.handleServiceMessage = function (message) {
306307
this.compiler.applyPlugins('fork-ts-checker-receive', this.diagnostics, this.lints);
307308

308309
if (this.compilationDone) {
309-
this.isWatching ? this.doneCallback() : this.emitCallback();
310+
(this.isWatching && this.async) ? this.doneCallback() : this.emitCallback();
310311
}
311312
};
312313

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fork-ts-checker-webpack-plugin",
3-
"version": "0.2.4",
3+
"version": "0.2.5",
44
"description": "Runs typescript type checker and linter on separate process.",
55
"main": "lib/index.js",
66
"files": [

test/integration/index.spec.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ describe('[INTEGRATION] index', function () {
8484
compiler.run(function() {});
8585
});
8686

87-
8887
it('should not block emit on watch mode', function (callback) {
8988
var compiler = createCompiler();
9089
var watching = compiler.watch({}, function() {});
@@ -97,6 +96,18 @@ describe('[INTEGRATION] index', function () {
9796
});
9897
});
9998

99+
it('should block emit if async flag is false', function (callback) {
100+
var compiler = createCompiler({ async: false });
101+
var watching = compiler.watch({}, function() {});
102+
103+
compiler.plugin('fork-ts-checker-emit', function () {
104+
watching.close(function() {
105+
expect(true).to.be.true;
106+
callback();
107+
});
108+
});
109+
});
110+
100111
it('should throw error if config container wrong tsconfig.json path', function () {
101112
expect(function() {
102113
createCompiler({

0 commit comments

Comments
 (0)