-
Notifications
You must be signed in to change notification settings - Fork 513
refactor: update to new plugin system and API's #707
Conversation
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.
@horo42 Thx
Wow! Thank you!!! |
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.
Oh, wow, thanks!
src/lib/helpers.js
Outdated
const parentCount = Array.from( | ||
chunk.groupsIterable, | ||
(chunkGroup) => chunkGroup.getParents().length | ||
).reduce((current, sum) => current + sum); |
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.
This was giving me an error:
TypeError: Reduce of empty array with no initial value
at Array.reduce (<anonymous>:null:null)
at isInitialOrHasNoParents (/home/sciyoshi/workspace/web/webpack/extract-text-webpack-plugin/dist/lib/helpers.js:15:102)
Changing the line to ).reduce((current, sum) => current + sum, 0);
fixed it.
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.
Thank you! I noticed that just yesterday, along with failing integration test. I didn’t push yet because I couldn’t make it pass everything.
I’ll fix and push the obvious low hanging fruits I missed and will keep working on the tests.
Expect an update ~12 hours later.
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.
@horo42 also can you add tests around this?
src/index.js
Outdated
if (chunkGroup instanceof Entrypoint) { | ||
extractedChunk.addGroup(chunkGroup); | ||
} | ||
|
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.
We add the ChunkGroups to the extracted chunk and the _children and _parents sets belong to ChunkGroup now. Please confirm that the commented lines below are unnecessary.
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.
I can't 💯 atm 😛, but likely that this can be removed with the introduction of ChunkGroups
now
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.
Please leave everything commented for now, I will tinker with this code once the PR landed :)
Test output: https://pastebin.com/z5FiXqk7 I'm not entirely sure where to look for these bugs. Guidance is more than welcome. |
@horo42 I will chime in deeper into this PR in a few days, feel free to leave comments/questions as so see fit in the meantime and I will try to work through them then :) |
@michael-ciniawsky @sokra @ooflorent would one of you give this a quick pass rereview? I'd like to merge this to next branch and have a -next build shipped for this if theres no blockers on it. |
Once the requested changes by @ooflorent are addressed I will cut an |
src/index.js
Outdated
(callback) => { | ||
extractedChunks.forEach((extractedChunk) => { | ||
if (extractedChunk.getNumberOfModules()) { | ||
extractedChunk.sortModules((a, b) => { |
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.
sortModules
is deprecated aswell, not to important though (leave it if it anything else causes failures) but if you can refactor it to use a standard Array.prototype.sort
instead it would be great 👍. Maybe chunk.getModules().sort()
works here
appveyor.yml
Outdated
@@ -7,13 +7,13 @@ init: | |||
environment: | |||
matrix: | |||
- nodejs_version: '8' | |||
webpack_version: latest | |||
webpack_version: '4.0.0-beta.0' |
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.
Please don't alter this, we have a boilerplate package (webpack-defaults
) which automatically updates these files
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.
What is not working here atm ?
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.
Sorry about that 😅 I'll revert that change.
src/loader.js
Outdated
@@ -8,16 +8,18 @@ import SingleEntryPlugin from 'webpack/lib/SingleEntryPlugin'; | |||
import LimitChunkCountPlugin from 'webpack/lib/optimize/LimitChunkCountPlugin'; | |||
|
|||
const NS = path.dirname(fs.realpathSync(__filename)); | |||
const pluginName = 'ExtractTextPlugin'; |
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.
const plugin = { name: 'ExtractTextPlugin' }
src/index.js
Outdated
for (const chunkModule of chunk.modulesIterable) { | ||
let moduleSource = chunkModule.source(); | ||
|
||
if (moduleSource instanceof CachedSource) { |
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.
During my testing I noticed that async imports are CachedSource module instances caching a ReplaceSource instance, which breaks the plugin.
The issue probably lies elsewhere, this is a temporary fix.
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.
Please add a comment for this to the code :)
src/index.js
Outdated
new OrderUndefinedError(b.getOriginalModule()) | ||
); | ||
} | ||
return getOrder(a, b); |
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.
The getOrder helper function uses the underlying index2 property of modules. Unfortunately this property seems to be set by webpack after sealing and apparently sealing happens after the additionalAssets hook (where the sorting takes place) because accessing index2 yielded null every time.
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.
Please add a comment for this to the code :)
🎉 Tests: 1 failed, 37 passed, 38 total The only remaining failing test is the CSS import order test case. I guess it fails because the test assumes a depth first order and webpack does it breadth first. |
src/loader.js
Outdated
// a child compiler so we don't spawn other child compilers from there. | ||
childCompiler.hooks.thisCompilation.tap(plugin.name, (compilation) => { | ||
compilation.hooks.normalModuleLoader.tap( | ||
plugin.name, |
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 can just pass the {Object}
here, since in theory plugin
could contain { name: 'MyPlugin', before: 'SomePlugin', after: 'SomePlugin' }
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.
One nitpick and please add comments to temporary fixes/workarounds, so we don't miss them. This is great work and I would like to merge this as soon as possible and release and alpha
so this can be tested by others 🎉
@michael-ciniawsky Looks like changes have been added. Are these enough to ship alpha? |
}, this); | ||
|
||
for (const chunkModule of chunk.modulesIterable) { | ||
let moduleSource = chunkModule.source(); |
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.
Seems this code causes runtime error when chunkModule is ConcatenatedModule
instance (https://github.com/webpack/webpack/blob/master/lib/optimize/ConcatenatedModule.js#L370). ConcatenatedModule
's source
function requires dependencyTemplate and runtimeTemplate parameters.
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.
Can you please share the code that causes this runtime error when compiled? If the code isn’t public, could you please try removing as much code as possible so as to still exit with a runtime error?
Thanks!
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.
@log2-hwan Please open an issue about this with some logs if possible
The plugin stopped working with webpack 4 because of breaking changes. I hacked away at it for a couple of hours and managed to get it to build without errors.
I haven't seen a lot of activity here, so I figured I'd share my work and maybe spare someone some time.