Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jumoel committed Jun 28, 2022
1 parent 0ce09f1 commit ee841d3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/utils/config/definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const allowed = [
'default',
'defaultDescription',
'deprecated',
'deprecatedValues',
'description',
'flatten',
'hint',
Expand Down
3 changes: 2 additions & 1 deletion lib/utils/config/definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,10 @@ define('auth-type', {
default: 'legacy',
type: ['legacy', 'webauthn', 'sso', 'saml', 'oauth'],
deprecated: `
The SSO/SAML/OAuth methods are deprecated and will be removed in
The SSO/SAML/OAuth/Webauthn methods are deprecated and will be removed in
a future version of npm in favor of web-based login.
`,
deprecatedValues: ['webauthn', 'sso', 'saml', 'oauth'],
description: `
What authentication strategy to use with \`adduser\`/\`login\`.
Expand Down
14 changes: 12 additions & 2 deletions node_modules/@npmcli/config/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,16 @@ class Config {
const types = {}
const defaults = {}
this.deprecated = {}
this.deprecatedValues = {}
for (const [key, def] of Object.entries(definitions)) {
defaults[key] = def.default
types[key] = def.type
if (def.deprecated) {
this.deprecated[key] = def.deprecated.trim().replace(/\n +/, '\n')
}
if (def.deprecatedValues) {
this.deprecatedValues[key] = def.deprecatedValues
}
}

// populated the first time we flatten the object
Expand Down Expand Up @@ -507,8 +511,14 @@ class Config {

[_checkDeprecated] (key, where, obj, kv) {
// XXX(npm9+) make this throw an error
if (this.deprecated[key]) {
log.warn('config', key, this.deprecated[key])
const value = obj[key];
const hasDeprecatedValues = Array.isArray(this.deprecatedValues[key]);
const warn =
(hasDeprecatedValues && this.deprecatedValues[key].includes(value)) ||
(!hasDeprecatedValues && this.deprecated[key]);

if (warn) {
log.warn("config", key, this.deprecated[key]);
}
}

Expand Down

0 comments on commit ee841d3

Please sign in to comment.