Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/Aquaticat/Monochromatic. TypeScript and Rust monorepo: Claude Code and Pi coding-agent plugins, a m
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384import { parseTomlEdit, tomlSet, tomlStringify, type TomlValueInput,} from '@monochromatic-dev/module-toml-edit/ts';import type { Path, } from '../types.ts';import { ABSENT_FILE_CONTENT, overwrite, readExisting,} from './write.ts';
/** Updates a single key in an existing TOML file, preserving comments and unmutated whitespace byte-identically (splice mode). Reads the destination via the shared read cache, applies one {@link tomlSet}, then routes the resulting text through {@link overwrite} so content-skip, cache update, and write-time tracking are inherited. Throws when the destination does not exist; create-from-empty is a different operation. To create an empty TOML and write keys into it, compose {@link emptyTomlEdit} + {@link tomlSet} + {@link tomlStringify} + {@link overwrite} from `\@monochromatic-dev/module-toml-edit` directly. @param dest - Path to the existing TOML file @param path - Sequence of key segments (and numeric array-of-tables indices) @param value - JS value to write at the path @throws Error when dest does not exist @throws Error from {@link parseTomlEdit} when the existing file is not valid TOML @example ```ts await overwriteTomlKey({ dest: './pkg.toml', path: ['package', 'version',], value: '1.2.3', },); ``` */export async function overwriteTomlKey( { dest, path, value, }: { readonly dest: string; readonly path: Path; readonly value: TomlValueInput; },): Promise<void> { /** Current file content; ABSENT_FILE_CONTENT when the file does not exist */ const existing = await readExisting(dest,); if (existing === ABSENT_FILE_CONTENT) throw new Error(`overwriteTomlKey: ${dest} does not exist`,); /** Parsed TOML state for the existing content */ const edit = parseTomlEdit({ source: existing, },); /** Fresh state with the pending edit recorded */ const edited = tomlSet({ edit, path, value, },); /** Updated source text; splice mode keeps unmutated regions byte-identical */ const newContent = tomlStringify({ edit: edited, },); await overwrite({ dest, content: newContent, },);}