Skip to content

Commit

Permalink
Respect name option when CACHE_DIR environment variable is set (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderGerbik committed Aug 29, 2021
1 parent 05a0b08 commit 6a378f5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -43,7 +43,7 @@ function getNodeModuleDirectory(directory) {

module.exports = (options = {}) => {
if (env.CACHE_DIR && !['true', 'false', '1', '0'].includes(env.CACHE_DIR)) {
return useDirectory(path.join(env.CACHE_DIR, 'find-cache-dir'), options);
return useDirectory(path.join(env.CACHE_DIR, options.name), options);
}

let {cwd: directory = cwd()} = options;
Expand Down
8 changes: 4 additions & 4 deletions test.js
Expand Up @@ -43,15 +43,15 @@ test('returns undefined if it can\'t find package.json', t => {

test('supports CACHE_DIR environment variable', t => {
const newCacheDirectory = tempDirectory();
const finalDirectory = path.join(newCacheDirectory, 'find-cache-dir');
const finalDirectory = path.join(newCacheDirectory, 'some-package');
process.env.CACHE_DIR = newCacheDirectory;

t.is(findCacheDir(), finalDirectory);
t.is(findCacheDir({name: 'some-package'}), finalDirectory);

findCacheDir({create: true});
findCacheDir({name: 'some-package', create: true});
t.true(fs.existsSync(finalDirectory));

const thunk = findCacheDir({thunk: true});
const thunk = findCacheDir({name: 'some-package', thunk: true});
t.is(thunk('foo'), path.join(finalDirectory, 'foo'));
t.is(thunk('bar'), path.join(finalDirectory, 'bar'));

Expand Down

0 comments on commit 6a378f5

Please sign in to comment.