Skip to content

[WIP] webpack@5 hooks support #166

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 5 commits into from
Dec 23, 2018
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
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ language: node_js
node_js:
- '10'
- '8'
- '6'
install:
- yarn install
- yarn build
- yarn add $WEBPACK $TSLOADER $VUELOADER -D
- yarn lint
env:
- WEBPACK=webpack@^5.0.0-alpha.0 TSLOADER=ts-loader@^5.0.0 VUELOADER=vue-loader@^15.2.4
- WEBPACK=webpack@^4.0.0 TSLOADER=ts-loader@^5.0.0 VUELOADER=vue-loader@^15.2.4
- WEBPACK=webpack@^3.10.0 TSLOADER=ts-loader@^3.4.0 VUELOADER=vue-loader@^13.5.0
- WEBPACK=webpack@^2.7.0 TSLOADER=ts-loader@^3.4.0 VUELOADER=vue-loader@^13.5.0
Expand All @@ -21,3 +21,4 @@ deploy:
on:
tags: true
branch: master
tag: next
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
## v1.0.0-alpha.0

* [Add support for webpack 5](https://github.com/Realytics/fork-ts-checker-webpack-plugin/pull/166)

### Breaking Changes

Version `1.x` additionally supports webpack 5 alongside webpack 4, whose hooks are now tapped differently:

```diff
- compiler.hooks.forkTsCheckerDone.tap(...args)
+ const forkTsCheckerHooks = ForkTsCheckerWebpackPlugin.getCompilerHooks(compiler)
+ forkTsCheckerHooks.done.tap(...args)
```

v1.0.0-alpha.0 drops support for node 6.

## v0.5.2

* [Fix erroneous error on diagnostics at 0 line; remove deprecated fs.existsSync](https://github.com/Realytics/fork-ts-checker-webpack-plugin/pull/190) (#190)
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fork-ts-checker-webpack-plugin",
"version": "0.5.2",
"version": "1.0.0-alpha.0",
"description": "Runs typescript type checker and linter on separate process.",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down Expand Up @@ -37,7 +37,7 @@
"webpack-plugin"
],
"engines": {
"node": ">=6.11.5"
"node": ">=8.9.0"
},
"author": "Piotr Oleś <[email protected]>",
"contributors": [
Expand Down Expand Up @@ -75,7 +75,7 @@
"vue-class-component": "^6.1.1",
"vue-loader": "^15.2.4",
"vue-template-compiler": "^2.5.16",
"webpack": "^4.16.5"
"webpack": "^5.0.0-alpha.0"
},
"peerDependencies": {
"tslint": "^4.0.0 || ^5.0.0",
Expand Down
61 changes: 61 additions & 0 deletions src/hooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import * as webpack from 'webpack';
import { AsyncSeriesHook, SyncHook } from 'tapable';

type ForkTsCheckerHooks =
| 'serviceBeforeStart'
| 'cancel'
| 'serviceStartError'
| 'waiting'
| 'serviceStart'
| 'receive'
| 'serviceOutOfMemory'
| 'emit'
| 'done';
type ForkTsCheckerHookMap = Record<
ForkTsCheckerHooks,
SyncHook | AsyncSeriesHook
>;
type ForkTsCheckerLegacyHookMap = Record<ForkTsCheckerHooks, string>;

const compilerHookMap = new WeakMap<webpack.Compiler, ForkTsCheckerHookMap>();

export const legacyHookMap: ForkTsCheckerLegacyHookMap = {
serviceBeforeStart: 'fork-ts-checker-service-before-start',
cancel: 'fork-ts-checker-cancel',
serviceStartError: 'fork-ts-checker-service-start-error',
waiting: 'fork-ts-checker-waiting',
serviceStart: 'fork-ts-checker-service-start',
receive: 'fork-ts-checker-receive',
serviceOutOfMemory: 'fork-ts-checker-service-out-of-memory',
emit: 'fork-ts-checker-emit',
done: 'fork-ts-checker-done'
};

function createForkTsCheckerWebpackPluginHooks(): ForkTsCheckerHookMap {
return {
serviceBeforeStart: new AsyncSeriesHook([]),
cancel: new SyncHook(['cancellationToken']),
serviceStartError: new SyncHook(['error']),
waiting: new SyncHook(['hasTsLint']),
serviceStart: new SyncHook([
'tsconfigPath',
'tslintPath',
'watchPaths',
'workersNumber',
'memoryLimit'
]),
receive: new SyncHook(['diagnostics', 'lints']),
serviceOutOfMemory: new SyncHook([]),
emit: new SyncHook(['diagnostics', 'lints', 'elapsed']),
done: new SyncHook(['diagnostics', 'lints', 'elapsed'])
};
}

export function getForkTsCheckerWebpackPluginHooks(compiler: webpack.Compiler) {
let hooks = compilerHookMap.get(compiler);
if (hooks === undefined) {
hooks = createForkTsCheckerWebpackPluginHooks();
compilerHookMap.set(compiler, hooks);
}
return hooks;
}
Loading