@npmcli/config 3.0.1 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -6
- package/lib/env-replace.js +1 -1
- package/lib/index.js +7 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -78,9 +78,12 @@ const conf = new Config({
|
|
|
78
78
|
platform: process.platform,
|
|
79
79
|
// optional, defaults to process.cwd()
|
|
80
80
|
cwd: process.cwd(),
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
// emits log events on the process object
|
|
84
|
+
// see `proc-log` for more info
|
|
85
|
+
process.on('log', (level, ...args) => {
|
|
86
|
+
console.log(level, ...args)
|
|
84
87
|
})
|
|
85
88
|
|
|
86
89
|
// returns a promise that fails if config loading fails, and
|
|
@@ -124,8 +127,6 @@ Options:
|
|
|
124
127
|
Windows.
|
|
125
128
|
- `execPath` Optional, defaults to `process.execPath`. Used to infer the
|
|
126
129
|
`globalPrefix`.
|
|
127
|
-
- `log` Optional, the object used to log debug messages, warnings, and
|
|
128
|
-
errors. Defaults to emitting on the `process` object.
|
|
129
130
|
- `env` Optional, defaults to `process.env`. Source of the environment
|
|
130
131
|
variables for configuration.
|
|
131
132
|
- `argv` Optional, defaults to `process.argv`. Source of the CLI options
|
|
@@ -161,7 +162,6 @@ Fields:
|
|
|
161
162
|
- `argv` The `argv` param
|
|
162
163
|
- `execPath` The `execPath` param
|
|
163
164
|
- `platform` The `platform` param
|
|
164
|
-
- `log` The `log` param
|
|
165
165
|
- `defaults` The `defaults` param
|
|
166
166
|
- `shorthands` The `shorthands` param
|
|
167
167
|
- `types` The `types` param
|
package/lib/env-replace.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// replace any ${ENV} values with the appropriate environ.
|
|
2
2
|
|
|
3
|
-
const envExpr = /(\\*)\$\{([
|
|
3
|
+
const envExpr = /(?<!\\)(\\*)\$\{([^${}]+)\}/g
|
|
4
4
|
|
|
5
5
|
module.exports = (f, env) => f.replace(envExpr, (orig, esc, name) => {
|
|
6
6
|
const val = env[name] !== undefined ? env[name] : `$\{${name}}`
|
package/lib/index.js
CHANGED
|
@@ -5,6 +5,7 @@ const nopt = require('nopt')
|
|
|
5
5
|
const mkdirp = require('mkdirp-infer-owner')
|
|
6
6
|
const mapWorkspaces = require('@npmcli/map-workspaces')
|
|
7
7
|
const rpj = require('read-package-json-fast')
|
|
8
|
+
const log = require('proc-log')
|
|
8
9
|
|
|
9
10
|
/* istanbul ignore next */
|
|
10
11
|
const myUid = process.getuid && process.getuid()
|
|
@@ -88,7 +89,6 @@ class Config {
|
|
|
88
89
|
// options just to override in tests, mostly
|
|
89
90
|
env = process.env,
|
|
90
91
|
argv = process.argv,
|
|
91
|
-
log = require('proc-log'),
|
|
92
92
|
platform = process.platform,
|
|
93
93
|
execPath = process.execPath,
|
|
94
94
|
cwd = process.cwd(),
|
|
@@ -114,7 +114,6 @@ class Config {
|
|
|
114
114
|
this.defaults = defaults
|
|
115
115
|
|
|
116
116
|
this.npmPath = npmPath
|
|
117
|
-
this.log = log
|
|
118
117
|
this.argv = argv
|
|
119
118
|
this.env = env
|
|
120
119
|
this.execPath = execPath
|
|
@@ -436,7 +435,7 @@ class Config {
|
|
|
436
435
|
}
|
|
437
436
|
|
|
438
437
|
invalidHandler (k, val, type, source, where) {
|
|
439
|
-
|
|
438
|
+
log.warn(
|
|
440
439
|
'invalid config',
|
|
441
440
|
k + '=' + JSON.stringify(val),
|
|
442
441
|
`set in ${source}`
|
|
@@ -469,7 +468,7 @@ class Config {
|
|
|
469
468
|
: mustBe.filter(m => m !== Array)
|
|
470
469
|
.map(n => typeof n === 'string' ? n : JSON.stringify(n))
|
|
471
470
|
.join(', ')
|
|
472
|
-
|
|
471
|
+
log.warn('invalid config', msg, desc)
|
|
473
472
|
}
|
|
474
473
|
|
|
475
474
|
[_loadObject] (obj, where, source, er = null) {
|
|
@@ -491,7 +490,7 @@ class Config {
|
|
|
491
490
|
if (er) {
|
|
492
491
|
conf.loadError = er
|
|
493
492
|
if (er.code !== 'ENOENT') {
|
|
494
|
-
|
|
493
|
+
log.verbose('config', `error loading ${where} config`, er)
|
|
495
494
|
}
|
|
496
495
|
} else {
|
|
497
496
|
conf.raw = obj
|
|
@@ -510,7 +509,7 @@ class Config {
|
|
|
510
509
|
// XXX a future npm version will make this a warning.
|
|
511
510
|
// An even more future npm version will make this an error.
|
|
512
511
|
if (this.deprecated[key]) {
|
|
513
|
-
|
|
512
|
+
log.verbose('config', key, this.deprecated[key])
|
|
514
513
|
}
|
|
515
514
|
}
|
|
516
515
|
|
|
@@ -607,14 +606,14 @@ class Config {
|
|
|
607
606
|
.catch(() => false)
|
|
608
607
|
|
|
609
608
|
if (hasNpmrc) {
|
|
610
|
-
|
|
609
|
+
log.warn(`ignoring workspace config at ${this.localPrefix}/.npmrc`)
|
|
611
610
|
}
|
|
612
611
|
|
|
613
612
|
// set the workspace in the default layer, which allows it to be overridden easily
|
|
614
613
|
const { data } = this.data.get('default')
|
|
615
614
|
data.workspace = [this.localPrefix]
|
|
616
615
|
this.localPrefix = p
|
|
617
|
-
|
|
616
|
+
log.info(`found workspace root at ${this.localPrefix}`)
|
|
618
617
|
// we found a root, so we return now
|
|
619
618
|
return
|
|
620
619
|
}
|