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>2011-12-01 22:36:57 +0400
committerisaacs <i@izs.me>2011-12-01 22:36:57 +0400
commit372a92e376413ceab65a1bb4ce2e21e969eb6a09 (patch)
tree7f39887126688ffebe0196e25fa8ffd551cc033a
parent69884e9c447d304e4b2bf9cab5a61abb739a679d (diff)
Support ${ENV} values in configs
-rw-r--r--lib/utils/config-defs.js5
-rw-r--r--lib/utils/ini.js17
2 files changed, 19 insertions, 3 deletions
diff --git a/lib/utils/config-defs.js b/lib/utils/config-defs.js
index 298b7cc54..c0ed1fca8 100644
--- a/lib/utils/config-defs.js
+++ b/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 () {
diff --git a/lib/utils/ini.js b/lib/utils/ini.js
index 81a937601..85aa28d23 100644
--- a/lib/utils/ini.js
+++ b/lib/utils/ini.js
@@ -199,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
}
@@ -327,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]