UNPKG

json-conflict-resolver

Version:

A rules-based JSON conflict resolver that parses Git conflict markers, reconstructs ours/theirs, and merges with deterministic strategies — beyond line-based merges.

2 lines (1 loc) 3.98 kB
import{a}from"./chunk-KGHZITSW.mjs";import"./chunk-2SJFRDGH.mjs";import{c as H}from"./chunk-WFDJ25NC.mjs";import{b as R}from"./chunk-Q4E7EFS7.mjs";import"./chunk-JD45QQDD.mjs";import{a as b}from"./chunk-ICS3PEIS.mjs";import"./chunk-NHG7C4LQ.mjs";import{a as w}from"./chunk-IOL4YJZP.mjs";import{h as V,j as y}from"./chunk-HB6Q755Y.mjs";import{a as j}from"./chunk-AUIVUOKV.mjs";import{a as h,b as l,e as p,f as C,g as o,h as e}from"./chunk-WP4ACXPN.mjs";import{a as B}from"./chunk-3PFH3U2T.mjs";import"./chunk-76CZ6Z7T.mjs";import{execSync as P}from"child_process";import F from"fs/promises";e.mock("node:child_process");e.mock("node:fs/promises");e.mock("./file-parser");e.mock("./file-serializer");e.mock("./merger");e.mock("./normalizer");e.mock("./utils");e.mock("./conflict-helper");e.mock("./logger");var k=e.mocked(P),v=e.mocked(F),s=e.mocked(j),d=e.mocked(B),n=e.mocked(H),g=e.mocked(R),u=e.mocked(y),c=e.mocked(V),W=e.mocked(w),S=e.mocked(b);h("resolveConflicts",()=>{let i={info:e.fn(),debug:e.fn(),warn:e.fn(),error:e.fn(),flush:e.fn()};p(()=>{e.clearAllMocks(),S.mockResolvedValue(i),g.mockResolvedValue({debug:!1,customStrategies:{}}),c.mockResolvedValue([])}),C(()=>{e.clearAllMocks()}),l("processes files without conflicts successfully",async()=>{let t={defaultStrategy:"ours"},r={filePath:"test.json",content:"content"},m={theirs:{a:1},ours:{a:2},format:"json"},f={a:2};c.mockResolvedValue([r]),s.mockResolvedValue(m),n.mockResolvedValue(f),d.mockResolvedValue('{"a":2}'),u.mockResolvedValue("backup/test.json"),await a(t),o(g).toHaveBeenCalledWith(t),o(c).toHaveBeenCalled(),o(s).toHaveBeenCalledWith("content",{filename:"test.json"}),o(n).toHaveBeenCalledWith({ours:{a:2},theirs:{a:1},base:void 0,filePath:"test.json",conflicts:[],path:"",ctx:o.objectContaining({config:o.any(Object),strategies:{},_strategyCache:o.any(Map)}),logger:i}),o(u).toHaveBeenCalledWith("test.json",void 0),o(d).toHaveBeenCalledWith("json",f),o(v.writeFile).toHaveBeenCalledWith("test.json",'{"a":2}',"utf8"),o(k).toHaveBeenCalledWith("git add test.json"),o(i.flush).toHaveBeenCalled()}),l("handles files with conflicts",async()=>{let t={writeConflictSidecar:!0},r=[{path:"a",reason:"test conflict"}],m="conflict content";c.mockResolvedValue([{filePath:"test.json",content:"content"}]),s.mockResolvedValue({theirs:{},ours:{},format:"json"}),n.mockImplementation(({conflicts:f})=>(f.push(...r),Promise.resolve({}))),W.mockResolvedValue(m),await a(t),o(W).toHaveBeenCalledWith({},{},{},"json"),o(v.writeFile).toHaveBeenCalledWith("test.json",m,"utf8"),o(v.writeFile).toHaveBeenCalledWith("test.json.conflict.json",JSON.stringify(r,null,2)),o(k).not.toHaveBeenCalled()}),l("handles git staging errors gracefully",async()=>{c.mockResolvedValue([{filePath:"test.json",content:"content"}]),s.mockResolvedValue({theirs:{},ours:{},format:"json"}),n.mockResolvedValue({}),d.mockResolvedValue("{}"),k.mockImplementation(()=>{throw new Error("git error")}),await a({}),o(i.warn).toHaveBeenCalledWith("test.json","Failed to stage file: Error: git error")}),l("enables debug logging when configured",async()=>{let t={debug:!0};g.mockResolvedValue({debug:!0,customStrategies:{}}),c.mockResolvedValue([{filePath:"test.json",content:"content"}]),s.mockResolvedValue({theirs:{},ours:{},format:"json"}),n.mockResolvedValue({}),await a(t)}),l("processes multiple files concurrently",async()=>{let t=[{filePath:"file1.json",content:"content1"},{filePath:"file2.json",content:"content2"}];c.mockResolvedValue(t),s.mockResolvedValue({theirs:{},ours:{},format:"json"}),n.mockResolvedValue({}),d.mockResolvedValue("{}"),await a({}),o(s).toHaveBeenCalledTimes(2),o(n).toHaveBeenCalledTimes(2),o(u).toHaveBeenCalledTimes(2)}),l("uses custom backup directory",async()=>{let t={backupDir:"custom-backup"};c.mockResolvedValue([{filePath:"test.json",content:"content"}]),s.mockResolvedValue({theirs:{},ours:{},format:"json"}),n.mockResolvedValue({}),await a(t),o(u).toHaveBeenCalledWith("test.json","custom-backup")})});