Detalhes do pacote

parse-conflict-json

npm12.5mISC4.0.0

Parse a JSON string that has git merge conflicts, resolving if possible

readme (leia-me)

parse-conflict-json

Parse a JSON string that has git merge conflicts, resolving if possible.

If the JSON is valid, it just does JSON.parse as normal.

If either side of the conflict is invalid JSON, then an error is thrown for that.

USAGE

// after a git merge that left some conflicts there
const data = fs.readFileSync('package-lock.json', 'utf8')

// reviverFunction is passed to JSON.parse as the reviver function
// preference defaults to 'ours', set to 'theirs' to prefer the other
// side's changes.
const parsed = parseConflictJson(data, reviverFunction, preference)

// returns true if the data looks like a conflicted diff file
parsed.isDiff(data)

Algorithm

If prefer is set to theirs, then the vaules of theirs and ours are switched in the resolver function. (Ie, we'll apply their changes on top of our object, rather than the other way around.)

  • Parse the conflicted file into 3 pieces: ours, theirs, and parent

  • Get the diff from parent to ours.

  • Apply each change of that diff to theirs.

    If any change in the diff set cannot be applied (ie, because they changed an object into a non-object and we changed a field on that object), then replace the object at the specified path with the object at the path in ours.

changelog (log de mudanças)

Changelog

4.0.0 (2024-09-24)

⚠️ BREAKING CHANGES

  • parse-conflict-json now supports node ^18.17.0 || >=20.5.0

    Bug Fixes

  • 2ff0df4 #97 align to npm 10 node engine range (@hashtagchris)

    Dependencies

  • 5d1036d #97 json-parse-even-better-errors@4.0.0

    Chores

  • bbad0b5 #97 run template-oss-apply (@hashtagchris)
  • aaa60b6 #96 enable auto publish (#96) (@reggi)
  • ceb69ec #93 bump @npmcli/eslint-config from 4.0.5 to 5.0.0 (@dependabot[bot])
  • 5724d51 #80 bump @npmcli/template-oss to 4.22.0 (@lukekarrys)
  • 46686e2 #94 postinstall for dependabot template-oss PR (@hashtagchris)
  • 0694002 #94 bump @npmcli/template-oss from 4.23.1 to 4.23.3 (@dependabot[bot])

3.0.1 (2023-03-16)

Dependencies

  • 13f103a #42 bump just-diff from 5.2.0 to 6.0.0 (#42)

3.0.0 (2022-10-12)

⚠️ BREAKING CHANGES

  • parse-conflict-json is now compatible with the following semver range for node: ^14.17.0 || ^16.13.0 || >=18.0.0

Features

  • 97eebf8 #27 postinstall for dependabot template-oss PR (@lukekarrys)

Dependencies

  • 11ac781 #33 bump json-parse-even-better-errors from 2.3.1 to 3.0.0

2.0.2 (2022-03-28)

Dependencies

  • bump just-diff-apply from 4.0.1 to 5.2.0 (#12) (3cdeb20)

v2.0.1

Bug Fixes

Move @npmcli/template-oss to a dev dependency

v2.0.0

BREAKING CHANGES

BREAKING CHANGE: drops suport for node <= 10 and non LTS versions of node 12 and node 14

Bug Fixes

Don't set global object properties