From 35162b7591bce73ff6c5f6c93e1bda8cbc8ee221 Mon Sep 17 00:00:00 2001 From: Jakob Rosenberg Date: Sat, 24 Oct 2020 09:43:45 +0200 Subject: [PATCH] fix: key was missing from $map warnings --- lib/utils/index.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/utils/index.js b/lib/utils/index.js index 72c0186..db421cb 100644 --- a/lib/utils/index.js +++ b/lib/utils/index.js @@ -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] @@ -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)}`) @@ -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)}` )