Skip to content

Commit

Permalink
perf: resolve config once
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Feb 12, 2024
1 parent 2c6fb22 commit 62a757a
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,30 @@ export interface Config {
generators?: Record<string, Generator>;
}

export type ResolvedConfig = { [P in keyof Config]-?: Config[P] };
const RESOLVED_CONFIG_SYMBOL = Symbol("automdConfig");

export type ResolvedConfig = { [P in keyof Config]-?: Config[P] } & {
[RESOLVED_CONFIG_SYMBOL]: true;
};

export function resolveConfig(
config?: Config | ResolvedConfig,
): ResolvedConfig {
if (config && RESOLVED_CONFIG_SYMBOL in config) {
return config as ResolvedConfig;
}

export function resolveConfig(config: Config | null): ResolvedConfig {
const _config = <ResolvedConfig>{
dir: ".",
file: "README.md",
generators: {},
[RESOLVED_CONFIG_SYMBOL]: true,
...config,
};

_config.dir = resolve(_config.dir);
_config.file = resolve(_config.dir, _config.file);

return _config;
}

Expand All @@ -49,5 +62,5 @@ export async function loadConfig(
overrides,
});

return resolveConfig(config);
return resolveConfig(config as Config);
}

0 comments on commit 62a757a

Please sign in to comment.