UNPKG

@baseplate-dev/sync

Version:

Library for syncing Baseplate descriptions

30 lines 1.1 kB
import { diffComm } from 'node-diff3'; /** * This algorithm just does a simple 2-way diff between the user's text and the baseplate's text * and returns the merged text without any base reference. * * @param input - Input for the merge algorithm * @returns Merged text and a boolean indicating if there was a conflict */ export const simpleDiffAlgorithm = ({ previousWorkingText, currentGeneratedText, }) => { const patch = diffComm(previousWorkingText.split('\n'), currentGeneratedText.split('\n')); const isCommonCommResult = (r) => 'common' in r; return { mergedText: patch .flatMap((result) => { if (isCommonCommResult(result)) { return result.common; } return [ '<<<<<<< existing', ...result.buffer1, '=======', ...result.buffer2, '>>>>>>> baseplate', ]; }) .join('\n'), hasConflict: patch.some((result) => !isCommonCommResult(result)), }; }; //# sourceMappingURL=simple-diff.js.map