| 616 | } |
| 617 | |
| 618 | export async function initConfigStore(opts: { |
| 619 | cwd: string; |
| 620 | fs: FileSystemExecutor; |
| 621 | overrides?: RuntimeConfigOverrides; |
| 622 | env?: NodeJS.ProcessEnv; |
| 623 | }): Promise<{ found: boolean; path?: string; notices: string[] }> { |
| 624 | storeState.cwd = opts.cwd; |
| 625 | storeState.fs = opts.fs; |
| 626 | storeState.env = opts.env; |
| 627 | storeState.overrides = opts.overrides; |
| 628 | |
| 629 | let fileConfig: ProjectConfig | undefined; |
| 630 | let found = false; |
| 631 | let path: string | undefined; |
| 632 | let notices: string[] = []; |
| 633 | |
| 634 | try { |
| 635 | const result = await loadProjectConfig({ fs: opts.fs, cwd: opts.cwd }); |
| 636 | if (result.found) { |
| 637 | fileConfig = result.config; |
| 638 | found = true; |
| 639 | path = result.path; |
| 640 | notices = result.notices; |
| 641 | } else if ('error' in result) { |
| 642 | const errorMessage = |
| 643 | result.error instanceof Error ? result.error.message : String(result.error); |
| 644 | log('warn', `Failed to read or parse project config at ${result.path}. ${errorMessage}`); |
| 645 | log('warn', '[infra/config-store] project config read/parse failed', { sentry: true }); |
| 646 | } |
| 647 | } catch (error) { |
| 648 | log('warn', `Failed to load project config from ${opts.cwd}. ${error}`); |
| 649 | log('warn', `[infra/config-store] project config load threw (${getErrorKind(error)})`, { |
| 650 | sentry: true, |
| 651 | }); |
| 652 | } |
| 653 | |
| 654 | storeState.fileConfig = fileConfig; |
| 655 | storeState.resolved = resolveConfig({ fileConfig, overrides: opts.overrides, env: opts.env }); |
| 656 | storeState.initialized = true; |
| 657 | return { found, path, notices }; |
| 658 | } |
| 659 | |
| 660 | export function getConfig(): ResolvedRuntimeConfig { |
| 661 | if (!storeState.initialized) { |