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

API to locate, but not load, config files #176

Closed
cspotcode opened this issue Mar 2, 2019 · 4 comments
Closed

API to locate, but not load, config files #176

cspotcode opened this issue Mar 2, 2019 · 4 comments

Comments

@cspotcode
Copy link

Coming from #172

It would be nice to use cosmiconfig to locate but not load a config file. This mechanism already exists internally but is not part of the API.

Ideally the API will allow requesting candidate files one at a time. If the first candidate should be skipped, the next is requested. This behavior already exists internally, via the ignoreEmptySearchPlaces option.

If it matches the (async) iterator interface, users can do:

const explorer = createExplorer({/* ...options */});
let config;
for(const configPath of explorer.locateSync()) {
    config = attemptToLoad(configPath);
    if(config) break;
}
@davidtheclark
Copy link
Collaborator

Thanks for filing this @cspotcode.

What are the reasons https://github.com/sindresorhus/find-up doesn't fulfill this need?

I'm partly wondering because it might, and partly to make sure that we're aware of whatever the key difference is, so we'd preserve that in a locate-only implementation.

@cspotcode
Copy link
Author

find-up sounds like it fits the bill; I wasn't aware of it. I'll do some reading.

@cspotcode
Copy link
Author

find-up was perfect, thanks for the suggestion. mochajs/mocha#3830

Since I went that route, I'm no longer investigating cosmiconfig for mocha. I appreciate you taking the time to discuss my use-case and potential implementations. Please don't feel the need to keep this issue open on my account.

@davidtheclark
Copy link
Collaborator

Great, @cspotcode 👍

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

2 participants