( options: LoadProjectConfigOptions, )
| 292 | } |
| 293 | |
| 294 | export async function loadProjectConfig( |
| 295 | options: LoadProjectConfigOptions, |
| 296 | ): Promise<LoadProjectConfigResult> { |
| 297 | const configPath = getConfigPath(options.cwd); |
| 298 | |
| 299 | if (!options.fs.existsSync(configPath)) { |
| 300 | return { found: false }; |
| 301 | } |
| 302 | |
| 303 | try { |
| 304 | const rawText = await options.fs.readFile(configPath, 'utf8'); |
| 305 | const parsed = parseProjectConfig(rawText); |
| 306 | const notices: string[] = []; |
| 307 | |
| 308 | let config = normalizeDebuggerBackend(parsed); |
| 309 | |
| 310 | if (parsed.enabledWorkflows !== undefined) { |
| 311 | const normalizedWorkflows = normalizeEnabledWorkflows(parsed.enabledWorkflows); |
| 312 | config = { ...config, enabledWorkflows: normalizedWorkflows }; |
| 313 | } |
| 314 | if (parsed.customWorkflows !== undefined) { |
| 315 | const normalizedCustomWorkflows = normalizeCustomWorkflows(parsed.customWorkflows); |
| 316 | config = { ...config, customWorkflows: normalizedCustomWorkflows }; |
| 317 | } |
| 318 | |
| 319 | if (config.sessionDefaults) { |
| 320 | const normalized = normalizeMutualExclusivity(config.sessionDefaults); |
| 321 | notices.push(...normalized.notices); |
| 322 | const resolved = resolveRelativeSessionPaths(normalized.normalized, options.cwd); |
| 323 | config = { ...config, sessionDefaults: resolved }; |
| 324 | } |
| 325 | |
| 326 | if (config.sessionDefaultsProfiles) { |
| 327 | const normalizedProfiles = normalizeSessionDefaultsProfiles( |
| 328 | config.sessionDefaultsProfiles, |
| 329 | options.cwd, |
| 330 | ); |
| 331 | notices.push(...normalizedProfiles.notices); |
| 332 | config = { ...config, sessionDefaultsProfiles: normalizedProfiles.profiles }; |
| 333 | } |
| 334 | |
| 335 | config = resolveRelativeTopLevelPaths(config, options.cwd); |
| 336 | |
| 337 | return { found: true, path: configPath, config, notices }; |
| 338 | } catch (error) { |
| 339 | return { found: false, path: configPath, error: toError(error) }; |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | export async function persistSessionDefaultsToProjectConfig( |
| 344 | options: PersistSessionDefaultsOptions, |
no test coverage detected