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

chore: simplify glob usage #789

Merged
merged 6 commits into from
Oct 30, 2024

Conversation

benmccann
Copy link
Contributor

This PR contains a:

  • bugfix
  • new feature
  • code refactor
  • test update
  • typo fix
  • metadata update

Motivation / Use-Case

I started looking at implementing #788 and noticed that some of the glob usage here was more complicated than it needed to be.

The first thing that was being done with the glob results was to check if it's a file. However, globby has an onlyFiles option that we can use to avoid the need for that check. After that's done, there's no longer a need to set objectMode. Thus, instead of getting back an object, we can simply receive back a string, which is both simpler and better for performance.

Breaking Changes

n/a

Additional Info

I may follow up with another PR to switch to tinyglobby. However, I thought it was better to separate those two refactorings to keep the PRs small and make it easier to debug if there are any unexpected issues

Copy link

codecov bot commented Oct 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.48%. Comparing base (a20dedd) to head (6fde592).
Report is 14 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #789      +/-   ##
==========================================
+ Coverage   90.55%   91.48%   +0.92%     
==========================================
  Files           2        2              
  Lines         413      411       -2     
  Branches      120      117       -3     
==========================================
+ Hits          374      376       +2     
+ Misses         38       34       -4     
  Partials        1        1              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@evenstensberg evenstensberg left a comment

Choose a reason for hiding this comment

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

I've enabled the CI's. If some tests fail we need to address those. I also want to add some more tests that verifies the changes.

@@ -407,12 +408,14 @@ class CopyPlugin {
logger.log(`begin globbing '${glob}'...`);

/**
* @type {GlobEntry[]}
* @type {string[]}
Copy link
Member

Choose a reason for hiding this comment

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

whats the typedef change here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

objectMode: true changes the return type from the default string[] to GlobEntry[]. Since we've removed objectMode: true we can go back to string[], which is simpler and has better performance

@benmccann
Copy link
Contributor Author

This code is quite well covered with tests: https://github.com/webpack-contrib/copy-webpack-plugin/blob/master/test/globOptions-option.test.js

No test changes were necessary since the code is equivalent, but the tests did ensure that things work the same even when passing some pretty weird combinations of options. Let me know if there's something specific that you think should be covered with tests though

src/index.js Outdated
*/
let globEntries;

try {
globEntries = await globby(glob, globOptions);
globEntries = globOptions.onlyDirectories
Copy link
Member

@alexander-akait alexander-akait Oct 30, 2024

Choose a reason for hiding this comment

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

Let's avoid it and just add the onlyDirectories doesn't supported in documentation. It doesn't make sense for our plugin anyway.

@alexander-akait alexander-akait merged commit a146720 into webpack-contrib:master Oct 30, 2024
17 checks passed
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.

3 participants