fix: Fix using environment variables to specify prefix
Previously, the code in workspaces/config/lib/index.js didn't take into account the environment variables when determining Config.localPrefix.
This means that commands using localPrefix could previously behave unexpectedly or fail (if the current working directory isn't part of a package) when the prefix is specified using NPM_CONFIG_PREFIX=... .
This PR fixes this by simply checking the environment variables as well using the Config.#get('prefix', 'env')
References
Fixes #4467.
This is a danger area and we should make sure we know if this was intentional before adding it. Setting the prefix before certain operations has caused bugs in the past.
I don't know for sure that this is a problem, but caution is in order here. Setting the prefix in npm is tricky because by the time we're parsing it we have sometimes already assumed we know what the prefix is.
I don't really understand why this could cause problems. We're already setting localPrefix from the CLI arguments in the same way so surely doing the same with the environment variable won't cause any problems (well unless they were there to begin with). The environment variable is just another source for the same data.
This is a danger area and we should make sure we know if this was intentional before adding it.
IMHO, this wasn't intentional and it was simply forgotten about when the environment variable configuration was added (as prefix is a bit of a special case). I looked at the history and I couldn't find any reason why it would be intentional; this bit of code (minus refactorings) was around since before the config-in-envvars was a thing. (Even though it moved between repositories like 3 times)
Could this be merged please?