diff --git a/src/main/js/config.js b/src/main/js/config.js index 771e0f2..97fbf9a 100644 --- a/src/main/js/config.js +++ b/src/main/js/config.js @@ -1,5 +1,5 @@ import { cosmiconfig } from 'cosmiconfig' -import { camelize } from './util.js' +import { camelize, memoizeBy } from './util.js' const CONFIG_NAME = 'release' const CONFIG_FILES = [ @@ -25,14 +25,14 @@ export const defaultConfig = { } export const getPkgConfig = async (...cwds) => - normalizePkgConfig((await Promise.all(cwds.map( - cwd => cosmiconfig(CONFIG_NAME, { - searchPlaces: CONFIG_FILES, - searchStrategy: 'global', // https://github.com/cosmiconfig/cosmiconfig/releases/tag/v9.0.0 - }) - .search(cwd) - .then(r => r?.config) - ))).find(Boolean) || defaultConfig) + normalizePkgConfig((await Promise.all(cwds.map(readPkgConfig))).find(Boolean) || defaultConfig) + +export const readPkgConfig = memoizeBy(async (cwd) => cosmiconfig(CONFIG_NAME, { + searchPlaces: CONFIG_FILES, + searchStrategy: 'global', // https://github.com/cosmiconfig/cosmiconfig/releases/tag/v9.0.0 +}) + .search(cwd) + .then(r => r?.config)) export const normalizePkgConfig = (config, env) => ({ ...parseEnv(env),