Skip to content

feat: support for noEmitOnErrors property in webpack.config #337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ This plugin provides some custom webpack hooks (all are sync):
| `fork-ts-checker-service-start-error` | `serviceStartError` | Cannot start service | `error` |
| `fork-ts-checker-service-out-of-memory` | `serviceOutOfMemory` | Service is out of memory | - |
| `fork-ts-checker-receive` | `receive` | Plugin receives diagnostics and lints from service | `diagnostics`, `lints` |
| `fork-ts-checker-emit` | `emit` | Service will add errors and warnings to webpack compilation ('build' mode) | `diagnostics`, `lints`, `elapsed` |
| `fork-ts-checker-after-compile` | `after-compile` | Service will add errors and warnings to webpack compilation ('build' mode) | `diagnostics`, `lints`, `elapsed` |
| `fork-ts-checker-done` | `done` | Service finished type checking and webpack finished compilation ('watch' mode) | `diagnostics`, `lints`, `elapsed` |

The **Event name** is there for backward compatibility with webpack 2/3. Regardless
Expand Down
25 changes: 15 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class ForkTsCheckerWebpackPlugin {
private diagnostics: NormalizedMessage[] = [];
private lints: NormalizedMessage[] = [];

private emitCallback: () => void;
private afterCompileCallback: () => void;
private doneCallback: () => void;
private typescriptPath: string;
private typescript: typeof ts;
Expand Down Expand Up @@ -184,7 +184,7 @@ class ForkTsCheckerWebpackPlugin {
options.formatterOptions || {}
);

this.emitCallback = this.createNoopEmitCallback();
this.afterCompileCallback = this.createNoopAfterCompileCallback();
this.doneCallback = this.createDoneCallback();

const {
Expand Down Expand Up @@ -560,18 +560,21 @@ class ForkTsCheckerWebpackPlugin {
return;
}

this.emitCallback = this.createEmitCallback(compilation, callback);
this.afterCompileCallback = this.createAfterCompileCallback(
compilation,
callback
);

if (this.checkDone) {
this.emitCallback();
this.afterCompileCallback();
}

this.compilationDone = true;
};

if ('hooks' in this.compiler) {
// webpack 4+
this.compiler.hooks.emit.tapAsync(checkerPluginName, emit);
this.compiler.hooks.afterCompile.tapAsync(checkerPluginName, emit);
} else {
// webpack 2 / 3
this.compiler.plugin('emit', emit);
Expand Down Expand Up @@ -834,7 +837,9 @@ class ForkTsCheckerWebpackPlugin {
}

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

Expand Down Expand Up @@ -865,11 +870,11 @@ class ForkTsCheckerWebpackPlugin {
}
}

private createEmitCallback(
private createAfterCompileCallback(
compilation: webpack.compilation.Compilation,
callback: () => void
) {
return function emitCallback(this: ForkTsCheckerWebpackPlugin) {
return function afterCompileCallback(this: ForkTsCheckerWebpackPlugin) {
if (!this.elapsed) {
throw new Error('Execution order error');
}
Expand Down Expand Up @@ -921,9 +926,9 @@ class ForkTsCheckerWebpackPlugin {
};
}

private createNoopEmitCallback() {
private createNoopAfterCompileCallback() {
// tslint:disable-next-line:no-empty
return function noopEmitCallback() {};
return function noopAfterCompileCallback() {};
}

private printLoggerMessage(
Expand Down