update
This commit is contained in:
20
package/node_modules/parse-conflict-json/LICENSE.md
generated
vendored
Normal file
20
package/node_modules/parse-conflict-json/LICENSE.md
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
<!-- This file is automatically added by @npmcli/template-oss. Do not edit. -->
|
||||
|
||||
ISC License
|
||||
|
||||
Copyright npm, Inc.
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this
|
||||
software for any purpose with or without fee is hereby
|
||||
granted, provided that the above copyright notice and this
|
||||
permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND NPM DISCLAIMS ALL
|
||||
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
|
||||
EVENT SHALL NPM BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
||||
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
||||
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
|
||||
USE OR PERFORMANCE OF THIS SOFTWARE.
|
104
package/node_modules/parse-conflict-json/lib/index.js
generated
vendored
Normal file
104
package/node_modules/parse-conflict-json/lib/index.js
generated
vendored
Normal file
@@ -0,0 +1,104 @@
|
||||
const parseJSON = require('json-parse-even-better-errors')
|
||||
const { diff } = require('just-diff')
|
||||
const { diffApply } = require('just-diff-apply')
|
||||
|
||||
const globalObjectProperties = Object.getOwnPropertyNames(Object.prototype)
|
||||
|
||||
const stripBOM = content => {
|
||||
content = content.toString()
|
||||
// Remove byte order marker. This catches EF BB BF (the UTF-8 BOM)
|
||||
// because the buffer-to-string conversion in `fs.readFileSync()`
|
||||
// translates it to FEFF, the UTF-16 BOM.
|
||||
if (content.charCodeAt(0) === 0xFEFF) {
|
||||
content = content.slice(1)
|
||||
}
|
||||
return content
|
||||
}
|
||||
|
||||
const PARENT_RE = /\|{7,}/g
|
||||
const OURS_RE = /<{7,}/g
|
||||
const THEIRS_RE = /={7,}/g
|
||||
const END_RE = />{7,}/g
|
||||
|
||||
const isDiff = str =>
|
||||
str.match(OURS_RE) && str.match(THEIRS_RE) && str.match(END_RE)
|
||||
|
||||
const parseConflictJSON = (str, reviver, prefer) => {
|
||||
prefer = prefer || 'ours'
|
||||
if (prefer !== 'theirs' && prefer !== 'ours') {
|
||||
throw new TypeError('prefer param must be "ours" or "theirs" if set')
|
||||
}
|
||||
|
||||
str = stripBOM(str)
|
||||
|
||||
if (!isDiff(str)) {
|
||||
return parseJSON(str)
|
||||
}
|
||||
|
||||
const pieces = str.split(/[\n\r]+/g).reduce((acc, line) => {
|
||||
if (line.match(PARENT_RE)) {
|
||||
acc.state = 'parent'
|
||||
} else if (line.match(OURS_RE)) {
|
||||
acc.state = 'ours'
|
||||
} else if (line.match(THEIRS_RE)) {
|
||||
acc.state = 'theirs'
|
||||
} else if (line.match(END_RE)) {
|
||||
acc.state = 'top'
|
||||
} else {
|
||||
if (acc.state === 'top' || acc.state === 'ours') {
|
||||
acc.ours += line
|
||||
}
|
||||
if (acc.state === 'top' || acc.state === 'theirs') {
|
||||
acc.theirs += line
|
||||
}
|
||||
if (acc.state === 'top' || acc.state === 'parent') {
|
||||
acc.parent += line
|
||||
}
|
||||
}
|
||||
return acc
|
||||
}, {
|
||||
state: 'top',
|
||||
ours: '',
|
||||
theirs: '',
|
||||
parent: '',
|
||||
})
|
||||
|
||||
// this will throw if either piece is not valid JSON, that's intended
|
||||
const parent = parseJSON(pieces.parent, reviver)
|
||||
const ours = parseJSON(pieces.ours, reviver)
|
||||
const theirs = parseJSON(pieces.theirs, reviver)
|
||||
|
||||
return prefer === 'ours'
|
||||
? resolve(parent, ours, theirs)
|
||||
: resolve(parent, theirs, ours)
|
||||
}
|
||||
|
||||
const isObj = obj => obj && typeof obj === 'object'
|
||||
|
||||
const copyPath = (to, from, path, i) => {
|
||||
const p = path[i]
|
||||
if (isObj(to[p]) && isObj(from[p]) &&
|
||||
Array.isArray(to[p]) === Array.isArray(from[p])) {
|
||||
return copyPath(to[p], from[p], path, i + 1)
|
||||
}
|
||||
to[p] = from[p]
|
||||
}
|
||||
|
||||
// get the diff from parent->ours and applying our changes on top of theirs.
|
||||
// If they turned an object into a non-object, then put it back.
|
||||
const resolve = (parent, ours, theirs) => {
|
||||
const dours = diff(parent, ours)
|
||||
for (let i = 0; i < dours.length; i++) {
|
||||
if (globalObjectProperties.find(prop => dours[i].path.includes(prop))) {
|
||||
continue
|
||||
}
|
||||
try {
|
||||
diffApply(theirs, [dours[i]])
|
||||
} catch (e) {
|
||||
copyPath(theirs, ours, dours[i].path, 0)
|
||||
}
|
||||
}
|
||||
return theirs
|
||||
}
|
||||
|
||||
module.exports = Object.assign(parseConflictJSON, { isDiff })
|
49
package/node_modules/parse-conflict-json/package.json
generated
vendored
Normal file
49
package/node_modules/parse-conflict-json/package.json
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
{
|
||||
"name": "parse-conflict-json",
|
||||
"version": "3.0.1",
|
||||
"description": "Parse a JSON string that has git merge conflicts, resolving if possible",
|
||||
"author": "GitHub Inc.",
|
||||
"license": "ISC",
|
||||
"main": "lib",
|
||||
"scripts": {
|
||||
"test": "tap",
|
||||
"snap": "tap",
|
||||
"lint": "eslint \"**/*.js\"",
|
||||
"postlint": "template-oss-check",
|
||||
"lintfix": "npm run lint -- --fix",
|
||||
"posttest": "npm run lint",
|
||||
"template-oss-apply": "template-oss-apply --force"
|
||||
},
|
||||
"tap": {
|
||||
"check-coverage": true,
|
||||
"nyc-arg": [
|
||||
"--exclude",
|
||||
"tap-snapshots/**"
|
||||
]
|
||||
},
|
||||
"devDependencies": {
|
||||
"@npmcli/eslint-config": "^4.0.0",
|
||||
"@npmcli/template-oss": "4.12.0",
|
||||
"tap": "^16.0.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"json-parse-even-better-errors": "^3.0.0",
|
||||
"just-diff": "^6.0.0",
|
||||
"just-diff-apply": "^5.2.0"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/npm/parse-conflict-json.git"
|
||||
},
|
||||
"files": [
|
||||
"bin/",
|
||||
"lib/"
|
||||
],
|
||||
"engines": {
|
||||
"node": "^14.17.0 || ^16.13.0 || >=18.0.0"
|
||||
},
|
||||
"templateOSS": {
|
||||
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
|
||||
"version": "4.12.0"
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user