@npmcli/config 10.0.0 → 10.1.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.
@@ -461,7 +461,7 @@ const definitions = {
461
461
  depth: new Definition('depth', {
462
462
  default: null,
463
463
  defaultDescription: `
464
- \`Infinity\` if \`--all\` is set, otherwise \`1\`
464
+ \`Infinity\` if \`--all\` is set, otherwise \`0\`
465
465
  `,
466
466
  type: [null, Number],
467
467
  description: `
@@ -954,6 +954,14 @@ const definitions = {
954
954
  more information, or [npm init](/commands/npm-init).
955
955
  `,
956
956
  }),
957
+ 'init-type': new Definition('init-type', {
958
+ default: 'commonjs',
959
+ type: String,
960
+ hint: '<type>',
961
+ description: `
962
+ The value that \`npm init\` should use by default for the package.json type field.
963
+ `,
964
+ }),
957
965
  'init-version': new Definition('init-version', {
958
966
  default: '1.0.0',
959
967
  type: Semver,
@@ -2231,7 +2239,6 @@ const definitions = {
2231
2239
  workspaces: new Definition('workspaces', {
2232
2240
  default: null,
2233
2241
  type: [null, Boolean],
2234
- short: 'ws',
2235
2242
  envExport: false,
2236
2243
  description: `
2237
2244
  Set to true to run the command in the context of **all** configured
@@ -55,12 +55,26 @@ const shorthands = {
55
55
  readonly: ['--read-only'],
56
56
  reg: ['--registry'],
57
57
  iwr: ['--include-workspace-root'],
58
+ ws: ['--workspaces'],
58
59
  ...definitionProps.shorthands,
59
60
  }
60
61
 
62
+ // These are the configs that we can nerf-dart. Only _auth even has a config definition so we have to explicitly validate them here.
63
+ // This is used to validate during "npm config set" and to not warn on loading unknown configs when we see these.
64
+ const nerfDarts = [
65
+ '_auth', // Has a config
66
+ '_authToken', // Does not have a config
67
+ '_password', // Does not have a config
68
+ 'certfile', // Does not have a config
69
+ 'email', // Does not have a config
70
+ 'keyfile', // Does not have a config
71
+ 'username', // Does not have a config
72
+ ]
73
+
61
74
  module.exports = {
62
75
  defaults: definitionProps.defaults,
63
76
  definitions,
64
77
  flatten,
78
+ nerfDarts,
65
79
  shorthands,
66
80
  }
package/lib/index.js CHANGED
@@ -15,6 +15,14 @@ const {
15
15
  mkdir,
16
16
  } = require('node:fs/promises')
17
17
 
18
+ // TODO these need to be either be ignored when parsing env, formalized as config, or not exported to the env in the first place. For now this list is just to suppress warnings till we can pay off this tech debt.
19
+ const internalEnv = [
20
+ 'global-prefix',
21
+ 'local-prefix',
22
+ 'npm-version',
23
+ 'node-gyp',
24
+ ]
25
+
18
26
  const fileExists = (...p) => stat(resolve(...p))
19
27
  .then((st) => st.isFile())
20
28
  .catch(() => false)
@@ -61,6 +69,7 @@ class Config {
61
69
  definitions,
62
70
  shorthands,
63
71
  flatten,
72
+ nerfDarts = [],
64
73
  npmPath,
65
74
 
66
75
  // options just to override in tests, mostly
@@ -71,8 +80,9 @@ class Config {
71
80
  cwd = process.cwd(),
72
81
  excludeNpmCwd = false,
73
82
  }) {
74
- // turn the definitions into nopt's weirdo syntax
83
+ this.nerfDarts = nerfDarts
75
84
  this.definitions = definitions
85
+ // turn the definitions into nopt's weirdo syntax
76
86
  const types = {}
77
87
  const defaults = {}
78
88
  this.deprecated = {}
@@ -272,6 +282,7 @@ class Config {
272
282
  }
273
283
 
274
284
  try {
285
+ // This does not have an actual definition
275
286
  defaultsObject['npm-version'] = require(join(this.npmPath, 'package.json')).version
276
287
  } catch {
277
288
  // in some weird state where the passed in npmPath does not have a package.json
@@ -346,6 +357,11 @@ class Config {
346
357
  }
347
358
 
348
359
  loadCLI () {
360
+ for (const s of Object.keys(this.shorthands)) {
361
+ if (s.length > 1 && this.argv.includes(`-${s}`)) {
362
+ log.warn(`-${s} is not a valid single-hyphen cli flag and will be removed in the future`)
363
+ }
364
+ }
349
365
  nopt.invalidHandler = (k, val, type) =>
350
366
  this.invalidHandler(k, val, type, 'command line options', 'cli')
351
367
  const conf = nopt(this.types, this.shorthands, this.argv)
@@ -566,13 +582,32 @@ class Config {
566
582
  }
567
583
  }
568
584
  }
585
+ // Some defaults like npm-version are not user-definable and thus don't have definitions
586
+ if (where !== 'default') {
587
+ this.checkUnknown(where, key)
588
+ }
569
589
  conf.data[k] = v
570
590
  }
571
591
  }
572
592
  }
573
593
 
594
+ checkUnknown (where, key) {
595
+ if (!this.definitions[key]) {
596
+ if (internalEnv.includes(key)) {
597
+ return
598
+ }
599
+ if (!key.includes(':')) {
600
+ log.warn(`Unknown ${where} config "${where === 'cli' ? '--' : ''}${key}". This will stop working in the next major version of npm.`)
601
+ return
602
+ }
603
+ const baseKey = key.split(':').pop()
604
+ if (!this.definitions[baseKey] && !this.nerfDarts.includes(baseKey)) {
605
+ log.warn(`Unknown ${where} config "${baseKey}" (${key}). This will stop working in the next major version of npm.`)
606
+ }
607
+ }
608
+ }
609
+
574
610
  #checkDeprecated (key) {
575
- // XXX(npm9+) make this throw an error
576
611
  if (this.deprecated[key]) {
577
612
  log.warn('config', key, this.deprecated[key])
578
613
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@npmcli/config",
3
- "version": "10.0.0",
3
+ "version": "10.1.0",
4
4
  "files": [
5
5
  "bin/",
6
6
  "lib/"
@@ -41,7 +41,7 @@
41
41
  "@npmcli/package-json": "^6.0.1",
42
42
  "ci-info": "^4.0.0",
43
43
  "ini": "^5.0.0",
44
- "nopt": "^8.0.0",
44
+ "nopt": "^8.1.0",
45
45
  "proc-log": "^5.0.0",
46
46
  "semver": "^7.3.5",
47
47
  "walk-up-path": "^4.0.0"