diff options
author | isaacs <i@izs.me> | 2011-10-08 04:18:52 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2011-10-08 04:18:52 +0400 |
commit | a5bbf487ee27255a97d0ac348b33eb692d2f6130 (patch) | |
tree | 3277ef4516cdbe0de3a547a4efc68b971bccb26d /lib | |
parent | ca71fc956dd589511d5258d3906a01edcd68555c (diff) |
Put builtinconfig file between defaults and global
Diffstat (limited to 'lib')
-rw-r--r-- | lib/utils/ini.js | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/lib/utils/ini.js b/lib/utils/ini.js index fd3847217..221f84af5 100644 --- a/lib/utils/ini.js +++ b/lib/utils/ini.js @@ -24,6 +24,7 @@ exports.get = get exports.set = set exports.unParseField = unParseField exports.defaultConfig = null +exports.saveConfig = saveConfig Object.defineProperty(exports, "keys", { get : function () { return configList.keys }}) @@ -47,7 +48,8 @@ var fs = require("graceful-fs") , configList = new ProtoList() , types = configDefs.types , TRANS = exports.TRANS = - { "default" : 4 + { "default" : 5 + , "builtin": 4 , "global" : 3 , "user" : 2 , "env" : 1 @@ -88,8 +90,13 @@ function resolveConfigs (cli, cb_) { , function (er, conf) { if (er) return cb(er) cl.push(conf) - cl.push(dc) - setUser(cl, dc, thenValidate(cl, cb)) + // the builtin config file, for distros to use. + parseFile(path.resolve(__dirname, "../../npmrc"), function (er, conf) { + if (er) conf = {} + cl.push(conf) + cl.push(dc) + setUser(cl, dc, thenValidate(cl, cb)) + }) }) }) } @@ -218,13 +225,33 @@ function parseAuth (config) { } function save (cb) { - return saveConfig("global", function (er) { saveConfig("user", cb) }) + var errState = null + , done = 3 + ;["global", "user", "builtin"].forEach(function (c) { + saveConfig(c, function (er) { + if (errState) return + if (er) return cb(errState = er) + if (-- done === 0) return cb() + }) + }) } function saveConfig (which, cb) { - if (which !== "global") which = "user" + var file + switch (which) { + case "builtin": + file = path.resolve(__dirname, "../../npmrc") + break + case "global": + file = configList.get("globalconfig") + break + default: + file = configList.get("userconfig") + which = "user" + } + saveConfigfile - ( configList.get(which + "config") + ( file , configList.list[TRANS[which]] , which , cb ) |