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

Add stopDir functionality #17

Closed
CVarisco opened this issue Jan 17, 2018 · 6 comments
Closed

Add stopDir functionality #17

CVarisco opened this issue Jan 17, 2018 · 6 comments

Comments

@CVarisco
Copy link

Hi @sindresorhus !

Thanks a lot to share with us your little tool.
I used your library in one of my side projects and I added the capability to the user to stop the find-up process if the last directory is equal to the stopDir passed like an option.

I'll open a PR to add the functionality on the original library.
Feel free to dismiss my PR on this project if you think that is useless 🙂

Have fun coding 🌮

@sholladay
Copy link
Collaborator

@CVarisco could you please elaborate on your use case (what exactly you used it for and why), so that we can better understand how common the need might be and so we can have the opportunity to propose alternative solutions? Thanks!

@CVarisco
Copy link
Author

Hi @sholladay,

sure :)
I'm working on this: CVarisco/create-component-app#61
And one solution is to use find-up but only in the project directory.

I hope that is enough to explain what I'm looking for 👍

@sholladay
Copy link
Collaborator

That issue's title mentions searching all the way to / (the root directory). But I think I understand. You want to limit the scope of where config files can be found, right?

I'd like to better understand why we should limit the search, though. Maybe there is a more appropriate algorithm for you. For example, I once wanted to search until a file does not exist, but after thinking about it a bit deeper, I ended up creating find-down. That worked out much better; it's simpler, faster, and more reliable for finding things high up in the tree, such as the user's code-dir.

In your case, is there an actual problem you foresee with allowing the search to continue upwards outside of the project directory or is this just a performance optimization?

@CVarisco
Copy link
Author

The feature should search from a child directory (from inside to outside) one file (in this case the config file).
I don't need to go more up then the project root, because of course the file doesn't exist out of the project root.
So, there is no a problem, but a reason to stop the search on a certain folder.

I hope that is clear why I thought about it 👍

@kevva
Copy link

kevva commented Feb 23, 2018

It makes sense, but if you know that your file will exist within a directory, why not check it directly?

@sholladay
Copy link
Collaborator

Closing since we decided to do this a bit differently, in order to solve multiple use cases.

See #21 and the discussion in PR #18.

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

No branches or pull requests

3 participants