Skip to content

Commit

Permalink
Tolerate lack of node_modules when checking if directory is writable (
Browse files Browse the repository at this point in the history
#20)

Do not return `undefined` when `node_modules` does not exist but can be
created.
  • Loading branch information
coreyfarrell authored and sindresorhus committed Dec 12, 2019
1 parent d3c64a7 commit a2679d9
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions index.js
Expand Up @@ -27,8 +27,11 @@ module.exports = (options = {}) => {
directory = pkgDir.sync(directory);

if (directory) {
if (!isWritable(path.join(directory, 'node_modules'))) {
return undefined;
const nodeModules = path.join(directory, 'node_modules');
if (!isWritable(nodeModules)) {
if (fs.existsSync(nodeModules) || !isWritable(path.join(directory))) {
return undefined;
}
}

directory = path.join(directory, 'node_modules', '.cache', name);
Expand Down

0 comments on commit a2679d9

Please sign in to comment.