opencode-orchestrator 1.2.67 → 1.2.69
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -1
- package/dist/core/notification/task-toast-manager.d.ts +3 -0
- package/dist/core/notification/toast-sanitizer.d.ts +3 -0
- package/dist/index.js +123 -59
- package/dist/scripts/postinstall.js +1407 -176
- package/dist/scripts/preuninstall.js +1407 -176
- package/package.json +4 -4
|
@@ -1,189 +1,1420 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
2
|
+
|
|
3
|
+
// scripts/preuninstall.ts
|
|
4
|
+
import { existsSync, readFileSync, writeFileSync, appendFileSync, copyFileSync, renameSync, unlinkSync, readdirSync } from "fs";
|
|
5
|
+
import { homedir, tmpdir } from "os";
|
|
6
|
+
import { dirname, join, basename } from "path";
|
|
7
|
+
|
|
8
|
+
// node_modules/jsonc-parser/lib/esm/impl/scanner.js
|
|
9
|
+
function createScanner(text, ignoreTrivia = false) {
|
|
10
|
+
const len = text.length;
|
|
11
|
+
let pos = 0, value = "", tokenOffset = 0, token = 16, lineNumber = 0, lineStartOffset = 0, tokenLineStartOffset = 0, prevTokenLineStartOffset = 0, scanError = 0;
|
|
12
|
+
function scanHexDigits(count, exact) {
|
|
13
|
+
let digits = 0;
|
|
14
|
+
let value2 = 0;
|
|
15
|
+
while (digits < count || !exact) {
|
|
16
|
+
let ch = text.charCodeAt(pos);
|
|
17
|
+
if (ch >= 48 && ch <= 57) {
|
|
18
|
+
value2 = value2 * 16 + ch - 48;
|
|
19
|
+
} else if (ch >= 65 && ch <= 70) {
|
|
20
|
+
value2 = value2 * 16 + ch - 65 + 10;
|
|
21
|
+
} else if (ch >= 97 && ch <= 102) {
|
|
22
|
+
value2 = value2 * 16 + ch - 97 + 10;
|
|
23
|
+
} else {
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
pos++;
|
|
27
|
+
digits++;
|
|
28
|
+
}
|
|
29
|
+
if (digits < count) {
|
|
30
|
+
value2 = -1;
|
|
31
|
+
}
|
|
32
|
+
return value2;
|
|
33
|
+
}
|
|
34
|
+
function setPosition(newPosition) {
|
|
35
|
+
pos = newPosition;
|
|
36
|
+
value = "";
|
|
37
|
+
tokenOffset = 0;
|
|
38
|
+
token = 16;
|
|
39
|
+
scanError = 0;
|
|
40
|
+
}
|
|
41
|
+
function scanNumber() {
|
|
42
|
+
let start = pos;
|
|
43
|
+
if (text.charCodeAt(pos) === 48) {
|
|
44
|
+
pos++;
|
|
45
|
+
} else {
|
|
46
|
+
pos++;
|
|
47
|
+
while (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
48
|
+
pos++;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (pos < text.length && text.charCodeAt(pos) === 46) {
|
|
52
|
+
pos++;
|
|
53
|
+
if (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
54
|
+
pos++;
|
|
55
|
+
while (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
56
|
+
pos++;
|
|
57
|
+
}
|
|
58
|
+
} else {
|
|
59
|
+
scanError = 3;
|
|
60
|
+
return text.substring(start, pos);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
let end = pos;
|
|
64
|
+
if (pos < text.length && (text.charCodeAt(pos) === 69 || text.charCodeAt(pos) === 101)) {
|
|
65
|
+
pos++;
|
|
66
|
+
if (pos < text.length && text.charCodeAt(pos) === 43 || text.charCodeAt(pos) === 45) {
|
|
67
|
+
pos++;
|
|
68
|
+
}
|
|
69
|
+
if (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
70
|
+
pos++;
|
|
71
|
+
while (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
72
|
+
pos++;
|
|
73
|
+
}
|
|
74
|
+
end = pos;
|
|
75
|
+
} else {
|
|
76
|
+
scanError = 3;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return text.substring(start, end);
|
|
80
|
+
}
|
|
81
|
+
function scanString() {
|
|
82
|
+
let result = "", start = pos;
|
|
83
|
+
while (true) {
|
|
84
|
+
if (pos >= len) {
|
|
85
|
+
result += text.substring(start, pos);
|
|
86
|
+
scanError = 2;
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
const ch = text.charCodeAt(pos);
|
|
90
|
+
if (ch === 34) {
|
|
91
|
+
result += text.substring(start, pos);
|
|
92
|
+
pos++;
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
if (ch === 92) {
|
|
96
|
+
result += text.substring(start, pos);
|
|
97
|
+
pos++;
|
|
98
|
+
if (pos >= len) {
|
|
99
|
+
scanError = 2;
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
const ch2 = text.charCodeAt(pos++);
|
|
103
|
+
switch (ch2) {
|
|
104
|
+
case 34:
|
|
105
|
+
result += '"';
|
|
106
|
+
break;
|
|
107
|
+
case 92:
|
|
108
|
+
result += "\\";
|
|
109
|
+
break;
|
|
110
|
+
case 47:
|
|
111
|
+
result += "/";
|
|
112
|
+
break;
|
|
113
|
+
case 98:
|
|
114
|
+
result += "\b";
|
|
115
|
+
break;
|
|
116
|
+
case 102:
|
|
117
|
+
result += "\f";
|
|
118
|
+
break;
|
|
119
|
+
case 110:
|
|
120
|
+
result += "\n";
|
|
121
|
+
break;
|
|
122
|
+
case 114:
|
|
123
|
+
result += "\r";
|
|
124
|
+
break;
|
|
125
|
+
case 116:
|
|
126
|
+
result += " ";
|
|
127
|
+
break;
|
|
128
|
+
case 117:
|
|
129
|
+
const ch3 = scanHexDigits(4, true);
|
|
130
|
+
if (ch3 >= 0) {
|
|
131
|
+
result += String.fromCharCode(ch3);
|
|
132
|
+
} else {
|
|
133
|
+
scanError = 4;
|
|
134
|
+
}
|
|
135
|
+
break;
|
|
136
|
+
default:
|
|
137
|
+
scanError = 5;
|
|
138
|
+
}
|
|
139
|
+
start = pos;
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
if (ch >= 0 && ch <= 31) {
|
|
143
|
+
if (isLineBreak(ch)) {
|
|
144
|
+
result += text.substring(start, pos);
|
|
145
|
+
scanError = 2;
|
|
146
|
+
break;
|
|
147
|
+
} else {
|
|
148
|
+
scanError = 6;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
pos++;
|
|
152
|
+
}
|
|
153
|
+
return result;
|
|
154
|
+
}
|
|
155
|
+
function scanNext() {
|
|
156
|
+
value = "";
|
|
157
|
+
scanError = 0;
|
|
158
|
+
tokenOffset = pos;
|
|
159
|
+
lineStartOffset = lineNumber;
|
|
160
|
+
prevTokenLineStartOffset = tokenLineStartOffset;
|
|
161
|
+
if (pos >= len) {
|
|
162
|
+
tokenOffset = len;
|
|
163
|
+
return token = 17;
|
|
164
|
+
}
|
|
165
|
+
let code = text.charCodeAt(pos);
|
|
166
|
+
if (isWhiteSpace(code)) {
|
|
167
|
+
do {
|
|
168
|
+
pos++;
|
|
169
|
+
value += String.fromCharCode(code);
|
|
170
|
+
code = text.charCodeAt(pos);
|
|
171
|
+
} while (isWhiteSpace(code));
|
|
172
|
+
return token = 15;
|
|
173
|
+
}
|
|
174
|
+
if (isLineBreak(code)) {
|
|
175
|
+
pos++;
|
|
176
|
+
value += String.fromCharCode(code);
|
|
177
|
+
if (code === 13 && text.charCodeAt(pos) === 10) {
|
|
178
|
+
pos++;
|
|
179
|
+
value += "\n";
|
|
180
|
+
}
|
|
181
|
+
lineNumber++;
|
|
182
|
+
tokenLineStartOffset = pos;
|
|
183
|
+
return token = 14;
|
|
184
|
+
}
|
|
185
|
+
switch (code) {
|
|
186
|
+
// tokens: []{}:,
|
|
187
|
+
case 123:
|
|
188
|
+
pos++;
|
|
189
|
+
return token = 1;
|
|
190
|
+
case 125:
|
|
191
|
+
pos++;
|
|
192
|
+
return token = 2;
|
|
193
|
+
case 91:
|
|
194
|
+
pos++;
|
|
195
|
+
return token = 3;
|
|
196
|
+
case 93:
|
|
197
|
+
pos++;
|
|
198
|
+
return token = 4;
|
|
199
|
+
case 58:
|
|
200
|
+
pos++;
|
|
201
|
+
return token = 6;
|
|
202
|
+
case 44:
|
|
203
|
+
pos++;
|
|
204
|
+
return token = 5;
|
|
205
|
+
// strings
|
|
206
|
+
case 34:
|
|
207
|
+
pos++;
|
|
208
|
+
value = scanString();
|
|
209
|
+
return token = 10;
|
|
210
|
+
// comments
|
|
211
|
+
case 47:
|
|
212
|
+
const start = pos - 1;
|
|
213
|
+
if (text.charCodeAt(pos + 1) === 47) {
|
|
214
|
+
pos += 2;
|
|
215
|
+
while (pos < len) {
|
|
216
|
+
if (isLineBreak(text.charCodeAt(pos))) {
|
|
217
|
+
break;
|
|
218
|
+
}
|
|
219
|
+
pos++;
|
|
220
|
+
}
|
|
221
|
+
value = text.substring(start, pos);
|
|
222
|
+
return token = 12;
|
|
223
|
+
}
|
|
224
|
+
if (text.charCodeAt(pos + 1) === 42) {
|
|
225
|
+
pos += 2;
|
|
226
|
+
const safeLength = len - 1;
|
|
227
|
+
let commentClosed = false;
|
|
228
|
+
while (pos < safeLength) {
|
|
229
|
+
const ch = text.charCodeAt(pos);
|
|
230
|
+
if (ch === 42 && text.charCodeAt(pos + 1) === 47) {
|
|
231
|
+
pos += 2;
|
|
232
|
+
commentClosed = true;
|
|
233
|
+
break;
|
|
234
|
+
}
|
|
235
|
+
pos++;
|
|
236
|
+
if (isLineBreak(ch)) {
|
|
237
|
+
if (ch === 13 && text.charCodeAt(pos) === 10) {
|
|
238
|
+
pos++;
|
|
239
|
+
}
|
|
240
|
+
lineNumber++;
|
|
241
|
+
tokenLineStartOffset = pos;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
if (!commentClosed) {
|
|
245
|
+
pos++;
|
|
246
|
+
scanError = 1;
|
|
247
|
+
}
|
|
248
|
+
value = text.substring(start, pos);
|
|
249
|
+
return token = 13;
|
|
250
|
+
}
|
|
251
|
+
value += String.fromCharCode(code);
|
|
252
|
+
pos++;
|
|
253
|
+
return token = 16;
|
|
254
|
+
// numbers
|
|
255
|
+
case 45:
|
|
256
|
+
value += String.fromCharCode(code);
|
|
257
|
+
pos++;
|
|
258
|
+
if (pos === len || !isDigit(text.charCodeAt(pos))) {
|
|
259
|
+
return token = 16;
|
|
260
|
+
}
|
|
261
|
+
// found a minus, followed by a number so
|
|
262
|
+
// we fall through to proceed with scanning
|
|
263
|
+
// numbers
|
|
264
|
+
case 48:
|
|
265
|
+
case 49:
|
|
266
|
+
case 50:
|
|
267
|
+
case 51:
|
|
268
|
+
case 52:
|
|
269
|
+
case 53:
|
|
270
|
+
case 54:
|
|
271
|
+
case 55:
|
|
272
|
+
case 56:
|
|
273
|
+
case 57:
|
|
274
|
+
value += scanNumber();
|
|
275
|
+
return token = 11;
|
|
276
|
+
// literals and unknown symbols
|
|
277
|
+
default:
|
|
278
|
+
while (pos < len && isUnknownContentCharacter(code)) {
|
|
279
|
+
pos++;
|
|
280
|
+
code = text.charCodeAt(pos);
|
|
281
|
+
}
|
|
282
|
+
if (tokenOffset !== pos) {
|
|
283
|
+
value = text.substring(tokenOffset, pos);
|
|
284
|
+
switch (value) {
|
|
285
|
+
case "true":
|
|
286
|
+
return token = 8;
|
|
287
|
+
case "false":
|
|
288
|
+
return token = 9;
|
|
289
|
+
case "null":
|
|
290
|
+
return token = 7;
|
|
291
|
+
}
|
|
292
|
+
return token = 16;
|
|
293
|
+
}
|
|
294
|
+
value += String.fromCharCode(code);
|
|
295
|
+
pos++;
|
|
296
|
+
return token = 16;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
function isUnknownContentCharacter(code) {
|
|
300
|
+
if (isWhiteSpace(code) || isLineBreak(code)) {
|
|
301
|
+
return false;
|
|
302
|
+
}
|
|
303
|
+
switch (code) {
|
|
304
|
+
case 125:
|
|
305
|
+
case 93:
|
|
306
|
+
case 123:
|
|
307
|
+
case 91:
|
|
308
|
+
case 34:
|
|
309
|
+
case 58:
|
|
310
|
+
case 44:
|
|
311
|
+
case 47:
|
|
312
|
+
return false;
|
|
313
|
+
}
|
|
314
|
+
return true;
|
|
315
|
+
}
|
|
316
|
+
function scanNextNonTrivia() {
|
|
317
|
+
let result;
|
|
318
|
+
do {
|
|
319
|
+
result = scanNext();
|
|
320
|
+
} while (result >= 12 && result <= 15);
|
|
321
|
+
return result;
|
|
322
|
+
}
|
|
323
|
+
return {
|
|
324
|
+
setPosition,
|
|
325
|
+
getPosition: () => pos,
|
|
326
|
+
scan: ignoreTrivia ? scanNextNonTrivia : scanNext,
|
|
327
|
+
getToken: () => token,
|
|
328
|
+
getTokenValue: () => value,
|
|
329
|
+
getTokenOffset: () => tokenOffset,
|
|
330
|
+
getTokenLength: () => pos - tokenOffset,
|
|
331
|
+
getTokenStartLine: () => lineStartOffset,
|
|
332
|
+
getTokenStartCharacter: () => tokenOffset - prevTokenLineStartOffset,
|
|
333
|
+
getTokenError: () => scanError
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
function isWhiteSpace(ch) {
|
|
337
|
+
return ch === 32 || ch === 9;
|
|
338
|
+
}
|
|
339
|
+
function isLineBreak(ch) {
|
|
340
|
+
return ch === 10 || ch === 13;
|
|
341
|
+
}
|
|
342
|
+
function isDigit(ch) {
|
|
343
|
+
return ch >= 48 && ch <= 57;
|
|
344
|
+
}
|
|
345
|
+
var CharacterCodes;
|
|
346
|
+
(function(CharacterCodes2) {
|
|
347
|
+
CharacterCodes2[CharacterCodes2["lineFeed"] = 10] = "lineFeed";
|
|
348
|
+
CharacterCodes2[CharacterCodes2["carriageReturn"] = 13] = "carriageReturn";
|
|
349
|
+
CharacterCodes2[CharacterCodes2["space"] = 32] = "space";
|
|
350
|
+
CharacterCodes2[CharacterCodes2["_0"] = 48] = "_0";
|
|
351
|
+
CharacterCodes2[CharacterCodes2["_1"] = 49] = "_1";
|
|
352
|
+
CharacterCodes2[CharacterCodes2["_2"] = 50] = "_2";
|
|
353
|
+
CharacterCodes2[CharacterCodes2["_3"] = 51] = "_3";
|
|
354
|
+
CharacterCodes2[CharacterCodes2["_4"] = 52] = "_4";
|
|
355
|
+
CharacterCodes2[CharacterCodes2["_5"] = 53] = "_5";
|
|
356
|
+
CharacterCodes2[CharacterCodes2["_6"] = 54] = "_6";
|
|
357
|
+
CharacterCodes2[CharacterCodes2["_7"] = 55] = "_7";
|
|
358
|
+
CharacterCodes2[CharacterCodes2["_8"] = 56] = "_8";
|
|
359
|
+
CharacterCodes2[CharacterCodes2["_9"] = 57] = "_9";
|
|
360
|
+
CharacterCodes2[CharacterCodes2["a"] = 97] = "a";
|
|
361
|
+
CharacterCodes2[CharacterCodes2["b"] = 98] = "b";
|
|
362
|
+
CharacterCodes2[CharacterCodes2["c"] = 99] = "c";
|
|
363
|
+
CharacterCodes2[CharacterCodes2["d"] = 100] = "d";
|
|
364
|
+
CharacterCodes2[CharacterCodes2["e"] = 101] = "e";
|
|
365
|
+
CharacterCodes2[CharacterCodes2["f"] = 102] = "f";
|
|
366
|
+
CharacterCodes2[CharacterCodes2["g"] = 103] = "g";
|
|
367
|
+
CharacterCodes2[CharacterCodes2["h"] = 104] = "h";
|
|
368
|
+
CharacterCodes2[CharacterCodes2["i"] = 105] = "i";
|
|
369
|
+
CharacterCodes2[CharacterCodes2["j"] = 106] = "j";
|
|
370
|
+
CharacterCodes2[CharacterCodes2["k"] = 107] = "k";
|
|
371
|
+
CharacterCodes2[CharacterCodes2["l"] = 108] = "l";
|
|
372
|
+
CharacterCodes2[CharacterCodes2["m"] = 109] = "m";
|
|
373
|
+
CharacterCodes2[CharacterCodes2["n"] = 110] = "n";
|
|
374
|
+
CharacterCodes2[CharacterCodes2["o"] = 111] = "o";
|
|
375
|
+
CharacterCodes2[CharacterCodes2["p"] = 112] = "p";
|
|
376
|
+
CharacterCodes2[CharacterCodes2["q"] = 113] = "q";
|
|
377
|
+
CharacterCodes2[CharacterCodes2["r"] = 114] = "r";
|
|
378
|
+
CharacterCodes2[CharacterCodes2["s"] = 115] = "s";
|
|
379
|
+
CharacterCodes2[CharacterCodes2["t"] = 116] = "t";
|
|
380
|
+
CharacterCodes2[CharacterCodes2["u"] = 117] = "u";
|
|
381
|
+
CharacterCodes2[CharacterCodes2["v"] = 118] = "v";
|
|
382
|
+
CharacterCodes2[CharacterCodes2["w"] = 119] = "w";
|
|
383
|
+
CharacterCodes2[CharacterCodes2["x"] = 120] = "x";
|
|
384
|
+
CharacterCodes2[CharacterCodes2["y"] = 121] = "y";
|
|
385
|
+
CharacterCodes2[CharacterCodes2["z"] = 122] = "z";
|
|
386
|
+
CharacterCodes2[CharacterCodes2["A"] = 65] = "A";
|
|
387
|
+
CharacterCodes2[CharacterCodes2["B"] = 66] = "B";
|
|
388
|
+
CharacterCodes2[CharacterCodes2["C"] = 67] = "C";
|
|
389
|
+
CharacterCodes2[CharacterCodes2["D"] = 68] = "D";
|
|
390
|
+
CharacterCodes2[CharacterCodes2["E"] = 69] = "E";
|
|
391
|
+
CharacterCodes2[CharacterCodes2["F"] = 70] = "F";
|
|
392
|
+
CharacterCodes2[CharacterCodes2["G"] = 71] = "G";
|
|
393
|
+
CharacterCodes2[CharacterCodes2["H"] = 72] = "H";
|
|
394
|
+
CharacterCodes2[CharacterCodes2["I"] = 73] = "I";
|
|
395
|
+
CharacterCodes2[CharacterCodes2["J"] = 74] = "J";
|
|
396
|
+
CharacterCodes2[CharacterCodes2["K"] = 75] = "K";
|
|
397
|
+
CharacterCodes2[CharacterCodes2["L"] = 76] = "L";
|
|
398
|
+
CharacterCodes2[CharacterCodes2["M"] = 77] = "M";
|
|
399
|
+
CharacterCodes2[CharacterCodes2["N"] = 78] = "N";
|
|
400
|
+
CharacterCodes2[CharacterCodes2["O"] = 79] = "O";
|
|
401
|
+
CharacterCodes2[CharacterCodes2["P"] = 80] = "P";
|
|
402
|
+
CharacterCodes2[CharacterCodes2["Q"] = 81] = "Q";
|
|
403
|
+
CharacterCodes2[CharacterCodes2["R"] = 82] = "R";
|
|
404
|
+
CharacterCodes2[CharacterCodes2["S"] = 83] = "S";
|
|
405
|
+
CharacterCodes2[CharacterCodes2["T"] = 84] = "T";
|
|
406
|
+
CharacterCodes2[CharacterCodes2["U"] = 85] = "U";
|
|
407
|
+
CharacterCodes2[CharacterCodes2["V"] = 86] = "V";
|
|
408
|
+
CharacterCodes2[CharacterCodes2["W"] = 87] = "W";
|
|
409
|
+
CharacterCodes2[CharacterCodes2["X"] = 88] = "X";
|
|
410
|
+
CharacterCodes2[CharacterCodes2["Y"] = 89] = "Y";
|
|
411
|
+
CharacterCodes2[CharacterCodes2["Z"] = 90] = "Z";
|
|
412
|
+
CharacterCodes2[CharacterCodes2["asterisk"] = 42] = "asterisk";
|
|
413
|
+
CharacterCodes2[CharacterCodes2["backslash"] = 92] = "backslash";
|
|
414
|
+
CharacterCodes2[CharacterCodes2["closeBrace"] = 125] = "closeBrace";
|
|
415
|
+
CharacterCodes2[CharacterCodes2["closeBracket"] = 93] = "closeBracket";
|
|
416
|
+
CharacterCodes2[CharacterCodes2["colon"] = 58] = "colon";
|
|
417
|
+
CharacterCodes2[CharacterCodes2["comma"] = 44] = "comma";
|
|
418
|
+
CharacterCodes2[CharacterCodes2["dot"] = 46] = "dot";
|
|
419
|
+
CharacterCodes2[CharacterCodes2["doubleQuote"] = 34] = "doubleQuote";
|
|
420
|
+
CharacterCodes2[CharacterCodes2["minus"] = 45] = "minus";
|
|
421
|
+
CharacterCodes2[CharacterCodes2["openBrace"] = 123] = "openBrace";
|
|
422
|
+
CharacterCodes2[CharacterCodes2["openBracket"] = 91] = "openBracket";
|
|
423
|
+
CharacterCodes2[CharacterCodes2["plus"] = 43] = "plus";
|
|
424
|
+
CharacterCodes2[CharacterCodes2["slash"] = 47] = "slash";
|
|
425
|
+
CharacterCodes2[CharacterCodes2["formFeed"] = 12] = "formFeed";
|
|
426
|
+
CharacterCodes2[CharacterCodes2["tab"] = 9] = "tab";
|
|
427
|
+
})(CharacterCodes || (CharacterCodes = {}));
|
|
428
|
+
|
|
429
|
+
// node_modules/jsonc-parser/lib/esm/impl/string-intern.js
|
|
430
|
+
var cachedSpaces = new Array(20).fill(0).map((_, index) => {
|
|
431
|
+
return " ".repeat(index);
|
|
13
432
|
});
|
|
14
|
-
var
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
433
|
+
var maxCachedValues = 200;
|
|
434
|
+
var cachedBreakLinesWithSpaces = {
|
|
435
|
+
" ": {
|
|
436
|
+
"\n": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
437
|
+
return "\n" + " ".repeat(index);
|
|
438
|
+
}),
|
|
439
|
+
"\r": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
440
|
+
return "\r" + " ".repeat(index);
|
|
441
|
+
}),
|
|
442
|
+
"\r\n": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
443
|
+
return "\r\n" + " ".repeat(index);
|
|
444
|
+
})
|
|
445
|
+
},
|
|
446
|
+
" ": {
|
|
447
|
+
"\n": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
448
|
+
return "\n" + " ".repeat(index);
|
|
449
|
+
}),
|
|
450
|
+
"\r": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
451
|
+
return "\r" + " ".repeat(index);
|
|
452
|
+
}),
|
|
453
|
+
"\r\n": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
454
|
+
return "\r\n" + " ".repeat(index);
|
|
455
|
+
})
|
|
22
456
|
}
|
|
23
|
-
return to;
|
|
24
457
|
};
|
|
25
|
-
var
|
|
26
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
27
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
28
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
29
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
30
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
31
|
-
mod
|
|
32
|
-
));
|
|
458
|
+
var supportedEols = ["\n", "\r", "\r\n"];
|
|
33
459
|
|
|
34
|
-
// node_modules/jsonc-parser/lib/
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
(
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
460
|
+
// node_modules/jsonc-parser/lib/esm/impl/format.js
|
|
461
|
+
function format(documentText, range, options) {
|
|
462
|
+
let initialIndentLevel;
|
|
463
|
+
let formatText;
|
|
464
|
+
let formatTextStart;
|
|
465
|
+
let rangeStart;
|
|
466
|
+
let rangeEnd;
|
|
467
|
+
if (range) {
|
|
468
|
+
rangeStart = range.offset;
|
|
469
|
+
rangeEnd = rangeStart + range.length;
|
|
470
|
+
formatTextStart = rangeStart;
|
|
471
|
+
while (formatTextStart > 0 && !isEOL(documentText, formatTextStart - 1)) {
|
|
472
|
+
formatTextStart--;
|
|
473
|
+
}
|
|
474
|
+
let endOffset = rangeEnd;
|
|
475
|
+
while (endOffset < documentText.length && !isEOL(documentText, endOffset)) {
|
|
476
|
+
endOffset++;
|
|
477
|
+
}
|
|
478
|
+
formatText = documentText.substring(formatTextStart, endOffset);
|
|
479
|
+
initialIndentLevel = computeIndentLevel(formatText, options);
|
|
480
|
+
} else {
|
|
481
|
+
formatText = documentText;
|
|
482
|
+
initialIndentLevel = 0;
|
|
483
|
+
formatTextStart = 0;
|
|
484
|
+
rangeStart = 0;
|
|
485
|
+
rangeEnd = documentText.length;
|
|
486
|
+
}
|
|
487
|
+
const eol = getEOL(options, documentText);
|
|
488
|
+
const eolFastPathSupported = supportedEols.includes(eol);
|
|
489
|
+
let numberLineBreaks = 0;
|
|
490
|
+
let indentLevel = 0;
|
|
491
|
+
let indentValue;
|
|
492
|
+
if (options.insertSpaces) {
|
|
493
|
+
indentValue = cachedSpaces[options.tabSize || 4] ?? repeat(cachedSpaces[1], options.tabSize || 4);
|
|
494
|
+
} else {
|
|
495
|
+
indentValue = " ";
|
|
496
|
+
}
|
|
497
|
+
const indentType = indentValue === " " ? " " : " ";
|
|
498
|
+
let scanner = createScanner(formatText, false);
|
|
499
|
+
let hasError = false;
|
|
500
|
+
function newLinesAndIndent() {
|
|
501
|
+
if (numberLineBreaks > 1) {
|
|
502
|
+
return repeat(eol, numberLineBreaks) + repeat(indentValue, initialIndentLevel + indentLevel);
|
|
503
|
+
}
|
|
504
|
+
const amountOfSpaces = indentValue.length * (initialIndentLevel + indentLevel);
|
|
505
|
+
if (!eolFastPathSupported || amountOfSpaces > cachedBreakLinesWithSpaces[indentType][eol].length) {
|
|
506
|
+
return eol + repeat(indentValue, initialIndentLevel + indentLevel);
|
|
507
|
+
}
|
|
508
|
+
if (amountOfSpaces <= 0) {
|
|
509
|
+
return eol;
|
|
510
|
+
}
|
|
511
|
+
return cachedBreakLinesWithSpaces[indentType][eol][amountOfSpaces];
|
|
512
|
+
}
|
|
513
|
+
function scanNext() {
|
|
514
|
+
let token = scanner.scan();
|
|
515
|
+
numberLineBreaks = 0;
|
|
516
|
+
while (token === 15 || token === 14) {
|
|
517
|
+
if (token === 14 && options.keepLines) {
|
|
518
|
+
numberLineBreaks += 1;
|
|
519
|
+
} else if (token === 14) {
|
|
520
|
+
numberLineBreaks = 1;
|
|
521
|
+
}
|
|
522
|
+
token = scanner.scan();
|
|
523
|
+
}
|
|
524
|
+
hasError = token === 16 || scanner.getTokenError() !== 0;
|
|
525
|
+
return token;
|
|
526
|
+
}
|
|
527
|
+
const editOperations = [];
|
|
528
|
+
function addEdit(text, startOffset, endOffset) {
|
|
529
|
+
if (!hasError && (!range || startOffset < rangeEnd && endOffset > rangeStart) && documentText.substring(startOffset, endOffset) !== text) {
|
|
530
|
+
editOperations.push({ offset: startOffset, length: endOffset - startOffset, content: text });
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
let firstToken = scanNext();
|
|
534
|
+
if (options.keepLines && numberLineBreaks > 0) {
|
|
535
|
+
addEdit(repeat(eol, numberLineBreaks), 0, 0);
|
|
536
|
+
}
|
|
537
|
+
if (firstToken !== 17) {
|
|
538
|
+
let firstTokenStart = scanner.getTokenOffset() + formatTextStart;
|
|
539
|
+
let initialIndent = indentValue.length * initialIndentLevel < 20 && options.insertSpaces ? cachedSpaces[indentValue.length * initialIndentLevel] : repeat(indentValue, initialIndentLevel);
|
|
540
|
+
addEdit(initialIndent, formatTextStart, firstTokenStart);
|
|
541
|
+
}
|
|
542
|
+
while (firstToken !== 17) {
|
|
543
|
+
let firstTokenEnd = scanner.getTokenOffset() + scanner.getTokenLength() + formatTextStart;
|
|
544
|
+
let secondToken = scanNext();
|
|
545
|
+
let replaceContent = "";
|
|
546
|
+
let needsLineBreak = false;
|
|
547
|
+
while (numberLineBreaks === 0 && (secondToken === 12 || secondToken === 13)) {
|
|
548
|
+
let commentTokenStart = scanner.getTokenOffset() + formatTextStart;
|
|
549
|
+
addEdit(cachedSpaces[1], firstTokenEnd, commentTokenStart);
|
|
550
|
+
firstTokenEnd = scanner.getTokenOffset() + scanner.getTokenLength() + formatTextStart;
|
|
551
|
+
needsLineBreak = secondToken === 12;
|
|
552
|
+
replaceContent = needsLineBreak ? newLinesAndIndent() : "";
|
|
553
|
+
secondToken = scanNext();
|
|
554
|
+
}
|
|
555
|
+
if (secondToken === 2) {
|
|
556
|
+
if (firstToken !== 1) {
|
|
557
|
+
indentLevel--;
|
|
558
|
+
}
|
|
559
|
+
;
|
|
560
|
+
if (options.keepLines && numberLineBreaks > 0 || !options.keepLines && firstToken !== 1) {
|
|
561
|
+
replaceContent = newLinesAndIndent();
|
|
562
|
+
} else if (options.keepLines) {
|
|
563
|
+
replaceContent = cachedSpaces[1];
|
|
564
|
+
}
|
|
565
|
+
} else if (secondToken === 4) {
|
|
566
|
+
if (firstToken !== 3) {
|
|
567
|
+
indentLevel--;
|
|
568
|
+
}
|
|
569
|
+
;
|
|
570
|
+
if (options.keepLines && numberLineBreaks > 0 || !options.keepLines && firstToken !== 3) {
|
|
571
|
+
replaceContent = newLinesAndIndent();
|
|
572
|
+
} else if (options.keepLines) {
|
|
573
|
+
replaceContent = cachedSpaces[1];
|
|
574
|
+
}
|
|
575
|
+
} else {
|
|
576
|
+
switch (firstToken) {
|
|
577
|
+
case 3:
|
|
578
|
+
case 1:
|
|
579
|
+
indentLevel++;
|
|
580
|
+
if (options.keepLines && numberLineBreaks > 0 || !options.keepLines) {
|
|
581
|
+
replaceContent = newLinesAndIndent();
|
|
582
|
+
} else {
|
|
583
|
+
replaceContent = cachedSpaces[1];
|
|
584
|
+
}
|
|
585
|
+
break;
|
|
586
|
+
case 5:
|
|
587
|
+
if (options.keepLines && numberLineBreaks > 0 || !options.keepLines) {
|
|
588
|
+
replaceContent = newLinesAndIndent();
|
|
589
|
+
} else {
|
|
590
|
+
replaceContent = cachedSpaces[1];
|
|
591
|
+
}
|
|
592
|
+
break;
|
|
593
|
+
case 12:
|
|
594
|
+
replaceContent = newLinesAndIndent();
|
|
595
|
+
break;
|
|
596
|
+
case 13:
|
|
597
|
+
if (numberLineBreaks > 0) {
|
|
598
|
+
replaceContent = newLinesAndIndent();
|
|
599
|
+
} else if (!needsLineBreak) {
|
|
600
|
+
replaceContent = cachedSpaces[1];
|
|
601
|
+
}
|
|
602
|
+
break;
|
|
603
|
+
case 6:
|
|
604
|
+
if (options.keepLines && numberLineBreaks > 0) {
|
|
605
|
+
replaceContent = newLinesAndIndent();
|
|
606
|
+
} else if (!needsLineBreak) {
|
|
607
|
+
replaceContent = cachedSpaces[1];
|
|
608
|
+
}
|
|
609
|
+
break;
|
|
610
|
+
case 10:
|
|
611
|
+
if (options.keepLines && numberLineBreaks > 0) {
|
|
612
|
+
replaceContent = newLinesAndIndent();
|
|
613
|
+
} else if (secondToken === 6 && !needsLineBreak) {
|
|
614
|
+
replaceContent = "";
|
|
615
|
+
}
|
|
616
|
+
break;
|
|
617
|
+
case 7:
|
|
618
|
+
case 8:
|
|
619
|
+
case 9:
|
|
620
|
+
case 11:
|
|
621
|
+
case 2:
|
|
622
|
+
case 4:
|
|
623
|
+
if (options.keepLines && numberLineBreaks > 0) {
|
|
624
|
+
replaceContent = newLinesAndIndent();
|
|
625
|
+
} else {
|
|
626
|
+
if ((secondToken === 12 || secondToken === 13) && !needsLineBreak) {
|
|
627
|
+
replaceContent = cachedSpaces[1];
|
|
628
|
+
} else if (secondToken !== 5 && secondToken !== 17) {
|
|
629
|
+
hasError = true;
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
break;
|
|
633
|
+
case 16:
|
|
634
|
+
hasError = true;
|
|
635
|
+
break;
|
|
636
|
+
}
|
|
637
|
+
if (numberLineBreaks > 0 && (secondToken === 12 || secondToken === 13)) {
|
|
638
|
+
replaceContent = newLinesAndIndent();
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
if (secondToken === 17) {
|
|
642
|
+
if (options.keepLines && numberLineBreaks > 0) {
|
|
643
|
+
replaceContent = newLinesAndIndent();
|
|
644
|
+
} else {
|
|
645
|
+
replaceContent = options.insertFinalNewline ? eol : "";
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
const secondTokenStart = scanner.getTokenOffset() + formatTextStart;
|
|
649
|
+
addEdit(replaceContent, firstTokenEnd, secondTokenStart);
|
|
650
|
+
firstToken = secondToken;
|
|
651
|
+
}
|
|
652
|
+
return editOperations;
|
|
653
|
+
}
|
|
654
|
+
function repeat(s, count) {
|
|
655
|
+
let result = "";
|
|
656
|
+
for (let i = 0; i < count; i++) {
|
|
657
|
+
result += s;
|
|
658
|
+
}
|
|
659
|
+
return result;
|
|
660
|
+
}
|
|
661
|
+
function computeIndentLevel(content, options) {
|
|
662
|
+
let i = 0;
|
|
663
|
+
let nChars = 0;
|
|
664
|
+
const tabSize = options.tabSize || 4;
|
|
665
|
+
while (i < content.length) {
|
|
666
|
+
let ch = content.charAt(i);
|
|
667
|
+
if (ch === cachedSpaces[1]) {
|
|
668
|
+
nChars++;
|
|
669
|
+
} else if (ch === " ") {
|
|
670
|
+
nChars += tabSize;
|
|
671
|
+
} else {
|
|
672
|
+
break;
|
|
673
|
+
}
|
|
674
|
+
i++;
|
|
675
|
+
}
|
|
676
|
+
return Math.floor(nChars / tabSize);
|
|
677
|
+
}
|
|
678
|
+
function getEOL(options, text) {
|
|
679
|
+
for (let i = 0; i < text.length; i++) {
|
|
680
|
+
const ch = text.charAt(i);
|
|
681
|
+
if (ch === "\r") {
|
|
682
|
+
if (i + 1 < text.length && text.charAt(i + 1) === "\n") {
|
|
683
|
+
return "\r\n";
|
|
684
|
+
}
|
|
685
|
+
return "\r";
|
|
686
|
+
} else if (ch === "\n") {
|
|
687
|
+
return "\n";
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
return options && options.eol || "\n";
|
|
691
|
+
}
|
|
692
|
+
function isEOL(text, offset) {
|
|
693
|
+
return "\r\n".indexOf(text.charAt(offset)) !== -1;
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
// node_modules/jsonc-parser/lib/esm/impl/parser.js
|
|
697
|
+
var ParseOptions;
|
|
698
|
+
(function(ParseOptions2) {
|
|
699
|
+
ParseOptions2.DEFAULT = {
|
|
700
|
+
allowTrailingComma: false
|
|
701
|
+
};
|
|
702
|
+
})(ParseOptions || (ParseOptions = {}));
|
|
703
|
+
function parse(text, errors = [], options = ParseOptions.DEFAULT) {
|
|
704
|
+
let currentProperty = null;
|
|
705
|
+
let currentParent = [];
|
|
706
|
+
const previousParents = [];
|
|
707
|
+
function onValue(value) {
|
|
708
|
+
if (Array.isArray(currentParent)) {
|
|
709
|
+
currentParent.push(value);
|
|
710
|
+
} else if (currentProperty !== null) {
|
|
711
|
+
currentParent[currentProperty] = value;
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
const visitor = {
|
|
715
|
+
onObjectBegin: () => {
|
|
716
|
+
const object = {};
|
|
717
|
+
onValue(object);
|
|
718
|
+
previousParents.push(currentParent);
|
|
719
|
+
currentParent = object;
|
|
720
|
+
currentProperty = null;
|
|
721
|
+
},
|
|
722
|
+
onObjectProperty: (name) => {
|
|
723
|
+
currentProperty = name;
|
|
724
|
+
},
|
|
725
|
+
onObjectEnd: () => {
|
|
726
|
+
currentParent = previousParents.pop();
|
|
727
|
+
},
|
|
728
|
+
onArrayBegin: () => {
|
|
729
|
+
const array = [];
|
|
730
|
+
onValue(array);
|
|
731
|
+
previousParents.push(currentParent);
|
|
732
|
+
currentParent = array;
|
|
733
|
+
currentProperty = null;
|
|
734
|
+
},
|
|
735
|
+
onArrayEnd: () => {
|
|
736
|
+
currentParent = previousParents.pop();
|
|
737
|
+
},
|
|
738
|
+
onLiteralValue: onValue,
|
|
739
|
+
onError: (error, offset, length) => {
|
|
740
|
+
errors.push({ error, offset, length });
|
|
741
|
+
}
|
|
742
|
+
};
|
|
743
|
+
visit(text, visitor, options);
|
|
744
|
+
return currentParent[0];
|
|
745
|
+
}
|
|
746
|
+
function parseTree(text, errors = [], options = ParseOptions.DEFAULT) {
|
|
747
|
+
let currentParent = { type: "array", offset: -1, length: -1, children: [], parent: void 0 };
|
|
748
|
+
function ensurePropertyComplete(endOffset) {
|
|
749
|
+
if (currentParent.type === "property") {
|
|
750
|
+
currentParent.length = endOffset - currentParent.offset;
|
|
751
|
+
currentParent = currentParent.parent;
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
function onValue(valueNode) {
|
|
755
|
+
currentParent.children.push(valueNode);
|
|
756
|
+
return valueNode;
|
|
757
|
+
}
|
|
758
|
+
const visitor = {
|
|
759
|
+
onObjectBegin: (offset) => {
|
|
760
|
+
currentParent = onValue({ type: "object", offset, length: -1, parent: currentParent, children: [] });
|
|
761
|
+
},
|
|
762
|
+
onObjectProperty: (name, offset, length) => {
|
|
763
|
+
currentParent = onValue({ type: "property", offset, length: -1, parent: currentParent, children: [] });
|
|
764
|
+
currentParent.children.push({ type: "string", value: name, offset, length, parent: currentParent });
|
|
765
|
+
},
|
|
766
|
+
onObjectEnd: (offset, length) => {
|
|
767
|
+
ensurePropertyComplete(offset + length);
|
|
768
|
+
currentParent.length = offset + length - currentParent.offset;
|
|
769
|
+
currentParent = currentParent.parent;
|
|
770
|
+
ensurePropertyComplete(offset + length);
|
|
771
|
+
},
|
|
772
|
+
onArrayBegin: (offset, length) => {
|
|
773
|
+
currentParent = onValue({ type: "array", offset, length: -1, parent: currentParent, children: [] });
|
|
774
|
+
},
|
|
775
|
+
onArrayEnd: (offset, length) => {
|
|
776
|
+
currentParent.length = offset + length - currentParent.offset;
|
|
777
|
+
currentParent = currentParent.parent;
|
|
778
|
+
ensurePropertyComplete(offset + length);
|
|
779
|
+
},
|
|
780
|
+
onLiteralValue: (value, offset, length) => {
|
|
781
|
+
onValue({ type: getNodeType(value), offset, length, parent: currentParent, value });
|
|
782
|
+
ensurePropertyComplete(offset + length);
|
|
783
|
+
},
|
|
784
|
+
onSeparator: (sep, offset, length) => {
|
|
785
|
+
if (currentParent.type === "property") {
|
|
786
|
+
if (sep === ":") {
|
|
787
|
+
currentParent.colonOffset = offset;
|
|
788
|
+
} else if (sep === ",") {
|
|
789
|
+
ensurePropertyComplete(offset);
|
|
145
790
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
791
|
+
}
|
|
792
|
+
},
|
|
793
|
+
onError: (error, offset, length) => {
|
|
794
|
+
errors.push({ error, offset, length });
|
|
795
|
+
}
|
|
796
|
+
};
|
|
797
|
+
visit(text, visitor, options);
|
|
798
|
+
const result = currentParent.children[0];
|
|
799
|
+
if (result) {
|
|
800
|
+
delete result.parent;
|
|
801
|
+
}
|
|
802
|
+
return result;
|
|
803
|
+
}
|
|
804
|
+
function findNodeAtLocation(root, path) {
|
|
805
|
+
if (!root) {
|
|
806
|
+
return void 0;
|
|
807
|
+
}
|
|
808
|
+
let node = root;
|
|
809
|
+
for (let segment of path) {
|
|
810
|
+
if (typeof segment === "string") {
|
|
811
|
+
if (node.type !== "object" || !Array.isArray(node.children)) {
|
|
812
|
+
return void 0;
|
|
813
|
+
}
|
|
814
|
+
let found = false;
|
|
815
|
+
for (const propertyNode of node.children) {
|
|
816
|
+
if (Array.isArray(propertyNode.children) && propertyNode.children[0].value === segment && propertyNode.children.length === 2) {
|
|
817
|
+
node = propertyNode.children[1];
|
|
818
|
+
found = true;
|
|
819
|
+
break;
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
if (!found) {
|
|
823
|
+
return void 0;
|
|
824
|
+
}
|
|
825
|
+
} else {
|
|
826
|
+
const index = segment;
|
|
827
|
+
if (node.type !== "array" || index < 0 || !Array.isArray(node.children) || index >= node.children.length) {
|
|
828
|
+
return void 0;
|
|
829
|
+
}
|
|
830
|
+
node = node.children[index];
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
return node;
|
|
834
|
+
}
|
|
835
|
+
function visit(text, visitor, options = ParseOptions.DEFAULT) {
|
|
836
|
+
const _scanner = createScanner(text, false);
|
|
837
|
+
const _jsonPath = [];
|
|
838
|
+
let suppressedCallbacks = 0;
|
|
839
|
+
function toNoArgVisit(visitFunction) {
|
|
840
|
+
return visitFunction ? () => suppressedCallbacks === 0 && visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
|
|
841
|
+
}
|
|
842
|
+
function toOneArgVisit(visitFunction) {
|
|
843
|
+
return visitFunction ? (arg) => suppressedCallbacks === 0 && visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
|
|
844
|
+
}
|
|
845
|
+
function toOneArgVisitWithPath(visitFunction) {
|
|
846
|
+
return visitFunction ? (arg) => suppressedCallbacks === 0 && visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice()) : () => true;
|
|
847
|
+
}
|
|
848
|
+
function toBeginVisit(visitFunction) {
|
|
849
|
+
return visitFunction ? () => {
|
|
850
|
+
if (suppressedCallbacks > 0) {
|
|
851
|
+
suppressedCallbacks++;
|
|
852
|
+
} else {
|
|
853
|
+
let cbReturn = visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice());
|
|
854
|
+
if (cbReturn === false) {
|
|
855
|
+
suppressedCallbacks = 1;
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
} : () => true;
|
|
859
|
+
}
|
|
860
|
+
function toEndVisit(visitFunction) {
|
|
861
|
+
return visitFunction ? () => {
|
|
862
|
+
if (suppressedCallbacks > 0) {
|
|
863
|
+
suppressedCallbacks--;
|
|
864
|
+
}
|
|
865
|
+
if (suppressedCallbacks === 0) {
|
|
866
|
+
visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter());
|
|
867
|
+
}
|
|
868
|
+
} : () => true;
|
|
869
|
+
}
|
|
870
|
+
const onObjectBegin = toBeginVisit(visitor.onObjectBegin), onObjectProperty = toOneArgVisitWithPath(visitor.onObjectProperty), onObjectEnd = toEndVisit(visitor.onObjectEnd), onArrayBegin = toBeginVisit(visitor.onArrayBegin), onArrayEnd = toEndVisit(visitor.onArrayEnd), onLiteralValue = toOneArgVisitWithPath(visitor.onLiteralValue), onSeparator = toOneArgVisit(visitor.onSeparator), onComment = toNoArgVisit(visitor.onComment), onError = toOneArgVisit(visitor.onError);
|
|
871
|
+
const disallowComments = options && options.disallowComments;
|
|
872
|
+
const allowTrailingComma = options && options.allowTrailingComma;
|
|
873
|
+
function scanNext() {
|
|
874
|
+
while (true) {
|
|
875
|
+
const token = _scanner.scan();
|
|
876
|
+
switch (_scanner.getTokenError()) {
|
|
877
|
+
case 4:
|
|
878
|
+
handleError(
|
|
879
|
+
14
|
|
880
|
+
/* ParseErrorCode.InvalidUnicode */
|
|
881
|
+
);
|
|
882
|
+
break;
|
|
883
|
+
case 5:
|
|
884
|
+
handleError(
|
|
885
|
+
15
|
|
886
|
+
/* ParseErrorCode.InvalidEscapeCharacter */
|
|
887
|
+
);
|
|
888
|
+
break;
|
|
889
|
+
case 3:
|
|
890
|
+
handleError(
|
|
891
|
+
13
|
|
892
|
+
/* ParseErrorCode.UnexpectedEndOfNumber */
|
|
893
|
+
);
|
|
894
|
+
break;
|
|
895
|
+
case 1:
|
|
896
|
+
if (!disallowComments) {
|
|
897
|
+
handleError(
|
|
898
|
+
11
|
|
899
|
+
/* ParseErrorCode.UnexpectedEndOfComment */
|
|
900
|
+
);
|
|
162
901
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
902
|
+
break;
|
|
903
|
+
case 2:
|
|
904
|
+
handleError(
|
|
905
|
+
12
|
|
906
|
+
/* ParseErrorCode.UnexpectedEndOfString */
|
|
907
|
+
);
|
|
908
|
+
break;
|
|
909
|
+
case 6:
|
|
910
|
+
handleError(
|
|
911
|
+
16
|
|
912
|
+
/* ParseErrorCode.InvalidCharacter */
|
|
913
|
+
);
|
|
914
|
+
break;
|
|
915
|
+
}
|
|
916
|
+
switch (token) {
|
|
917
|
+
case 12:
|
|
918
|
+
case 13:
|
|
919
|
+
if (disallowComments) {
|
|
920
|
+
handleError(
|
|
921
|
+
10
|
|
922
|
+
/* ParseErrorCode.InvalidCommentToken */
|
|
923
|
+
);
|
|
170
924
|
} else {
|
|
171
|
-
|
|
925
|
+
onComment();
|
|
172
926
|
}
|
|
173
|
-
|
|
927
|
+
break;
|
|
928
|
+
case 16:
|
|
929
|
+
handleError(
|
|
930
|
+
1
|
|
931
|
+
/* ParseErrorCode.InvalidSymbol */
|
|
932
|
+
);
|
|
933
|
+
break;
|
|
934
|
+
case 15:
|
|
935
|
+
case 14:
|
|
936
|
+
break;
|
|
937
|
+
default:
|
|
938
|
+
return token;
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
function handleError(error, skipUntilAfter = [], skipUntil = []) {
|
|
943
|
+
onError(error);
|
|
944
|
+
if (skipUntilAfter.length + skipUntil.length > 0) {
|
|
945
|
+
let token = _scanner.getToken();
|
|
946
|
+
while (token !== 17) {
|
|
947
|
+
if (skipUntilAfter.indexOf(token) !== -1) {
|
|
948
|
+
scanNext();
|
|
949
|
+
break;
|
|
950
|
+
} else if (skipUntil.indexOf(token) !== -1) {
|
|
951
|
+
break;
|
|
174
952
|
}
|
|
175
|
-
|
|
953
|
+
token = scanNext();
|
|
176
954
|
}
|
|
177
|
-
|
|
178
|
-
});
|
|
955
|
+
}
|
|
179
956
|
}
|
|
180
|
-
|
|
957
|
+
function parseString(isValue) {
|
|
958
|
+
const value = _scanner.getTokenValue();
|
|
959
|
+
if (isValue) {
|
|
960
|
+
onLiteralValue(value);
|
|
961
|
+
} else {
|
|
962
|
+
onObjectProperty(value);
|
|
963
|
+
_jsonPath.push(value);
|
|
964
|
+
}
|
|
965
|
+
scanNext();
|
|
966
|
+
return true;
|
|
967
|
+
}
|
|
968
|
+
function parseLiteral() {
|
|
969
|
+
switch (_scanner.getToken()) {
|
|
970
|
+
case 11:
|
|
971
|
+
const tokenValue = _scanner.getTokenValue();
|
|
972
|
+
let value = Number(tokenValue);
|
|
973
|
+
if (isNaN(value)) {
|
|
974
|
+
handleError(
|
|
975
|
+
2
|
|
976
|
+
/* ParseErrorCode.InvalidNumberFormat */
|
|
977
|
+
);
|
|
978
|
+
value = 0;
|
|
979
|
+
}
|
|
980
|
+
onLiteralValue(value);
|
|
981
|
+
break;
|
|
982
|
+
case 7:
|
|
983
|
+
onLiteralValue(null);
|
|
984
|
+
break;
|
|
985
|
+
case 8:
|
|
986
|
+
onLiteralValue(true);
|
|
987
|
+
break;
|
|
988
|
+
case 9:
|
|
989
|
+
onLiteralValue(false);
|
|
990
|
+
break;
|
|
991
|
+
default:
|
|
992
|
+
return false;
|
|
993
|
+
}
|
|
994
|
+
scanNext();
|
|
995
|
+
return true;
|
|
996
|
+
}
|
|
997
|
+
function parseProperty() {
|
|
998
|
+
if (_scanner.getToken() !== 10) {
|
|
999
|
+
handleError(3, [], [
|
|
1000
|
+
2,
|
|
1001
|
+
5
|
|
1002
|
+
/* SyntaxKind.CommaToken */
|
|
1003
|
+
]);
|
|
1004
|
+
return false;
|
|
1005
|
+
}
|
|
1006
|
+
parseString(false);
|
|
1007
|
+
if (_scanner.getToken() === 6) {
|
|
1008
|
+
onSeparator(":");
|
|
1009
|
+
scanNext();
|
|
1010
|
+
if (!parseValue()) {
|
|
1011
|
+
handleError(4, [], [
|
|
1012
|
+
2,
|
|
1013
|
+
5
|
|
1014
|
+
/* SyntaxKind.CommaToken */
|
|
1015
|
+
]);
|
|
1016
|
+
}
|
|
1017
|
+
} else {
|
|
1018
|
+
handleError(5, [], [
|
|
1019
|
+
2,
|
|
1020
|
+
5
|
|
1021
|
+
/* SyntaxKind.CommaToken */
|
|
1022
|
+
]);
|
|
1023
|
+
}
|
|
1024
|
+
_jsonPath.pop();
|
|
1025
|
+
return true;
|
|
1026
|
+
}
|
|
1027
|
+
function parseObject() {
|
|
1028
|
+
onObjectBegin();
|
|
1029
|
+
scanNext();
|
|
1030
|
+
let needsComma = false;
|
|
1031
|
+
while (_scanner.getToken() !== 2 && _scanner.getToken() !== 17) {
|
|
1032
|
+
if (_scanner.getToken() === 5) {
|
|
1033
|
+
if (!needsComma) {
|
|
1034
|
+
handleError(4, [], []);
|
|
1035
|
+
}
|
|
1036
|
+
onSeparator(",");
|
|
1037
|
+
scanNext();
|
|
1038
|
+
if (_scanner.getToken() === 2 && allowTrailingComma) {
|
|
1039
|
+
break;
|
|
1040
|
+
}
|
|
1041
|
+
} else if (needsComma) {
|
|
1042
|
+
handleError(6, [], []);
|
|
1043
|
+
}
|
|
1044
|
+
if (!parseProperty()) {
|
|
1045
|
+
handleError(4, [], [
|
|
1046
|
+
2,
|
|
1047
|
+
5
|
|
1048
|
+
/* SyntaxKind.CommaToken */
|
|
1049
|
+
]);
|
|
1050
|
+
}
|
|
1051
|
+
needsComma = true;
|
|
1052
|
+
}
|
|
1053
|
+
onObjectEnd();
|
|
1054
|
+
if (_scanner.getToken() !== 2) {
|
|
1055
|
+
handleError(7, [
|
|
1056
|
+
2
|
|
1057
|
+
/* SyntaxKind.CloseBraceToken */
|
|
1058
|
+
], []);
|
|
1059
|
+
} else {
|
|
1060
|
+
scanNext();
|
|
1061
|
+
}
|
|
1062
|
+
return true;
|
|
1063
|
+
}
|
|
1064
|
+
function parseArray() {
|
|
1065
|
+
onArrayBegin();
|
|
1066
|
+
scanNext();
|
|
1067
|
+
let isFirstElement = true;
|
|
1068
|
+
let needsComma = false;
|
|
1069
|
+
while (_scanner.getToken() !== 4 && _scanner.getToken() !== 17) {
|
|
1070
|
+
if (_scanner.getToken() === 5) {
|
|
1071
|
+
if (!needsComma) {
|
|
1072
|
+
handleError(4, [], []);
|
|
1073
|
+
}
|
|
1074
|
+
onSeparator(",");
|
|
1075
|
+
scanNext();
|
|
1076
|
+
if (_scanner.getToken() === 4 && allowTrailingComma) {
|
|
1077
|
+
break;
|
|
1078
|
+
}
|
|
1079
|
+
} else if (needsComma) {
|
|
1080
|
+
handleError(6, [], []);
|
|
1081
|
+
}
|
|
1082
|
+
if (isFirstElement) {
|
|
1083
|
+
_jsonPath.push(0);
|
|
1084
|
+
isFirstElement = false;
|
|
1085
|
+
} else {
|
|
1086
|
+
_jsonPath[_jsonPath.length - 1]++;
|
|
1087
|
+
}
|
|
1088
|
+
if (!parseValue()) {
|
|
1089
|
+
handleError(4, [], [
|
|
1090
|
+
4,
|
|
1091
|
+
5
|
|
1092
|
+
/* SyntaxKind.CommaToken */
|
|
1093
|
+
]);
|
|
1094
|
+
}
|
|
1095
|
+
needsComma = true;
|
|
1096
|
+
}
|
|
1097
|
+
onArrayEnd();
|
|
1098
|
+
if (!isFirstElement) {
|
|
1099
|
+
_jsonPath.pop();
|
|
1100
|
+
}
|
|
1101
|
+
if (_scanner.getToken() !== 4) {
|
|
1102
|
+
handleError(8, [
|
|
1103
|
+
4
|
|
1104
|
+
/* SyntaxKind.CloseBracketToken */
|
|
1105
|
+
], []);
|
|
1106
|
+
} else {
|
|
1107
|
+
scanNext();
|
|
1108
|
+
}
|
|
1109
|
+
return true;
|
|
1110
|
+
}
|
|
1111
|
+
function parseValue() {
|
|
1112
|
+
switch (_scanner.getToken()) {
|
|
1113
|
+
case 3:
|
|
1114
|
+
return parseArray();
|
|
1115
|
+
case 1:
|
|
1116
|
+
return parseObject();
|
|
1117
|
+
case 10:
|
|
1118
|
+
return parseString(true);
|
|
1119
|
+
default:
|
|
1120
|
+
return parseLiteral();
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
scanNext();
|
|
1124
|
+
if (_scanner.getToken() === 17) {
|
|
1125
|
+
if (options.allowEmptyContent) {
|
|
1126
|
+
return true;
|
|
1127
|
+
}
|
|
1128
|
+
handleError(4, [], []);
|
|
1129
|
+
return false;
|
|
1130
|
+
}
|
|
1131
|
+
if (!parseValue()) {
|
|
1132
|
+
handleError(4, [], []);
|
|
1133
|
+
return false;
|
|
1134
|
+
}
|
|
1135
|
+
if (_scanner.getToken() !== 17) {
|
|
1136
|
+
handleError(9, [], []);
|
|
1137
|
+
}
|
|
1138
|
+
return true;
|
|
1139
|
+
}
|
|
1140
|
+
function getNodeType(value) {
|
|
1141
|
+
switch (typeof value) {
|
|
1142
|
+
case "boolean":
|
|
1143
|
+
return "boolean";
|
|
1144
|
+
case "number":
|
|
1145
|
+
return "number";
|
|
1146
|
+
case "string":
|
|
1147
|
+
return "string";
|
|
1148
|
+
case "object": {
|
|
1149
|
+
if (!value) {
|
|
1150
|
+
return "null";
|
|
1151
|
+
} else if (Array.isArray(value)) {
|
|
1152
|
+
return "array";
|
|
1153
|
+
}
|
|
1154
|
+
return "object";
|
|
1155
|
+
}
|
|
1156
|
+
default:
|
|
1157
|
+
return "null";
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
// node_modules/jsonc-parser/lib/esm/impl/edit.js
|
|
1162
|
+
function setProperty(text, originalPath, value, options) {
|
|
1163
|
+
const path = originalPath.slice();
|
|
1164
|
+
const errors = [];
|
|
1165
|
+
const root = parseTree(text, errors);
|
|
1166
|
+
let parent = void 0;
|
|
1167
|
+
let lastSegment = void 0;
|
|
1168
|
+
while (path.length > 0) {
|
|
1169
|
+
lastSegment = path.pop();
|
|
1170
|
+
parent = findNodeAtLocation(root, path);
|
|
1171
|
+
if (parent === void 0 && value !== void 0) {
|
|
1172
|
+
if (typeof lastSegment === "string") {
|
|
1173
|
+
value = { [lastSegment]: value };
|
|
1174
|
+
} else {
|
|
1175
|
+
value = [value];
|
|
1176
|
+
}
|
|
1177
|
+
} else {
|
|
1178
|
+
break;
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
if (!parent) {
|
|
1182
|
+
if (value === void 0) {
|
|
1183
|
+
throw new Error("Can not delete in empty document");
|
|
1184
|
+
}
|
|
1185
|
+
return withFormatting(text, { offset: root ? root.offset : 0, length: root ? root.length : 0, content: JSON.stringify(value) }, options);
|
|
1186
|
+
} else if (parent.type === "object" && typeof lastSegment === "string" && Array.isArray(parent.children)) {
|
|
1187
|
+
const existing = findNodeAtLocation(parent, [lastSegment]);
|
|
1188
|
+
if (existing !== void 0) {
|
|
1189
|
+
if (value === void 0) {
|
|
1190
|
+
if (!existing.parent) {
|
|
1191
|
+
throw new Error("Malformed AST");
|
|
1192
|
+
}
|
|
1193
|
+
const propertyIndex = parent.children.indexOf(existing.parent);
|
|
1194
|
+
let removeBegin;
|
|
1195
|
+
let removeEnd = existing.parent.offset + existing.parent.length;
|
|
1196
|
+
if (propertyIndex > 0) {
|
|
1197
|
+
let previous = parent.children[propertyIndex - 1];
|
|
1198
|
+
removeBegin = previous.offset + previous.length;
|
|
1199
|
+
} else {
|
|
1200
|
+
removeBegin = parent.offset + 1;
|
|
1201
|
+
if (parent.children.length > 1) {
|
|
1202
|
+
let next = parent.children[1];
|
|
1203
|
+
removeEnd = next.offset;
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
return withFormatting(text, { offset: removeBegin, length: removeEnd - removeBegin, content: "" }, options);
|
|
1207
|
+
} else {
|
|
1208
|
+
return withFormatting(text, { offset: existing.offset, length: existing.length, content: JSON.stringify(value) }, options);
|
|
1209
|
+
}
|
|
1210
|
+
} else {
|
|
1211
|
+
if (value === void 0) {
|
|
1212
|
+
return [];
|
|
1213
|
+
}
|
|
1214
|
+
const newProperty = `${JSON.stringify(lastSegment)}: ${JSON.stringify(value)}`;
|
|
1215
|
+
const index = options.getInsertionIndex ? options.getInsertionIndex(parent.children.map((p) => p.children[0].value)) : parent.children.length;
|
|
1216
|
+
let edit;
|
|
1217
|
+
if (index > 0) {
|
|
1218
|
+
let previous = parent.children[index - 1];
|
|
1219
|
+
edit = { offset: previous.offset + previous.length, length: 0, content: "," + newProperty };
|
|
1220
|
+
} else if (parent.children.length === 0) {
|
|
1221
|
+
edit = { offset: parent.offset + 1, length: 0, content: newProperty };
|
|
1222
|
+
} else {
|
|
1223
|
+
edit = { offset: parent.offset + 1, length: 0, content: newProperty + "," };
|
|
1224
|
+
}
|
|
1225
|
+
return withFormatting(text, edit, options);
|
|
1226
|
+
}
|
|
1227
|
+
} else if (parent.type === "array" && typeof lastSegment === "number" && Array.isArray(parent.children)) {
|
|
1228
|
+
const insertIndex = lastSegment;
|
|
1229
|
+
if (insertIndex === -1) {
|
|
1230
|
+
const newProperty = `${JSON.stringify(value)}`;
|
|
1231
|
+
let edit;
|
|
1232
|
+
if (parent.children.length === 0) {
|
|
1233
|
+
edit = { offset: parent.offset + 1, length: 0, content: newProperty };
|
|
1234
|
+
} else {
|
|
1235
|
+
const previous = parent.children[parent.children.length - 1];
|
|
1236
|
+
edit = { offset: previous.offset + previous.length, length: 0, content: "," + newProperty };
|
|
1237
|
+
}
|
|
1238
|
+
return withFormatting(text, edit, options);
|
|
1239
|
+
} else if (value === void 0 && parent.children.length >= 0) {
|
|
1240
|
+
const removalIndex = lastSegment;
|
|
1241
|
+
const toRemove = parent.children[removalIndex];
|
|
1242
|
+
let edit;
|
|
1243
|
+
if (parent.children.length === 1) {
|
|
1244
|
+
edit = { offset: parent.offset + 1, length: parent.length - 2, content: "" };
|
|
1245
|
+
} else if (parent.children.length - 1 === removalIndex) {
|
|
1246
|
+
let previous = parent.children[removalIndex - 1];
|
|
1247
|
+
let offset = previous.offset + previous.length;
|
|
1248
|
+
let parentEndOffset = parent.offset + parent.length;
|
|
1249
|
+
edit = { offset, length: parentEndOffset - 2 - offset, content: "" };
|
|
1250
|
+
} else {
|
|
1251
|
+
edit = { offset: toRemove.offset, length: parent.children[removalIndex + 1].offset - toRemove.offset, content: "" };
|
|
1252
|
+
}
|
|
1253
|
+
return withFormatting(text, edit, options);
|
|
1254
|
+
} else if (value !== void 0) {
|
|
1255
|
+
let edit;
|
|
1256
|
+
const newProperty = `${JSON.stringify(value)}`;
|
|
1257
|
+
if (!options.isArrayInsertion && parent.children.length > lastSegment) {
|
|
1258
|
+
const toModify = parent.children[lastSegment];
|
|
1259
|
+
edit = { offset: toModify.offset, length: toModify.length, content: newProperty };
|
|
1260
|
+
} else if (parent.children.length === 0 || lastSegment === 0) {
|
|
1261
|
+
edit = { offset: parent.offset + 1, length: 0, content: parent.children.length === 0 ? newProperty : newProperty + "," };
|
|
1262
|
+
} else {
|
|
1263
|
+
const index = lastSegment > parent.children.length ? parent.children.length : lastSegment;
|
|
1264
|
+
const previous = parent.children[index - 1];
|
|
1265
|
+
edit = { offset: previous.offset + previous.length, length: 0, content: "," + newProperty };
|
|
1266
|
+
}
|
|
1267
|
+
return withFormatting(text, edit, options);
|
|
1268
|
+
} else {
|
|
1269
|
+
throw new Error(`Can not ${value === void 0 ? "remove" : options.isArrayInsertion ? "insert" : "modify"} Array index ${insertIndex} as length is not sufficient`);
|
|
1270
|
+
}
|
|
1271
|
+
} else {
|
|
1272
|
+
throw new Error(`Can not add ${typeof lastSegment !== "number" ? "index" : "property"} to parent of type ${parent.type}`);
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
function withFormatting(text, edit, options) {
|
|
1276
|
+
if (!options.formattingOptions) {
|
|
1277
|
+
return [edit];
|
|
1278
|
+
}
|
|
1279
|
+
let newText = applyEdit(text, edit);
|
|
1280
|
+
let begin = edit.offset;
|
|
1281
|
+
let end = edit.offset + edit.content.length;
|
|
1282
|
+
if (edit.length === 0 || edit.content.length === 0) {
|
|
1283
|
+
while (begin > 0 && !isEOL(newText, begin - 1)) {
|
|
1284
|
+
begin--;
|
|
1285
|
+
}
|
|
1286
|
+
while (end < newText.length && !isEOL(newText, end)) {
|
|
1287
|
+
end++;
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1290
|
+
const edits = format(newText, { offset: begin, length: end - begin }, { ...options.formattingOptions, keepLines: false });
|
|
1291
|
+
for (let i = edits.length - 1; i >= 0; i--) {
|
|
1292
|
+
const edit2 = edits[i];
|
|
1293
|
+
newText = applyEdit(newText, edit2);
|
|
1294
|
+
begin = Math.min(begin, edit2.offset);
|
|
1295
|
+
end = Math.max(end, edit2.offset + edit2.length);
|
|
1296
|
+
end += edit2.content.length - edit2.length;
|
|
1297
|
+
}
|
|
1298
|
+
const editLength = text.length - (newText.length - end) - begin;
|
|
1299
|
+
return [{ offset: begin, length: editLength, content: newText.substring(begin, end) }];
|
|
1300
|
+
}
|
|
1301
|
+
function applyEdit(text, edit) {
|
|
1302
|
+
return text.substring(0, edit.offset) + edit.content + text.substring(edit.offset + edit.length);
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1305
|
+
// node_modules/jsonc-parser/lib/esm/main.js
|
|
1306
|
+
var ScanError;
|
|
1307
|
+
(function(ScanError2) {
|
|
1308
|
+
ScanError2[ScanError2["None"] = 0] = "None";
|
|
1309
|
+
ScanError2[ScanError2["UnexpectedEndOfComment"] = 1] = "UnexpectedEndOfComment";
|
|
1310
|
+
ScanError2[ScanError2["UnexpectedEndOfString"] = 2] = "UnexpectedEndOfString";
|
|
1311
|
+
ScanError2[ScanError2["UnexpectedEndOfNumber"] = 3] = "UnexpectedEndOfNumber";
|
|
1312
|
+
ScanError2[ScanError2["InvalidUnicode"] = 4] = "InvalidUnicode";
|
|
1313
|
+
ScanError2[ScanError2["InvalidEscapeCharacter"] = 5] = "InvalidEscapeCharacter";
|
|
1314
|
+
ScanError2[ScanError2["InvalidCharacter"] = 6] = "InvalidCharacter";
|
|
1315
|
+
})(ScanError || (ScanError = {}));
|
|
1316
|
+
var SyntaxKind;
|
|
1317
|
+
(function(SyntaxKind2) {
|
|
1318
|
+
SyntaxKind2[SyntaxKind2["OpenBraceToken"] = 1] = "OpenBraceToken";
|
|
1319
|
+
SyntaxKind2[SyntaxKind2["CloseBraceToken"] = 2] = "CloseBraceToken";
|
|
1320
|
+
SyntaxKind2[SyntaxKind2["OpenBracketToken"] = 3] = "OpenBracketToken";
|
|
1321
|
+
SyntaxKind2[SyntaxKind2["CloseBracketToken"] = 4] = "CloseBracketToken";
|
|
1322
|
+
SyntaxKind2[SyntaxKind2["CommaToken"] = 5] = "CommaToken";
|
|
1323
|
+
SyntaxKind2[SyntaxKind2["ColonToken"] = 6] = "ColonToken";
|
|
1324
|
+
SyntaxKind2[SyntaxKind2["NullKeyword"] = 7] = "NullKeyword";
|
|
1325
|
+
SyntaxKind2[SyntaxKind2["TrueKeyword"] = 8] = "TrueKeyword";
|
|
1326
|
+
SyntaxKind2[SyntaxKind2["FalseKeyword"] = 9] = "FalseKeyword";
|
|
1327
|
+
SyntaxKind2[SyntaxKind2["StringLiteral"] = 10] = "StringLiteral";
|
|
1328
|
+
SyntaxKind2[SyntaxKind2["NumericLiteral"] = 11] = "NumericLiteral";
|
|
1329
|
+
SyntaxKind2[SyntaxKind2["LineCommentTrivia"] = 12] = "LineCommentTrivia";
|
|
1330
|
+
SyntaxKind2[SyntaxKind2["BlockCommentTrivia"] = 13] = "BlockCommentTrivia";
|
|
1331
|
+
SyntaxKind2[SyntaxKind2["LineBreakTrivia"] = 14] = "LineBreakTrivia";
|
|
1332
|
+
SyntaxKind2[SyntaxKind2["Trivia"] = 15] = "Trivia";
|
|
1333
|
+
SyntaxKind2[SyntaxKind2["Unknown"] = 16] = "Unknown";
|
|
1334
|
+
SyntaxKind2[SyntaxKind2["EOF"] = 17] = "EOF";
|
|
1335
|
+
})(SyntaxKind || (SyntaxKind = {}));
|
|
1336
|
+
var parse2 = parse;
|
|
1337
|
+
var ParseErrorCode;
|
|
1338
|
+
(function(ParseErrorCode2) {
|
|
1339
|
+
ParseErrorCode2[ParseErrorCode2["InvalidSymbol"] = 1] = "InvalidSymbol";
|
|
1340
|
+
ParseErrorCode2[ParseErrorCode2["InvalidNumberFormat"] = 2] = "InvalidNumberFormat";
|
|
1341
|
+
ParseErrorCode2[ParseErrorCode2["PropertyNameExpected"] = 3] = "PropertyNameExpected";
|
|
1342
|
+
ParseErrorCode2[ParseErrorCode2["ValueExpected"] = 4] = "ValueExpected";
|
|
1343
|
+
ParseErrorCode2[ParseErrorCode2["ColonExpected"] = 5] = "ColonExpected";
|
|
1344
|
+
ParseErrorCode2[ParseErrorCode2["CommaExpected"] = 6] = "CommaExpected";
|
|
1345
|
+
ParseErrorCode2[ParseErrorCode2["CloseBraceExpected"] = 7] = "CloseBraceExpected";
|
|
1346
|
+
ParseErrorCode2[ParseErrorCode2["CloseBracketExpected"] = 8] = "CloseBracketExpected";
|
|
1347
|
+
ParseErrorCode2[ParseErrorCode2["EndOfFileExpected"] = 9] = "EndOfFileExpected";
|
|
1348
|
+
ParseErrorCode2[ParseErrorCode2["InvalidCommentToken"] = 10] = "InvalidCommentToken";
|
|
1349
|
+
ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfComment"] = 11] = "UnexpectedEndOfComment";
|
|
1350
|
+
ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfString"] = 12] = "UnexpectedEndOfString";
|
|
1351
|
+
ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfNumber"] = 13] = "UnexpectedEndOfNumber";
|
|
1352
|
+
ParseErrorCode2[ParseErrorCode2["InvalidUnicode"] = 14] = "InvalidUnicode";
|
|
1353
|
+
ParseErrorCode2[ParseErrorCode2["InvalidEscapeCharacter"] = 15] = "InvalidEscapeCharacter";
|
|
1354
|
+
ParseErrorCode2[ParseErrorCode2["InvalidCharacter"] = 16] = "InvalidCharacter";
|
|
1355
|
+
})(ParseErrorCode || (ParseErrorCode = {}));
|
|
1356
|
+
function printParseErrorCode(code) {
|
|
1357
|
+
switch (code) {
|
|
1358
|
+
case 1:
|
|
1359
|
+
return "InvalidSymbol";
|
|
1360
|
+
case 2:
|
|
1361
|
+
return "InvalidNumberFormat";
|
|
1362
|
+
case 3:
|
|
1363
|
+
return "PropertyNameExpected";
|
|
1364
|
+
case 4:
|
|
1365
|
+
return "ValueExpected";
|
|
1366
|
+
case 5:
|
|
1367
|
+
return "ColonExpected";
|
|
1368
|
+
case 6:
|
|
1369
|
+
return "CommaExpected";
|
|
1370
|
+
case 7:
|
|
1371
|
+
return "CloseBraceExpected";
|
|
1372
|
+
case 8:
|
|
1373
|
+
return "CloseBracketExpected";
|
|
1374
|
+
case 9:
|
|
1375
|
+
return "EndOfFileExpected";
|
|
1376
|
+
case 10:
|
|
1377
|
+
return "InvalidCommentToken";
|
|
1378
|
+
case 11:
|
|
1379
|
+
return "UnexpectedEndOfComment";
|
|
1380
|
+
case 12:
|
|
1381
|
+
return "UnexpectedEndOfString";
|
|
1382
|
+
case 13:
|
|
1383
|
+
return "UnexpectedEndOfNumber";
|
|
1384
|
+
case 14:
|
|
1385
|
+
return "InvalidUnicode";
|
|
1386
|
+
case 15:
|
|
1387
|
+
return "InvalidEscapeCharacter";
|
|
1388
|
+
case 16:
|
|
1389
|
+
return "InvalidCharacter";
|
|
1390
|
+
}
|
|
1391
|
+
return "<unknown ParseErrorCode>";
|
|
1392
|
+
}
|
|
1393
|
+
function modify(text, path, value, options) {
|
|
1394
|
+
return setProperty(text, path, value, options);
|
|
1395
|
+
}
|
|
1396
|
+
function applyEdits(text, edits) {
|
|
1397
|
+
let sortedEdits = edits.slice(0).sort((a, b) => {
|
|
1398
|
+
const diff = a.offset - b.offset;
|
|
1399
|
+
if (diff === 0) {
|
|
1400
|
+
return a.length - b.length;
|
|
1401
|
+
}
|
|
1402
|
+
return diff;
|
|
1403
|
+
});
|
|
1404
|
+
let lastModifiedOffset = text.length;
|
|
1405
|
+
for (let i = sortedEdits.length - 1; i >= 0; i--) {
|
|
1406
|
+
let e = sortedEdits[i];
|
|
1407
|
+
if (e.offset + e.length <= lastModifiedOffset) {
|
|
1408
|
+
text = applyEdit(text, e);
|
|
1409
|
+
} else {
|
|
1410
|
+
throw new Error("Overlapping edit");
|
|
1411
|
+
}
|
|
1412
|
+
lastModifiedOffset = e.offset;
|
|
1413
|
+
}
|
|
1414
|
+
return text;
|
|
1415
|
+
}
|
|
181
1416
|
|
|
182
1417
|
// scripts/preuninstall.ts
|
|
183
|
-
var import_jsonc_parser = __toESM(require_main(), 1);
|
|
184
|
-
import { existsSync, readFileSync, writeFileSync, appendFileSync, copyFileSync, renameSync, unlinkSync, readdirSync } from "fs";
|
|
185
|
-
import { homedir, tmpdir } from "os";
|
|
186
|
-
import { dirname, join, basename } from "path";
|
|
187
1418
|
var isCI = process.env.CI === "true" || process.env.CONTINUOUS_INTEGRATION === "true";
|
|
188
1419
|
var TIMEOUT_MS = 3e4;
|
|
189
1420
|
var timeoutId = setTimeout(() => {
|
|
@@ -244,7 +1475,7 @@ function resolveConfigFile(configDir) {
|
|
|
244
1475
|
}
|
|
245
1476
|
function parseConfigContent(rawContent) {
|
|
246
1477
|
const errors = [];
|
|
247
|
-
const config = (
|
|
1478
|
+
const config = parse2(rawContent, errors, {
|
|
248
1479
|
allowTrailingComma: true,
|
|
249
1480
|
disallowComments: false
|
|
250
1481
|
});
|
|
@@ -253,7 +1484,7 @@ function parseConfigContent(rawContent) {
|
|
|
253
1484
|
const line = rawContent.slice(0, firstError.offset).split("\n").length;
|
|
254
1485
|
const column = firstError.offset - rawContent.lastIndexOf("\n", firstError.offset - 1);
|
|
255
1486
|
return {
|
|
256
|
-
parseError: `${
|
|
1487
|
+
parseError: `${printParseErrorCode(firstError.error)} at line ${line}, column ${column}`
|
|
257
1488
|
};
|
|
258
1489
|
}
|
|
259
1490
|
if (typeof config !== "object" || config === null || Array.isArray(config)) {
|
|
@@ -363,10 +1594,10 @@ function atomicWriteJSON(filePath, data, originalContent) {
|
|
|
363
1594
|
let output = JSON.stringify(data, null, 2) + "\n";
|
|
364
1595
|
if (filePath.endsWith(".jsonc") && originalContent !== void 0) {
|
|
365
1596
|
const source = originalContent.trim() ? originalContent : "{}";
|
|
366
|
-
const edits =
|
|
1597
|
+
const edits = modify(source, ["plugin"], data.plugin, {
|
|
367
1598
|
formattingOptions: { tabSize: 2, insertSpaces: true }
|
|
368
1599
|
});
|
|
369
|
-
output =
|
|
1600
|
+
output = applyEdits(source, edits);
|
|
370
1601
|
if (!output.endsWith("\n")) output += "\n";
|
|
371
1602
|
}
|
|
372
1603
|
writeFileSync(tempFile, output, { mode: 420 });
|