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
path: root/lib
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2011-03-11 05:15:57 +0300
committerisaacs <i@izs.me>2011-03-22 01:56:00 +0300
commitb6d75d836555fabb1e4672ec39ff7d8dc2caa939 (patch)
tree7d348ddd4c30861a389cdb547a47c712bde3f99f /lib
parent221c2efd0ed4302d1531cfdec8c131237e09257b (diff)
Terseness. simplify "prefix" config and output cmd.
Diffstat (limited to 'lib')
-rw-r--r--lib/build.js6
-rw-r--r--lib/completion.js3
-rw-r--r--lib/config.js6
-rw-r--r--lib/help.js42
-rw-r--r--lib/install.js2
-rw-r--r--lib/link.js8
-rw-r--r--lib/ls.js6
-rw-r--r--lib/outdated.js7
-rw-r--r--lib/owner.js7
-rw-r--r--lib/prefix.js4
-rw-r--r--lib/prune.js2
-rw-r--r--lib/rebuild.js2
-rw-r--r--lib/root.js4
-rw-r--r--lib/search.js5
-rw-r--r--lib/unbuild.js4
-rw-r--r--lib/utils/default-config.js1
-rw-r--r--lib/utils/log.js2
-rw-r--r--lib/utils/output.js9
-rw-r--r--lib/utils/parse-args.js1
-rw-r--r--lib/view.js7
-rw-r--r--lib/xmas.js3
21 files changed, 62 insertions, 69 deletions
diff --git a/lib/build.js b/lib/build.js
index f49664c2e..e9dcd3b84 100644
--- a/lib/build.js
+++ b/lib/build.js
@@ -42,7 +42,7 @@ function linkStuff (pkg, folder, cb) {
// then bins are in {prefix}/bin
// otherwise, then bins are in folder/../.bin
var parent = path.dirname(folder)
- , gnm = path.resolve(npm.config.get("globalprefix"), "node_modules")
+ , gnm = path.resolve(npm.config.get("prefix"), "node_modules")
, top = gnm === parent
asyncMap([linkBins, linkMans, rebuildBundles], function (fn, cb) {
@@ -79,7 +79,7 @@ function rebuildBundles (pkg, folder, parent, top, cb) {
function linkBins (pkg, folder, parent, top, cb) {
if (!pkg.bin) return cb()
log(pkg.bin, "bins linking")
- var binRoot = top ? path.resolve(npm.config.get("globalprefix"), "bin")
+ var binRoot = top ? path.resolve(npm.config.get("prefix"), "bin")
: path.resolve(parent, ".bin")
asyncMap(Object.keys(pkg.bin), function (b, cb) {
linkIfExists(path.resolve(folder, pkg.bin[b])
@@ -91,7 +91,7 @@ function linkBins (pkg, folder, parent, top, cb) {
function linkMans (pkg, folder, parent, top, cb) {
if (!pkg.man || !top) return cb()
- var manRoot = path.resolve(npm.config.get("globalprefix"), "share", "man")
+ var manRoot = path.resolve(npm.config.get("prefix"), "share", "man")
asyncMap(pkg.man, function (man, cb) {
var parseMan = man.match(/(.*)\.([0-9]+)(\.gz)?$/)
, stem = parseMan[1]
diff --git a/lib/completion.js b/lib/completion.js
index 8a1ba70fc..f1ae8f4c1 100644
--- a/lib/completion.js
+++ b/lib/completion.js
@@ -40,8 +40,7 @@ function completion (args, cb_) {
}
function outputCompletions (list, cb_) {
- var outfd = npm.config.get("outfd")
function cb () { cb_(list.length ? null : "no match found", list) }
//log.warn(list, "completion output")
- output.write(outfd, list, false, cb)
+ output.write(list, npm.config.get("outfd"), false, cb)
}
diff --git a/lib/config.js b/lib/config.js
index 4bfddfb21..b475d69b6 100644
--- a/lib/config.js
+++ b/lib/config.js
@@ -116,17 +116,15 @@ function set (key, val, cb) {
}
function get (key, cb) {
- var outfd = npm.config.get("outfd")
if (!key) return list(cb)
if (key.charAt(0) === "_") {
return cb(new Error("---sekretz---"))
}
- output.write(outfd, npm.config.get(key), cb)
+ output.write(npm.config.get(key), cb)
}
function list (cb) {
var msg = ""
- , outfd = npm.config.get("outfd")
ini.keys.sort(function (a,b) { return a > b ? 1 : -1 })
.forEach(function (i) {
if (parseArgs.types[i] !== parseArgs.types[i]) {
@@ -137,7 +135,7 @@ function list (cb) {
: JSON.stringify(ini.get(i))
msg += i.replace(/^_/,';_')+" = "+val+"\n"
})
- output.write(outfd, msg, cb)
+ output.write(msg, cb)
}
function unknown (action, cb) {
diff --git a/lib/help.js b/lib/help.js
index 11e193be9..c7d81e746 100644
--- a/lib/help.js
+++ b/lib/help.js
@@ -30,7 +30,7 @@ function help (args, cb) {
&& npm.commands[section].usage
) {
npm.config.set("loglevel", "silent")
- return output.write(npm.config.get("outfd"), npm.commands[section].usage, cb)
+ return output.write(npm.commands[section].usage, cb)
}
var section_path = path.join(__dirname, "../man1/"+section+".1")
return fs.stat
@@ -56,26 +56,26 @@ function help (args, cb) {
} else getSections(function (er, sections) {
if (er) return cb(er)
npm.config.set("loglevel", "silent")
- output.write(npm.config.get("outfd"),
- ["\nUsage: npm <command>"
- , ""
- , "where <command> is one of:"
- , " "+wrap(Object.keys(npm.commands))
- , ""
- , "Add -h to any command for quick help."
- , ""
- , "Specify configs in the ini-formatted file at "
- + npm.config.get("userconfig")
- , "or on the command line via: npm <command> --key value"
- , "Config info can be viewed via: npm help config"
- , ""
- , "Help usage: npm help <section>"
- , ""
- , "where <section> is one of:"
- , " " + wrap(sections)
- , ""
- , "Even more help at: npm help help"
- ].join("\n"), function () { cb(er) })
+ output.write
+ ( ["\nUsage: npm <command>"
+ , ""
+ , "where <command> is one of:"
+ , " "+wrap(Object.keys(npm.commands))
+ , ""
+ , "Add -h to any command for quick help."
+ , ""
+ , "Specify configs in the ini-formatted file at "
+ + npm.config.get("userconfig")
+ , "or on the command line via: npm <command> --key value"
+ , "Config info can be viewed via: npm help config"
+ , ""
+ , "Help usage: npm help <section>"
+ , ""
+ , "where <section> is one of:"
+ , " " + wrap(sections)
+ , ""
+ , "Even more help at: npm help help"
+ ].join("\n"), function () { cb(er) })
})
}
diff --git a/lib/install.js b/lib/install.js
index 51f7f5f80..f0645dc30 100644
--- a/lib/install.js
+++ b/lib/install.js
@@ -119,7 +119,7 @@ var npm = require("../npm")
function install (args, cb) {
- var where = npm.config.get("prefix")
+ var where = npm.prefix
// internal api: install(what, where, cb)
if (arguments.length === 3) {
diff --git a/lib/link.js b/lib/link.js
index 0c452c0da..df77e1518 100644
--- a/lib/link.js
+++ b/lib/link.js
@@ -23,11 +23,11 @@ function link (args, cb) {
return cb(new Error("link should never be --global."))
}
if (args.length) return linkInstall(args, cb)
- linkPkg(npm.config.get("prefix"), cb)
+ linkPkg(npm.prefix, cb)
}
function linkInstall (pkgs, cb) {
- var gp = npm.config.get("globalprefix")
+ var gp = npm.config.get("prefix")
asyncMap(pkgs, function (pkg, cb) {
var pp = path.resolve(gp, "node_modules", pkg)
, rp = null
@@ -61,8 +61,8 @@ function linkInstall (pkgs, cb) {
}
function linkPkg (folder, cb) {
- var gp = npm.config.get("globalprefix")
- , me = npm.config.get("prefix")
+ var gp = npm.config.get("prefix")
+ , me = npm.prefix
, target = path.resolve(gp, "node_modules", path.basename(me))
rm(target, function (er) {
if (er) return cb(er)
diff --git a/lib/ls.js b/lib/ls.js
index 5ac3d2af1..5805f8eee 100644
--- a/lib/ls.js
+++ b/lib/ls.js
@@ -23,13 +23,11 @@ ls.completion = function (args, index, cb) {
function ls (args, cb) {
- var dir = npm.config.get("prefix")
+ var dir = npm.prefix
readInstalled(dir, function (er, data) {
if (er) return cb(er)
var long = npm.config.get("long")
- output.write(npm.config.get("outfd")
- ,makePretty(bfsify(data), long, dir).join("\n")
- ,cb)
+ output.write(makePretty(bfsify(data), long, dir).join("\n"), cb)
})
}
diff --git a/lib/outdated.js b/lib/outdated.js
index d101732f0..c0965cc38 100644
--- a/lib/outdated.js
+++ b/lib/outdated.js
@@ -42,16 +42,17 @@ var readInstalled = require("./utils/read-installed")
// for each thing in prefix/node_modules/*
// if there's a newer one, report it
// otherwise, check its children
-var output = require("./utils/output")
+var output
function outdated (args, silent, cb) {
if (typeof cb !== "function") cb = silent, silent = false
- outdated_(npm.config.get("prefix"), args, function (er, list) {
+ outdated_(npm.prefix, args, function (er, list) {
if (er) return cb(er)
if (list.length && !silent) {
var outList = list.map(function (ww) {
return ww[1] + ": "+ww[0] + (ww[2] ? " (currently: "+ww[2]+")":"")
})
- output.write(npm.config.get("outfd"), outList.join("\n"), function (e) {
+ output = ouput || require("./utils/output")
+ output.write(outList.join("\n"), function (e) {
cb(e, list)
})
} else cb(null, list)
diff --git a/lib/owner.js b/lib/owner.js
index 7bd014372..fbd12076e 100644
--- a/lib/owner.js
+++ b/lib/owner.js
@@ -29,7 +29,7 @@ var registry = require("./utils/registry")
, get = registry.request.GET
, put = registry.request.PUT
, log = require("./utils/log")
- , output = require("./utils/output")
+ , output
, npm = require("../npm")
function owner (args, cb) {
@@ -50,9 +50,8 @@ function ls (pkg, cb) {
var owners = data.maintainers
if (!owners || !owners.length) msg = "admin party!"
else msg = owners.map(function (o) { return o.name +" <"+o.email+">" }).join("\n")
- output.write(npm.config.get("outfd"), msg, function (er) {
- cb(er, owners)
- })
+ output = output || require("./utils/output")
+ output.write(msg, function (er) { cb(er, owners) })
})
}
diff --git a/lib/prefix.js b/lib/prefix.js
index aebe1993a..61a71092d 100644
--- a/lib/prefix.js
+++ b/lib/prefix.js
@@ -3,6 +3,4 @@ module.exports = prefix
var npm = require("../npm")
, output = require("./utils/output")
-function prefix (args, cb) {
- output.write(npm.config.get("outfd"), npm.prefix, cb)
-}
+function prefix (args, cb) { output.write(npm.prefix, cb) }
diff --git a/lib/prune.js b/lib/prune.js
index 8217c3a1d..a39a7a4f8 100644
--- a/lib/prune.js
+++ b/lib/prune.js
@@ -8,7 +8,7 @@ var readInstalled = require("./utils/read-installed")
, npm = require("../npm")
function prune (args, cb) {
- readInstalled(npm.config.get("prefix"), function (er, data) {
+ readInstalled(npm.prefix, function (er, data) {
if (er) return cb(er)
prune_(args, data, cb)
})
diff --git a/lib/rebuild.js b/lib/rebuild.js
index 9f0299fd4..6ba11680e 100644
--- a/lib/rebuild.js
+++ b/lib/rebuild.js
@@ -16,7 +16,7 @@ rebuild.completion = function (args, index, cb) {
}
function rebuild (args, cb) {
- readInstalled(npm.config.get("prefix"), function (er, data) {
+ readInstalled(npm.prefix, function (er, data) {
if (er) return cb(er)
var set = filter(data, args)
, folders = Object.keys(set)
diff --git a/lib/root.js b/lib/root.js
index 6b06b3593..fbe309d70 100644
--- a/lib/root.js
+++ b/lib/root.js
@@ -3,6 +3,4 @@ module.exports = root
var npm = require("../npm")
, output = require("./utils/output")
-function root (args, cb) {
- output.write(npm.config.get("outfd"), npm.dir, cb)
-}
+function root (args, cb) { output.write(npm.dir, cb) }
diff --git a/lib/search.js b/lib/search.js
index faa663c59..ae205994e 100644
--- a/lib/search.js
+++ b/lib/search.js
@@ -4,7 +4,7 @@ module.exports = exports = search
var npm = require("../npm")
, registry = require("./utils/registry")
, semver = require("semver")
- , output = require("./utils/output")
+ , output
, log = require("./utils/log")
search.usage = "npm search [some search terms ...]"
@@ -60,7 +60,8 @@ function search (args, silent, staleness, cb_) {
if (er) return cb_(er)
function cb (er) { return cb_(er, data) }
if (silent) return cb()
- output.write(npm.config.get("outfd"), prettify(data, args), cb)
+ output = output || require("./utils/output")
+ output.write(prettify(data, args), cb)
})
}
diff --git a/lib/unbuild.js b/lib/unbuild.js
index e4c3a571c..9902e7ff9 100644
--- a/lib/unbuild.js
+++ b/lib/unbuild.js
@@ -45,7 +45,7 @@ function rmStuff (pkg, folder, cb) {
function rmBins (pkg, folder, parent, top, cb) {
if (!pkg.bin) return cb()
- var binRoot = top ? path.resolve(npm.config.get("globalprefix"), "bin")
+ var binRoot = top ? path.resolve(npm.config.get("prefix"), "bin")
: path.resolve(parent, ".bin")
asyncMap(Object.keys(pkg.bin), function (b, cb) {
rm(path.resolve(binRoot, b), folder, cb)
@@ -54,7 +54,7 @@ function rmBins (pkg, folder, parent, top, cb) {
function rmMans (pkg, folder, parent, top, cb) {
if (!pkg.man || !top) return cb()
- var manRoot = path.resolve(npm.config.get("globalprefix"), "share", "man")
+ var manRoot = path.resolve(npm.config.get("prefix"), "share", "man")
asyncMap(pkg.man, function (man, cb) {
var parseMan = man.match(/(.*)\.([0-9]+)(\.gz)?$/)
, stem = parseMan[1]
diff --git a/lib/utils/default-config.js b/lib/utils/default-config.js
index a5794b109..0436c1005 100644
--- a/lib/utils/default-config.js
+++ b/lib/utils/default-config.js
@@ -27,7 +27,6 @@ module.exports =
, force : false
, global : false
, globalconfig : path.resolve(process.execPath, "..", "..", "etc", "npmrc")
- , globalprefix : path.join(process.execPath, "..", "..")
, group : process.env.SUDO_GID || process.getgid()
, gzipbin : process.env.GZIPBIN || "gzip"
, logfd : stdio.stderrFD
diff --git a/lib/utils/log.js b/lib/utils/log.js
index 5c3b8b7c9..413a89d97 100644
--- a/lib/utils/log.js
+++ b/lib/utils/log.js
@@ -157,7 +157,7 @@ npm.on("log", function (logData) {
msg = msg.split(/\n/).join("\n"+pref+" ")
}
msg = pref+" "+msg
- return output.write(logFD, [msg], cb)
+ return output.write(logFD, msg, cb)
})
log.er = function (cb, msg) {
diff --git a/lib/utils/output.js b/lib/utils/output.js
index d24fc2abb..368ba96e5 100644
--- a/lib/utils/output.js
+++ b/lib/utils/output.js
@@ -24,11 +24,15 @@ function isatty (stream) {
return ttys[stream] = stdio.isatty(stream)
}
-function write (stream, args, lf, cb) {
+function write (args, stream, lf, cb) {
+ if (typeof cb !== "function") cb = lf, lf = null
+ if (typeof cb !== "function") cb = stream, stream = npm.config.get("outfd")
+
stream = getStream(stream)
- if (!cb && typeof lf === "function") cb = lf , lf = isatty(stream)
+ if (lf == null) cb = lf , lf = isatty(stream)
if (!stream) return cb && cb()
if (!Array.isArray(args)) args = [args]
+
var msg = ""
, colored = doColor(stream)
args.forEach(function (arg) {
@@ -56,6 +60,7 @@ function write (stream, args, lf, cb) {
if (cb) cb()
return true
}
+
var flushed = stream.write(msg)
if (!cb) return flushed
if (flushed) return cb(), true
diff --git a/lib/utils/parse-args.js b/lib/utils/parse-args.js
index be94c63bb..a84efc198 100644
--- a/lib/utils/parse-args.js
+++ b/lib/utils/parse-args.js
@@ -25,7 +25,6 @@ exports.types =
, force : Boolean
, global : Boolean
, globalconfig : path
- , globalprefix: path
, group : String
, gzipbin : String
, logfd : [Number, Stream]
diff --git a/lib/view.js b/lib/view.js
index f435704d3..9b568291c 100644
--- a/lib/view.js
+++ b/lib/view.js
@@ -36,7 +36,7 @@ var registry = require("./utils/registry")
, ini = require("./utils/ini-parser")
, log = require("./utils/log")
, sys = require("./utils/sys")
- , output = require("./utils/output")
+ , output
, npm = require("../npm")
, semver = require("semver")
, readJson = require("./utils/read-json")
@@ -146,8 +146,7 @@ function search (data, fields, version, title) {
}
function printData (data, cb) {
- var outfd = npm.config.get("outfd")
- , versions = Object.keys(data)
+ var versions = Object.keys(data)
, msg = ""
, showVersions = versions.length > 1
, showFields
@@ -166,7 +165,7 @@ function printData (data, cb) {
msg += (showVersions ? v + " " : "") + (showFields ? f : "") + d + "\n"
})
})
- output.write(outfd, msg, cb_)
+ output.write(msg, cb_)
}
function cleanup (data) {
if (Array.isArray(data)) {
diff --git a/lib/xmas.js b/lib/xmas.js
index 8cde0160d..12d7308bb 100644
--- a/lib/xmas.js
+++ b/lib/xmas.js
@@ -1,6 +1,5 @@
// happy xmas
-var output = require("./utils/output")
- , npm = require("../npm")
+var npm = require("../npm")
, log = require("./utils/log")
module.exports = function (args, cb) {
npm.config.set("loglevel", "win")