Implement fs.glob, fs.globSync, and fs/promises.glob#6378
Implement fs.glob, fs.globSync, and fs/promises.glob#6378jasnell merged 7 commits intocloudflare:mainfrom
Conversation
|
All contributors have signed the CLA ✍️ ✅ |
|
I have read the CLA Document and I hereby sign the CLA |
|
Hey @fraidev! thank you for this! I've done a first pass look over and have asked the AI agent to review also.. it should post it's findings in a moment. How closely does this follow the node.js implementation? (I haven't looked at it in a while) Is it a straight up port of the original or did you reimplement? The main reason I ask is that if it is a straight port over, we might need to carry over the Node.js copyright/license detail in the header of the new file(s). |
jasnell
left a comment
There was a problem hiding this comment.
Review Summary
Note: This review was generated by an AI assistant (Claude) and may contain inaccuracies. Please evaluate each suggestion on its merits.
Findings (6):
- [HIGH]
excludetype handling — unsafe cast incompileExcludewhenexcludeis a user function - [MEDIUM]
**in middle of exclude pattern doesn't match zero segments (a/**/bwon't matcha/b) - [MEDIUM]
walkGlobhas unbounded recursion depth — no depth guard - [MEDIUM] Non-null assertions (
!) used extensively — violates ts-style convention - [MEDIUM] Missing callback guard in
fs.glob— throws when callback omitted - [LOW] Copyright year says 2017-2022 in new file
Hey @jasnell! This is a reimplementation, not a port. Node.js uses |
|
@jasnell is there a way to run CI for a non-Cloudflare member? |
|
Just did. Internal_build will fail but I'll run that one manually |
Great! I fixed ESLint errors. I think that we need one more run. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6378 +/- ##
========================================
Coverage 70.79% 70.79%
========================================
Files 427 427
Lines 117724 117869 +145
Branches 18909 18935 +26
========================================
+ Hits 83338 83446 +108
- Misses 23132 23154 +22
- Partials 11254 11269 +15 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Hi @jasnell, this PR is ready for another review. It was passing all tests (except Internal_build). |
|
@fraidev ... yeah, I'm just a bit backlogged on a number of PR review items. I've got this on my agenda to fully review either later today or tomorrow |
|
@fraidev ... can I ask you to remove the merge commit and instead rebase on |
jasnell
left a comment
There was a problem hiding this comment.
Correctness & Performance Analysis
Note: This review was generated by an AI assistant (Claude) and may contain inaccuracies. Please evaluate each suggestion on its merits.
Findings (5):
- [MEDIUM]
splitTopLevellost backslash escape handling when converting tofor...of - [MEDIUM]
segmentToRegexStrdoesn't escape{and}— patterns likea{3}silently produce wrong matches - [HIGH]
..traversal guard uses length comparison instead of prefix check - [MEDIUM] Consecutive
**segments not collapsed — potential exponential blowup - [MEDIUM]
segmentToRegexrecompiled on every recursivewalkGlobcall
|
|
||
| // Handle '..' — go up one directory (but don't escape cwd) | ||
| if (seg === '..') { | ||
| if (currentAbsPath === cwd || currentAbsPath.length <= cwd.length) { |
There was a problem hiding this comment.
[HIGH] The length comparison currentAbsPath.length <= cwd.length is not a safe containment check. While it works today because currentAbsPath is always built by appending to cwd, it's brittle — it would silently do the wrong thing if the code were refactored to allow other path construction.
Consider using a prefix check instead:
| if (currentAbsPath === cwd || currentAbsPath.length <= cwd.length) { | |
| if (currentAbsPath === cwd || !currentAbsPath.startsWith(cwd + '/')) { |
There was a problem hiding this comment.
Replaced currentAbsPath.length <= cwd.length with !currentAbsPath.startsWith(cwd + '/')
Implements the Node.js fs.glob APIs that were previously stubbed with ERR_UNSUPPORTED_OPERATION. Uses a custom glob-to-regex pattern matcher instead of the minimatch library which is unavailable in the Workers runtime. Closes cloudflare#5416
756e1b9 to
97e8aa8
Compare
Sure, done |
|
Not quite sure what's happening with the CI right now. I'll try to run it again tomorrow and hopefully the issues are transient. |
oh, I think it's just lint. I think I fixed it |
This comment was marked as outdated.
This comment was marked as outdated.
|
Manual testing on the internal-build is green. Merging! Thank you @fraidev ! |
Implements the Node.js fs.glob APIs that were previously stubbed with ERR_UNSUPPORTED_OPERATION. Uses a custom glob-to-regex pattern matcher.
Closes #5416