X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.maps.server%2Fnode%2Fnode-v4.8.0-win-x64%2Fnode_modules%2Fnpm%2Flib%2Fconfig%2Ffind-prefix.js;fp=org.simantics.maps.server%2Fnode%2Fnode-v4.8.0-win-x64%2Fnode_modules%2Fnpm%2Flib%2Fconfig%2Ffind-prefix.js;h=bb00cd6b10c2fe99ebaec826d4bfa5191c16f268;hb=2529be6d456deeb07c128603ce4971f1dc29b695;hp=0000000000000000000000000000000000000000;hpb=2636fc31c16c23711cf2b06a4ae8537bba9c1d35;p=simantics%2Fdistrict.git diff --git a/org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/lib/config/find-prefix.js b/org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/lib/config/find-prefix.js new file mode 100644 index 00000000..bb00cd6b --- /dev/null +++ b/org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/lib/config/find-prefix.js @@ -0,0 +1,56 @@ +// try to find the most reasonable prefix to use + +module.exports = findPrefix + +var fs = require("fs") +var path = require("path") + +function findPrefix (p, cb_) { + function cb (er, p) { + process.nextTick(function () { + cb_(er, p) + }) + } + + p = path.resolve(p) + // if there's no node_modules folder, then + // walk up until we hopefully find one. + // if none anywhere, then use cwd. + var walkedUp = false + while (path.basename(p) === "node_modules") { + p = path.dirname(p) + walkedUp = true + } + if (walkedUp) return cb(null, p) + + findPrefix_(p, p, cb) +} + +function findPrefix_ (p, original, cb) { + if (p === "/" + || (process.platform === "win32" && p.match(/^[a-zA-Z]:(\\|\/)?$/))) { + return cb(null, original) + } + fs.readdir(p, function (er, files) { + // an error right away is a bad sign. + // unless the prefix was simply a non + // existent directory. + if (er && p === original) { + if (er.code === "ENOENT") return cb(null, original); + return cb(er) + } + + // walked up too high or something. + if (er) return cb(null, original) + + if (files.indexOf("node_modules") !== -1 + || files.indexOf("package.json") !== -1) { + return cb(null, p) + } + + var d = path.dirname(p) + if (d === p) return cb(null, original) + + return findPrefix_(d, original, cb) + }) +}