Skip to content

configLocations

configLocations(root, env?, home?): ConfigLocations

Resolve where each layer’s file lives. Pure — env and home are injectable because a test that consulted the real environment would read the developer’s own ~/.config, and pass or fail according to what is in it.

Two details of how a path out of the environment is read:

A leading ~ is expanded against home. A shell expands it before exec, but .env loaders, direnv and CI YAML hand the literal tilde through, and ~/config.json quietly becoming <somewhere>/~/config.json is the silent wrong answer this module refuses to give anywhere else.

A RELATIVE path resolves against root, not the process working directory. This function is otherwise a pure function of its arguments; reading process.cwd() would smuggle an ambient input in, so a library consumer scanning some other directory would get a user-layer path unrelated to the directory being scanned while the project layer tracked it.

ParameterTypeDefault value
rootstringundefined
envRecord<string, string | undefined>process.env
homestring...

ConfigLocations