Skip to content

Commit

Permalink
ref: Support lower and uppercased env vars for npm cache
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilogorek committed Feb 28, 2023
1 parent 872bd77 commit a915463
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions scripts/install.js
Expand Up @@ -123,13 +123,17 @@ function createProgressBar(name, total) {
}

function npmCache() {
const env = process.env;
return (
env.npm_config_cache ||
env.npm_config_cache_folder ||
env.npm_config_yarn_offline_mirror ||
(env.APPDATA ? path.join(env.APPDATA, 'npm-cache') : path.join(os.homedir(), '.npm'))
);
const keys = ['npm_config_cache', 'npm_config_cache_folder', 'npm_config_yarn_offline_mirror'];

for (let key in [keys, ...keys.map((k) => k.toUpperCase())]) {
if (process.env[key]) return process.env[key];
}

if (process.env.APPDATA) {
return path.join(process.env.APPDATA, 'npm-cache');
}

return path.join(os.homedir(), '.npm');
}

function getCachedPath(url) {
Expand Down

0 comments on commit a915463

Please sign in to comment.