Skip to content

Commit

Permalink
feat: support npm_config_cache to change default cache dir (#335)
Browse files Browse the repository at this point in the history
```bash
npm_config_cache=/oss/cache/.npminstall npminstall koa
```
  • Loading branch information
fengmk2 authored Oct 30, 2020
1 parent f87d6bd commit d598f9d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions bin/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ let cacheDir = argv.cache === false ? '' : null;
if (production) {
cacheDir = '';
}
// support npm_config_cache to change default cache dir
if (cacheDir === null && process.env.npm_config_cache) {
cacheDir = process.env.npm_config_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 @@ -34,6 +34,19 @@ describe('test/install-cache-strict.test.js', () => {
assert(await fs.stat(path.join(homedir, '.npminstall_tarball/d/e/b/u/debug')));
});

it('should read disk cache from npm_config_cache env', async () => {
await coffee.fork(helper.npminstall, [], {
cwd: demo,
env: Object.assign({}, process.env, {
HOME: homedir,
npm_config_cache: path.join(homedir, 'foocache/.npminstall_tarball'),
}),
})
.debug()
.end();
assert(await fs.stat(path.join(homedir, 'foocache/.npminstall_tarball/d/e/b/u/debug')));
});

it('should read disk cache on --cache-strict NODE_ENV=production', async () => {
await coffee.fork(helper.npminstall, [ '--cache-strict' ], {
cwd: demo,
Expand Down

0 comments on commit d598f9d

Please sign in to comment.