Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

refactor: update to new plugin system and API's #707

Merged
merged 23 commits into from
Feb 14, 2018

Conversation

horo42
Copy link

@horo42 horo42 commented Jan 28, 2018

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.

@jsf-clabot
Copy link

jsf-clabot commented Jan 28, 2018

CLA assistant check
All committers have signed the CLA.

@michael-ciniawsky michael-ciniawsky changed the title Add webpack beta0 support, fix most deprecation warnings refactor: update to new plugin system and API's Jan 28, 2018
@michael-ciniawsky michael-ciniawsky added this to the 4.0.0 milestone Jan 28, 2018
Copy link
Member

@michael-ciniawsky michael-ciniawsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@horo42 Thx

@TheLarkInn
Copy link

Wow! Thank you!!!

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, wow, thanks!

const parentCount = Array.from(
chunk.groupsIterable,
(chunkGroup) => chunkGroup.getParents().length
).reduce((current, sum) => current + sum);

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.

Copy link
Author

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.

Copy link
Member

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);
}

Copy link
Author

@horo42 horo42 Jan 30, 2018

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.

Copy link
Member

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

Copy link
Member

@michael-ciniawsky michael-ciniawsky Feb 8, 2018

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 :)

@horo42
Copy link
Author

horo42 commented Jan 30, 2018

Test output: https://pastebin.com/z5FiXqk7

I'm not entirely sure where to look for these bugs. Guidance is more than welcome.
Will keep looking in my free time.

@michael-ciniawsky
Copy link
Member

michael-ciniawsky commented Feb 2, 2018

@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 :)

@TheLarkInn
Copy link

@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.

@michael-ciniawsky
Copy link
Member

Once the requested changes by @ooflorent are addressed I will cut an alpha release with this PR so folks can start trying it out and outstanding fixes can simply follow up

src/index.js Outdated
(callback) => {
extractedChunks.forEach((extractedChunk) => {
if (extractedChunk.getNumberOfModules()) {
extractedChunk.sortModules((a, b) => {
Copy link
Member

@michael-ciniawsky michael-ciniawsky Feb 8, 2018

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'
Copy link
Member

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

Copy link
Member

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 ?

Copy link
Author

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';
Copy link
Member

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) {
Copy link
Author

@horo42 horo42 Feb 10, 2018

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.

Copy link
Member

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);
Copy link
Author

@horo42 horo42 Feb 10, 2018

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.

Copy link
Member

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 :)

@horo42
Copy link
Author

horo42 commented Feb 10, 2018

🎉 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,
Copy link
Member

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' }

Copy link
Member

@michael-ciniawsky michael-ciniawsky left a 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 🎉

@TheLarkInn
Copy link

@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();

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.

Copy link
Author

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!

Copy link
Member

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

@michael-ciniawsky michael-ciniawsky merged commit 9e12b8e into webpack-contrib:next Feb 14, 2018
michael-ciniawsky pushed a commit that referenced this pull request Feb 14, 2018
@michael-ciniawsky
Copy link
Member

https://github.com/webpack-contrib/extract-text-webpack-plugin/releases/tag/v4.0.0-alpha.0 🎉

joshwiens pushed a commit that referenced this pull request Apr 2, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants