Skip to content
This repository was archived by the owner on Nov 3, 2022. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion 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,7 +511,13 @@ class Config {

[_checkDeprecated] (key, where, obj, kv) {
// XXX(npm9+) make this throw an error
if (this.deprecated[key]) {
const value = obj[key]
const hasDeprecatedValues = Array.isArray(this.deprecatedValues[key])
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should deprecatedValues perhaps be a function instead, to make it more generic and work on arbitrary types like Number?

const warn =
(hasDeprecatedValues && this.deprecatedValues[key].includes(value)) ||
(!hasDeprecatedValues && this.deprecated[key])

if (warn) {
log.warn('config', key, this.deprecated[key])
}
}
Expand Down