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

Tolerate absolute filenames? #36

Closed
coreyfarrell opened this issue Apr 17, 2019 · 6 comments · Fixed by #28
Closed

Tolerate absolute filenames? #36

coreyfarrell opened this issue Apr 17, 2019 · 6 comments · Fixed by #28

Comments

@coreyfarrell
Copy link
Contributor

nyc has gotten a report that --nycrc-path does not support absolute paths - true as we use find-up to find the requested configuration file. Currently if CWD is /home/coreyfarrell/test-project and I run findUp.sync('/home/coreyfarrell/nycrc.json', {cwd: process.cwd()}), this will return /home/coreyfarrell/test-project/home/coreyfarrell/nycrc.json. This would be fixed if find-up used path.resolve instead of path.join. Would you be open to this? I can post an implementation including tests.

@sholladay
Copy link
Collaborator

This is already fixed in #28. Feel free to use the fork until we merge it. :)

That said, IMO passing absolute paths to find-up is a bit confusing because it's not clear whether find-up should return the path as-is or whether it will do a search for the filename of the leaf. And if it does a search, does the directory from the absolute path take precedence over the cwd option? It's all a little murky unless you dig into it.

I would recommend short-circuiting the logic to explicitly use the given filepath as-is if it is absolute, for clarity's sake, avoiding find-up altogether.

@sindresorhus
Copy link
Owner

That said, IMO passing absolute paths to find-up is a bit confusing because it's not clear whether find-up should return the path as-is or whether it will do a search for the filename of the leaf. And if it does a search, does the directory from the absolute path take precedence over the cwd option? It's all a little murky unless you dig into it.

Let's document it. I think find-up should return the path as-is if it exists.

@coreyfarrell
Copy link
Contributor Author

@sholladay Yes it looks like your PR will resolve this for us in nyc@15 (that'll be when we drop node.js 6). Do you want to add Fixes #36 to your PR?

@sholladay
Copy link
Collaborator

sholladay commented Apr 19, 2019

Let's document it. I think find-up should return the path as-is if it exists.

Sure, that's reasonable. But what if it doesn't exist at the given path? Do people expect us to immediately return undefined or to search for the basename of that filepath (i.e. what this module is designed to do) under the assumption that the basename is really what the user cares about? Does the nyc team have an opinion on that @coreyfarrell? I think I lean towards the former, but it's worth discussing as I can see people misunderstanding it from glancing at code (without reading the docs).

@coreyfarrell
Copy link
Contributor Author

Other than using path.resolve instead of path.join I don't think findUp should make any special consideration for absolute filenames. Otherwise it would complicate handling of situations like findUp(['/tmp/absolute/filename', 'relative-filename']).

If find-up doesn't find an absolute filename in cwd then it won't find it in path.dirname(cwd), eventually it'll return undefined. I don't think it's very important that cycles are wasted searching up the path for the same absolute filename, this is an edge case and IMO not worth optimizing at the expense of code clarity.

Unrelated but for completeness of discussion, find-up does support finding relative filenames. For example you could have /usr/src/test-project/.github/ISSUE_TEMPLATE and run findUp('.github/ISSUE_TEMPLATE', {cwd: '/usr/src/test-project/test'}). This will find the file one directory up from cwd.

I've opened sholladay#1 to add tests to cover edge cases.

@sindresorhus
Copy link
Owner

Other than using path.resolve instead of path.join I don't think findUp should make any special consideration for absolute filenames.

👍

I don't think it's very important that cycles are wasted searching up the path for the same absolute filename, this is an edge case and IMO not worth optimizing at the expense of code clarity.

👍

rthaut added a commit to rthaut/deviantART-Filter that referenced this issue Jan 23, 2024
requires another patch to @webextension-toolbox/webextension-toolbox due to default config file path not resolving with find-up (sindresorhus/find-up#36 (comment))
rthaut added a commit to rthaut/deviantART-Filter that referenced this issue Jan 23, 2024
requires another patch to @webextension-toolbox/webextension-toolbox due to default config file path not resolving with find-up (sindresorhus/find-up#36 (comment))
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

Successfully merging a pull request may close this issue.

3 participants