-
-
Notifications
You must be signed in to change notification settings - Fork 480
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
Globstar pattern returns an empty string as an element of the results array #519
Comments
This is by design. That empty string is a valid result. Globstar matches directories as well as files, and You could argue, I guess, that the first globstar portion should not match the cwd, but that's a quirk of bash that I didn't copy, since node-glob normalizes all "empty" portions at the start of the pattern, so const ng = require('glob');
// MaxDepth option only for shortening the list of results
const entries = ng.globSync('**', { maxDepth: 1, dotRelative: true });
console.dir(entries, { colors: true });
|
I think this is a very inconvenient solution for the end user. An empty string cannot be used in many standard methods for working with the file system. > fs.readdir('')
Uncaught:
TypeError [ERR_INVALID_CALLBACK]: Callback must be a function. Received undefined
at __node_internal_captureLargerStackTrace (node:internal/errors:465:5)
at new NodeError (node:internal/errors:372:5)
at __node_internal_ (node:internal/validators:224:11)
at makeCallback (node:fs:186:3)
at Object.readdir (node:fs:1369:14) {
code: 'ERR_INVALID_CALLBACK'
}
> fs.lstatSync('')
Uncaught Error: ENOENT: no such file or directory, lstat
at Object.lstatSync (node:fs:1529:3) {
errno: -2,
syscall: 'lstat',
code: 'ENOENT'
} And every time the user will have to exclude this element from the results array. And, yeap, makes sense with the options that you mentioned above. |
Hm. Maybe I could have |
Someone else pinged me about the same thing, so just further validation that this is legitimately confusing. Landed in 10.1.0, |
Sorry to keep you waiting. I keep thinking that in most cases this is extra information for the user, but I have a similar request in fast-glob (mrmlnc/fast-glob#47) and I am also going to implement it in the near future. |
What the problem?
The
**
pattern returns an empty string as an element of the results array.Steps to reproduce
Actual behaviour
Expected behavioud
[ - '', 'tsconfig.json', 'src', 'package.json', 'out', 'node_modules', 'index.js', 'herebyfile.mjs', 'fixtures', 'README.md', 'LICENSE' ]
The text was updated successfully, but these errors were encountered: