Skip to content

Commit

Permalink
Merge pull request #30 from Realytics/feature/add-async-flag
Browse files Browse the repository at this point in the history
Add async flag in options + v0.2.5 release
  • Loading branch information
piotr-oles authored Jul 8, 2017
2 parents 18a5152 + 9d8619f commit af91b09
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## v0.2.5
* Add `async` option - more information in `README.md`

## v0.2.4
* Fix `ESLint: "fork-ts-checker-webpack-plugin" is not published.` issue

Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ Path to *tslint.json* file or `true`. If `true`, uses `path.resolve(compiler.opt

* **watch** `string | string[]`:
Directories or files to watch by service. Not necessary but improves performance (reduces number of `fs.stat` calls).


* **async** `boolean`:
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.
We recommend to use it in projects where type checking is faster than webpack's build - it's better for integration with other plugins.

* **ignoreDiagnostics** `number[]`:
List of typescript diagnostic codes to ignore.

Expand Down
9 changes: 5 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ function ForkTsCheckerWebpackPlugin (options) {
this.ignoreDiagnostics = options.ignoreDiagnostics || [];
this.ignoreLints = options.ignoreLints || [];
this.logger = options.logger || console;
this.silent = !!options.silent;
this.silent = options.silent === true; // default false
this.async = options.async !== false; // default true
this.workersNumber = options.workers || ForkTsCheckerWebpackPlugin.ONE_CPU;
this.memoryLimit = options.memoryLimit || ForkTsCheckerWebpackPlugin.DEFAULT_MEMORY_LIMIT;
this.colors = new chalk.constructor({ enabled: options.colors === undefined ? true : !!options.colors });
Expand Down Expand Up @@ -171,7 +172,7 @@ ForkTsCheckerWebpackPlugin.prototype.pluginCompile = function () {

ForkTsCheckerWebpackPlugin.prototype.pluginEmit = function () {
this.compiler.plugin('emit', function (compilation, callback) {
if (this.isWatching) {
if (this.isWatching && this.async) {
callback();
return;
}
Expand All @@ -188,7 +189,7 @@ ForkTsCheckerWebpackPlugin.prototype.pluginEmit = function () {

ForkTsCheckerWebpackPlugin.prototype.pluginDone = function () {
this.compiler.plugin('done', function () {
if (!this.isWatching) {
if (!this.isWatching || !this.async) {
return;
}

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

if (this.compilationDone) {
this.isWatching ? this.doneCallback() : this.emitCallback();
(this.isWatching && this.async) ? this.doneCallback() : this.emitCallback();
}
};

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fork-ts-checker-webpack-plugin",
"version": "0.2.4",
"version": "0.2.5",
"description": "Runs typescript type checker and linter on separate process.",
"main": "lib/index.js",
"files": [
Expand Down
13 changes: 12 additions & 1 deletion test/integration/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ describe('[INTEGRATION] index', function () {
compiler.run(function() {});
});


it('should not block emit on watch mode', function (callback) {
var compiler = createCompiler();
var watching = compiler.watch({}, function() {});
Expand All @@ -97,6 +96,18 @@ describe('[INTEGRATION] index', function () {
});
});

it('should block emit if async flag is false', function (callback) {
var compiler = createCompiler({ async: false });
var watching = compiler.watch({}, function() {});

compiler.plugin('fork-ts-checker-emit', function () {
watching.close(function() {
expect(true).to.be.true;
callback();
});
});
});

it('should throw error if config container wrong tsconfig.json path', function () {
expect(function() {
createCompiler({
Expand Down

0 comments on commit af91b09

Please sign in to comment.