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

ref: Support lower and uppercased env vars for npm cache #1493

Merged
merged 1 commit into from
Mar 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions scripts/install.js
Original file line number Diff line number Diff line change
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 of [...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