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 ability to specify if looking for file or directory, only match files by default #40
Conversation
By default directories will no longer match. Fixes #33
index.d.ts
Outdated
@@ -8,6 +8,22 @@ declare namespace findUp { | |||
readonly cwd?: string; | |||
} | |||
|
|||
interface FullOptions extends Options { |
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 don't know TypeScript that well, could this be imported from locate-path
(and if it can should it)?
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.
You can import it at line 1:
import {Options as LocatePathOptions} from 'locate-path';
And then extend it on line 2:
interface Options extends LocatePathOptions {
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.
Actually Options
is for using a matcher
function where only cwd
is accepted.
For the normal mode technically locatePath.AsyncOptions is supported, though I'm not sure we want TS to allow concurrency
and preserveOrder
to be used? For now my patch is using locatePath.AsyncOptions but can easily be switched to locatePath.Options.
Also instead of extending the locate-path
options I just directly used them since this module does not add any new options.
Hmm, just started thinking; when using // @sholladay |
I was assuming that the matcher would deal with restricting the type, possibly by wrapping locatePath. Adapted from the test added in #28: function matchUnicornParentPath(options = {}) {
return async (cwd) => {
const hasUnicorns = await locatePath(['unicorns.png'], { ...options, cwd});
return hasUnicorns && cwd;
};
}
console.log(await findUp(matchUnicornParentPath({allowSymlinks: false})); |
But is there any point in that flexibility? I can think of no reason to want either file or directory. Everything would be a lot simpler if the user could just define that upfront in the options like the normal |
The normal findUp is adequate for my needs so I can't speak to the need for flexibility but the example matcher I gave is only capable of returning a directory (or undefined). I think it would be convoluted if this matcher failed to work without giving |
Personally, I am fine with it either way. I have never needed the flexibility mentioned above, however my thinking has been that the matcher function is responsible for the implementation details of how to match, hence the name, and in that case, That said, I also cannot think of a use case where it would be a problem for |
By default directories will no longer match.
Fixes #33