json-merge-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.29 kB
JavaScript
import{a as r,b as s,c as f,d as c}from"./chunk-QY2IMCJG.mjs";import{a as l,b as o,g as t}from"./chunk-YAHYZFUT.mjs";import"./chunk-76CZ6Z7T.mjs";for(let a of["basicMatcher","micromatch","picomatch"])l(a,async()=>{let e=a==="basicMatcher"?f:await c(a);o("matches exact strings",()=>{t(e.isMatch("foo.bar",["foo.bar"])).toBe(!0),t(e.isMatch("foo.bar",["foo.baz"])).toBe(!1)}),o("matches with single * segment",()=>{t(e.isMatch("foo.bar",["foo.*"])).toBe(!0),t(e.isMatch("foo.baz.qux",["foo.*.qux"])).toBe(!0),t(e.isMatch("foo.bar",["*.baz"])).toBe(!1)}),o("matches with ** for nested paths",()=>{t(e.isMatch("a.b.c",["a.**"])).toBe(!0),t(e.isMatch("a.b.c.d",["a.**.d"])).toBe(!0),t(e.isMatch("a.b.c.d",["**.d"])).toBe(!0),t(e.isMatch("a.b.c.d",["*.d"])).toBe(!1),t(e.isMatch("a.b.c",["**"])).toBe(!0)}),o("supports prefix-* and *-suffix in segments",()=>{t(e.isMatch("foo.helloWorld",["foo.hello*"])).toBe(!0),t(e.isMatch("foo.helloWorld",["foo.*World"])).toBe(!0),t(e.isMatch("foo.helloWorld",["foo.hel*ld"])).toBe(!0),t(e.isMatch("foo.helloWorld",["foo.hel*xyz"])).toBe(!1)}),o("returns true if any pattern matches",()=>{t(e.isMatch("foo.bar",["no.match","foo.*"])).toBe(!0)}),o("handles empty patterns",()=>{t(e.isMatch("foo.bar",[])).toBe(!1)}),o("respects escapes",()=>{t(e.isMatch("foo.helloWorld",["foo.hello*"])).toBe(!0),t(e.isMatch("foo.helloWorld",["foo.hello\\*"])).toBe(!1),t(e.isMatch("foo.hello*",["foo.hello\\*"])).toBe(!0),t(e.isMatch("a.b.c",["a.**"])).toBe(!0),t(e.isMatch("a.b.c",["a.\\*\\*"])).toBe(!1),t(e.isMatch("a.**",["a.\\*\\*"])).toBe(!0),t(e.isMatch("a.c.b",["a.***"])).toBe(!1)}),o("negates exact match",()=>{t(e.isMatch("src/index.ts",["!src/index.ts"])).toBe(!1),t(e.isMatch("src/other.ts",["!src/index.ts"])).toBe(!0)}),o("negates directory glob",()=>{t(e.isMatch("src/utils/app.ts",["!src/**"])).toBe(!1),t(e.isMatch("lib/app.ts",["!src/**"])).toBe(!0)}),o("negates simple * wildcard (recursive)",()=>{t(e.isMatch("test/app.test.ts",["!**/*.test.ts"])).toBe(!1),t(e.isMatch("test/app.ts",["!**/*.test.ts"])).toBe(!0)}),o("root level negation",()=>{t(e.isMatch("src",["!src"])).toBe(!1),t(e.isMatch("other",["!src"])).toBe(!0)}),o("handles object fields with dots and slashes",()=>{t(e.isMatch(`deps.@m2d${""}core`,["deps.*"])).toBe(!0),t(e.isMatch(`deps.@m2d${""}core`,["deps.@m2d\\/core"])).toBe(!0),t(e.isMatch(`urls.https:${""}${""}api${"\0"}example${"\0"}com${""}v1`,["urls.*"])).toBe(!0)})});l("loadMatcher",()=>{o("loads micromatch when available",async()=>{let a=await c("micromatch");t(a.isMatch("foo",["foo"])).toBe(!0),t(a.isMatch("bar",["foo"])).toBe(!1)}),o("loads picomatch when available",async()=>{let a=await c("picomatch");t(a.isMatch("okmyfield",["ok*"])).toBe(!0),t(a.isMatch("fail",["pattern"])).toBe(!1)}),o("throws on unknown matcher",async()=>{await t(()=>c("invalid")).rejects.toThrow(/Unknown matcher/)}),o("handles complex field names consistently across matchers",async()=>{let a=[{field:`deps.@m2d${""}core`,pattern:"deps.*",expected:!0},{field:`urls.https:${""}${""}api${"\0"}example${"\0"}com${""}v1`,pattern:"urls.*",expected:!0}];for(let{field:e,pattern:i,expected:h}of a){t(f.isMatch(e,[i])).toBe(h);let n=await c("micromatch");t(n.isMatch(e,[i])).toBe(h);let d=await c("picomatch");t(d.isMatch(e,[i])).toBe(h)}})});