Skip to content

Commit

Permalink
perf: memoize to config loader
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Oct 10, 2024
1 parent 7a72d72 commit e16847f
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/main/js/config.js
Original file line number Diff line number Diff line change
@@ -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 = [
Expand All @@ -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),
Expand Down

0 comments on commit e16847f

Please sign in to comment.