@npmcli/config
Advanced tools
Comparing version 1.0.2 to 1.1.0
@@ -181,2 +181,5 @@ // TODO: set the scope config from package.json or explicit cli config | ||
this.data.get(where).data[key] = val | ||
// this is now dirty, the next call to this.valid will have to check it | ||
this.data.get(where)[_valid] = null | ||
} | ||
@@ -256,3 +259,3 @@ | ||
prefix: this.globalPrefix, | ||
}, 'default', '(default values)') | ||
}, 'default', 'default values') | ||
@@ -309,3 +312,3 @@ const { data } = this.data.get('default') | ||
} | ||
this[_loadObject](conf, 'env', '(environment)') | ||
this[_loadObject](conf, 'env', 'environment') | ||
} | ||
@@ -315,3 +318,3 @@ | ||
nopt.invalidHandler = (k, val, type) => | ||
this.invalidHandler(k, val, type, 'cli options') | ||
this.invalidHandler(k, val, type, 'command line options', 'cli') | ||
const conf = nopt(this.types, this.shorthands, this.argv) | ||
@@ -321,21 +324,41 @@ nopt.invalidHandler = null | ||
delete conf.argv | ||
this[_loadObject](conf, 'cli', '(command line options)') | ||
this[_loadObject](conf, 'cli', 'command line options') | ||
} | ||
validate () { | ||
for (const [where, obj] of this.data.entries()) { | ||
// no need to validate our defaults, we know they're fine | ||
// cli was already validated when parsed the first time | ||
if (where === 'default' || where === 'builtin' || where === 'cli') | ||
continue | ||
get valid () { | ||
for (const [where, {valid}] of this.data.entries()) { | ||
if (valid === null) | ||
this.validate(where) | ||
if (!valid) | ||
return false | ||
} | ||
return true | ||
} | ||
validate (where) { | ||
if (!where) { | ||
for (const [where, obj] of this.data.entries()) { | ||
// no need to validate our defaults, we know they're fine | ||
// cli was already validated when parsed the first time | ||
if (where === 'default' || where === 'builtin' || where === 'cli') | ||
continue | ||
this.validate(where) | ||
} | ||
} else { | ||
const obj = this.data.get(where) | ||
obj[_valid] = true | ||
nopt.invalidHandler = (k, val, type) => | ||
this.invalidHandler(k, val, type, this.data.get(where).source) | ||
this.invalidHandler(k, val, type, obj.source, where) | ||
nopt.clean(obj.data, this.types, this.typeDefs) | ||
nopt.invalidHandler = null | ||
} | ||
nopt.invalidHandler = null | ||
return this.valid | ||
} | ||
invalidHandler (k, val, type, source) { | ||
invalidHandler (k, val, type, source, where) { | ||
this.log.warn( | ||
@@ -346,2 +369,3 @@ 'invalid config', | ||
) | ||
this.data.get(where)[_valid] = false | ||
@@ -668,2 +692,3 @@ if (Array.isArray(type)) { | ||
const _source = Symbol('source') | ||
const _valid = Symbol('valid') | ||
class ConfigData { | ||
@@ -675,2 +700,3 @@ constructor (parent) { | ||
this[_raw] = null | ||
this[_valid] = true | ||
} | ||
@@ -682,2 +708,6 @@ | ||
get valid () { | ||
return this[_valid] | ||
} | ||
set source (s) { | ||
@@ -684,0 +714,0 @@ if (this[_source]) |
{ | ||
"name": "@npmcli/config", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"files": [ | ||
@@ -5,0 +5,0 @@ "lib" |
@@ -176,2 +176,5 @@ # `@npmcli/config` | ||
- `loaded` A boolean indicating whether or not configs are loaded | ||
- `valid` A getter that returns `true` if all the config objects are valid. | ||
Any data objects that have been modified with `config.set(...)` will be | ||
re-evaluated when `config.valid` is read. | ||
@@ -206,6 +209,15 @@ ### `config.load()` | ||
### `config.validate()` | ||
### `config.validate(where)` | ||
Verify that all known configuration options are set to valid values. | ||
Verify that all known configuration options are set to valid values, and | ||
log a warning if they are invalid. | ||
If `where` is not set, then all config objects are validated. | ||
Returns `true` if all configs are valid. | ||
Note that it's usually enough (and more efficient) to just check | ||
`config.valid`, since each data object is marked for re-evaluation on every | ||
`config.set()` operation. | ||
### `config.save(where)` | ||
@@ -212,0 +224,0 @@ |
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
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
41152
891
225