From 4c2cc3bc937bf01e39963e4f06d5b55bfd91826c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A3=9E=E8=B6=85?= <842351815@qq.com> Date: Mon, 18 Dec 2023 17:39:04 +0800 Subject: [PATCH] feat: add support for process.env.npminstall_cache (cherry-pick #471) (#472) pick from https://github.com/cnpm/npminstall/pull/471 --- bin/install.js | 3 +++ test/install-cache-strict.test.js | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/bin/install.js b/bin/install.js index fc83679a..35629822 100755 --- a/bin/install.js +++ b/bin/install.js @@ -206,6 +206,9 @@ let cacheDir = defaultCacheDir; if (!cacheStrict && (production || argv.cache === false)) { cacheDir = ''; } +if (process.env.npminstall_cache) { + cacheDir = process.env.npminstall_cache; +} let forbiddenLicenses = argv['forbidden-licenses']; forbiddenLicenses = forbiddenLicenses ? forbiddenLicenses.split(',') : null; diff --git a/test/install-cache-strict.test.js b/test/install-cache-strict.test.js index 2d47975b..c090f613 100644 --- a/test/install-cache-strict.test.js +++ b/test/install-cache-strict.test.js @@ -72,4 +72,17 @@ describe('test/install-cache-strict.test.js', () => { .end(); assert(await fs.stat(path.join(homedir, '.npminstall_tarball/d/e/b/u/debug'))); }); + + it('should read disk cache from npminstall_cache env', async () => { + await coffee.fork(helper.npminstall, [], { + cwd: demo, + env: Object.assign({}, process.env, { + HOME: homedir, + npminstall_cache: path.join(homedir, 'foocache/.npminstall_tarball'), + }), + }) + .debug() + .end(); + assert(await fs.stat(path.join(homedir, 'foocache/.npminstall_tarball/d/e/b/u/debug'))); + }); });