@npmcli/config 4.0.1 → 4.2.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.
@@ -7,8 +7,8 @@ module.exports = (f, env) => f.replace(envExpr, (orig, esc, 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
@@ -366,7 +366,7 @@ class Config {
366
366
  if (!/^npm_config_/i.test(envKey) || envVal === '') {
367
367
  continue
368
368
  }
369
- const key = envKey.substr('npm_config_'.length)
369
+ const key = envKey.slice('npm_config_'.length)
370
370
  .replace(/(?!^)_/g, '-') // don't replace _ at the start of the key
371
371
  .toLowerCase()
372
372
  conf[key] = envVal
@@ -396,13 +396,13 @@ class Config {
396
396
  validate (where) {
397
397
  if (!where) {
398
398
  let valid = true
399
- for (const [where] of this.data.entries()) {
399
+ for (const [entryWhere] of this.data.entries()) {
400
400
  // no need to validate our defaults, we know they're fine
401
401
  // cli was already validated when parsed the first time
402
- if (where === 'default' || where === 'builtin' || where === 'cli') {
402
+ if (entryWhere === 'default' || entryWhere === 'builtin' || entryWhere === 'cli') {
403
403
  continue
404
404
  }
405
- const ret = this.validate(where)
405
+ const ret = this.validate(entryWhere)
406
406
  valid = valid && ret
407
407
  }
408
408
  return valid
@@ -506,10 +506,9 @@ class Config {
506
506
  }
507
507
 
508
508
  [_checkDeprecated] (key, where, obj, kv) {
509
- // XXX a future npm version will make this a warning.
510
- // An even more future npm version will make this an error.
509
+ // XXX(npm9+) make this throw an error
511
510
  if (this.deprecated[key]) {
512
- log.verbose('config', key, this.deprecated[key])
511
+ log.warn('config', key, this.deprecated[key])
513
512
  }
514
513
  }
515
514
 
@@ -699,9 +698,11 @@ class Config {
699
698
  this.delete(`${nerfed}:_password`, 'user')
700
699
  this.delete(`${nerfed}:username`, 'user')
701
700
  this.delete(`${nerfed}:email`, 'user')
701
+ this.delete(`${nerfed}:certfile`, 'user')
702
+ this.delete(`${nerfed}:keyfile`, 'user')
702
703
  }
703
704
 
704
- setCredentialsByURI (uri, { token, username, password, email }) {
705
+ setCredentialsByURI (uri, { token, username, password, email, certfile, keyfile }) {
705
706
  const nerfed = nerfDart(uri)
706
707
  const def = nerfDart(this.get('registry'))
707
708
 
@@ -734,6 +735,11 @@ class Config {
734
735
  this.delete(`${nerfed}:-authtoken`, 'user')
735
736
  this.delete(`${nerfed}:_authtoken`, 'user')
736
737
  this.delete(`${nerfed}:email`, 'user')
738
+ if (certfile && keyfile) {
739
+ this.set(`${nerfed}:certfile`, certfile, 'user')
740
+ this.set(`${nerfed}:keyfile`, keyfile, 'user')
741
+ // cert/key may be used in conjunction with other credentials, thus no `else`
742
+ }
737
743
  if (token) {
738
744
  this.set(`${nerfed}:_authToken`, token, 'user')
739
745
  this.delete(`${nerfed}:_password`, 'user')
@@ -751,7 +757,7 @@ class Config {
751
757
  // protects against shoulder-hacks if password is memorable, I guess?
752
758
  const encoded = Buffer.from(password, 'utf8').toString('base64')
753
759
  this.set(`${nerfed}:_password`, encoded, 'user')
754
- } else {
760
+ } else if (!certfile || !keyfile) {
755
761
  throw new Error('No credentials to set.')
756
762
  }
757
763
  }
@@ -766,6 +772,14 @@ class Config {
766
772
  creds.email = email
767
773
  }
768
774
 
775
+ const certfileReg = this.get(`${nerfed}:certfile`)
776
+ const keyfileReg = this.get(`${nerfed}:keyfile`)
777
+ if (certfileReg && keyfileReg) {
778
+ creds.certfile = certfileReg
779
+ creds.keyfile = keyfileReg
780
+ // cert/key may be used in conjunction with other credentials, thus no `return`
781
+ }
782
+
769
783
  const tokenReg = this.get(`${nerfed}:_authToken`) ||
770
784
  this.get(`${nerfed}:_authtoken`) ||
771
785
  this.get(`${nerfed}:-authtoken`) ||
@@ -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": "4.0.1",
3
+ "version": "4.2.0",
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.8.1",
34
- "tap": "^15.1.6"
33
+ "@npmcli/eslint-config": "^3.0.1",
34
+ "@npmcli/template-oss": "3.5.0",
35
+ "tap": "^16.0.1"
35
36
  },
36
37
  "dependencies": {
37
- "@npmcli/map-workspaces": "^2.0.1",
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.8.1"
51
+ "//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
52
+ "version": "3.5.0"
51
53
  }
52
54
  }