summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/libnpx/get-prefix.js
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/node_modules/libnpx/get-prefix.js')
-rw-r--r--deps/npm/node_modules/libnpx/get-prefix.js32
1 files changed, 16 insertions, 16 deletions
diff --git a/deps/npm/node_modules/libnpx/get-prefix.js b/deps/npm/node_modules/libnpx/get-prefix.js
index 71bedffc58..3fef7f7eb9 100644
--- a/deps/npm/node_modules/libnpx/get-prefix.js
+++ b/deps/npm/node_modules/libnpx/get-prefix.js
@@ -6,21 +6,22 @@ const path = require('path')
const statAsync = promisify(require('fs').stat)
module.exports = getPrefix
-function getPrefix (current, root) {
- if (!root) {
- const original = root = path.resolve(current)
- while (path.basename(root) === 'node_modules') {
- root = path.dirname(root)
- }
- if (original !== root) {
- return Promise.resolve(root)
- } else {
- return getPrefix(root, root)
- }
+function getPrefix (root) {
+ const original = root = path.resolve(root)
+ while (path.basename(root) === 'node_modules') {
+ root = path.dirname(root)
}
- if (isRootPath(current, process.platform)) {
+ if (original !== root) {
return Promise.resolve(root)
} else {
+ return Promise.resolve(getPrefixFromTree(root))
+ }
+}
+
+function getPrefixFromTree (current) {
+ if (isRootPath(current, process.platform)) {
+ return false
+ } else {
return Promise.all([
fileExists(path.join(current, 'package.json')),
fileExists(path.join(current, 'node_modules'))
@@ -30,8 +31,7 @@ function getPrefix (current, root) {
if (hasPkg || hasModules) {
return current
} else {
- const parent = path.dirname(current)
- return getPrefix(parent, root)
+ return getPrefixFromTree(path.dirname(current))
}
})
}
@@ -49,6 +49,6 @@ function fileExists (f) {
module.exports._isRootPath = isRootPath
function isRootPath (p, platform) {
return platform === 'win32'
- ? p.match(/^[a-z]+:[/\\]?$/i)
- : p === '/'
+ ? p.match(/^[a-z]+:[/\\]?$/i)
+ : p === '/'
}