-
-
Notifications
You must be signed in to change notification settings - Fork 10
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
Add files
option
#3
Conversation
index.js
Outdated
const getGlob = (fp, ext) => path.join(fp, '**', ext || ''); | ||
const getExt = ext => Array.isArray(ext) ? `*.{${ext.join(',')}}` : `*.${ext}`; | ||
const getPath = fp => fp[0] === '!' ? fp.slice(1) : fp; | ||
const isDirectoryP = pify(isDirectory); |
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.
Instead of using pify
here, just use https://github.com/sindresorhus/path-type instead
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.
Used is-directory
because it doesn't throw
when the path doesn't exist. Could handle it here, but I thought it was cleaner not to.
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.
path-type
doesn't throw either, it just returns a boolean.
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.
Yes, it does. You aren't handling ENOENT
anywhere. Tests are failing when using it:
convert directories to glob - async
Rejected promise returned by test. Reason:
Error {
code: 'ENOENT',
errno: -2,
path: 'foo/**',
syscall: 'stat',
message: 'ENOENT: no such file or directory, stat \'foo/**\'',
}
If can do a PR if you want.
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.
Oh. That is definitely not the intention. PR would be lovely :)
index.js
Outdated
module.exports = (input, opts) => { | ||
return Promise.all(arrify(input).map(x => isDirectoryP(getPath(x)) | ||
.then(isDir => isDir ? getGlob(x, opts) : x))) | ||
.then(globs => globs.reduce((a, b) => a.concat(b), [])); |
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.
[].concat.apply([], globs);
instead?
How does the |
It doesn't atm. Any ideas? |
We have to decide whether the extension is after the first or last dot. |
The last dot might be a better default since it'll cover most cases except |
I would go with the last dot too. I don't think it should be configurable. |
Alright. What's your thoughts on sindresorhus/globby#46 (comment) to increase performance?
|
I don't think it's worth it. You don't usually have a lot of glob patterns, and few fs.stat checks are pretty cheap relatively to everything else involved in globbing. Using a regex will have ambiguous cases. The only way to be totally sure is to actually check the disk. |
Alright, then I think this is good to 🚢 ? |
👍 |
Probably room for some improvement here and there, but it's functioning at least :). This is so we can use this in sindresorhus/globby#33.
@sindresorhus @SamVerschueren @schnittstabil