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>2010-09-22 03:36:13 +0400
committerisaacs <i@izs.me>2010-09-22 03:36:13 +0400
commit216d89f90312564a6837b716313f504f37700677 (patch)
treecfe7b2c0f092ba237f8bd67adf7264eacb825ed5
parent45a81e307f7a65e5eab3f7885cd2934d2471c550 (diff)
Support "./foo" for root configs, and parse cli with the same logic that ini and env confs go through
-rwxr-xr-xcli.js3
-rw-r--r--lib/utils/ini.js20
2 files changed, 15 insertions, 8 deletions
diff --git a/cli.js b/cli.js
index 02a8f3071..6cc62d010 100755
--- a/cli.js
+++ b/cli.js
@@ -39,9 +39,6 @@ while (arg = argv.shift()) {
if (key === "help") conf[key] = true, key = null
flagsDone = (key === "")
} else if (key) {
- if (arg === "false" || arg === "null") arg = JSON.parse(arg)
- else if ( arg === "undefined" ) arg = undefined
- else if (!isNaN(arg)) arg = +arg
conf[key] = arg
key = null
} else arglist.push(arg)
diff --git a/lib/utils/ini.js b/lib/utils/ini.js
index d17da7a4d..6f2780876 100644
--- a/lib/utils/ini.js
+++ b/lib/utils/ini.js
@@ -55,6 +55,9 @@ function resolveConfigs (cli, cb) {
, dc = cl.pop()
if (!cb) cb = cli, cli = {}
cl.list.length = 0
+ Object.keys(cli).forEach(function (k) {
+ cli[k] = parseField(cli[k], k.match(/root$/i))
+ })
cl.push(cli)
cl.push(parseEnv(process.env))
parseFile(cl.get("userconfig") || dc.userconfig, function (er, conf) {
@@ -88,15 +91,20 @@ function parseEnv (env) {
.forEach(function (k) {
conf[k.replace(/^npm_config_/i, "")
.toLowerCase()
- .replace(/_/g, "-")] = parseField(env[k])
+ .replace(/_/g, "-")] = parseField(env[k], k.match(/root$/i))
})
return conf
}
-function parseField (f) {
+function parseField (f, isPath) {
f = (""+f).trim()
if (f === "") f = true
- if (f.substr(0, 2) === "~/" && process.env.HOME) {
- f = path.join(process.env.HOME, f.substr(2))
+ if (isPath) {
+ if (f.substr(0, 2) === "~/" && process.env.HOME) {
+ f = path.join(process.env.HOME, f.substr(2))
+ }
+ if (f.substr(0, 2) === "./") {
+ f = path.join(process.cwd(), f.substr(2))
+ }
}
switch (f) {
case "true": f = true; break
@@ -111,7 +119,9 @@ function parseFile (file, cb) {
fs.readFile(file, function (er, data) {
if (er) return cb(null, {})
var d = ini.parse(""+data)["-"]
- Object.keys(d).forEach(function (k) { d[k] = parseField(d[k]) })
+ Object.keys(d).forEach(function (k) {
+ d[k] = parseField(d[k], k.match(/root$/i))
+ })
decryptAuth(d, cb)
})
}