( options: PersistProjectConfigPatchOptions, )
| 401 | } |
| 402 | |
| 403 | export async function persistProjectConfigPatch( |
| 404 | options: PersistProjectConfigPatchOptions, |
| 405 | ): Promise<{ path: string }> { |
| 406 | const configDir = getConfigDir(options.cwd); |
| 407 | const configPath = getConfigPath(options.cwd); |
| 408 | |
| 409 | await options.fs.mkdir(configDir, { recursive: true }); |
| 410 | const baseConfig = await readBaseConfigForPersistence({ fs: options.fs, configPath }); |
| 411 | |
| 412 | const nextConfig: ProjectConfig = { |
| 413 | ...baseConfig, |
| 414 | schemaVersion: 1, |
| 415 | }; |
| 416 | |
| 417 | if (options.patch.enabledWorkflows !== undefined) { |
| 418 | nextConfig.enabledWorkflows = normalizeEnabledWorkflows(options.patch.enabledWorkflows); |
| 419 | } |
| 420 | |
| 421 | const topLevelPatch = removeUndefined({ |
| 422 | debug: options.patch.debug, |
| 423 | sentryDisabled: options.patch.sentryDisabled, |
| 424 | experimentalWorkflowDiscovery: options.patch.experimentalWorkflowDiscovery, |
| 425 | disableSessionDefaults: options.patch.disableSessionDefaults, |
| 426 | filePathRenderStyle: options.patch.filePathRenderStyle, |
| 427 | }); |
| 428 | |
| 429 | for (const [key, value] of Object.entries(topLevelPatch)) { |
| 430 | nextConfig[key] = value; |
| 431 | } |
| 432 | |
| 433 | if (options.patch.setupPreferences === null) { |
| 434 | delete nextConfig.setupPreferences; |
| 435 | } else if (options.patch.setupPreferences !== undefined) { |
| 436 | nextConfig.setupPreferences = options.patch.setupPreferences; |
| 437 | } |
| 438 | |
| 439 | if (options.patch.sessionDefaults) { |
| 440 | const patch = removeUndefined(options.patch.sessionDefaults as Record<string, unknown>); |
| 441 | const nextSessionDefaults: Partial<SessionDefaults> = { |
| 442 | ...(nextConfig.sessionDefaults ?? {}), |
| 443 | ...patch, |
| 444 | }; |
| 445 | |
| 446 | for (const key of options.deleteSessionDefaultKeys ?? []) { |
| 447 | delete nextSessionDefaults[key]; |
| 448 | } |
| 449 | |
| 450 | nextConfig.sessionDefaults = nextSessionDefaults; |
| 451 | } |
| 452 | |
| 453 | await options.fs.writeFile(configPath, stringifyYaml(nextConfig), 'utf8'); |
| 454 | |
| 455 | return { path: configPath }; |
| 456 | } |
no test coverage detected