Skip to content

Commit 5665dac

Browse files
authored
feat: change start hook to AsyncSeriesWaterfallHook (#425)
Adds possibility to delay the start of the plugin by tapping into the start hook. BREAKING CHANGE: 🧨 start hook changed from SyncWaterfallHook to AsyncSeriesWaterfallHook ✅ Closes: #424
1 parent 8687c63 commit 5665dac

File tree

3 files changed

+22
-18
lines changed

3 files changed

+22
-18
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ Options for the ESLint linter (`eslint` option object).
178178

179179
| Name | Type | Default value | Description |
180180
| -------------------- | ---------------------- | ------------------------- | ----------- |
181-
| `enabled` | `boolean` | `true` | If `true`, it enables ESLint linter. |
181+
| `enabled` | `boolean` | `false` | If `true`, it enables ESLint linter. |
182182
| `files` | `string` or `string[]` | This value is required | One or more [glob patterns](https://en.wikipedia.org/wiki/Glob_(programming)) to the files that should be linted. Works the same as the `eslint` command. |
183183
| `memoryLimit` | `number` | `2048` | Memory limit for the linter process in MB. If the process exits with the allocation failed error, try to increase this number. |
184184
| `options` | `object` | `{}` | [Options](https://eslint.org/docs/developer-guide/nodejs-api#cliengine) that can be used to initialize ESLint. |
@@ -316,13 +316,13 @@ If you use **TypeScript >=3.8.0**, you can fix it by passing `"importsNotUsedAsV
316316

317317
This plugin provides some custom webpack hooks:
318318

319-
| Hook key | Type | Params | Description |
320-
| ---------- | ------------------- | --------------------- | ----------- |
321-
| `start` | `SyncWaterfallHook` | `change, compilation` | Starts issues checking for a compilation. It's a waterfall hook, so you can modify the list of changed and removed files. |
322-
| `waiting` | `SyncHook` | `compilation` | Waiting for the issues checking. |
323-
| `canceled` | `SyncHook` | `compilation` | Issues checking for the compilation has been canceled. |
324-
| `error` | `SyncHook` | `compilation` | An error occurred during issues checking. |
325-
| `issues` | `SyncWaterfallHook` | `issues, compilation` | Issues have been received and will be reported. It's a waterfall hook, so you can modify the list of received issues. |
319+
| Hook key | Type | Params | Description |
320+
| ---------- | -------------------------- | --------------------- | ----------- |
321+
| `start` | `AsyncSeriesWaterfallHook` | `change, compilation` | Starts issues checking for a compilation. It's an async waterfall hook, so you can modify the list of changed and removed files or delay the start of the service. |
322+
| `waiting` | `SyncHook` | `compilation` | Waiting for the issues checking. |
323+
| `canceled` | `SyncHook` | `compilation` | Issues checking for the compilation has been canceled. |
324+
| `error` | `SyncHook` | `compilation` | An error occurred during issues checking. |
325+
| `issues` | `SyncWaterfallHook` | `issues, compilation` | Issues have been received and will be reported. It's a waterfall hook, so you can modify the list of received issues. |
326326

327327
To access plugin hooks and tap into the event, we need to use the `getCompilerHooks` static method.
328328
When we call this method with a [webpack compiler instance](https://webpack.js.org/api/node/), it returns the object with

src/hooks/pluginHooks.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as webpack from 'webpack';
2-
import { SyncHook, SyncWaterfallHook } from 'tapable';
2+
import { SyncHook, SyncWaterfallHook, AsyncSeriesWaterfallHook } from 'tapable';
33
import { FilesChange } from '../reporter';
44
import { Issue } from '../issue';
55

@@ -10,7 +10,7 @@ const compilerHookMap = new WeakMap<
1010

1111
function createForkTsCheckerWebpackPluginHooks() {
1212
return {
13-
start: new SyncWaterfallHook<FilesChange, webpack.compilation.Compilation>([
13+
start: new AsyncSeriesWaterfallHook<FilesChange, webpack.compilation.Compilation>([
1414
'change',
1515
'compilation',
1616
]),
@@ -30,7 +30,7 @@ function forwardForkTsCheckerWebpackPluginHooks(
3030
source: ForkTsCheckerWebpackPluginHooks,
3131
target: ForkTsCheckerWebpackPluginHooks
3232
) {
33-
source.start.tap('ForkTsCheckerWebpackPlugin', target.start.call);
33+
source.start.tapPromise('ForkTsCheckerWebpackPlugin', target.start.promise);
3434
source.waiting.tap('ForkTsCheckerWebpackPlugin', target.waiting.call);
3535
source.canceled.tap('ForkTsCheckerWebpackPlugin', target.canceled.call);
3636
source.error.tap('ForkTsCheckerWebpackPlugin', target.error.call);

src/hooks/tapStartToConnectAndRunReporter.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,24 @@ function tapStartToConnectAndRunReporter(
6161
configuration.logger.infrastructure.info('Calling reporter service for single check.');
6262
}
6363

64-
change = hooks.start.call(change, compilation);
64+
state.report = new Promise(async (resolve) => {
65+
change = await hooks.start.promise(change, compilation);
6566

66-
state.report = reporter
67-
.connect()
68-
.then(() => reporter.getReport(change))
69-
.catch((error) => {
67+
try {
68+
await reporter.connect();
69+
const report = await reporter.getReport(change);
70+
71+
resolve(report);
72+
} catch (error) {
7073
if (error instanceof OperationCanceledError) {
7174
hooks.canceled.call(compilation);
7275
} else {
7376
hooks.error.call(error, compilation);
7477
}
7578

76-
return undefined;
77-
});
79+
resolve(undefined);
80+
}
81+
});
7882
});
7983
}
8084

0 commit comments

Comments
 (0)