All Projects → npm → parse-conflict-json

npm / parse-conflict-json

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

Programming Languages

javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to parse-conflict-json

libnpmpublish
programmatically publish and unpublish npm packages
Stars: ✭ 44 (+83.33%)
Mutual labels:  npm-cli
config
Configuration management for https://github.com/npm/cli
Stars: ✭ 22 (-8.33%)
Mutual labels:  npm-cli
cacache
npm's content-addressable cache
Stars: ✭ 181 (+654.17%)
Mutual labels:  npm-cli
cmd-shim
The cmd-shim used in npm
Stars: ✭ 65 (+170.83%)
Mutual labels:  npm-cli
libnpmsearch
programmatic API for the shiny new npm search endpoint
Stars: ✭ 25 (+4.17%)
Mutual labels:  npm-cli
cross-post
Cross Post a blog to multiple websites
Stars: ✭ 66 (+175%)
Mutual labels:  npm-cli
git
a util for spawning git from npm CLI contexts
Stars: ✭ 48 (+100%)
Mutual labels:  npm-cli
fs-minipass
fs read and write streams based on minipass
Stars: ✭ 15 (-37.5%)
Mutual labels:  npm-cli
npm-registry-mock
mock the npm registry
Stars: ✭ 26 (+8.33%)
Mutual labels:  npm-cli
node-cli-boilerplate
🪓 Create node cli with this user friendly boilerplate
Stars: ✭ 17 (-29.17%)
Mutual labels:  npm-cli
npm-profile
Make changes to your npmjs.com profile via cli or library
Stars: ✭ 29 (+20.83%)
Mutual labels:  npm-cli
inflight
Add callbacks to requests in flight to avoid async duplication
Stars: ✭ 63 (+162.5%)
Mutual labels:  npm-cli
Cli
the package manager for JavaScript
Stars: ✭ 5,277 (+21887.5%)
Mutual labels:  npm-cli
Node Semver
The semver parser for node (the one npm uses)
Stars: ✭ 3,944 (+16333.33%)
Mutual labels:  npm-cli
run-script
Run a lifecycle script for a package (descendant of npm-lifecycle)
Stars: ✭ 29 (+20.83%)
Mutual labels:  npm-cli
lint
lint the npmcli way
Stars: ✭ 27 (+12.5%)
Mutual labels:  npm-cli
proggy
Progress bar updates at a distance
Stars: ✭ 12 (-50%)
Mutual labels:  npm-cli
pacote
npm fetcher
Stars: ✭ 179 (+645.83%)
Mutual labels:  npm-cli

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].