Skip to content

Commit 041b9b2

Browse files
committed
deps: parse-conflict-json@5.0.1
1 parent a1b0fea commit 041b9b2

File tree

8 files changed

+239
-12
lines changed

8 files changed

+239
-12
lines changed

node_modules/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@
179179
!/package-json-from-dist
180180
!/pacote
181181
!/parse-conflict-json
182+
!/parse-conflict-json/node_modules/
183+
/parse-conflict-json/node_modules/*
184+
!/parse-conflict-json/node_modules/json-parse-even-better-errors
182185
!/path-key
183186
!/path-scurry
184187
!/postcss-selector-parser
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Copyright 2017 Kat Marchán
2+
Copyright npm, Inc.
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a
5+
copy of this software and associated documentation files (the "Software"),
6+
to deal in the Software without restriction, including without limitation
7+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
and/or sell copies of the Software, and to permit persons to whom the
9+
Software is furnished to do so, subject to the following conditions:
10+
11+
The above copyright notice and this permission notice shall be included in
12+
all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20+
DEALINGS IN THE SOFTWARE.
21+
22+
---
23+
24+
This library is a fork of 'better-json-errors' by Kat Marchán, extended and
25+
distributed under the terms of the MIT license above.
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
'use strict'
2+
3+
const INDENT = Symbol.for('indent')
4+
const NEWLINE = Symbol.for('newline')
5+
6+
const DEFAULT_NEWLINE = '\n'
7+
const DEFAULT_INDENT = ' '
8+
const BOM = /^\uFEFF/
9+
10+
// only respect indentation if we got a line break, otherwise squash it
11+
// things other than objects and arrays aren't indented, so ignore those
12+
// Important: in both of these regexps, the $1 capture group is the newline
13+
// or undefined, and the $2 capture group is the indent, or undefined.
14+
const FORMAT = /^\s*[{[]((?:\r?\n)+)([\s\t]*)/
15+
const EMPTY = /^(?:\{\}|\[\])((?:\r?\n)+)?$/
16+
17+
// Node 20 puts single quotes around the token and a comma after it
18+
const UNEXPECTED_TOKEN = /^Unexpected token '?(.)'?(,)? /i
19+
20+
const hexify = (char) => {
21+
const h = char.charCodeAt(0).toString(16).toUpperCase()
22+
return `0x${h.length % 2 ? '0' : ''}${h}`
23+
}
24+
25+
// Remove byte order marker. This catches EF BB BF (the UTF-8 BOM)
26+
// because the buffer-to-string conversion in `fs.readFileSync()`
27+
// translates it to FEFF, the UTF-16 BOM.
28+
const stripBOM = (txt) => String(txt).replace(BOM, '')
29+
30+
const makeParsedError = (msg, parsing, position = 0) => ({
31+
message: `${msg} while parsing ${parsing}`,
32+
position,
33+
})
34+
35+
const parseError = (e, txt, context = 20) => {
36+
let msg = e.message
37+
38+
if (!txt) {
39+
return makeParsedError(msg, 'empty string')
40+
}
41+
42+
const badTokenMatch = msg.match(UNEXPECTED_TOKEN)
43+
const badIndexMatch = msg.match(/ position\s+(\d+)/i)
44+
45+
if (badTokenMatch) {
46+
msg = msg.replace(
47+
UNEXPECTED_TOKEN,
48+
`Unexpected token ${JSON.stringify(badTokenMatch[1])} (${hexify(badTokenMatch[1])})$2 `
49+
)
50+
}
51+
52+
let errIdx
53+
if (badIndexMatch) {
54+
errIdx = +badIndexMatch[1]
55+
} else /* istanbul ignore next - doesnt happen in Node 22 */ if (
56+
msg.match(/^Unexpected end of JSON.*/i)
57+
) {
58+
errIdx = txt.length - 1
59+
}
60+
61+
if (errIdx == null) {
62+
return makeParsedError(msg, `'${txt.slice(0, context * 2)}'`)
63+
}
64+
65+
const start = errIdx <= context ? 0 : errIdx - context
66+
const end = errIdx + context >= txt.length ? txt.length : errIdx + context
67+
const slice = `${start ? '...' : ''}${txt.slice(start, end)}${end === txt.length ? '' : '...'}`
68+
69+
return makeParsedError(
70+
msg,
71+
`${txt === slice ? '' : 'near '}${JSON.stringify(slice)}`,
72+
errIdx
73+
)
74+
}
75+
76+
class JSONParseError extends SyntaxError {
77+
constructor (er, txt, context, caller) {
78+
const metadata = parseError(er, txt, context)
79+
super(metadata.message)
80+
Object.assign(this, metadata)
81+
this.code = 'EJSONPARSE'
82+
this.systemError = er
83+
Error.captureStackTrace(this, caller || this.constructor)
84+
}
85+
86+
get name () {
87+
return this.constructor.name
88+
}
89+
90+
set name (n) {}
91+
92+
get [Symbol.toStringTag] () {
93+
return this.constructor.name
94+
}
95+
}
96+
97+
const parseJson = (txt, reviver) => {
98+
const result = JSON.parse(txt, reviver)
99+
if (result && typeof result === 'object') {
100+
// get the indentation so that we can save it back nicely
101+
// if the file starts with {" then we have an indent of '', ie, none
102+
// otherwise, pick the indentation of the next line after the first \n If the
103+
// pattern doesn't match, then it means no indentation. JSON.stringify ignores
104+
// symbols, so this is reasonably safe. if the string is '{}' or '[]', then
105+
// use the default 2-space indent.
106+
const match = txt.match(EMPTY) || txt.match(FORMAT) || [null, '', '']
107+
result[NEWLINE] = match[1] ?? DEFAULT_NEWLINE
108+
result[INDENT] = match[2] ?? DEFAULT_INDENT
109+
}
110+
return result
111+
}
112+
113+
const parseJsonError = (raw, reviver, context) => {
114+
const txt = stripBOM(raw)
115+
try {
116+
return parseJson(txt, reviver)
117+
} catch (e) {
118+
if (typeof raw !== 'string' && !Buffer.isBuffer(raw)) {
119+
const msg = Array.isArray(raw) && raw.length === 0 ? 'an empty array' : String(raw)
120+
throw Object.assign(
121+
new TypeError(`Cannot parse ${msg}`),
122+
{ code: 'EJSONPARSE', systemError: e }
123+
)
124+
}
125+
throw new JSONParseError(e, txt, context, parseJsonError)
126+
}
127+
}
128+
129+
module.exports = parseJsonError
130+
parseJsonError.JSONParseError = JSONParseError
131+
parseJsonError.noExceptions = (raw, reviver) => {
132+
try {
133+
return parseJson(stripBOM(raw), reviver)
134+
} catch {
135+
// no exceptions
136+
}
137+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"name": "json-parse-even-better-errors",
3+
"version": "5.0.0",
4+
"description": "JSON.parse with context information on error",
5+
"main": "lib/index.js",
6+
"files": [
7+
"bin/",
8+
"lib/"
9+
],
10+
"scripts": {
11+
"test": "tap",
12+
"snap": "tap",
13+
"lint": "npm run eslint",
14+
"postlint": "template-oss-check",
15+
"template-oss-apply": "template-oss-apply --force",
16+
"lintfix": "npm run eslint -- --fix",
17+
"posttest": "npm run lint",
18+
"eslint": "eslint \"**/*.{js,cjs,ts,mjs,jsx,tsx}\""
19+
},
20+
"repository": {
21+
"type": "git",
22+
"url": "git+https://github.com/npm/json-parse-even-better-errors.git"
23+
},
24+
"keywords": [
25+
"JSON",
26+
"parser"
27+
],
28+
"author": "GitHub Inc.",
29+
"license": "MIT",
30+
"devDependencies": {
31+
"@npmcli/eslint-config": "^5.0.0",
32+
"@npmcli/template-oss": "4.27.1",
33+
"tap": "^16.3.0"
34+
},
35+
"tap": {
36+
"check-coverage": true,
37+
"nyc-arg": [
38+
"--exclude",
39+
"tap-snapshots/**"
40+
]
41+
},
42+
"engines": {
43+
"node": "^20.17.0 || >=22.9.0"
44+
},
45+
"templateOSS": {
46+
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
47+
"version": "4.27.1",
48+
"publish": true
49+
}
50+
}

node_modules/parse-conflict-json/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "parse-conflict-json",
3-
"version": "4.0.0",
3+
"version": "5.0.1",
44
"description": "Parse a JSON string that has git merge conflicts, resolving if possible",
55
"author": "GitHub Inc.",
66
"license": "ISC",
@@ -24,11 +24,11 @@
2424
},
2525
"devDependencies": {
2626
"@npmcli/eslint-config": "^5.0.0",
27-
"@npmcli/template-oss": "4.23.3",
27+
"@npmcli/template-oss": "4.27.1",
2828
"tap": "^16.0.1"
2929
},
3030
"dependencies": {
31-
"json-parse-even-better-errors": "^4.0.0",
31+
"json-parse-even-better-errors": "^5.0.0",
3232
"just-diff": "^6.0.0",
3333
"just-diff-apply": "^5.2.0"
3434
},
@@ -41,11 +41,11 @@
4141
"lib/"
4242
],
4343
"engines": {
44-
"node": "^18.17.0 || >=20.5.0"
44+
"node": "^20.17.0 || >=22.9.0"
4545
},
4646
"templateOSS": {
4747
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
48-
"version": "4.23.3",
48+
"version": "4.27.1",
4949
"publish": true
5050
}
5151
}

package-lock.json

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136
"npm-user-validate": "^3.0.0",
137137
"p-map": "^7.0.3",
138138
"pacote": "^21.0.3",
139-
"parse-conflict-json": "^4.0.0",
139+
"parse-conflict-json": "^5.0.1",
140140
"proc-log": "^5.0.0",
141141
"qrcode-terminal": "^0.12.0",
142142
"read": "^4.1.0",
@@ -9148,16 +9148,28 @@
91489148
}
91499149
},
91509150
"node_modules/parse-conflict-json": {
9151-
"version": "4.0.0",
9151+
"version": "5.0.1",
9152+
"resolved": "https://registry.npmjs.org/parse-conflict-json/-/parse-conflict-json-5.0.1.tgz",
9153+
"integrity": "sha512-ZHEmNKMq1wyJXNwLxyHnluPfRAFSIliBvbK/UiOceROt4Xh9Pz0fq49NytIaeaCUf5VR86hwQ/34FCcNU5/LKQ==",
91529154
"inBundle": true,
91539155
"license": "ISC",
91549156
"dependencies": {
9155-
"json-parse-even-better-errors": "^4.0.0",
9157+
"json-parse-even-better-errors": "^5.0.0",
91569158
"just-diff": "^6.0.0",
91579159
"just-diff-apply": "^5.2.0"
91589160
},
91599161
"engines": {
9160-
"node": "^18.17.0 || >=20.5.0"
9162+
"node": "^20.17.0 || >=22.9.0"
9163+
}
9164+
},
9165+
"node_modules/parse-conflict-json/node_modules/json-parse-even-better-errors": {
9166+
"version": "5.0.0",
9167+
"resolved": "https://registry.npmjs.org/json-parse-even-better-errors/-/json-parse-even-better-errors-5.0.0.tgz",
9168+
"integrity": "sha512-ZF1nxZ28VhQouRWhUcVlUIN3qwSgPuswK05s/HIaoetAoE/9tngVmCHjSxmSQPav1nd+lPtTL0YZ/2AFdR/iYQ==",
9169+
"inBundle": true,
9170+
"license": "MIT",
9171+
"engines": {
9172+
"node": "^20.17.0 || >=22.9.0"
91619173
}
91629174
},
91639175
"node_modules/parse-diff": {
@@ -14558,7 +14570,7 @@
1455814570
"npm-pick-manifest": "^11.0.1",
1455914571
"npm-registry-fetch": "^19.0.0",
1456014572
"pacote": "^21.0.2",
14561-
"parse-conflict-json": "^4.0.0",
14573+
"parse-conflict-json": "^5.0.1",
1456214574
"proc-log": "^5.0.0",
1456314575
"proggy": "^3.0.0",
1456414576
"promise-all-reject-late": "^1.0.0",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
"npm-user-validate": "^3.0.0",
104104
"p-map": "^7.0.3",
105105
"pacote": "^21.0.3",
106-
"parse-conflict-json": "^4.0.0",
106+
"parse-conflict-json": "^5.0.1",
107107
"proc-log": "^5.0.0",
108108
"qrcode-terminal": "^0.12.0",
109109
"read": "^4.1.0",

workspaces/arborist/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"npm-pick-manifest": "^11.0.1",
2828
"npm-registry-fetch": "^19.0.0",
2929
"pacote": "^21.0.2",
30-
"parse-conflict-json": "^4.0.0",
30+
"parse-conflict-json": "^5.0.1",
3131
"proc-log": "^5.0.0",
3232
"proggy": "^3.0.0",
3333
"promise-all-reject-late": "^1.0.0",

0 commit comments

Comments
 (0)