-
Notifications
You must be signed in to change notification settings - Fork 18
refactor: remove glob #504
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
base: main
Are you sure you want to change the base?
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #504 +/- ##
==========================================
+ Coverage 74.60% 75.13% +0.52%
==========================================
Files 112 114 +2
Lines 10700 10807 +107
Branches 722 736 +14
==========================================
+ Hits 7983 8120 +137
+ Misses 2714 2684 -30
Partials 3 3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
ovflowd
left a comment
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.
Do all LTS versions of Node now support glob?
| const loadFiles = searchPath => { | ||
| const resolvedFiles = globSync(searchPath).filter( | ||
| const loadFiles = async searchPath => { | ||
| const resolvedFiles = globSync(searchPath); |
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.
nit: let's use the async variant
| @@ -1,9 +1,9 @@ | |||
| 'use strict'; | |||
|
|
|||
| import { globSync } from 'node:fs'; | |||
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.
Ditto
As of October, yes |
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.
Pull request overview
This PR attempts to remove the external glob dependency and replace it with Node.js's native fs.globSync() function (available in Node.js v22+), while also adding unit tests for the loader modules and fixing an async/await bug in the JavaScript loader.
Key Changes:
- Replaced
import { globSync } from 'glob'withimport { globSync } from 'node:fs' - Made
loadFiles()functions properly async withPromise.all()to correctly handle concurrent file reads - Added JSDoc
@returns {Promise<VFile[]>}documentation for return types - Added comprehensive unit tests for both markdown and JavaScript loaders
- Removed
globpackage from dependencies
Critical Issue: The native Node.js fs.globSync() API is incompatible with the glob package's globSync() - specifically, the native version only accepts a single string pattern, while the code (and tests) are written to handle arrays of patterns. This will cause runtime failures in production.
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| src/loaders/markdown.mjs | Replaced glob import with node:fs globSync and added return type documentation - has API incompatibility issues |
| src/loaders/javascript.mjs | Replaced glob import, fixed async/await Promise handling bug, added return type documentation - has API incompatibility issues |
| src/loaders/tests/markdown.test.mjs | New test file with mocked globSync - mock doesn't match real API |
| src/loaders/tests/javascript.test.mjs | New test file with mocked globSync |
| src/generators/ast-js/index.mjs | Added await for now-async loadFiles call |
| package.json | Removed glob dependency |
| npm-shrinkwrap.json | Removed glob and related transitive dependencies |
Files not reviewed (1)
- npm-shrinkwrap.json: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -1,9 +1,9 @@ | |||
| 'use strict'; | |||
|
|
|||
| import { globSync } from 'node:fs'; | |||
Copilot
AI
Dec 2, 2025
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.
The import { globSync } from 'node:fs' is only available in Node.js v22.0.0 and later. While the project uses Node.js 22 per .nvmrc, consider documenting this Node.js version requirement in the package.json engines field to prevent issues for users on older versions:
"engines": {
"node": ">=22.0.0"
}| globSync: (/** @type {string[]} */ path) => { | ||
| if (isDeepStrictEqual(path, ['ignore.md'])) { | ||
| return ['/fake/path/file2.md']; | ||
| } | ||
| return [ | ||
| '/fake/path/file1.md', | ||
| '/fake/path/file2.md', | ||
| '/fake/path/not-a-md-file.txt', | ||
| ]; | ||
| }, | ||
| }, |
Copilot
AI
Dec 2, 2025
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.
The mock implementation accepts an array parameter (string[]), but the native Node.js fs.globSync() only accepts a single string pattern, not an array. This mock doesn't match the actual API behavior, which could hide bugs. The mock should match the real API signature:
globSync: (pattern) => {
if (pattern === 'ignore.md') {
return ['/fake/path/file2.md'];
}
// handle string pattern
return [...];
}Also, the test on line 42 calls loadFiles(['*.md']) with an array, but this won't work with the real fs.globSync implementation.
| ]; | ||
|
|
||
| const loader = createLoader(); | ||
| const vfiles = await loader.loadFiles(['*.md']); |
Copilot
AI
Dec 2, 2025
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.
Test calls loadFiles(['*.md']) with an array, but according to the JSDoc in the source, searchPath should be Array<string>. However, the native Node.js fs.globSync() only accepts a single string pattern, not an array. This test would pass with the mock but fail in production. Consider using a string pattern instead: loadFiles('*.md')
| const vfiles = await loader.loadFiles(['*.md']); | |
| const vfiles = await loader.loadFiles('*.md'); |
|
|
||
| it('should ignore specified files', async () => { | ||
| const loader = createLoader(); | ||
| const vfiles = await loader.loadFiles(['*.md'], ['ignore.md']); |
Copilot
AI
Dec 2, 2025
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.
Test calls loadFiles(['*.md'], ['ignore.md']) with arrays, but the native Node.js fs.globSync() only accepts a single string pattern, not an array. This test would pass with the mock but fail in production. Consider using string patterns instead: loadFiles('*.md', 'ignore.md')
| * Loads API Doc files and transforms it into VFiles | ||
| * | ||
| * @param {Array<string>} searchPath A glob/path for API docs to be loaded | ||
| * @param {Array<string> | undefined} [ignorePath] A glob/path of files to ignore |
Copilot
AI
Dec 2, 2025
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.
The JSDoc indicates searchPath is Array<string>, but the native Node.js fs.globSync() expects a string pattern as its first argument, not an array (unlike the glob package which could handle arrays). This will cause a runtime error when an array is passed to loadFiles().
Consider either:
- Updating the JSDoc to reflect that
searchPathshould be a string:@param {string} searchPath - Or updating the implementation to handle arrays by iterating over patterns
| const loadFiles = searchPath => { | ||
| const resolvedFiles = globSync(searchPath).filter( | ||
| const loadFiles = async searchPath => { | ||
| const resolvedFiles = globSync(searchPath); |
Copilot
AI
Dec 2, 2025
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.
Similar issue: The JSDoc indicates searchPath can be string | Array<string>, but the native Node.js fs.globSync() expects only a string pattern as its first argument (unlike the glob package). When an array is passed, it will cause a runtime error.
Consider either:
- Updating the JSDoc to only accept string:
@param {string} searchPath - Or updating the implementation to handle arrays by iterating over patterns
| const resolvedFiles = globSync(searchPath); | |
| let resolvedFiles = []; | |
| if (Array.isArray(searchPath)) { | |
| for (const pattern of searchPath) { | |
| resolvedFiles.push(...globSync(pattern)); | |
| } | |
| } else { | |
| resolvedFiles = globSync(searchPath); | |
| } |
Node.js 20 does not. |
Indeed, Node.js 20 is not EoL yet |
|
Ahh, I thought it did, apologies |
Uh, should I close this PR then? |
Description
Removes
globdependency and create unit testsValidation
https://gist.github.com/araujogui/3b3f8d4a597dce9615607a4b2b22660d
Related Issues
Check List
node --run testand all tests passed.node --run format&node --run lint.