opencode-supertask 0.1.40 → 0.2.0
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/CHANGELOG.md +95 -1
- package/LICENSE +21 -0
- package/README.md +73 -39
- package/README.zh-CN.md +73 -39
- package/dist/cli/chunk-3PIYMBV3.js +45 -0
- package/dist/cli/chunk-3PIYMBV3.js.map +1 -0
- package/dist/cli/chunk-4FK5KE6G.js +111 -0
- package/dist/cli/chunk-4FK5KE6G.js.map +1 -0
- package/dist/cli/chunk-5VKFECHP.js +412 -0
- package/dist/cli/chunk-5VKFECHP.js.map +1 -0
- package/dist/cli/chunk-AZM76ISG.js +143 -0
- package/dist/cli/chunk-AZM76ISG.js.map +1 -0
- package/dist/cli/chunk-CMEP6IB4.js +9379 -0
- package/dist/cli/chunk-CMEP6IB4.js.map +1 -0
- package/dist/cli/chunk-DF56RPNL.js +65 -0
- package/dist/cli/chunk-DF56RPNL.js.map +1 -0
- package/dist/cli/chunk-DIJEKFBV.js +486 -0
- package/dist/cli/chunk-DIJEKFBV.js.map +1 -0
- package/dist/cli/chunk-DYXFSX5J.js +28 -0
- package/dist/cli/chunk-DYXFSX5J.js.map +1 -0
- package/dist/cli/chunk-EQWICVCJ.js +1701 -0
- package/dist/cli/chunk-EQWICVCJ.js.map +1 -0
- package/dist/cli/chunk-GHXFMJTS.js +42 -0
- package/dist/cli/chunk-GHXFMJTS.js.map +1 -0
- package/dist/cli/chunk-IYYBJHZF.js +28 -0
- package/dist/cli/chunk-IYYBJHZF.js.map +1 -0
- package/dist/cli/chunk-J34FWHQU.js +376 -0
- package/dist/cli/chunk-J34FWHQU.js.map +1 -0
- package/dist/cli/chunk-LX5CBJLP.js +121 -0
- package/dist/cli/chunk-LX5CBJLP.js.map +1 -0
- package/dist/cli/chunk-MVQ2XONT.js +139 -0
- package/dist/cli/chunk-MVQ2XONT.js.map +1 -0
- package/dist/cli/chunk-NCT3ETTK.js +1332 -0
- package/dist/cli/chunk-NCT3ETTK.js.map +1 -0
- package/dist/cli/chunk-YB7MYTE5.js +34 -0
- package/dist/cli/chunk-YB7MYTE5.js.map +1 -0
- package/dist/cli/chunk-YGELD2E5.js +5464 -0
- package/dist/cli/chunk-YGELD2E5.js.map +1 -0
- package/dist/cli/chunk-ZBH7YWXF.js +314 -0
- package/dist/cli/chunk-ZBH7YWXF.js.map +1 -0
- package/dist/cli/config-ED56ZLHY.js +20 -0
- package/dist/cli/config-ED56ZLHY.js.map +1 -0
- package/dist/cli/database-maintenance.service-F3IZU52F.js +16 -0
- package/dist/cli/database-maintenance.service-F3IZU52F.js.map +1 -0
- package/dist/cli/database-output-GH7F6X6D.js +165 -0
- package/dist/cli/database-output-GH7F6X6D.js.map +1 -0
- package/dist/cli/db-H7GIFWS2.js +26 -0
- package/dist/cli/db-H7GIFWS2.js.map +1 -0
- package/dist/cli/doctor-smoke-QXHF7UNN.js +150 -0
- package/dist/cli/doctor-smoke-QXHF7UNN.js.map +1 -0
- package/dist/cli/duration-Q3UMLO6F.js +10 -0
- package/dist/cli/duration-Q3UMLO6F.js.map +1 -0
- package/dist/cli/gateway-HNMX5ZTO.js +1738 -0
- package/dist/cli/gateway-HNMX5ZTO.js.map +1 -0
- package/dist/cli/gateway-wake-U4HTV56Q.js +14 -0
- package/dist/cli/gateway-wake-U4HTV56Q.js.map +1 -0
- package/dist/cli/index.js +626 -26342
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/job-templates-RPQJ4XXW.js +21 -0
- package/dist/cli/job-templates-RPQJ4XXW.js.map +1 -0
- package/dist/cli/logs-QD2N62KK.js +316 -0
- package/dist/cli/logs-QD2N62KK.js.map +1 -0
- package/dist/cli/output-2INTEUFQ.js +19 -0
- package/dist/cli/output-2INTEUFQ.js.map +1 -0
- package/dist/cli/pm2-WY644BUO.js +49 -0
- package/dist/cli/pm2-WY644BUO.js.map +1 -0
- package/dist/cli/task-run.service-QMDINJKG.js +15 -0
- package/dist/cli/task-run.service-QMDINJKG.js.map +1 -0
- package/dist/cli/task-template.service-SZBKGLCB.js +12 -0
- package/dist/cli/task-template.service-SZBKGLCB.js.map +1 -0
- package/dist/cli/task.service-ZVDJ6VSQ.js +19 -0
- package/dist/cli/task.service-ZVDJ6VSQ.js.map +1 -0
- package/dist/cli/update-FYD546I2.js +2058 -0
- package/dist/cli/update-FYD546I2.js.map +1 -0
- package/dist/cli/web-2S7DW7XA.js +9403 -0
- package/dist/cli/web-2S7DW7XA.js.map +1 -0
- package/dist/daemon/gateway-diagnostic-runner.d.ts +2 -0
- package/dist/daemon/gateway-diagnostic-runner.js +503 -0
- package/dist/daemon/gateway-diagnostic-runner.js.map +1 -0
- package/dist/gateway/index.d.ts +82 -1
- package/dist/gateway/index.js +9301 -2948
- package/dist/gateway/index.js.map +1 -1
- package/dist/plugin/supertask.d.ts +157 -1
- package/dist/plugin/supertask.js +5066 -1531
- package/dist/plugin/supertask.js.map +1 -1
- package/dist/pm2-cli-CEDhULjk.d.ts +40 -0
- package/dist/web/index.d.ts +36 -34
- package/dist/web/index.js +10030 -4341
- package/dist/web/index.js.map +1 -1
- package/dist/worker/index.d.ts +13 -0
- package/dist/worker/index.js +2147 -364
- package/dist/worker/index.js.map +1 -1
- package/dist/worker/launcher.d.ts +46 -1
- package/dist/worker/launcher.js +218 -68
- package/dist/worker/launcher.js.map +1 -1
- package/drizzle/0009_little_weapon_omega.sql +7 -0
- package/drizzle/meta/0009_snapshot.json +681 -0
- package/drizzle/meta/_journal.json +7 -0
- package/package.json +15 -6
|
@@ -0,0 +1,2058 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
detectOpenCodeVersionSync,
|
|
5
|
+
openCodeExecutable
|
|
6
|
+
} from "./chunk-LX5CBJLP.js";
|
|
7
|
+
import {
|
|
8
|
+
MANAGED_RUN_ENV,
|
|
9
|
+
MANAGED_RUN_ENV_VALUE
|
|
10
|
+
} from "./chunk-YB7MYTE5.js";
|
|
11
|
+
import {
|
|
12
|
+
getGatewayDiagnostic,
|
|
13
|
+
upgrade
|
|
14
|
+
} from "./chunk-NCT3ETTK.js";
|
|
15
|
+
import {
|
|
16
|
+
getPackageVersion
|
|
17
|
+
} from "./chunk-DYXFSX5J.js";
|
|
18
|
+
import "./chunk-MVQ2XONT.js";
|
|
19
|
+
import "./chunk-3PIYMBV3.js";
|
|
20
|
+
|
|
21
|
+
// src/daemon/update.ts
|
|
22
|
+
import { spawnSync } from "child_process";
|
|
23
|
+
import {
|
|
24
|
+
chmodSync,
|
|
25
|
+
closeSync,
|
|
26
|
+
existsSync,
|
|
27
|
+
mkdirSync,
|
|
28
|
+
mkdtempSync,
|
|
29
|
+
openSync,
|
|
30
|
+
readFileSync,
|
|
31
|
+
readdirSync,
|
|
32
|
+
realpathSync,
|
|
33
|
+
renameSync,
|
|
34
|
+
rmSync,
|
|
35
|
+
writeFileSync
|
|
36
|
+
} from "fs";
|
|
37
|
+
|
|
38
|
+
// node_modules/jsonc-parser/lib/esm/impl/scanner.js
|
|
39
|
+
function createScanner(text, ignoreTrivia = false) {
|
|
40
|
+
const len = text.length;
|
|
41
|
+
let pos = 0, value = "", tokenOffset = 0, token = 16, lineNumber = 0, lineStartOffset = 0, tokenLineStartOffset = 0, prevTokenLineStartOffset = 0, scanError = 0;
|
|
42
|
+
function scanHexDigits(count, exact) {
|
|
43
|
+
let digits = 0;
|
|
44
|
+
let value2 = 0;
|
|
45
|
+
while (digits < count || !exact) {
|
|
46
|
+
let ch = text.charCodeAt(pos);
|
|
47
|
+
if (ch >= 48 && ch <= 57) {
|
|
48
|
+
value2 = value2 * 16 + ch - 48;
|
|
49
|
+
} else if (ch >= 65 && ch <= 70) {
|
|
50
|
+
value2 = value2 * 16 + ch - 65 + 10;
|
|
51
|
+
} else if (ch >= 97 && ch <= 102) {
|
|
52
|
+
value2 = value2 * 16 + ch - 97 + 10;
|
|
53
|
+
} else {
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
pos++;
|
|
57
|
+
digits++;
|
|
58
|
+
}
|
|
59
|
+
if (digits < count) {
|
|
60
|
+
value2 = -1;
|
|
61
|
+
}
|
|
62
|
+
return value2;
|
|
63
|
+
}
|
|
64
|
+
function setPosition(newPosition) {
|
|
65
|
+
pos = newPosition;
|
|
66
|
+
value = "";
|
|
67
|
+
tokenOffset = 0;
|
|
68
|
+
token = 16;
|
|
69
|
+
scanError = 0;
|
|
70
|
+
}
|
|
71
|
+
function scanNumber() {
|
|
72
|
+
let start = pos;
|
|
73
|
+
if (text.charCodeAt(pos) === 48) {
|
|
74
|
+
pos++;
|
|
75
|
+
} else {
|
|
76
|
+
pos++;
|
|
77
|
+
while (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
78
|
+
pos++;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (pos < text.length && text.charCodeAt(pos) === 46) {
|
|
82
|
+
pos++;
|
|
83
|
+
if (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
84
|
+
pos++;
|
|
85
|
+
while (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
86
|
+
pos++;
|
|
87
|
+
}
|
|
88
|
+
} else {
|
|
89
|
+
scanError = 3;
|
|
90
|
+
return text.substring(start, pos);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
let end = pos;
|
|
94
|
+
if (pos < text.length && (text.charCodeAt(pos) === 69 || text.charCodeAt(pos) === 101)) {
|
|
95
|
+
pos++;
|
|
96
|
+
if (pos < text.length && text.charCodeAt(pos) === 43 || text.charCodeAt(pos) === 45) {
|
|
97
|
+
pos++;
|
|
98
|
+
}
|
|
99
|
+
if (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
100
|
+
pos++;
|
|
101
|
+
while (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
102
|
+
pos++;
|
|
103
|
+
}
|
|
104
|
+
end = pos;
|
|
105
|
+
} else {
|
|
106
|
+
scanError = 3;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return text.substring(start, end);
|
|
110
|
+
}
|
|
111
|
+
function scanString() {
|
|
112
|
+
let result = "", start = pos;
|
|
113
|
+
while (true) {
|
|
114
|
+
if (pos >= len) {
|
|
115
|
+
result += text.substring(start, pos);
|
|
116
|
+
scanError = 2;
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
const ch = text.charCodeAt(pos);
|
|
120
|
+
if (ch === 34) {
|
|
121
|
+
result += text.substring(start, pos);
|
|
122
|
+
pos++;
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
if (ch === 92) {
|
|
126
|
+
result += text.substring(start, pos);
|
|
127
|
+
pos++;
|
|
128
|
+
if (pos >= len) {
|
|
129
|
+
scanError = 2;
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
const ch2 = text.charCodeAt(pos++);
|
|
133
|
+
switch (ch2) {
|
|
134
|
+
case 34:
|
|
135
|
+
result += '"';
|
|
136
|
+
break;
|
|
137
|
+
case 92:
|
|
138
|
+
result += "\\";
|
|
139
|
+
break;
|
|
140
|
+
case 47:
|
|
141
|
+
result += "/";
|
|
142
|
+
break;
|
|
143
|
+
case 98:
|
|
144
|
+
result += "\b";
|
|
145
|
+
break;
|
|
146
|
+
case 102:
|
|
147
|
+
result += "\f";
|
|
148
|
+
break;
|
|
149
|
+
case 110:
|
|
150
|
+
result += "\n";
|
|
151
|
+
break;
|
|
152
|
+
case 114:
|
|
153
|
+
result += "\r";
|
|
154
|
+
break;
|
|
155
|
+
case 116:
|
|
156
|
+
result += " ";
|
|
157
|
+
break;
|
|
158
|
+
case 117:
|
|
159
|
+
const ch3 = scanHexDigits(4, true);
|
|
160
|
+
if (ch3 >= 0) {
|
|
161
|
+
result += String.fromCharCode(ch3);
|
|
162
|
+
} else {
|
|
163
|
+
scanError = 4;
|
|
164
|
+
}
|
|
165
|
+
break;
|
|
166
|
+
default:
|
|
167
|
+
scanError = 5;
|
|
168
|
+
}
|
|
169
|
+
start = pos;
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
if (ch >= 0 && ch <= 31) {
|
|
173
|
+
if (isLineBreak(ch)) {
|
|
174
|
+
result += text.substring(start, pos);
|
|
175
|
+
scanError = 2;
|
|
176
|
+
break;
|
|
177
|
+
} else {
|
|
178
|
+
scanError = 6;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
pos++;
|
|
182
|
+
}
|
|
183
|
+
return result;
|
|
184
|
+
}
|
|
185
|
+
function scanNext() {
|
|
186
|
+
value = "";
|
|
187
|
+
scanError = 0;
|
|
188
|
+
tokenOffset = pos;
|
|
189
|
+
lineStartOffset = lineNumber;
|
|
190
|
+
prevTokenLineStartOffset = tokenLineStartOffset;
|
|
191
|
+
if (pos >= len) {
|
|
192
|
+
tokenOffset = len;
|
|
193
|
+
return token = 17;
|
|
194
|
+
}
|
|
195
|
+
let code = text.charCodeAt(pos);
|
|
196
|
+
if (isWhiteSpace(code)) {
|
|
197
|
+
do {
|
|
198
|
+
pos++;
|
|
199
|
+
value += String.fromCharCode(code);
|
|
200
|
+
code = text.charCodeAt(pos);
|
|
201
|
+
} while (isWhiteSpace(code));
|
|
202
|
+
return token = 15;
|
|
203
|
+
}
|
|
204
|
+
if (isLineBreak(code)) {
|
|
205
|
+
pos++;
|
|
206
|
+
value += String.fromCharCode(code);
|
|
207
|
+
if (code === 13 && text.charCodeAt(pos) === 10) {
|
|
208
|
+
pos++;
|
|
209
|
+
value += "\n";
|
|
210
|
+
}
|
|
211
|
+
lineNumber++;
|
|
212
|
+
tokenLineStartOffset = pos;
|
|
213
|
+
return token = 14;
|
|
214
|
+
}
|
|
215
|
+
switch (code) {
|
|
216
|
+
// tokens: []{}:,
|
|
217
|
+
case 123:
|
|
218
|
+
pos++;
|
|
219
|
+
return token = 1;
|
|
220
|
+
case 125:
|
|
221
|
+
pos++;
|
|
222
|
+
return token = 2;
|
|
223
|
+
case 91:
|
|
224
|
+
pos++;
|
|
225
|
+
return token = 3;
|
|
226
|
+
case 93:
|
|
227
|
+
pos++;
|
|
228
|
+
return token = 4;
|
|
229
|
+
case 58:
|
|
230
|
+
pos++;
|
|
231
|
+
return token = 6;
|
|
232
|
+
case 44:
|
|
233
|
+
pos++;
|
|
234
|
+
return token = 5;
|
|
235
|
+
// strings
|
|
236
|
+
case 34:
|
|
237
|
+
pos++;
|
|
238
|
+
value = scanString();
|
|
239
|
+
return token = 10;
|
|
240
|
+
// comments
|
|
241
|
+
case 47:
|
|
242
|
+
const start = pos - 1;
|
|
243
|
+
if (text.charCodeAt(pos + 1) === 47) {
|
|
244
|
+
pos += 2;
|
|
245
|
+
while (pos < len) {
|
|
246
|
+
if (isLineBreak(text.charCodeAt(pos))) {
|
|
247
|
+
break;
|
|
248
|
+
}
|
|
249
|
+
pos++;
|
|
250
|
+
}
|
|
251
|
+
value = text.substring(start, pos);
|
|
252
|
+
return token = 12;
|
|
253
|
+
}
|
|
254
|
+
if (text.charCodeAt(pos + 1) === 42) {
|
|
255
|
+
pos += 2;
|
|
256
|
+
const safeLength = len - 1;
|
|
257
|
+
let commentClosed = false;
|
|
258
|
+
while (pos < safeLength) {
|
|
259
|
+
const ch = text.charCodeAt(pos);
|
|
260
|
+
if (ch === 42 && text.charCodeAt(pos + 1) === 47) {
|
|
261
|
+
pos += 2;
|
|
262
|
+
commentClosed = true;
|
|
263
|
+
break;
|
|
264
|
+
}
|
|
265
|
+
pos++;
|
|
266
|
+
if (isLineBreak(ch)) {
|
|
267
|
+
if (ch === 13 && text.charCodeAt(pos) === 10) {
|
|
268
|
+
pos++;
|
|
269
|
+
}
|
|
270
|
+
lineNumber++;
|
|
271
|
+
tokenLineStartOffset = pos;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
if (!commentClosed) {
|
|
275
|
+
pos++;
|
|
276
|
+
scanError = 1;
|
|
277
|
+
}
|
|
278
|
+
value = text.substring(start, pos);
|
|
279
|
+
return token = 13;
|
|
280
|
+
}
|
|
281
|
+
value += String.fromCharCode(code);
|
|
282
|
+
pos++;
|
|
283
|
+
return token = 16;
|
|
284
|
+
// numbers
|
|
285
|
+
case 45:
|
|
286
|
+
value += String.fromCharCode(code);
|
|
287
|
+
pos++;
|
|
288
|
+
if (pos === len || !isDigit(text.charCodeAt(pos))) {
|
|
289
|
+
return token = 16;
|
|
290
|
+
}
|
|
291
|
+
// found a minus, followed by a number so
|
|
292
|
+
// we fall through to proceed with scanning
|
|
293
|
+
// numbers
|
|
294
|
+
case 48:
|
|
295
|
+
case 49:
|
|
296
|
+
case 50:
|
|
297
|
+
case 51:
|
|
298
|
+
case 52:
|
|
299
|
+
case 53:
|
|
300
|
+
case 54:
|
|
301
|
+
case 55:
|
|
302
|
+
case 56:
|
|
303
|
+
case 57:
|
|
304
|
+
value += scanNumber();
|
|
305
|
+
return token = 11;
|
|
306
|
+
// literals and unknown symbols
|
|
307
|
+
default:
|
|
308
|
+
while (pos < len && isUnknownContentCharacter(code)) {
|
|
309
|
+
pos++;
|
|
310
|
+
code = text.charCodeAt(pos);
|
|
311
|
+
}
|
|
312
|
+
if (tokenOffset !== pos) {
|
|
313
|
+
value = text.substring(tokenOffset, pos);
|
|
314
|
+
switch (value) {
|
|
315
|
+
case "true":
|
|
316
|
+
return token = 8;
|
|
317
|
+
case "false":
|
|
318
|
+
return token = 9;
|
|
319
|
+
case "null":
|
|
320
|
+
return token = 7;
|
|
321
|
+
}
|
|
322
|
+
return token = 16;
|
|
323
|
+
}
|
|
324
|
+
value += String.fromCharCode(code);
|
|
325
|
+
pos++;
|
|
326
|
+
return token = 16;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
function isUnknownContentCharacter(code) {
|
|
330
|
+
if (isWhiteSpace(code) || isLineBreak(code)) {
|
|
331
|
+
return false;
|
|
332
|
+
}
|
|
333
|
+
switch (code) {
|
|
334
|
+
case 125:
|
|
335
|
+
case 93:
|
|
336
|
+
case 123:
|
|
337
|
+
case 91:
|
|
338
|
+
case 34:
|
|
339
|
+
case 58:
|
|
340
|
+
case 44:
|
|
341
|
+
case 47:
|
|
342
|
+
return false;
|
|
343
|
+
}
|
|
344
|
+
return true;
|
|
345
|
+
}
|
|
346
|
+
function scanNextNonTrivia() {
|
|
347
|
+
let result;
|
|
348
|
+
do {
|
|
349
|
+
result = scanNext();
|
|
350
|
+
} while (result >= 12 && result <= 15);
|
|
351
|
+
return result;
|
|
352
|
+
}
|
|
353
|
+
return {
|
|
354
|
+
setPosition,
|
|
355
|
+
getPosition: () => pos,
|
|
356
|
+
scan: ignoreTrivia ? scanNextNonTrivia : scanNext,
|
|
357
|
+
getToken: () => token,
|
|
358
|
+
getTokenValue: () => value,
|
|
359
|
+
getTokenOffset: () => tokenOffset,
|
|
360
|
+
getTokenLength: () => pos - tokenOffset,
|
|
361
|
+
getTokenStartLine: () => lineStartOffset,
|
|
362
|
+
getTokenStartCharacter: () => tokenOffset - prevTokenLineStartOffset,
|
|
363
|
+
getTokenError: () => scanError
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
function isWhiteSpace(ch) {
|
|
367
|
+
return ch === 32 || ch === 9;
|
|
368
|
+
}
|
|
369
|
+
function isLineBreak(ch) {
|
|
370
|
+
return ch === 10 || ch === 13;
|
|
371
|
+
}
|
|
372
|
+
function isDigit(ch) {
|
|
373
|
+
return ch >= 48 && ch <= 57;
|
|
374
|
+
}
|
|
375
|
+
var CharacterCodes;
|
|
376
|
+
(function(CharacterCodes2) {
|
|
377
|
+
CharacterCodes2[CharacterCodes2["lineFeed"] = 10] = "lineFeed";
|
|
378
|
+
CharacterCodes2[CharacterCodes2["carriageReturn"] = 13] = "carriageReturn";
|
|
379
|
+
CharacterCodes2[CharacterCodes2["space"] = 32] = "space";
|
|
380
|
+
CharacterCodes2[CharacterCodes2["_0"] = 48] = "_0";
|
|
381
|
+
CharacterCodes2[CharacterCodes2["_1"] = 49] = "_1";
|
|
382
|
+
CharacterCodes2[CharacterCodes2["_2"] = 50] = "_2";
|
|
383
|
+
CharacterCodes2[CharacterCodes2["_3"] = 51] = "_3";
|
|
384
|
+
CharacterCodes2[CharacterCodes2["_4"] = 52] = "_4";
|
|
385
|
+
CharacterCodes2[CharacterCodes2["_5"] = 53] = "_5";
|
|
386
|
+
CharacterCodes2[CharacterCodes2["_6"] = 54] = "_6";
|
|
387
|
+
CharacterCodes2[CharacterCodes2["_7"] = 55] = "_7";
|
|
388
|
+
CharacterCodes2[CharacterCodes2["_8"] = 56] = "_8";
|
|
389
|
+
CharacterCodes2[CharacterCodes2["_9"] = 57] = "_9";
|
|
390
|
+
CharacterCodes2[CharacterCodes2["a"] = 97] = "a";
|
|
391
|
+
CharacterCodes2[CharacterCodes2["b"] = 98] = "b";
|
|
392
|
+
CharacterCodes2[CharacterCodes2["c"] = 99] = "c";
|
|
393
|
+
CharacterCodes2[CharacterCodes2["d"] = 100] = "d";
|
|
394
|
+
CharacterCodes2[CharacterCodes2["e"] = 101] = "e";
|
|
395
|
+
CharacterCodes2[CharacterCodes2["f"] = 102] = "f";
|
|
396
|
+
CharacterCodes2[CharacterCodes2["g"] = 103] = "g";
|
|
397
|
+
CharacterCodes2[CharacterCodes2["h"] = 104] = "h";
|
|
398
|
+
CharacterCodes2[CharacterCodes2["i"] = 105] = "i";
|
|
399
|
+
CharacterCodes2[CharacterCodes2["j"] = 106] = "j";
|
|
400
|
+
CharacterCodes2[CharacterCodes2["k"] = 107] = "k";
|
|
401
|
+
CharacterCodes2[CharacterCodes2["l"] = 108] = "l";
|
|
402
|
+
CharacterCodes2[CharacterCodes2["m"] = 109] = "m";
|
|
403
|
+
CharacterCodes2[CharacterCodes2["n"] = 110] = "n";
|
|
404
|
+
CharacterCodes2[CharacterCodes2["o"] = 111] = "o";
|
|
405
|
+
CharacterCodes2[CharacterCodes2["p"] = 112] = "p";
|
|
406
|
+
CharacterCodes2[CharacterCodes2["q"] = 113] = "q";
|
|
407
|
+
CharacterCodes2[CharacterCodes2["r"] = 114] = "r";
|
|
408
|
+
CharacterCodes2[CharacterCodes2["s"] = 115] = "s";
|
|
409
|
+
CharacterCodes2[CharacterCodes2["t"] = 116] = "t";
|
|
410
|
+
CharacterCodes2[CharacterCodes2["u"] = 117] = "u";
|
|
411
|
+
CharacterCodes2[CharacterCodes2["v"] = 118] = "v";
|
|
412
|
+
CharacterCodes2[CharacterCodes2["w"] = 119] = "w";
|
|
413
|
+
CharacterCodes2[CharacterCodes2["x"] = 120] = "x";
|
|
414
|
+
CharacterCodes2[CharacterCodes2["y"] = 121] = "y";
|
|
415
|
+
CharacterCodes2[CharacterCodes2["z"] = 122] = "z";
|
|
416
|
+
CharacterCodes2[CharacterCodes2["A"] = 65] = "A";
|
|
417
|
+
CharacterCodes2[CharacterCodes2["B"] = 66] = "B";
|
|
418
|
+
CharacterCodes2[CharacterCodes2["C"] = 67] = "C";
|
|
419
|
+
CharacterCodes2[CharacterCodes2["D"] = 68] = "D";
|
|
420
|
+
CharacterCodes2[CharacterCodes2["E"] = 69] = "E";
|
|
421
|
+
CharacterCodes2[CharacterCodes2["F"] = 70] = "F";
|
|
422
|
+
CharacterCodes2[CharacterCodes2["G"] = 71] = "G";
|
|
423
|
+
CharacterCodes2[CharacterCodes2["H"] = 72] = "H";
|
|
424
|
+
CharacterCodes2[CharacterCodes2["I"] = 73] = "I";
|
|
425
|
+
CharacterCodes2[CharacterCodes2["J"] = 74] = "J";
|
|
426
|
+
CharacterCodes2[CharacterCodes2["K"] = 75] = "K";
|
|
427
|
+
CharacterCodes2[CharacterCodes2["L"] = 76] = "L";
|
|
428
|
+
CharacterCodes2[CharacterCodes2["M"] = 77] = "M";
|
|
429
|
+
CharacterCodes2[CharacterCodes2["N"] = 78] = "N";
|
|
430
|
+
CharacterCodes2[CharacterCodes2["O"] = 79] = "O";
|
|
431
|
+
CharacterCodes2[CharacterCodes2["P"] = 80] = "P";
|
|
432
|
+
CharacterCodes2[CharacterCodes2["Q"] = 81] = "Q";
|
|
433
|
+
CharacterCodes2[CharacterCodes2["R"] = 82] = "R";
|
|
434
|
+
CharacterCodes2[CharacterCodes2["S"] = 83] = "S";
|
|
435
|
+
CharacterCodes2[CharacterCodes2["T"] = 84] = "T";
|
|
436
|
+
CharacterCodes2[CharacterCodes2["U"] = 85] = "U";
|
|
437
|
+
CharacterCodes2[CharacterCodes2["V"] = 86] = "V";
|
|
438
|
+
CharacterCodes2[CharacterCodes2["W"] = 87] = "W";
|
|
439
|
+
CharacterCodes2[CharacterCodes2["X"] = 88] = "X";
|
|
440
|
+
CharacterCodes2[CharacterCodes2["Y"] = 89] = "Y";
|
|
441
|
+
CharacterCodes2[CharacterCodes2["Z"] = 90] = "Z";
|
|
442
|
+
CharacterCodes2[CharacterCodes2["asterisk"] = 42] = "asterisk";
|
|
443
|
+
CharacterCodes2[CharacterCodes2["backslash"] = 92] = "backslash";
|
|
444
|
+
CharacterCodes2[CharacterCodes2["closeBrace"] = 125] = "closeBrace";
|
|
445
|
+
CharacterCodes2[CharacterCodes2["closeBracket"] = 93] = "closeBracket";
|
|
446
|
+
CharacterCodes2[CharacterCodes2["colon"] = 58] = "colon";
|
|
447
|
+
CharacterCodes2[CharacterCodes2["comma"] = 44] = "comma";
|
|
448
|
+
CharacterCodes2[CharacterCodes2["dot"] = 46] = "dot";
|
|
449
|
+
CharacterCodes2[CharacterCodes2["doubleQuote"] = 34] = "doubleQuote";
|
|
450
|
+
CharacterCodes2[CharacterCodes2["minus"] = 45] = "minus";
|
|
451
|
+
CharacterCodes2[CharacterCodes2["openBrace"] = 123] = "openBrace";
|
|
452
|
+
CharacterCodes2[CharacterCodes2["openBracket"] = 91] = "openBracket";
|
|
453
|
+
CharacterCodes2[CharacterCodes2["plus"] = 43] = "plus";
|
|
454
|
+
CharacterCodes2[CharacterCodes2["slash"] = 47] = "slash";
|
|
455
|
+
CharacterCodes2[CharacterCodes2["formFeed"] = 12] = "formFeed";
|
|
456
|
+
CharacterCodes2[CharacterCodes2["tab"] = 9] = "tab";
|
|
457
|
+
})(CharacterCodes || (CharacterCodes = {}));
|
|
458
|
+
|
|
459
|
+
// node_modules/jsonc-parser/lib/esm/impl/string-intern.js
|
|
460
|
+
var cachedSpaces = new Array(20).fill(0).map((_, index) => {
|
|
461
|
+
return " ".repeat(index);
|
|
462
|
+
});
|
|
463
|
+
var maxCachedValues = 200;
|
|
464
|
+
var cachedBreakLinesWithSpaces = {
|
|
465
|
+
" ": {
|
|
466
|
+
"\n": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
467
|
+
return "\n" + " ".repeat(index);
|
|
468
|
+
}),
|
|
469
|
+
"\r": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
470
|
+
return "\r" + " ".repeat(index);
|
|
471
|
+
}),
|
|
472
|
+
"\r\n": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
473
|
+
return "\r\n" + " ".repeat(index);
|
|
474
|
+
})
|
|
475
|
+
},
|
|
476
|
+
" ": {
|
|
477
|
+
"\n": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
478
|
+
return "\n" + " ".repeat(index);
|
|
479
|
+
}),
|
|
480
|
+
"\r": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
481
|
+
return "\r" + " ".repeat(index);
|
|
482
|
+
}),
|
|
483
|
+
"\r\n": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
484
|
+
return "\r\n" + " ".repeat(index);
|
|
485
|
+
})
|
|
486
|
+
}
|
|
487
|
+
};
|
|
488
|
+
var supportedEols = ["\n", "\r", "\r\n"];
|
|
489
|
+
|
|
490
|
+
// node_modules/jsonc-parser/lib/esm/impl/format.js
|
|
491
|
+
function format(documentText, range, options) {
|
|
492
|
+
let initialIndentLevel;
|
|
493
|
+
let formatText;
|
|
494
|
+
let formatTextStart;
|
|
495
|
+
let rangeStart;
|
|
496
|
+
let rangeEnd;
|
|
497
|
+
if (range) {
|
|
498
|
+
rangeStart = range.offset;
|
|
499
|
+
rangeEnd = rangeStart + range.length;
|
|
500
|
+
formatTextStart = rangeStart;
|
|
501
|
+
while (formatTextStart > 0 && !isEOL(documentText, formatTextStart - 1)) {
|
|
502
|
+
formatTextStart--;
|
|
503
|
+
}
|
|
504
|
+
let endOffset = rangeEnd;
|
|
505
|
+
while (endOffset < documentText.length && !isEOL(documentText, endOffset)) {
|
|
506
|
+
endOffset++;
|
|
507
|
+
}
|
|
508
|
+
formatText = documentText.substring(formatTextStart, endOffset);
|
|
509
|
+
initialIndentLevel = computeIndentLevel(formatText, options);
|
|
510
|
+
} else {
|
|
511
|
+
formatText = documentText;
|
|
512
|
+
initialIndentLevel = 0;
|
|
513
|
+
formatTextStart = 0;
|
|
514
|
+
rangeStart = 0;
|
|
515
|
+
rangeEnd = documentText.length;
|
|
516
|
+
}
|
|
517
|
+
const eol = getEOL(options, documentText);
|
|
518
|
+
const eolFastPathSupported = supportedEols.includes(eol);
|
|
519
|
+
let numberLineBreaks = 0;
|
|
520
|
+
let indentLevel = 0;
|
|
521
|
+
let indentValue;
|
|
522
|
+
if (options.insertSpaces) {
|
|
523
|
+
indentValue = cachedSpaces[options.tabSize || 4] ?? repeat(cachedSpaces[1], options.tabSize || 4);
|
|
524
|
+
} else {
|
|
525
|
+
indentValue = " ";
|
|
526
|
+
}
|
|
527
|
+
const indentType = indentValue === " " ? " " : " ";
|
|
528
|
+
let scanner = createScanner(formatText, false);
|
|
529
|
+
let hasError = false;
|
|
530
|
+
function newLinesAndIndent() {
|
|
531
|
+
if (numberLineBreaks > 1) {
|
|
532
|
+
return repeat(eol, numberLineBreaks) + repeat(indentValue, initialIndentLevel + indentLevel);
|
|
533
|
+
}
|
|
534
|
+
const amountOfSpaces = indentValue.length * (initialIndentLevel + indentLevel);
|
|
535
|
+
if (!eolFastPathSupported || amountOfSpaces > cachedBreakLinesWithSpaces[indentType][eol].length) {
|
|
536
|
+
return eol + repeat(indentValue, initialIndentLevel + indentLevel);
|
|
537
|
+
}
|
|
538
|
+
if (amountOfSpaces <= 0) {
|
|
539
|
+
return eol;
|
|
540
|
+
}
|
|
541
|
+
return cachedBreakLinesWithSpaces[indentType][eol][amountOfSpaces];
|
|
542
|
+
}
|
|
543
|
+
function scanNext() {
|
|
544
|
+
let token = scanner.scan();
|
|
545
|
+
numberLineBreaks = 0;
|
|
546
|
+
while (token === 15 || token === 14) {
|
|
547
|
+
if (token === 14 && options.keepLines) {
|
|
548
|
+
numberLineBreaks += 1;
|
|
549
|
+
} else if (token === 14) {
|
|
550
|
+
numberLineBreaks = 1;
|
|
551
|
+
}
|
|
552
|
+
token = scanner.scan();
|
|
553
|
+
}
|
|
554
|
+
hasError = token === 16 || scanner.getTokenError() !== 0;
|
|
555
|
+
return token;
|
|
556
|
+
}
|
|
557
|
+
const editOperations = [];
|
|
558
|
+
function addEdit(text, startOffset, endOffset) {
|
|
559
|
+
if (!hasError && (!range || startOffset < rangeEnd && endOffset > rangeStart) && documentText.substring(startOffset, endOffset) !== text) {
|
|
560
|
+
editOperations.push({ offset: startOffset, length: endOffset - startOffset, content: text });
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
let firstToken = scanNext();
|
|
564
|
+
if (options.keepLines && numberLineBreaks > 0) {
|
|
565
|
+
addEdit(repeat(eol, numberLineBreaks), 0, 0);
|
|
566
|
+
}
|
|
567
|
+
if (firstToken !== 17) {
|
|
568
|
+
let firstTokenStart = scanner.getTokenOffset() + formatTextStart;
|
|
569
|
+
let initialIndent = indentValue.length * initialIndentLevel < 20 && options.insertSpaces ? cachedSpaces[indentValue.length * initialIndentLevel] : repeat(indentValue, initialIndentLevel);
|
|
570
|
+
addEdit(initialIndent, formatTextStart, firstTokenStart);
|
|
571
|
+
}
|
|
572
|
+
while (firstToken !== 17) {
|
|
573
|
+
let firstTokenEnd = scanner.getTokenOffset() + scanner.getTokenLength() + formatTextStart;
|
|
574
|
+
let secondToken = scanNext();
|
|
575
|
+
let replaceContent = "";
|
|
576
|
+
let needsLineBreak = false;
|
|
577
|
+
while (numberLineBreaks === 0 && (secondToken === 12 || secondToken === 13)) {
|
|
578
|
+
let commentTokenStart = scanner.getTokenOffset() + formatTextStart;
|
|
579
|
+
addEdit(cachedSpaces[1], firstTokenEnd, commentTokenStart);
|
|
580
|
+
firstTokenEnd = scanner.getTokenOffset() + scanner.getTokenLength() + formatTextStart;
|
|
581
|
+
needsLineBreak = secondToken === 12;
|
|
582
|
+
replaceContent = needsLineBreak ? newLinesAndIndent() : "";
|
|
583
|
+
secondToken = scanNext();
|
|
584
|
+
}
|
|
585
|
+
if (secondToken === 2) {
|
|
586
|
+
if (firstToken !== 1) {
|
|
587
|
+
indentLevel--;
|
|
588
|
+
}
|
|
589
|
+
;
|
|
590
|
+
if (options.keepLines && numberLineBreaks > 0 || !options.keepLines && firstToken !== 1) {
|
|
591
|
+
replaceContent = newLinesAndIndent();
|
|
592
|
+
} else if (options.keepLines) {
|
|
593
|
+
replaceContent = cachedSpaces[1];
|
|
594
|
+
}
|
|
595
|
+
} else if (secondToken === 4) {
|
|
596
|
+
if (firstToken !== 3) {
|
|
597
|
+
indentLevel--;
|
|
598
|
+
}
|
|
599
|
+
;
|
|
600
|
+
if (options.keepLines && numberLineBreaks > 0 || !options.keepLines && firstToken !== 3) {
|
|
601
|
+
replaceContent = newLinesAndIndent();
|
|
602
|
+
} else if (options.keepLines) {
|
|
603
|
+
replaceContent = cachedSpaces[1];
|
|
604
|
+
}
|
|
605
|
+
} else {
|
|
606
|
+
switch (firstToken) {
|
|
607
|
+
case 3:
|
|
608
|
+
case 1:
|
|
609
|
+
indentLevel++;
|
|
610
|
+
if (options.keepLines && numberLineBreaks > 0 || !options.keepLines) {
|
|
611
|
+
replaceContent = newLinesAndIndent();
|
|
612
|
+
} else {
|
|
613
|
+
replaceContent = cachedSpaces[1];
|
|
614
|
+
}
|
|
615
|
+
break;
|
|
616
|
+
case 5:
|
|
617
|
+
if (options.keepLines && numberLineBreaks > 0 || !options.keepLines) {
|
|
618
|
+
replaceContent = newLinesAndIndent();
|
|
619
|
+
} else {
|
|
620
|
+
replaceContent = cachedSpaces[1];
|
|
621
|
+
}
|
|
622
|
+
break;
|
|
623
|
+
case 12:
|
|
624
|
+
replaceContent = newLinesAndIndent();
|
|
625
|
+
break;
|
|
626
|
+
case 13:
|
|
627
|
+
if (numberLineBreaks > 0) {
|
|
628
|
+
replaceContent = newLinesAndIndent();
|
|
629
|
+
} else if (!needsLineBreak) {
|
|
630
|
+
replaceContent = cachedSpaces[1];
|
|
631
|
+
}
|
|
632
|
+
break;
|
|
633
|
+
case 6:
|
|
634
|
+
if (options.keepLines && numberLineBreaks > 0) {
|
|
635
|
+
replaceContent = newLinesAndIndent();
|
|
636
|
+
} else if (!needsLineBreak) {
|
|
637
|
+
replaceContent = cachedSpaces[1];
|
|
638
|
+
}
|
|
639
|
+
break;
|
|
640
|
+
case 10:
|
|
641
|
+
if (options.keepLines && numberLineBreaks > 0) {
|
|
642
|
+
replaceContent = newLinesAndIndent();
|
|
643
|
+
} else if (secondToken === 6 && !needsLineBreak) {
|
|
644
|
+
replaceContent = "";
|
|
645
|
+
}
|
|
646
|
+
break;
|
|
647
|
+
case 7:
|
|
648
|
+
case 8:
|
|
649
|
+
case 9:
|
|
650
|
+
case 11:
|
|
651
|
+
case 2:
|
|
652
|
+
case 4:
|
|
653
|
+
if (options.keepLines && numberLineBreaks > 0) {
|
|
654
|
+
replaceContent = newLinesAndIndent();
|
|
655
|
+
} else {
|
|
656
|
+
if ((secondToken === 12 || secondToken === 13) && !needsLineBreak) {
|
|
657
|
+
replaceContent = cachedSpaces[1];
|
|
658
|
+
} else if (secondToken !== 5 && secondToken !== 17) {
|
|
659
|
+
hasError = true;
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
break;
|
|
663
|
+
case 16:
|
|
664
|
+
hasError = true;
|
|
665
|
+
break;
|
|
666
|
+
}
|
|
667
|
+
if (numberLineBreaks > 0 && (secondToken === 12 || secondToken === 13)) {
|
|
668
|
+
replaceContent = newLinesAndIndent();
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
if (secondToken === 17) {
|
|
672
|
+
if (options.keepLines && numberLineBreaks > 0) {
|
|
673
|
+
replaceContent = newLinesAndIndent();
|
|
674
|
+
} else {
|
|
675
|
+
replaceContent = options.insertFinalNewline ? eol : "";
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
const secondTokenStart = scanner.getTokenOffset() + formatTextStart;
|
|
679
|
+
addEdit(replaceContent, firstTokenEnd, secondTokenStart);
|
|
680
|
+
firstToken = secondToken;
|
|
681
|
+
}
|
|
682
|
+
return editOperations;
|
|
683
|
+
}
|
|
684
|
+
function repeat(s, count) {
|
|
685
|
+
let result = "";
|
|
686
|
+
for (let i = 0; i < count; i++) {
|
|
687
|
+
result += s;
|
|
688
|
+
}
|
|
689
|
+
return result;
|
|
690
|
+
}
|
|
691
|
+
function computeIndentLevel(content, options) {
|
|
692
|
+
let i = 0;
|
|
693
|
+
let nChars = 0;
|
|
694
|
+
const tabSize = options.tabSize || 4;
|
|
695
|
+
while (i < content.length) {
|
|
696
|
+
let ch = content.charAt(i);
|
|
697
|
+
if (ch === cachedSpaces[1]) {
|
|
698
|
+
nChars++;
|
|
699
|
+
} else if (ch === " ") {
|
|
700
|
+
nChars += tabSize;
|
|
701
|
+
} else {
|
|
702
|
+
break;
|
|
703
|
+
}
|
|
704
|
+
i++;
|
|
705
|
+
}
|
|
706
|
+
return Math.floor(nChars / tabSize);
|
|
707
|
+
}
|
|
708
|
+
function getEOL(options, text) {
|
|
709
|
+
for (let i = 0; i < text.length; i++) {
|
|
710
|
+
const ch = text.charAt(i);
|
|
711
|
+
if (ch === "\r") {
|
|
712
|
+
if (i + 1 < text.length && text.charAt(i + 1) === "\n") {
|
|
713
|
+
return "\r\n";
|
|
714
|
+
}
|
|
715
|
+
return "\r";
|
|
716
|
+
} else if (ch === "\n") {
|
|
717
|
+
return "\n";
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
return options && options.eol || "\n";
|
|
721
|
+
}
|
|
722
|
+
function isEOL(text, offset) {
|
|
723
|
+
return "\r\n".indexOf(text.charAt(offset)) !== -1;
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
// node_modules/jsonc-parser/lib/esm/impl/parser.js
|
|
727
|
+
var ParseOptions;
|
|
728
|
+
(function(ParseOptions2) {
|
|
729
|
+
ParseOptions2.DEFAULT = {
|
|
730
|
+
allowTrailingComma: false
|
|
731
|
+
};
|
|
732
|
+
})(ParseOptions || (ParseOptions = {}));
|
|
733
|
+
function parse(text, errors = [], options = ParseOptions.DEFAULT) {
|
|
734
|
+
let currentProperty = null;
|
|
735
|
+
let currentParent = [];
|
|
736
|
+
const previousParents = [];
|
|
737
|
+
function onValue(value) {
|
|
738
|
+
if (Array.isArray(currentParent)) {
|
|
739
|
+
currentParent.push(value);
|
|
740
|
+
} else if (currentProperty !== null) {
|
|
741
|
+
currentParent[currentProperty] = value;
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
const visitor = {
|
|
745
|
+
onObjectBegin: () => {
|
|
746
|
+
const object = {};
|
|
747
|
+
onValue(object);
|
|
748
|
+
previousParents.push(currentParent);
|
|
749
|
+
currentParent = object;
|
|
750
|
+
currentProperty = null;
|
|
751
|
+
},
|
|
752
|
+
onObjectProperty: (name) => {
|
|
753
|
+
currentProperty = name;
|
|
754
|
+
},
|
|
755
|
+
onObjectEnd: () => {
|
|
756
|
+
currentParent = previousParents.pop();
|
|
757
|
+
},
|
|
758
|
+
onArrayBegin: () => {
|
|
759
|
+
const array = [];
|
|
760
|
+
onValue(array);
|
|
761
|
+
previousParents.push(currentParent);
|
|
762
|
+
currentParent = array;
|
|
763
|
+
currentProperty = null;
|
|
764
|
+
},
|
|
765
|
+
onArrayEnd: () => {
|
|
766
|
+
currentParent = previousParents.pop();
|
|
767
|
+
},
|
|
768
|
+
onLiteralValue: onValue,
|
|
769
|
+
onError: (error, offset, length) => {
|
|
770
|
+
errors.push({ error, offset, length });
|
|
771
|
+
}
|
|
772
|
+
};
|
|
773
|
+
visit(text, visitor, options);
|
|
774
|
+
return currentParent[0];
|
|
775
|
+
}
|
|
776
|
+
function parseTree(text, errors = [], options = ParseOptions.DEFAULT) {
|
|
777
|
+
let currentParent = { type: "array", offset: -1, length: -1, children: [], parent: void 0 };
|
|
778
|
+
function ensurePropertyComplete(endOffset) {
|
|
779
|
+
if (currentParent.type === "property") {
|
|
780
|
+
currentParent.length = endOffset - currentParent.offset;
|
|
781
|
+
currentParent = currentParent.parent;
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
function onValue(valueNode) {
|
|
785
|
+
currentParent.children.push(valueNode);
|
|
786
|
+
return valueNode;
|
|
787
|
+
}
|
|
788
|
+
const visitor = {
|
|
789
|
+
onObjectBegin: (offset) => {
|
|
790
|
+
currentParent = onValue({ type: "object", offset, length: -1, parent: currentParent, children: [] });
|
|
791
|
+
},
|
|
792
|
+
onObjectProperty: (name, offset, length) => {
|
|
793
|
+
currentParent = onValue({ type: "property", offset, length: -1, parent: currentParent, children: [] });
|
|
794
|
+
currentParent.children.push({ type: "string", value: name, offset, length, parent: currentParent });
|
|
795
|
+
},
|
|
796
|
+
onObjectEnd: (offset, length) => {
|
|
797
|
+
ensurePropertyComplete(offset + length);
|
|
798
|
+
currentParent.length = offset + length - currentParent.offset;
|
|
799
|
+
currentParent = currentParent.parent;
|
|
800
|
+
ensurePropertyComplete(offset + length);
|
|
801
|
+
},
|
|
802
|
+
onArrayBegin: (offset, length) => {
|
|
803
|
+
currentParent = onValue({ type: "array", offset, length: -1, parent: currentParent, children: [] });
|
|
804
|
+
},
|
|
805
|
+
onArrayEnd: (offset, length) => {
|
|
806
|
+
currentParent.length = offset + length - currentParent.offset;
|
|
807
|
+
currentParent = currentParent.parent;
|
|
808
|
+
ensurePropertyComplete(offset + length);
|
|
809
|
+
},
|
|
810
|
+
onLiteralValue: (value, offset, length) => {
|
|
811
|
+
onValue({ type: getNodeType(value), offset, length, parent: currentParent, value });
|
|
812
|
+
ensurePropertyComplete(offset + length);
|
|
813
|
+
},
|
|
814
|
+
onSeparator: (sep, offset, length) => {
|
|
815
|
+
if (currentParent.type === "property") {
|
|
816
|
+
if (sep === ":") {
|
|
817
|
+
currentParent.colonOffset = offset;
|
|
818
|
+
} else if (sep === ",") {
|
|
819
|
+
ensurePropertyComplete(offset);
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
},
|
|
823
|
+
onError: (error, offset, length) => {
|
|
824
|
+
errors.push({ error, offset, length });
|
|
825
|
+
}
|
|
826
|
+
};
|
|
827
|
+
visit(text, visitor, options);
|
|
828
|
+
const result = currentParent.children[0];
|
|
829
|
+
if (result) {
|
|
830
|
+
delete result.parent;
|
|
831
|
+
}
|
|
832
|
+
return result;
|
|
833
|
+
}
|
|
834
|
+
function findNodeAtLocation(root, path) {
|
|
835
|
+
if (!root) {
|
|
836
|
+
return void 0;
|
|
837
|
+
}
|
|
838
|
+
let node = root;
|
|
839
|
+
for (let segment of path) {
|
|
840
|
+
if (typeof segment === "string") {
|
|
841
|
+
if (node.type !== "object" || !Array.isArray(node.children)) {
|
|
842
|
+
return void 0;
|
|
843
|
+
}
|
|
844
|
+
let found = false;
|
|
845
|
+
for (const propertyNode of node.children) {
|
|
846
|
+
if (Array.isArray(propertyNode.children) && propertyNode.children[0].value === segment && propertyNode.children.length === 2) {
|
|
847
|
+
node = propertyNode.children[1];
|
|
848
|
+
found = true;
|
|
849
|
+
break;
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
if (!found) {
|
|
853
|
+
return void 0;
|
|
854
|
+
}
|
|
855
|
+
} else {
|
|
856
|
+
const index = segment;
|
|
857
|
+
if (node.type !== "array" || index < 0 || !Array.isArray(node.children) || index >= node.children.length) {
|
|
858
|
+
return void 0;
|
|
859
|
+
}
|
|
860
|
+
node = node.children[index];
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
return node;
|
|
864
|
+
}
|
|
865
|
+
function visit(text, visitor, options = ParseOptions.DEFAULT) {
|
|
866
|
+
const _scanner = createScanner(text, false);
|
|
867
|
+
const _jsonPath = [];
|
|
868
|
+
let suppressedCallbacks = 0;
|
|
869
|
+
function toNoArgVisit(visitFunction) {
|
|
870
|
+
return visitFunction ? () => suppressedCallbacks === 0 && visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
|
|
871
|
+
}
|
|
872
|
+
function toOneArgVisit(visitFunction) {
|
|
873
|
+
return visitFunction ? (arg) => suppressedCallbacks === 0 && visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
|
|
874
|
+
}
|
|
875
|
+
function toOneArgVisitWithPath(visitFunction) {
|
|
876
|
+
return visitFunction ? (arg) => suppressedCallbacks === 0 && visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice()) : () => true;
|
|
877
|
+
}
|
|
878
|
+
function toBeginVisit(visitFunction) {
|
|
879
|
+
return visitFunction ? () => {
|
|
880
|
+
if (suppressedCallbacks > 0) {
|
|
881
|
+
suppressedCallbacks++;
|
|
882
|
+
} else {
|
|
883
|
+
let cbReturn = visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice());
|
|
884
|
+
if (cbReturn === false) {
|
|
885
|
+
suppressedCallbacks = 1;
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
} : () => true;
|
|
889
|
+
}
|
|
890
|
+
function toEndVisit(visitFunction) {
|
|
891
|
+
return visitFunction ? () => {
|
|
892
|
+
if (suppressedCallbacks > 0) {
|
|
893
|
+
suppressedCallbacks--;
|
|
894
|
+
}
|
|
895
|
+
if (suppressedCallbacks === 0) {
|
|
896
|
+
visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter());
|
|
897
|
+
}
|
|
898
|
+
} : () => true;
|
|
899
|
+
}
|
|
900
|
+
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);
|
|
901
|
+
const disallowComments = options && options.disallowComments;
|
|
902
|
+
const allowTrailingComma = options && options.allowTrailingComma;
|
|
903
|
+
function scanNext() {
|
|
904
|
+
while (true) {
|
|
905
|
+
const token = _scanner.scan();
|
|
906
|
+
switch (_scanner.getTokenError()) {
|
|
907
|
+
case 4:
|
|
908
|
+
handleError(
|
|
909
|
+
14
|
|
910
|
+
/* ParseErrorCode.InvalidUnicode */
|
|
911
|
+
);
|
|
912
|
+
break;
|
|
913
|
+
case 5:
|
|
914
|
+
handleError(
|
|
915
|
+
15
|
|
916
|
+
/* ParseErrorCode.InvalidEscapeCharacter */
|
|
917
|
+
);
|
|
918
|
+
break;
|
|
919
|
+
case 3:
|
|
920
|
+
handleError(
|
|
921
|
+
13
|
|
922
|
+
/* ParseErrorCode.UnexpectedEndOfNumber */
|
|
923
|
+
);
|
|
924
|
+
break;
|
|
925
|
+
case 1:
|
|
926
|
+
if (!disallowComments) {
|
|
927
|
+
handleError(
|
|
928
|
+
11
|
|
929
|
+
/* ParseErrorCode.UnexpectedEndOfComment */
|
|
930
|
+
);
|
|
931
|
+
}
|
|
932
|
+
break;
|
|
933
|
+
case 2:
|
|
934
|
+
handleError(
|
|
935
|
+
12
|
|
936
|
+
/* ParseErrorCode.UnexpectedEndOfString */
|
|
937
|
+
);
|
|
938
|
+
break;
|
|
939
|
+
case 6:
|
|
940
|
+
handleError(
|
|
941
|
+
16
|
|
942
|
+
/* ParseErrorCode.InvalidCharacter */
|
|
943
|
+
);
|
|
944
|
+
break;
|
|
945
|
+
}
|
|
946
|
+
switch (token) {
|
|
947
|
+
case 12:
|
|
948
|
+
case 13:
|
|
949
|
+
if (disallowComments) {
|
|
950
|
+
handleError(
|
|
951
|
+
10
|
|
952
|
+
/* ParseErrorCode.InvalidCommentToken */
|
|
953
|
+
);
|
|
954
|
+
} else {
|
|
955
|
+
onComment();
|
|
956
|
+
}
|
|
957
|
+
break;
|
|
958
|
+
case 16:
|
|
959
|
+
handleError(
|
|
960
|
+
1
|
|
961
|
+
/* ParseErrorCode.InvalidSymbol */
|
|
962
|
+
);
|
|
963
|
+
break;
|
|
964
|
+
case 15:
|
|
965
|
+
case 14:
|
|
966
|
+
break;
|
|
967
|
+
default:
|
|
968
|
+
return token;
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
function handleError(error, skipUntilAfter = [], skipUntil = []) {
|
|
973
|
+
onError(error);
|
|
974
|
+
if (skipUntilAfter.length + skipUntil.length > 0) {
|
|
975
|
+
let token = _scanner.getToken();
|
|
976
|
+
while (token !== 17) {
|
|
977
|
+
if (skipUntilAfter.indexOf(token) !== -1) {
|
|
978
|
+
scanNext();
|
|
979
|
+
break;
|
|
980
|
+
} else if (skipUntil.indexOf(token) !== -1) {
|
|
981
|
+
break;
|
|
982
|
+
}
|
|
983
|
+
token = scanNext();
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
function parseString(isValue) {
|
|
988
|
+
const value = _scanner.getTokenValue();
|
|
989
|
+
if (isValue) {
|
|
990
|
+
onLiteralValue(value);
|
|
991
|
+
} else {
|
|
992
|
+
onObjectProperty(value);
|
|
993
|
+
_jsonPath.push(value);
|
|
994
|
+
}
|
|
995
|
+
scanNext();
|
|
996
|
+
return true;
|
|
997
|
+
}
|
|
998
|
+
function parseLiteral() {
|
|
999
|
+
switch (_scanner.getToken()) {
|
|
1000
|
+
case 11:
|
|
1001
|
+
const tokenValue = _scanner.getTokenValue();
|
|
1002
|
+
let value = Number(tokenValue);
|
|
1003
|
+
if (isNaN(value)) {
|
|
1004
|
+
handleError(
|
|
1005
|
+
2
|
|
1006
|
+
/* ParseErrorCode.InvalidNumberFormat */
|
|
1007
|
+
);
|
|
1008
|
+
value = 0;
|
|
1009
|
+
}
|
|
1010
|
+
onLiteralValue(value);
|
|
1011
|
+
break;
|
|
1012
|
+
case 7:
|
|
1013
|
+
onLiteralValue(null);
|
|
1014
|
+
break;
|
|
1015
|
+
case 8:
|
|
1016
|
+
onLiteralValue(true);
|
|
1017
|
+
break;
|
|
1018
|
+
case 9:
|
|
1019
|
+
onLiteralValue(false);
|
|
1020
|
+
break;
|
|
1021
|
+
default:
|
|
1022
|
+
return false;
|
|
1023
|
+
}
|
|
1024
|
+
scanNext();
|
|
1025
|
+
return true;
|
|
1026
|
+
}
|
|
1027
|
+
function parseProperty() {
|
|
1028
|
+
if (_scanner.getToken() !== 10) {
|
|
1029
|
+
handleError(3, [], [
|
|
1030
|
+
2,
|
|
1031
|
+
5
|
|
1032
|
+
/* SyntaxKind.CommaToken */
|
|
1033
|
+
]);
|
|
1034
|
+
return false;
|
|
1035
|
+
}
|
|
1036
|
+
parseString(false);
|
|
1037
|
+
if (_scanner.getToken() === 6) {
|
|
1038
|
+
onSeparator(":");
|
|
1039
|
+
scanNext();
|
|
1040
|
+
if (!parseValue()) {
|
|
1041
|
+
handleError(4, [], [
|
|
1042
|
+
2,
|
|
1043
|
+
5
|
|
1044
|
+
/* SyntaxKind.CommaToken */
|
|
1045
|
+
]);
|
|
1046
|
+
}
|
|
1047
|
+
} else {
|
|
1048
|
+
handleError(5, [], [
|
|
1049
|
+
2,
|
|
1050
|
+
5
|
|
1051
|
+
/* SyntaxKind.CommaToken */
|
|
1052
|
+
]);
|
|
1053
|
+
}
|
|
1054
|
+
_jsonPath.pop();
|
|
1055
|
+
return true;
|
|
1056
|
+
}
|
|
1057
|
+
function parseObject() {
|
|
1058
|
+
onObjectBegin();
|
|
1059
|
+
scanNext();
|
|
1060
|
+
let needsComma = false;
|
|
1061
|
+
while (_scanner.getToken() !== 2 && _scanner.getToken() !== 17) {
|
|
1062
|
+
if (_scanner.getToken() === 5) {
|
|
1063
|
+
if (!needsComma) {
|
|
1064
|
+
handleError(4, [], []);
|
|
1065
|
+
}
|
|
1066
|
+
onSeparator(",");
|
|
1067
|
+
scanNext();
|
|
1068
|
+
if (_scanner.getToken() === 2 && allowTrailingComma) {
|
|
1069
|
+
break;
|
|
1070
|
+
}
|
|
1071
|
+
} else if (needsComma) {
|
|
1072
|
+
handleError(6, [], []);
|
|
1073
|
+
}
|
|
1074
|
+
if (!parseProperty()) {
|
|
1075
|
+
handleError(4, [], [
|
|
1076
|
+
2,
|
|
1077
|
+
5
|
|
1078
|
+
/* SyntaxKind.CommaToken */
|
|
1079
|
+
]);
|
|
1080
|
+
}
|
|
1081
|
+
needsComma = true;
|
|
1082
|
+
}
|
|
1083
|
+
onObjectEnd();
|
|
1084
|
+
if (_scanner.getToken() !== 2) {
|
|
1085
|
+
handleError(7, [
|
|
1086
|
+
2
|
|
1087
|
+
/* SyntaxKind.CloseBraceToken */
|
|
1088
|
+
], []);
|
|
1089
|
+
} else {
|
|
1090
|
+
scanNext();
|
|
1091
|
+
}
|
|
1092
|
+
return true;
|
|
1093
|
+
}
|
|
1094
|
+
function parseArray() {
|
|
1095
|
+
onArrayBegin();
|
|
1096
|
+
scanNext();
|
|
1097
|
+
let isFirstElement = true;
|
|
1098
|
+
let needsComma = false;
|
|
1099
|
+
while (_scanner.getToken() !== 4 && _scanner.getToken() !== 17) {
|
|
1100
|
+
if (_scanner.getToken() === 5) {
|
|
1101
|
+
if (!needsComma) {
|
|
1102
|
+
handleError(4, [], []);
|
|
1103
|
+
}
|
|
1104
|
+
onSeparator(",");
|
|
1105
|
+
scanNext();
|
|
1106
|
+
if (_scanner.getToken() === 4 && allowTrailingComma) {
|
|
1107
|
+
break;
|
|
1108
|
+
}
|
|
1109
|
+
} else if (needsComma) {
|
|
1110
|
+
handleError(6, [], []);
|
|
1111
|
+
}
|
|
1112
|
+
if (isFirstElement) {
|
|
1113
|
+
_jsonPath.push(0);
|
|
1114
|
+
isFirstElement = false;
|
|
1115
|
+
} else {
|
|
1116
|
+
_jsonPath[_jsonPath.length - 1]++;
|
|
1117
|
+
}
|
|
1118
|
+
if (!parseValue()) {
|
|
1119
|
+
handleError(4, [], [
|
|
1120
|
+
4,
|
|
1121
|
+
5
|
|
1122
|
+
/* SyntaxKind.CommaToken */
|
|
1123
|
+
]);
|
|
1124
|
+
}
|
|
1125
|
+
needsComma = true;
|
|
1126
|
+
}
|
|
1127
|
+
onArrayEnd();
|
|
1128
|
+
if (!isFirstElement) {
|
|
1129
|
+
_jsonPath.pop();
|
|
1130
|
+
}
|
|
1131
|
+
if (_scanner.getToken() !== 4) {
|
|
1132
|
+
handleError(8, [
|
|
1133
|
+
4
|
|
1134
|
+
/* SyntaxKind.CloseBracketToken */
|
|
1135
|
+
], []);
|
|
1136
|
+
} else {
|
|
1137
|
+
scanNext();
|
|
1138
|
+
}
|
|
1139
|
+
return true;
|
|
1140
|
+
}
|
|
1141
|
+
function parseValue() {
|
|
1142
|
+
switch (_scanner.getToken()) {
|
|
1143
|
+
case 3:
|
|
1144
|
+
return parseArray();
|
|
1145
|
+
case 1:
|
|
1146
|
+
return parseObject();
|
|
1147
|
+
case 10:
|
|
1148
|
+
return parseString(true);
|
|
1149
|
+
default:
|
|
1150
|
+
return parseLiteral();
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1153
|
+
scanNext();
|
|
1154
|
+
if (_scanner.getToken() === 17) {
|
|
1155
|
+
if (options.allowEmptyContent) {
|
|
1156
|
+
return true;
|
|
1157
|
+
}
|
|
1158
|
+
handleError(4, [], []);
|
|
1159
|
+
return false;
|
|
1160
|
+
}
|
|
1161
|
+
if (!parseValue()) {
|
|
1162
|
+
handleError(4, [], []);
|
|
1163
|
+
return false;
|
|
1164
|
+
}
|
|
1165
|
+
if (_scanner.getToken() !== 17) {
|
|
1166
|
+
handleError(9, [], []);
|
|
1167
|
+
}
|
|
1168
|
+
return true;
|
|
1169
|
+
}
|
|
1170
|
+
function getNodeType(value) {
|
|
1171
|
+
switch (typeof value) {
|
|
1172
|
+
case "boolean":
|
|
1173
|
+
return "boolean";
|
|
1174
|
+
case "number":
|
|
1175
|
+
return "number";
|
|
1176
|
+
case "string":
|
|
1177
|
+
return "string";
|
|
1178
|
+
case "object": {
|
|
1179
|
+
if (!value) {
|
|
1180
|
+
return "null";
|
|
1181
|
+
} else if (Array.isArray(value)) {
|
|
1182
|
+
return "array";
|
|
1183
|
+
}
|
|
1184
|
+
return "object";
|
|
1185
|
+
}
|
|
1186
|
+
default:
|
|
1187
|
+
return "null";
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1191
|
+
// node_modules/jsonc-parser/lib/esm/impl/edit.js
|
|
1192
|
+
function setProperty(text, originalPath, value, options) {
|
|
1193
|
+
const path = originalPath.slice();
|
|
1194
|
+
const errors = [];
|
|
1195
|
+
const root = parseTree(text, errors);
|
|
1196
|
+
let parent = void 0;
|
|
1197
|
+
let lastSegment = void 0;
|
|
1198
|
+
while (path.length > 0) {
|
|
1199
|
+
lastSegment = path.pop();
|
|
1200
|
+
parent = findNodeAtLocation(root, path);
|
|
1201
|
+
if (parent === void 0 && value !== void 0) {
|
|
1202
|
+
if (typeof lastSegment === "string") {
|
|
1203
|
+
value = { [lastSegment]: value };
|
|
1204
|
+
} else {
|
|
1205
|
+
value = [value];
|
|
1206
|
+
}
|
|
1207
|
+
} else {
|
|
1208
|
+
break;
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
if (!parent) {
|
|
1212
|
+
if (value === void 0) {
|
|
1213
|
+
throw new Error("Can not delete in empty document");
|
|
1214
|
+
}
|
|
1215
|
+
return withFormatting(text, { offset: root ? root.offset : 0, length: root ? root.length : 0, content: JSON.stringify(value) }, options);
|
|
1216
|
+
} else if (parent.type === "object" && typeof lastSegment === "string" && Array.isArray(parent.children)) {
|
|
1217
|
+
const existing = findNodeAtLocation(parent, [lastSegment]);
|
|
1218
|
+
if (existing !== void 0) {
|
|
1219
|
+
if (value === void 0) {
|
|
1220
|
+
if (!existing.parent) {
|
|
1221
|
+
throw new Error("Malformed AST");
|
|
1222
|
+
}
|
|
1223
|
+
const propertyIndex = parent.children.indexOf(existing.parent);
|
|
1224
|
+
let removeBegin;
|
|
1225
|
+
let removeEnd = existing.parent.offset + existing.parent.length;
|
|
1226
|
+
if (propertyIndex > 0) {
|
|
1227
|
+
let previous = parent.children[propertyIndex - 1];
|
|
1228
|
+
removeBegin = previous.offset + previous.length;
|
|
1229
|
+
} else {
|
|
1230
|
+
removeBegin = parent.offset + 1;
|
|
1231
|
+
if (parent.children.length > 1) {
|
|
1232
|
+
let next = parent.children[1];
|
|
1233
|
+
removeEnd = next.offset;
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1236
|
+
return withFormatting(text, { offset: removeBegin, length: removeEnd - removeBegin, content: "" }, options);
|
|
1237
|
+
} else {
|
|
1238
|
+
return withFormatting(text, { offset: existing.offset, length: existing.length, content: JSON.stringify(value) }, options);
|
|
1239
|
+
}
|
|
1240
|
+
} else {
|
|
1241
|
+
if (value === void 0) {
|
|
1242
|
+
return [];
|
|
1243
|
+
}
|
|
1244
|
+
const newProperty = `${JSON.stringify(lastSegment)}: ${JSON.stringify(value)}`;
|
|
1245
|
+
const index = options.getInsertionIndex ? options.getInsertionIndex(parent.children.map((p) => p.children[0].value)) : parent.children.length;
|
|
1246
|
+
let edit;
|
|
1247
|
+
if (index > 0) {
|
|
1248
|
+
let previous = parent.children[index - 1];
|
|
1249
|
+
edit = { offset: previous.offset + previous.length, length: 0, content: "," + newProperty };
|
|
1250
|
+
} else if (parent.children.length === 0) {
|
|
1251
|
+
edit = { offset: parent.offset + 1, length: 0, content: newProperty };
|
|
1252
|
+
} else {
|
|
1253
|
+
edit = { offset: parent.offset + 1, length: 0, content: newProperty + "," };
|
|
1254
|
+
}
|
|
1255
|
+
return withFormatting(text, edit, options);
|
|
1256
|
+
}
|
|
1257
|
+
} else if (parent.type === "array" && typeof lastSegment === "number" && Array.isArray(parent.children)) {
|
|
1258
|
+
const insertIndex = lastSegment;
|
|
1259
|
+
if (insertIndex === -1) {
|
|
1260
|
+
const newProperty = `${JSON.stringify(value)}`;
|
|
1261
|
+
let edit;
|
|
1262
|
+
if (parent.children.length === 0) {
|
|
1263
|
+
edit = { offset: parent.offset + 1, length: 0, content: newProperty };
|
|
1264
|
+
} else {
|
|
1265
|
+
const previous = parent.children[parent.children.length - 1];
|
|
1266
|
+
edit = { offset: previous.offset + previous.length, length: 0, content: "," + newProperty };
|
|
1267
|
+
}
|
|
1268
|
+
return withFormatting(text, edit, options);
|
|
1269
|
+
} else if (value === void 0 && parent.children.length >= 0) {
|
|
1270
|
+
const removalIndex = lastSegment;
|
|
1271
|
+
const toRemove = parent.children[removalIndex];
|
|
1272
|
+
let edit;
|
|
1273
|
+
if (parent.children.length === 1) {
|
|
1274
|
+
edit = { offset: parent.offset + 1, length: parent.length - 2, content: "" };
|
|
1275
|
+
} else if (parent.children.length - 1 === removalIndex) {
|
|
1276
|
+
let previous = parent.children[removalIndex - 1];
|
|
1277
|
+
let offset = previous.offset + previous.length;
|
|
1278
|
+
let parentEndOffset = parent.offset + parent.length;
|
|
1279
|
+
edit = { offset, length: parentEndOffset - 2 - offset, content: "" };
|
|
1280
|
+
} else {
|
|
1281
|
+
edit = { offset: toRemove.offset, length: parent.children[removalIndex + 1].offset - toRemove.offset, content: "" };
|
|
1282
|
+
}
|
|
1283
|
+
return withFormatting(text, edit, options);
|
|
1284
|
+
} else if (value !== void 0) {
|
|
1285
|
+
let edit;
|
|
1286
|
+
const newProperty = `${JSON.stringify(value)}`;
|
|
1287
|
+
if (!options.isArrayInsertion && parent.children.length > lastSegment) {
|
|
1288
|
+
const toModify = parent.children[lastSegment];
|
|
1289
|
+
edit = { offset: toModify.offset, length: toModify.length, content: newProperty };
|
|
1290
|
+
} else if (parent.children.length === 0 || lastSegment === 0) {
|
|
1291
|
+
edit = { offset: parent.offset + 1, length: 0, content: parent.children.length === 0 ? newProperty : newProperty + "," };
|
|
1292
|
+
} else {
|
|
1293
|
+
const index = lastSegment > parent.children.length ? parent.children.length : lastSegment;
|
|
1294
|
+
const previous = parent.children[index - 1];
|
|
1295
|
+
edit = { offset: previous.offset + previous.length, length: 0, content: "," + newProperty };
|
|
1296
|
+
}
|
|
1297
|
+
return withFormatting(text, edit, options);
|
|
1298
|
+
} else {
|
|
1299
|
+
throw new Error(`Can not ${value === void 0 ? "remove" : options.isArrayInsertion ? "insert" : "modify"} Array index ${insertIndex} as length is not sufficient`);
|
|
1300
|
+
}
|
|
1301
|
+
} else {
|
|
1302
|
+
throw new Error(`Can not add ${typeof lastSegment !== "number" ? "index" : "property"} to parent of type ${parent.type}`);
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
function withFormatting(text, edit, options) {
|
|
1306
|
+
if (!options.formattingOptions) {
|
|
1307
|
+
return [edit];
|
|
1308
|
+
}
|
|
1309
|
+
let newText = applyEdit(text, edit);
|
|
1310
|
+
let begin = edit.offset;
|
|
1311
|
+
let end = edit.offset + edit.content.length;
|
|
1312
|
+
if (edit.length === 0 || edit.content.length === 0) {
|
|
1313
|
+
while (begin > 0 && !isEOL(newText, begin - 1)) {
|
|
1314
|
+
begin--;
|
|
1315
|
+
}
|
|
1316
|
+
while (end < newText.length && !isEOL(newText, end)) {
|
|
1317
|
+
end++;
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
const edits = format(newText, { offset: begin, length: end - begin }, { ...options.formattingOptions, keepLines: false });
|
|
1321
|
+
for (let i = edits.length - 1; i >= 0; i--) {
|
|
1322
|
+
const edit2 = edits[i];
|
|
1323
|
+
newText = applyEdit(newText, edit2);
|
|
1324
|
+
begin = Math.min(begin, edit2.offset);
|
|
1325
|
+
end = Math.max(end, edit2.offset + edit2.length);
|
|
1326
|
+
end += edit2.content.length - edit2.length;
|
|
1327
|
+
}
|
|
1328
|
+
const editLength = text.length - (newText.length - end) - begin;
|
|
1329
|
+
return [{ offset: begin, length: editLength, content: newText.substring(begin, end) }];
|
|
1330
|
+
}
|
|
1331
|
+
function applyEdit(text, edit) {
|
|
1332
|
+
return text.substring(0, edit.offset) + edit.content + text.substring(edit.offset + edit.length);
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1335
|
+
// node_modules/jsonc-parser/lib/esm/main.js
|
|
1336
|
+
var ScanError;
|
|
1337
|
+
(function(ScanError2) {
|
|
1338
|
+
ScanError2[ScanError2["None"] = 0] = "None";
|
|
1339
|
+
ScanError2[ScanError2["UnexpectedEndOfComment"] = 1] = "UnexpectedEndOfComment";
|
|
1340
|
+
ScanError2[ScanError2["UnexpectedEndOfString"] = 2] = "UnexpectedEndOfString";
|
|
1341
|
+
ScanError2[ScanError2["UnexpectedEndOfNumber"] = 3] = "UnexpectedEndOfNumber";
|
|
1342
|
+
ScanError2[ScanError2["InvalidUnicode"] = 4] = "InvalidUnicode";
|
|
1343
|
+
ScanError2[ScanError2["InvalidEscapeCharacter"] = 5] = "InvalidEscapeCharacter";
|
|
1344
|
+
ScanError2[ScanError2["InvalidCharacter"] = 6] = "InvalidCharacter";
|
|
1345
|
+
})(ScanError || (ScanError = {}));
|
|
1346
|
+
var SyntaxKind;
|
|
1347
|
+
(function(SyntaxKind2) {
|
|
1348
|
+
SyntaxKind2[SyntaxKind2["OpenBraceToken"] = 1] = "OpenBraceToken";
|
|
1349
|
+
SyntaxKind2[SyntaxKind2["CloseBraceToken"] = 2] = "CloseBraceToken";
|
|
1350
|
+
SyntaxKind2[SyntaxKind2["OpenBracketToken"] = 3] = "OpenBracketToken";
|
|
1351
|
+
SyntaxKind2[SyntaxKind2["CloseBracketToken"] = 4] = "CloseBracketToken";
|
|
1352
|
+
SyntaxKind2[SyntaxKind2["CommaToken"] = 5] = "CommaToken";
|
|
1353
|
+
SyntaxKind2[SyntaxKind2["ColonToken"] = 6] = "ColonToken";
|
|
1354
|
+
SyntaxKind2[SyntaxKind2["NullKeyword"] = 7] = "NullKeyword";
|
|
1355
|
+
SyntaxKind2[SyntaxKind2["TrueKeyword"] = 8] = "TrueKeyword";
|
|
1356
|
+
SyntaxKind2[SyntaxKind2["FalseKeyword"] = 9] = "FalseKeyword";
|
|
1357
|
+
SyntaxKind2[SyntaxKind2["StringLiteral"] = 10] = "StringLiteral";
|
|
1358
|
+
SyntaxKind2[SyntaxKind2["NumericLiteral"] = 11] = "NumericLiteral";
|
|
1359
|
+
SyntaxKind2[SyntaxKind2["LineCommentTrivia"] = 12] = "LineCommentTrivia";
|
|
1360
|
+
SyntaxKind2[SyntaxKind2["BlockCommentTrivia"] = 13] = "BlockCommentTrivia";
|
|
1361
|
+
SyntaxKind2[SyntaxKind2["LineBreakTrivia"] = 14] = "LineBreakTrivia";
|
|
1362
|
+
SyntaxKind2[SyntaxKind2["Trivia"] = 15] = "Trivia";
|
|
1363
|
+
SyntaxKind2[SyntaxKind2["Unknown"] = 16] = "Unknown";
|
|
1364
|
+
SyntaxKind2[SyntaxKind2["EOF"] = 17] = "EOF";
|
|
1365
|
+
})(SyntaxKind || (SyntaxKind = {}));
|
|
1366
|
+
var parse2 = parse;
|
|
1367
|
+
var ParseErrorCode;
|
|
1368
|
+
(function(ParseErrorCode2) {
|
|
1369
|
+
ParseErrorCode2[ParseErrorCode2["InvalidSymbol"] = 1] = "InvalidSymbol";
|
|
1370
|
+
ParseErrorCode2[ParseErrorCode2["InvalidNumberFormat"] = 2] = "InvalidNumberFormat";
|
|
1371
|
+
ParseErrorCode2[ParseErrorCode2["PropertyNameExpected"] = 3] = "PropertyNameExpected";
|
|
1372
|
+
ParseErrorCode2[ParseErrorCode2["ValueExpected"] = 4] = "ValueExpected";
|
|
1373
|
+
ParseErrorCode2[ParseErrorCode2["ColonExpected"] = 5] = "ColonExpected";
|
|
1374
|
+
ParseErrorCode2[ParseErrorCode2["CommaExpected"] = 6] = "CommaExpected";
|
|
1375
|
+
ParseErrorCode2[ParseErrorCode2["CloseBraceExpected"] = 7] = "CloseBraceExpected";
|
|
1376
|
+
ParseErrorCode2[ParseErrorCode2["CloseBracketExpected"] = 8] = "CloseBracketExpected";
|
|
1377
|
+
ParseErrorCode2[ParseErrorCode2["EndOfFileExpected"] = 9] = "EndOfFileExpected";
|
|
1378
|
+
ParseErrorCode2[ParseErrorCode2["InvalidCommentToken"] = 10] = "InvalidCommentToken";
|
|
1379
|
+
ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfComment"] = 11] = "UnexpectedEndOfComment";
|
|
1380
|
+
ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfString"] = 12] = "UnexpectedEndOfString";
|
|
1381
|
+
ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfNumber"] = 13] = "UnexpectedEndOfNumber";
|
|
1382
|
+
ParseErrorCode2[ParseErrorCode2["InvalidUnicode"] = 14] = "InvalidUnicode";
|
|
1383
|
+
ParseErrorCode2[ParseErrorCode2["InvalidEscapeCharacter"] = 15] = "InvalidEscapeCharacter";
|
|
1384
|
+
ParseErrorCode2[ParseErrorCode2["InvalidCharacter"] = 16] = "InvalidCharacter";
|
|
1385
|
+
})(ParseErrorCode || (ParseErrorCode = {}));
|
|
1386
|
+
function modify(text, path, value, options) {
|
|
1387
|
+
return setProperty(text, path, value, options);
|
|
1388
|
+
}
|
|
1389
|
+
function applyEdits(text, edits) {
|
|
1390
|
+
let sortedEdits = edits.slice(0).sort((a, b) => {
|
|
1391
|
+
const diff = a.offset - b.offset;
|
|
1392
|
+
if (diff === 0) {
|
|
1393
|
+
return a.length - b.length;
|
|
1394
|
+
}
|
|
1395
|
+
return diff;
|
|
1396
|
+
});
|
|
1397
|
+
let lastModifiedOffset = text.length;
|
|
1398
|
+
for (let i = sortedEdits.length - 1; i >= 0; i--) {
|
|
1399
|
+
let e = sortedEdits[i];
|
|
1400
|
+
if (e.offset + e.length <= lastModifiedOffset) {
|
|
1401
|
+
text = applyEdit(text, e);
|
|
1402
|
+
} else {
|
|
1403
|
+
throw new Error("Overlapping edit");
|
|
1404
|
+
}
|
|
1405
|
+
lastModifiedOffset = e.offset;
|
|
1406
|
+
}
|
|
1407
|
+
return text;
|
|
1408
|
+
}
|
|
1409
|
+
|
|
1410
|
+
// src/daemon/update.ts
|
|
1411
|
+
import { homedir, tmpdir } from "os";
|
|
1412
|
+
import { dirname, join, resolve } from "path";
|
|
1413
|
+
|
|
1414
|
+
// src/core/semver.ts
|
|
1415
|
+
function parseSemanticVersion(version) {
|
|
1416
|
+
const match = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/.exec(version);
|
|
1417
|
+
if (!match) return null;
|
|
1418
|
+
const prerelease = match[4]?.split(".") ?? [];
|
|
1419
|
+
if (prerelease.some((identifier) => /^\d+$/.test(identifier) && identifier.length > 1 && identifier.startsWith("0"))) {
|
|
1420
|
+
return null;
|
|
1421
|
+
}
|
|
1422
|
+
return {
|
|
1423
|
+
major: BigInt(match[1]),
|
|
1424
|
+
minor: BigInt(match[2]),
|
|
1425
|
+
patch: BigInt(match[3]),
|
|
1426
|
+
prerelease
|
|
1427
|
+
};
|
|
1428
|
+
}
|
|
1429
|
+
function compareSemanticVersions(left, right) {
|
|
1430
|
+
const a = parseSemanticVersion(left);
|
|
1431
|
+
const b = parseSemanticVersion(right);
|
|
1432
|
+
if (!a || !b) return null;
|
|
1433
|
+
for (const key of ["major", "minor", "patch"]) {
|
|
1434
|
+
if (a[key] !== b[key]) return a[key] < b[key] ? -1 : 1;
|
|
1435
|
+
}
|
|
1436
|
+
if (a.prerelease.length === 0 || b.prerelease.length === 0) {
|
|
1437
|
+
if (a.prerelease.length === b.prerelease.length) return 0;
|
|
1438
|
+
return a.prerelease.length === 0 ? 1 : -1;
|
|
1439
|
+
}
|
|
1440
|
+
const identifiers = Math.max(a.prerelease.length, b.prerelease.length);
|
|
1441
|
+
for (let index = 0; index < identifiers; index += 1) {
|
|
1442
|
+
const leftIdentifier = a.prerelease[index];
|
|
1443
|
+
const rightIdentifier = b.prerelease[index];
|
|
1444
|
+
if (leftIdentifier === void 0 || rightIdentifier === void 0) {
|
|
1445
|
+
return leftIdentifier === rightIdentifier ? 0 : leftIdentifier === void 0 ? -1 : 1;
|
|
1446
|
+
}
|
|
1447
|
+
if (leftIdentifier === rightIdentifier) continue;
|
|
1448
|
+
const leftNumeric = /^\d+$/.test(leftIdentifier);
|
|
1449
|
+
const rightNumeric = /^\d+$/.test(rightIdentifier);
|
|
1450
|
+
if (leftNumeric && rightNumeric) {
|
|
1451
|
+
const leftBig = BigInt(leftIdentifier);
|
|
1452
|
+
const rightBig = BigInt(rightIdentifier);
|
|
1453
|
+
return leftBig < rightBig ? -1 : leftBig > rightBig ? 1 : 0;
|
|
1454
|
+
}
|
|
1455
|
+
if (leftNumeric !== rightNumeric) return leftNumeric ? -1 : 1;
|
|
1456
|
+
return leftIdentifier < rightIdentifier ? -1 : 1;
|
|
1457
|
+
}
|
|
1458
|
+
return 0;
|
|
1459
|
+
}
|
|
1460
|
+
function isSemanticVersion(version) {
|
|
1461
|
+
return parseSemanticVersion(version) !== null;
|
|
1462
|
+
}
|
|
1463
|
+
|
|
1464
|
+
// src/daemon/update.ts
|
|
1465
|
+
var PACKAGE_NAME = "opencode-supertask";
|
|
1466
|
+
function isVersionConverged(version, state) {
|
|
1467
|
+
return state.packageVersion === version && state.plugin.ok && state.plugin.version === version && state.plugin.cachedVersion === version && (!state.cli.installed || state.cli.version === version) && state.gateway.pm2Installed && state.gateway.processFound && state.gateway.status === "online" && state.gateway.ready && state.gateway.runningVersion === version && state.gateway.gatewayPackageVersion === version && state.gateway.scopeMatches;
|
|
1468
|
+
}
|
|
1469
|
+
function pluginAt(packageDir) {
|
|
1470
|
+
const packageJson = join(packageDir, "package.json");
|
|
1471
|
+
const gatewayEntry = join(packageDir, "dist/gateway/index.js");
|
|
1472
|
+
if (!existsSync(packageJson) || !existsSync(gatewayEntry)) return null;
|
|
1473
|
+
try {
|
|
1474
|
+
const pkg = JSON.parse(readFileSync(packageJson, "utf8"));
|
|
1475
|
+
if (pkg.name !== PACKAGE_NAME || typeof pkg.version !== "string") return null;
|
|
1476
|
+
return { packageDir, gatewayEntry, version: pkg.version };
|
|
1477
|
+
} catch {
|
|
1478
|
+
return null;
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1481
|
+
function compareVersions(left, right) {
|
|
1482
|
+
return compareSemanticVersions(left, right) ?? left.localeCompare(right);
|
|
1483
|
+
}
|
|
1484
|
+
function cacheRoots() {
|
|
1485
|
+
const override = process.env.SUPERTASK_OPENCODE_CACHE_DIR;
|
|
1486
|
+
if (override) return [override];
|
|
1487
|
+
const opencodeCache = join(process.env.XDG_CACHE_HOME || join(homedir(), ".cache"), "opencode");
|
|
1488
|
+
return [join(opencodeCache, "packages"), join(opencodeCache, "npm")];
|
|
1489
|
+
}
|
|
1490
|
+
function subdirectories(directory) {
|
|
1491
|
+
try {
|
|
1492
|
+
return readdirSync(directory, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => join(directory, entry.name));
|
|
1493
|
+
} catch {
|
|
1494
|
+
return [];
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
function installedPlugins() {
|
|
1498
|
+
const packageDirs = cacheRoots().flatMap((root) => subdirectories(root).filter((directory) => {
|
|
1499
|
+
const name = directory.slice(root.length + 1);
|
|
1500
|
+
return name === PACKAGE_NAME || name.startsWith(`${PACKAGE_NAME}@`);
|
|
1501
|
+
}).flatMap((specDirectory) => [
|
|
1502
|
+
join(specDirectory, "node_modules", PACKAGE_NAME),
|
|
1503
|
+
...subdirectories(specDirectory).map((generation) => join(generation, "node_modules", PACKAGE_NAME))
|
|
1504
|
+
]));
|
|
1505
|
+
return packageDirs.map(pluginAt).filter((plugin) => plugin !== null);
|
|
1506
|
+
}
|
|
1507
|
+
function resolveInstalledPlugin() {
|
|
1508
|
+
const override = process.env.SUPERTASK_PLUGIN_PACKAGE_DIR;
|
|
1509
|
+
if (override) {
|
|
1510
|
+
const plugin = pluginAt(override);
|
|
1511
|
+
if (!plugin) throw new Error(`[supertask] \u5B89\u88C5\u5305\u65E0\u6548\u6216\u7F3A\u5C11 Gateway \u6784\u5EFA\u4EA7\u7269: ${override}`);
|
|
1512
|
+
return plugin;
|
|
1513
|
+
}
|
|
1514
|
+
const installed = installedPlugins().sort((left, right) => compareVersions(right.version, left.version));
|
|
1515
|
+
if (!installed[0]) {
|
|
1516
|
+
throw new Error(`[supertask] OpenCode \u63D2\u4EF6\u7F13\u5B58\u4E2D\u627E\u4E0D\u5230\u53EF\u8FD0\u884C\u7684 ${PACKAGE_NAME}`);
|
|
1517
|
+
}
|
|
1518
|
+
return installed[0];
|
|
1519
|
+
}
|
|
1520
|
+
function opencodeBin() {
|
|
1521
|
+
return openCodeExecutable();
|
|
1522
|
+
}
|
|
1523
|
+
function npmBin() {
|
|
1524
|
+
return process.env.SUPERTASK_NPM_BIN ?? "npm";
|
|
1525
|
+
}
|
|
1526
|
+
function bunBin() {
|
|
1527
|
+
return process.env.SUPERTASK_BUN_BIN ?? "bun";
|
|
1528
|
+
}
|
|
1529
|
+
function resolveGlobalCliExecutable() {
|
|
1530
|
+
const override = process.env.SUPERTASK_CLI_BIN;
|
|
1531
|
+
if (override) return existsSync(override) ? resolve(override) : null;
|
|
1532
|
+
const result = spawnSync(process.platform === "win32" ? "where" : "which", ["supertask"], {
|
|
1533
|
+
encoding: "utf8",
|
|
1534
|
+
env: process.env,
|
|
1535
|
+
timeout: 1e4
|
|
1536
|
+
});
|
|
1537
|
+
if (result.status !== 0) return null;
|
|
1538
|
+
const executable = `${result.stdout ?? ""}`.trim().split(/\r?\n/)[0];
|
|
1539
|
+
return executable && existsSync(executable) ? resolve(executable) : null;
|
|
1540
|
+
}
|
|
1541
|
+
function cliPackageDir(executable) {
|
|
1542
|
+
try {
|
|
1543
|
+
let directory = dirname(realpathSync(executable));
|
|
1544
|
+
for (let depth = 0; depth < 6; depth += 1) {
|
|
1545
|
+
const packagePath = join(directory, "package.json");
|
|
1546
|
+
if (existsSync(packagePath)) {
|
|
1547
|
+
const pkg = JSON.parse(readFileSync(packagePath, "utf8"));
|
|
1548
|
+
if (pkg.name === PACKAGE_NAME) return directory;
|
|
1549
|
+
}
|
|
1550
|
+
const parent = dirname(directory);
|
|
1551
|
+
if (parent === directory) break;
|
|
1552
|
+
directory = parent;
|
|
1553
|
+
}
|
|
1554
|
+
} catch {
|
|
1555
|
+
}
|
|
1556
|
+
return null;
|
|
1557
|
+
}
|
|
1558
|
+
function packageVersion(packageDir) {
|
|
1559
|
+
try {
|
|
1560
|
+
const pkg = JSON.parse(readFileSync(join(packageDir, "package.json"), "utf8"));
|
|
1561
|
+
return pkg.name === PACKAGE_NAME && typeof pkg.version === "string" ? pkg.version : null;
|
|
1562
|
+
} catch {
|
|
1563
|
+
return null;
|
|
1564
|
+
}
|
|
1565
|
+
}
|
|
1566
|
+
function npmGlobalRoot() {
|
|
1567
|
+
const result = spawnSync(npmBin(), ["root", "-g"], {
|
|
1568
|
+
encoding: "utf8",
|
|
1569
|
+
env: process.env,
|
|
1570
|
+
timeout: 3e4
|
|
1571
|
+
});
|
|
1572
|
+
if (result.status !== 0) return null;
|
|
1573
|
+
const root = `${result.stdout ?? ""}`.trim();
|
|
1574
|
+
if (!root) return null;
|
|
1575
|
+
try {
|
|
1576
|
+
return realpathSync(root);
|
|
1577
|
+
} catch {
|
|
1578
|
+
return resolve(root);
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
function globalCliPackageManager(packageDir) {
|
|
1582
|
+
const normalized = packageDir.replaceAll("\\", "/");
|
|
1583
|
+
if (normalized.includes("/install/global/node_modules/")) return "bun";
|
|
1584
|
+
const npmRoot = npmGlobalRoot();
|
|
1585
|
+
if (npmRoot && resolve(packageDir) === join(npmRoot, PACKAGE_NAME)) return "npm";
|
|
1586
|
+
return null;
|
|
1587
|
+
}
|
|
1588
|
+
function getGlobalCliDiagnostic() {
|
|
1589
|
+
const executable = resolveGlobalCliExecutable();
|
|
1590
|
+
if (!executable) {
|
|
1591
|
+
return {
|
|
1592
|
+
installed: false,
|
|
1593
|
+
executable: null,
|
|
1594
|
+
packageDir: null,
|
|
1595
|
+
version: null,
|
|
1596
|
+
packageManager: null
|
|
1597
|
+
};
|
|
1598
|
+
}
|
|
1599
|
+
const packageDir = cliPackageDir(executable);
|
|
1600
|
+
if (!packageDir) {
|
|
1601
|
+
return {
|
|
1602
|
+
installed: true,
|
|
1603
|
+
executable,
|
|
1604
|
+
packageDir: null,
|
|
1605
|
+
version: null,
|
|
1606
|
+
packageManager: null
|
|
1607
|
+
};
|
|
1608
|
+
}
|
|
1609
|
+
return {
|
|
1610
|
+
installed: true,
|
|
1611
|
+
executable,
|
|
1612
|
+
packageDir,
|
|
1613
|
+
version: packageVersion(packageDir),
|
|
1614
|
+
packageManager: globalCliPackageManager(packageDir)
|
|
1615
|
+
};
|
|
1616
|
+
}
|
|
1617
|
+
function updateGlobalCli(version) {
|
|
1618
|
+
if (!isSemanticVersion(version)) {
|
|
1619
|
+
throw new Error(`[supertask] \u5168\u5C40 CLI \u76EE\u6807\u7248\u672C\u65E0\u6548: ${version}`);
|
|
1620
|
+
}
|
|
1621
|
+
const before = getGlobalCliDiagnostic();
|
|
1622
|
+
if (!before.installed) return { ...before, action: "not-installed" };
|
|
1623
|
+
if (before.version === version) return { ...before, action: "already-current" };
|
|
1624
|
+
if (!before.packageManager) {
|
|
1625
|
+
throw new Error(
|
|
1626
|
+
`[supertask] \u65E0\u6CD5\u786E\u8BA4\u5168\u5C40 CLI \u7684\u5305\u7BA1\u7406\u5668\uFF08\u5F53\u524D ${before.version ?? "unknown"}\uFF0C\u76EE\u6807 ${version}\uFF09\uFF1B\u8BF7\u6267\u884C npm install -g ${PACKAGE_NAME}@${version} \u6216 bun add -g ${PACKAGE_NAME}@${version}`
|
|
1627
|
+
);
|
|
1628
|
+
}
|
|
1629
|
+
const command = before.packageManager === "npm" ? npmBin() : bunBin();
|
|
1630
|
+
const args = before.packageManager === "npm" ? ["install", "-g", `${PACKAGE_NAME}@${version}`] : ["add", "-g", `${PACKAGE_NAME}@${version}`];
|
|
1631
|
+
const result = spawnSync(command, args, {
|
|
1632
|
+
encoding: "utf8",
|
|
1633
|
+
env: process.env,
|
|
1634
|
+
timeout: 12e4
|
|
1635
|
+
});
|
|
1636
|
+
const output = `${result.stdout ?? ""}${result.stderr ?? ""}`.trim();
|
|
1637
|
+
if (result.error) {
|
|
1638
|
+
throw new Error(`[supertask] \u5168\u5C40 CLI \u66F4\u65B0\u5931\u8D25: ${result.error.message}`);
|
|
1639
|
+
}
|
|
1640
|
+
if (result.status !== 0) {
|
|
1641
|
+
throw new Error(`[supertask] \u5168\u5C40 CLI \u66F4\u65B0\u5931\u8D25: ${output || `\u9000\u51FA\u7801 ${result.status}`}`);
|
|
1642
|
+
}
|
|
1643
|
+
const after = getGlobalCliDiagnostic();
|
|
1644
|
+
if (after.version !== version) {
|
|
1645
|
+
throw new Error(
|
|
1646
|
+
`[supertask] \u5168\u5C40 CLI \u66F4\u65B0\u540E\u7248\u672C\u4E0D\u5339\u914D\uFF1A\u671F\u671B ${version}\uFF0C\u5B9E\u9645 ${after.version ?? "unknown"}`
|
|
1647
|
+
);
|
|
1648
|
+
}
|
|
1649
|
+
return { ...after, action: "updated" };
|
|
1650
|
+
}
|
|
1651
|
+
function getLatestVersion() {
|
|
1652
|
+
const result = spawnSync(npmBin(), [
|
|
1653
|
+
"view",
|
|
1654
|
+
PACKAGE_NAME,
|
|
1655
|
+
"dist-tags.latest",
|
|
1656
|
+
"--json"
|
|
1657
|
+
], {
|
|
1658
|
+
encoding: "utf8",
|
|
1659
|
+
env: process.env,
|
|
1660
|
+
timeout: 3e4
|
|
1661
|
+
});
|
|
1662
|
+
const output = `${result.stdout ?? ""}`.trim();
|
|
1663
|
+
if (result.error) {
|
|
1664
|
+
throw new Error(`[supertask] \u67E5\u8BE2 npm latest \u5931\u8D25: ${result.error.message}`);
|
|
1665
|
+
}
|
|
1666
|
+
if (result.status !== 0) {
|
|
1667
|
+
const detail = `${result.stderr ?? ""}`.trim();
|
|
1668
|
+
throw new Error(`[supertask] \u67E5\u8BE2 npm latest \u5931\u8D25: ${detail || `\u9000\u51FA\u7801 ${result.status}`}`);
|
|
1669
|
+
}
|
|
1670
|
+
let response;
|
|
1671
|
+
try {
|
|
1672
|
+
response = JSON.parse(output);
|
|
1673
|
+
} catch {
|
|
1674
|
+
throw new Error(`[supertask] npm latest \u8FD4\u56DE\u65E0\u6CD5\u89E3\u6790: ${output || "(empty)"}`);
|
|
1675
|
+
}
|
|
1676
|
+
const versions = typeof response === "string" ? [response] : Array.isArray(response) && response.every((value) => typeof value === "string") ? response : [];
|
|
1677
|
+
const uniqueVersions = [...new Set(versions)];
|
|
1678
|
+
if (uniqueVersions.length !== 1 || !isSemanticVersion(uniqueVersions[0])) {
|
|
1679
|
+
throw new Error(`[supertask] npm latest \u7248\u672C\u65E0\u6548: ${String(response)}`);
|
|
1680
|
+
}
|
|
1681
|
+
return uniqueVersions[0];
|
|
1682
|
+
}
|
|
1683
|
+
function resolveInstalledPluginVersion(expectedVersion) {
|
|
1684
|
+
const override = process.env.SUPERTASK_PLUGIN_PACKAGE_DIR;
|
|
1685
|
+
const installed = override ? [pluginAt(override)].filter((plugin) => plugin !== null) : installedPlugins();
|
|
1686
|
+
const matched = installed.find((plugin) => plugin.version === expectedVersion);
|
|
1687
|
+
if (matched) return matched;
|
|
1688
|
+
const actual = installed.length > 0 ? installed.map((plugin) => plugin.version).join(", ") : "\u672A\u627E\u5230\u53EF\u8FD0\u884C\u7F13\u5B58";
|
|
1689
|
+
throw new Error(`[supertask] OpenCode \u63D2\u4EF6\u7F13\u5B58\u7248\u672C\u4E0D\u5339\u914D\uFF1A\u671F\u671B ${expectedVersion}\uFF0C\u5B9E\u9645 ${actual}`);
|
|
1690
|
+
}
|
|
1691
|
+
function pluginEntrySpec(entry) {
|
|
1692
|
+
if (typeof entry === "string") return entry;
|
|
1693
|
+
if (Array.isArray(entry) && typeof entry[0] === "string") return entry[0];
|
|
1694
|
+
if (entry !== null && typeof entry === "object" && typeof entry.package === "string") {
|
|
1695
|
+
return entry.package;
|
|
1696
|
+
}
|
|
1697
|
+
return null;
|
|
1698
|
+
}
|
|
1699
|
+
function mergeOpenCodeV2PluginConfig(value) {
|
|
1700
|
+
if (!Array.isArray(value)) throw new Error("[supertask] OpenCode 2.x \u914D\u7F6E\u6765\u6E90\u4E0D\u662F\u6570\u7EC4");
|
|
1701
|
+
const merged = [];
|
|
1702
|
+
for (const entry of value) {
|
|
1703
|
+
if (entry === null || typeof entry !== "object" || entry.type !== "document") continue;
|
|
1704
|
+
const info = entry.info;
|
|
1705
|
+
if (info === null || typeof info !== "object") continue;
|
|
1706
|
+
const record = info;
|
|
1707
|
+
for (const key of ["plugin", "plugins"]) {
|
|
1708
|
+
const list = record[key];
|
|
1709
|
+
if (!Array.isArray(list)) continue;
|
|
1710
|
+
for (const spec of list.map(pluginEntrySpec)) {
|
|
1711
|
+
if (spec === null) continue;
|
|
1712
|
+
if (spec.startsWith("-")) {
|
|
1713
|
+
const target = spec.slice(1);
|
|
1714
|
+
for (let index = merged.length - 1; index >= 0; index -= 1) {
|
|
1715
|
+
if (merged[index] === target) merged.splice(index, 1);
|
|
1716
|
+
}
|
|
1717
|
+
continue;
|
|
1718
|
+
}
|
|
1719
|
+
if (!merged.includes(spec)) merged.push(spec);
|
|
1720
|
+
}
|
|
1721
|
+
}
|
|
1722
|
+
}
|
|
1723
|
+
return { plugin: merged };
|
|
1724
|
+
}
|
|
1725
|
+
function resolveConfiguredPluginSpec(value) {
|
|
1726
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
1727
|
+
throw new Error("[supertask] OpenCode \u6700\u7EC8\u914D\u7F6E\u4E0D\u662F\u5BF9\u8C61");
|
|
1728
|
+
}
|
|
1729
|
+
const plugins = value.plugin;
|
|
1730
|
+
if (!Array.isArray(plugins)) {
|
|
1731
|
+
throw new Error(`[supertask] OpenCode \u6700\u7EC8\u914D\u7F6E\u672A\u542F\u7528 ${PACKAGE_NAME}`);
|
|
1732
|
+
}
|
|
1733
|
+
const matches = plugins.map(pluginEntrySpec).filter((spec2) => spec2 !== null).filter((spec2) => spec2 === PACKAGE_NAME || spec2.startsWith(`${PACKAGE_NAME}@`));
|
|
1734
|
+
if (matches.length === 0) {
|
|
1735
|
+
throw new Error(`[supertask] OpenCode \u6700\u7EC8\u914D\u7F6E\u672A\u542F\u7528 ${PACKAGE_NAME}`);
|
|
1736
|
+
}
|
|
1737
|
+
if (matches.length !== 1) {
|
|
1738
|
+
throw new Error(`[supertask] OpenCode \u6700\u7EC8\u914D\u7F6E\u5305\u542B\u591A\u4E2A ${PACKAGE_NAME} \u58F0\u660E: ${matches.join(", ")}`);
|
|
1739
|
+
}
|
|
1740
|
+
const spec = matches[0];
|
|
1741
|
+
const version = spec.startsWith(`${PACKAGE_NAME}@`) ? spec.slice(PACKAGE_NAME.length + 1) : null;
|
|
1742
|
+
return {
|
|
1743
|
+
spec,
|
|
1744
|
+
version: version !== null && isSemanticVersion(version) ? version : null,
|
|
1745
|
+
exact: version !== null && isSemanticVersion(version)
|
|
1746
|
+
};
|
|
1747
|
+
}
|
|
1748
|
+
function getOpenCodePluginDiagnostic() {
|
|
1749
|
+
const failed = (message) => ({
|
|
1750
|
+
ok: false,
|
|
1751
|
+
spec: "",
|
|
1752
|
+
version: null,
|
|
1753
|
+
exact: false,
|
|
1754
|
+
cachedVersion: null,
|
|
1755
|
+
packageDir: null,
|
|
1756
|
+
error: message
|
|
1757
|
+
});
|
|
1758
|
+
let outputDirectory = null;
|
|
1759
|
+
let outputFd = null;
|
|
1760
|
+
try {
|
|
1761
|
+
const openCode = detectOpenCodeVersionSync(opencodeBin());
|
|
1762
|
+
outputDirectory = mkdtempSync(join(tmpdir(), "opencode-supertask-config-"));
|
|
1763
|
+
chmodSync(outputDirectory, 448);
|
|
1764
|
+
const outputPath = join(outputDirectory, "resolved-config.json");
|
|
1765
|
+
outputFd = openSync(outputPath, "w", 384);
|
|
1766
|
+
const args = openCode.major === 2 ? ["debug", "config"] : ["debug", "config", "--pure"];
|
|
1767
|
+
const result = spawnSync(opencodeBin(), args, {
|
|
1768
|
+
encoding: "utf8",
|
|
1769
|
+
env: process.env,
|
|
1770
|
+
timeout: 3e4,
|
|
1771
|
+
stdio: ["ignore", outputFd, "pipe"]
|
|
1772
|
+
});
|
|
1773
|
+
closeSync(outputFd);
|
|
1774
|
+
outputFd = null;
|
|
1775
|
+
if (result.error) {
|
|
1776
|
+
return failed(`[supertask] \u65E0\u6CD5\u8BFB\u53D6 OpenCode \u6700\u7EC8\u914D\u7F6E: ${result.error.message}`);
|
|
1777
|
+
}
|
|
1778
|
+
if (result.status !== 0) {
|
|
1779
|
+
const detail = `${result.stderr ?? ""}`.trim();
|
|
1780
|
+
return failed(`[supertask] \u65E0\u6CD5\u8BFB\u53D6 OpenCode \u6700\u7EC8\u914D\u7F6E: ${detail || `\u9000\u51FA\u7801 ${result.status}`}`);
|
|
1781
|
+
}
|
|
1782
|
+
let config;
|
|
1783
|
+
try {
|
|
1784
|
+
config = JSON.parse(readFileSync(outputPath, "utf8"));
|
|
1785
|
+
} catch {
|
|
1786
|
+
return failed("[supertask] OpenCode \u6700\u7EC8\u914D\u7F6E\u4E0D\u662F\u6709\u6548 JSON");
|
|
1787
|
+
}
|
|
1788
|
+
let configured;
|
|
1789
|
+
try {
|
|
1790
|
+
configured = resolveConfiguredPluginSpec(
|
|
1791
|
+
openCode.major === 2 ? mergeOpenCodeV2PluginConfig(config) : config
|
|
1792
|
+
);
|
|
1793
|
+
} catch (error) {
|
|
1794
|
+
return failed(error instanceof Error ? error.message : String(error));
|
|
1795
|
+
}
|
|
1796
|
+
if (!configured.exact || configured.version === null) {
|
|
1797
|
+
return {
|
|
1798
|
+
ok: false,
|
|
1799
|
+
...configured,
|
|
1800
|
+
cachedVersion: null,
|
|
1801
|
+
packageDir: null,
|
|
1802
|
+
error: `[supertask] OpenCode \u63D2\u4EF6\u5FC5\u987B\u56FA\u5B9A\u7CBE\u786E\u7248\u672C\uFF0C\u4E0D\u80FD\u4F7F\u7528 ${configured.spec}`
|
|
1803
|
+
};
|
|
1804
|
+
}
|
|
1805
|
+
try {
|
|
1806
|
+
const installed = resolveInstalledPluginVersion(configured.version);
|
|
1807
|
+
return {
|
|
1808
|
+
ok: true,
|
|
1809
|
+
...configured,
|
|
1810
|
+
cachedVersion: installed.version,
|
|
1811
|
+
packageDir: installed.packageDir,
|
|
1812
|
+
error: null
|
|
1813
|
+
};
|
|
1814
|
+
} catch (error) {
|
|
1815
|
+
return {
|
|
1816
|
+
ok: false,
|
|
1817
|
+
...configured,
|
|
1818
|
+
cachedVersion: null,
|
|
1819
|
+
packageDir: null,
|
|
1820
|
+
error: error instanceof Error ? error.message : String(error)
|
|
1821
|
+
};
|
|
1822
|
+
}
|
|
1823
|
+
} catch (error) {
|
|
1824
|
+
return failed(`[supertask] \u65E0\u6CD5\u8BFB\u53D6 OpenCode \u6700\u7EC8\u914D\u7F6E: ${error instanceof Error ? error.message : String(error)}`);
|
|
1825
|
+
} finally {
|
|
1826
|
+
if (outputFd !== null) {
|
|
1827
|
+
try {
|
|
1828
|
+
closeSync(outputFd);
|
|
1829
|
+
} catch {
|
|
1830
|
+
}
|
|
1831
|
+
}
|
|
1832
|
+
if (outputDirectory !== null) rmSync(outputDirectory, { recursive: true, force: true });
|
|
1833
|
+
}
|
|
1834
|
+
}
|
|
1835
|
+
function isSuperTaskPluginEntry(entry) {
|
|
1836
|
+
const spec = pluginEntrySpec(entry);
|
|
1837
|
+
return spec === PACKAGE_NAME || (spec?.startsWith(`${PACKAGE_NAME}@`) ?? false);
|
|
1838
|
+
}
|
|
1839
|
+
function openCodeGlobalConfigPath() {
|
|
1840
|
+
const directory = process.env.OPENCODE_CONFIG_DIR ?? join(process.env.XDG_CONFIG_HOME || join(homedir(), ".config"), "opencode");
|
|
1841
|
+
const candidates = ["opencode.json", "opencode.jsonc", ".opencode/opencode.json", ".opencode/opencode.jsonc"].map((name) => join(directory, name));
|
|
1842
|
+
return candidates.find((candidate) => existsSync(candidate)) ?? candidates[0];
|
|
1843
|
+
}
|
|
1844
|
+
function pinPluginInGlobalConfig(configPath, spec) {
|
|
1845
|
+
const original = existsSync(configPath) ? readFileSync(configPath, "utf8") : "{}";
|
|
1846
|
+
const errors = [];
|
|
1847
|
+
const config = parse2(original, errors, { allowTrailingComma: true });
|
|
1848
|
+
if (errors.length > 0 || config === null || typeof config !== "object" || Array.isArray(config)) {
|
|
1849
|
+
throw new Error(`[supertask] OpenCode \u5168\u5C40\u914D\u7F6E\u4E0D\u662F\u6709\u6548 JSON \u5BF9\u8C61: ${configPath}`);
|
|
1850
|
+
}
|
|
1851
|
+
const record = config;
|
|
1852
|
+
const targetKey = Array.isArray(record.plugin) ? "plugin" : "plugins";
|
|
1853
|
+
let replacement = spec;
|
|
1854
|
+
for (const key of ["plugin", "plugins"]) {
|
|
1855
|
+
const list = record[key];
|
|
1856
|
+
const existing = Array.isArray(list) ? list.find(isSuperTaskPluginEntry) : void 0;
|
|
1857
|
+
if (existing === void 0) continue;
|
|
1858
|
+
if (Array.isArray(existing)) replacement = [spec, ...existing.slice(1)];
|
|
1859
|
+
else if (existing !== null && typeof existing === "object") replacement = { ...existing, package: spec };
|
|
1860
|
+
break;
|
|
1861
|
+
}
|
|
1862
|
+
let text = original;
|
|
1863
|
+
for (const key of ["plugin", "plugins"]) {
|
|
1864
|
+
const list = Array.isArray(record[key]) ? record[key] : void 0;
|
|
1865
|
+
if (key !== targetKey && (list === void 0 || !list.some(isSuperTaskPluginEntry))) continue;
|
|
1866
|
+
const current = list ?? [];
|
|
1867
|
+
let next = current.filter((entry) => !isSuperTaskPluginEntry(entry));
|
|
1868
|
+
if (key === targetKey) {
|
|
1869
|
+
const position = current.findIndex(isSuperTaskPluginEntry);
|
|
1870
|
+
next = [...next];
|
|
1871
|
+
next.splice(position < 0 ? next.length : Math.min(position, next.length), 0, replacement);
|
|
1872
|
+
}
|
|
1873
|
+
text = applyEdits(text, modify(text, [key], next, {
|
|
1874
|
+
formattingOptions: { tabSize: 2, insertSpaces: true }
|
|
1875
|
+
}));
|
|
1876
|
+
}
|
|
1877
|
+
if (text === original) return;
|
|
1878
|
+
mkdirSync(dirname(configPath), { recursive: true });
|
|
1879
|
+
const temporary = `${configPath}.supertask-${process.pid}.tmp`;
|
|
1880
|
+
writeFileSync(temporary, text.endsWith("\n") ? text : `${text}
|
|
1881
|
+
`, { mode: 384 });
|
|
1882
|
+
renameSync(temporary, configPath);
|
|
1883
|
+
}
|
|
1884
|
+
function installPluginVersion(version) {
|
|
1885
|
+
if (!isSemanticVersion(version)) {
|
|
1886
|
+
throw new Error(`[supertask] OpenCode \u63D2\u4EF6\u7248\u672C\u65E0\u6548: ${version}`);
|
|
1887
|
+
}
|
|
1888
|
+
const spec = `${PACKAGE_NAME}@${version}`;
|
|
1889
|
+
const major = detectOpenCodeVersionSync(opencodeBin()).major;
|
|
1890
|
+
const result = spawnSync(opencodeBin(), major === 2 ? ["plugin", "add", spec] : ["plugin", spec, "--global", "--force"], {
|
|
1891
|
+
encoding: "utf8",
|
|
1892
|
+
env: process.env,
|
|
1893
|
+
timeout: 12e4
|
|
1894
|
+
});
|
|
1895
|
+
const output = `${result.stdout ?? ""}${result.stderr ?? ""}`.trim();
|
|
1896
|
+
if (result.error) {
|
|
1897
|
+
throw new Error(`[supertask] OpenCode \u63D2\u4EF6\u66F4\u65B0\u5931\u8D25: ${result.error.message}`);
|
|
1898
|
+
}
|
|
1899
|
+
if (result.status !== 0) {
|
|
1900
|
+
throw new Error(`[supertask] OpenCode \u63D2\u4EF6\u66F4\u65B0\u5931\u8D25: ${output || `\u9000\u51FA\u7801 ${result.status}`}`);
|
|
1901
|
+
}
|
|
1902
|
+
if (major === 2) pinPluginInGlobalConfig(openCodeGlobalConfigPath(), spec);
|
|
1903
|
+
return resolveInstalledPluginVersion(version);
|
|
1904
|
+
}
|
|
1905
|
+
function installLatestPlugin() {
|
|
1906
|
+
return installPluginVersion(getLatestVersion());
|
|
1907
|
+
}
|
|
1908
|
+
function errorMessage(error) {
|
|
1909
|
+
return error instanceof Error ? error.message : String(error);
|
|
1910
|
+
}
|
|
1911
|
+
var DEFAULT_UPGRADE_DEPS = {
|
|
1912
|
+
isManagedRun: () => process.env[MANAGED_RUN_ENV] === MANAGED_RUN_ENV_VALUE,
|
|
1913
|
+
getPackageVersion,
|
|
1914
|
+
getLatestVersion,
|
|
1915
|
+
getOpenCodePluginDiagnostic,
|
|
1916
|
+
getGlobalCliDiagnostic,
|
|
1917
|
+
getGatewayDiagnostic: () => getGatewayDiagnostic(),
|
|
1918
|
+
resolveInstalledPlugin,
|
|
1919
|
+
installPluginVersion,
|
|
1920
|
+
upgradeGateway: upgrade,
|
|
1921
|
+
updateGlobalCli
|
|
1922
|
+
};
|
|
1923
|
+
function executeUpgrade(options = {}) {
|
|
1924
|
+
const deps = { ...DEFAULT_UPGRADE_DEPS, ...options.deps };
|
|
1925
|
+
if (deps.isManagedRun()) {
|
|
1926
|
+
return {
|
|
1927
|
+
status: "blocked",
|
|
1928
|
+
reason: "managed-run",
|
|
1929
|
+
error: "Gateway \u7BA1\u7406\u7684\u961F\u5217\u4EFB\u52A1\u4E0D\u80FD\u5347\u7EA7 SuperTask\uFF0C\u5426\u5219\u4F1A\u7EC8\u6B62\u627F\u8F7D\u5F53\u524D\u4EFB\u52A1\u7684 Gateway\u3002"
|
|
1930
|
+
};
|
|
1931
|
+
}
|
|
1932
|
+
options.onStage?.("checking");
|
|
1933
|
+
let targetVersion = null;
|
|
1934
|
+
let previousVersion;
|
|
1935
|
+
try {
|
|
1936
|
+
targetVersion = deps.getLatestVersion();
|
|
1937
|
+
const plugin = deps.getOpenCodePluginDiagnostic();
|
|
1938
|
+
const cli = deps.getGlobalCliDiagnostic();
|
|
1939
|
+
const gateway = deps.getGatewayDiagnostic();
|
|
1940
|
+
const currentPackageVersion = options.packageVersion ?? deps.getPackageVersion();
|
|
1941
|
+
if (!options.force && isVersionConverged(targetVersion, {
|
|
1942
|
+
packageVersion: currentPackageVersion,
|
|
1943
|
+
plugin,
|
|
1944
|
+
cli,
|
|
1945
|
+
gateway
|
|
1946
|
+
})) {
|
|
1947
|
+
return {
|
|
1948
|
+
status: "up-to-date",
|
|
1949
|
+
targetVersion,
|
|
1950
|
+
before: targetVersion,
|
|
1951
|
+
after: targetVersion,
|
|
1952
|
+
restarted: false,
|
|
1953
|
+
cli
|
|
1954
|
+
};
|
|
1955
|
+
}
|
|
1956
|
+
previousVersion = plugin.version ?? options.fallbackPreviousVersion ?? deps.resolveInstalledPlugin().version;
|
|
1957
|
+
} catch (error) {
|
|
1958
|
+
return {
|
|
1959
|
+
status: "failed",
|
|
1960
|
+
phase: "preflight",
|
|
1961
|
+
targetVersion,
|
|
1962
|
+
previousVersion: null,
|
|
1963
|
+
error: errorMessage(error),
|
|
1964
|
+
pluginRolledBack: false,
|
|
1965
|
+
pluginRollbackError: null
|
|
1966
|
+
};
|
|
1967
|
+
}
|
|
1968
|
+
options.onStage?.("installing-plugin", { targetVersion });
|
|
1969
|
+
let installed;
|
|
1970
|
+
try {
|
|
1971
|
+
installed = deps.installPluginVersion(targetVersion);
|
|
1972
|
+
} catch (error) {
|
|
1973
|
+
let detail = errorMessage(error);
|
|
1974
|
+
let pluginRolledBack = false;
|
|
1975
|
+
let pluginRollbackError = null;
|
|
1976
|
+
try {
|
|
1977
|
+
deps.installPluginVersion(previousVersion);
|
|
1978
|
+
pluginRolledBack = true;
|
|
1979
|
+
} catch (rollbackError) {
|
|
1980
|
+
pluginRollbackError = errorMessage(rollbackError);
|
|
1981
|
+
detail += `; OpenCode \u63D2\u4EF6\u56DE\u6EDA\u5931\u8D25: ${pluginRollbackError}`;
|
|
1982
|
+
}
|
|
1983
|
+
return {
|
|
1984
|
+
status: "failed",
|
|
1985
|
+
phase: "plugin-install",
|
|
1986
|
+
targetVersion,
|
|
1987
|
+
previousVersion,
|
|
1988
|
+
error: detail,
|
|
1989
|
+
pluginRolledBack,
|
|
1990
|
+
pluginRollbackError
|
|
1991
|
+
};
|
|
1992
|
+
}
|
|
1993
|
+
options.onStage?.("restarting-gateway", { targetVersion: installed.version });
|
|
1994
|
+
let gatewayResult;
|
|
1995
|
+
try {
|
|
1996
|
+
gatewayResult = deps.upgradeGateway(installed);
|
|
1997
|
+
} catch (error) {
|
|
1998
|
+
let detail = errorMessage(error);
|
|
1999
|
+
let pluginRolledBack = false;
|
|
2000
|
+
let pluginRollbackError = null;
|
|
2001
|
+
if (previousVersion !== installed.version) {
|
|
2002
|
+
try {
|
|
2003
|
+
deps.installPluginVersion(previousVersion);
|
|
2004
|
+
pluginRolledBack = true;
|
|
2005
|
+
} catch (rollbackError) {
|
|
2006
|
+
pluginRollbackError = errorMessage(rollbackError);
|
|
2007
|
+
detail += `; OpenCode \u63D2\u4EF6\u56DE\u6EDA\u5931\u8D25: ${pluginRollbackError}`;
|
|
2008
|
+
}
|
|
2009
|
+
}
|
|
2010
|
+
return {
|
|
2011
|
+
status: "failed",
|
|
2012
|
+
phase: "gateway-restart",
|
|
2013
|
+
targetVersion,
|
|
2014
|
+
previousVersion,
|
|
2015
|
+
error: detail,
|
|
2016
|
+
pluginRolledBack,
|
|
2017
|
+
pluginRollbackError
|
|
2018
|
+
};
|
|
2019
|
+
}
|
|
2020
|
+
options.onStage?.("updating-cli", { targetVersion: gatewayResult.after });
|
|
2021
|
+
try {
|
|
2022
|
+
const cli = deps.updateGlobalCli(gatewayResult.after);
|
|
2023
|
+
return {
|
|
2024
|
+
status: "upgraded",
|
|
2025
|
+
targetVersion,
|
|
2026
|
+
before: gatewayResult.before,
|
|
2027
|
+
after: gatewayResult.after,
|
|
2028
|
+
restarted: gatewayResult.restarted,
|
|
2029
|
+
cli
|
|
2030
|
+
};
|
|
2031
|
+
} catch (cliError) {
|
|
2032
|
+
return {
|
|
2033
|
+
status: "partial",
|
|
2034
|
+
targetVersion,
|
|
2035
|
+
before: gatewayResult.before,
|
|
2036
|
+
after: gatewayResult.after,
|
|
2037
|
+
restarted: gatewayResult.restarted,
|
|
2038
|
+
cliError: errorMessage(cliError)
|
|
2039
|
+
};
|
|
2040
|
+
}
|
|
2041
|
+
}
|
|
2042
|
+
export {
|
|
2043
|
+
executeUpgrade,
|
|
2044
|
+
getGlobalCliDiagnostic,
|
|
2045
|
+
getLatestVersion,
|
|
2046
|
+
getOpenCodePluginDiagnostic,
|
|
2047
|
+
installLatestPlugin,
|
|
2048
|
+
installPluginVersion,
|
|
2049
|
+
isVersionConverged,
|
|
2050
|
+
mergeOpenCodeV2PluginConfig,
|
|
2051
|
+
openCodeGlobalConfigPath,
|
|
2052
|
+
pinPluginInGlobalConfig,
|
|
2053
|
+
resolveConfiguredPluginSpec,
|
|
2054
|
+
resolveInstalledPlugin,
|
|
2055
|
+
resolveInstalledPluginVersion,
|
|
2056
|
+
updateGlobalCli
|
|
2057
|
+
};
|
|
2058
|
+
//# sourceMappingURL=update-FYD546I2.js.map
|