Skip to content
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

Search in upper directories with depth based on param #47

Open
makbol opened this issue Sep 19, 2019 · 2 comments
Open

Search in upper directories with depth based on param #47

makbol opened this issue Sep 19, 2019 · 2 comments

Comments

@makbol
Copy link

makbol commented Sep 19, 2019

While walking up recursively check also subdirectories for a searched file. Depth is set by param.

findUp('findme.js', { subdirs: true, depth: 1 })

/
└── Users
    └── ham
        ├── eggs
             └── findme.js
        └── foo
            └── bar
                ├── baz
                └── example.js

I can offer help with that if you are open for PRs.

@sholladay
Copy link
Collaborator

If you expect findme.js to be inside of a directory named eggs, then you can do findUp('eggs/findme.js') and it will find which level of the tree it is at.

But yeah, if you need actual recursive search of only a filename, then we don't currently have first-class support for thst.

For now, you could certainly use a matcher function to do it.

I'm not a huge fan of exposing this as an option, but I think I would support having a built-in recursive search helper function, which you would pass to findUp as a matcher. That would make it a bit easier to combine with other use cases.

@sindresorhus
Copy link
Owner

I'm not a huge fan of exposing this as an option, but I think I would support having a built-in recursive search helper function, which you would pass to findUp as a matcher. That would make it a bit easier to combine with other use cases.

👍 Something like:

await findUp(async directory => {
	return findUp.down('findme.js', {cwd: directory, depth: 1})
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants