diff options
author | isaacs <i@izs.me> | 2012-06-10 21:29:47 -0700 |
---|---|---|
committer | isaacs <i@izs.me> | 2012-06-11 08:13:36 -0700 |
commit | 13198357e9973c6d29283ca7d69d57f5986b9474 (patch) | |
tree | 93de20789b309b2315b75e4a5577bd644335add5 /deps/npm/lib | |
parent | 284816ee9ff67aaa997b803db4f1ebb207672c6d (diff) | |
download | node-13198357e9973c6d29283ca7d69d57f5986b9474.tar.gz |
Upgrade npm to 1.1.25
Diffstat (limited to 'deps/npm/lib')
58 files changed, 561 insertions, 1492 deletions
diff --git a/deps/npm/lib/adduser.js b/deps/npm/lib/adduser.js index d65eed595..f0fc8d10e 100644 --- a/deps/npm/lib/adduser.js +++ b/deps/npm/lib/adduser.js @@ -1,10 +1,10 @@ module.exports = adduser -var registry = require("./utils/npm-registry-client/index.js") - , ini = require("./utils/ini.js") - , log = require("./utils/log.js") +var ini = require("./utils/ini.js") + , log = require("npmlog") , npm = require("./npm.js") + , registry = npm.registry , read = require("read") , promiseChain = require("./utils/promise-chain.js") , crypto @@ -39,10 +39,13 @@ function adduser (args, cb) { if (changed) npm.config.del("_auth") registry.adduser(u.u, u.p, u.e, function (er) { if (er) return cb(er) + registry.username = u.u + registry.password = u.p + registry.email = u.e ini.set("username", u.u, "user") ini.set("_password", u.p, "user") ini.set("email", u.e, "user") - log("Authorized user " + u.u, "adduser") + log.info("adduser", "Authorized user %s", u.u) ini.save("user", cb) }) }) diff --git a/deps/npm/lib/bugs.js b/deps/npm/lib/bugs.js index 2a9352632..3f9de1231 100644 --- a/deps/npm/lib/bugs.js +++ b/deps/npm/lib/bugs.js @@ -3,22 +3,22 @@ module.exports = bugs bugs.usage = "npm bugs <pkgname>" +var exec = require("./utils/exec.js") + , npm = require("./npm.js") + , registry = npm.registry + , log = require("npmlog") + bugs.completion = function (opts, cb) { if (opts.conf.argv.remain.length > 2) return cb() - registry.get("/-/short", null, 60000, function (er, list) { + registry.get("/-/short", 60000, function (er, list) { return cb(null, list || []) }) } -var exec = require("./utils/exec.js") - , registry = require("./utils/npm-registry-client/index.js") - , npm = require("./npm.js") - , log = require("./utils/log.js") - function bugs (args, cb) { if (!args.length) return cb(bugs.usage) var n = args[0].split("@").shift() - registry.get(n, "latest", 3600, function (er, d) { + registry.get(n + "/latest", 3600, function (er, d) { if (er) return cb(er) var bugs = d.bugs , repo = d.repository || d.repositories @@ -29,7 +29,7 @@ function bugs (args, cb) { if (repo) { if (Array.isArray(repo)) repo = repo.shift() if (repo.hasOwnProperty("url")) repo = repo.url - log.verbose(repo, "repository") + log.verbose("repository", repo) if (repo && repo.match(/^(https?:\/\/|git(:\/\/|@))github.com/)) { return open(repo.replace(/^git(@|:\/\/)/, "http://") .replace(/^https?:\/\/github.com:/, "github.com/") diff --git a/deps/npm/lib/build.js b/deps/npm/lib/build.js index 864eb27cf..c0dcbf7fb 100644 --- a/deps/npm/lib/build.js +++ b/deps/npm/lib/build.js @@ -9,7 +9,7 @@ // This runs AFTER install or link are completed. var npm = require("./npm.js") - , log = require("./utils/log.js") + , log = require("npmlog") , chain = require("slide").chain , fs = require("graceful-fs") , path = require("path") @@ -44,7 +44,7 @@ function build (args, global, didPre, didRB, cb) { function build_ (global, didPre, didRB) { return function (folder, cb) { folder = path.resolve(folder) build._didBuild[folder] = true - log.info(folder, "build") + log.info("build", folder) readJson(path.resolve(folder, "package.json"), function (er, pkg) { if (er) return cb(er) chain @@ -76,17 +76,17 @@ function linkStuff (pkg, folder, global, didRB, cb) { , top = parent === npm.dir , gtop = parent === gnm - log.verbose([global, gnm, gtop, parent], "linkStuff") - log(pkg._id, "linkStuff") + log.verbose("linkStuff", [global, gnm, gtop, parent]) + log.info("linkStuff", pkg._id) if (top && pkg.preferGlobal && !global) { - log.warn(pkg._id + " should be installed with -g", "prefer global") + log.warn("prefer global", pkg._id + " should be installed with -g") } asyncMap( [linkBins, linkMans, !didRB && rebuildBundles] , function (fn, cb) { if (!fn) return cb() - log.verbose(pkg._id, fn.name) + log.verbose(fn.name, pkg._id) fn(pkg, folder, parent, gtop, cb) }, cb) } @@ -102,7 +102,7 @@ function rebuildBundles (pkg, folder, parent, gtop, cb) { // error means no bundles if (er) return cb() - log.verbose(files, "rebuildBundles") + log.verbose("rebuildBundles", files) // don't asyncMap these, because otherwise build script output // gets interleaved and is impossible to read chain(files.filter(function (file) { @@ -117,7 +117,7 @@ function rebuildBundles (pkg, folder, parent, gtop, cb) { file = path.resolve(folder, "node_modules", file) return function (cb) { if (build._didBuild[file]) return cb() - log.verbose(file, "rebuild bundle") + log.verbose("rebuild bundle", file) // if file is not a package dir, then don't do it. fs.lstat(path.resolve(file, "package.json"), function (er, st) { if (er) return cb() @@ -133,7 +133,7 @@ function linkBins (pkg, folder, parent, gtop, cb) { } var binRoot = gtop ? npm.globalBin : path.resolve(parent, ".bin") - log.verbose([pkg.bin, binRoot, gtop], "bins linking") + log.verbose("link bins", [pkg.bin, binRoot, gtop]) asyncMap(Object.keys(pkg.bin), function (b, cb) { linkBin( path.resolve(folder, pkg.bin[b]) diff --git a/deps/npm/lib/cache.js b/deps/npm/lib/cache.js index 076267e89..e2e037ebe 100644 --- a/deps/npm/lib/cache.js +++ b/deps/npm/lib/cache.js @@ -13,7 +13,7 @@ Adding a url: 2. goto folder(2) adding a name@version: -1. registry.get(name, version) +1. registry.get(name/version) 2. if response isn't 304, add url(dist.tarball) adding a name@range: @@ -38,8 +38,8 @@ var mkdir = require("mkdirp") , fs = require("graceful-fs") , rm = require("rimraf") , readJson = require("./utils/read-json.js") - , registry = require("./utils/npm-registry-client/index.js") - , log = require("./utils/log.js") + , registry = npm.registry + , log = require("npmlog") , path = require("path") , output , sha = require("./utils/sha.js") @@ -104,7 +104,7 @@ function read (name, ver, forceBypass, cb) { } if (forceBypass && npm.config.get("force")) { - log.verbose(true, "force found, skipping cache") + log.verbose("using force", "skipping cache") return addNamed(name, ver, c) } @@ -171,7 +171,7 @@ exports.add = function (pkg, ver, scrub, cb) { add([pkg, ver], cb) }) } - log.verbose([pkg, ver], "cache add") + log.verbose("cache add", [pkg, ver]) return add([pkg, ver], cb) } @@ -204,14 +204,15 @@ function add (args, cb) { spec = args[0] } - log.silly([name, spec, args], "cache add: name, spec, args") + log.silly("cache add", "name=%j spec=%j args=%j", name, spec, args) + if (!name && !spec) return cb(usage) // see if the spec is a url // otherwise, treat as name@version var p = url.parse(spec) || {} - log.verbose(p, "parsed url") + log.verbose("parsed url", p) // it could be that we got name@http://blah // in that case, we will not have a protocol now, but if we @@ -260,12 +261,15 @@ function addRemoteTarball (u, shasum, name, cb_) { delete inFlightURLs[u] } - log.verbose([u, shasum], "addRemoteTarball") + log.verbose("addRemoteTarball", [u, shasum]) var tmp = path.join(npm.tmp, Date.now()+"-"+Math.random(), "tmp.tgz") mkdir(path.dirname(tmp), function (er) { if (er) return cb(er) fetch(u, tmp, function (er) { - if (er) return log.er(cb, "failed to fetch "+u)(er) + if (er) { + log.error("fetch failed", u) + return cb(er) + } if (!shasum) return done() // validate that the url we just downloaded matches the expected shasum. sha.check(tmp, shasum, done) @@ -309,7 +313,7 @@ function addRemoteGit (u, parsed, name, cb_) { u = u.replace(/^ssh:\/\//, "") } - log.verbose([u, co], "addRemoteGit") + log.verbose("addRemoteGit", [u, co]) var tmp = path.join(npm.tmp, Date.now()+"-"+Math.random()) mkdir(path.dirname(tmp), function (er) { @@ -318,18 +322,18 @@ function addRemoteGit (u, parsed, name, cb_) { , function (er, code, stdout, stderr) { stdout = (stdout + "\n" + stderr).trim() if (er) { - log.error(stdout, "git clone "+u) + log.error("git clone " + u, stdout) return cb(er) } - log.verbose(stdout, "git clone "+u) + log.verbose("git clone "+u, stdout) exec( npm.config.get("git"), ["checkout", co], null, false, tmp , function (er, code, stdout, stderr) { stdout = (stdout + "\n" + stderr).trim() if (er) { - log.error(stdout, "git checkout "+co) + log.error("git checkout " + co, stdout) return cb(er) } - log.verbose(stdout, "git checkout "+co) + log.verbose("git checkout " + co, stdout) addLocalDirectory(tmp, cb) }) }) @@ -341,7 +345,7 @@ function addRemoteGit (u, parsed, name, cb_) { // name@blah thing. var inFlightNames = {} function addNamed (name, x, cb_) { - log.verbose([name, x], "addNamed") + log.verbose("addNamed", [name, x]) var k = name + "@" + x if (!inFlightNames[k]) inFlightNames[k] = [] var iF = inFlightNames[k] @@ -354,7 +358,7 @@ function addNamed (name, x, cb_) { delete inFlightNames[k] } - log.verbose([semver.valid(x), semver.validRange(x)], "addNamed") + log.verbose("addNamed", [semver.valid(x), semver.validRange(x)]) return ( null !== semver.valid(x) ? addNameVersion : null !== semver.validRange(x) ? addNameRange : addNameTag @@ -362,7 +366,7 @@ function addNamed (name, x, cb_) { } function addNameTag (name, tag, cb) { - log([name, tag], "addNameTag") + log.info("addNameTag", [name, tag]) var explicit = true if (!tag) { explicit = false @@ -407,7 +411,7 @@ function addNameRange (name, range, data, cb) { if (range === null) return cb(new Error( "Invalid version range: "+range)) - log.silly([name, range, !!data], "name, range, hasData") + log.silly("addNameRange", {name:name, range:range, hasData:!!data}) if (data) return next() registry.get(name, function (er, d, json, response) { @@ -417,7 +421,8 @@ function addNameRange (name, range, data, cb) { }) function next () { - log.silly([name, range, !!data], "name, range, hasData 2") + log.silly( "addNameRange", "number 2" + , {name:name, range:range, hasData:!!data}) engineFilter(data) if (npm.config.get("registry")) return next_() @@ -433,7 +438,9 @@ function addNameRange (name, range, data, cb) { } function next_ () { - log.silly([data.name, Object.keys(data.versions)], "versions") + log.silly("addNameRange", "versions" + , [data.name, Object.keys(data.versions)]) + // if the tagged version satisfies, then use that. var tagged = data["dist-tags"][npm.config.get("tag")] if (tagged && data.versions[tagged] && semver.satisfies(tagged, range)) { @@ -454,9 +461,12 @@ function addNameRange (name, range, data, cb) { // filter the versions down based on what's already in cache. function cachedFilter (data, range, cb) { - log.silly(data.name, "cachedFilter") + log.silly("cachedFilter", data.name) ls_(data.name, 1, function (er, files) { - if (er) return log.er(cb, "Not in cache, can't fetch: "+data.name)(er) + if (er) { + log.error("cachedFilter", "Not in cache, can't fetch", data.name) + return cb(er) + } files = files.map(function (f) { return path.basename(f.replace(/(\\|\/)$/, "")) }).filter(function (f) { @@ -467,16 +477,17 @@ function cachedFilter (data, range, cb) { return cb(new Error("Not in cache, can't fetch: "+data.name+"@"+range)) } - log.silly([data.name, files], "cached") + log.silly("cached", [data.name, files]) Object.keys(data.versions).forEach(function (v) { if (files.indexOf(v) === -1) delete data.versions[v] }) if (Object.keys(data.versions).length === 0) { - return log.er(cb, "Not in cache, can't fetch: "+data.name)(er) + log.error("cachedFilter", "Not in cache, can't fetch", data.name) + return cb(new Error("Not in cache, can't fetch: "+data.name+"@"+range)) } - log.silly([data.name, Object.keys(data.versions)], "filtered") + log.silly("filtered", [data.name, Object.keys(data.versions)]) cb(null, data) }) } @@ -509,7 +520,7 @@ function addNameVersion (name, ver, data, cb) { response = null return next() } - registry.get(name, ver, function (er, d, json, resp) { + registry.get(name + "/" + ver, function (er, d, json, resp) { if (er) return cb(er) data = d response = resp @@ -524,10 +535,10 @@ function addNameVersion (name, ver, data, cb) { var bd = npm.config.get("bindist") , b = dist.bin && bd && dist.bin[bd] - log.verbose([bd, dist], "bin dist") + log.verbose("bin dist", [bd, dist]) if (b && b.tarball && b.shasum) { - log.info(data._id, "prebuilt") - log.verbose(b, "prebuilt "+data._id) + log.info("prebuilt", data._id) + log.verbose("prebuilt", data._id, b) dist = b } @@ -579,7 +590,8 @@ function addLocal (p, name, cb_) { && (process.platform !== "win32" || p.indexOf("\\") === -1)) { return addNamed(p, "", cb_) } - return log.er(cb_, "Could not install: "+p)(er) + log.error("addLocal", "Could not install %s", p) + return cb_(er) } return cb_(er, data) } @@ -620,7 +632,7 @@ function addLocalTarball (p, name, cb) { to.on("error", errHandler) to.on("close", function () { if (errState) return - log.verbose(npm.modes.file.toString(8), "chmod "+tmp) + log.verbose("chmod", tmp, npm.modes.file.toString(8)) fs.chmod(tmp, npm.modes.file, function (er) { if (er) return cb(er) addTmpTarball(tmp, name, cb) @@ -637,7 +649,8 @@ function getCacheStat (cb) { fs.stat(npm.cache, function (er, st) { if (er) return makeCacheDir(cb) if (!st.isDirectory()) { - return log.er(cb, "invalid cache directory: "+npm.cache)(er) + log.error("getCacheStat", "invalid cache dir %j", npm.cache) + return cb(er) } return cb(null, cacheStat = st) }) @@ -659,9 +672,12 @@ function makeCacheDir (cb) { } fs.stat(process.env.HOME, function (er, st) { - if (er) return log.er(cb, "homeless?")(er) + if (er) { + log.error("makeCacheDir", "homeless?") + return cb(er) + } cacheStat = st - log.silly([st.uid, st.gid], "uid, gid for cache dir") + log.silly("makeCacheDir", "cache dir uid, gid", [st.uid, st.gid]) return mkdir(npm.cache, afterMkdir) }) @@ -698,33 +714,46 @@ function addPlacedTarball_ (p, name, uid, gid, cb) { , folder = path.join(target, "package") rm(folder, function (er) { - if (er) return log.er(cb, "Could not remove "+folder)(er) + if (er) { + log.error("addPlacedTarball", "Could not remove %j", folder) + return cb(er) + } tar.unpack(p, folder, null, null, uid, gid, function (er) { - if (er) return log.er(cb, "Could not unpack "+p+" to "+target)(er) + if (er) { + log.error("addPlacedTarball", "Could not unpack %j to %j", p, target) + return cb(er) + } // calculate the sha of the file that we just unpacked. // this is so that the data is available when publishing. sha.get(p, function (er, shasum) { - if (er) return log.er(cb, "couldn't validate shasum of "+p)(er) + if (er) { + log.error("addPlacedTarball", "shasum fail", p) + return cb(er) + } readJson(path.join(folder, "package.json"), function (er, data) { - if (er) return log.er(cb, "couldn't read json in "+folder)(er) + if (er) { + log.error("addPlacedTarball", "Couldn't read json in %j" + , folder) + return cb(er) + } data.dist = data.dist || {} if (shasum) data.dist.shasum = shasum deprCheck(data) asyncMap([p], function (f, cb) { - log.verbose(npm.modes.file.toString(8), "chmod "+f) + log.verbose("chmod", f, npm.modes.file.toString(8)) fs.chmod(f, npm.modes.file, cb) }, function (f, cb) { if (process.platform === "win32") { - log.silly(f, "skipping chown for windows") + log.silly("chown", "skipping for windows", f) cb() } else if (typeof uid === "number" && typeof gid === "number" && parseInt(uid, 10) === uid && parseInt(gid, 10) === gid) { - log.verbose([f, uid, gid], "chown") + log.verbose("chown", f, [uid, gid]) fs.chown(f, uid, gid, cb) } else { - log.verbose([f, uid, gid], "not chowning, invalid uid/gid") + log.verbose("chown", "skip for invalid uid/gid", [f, uid, gid]) cb() } }, function (er) { @@ -758,9 +787,15 @@ function addLocalDirectory (p, name, cb) { mkdir(path.dirname(tgz), function (er, made) { if (er) return cb(er) tar.pack(tgz, p, data, doFancyCrap, function (er) { - if (er) return log.er(cb,"couldn't pack "+p+ " to "+tgz)(er) + if (er) { + log.error( "addLocalDirectory", "Could not pack %j to %j" + , p, tgz ) + return cb(er) + } - if (er || !cs || isNaN(cs.uid) || isNaN(cs.gid)) return cb() + // if we don't get a cache stat, or if the gid/uid is not + // a number, then just move on. chown would fail anyway. + if (!cs || isNaN(cs.uid) || isNaN(cs.gid)) return cb() chownr(made || tgz, cs.uid, cs.gid, function (er) { if (er) return cb(er) @@ -797,7 +832,7 @@ function unpack (pkg, ver, unpackTarget, dMode, fMode, uid, gid, cb) { read(pkg, ver, false, function (er, data) { if (er) { - log.error("Could not read data for "+pkg+"@"+ver) + log.error("unpack", "Could not read data for %s", pkg + "@" + ver) return cb(er) } npm.commands.unbuild([unpackTarget], function (er) { @@ -819,6 +854,6 @@ function deprCheck (data) { else return if (!deprWarned[data._id]) { deprWarned[data._id] = true - log.warn(data._id+": "+data.deprecated, "deprecated") + log.warn("deprecated", "%s: %s", data._id, data.deprecated) } } diff --git a/deps/npm/lib/config.js b/deps/npm/lib/config.js index a69c30ea6..44f3d36f4 100644 --- a/deps/npm/lib/config.js +++ b/deps/npm/lib/config.js @@ -10,7 +10,7 @@ config.usage = "npm config set <key> <value>" + "\nnpm get [<key>]" var ini = require("./utils/ini.js") - , log = require("./utils/log.js") + , log = require("npmlog") , npm = require("./npm.js") , exec = require("./utils/exec.js") , fs = require("graceful-fs") @@ -129,7 +129,7 @@ function set (key, val, cb) { } key = key.trim() val = val.trim() - log("set "+key+" "+val, "config") + log.info("config", "set %j %j", key, val) var where = ini.get("global") ? "global" : "user" ini.set(key, val, where) ini.save(where, cb) diff --git a/deps/npm/lib/deprecate.js b/deps/npm/lib/deprecate.js index 6f18879e4..c9e724e69 100644 --- a/deps/npm/lib/deprecate.js +++ b/deps/npm/lib/deprecate.js @@ -18,10 +18,9 @@ deprecate.completion = function (opts, cb) { }) } -var registry = require("./utils/npm-registry-client/index.js") - , semver = require("semver") - , log = require("./utils/log.js") +var semver = require("semver") , npm = require("./npm.js") + , registry = npm.registry function deprecate (args, cb) { var pkg = args[0] @@ -43,6 +42,6 @@ function deprecate (args, cb) { data.versions[v].deprecated = msg }) // now update the doc on the registry - registry.request.PUT(data._id, data, cb) + registry.request('PUT', data._id, data, cb) }) } diff --git a/deps/npm/lib/docs.js b/deps/npm/lib/docs.js index 20b110406..72c1869b9 100644 --- a/deps/npm/lib/docs.js +++ b/deps/npm/lib/docs.js @@ -5,20 +5,20 @@ docs.usage = "npm docs <pkgname>" docs.completion = function (opts, cb) { if (opts.conf.argv.remain.length > 2) return cb() - registry.get("/-/short", null, 60000, function (er, list) { + registry.get("/-/short", 60000, function (er, list) { return cb(null, list || []) }) } var exec = require("./utils/exec.js") - , registry = require("./utils/npm-registry-client/index.js") , npm = require("./npm.js") - , log = require("./utils/log.js") + , registry = npm.registry + , log = require("npmlog") function docs (args, cb) { if (!args.length) return cb(docs.usage) var n = args[0].split("@").shift() - registry.get(n, "latest", 3600, function (er, d) { + registry.get(n + "/latest", 3600, function (er, d) { if (er) return cb(er) var homepage = d.homepage , repo = d.repository || d.repositories @@ -26,7 +26,7 @@ function docs (args, cb) { if (repo) { if (Array.isArray(repo)) repo = repo.shift() if (repo.hasOwnProperty("url")) repo = repo.url - log.verbose(repo, "repository") + log.verbose("repository", repo) if (repo) { return open(repo.replace(/^git(@|:\/\/)/, 'http://') .replace(/\.git$/, '')+"#readme", cb) diff --git a/deps/npm/lib/edit.js b/deps/npm/lib/edit.js index df103d4df..0ffe723bc 100644 --- a/deps/npm/lib/edit.js +++ b/deps/npm/lib/edit.js @@ -10,7 +10,6 @@ var npm = require("./npm.js") , exec = require("./utils/exec.js") , path = require("path") , fs = require("graceful-fs") - , log = require("./utils/log.js") function edit (args, cb) { var p = args[0] diff --git a/deps/npm/lib/help-search.js b/deps/npm/lib/help-search.js index a4ef667c0..6f1f117cb 100644 --- a/deps/npm/lib/help-search.js +++ b/deps/npm/lib/help-search.js @@ -7,7 +7,7 @@ var fs = require("graceful-fs") , asyncMap = require("slide").asyncMap , cliDocsPath = path.join(__dirname, "..", "doc", "cli") , apiDocsPath = path.join(__dirname, "..", "doc", "api") - , log = require("./utils/log.js") + , log = require("npmlog") , npm = require("./npm.js") helpSearch.usage = "npm help-search <text>" @@ -26,7 +26,10 @@ function helpSearch (args, silent, cb) { } fs.readdir(docsPath, function(er, files) { - if (er) return log.er(cb, "Could not load documentation")(er) + if (er) { + log.error("helpSearch", "Could not load documentation") + return cb(er) + } var search = args.join(" ") , results = [] diff --git a/deps/npm/lib/help.js b/deps/npm/lib/help.js index 442f839b3..998d90471 100644 --- a/deps/npm/lib/help.js +++ b/deps/npm/lib/help.js @@ -13,7 +13,7 @@ var fs = require("graceful-fs") , exec = require("./utils/exec.js") , npm = require("./npm.js") , output = require("./utils/output.js") - , log = require("./utils/log.js") + , log = require("npmlog") function help (args, cb) { var num = 1 @@ -34,6 +34,7 @@ function help (args, cb) { && npm.commands[section].usage ) { npm.config.set("loglevel", "silent") + log.level = "silent" return output.write(npm.commands[section].usage, cb) } @@ -83,6 +84,7 @@ function help (args, cb) { } else getSections(function (er, sections) { if (er) return cb(er) npm.config.set("loglevel", "silent") + log.level = "silent" output.write ( ["\nUsage: npm <command>" , "" diff --git a/deps/npm/lib/init.js b/deps/npm/lib/init.js index 7cd7da8e2..0d96e07ac 100644 --- a/deps/npm/lib/init.js +++ b/deps/npm/lib/init.js @@ -10,7 +10,7 @@ var read = require("read") , promiseChain = require("./utils/promise-chain.js") , exec = require("./utils/exec.js") , semver = require("semver") - , log = require("./utils/log.js") + , log = require("npmlog") , npm = require("./npm.js") , output = require("./utils/output.js") @@ -18,8 +18,7 @@ init.usage = "npm init [folder]" function init (args, cb) { var folder = args[0] || "." - , ll = npm.config.get("loglevel") - npm.config.set("loglevel", "paused") + log.pause() if (folder.charAt(0) !== "/") folder = path.join(process.cwd(), folder) readJson(path.join(folder, "package.json"), function (er, data) { @@ -31,8 +30,8 @@ function init (args, cb) { , url: npm.config.get("init.author.url") } init_(data, folder, function (er) { - npm.config.set("loglevel", ll) - if (!er) log(path.resolve(folder, "package.json"), "written") + log.resume() + if (!er) log.info("written", path.resolve(folder, "package.json")) cb(er) }) }) diff --git a/deps/npm/lib/install.js b/deps/npm/lib/install.js index 276f3d8b3..26a5a63ee 100644 --- a/deps/npm/lib/install.js +++ b/deps/npm/lib/install.js @@ -30,7 +30,7 @@ install.completion = function (opts, cb) { // if it has a slash, then it's gotta be a folder // if it starts with https?://, then just give up, because it's a url // for now, not yet implemented. - var registry = require("./utils/npm-registry-client/index.js") + var registry = npm.registry registry.get("/-/short", function (er, pkgs) { if (er) return cb() if (!opts.partialWord) return cb(null, pkgs) @@ -58,7 +58,7 @@ install.completion = function (opts, cb) { var npm = require("./npm.js") , semver = require("semver") , readJson = require("./utils/read-json.js") - , log = require("./utils/log.js") + , log = require("npmlog") , path = require("path") , fs = require("graceful-fs") , cache = require("./cache.js") @@ -98,7 +98,7 @@ function install (args, cb_) { where = args args = [].concat(cb_) // pass in [] to do default dep-install cb_ = arguments[2] - log.verbose([where, args], "install(where, what)") + log.verbose("install", "where,what", [where, args]) } if (!npm.config.get("global")) { @@ -117,9 +117,12 @@ function install (args, cb_) { , where , { dev: !npm.config.get("production") } , function (er, data) { - if (er) return log.er(cb, "Couldn't read dependencies.")(er) + if (er) { + log.error("install", "Couldn't read dependencies") + return cb(er) + } var deps = Object.keys(data.dependencies || {}) - log.verbose([where, deps], "where, deps") + log.verbose("install", "where, deps", [where, deps]) var context = { family: {} , ancestors: {} , explicit: false @@ -176,18 +179,18 @@ function readDependencies (context, where, opts, cb) { if (er) return cb(er) if (wrap) { - log.verbose([where, wrap], "readDependencies: using existing wrap") + log.verbose("readDependencies: using existing wrap", [where, wrap]) var rv = {} Object.keys(data).forEach(function (key) { rv[key] = data[key] }) rv.dependencies = {} Object.keys(wrap).forEach(function (key) { - log.verbose([key, wrap[key]], "from wrap") + log.verbose("from wrap", [key, wrap[key]]) var w = wrap[key] rv.dependencies[key] = w.from || w.version }) - log.verbose([rv.dependencies], "readDependencies: returned deps") + log.verbose("readDependencies returned deps", rv.dependencies) return cb(null, rv, wrap) } @@ -195,7 +198,7 @@ function readDependencies (context, where, opts, cb) { fs.readFile(wrapfile, "utf8", function (er, wrapjson) { if (er) { - log.verbose("readDependencies: using package.json deps") + log.verbose("readDependencies", "using package.json deps") return cb(null, data, null) } @@ -205,7 +208,7 @@ function readDependencies (context, where, opts, cb) { return cb(ex) } - log.info(wrapfile, "using shrinkwrap file") + log.info("shrinkwrap", "file %j", wrapfile) var rv = {} Object.keys(data).forEach(function (key) { rv[key] = data[key] @@ -215,7 +218,7 @@ function readDependencies (context, where, opts, cb) { var w = newwrap.dependencies[key] rv.dependencies[key] = w.from || w.version }) - log.verbose([rv.dependencies], "readDependencies: returned deps") + log.verbose("readDependencies returned deps", rv.dependencies) return cb(null, rv, newwrap.dependencies) }) }) @@ -358,10 +361,10 @@ function treeify (installed) { return l }, {}) - //log.warn(whatWhere, "whatWhere") + //log.warn("install", whatWhere, "whatWhere") return Object.keys(whatWhere).reduce(function (l, r) { var ww = whatWhere[r] - //log.warn([r, ww], "r, ww") + //log.warn("r, ww", [r, ww]) if (!ww.parent) { l[r] = ww } else { @@ -464,12 +467,12 @@ function installMany (what, where, context, cb) { targets.forEach(function (t) { newPrev[t.name] = t.version }) - log.silly(targets, "resolved") + log.silly("resolved", targets) targets.filter(function (t) { return t }).forEach(function (t) { - log.info(t._id, "into "+where) + log.info("install", "%s into %s", t._id, where) }) asyncMap(targets, function (target, cb) { - log.info(target._id, "installOne") + log.info("installOne", target._id) var newWrap = wrap ? wrap[target.name].dependencies || {} : null var newContext = { family: newPrev , ancestors: newAnc @@ -521,7 +524,7 @@ function targetResolver (where, context, deps) { // now we know what's been installed here manually, // or tampered with in some way that npm doesn't want to overwrite. if (alreadyInstalledManually.indexOf(what.split("@").shift()) !== -1) { - log.verbose("skipping "+what, "already installed in "+where) + log.verbose("already installed", "skipping %s %s", what, where) return cb(null, []) } @@ -529,7 +532,7 @@ function targetResolver (where, context, deps) { // If installing from a shrinkwrap, it must match exactly. if (context.family[what]) { if (wrap && wrap[what].version === context.family[what]) { - log.verbose(what, "using existing (matches shrinkwrap)") + log.verbose("shrinkwrap", "use existing", what) return cb(null, []) } } @@ -538,8 +541,8 @@ function targetResolver (where, context, deps) { // doing `npm install foo` inside of the foo project. Print // a warning, and skip it. if (parent && parent.name === what && !npm.config.get("force")) { - log.warn("Refusing to install "+what+" as a dependency of itself" - ,"install") + log.warn("install", "Refusing to install %s as a dependency of itself" + , what) return cb(null, []) } @@ -547,10 +550,10 @@ function targetResolver (where, context, deps) { name = what.split(/@/).shift() if (wrap[name]) { var wrapTarget = wrap[name].from || wrap[name].version - log.verbose("resolving "+what+" to "+wrapTarget, "shrinkwrap") + log.verbose("shrinkwrap", "resolving %s to %s", wrapTarget, what) what = name + "@" + wrapTarget } else { - log.verbose("skipping "+what+" (not in shrinkwrap)", "shrinkwrap") + log.verbose("shrinkwrap", "skipping %s (not in shrinkwrap)", what) } } else if (deps[what]) { what = what + "@" + deps[what] @@ -559,8 +562,8 @@ function targetResolver (where, context, deps) { cache.add(what, function (er, data) { if (er && parent && parent.optionalDependencies && parent.optionalDependencies.hasOwnProperty(what.split("@")[0])) { - log.warn(what, "optional dependency failed, continuing") - log.verbose([what, er], "optional dependency failed, continuing") + log.warn("optional dep failed, continuing", what) + log.verbose("optional dep failed, continuing", [what, er]) return cb(null, []) } @@ -569,7 +572,7 @@ function targetResolver (where, context, deps) { !context.explicit && context.family[data.name] === data.version && !npm.config.get("force")) { - log.info(data.name + "@" + data.version, "already installed") + log.info("already installed", data.name + "@" + data.version) return cb(null, []) } @@ -594,8 +597,8 @@ function installOne (target, where, context, cb) { // check if this one is optional to its parent. if (er && context.parent && context.parent.optionalDependencies && context.parent.optionalDependencies.hasOwnProperty(target.name)) { - log.warn(target._id, "optional dependency failed, continuing") - log.verbose([target._id, er], "optional dependency failed, continuing") + log.warn("optional dep failed, continuing", target._id) + log.verbose("optional dep failed, continuing", [target._id, er]) er = null } @@ -605,7 +608,7 @@ function installOne (target, where, context, cb) { } function localLink (target, where, context, cb) { - log.verbose(target._id, "try to link") + log.verbose("localLink", target._id) var jsonFile = path.resolve( npm.globalDir, target.name , "package.json" ) , parent = context.parent @@ -623,13 +626,13 @@ function localLink (target, where, context, cb) { function thenLink () { npm.commands.link([target.name], function (er, d) { - log.silly([er, d], "back from link") + log.silly("localLink", "back from link", [er, d]) cb(er, [resultList(target, where, parent && parent._id)]) }) } } else { - log.verbose(target._id, "install locally (no link)") + log.verbose("localLink", "install locally (no link)", target._id) installOne_(target, where, context, cb) } }) @@ -686,7 +689,7 @@ function checkEngine (target, cb) { if (nodev && eng.node && !semver.satisfies(nodev, eng.node) || eng.npm && !semver.satisfies(npmv, eng.npm)) { var er = new Error("Unsupported") - er.errno = npm.ENOTSUP + er.code = "ENOTSUP" er.required = eng er.pkgid = target._id return cb(er) @@ -713,7 +716,7 @@ function checkPlatform (target, cb) { } if (!osOk || !cpuOk) { var er = new Error("Unsupported") - er.errno = npm.EBADPLATFORM + er.code = "EBADPLATFORM" er.os = target.os || ['any'] er.cpu = target.cpu || ['any'] er.pkgid = target._id @@ -785,9 +788,9 @@ function checkCycle (target, ancestors, cb) { tree.push(JSON.parse(JSON.stringify(t))) t = Object.getPrototypeOf(t) } - log.verbose(tree, "unresolvable dependency tree") + log.verbose("unresolvable dependency tree", tree) er.pkgid = target._id - er.errno = npm.ECYCLE + er.code = "ECYCLE" return cb(er) } @@ -804,7 +807,7 @@ function checkGit_ (folder, cb) { if (!er && s.isDirectory()) { var e = new Error("Appears to be a git repo or submodule.") e.path = folder - e.errno = npm.EISGIT + e.code = "EISGIT" return cb(e) } cb() @@ -824,7 +827,7 @@ function write (target, targetFolder, context, cb_) { if (false === npm.config.get("rollback")) return cb_(er) npm.commands.unbuild([targetFolder], function (er2) { - if (er2) log.error(er2, "error rolling back "+target._id) + if (er2) log.error("error rolling back", target._id, er2) return cb_(er, data) }) } @@ -883,7 +886,7 @@ function write (target, targetFolder, context, cb_) { t = d + "@" + t return t }), targetFolder, newcontext, function (er, d) { - log.verbose(targetFolder, "about to build") + log.verbose("about to build", targetFolder) if (er) return cb(er) npm.commands.build( [targetFolder] , npm.config.get("global") diff --git a/deps/npm/lib/link.js b/deps/npm/lib/link.js index 3049884ca..de3d09c1c 100644 --- a/deps/npm/lib/link.js +++ b/deps/npm/lib/link.js @@ -1,11 +1,10 @@ - // link with no args: symlink the folder to the global location // link with package arg: symlink the global to the local var npm = require("./npm.js") , symlink = require("./utils/link.js") , fs = require("graceful-fs") - , log = require("./utils/log.js") + , log = require("npmlog") , asyncMap = require("slide").asyncMap , chain = require("slide").chain , path = require("path") @@ -30,16 +29,21 @@ link.completion = function (opts, cb) { function link (args, cb) { if (process.platform === "win32") { - var e = new Error("npm link not supported on windows") - e.code = "ENOTSUP" - e.errno = require("constants").ENOTSUP - return cb(e) + var semver = require("semver") + if (!semver.satisfies(process.version, ">=0.7.9")) { + var msg = "npm link not supported on windows prior to node 0.7.9" + , e = new Error(msg) + e.code = "ENOTSUP" + e.errno = require("constants").ENOTSUP + return cb(e) + } } if (npm.config.get("global")) { return cb(new Error("link should never be --global.\n" +"Please re-run this command with --local")) } + if (args.length === 1 && args[0] === ".") args = [] if (args.length) return linkInstall(args, cb) linkPkg(npm.prefix, cb) @@ -85,7 +89,7 @@ function linkInstall (pkgs, cb) { next() } else { return fs.realpath(pp, function (er, real) { - if (er) log.warn(pkg, "invalid symbolic link") + if (er) log.warn("invalid symbolic link", pkg) else rp = real next() }) @@ -95,7 +99,10 @@ function linkInstall (pkgs, cb) { function next () { chain ( [ [npm.commands, "unbuild", [target]] - , [log.verbose, "symlinking " + pp + " to "+target, "link"] + , [function (cb) { + log.verbose("link", "symlinking %s to %s", pp, target) + cb() + }] , [symlink, pp, target] // do run lifecycle scripts - full build here. , rp && [build, [target]] @@ -108,6 +115,9 @@ function linkInstall (pkgs, cb) { function linkPkg (folder, cb_) { var me = folder || npm.prefix , readJson = require("./utils/read-json.js") + + log.verbose("linkPkg", folder) + readJson( path.resolve(me, "package.json") , { dev: true } , function (er, d) { @@ -120,7 +130,7 @@ function linkPkg (folder, cb_) { if (er) return cb(er) symlink(me, target, function (er) { if (er) return cb(er) - log.verbose(target, "link: build target") + log.verbose("link", "build target", target) // also install missing dependencies. npm.commands.install(me, [], function (er, installed) { if (er) return cb(er) diff --git a/deps/npm/lib/ls.js b/deps/npm/lib/ls.js index 276530c35..29e65ad0d 100644 --- a/deps/npm/lib/ls.js +++ b/deps/npm/lib/ls.js @@ -10,7 +10,7 @@ module.exports = exports = ls var npm = require("./npm.js") , readInstalled = require("./utils/read-installed.js") , output = require("./utils/output.js") - , log = require("./utils/log.js") + , log = require("npmlog") , relativize = require("./utils/relativize.js") , path = require("path") , archy = require("archy") @@ -21,6 +21,8 @@ function ls (args, silent, cb) { if (typeof cb !== "function") cb = silent, silent = false if (args.length) { + // TODO: it would actually be nice to maybe show the locally + // installed packages only matching the argument names. log.warn("ls doesn't take positional args. Try the 'search' command") } @@ -167,10 +169,10 @@ function makeArchy_ (data, long, dir, depth, parent, d) { if (depth < npm.config.get("depth")) { // just missing var p = parent.link || parent.path - log.warn("Unmet dependency in "+p, d+" "+data) + log.warn("unmet dependency", "%s in %s", d+" "+data, p) data = "\033[31;40mUNMET DEPENDENCY\033[0m " + d + " " + data } else { - data = d+"@'"+ data +"' (max depth reached)" + data = d+"@"+ data +" (max depth reached)" } return data } @@ -244,7 +246,7 @@ function makeParseable_ (data, long, dir, depth, parent, d) { if (typeof data === "string") { if (data.depth < npm.config.get("depth")) { var p = parent.link || parent.path - log.warn("Unmet dependency in "+p, d+" "+data) + log.warn("unmet dependency", "%s in %s", d+" "+data, p) data = npm.config.get("long") ? path.resolve(parent.path, "node_modules", d) + ":"+d+"@"+JSON.stringify(data)+":INVALID:MISSING" diff --git a/deps/npm/lib/npm.js b/deps/npm/lib/npm.js index 2db21e34d..9b9545914 100644 --- a/deps/npm/lib/npm.js +++ b/deps/npm/lib/npm.js @@ -18,7 +18,7 @@ var EventEmitter = require("events").EventEmitter , npm = module.exports = new EventEmitter , config = require("./config.js") , ini = require("./utils/ini.js") - , log = require("./utils/log.js") + , log = require("npmlog") , fs = require("graceful-fs") , path = require("path") , abbrev = require("abbrev") @@ -29,6 +29,7 @@ var EventEmitter = require("events").EventEmitter , mkdirp = require("mkdirp") , slide = require("slide") , chain = slide.chain + , RegClient = require("npm-registry-client") // /usr/local is often a read-only fs, which is not // well handled by node or mkdirp. Just double-check @@ -48,14 +49,6 @@ function mkdir (p, cb) { } npm.commands = {} -npm.ELIFECYCLE = {} -npm.E404 = {} -npm.EPUBLISHCONFLICT = {} -npm.EJSONPARSE = {} -npm.EISGIT = {} -npm.ECYCLE = {} -npm.ENOTSUP = {} -npm.EBADPLATFORM = {} try { // startup, ok to do this synchronously @@ -64,17 +57,17 @@ try { npm.version = j.version npm.nodeVersionRequired = j.engines.node if (!semver.satisfies(process.version, j.engines.node)) { - log.error(["" + log.error("unsupported version", ["" ,"npm requires node version: "+j.engines.node ,"And you have: "+process.version ,"which is not satisfactory." ,"" ,"Bad things will likely happen. You have been warned." - ,""].join("\n"), "unsupported version") + ,""].join("\n")) } } catch (ex) { try { - log(ex, "error reading version") + log.info("error reading version", ex) } catch (er) {} npm.version = ex } @@ -250,7 +243,7 @@ npm.load = function (conf, cb_) { } } - log.waitForConfig() + log.pause() load(npm, conf, cb) } @@ -268,9 +261,33 @@ function load (npm, conf, cb) { //console.error("about to look up configs") ini.resolveConfigs(conf, function (er) { - //console.error("back from config lookup", er && er.stack) + log.level = npm.config.get("loglevel") + log.heading = "npm" + switch (npm.config.get("color")) { + case "always": log.enableColor(); break + case false: log.disableColor(); break + } + log.resume() + if (er) return cb(er) + // at this point the configs are all set. + // go ahead and spin up the registry client. + npm.registry = new RegClient( + { registry: npm.config.get("registry") + , cache: npm.config.get("cache") + , auth: npm.config.get("_auth") + , alwaysAuth: npm.config.get("always-auth") + , email: npm.config.get("email") + , tag: npm.config.get("tag") + , ca: npm.config.get("ca") + , strictSSL: npm.config.get("strict-ssl") + , userAgent: npm.config.get("user-agent") + , E404: npm.E404 + , EPUBLISHCONFLICT: npm.EPUBLISHCONFLICT + , log: log + }) + var umask = parseInt(conf.umask, 8) npm.modes = { exec: 0777 & (~umask) , file: 0666 & (~umask) @@ -352,7 +369,7 @@ function setUser (cl, dc, cb) { var prefix = path.resolve(cl.get("prefix")) mkdir(prefix, function (er) { if (er) { - log.error(prefix, "could not create prefix directory") + log.error("could not create prefix dir", prefix) return cb(er) } fs.stat(prefix, function (er, st) { diff --git a/deps/npm/lib/outdated.js b/deps/npm/lib/outdated.js index e883abd35..d87dc9ab6 100644 --- a/deps/npm/lib/outdated.js +++ b/deps/npm/lib/outdated.js @@ -24,7 +24,6 @@ var path = require("path") , cache = require("./cache.js") , asyncMap = require("slide").asyncMap , npm = require("./npm.js") - , log = require("./utils/log.js") , semver = require("semver") , relativize = require("./utils/relativize.js") diff --git a/deps/npm/lib/owner.js b/deps/npm/lib/owner.js index 5f13d926f..6a38625e5 100644 --- a/deps/npm/lib/owner.js +++ b/deps/npm/lib/owner.js @@ -64,12 +64,10 @@ owner.completion = function (opts, cb) { } } -var registry = require("./utils/npm-registry-client/index.js") - , get = registry.request.GET - , put = registry.request.PUT - , log = require("./utils/log.js") +var npm = require("./npm.js") + , registry = npm.registry + , log = require("npmlog") , output - , npm = require("./npm.js") function owner (args, cb) { var action = args.shift() @@ -83,9 +81,12 @@ function owner (args, cb) { function ls (pkg, cb) { if (!pkg) return cb(owner.usage) - get(pkg, function (er, data) { + registry.get(pkg, function (er, data) { var msg = "" - if (er) return log.er(cb, "Couldn't get owner data for "+pkg)(er) + if (er) { + log.error("owner ls", "Couldn't get owner data", pkg) + return cb(er) + } var owners = data.maintainers if (!owners || !owners.length) msg = "admin party!" else msg = owners.map(function (o) { return o.name +" <"+o.email+">" }).join("\n") @@ -101,15 +102,14 @@ function add (user, pkg, cb) { add(user, pkg, cb) }) - log.verbose(user+" to "+pkg, "owner add") + log.verbose("owner add", "%s to %s", user, pkg) mutate(pkg, user, function (u, owners) { if (!owners) owners = [] for (var i = 0, l = owners.length; i < l; i ++) { var o = owners[i] if (o.name === u.name) { - log( "Already a package owner: "+o.name+" <"+o.email+">" - , "owner add" - ) + log.info( "owner add" + , "Already a package owner: "+o.name+" <"+o.email+">") return false } } @@ -125,7 +125,7 @@ function rm (user, pkg, cb) { rm(user, pkg, cb) }) - log.verbose(user+" from "+pkg, "owner rm") + log.verbose("owner rm", "%s from %s", user, pkg) mutate(pkg, null, function (u, owners) { var found = false , m = owners.filter(function (o) { @@ -134,7 +134,7 @@ function rm (user, pkg, cb) { return !match }) if (!found) { - log("Not a package owner: "+user, "owner rm") + log.info("owner rm", "Not a package owner: "+user) return false } if (!m.length) return new Error( @@ -145,18 +145,26 @@ function rm (user, pkg, cb) { function mutate (pkg, user, mutation, cb) { if (user) { - get("/-/user/org.couchdb.user:"+user, mutate_) + registry.get("/-/user/org.couchdb.user:"+user, mutate_) } else { mutate_(null, null) } function mutate_ (er, u) { - if (er) return log.er(cb, "Error getting user data for "+user)(er) - if (user && (!u || u.error)) return cb(new Error( - "Couldn't get user data for "+user+": "+JSON.stringify(u))) + if (!er && user && (!u || u.error)) er = new Error( + "Couldn't get user data for "+user+": "+JSON.stringify(u)) + + if (er) { + log.error("owner mutate", "Error getting user data for %s", user) + return cb(er) + } + if (u) u = { "name" : u.name, "email" : u.email } - get("/"+pkg, function (er, data) { - if (er) return log.er(cb, "Couldn't get package data for "+pkg)(er) + registry.get(pkg, function (er, data) { + if (er) { + log.error("owner mutate", "Error getting package data for %s", pkg) + return cb(er) + } var m = mutation(u, data.maintainers) if (!m) return cb() // handled if (m instanceof Error) return cb(m) // error @@ -164,11 +172,15 @@ function mutate (pkg, user, mutation, cb) { , _rev : data._rev , maintainers : m } - put("/"+pkg+"/-rev/"+data._rev, data, function (er, data) { - if (er) return log.er(cb, "Failed to update package metadata")(er) - if (data.error) return cb(new Error( - "Failed to update package metadata: "+JSON.stringify(data))) - cb(null, data) + registry.request("PUT" + , pkg+"/-rev/"+data._rev, data + , function (er, data) { + if (!er && data.error) er = new Error( + "Failed to update package metadata: "+JSON.stringify(data)) + if (er) { + log.error("owner mutate", "Failed to update package metadata") + } + cb(er, data) }) }) } diff --git a/deps/npm/lib/publish.js b/deps/npm/lib/publish.js index 1cf59f01a..dfe21c251 100644 --- a/deps/npm/lib/publish.js +++ b/deps/npm/lib/publish.js @@ -2,8 +2,8 @@ module.exports = publish var npm = require("./npm.js") - , registry = require("./utils/npm-registry-client/index.js") - , log = require("./utils/log.js") + , registry = npm.registry + , log = require("npmlog") , tar = require("./utils/tar.js") , sha = require("./utils/sha.js") , path = require("path") @@ -29,7 +29,7 @@ function publish (args, isRetry, cb) { if (args.length === 0) args = ["."] if (args.length !== 1) return cb(publish.usage) - log.verbose(args, "publish") + log.verbose("publish", args) var arg = args[0] // if it's a local folder, then run the prepublish there, first. readJson(path.resolve(arg, "package.json"), function (er, data) { @@ -46,7 +46,7 @@ function publish (args, isRetry, cb) { function cacheAddPublish (arg, didPre, isRetry, cb) { npm.commands.cache.add(arg, function (er, data) { if (er) return cb(er) - log.silly(data, "publish") + log.silly("publish", data) var cachedir = path.resolve( npm.cache , data.name , data.version @@ -66,7 +66,7 @@ function publish_ (arg, data, isRetry, cachedir, cb) { // check for publishConfig hash if (data.publishConfig) { Object.keys(data.publishConfig).forEach(function (k) { - log.info(k + "=" + data.publishConfig[k], "publishConfig") + log.info("publishConfig", k + "=" + data.publishConfig[k]) npm.config.set(k, data.publishConfig[k]) }) } @@ -101,13 +101,13 @@ function preBuild (data, bd, cb) { , tb = path.resolve(cf, "package-"+bd+".tgz") , sourceBall = path.resolve(cf, "package.tgz") - log.verbose("about to cache unpack") - log.verbose(sourceBall, "the tarball") + log.verbose("preBuild", "about to cache unpack") + log.verbose("preBuild", "tarball = %s", sourceBall) npm.commands.install(pb, sourceBall, function (er) { - log.info(data._id, "prebuild done") + log.info("preBuild", "done", data._id) // build failure just means that we can't prebuild if (er) { - log.warn(er.message, "prebuild failed "+bd) + log.warn("preBuild", "failed (continuing without prebuild)", bd, er) return cb() } // now strip the preinstall/install scripts @@ -149,12 +149,15 @@ function preBuild (data, bd, cb) { function regPublish (data, prebuilt, isRetry, arg, cachedir, cb) { // check to see if there's a README.md in there. var readme = path.resolve(cachedir, "README.md") + , tarball = cachedir + ".tgz" + fs.readFile(readme, function (er, readme) { // ignore error. it's an optional feature - registry.publish(data, prebuilt, readme, function (er) { - if (er && er.errno === npm.EPUBLISHCONFLICT + + registry.publish(data, tarball, readme, function (er) { + if (er && er.code === "EPUBLISHCONFLICT" && npm.config.get("force") && !isRetry) { - log.warn("Forced publish over "+data._id, "publish") + log.warn("publish", "Forced publish over "+data._id) return npm.commands.unpublish([data._id], function (er) { // ignore errors. Use the force. Reach out with your feelings. publish([arg], true, cb) diff --git a/deps/npm/lib/rebuild.js b/deps/npm/lib/rebuild.js index 0e1d56a1d..a4a39f7b9 100644 --- a/deps/npm/lib/rebuild.js +++ b/deps/npm/lib/rebuild.js @@ -3,7 +3,7 @@ module.exports = rebuild var readInstalled = require("./utils/read-installed.js") , semver = require("semver") - , log = require("./utils/log.js") + , log = require("npmlog") , path = require("path") , npm = require("./npm.js") , output = require("./utils/output.js") @@ -17,14 +17,14 @@ rebuild.completion = require("./utils/completion/installed-deep.js") function rebuild (args, cb) { readInstalled(npm.prefix, function (er, data) { - log(typeof data, "read Installed") + log.info("readInstalled", typeof data) if (er) return cb(er) var set = filter(data, args) , folders = Object.keys(set).filter(function (f) { return f !== npm.prefix }) if (!folders.length) return cb() - log.silly(folders, "rebuild set") + log.silly("rebuild set", folders) cleanBuild(folders, set, cb) }) } @@ -79,7 +79,7 @@ function filter (data, args, set, seen) { } } if (pass && data._id) { - log.verbose([data.path, data._id], "path id") + log.verbose("rebuild", "path, id", [data.path, data._id]) set[data.path] = data._id } // need to also dive through kids, always. diff --git a/deps/npm/lib/root.js b/deps/npm/lib/root.js index 6062ec220..59ccc0b08 100644 --- a/deps/npm/lib/root.js +++ b/deps/npm/lib/root.js @@ -2,7 +2,6 @@ module.exports = root var npm = require("./npm.js") , output = require("./utils/output.js") - , log = require("./utils/log.js") root.usage = "npm root\nnpm root -g\n(just prints the root folder)" diff --git a/deps/npm/lib/run-script.js b/deps/npm/lib/run-script.js index 4a4d2dc61..17b48abf8 100644 --- a/deps/npm/lib/run-script.js +++ b/deps/npm/lib/run-script.js @@ -5,7 +5,7 @@ var lifecycle = require("./utils/lifecycle.js") , npm = require("./npm.js") , path = require("path") , readJson = require("./utils/read-json.js") - , log = require("./utils/log.js") + , log = require("npmlog") , chain = require("slide").chain , fs = require("graceful-fs") , asyncMap = require("slide").asyncMap @@ -92,7 +92,7 @@ function run (pkg, wd, cmd, cb) { if (!cmd.match(/^(pre|post)/)) { cmds = ["pre"+cmd].concat(cmds).concat("post"+cmd) } - log.verbose(cmds, "run-script") + log.verbose("run-script", cmds) chain(cmds.map(function (c) { // when running scripts explicitly, assume that they're trusted. return [lifecycle, pkg, c, wd, true] diff --git a/deps/npm/lib/search.js b/deps/npm/lib/search.js index 213390eb0..9ed712bcc 100644 --- a/deps/npm/lib/search.js +++ b/deps/npm/lib/search.js @@ -2,10 +2,9 @@ module.exports = exports = search var npm = require("./npm.js") - , registry = require("./utils/npm-registry-client/index.js") + , registry = npm.registry , semver = require("semver") , output - , log = require("./utils/log.js") search.usage = "npm search [some search terms ...]" @@ -60,7 +59,7 @@ function search (args, silent, staleness, cb_) { } function getFilteredData (staleness, args, notArgs, cb) { - registry.get( "/-/all", null, staleness, false + registry.get( "/-/all", staleness, false , true, function (er, data) { if (er) return cb(er) return cb(null, filter(data, args, notArgs)) diff --git a/deps/npm/lib/shrinkwrap.js b/deps/npm/lib/shrinkwrap.js index 59942d586..cdad89abc 100644 --- a/deps/npm/lib/shrinkwrap.js +++ b/deps/npm/lib/shrinkwrap.js @@ -5,7 +5,7 @@ module.exports = exports = shrinkwrap var npm = require("./npm.js") , output = require("./utils/output.js") - , log = require("./utils/log.js") + , log = require("npmlog") , fs = require("fs") , path = require("path") @@ -15,7 +15,7 @@ function shrinkwrap (args, silent, cb) { if (typeof cb !== "function") cb = silent, silent = false if (args.length) { - log.warn("shrinkwrap doesn't take positional args.") + log.warn("shrinkwrap", "doesn't take positional args") } npm.commands.ls([], true, function (er, _, pkginfo) { @@ -33,7 +33,7 @@ function shrinkwrap_ (pkginfo, silent, cb) { try { var swdata = JSON.stringify(pkginfo, null, 2) + "\n" } catch (er) { - log.error("Error converting package info to json") + log.error("shrinkwrap", "Error converting package info to json") return cb(er) } diff --git a/deps/npm/lib/star.js b/deps/npm/lib/star.js index d84fa02ed..fc4fb96f1 100644 --- a/deps/npm/lib/star.js +++ b/deps/npm/lib/star.js @@ -2,8 +2,8 @@ module.exports = star var npm = require("./npm.js") - , registry = require("./utils/npm-registry-client/index.js") - , log = require("./utils/log.js") + , registry = npm.registry + , log = require("npmlog") , asyncMap = require("slide").asyncMap , output = require("./utils/output.js") @@ -11,7 +11,7 @@ star.usage = "npm star <package> [pkg, pkg, ...]\n" + "npm unstar <package> [pkg, pkg, ...]" star.completion = function (opts, cb) { - registry.get("/-/short", null, 60000, function (er, list) { + registry.get("/-/short", 60000, function (er, list) { return cb(null, list || []) }) } @@ -26,7 +26,7 @@ function star (args, cb) { registry.star(pkg, using, function (er, data, raw, req) { if (!er) { output.write(s + " "+pkg, npm.config.get("outfd")) - log.verbose(data, "back from star/unstar") + log.verbose("star", data) } cb(er, data, raw, req) }) diff --git a/deps/npm/lib/substack.js b/deps/npm/lib/substack.js index 95a90f824..1929f1873 100644 --- a/deps/npm/lib/substack.js +++ b/deps/npm/lib/substack.js @@ -1,9 +1,19 @@ module.exports = substack var npm = require("./npm.js") - , log = require("./utils/log.js") + +var isms = + [ "\033[32mbeep \033[35mboop\033[m" + , "Replace your configs with services" + , "SEPARATE ALL THE CONCERNS!" + , "MODULE ALL THE THINGS!" + , "\\o/" + , "but first, burritos" + , "full time mad scientist here" + , "c/,,\\" ] function substack (args, cb) { - console.log("\033[32mbeep \033[35mboop\033[m") + var i = Math.floor(Math.random() * isms.length) + console.log(isms[i]) var c = args.shift() if (c) npm.commands[c](args, cb) else cb() diff --git a/deps/npm/lib/tag.js b/deps/npm/lib/tag.js index 06aa70c5e..8a7c51ca0 100644 --- a/deps/npm/lib/tag.js +++ b/deps/npm/lib/tag.js @@ -6,6 +6,7 @@ tag.usage = "npm tag <project>@<version> [<tag>]" tag.completion = require("./unpublish.js").completion var npm = require("./npm.js") + , registry = npm.registry function tag (args, cb) { var thing = (args.shift() || "").split("@") @@ -13,5 +14,5 @@ function tag (args, cb) { , version = thing.join("@") , t = args.shift() || npm.config.get("tag") if (!project || !version || !t) return cb("Usage:\n"+tag.usage) - require("./utils/npm-registry-client/index.js").tag(project, version, t, cb) + registry.tag(project, version, t, cb) } diff --git a/deps/npm/lib/unbuild.js b/deps/npm/lib/unbuild.js index 771eddf7d..dd0293be5 100644 --- a/deps/npm/lib/unbuild.js +++ b/deps/npm/lib/unbuild.js @@ -10,7 +10,7 @@ var readJson = require("./utils/read-json.js") , lifecycle = require("./utils/lifecycle.js") , asyncMap = require("slide").asyncMap , chain = require("slide").chain - , log = require("./utils/log.js") + , log = require("npmlog") , build = require("./build.js") // args is a list of folders. @@ -55,7 +55,8 @@ function rmBins (pkg, folder, parent, top, cb) { log.verbose([binRoot, pkg.bin], "binRoot") asyncMap(Object.keys(pkg.bin), function (b, cb) { if (process.platform === "win32") { - rm(path.resolve(binRoot, b) + ".cmd", cb) + chain([ [rm, path.resolve(binRoot, b) + ".cmd"] + , [rm, path.resolve(binRoot, b) ] ], cb) } else { gentlyRm( path.resolve(binRoot, b) , !npm.config.get("force") && folder diff --git a/deps/npm/lib/uninstall.js b/deps/npm/lib/uninstall.js index 655e5eb96..a1998e7fe 100644 --- a/deps/npm/lib/uninstall.js +++ b/deps/npm/lib/uninstall.js @@ -9,7 +9,7 @@ uninstall.usage = "npm uninstall <name>[@<version> [<name>[@<version>] ...]" uninstall.completion = require("./utils/completion/installed-shallow.js") var fs = require("graceful-fs") - , log = require("./utils/log.js") + , log = require("npmlog") , readJson = require("./utils/read-json.js") , path = require("path") , npm = require("./npm.js") @@ -43,12 +43,12 @@ function uninstall_ (args, nm, cb) { // uninstall .. should not delete /usr/local/lib/node_modules/.. var p = path.join(path.resolve(nm), path.join("/", arg)) if (path.resolve(p) === nm) { - log.warn(arg, "uninstall: invalid argument") + log.warn("uninstall", "invalid argument: %j", arg) return cb(null, []) } fs.lstat(p, function (er) { if (er) { - log.warn(arg, "Not installed in "+nm) + log.warn("uninstall", "not installed in %s: %j", nm, arg) return cb(null, []) } cb(null, p) diff --git a/deps/npm/lib/unpublish.js b/deps/npm/lib/unpublish.js index b7f6cbec8..8aae12c3d 100644 --- a/deps/npm/lib/unpublish.js +++ b/deps/npm/lib/unpublish.js @@ -1,9 +1,9 @@ module.exports = unpublish -var registry = require("./utils/npm-registry-client/index.js") - , log = require("./utils/log.js") +var log = require("npmlog") , npm = require("./npm.js") + , registry = npm.registry , readJson = require("./utils/read-json.js") , path = require("path") , output = require("./utils/output.js") @@ -72,7 +72,11 @@ function gotProject (project, version, cb_) { // remove from the cache first npm.commands.cache(["clean", project, version], function (er) { - if (er) return log.er(cb, "Failed to clean cache")(er) + if (er) { + log.error("unpublish", "Failed to clean cache") + return cb(er) + } + registry.unpublish(project, version, cb) }) } diff --git a/deps/npm/lib/update.js b/deps/npm/lib/update.js index 69b9f98e8..46d32678e 100644 --- a/deps/npm/lib/update.js +++ b/deps/npm/lib/update.js @@ -12,7 +12,7 @@ update.usage = "npm update [pkg]" var npm = require("./npm.js") , lifecycle = require("./utils/lifecycle.js") , asyncMap = require("slide").asyncMap - , log = require("./utils/log.js") + , log = require("npmlog") // load these, just so that we know that they'll be available, in case // npm itself is getting overwritten. @@ -23,7 +23,7 @@ update.completion = npm.commands.outdated.completion function update (args, cb) { npm.commands.outdated(args, true, function (er, outdated) { - log(outdated, "outdated updating") + log.info("outdated", "updating", outdated) if (er) return cb(er) asyncMap(outdated, function (ww, cb) { diff --git a/deps/npm/lib/utils/cmd-shim.js b/deps/npm/lib/utils/cmd-shim.js index e24da36f6..a31af6801 100644 --- a/deps/npm/lib/utils/cmd-shim.js +++ b/deps/npm/lib/utils/cmd-shim.js @@ -16,7 +16,7 @@ var fs = require("graceful-fs") , chain = require("slide").chain , mkdir = require("mkdirp") , rm = require("rimraf") - , log = require("./log.js") + , log = require("npmlog") , path = require("path") , relativize = require("./relativize.js") , npm = require("../npm.js") @@ -122,12 +122,12 @@ function writeShim_ (from, to, prog, args, cb) { fs.writeFile(to + ".cmd", cmd, "utf8", function (er) { if (er) { - log.warn("Could not write "+to+".cmd", "cmdShim") + log.warn("cmdShim", "Could not write "+to+".cmd") return cb(er) } fs.writeFile(to, sh, "utf8", function (er) { if (er) { - log.warn("Could not write "+to, "shShim") + log.warn("shShim", "Could not write "+to) return cb(er) } fs.chmod(to, 0755, cb) diff --git a/deps/npm/lib/utils/completion/remote-packages.js b/deps/npm/lib/utils/completion/remote-packages.js index 4bf82d070..18d812caa 100644 --- a/deps/npm/lib/utils/completion/remote-packages.js +++ b/deps/npm/lib/utils/completion/remote-packages.js @@ -1,7 +1,8 @@ module.exports = remotePackages -var registry = require("../npm-registry-client/index.js") +var npm = require("../../npm.js") + , registry = npm.registry , containsSingleMatch = require("./contains-single-match.js") , getCompletions = require("./get-completions.js") @@ -25,7 +26,7 @@ function remotePackages (args, index, doVersion, doTag if (name === undefined) name = "" if (name.indexOf("/") !== -1) return cb(null, []) // use up-to 1 hour stale cache. not super urgent. - registry.get("/", null, 3600, function (er, d) { + registry.get("/", 3600, function (er, d) { if (er) return cb(er) var remoteList = Object.keys(d) , found = remoteList.indexOf(name) diff --git a/deps/npm/lib/utils/completion/users.js b/deps/npm/lib/utils/completion/users.js index f77312c94..1dc6dbb91 100644 --- a/deps/npm/lib/utils/completion/users.js +++ b/deps/npm/lib/utils/completion/users.js @@ -1,19 +1,20 @@ module.exports = users -var registry = require("../npm-registry-client/index.js") +var npm = require("../../npm") + , registry = npm.registry , containsSingleMatch = require("./contains-single-match.js") , getCompletions = require("./get-completions.js") - , log = require("../log.js") + , log = require("npmlog") function users (args, index, cb) { var name = (args.length + 1 === index) ? args[args.length - 1] : "" if (name === undefined) name = "" // use up-to 1 day stale cache. doesn't change much - log.warn("About to fetch", "users completion") - registry.get("/-/users", null, 24*60*60, function (er, d) { - log.warn(d, "userdata") - log.warn(name, "name") + log.warn("users completion", "About to fetch") + registry.get("/-/users", 24*60*60, function (er, d) { + log.warn("userdata", d) + log.warn("name", name) if (er) return cb(er) var remoteList = Object.keys(d) , simpleMatches = getCompletions(name, remoteList) diff --git a/deps/npm/lib/utils/config-defs.js b/deps/npm/lib/utils/config-defs.js index 18b47ecdb..4542e8fd6 100644 --- a/deps/npm/lib/utils/config-defs.js +++ b/deps/npm/lib/utils/config-defs.js @@ -8,7 +8,7 @@ var path = require("path") , stableFamily = semver.parse(process.version) , os = require("os") , nopt = require("nopt") - , log = require("./log.js") + , log = require("npmlog") , npm = require("../npm.js") function Octal () {} @@ -32,7 +32,7 @@ nopt.typeDefs.semver = { type: semver, validate: validateSemver } nopt.typeDefs.Octal = { type: Octal, validate: validateOctal } nopt.invalidHandler = function (k, val, type, data) { - log.warn(k + "=" + JSON.stringify(val), "invalid config") + log.warn("invalid config", k + "=" + JSON.stringify(val)) if (Array.isArray(type)) { if (type.indexOf(url) !== -1) type = url @@ -41,16 +41,16 @@ nopt.invalidHandler = function (k, val, type, data) { switch (type) { case Octal: - log.warn("Must be octal number, starting with 0", "invalid config") + log.warn("invalid config", "Must be octal number, starting with 0") break case url: - log.warn("Must be a full url with 'http://'", "invalid config") + log.warn("invalid config", "Must be a full url with 'http://'") break case path: - log.warn("Must be a valid filesystem path", "invalid config") + log.warn("invalid config", "Must be a valid filesystem path") break case Number: - log.warn("Must be a numeric value", "invalid config") + log.warn("invalid config", "Must be a numeric value") break } } @@ -58,9 +58,6 @@ nopt.invalidHandler = function (k, val, type, data) { if (!stableFamily || (+stableFamily[2] % 2)) stableFamily = null else stableFamily = stableFamily[1] + "." + stableFamily[2] -var httpsOk = semver.satisfies(process.version, ">=0.4.9") -var winColor = semver.satisfies(process.version, ">=0.5.9") - var defaults var temp = process.env.TMPDIR @@ -143,7 +140,7 @@ Object.defineProperty(exports, "defaults", {get: function () { , "cache-max": Infinity , "cache-min": 0 - , color : process.platform !== "win32" || winColor + , color : true , coverage: false , depth: Infinity , description : true @@ -166,9 +163,7 @@ Object.defineProperty(exports, "defaults", {get: function () { , "init.author.url" : "" , json: false , link: false - , logfd : 2 , loglevel : "http" - , logprefix : process.platform !== "win32" || winColor , long : false , message : "%s" , "node-version" : process.version @@ -186,7 +181,7 @@ Object.defineProperty(exports, "defaults", {get: function () { process.env.HTTP_PROXY || process.env.http_proxy || null , "user-agent" : "npm/" + npm.version + " node/" + process.version , "rebuild-bundle" : true - , registry : "http" + (httpsOk ? "s" : "") + "://registry.npmjs.org/" + , registry : "https://registry.npmjs.org/" , rollback : true , save : false , "save-dev" : false @@ -251,9 +246,7 @@ exports.types = , "init.author.url" : ["", url] , json: Boolean , link: Boolean - , logfd : [Number, Stream] , loglevel : ["silent","win","error","warn","http","info","verbose","silly"] - , logprefix : Boolean , long : Boolean , message: String , "node-version" : [null, semver] diff --git a/deps/npm/lib/utils/error-handler.js b/deps/npm/lib/utils/error-handler.js index f7fdf165f..a5332b050 100644 --- a/deps/npm/lib/utils/error-handler.js +++ b/deps/npm/lib/utils/error-handler.js @@ -2,10 +2,9 @@ module.exports = errorHandler var cbCalled = false - , log = require("./log.js") + , log = require("npmlog") , npm = require("../npm.js") , rm = require("rimraf") - , constants = require("constants") , itWorked = false , path = require("path") , ini = require("./ini.js") @@ -20,16 +19,17 @@ process.on("exit", function (code) { if (itWorked) log.info("ok") else { if (!cbCalled) { - log.error("cb() never called!\n ") + log.error("", "cb() never called!") } + if (wroteLogFile) { - log.error(["" + log.error("", ["" ,"Additional logging details can be found in:" ," " + path.resolve("npm-debug.log") ].join("\n")) wroteLogFile = false } - log.win("not ok") + log.error("not ok", "code", code) } var doExit = npm.config.get("_exit") @@ -48,13 +48,16 @@ function exit (code, noLog) { exitCode = exitCode || code var doExit = npm.config.get("_exit") - log.verbose([code, doExit], "exit") - if (log.level === log.LEVEL.silent) noLog = true + log.verbose("exit", [code, doExit]) + if (log.level === "silent") noLog = true if (code && !noLog) writeLogFile(reallyExit) else rm("npm-debug.log", function () { rm(npm.tmp, reallyExit) }) function reallyExit() { + // truncate once it's been written. + log.record.length = 0 + itWorked = !code // just emit a fake exit event. @@ -80,40 +83,32 @@ function errorHandler (er) { cbCalled = true if (!er) return exit(0) if (!(er instanceof Error)) { - log.error(er) + log.error("weird error", er) return exit(1, true) } var m = er.code || er.message.match(/^(?:Error: )?(E[A-Z]+)/) - if (m) { - m = m[1] - if (!constants[m] && !npm[m]) constants[m] = {} - er.errno = npm[m] || constants[m] - } + if (m && !er.code) er.code = m - console.error("") - switch (er.code || er.errno) { + switch (er.code) { case "ECONNREFUSED": - case constants.ECONNREFUSED: - log.error(er) - log.error(["\nIf you are behind a proxy, please make sure that the" + log.error("", er) + log.error("", ["\nIf you are behind a proxy, please make sure that the" ,"'proxy' config is set properly. See: 'npm help config'" ].join("\n")) break case "EACCES": case "EPERM": - case constants.EACCES: - case constants.EPERM: - log.error(er) - log.error(["\nPlease try running this command again as root/Administrator." + log.error("", er) + log.error("", ["\nPlease try running this command again as root/Administrator." ].join("\n")) break - case npm.ELIFECYCLE: + case "ELIFECYCLE": er.code = "ELIFECYCLE" - log.error(er.message) - log.error(["","Failed at the "+er.pkgid+" "+er.stage+" script." + log.error("", er.message) + log.error("", ["","Failed at the "+er.pkgid+" "+er.stage+" script." ,"This is most likely a problem with the "+er.pkgname+" package," ,"not with npm itself." ,"Tell the author that this fails on your system:" @@ -124,18 +119,18 @@ function errorHandler (er) { ].join("\n")) break - case npm.EJSONPARSE: + case "EJSONPARSE": er.code = "EJSONPARSE" - log.error(er.message) - log.error("File: "+er.file) - log.error(["Failed to parse package.json data." + log.error("", er.message) + log.error("", "File: "+er.file) + log.error("", ["Failed to parse package.json data." ,"package.json must be actual JSON, not just JavaScript." ,"","This is not a bug in npm." ,"Tell the package author to fix their package.json file." ].join("\n"), "JSON.parse") break - case npm.E404: + case "E404": er.code = "E404" if (er.pkgid && er.pkgid !== "-") { var msg = ["'"+er.pkgid+"' is not in the npm registry." @@ -149,51 +144,40 @@ function errorHandler (er) { } msg.push("\nNote that you can also install from a" ,"tarball, folder, or http url, or git url.") - log.error(msg.join("\n"), "404") + log.error("404", msg.join("\n")) } break - case npm.EPUBLISHCONFLICT: + case "EPUBLISHCONFLICT": er.code = "EPUBLISHCONFLICT" - log.error(["Cannot publish over existing version." + log.error("publish fail", ["Cannot publish over existing version." ,"Bump the 'version' field, set the --force flag, or" ," npm unpublish '"+er.pkgid+"'" ,"and try again" - ].join("\n"), "publish fail" ) + ].join("\n")) break - case npm.EISGIT: + case "EISGIT": er.code = "EISGIT" - log.error([er.message + log.error("git", [er.message ," "+er.path ,"Refusing to remove it. Update manually," ,"or move it out of the way first." - ].join("\n"), "git" ) + ].join("\n")) break - case npm.ECYCLE: + case "ECYCLE": er.code = "ECYCLE" - log.error([er.message + log.error("cycle", [er.message ,"While installing: "+er.pkgid ,"Found a pathological dependency case that npm cannot solve." ,"Please report this to the package author." ].join("\n")) break - case npm.ENOTSUP: - er.code = "ENOTSUP" - log.error([er.message - ,"Not compatible with your version of node/npm: "+er.pkgid - ,"Required: "+JSON.stringify(er.required) - ,"Actual: " - +JSON.stringify({npm:npm.version - ,node:npm.config.get("node-version")}) - ].join("\n")) - break - - case npm.EBADPLATFORM: + case "EBADPLATFORM": er.code = "EBADPLATFORM" - log.error([er.message + log.error("notsup", [er.message ,"Not compatible with your operating system or architecture: "+er.pkgid ,"Valid OS: "+er.os.join(",") ,"Valid Arch: "+er.cpu.join(",") @@ -203,15 +187,26 @@ function errorHandler (er) { break case "EEXIST": - case constants.EEXIST: log.error([er.message ,"File exists: "+er.path ,"Move it away, and try again."].join("\n")) break + case "ENOTSUP": + if (er.required) { + log.error("notsup", [er.message + ,"Not compatible with your version of node/npm: "+er.pkgid + ,"Required: "+JSON.stringify(er.required) + ,"Actual: " + +JSON.stringify({npm:npm.version + ,node:npm.config.get("node-version")}) + ].join("\n")) + break + } // else passthrough + default: - log.error(er) - log.error(["You may report this log at:" + log.error("", er) + log.error("", ["You may report this log at:" ," <http://github.com/isaacs/npm/issues>" ,"or email it to:" ," <npm-@googlegroups.com>" @@ -220,13 +215,14 @@ function errorHandler (er) { } var os = require("os") - log.error("") - log.error(os.type() + " " + os.release(), "System") - log.error(process.argv - .map(JSON.stringify).join(" "), "command") - log.error(process.cwd(), "cwd") - log.error(process.version, "node -v") - log.error(npm.version, "npm -v") + // just a line break + console.error("") + log.error("System", os.type() + " " + os.release()) + log.error("command", process.argv + .map(JSON.stringify).join(" ")) + log.error("cwd", process.cwd()) + log.error("node -v", process.version) + log.error("npm -v", npm.version) ; [ "file" , "path" @@ -238,16 +234,15 @@ function errorHandler (er) { , "fstream_class" , "fstream_finish_call" , "fstream_linkpath" - , "arguments" , "code" , "message" , "errno" ].forEach(function (k) { - if (er[k]) log.error(er[k], k) + if (er[k]) log.error(k, er[k]) }) if (er.fstream_stack) { - log.error(er.fstream_stack.join("\n"), "fstream_stack") + log.error("fstream_stack", er.fstream_stack.join("\n")) } if (er.errno && typeof er.errno !== "object") log.error(er.errno, "errno") @@ -263,19 +258,21 @@ function writeLogFile (cb) { var fs = require("graceful-fs") , fstr = fs.createWriteStream("npm-debug.log") , util = require("util") - - log.history.forEach(function (m) { - var lvl = log.LEVEL[m.level] - , pref = m.pref ? " " + m.pref : "" - , b = lvl + pref + " " - , eol = process.platform === "win32" ? "\r\n" : "\n" - , msg = typeof m.msg === "string" ? m.msg - : msg instanceof Error ? msg.stack || msg.message - : util.inspect(m.msg, 0, 4) - fstr.write(new Buffer(b - +(msg.split(/\r?\n+/).join(eol+b)) - + eol)) + , eol = process.platform === "win32" ? "\r\n" : "\n" + , out = "" + + log.record.forEach(function (m) { + var pref = [m.id, m.level] + if (m.prefix) pref.push(m.prefix) + pref = pref.join(' ') + + m.message.trim().split(/\r?\n/).map(function (line) { + return (pref + ' ' + line).trim() + }).forEach(function (line) { + out += line + eol + }) }) - fstr.end() + + fstr.end(out) fstr.on("close", cb) } diff --git a/deps/npm/lib/utils/exec.js b/deps/npm/lib/utils/exec.js index b9a5b6911..56d331a67 100644 --- a/deps/npm/lib/utils/exec.js +++ b/deps/npm/lib/utils/exec.js @@ -1,8 +1,7 @@ module.exports = exec exec.spawn = spawn -exec.pipe = pipe -var log = require("./log.js") +var log = require("npmlog") , child_process = require("child_process") , util = require("util") , npm = require("../npm.js") @@ -31,8 +30,7 @@ function exec (cmd, args, env, takeOver, cwd, uid, gid, cb) { } } if (uid !== myUID) { - log.verbose(uid, "Setting uid from "+myUID) - log.verbose(new Error().stack, "stack at uid setting") + log.verbose("set uid", "from=%s to=%s", myUID, uid) } if (uid && gid && (isNaN(uid) || isNaN(gid))) { @@ -43,7 +41,7 @@ function exec (cmd, args, env, takeOver, cwd, uid, gid, cb) { }) } - log.silly(cmd+" "+args.map(JSON.stringify).join(" "), "exec") + log.silly("exec", cmd+" "+args.map(JSON.stringify).join(" ")) var stdout = "" , stderr = "" , cp = spawn(cmd, args, env, takeOver, cwd, uid, gid) @@ -65,38 +63,6 @@ function exec (cmd, args, env, takeOver, cwd, uid, gid, cb) { return cp } -function logger (d) { if (d) process.stderr.write(d+"") } -function pipe (cp1, cp2, cb) { - util.pump(cp1.stdout, cp2.stdin) - var errState = null - , buff1 = "" - , buff2 = "" - if (log.level <= log.LEVEL.silly) { - cp1.stderr.on("data", logger) - cp2.stderr.on("data", logger) - } else { - cp1.stderr.on("data", function (d) { buff1 += d }) - cp2.stderr.on("data", function (d) { buff2 += d }) - } - - cp1.on("exit", function (code) { - if (!code) return log.verbose(cp1.name || "<unknown>", "success") - if (!cp2._exited) cp2.kill() - log.error(buff1, cp1.name || "<unknown>") - cb(errState = new Error( - "Failed "+(cp1.name || "<unknown>")+"\nexited with "+code)) - }) - - cp2.on("exit", function (code) { - cp2._exited = true - if (errState) return - if (!code) return log.verbose(cp2.name || "<unknown>", "success", cb) - log.error(buff2, cp2.name || "<unknown>") - cb(new Error( "Failed " - + (cp2.name || "<unknown>") - + "\nexited with " + code )) - }) -} function spawn (c, a, env, takeOver, cwd, uid, gid) { var fds = [ 0, 1, 2 ] diff --git a/deps/npm/lib/utils/fetch.js b/deps/npm/lib/utils/fetch.js index bc1c095cd..f69975ba6 100644 --- a/deps/npm/lib/utils/fetch.js +++ b/deps/npm/lib/utils/fetch.js @@ -6,7 +6,7 @@ var request = require("request") , fs = require("graceful-fs") , npm = require("../npm.js") , url = require("url") - , log = require("./log.js") + , log = require("npmlog") , path = require("path") , mkdir = require("mkdirp") , chownr = require("chownr") @@ -16,7 +16,7 @@ module.exports = fetch function fetch (remote, local, headers, cb) { if (typeof cb !== "function") cb = headers, headers = {} - log.verbose(local, "fetch to") + log.verbose("fetch", "to=", local) mkdir(path.dirname(local), function (er, made) { if (er) return cb(er) fetch_(remote, local, headers, cb) @@ -41,7 +41,7 @@ function fetch_ (remote, local, headers, cb) { function makeRequest (remote, fstr, headers) { remote = url.parse(remote) - log.http(remote.href, "GET") + log.http("GET", remote.href) regHost = regHost || url.parse(npm.config.get("registry")).host if (remote.host === regHost && npm.config.get("always-auth")) { @@ -63,6 +63,6 @@ function makeRequest (remote, fstr, headers) { , onResponse: onResponse }).pipe(fstr) function onResponse (er, res) { if (er) return fstr.emit("error", er) - log.http(res.statusCode + " " + remote.href) + log.http(res.statusCode, remote.href) } } diff --git a/deps/npm/lib/utils/ini.js b/deps/npm/lib/utils/ini.js index b033b6a04..aa4f43180 100644 --- a/deps/npm/lib/utils/ini.js +++ b/deps/npm/lib/utils/ini.js @@ -39,7 +39,7 @@ var fs = require("graceful-fs") , mkdir = require("mkdirp") , npm = require("../npm.js") - , log = require("./log.js") + , log = require("npmlog") , configDefs = require("./config-defs.js") , myUid = process.env.SUDO_UID !== undefined @@ -66,7 +66,6 @@ exports.configList = configList // just put this here for a moment, so that the logs // in the config-loading phase don't cause it to blow up. -configList.push({loglevel:"warn"}) function resolveConfigs (cli, cb_) { defaultConfig = defaultConfig || configDefs.defaults @@ -108,7 +107,8 @@ function resolveConfigs (cli, cb_) { if (er) return cb(er) if (conf.hasOwnProperty("prefix")) { - log.warn("Cannot set prefix in globalconfig file" + log.warn( "globalconfig" + , "Cannot set prefix in globalconfig file" , cl.get("globalconfig")) delete conf.prefix } @@ -196,7 +196,7 @@ function parseField (f, k, emptyIsFalse) { function parseFile (file, cb) { if (!file) return cb(null, {}) - log.verbose(file, "config file") + log.verbose("config file", file) fs.readFile(file, function (er, data) { // treat all errors as just an empty file if (er) return cb(null, {}) diff --git a/deps/npm/lib/utils/lifecycle.js b/deps/npm/lib/utils/lifecycle.js index c5ebbbee1..2f31af007 100644 --- a/deps/npm/lib/utils/lifecycle.js +++ b/deps/npm/lib/utils/lifecycle.js @@ -2,7 +2,7 @@ exports = module.exports = lifecycle exports.cmd = cmd -var log = require("./log.js") +var log = require("npmlog") , exec = require("./exec.js") , npm = require("../npm.js") , path = require("path") @@ -31,7 +31,7 @@ function lifecycle (pkg, stage, wd, unsafe, failOk, cb) { while (pkg && pkg._data) pkg = pkg._data if (!pkg) return cb(new Error("Invalid package data")) - log(pkg._id, stage) + log.info(stage, pkg._id) if (!pkg.scripts) pkg.scripts = {} validWd(wd || path.resolve(npm.dir, pkg.name), function (er, wd) { @@ -41,7 +41,8 @@ function lifecycle (pkg, stage, wd, unsafe, failOk, cb) { if ((wd.indexOf(npm.dir) !== 0 || path.basename(wd) !== pkg.name) && !unsafe && pkg.scripts[stage]) { - log.warn(pkg._id+" "+pkg.scripts[stage], "skipping, cannot run in "+wd) + log.warn( "cannot run in wd", "%s %s (wd=%s)" + , pkg._id, pkg.scripts[stage], wd) return cb() } @@ -98,14 +99,14 @@ function lifecycle_ (pkg, stage, wd, env, unsafe, failOk, cb) { if (failOk) { cb = (function (cb_) { return function (er) { - if (er) log.warn(er.message, "continuing anyway") + if (er) log.warn("continuing anyway", er.message) cb_() }})(cb) } if (npm.config.get("force")) { cb = (function (cb_) { return function (er) { - if (er) log(er, "forced, continuing") + if (er) log.info("forced, continuing", er) cb_() }})(cb) } @@ -143,7 +144,7 @@ function runPackageLifecycle (pkg, env, wd, unsafe, cb) { shFlag = "/c" } - log.verbose(unsafe, "unsafe-perm in lifecycle") + log.verbose("unsafe-perm in lifecycle", unsafe) var note = "\n> " + pkg._id + " " + stage + " " + wd + "\n> " + cmd + "\n" @@ -155,12 +156,12 @@ function runPackageLifecycle (pkg, env, wd, unsafe, cb) { , user, group , function (er, code, stdout, stderr) { if (er && !npm.ROLLBACK) { - log("Failed to exec "+stage+" script", pkg._id) + log.info(pkg._id, "Failed to exec "+stage+" script") er.message = pkg._id + " " + stage + ": `" + env.npm_lifecycle_script+"`\n" + er.message - if (er.errno !== constants.EPERM) { - er.errno = npm.ELIFECYCLE + if (er.code !== "EPERM") { + er.code = "ELIFECYCLE" } er.pkgid = pkg._id er.stage = stage @@ -168,8 +169,8 @@ function runPackageLifecycle (pkg, env, wd, unsafe, cb) { er.pkgname = pkg.name return cb(er) } else if (er) { - log.error(er, pkg._id+"."+stage) - log.error("failed, but continuing anyway", pkg._id+"."+stage) + log.error(pkg._id+"."+stage, er) + log.error(pkg._id+"."+stage, "continuing anyway") return cb() } cb(er) @@ -193,7 +194,7 @@ function runHookLifecycle (pkg, env, wd, unsafe, cb) { , function (er) { if (er) { er.message += "\nFailed to exec "+stage+" hook script" - log(er, pkg._id) + log.info(pkg._id, er) } if (npm.ROLLBACK) return cb() cb(er) @@ -260,10 +261,6 @@ function makeEnv (data, prefix, env) { return } var value = ini.get(i) - if (/^(log|out)fd$/.test(i) && typeof value === "object") { - // not an fd, a stream - return - } if (!value) value = "" else if (typeof value !== "string") value = JSON.stringify(value) diff --git a/deps/npm/lib/utils/link.js b/deps/npm/lib/utils/link.js index 7fa80d5e1..806fe22eb 100644 --- a/deps/npm/lib/utils/link.js +++ b/deps/npm/lib/utils/link.js @@ -6,7 +6,6 @@ var fs = require("graceful-fs") , chain = require("slide").chain , mkdir = require("mkdirp") , rm = require("./gently-rm.js") - , log = require("./log.js") , path = require("path") , relativize = require("./relativize.js") , npm = require("../npm.js") @@ -21,10 +20,14 @@ function linkIfExists (from, to, gently, cb) { function link (from, to, gently, cb) { if (typeof cb !== "function") cb = gently, gently = null if (npm.config.get("force")) gently = false + + // junction symlinks on windows must be absolute + var rel = process.platform === "win32" ? from : relativize(from, to) + chain ( [ [fs, "stat", from] , [rm, to, gently] , [mkdir, path.dirname(to)] - , [fs, "symlink", relativize(from, to), to] ] + , [fs, "symlink", rel, to, "junction"] ] , cb) } diff --git a/deps/npm/lib/utils/load-package-defaults.js b/deps/npm/lib/utils/load-package-defaults.js index 180507a44..8a72ade30 100644 --- a/deps/npm/lib/utils/load-package-defaults.js +++ b/deps/npm/lib/utils/load-package-defaults.js @@ -2,7 +2,7 @@ module.exports = loadPackageDefaults var path = require("path") - , log = require("./log.js") + , log = require("npmlog") , find = require("./find.js") , asyncMap = require("slide").asyncMap , npm = require("../npm.js") @@ -21,7 +21,7 @@ function loadPackageDefaults (pkg, pkgDir, cb) { pkg._defaultsLoaded = true asyncMap ( [pkg] - , function (pkg, cb) { log.verbose(pkg._id, "loadDefaults", cb) } + , function (pkg, cb) { log.verbose("loadDefaults", pkg._id); cb() } , readDefaultBins(pkgDir) , readDefaultMans(pkgDir) , function (er) { cb(er, pkg) } ) @@ -54,7 +54,7 @@ function readDefaultBins (pkgDir) { return function (pkg, cb) { var bin = pkg.directories && pkg.directories.bin if (pkg.bins) pkg.bin = pkg.bins, delete pkg.bins if (pkg.bin || !bin) return cb(null, pkg) - log.verbose("linking default bins", pkg._id) + log.verbose("loadDefaults", pkg._id, "linking default bins") var binDir = path.join(pkgDir, bin) pkg.bin = {} find(binDir, function (er, filenames) { @@ -69,7 +69,7 @@ function readDefaultBins (pkgDir) { return function (pkg, cb) { , val = filename.substr(cut) if (key.length && val.length) pkg.bin[key] = val }) - log.silly(pkg.bin, pkg._id+".bin") + log.silly("loadDefaults", pkg._id, "bin", pkg.bin) cb(null, pkg) }) }} diff --git a/deps/npm/lib/utils/log.js b/deps/npm/lib/utils/log.js deleted file mode 100644 index 07867e3e9..000000000 --- a/deps/npm/lib/utils/log.js +++ /dev/null @@ -1,170 +0,0 @@ - -module.exports = log - -var output = require("./output.js") - -function colorize (msg, color) { - return msg ? "\033["+color+"m"+msg+"\033[0m" : "" -} - -var l = -1 - , LEVEL = { silly : l++ - , verbose : l++ - , info : l++ - , "http" : l++ - , WARN : l++ - , "ERR!" : l++ - , ERROR : "ERR!" - , ERR : "ERR!" - , win : 0x15AAC5 - , paused : 0x19790701 - , silent : 0xDECAFBAD - } - , COLOR = {} - , SHOWLEVEL = null - , normalNames = {} -log.LEVEL = LEVEL -normalNames[LEVEL["ERR!"]] = "error" -normalNames[LEVEL.WARN] = "warn" -normalNames[LEVEL.info] = "info" -normalNames[LEVEL.verbose] = "verbose" -normalNames[LEVEL.silly] = "silly" -normalNames[LEVEL.win] = "win" - -Object.keys(LEVEL).forEach(function (l) { - if (typeof LEVEL[l] === "string") LEVEL[l] = LEVEL[LEVEL[l]] - else LEVEL[LEVEL[l]] = l - LEVEL[l.toLowerCase()] = LEVEL[l] - if (l === "silent" || l === "paused") return - log[l] = log[l.toLowerCase()] = - function (msg, pref, cb) { return log(msg, pref, l, cb) } -}) - -COLOR[LEVEL.silly] = 30 -COLOR[LEVEL.verbose] = "34;40" -COLOR[LEVEL.info] = 32 -COLOR[LEVEL.http] = "32;40" -COLOR[LEVEL.warn] = "30;41" -COLOR[LEVEL.error] = "31;40" -for (var c in COLOR) COLOR[LEVEL[c]] = COLOR[c] -COLOR.npm = "37;40" -COLOR.pref = 35 - -var logBuffer = [] - , ini = require("./ini.js") - , waitForConfig -log.waitForConfig = function () { waitForConfig = true } - -// now the required stuff has been loaded, -// so the transitive module dep will work -var util = require("util") - , npm = require("../npm.js") - , net = require("net") - -Object.defineProperty(log, "level", - { get : function () { - if (SHOWLEVEL !== null) return SHOWLEVEL - var show = npm.config && npm.config.get("loglevel") || '' - show = show.split(",")[0] - if (!isNaN(show)) show = +show - else if (!LEVEL.hasOwnProperty(show)) { - util.error("Invalid loglevel config: "+JSON.stringify(show)) - show = "info" - } - if (isNaN(show)) show = LEVEL[show] - else show = +show - if (!waitForConfig || ini.resolved) SHOWLEVEL = show - return show - } - , set : function (l) { - SHOWLEVEL = null - npm.config.set("showlevel", l) - } - }) - -function log (msg, pref, level, cb) { - if (typeof level === "function") cb = level, level = null - var show = log.level - if (show === LEVEL.silent || show === LEVEL.paused) return cb && cb() - if (level == null) level = LEVEL.info - if (isNaN(level)) level = LEVEL[level] - else level = +level - - // logging just undefined is almost never the right thing. - // a lot of these are kicking around throughout the codebase - // with relatively unhelpful prefixes. - if (msg === undefined && level > LEVEL.silly) { - msg = new Error("undefined log message") - } - if (typeof msg === "object" && (msg instanceof Error)) level = LEVEL.error - if (!ini.resolved && waitForConfig || level === LEVEL.paused) { - return logBuffer.push([msg, pref, level, cb]) - } - if (logBuffer.length && !logBuffer.discharging) { - logBuffer.push([msg, pref, level, cb]) - logBuffer.discharging = true - logBuffer.forEach(function (l) { log.apply(null, l) }) - logBuffer.length = 0 - delete logBuffer.discharging - return - } - log.level = show - npm.emit("log", { level : level, msg : msg, pref : pref, cb : cb }) - npm.emit("log."+normalNames[level], { msg : msg, pref : pref, cb : cb }) -} - -var loglog = log.history = [] - , loglogLen = 0 -npm.on("log", function (logData) { - var level = logData.level - , msg = logData.msg - , pref = logData.pref - , cb = logData.cb || function () {} - , show = log.level - , spaces = " " - , logFD = npm.config.get("logfd") - if (msg instanceof Error) { - msg = logData.msg = msg.stack || msg.toString() - } - loglog.push(logData) - loglogLen ++ - if (loglogLen > 2000) { - loglog = loglog.slice(loglogLen - 1000) - loglogLen = 1000 - } - if (!isFinite(level) || level < show) return cb() - if (typeof msg !== "string" && !(msg instanceof Error)) { - msg = util.inspect(msg, 0, 4, true) - } - - // console.error("level, showlevel, show", level, show, (level >= show)) - if (pref && COLOR.pref) { - pref = colorize(pref, COLOR.pref) - } - if (!pref) pref = "" - - if (npm.config.get("logprefix")) { - pref = colorize("npm", COLOR.npm) - + (COLOR[level] ? " "+colorize( - (LEVEL[level]+spaces).substr(0,4), COLOR[level]) : "") - + (pref ? (" " + pref) : "") - } - if (pref) pref += " " - - - - if (msg.indexOf("\n") !== -1) { - msg = msg.split(/\n/).join("\n"+pref) - } - msg = pref+msg - return output.write(msg, logFD, cb) -}) - -log.er = function (cb, msg) { - if (!msg) throw new Error( - "Why bother logging it if you're not going to print a message?") - return function (er) { - if (er) log.error(msg) - cb.apply(this, arguments) - } -} diff --git a/deps/npm/lib/utils/npm-registry-client/adduser.js b/deps/npm/lib/utils/npm-registry-client/adduser.js deleted file mode 100644 index 5e6794a75..000000000 --- a/deps/npm/lib/utils/npm-registry-client/adduser.js +++ /dev/null @@ -1,100 +0,0 @@ - -module.exports = adduser - -var uuid = require("node-uuid") - , request = require("./request.js") - , log = require("../log.js") - , npm = require("../../npm.js") - , crypto - -try { - crypto = process.binding("crypto") && require("crypto") -} catch (ex) {} - -function sha (s) { - return crypto.createHash("sha1").update(s).digest("hex") -} - -function adduser (username, password, email, cb) { - if (!crypto) return cb(new Error( - "You must compile node with ssl support to use the adduser feature")) - - password = ("" + (password || "")).trim() - if (!password) return cb(new Error("No password supplied.")) - - email = ("" + (email || "")).trim() - if (!email) return cb(new Error("No email address supplied.")) - if (!email.match(/^[^@]+@[^\.]+\.[^\.]+/)) { - return cb(new Error("Please use a real email address.")) - } - - if (password.indexOf(":") !== -1) return cb(new Error( - "Sorry, ':' chars are not allowed in passwords.\n"+ - "See <https://issues.apache.org/jira/browse/COUCHDB-969> for why.")) - var salt = uuid() - , userobj = - { name : username - , salt : salt - , password_sha : sha(password + salt) - , email : email - , _id : 'org.couchdb.user:'+username - , type : "user" - , roles : [] - , date: new Date().toISOString() - } - cb = done(cb) - log.verbose(userobj, "before first PUT") - request.PUT - ( '/-/user/org.couchdb.user:'+encodeURIComponent(username) - , userobj - , function (error, data, json, response) { - // if it worked, then we just created a new user, and all is well. - // but if we're updating a current record, then it'll 409 first - if (error && !npm.config.get("_auth")) { - // must be trying to re-auth on a new machine. - // use this info as auth - npm.config.set("username", username) - npm.config.set("_password", password) - var b = new Buffer(username + ":" + password) - npm.config.set("_auth", b.toString("base64")) - } - if (!error || !response || response.statusCode !== 409) { - return cb(error, data, json, response) - } - log.verbose("update existing user", "adduser") - return request.GET - ( '/-/user/org.couchdb.user:'+encodeURIComponent(username) - , function (er, data, json, response) { - userobj._rev = data._rev - userobj.roles = data.roles - log.verbose(userobj, "userobj") - request.PUT - ( '/-/user/org.couchdb.user:'+encodeURIComponent(username) - + "/-rev/" + userobj._rev - , userobj - , cb ) - } - ) - } - ) -} - -function done (cb) { return function (error, data, json, response) { - if (!error && (!response || response.statusCode === 201)) { - return cb(error, data, json, response) - } - log.verbose([error, data, json], "back from adduser") - if (!error) { - error = new Error( (response && response.statusCode || "") + " "+ - "Could not create user\n"+JSON.stringify(data)) - } - if (response - && (response.statusCode === 401 || response.statusCode === 403)) { - log.warn("Incorrect username or password\n" - +"You can reset your account by visiting:\n" - +"\n" - +" http://admin.npmjs.org/reset\n") - } - - return cb(error) -}} diff --git a/deps/npm/lib/utils/npm-registry-client/get.js b/deps/npm/lib/utils/npm-registry-client/get.js deleted file mode 100644 index e0902f027..000000000 --- a/deps/npm/lib/utils/npm-registry-client/get.js +++ /dev/null @@ -1,186 +0,0 @@ - -module.exports = get - -var GET = require("./request.js").GET - , fs = require("graceful-fs") - , npm = require("../../npm.js") - , path = require("path") - , log = require("../log.js") - , mkdir = require("mkdirp") - , cacheStat = null - , chownr = require("chownr") - -function get (project, version, timeout, nofollow, staleOk, cb) { - if (typeof cb !== "function") cb = staleOk, staleOk = false - if (typeof cb !== "function") cb = nofollow, nofollow = false - if (typeof cb !== "function") cb = timeout, timeout = -1 - if (typeof cb !== "function") cb = version, version = null - if (typeof cb !== "function") cb = project, project = null - if (typeof cb !== "function") { - throw new Error("No callback provided to registry.get") - } - - timeout = Math.min(timeout, npm.config.get("cache-max")) - timeout = Math.max(timeout, npm.config.get("cache-min")) - - if ( process.env.COMP_CWORD !== undefined - && process.env.COMP_LINE !== undefined - && process.env.COMP_POINT !== undefined - ) timeout = Math.max(timeout, 60000) - - var uri = [] - uri.push(project || "") - if (version) uri.push(version) - uri = uri.join("/") - - // /-/all is special. - // It uses timestamp-based caching and partial updates, - // because it is a monster. - if (uri === "/-/all") { - return requestAll(cb) - } - - var cache = path.join(npm.cache, uri, ".cache.json") - fs.stat(cache, function (er, stat) { - if (!er) fs.readFile(cache, function (er, data) { - try { data = JSON.parse(data) } - catch (ex) { data = null } - get_(uri, timeout, cache, stat, data, nofollow, staleOk, cb) - }) - else get_(uri, timeout, cache, null, null, nofollow, staleOk, cb) - }) -} - -function requestAll (cb) { - var cache = path.join(npm.cache, "/-/all", ".cache.json") - - mkdir(path.join(npm.cache, "-", "all"), function (er) { - fs.readFile(cache, function (er, data) { - if (er) return requestAll_(0, {}, cb) - try { - data = JSON.parse(data) - } catch (ex) { - fs.writeFile(cache, "{}", function (er) { - if (er) return cb(new Error("Broken cache. " - +"Please run 'npm cache clean' " - +"and try again.")) - return requestAll_(0, {}, cb) - }) - } - var t = +data._updated || 0 - requestAll_(t, data, cb) - }) - }) -} - -function requestAll_ (c, data, cb) { - // use the cache and update in the background if it's not too old - if (Date.now() - c < 60000) { - cb(null, data) - cb = function () {} - } - - var uri = "/-/all/since?stale=update_after&startkey=" + c - - if (c === 0) { - log.warn("Building the local index for the first time, please be patient") - uri = "/-/all" - } - - var cache = path.join(npm.cache, "-/all", ".cache.json") - GET(uri, function (er, updates, _, res) { - if (er) return cb(er, data) - var headers = res.headers - , updated = Date.parse(headers.date) - Object.keys(updates).forEach(function (p) { - data[p] = updates[p] - }) - data._updated = updated - fs.writeFile( cache, JSON.stringify(data) - , function (er) { - delete data._updated - return cb(er, data) - }) - }) -} - -function get_ (uri, timeout, cache, stat, data, nofollow, staleOk, cb) { - var etag - if (data && data._etag) etag = data._etag - if (timeout && timeout > 0 && stat && data) { - if ((Date.now() - stat.mtime.getTime())/1000 < timeout) { - log.verbose("not expired, no request", "registry.get " +uri) - delete data._etag - return cb(null, data, JSON.stringify(data), {statusCode:304}) - } - if (staleOk) { - log.verbose("staleOk, background update", "registry.get " +uri) - delete data._etag - process.nextTick(cb.bind( null, null, data, JSON.stringify(data) - , {statusCode: 304} )) - cb = function () {} - } - } - - GET(uri, etag, nofollow, function (er, remoteData, raw, response) { - // if we get an error talking to the registry, but we have it - // from the cache, then just pretend we got it. - if (er && cache && data && !data.error) { - er = null - response = {statusCode: 304} - } - - if (response) { - log.silly([response.statusCode, response.headers], "get cb") - if (response.statusCode === 304 && etag) { - remoteData = data - log.verbose(uri+" from cache", "etag") - } - } - - data = remoteData - if (!data) { - er = er || new Error("failed to fetch from registry: " + uri) - } - - if (er) return cb(er, data, raw, response) - - // just give the write the old college try. if it fails, whatever. - function saved () { - delete data._etag - cb(er, data, raw, response) - } - - saveToCache(cache, data, saved) - }) -} - -function saveToCache (cache, data, saved) { - if (cacheStat) { - return saveToCache_(cache, data, cacheStat.uid, cacheStat.gid, saved) - } - fs.stat(npm.cache, function (er, st) { - if (er) { - return fs.stat(process.env.HOME || "", function (er, st) { - // if this fails, oh well. - if (er) return saved() - cacheStat = st - return saveToCache(cache, data, saved) - }) - } - cacheStat = st || { uid: null, gid: null } - return saveToCache(cache, data, saved) - }) -} - -function saveToCache_ (cache, data, uid, gid, saved) { - mkdir(path.dirname(cache), function (er, made) { - if (er) return saved() - fs.writeFile(cache, JSON.stringify(data), function (er) { - if (er || uid === null || gid === null) { - return saved() - } - chownr(made || cache, uid, gid, saved) - }) - }) -} diff --git a/deps/npm/lib/utils/npm-registry-client/index.js b/deps/npm/lib/utils/npm-registry-client/index.js deleted file mode 100644 index 2a4294745..000000000 --- a/deps/npm/lib/utils/npm-registry-client/index.js +++ /dev/null @@ -1,16 +0,0 @@ - -// utilities for working with the js-registry site. - -var cached = {} -function lazyGet (p) { return function () { - return cached[p] || (cached[p] = require("./"+p+".js")) -}} - -function setLazyGet (p) { - Object.defineProperty(exports, p, - { get : lazyGet(p) - , enumerable : true }) -} - -; ["publish", "unpublish", "tag", "adduser", "get", "request", "star"] - .forEach(setLazyGet) diff --git a/deps/npm/lib/utils/npm-registry-client/publish.js b/deps/npm/lib/utils/npm-registry-client/publish.js deleted file mode 100644 index a196a3c07..000000000 --- a/deps/npm/lib/utils/npm-registry-client/publish.js +++ /dev/null @@ -1,170 +0,0 @@ - -module.exports = publish - -var request = require("./request.js") - , GET = request.GET - , PUT = request.PUT - , DELETE = request.DELETE - , reg = request.reg - , upload = request.upload - , log = require("../log.js") - , path = require("path") - , npm = require("../../npm.js") - , url = require("url") - -function publish (data, prebuilt, readme, cb) { - if (typeof readme === "function") cb = readme, readme = "" - if (typeof prebuilt === "function") cb = prebuilt, prebuilt = null - // add the dist-url to the data, pointing at the tarball. - // if the {name} isn't there, then create it. - // if the {version} is already there, then fail. - // then: - // PUT the data to {config.registry}/{data.name}/{data.version} - var registry = reg() - if (registry instanceof Error) return cb(registry) - - readme = readme ? "" + readme : "" - - var fullData = - { _id : data.name - , name : data.name - , description : data.description - , "dist-tags" : {} - , versions : {} - , readme: readme - , maintainers : - [ { name : npm.config.get("username") - , email : npm.config.get("email") - } - ] - } - - var tbName = data.name + "-" + data.version + ".tgz" - , bd = npm.config.get("bindist") - , pbName = data.name + "-" + data.version + "-" + bd + ".tgz" - , tbURI = data.name + "/-/" + tbName - , pbURI = data.name + "/-/" + pbName - - data._id = data.name+"@"+data.version - data.dist = data.dist || {} - data.dist.tarball = url.resolve(registry, tbURI) - .replace(/^https:\/\//, "http://") - - if (prebuilt && bd) { - data.dist.bin[bd] = data.dist.bin[bd] || {} - data.dist.bin[bd].tarball = url.resolve(registry, pbURI) - .replace(/^https:\/\//, "http://") - } - - - - - // first try to just PUT the whole fullData, and this will fail if it's - // already there, because it'll be lacking a _rev, so couch'll bounce it. - PUT(encodeURIComponent(data.name), fullData, - function (er, parsed, json, response) { - // get the rev and then upload the attachment - // a 409 is expected here, if this is a new version of an existing package. - if (er - && !(response && response.statusCode === 409) - && !( parsed - && parsed.reason === - "must supply latest _rev to update existing package" )) { - return log.er(cb, "Failed PUT response " - +(response && response.statusCode))(er) - } - var dataURI = encodeURIComponent(data.name) - + "/" + encodeURIComponent(data.version) - - var tag = data.tag || npm.config.get("tag") - if (npm.config.get("pre")) dataURI += "/-pre/true" - else if (tag) dataURI += "/-tag/" + tag - else dataURI += "/-tag/latest" - - // let's see what verions are already published. - // could be that we just need to update the bin dist values. - GET(data.name, function (er, fullData) { - if (er) return cb(er) - - var exists = fullData.versions && fullData.versions[data.version] - if (exists) { - log(exists._id, "Already published") - var ebin = exists.dist.bin || {} - , nbin = data.dist.bin || {} - , needs = Object.keys(nbin).filter(function (bd) { - return !ebin.hasOwnProperty(bd) - }) - log.verbose(needs, "uploading bin dists") - if (!needs.length) return cb(conflictError(data._id)) - // attach the needed bindists, upload the new metadata - exists.dist.bin = ebin - needs.forEach(function (bd) { exists.dist.bin[bd] = nbin[bd] }) - return PUT(dataURI + "/-rev/" + fullData._rev, exists, function (er) { - if (er) return cb(er) - attach(data.name, prebuilt, pbName, cb) - }) - } - - // this way, it'll also get attached to packages that were previously - // published with a version of npm that lacked this feature. - if (!fullData.readme) { - data.readme = readme - } - PUT(dataURI, data, function (er) { - if (er) { - if (er.message.indexOf("conflict Document update conflict.") === 0) { - return cb(conflictError(data._id)) - } - return log.er(cb, "Error sending version data")(er) - } - - var c = path.resolve(npm.cache, data.name, data.version) - , tb = path.resolve(c, "package.tgz") - - cb = rollbackFailure(data, cb) - - log.verbose([data.name, tb, tbName], "attach 2") - attach(data.name, tb, tbName, function (er) { - log.verbose([er, data.name, prebuilt, pbName], "attach 3") - if (er || !prebuilt) return cb(er) - attach(data.name, prebuilt, pbName, cb) - }) - }) - }) - }) -} - -function conflictError (pkgid) { - var e = new Error("publish fail") - e.errno = npm.EPUBLISHCONFLICT - e.pkgid = pkgid - return e -} - -function attach (doc, file, filename, cb) { - doc = encodeURIComponent(doc) - GET(doc, function (er, d) { - if (er) return cb(er) - if (!d) return cb(new Error( - "Attempting to upload to invalid doc "+doc)) - var rev = "-rev/"+d._rev - , attURI = doc + "/-/" + encodeURIComponent(filename) + "/" + rev - log.verbose([attURI, file], "uploading") - upload(attURI, file, cb) - }) -} - -function rollbackFailure (data, cb) { return function (er) { - if (!er) return cb() - npm.ROLLBACK = true - log.error(er, "publish failed") - log("rollback", "publish failed") - npm.commands.unpublish([data.name+"@"+data.version], function (er_) { - if (er_) { - log.error(er_, "rollback failed") - log.error( "Invalid data in registry! Please report this." - , "rollback failed" ) - } else log("rolled back", "publish failed") - cb(er) - }) -}} diff --git a/deps/npm/lib/utils/npm-registry-client/request.js b/deps/npm/lib/utils/npm-registry-client/request.js deleted file mode 100644 index d5122629d..000000000 --- a/deps/npm/lib/utils/npm-registry-client/request.js +++ /dev/null @@ -1,245 +0,0 @@ -module.exports = regRequest - -regRequest.GET = GET -regRequest.PUT = PUT -regRequest.reg = reg -regRequest.upload = upload - -var npm = require("../../npm.js") - , url = require("url") - , log = require("../log.js") - , fs = require("graceful-fs") - , rm = require("rimraf") - , asyncMap = require("slide").asyncMap - , warnedAuth = false - , newloctimeout = 0 - , stream = require("stream") - , Stream = stream.Stream - , request = require("request") - -function regRequest (method, where, what, etag, nofollow, cb_) { - if (typeof cb_ !== "function") cb_ = nofollow, nofollow = false - if (typeof cb_ !== "function") cb_ = etag, etag = null - if (typeof cb_ !== "function") cb_ = what, what = null - - // Since there are multiple places where an error could occur, - // don't let the cb be called more than once. - var errState = null - function cb (er) { - if (errState) return - if (er) errState = er - cb_.apply(null, arguments) - } - - if (where.match(/^\/?favicon.ico/)) { - return cb(new Error("favicon.ico isn't a package, it's a picture.")) - } - - var registry = reg() - if (registry instanceof Error) return cb(registry) - - var adduserChange = /^\/?-\/user\/org\.couchdb\.user:([^\/]+)\/-rev/ - , adduserNew = /^\/?-\/user\/org\.couchdb\.user:([^\/]+)/ - , authRequired = (what || npm.config.get("always-auth")) - && !where.match(adduserNew) - || where.match(adduserChange) - || method === "DELETE" - - // resolve to a full url on the registry - if (!where.match(/^https?:\/\//)) { - log.verbose(where, "raw, before any munging") - - var q = where.split("?") - where = q.shift() - q = q.join("?") - - if (where.charAt(0) !== "/") where = "/" + where - where = "." + where.split("/").map(function (p) { - p = p.trim() - if (p.match(/^org.couchdb.user/)) { - return p.replace(/\//g, encodeURIComponent("/")) - } - return encodeURIComponent(p) - }).join("/") - if (q) where += "?" + q - log.verbose([registry, where], "url resolving") - where = url.resolve(registry, where) - log.verbose(where, "url resolved") - } - - var remote = url.parse(where) - , auth = authRequired && npm.config.get("_auth") - - if (authRequired && !auth) { - return cb(new Error( - "Cannot insert data into the registry without authorization\n" - + "See: npm-adduser(1)")) - } - - if (auth) remote.auth = new Buffer(auth, "base64").toString("utf8") - - makeRequest(method, remote, where, what, etag, nofollow, cb) -} - -function makeRequest (method, remote, where, what, etag, nofollow, cb) { - var opts = { url: remote - , method: method - , ca: npm.config.get("ca") - , strictSSL: npm.config.get("strict-ssl") } - , headers = opts.headers = {} - if (etag) { - log.verbose(etag, "etag") - headers[method === "GET" ? "if-none-match" : "if-match"] = etag - } - - headers.accept = "application/json" - - headers["user-agent"] = npm.config.get("user-agent") - - opts.proxy = npm.config.get( remote.protocol === "https:" - ? "https-proxy" : "proxy" ) - - // figure out wth 'what' is - if (what) { - if (Buffer.isBuffer(what) || typeof what === "string") { - opts.body = what - headers["content-type"] = "application/json" - headers["content-length"] = Buffer.byteLength(what) - } else if (what instanceof Stream) { - headers["content-type"] = "application/octet-stream" - if (what.size) headers["content-length"] = what.size - } else { - delete what._etag - opts.json = what - } - } - - if (nofollow) { - opts.followRedirect = false - } - - log.http(remote.href || "/", method) - - var req = request(opts, requestDone(method, where, cb)) - var r = npm.config.get("registry") - if (!r) { - return new Error("Must define registry URL before accessing registry.") - } - - req.on("error", cb) - - if (what && (what instanceof Stream)) { - what.pipe(req) - } -} - -// cb(er, parsed, raw, response) -function requestDone (method, where, cb) { return function (er, response, data) { - if (er) return cb(er) - - log.http(response.statusCode + " " + url.parse(where).href) - - var parsed - - if (Buffer.isBuffer(data)) { - data = data.toString() - } - - if (data && typeof data === "string" && response.statusCode !== 304) { - try { - parsed = JSON.parse(data) - } catch (ex) { - ex.message += "\n" + data - log.verbose(data, "bad json") - log.error("error parsing json", "registry") - return cb(ex, null, data, response) - } - } else if (data) { - parsed = data - data = JSON.stringify(parsed) - } - - // expect data with any error codes - if (!data && response.statusCode >= 400) { - return cb( response.statusCode + " " - + require("http").STATUS_CODES[response.statusCode] - , null, data, response ) - } - - var er = null - if (parsed && response.headers.etag) { - parsed._etag = response.headers.etag - } - - if (parsed && parsed.error && response.statusCode >= 400) { - var w = url.parse(where).pathname.substr(1) - if (!w.match(/^-/) && parsed.error === "not_found") { - w = w.split("/") - name = w[w.indexOf("_rewrite") + 1] - er = new Error("404 Not Found: "+name) - er.errno = npm.E404 - er.pkgid = name - } else { - er = new Error( - parsed.error + " " + (parsed.reason || "") + ": " + w) - } - } else if (method !== "HEAD" && method !== "GET") { - // invalidate cache - // This is irrelevant for commands that do etag caching, but - // ls and view also have a timed cache, so this keeps the user - // from thinking that it didn't work when it did. - // Note that failure is an acceptable option here, since the - // only result will be a stale cache for some helper commands. - var path = require("path") - , p = url.parse(where).pathname.split("/") - , _ = "/" - , caches = p.map(function (part) { - return _ = path.join(_, part) - }).map(function (cache) { - return path.join(npm.cache, cache, ".cache.json") - }) - - // if the method is DELETE, then also remove the thing itself. - // Note that the search index is probably invalid. Whatever. - // That's what you get for deleting stuff. Don't do that. - if (method === "DELETE") { - p = p.slice(0, p.indexOf("-rev")) - caches.push(path.join(npm.cache, p.join("/"))) - } - - asyncMap(caches, rm, function () {}) - } - return cb(er, parsed, data, response) -}} - -function GET (where, etag, nofollow, cb) { - regRequest("GET", where, null, etag, nofollow, cb) -} - -function PUT (where, what, etag, nofollow, cb) { - regRequest("PUT", where, what, etag, nofollow, cb) -} - -function upload (where, filename, etag, nofollow, cb) { - if (typeof nofollow === "function") cb = nofollow, nofollow = false - if (typeof etag === "function") cb = etag, etag = null - - fs.stat(filename, function (er, stat) { - if (er) return cb(er) - var s = fs.createReadStream(filename) - s.size = stat.size - s.on("error", cb) - - PUT(where, s, etag, nofollow, cb) - }) -} - -function reg () { - var r = npm.config.get("registry") - if (!r) { - return new Error("Must define registry URL before accessing registry.") - } - if (r.substr(-1) !== "/") r += "/" - npm.config.set("registry", r) - return r -} diff --git a/deps/npm/lib/utils/npm-registry-client/star.js b/deps/npm/lib/utils/npm-registry-client/star.js deleted file mode 100644 index 474a1786d..000000000 --- a/deps/npm/lib/utils/npm-registry-client/star.js +++ /dev/null @@ -1,32 +0,0 @@ - -module.exports = star - -var request = require("./request.js") - , GET = request.GET - , PUT = request.PUT - , log = require("../log.js") - , npm = require("../../npm.js") - -function star (package, starred, cb) { - var users = {} - - GET(package, function (er, fullData) { - if (er) return cb(er) - - fullData = { _id: fullData._id - , _rev: fullData._rev - , users: fullData.users || {} } - - if (starred) { - log.info("starring", fullData._id) - fullData.users[npm.config.get("username")] = true - log.verbose(fullData) - } else { - delete fullData.users[npm.config.get("username")] - log.info("unstarring", fullData._id) - log.verbose(fullData) - } - - return PUT(package, fullData, cb) - }) -} diff --git a/deps/npm/lib/utils/npm-registry-client/tag.js b/deps/npm/lib/utils/npm-registry-client/tag.js deleted file mode 100644 index 4d88a98db..000000000 --- a/deps/npm/lib/utils/npm-registry-client/tag.js +++ /dev/null @@ -1,8 +0,0 @@ - -module.exports = tag - -var PUT = require("./request.js").PUT - -function tag (project, version, tag, cb) { - PUT(project+"/"+tag, JSON.stringify(version), cb) -} diff --git a/deps/npm/lib/utils/npm-registry-client/unpublish.js b/deps/npm/lib/utils/npm-registry-client/unpublish.js deleted file mode 100644 index 0c7c44991..000000000 --- a/deps/npm/lib/utils/npm-registry-client/unpublish.js +++ /dev/null @@ -1,98 +0,0 @@ - -// fetch the data -// modify to remove the version in question -// If no versions remaining, then DELETE -// else, PUT the modified data -// delete the tarball - -module.exports = unpublish - -var request = require("./request.js") - , log = require("../log.js") - , get = require("./get.js") - , semver = require("semver") - , url = require("url") - , chain = require("slide").chain - -function unpublish (name, ver, cb) { - if (!cb) cb = ver, ver = null - if (!cb) throw new Error( - "Not enough arguments for registry unpublish") - - get(name, null, -1, true, function (er, data) { - if (er) return log(name+" not published", "unpublish", cb) - // remove all if no version specified - if (!ver) { - log("No version specified, removing all", "unpublish") - return request("DELETE", name+'/-rev/'+data._rev, cb) - } - - var versions = data.versions || {} - , versionPublic = versions.hasOwnProperty(ver) - - if (!versionPublic) log(name+"@"+ver+" not published", "unpublish") - else { - var dist = versions[ver].dist - log.verbose(dist, "removing attachments") - } - - delete versions[ver] - // if it was the only version, then delete the whole package. - if (!Object.keys(versions).length) { - log("No versions remain, removing entire package", "unpublish") - return request("DELETE", name+"/-rev/"+data._rev, cb) - } - - if (!versionPublic) return cb() - - var latestVer = data["dist-tags"].latest - for (var tag in data["dist-tags"]) { - if (data["dist-tags"][tag] === ver) delete data["dist-tags"][tag] - } - - if (latestVer === ver) { - data["dist-tags"].latest = - Object.getOwnPropertyNames(versions).sort(semver.compare).pop() - } - - var rev = data._rev - delete data._revisions - delete data._attachments - // log(data._rev, "rev") - request.PUT(name+"/-rev/"+rev, data, - log.er(detacher(data, dist, cb), "Failed to update the data")) - }) -} - -function detacher (data, dist, cb) { return function (er) { - if (er) return cb(er) - get(data.name, function (er, data) { - if (er) return cb(er) - - var tb = url.parse(dist.tarball) - - detach(data, tb.pathname, data._rev, function (er) { - if (er || !dist.bin) return cb(er) - chain(Object.keys(dist.bin).map(function (bt) { - return function (cb) { - var d = dist.bin[bt] - detach(data, url.parse(d.tarball).pathname, null, cb) - } - }), cb) - }) - }) -}} - -function detach (data, path, rev, cb) { - if (rev) { - path += "/-rev/" + rev - log(path, "detach") - return request("DELETE", path, cb) - } - get(data.name, function (er, data) { - rev = data._rev - if (!rev) return cb(new Error( - "No _rev found in "+data._id)) - detach(data, path, rev, cb) - }) -} diff --git a/deps/npm/lib/utils/read-installed.js b/deps/npm/lib/utils/read-installed.js index ff220943d..3776f9019 100644 --- a/deps/npm/lib/utils/read-installed.js +++ b/deps/npm/lib/utils/read-installed.js @@ -93,7 +93,7 @@ var npm = require("../npm.js") , asyncMap = require("slide").asyncMap , semver = require("semver") , readJson = require("./read-json.js") - , log = require("./log.js") + , log = require("npmlog") , url = require("url") module.exports = readInstalled @@ -186,13 +186,26 @@ function readInstalled_ (folder, parent, name, reqver, depth, maxDepth, cb) { if (parent && !obj.link) obj.parent = parent rpSeen[real] = obj obj.depth = depth - if (depth >= maxDepth) return cb(null, obj) + //if (depth >= maxDepth) return cb(null, obj) asyncMap(installed, function (pkg, cb) { var rv = obj.dependencies[pkg] if (!rv && obj.devDependencies) rv = obj.devDependencies[pkg] + if (depth >= maxDepth) { + // just try to get the version number + var pkgfolder = path.resolve(folder, "node_modules", pkg) + , jsonFile = path.resolve(pkgfolder, "package.json") + return readJson(jsonFile, function (er, depData) { + // already out of our depth, ignore errors + if (er || !depData || !depData.version) return cb(null, obj) + obj.dependencies[pkg] = depData.version + cb(null, obj) + }) + } + readInstalled_( path.resolve(folder, "node_modules/"+pkg) , obj, pkg, obj.dependencies[pkg], depth + 1, maxDepth , cb ) + }, function (er, installedData) { if (er) return cb(er) installedData.forEach(function (dep) { @@ -259,17 +272,17 @@ function findUnmet (obj) { && !url.parse(deps[d]).protocol && !semver.satisfies(found.version, deps[d])) { // the bad thing will happen - log.warn(obj.path + " requires "+d+"@'"+deps[d] + log.warn("unmet dependency", obj.path + " requires "+d+"@'"+deps[d] +"' but will load\n" +found.path+",\nwhich is version "+found.version - ,"unmet dependency") + ) found.invalid = true } deps[d] = found } }) - log.verbose([obj._id], "returning") + log.verbose("readInstalled", "returning", obj._id) return obj } diff --git a/deps/npm/lib/utils/read-json.js b/deps/npm/lib/utils/read-json.js index d1bba10f5..146f46062 100644 --- a/deps/npm/lib/utils/read-json.js +++ b/deps/npm/lib/utils/read-json.js @@ -8,7 +8,7 @@ readJson.clearCache = clearCache var fs = require("graceful-fs") , semver = require("semver") , path = require("path") - , log = require("./log.js") + , log = require("npmlog") , npm = require("../npm.js") , cache = {} , timers = {} @@ -17,19 +17,12 @@ var fs = require("graceful-fs") function readJson (jsonFile, opts, cb) { if (typeof cb !== "function") cb = opts, opts = {} if (cache.hasOwnProperty(jsonFile)) { - log.verbose(jsonFile, "from cache") + log.verbose("json from cache", jsonFile) return cb(null, cache[jsonFile]) } + log.verbose("read json", jsonFile) + opts.file = jsonFile - if (!opts.tag) { - var parsedPath = jsonFile.indexOf(npm.dir) === 0 && jsonFile.match( - /\/([^\/]+)\/([^\/]+)\/package\/package\.json$/) - if (parsedPath && semver.valid(parsedPath[2])) { - // this is a package.json in some installed package. - // infer the opts.tag so that linked packages behave right. - opts.tag = parsedPath[2] - } - } var wscript = null , contributors = null @@ -180,8 +173,7 @@ function processJsonString (opts, cb) { return function (er, jsonString) { if (opts.file && opts.file.indexOf(npm.dir) === 0) { try { json = require("vm").runInNewContext("(\n"+jsonString+"\n)") - log.error(opts.file, "Error parsing json") - log.error(ex, "parse error ") + log.error("Error parsing json", opts.file, ex) } catch (ex2) { return jsonParseFail(ex, opts.file, cb) } @@ -196,7 +188,7 @@ function processJsonString (opts, cb) { return function (er, jsonString) { function jsonParseFail (ex, file, cb) { var e = new Error( "Failed to parse json\n"+ex.message) - e.errno = npm.EJSONPARSE + e.code = "EJSONPARSE" e.file = file if (cb) return cb(e) throw e @@ -209,7 +201,7 @@ function typoWarn (json) { typoWarned[json._id] = true if (json.modules) { - log.warn("package.json: 'modules' object is deprecated", json._id) + log.verbose("package.json", "'modules' object is deprecated", json._id) delete json.modules } @@ -235,8 +227,8 @@ function typoWarn (json) { Object.keys(typos).forEach(function (d) { if (json.hasOwnProperty(d)) { - log.warn( "package.json: '" + d + "' should probably be '" - + typos[d] + "'", json._id) + log.warn( json._id, "package.json: '" + d + "' should probably be '" + + typos[d] + "'" ) } }) @@ -259,8 +251,9 @@ function typoWarn (json) { var scriptTypos = { "server": "start" } if (json.scripts) Object.keys(scriptTypos).forEach(function (d) { if (json.scripts.hasOwnProperty(d)) { - log.warn( "package.json: scripts['" + d + "'] should probably be " - + "scripts['" + scriptTypos[d] + "']", json._id) + log.warn( json._id + , "package.json: scripts['" + d + "'] should probably be " + + "scripts['" + scriptTypos[d] + "']" ) } }) } @@ -268,7 +261,6 @@ function typoWarn (json) { function processObject (opts, cb) { return function (er, json) { // json._npmJsonOpts = opts - // log.warn(json, "processing json") if (npm.config.get("username")) { json._npmUser = { name: npm.config.get("username") , email: npm.config.get("email") } @@ -310,7 +302,7 @@ function processObject (opts, cb) { return function (er, json) { // uncomment once this is no longer an issue. // if (cb) return cb(e) // throw e - log.error(msg, "incorrect json: "+json.name) + log.error("json", "incorrect json: "+json.name, msg) json.repostory = json.repositories[0] delete json.repositories } @@ -335,14 +327,14 @@ function processObject (opts, cb) { return function (er, json) { } if (repo.match(/github\.com\/[^\/]+\/[^\/]+\/?$/) && repo.match(/\.git\.git$/)) { - log.warn(repo, "Probably broken git url") + log.warn(json._id, "Probably broken git url", repo) } json.repository.url = repo } var files = json.files if (files && !Array.isArray(files)) { - log.warn(files, "Invalid 'files' member. See 'npm help json'") + log.warn(json._id, "Invalid 'files' member. See 'npm help json'", files) delete json.files } @@ -354,14 +346,11 @@ function processObject (opts, cb) { return function (er, json) { json._id = json.name+"@"+json.version - var tag = opts.tag - if (tag) json.version = tag - var scripts = json.scripts || {} // if it has a bindings.gyp, then build with node-gyp if (opts.gypfile && !json.prebuilt) { - log.verbose([json.prebuilt, opts], "has bindings.gyp") + log.verbose(json._id, "has bindings.gyp", [json.prebuilt, opts]) if (!scripts.install && !scripts.preinstall) { scripts.install = "node-gyp rebuild" json.scripts = scripts @@ -370,7 +359,7 @@ function processObject (opts, cb) { return function (er, json) { // if it has a wscript, then build it. if (opts.wscript && !json.prebuilt) { - log.verbose([json.prebuilt, opts], "has wscript") + log.verbose(json._id, "has wscript", [json.prebuilt, opts]) if (!scripts.install && !scripts.preinstall) { // don't fail if it was unexpected, just try. scripts.preinstall = "node-waf clean || (exit 0); node-waf configure build" @@ -460,7 +449,7 @@ function processObject (opts, cb) { return function (er, json) { json._npmVersion = npm.version json._nodeVersion = process.version if (opts.file) { - log.verbose(opts.file, "caching") + log.verbose("caching json", opts.file) cache[opts.file] = json // arbitrary var keys = Object.keys(cache) @@ -522,8 +511,9 @@ function testEngine (json) { } if (json.engines.node === "") json.engines.node = "*" if (json.engines.node && null === semver.validRange(json.engines.node)) { - log.warn( json.engines.node - , "Invalid range in engines.node. Please see `npm help json`" ) + log.warn( json._id + , "Invalid range in engines.node. Please see `npm help json`" + , json.engines.node ) } if (nodeVer) { diff --git a/deps/npm/lib/utils/sha.js b/deps/npm/lib/utils/sha.js index 17b8c38f9..d3cd83a93 100644 --- a/deps/npm/lib/utils/sha.js +++ b/deps/npm/lib/utils/sha.js @@ -1,7 +1,7 @@ var fs = require("graceful-fs") , crypto = require("crypto") - , log = require("./log.js") + , log = require("npmlog") , binding try { binding = process.binding("crypto") } @@ -12,11 +12,14 @@ exports.get = get function check (file, sum, cb) { if (!binding) { - log.warn("crypto binding not found. Cannot verify shasum.", "shasum") + log.warn("shasum", "crypto binding not found. Cannot verify shasum.") return cb() } get(file, function (er, actual) { - if (er) return log.er(cb, "Error getting shasum")(er) + if (er) { + log.error("shasum", "error getting shasum") + return cb(er) + } var expected = sum.toLowerCase().trim() , ok = actual === expected cb(ok ? null : new Error( @@ -28,7 +31,7 @@ function check (file, sum, cb) { function get (file, cb) { if (!binding) { - log.warn("crypto binding not found. Cannot verify shasum.", "shasum") + log.warn("shasum", "crypto binding not found. Cannot verify shasum.") return cb() } var h = crypto.createHash("sha1") @@ -36,16 +39,16 @@ function get (file, cb) { , errState = null s.on("error", function (er) { if (errState) return - log.silly(er.stack || er.message, "sha error") + log.silly("shasum", "error", er) return cb(errState = er) }).on("data", function (chunk) { if (errState) return - log.silly(chunk.length, "updated sha bytes") + log.silly("shasum", "updated bytes", chunk.length) h.update(chunk) }).on("end", function () { if (errState) return var actual = h.digest("hex").toLowerCase().trim() - log(actual+"\n"+file, "shasum") + log.info("shasum", actual+"\n"+file) cb(null, actual) }) } diff --git a/deps/npm/lib/utils/tar.js b/deps/npm/lib/utils/tar.js index 76ef6ea92..22a4a852c 100644 --- a/deps/npm/lib/utils/tar.js +++ b/deps/npm/lib/utils/tar.js @@ -4,7 +4,7 @@ var npm = require("../npm.js") , fs = require("graceful-fs") , path = require("path") - , log = require("./log.js") + , log = require("npmlog") , uidNumber = require("uid-number") , rm = require("rimraf") , readJson = require("./read-json.js") @@ -27,11 +27,11 @@ exports.pack = pack exports.unpack = unpack function pack (targetTarball, folder, pkg, dfc, cb) { - log.verbose([targetTarball, folder], "tar.pack") + log.verbose("tar pack", [targetTarball, folder]) if (typeof cb !== "function") cb = dfc, dfc = false - log.verbose(targetTarball, "tarball") - log.verbose(folder, "folder") + log.verbose("tarball", targetTarball) + log.verbose("folder", folder) if (dfc) { // do fancy crap @@ -46,7 +46,10 @@ function pack (targetTarball, folder, pkg, dfc, cb) { function pack_ (targetTarball, folder, pkg, cb) { new Packer({ path: folder, type: "Directory", isDirectory: true }) - .on("error", log.er(cb, "error reading "+folder)) + .on("error", function (er) { + if (er) log.error("tar pack", "Error reading " + folder) + return cb(er) + }) // By default, npm includes some proprietary attributes in the // package tarball. This is sane, and allowed by the spec. @@ -54,19 +57,26 @@ function pack_ (targetTarball, folder, pkg, cb) { // so that it can be more easily bootstrapped using old and // non-compliant tar implementations. .pipe(tar.Pack({ noProprietary: !npm.config.get("proprietary-attribs") })) - .on("error", log.er(cb, "tar creation error "+targetTarball)) + .on("error", function (er) { + if (er) log.error("tar.pack", "tar creation error", targetTarball) + cb(er) + }) .pipe(zlib.Gzip()) - .on("error", log.er(cb, "gzip error "+targetTarball)) + .on("error", function (er) { + if (er) log.error("tar.pack", "gzip error "+targetTarball) + cb(er) + }) .pipe(fstream.Writer({ type: "File", path: targetTarball })) - .on("error", log.er(cb, "Could not write "+targetTarball)) - .on("close", function () { - cb() + .on("error", function (er) { + if (er) log.error("tar.pack", "Could not write "+targetTarball) + cb(er) }) + .on("close", cb) } function unpack (tarball, unpackTarget, dMode, fMode, uid, gid, cb) { - log.verbose(tarball, "unpack") + log.verbose("tar unpack", tarball) if (typeof cb !== "function") cb = gid, gid = null if (typeof cb !== "function") cb = uid, uid = null if (typeof cb !== "function") cb = fMode, fMode = npm.modes.file @@ -101,7 +111,7 @@ function unpack_ ( tarball, unpackTarget, dMode, fMode, uid, gid, cb ) { function gunzTarPerm (tarball, target, dMode, fMode, uid, gid, cb_) { if (!dMode) dMode = npm.modes.exec if (!fMode) fMode = npm.modes.file - log.silly([dMode.toString(8), fMode.toString(8)], "gunzTarPerm modes") + log.silly("gunzTarPerm", "modes", [dMode.toString(8), fMode.toString(8)]) var cbCalled = false function cb (er) { @@ -120,7 +130,7 @@ function gunzTarPerm (tarball, target, dMode, fMode, uid, gid, cb_) { } function extractEntry (entry) { - log.silly(entry.path, "extracting entry") + log.silly("gunzTarPerm", "extractEntry", entry.path) // never create things that are user-unreadable, // or dirs that are user-un-listable. Only leads to headaches. var originalMode = entry.mode = entry.mode || entry.props.mode @@ -128,7 +138,8 @@ function gunzTarPerm (tarball, target, dMode, fMode, uid, gid, cb_) { entry.mode = entry.mode & (~npm.modes.umask) entry.props.mode = entry.mode if (originalMode !== entry.mode) { - log.silly([entry.path, originalMode, entry.mode], "modified mode") + log.silly( "gunzTarPerm", "modified mode" + , [entry.path, originalMode, entry.mode]) } // if there's a specific owner uid/gid that we want, then set that @@ -152,16 +163,19 @@ function gunzTarPerm (tarball, target, dMode, fMode, uid, gid, cb_) { extractOpts.filter = function () { // symbolic links are not allowed in packages. if (this.type.match(/^.*Link$/)) { - log.warn( this.path.substr(target.length + 1) - + ' -> ' + this.linkpath - , "excluding symbolic link") + log.warn( "excluding symbolic link" + , this.path.substr(target.length + 1) + + ' -> ' + this.linkpath ) return false } return true } - fst.on("error", log.er(cb, "error reading "+tarball)) + fst.on("error", function (er) { + if (er) log.error("tar.unpack", "error reading "+tarball) + cb(er) + }) fst.on("data", function OD (c) { // detect what it is. // Then, depending on that, we'll figure out whether it's @@ -172,17 +186,26 @@ function gunzTarPerm (tarball, target, dMode, fMode, uid, gid, cb_) { c[2] === 0x08) { fst .pipe(zlib.Unzip()) - .on("error", log.er(cb, "unzip error "+tarball)) + .on("error", function (er) { + if (er) log.error("tar.unpack", "unzip error "+tarball) + cb(er) + }) .pipe(tar.Extract(extractOpts)) .on("entry", extractEntry) - .on("error", log.er(cb, "untar error "+tarball)) + .on("error", function (er) { + if (er) log.error("tar.unpack", "untar error "+tarball) + cb(er) + }) .on("close", cb) } else if (c.toString().match(/^package\//)) { // naked tar fst .pipe(tar.Extract(extractOpts)) .on("entry", extractEntry) - .on("error", log.er(cb, "untar error "+tarball)) + .on("error", function (er) { + if (er) log.error("tar.unpack", "untar error "+tarball) + cb(er) + }) .on("close", cb) } else { // naked js file @@ -197,12 +220,15 @@ function gunzTarPerm (tarball, target, dMode, fMode, uid, gid, cb_) { fst .pipe(fstream.Writer(jsOpts)) - .on("error", log.er(cb, "copy error "+tarball)) + .on("error", function (er) { + if (er) log.error("tar.unpack", "copy error "+tarball) + cb(er) + }) .on("close", function () { var j = path.resolve(target, "package.json") readJson(j, function (er, d) { if (er) { - log.error(tarball, "Not a package") + log.error("not a package", tarball) return cb(er) } fs.writeFile(j, JSON.stringify(d) + "\n", cb) diff --git a/deps/npm/lib/version.js b/deps/npm/lib/version.js index febb56d73..35329760e 100644 --- a/deps/npm/lib/version.js +++ b/deps/npm/lib/version.js @@ -8,7 +8,7 @@ var exec = require("./utils/exec.js") , path = require("path") , fs = require("graceful-fs") , chain = require("slide").chain - , log = require("./utils/log.js") + , log = require("npmlog") , npm = require("./npm.js") version.usage = "npm version <newversion> [--message commit-message]" @@ -22,7 +22,10 @@ version.usage = "npm version <newversion> [--message commit-message]" function version (args, cb) { if (args.length !== 1) return cb(version.usage) readJson(path.join(process.cwd(), "package.json"), function (er, data) { - if (er) return log.er(cb, "No package.json found")(er) + if (er) { + log.error("version", "No package.json found") + return cb(er) + } var newVer = semver.valid(args[0]) if (!newVer) newVer = semver.inc(data.version, args[0]) if (!newVer) return cb(version.usage) diff --git a/deps/npm/lib/view.js b/deps/npm/lib/view.js index 33a5d0df8..6ffde4c28 100644 --- a/deps/npm/lib/view.js +++ b/deps/npm/lib/view.js @@ -39,12 +39,12 @@ view.completion = function (opts, cb) { } } -var registry = require("./utils/npm-registry-client/index.js") +var npm = require("./npm.js") + , registry = npm.registry , ini = require("ini") - , log = require("./utils/log.js") + , log = require("npmlog") , util = require("util") , output - , npm = require("./npm.js") , semver = require("semver") , readJson = require("./utils/read-json.js") @@ -59,7 +59,7 @@ function view (args, silent, cb) { if (name === ".") return cb(view.usage) // get the data about this package - registry.get(name, null, 600, function (er, data) { + registry.get(name, 600, function (er, data) { if (er) return cb(er) if (data["dist-tags"].hasOwnProperty(version)) { version = data["dist-tags"][version] @@ -94,7 +94,7 @@ function view (args, silent, cb) { if (args.length === 1 && args[0] === "") { retval = cleanBlanks(retval) - log.silly(retval, "cleanup") + log.silly("cleanup", retval) } if (error || silent) cb(error, retval) diff --git a/deps/npm/lib/whoami.js b/deps/npm/lib/whoami.js index c48f04b1d..b6e495253 100644 --- a/deps/npm/lib/whoami.js +++ b/deps/npm/lib/whoami.js @@ -2,7 +2,6 @@ module.exports = whoami var npm = require("./npm.js") , output = require("./utils/output.js") - , log = require("./utils/log.js") whoami.usage = "npm whoami\n(just prints the 'username' config)" diff --git a/deps/npm/lib/xmas.js b/deps/npm/lib/xmas.js index 90282d0f7..bf838a87a 100644 --- a/deps/npm/lib/xmas.js +++ b/deps/npm/lib/xmas.js @@ -1,9 +1,8 @@ // happy xmas var npm = require("./npm.js") - , log = require("./utils/log.js") + , log = require("npmlog") module.exports = function (args, cb) { -npm.config.set("loglevel", "win") var s = process.platform === "win32" ? " *" : " \u2605" , f = "\uFF0F" , b = "\uFF3C" @@ -44,7 +43,10 @@ w("\n") } })(20) w("\n\n") -log.win("Happy Xmas, Noders!", "loves you", cb) +log.heading = '' +log.addLevel('npm', 100000, log.headingStyle) +log.npm("loves you", "Happy Xmas, Noders!") +cb() } var dg=false Object.defineProperty(module.exports, "usage", {get:function () { |