find-npm-prefix
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -8,7 +8,5 @@ 'use strict' | ||
const path = require('path') | ||
const Bluebird = require('bluebird') | ||
const readdir = Bluebird.promisify(fs.readdir) | ||
function findPrefix (dir) { | ||
return Bluebird.try(() => { | ||
return new Promise((resolve, reject) => { | ||
dir = path.resolve(dir) | ||
@@ -24,5 +22,7 @@ | ||
} | ||
if (walkedUp) return dir | ||
return findPrefix_(dir) | ||
if (walkedUp) { | ||
resolve(dir) | ||
} else { | ||
resolve(findPrefix_(dir)) | ||
} | ||
}) | ||
@@ -37,21 +37,23 @@ } | ||
// directory | ||
if (parent === dir) return original | ||
if (parent === dir) return Promise.resolve(original) | ||
return readdir(dir).then(files => { | ||
if (files.indexOf('node_modules') !== -1 || | ||
files.indexOf('package.json') !== -1) { | ||
return dir | ||
} | ||
return findPrefix_(parent, original) | ||
}, er => { | ||
// an error right away is a bad sign. | ||
// unless the prefix was simply a non | ||
// existent directory. | ||
if (er && dir === original && er.code !== 'ENOENT') { | ||
throw er | ||
} else { | ||
return original | ||
} | ||
return new Promise((resolve, reject) => { | ||
fs.readdir(dir, (err, files) => { | ||
if (err) { | ||
// an error right away is a bad sign. | ||
// unless the prefix was simply a non | ||
// existent directory. | ||
if (err && dir === original && err.code !== 'ENOENT') { | ||
reject(err) | ||
} else { | ||
resolve(original) | ||
} | ||
} else if (files.indexOf('node_modules') !== -1 || | ||
files.indexOf('package.json') !== -1) { | ||
resolve(dir) | ||
} else { | ||
resolve(findPrefix_(parent, original)) | ||
} | ||
}) | ||
}) | ||
} |
{ | ||
"name": "find-npm-prefix", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Find the npm project directory associated with for a given directory", | ||
@@ -5,0 +5,0 @@ "main": "find-prefix.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7786
124