diff options
author | isaacs <i@izs.me> | 2011-10-15 01:04:56 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2011-10-15 01:06:12 +0400 |
commit | 4eb8f6b7bfced57ce8415e98a632af5c5317011c (patch) | |
tree | 68ae609781fc65140b5e6f36f62abf8159ebc5ef /lib | |
parent | f2b9b5dd5b02625cf26c2050916a422650ce3e99 (diff) |
Avoid accidentally opening npm.js with WSH
Diffstat (limited to 'lib')
65 files changed, 468 insertions, 70 deletions
diff --git a/lib/adduser.js b/lib/adduser.js index b52e2a2bf..b6d08ed76 100644 --- a/lib/adduser.js +++ b/lib/adduser.js @@ -4,7 +4,7 @@ module.exports = adduser var registry = require("./utils/npm-registry-client/index.js") , ini = require("./utils/ini.js") , log = require("./utils/log.js") - , npm = require("../npm.js") + , npm = require("./npm.js") , prompt = require("./utils/prompt.js") , promiseChain = require("./utils/promise-chain.js") , crypto diff --git a/lib/bin.js b/lib/bin.js index a2753c127..46535564d 100644 --- a/lib/bin.js +++ b/lib/bin.js @@ -1,6 +1,6 @@ module.exports = bin -var npm = require("../npm.js") +var npm = require("./npm.js") , output = require("./utils/output.js") bin.usage = "npm bin\nnpm bin -g\n(just prints the bin folder)" diff --git a/lib/bugs.js b/lib/bugs.js index 654f4487b..1c52ffda0 100644 --- a/lib/bugs.js +++ b/lib/bugs.js @@ -12,7 +12,7 @@ bugs.completion = function (opts, cb) { var exec = require("./utils/exec.js") , registry = require("./utils/npm-registry-client/index.js") - , npm = require("../npm.js") + , npm = require("./npm.js") , log = require("./utils/log.js") function bugs (args, cb) { diff --git a/lib/build.js b/lib/build.js index 00e03af5a..6e99caa15 100644 --- a/lib/build.js +++ b/lib/build.js @@ -8,7 +8,7 @@ // This runs AFTER install or link are completed. -var npm = require("../npm.js") +var npm = require("./npm.js") , log = require("./utils/log.js") , chain = require("slide").chain , fs = require("graceful-fs") diff --git a/lib/cache.js b/lib/cache.js index 09dd67ede..01d9aab60 100644 --- a/lib/cache.js +++ b/lib/cache.js @@ -34,7 +34,7 @@ exports.unpack = unpack var mkdir = require("./utils/mkdir-p.js") , exec = require("./utils/exec.js") , fetch = require("./utils/fetch.js") - , npm = require("../npm.js") + , npm = require("./npm.js") , fs = require("graceful-fs") , rm = require("rimraf") , readJson = require("./utils/read-json.js") diff --git a/lib/completion.js b/lib/completion.js index 5ff765a08..bc97bf1af 100644 --- a/lib/completion.js +++ b/lib/completion.js @@ -15,7 +15,7 @@ var output = require("./utils/output.js") }) , shorthandNames = Object.keys(shorthands) , allConfs = configNames.concat(shorthandNames) - , npm = require("../npm.js") + , npm = require("./npm.js") completion.completion = function (opts, cb) { if (opts.w > 3) return cb() diff --git a/lib/config.js b/lib/config.js index 8e5408100..6781679f1 100644 --- a/lib/config.js +++ b/lib/config.js @@ -9,7 +9,7 @@ config.usage = "npm config set <key> <value>" var ini = require("./utils/ini.js") , log = require("./utils/log.js") - , npm = require("../npm.js") + , npm = require("./npm.js") , exec = require("./utils/exec.js") , fs = require("graceful-fs") , dc diff --git a/lib/deprecate.js b/lib/deprecate.js index 28c7e831f..6f18879e4 100644 --- a/lib/deprecate.js +++ b/lib/deprecate.js @@ -21,7 +21,7 @@ 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") + , npm = require("./npm.js") function deprecate (args, cb) { var pkg = args[0] diff --git a/lib/docs.js b/lib/docs.js index 28db94914..de9f71c65 100644 --- a/lib/docs.js +++ b/lib/docs.js @@ -12,7 +12,7 @@ docs.completion = function (opts, cb) { var exec = require("./utils/exec.js") , registry = require("./utils/npm-registry-client/index.js") - , npm = require("../npm.js") + , npm = require("./npm.js") , log = require("./utils/log.js") function docs (args, cb) { diff --git a/lib/edit.js b/lib/edit.js index f8f3b9a89..df103d4df 100644 --- a/lib/edit.js +++ b/lib/edit.js @@ -6,7 +6,7 @@ edit.usage = "npm edit <pkg>" edit.completion = require("./utils/completion/installed-shallow.js") -var npm = require("../npm.js") +var npm = require("./npm.js") , exec = require("./utils/exec.js") , path = require("path") , fs = require("graceful-fs") diff --git a/lib/explore.js b/lib/explore.js index aa6178186..8392c9172 100644 --- a/lib/explore.js +++ b/lib/explore.js @@ -5,7 +5,7 @@ module.exports = explore explore.usage = "npm explore <pkg> [ -- <cmd>]" explore.completion = require("./utils/completion/installed-shallow.js") -var npm = require("../npm.js") +var npm = require("./npm.js") , exec = require("./utils/exec.js") , path = require("path") , fs = require("graceful-fs") diff --git a/lib/faq.js b/lib/faq.js index 32df1e252..912db0072 100644 --- a/lib/faq.js +++ b/lib/faq.js @@ -3,6 +3,6 @@ module.exports = faq faq.usage = "npm faq" -var npm = require("../npm.js") +var npm = require("./npm.js") function faq (args, cb) { npm.commands.help(["faq"], cb) } diff --git a/lib/get.js b/lib/get.js index 8d445ff27..aa058002e 100644 --- a/lib/get.js +++ b/lib/get.js @@ -3,7 +3,7 @@ module.exports = get get.usage = "npm get <key> <value> (See `npm config`)" -var npm = require("../npm.js") +var npm = require("./npm.js") get.completion = npm.commands.config.completion diff --git a/lib/help-search.js b/lib/help-search.js index f35b6eee8..a4ef667c0 100644 --- a/lib/help-search.js +++ b/lib/help-search.js @@ -8,7 +8,7 @@ var fs = require("graceful-fs") , cliDocsPath = path.join(__dirname, "..", "doc", "cli") , apiDocsPath = path.join(__dirname, "..", "doc", "api") , log = require("./utils/log.js") - , npm = require("../npm.js") + , npm = require("./npm.js") helpSearch.usage = "npm help-search <text>" diff --git a/lib/help.js b/lib/help.js index d1e56ff3f..854a7d6ba 100644 --- a/lib/help.js +++ b/lib/help.js @@ -11,7 +11,7 @@ help.completion = function (opts, cb) { var fs = require("graceful-fs") , path = require("path") , exec = require("./utils/exec.js") - , npm = require("../npm.js") + , npm = require("./npm.js") , output = require("./utils/output.js") , log = require("./utils/log.js") diff --git a/lib/init.js b/lib/init.js index 26b9f8415..b3e61b291 100644 --- a/lib/init.js +++ b/lib/init.js @@ -11,7 +11,7 @@ var prompt = require("./utils/prompt.js") , exec = require("./utils/exec.js") , semver = require("semver") , log = require("./utils/log.js") - , npm = require("../npm.js") + , npm = require("./npm.js") , output = require("./utils/output.js") init.usage = "npm init [folder]" diff --git a/lib/install.js b/lib/install.js index 01eb1a983..9b0bde6c0 100644 --- a/lib/install.js +++ b/lib/install.js @@ -52,7 +52,7 @@ install.completion = function (opts, cb) { }) } -var npm = require("../npm.js") +var npm = require("./npm.js") , semver = require("semver") , readJson = require("./utils/read-json.js") , log = require("./utils/log.js") diff --git a/lib/link.js b/lib/link.js index 1115bc49c..a1df2449b 100644 --- a/lib/link.js +++ b/lib/link.js @@ -2,7 +2,7 @@ // link with no args: symlink the folder to the global location // link with package arg: symlink the global to the local -var npm = require("../npm.js") +var npm = require("./npm.js") , symlink = require("./utils/link.js") , fs = require("graceful-fs") , log = require("./utils/log.js") @@ -7,7 +7,7 @@ module.exports = exports = ls -var npm = require("../npm.js") +var npm = require("./npm.js") , readInstalled = require("./utils/read-installed.js") , output = require("./utils/output.js") , log = require("./utils/log.js") diff --git a/lib/npm.js b/lib/npm.js new file mode 100644 index 000000000..d40b85ca4 --- /dev/null +++ b/lib/npm.js @@ -0,0 +1,397 @@ +;(function(){ +// windows: running "npm blah" in this folder will invoke WSH, not node. +if (typeof WScript !== "undefined") { + WScript.echo("npm does not work when run\n" + +"with the Windows Scripting Host\n\n" + +"'cd' to a different directory,\n" + +"or type 'npm.cmd <args>',\n" + +"or type 'node npm <args>'.") + WScript.quit(1) + return +} + + +process.title = "npm" + + +// FIXME there really ought to be a path.split in node core +require("path").SPLIT_CHAR = process.platform === "win32" ? "\\" : "/" + +var EventEmitter = require("events").EventEmitter + , npm = module.exports = new EventEmitter + , config = require("./config.js") + , set = require("./utils/set.js") + , get = require("./utils/get.js") + , ini = require("./utils/ini.js") + , log = require("./utils/log.js") + , fs = require("graceful-fs") + , path = require("path") + , abbrev = require("abbrev") + , which = require("which") + , semver = require("semver") + , findPrefix = require("./utils/find-prefix.js") + , getUid = require("./utils/uid-number.js") + , mkdir = require("./utils/mkdir-p.js") + +npm.commands = {} +npm.ELIFECYCLE = {} +npm.E404 = {} +npm.EPUBLISHCONFLICT = {} +npm.EJSONPARSE = {} +npm.EISGIT = {} +npm.ECYCLE = {} +npm.ENOTSUP = {} + +// HACK for windows +if (process.platform === "win32") { + // stub in unavailable methods from process and fs binding + if (!process.getuid) process.getuid = function() {} + if (!process.getgid) process.getgid = function() {} + var fsBinding = process.binding("fs") + if (!fsBinding.chown) fsBinding.chown = function() { + var cb = arguments[arguments.length - 1] + if (typeof cb == "function") cb() + } + + // patch rename/renameSync, but this should really be fixed in node + var _fsRename = fs.rename + , _fsPathPatch + _fsPathPatch = function(p) { + return p && p.replace(/\\/g, "/") || p; + } + fs.rename = function(p1, p2) { + arguments[0] = _fsPathPatch(p1) + arguments[1] = _fsPathPatch(p2) + return _fsRename.apply(fs, arguments); + } +} + +try { + // startup, ok to do this synchronously + var j = JSON.parse(fs.readFileSync( + path.join(__dirname, "../package.json"))+"") + npm.version = j.version + npm.nodeVersionRequired = j.engines.node + if (!semver.satisfies(process.version, j.engines.node)) { + log.error(["" + ,"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") + } +} catch (ex) { + try { + log(ex, "error reading version") + } catch (er) {} + npm.version = ex +} + +var commandCache = {} + // short names for common things + , aliases = { "rm" : "uninstall" + , "r" : "uninstall" + , "un" : "uninstall" + , "unlink" : "uninstall" + , "remove" : "uninstall" + , "rb" : "rebuild" + , "list" : "ls" + , "la" : "ls" + , "ll" : "ls" + , "ln" : "link" + , "i" : "install" + , "up" : "update" + , "c" : "config" + , "info" : "view" + , "show" : "view" + , "find" : "search" + , "s" : "search" + , "se" : "search" + , "author" : "owner" + , "home" : "docs" + , "unstar": "star" // same function + , "apihelp" : "help" + } + + , aliasNames = Object.keys(aliases) + // these are filenames in . + , cmdList = [ "install" + , "uninstall" + , "cache" + , "config" + , "set" + , "get" + , "update" + , "outdated" + , "prune" + , "submodule" + , "pack" + + , "rebuild" + , "link" + + , "publish" + , "star" + , "tag" + , "adduser" + , "unpublish" + , "owner" + , "deprecate" + + , "help" + , "help-search" + , "ls" + , "search" + , "view" + , "init" + , "version" + , "edit" + , "explore" + , "docs" + , "bugs" + , "faq" + , "root" + , "prefix" + , "bin" + , "whoami" + + , "test" + , "stop" + , "start" + , "restart" + , "run-script" + , "completion" + ] + , plumbing = [ "build" + , "unbuild" + , "xmas" + ] + , fullList = npm.fullList = cmdList.concat(aliasNames).filter(function (c) { + return plumbing.indexOf(c) === -1 + }) + , abbrevs = abbrev(fullList) + +Object.keys(abbrevs).concat(plumbing).forEach(function addCommand (c) { + Object.defineProperty(npm.commands, c, { get : function () { + if (!loaded) throw new Error( + "Call npm.load(conf, cb) before using this command.\n"+ + "See the README.md or cli.js for example usage.") + var a = npm.deref(c) + if (c === "la" || c === "ll") { + npm.config.set("long", true) + } + npm.command = c + if (commandCache[a]) return commandCache[a] + var cmd = require(__dirname+"/"+a+".js") + commandCache[a] = function () { + var args = Array.prototype.slice.call(arguments, 0) + if (typeof args[args.length - 1] !== "function") { + args.push(defaultCb) + } + if (args.length === 1) args.unshift([]) + cmd.apply(npm, args) + } + Object.keys(cmd).forEach(function (k) { + commandCache[a][k] = cmd[k] + }) + return commandCache[a] + }, enumerable: fullList.indexOf(c) !== -1 }) + + // make css-case commands callable via camelCase as well + if (c.match(/\-([a-z])/)) { + addCommand(c.replace(/\-([a-z])/g, function (a, b) { + return b.toUpperCase() + })) + } +}) + +function defaultCb (er, data) { + if (er) console.error(er.stack || er.message) + else console.log(data) +} + +npm.deref = function (c) { + if (!c) return "" + if (c.match(/[A-Z]/)) c = c.replace(/([A-Z])/g, function (m) { + return "-" + m.toLowerCase() + }) + if (plumbing.indexOf(c) !== -1) return c + var a = abbrevs[c] + if (aliases[a]) a = aliases[a] + return a +} + +var loaded = false + , loading = false + , loadErr = null + , loadListeners = [] + +function loadCb (er) { + loadListeners.forEach(function (cb) { + process.nextTick(cb.bind(npm, er, npm)) + }) + loadListeners.length = 0 +} + + +npm.load = function (conf, cb_) { + if (!cb_ && typeof conf === "function") cb_ = conf , conf = {} + if (!cb_) cb_ = function () {} + if (!conf) conf = {} + loadListeners.push(cb_) + if (loaded || loadErr) return cb(loadErr) + if (loading) return + loading = true + var onload = true + + function cb (er) { + if (loadErr) return + loaded = true + loadCb(loadErr = er) + if (onload = onload && npm.config.get("onload-script")) { + require(onload) + onload = false + } + } + + log.waitForConfig() + + load(npm, conf, cb) +} + + +function load (npm, conf, cb) { + which(process.argv[0], function (er, node) { + //console.error("back from which") + if (!er && node.toUpperCase() !== process.execPath.toUpperCase()) { + log.verbose("node symlink", node) + process.execPath = node + process.installPrefix = path.resolve(node, "..", "..") + } + + // look up configs + //console.error("about to look up configs") + + ini.resolveConfigs(conf, function (er) { + //console.error("back from config lookup", er && er.stack) + if (er) return cb(er) + + var n = 2 + , errState + + var umask = parseInt(conf.umask, 8) + npm.modes = { exec: 0777 & (~umask) + , file: 0666 & (~umask) + , umask: umask } + + loadPrefix(npm, conf, next) + loadUid(npm, conf, next) + + function next (er) { + //console.error("next", er && er.stack) + if (errState) return + if (er) return cb(errState = er) + if (-- n <= 0) return cb() + } + }) + }) +} + + +function loadPrefix (npm, conf, cb) { + // try to guess at a good node_modules location. + var p + if (!npm.config.get("global") + && !conf.hasOwnProperty("prefix")) { + p = process.cwd() + } else { + p = npm.config.get("prefix") + } + + findPrefix(p, function (er, p) { + //console.log("Back from findPrefix", er && er.stack, p) + Object.defineProperty(npm, "prefix", + { get : function () { return p } + , set : function (r) { return p = r } + , enumerable : true + }) + // the prefix MUST exist, or else nothing works. + mkdir(p, cb) + }) +} + + +function loadUid (npm, conf, cb) { + // if we're not in unsafe-perm mode, then figure out who + // to run stuff as. Do this first, to support `npm update npm -g` + if (!npm.config.get("unsafe-perm")) { + getUid(npm.config.get("user"), npm.config.get("group"), cb) + } else { + //console.error("skipping loadUid") + process.nextTick(cb) + } +} + + +npm.config = + { get : function (key) { return ini.get(key) } + , set : function (key, val) { return ini.set(key, val, "cli") } + , del : function (key, val) { return ini.del(key, val, "cli") } + } + +Object.defineProperty(npm, "dir", + { get : function () { + if (npm.config.get("global")) { + return path.resolve(npm.prefix, "lib", "node_modules") + } else { + return path.resolve(npm.prefix, "node_modules") + } + } + , enumerable : true + }) + +Object.defineProperty(npm, "root", + { get : function () { return npm.dir } }) + +Object.defineProperty(npm, "cache", + { get : function () { return npm.config.get("cache") } + , set : function (r) { return npm.config.set("cache", r) } + , enumerable : true + }) + +var tmpFolder +Object.defineProperty(npm, "tmp", + { get : function () { + if (!tmpFolder) tmpFolder = "npm-"+Date.now() + return path.resolve(npm.config.get("tmp"), tmpFolder) + } + , enumerable : true + }) + +// the better to repl you with +Object.getOwnPropertyNames(npm.commands).forEach(function (n) { + if (npm.hasOwnProperty(n)) return + + Object.defineProperty(npm, n, { get: function () { + return function () { + var args = Array.prototype.slice.call(arguments, 0) + , cb = defaultCb + + if (args.length === 1 && Array.isArray(args[0])) { + args = args[0] + } + + if (typeof args[args.length - 1] === "function") { + cb = args.pop() + } + + npm.commands[n](args, cb) + } + }, enumerable: false, configurable: true }) +}) + +if (require.main === module) { + require("../bin/npm-cli.js") +} +})() diff --git a/lib/outdated.js b/lib/outdated.js index 659e04a74..1d4f62761 100644 --- a/lib/outdated.js +++ b/lib/outdated.js @@ -23,7 +23,7 @@ var path = require("path") , readJson = require("./utils/read-json.js") , cache = require("./cache.js") , asyncMap = require("slide").asyncMap - , npm = require("../npm.js") + , 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 2295bde8e..427965638 100644 --- a/lib/owner.js +++ b/lib/owner.js @@ -69,7 +69,7 @@ var registry = require("./utils/npm-registry-client/index.js") , put = registry.request.PUT , log = require("./utils/log.js") , output - , npm = require("../npm.js") + , npm = require("./npm.js") function owner (args, cb) { var action = args.shift() diff --git a/lib/pack.js b/lib/pack.js index 985186eef..3475c4a3e 100644 --- a/lib/pack.js +++ b/lib/pack.js @@ -4,7 +4,7 @@ module.exports = pack -var npm = require("../npm.js") +var npm = require("./npm.js") , install = require("./install.js") , cache = require("./cache.js") , output = require("./utils/output.js") diff --git a/lib/prefix.js b/lib/prefix.js index d02a6e0bd..f37aacf2c 100644 --- a/lib/prefix.js +++ b/lib/prefix.js @@ -1,6 +1,6 @@ module.exports = prefix -var npm = require("../npm.js") +var npm = require("./npm.js") , output = require("./utils/output.js") prefix.usage = "npm prefix\nnpm prefix -g\n(just prints the prefix folder)" diff --git a/lib/prune.js b/lib/prune.js index 3d659e480..4a02dc1f8 100644 --- a/lib/prune.js +++ b/lib/prune.js @@ -5,7 +5,7 @@ module.exports = prune prune.usage = "npm prune" var readInstalled = require("./utils/read-installed.js") - , npm = require("../npm.js") + , npm = require("./npm.js") prune.completion = require("./utils/completion/installed-deep.js") diff --git a/lib/publish.js b/lib/publish.js index 7a47b73c1..b61a92524 100644 --- a/lib/publish.js +++ b/lib/publish.js @@ -1,7 +1,7 @@ module.exports = publish -var npm = require("../npm.js") +var npm = require("./npm.js") , registry = require("./utils/npm-registry-client/index.js") , log = require("./utils/log.js") , tar = require("./utils/tar.js") diff --git a/lib/rebuild.js b/lib/rebuild.js index f5773583f..f3f759620 100644 --- a/lib/rebuild.js +++ b/lib/rebuild.js @@ -5,7 +5,7 @@ var readInstalled = require("./utils/read-installed.js") , semver = require("semver") , log = require("./utils/log.js") , path = require("path") - , npm = require("../npm.js") + , npm = require("./npm.js") , output = require("./utils/output.js") rebuild.usage = "npm rebuild [<name>[@<version>] [name[@<version>] ...]]" diff --git a/lib/root.js b/lib/root.js index 55b122d79..6062ec220 100644 --- a/lib/root.js +++ b/lib/root.js @@ -1,6 +1,6 @@ module.exports = root -var npm = require("../npm.js") +var npm = require("./npm.js") , output = require("./utils/output.js") , log = require("./utils/log.js") diff --git a/lib/run-script.js b/lib/run-script.js index c00747ca1..4a4d2dc61 100644 --- a/lib/run-script.js +++ b/lib/run-script.js @@ -2,7 +2,7 @@ module.exports = runScript var lifecycle = require("./utils/lifecycle.js") - , npm = require("../npm.js") + , npm = require("./npm.js") , path = require("path") , readJson = require("./utils/read-json.js") , log = require("./utils/log.js") diff --git a/lib/search.js b/lib/search.js index 0e88ee783..da0e06f0d 100644 --- a/lib/search.js +++ b/lib/search.js @@ -1,7 +1,7 @@ module.exports = exports = search -var npm = require("../npm.js") +var npm = require("./npm.js") , registry = require("./utils/npm-registry-client/index.js") , semver = require("semver") , output diff --git a/lib/set.js b/lib/set.js index 1d0fd6d3b..d82109515 100644 --- a/lib/set.js +++ b/lib/set.js @@ -3,7 +3,7 @@ module.exports = set set.usage = "npm set <key> <value> (See `npm config`)" -var npm = require("../npm.js") +var npm = require("./npm.js") set.completion = npm.commands.config.completion diff --git a/lib/star.js b/lib/star.js index 6bb0b5a45..d84fa02ed 100644 --- a/lib/star.js +++ b/lib/star.js @@ -1,7 +1,7 @@ module.exports = star -var npm = require("../npm.js") +var npm = require("./npm.js") , registry = require("./utils/npm-registry-client/index.js") , log = require("./utils/log.js") , asyncMap = require("slide").asyncMap diff --git a/lib/submodule.js b/lib/submodule.js index d90a1de56..92fb41f88 100644 --- a/lib/submodule.js +++ b/lib/submodule.js @@ -4,7 +4,7 @@ module.exports = submodule -var npm = require("../npm.js") +var npm = require("./npm.js") , readJson = require("./utils/read-json.js") , exec = require("./utils/exec.js") , output = require("./utils/output.js") diff --git a/lib/tag.js b/lib/tag.js index fef7b06f6..06aa70c5e 100644 --- a/lib/tag.js +++ b/lib/tag.js @@ -5,7 +5,7 @@ tag.usage = "npm tag <project>@<version> [<tag>]" tag.completion = require("./unpublish.js").completion -var npm = require("../npm.js") +var npm = require("./npm.js") function tag (args, cb) { var thing = (args.shift() || "").split("@") diff --git a/lib/unbuild.js b/lib/unbuild.js index 783765f10..dc3a6a2f5 100644 --- a/lib/unbuild.js +++ b/lib/unbuild.js @@ -3,7 +3,7 @@ unbuild.usage = "npm unbuild <folder>\n(this is plumbing)" var readJson = require("./utils/read-json.js") , rm = require("rimraf") - , npm = require("../npm.js") + , npm = require("./npm.js") , path = require("path") , fs = require("graceful-fs") , lifecycle = require("./utils/lifecycle.js") diff --git a/lib/uninstall.js b/lib/uninstall.js index 9fe465fb9..0d8266009 100644 --- a/lib/uninstall.js +++ b/lib/uninstall.js @@ -12,7 +12,7 @@ var fs = require("graceful-fs") , log = require("./utils/log.js") , readJson = require("./utils/read-json.js") , path = require("path") - , npm = require("../npm.js") + , npm = require("./npm.js") , semver = require("semver") , asyncMap = require("slide").asyncMap diff --git a/lib/unpublish.js b/lib/unpublish.js index 41af591cb..9364aa62e 100644 --- a/lib/unpublish.js +++ b/lib/unpublish.js @@ -3,7 +3,7 @@ module.exports = unpublish var registry = require("./utils/npm-registry-client/index.js") , log = require("./utils/log.js") - , npm = require("../npm.js") + , npm = require("./npm.js") , readJson = require("./utils/read-json.js") , path = require("path") diff --git a/lib/update.js b/lib/update.js index 106e1f5a7..6bb9f3961 100644 --- a/lib/update.js +++ b/lib/update.js @@ -9,7 +9,7 @@ module.exports = update update.usage = "npm update [pkg]" -var npm = require("../npm.js") +var npm = require("./npm.js") , lifecycle = require("./utils/lifecycle.js") , asyncMap = require("slide").asyncMap , log = require("./utils/log.js") diff --git a/lib/utils/cmd-shim.js b/lib/utils/cmd-shim.js index 7d36bcca9..1bd483329 100644 --- a/lib/utils/cmd-shim.js +++ b/lib/utils/cmd-shim.js @@ -19,7 +19,7 @@ var fs = require("graceful-fs") , log = require("./log.js") , path = require("path") , relativize = require("./relativize.js") - , npm = require("../../npm.js") + , npm = require("../npm.js") , shebangExpr = /^#\!(?:\/usr\/bin\/env )?([^ \t]+)(.*)$/ function cmdShimIfExists (from, to, cb) { diff --git a/lib/utils/completion/installed-deep.js b/lib/utils/completion/installed-deep.js index d421ae70e..1188f408f 100644 --- a/lib/utils/completion/installed-deep.js +++ b/lib/utils/completion/installed-deep.js @@ -1,6 +1,6 @@ module.exports = installedDeep -var npm = require("../../../npm.js") +var npm = require("../../npm.js") , readInstalled = require("../read-installed.js") function installedDeep (opts, cb) { diff --git a/lib/utils/completion/installed-shallow.js b/lib/utils/completion/installed-shallow.js index d70c299cb..0cf74917e 100644 --- a/lib/utils/completion/installed-shallow.js +++ b/lib/utils/completion/installed-shallow.js @@ -1,7 +1,7 @@ module.exports = installedShallow -var npm = require("../../../npm.js") +var npm = require("../../npm.js") , fs = require("graceful-fs") , path = require("path") , readJson = require("../read-json.js") diff --git a/lib/utils/error-handler.js b/lib/utils/error-handler.js index 7a8276315..7743de8a5 100644 --- a/lib/utils/error-handler.js +++ b/lib/utils/error-handler.js @@ -3,7 +3,7 @@ module.exports = errorHandler var cbCalled = false , log = require("./log.js") - , npm = require("../../npm.js") + , npm = require("../npm.js") , rm = require("rimraf") , constants = require("constants") , itWorked = false diff --git a/lib/utils/exec.js b/lib/utils/exec.js index 7fa865cd9..0fa0371b2 100644 --- a/lib/utils/exec.js +++ b/lib/utils/exec.js @@ -6,7 +6,7 @@ exec.pipe = pipe var log = require("./log.js") , child_process = require("child_process") , util = require("util") - , npm = require("../../npm.js") + , npm = require("../npm.js") , myUID = process.getuid ? process.getuid() : null , myGID = process.getgid ? process.getgid() : null , isRoot = process.getuid && myUID === 0 diff --git a/lib/utils/fetch.js b/lib/utils/fetch.js index 4fab57d02..726be8848 100644 --- a/lib/utils/fetch.js +++ b/lib/utils/fetch.js @@ -4,7 +4,7 @@ var request = require("request") , fs = require("graceful-fs") - , npm = require("../../npm.js") + , npm = require("../npm.js") , url = require("url") , log = require("./log.js") , path = require("path") diff --git a/lib/utils/find-prefix.js b/lib/utils/find-prefix.js index e7e4e7a86..68f3427e8 100644 --- a/lib/utils/find-prefix.js +++ b/lib/utils/find-prefix.js @@ -4,7 +4,7 @@ module.exports = findPrefix var fs = require("graceful-fs") , path = require("path") - , npm = require("../../npm.js") + , npm = require("../npm.js") function findPrefix (p, cb) { p = path.resolve(p) diff --git a/lib/utils/get-agent.js b/lib/utils/get-agent.js index a05f29e01..b4a5738d2 100644 --- a/lib/utils/get-agent.js +++ b/lib/utils/get-agent.js @@ -9,7 +9,7 @@ module.exports = getAgent -var npm = require("../../npm.js") +var npm = require("../npm.js") , url = require("url") , agents = {} , isHttp2 = !!require("http").globalAgent diff --git a/lib/utils/lifecycle.js b/lib/utils/lifecycle.js index 879ef78c1..878fc88cf 100644 --- a/lib/utils/lifecycle.js +++ b/lib/utils/lifecycle.js @@ -4,7 +4,7 @@ exports.cmd = cmd var log = require("./log.js") , exec = require("./exec.js") - , npm = require("../../npm.js") + , npm = require("../npm.js") , path = require("path") , readJson = require("./read-json.js") , fs = require("graceful-fs") diff --git a/lib/utils/link.js b/lib/utils/link.js index 56d2664d4..9be1221f0 100644 --- a/lib/utils/link.js +++ b/lib/utils/link.js @@ -9,7 +9,7 @@ var fs = require("graceful-fs") , log = require("./log.js") , path = require("path") , relativize = require("./relativize.js") - , npm = require("../../npm.js") + , npm = require("../npm.js") function linkIfExists (from, to, gently, cb) { fs.stat(from, function (er) { diff --git a/lib/utils/load-package-defaults.js b/lib/utils/load-package-defaults.js index a5766a4e1..180507a44 100644 --- a/lib/utils/load-package-defaults.js +++ b/lib/utils/load-package-defaults.js @@ -5,7 +5,7 @@ var path = require("path") , log = require("./log.js") , find = require("./find.js") , asyncMap = require("slide").asyncMap - , npm = require("../../npm.js") + , npm = require("../npm.js") , fs = require("graceful-fs") function loadPackageDefaults (pkg, pkgDir, cb) { diff --git a/lib/utils/log.js b/lib/utils/log.js index 38c36a61c..dece9e3d1 100644 --- a/lib/utils/log.js +++ b/lib/utils/log.js @@ -73,7 +73,7 @@ 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") + , npm = require("../npm.js") , net = require("net") Object.defineProperty(log, "level", diff --git a/lib/utils/mkdir-p.js b/lib/utils/mkdir-p.js index e2a874d1a..645e45d02 100644 --- a/lib/utils/mkdir-p.js +++ b/lib/utils/mkdir-p.js @@ -2,7 +2,7 @@ var log = require("./log.js") , fs = require("graceful-fs") , path = require("path") - , npm = require("../../npm.js") + , npm = require("../npm.js") , exec = require("./exec.js") , uidNumber = require("./uid-number.js") , umask = process.umask() diff --git a/lib/utils/npm-registry-client/adduser.js b/lib/utils/npm-registry-client/adduser.js index 43fd08ad4..5e6794a75 100644 --- a/lib/utils/npm-registry-client/adduser.js +++ b/lib/utils/npm-registry-client/adduser.js @@ -4,7 +4,7 @@ module.exports = adduser var uuid = require("node-uuid") , request = require("./request.js") , log = require("../log.js") - , npm = require("../../../npm.js") + , npm = require("../../npm.js") , crypto try { diff --git a/lib/utils/npm-registry-client/get.js b/lib/utils/npm-registry-client/get.js index 206077c81..062244df3 100644 --- a/lib/utils/npm-registry-client/get.js +++ b/lib/utils/npm-registry-client/get.js @@ -3,7 +3,7 @@ module.exports = get var GET = require("./request.js").GET , fs = require("graceful-fs") - , npm = require("../../../npm.js") + , npm = require("../../npm.js") , path = require("path") , log = require("../log.js") , mkdir = require("../mkdir-p.js") diff --git a/lib/utils/npm-registry-client/publish.js b/lib/utils/npm-registry-client/publish.js index 4584646c3..4500a5071 100644 --- a/lib/utils/npm-registry-client/publish.js +++ b/lib/utils/npm-registry-client/publish.js @@ -9,7 +9,7 @@ var request = require("./request.js") , upload = request.upload , log = require("../log.js") , path = require("path") - , npm = require("../../../npm.js") + , npm = require("../../npm.js") , url = require("url") function publish (data, prebuilt, cb) { diff --git a/lib/utils/npm-registry-client/request.js b/lib/utils/npm-registry-client/request.js index 78f575a08..c80114db8 100644 --- a/lib/utils/npm-registry-client/request.js +++ b/lib/utils/npm-registry-client/request.js @@ -5,7 +5,7 @@ regRequest.PUT = PUT regRequest.reg = reg regRequest.upload = upload -var npm = require("../../../npm.js") +var npm = require("../../npm.js") , url = require("url") , log = require("../log.js") , fs = require("graceful-fs") diff --git a/lib/utils/npm-registry-client/star.js b/lib/utils/npm-registry-client/star.js index 286a933e5..474a1786d 100644 --- a/lib/utils/npm-registry-client/star.js +++ b/lib/utils/npm-registry-client/star.js @@ -5,7 +5,7 @@ var request = require("./request.js") , GET = request.GET , PUT = request.PUT , log = require("../log.js") - , npm = require("../../../npm.js") + , npm = require("../../npm.js") function star (package, starred, cb) { var users = {} diff --git a/lib/utils/output.js b/lib/utils/output.js index 101018a91..00da9f69f 100644 --- a/lib/utils/output.js +++ b/lib/utils/output.js @@ -4,7 +4,7 @@ exports.doColor = doColor exports.write = write -var npm = require("../../npm.js") +var npm = require("../npm.js") , tty = require("tty") , streams = {} , ttys = {} diff --git a/lib/utils/read-installed.js b/lib/utils/read-installed.js index b49ae39de..59fc6c490 100644 --- a/lib/utils/read-installed.js +++ b/lib/utils/read-installed.js @@ -87,7 +87,7 @@ as far as the left-most node_modules folder. */ -var npm = require("../../npm.js") +var npm = require("../npm.js") , fs = require("graceful-fs") , path = require("path") , asyncMap = require("slide").asyncMap diff --git a/lib/utils/read-json.js b/lib/utils/read-json.js index d8a195e88..47682dc74 100644 --- a/lib/utils/read-json.js +++ b/lib/utils/read-json.js @@ -9,7 +9,7 @@ var fs = require("graceful-fs") , semver = require("semver") , path = require("path") , log = require("./log.js") - , npm = require("../../npm.js") + , npm = require("../npm.js") , cache = {} , timers = {} , loadPackageDefaults = require("./load-package-defaults.js") diff --git a/lib/utils/tar.js b/lib/utils/tar.js index 81244c99b..b60b3a427 100644 --- a/lib/utils/tar.js +++ b/lib/utils/tar.js @@ -1,7 +1,7 @@ // commands for packing and unpacking tarballs // this file is used by lib/cache.js -var npm = require("../../npm.js") +var npm = require("../npm.js") , fs = require("graceful-fs") , exec = require("./exec.js") , spawn = exec.spawn diff --git a/lib/utils/uid-number.js b/lib/utils/uid-number.js index ed11ec83f..375627553 100644 --- a/lib/utils/uid-number.js +++ b/lib/utils/uid-number.js @@ -9,7 +9,7 @@ var exec = require("./exec.js") , path = require("path") , log = require("./log.js") , constants = require("constants") - , npm = require("../../npm.js") + , npm = require("../npm.js") , uidSupport = process.getuid && process.setuid , uidCache = {} , gidCache = {} diff --git a/lib/version.js b/lib/version.js index 48e2ff814..2ebd02bc0 100644 --- a/lib/version.js +++ b/lib/version.js @@ -9,7 +9,7 @@ var exec = require("./utils/exec.js") , fs = require("graceful-fs") , chain = require("slide").chain , log = require("./utils/log.js") - , npm = require("../npm.js") + , npm = require("./npm.js") version.usage = "npm version <newversion> [--message commit-message]" + "\n(run in package dir)\n" diff --git a/lib/view.js b/lib/view.js index 266996306..38bb0deee 100644 --- a/lib/view.js +++ b/lib/view.js @@ -44,7 +44,7 @@ var registry = require("./utils/npm-registry-client/index.js") , log = require("./utils/log.js") , util = require("util") , output - , npm = require("../npm.js") + , npm = require("./npm.js") , semver = require("semver") , readJson = require("./utils/read-json.js") diff --git a/lib/whoami.js b/lib/whoami.js index 984e3ad66..c48f04b1d 100644 --- a/lib/whoami.js +++ b/lib/whoami.js @@ -1,6 +1,6 @@ module.exports = whoami -var npm = require("../npm.js") +var npm = require("./npm.js") , output = require("./utils/output.js") , log = require("./utils/log.js") diff --git a/lib/xmas.js b/lib/xmas.js index c039e6de0..90282d0f7 100644 --- a/lib/xmas.js +++ b/lib/xmas.js @@ -1,12 +1,13 @@ // happy xmas -var npm = require("../npm.js") +var npm = require("./npm.js") , log = require("./utils/log.js") module.exports = function (args, cb) { npm.config.set("loglevel", "win") -var s = " \u2605" +var s = process.platform === "win32" ? " *" : " \u2605" , f = "\uFF0F" , b = "\uFF3C" + , x = process.platform === "win32" ? " " : "" , o = [ "\u0069" , "\u0020", "\u0020", "\u0020", "\u0020", "\u0020" , "\u0020", "\u0020", "\u0020", "\u0020", "\u0020", "\u0020" , "\u0020", "\u2E1B","\u2042","\u2E2E","&","@","\uFF61" ] @@ -18,27 +19,27 @@ function w (s) { process.stderr.write(s) } w("\n") ;(function T (H) { for (var i = 0; i < H; i ++) w(" ") - w("\033[33m"+s+"\n") + w(x+"\033[33m"+s+"\n") var M = H * 2 - 1 for (L = 1; L <= H; L ++) { var O = L * 2 - 2 var S = (M - O) / 2 for (var i = 0; i < S; i ++) w(" ") - w("\033[32m"+f) + w(x+"\033[32m"+f) for (var i = 0; i < O; i ++) w( "\033["+oc[Math.floor(Math.random()*oc.length)]+"m"+ o[Math.floor(Math.random() * o.length)] ) - w("\033[32m"+b+"\n") + w(x+"\033[32m"+b+"\n") } w(" ") for (var i = 1; i < H; i ++) w("\033[32m"+l) - w("| |") + w("| "+x+" |") for (var i = 1; i < H; i ++) w("\033[32m"+l) if (H > 10) { w("\n ") for (var i = 1; i < H; i ++) w(" ") - w("| |") + w("| "+x+" |") for (var i = 1; i < H; i ++) w(" ") } })(20) |