@npmcli/config 3.0.0 → 4.0.1

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 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
- // optional, defaults to emitting 'log' events on process object
82
- // only silly, verbose, warn, and error are logged by this module
83
- log: require('npmlog')
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
@@ -1,6 +1,6 @@
1
1
  // replace any ${ENV} values with the appropriate environ.
2
2
 
3
- const envExpr = /(\\*)\$\{([^}]+)\}/g
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.js'),
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
- this.log.warn(
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
- this.log.warn('invalid config', msg, desc)
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
- this.log.verbose('config', `error loading ${where} config`, er)
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
- this.log.verbose('config', key, this.deprecated[key])
512
+ log.verbose('config', key, this.deprecated[key])
514
513
  }
515
514
  }
516
515
 
@@ -567,6 +566,7 @@ class Config {
567
566
  }
568
567
 
569
568
  const cliWorkspaces = this[_get]('workspaces', 'cli')
569
+ const isGlobal = this[_get]('global') || this[_get]('location') === 'global'
570
570
 
571
571
  for (const p of walkUp(this.cwd)) {
572
572
  const hasNodeModules = await stat(resolve(p, 'node_modules'))
@@ -580,8 +580,8 @@ class Config {
580
580
  if (!this.localPrefix && (hasNodeModules || hasPackageJson)) {
581
581
  this.localPrefix = p
582
582
 
583
- // if workspaces are disabled, return now
584
- if (cliWorkspaces === false) {
583
+ // if workspaces are disabled, or we're in global mode, return now
584
+ if (cliWorkspaces === false || isGlobal) {
585
585
  return
586
586
  }
587
587
 
@@ -607,14 +607,14 @@ class Config {
607
607
  .catch(() => false)
608
608
 
609
609
  if (hasNpmrc) {
610
- this.log.warn(`ignoring workspace config at ${this.localPrefix}/.npmrc`)
610
+ log.warn(`ignoring workspace config at ${this.localPrefix}/.npmrc`)
611
611
  }
612
612
 
613
613
  // set the workspace in the default layer, which allows it to be overridden easily
614
614
  const { data } = this.data.get('default')
615
615
  data.workspace = [this.localPrefix]
616
616
  this.localPrefix = p
617
- this.log.info(`found workspace root at ${this.localPrefix}`)
617
+ log.info(`found workspace root at ${this.localPrefix}`)
618
618
  // we found a root, so we return now
619
619
  return
620
620
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@npmcli/config",
3
- "version": "3.0.0",
3
+ "version": "4.0.1",
4
4
  "files": [
5
5
  "bin",
6
6
  "lib"
@@ -30,22 +30,23 @@
30
30
  "coverage-map": "map.js"
31
31
  },
32
32
  "devDependencies": {
33
- "@npmcli/template-oss": "^2.5.1",
34
- "tap": "^15.0.4"
33
+ "@npmcli/template-oss": "^2.8.1",
34
+ "tap": "^15.1.6"
35
35
  },
36
36
  "dependencies": {
37
- "@npmcli/map-workspaces": "^2.0.0",
37
+ "@npmcli/map-workspaces": "^2.0.1",
38
38
  "ini": "^2.0.0",
39
39
  "mkdirp-infer-owner": "^2.0.0",
40
40
  "nopt": "^5.0.0",
41
+ "proc-log": "^2.0.0",
41
42
  "read-package-json-fast": "^2.0.3",
42
- "semver": "^7.3.4",
43
+ "semver": "^7.3.5",
43
44
  "walk-up-path": "^1.0.0"
44
45
  },
45
46
  "engines": {
46
47
  "node": "^12.13.0 || ^14.15.0 || >=16"
47
48
  },
48
49
  "templateOSS": {
49
- "version": "2.6.0"
50
+ "version": "2.8.1"
50
51
  }
51
52
  }
package/lib/proc-log.js DELETED
@@ -1,4 +0,0 @@
1
- const log = (level) => (...args) => process.emit('log', level, ...args)
2
- for (const level of ['silly', 'verbose', 'warn', 'error']) {
3
- exports[level] = log(level)
4
- }