2026-07-31 02:00:01 +08:00
|
|
|
/**
|
2026-08-06 04:40:32 +08:00
|
|
|
* Config-dump entry for `dsh --profile <name> --dump-config`: compose the
|
|
|
|
|
* profile's patch layers through the include plugin's patch algorithm without
|
|
|
|
|
* booting or evaluating `!!js`, with one provenance layer per bundle, the
|
|
|
|
|
* profile's own patch file, and each `--patch` overlay.
|
2026-07-31 02:00:01 +08:00
|
|
|
* @module @deepseek-ai/dsh/dump-config
|
|
|
|
|
*/
|
|
|
|
|
|
2026-08-06 04:40:32 +08:00
|
|
|
import { existsSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
|
|
|
|
|
import { tmpdir } from 'node:os'
|
|
|
|
|
import { join, resolve } from 'node:path'
|
2026-07-31 02:00:01 +08:00
|
|
|
import {
|
2026-08-06 04:40:32 +08:00
|
|
|
healProfilesModuleFallback,
|
2026-07-31 02:00:01 +08:00
|
|
|
loadOverlayPatches,
|
2026-08-06 04:40:32 +08:00
|
|
|
loadProfile,
|
2026-07-31 02:00:01 +08:00
|
|
|
renderConfigDump,
|
|
|
|
|
type ConfigDumpLayer,
|
|
|
|
|
} from '@deepseek-ai/dsh-app-boot'
|
2026-08-06 04:40:32 +08:00
|
|
|
import { INSTALL_ANCHOR } from './profile-boot.ts'
|
2026-07-31 02:00:01 +08:00
|
|
|
|
|
|
|
|
const NAME = 'dsh'
|
|
|
|
|
|
2026-08-04 10:07:17 +08:00
|
|
|
/* v8 ignore start -- built-bin acceptance drives this boot-free dispatch */
|
2026-07-31 02:00:01 +08:00
|
|
|
/**
|
2026-08-06 04:40:32 +08:00
|
|
|
* Print a profile composition with provenance comments.
|
|
|
|
|
* @param profile - the profile name.
|
|
|
|
|
* @param defaultOnly - omit the profile's user layer and `--patch` overlays.
|
|
|
|
|
* @param patches - `--patch` overlay paths, in argv order.
|
2026-07-31 02:00:01 +08:00
|
|
|
*/
|
2026-08-06 04:40:32 +08:00
|
|
|
export function runDumpConfig(profile: string, defaultOnly: boolean, patches: readonly string[]): void {
|
|
|
|
|
healProfilesModuleFallback(INSTALL_ANCHOR)
|
|
|
|
|
const loaded = loadProfile(NAME, profile, INSTALL_ANCHOR)
|
|
|
|
|
const layers: ConfigDumpLayer[] = loaded.layers.map(layer => ({
|
|
|
|
|
label: layer.packageName,
|
|
|
|
|
patches: layer.patches,
|
|
|
|
|
}))
|
|
|
|
|
if (!defaultOnly) {
|
|
|
|
|
if (existsSync(loaded.patchPath)) {
|
|
|
|
|
layers.push({ label: loaded.patchPath, patches: loaded.patches })
|
2026-07-31 02:00:01 +08:00
|
|
|
}
|
2026-08-06 04:40:32 +08:00
|
|
|
for (const file of patches) {
|
|
|
|
|
const absolute = resolve(file)
|
|
|
|
|
layers.push({ label: absolute, patches: loadOverlayPatches(NAME, absolute) })
|
2026-08-04 10:07:17 +08:00
|
|
|
}
|
2026-07-31 02:00:01 +08:00
|
|
|
}
|
2026-08-06 04:40:32 +08:00
|
|
|
// renderConfigDump anchors on a base entry-list file; a profile's base is
|
|
|
|
|
// the empty list, materialized as a temp document.
|
|
|
|
|
const emptyRoot = mkdtempSync(join(tmpdir(), 'dsh-dump-'))
|
|
|
|
|
const emptyRootFile = join(emptyRoot, 'profile-root.yml')
|
|
|
|
|
writeFileSync(emptyRootFile, '[]\n')
|
|
|
|
|
try {
|
|
|
|
|
process.stdout.write(renderConfigDump(NAME, emptyRootFile, layers))
|
|
|
|
|
} finally {
|
|
|
|
|
rmSync(emptyRoot, { recursive: true, force: true })
|
|
|
|
|
}
|
2026-07-31 02:00:01 +08:00
|
|
|
}
|
|
|
|
|
/* v8 ignore stop */
|