Skip to content
This repository has been archived by the owner on Nov 3, 2022. It is now read-only.

Commit

Permalink
feat: Add ability to deprecate singular config values
Browse files Browse the repository at this point in the history
  • Loading branch information
jumoel committed Jul 1, 2022
1 parent 98eb307 commit 65af934
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions 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 65af934

Please sign in to comment.