@npmcli/config 3.0.1 → 4.0.2

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('proc-log')
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,14 +1,14 @@
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}}`
7
7
 
8
8
  // consume the escape chars that are relevant.
9
9
  if (esc.length % 2) {
10
- return orig.substr((esc.length + 1) / 2)
10
+ return orig.slice((esc.length + 1) / 2)
11
11
  }
12
12
 
13
- return (esc.substr(esc.length / 2)) + val
13
+ return (esc.slice(esc.length / 2)) + val
14
14
  })
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
@@ -367,7 +366,7 @@ class Config {
367
366
  if (!/^npm_config_/i.test(envKey) || envVal === '') {
368
367
  continue
369
368
  }
370
- const key = envKey.substr('npm_config_'.length)
369
+ const key = envKey.slice('npm_config_'.length)
371
370
  .replace(/(?!^)_/g, '-') // don't replace _ at the start of the key
372
371
  .toLowerCase()
373
372
  conf[key] = envVal
@@ -397,13 +396,13 @@ class Config {
397
396
  validate (where) {
398
397
  if (!where) {
399
398
  let valid = true
400
- for (const [where] of this.data.entries()) {
399
+ for (const [entryWhere] of this.data.entries()) {
401
400
  // no need to validate our defaults, we know they're fine
402
401
  // cli was already validated when parsed the first time
403
- if (where === 'default' || where === 'builtin' || where === 'cli') {
402
+ if (entryWhere === 'default' || entryWhere === 'builtin' || entryWhere === 'cli') {
404
403
  continue
405
404
  }
406
- const ret = this.validate(where)
405
+ const ret = this.validate(entryWhere)
407
406
  valid = valid && ret
408
407
  }
409
408
  return valid
@@ -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
  }
@@ -56,7 +56,7 @@ const parseField = (f, key, opts, listElement = false) => {
56
56
  if (isPath) {
57
57
  const homePattern = platform === 'win32' ? /^~(\/|\\)/ : /^~\//
58
58
  if (homePattern.test(f) && home) {
59
- f = resolve(home, f.substr(2))
59
+ f = resolve(home, f.slice(2))
60
60
  } else {
61
61
  f = resolve(f)
62
62
  }
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@npmcli/config",
3
- "version": "3.0.1",
3
+ "version": "4.0.2",
4
4
  "files": [
5
- "bin",
6
- "lib"
5
+ "bin/",
6
+ "lib/"
7
7
  ],
8
8
  "main": "lib/index.js",
9
9
  "description": "Configuration management for the npm cli",
10
10
  "repository": {
11
11
  "type": "git",
12
- "url": "git+https://github.com/npm/config"
12
+ "url": "https://github.com/npm/config.git"
13
13
  },
14
14
  "author": "GitHub Inc.",
15
15
  "license": "ISC",
@@ -19,23 +19,24 @@
19
19
  "preversion": "npm test",
20
20
  "postversion": "npm publish",
21
21
  "prepublishOnly": "git push origin --follow-tags",
22
- "lint": "eslint '**/*.js'",
23
- "postlint": "npm-template-check",
22
+ "lint": "eslint \"**/*.js\"",
23
+ "postlint": "template-oss-check",
24
24
  "lintfix": "npm run lint -- --fix",
25
25
  "posttest": "npm run lint",
26
- "template-copy": "npm-template-copy --force"
26
+ "template-oss-apply": "template-oss-apply --force"
27
27
  },
28
28
  "tap": {
29
29
  "check-coverage": true,
30
30
  "coverage-map": "map.js"
31
31
  },
32
32
  "devDependencies": {
33
- "@npmcli/template-oss": "^2.7.1",
34
- "tap": "^15.1.6"
33
+ "@npmcli/eslint-config": "^3.0.1",
34
+ "@npmcli/template-oss": "3.2.2",
35
+ "tap": "^16.0.1"
35
36
  },
36
37
  "dependencies": {
37
- "@npmcli/map-workspaces": "^2.0.0",
38
- "ini": "^2.0.0",
38
+ "@npmcli/map-workspaces": "^2.0.2",
39
+ "ini": "^3.0.0",
39
40
  "mkdirp-infer-owner": "^2.0.0",
40
41
  "nopt": "^5.0.0",
41
42
  "proc-log": "^2.0.0",
@@ -44,9 +45,10 @@
44
45
  "walk-up-path": "^1.0.0"
45
46
  },
46
47
  "engines": {
47
- "node": "^12.13.0 || ^14.15.0 || >=16"
48
+ "node": "^12.13.0 || ^14.15.0 || >=16.0.0"
48
49
  },
49
50
  "templateOSS": {
50
- "version": "2.7.1"
51
+ "//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
52
+ "version": "3.2.2"
51
53
  }
52
54
  }