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

Dynamic stopDir #219

Open
chocolateboy opened this issue Oct 29, 2019 · 0 comments
Open

Dynamic stopDir #219

chocolateboy opened this issue Oct 29, 2019 · 0 comments

Comments

@chocolateboy
Copy link

chocolateboy commented Oct 29, 2019

I'm trying to emulate Parcel's config-file resolution[1][2] (to work around the fact that it no longer works synchronously), which walks up from an asset's directory to either the filesystem root directory or the nearest enclosing node_modules directory, whichever comes first. This is proving to be difficult because stopDir is required to be a fixed/absolute path.

In theory, I could walk up from the asset's directory myself to see if there's an enclosing node_modules directory and supply that as the static stopDir, but I'd rather not roll my own directory traversal since it defeats the point of using this module.

The desired behavior would be straightforward to emulate if the stopDir option could (optionally) be supplied as a function, e.g.:

const stopDir = dir => {                                                      
    return (dir === fsRoot) || Path.basename(dir) === 'node_modules'          
}

const explorer = cosmiconfig(name, { stopDir })
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

2 participants