fix compilation.compiler not wrapped in callback arguments #116
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi @stephencookdev
First thanks a lot for this fantastic plugin.!I was searching for a way to measure the performance of webpack building, while the built-in ProfilingPlugin is not that straightforward to measure the timing for each plugin & loader, this plugin shows up and I think it is really brilliant.
One thing though, is that when I integrate it into my project I found that it cannot work with html-webpack-plugin@next. It works with html-webpack-plugin v3 though, but I decided to dig in and take a look. (because I'm also using other plugins that require html-webpack-plugin@next)
So if I do not understand this plugin wrong, it's using proxy and reflect to intercept webpack's tabable plugin system. Object such as
compiler
andcompilation
, along with their methods such astap
,tapAsync
and hooks are proxyed, which I think is really clever. Even argument in hook's callback is proxyed, such as argumentcompilation
.The problem lies in how html-webpack-plugin works, https://github.com/jantimon/html-webpack-plugin/blob/master/lib/compiler.js#L203-L218 on
apply
it will save compiler into a cache weakmap (with the key as the compiler, which is already proxyed). However, in it'sthisCompilation
hook https://github.com/jantimon/html-webpack-plugin/blob/master/index.js#L134-L136 , it will search that cache again with the keycompilation.compiler
. ⬅️This is where the problem is from. In SMP,compilation.compiler
in hook callback will return the original compiler object, not the proxyed one. I believe this is because in webpack's code, in it's constructor compilation will have a reference of compiler on being created. https://github.com/webpack/webpack/blob/master/lib/Compiler.js#L852-L854 Therefore, if any plugin is accessingcompilation.compiler
in hooks callback, it will not get the proxied one.Luckily I found that in your code, you have a
wrappedObj
which contains the already proxied objects. So it's possible that we check in the wrappedObjs before returning the raw object forcompilation.compiler
.I extracted the
prevWrapped
logic out into a method calledfindWrappedObj
, and reuse it in the proxy handler for property retrieving on argument.In the issues list I also found that there're some plugins won't work with SMP. I'm not sure if this could help with them. But for html-webpack-plugin@next, you could find how to reproduce it here from this project: https://github.com/NdYAG/smp-html
It would be really great if you could take a look of it, if there're any questions please comment and metion me. I love this plugin and hope that it could work with as many other plugins as possible.