Browse files

Replace the log util with npmlog module

This feels so good.  lib/utils/log.js is the worst kind of
glue code that keeps the npm project from being properly
abstracted into independent pieces.

In the process, also cleaned up a lot of unproductive logging,
and made the npm-debug.log generated on errors be a bit more
easy to read.
  • Loading branch information...
1 parent d4b2d11 commit 2568e40a395b809fb34125b3383f9f2616004f73 @isaacs isaacs committed Jun 6, 2012
Showing with 498 additions and 621 deletions.
  1. +6 −6 bin/npm-cli.js
  2. +5 −16 doc/cli/coding-style.md
  3. +0 −22 doc/cli/config.md
  4. +2 −2 lib/adduser.js
  5. +2 −2 lib/bugs.js
  6. +9 −9 lib/build.js
  7. +78 −43 lib/cache.js
  8. +2 −2 lib/config.js
  9. +0 −1 lib/deprecate.js
  10. +2 −2 lib/docs.js
  11. +0 −1 lib/edit.js
  12. +5 −2 lib/help-search.js
  13. +3 −1 lib/help.js
  14. +4 −5 lib/init.js
  15. +35 −32 lib/install.js
  16. +7 −4 lib/link.js
  17. +5 −3 lib/ls.js
  18. +14 −6 lib/npm.js
  19. +0 −1 lib/outdated.js
  20. +28 −16 lib/owner.js
  21. +9 −9 lib/publish.js
  22. +4 −4 lib/rebuild.js
  23. +0 −1 lib/root.js
  24. +2 −2 lib/run-script.js
  25. +0 −1 lib/search.js
  26. +3 −3 lib/shrinkwrap.js
  27. +2 −2 lib/star.js
  28. +12 −2 lib/substack.js
  29. +1 −1 lib/unbuild.js
  30. +3 −3 lib/uninstall.js
  31. +6 −2 lib/unpublish.js
  32. +2 −2 lib/update.js
  33. +3 −3 lib/utils/cmd-shim.js
  34. +4 −4 lib/utils/completion/users.js
  35. +8 −15 lib/utils/config-defs.js
  36. +55 −48 lib/utils/error-handler.js
  37. +3 −37 lib/utils/exec.js
  38. +4 −4 lib/utils/fetch.js
  39. +4 −4 lib/utils/ini.js
  40. +11 −14 lib/utils/lifecycle.js
  41. +0 −1 lib/utils/link.js
  42. +4 −4 lib/utils/load-package-defaults.js
  43. +0 −170 lib/utils/log.js
  44. +6 −6 lib/utils/npm-registry-client/adduser.js
  45. +6 −6 lib/utils/npm-registry-client/get.js
  46. +17 −15 lib/utils/npm-registry-client/publish.js
  47. +9 −9 lib/utils/npm-registry-client/request.js
  48. +3 −3 lib/utils/npm-registry-client/star.js
  49. +17 −10 lib/utils/npm-registry-client/unpublish.js
  50. +4 −4 lib/utils/read-installed.js
  51. +18 −18 lib/utils/read-json.js
  52. +10 −7 lib/utils/sha.js
  53. +49 −23 lib/utils/tar.js
  54. +5 −2 lib/version.js
  55. +2 −2 lib/view.js
  56. +0 −1 lib/whoami.js
  57. +5 −3 lib/xmas.js
View
12 bin/npm-cli.js
@@ -15,9 +15,9 @@ if (typeof WScript !== "undefined") {
process.title = "npm"
-var log = require("../lib/utils/log.js")
-log.waitForConfig()
-log.info("ok", "it worked if it ends with")
+var log = require("npmlog")
+log.pause() // will be unpaused when config is loaded.
+log.info("it worked if it ends with", "ok")
var fs = require("graceful-fs")
, path = require("path")
@@ -36,7 +36,7 @@ if (path.basename(process.argv[1]).slice(-1) === "g") {
process.argv.splice(1, 1, "npm", "-g")
}
-log.verbose(process.argv, "cli")
+log.verbose("cli", process.argv)
var conf = nopt(types, shorthands)
npm.argv = conf.argv.remain
@@ -56,8 +56,8 @@ if (conf.versions) {
return
}
-log.info("npm@"+npm.version, "using")
-log.info("node@"+process.version, "using")
+log.info("using", "npm@%s", npm.version)
+log.info("using", "node@%s", process.version)
// make sure that this version of node works with this version of npm.
var semver = require("semver")
View
21 doc/cli/coding-style.md
@@ -129,29 +129,18 @@ Just send the error message back as the first argument to the callback.
Always create a new Error object with your message. Don't just return a
string message to the callback. Stack traces are handy.
-Use the `require("./utils/log").er` function. It takes a callback and an
-error message, and returns an object that will report the message in the
-event of a failure. It's quite handy.
-
- function myThing (args, cb) {
- getData(args, function (er, data) {
- if (er) return log.er(cb, "Couldn't get data")(er)
- doSomethingElse(data, cb)
- })
- }
- function justHasToWork (cb) {
- doSomething(log.er(cb, "the doSomething failed."))
- }
-
## Logging
+Logging is done using the [npmlog](https://github.com/isaacs/npmlog)
+utility.
+
Please clean up logs when they are no longer helpful. In particular,
logging the same object over and over again is not helpful. Logs should
report what's happening so that it's easier to track down where a fault
occurs.
-Use appropriate log levels. The default log() function logs at the
-"info" level. See `npm-config(1)` and search for "loglevel".
+Use appropriate log levels. See `npm-config(1)` and search for
+"loglevel".
## Case, naming, etc.
View
22 doc/cli/config.md
@@ -430,13 +430,6 @@ if one of the two conditions are met:
* the globally installed version is identical to the version that is
being installed locally.
-### logfd
-
-* Default: stderr file descriptor
-* Type: Number or Stream
-
-The location to write log output.
-
### loglevel
* Default: "http"
@@ -449,14 +442,6 @@ What level of logs to report. On failure, *all* logs are written to
Any logs of a higher level than the setting are shown.
The default is "http", which shows http, warn, and error output.
-### logprefix
-
-* Default: true on Posix, false on Windows
-* Type: Boolean
-
-Whether or not to prefix log messages with "npm" and the log level. See
-also "color" and "loglevel".
-
### long
* Default: false
@@ -503,13 +488,6 @@ The url to report npat test results.
A node module to `require()` when npm loads. Useful for programmatic
usage.
-### outfd
-
-* Default: standard output file descriptor
-* Type: Number or Stream
-
-Where to write "normal" output. This has no effect on log output.
-
### parseable
* Default: false
View
4 lib/adduser.js
@@ -3,7 +3,7 @@ module.exports = adduser
var registry = require("./utils/npm-registry-client/index.js")
, ini = require("./utils/ini.js")
- , log = require("./utils/log.js")
+ , log = require("npmlog")
, npm = require("./npm.js")
, read = require("read")
, promiseChain = require("./utils/promise-chain.js")
@@ -42,7 +42,7 @@ function adduser (args, cb) {
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)
})
})
View
4 lib/bugs.js
@@ -13,7 +13,7 @@ bugs.completion = function (opts, cb) {
var exec = require("./utils/exec.js")
, registry = require("./utils/npm-registry-client/index.js")
, npm = require("./npm.js")
- , log = require("./utils/log.js")
+ , log = require("npmlog")
function bugs (args, cb) {
if (!args.length) return cb(bugs.usage)
@@ -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/")
View
18 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])
View
121 lib/cache.js
@@ -39,7 +39,7 @@ var mkdir = require("mkdirp")
, rm = require("rimraf")
, readJson = require("./utils/read-json.js")
, registry = require("./utils/npm-registry-client/index.js")
- , log = require("./utils/log.js")
+ , 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,15 +358,15 @@ 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
)(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)
})
}
@@ -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)
}
}
View
4 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)
View
1 lib/deprecate.js
@@ -20,7 +20,6 @@ deprecate.completion = function (opts, cb) {
var registry = require("./utils/npm-registry-client/index.js")
, semver = require("semver")
- , log = require("./utils/log.js")
, npm = require("./npm.js")
function deprecate (args, cb) {
View
4 lib/docs.js
@@ -13,7 +13,7 @@ docs.completion = function (opts, cb) {
var exec = require("./utils/exec.js")
, registry = require("./utils/npm-registry-client/index.js")
, npm = require("./npm.js")
- , log = require("./utils/log.js")
+ , log = require("npmlog")
function docs (args, cb) {
if (!args.length) return cb(docs.usage)
@@ -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)
View
1 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]
View
7 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 = []
View
4 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>"
, ""
View
9 lib/init.js
@@ -10,16 +10,15 @@ 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")
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)
})
})
View
67 lib/install.js
@@ -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,26 +179,26 @@ 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)
}
var wrapfile = path.resolve(where, "npm-shrinkwrap.json")
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,15 +524,15 @@ 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, [])
}
// check for a version installed higher in the tree.
// 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,19 +541,19 @@ 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, [])
}
if (wrap) {
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)
}
})
@@ -785,7 +788,7 @@ 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
return cb(er)
@@ -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")
View
11 lib/link.js
@@ -5,7 +5,7 @@
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")
@@ -85,7 +85,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 +95,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]]
@@ -120,7 +123,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)
View
8 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,7 +169,7 @@ 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)"
@@ -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"
View
20 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")
@@ -64,17 +64,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 +250,7 @@ npm.load = function (conf, cb_) {
}
}
- log.waitForConfig()
+ log.pause()
load(npm, conf, cb)
}
@@ -268,6 +268,14 @@ function load (npm, conf, cb) {
//console.error("about to look up configs")
ini.resolveConfigs(conf, function (er) {
+ 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()
+
//console.error("back from config lookup", er && er.stack)
if (er) return cb(er)
@@ -352,7 +360,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) {
View
1 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")
View
44 lib/owner.js
@@ -67,7 +67,7 @@ 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")
+ , log = require("npmlog")
, output
, npm = require("./npm.js")
@@ -85,7 +85,10 @@ function ls (pkg, cb) {
if (!pkg) return cb(owner.usage)
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 +104,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 +127,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 +136,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(
@@ -151,12 +153,20 @@ function mutate (pkg, user, mutation, cb) {
}
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)
+ 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
@@ -165,10 +175,12 @@ function mutate (pkg, user, mutation, cb) {
, 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)
+ 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)
})
})
}
View
18 lib/publish.js
@@ -3,7 +3,7 @@ module.exports = publish
var npm = require("./npm.js")
, registry = require("./utils/npm-registry-client/index.js")
- , log = require("./utils/log.js")
+ , 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
@@ -154,7 +154,7 @@ function regPublish (data, prebuilt, isRetry, arg, cachedir, cb) {
registry.publish(data, prebuilt, readme, function (er) {
if (er && er.errno === npm.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)
View
8 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.
View
1 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)"
View
4 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]
View
1 lib/search.js
@@ -5,7 +5,6 @@ var npm = require("./npm.js")
, registry = require("./utils/npm-registry-client/index.js")
, semver = require("semver")
, output
- , log = require("./utils/log.js")
search.usage = "npm search [some search terms ...]"
View
6 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)
}
View
4 lib/star.js
@@ -3,7 +3,7 @@ module.exports = star
var npm = require("./npm.js")
, registry = require("./utils/npm-registry-client/index.js")
- , log = require("./utils/log.js")
+ , log = require("npmlog")
, asyncMap = require("slide").asyncMap
, output = require("./utils/output.js")
@@ -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)
})
View
14 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()
View
2 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.
View
6 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)
View
8 lib/unpublish.js
@@ -2,7 +2,7 @@
module.exports = unpublish
var registry = require("./utils/npm-registry-client/index.js")
- , log = require("./utils/log.js")
+ , log = require("npmlog")
, npm = require("./npm.js")
, readJson = require("./utils/read-json.js")
, path = require("path")
@@ -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)
})
}
View
4 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) {
View
6 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)
View
8 lib/utils/completion/users.js
@@ -4,16 +4,16 @@ module.exports = users
var registry = require("../npm-registry-client/index.js")
, 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")
+ log.warn("users completion", "About to fetch")
registry.get("/-/users", null, 24*60*60, function (er, d) {
- log.warn(d, "userdata")
- log.warn(name, "name")
+ log.warn("userdata", d)
+ log.warn("name", name)
if (er) return cb(er)
var remoteList = Object.keys(d)
, simpleMatches = getCompletions(name, remoteList)
View
23 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))