@npmcli/config 6.2.0 → 7.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.
@@ -0,0 +1,73 @@
1
+ const definitions = require('./definitions.js')
2
+
3
+ // use the defined flattening function, and copy over any scoped
4
+ // registries and registry-specific "nerfdart" configs verbatim
5
+ //
6
+ // TODO: make these getters so that we only have to make dirty
7
+ // the thing that changed, and then flatten the fields that
8
+ // could have changed when a config.set is called.
9
+ //
10
+ // TODO: move nerfdart auth stuff into a nested object that
11
+ // is only passed along to paths that end up calling npm-registry-fetch.
12
+ const flatten = (obj, flat = {}) => {
13
+ for (const [key, val] of Object.entries(obj)) {
14
+ const def = definitions[key]
15
+ if (def && def.flatten) {
16
+ def.flatten(key, obj, flat)
17
+ } else if (/@.*:registry$/i.test(key) || /^\/\//.test(key)) {
18
+ flat[key] = val
19
+ }
20
+ }
21
+
22
+ // XXX make this the bin/npm-cli.js file explicitly instead
23
+ // otherwise using npm programmatically is a bit of a pain.
24
+ flat.npmBin = require.main ? require.main.filename
25
+ : /* istanbul ignore next - not configurable property */ undefined
26
+ flat.nodeBin = process.env.NODE || process.execPath
27
+
28
+ return flat
29
+ }
30
+
31
+ const definitionProps = Object.entries(definitions)
32
+ .reduce((acc, [key, { short = [], default: d }]) => {
33
+ // can be either an array or string
34
+ for (const s of [].concat(short)) {
35
+ acc.shorthands[s] = [`--${key}`]
36
+ }
37
+ acc.defaults[key] = d
38
+ return acc
39
+ }, { shorthands: {}, defaults: {} })
40
+
41
+ // aliases where they get expanded into a completely different thing
42
+ // these are NOT supported in the environment or npmrc files, only
43
+ // expanded on the CLI.
44
+ // TODO: when we switch off of nopt, use an arg parser that supports
45
+ // more reasonable aliasing and short opts right in the definitions set.
46
+ const shorthands = {
47
+ 'enjoy-by': ['--before'],
48
+ d: ['--loglevel', 'info'],
49
+ dd: ['--loglevel', 'verbose'],
50
+ ddd: ['--loglevel', 'silly'],
51
+ quiet: ['--loglevel', 'warn'],
52
+ q: ['--loglevel', 'warn'],
53
+ s: ['--loglevel', 'silent'],
54
+ silent: ['--loglevel', 'silent'],
55
+ verbose: ['--loglevel', 'verbose'],
56
+ desc: ['--description'],
57
+ help: ['--usage'],
58
+ local: ['--no-global'],
59
+ n: ['--no-yes'],
60
+ no: ['--no-yes'],
61
+ porcelain: ['--parseable'],
62
+ readonly: ['--read-only'],
63
+ reg: ['--registry'],
64
+ iwr: ['--include-workspace-root'],
65
+ ...definitionProps.shorthands,
66
+ }
67
+
68
+ module.exports = {
69
+ defaults: definitionProps.defaults,
70
+ definitions,
71
+ flatten,
72
+ shorthands,
73
+ }
package/lib/errors.js CHANGED
@@ -4,6 +4,7 @@ class ErrInvalidAuth extends Error {
4
4
  constructor (problems) {
5
5
  let message = 'Invalid auth configuration found: '
6
6
  message += problems.map((problem) => {
7
+ // istanbul ignore else
7
8
  if (problem.action === 'delete') {
8
9
  return `\`${problem.key}\` is not allowed in ${problem.where} config`
9
10
  } else if (problem.action === 'rename') {
package/lib/index.js CHANGED
@@ -305,16 +305,22 @@ class Config {
305
305
  this.loadGlobalPrefix()
306
306
  this.loadHome()
307
307
 
308
- this.#loadObject({
308
+ const defaultsObject = {
309
309
  ...this.defaults,
310
310
  prefix: this.globalPrefix,
311
- }, 'default', 'default values')
311
+ }
312
312
 
313
- const { data } = this.data.get('default')
313
+ try {
314
+ defaultsObject['npm-version'] = require(join(this.npmPath, 'package.json')).version
315
+ } catch {
316
+ // in some weird state where the passed in npmPath does not have a package.json
317
+ // this will never happen in npm, but is guarded here in case this is consumed
318
+ // in other ways + tests
319
+ }
314
320
 
315
- // the metrics-registry defaults to the current resolved value of
316
- // the registry, unless overridden somewhere else.
317
- settableGetter(data, 'metrics-registry', () => this.#get('registry'))
321
+ this.#loadObject(defaultsObject, 'default', 'default values')
322
+
323
+ const { data } = this.data.get('default')
318
324
 
319
325
  // if the prefix is set on cli, env, or userconfig, then we need to
320
326
  // default the globalconfig file to that location, instead of the default
@@ -446,7 +452,7 @@ class Config {
446
452
  nopt.invalidHandler = (k, val, type) =>
447
453
  this.invalidHandler(k, val, type, obj.source, where)
448
454
 
449
- nopt.clean(obj.data, this.types, this.typeDefs)
455
+ nopt.clean(obj.data, this.types, typeDefs)
450
456
 
451
457
  nopt.invalidHandler = null
452
458
  return obj[_valid]
package/lib/umask.js CHANGED
@@ -1,5 +1,9 @@
1
1
  class Umask {}
2
2
  const parse = val => {
3
+ // this is run via nopt and parse field where everything is
4
+ // converted to a string first, ignoring coverage for now
5
+ // instead of figuring out what is happening under the hood in nopt
6
+ // istanbul ignore else
3
7
  if (typeof val === 'string') {
4
8
  if (/^0o?[0-7]+$/.test(val)) {
5
9
  return parseInt(val.replace(/^0o?/, ''), 8)
@@ -8,15 +12,16 @@ const parse = val => {
8
12
  } else {
9
13
  throw new Error(`invalid umask value: ${val}`)
10
14
  }
15
+ } else {
16
+ if (typeof val !== 'number') {
17
+ throw new Error(`invalid umask value: ${val}`)
18
+ }
19
+ val = Math.floor(val)
20
+ if (val < 0 || val > 511) {
21
+ throw new Error(`invalid umask value: ${val}`)
22
+ }
23
+ return val
11
24
  }
12
- if (typeof val !== 'number') {
13
- throw new Error(`invalid umask value: ${val}`)
14
- }
15
- val = Math.floor(val)
16
- if (val < 0 || val > 511) {
17
- throw new Error(`invalid umask value: ${val}`)
18
- }
19
- return val
20
25
  }
21
26
 
22
27
  const validate = (data, k, val) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@npmcli/config",
3
- "version": "6.2.0",
3
+ "version": "7.0.0",
4
4
  "files": [
5
5
  "bin/",
6
6
  "lib/"
@@ -24,8 +24,6 @@
24
24
  "template-oss-apply": "template-oss-apply --force"
25
25
  },
26
26
  "tap": {
27
- "check-coverage": true,
28
- "coverage-map": "map.js",
29
27
  "nyc-arg": [
30
28
  "--exclude",
31
29
  "tap-snapshots/**"
@@ -33,11 +31,13 @@
33
31
  },
34
32
  "devDependencies": {
35
33
  "@npmcli/eslint-config": "^4.0.0",
36
- "@npmcli/template-oss": "4.14.1",
34
+ "@npmcli/mock-globals": "^1.0.0",
35
+ "@npmcli/template-oss": "4.18.0",
37
36
  "tap": "^16.3.4"
38
37
  },
39
38
  "dependencies": {
40
39
  "@npmcli/map-workspaces": "^3.0.2",
40
+ "ci-info": "^3.8.0",
41
41
  "ini": "^4.1.0",
42
42
  "nopt": "^7.0.0",
43
43
  "proc-log": "^3.0.0",
@@ -50,6 +50,6 @@
50
50
  },
51
51
  "templateOSS": {
52
52
  "//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
53
- "version": "4.14.1"
53
+ "version": "4.18.0"
54
54
  }
55
55
  }