Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2012-06-07 01:48:24 +0400
committerisaacs <i@izs.me>2012-06-07 01:56:35 +0400
commit2568e40a395b809fb34125b3383f9f2616004f73 (patch)
treeb770c89d4ed5a46341bf3b42e563a7fbf110af32
parentd4b2d1149a0f2b56467ebeebd36e21d3a2bfe48a (diff)
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.
-rwxr-xr-xbin/npm-cli.js12
-rw-r--r--doc/cli/coding-style.md21
-rw-r--r--doc/cli/config.md22
-rw-r--r--lib/adduser.js4
-rw-r--r--lib/bugs.js4
-rw-r--r--lib/build.js18
-rw-r--r--lib/cache.js121
-rw-r--r--lib/config.js4
-rw-r--r--lib/deprecate.js1
-rw-r--r--lib/docs.js4
-rw-r--r--lib/edit.js1
-rw-r--r--lib/help-search.js7
-rw-r--r--lib/help.js4
-rw-r--r--lib/init.js9
-rw-r--r--lib/install.js67
-rw-r--r--lib/link.js11
-rw-r--r--lib/ls.js8
-rw-r--r--lib/npm.js20
-rw-r--r--lib/outdated.js1
-rw-r--r--lib/owner.js44
-rw-r--r--lib/publish.js18
-rw-r--r--lib/rebuild.js8
-rw-r--r--lib/root.js1
-rw-r--r--lib/run-script.js4
-rw-r--r--lib/search.js1
-rw-r--r--lib/shrinkwrap.js6
-rw-r--r--lib/star.js4
-rw-r--r--lib/substack.js14
-rw-r--r--lib/unbuild.js2
-rw-r--r--lib/uninstall.js6
-rw-r--r--lib/unpublish.js8
-rw-r--r--lib/update.js4
-rw-r--r--lib/utils/cmd-shim.js6
-rw-r--r--lib/utils/completion/users.js8
-rw-r--r--lib/utils/config-defs.js23
-rw-r--r--lib/utils/error-handler.js103
-rw-r--r--lib/utils/exec.js40
-rw-r--r--lib/utils/fetch.js8
-rw-r--r--lib/utils/ini.js8
-rw-r--r--lib/utils/lifecycle.js25
-rw-r--r--lib/utils/link.js1
-rw-r--r--lib/utils/load-package-defaults.js8
-rw-r--r--lib/utils/log.js170
-rw-r--r--lib/utils/npm-registry-client/adduser.js12
-rw-r--r--lib/utils/npm-registry-client/get.js12
-rw-r--r--lib/utils/npm-registry-client/publish.js32
-rw-r--r--lib/utils/npm-registry-client/request.js18
-rw-r--r--lib/utils/npm-registry-client/star.js6
-rw-r--r--lib/utils/npm-registry-client/unpublish.js27
-rw-r--r--lib/utils/read-installed.js8
-rw-r--r--lib/utils/read-json.js36
-rw-r--r--lib/utils/sha.js17
-rw-r--r--lib/utils/tar.js72
-rw-r--r--lib/version.js7
-rw-r--r--lib/view.js4
-rw-r--r--lib/whoami.js1
-rw-r--r--lib/xmas.js8
57 files changed, 498 insertions, 621 deletions
diff --git a/bin/npm-cli.js b/bin/npm-cli.js
index f29437093..a71985b37 100755
--- a/bin/npm-cli.js
+++ b/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")
diff --git a/doc/cli/coding-style.md b/doc/cli/coding-style.md
index 42ac1d785..c505dba83 100644
--- a/doc/cli/coding-style.md
+++ b/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.
diff --git a/doc/cli/config.md b/doc/cli/config.md
index 3fd9cb826..659895eaf 100644
--- a/doc/cli/config.md
+++ b/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
diff --git a/lib/adduser.js b/lib/adduser.js
index d65eed595..4aa54cf0e 100644
--- a/lib/adduser.js
+++ b/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)
})
})
diff --git a/lib/bugs.js b/lib/bugs.js
index 2a9352632..0d5460ac9 100644
--- a/lib/bugs.js
+++ b/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/")
diff --git a/lib/build.js b/lib/build.js
index 864eb27cf..c0dcbf7fb 100644
--- a/lib/build.js
+++ b/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/lib/cache.js b/lib/cache.js
index 076267e89..69f0c746d 100644
--- a/lib/cache.js
+++ b/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,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)
})
}
@@ -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/lib/config.js b/lib/config.js
index a69c30ea6..44f3d36f4 100644
--- a/lib/config.js
+++ b/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/lib/deprecate.js b/lib/deprecate.js
index 6f18879e4..2fd18cf9f 100644
--- a/lib/deprecate.js
+++ b/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) {
diff --git a/lib/docs.js b/lib/docs.js
index 20b110406..275fce7e9 100644
--- a/lib/docs.js
+++ b/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)
diff --git a/lib/edit.js b/lib/edit.js
index df103d4df..0ffe723bc 100644
--- a/lib/edit.js
+++ b/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/lib/help-search.js b/lib/help-search.js
index a4ef667c0..6f1f117cb 100644
--- a/lib/help-search.js
+++ b/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/lib/help.js b/lib/help.js
index 442f839b3..998d90471 100644
--- a/lib/help.js
+++ b/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/lib/init.js b/lib/init.js
index 7cd7da8e2..0d96e07ac 100644
--- a/lib/init.js
+++ b/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/lib/install.js b/lib/install.js
index 276f3d8b3..ed5c4ce2b 100644
--- a/lib/install.js
+++ b/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,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)
}
})
@@ -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")
diff --git a/lib/link.js b/lib/link.js
index 3049884ca..c7bf6eafe 100644
--- a/lib/link.js
+++ b/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)
diff --git a/lib/ls.js b/lib/ls.js
index 276530c35..f71af6831 100644
--- a/lib/ls.js
+++ b/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"
diff --git a/lib/npm.js b/lib/npm.js
index 2db21e34d..1a7ae4b42 100644
--- a/lib/npm.js
+++ b/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) {
diff --git a/lib/outdated.js b/lib/outdated.js
index e883abd35..d87dc9ab6 100644
--- a/lib/outdated.js
+++ b/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/lib/owner.js b/lib/owner.js
index 5f13d926f..ebad9ed10 100644
--- a/lib/owner.js
+++ b/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)
})
})
}
diff --git a/lib/publish.js b/lib/publish.js
index 1cf59f01a..eed04cf2f 100644
--- a/lib/publish.js
+++ b/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)
diff --git a/lib/rebuild.js b/lib/rebuild.js
index 0e1d56a1d..a4a39f7b9 100644
--- a/lib/rebuild.js
+++ b/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/lib/root.js b/lib/root.js
index 6062ec220..59ccc0b08 100644
--- a/lib/root.js
+++ b/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/lib/run-script.js b/lib/run-script.js
index 4a4d2dc61..17b48abf8 100644
--- a/lib/run-script.js
+++ b/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/lib/search.js b/lib/search.js
index 213390eb0..ba27bdb52 100644
--- a/lib/search.js
+++ b/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 ...]"
diff --git a/lib/shrinkwrap.js b/lib/shrinkwrap.js
index 59942d586..cdad89abc 100644
--- a/lib/shrinkwrap.js
+++ b/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/lib/star.js b/lib/star.js
index d84fa02ed..2ad818479 100644
--- a/lib/star.js
+++ b/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)
})
diff --git a/lib/substack.js b/lib/substack.js
index 95a90f824..1929f1873 100644
--- a/lib/substack.js
+++ b/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/lib/unbuild.js b/lib/unbuild.js
index 771eddf7d..c5ef21f22 100644
--- a/lib/unbuild.js
+++ b/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.
diff --git a/lib/uninstall.js b/lib/uninstall.js
index 655e5eb96..a1998e7fe 100644
--- a/lib/uninstall.js
+++ b/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/lib/unpublish.js b/lib/unpublish.js
index b7f6cbec8..46c91d1ef 100644
--- a/lib/unpublish.js
+++ b/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)
})
}
diff --git a/lib/update.js b/lib/update.js
index 69b9f98e8..46d32678e 100644
--- a/lib/update.js
+++ b/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/lib/utils/cmd-shim.js b/lib/utils/cmd-shim.js
index e24da36f6..a31af6801 100644
--- a/lib/utils/cmd-shim.js
+++ b/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/lib/utils/completion/users.js b/lib/utils/completion/users.js
index f77312c94..2c62fc6ec 100644
--- a/lib/utils/completion/users.js
+++ b/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)
diff --git a/lib/utils/config-defs.js b/lib/utils/config-defs.js
index 18b47ecdb..4542e8fd6 100644
--- a/lib/utils/config-defs.js
+++ b/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/lib/utils/error-handler.js b/lib/utils/error-handler.js
index f7fdf165f..3ee337bb1 100644
--- a/lib/utils/error-handler.js
+++ b/lib/utils/error-handler.js
@@ -2,7 +2,7 @@
module.exports = errorHandler
var cbCalled = false
- , log = require("./log.js")
+ , log = require("npmlog")
, npm = require("../npm.js")
, rm = require("rimraf")
, constants = require("constants")
@@ -20,16 +20,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 +49,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,7 +84,7 @@ 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)
}
@@ -95,8 +99,8 @@ function errorHandler (er) {
switch (er.code || er.errno) {
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
@@ -105,15 +109,15 @@ function errorHandler (er) {
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:
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:"
@@ -126,9 +130,9 @@ function errorHandler (er) {
case npm.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."
@@ -149,31 +153,31 @@ 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:
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:
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:
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."
@@ -182,7 +186,7 @@ function errorHandler (er) {
case npm.ENOTSUP:
er.code = "ENOTSUP"
- log.error([er.message
+ log.error("notsup", [er.message
,"Not compatible with your version of node/npm: "+er.pkgid
,"Required: "+JSON.stringify(er.required)
,"Actual: "
@@ -193,7 +197,7 @@ function errorHandler (er) {
case npm.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(",")
@@ -210,8 +214,8 @@ function errorHandler (er) {
break
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 +224,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"
@@ -243,11 +248,11 @@ function errorHandler (er) {
, "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 +268,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/lib/utils/exec.js b/lib/utils/exec.js
index b9a5b6911..56d331a67 100644
--- a/lib/utils/exec.js
+++ b/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/lib/utils/fetch.js b/lib/utils/fetch.js
index bc1c095cd..f69975ba6 100644
--- a/lib/utils/fetch.js
+++ b/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/lib/utils/ini.js b/lib/utils/ini.js
index b033b6a04..aa4f43180 100644
--- a/lib/utils/ini.js
+++ b/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/lib/utils/lifecycle.js b/lib/utils/lifecycle.js
index c5ebbbee1..69935b9b1 100644
--- a/lib/utils/lifecycle.js
+++ b/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,7 +156,7 @@ 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
@@ -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/lib/utils/link.js b/lib/utils/link.js
index 7fa80d5e1..17a02e5ba 100644
--- a/lib/utils/link.js
+++ b/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")
diff --git a/lib/utils/load-package-defaults.js b/lib/utils/load-package-defaults.js
index 180507a44..8a72ade30 100644
--- a/lib/utils/load-package-defaults.js
+++ b/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/lib/utils/log.js b/lib/utils/log.js
deleted file mode 100644
index 07867e3e9..000000000
--- a/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/lib/utils/npm-registry-client/adduser.js b/lib/utils/npm-registry-client/adduser.js
index 5e6794a75..0dc582395 100644
--- a/lib/utils/npm-registry-client/adduser.js
+++ b/lib/utils/npm-registry-client/adduser.js
@@ -3,7 +3,7 @@ module.exports = adduser
var uuid = require("node-uuid")
, request = require("./request.js")
- , log = require("../log.js")
+ , log = require("npmlog")
, npm = require("../../npm.js")
, crypto
@@ -43,7 +43,7 @@ function adduser (username, password, email, cb) {
, date: new Date().toISOString()
}
cb = done(cb)
- log.verbose(userobj, "before first PUT")
+ log.verbose("adduser", "before first PUT", userobj)
request.PUT
( '/-/user/org.couchdb.user:'+encodeURIComponent(username)
, userobj
@@ -61,13 +61,13 @@ function adduser (username, password, email, cb) {
if (!error || !response || response.statusCode !== 409) {
return cb(error, data, json, response)
}
- log.verbose("update existing user", "adduser")
+ log.verbose("adduser", "update existing user")
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")
+ log.verbose("adduser", "userobj", userobj)
request.PUT
( '/-/user/org.couchdb.user:'+encodeURIComponent(username)
+ "/-rev/" + userobj._rev
@@ -83,14 +83,14 @@ 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")
+ log.verbose("adduser", "back", [error, data, json])
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"
+ log.warn("adduser", "Incorrect username or password\n"
+"You can reset your account by visiting:\n"
+"\n"
+" http://admin.npmjs.org/reset\n")
diff --git a/lib/utils/npm-registry-client/get.js b/lib/utils/npm-registry-client/get.js
index e0902f027..89a3d7cbc 100644
--- a/lib/utils/npm-registry-client/get.js
+++ b/lib/utils/npm-registry-client/get.js
@@ -5,7 +5,7 @@ var GET = require("./request.js").GET
, fs = require("graceful-fs")
, npm = require("../../npm.js")
, path = require("path")
- , log = require("../log.js")
+ , log = require("npmlog")
, mkdir = require("mkdirp")
, cacheStat = null
, chownr = require("chownr")
@@ -83,7 +83,7 @@ function requestAll_ (c, data, cb) {
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")
+ log.warn("", "Building the local index for the first time, please be patient")
uri = "/-/all"
}
@@ -109,12 +109,12 @@ function get_ (uri, timeout, cache, stat, data, nofollow, staleOk, cb) {
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)
+ log.verbose("registry.get", uri, "not expired, no request")
delete data._etag
return cb(null, data, JSON.stringify(data), {statusCode:304})
}
if (staleOk) {
- log.verbose("staleOk, background update", "registry.get " +uri)
+ log.verbose("registry.get", uri, "staleOk, background update")
delete data._etag
process.nextTick(cb.bind( null, null, data, JSON.stringify(data)
, {statusCode: 304} ))
@@ -131,10 +131,10 @@ function get_ (uri, timeout, cache, stat, data, nofollow, staleOk, cb) {
}
if (response) {
- log.silly([response.statusCode, response.headers], "get cb")
+ log.silly("registry.get", "cb", [response.statusCode, response.headers])
if (response.statusCode === 304 && etag) {
remoteData = data
- log.verbose(uri+" from cache", "etag")
+ log.verbose("etag", uri+" from cache")
}
}
diff --git a/lib/utils/npm-registry-client/publish.js b/lib/utils/npm-registry-client/publish.js
index a196a3c07..7df65fa50 100644
--- a/lib/utils/npm-registry-client/publish.js
+++ b/lib/utils/npm-registry-client/publish.js
@@ -7,7 +7,7 @@ var request = require("./request.js")
, DELETE = request.DELETE
, reg = request.reg
, upload = request.upload
- , log = require("../log.js")
+ , log = require("npmlog")
, path = require("path")
, npm = require("../../npm.js")
, url = require("url")
@@ -70,8 +70,9 @@ function publish (data, prebuilt, readme, cb) {
&& !( parsed
&& parsed.reason ===
"must supply latest _rev to update existing package" )) {
- return log.er(cb, "Failed PUT response "
- +(response && response.statusCode))(er)
+ log.error("publish", "Failed PUT response "
+ +(response && response.statusCode))
+ return cb(er)
}
var dataURI = encodeURIComponent(data.name)
+ "/" + encodeURIComponent(data.version)
@@ -88,13 +89,13 @@ function publish (data, prebuilt, readme, cb) {
var exists = fullData.versions && fullData.versions[data.version]
if (exists) {
- log(exists._id, "Already published")
+ log.info("already published", exists._id)
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")
+ log.verbose("upload bindist", needs)
if (!needs.length) return cb(conflictError(data._id))
// attach the needed bindists, upload the new metadata
exists.dist.bin = ebin
@@ -115,7 +116,8 @@ function publish (data, prebuilt, readme, cb) {
if (er.message.indexOf("conflict Document update conflict.") === 0) {
return cb(conflictError(data._id))
}
- return log.er(cb, "Error sending version data")(er)
+ log.error("publish", "Error sending version data")
+ return cb(er)
}
var c = path.resolve(npm.cache, data.name, data.version)
@@ -123,9 +125,9 @@ function publish (data, prebuilt, readme, cb) {
cb = rollbackFailure(data, cb)
- log.verbose([data.name, tb, tbName], "attach 2")
+ log.verbose("publish", "attach 2", [data.name, tb, tbName])
attach(data.name, tb, tbName, function (er) {
- log.verbose([er, data.name, prebuilt, pbName], "attach 3")
+ log.verbose("publish", "attach 3", [er, data.name, prebuilt, pbName])
if (er || !prebuilt) return cb(er)
attach(data.name, prebuilt, pbName, cb)
})
@@ -149,7 +151,7 @@ function attach (doc, file, filename, cb) {
"Attempting to upload to invalid doc "+doc))
var rev = "-rev/"+d._rev
, attURI = doc + "/-/" + encodeURIComponent(filename) + "/" + rev
- log.verbose([attURI, file], "uploading")
+ log.verbose("uploading", [attURI, file])
upload(attURI, file, cb)
})
}
@@ -157,14 +159,14 @@ function attach (doc, file, filename, cb) {
function rollbackFailure (data, cb) { return function (er) {
if (!er) return cb()
npm.ROLLBACK = true
- log.error(er, "publish failed")
- log("rollback", "publish failed")
+ log.error("publish failed", er)
+ log.info("publish failed", "rollback")
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")
+ log.error("rollback failed", er_)
+ log.error( "rollback failed"
+ , "Invalid data in registry! Please report this.")
+ } else log.info("publish failed", "rolled back")
cb(er)
})
}}
diff --git a/lib/utils/npm-registry-client/request.js b/lib/utils/npm-registry-client/request.js
index d5122629d..2ecae9386 100644
--- a/lib/utils/npm-registry-client/request.js
+++ b/lib/utils/npm-registry-client/request.js
@@ -7,7 +7,7 @@ regRequest.upload = upload
var npm = require("../../npm.js")
, url = require("url")
- , log = require("../log.js")
+ , log = require("npmlog")
, fs = require("graceful-fs")
, rm = require("rimraf")
, asyncMap = require("slide").asyncMap
@@ -47,7 +47,7 @@ function regRequest (method, where, what, etag, nofollow, cb_) {
// resolve to a full url on the registry
if (!where.match(/^https?:\/\//)) {
- log.verbose(where, "raw, before any munging")
+ log.verbose("url raw", where)
var q = where.split("?")
where = q.shift()
@@ -62,9 +62,9 @@ function regRequest (method, where, what, etag, nofollow, cb_) {
return encodeURIComponent(p)
}).join("/")
if (q) where += "?" + q
- log.verbose([registry, where], "url resolving")
+ log.verbose("url resolving", [registry, where])
where = url.resolve(registry, where)
- log.verbose(where, "url resolved")
+ log.verbose("url resolved", where)
}
var remote = url.parse(where)
@@ -88,7 +88,7 @@ function makeRequest (method, remote, where, what, etag, nofollow, cb) {
, strictSSL: npm.config.get("strict-ssl") }
, headers = opts.headers = {}
if (etag) {
- log.verbose(etag, "etag")
+ log.verbose("etag", etag)
headers[method === "GET" ? "if-none-match" : "if-match"] = etag
}
@@ -118,7 +118,7 @@ function makeRequest (method, remote, where, what, etag, nofollow, cb) {
opts.followRedirect = false
}
- log.http(remote.href || "/", method)
+ log.http(method, remote.href || "/")
var req = request(opts, requestDone(method, where, cb))
var r = npm.config.get("registry")
@@ -137,7 +137,7 @@ function makeRequest (method, remote, where, what, etag, nofollow, cb) {
function requestDone (method, where, cb) { return function (er, response, data) {
if (er) return cb(er)
- log.http(response.statusCode + " " + url.parse(where).href)
+ log.http(response.statusCode, url.parse(where).href)
var parsed
@@ -150,8 +150,8 @@ function requestDone (method, where, cb) { return function (er, response, data)
parsed = JSON.parse(data)
} catch (ex) {
ex.message += "\n" + data
- log.verbose(data, "bad json")
- log.error("error parsing json", "registry")
+ log.verbose("bad json", data)
+ log.error("registry", "error parsing json")
return cb(ex, null, data, response)
}
} else if (data) {
diff --git a/lib/utils/npm-registry-client/star.js b/lib/utils/npm-registry-client/star.js
index 474a1786d..eeaca14ef 100644
--- a/lib/utils/npm-registry-client/star.js
+++ b/lib/utils/npm-registry-client/star.js
@@ -4,7 +4,7 @@ module.exports = star
var request = require("./request.js")
, GET = request.GET
, PUT = request.PUT
- , log = require("../log.js")
+ , log = require("npmlog")
, npm = require("../../npm.js")
function star (package, starred, cb) {
@@ -20,11 +20,11 @@ function star (package, starred, cb) {
if (starred) {
log.info("starring", fullData._id)
fullData.users[npm.config.get("username")] = true
- log.verbose(fullData)
+ log.verbose("starring", fullData)
} else {
delete fullData.users[npm.config.get("username")]
log.info("unstarring", fullData._id)
- log.verbose(fullData)
+ log.verbose("unstarring", fullData)
}
return PUT(package, fullData, cb)
diff --git a/lib/utils/npm-registry-client/unpublish.js b/lib/utils/npm-registry-client/unpublish.js
index 0c7c44991..4e4982c6b 100644
--- a/lib/utils/npm-registry-client/unpublish.js
+++ b/lib/utils/npm-registry-client/unpublish.js
@@ -8,7 +8,7 @@
module.exports = unpublish
var request = require("./request.js")
- , log = require("../log.js")
+ , log = require("npmlog")
, get = require("./get.js")
, semver = require("semver")
, url = require("url")
@@ -20,26 +20,29 @@ function unpublish (name, ver, cb) {
"Not enough arguments for registry unpublish")
get(name, null, -1, true, function (er, data) {
- if (er) return log(name+" not published", "unpublish", cb)
+ if (er) {
+ log.info("unpublish", name+" not published")
+ return cb()
+ }
// remove all if no version specified
if (!ver) {
- log("No version specified, removing all", "unpublish")
+ log.info("unpublish", "No version specified, removing all")
return request("DELETE", name+'/-rev/'+data._rev, cb)
}
var versions = data.versions || {}
, versionPublic = versions.hasOwnProperty(ver)
- if (!versionPublic) log(name+"@"+ver+" not published", "unpublish")
+ if (!versionPublic) log.info("unpublish", name+"@"+ver+" not published")
else {
var dist = versions[ver].dist
- log.verbose(dist, "removing attachments")
+ log.verbose("unpublish", "removing attachments", dist)
}
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")
+ log.info("unpublish", "No versions remain, removing entire package")
return request("DELETE", name+"/-rev/"+data._rev, cb)
}
@@ -58,9 +61,13 @@ function unpublish (name, ver, cb) {
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"))
+ var cb_ = detacher(data, dist, cb)
+ request.PUT(name+"/-rev/"+rev, data, function (er) {
+ if (er) {
+ log.error("unpublish", "Failed to update data")
+ }
+ cb_(er)
+ })
})
}
@@ -86,7 +93,7 @@ function detacher (data, dist, cb) { return function (er) {
function detach (data, path, rev, cb) {
if (rev) {
path += "/-rev/" + rev
- log(path, "detach")
+ log.info("detach", path)
return request("DELETE", path, cb)
}
get(data.name, function (er, data) {
diff --git a/lib/utils/read-installed.js b/lib/utils/read-installed.js
index ff220943d..d298f1c86 100644
--- a/lib/utils/read-installed.js
+++ b/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
@@ -259,17 +259,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/lib/utils/read-json.js b/lib/utils/read-json.js
index d1bba10f5..68153ab21 100644
--- a/lib/utils/read-json.js
+++ b/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,7 +17,7 @@ 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])
}
opts.file = jsonFile
@@ -180,8 +180,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)
}
@@ -209,7 +208,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 +234,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 +258,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 +268,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 +309,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 +334,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
}
@@ -361,7 +360,7 @@ function processObject (opts, cb) { return function (er, json) {
// 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 +369,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 +459,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 +521,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/lib/utils/sha.js b/lib/utils/sha.js
index 17b8c38f9..d3cd83a93 100644
--- a/lib/utils/sha.js
+++ b/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/lib/utils/tar.js b/lib/utils/tar.js
index 76ef6ea92..22a4a852c 100644
--- a/lib/utils/tar.js
+++ b/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/lib/version.js b/lib/version.js
index febb56d73..35329760e 100644
--- a/lib/version.js
+++ b/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/lib/view.js b/lib/view.js
index 33a5d0df8..646b6377f 100644
--- a/lib/view.js
+++ b/lib/view.js
@@ -41,7 +41,7 @@ view.completion = function (opts, cb) {
var registry = require("./utils/npm-registry-client/index.js")
, ini = require("ini")
- , log = require("./utils/log.js")
+ , log = require("npmlog")
, util = require("util")
, output
, npm = require("./npm.js")
@@ -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/lib/whoami.js b/lib/whoami.js
index c48f04b1d..b6e495253 100644
--- a/lib/whoami.js
+++ b/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/lib/xmas.js b/lib/xmas.js
index 90282d0f7..bf838a87a 100644
--- a/lib/xmas.js
+++ b/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 () {