Skip to content
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

Update webpack to version 5 #195

Merged
merged 11 commits into from
Apr 10, 2021
Merged

Update webpack to version 5 #195

merged 11 commits into from
Apr 10, 2021

Conversation

strootje
Copy link
Contributor

@strootje strootje commented Jan 7, 2021

Updated to webpack version 5.
I had to drop support for webpack version 3 and node < 10.

@codecov-io
Copy link

codecov-io commented Jan 7, 2021

Codecov Report

Merging #195 (6d8a232) into master (021d2b6) will increase coverage by 1.13%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master      #195      +/-   ##
===========================================
+ Coverage   98.86%   100.00%   +1.13%     
===========================================
  Files           1         1              
  Lines          88        76      -12     
  Branches       30        27       -3     
===========================================
- Hits           87        76      -11     
+ Misses          1         0       -1     
Impacted Files Coverage Δ
src/clean-webpack-plugin.ts 100.00% <100.00%> (+1.13%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 64c4241...6d8a232. Read the comment docs.

@johnagan
Copy link
Owner

johnagan commented Jan 8, 2021

wow! great work here and thank you for the contribution 👏 I'm not currently using webpack to validate we're all good here, but the code changes look good. Would be great to get some other eyes on this before bringing it in. cc @chrisblossom

@strootje
Copy link
Contributor Author

strootje commented Jan 9, 2021

I'm not really sure how to fix the coverage report. I've added some code to make typescript happy (for selecting the related assets) but I'm not really sure how to trigger that which webpack. Tips are appreciated

@strootje strootje marked this pull request as ready for review January 12, 2021 06:49
package.json Outdated
},
"dependencies": {
"@types/webpack": "^4.4.31",
"@types/webpack": "^4.41.25",

Choose a reason for hiding this comment

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

You may want to remove this dependency since webpack 5 has it's own typescript types which conflict with these types. This is also the reason why a lot of people have troubles using webpack 5 with typescript because plugins stil have this package as a dependency.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How will this affect people not using webpack 5? Does that even matter?

Choose a reason for hiding this comment

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

Think you need to make a decision if you want to typecheck the webpack 5 code or the webpack 4 code. if you want to keep type checking webpack 4 code you should move this to dev dependencies so webpack 5 users won't have conflicts.

But i'm not totally sure about this. In my recent projects I only supported webpack 5 from a certain version and not both at the same time.

@djcsdy
Copy link

djcsdy commented Feb 10, 2021

import { Compiler, Stats, compilation as compilationType } from 'webpack';
declare type Compilation = compilationType.Compilation;

should also be changed to

import { Compiler, Stats, Compilation} from 'webpack';

for compatibility with type declarations provided by webpack 5, see #193.

@strootje
Copy link
Contributor Author

@djcsdy I think I did that already. Could you specify in which file I've missed it?

@djcsdy
Copy link

djcsdy commented Feb 11, 2021

@strootje My mistake, you're right, it's already done. I must have been looking at the wrong commit.

@alpadev
Copy link

alpadev commented Mar 5, 2021

The README.md still mentions

NOTE: Node v8+ and webpack v3+ are supported and tested.

Just to mention it, the zero configuration doesn't work anymore with this plugin and v5 (probably the reason why you had to limit that test case to webpack v4). Mentioned the reason for this here: #181 (comment).

Comment on lines 241 to 262
const assets =
stats.toJson(
{
assets: true,
},
true,
).assets || [];
const assetList = assets.map((asset: { name: string }) => {
stats.toJson({
assets: true,
}).assets || [];

const relatedAssets = assets
.map((asset) => {
return (
(asset.related &&
Array.isArray(asset.related) &&
asset.related) ||
[]
);
})
.reduce((previousAssets, currentAssets) => {
return [...previousAssets, ...currentAssets];
}, []);

const allAssets = [...assets, ...relatedAssets];
const assetList = allAssets.map((asset) => {
return asset.name;
});
Copy link

Choose a reason for hiding this comment

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

I think you can just use

const assetList = Object.keys(stats.compilation.assets);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion. This seems to be working and let's me throw almost all my code away! 👍

@alpadev
Copy link

alpadev commented Mar 6, 2021

I'm not really sure how to fix the coverage report. I've added some code to make typescript happy (for selecting the related assets) but I'm not really sure how to trigger that which webpack. Tips are appreciated

I think the reason for this is that you removed some code which changed the ratio between tested and untested code. Looks like there is only one line/case that isn't covered by tests see https://codecov.io/gh/johnagan/clean-webpack-plugin/src/b2dccbbcd626a151772332ec1ba567473458a8c2/src/clean-webpack-plugin.ts#L340

You can try changing it to

/* istanbul ignore next */
throw error;

I checked del/rimraf and looks like they handle errors quite well so I'd say it's not that easy to build a test for this.

@strootje
Copy link
Contributor Author

@chrisblossom and @johnagan any chance for a rereview?

@johnagan
Copy link
Owner

@strootje nice work! I'll merge it in 🎉

@johnagan johnagan merged commit 8190568 into johnagan:master Apr 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants