Skip to content

Commit

Permalink
feat: add support for process.env.npminstall_cache (cherry-pick #471) (
Browse files Browse the repository at this point in the history
…#472)

pick from #471
  • Loading branch information
feichao93 authored Dec 18, 2023
1 parent caae2a5 commit 4c2cc3b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions bin/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 13 additions & 0 deletions test/install-cache-strict.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')));
});
});

0 comments on commit 4c2cc3b

Please sign in to comment.