-
-
Notifications
You must be signed in to change notification settings - Fork 246
[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
Conversation
First of all, thanks for your work here; this is awesome! I've put some adhoc comments on the PR but I've realised a few things. First of all there's quite a lot of "noise" in this PR due to formatting changes / linting related stuff. I'd really like to separate out the webpack 5 support changes from that. We use prettier in ts-loader; (see the I've long thought I'd like to apply prettier in fork-ts-checker-webpack-plugin. I'd be happy to do that, get it merged in and then have you merge that into your PR and work against that. Or you could apply prettier yourself in a separate PR? Or you could just drop all the styling changes entirely from this PR. I honestly don't mind which; but I'd like this PR to be webpack 5 focussed only if that's okay! Sorry - this may sound ungrateful; but I'm just trying to make it easier to focus on doing a good review and catching the right issues. At present I'm quite distracted by all the formatting changes! |
Can you confirm if this supports webpack 4 as well as 5 please? I think it might; but I'm not certain. |
@johnnyreilly Are there any comments on the |
Do you mean the support for webpack 2/3? |
Yes and no. If you look into this line on master (https://github.com/Realytics/fork-ts-checker-webpack-plugin/blob/master/src/index.ts#L189-L191), the |
I see. Take off and nuke |
I'm curious as to how the webpack 4 back compatibility works. |
I've been trying to understand why this change was made in webpack@5 as well... Unfortunately webpack@5 is a major change, most plugins will definitely break, and you might want to publish a major version of this plugin with no backwards compatibility. This is because webpack@5 is removing hooks on This means that plugins like Example (https://github.com/johnnyreilly/fork-ts-checker-notifier-webpack-plugin/blob/master/index.ts#L101): I am going to close this PR. |
Hey @liangchunn , Actually - I'd quite like to leave this PR open if that's okay with you? We're not ready to ship but I suspect we're very close! Also, doesn't the:
provide the webpack 4 compatibility? That seems to be implied in this PR: webpack/webpack#7672 Actually - I'm not totally clear; but I feel this could well become the webpack 5 support we need in future! |
I don't think that those lines provide webpack 4 compat. That PR changes its own HMR plugins which is shipped with webpack@5, AFAIK. |
Ah right; either way, the fact we got passing tests with all versions of webpack was very encouraging! |
One way we could provide webpack@5 support is to use I'll experiment again when I have some free time on hand. |
I've added tests against
|
Awesome!
Yup sounds about right. |
Hey @liangchunn, Would you be up for continuing your work now 5 alpha is out? |
src/hooks.ts
Outdated
|
||
function createForkTsCheckerWebpackPluginHooks(): Record<keyof typeof customHooks, SyncHook | AsyncSeriesHook> { | ||
return { | ||
forkTsCheckerServiceBeforeStart: new AsyncSeriesHook([]), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use shorter names now, as it's already scoped to this plugin:
forkTsCheckerServiceBeforeStart: new AsyncSeriesHook([]), | |
serviceBeforeStart: new AsyncSeriesHook([]), |
src/index.ts
Outdated
@@ -156,6 +142,10 @@ class ForkTsCheckerWebpackPlugin { | |||
this.vue = options.vue === true; // default false | |||
} | |||
|
|||
static getHooks(compiler: webpack.Compiler) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static getHooks(compiler: webpack.Compiler) { | |
static getCompilerHooks(compiler: webpack.Compiler) { |
That would be our naming convention, but technically you are free to choose whatever you like.
We have chosen this naming to allow adding hooks for other objects later, i. e. getCompilationHooks
.
@johnnyreilly Will do when I have the time! |
Awesome! |
Hey @liangchunn , I just tried to make your life easier by catching the branch up with upstream changes. For some reason the GitHub UI is reporting conflicting files.... I'm not sure why; it's fine when I build locally. Maybe it's just easier to reapply your changes (with @sokra's feedback) on a new PR. Not sure... Apologies if I've just made things harder... 😢 |
51dec73
to
0faa5d5
Compare
814632f
to
63ba7e3
Compare
I've re-applied all my changes with the current master branch. Hook namingNow for the naming, as @sokra suggested, we could rename the all the hooks since it's now scoped by default: src/hooks.ts
- forkTsCheckerServiceBeforeStart: 'fork-ts-checker-service-before-start',
+ serviceBeforeStart: 'fork-ts-checker-service-before-start',
- forkTsCheckerCancel: 'fork-ts-checker-cancel',
+ cancel: 'fork-ts-checker-cancel',
- forkTsCheckerDone: 'fork-ts-checker-done',
+ done: 'fork-ts-checker-done', Which means that tapping into the plugin's events will change (for webpack 4+): - compiler.hooks.forkTsCheckerDone.tap(...args)
+ const forkTsCheckerHooks = ForkTsCheckerWebpackPlugin.getCompilerHooks(compiler)
+ forkTsCheckerHooks.done.tap(...args) I've introduced a migration section in Tests Failures on node 6There are some issues with the build with node 6 only:
|
First of all, amazing work @liangchunn! To your points:
I think that's fine. This is a major version bump for webpack. It's reasonable that we have the same here.
I think renaming the hooks as suggested by @sokra is a good idea. Particularly if we're going to go for a breaking changes version bump. Let's do it. I maintain https://github.com/johnnyreilly/fork-ts-checker-notifier-webpack-plugin which depends upon this. I'm happy to make the required changes around hook renaming there.
I think it's time to drop support for node 6. webpack 5 drops support for it and the minimum recommended download of nodejs is node 10. Further to that, node 6 is being end of lifed in 3 months time. Can you remove node 6 from the Travis test matrix please? Also could you align the engines section of the
Regarding what version number we should bump the plugin to, I've long felt that it's time this plugin should have a major version number; What do you think? cc @piotr-oles |
I'd fully agree to this. Recently upgraded from |
@johnnyreilly
|
Tremendous work @liangchunn! I've hacked on your branch and:
I think we're pretty good to push this out as an alpha release. Is there anything else you think we should get in there first? Also, I've been thinking about how to upgrade
|
It should be exposed, I messed up 😅. Moved it to a public method in c410927.
You would want to do: import * as forkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin'
forkTsCheckerWebpackPlugin.getCompilerHooks(compiler).tap('...', () => {}) EDIT: I've tried it locally and the tests seem to pass AFAIK there isn't anything left to do, I've tested this against a real project (without tapping into hooks) and everything is working fine for me! |
That's awesome - let's get this out there! Thanks for all your hard work 🌻 |
Should be available on npm now - can you confirm? It's published as |
@alfaproject you might be interested to learn that We can't add it back to the travis test matrix as the project will not build on node 6 due to webpack 5 dependency issues. It runs just fine though as long as you don't use the new "engines": {
"node": ">=6.11.5"
}, |
In
webpack@5
, custom hooks are no longer allowed to be added directly ontothis.compiler.hooks
.WeakMap + static getHooks()
should be used instead (More details here: https://github.com/webpack/webpack/projects/5#card-10390019)This is a WIP, please give feedback on what should be updated.
Changed
static getHooks()
require('webpack').version
when available intest/integration/webpackVersion.js
[email protected]
into CI envResolved
(webpack5): Decide ifRemoved_pluginCompat
should be removed (*)_pluginCompat
(ci): Decide if we should reorderyarn add $WEBPACK $TSLOADER $VUELOADER -D
intravis.yml
(ci): Skip tests fornode6 + webpack@5
Resolved in #169 instead
- [x] (ci): Lint in CI- [x] (lint): Upgrade TSLint and ESLint- [x] (lint): Lint*.ts
and*.js
files- [x] (tests): don't use object spread (node6 does not support this: https://node.green/#ES2018-features-object-rest-spread-properties)(*) I don't really know what_pluginCompat
does, removing it doesn't cause build failures on CI