diff --git a/bin/install.js b/bin/install.js index eb90dcb5..409f4139 100755 --- a/bin/install.js +++ b/bin/install.js @@ -196,6 +196,9 @@ if (production) { if (cacheDir === null && process.env.npm_config_cache) { cacheDir = process.env.npm_config_cache; } +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 7427cd1f..b1e085d2 100644 --- a/test/install-cache-strict.test.js +++ b/test/install-cache-strict.test.js @@ -59,4 +59,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'))); + }); });