Skip to content

Commit a2679d9

Browse files
coreyfarrellsindresorhus
authored andcommittedDec 12, 2019
Tolerate lack of node_modules when checking if directory is writable (#20)
Do not return `undefined` when `node_modules` does not exist but can be created.
1 parent d3c64a7 commit a2679d9

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed
 

‎index.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@ module.exports = (options = {}) => {
2727
directory = pkgDir.sync(directory);
2828

2929
if (directory) {
30-
if (!isWritable(path.join(directory, 'node_modules'))) {
31-
return undefined;
30+
const nodeModules = path.join(directory, 'node_modules');
31+
if (!isWritable(nodeModules)) {
32+
if (fs.existsSync(nodeModules) || !isWritable(path.join(directory))) {
33+
return undefined;
34+
}
3235
}
3336

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

0 commit comments

Comments
 (0)
Please sign in to comment.