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:
Diffstat (limited to 'node_modules/npmconf/npmconf.js')
-rw-r--r--node_modules/npmconf/npmconf.js63
1 files changed, 52 insertions, 11 deletions
diff --git a/node_modules/npmconf/npmconf.js b/node_modules/npmconf/npmconf.js
index c319c64d4..d1f334b79 100644
--- a/node_modules/npmconf/npmconf.js
+++ b/node_modules/npmconf/npmconf.js
@@ -107,12 +107,34 @@ function load_(builtin, rc, cli, cb) {
if (er)
return cb(er)
- if (!conf.get('global')) {
- var projectConf = path.resolve(conf.localPrefix, '.npmrc')
+ // If you're doing `npm --userconfig=~/foo.npmrc` then you'd expect
+ // that ~/.npmrc won't override the stuff in ~/foo.npmrc (or, indeed
+ // be used at all).
+ //
+ // However, if the cwd is ~, then ~/.npmrc is the home for the project
+ // config, and will override the userconfig.
+ //
+ // If you're not setting the userconfig explicitly, then it will be loaded
+ // twice, which is harmless but excessive. If you *are* setting the
+ // userconfig explicitly then it will override your explicit intent, and
+ // that IS harmful and unexpected.
+ //
+ // Solution: Do not load project config file that is the same as either
+ // the default or resolved userconfig value. npm will log a "verbose"
+ // message about this when it happens, but it is a rare enough edge case
+ // that we don't have to be super concerned about it.
+ var projectConf = path.resolve(conf.localPrefix, '.npmrc')
+ var defaultUserConfig = rc.get('userconfig')
+ var resolvedUserConfig = conf.get('userconfig')
+ if (!conf.get('global') &&
+ projectConf !== defaultUserConfig &&
+ projectConf !== resolvedUserConfig) {
conf.addFile(projectConf, 'project')
conf.once('load', afterPrefix)
+ } else {
+ conf.add({}, 'project')
+ afterPrefix()
}
- else return afterPrefix()
})
function afterPrefix() {
@@ -139,16 +161,34 @@ function load_(builtin, rc, cli, cb) {
conf.root = defaults
conf.add(rc.shift(), 'builtin')
conf.once('load', function () {
- conf.loadExtras(function(er) {
- if (er)
- return cb(er)
- // warn about invalid bits.
- validate(conf)
- exports.loaded = conf
- cb(er, conf)
- })
+ conf.loadExtras(afterExtras)
})
}
+
+ function afterExtras(er) {
+ if (er)
+ return cb(er)
+
+ // warn about invalid bits.
+ validate(conf)
+
+ var cafile = conf.get('cafile')
+
+ if (cafile) {
+ return conf.loadCAFile(cafile, finalize)
+ }
+
+ finalize()
+ }
+
+ function finalize(er, cadata) {
+ if (er) {
+ return cb(er)
+ }
+
+ exports.loaded = conf
+ cb(er, conf)
+ }
}
// Basically the same as CC, but:
@@ -173,6 +213,7 @@ function Conf (base) {
}
Conf.prototype.loadPrefix = require('./lib/load-prefix.js')
+Conf.prototype.loadCAFile = require('./lib/load-cafile.js')
Conf.prototype.loadUid = require('./lib/load-uid.js')
Conf.prototype.setUser = require('./lib/set-user.js')
Conf.prototype.findPrefix = require('./lib/find-prefix.js')