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>2012-07-31 00:40:22 +0400
committerisaacs <i@izs.me>2012-07-31 00:40:22 +0400
commit400763888f1f8321ef7c5b2d1928752391b20dba (patch)
tree2ea42b00b2087736a7d489519f4add12fedc6012
parent9b0b53ace2eb51aebb2d591d05200b05ddf8ccf2 (diff)
The token is an object. Treat it as one.
Allow objects in config files, and leverage the ini format's ability to handle them intelligently.
-rw-r--r--lib/config.js9
-rw-r--r--lib/npm.js17
-rw-r--r--lib/utils/ini.js5
3 files changed, 16 insertions, 15 deletions
diff --git a/lib/config.js b/lib/config.js
index c9f476698..9c632c082 100644
--- a/lib/config.js
+++ b/lib/config.js
@@ -167,9 +167,8 @@ function list (cb) {
if (cliKeys.length) {
msg += "; cli configs" + eol
cliKeys.forEach(function (k) {
- if (cli[k] && typeof cli[k] === 'object') return
+ if (cli[k] && typeof cli[k] === "object") return
if (k === "argv") return
- if (typeof cli[k] === 'object') return
msg += k + " = " + JSON.stringify(cli[k]) + eol
})
msg += eol
@@ -185,7 +184,6 @@ function list (cb) {
if (envKeys.length) {
msg += "; environment configs" + eol
envKeys.forEach(function (k) {
- if (env[k] && typeof env[k] === 'object') return
if (env[k] !== ini.get(k)) {
if (!long) return
msg += "; " + k + " = " + JSON.stringify(env[k])
@@ -205,7 +203,6 @@ function list (cb) {
if (uconfKeys.length) {
msg += "; userconfig " + ini.get("userconfig") + eol
uconfKeys.forEach(function (k) {
- if (uconf[k] && typeof uconf[k] === 'object') return
var val = (k.charAt(0) === "_")
? "---sekretz---"
: JSON.stringify(uconf[k])
@@ -228,7 +225,6 @@ function list (cb) {
if (gconfKeys.length) {
msg += "; globalconfig " + ini.get("globalconfig") + eol
gconfKeys.forEach(function (k) {
- if (gconf[k] && typeof gconf[k] === 'object') return
var val = (k.charAt(0) === "_")
? "---sekretz---"
: JSON.stringify(gconf[k])
@@ -252,7 +248,6 @@ function list (cb) {
var path = require("path")
msg += "; builtin config " + path.resolve(__dirname, "../npmrc") + eol
bconfKeys.forEach(function (k) {
- if (bconf[k] && typeof bconf[k] === 'object') return
var val = (k.charAt(0) === "_")
? "---sekretz---"
: JSON.stringify(bconf[k])
@@ -281,7 +276,7 @@ function list (cb) {
, defKeys = Object.keys(defaults)
msg += "; default values" + eol
defKeys.forEach(function (k) {
- if (defaults[k] && typeof defaults[k] === 'object') return
+ if (defaults[k] && typeof defaults[k] === "object") return
var val = JSON.stringify(defaults[k])
if (defaults[k] !== ini.get(k)) {
if (!long) return
diff --git a/lib/npm.js b/lib/npm.js
index 4db289a58..e5d4b2450 100644
--- a/lib/npm.js
+++ b/lib/npm.js
@@ -294,9 +294,14 @@ function load (npm, conf, cb) {
// at this point the configs are all set.
// go ahead and spin up the registry client.
- var token
- try { token = JSON.parse(npm.config.get("_token")) }
- catch (er) { token = null }
+ var token = npm.config.get("_token")
+ if (typeof token === "string") {
+ try {
+ token = JSON.parse(token)
+ npm.config.set("_token", token, "user")
+ ini.save("user", function () {})
+ } catch (e) { token = null }
+ }
npm.registry = new RegClient(
{ registry: npm.config.get("registry")
@@ -324,7 +329,7 @@ function load (npm, conf, cb) {
// save the token cookie in the config file
if (npm.registry.couchLogin) {
npm.registry.couchLogin.tokenSet = function (tok) {
- ini.set("_token", JSON.stringify(tok), "user")
+ ini.set("_token", tok, "user")
// ignore save error. best effort.
ini.save("user", function () {})
}
@@ -424,8 +429,8 @@ function setUser (cl, dc, 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") }
+ , set : function (key, val, which) { return ini.set(key, val, which) }
+ , del : function (key, val, which) { return ini.del(key, val, which) }
}
Object.defineProperty(npm, "prefix",
diff --git a/lib/utils/ini.js b/lib/utils/ini.js
index aa4f43180..3bbffb09c 100644
--- a/lib/utils/ini.js
+++ b/lib/utils/ini.js
@@ -163,6 +163,7 @@ function unParseField (f, k) {
}
}
}
+ return (!f || typeof f !== "object") ? ini.safe(f) : f
return ini.safe(f)
}
@@ -220,7 +221,6 @@ function encryptAuth (config, cb) {
}
function parseAuth (config) {
- //console.error("parsing config %j", config)
if (!config._auth) return config
var b = new Buffer(config._auth, "base64")
, unpw = b.toString().split(":")
@@ -347,5 +347,6 @@ function set (key, value, which) {
if (configList.length === 1) {
return new Error("trying to set before loading")
}
- return configList.list[TRANS[which]][key] = value
+ configList.list[TRANS[which]][key] = value
+ return value
}