UNPKG

@baseplate-dev/sync

Version:

Library for syncing Baseplate descriptions

25 lines 868 B
import { parse } from 'yaml'; import { yamlDiffPatch } from 'yaml-diff-patch'; /** * Merges YAML strings using a 3-way merge algorithm */ export const yamlMergeAlgorithm = (input) => { try { // Parse YAML strings to JSON objects const originalJson = parse(input.previousGeneratedText); const newJson = parse(input.currentGeneratedText); const existingYaml = input.previousWorkingText; // Use yamlDiffPatch to apply the JSON diff as a patch to the YAML // This preserves whitespace, comments, and structure const result = yamlDiffPatch(existingYaml, originalJson, newJson); return { mergedText: result, hasConflict: false, }; } catch { // default to merge strings method if patching fails return null; } }; //# sourceMappingURL=yaml.js.map