From a91546384204b4c16eddf5a5806da8e729b4e5d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Og=C3=B3rek?= Date: Tue, 28 Feb 2023 18:04:20 +0100 Subject: [PATCH] ref: Support lower and uppercased env vars for npm cache --- scripts/install.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/scripts/install.js b/scripts/install.js index 9a2b652350..63aa635d8d 100755 --- a/scripts/install.js +++ b/scripts/install.js @@ -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) {