-
-
Notifications
You must be signed in to change notification settings - Fork 283
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
chore: simplify glob usage #789
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. |
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'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[]} |
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.
whats the typedef change here?
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.
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
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 |
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.
Let's avoid it and just add the onlyDirectories
doesn't supported in documentation. It doesn't make sense for our plugin anyway.
This PR contains a:
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 setobjectMode
. 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