sindresorhus / find-up

Find a file or directory by walking up parent directories
MIT License
582 stars 40 forks source link

Search in upper directories with depth based on param #47

Open makbol opened 5 years ago

makbol commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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})
})