From ee841d3c8d58f83bb5133d14daeeb9d39fc392c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20M=C3=B8ller=20Ellehauge?= Date: Tue, 28 Jun 2022 13:57:13 +0200 Subject: [PATCH] WIP --- lib/utils/config/definition.js | 1 + lib/utils/config/definitions.js | 3 ++- node_modules/@npmcli/config/lib/index.js | 14 ++++++++++++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/utils/config/definition.js b/lib/utils/config/definition.js index f88d8334cf01f..1ac86a43059d3 100644 --- a/lib/utils/config/definition.js +++ b/lib/utils/config/definition.js @@ -12,6 +12,7 @@ const allowed = [ 'default', 'defaultDescription', 'deprecated', + 'deprecatedValues', 'description', 'flatten', 'hint', diff --git a/lib/utils/config/definitions.js b/lib/utils/config/definitions.js index 6b35e7d4d05b4..87e97f22af875 100644 --- a/lib/utils/config/definitions.js +++ b/lib/utils/config/definitions.js @@ -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\`. diff --git a/node_modules/@npmcli/config/lib/index.js b/node_modules/@npmcli/config/lib/index.js index 5b7ea68e91e36..e2a7a4a83994a 100644 --- a/node_modules/@npmcli/config/lib/index.js +++ b/node_modules/@npmcli/config/lib/index.js @@ -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 @@ -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]); } }