(cwd?: string)
| 101 | } |
| 102 | |
| 103 | export function loadConfig(cwd?: string): LoadConfigResult { |
| 104 | const workingDir = cwd ?? process.cwd(); |
| 105 | const sources: string[] = []; |
| 106 | |
| 107 | const userConfigPath = resolveConfigPath('user', workingDir); |
| 108 | const userResult = readConfigSafely({ absPath: userConfigPath }); |
| 109 | let merged: Record<string, unknown> = {}; |
| 110 | if (userResult.valid && userResult.source !== undefined) { |
| 111 | merged = deepMerge(merged, userResult.value as unknown as Record<string, unknown>); |
| 112 | sources.push(userConfigPath); |
| 113 | } else if (!userResult.valid) { |
| 114 | } |
| 115 | |
| 116 | const projectConfigPath = resolve(workingDir, OK_DIR, CONFIG_FILENAME); |
| 117 | const projectFile = loadYamlFile(projectConfigPath); |
| 118 | if (projectFile.value !== null) { |
| 119 | const removedKeyErrors = detectRemovedKeys({ |
| 120 | value: projectFile.value, |
| 121 | file: projectFile.path, |
| 122 | source: projectFile.source, |
| 123 | doc: projectFile.doc, |
| 124 | }); |
| 125 | if (removedKeyErrors.length > 0) { |
| 126 | throw new Error(removedKeyErrors.map(humanFormat).join('\n\n')); |
| 127 | } |
| 128 | merged = deepMerge(merged, projectFile.value); |
| 129 | sources.push(projectConfigPath); |
| 130 | } |
| 131 | |
| 132 | const result = ConfigSchema.safeParse(merged); |
| 133 | if (!result.success) { |
| 134 | const issues = annotateIssuesWithSource(result.error.issues, projectFile); |
| 135 | const error: ConfigValidationError = { code: 'SCHEMA_INVALID', issues }; |
| 136 | throw new Error(humanFormat(error)); |
| 137 | } |
| 138 | |
| 139 | return { config: result.data, sources }; |
| 140 | } |
| 141 | |
| 142 | interface CreateProjectConfigResolverOptions { |
| 143 | startupCwd: string; |
no test coverage detected