Skip to content

Commit

Permalink
fix: key was missing from $map warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobrosenberg committed Oct 24, 2020
1 parent 612932f commit 35162b7
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ async function keysAsFunctionsRecursive(obj, suffix = '$map', breadcrumbs = [])
await Promise.all(maps.map(async ({ mapKey, value }) => {
const key = mapKey.substr(0, mapKey.length - suffix.length)
const optionsKey = `${key}$options`
const result = await keysAsFunctions(obj[optionsKey], value, breadcrumbs)
const result = await keysAsFunctions(obj[optionsKey], value, [...breadcrumbs, mapKey])
delete obj[mapKey]
delete obj[optionsKey]

Expand All @@ -98,6 +98,7 @@ async function keysAsFunctionsRecursive(obj, suffix = '$map', breadcrumbs = [])
*/
async function keysAsFunctions(obj, map, breadcrumbs) {
const name = breadcrumbs.join('.')
const targetName = name.replace(/\$map$/, '')

if (!isObject(obj))
throw new Error(`expected an object for "${name}", but got ${JSON.stringify(obj, null, 2)}`)
Expand All @@ -108,8 +109,11 @@ async function keysAsFunctions(obj, map, breadcrumbs) {
const fn = map[fnName]

if (!fn && isFn) log.warn(
`--${name}$map-- does not have a method called --${key}--. Available methods: --${Object.keys(map)}--.` +
`\nRenaming to --${key}-- or pushing the value of --${key}-- to --${name}-- will hide this message.`
`--${name}-- does not have a method called --${key}--. Available methods: --${Object.keys(map)}--.`
+ `\n To hide this message, do one of the following:`
+ `\n - Underscore the key. Ie. rename --${key}-- to --_${key}--`
+ `\n - move the value of --${key}-- to the target array. Ie. --${targetName}.push(${key})--`
+ `\n - add a noop function to the map. Ie. --${name}.${key} = x => x--.`
// `\nvalue: ${JSON.stringify(value, null, 2)}` +
// `\nobj: ${JSON.stringify(obj, null, 2)}`
)
Expand Down

0 comments on commit 35162b7

Please sign in to comment.