diff options
Diffstat (limited to 'deps/npm/lib/utils')
-rw-r--r-- | deps/npm/lib/utils/cmd-shim.js | 6 | ||||
-rw-r--r-- | deps/npm/lib/utils/config-defs.js | 4 | ||||
-rw-r--r-- | deps/npm/lib/utils/read-installed.js | 12 | ||||
-rw-r--r-- | deps/npm/lib/utils/read-json.js | 44 |
4 files changed, 56 insertions, 10 deletions
diff --git a/deps/npm/lib/utils/cmd-shim.js b/deps/npm/lib/utils/cmd-shim.js index a7892e8ee3..f53ab3cf83 100644 --- a/deps/npm/lib/utils/cmd-shim.js +++ b/deps/npm/lib/utils/cmd-shim.js @@ -73,16 +73,16 @@ function writeShim_ (from, to, prog, args, cb) { target = "" shTarget = "" } else { - longProg = "\"%~dp0\"\\\"" + prog + ".exe\"" + longProg = "\"%~dp0\\" + prog + ".exe\"" shLongProg = "\"`dirname \"$0\"`/" + prog + "\"" target = "\"%~dp0\\" + target + "\"" shTarget = "\"`dirname \"$0\"`/" + shTarget + "\"" } - // @IF EXIST "%~dp0"\"node.exe" ( + // @IF EXIST "%~dp0\node.exe" ( // "%~dp0\node.exe" "%~dp0\.\node_modules\npm\bin\npm-cli.js" %* // ) ELSE ( - // node "%~dp0\.\node_modules\npm\bin\npm-cli.js" %* + // node "%~dp0\.\node_modules\npm\bin\npm-cli.js" %* // ) var cmd if (longProg) { diff --git a/deps/npm/lib/utils/config-defs.js b/deps/npm/lib/utils/config-defs.js index d368c49726..9c50741357 100644 --- a/deps/npm/lib/utils/config-defs.js +++ b/deps/npm/lib/utils/config-defs.js @@ -161,6 +161,7 @@ Object.defineProperty(exports, "defaults", {get: function () { , "init.author.name" : "" , "init.author.email" : "" , "init.author.url" : "" + , json: false , link: false , logfd : 2 , loglevel : "http" @@ -206,6 +207,7 @@ Object.defineProperty(exports, "defaults", {get: function () { , userignorefile : path.resolve(home, ".npmignore") , umask: 022 , version : false + , versions : false , viewer: process.platform === "win32" ? "browser" : "man" , yes: null @@ -238,6 +240,7 @@ exports.types = , "init.author.name" : String , "init.author.email" : String , "init.author.url" : ["", url] + , json: Boolean , link: Boolean , logfd : [Number, Stream] , loglevel : ["silent","win","error","warn","http","info","verbose","silly"] @@ -279,6 +282,7 @@ exports.types = , userignorefile : path , umask: Octal , version : Boolean + , versions : Boolean , viewer: String , yes: [false, null, Boolean] , _exit : Boolean diff --git a/deps/npm/lib/utils/read-installed.js b/deps/npm/lib/utils/read-installed.js index 6c0ece25bc..60cbea15c5 100644 --- a/deps/npm/lib/utils/read-installed.js +++ b/deps/npm/lib/utils/read-installed.js @@ -125,7 +125,8 @@ function readInstalled_ (folder, parent, name, reqver, depth, maxDepth, cb) { }) readJson(path.resolve(folder, "package.json"), function (er, data) { - obj = data + obj = copy(data) + if (!parent) { obj = obj || true er = null @@ -269,6 +270,15 @@ function findUnmet (obj) { return obj } +function copy (obj) { + if (!obj || typeof obj !== 'object') return obj + if (Array.isArray(obj)) return obj.map(copy) + + var o = {} + for (var i in obj) o[i] = copy(obj[i]) + return o +} + if (module === require.main) { var util = require("util") console.error("testing") diff --git a/deps/npm/lib/utils/read-json.js b/deps/npm/lib/utils/read-json.js index 388d6727eb..8fdd60f66d 100644 --- a/deps/npm/lib/utils/read-json.js +++ b/deps/npm/lib/utils/read-json.js @@ -35,7 +35,7 @@ function readJson (jsonFile, opts, cb) { , contributors = null , serverjs = null - if (opts.wscript != null) { + if (opts.wscript !== null && opts.wscript !== undefined) { wscript = opts.wscript next() } else fs.readFile( path.join(path.dirname(jsonFile), "wscript") @@ -47,7 +47,7 @@ function readJson (jsonFile, opts, cb) { next() }) - if (opts.contributors != null) { + if (opts.contributors !== null && opts.contributors !== undefined) { contributors = opts.contributors next() } else fs.readFile( path.join(path.dirname(jsonFile), "AUTHORS") @@ -64,7 +64,7 @@ function readJson (jsonFile, opts, cb) { next() }) - if (opts.serverjs != null) { + if (opts.serverjs !== null && opts.serverjs !== undefined) { serverjs = opts.serverjs next() } else fs.stat( path.join(path.dirname(jsonFile), "server.js") @@ -82,16 +82,48 @@ function readJson (jsonFile, opts, cb) { return } - fs.readFile(jsonFile, processJson(opts, function (er, data) { + // XXX this api here is insane. being internal is no excuse. + // please refactor. + var thenLoad = processJson(opts, function (er, data) { if (er) return cb(er) var doLoad = !(jsonFile.indexOf(npm.cache) === 0 && path.basename(path.dirname(jsonFile)) !== "package") if (!doLoad) return cb(er, data) loadPackageDefaults(data, path.dirname(jsonFile), cb) - })) + }) + + fs.readFile(jsonFile, function (er, data) { + if (er && er.code === "ENOENT") { + // single-file module, maybe? + // check index.js for a /**package { ... } **/ section. + var indexFile = path.resolve(path.dirname(jsonFile), "index.js") + return fs.readFile(indexFile, function (er2, data) { + // if this doesn't work, then die with the original error. + if (er2) return cb(er) + data = parseIndex(data) + if (!data) return cb(er) + thenLoad(null, data) + }) + } + thenLoad(er, data) + }) } } +// sync. no io. +// /**package { "name": "foo", "version": "1.2.3", ... } **/ +function parseIndex (data) { + data = data.toString() + data = data.split(/^\/\*\*package(?:\s|$)/m) + if (data.length < 2) return null + data = data[1] + data = data.split(/\*\*\/$/m) + if (data.length < 2) return null + data = data[0] + data = data.replace(/^\s*\*/mg, "") + return data +} + function processJson (opts, cb) { if (typeof cb !== "function") cb = opts, opts = {} if (typeof cb !== "function") { @@ -113,8 +145,8 @@ function processJson (opts, cb) { } function processJsonString (opts, cb) { return function (er, jsonString) { - jsonString += "" if (er) return cb(er, jsonString) + jsonString += "" var json try { json = JSON.parse(jsonString) |