Comparing version 0.2.0 to 1.0.0
103
npmconf.js
@@ -13,2 +13,3 @@ | ||
var mkdirp = require('mkdirp') | ||
var path = require('path') | ||
@@ -21,5 +22,7 @@ exports.load = load | ||
exports.defs = configDefs | ||
Object.defineProperty(exports, 'defaults', { get: function () { | ||
return configDefs.defaults | ||
}, enumerable: true }) | ||
Object.defineProperty(exports, 'types', { get: function () { | ||
@@ -72,2 +75,3 @@ return configDefs.types | ||
return | ||
loading = true | ||
@@ -87,3 +91,2 @@ | ||
var rc = exports.rootConf = new Conf() | ||
var defaults = configDefs.defaults | ||
if (builtin) | ||
@@ -95,35 +98,58 @@ rc.addFile(builtin, 'builtin') | ||
rc.on('load', function () { | ||
var conf = new Conf(rc) | ||
conf.usingBuiltin = !!builtin | ||
conf.add(cli, 'cli') | ||
conf.addEnv() | ||
load_(builtin, rc, cli, cb) | ||
}) | ||
} | ||
function load_(builtin, rc, cli, cb) { | ||
var defaults = configDefs.defaults | ||
var conf = new Conf(rc) | ||
conf.usingBuiltin = !!builtin | ||
conf.add(cli, 'cli') | ||
conf.addEnv() | ||
conf.loadExtras(function(er) { | ||
if (er) | ||
return cb(er) | ||
if (!conf.get('global')) { | ||
var projectConf = path.resolve(conf.localPrefix, '.npmrc') | ||
conf.addFile(projectConf, 'project') | ||
conf.once('load', afterPrefix) | ||
} | ||
else return afterPrefix() | ||
}) | ||
function afterPrefix() { | ||
conf.addFile(conf.get('userconfig'), 'user') | ||
conf.once('error', cb) | ||
conf.once('load', afterUser) | ||
} | ||
function afterUser () { | ||
// globalconfig and globalignorefile defaults | ||
// need to respond to the 'prefix' setting up to this point. | ||
// Eg, `npm config get globalconfig --prefix ~/local` should | ||
// return `~/local/etc/npmrc` | ||
// annoying humans and their expectations! | ||
if (conf.get('prefix')) { | ||
var etc = path.resolve(conf.get('prefix'), 'etc') | ||
defaults.globalconfig = path.resolve(etc, 'npmrc') | ||
defaults.globalignorefile = path.resolve(etc, 'npmignore') | ||
} | ||
conf.addFile(conf.get('globalconfig'), 'global') | ||
// move the builtin into the conf stack now. | ||
conf.root = defaults | ||
conf.add(rc.shift(), 'builtin') | ||
conf.once('load', function () { | ||
// globalconfig and globalignorefile defaults | ||
// need to respond to the "prefix" setting up to this point. | ||
// Eg, `npm config get globalconfig --prefix ~/local` should | ||
// return `~/local/etc/npmrc` | ||
// annoying humans and their expectations! | ||
if (conf.get('prefix')) { | ||
var etc = path.resolve(conf.get("prefix"), "etc") | ||
defaults.globalconfig = path.resolve(etc, "npmrc") | ||
defaults.globalignorefile = path.resolve(etc, "npmignore") | ||
} | ||
conf.addFile(conf.get('globalconfig'), 'global') | ||
// move the builtin into the conf stack now. | ||
conf.root = defaults | ||
conf.add(rc.shift(), 'builtin') | ||
conf.once('load', function () { | ||
// warn about invalid bits. | ||
validate(conf) | ||
exports.loaded = conf | ||
cb(null, conf) | ||
}) | ||
// warn about invalid bits. | ||
validate(conf) | ||
exports.loaded = conf | ||
cb(null, conf) | ||
}) | ||
}) | ||
} | ||
} | ||
// Basically the same as CC, but: | ||
@@ -150,2 +176,19 @@ // 1. Always ini | ||
Conf.prototype.loadPrefix = require('./lib/load-prefix.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') | ||
Conf.prototype.loadExtras = function(cb) { | ||
this.loadPrefix(function(er) { | ||
if (er) | ||
return cb(er) | ||
this.setUser(function(er) { | ||
if (er) | ||
return cb(er) | ||
this.loadUid(cb) | ||
}.bind(this)) | ||
}.bind(this)) | ||
} | ||
Conf.prototype.save = function (where, cb) { | ||
@@ -325,3 +368,3 @@ var target = this.sources[where] | ||
function envReplace (f) { | ||
if (typeof f !== "string" || !f) return f | ||
if (typeof f !== 'string' || !f) return f | ||
@@ -335,3 +378,3 @@ // replace any ${ENV} values with the appropriate environ. | ||
if (undefined === process.env[name]) | ||
throw new Error("Failed to replace env in config: "+orig) | ||
throw new Error('Failed to replace env in config: '+orig) | ||
return process.env[name] | ||
@@ -338,0 +381,0 @@ }) |
{ | ||
"name": "npmconf", | ||
"version": "0.2.0", | ||
"version": "1.0.0", | ||
"description": "The config thing npm uses", | ||
@@ -12,8 +12,9 @@ "main": "npmconf.js", | ||
"inherits": "~2.0.0", | ||
"ini": "~1.1.0", | ||
"mkdirp": "~0.3.3", | ||
"nopt": "2", | ||
"once": "~1.3.0", | ||
"mkdirp": "~0.3.3", | ||
"osenv": "0.0.3", | ||
"nopt": "2", | ||
"semver": "2", | ||
"ini": "~1.1.0" | ||
"uid-number": "0.0.5" | ||
}, | ||
@@ -20,0 +21,0 @@ "devDependencies": { |
var test = require('tap').test | ||
var npmconf = require('../npmconf.js') | ||
var common = require('./00-setup.js') | ||
var path = require('path') | ||
var projectData = {} | ||
var ucData = | ||
@@ -32,2 +35,3 @@ { globalconfig: common.globalconfig, | ||
var envData = { userconfig: common.userconfig, 'other-env-thing': '1000' } | ||
var envDataFix = { userconfig: common.userconfig, 'other-env-thing': 1000 } | ||
@@ -42,3 +46,4 @@ var gcData = { 'package-config:foo': 'boo' } | ||
[ cli, | ||
envData, | ||
envDataFix, | ||
projectData, | ||
ucData, | ||
@@ -51,5 +56,9 @@ gcData, | ||
env: | ||
{ data: envData, | ||
{ data: envDataFix, | ||
source: envData, | ||
prefix: '' }, | ||
project: | ||
{ path: path.resolve(__dirname, '..', '.npmrc'), | ||
type: 'ini', | ||
data: projectData }, | ||
user: | ||
@@ -56,0 +65,0 @@ { path: common.userconfig, |
var test = require('tap').test | ||
var npmconf = require('../npmconf.js') | ||
var common = require('./00-setup.js') | ||
var path = require('path') | ||
@@ -32,2 +33,3 @@ var ucData = | ||
var envData = { userconfig: common.userconfig, 'other-env-thing': '1000' } | ||
var envDataFix = { userconfig: common.userconfig, 'other-env-thing': 1000 } | ||
@@ -40,5 +42,8 @@ var gcData = { 'package-config:foo': 'boo' } | ||
var projectData = {} | ||
var expectList = | ||
[ cli, | ||
envData, | ||
envDataFix, | ||
projectData, | ||
ucData, | ||
@@ -51,5 +56,9 @@ gcData, | ||
env: | ||
{ data: envData, | ||
{ data: envDataFix, | ||
source: envData, | ||
prefix: '' }, | ||
project: | ||
{ path: path.resolve(__dirname, '..', '.npmrc'), | ||
type: 'ini', | ||
data: projectData }, | ||
user: | ||
@@ -56,0 +65,0 @@ { path: common.userconfig, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Misc. License Issues
License(Experimental) A package's licensing information has fine-grained problems.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
36510
20
1092
1
9
2
38
+ Addeduid-number@0.0.5
+ Addeduid-number@0.0.5(transitive)