summaryrefslogtreecommitdiff
path: root/deps/npm/lib
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2011-11-30 16:45:26 -0800
committerBen Noordhuis <info@bnoordhuis.nl>2011-12-01 21:12:17 +0100
commit61764613d1b7b54788c3954735cbbdcb078e295d (patch)
tree349595a49371e1bb53244221ff0536ffed988377 /deps/npm/lib
parentd5feb1c280d0b14fa8ef116dd02ce1a243b81869 (diff)
downloadnode-new-61764613d1b7b54788c3954735cbbdcb078e295d.tar.gz
npm 1.1.0-alpha-5
Fix #2186 First part of #2207
Diffstat (limited to 'deps/npm/lib')
-rw-r--r--deps/npm/lib/cache.js3
-rw-r--r--deps/npm/lib/help.js8
-rw-r--r--deps/npm/lib/utils/config-defs.js21
-rw-r--r--deps/npm/lib/utils/ini.js82
-rw-r--r--deps/npm/lib/utils/read-json.js2
-rw-r--r--deps/npm/lib/utils/tar.js25
6 files changed, 100 insertions, 41 deletions
diff --git a/deps/npm/lib/cache.js b/deps/npm/lib/cache.js
index bde72c4f95..7260ab61a3 100644
--- a/deps/npm/lib/cache.js
+++ b/deps/npm/lib/cache.js
@@ -490,7 +490,8 @@ function addLocal (p, name, cb_) {
if (er) {
// if it doesn't have a / in it, it might be a
// remote thing.
- if (p.indexOf("/") === -1 && p.charAt(0) !== ".") {
+ if (p.indexOf("/") === -1 && p.charAt(0) !== "."
+ && (process.platform !== "win32" || p.indexOf("\\") === -1)) {
return addNamed(p, "", cb_)
}
return log.er(cb_, "Could not install: "+p)(er)
diff --git a/deps/npm/lib/help.js b/deps/npm/lib/help.js
index 854a7d6bab..442f839b3a 100644
--- a/deps/npm/lib/help.js
+++ b/deps/npm/lib/help.js
@@ -26,7 +26,7 @@ function help (args, cb) {
return npm.commands["help-search"](args, num, cb)
}
- var section = args[0]
+ var section = npm.deref(args[0]) || args[0]
if (section) {
if ( npm.config.get("usage")
@@ -36,6 +36,7 @@ function help (args, cb) {
npm.config.set("loglevel", "silent")
return output.write(npm.commands[section].usage, cb)
}
+
var sectionPath = path.join( __dirname, "..", "man", "man" + num
, section + "." + num)
, htmlPath = path.resolve( __dirname, "..", "html"
@@ -53,11 +54,13 @@ function help (args, cb) {
})
env.MANPATH = manpath
var viewer = npm.config.get("viewer")
+
switch (viewer) {
case "woman":
var a = ["-e", "(woman-find-file \"" + sectionPath + "\")"]
exec("emacsclient", a, env, true, cb)
break
+
case "browser":
var b = npm.config.get("browser")
if (!b) {
@@ -71,6 +74,7 @@ function help (args, cb) {
exec(b, [htmlPath], env, false, function () {})
}
break
+
default:
exec("man", [num, section], env, true, cb)
}
@@ -96,6 +100,8 @@ function help (args, cb) {
, " " + npm.config.get("userconfig")
, "or on the command line via: npm <command> --key value"
, "Config info can be viewed via: npm help config"
+ , ""
+ , "npm@" + npm.version + " " + path.dirname(__dirname)
].join("\n"), function () { cb(er) })
})
}
diff --git a/deps/npm/lib/utils/config-defs.js b/deps/npm/lib/utils/config-defs.js
index 55d5c887de..c0ed1fca88 100644
--- a/deps/npm/lib/utils/config-defs.js
+++ b/deps/npm/lib/utils/config-defs.js
@@ -71,7 +71,10 @@ var temp = process.env.TMPDIR
var home = ( process.platform === "win32"
? process.env.USERPROFILE
- : process.env.HOME ) || temp
+ : process.env.HOME )
+
+if (home) process.env.HOME = home
+else home = temp
var globalPrefix
Object.defineProperty(exports, "defaults", {get: function () {
@@ -133,9 +136,10 @@ Object.defineProperty(exports, "defaults", {get: function () {
"ZNufy1Jf1r0ldEGeA+0ISck7s+xSh9rQD2Op\n"+
"-----END CERTIFICATE-----\n"
- , cache : path.resolve( home || temp
- , process.platform === "win32"
- ? "npm-cache" : ".npm")
+ , cache : process.platform === "win32"
+ ? path.resolve(process.env.APPDATA || home || temp, "npm-cache")
+ : path.resolve( home || temp, ".npm")
+
, color : process.platform !== "win32" || winColor
, depth: Infinity
, description : true
@@ -144,9 +148,8 @@ Object.defineProperty(exports, "defaults", {get: function () {
( process.platform === "win32" ? "notepad" : "vi" )
, force : false
, global : false
- , globalconfig : path.resolve(process.execPath, "..", "..", "etc", "npmrc")
- , globalignorefile : path.resolve( process.execPath
- , "..", "..", "etc", "npmignore")
+ , globalconfig : path.resolve(globalPrefix, "etc", "npmrc")
+ , globalignorefile : path.resolve( globalPrefix, "etc", "npmignore")
, group : process.platform === "win32" ? 0
: process.env.SUDO_GID || (process.getgid && process.getgid())
, ignore: ""
@@ -169,6 +172,7 @@ Object.defineProperty(exports, "defaults", {get: function () {
, pre: false
, prefix : globalPrefix
, production: false
+ , "proprietary-attribs": true
, proxy : process.env.HTTP_PROXY || process.env.http_proxy || null
, "https-proxy" : process.env.HTTPS_PROXY || process.env.https_proxy ||
process.env.HTTP_PROXY || process.env.http_proxy || null
@@ -178,7 +182,7 @@ Object.defineProperty(exports, "defaults", {get: function () {
, save : false
, searchopts: ""
, searchexclude: null
- , shell : process.env.platform === "win32"
+ , shell : process.platform === "win32"
? process.env.ComSpec || "cmd"
: process.env.SHELL || "bash"
, "strict-ssl": true
@@ -242,6 +246,7 @@ exports.types =
, pre: Boolean
, prefix: path
, production: Boolean
+ , "proprietary-attribs": Boolean
, proxy : [null, url]
, "rebuild-bundle" : Boolean
, registry : [null, url]
diff --git a/deps/npm/lib/utils/ini.js b/deps/npm/lib/utils/ini.js
index f31bdeb790..85aa28d23b 100644
--- a/deps/npm/lib/utils/ini.js
+++ b/deps/npm/lib/utils/ini.js
@@ -30,6 +30,8 @@ Object.defineProperty(exports, "keys",
{ get : function () { return configList.keys }})
var fs = require("graceful-fs")
+ , fstream = require("fstream")
+ , rimraf = require("rimraf")
, path = require("path")
, nopt = require("nopt")
, ini = require("ini")
@@ -42,11 +44,13 @@ var fs = require("graceful-fs")
? process.env.SUDO_UID : (process.getuid && process.getuid())
, myGid = process.env.SUDO_GID !== undefined
? process.env.SUDO_GID : (process.getgid && process.getgid())
+
, eol = process.platform === "win32" ? "\r\n" : "\n"
, privateKey = null
, defaultConfig
, configList = new ProtoList()
, types = configDefs.types
+
, TRANS = exports.TRANS =
{ "default" : 5
, "builtin": 4
@@ -83,14 +87,33 @@ function resolveConfigs (cli, cb_) {
})
cl.push(cli)
cl.push(parseEnv(process.env))
+
parseFile(cl.get("userconfig") || dc.userconfig, function (er, conf) {
if (er) return cb(er)
cl.push(conf)
+
+ // globalconfig and globalignorefile defaults
+ // need to respond to the "prefix" setting up to this point.
+ // Eg, `npm config get globalconfig --prefix ~/local` should
+ // return `~/local/etc/npmrc`
+ if (cl.get("prefix")) {
+ dc.globalconfig = path.resolve(cl.get("prefix"), "etc", "npmrc")
+ dc.globalignorefile = path.resolve(cl.get("prefix"), "etc", "npmignore")
+ }
+
parseFile( cl.get("globalconfig") || dc.globalconfig
, function (er, conf) {
if (er) return cb(er)
+
+ if (conf.hasOwnProperty("prefix")) {
+ log.warn("Cannot set prefix in globalconfig file"
+ , cl.get("globalconfig"))
+ delete conf.prefix
+ }
+
cl.push(conf)
// the builtin config file, for distros to use.
+
parseFile(path.resolve(__dirname, "../../npmrc"), function (er, conf) {
if (er) conf = {}
cl.push(conf)
@@ -176,12 +199,14 @@ function parseField (f, k, emptyIsFalse) {
case "null": return null
case "undefined": return undefined
}
+
if (isPath) {
if (f.substr(0, 2) === "~/" && process.env.HOME) {
f = path.resolve(process.env.HOME, f.substr(2))
}
f = path.resolve(f)
}
+
return f
}
@@ -272,36 +297,28 @@ function saveConfigfile (file, config, which, cb) {
data = ini.stringify(data)
return (data.trim())
? writeConfigfile(file, data, which, cb)
- : rmConfigfile(file, cb)
+ : rimraf(file, cb)
})
}
+
function writeConfigfile (configfile, data, which, cb) {
data = data.split(/\r*\n/).join(eol)
- fs.writeFile
- ( configfile, data, "utf8"
- , function (er) {
- if (er) log(er, "Failed saving "+configfile, cb)
- else if (which) {
- fs.chmod(configfile, which === "user" ? 0600 : 0644, function (e) {
- if (e || which !== "user" || typeof myUid !== "number") {
- return cb(e)
- }
- fs.chown(configfile, +myUid, +myGid, cb)
- })
- }
- else cb()
- }
- )
-}
-function rmConfigfile (configfile, cb) {
- fs.stat(configfile, function (e) {
- if (e) return cb()
- fs.unlink(configfile, function (er) {
- if (er) log(er, "Couldn't remove "+configfile)
- cb()
- })
- })
+ var props = { type: "File", path: configfile }
+ if (which === "user") {
+ props.mode = 0600
+ if (typeof myUid === "number") {
+ props.uid = +myUid
+ props.gid = +myGid
+ }
+ } else {
+ props.mode = 0644
+ }
+ fstream.Writer(props)
+ .on("close", cb)
+ .on("error", cb)
+ .end(data)
}
+
function snapshot (which) {
var x = (!which) ? configList.snapshot
: configList.list[TRANS[which]] ? configList.list[TRANS[which]]
@@ -312,10 +329,21 @@ function snapshot (which) {
}
function get (key, which) {
return (!key) ? snapshot(which)
- : (!which) ? configList.get(key) // resolved
- : configList.list[TRANS[which]] ? configList.list[TRANS[which]][key]
+ : (!which) ? envReplace(configList.get(key)) // resolved
+ : configList.list[TRANS[which]]
+ ? envReplace(configList.list[TRANS[which]][key])
: undefined
}
+
+function envReplace (f) {
+ if (typeof f !== "string" || !f) return f
+
+ // replace any ${ENV} values with the appropriate environ.
+ return f.replace(/\$\{([^}]+)\}/g, function (orig, name, i, s) {
+ return process.env[name] || orig
+ })
+}
+
function del (key, which) {
if (!which) configList.list.forEach(function (l) {
delete l[key]
diff --git a/deps/npm/lib/utils/read-json.js b/deps/npm/lib/utils/read-json.js
index e71128c1b1..68e5c25641 100644
--- a/deps/npm/lib/utils/read-json.js
+++ b/deps/npm/lib/utils/read-json.js
@@ -304,7 +304,7 @@ function processObject (opts, cb) { return function (er, json) {
log.verbose([json.prebuilt, opts], "has wscript")
if (!scripts.install && !scripts.preinstall) {
// don't fail if it was unexpected, just try.
- scripts.preinstall = "node-waf clean || true; node-waf configure build"
+ scripts.preinstall = "node-waf clean || (exit 0); node-waf configure build"
json.scripts = scripts
}
}
diff --git a/deps/npm/lib/utils/tar.js b/deps/npm/lib/utils/tar.js
index 9d5f05210f..1fe705377e 100644
--- a/deps/npm/lib/utils/tar.js
+++ b/deps/npm/lib/utils/tar.js
@@ -45,6 +45,7 @@ function pack (targetTarball, folder, pkg, dfc, cb) {
log.silly(folder, "makeList")
makeList(folder, pkg, dfc, function (er, files, cleanup) {
if (er) return cb(er)
+ // log.silly(files, "files")
return packFiles(targetTarball, parent, files, pkg, function (er) {
if (!cleanup || !cleanup.length) return cb(er)
// try to be a good citizen, even/especially in the event of failure.
@@ -59,7 +60,7 @@ function pack (targetTarball, folder, pkg, dfc, cb) {
})
}
-function packFiles (targetTarball, parent, files, pkg, cb) {
+function packFiles (targetTarball, parent, files, pkg, cb_) {
var p
@@ -70,16 +71,33 @@ function packFiles (targetTarball, parent, files, pkg, cb) {
parent = path.resolve(parent, p)
+ var called = false
+ function cb (er) {
+ if (called) return
+ called = true
+ cb_(er)
+ }
+
log.verbose(targetTarball, "tarball")
log.verbose(parent, "parent")
fstream.Reader({ type: "Directory"
, path: parent
, filter: function () {
+ // files should *always* get into tarballs
+ // in a user-writable state, even if they're
+ // being installed from some wackey vm-mounted
+ // read-only filesystem.
+ this.props.mode = this.props.mode | 0200
return -1 !== files.indexOf(this.path)
}
})
.on("error", log.er(cb, "error reading "+parent))
- .pipe(tar.Pack())
+ // By default, npm includes some proprietary attributes in the
+ // package tarball. This is sane, and allowed by the spec.
+ // However, npm *itself* excludes these from its own package,
+ // 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))
.pipe(zlib.Gzip())
.on("error", log.er(cb, "gzip error "+targetTarball))
@@ -276,7 +294,8 @@ function makeList (dir, pkg, dfc, cb) {
makeList_(dir, pkg, exList, dfc, function (er, files, cleanup) {
if (er) return cb(er)
- var dirLen = dir.length + 1
+ var dirLen = dir.replace(/(\/|\\)$/, "").length + 1
+ log.silly([dir, dirLen], "dir, dirLen")
files = files.map(function (file) {
return path.join(name, file.substr(dirLen))
})