Skip to content

Commit

Permalink
Merge fb92004 into e30f2cf
Browse files Browse the repository at this point in the history
  • Loading branch information
Richienb committed Mar 7, 2020
2 parents e30f2cf + fb92004 commit 407026d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
9 changes: 6 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ const fs = require('fs');
const commonDir = require('commondir');
const pkgDir = require('pkg-dir');
const makeDir = require('make-dir');
const yn = require('yn');

const {env, cwd} = process;

const isWritable = path => {
try {
Expand Down Expand Up @@ -40,11 +43,11 @@ function getNodeModuleDirectory(directory) {
}

module.exports = (options = {}) => {
if (process.env.CACHE_DIR) {
return useDirectory(path.join(process.env.CACHE_DIR, 'find-cache-dir'), options);
if (env.CACHE_DIR && yn(env.CACHE_DIR) === undefined) {
return useDirectory(path.join(env.CACHE_DIR, 'find-cache-dir'), options);
}

let {cwd: directory = process.cwd()} = options;
let {cwd: directory = cwd()} = options;

if (options.files) {
directory = commonDir(directory, options.files);
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"dependencies": {
"commondir": "^1.0.1",
"make-dir": "^3.0.2",
"pkg-dir": "^4.1.0"
"pkg-dir": "^4.1.0",
"yn": "^4.0.0"
},
"devDependencies": {
"ava": "^2.4.0",
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ findCacheDir({name: 'unicorns'});

### findCacheDir(options?)

Finds the cache directory using the supplied options. The algorithm checks for the `CACHE_DIR` environmental variable, and if one is not found, it tries to find a `package.json` file, searching every parent directory of the `cwd` specified (or implied from other options). It returns a `string` containing the absolute path to the cache directory, or `undefined` if `package.json` was never found or if the `node_modules` directory is unwritable.
Finds the cache directory using the supplied options. The algorithm checks for the `CACHE_DIR` environmental variable and uses it if it is not set to a yes/no like value. If one is not found, it tries to find a `package.json` file, searching every parent directory of the `cwd` specified (or implied from other options). It returns a `string` containing the absolute path to the cache directory, or `undefined` if `package.json` was never found or if the `node_modules` directory is unwritable.

#### options

Expand Down
6 changes: 6 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,9 @@ test('supports CACHE_DIR environment variable', t => {

delete process.env.CACHE_DIR;
});

test('ignores yes/no like value for CACHE_DIR environmental variable', t => {
process.env.CACHE_DIR = false;

t.not(findCacheDir(), path.resolve(__dirname, 'false', 'find-cache-dir'));
});

0 comments on commit 407026d

Please sign in to comment.