cosmiconfig icon indicating copy to clipboard operation
cosmiconfig copied to clipboard

Dynamic stopDir

Open chocolateboy opened this issue 5 years ago • 0 comments

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

chocolateboy avatar Oct 29 '19 06:10 chocolateboy