dump-config.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /**
  2. * Config-dump entry for `dsh --profile <name> --dump-config`: compose the
  3. * profile's patch layers through the include plugin's patch algorithm without
  4. * booting or evaluating `!!js`, with one source layer per bundle, the
  5. * profile's own patch file, and each `--patch` overlay.
  6. * @module @deepseek-ai/dsh/dump-config
  7. */
  8. import { existsSync } from 'node:fs'
  9. import { join, resolve } from 'node:path'
  10. import {
  11. loadOptionalPatches,
  12. loadOverlayPatches,
  13. renderConfigDump,
  14. type ConfigDumpLayer,
  15. } from '@deepseek-ai/dsh-app-boot'
  16. import { homePatchPath, prepareProfile, PROFILE_ROOT_FILENAME } from './profile-boot.ts'
  17. const NAME = 'dsh'
  18. /* v8 ignore start -- built-bin acceptance drives this boot-free dispatch */
  19. /**
  20. * Print a profile composition with comments naming each source file and patch layer.
  21. * @param profile - the profile name.
  22. * @param defaultOnly - omit the profile's user layer and `--patch` overlays
  23. * (the recovery diagnostic for a broken `cordis.patch.yml`, which is then
  24. * never parsed).
  25. * @param patches - `--patch` overlay paths, in argv order.
  26. */
  27. export function runDumpConfig(profile: string, defaultOnly: boolean, patches: readonly string[]): void {
  28. const loaded = prepareProfile(profile, !defaultOnly)
  29. const layers: ConfigDumpLayer[] = loaded.layers.map(layer => ({
  30. label: layer.packageName,
  31. patches: layer.patches,
  32. }))
  33. if (!defaultOnly) {
  34. if (existsSync(loaded.patchPath)) {
  35. layers.push({ label: loaded.patchPath, patches: loaded.patches })
  36. }
  37. const homePatchFile = homePatchPath()
  38. const homePatches = loadOptionalPatches(NAME, homePatchFile)
  39. if (homePatches !== undefined) {
  40. layers.push({ label: homePatchFile, patches: homePatches })
  41. }
  42. for (const file of patches) {
  43. const absolute = resolve(file)
  44. layers.push({ label: absolute, patches: loadOverlayPatches(NAME, absolute) })
  45. }
  46. }
  47. // The dump anchors on the same empty root file the boot includes.
  48. process.stdout.write(renderConfigDump(NAME, join(loaded.dir, PROFILE_ROOT_FILENAME), layers))
  49. }
  50. /* v8 ignore stop */