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'))); + }); });