@srobroek/pi-dep-update 0.0.0-stage → 0.7.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 +58 -0
- package/LICENSE +202 -0
- package/README.md +80 -2
- package/extensions/index.js +2611 -0
- package/package.json +34 -4
- package/skills/dep-update/SKILL.md +110 -0
- package/skills/dep-update/references/recipes.md +66 -0
|
@@ -0,0 +1,2611 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// Generated by scripts/build.ts. Do not edit.
|
|
3
|
+
// plugins/dep-update/pi-src/index.ts
|
|
4
|
+
import { isAbsolute, resolve } from "path";
|
|
5
|
+
|
|
6
|
+
// lib/src/dep-bump.ts
|
|
7
|
+
import { spawn } from "child_process";
|
|
8
|
+
import { statSync as statSync2 } from "fs";
|
|
9
|
+
import { join as join2 } from "path";
|
|
10
|
+
|
|
11
|
+
// node_modules/smol-toml/dist/error.js
|
|
12
|
+
/*!
|
|
13
|
+
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
14
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
15
|
+
*
|
|
16
|
+
* Redistribution and use in source and binary forms, with or without
|
|
17
|
+
* modification, are permitted provided that the following conditions are met:
|
|
18
|
+
*
|
|
19
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
20
|
+
* list of conditions and the following disclaimer.
|
|
21
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
22
|
+
* this list of conditions and the following disclaimer in the
|
|
23
|
+
* documentation and/or other materials provided with the distribution.
|
|
24
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
25
|
+
* may be used to endorse or promote products derived from this software without
|
|
26
|
+
* specific prior written permission.
|
|
27
|
+
*
|
|
28
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
29
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
30
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
31
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
32
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
33
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
34
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
35
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
36
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
37
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
38
|
+
*/
|
|
39
|
+
function getLineColFromPtr(string, ptr) {
|
|
40
|
+
let lines = string.slice(0, ptr).split(/\r?\n/);
|
|
41
|
+
return [lines.length, lines.pop().length + 1];
|
|
42
|
+
}
|
|
43
|
+
function makeCodeBlock(string, line, column) {
|
|
44
|
+
let lines = string.split(/\r?\n/);
|
|
45
|
+
let codeblock = "";
|
|
46
|
+
let numberLen = (Math.log10(line + 1) | 0) + 1;
|
|
47
|
+
for (let i = line - 1;i <= line + 1; i++) {
|
|
48
|
+
let l = lines[i - 1];
|
|
49
|
+
if (!l)
|
|
50
|
+
continue;
|
|
51
|
+
codeblock += i.toString().padEnd(numberLen, " ");
|
|
52
|
+
codeblock += ": ";
|
|
53
|
+
codeblock += l;
|
|
54
|
+
codeblock += `
|
|
55
|
+
`;
|
|
56
|
+
if (i === line) {
|
|
57
|
+
codeblock += " ".repeat(numberLen + column + 2);
|
|
58
|
+
codeblock += `^
|
|
59
|
+
`;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return codeblock;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
class TomlError extends Error {
|
|
66
|
+
line;
|
|
67
|
+
column;
|
|
68
|
+
codeblock;
|
|
69
|
+
constructor(message, options) {
|
|
70
|
+
const [line, column] = getLineColFromPtr(options.toml, options.ptr);
|
|
71
|
+
const codeblock = makeCodeBlock(options.toml, line, column);
|
|
72
|
+
super(`Invalid TOML document: ${message}
|
|
73
|
+
|
|
74
|
+
${codeblock}`, options);
|
|
75
|
+
this.line = line;
|
|
76
|
+
this.column = column;
|
|
77
|
+
this.codeblock = codeblock;
|
|
78
|
+
}
|
|
79
|
+
static x(message, ctx, ptr) {
|
|
80
|
+
throw new TomlError(message, { toml: ctx.s, ptr: ptr ?? ctx.p });
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// node_modules/smol-toml/dist/primitive.js
|
|
85
|
+
/*!
|
|
86
|
+
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
87
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
88
|
+
*
|
|
89
|
+
* Redistribution and use in source and binary forms, with or without
|
|
90
|
+
* modification, are permitted provided that the following conditions are met:
|
|
91
|
+
*
|
|
92
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
93
|
+
* list of conditions and the following disclaimer.
|
|
94
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
95
|
+
* this list of conditions and the following disclaimer in the
|
|
96
|
+
* documentation and/or other materials provided with the distribution.
|
|
97
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
98
|
+
* may be used to endorse or promote products derived from this software without
|
|
99
|
+
* specific prior written permission.
|
|
100
|
+
*
|
|
101
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
102
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
103
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
104
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
105
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
106
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
107
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
108
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
109
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
110
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
111
|
+
*/
|
|
112
|
+
function parseString(ctx) {
|
|
113
|
+
let startPtr = ctx.p;
|
|
114
|
+
let c = ctx.s.charCodeAt(ctx.p++);
|
|
115
|
+
let first = c;
|
|
116
|
+
let isLiteral = c === 39;
|
|
117
|
+
let isMultiline = c === ctx.s.charCodeAt(ctx.p) && c === ctx.s.charCodeAt(ctx.p + 1);
|
|
118
|
+
if (isMultiline) {
|
|
119
|
+
if ((c = ctx.s.charCodeAt(ctx.p += 2)) === 10)
|
|
120
|
+
ctx.p++;
|
|
121
|
+
else if (c === 13 && ctx.s.charCodeAt(ctx.p + 1) === 10)
|
|
122
|
+
ctx.p += 2;
|
|
123
|
+
}
|
|
124
|
+
let parsed = "";
|
|
125
|
+
let sliceStart = ctx.p;
|
|
126
|
+
let state = 0;
|
|
127
|
+
for (;ctx.p < ctx.s.length; ctx.p++) {
|
|
128
|
+
c = ctx.s.charCodeAt(ctx.p);
|
|
129
|
+
if (isMultiline && (c === 10 || c === 13 && ctx.s.charCodeAt(ctx.p + 1) === 10)) {
|
|
130
|
+
state = state && 3;
|
|
131
|
+
} else if (c < 32 && c !== 9 || c === 127) {
|
|
132
|
+
TomlError.x("control characters are not allowed in strings", ctx);
|
|
133
|
+
} else if ((!state || state === 3) && c === first && (!isMultiline || ctx.s.charCodeAt(ctx.p + 1) === first && ctx.s.charCodeAt(ctx.p + 2) === first)) {
|
|
134
|
+
if (isMultiline) {
|
|
135
|
+
if (ctx.s.charCodeAt(ctx.p + 3) === first)
|
|
136
|
+
ctx.p++;
|
|
137
|
+
if (ctx.s.charCodeAt(ctx.p + 3) === first)
|
|
138
|
+
ctx.p++;
|
|
139
|
+
}
|
|
140
|
+
if (!state) {
|
|
141
|
+
let s = ctx.s.slice(sliceStart, ctx.p);
|
|
142
|
+
parsed = parsed ? parsed + s : s;
|
|
143
|
+
}
|
|
144
|
+
ctx.p += isMultiline ? 3 : 1;
|
|
145
|
+
return parsed;
|
|
146
|
+
} else if (!state) {
|
|
147
|
+
if (!isLiteral && c === 92) {
|
|
148
|
+
parsed += ctx.s.slice(sliceStart, sliceStart = ctx.p);
|
|
149
|
+
state = 1;
|
|
150
|
+
}
|
|
151
|
+
} else if (state === 1) {
|
|
152
|
+
if (c === 120 || c === 117 || c === 85) {
|
|
153
|
+
let errPtr = ctx.p++ - 1;
|
|
154
|
+
let value = 0;
|
|
155
|
+
let len = c === 120 ? 2 : c === 117 ? 4 : 8;
|
|
156
|
+
for (let j = 0;j < len; j++, ctx.p++) {
|
|
157
|
+
let hex = ctx.s.charCodeAt(ctx.p);
|
|
158
|
+
let digit = hex >= 48 && hex <= 57 ? hex - 48 : hex >= 65 && hex <= 70 ? hex - 65 + 10 : hex >= 97 && hex <= 102 ? hex - 97 + 10 : -1;
|
|
159
|
+
if (digit < 0)
|
|
160
|
+
TomlError.x("invalid non-hex character in unicode escape", ctx);
|
|
161
|
+
value = value << 4 | digit;
|
|
162
|
+
}
|
|
163
|
+
if (value < 0 || value > 1114111 || value >= 55296 && value <= 57343) {
|
|
164
|
+
TomlError.x("invalid unicode escape", ctx, errPtr);
|
|
165
|
+
}
|
|
166
|
+
parsed += String.fromCodePoint(value);
|
|
167
|
+
sliceStart = ctx.p--;
|
|
168
|
+
state = 0;
|
|
169
|
+
} else if (isMultiline && (c === 32 || c === 9)) {
|
|
170
|
+
state = 2;
|
|
171
|
+
} else {
|
|
172
|
+
if (c === 98)
|
|
173
|
+
parsed += "\b";
|
|
174
|
+
else if (c === 116)
|
|
175
|
+
parsed += "\t";
|
|
176
|
+
else if (c === 110)
|
|
177
|
+
parsed += `
|
|
178
|
+
`;
|
|
179
|
+
else if (c === 102)
|
|
180
|
+
parsed += "\f";
|
|
181
|
+
else if (c === 114)
|
|
182
|
+
parsed += "\r";
|
|
183
|
+
else if (c === 101)
|
|
184
|
+
parsed += "\x1B";
|
|
185
|
+
else if (c === 34)
|
|
186
|
+
parsed += '"';
|
|
187
|
+
else if (c === 92)
|
|
188
|
+
parsed += "\\";
|
|
189
|
+
else
|
|
190
|
+
TomlError.x("unrecognised escape sequence", ctx);
|
|
191
|
+
sliceStart = ctx.p + 1;
|
|
192
|
+
state = 0;
|
|
193
|
+
}
|
|
194
|
+
} else if (c !== 32 && c !== 9) {
|
|
195
|
+
if (state === 2)
|
|
196
|
+
TomlError.x("invalid escape: only line-ending whitespace may be escaped", ctx, sliceStart);
|
|
197
|
+
state = !isLiteral && c === 92 ? 1 : 0;
|
|
198
|
+
sliceStart = ctx.p;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
TomlError.x("unfinished string", ctx, startPtr);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// node_modules/smol-toml/dist/date.js
|
|
205
|
+
/*!
|
|
206
|
+
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
207
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
208
|
+
*
|
|
209
|
+
* Redistribution and use in source and binary forms, with or without
|
|
210
|
+
* modification, are permitted provided that the following conditions are met:
|
|
211
|
+
*
|
|
212
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
213
|
+
* list of conditions and the following disclaimer.
|
|
214
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
215
|
+
* this list of conditions and the following disclaimer in the
|
|
216
|
+
* documentation and/or other materials provided with the distribution.
|
|
217
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
218
|
+
* may be used to endorse or promote products derived from this software without
|
|
219
|
+
* specific prior written permission.
|
|
220
|
+
*
|
|
221
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
222
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
223
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
224
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
225
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
226
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
227
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
228
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
229
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
230
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
231
|
+
*/
|
|
232
|
+
var DATE_TIME_RE = /^(\d{4}-\d{2}-\d{2})?[Tt ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|z|[-+]\d{2}:\d{2})?$/i;
|
|
233
|
+
|
|
234
|
+
class TomlDate extends Date {
|
|
235
|
+
#hasDate = false;
|
|
236
|
+
#hasTime = false;
|
|
237
|
+
#offset = null;
|
|
238
|
+
constructor(date, fasttype, unsafeDelim) {
|
|
239
|
+
let hasDate = true;
|
|
240
|
+
let hasTime = true;
|
|
241
|
+
let offset = "Z";
|
|
242
|
+
let c;
|
|
243
|
+
if (typeof date === "string") {
|
|
244
|
+
if (fasttype)
|
|
245
|
+
prep: {
|
|
246
|
+
if (fasttype < 3) {
|
|
247
|
+
if (+date.slice(11, 13) > 23) {
|
|
248
|
+
date = "";
|
|
249
|
+
break prep;
|
|
250
|
+
}
|
|
251
|
+
if (fasttype === 2) {
|
|
252
|
+
offset = null;
|
|
253
|
+
date += "Z";
|
|
254
|
+
} else if ((c = date.charCodeAt(date.length - 1)) !== 90 && c !== 122) {
|
|
255
|
+
offset = date.slice(date.length - 6);
|
|
256
|
+
}
|
|
257
|
+
if (unsafeDelim)
|
|
258
|
+
date = date.slice(0, 10) + "T" + date.slice(11);
|
|
259
|
+
} else if (fasttype === 4) {
|
|
260
|
+
date = +date.slice(0, 2) > 23 ? "" : `0000-01-01T${date}Z`;
|
|
261
|
+
}
|
|
262
|
+
hasDate = fasttype !== 4;
|
|
263
|
+
hasTime = fasttype !== 3;
|
|
264
|
+
}
|
|
265
|
+
else {
|
|
266
|
+
let match = date.match(DATE_TIME_RE);
|
|
267
|
+
if (match) {
|
|
268
|
+
if (!match[1]) {
|
|
269
|
+
hasDate = false;
|
|
270
|
+
date = `0000-01-01T${date}`;
|
|
271
|
+
}
|
|
272
|
+
hasTime = !!match[2];
|
|
273
|
+
hasTime && date[10] === " " && (date = date.replace(" ", "T"));
|
|
274
|
+
if (match[2] && +match[2] > 23) {
|
|
275
|
+
date = "";
|
|
276
|
+
} else {
|
|
277
|
+
offset = match[3] || null;
|
|
278
|
+
if (!offset && hasTime)
|
|
279
|
+
date += "Z";
|
|
280
|
+
}
|
|
281
|
+
} else {
|
|
282
|
+
date = "";
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
super(date);
|
|
287
|
+
if (!isNaN(this.getTime())) {
|
|
288
|
+
this.#hasDate = hasDate;
|
|
289
|
+
this.#hasTime = hasTime;
|
|
290
|
+
this.#offset = offset;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
isDateTime() {
|
|
294
|
+
return this.#hasDate && this.#hasTime;
|
|
295
|
+
}
|
|
296
|
+
isLocal() {
|
|
297
|
+
return !this.#hasDate || !this.#hasTime || !this.#offset;
|
|
298
|
+
}
|
|
299
|
+
isDate() {
|
|
300
|
+
return this.#hasDate && !this.#hasTime;
|
|
301
|
+
}
|
|
302
|
+
isTime() {
|
|
303
|
+
return this.#hasTime && !this.#hasDate;
|
|
304
|
+
}
|
|
305
|
+
isValid() {
|
|
306
|
+
return this.#hasDate || this.#hasTime;
|
|
307
|
+
}
|
|
308
|
+
toISOString() {
|
|
309
|
+
let iso = super.toISOString();
|
|
310
|
+
if (this.isDate())
|
|
311
|
+
return iso.slice(0, 10);
|
|
312
|
+
if (this.isTime())
|
|
313
|
+
return iso.slice(11, 23);
|
|
314
|
+
if (this.#offset === null)
|
|
315
|
+
return iso.slice(0, -1);
|
|
316
|
+
if (this.#offset === "Z" || this.#offset === "z")
|
|
317
|
+
return iso;
|
|
318
|
+
let offset = +this.#offset.slice(1, 3) * 60 + +this.#offset.slice(4, 6);
|
|
319
|
+
offset = this.#offset[0] === "-" ? offset : -offset;
|
|
320
|
+
let offsetDate = new Date(this.getTime() - offset * 60000);
|
|
321
|
+
return offsetDate.toISOString().slice(0, -1) + this.#offset;
|
|
322
|
+
}
|
|
323
|
+
static wrapAsOffsetDateTime(jsDate, offset = "Z") {
|
|
324
|
+
let date = new TomlDate(jsDate);
|
|
325
|
+
date.#offset = offset;
|
|
326
|
+
return date;
|
|
327
|
+
}
|
|
328
|
+
static wrapAsLocalDateTime(jsDate) {
|
|
329
|
+
let date = new TomlDate(jsDate);
|
|
330
|
+
date.#offset = null;
|
|
331
|
+
return date;
|
|
332
|
+
}
|
|
333
|
+
static wrapAsLocalDate(jsDate) {
|
|
334
|
+
let date = new TomlDate(jsDate);
|
|
335
|
+
date.#hasTime = false;
|
|
336
|
+
date.#offset = null;
|
|
337
|
+
return date;
|
|
338
|
+
}
|
|
339
|
+
static wrapAsLocalTime(jsDate) {
|
|
340
|
+
let date = new TomlDate(jsDate);
|
|
341
|
+
date.#hasDate = false;
|
|
342
|
+
date.#offset = null;
|
|
343
|
+
return date;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// node_modules/smol-toml/dist/extract.js
|
|
348
|
+
/*!
|
|
349
|
+
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
350
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
351
|
+
*
|
|
352
|
+
* Redistribution and use in source and binary forms, with or without
|
|
353
|
+
* modification, are permitted provided that the following conditions are met:
|
|
354
|
+
*
|
|
355
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
356
|
+
* list of conditions and the following disclaimer.
|
|
357
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
358
|
+
* this list of conditions and the following disclaimer in the
|
|
359
|
+
* documentation and/or other materials provided with the distribution.
|
|
360
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
361
|
+
* may be used to endorse or promote products derived from this software without
|
|
362
|
+
* specific prior written permission.
|
|
363
|
+
*
|
|
364
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
365
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
366
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
367
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
368
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
369
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
370
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
371
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
372
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
373
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
374
|
+
*/
|
|
375
|
+
function isDigit(char, base = 10) {
|
|
376
|
+
return base === 16 ? char > 47 && char < 58 || char > 64 && char < 71 || char > 96 && char < 103 : char > 47 && char < 48 + base;
|
|
377
|
+
}
|
|
378
|
+
function isEndOfValue(char, delim) {
|
|
379
|
+
return char === 32 || char === 9 || char === 10 || char === 13 || delim && (char === delim || char === 44) || char === 35;
|
|
380
|
+
}
|
|
381
|
+
function extractValue(ctx, end) {
|
|
382
|
+
let errPtr = ctx.p;
|
|
383
|
+
let c = ctx.s.charCodeAt(ctx.p);
|
|
384
|
+
if (c === 91 || c === 123) {
|
|
385
|
+
ctx.d-- || TomlError.x("document contains excessively nested structures. aborting.", ctx);
|
|
386
|
+
let value = c === 91 ? parseArray(ctx) : parseInlineTable(ctx);
|
|
387
|
+
ctx.d++;
|
|
388
|
+
return value;
|
|
389
|
+
}
|
|
390
|
+
if (c === 34 || c === 39) {
|
|
391
|
+
return parseString(ctx);
|
|
392
|
+
}
|
|
393
|
+
if (c === 116) {
|
|
394
|
+
if (ctx.s.charCodeAt(++ctx.p) !== 114 || ctx.s.charCodeAt(++ctx.p) !== 117 || ctx.s.charCodeAt(++ctx.p) !== 101)
|
|
395
|
+
TomlError.x("invalid value", ctx, errPtr);
|
|
396
|
+
return ctx.p++, true;
|
|
397
|
+
}
|
|
398
|
+
if (c === 102) {
|
|
399
|
+
if (ctx.s.charCodeAt(++ctx.p) !== 97 || ctx.s.charCodeAt(++ctx.p) !== 108 || ctx.s.charCodeAt(++ctx.p) !== 115 || ctx.s.charCodeAt(++ctx.p) !== 101)
|
|
400
|
+
TomlError.x("invalid value", ctx, errPtr);
|
|
401
|
+
return ctx.p++, false;
|
|
402
|
+
}
|
|
403
|
+
if (c === 43 || c === 45) {
|
|
404
|
+
return parseNumber(ctx, ctx.p, ctx.s.charCodeAt(++ctx.p), 44 - c, end);
|
|
405
|
+
}
|
|
406
|
+
if (ctx.s.charCodeAt(ctx.p + 4) === 45 && ctx.s.charCodeAt(ctx.p + 7) === 45) {
|
|
407
|
+
return parseDate(ctx, c, end);
|
|
408
|
+
}
|
|
409
|
+
if (ctx.s.charCodeAt(ctx.p + 2) === 58) {
|
|
410
|
+
return parseTime(ctx, c, end);
|
|
411
|
+
}
|
|
412
|
+
return parseNumber(ctx, ctx.p, c, 0, end);
|
|
413
|
+
}
|
|
414
|
+
function parseNumber(ctx, startPtr, startChr, sign, endChr) {
|
|
415
|
+
let c = startChr;
|
|
416
|
+
let state = 0;
|
|
417
|
+
let hasUnderscores = false;
|
|
418
|
+
if (c === 105) {
|
|
419
|
+
if (ctx.s.charCodeAt(++ctx.p) !== 110 || ctx.s.charCodeAt(++ctx.p) !== 102)
|
|
420
|
+
TomlError.x("invalid value", ctx, startPtr);
|
|
421
|
+
return ctx.p++, (sign || 1) / 0;
|
|
422
|
+
}
|
|
423
|
+
if (c === 110) {
|
|
424
|
+
if (ctx.s.charCodeAt(++ctx.p) !== 97 || ctx.s.charCodeAt(++ctx.p) !== 110)
|
|
425
|
+
TomlError.x("invalid value", ctx, startPtr);
|
|
426
|
+
return ctx.p++, NaN;
|
|
427
|
+
}
|
|
428
|
+
if (c === 48) {
|
|
429
|
+
if (++ctx.p >= ctx.s.length || isEndOfValue(c = ctx.s.charCodeAt(ctx.p), endChr))
|
|
430
|
+
return ctx.bi === true ? 0n : 0;
|
|
431
|
+
if (!sign) {
|
|
432
|
+
if (c === 120)
|
|
433
|
+
return parseIntegerBaseN(ctx, startPtr, 16, endChr);
|
|
434
|
+
else if (c === 98)
|
|
435
|
+
return parseIntegerBaseN(ctx, startPtr, 2, endChr);
|
|
436
|
+
else if (c === 111)
|
|
437
|
+
return parseIntegerBaseN(ctx, startPtr, 8, endChr);
|
|
438
|
+
}
|
|
439
|
+
if (c === 46)
|
|
440
|
+
state = 2;
|
|
441
|
+
else if (c === 101 || c === 69)
|
|
442
|
+
state = 4;
|
|
443
|
+
else
|
|
444
|
+
TomlError.x("illegal leading zero", ctx, startPtr);
|
|
445
|
+
} else if (!isDigit(c))
|
|
446
|
+
TomlError.x("invalid value", ctx, startPtr);
|
|
447
|
+
while (++ctx.p < ctx.s.length && (c = ctx.s.charCodeAt(ctx.p), !isEndOfValue(c, endChr))) {
|
|
448
|
+
if (!state)
|
|
449
|
+
state = 1;
|
|
450
|
+
if (c === 95) {
|
|
451
|
+
if (!(state & 1))
|
|
452
|
+
TomlError.x("illegal underscore", ctx);
|
|
453
|
+
state += 11;
|
|
454
|
+
hasUnderscores = true;
|
|
455
|
+
} else if (state === 1 && c === 46)
|
|
456
|
+
state = 2;
|
|
457
|
+
else if ((state === 1 || state === 3) && (c === 101 || c === 69))
|
|
458
|
+
state = 4;
|
|
459
|
+
else if (state === 4 && (c === 43 || c === 45)) {
|
|
460
|
+
state = 6;
|
|
461
|
+
} else if (!isDigit(c))
|
|
462
|
+
TomlError.x(`illegal character in numeric literal`, ctx);
|
|
463
|
+
else if (state > 9)
|
|
464
|
+
state -= 11;
|
|
465
|
+
else if (!(state & 1))
|
|
466
|
+
state++;
|
|
467
|
+
}
|
|
468
|
+
if (!state) {
|
|
469
|
+
let val = (startChr - 48) * (sign || 1);
|
|
470
|
+
return ctx.bi === true ? BigInt(val) : val;
|
|
471
|
+
}
|
|
472
|
+
if (!(state & 1))
|
|
473
|
+
TomlError.x("unfinished numeric value", ctx, startPtr);
|
|
474
|
+
let str = ctx.s.slice(startPtr, ctx.p);
|
|
475
|
+
if (hasUnderscores)
|
|
476
|
+
str = str.replaceAll("_", "");
|
|
477
|
+
return state > 1 ? parseFloat(str) : parseInteger(ctx, str, 10, startPtr);
|
|
478
|
+
}
|
|
479
|
+
function parseIntegerBaseN(ctx, startPtr, base, endChr) {
|
|
480
|
+
let c, underscore = 1;
|
|
481
|
+
while (++ctx.p < ctx.s.length && (c = ctx.s.charCodeAt(ctx.p), !isEndOfValue(c, endChr))) {
|
|
482
|
+
if (c === 95) {
|
|
483
|
+
if (underscore & 1)
|
|
484
|
+
TomlError.x("illegal underscore", ctx);
|
|
485
|
+
underscore = 3;
|
|
486
|
+
} else if (!isDigit(c, base))
|
|
487
|
+
TomlError.x(`illegal character in numeric literal`, ctx);
|
|
488
|
+
else if (underscore & 1)
|
|
489
|
+
underscore--;
|
|
490
|
+
}
|
|
491
|
+
if (underscore & 1)
|
|
492
|
+
TomlError.x("unfinished numeric value", ctx);
|
|
493
|
+
let str = ctx.s.slice(startPtr + 2, ctx.p);
|
|
494
|
+
if (underscore)
|
|
495
|
+
str = str.replaceAll("_", "");
|
|
496
|
+
return parseInteger(ctx, str, base, startPtr);
|
|
497
|
+
}
|
|
498
|
+
function parseInteger(ctx, str, base, startPtr) {
|
|
499
|
+
if (ctx.bi !== true)
|
|
500
|
+
int: {
|
|
501
|
+
let val = parseInt(str, base);
|
|
502
|
+
if (!Number.isSafeInteger(val)) {
|
|
503
|
+
if (ctx.bi)
|
|
504
|
+
break int;
|
|
505
|
+
TomlError.x("integer value cannot be represented losslessly", ctx, startPtr);
|
|
506
|
+
}
|
|
507
|
+
return val;
|
|
508
|
+
}
|
|
509
|
+
return base === 10 ? BigInt(str) : BigInt((base === 2 ? "0b" : base === 8 ? "0o" : "0x") + str);
|
|
510
|
+
}
|
|
511
|
+
function parseDate(ctx, c, endChr) {
|
|
512
|
+
let startPtr = ctx.p++, unsafeSeparator;
|
|
513
|
+
if (!isDigit(c) || !isDigit(ctx.s.charCodeAt(ctx.p++)) || !isDigit(ctx.s.charCodeAt(ctx.p++)) || !isDigit(ctx.s.charCodeAt(ctx.p++))) {
|
|
514
|
+
return parseNumber(ctx, ctx.p = startPtr, c, 0, endChr);
|
|
515
|
+
}
|
|
516
|
+
ctx.p += 5;
|
|
517
|
+
if (!isDigit(ctx.s.charCodeAt(ctx.p++)))
|
|
518
|
+
TomlError.x("invalid date-time: date part is malformed", ctx, startPtr);
|
|
519
|
+
if (ctx.p >= ctx.s.length || ((c = ctx.s.charCodeAt(ctx.p)) !== 32 || (unsafeSeparator = true, !isDigit(ctx.s.charCodeAt(ctx.p + 1)))) && c !== 84 && c !== 116) {
|
|
520
|
+
let t = ctx.s.slice(startPtr, ctx.p);
|
|
521
|
+
return readDate(ctx, t, 3, false, startPtr);
|
|
522
|
+
}
|
|
523
|
+
if (ctx.s.charCodeAt(ctx.p += 3) !== 58)
|
|
524
|
+
TomlError.x("invalid date-time: time part is malformed", ctx, startPtr);
|
|
525
|
+
if (ctx.s.charCodeAt(ctx.p += 3) === 58)
|
|
526
|
+
ctx.p += 3;
|
|
527
|
+
if (ctx.s.charCodeAt(ctx.p) === 46)
|
|
528
|
+
while (isDigit(ctx.s.charCodeAt(++ctx.p)))
|
|
529
|
+
;
|
|
530
|
+
if (c = ctx.s.charCodeAt(ctx.p)) {
|
|
531
|
+
if (c === 90 || c === 122) {
|
|
532
|
+
let t = ctx.s.slice(startPtr, ++ctx.p);
|
|
533
|
+
return readDate(ctx, t, 1, unsafeSeparator, startPtr, "[+00:00]");
|
|
534
|
+
}
|
|
535
|
+
if (c === 43 || c === 45) {
|
|
536
|
+
let t = ctx.s.slice(startPtr, ctx.p += 6);
|
|
537
|
+
return readDate(ctx, t, 1, unsafeSeparator, startPtr, !ctx.ld && "[" + ctx.s.slice(ctx.p - 6, ctx.p) + "]");
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
let t = ctx.s.slice(startPtr, ctx.p);
|
|
541
|
+
return readDate(ctx, t, 2, unsafeSeparator, startPtr);
|
|
542
|
+
}
|
|
543
|
+
function parseTime(ctx, c, endChr) {
|
|
544
|
+
let start = ctx.p;
|
|
545
|
+
if (!isDigit(c) || !isDigit(ctx.s.charCodeAt(++ctx.p))) {
|
|
546
|
+
return parseNumber(ctx, --ctx.p, c, 0, endChr);
|
|
547
|
+
}
|
|
548
|
+
if (ctx.s.charCodeAt(ctx.p += 4) === 58)
|
|
549
|
+
ctx.p += 3;
|
|
550
|
+
if (ctx.s.charCodeAt(ctx.p) === 46)
|
|
551
|
+
while (isDigit(ctx.s.charCodeAt(++ctx.p)))
|
|
552
|
+
;
|
|
553
|
+
let t = ctx.s.slice(start, ctx.p);
|
|
554
|
+
return readDate(ctx, t, 4, false, start);
|
|
555
|
+
}
|
|
556
|
+
function readDate(ctx, str, type, unsafeDelim, errPtr, temporalSuffix) {
|
|
557
|
+
if (ctx.ld) {
|
|
558
|
+
let date = new TomlDate(str, type, unsafeDelim);
|
|
559
|
+
if (!date.isValid())
|
|
560
|
+
TomlError.x("invalid date", ctx, errPtr);
|
|
561
|
+
return date;
|
|
562
|
+
}
|
|
563
|
+
try {
|
|
564
|
+
if (temporalSuffix)
|
|
565
|
+
str += temporalSuffix;
|
|
566
|
+
switch (type) {
|
|
567
|
+
case 1:
|
|
568
|
+
return Temporal.ZonedDateTime.from(str);
|
|
569
|
+
case 2:
|
|
570
|
+
return Temporal.PlainDateTime.from(str);
|
|
571
|
+
case 3:
|
|
572
|
+
return Temporal.PlainDate.from(str);
|
|
573
|
+
case 4:
|
|
574
|
+
return Temporal.PlainTime.from(str);
|
|
575
|
+
}
|
|
576
|
+
} catch (e) {
|
|
577
|
+
TomlError.x(e instanceof Error ? e.message : "" + e, ctx, errPtr);
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
// node_modules/smol-toml/dist/util.js
|
|
582
|
+
/*!
|
|
583
|
+
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
584
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
585
|
+
*
|
|
586
|
+
* Redistribution and use in source and binary forms, with or without
|
|
587
|
+
* modification, are permitted provided that the following conditions are met:
|
|
588
|
+
*
|
|
589
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
590
|
+
* list of conditions and the following disclaimer.
|
|
591
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
592
|
+
* this list of conditions and the following disclaimer in the
|
|
593
|
+
* documentation and/or other materials provided with the distribution.
|
|
594
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
595
|
+
* may be used to endorse or promote products derived from this software without
|
|
596
|
+
* specific prior written permission.
|
|
597
|
+
*
|
|
598
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
599
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
600
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
601
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
602
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
603
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
604
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
605
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
606
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
607
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
608
|
+
*/
|
|
609
|
+
function skipComment(ctx) {
|
|
610
|
+
for (;ctx.p < ctx.s.length; ctx.p++) {
|
|
611
|
+
let c = ctx.s.charCodeAt(ctx.p);
|
|
612
|
+
if (c === 10)
|
|
613
|
+
break;
|
|
614
|
+
if (c === 13 && ctx.s.charCodeAt(ctx.p + 1) === 10) {
|
|
615
|
+
ctx.p++;
|
|
616
|
+
break;
|
|
617
|
+
}
|
|
618
|
+
if (c < 32 && c !== 9 || c === 127) {
|
|
619
|
+
TomlError.x("control characters are not allowed in comments", ctx);
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
function skipVoid(ctx, banNewLines, banComments) {
|
|
624
|
+
let c;
|
|
625
|
+
while (ctx.p < ctx.s.length) {
|
|
626
|
+
while (ctx.p < ctx.s.length && ((c = ctx.s.charCodeAt(ctx.p)) === 32 || c === 9 || !banNewLines && (c === 10 || c === 13 && ctx.s.charCodeAt(ctx.p + 1) === 10)))
|
|
627
|
+
ctx.p++;
|
|
628
|
+
if (banComments || c !== 35)
|
|
629
|
+
break;
|
|
630
|
+
skipComment(ctx);
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
// node_modules/smol-toml/dist/struct.js
|
|
635
|
+
/*!
|
|
636
|
+
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
637
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
638
|
+
*
|
|
639
|
+
* Redistribution and use in source and binary forms, with or without
|
|
640
|
+
* modification, are permitted provided that the following conditions are met:
|
|
641
|
+
*
|
|
642
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
643
|
+
* list of conditions and the following disclaimer.
|
|
644
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
645
|
+
* this list of conditions and the following disclaimer in the
|
|
646
|
+
* documentation and/or other materials provided with the distribution.
|
|
647
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
648
|
+
* may be used to endorse or promote products derived from this software without
|
|
649
|
+
* specific prior written permission.
|
|
650
|
+
*
|
|
651
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
652
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
653
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
654
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
655
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
656
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
657
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
658
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
659
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
660
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
661
|
+
*/
|
|
662
|
+
function parseKey(ctx, end = 61) {
|
|
663
|
+
let startPtr;
|
|
664
|
+
let state = 0;
|
|
665
|
+
let parsed = [];
|
|
666
|
+
let sliceStart;
|
|
667
|
+
let c = ctx.s.charCodeAt(startPtr = ctx.p);
|
|
668
|
+
do {
|
|
669
|
+
if (c === end) {
|
|
670
|
+
if (!state)
|
|
671
|
+
TomlError.x("unexpected end of key", ctx);
|
|
672
|
+
if (state === 1)
|
|
673
|
+
parsed.push(ctx.s.slice(sliceStart, ctx.p));
|
|
674
|
+
return ctx.p++, parsed;
|
|
675
|
+
} else if (c === 46) {
|
|
676
|
+
if (!state)
|
|
677
|
+
TomlError.x("illegal empty bare key", ctx);
|
|
678
|
+
if (state === 1)
|
|
679
|
+
parsed.push(ctx.s.slice(sliceStart, ctx.p));
|
|
680
|
+
state = 0;
|
|
681
|
+
} else if (!state && (c === 34 || c === 39)) {
|
|
682
|
+
if (c === ctx.s.charCodeAt(ctx.p + 1) && c === ctx.s.charCodeAt(ctx.p + 2))
|
|
683
|
+
TomlError.x("illegal quoted key: multiline strings are not allowed", ctx);
|
|
684
|
+
parsed.push(parseString(ctx));
|
|
685
|
+
state = 2;
|
|
686
|
+
ctx.p--;
|
|
687
|
+
} else if (c === 32 || c === 9) {
|
|
688
|
+
if (state === 1) {
|
|
689
|
+
parsed.push(ctx.s.slice(sliceStart, ctx.p));
|
|
690
|
+
state = 2;
|
|
691
|
+
}
|
|
692
|
+
} else if (state === 2 || c < 48 && c !== 45 || c > 57 && c < 65 || c > 90 && c < 97 && c !== 95 || c > 122) {
|
|
693
|
+
TomlError.x("illegal character in key", ctx);
|
|
694
|
+
} else if (!state) {
|
|
695
|
+
state = 1;
|
|
696
|
+
sliceStart = ctx.p;
|
|
697
|
+
}
|
|
698
|
+
} while (c = ctx.s.charCodeAt(++ctx.p));
|
|
699
|
+
TomlError.x("incomplete key-value: cannot find end of key", ctx, startPtr);
|
|
700
|
+
}
|
|
701
|
+
function parseInlineTable(ctx) {
|
|
702
|
+
let startPtr = ctx.p++;
|
|
703
|
+
let res = Object.create(null);
|
|
704
|
+
let seen = new Set;
|
|
705
|
+
let c;
|
|
706
|
+
while (ctx.p < ctx.s.length) {
|
|
707
|
+
skipVoid(ctx);
|
|
708
|
+
if ((c = ctx.s.charCodeAt(ctx.p)) === 125) {
|
|
709
|
+
ctx.p++;
|
|
710
|
+
return res;
|
|
711
|
+
}
|
|
712
|
+
let k;
|
|
713
|
+
let t = res;
|
|
714
|
+
let hasOwn = false;
|
|
715
|
+
let errPtr = ctx.p;
|
|
716
|
+
let key = parseKey(ctx);
|
|
717
|
+
for (let i = 0;i < key.length; i++) {
|
|
718
|
+
if (i)
|
|
719
|
+
t = hasOwn ? t[k] : t[k] = Object.create(null);
|
|
720
|
+
k = key[i];
|
|
721
|
+
if ((hasOwn = Object.hasOwn(t, k)) && (typeof t[k] !== "object" || seen.has(t[k]))) {
|
|
722
|
+
TomlError.x("trying to redefine an already defined value", ctx, errPtr);
|
|
723
|
+
}
|
|
724
|
+
let unsafe = k === "__proto__";
|
|
725
|
+
if (ctx.uk && (unsafe || k === "constructor")) {
|
|
726
|
+
t = ctx.uk !== 1 && TomlError.x("document contains an unsafe property", ctx, errPtr);
|
|
727
|
+
break;
|
|
728
|
+
}
|
|
729
|
+
if (!hasOwn && unsafe) {
|
|
730
|
+
Object.defineProperty(t, k, { enumerable: true, configurable: true, writable: true });
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
if (hasOwn) {
|
|
734
|
+
TomlError.x("trying to redefine an already defined value", ctx, errPtr);
|
|
735
|
+
}
|
|
736
|
+
skipVoid(ctx, true, true);
|
|
737
|
+
let value = extractValue(ctx, 125);
|
|
738
|
+
if (t && typeof (t[k] = value) === "object")
|
|
739
|
+
seen.add(value);
|
|
740
|
+
skipVoid(ctx);
|
|
741
|
+
if ((c = ctx.s.charCodeAt(ctx.p++)) === 125) {
|
|
742
|
+
return res;
|
|
743
|
+
}
|
|
744
|
+
if (c !== 44)
|
|
745
|
+
TomlError.x("expected comma or end of structure", ctx, ctx.p - 1);
|
|
746
|
+
}
|
|
747
|
+
TomlError.x("unfinished table", ctx, startPtr);
|
|
748
|
+
}
|
|
749
|
+
function parseArray(ctx) {
|
|
750
|
+
let startPtr = ctx.p++;
|
|
751
|
+
let res = [];
|
|
752
|
+
let c;
|
|
753
|
+
while (ctx.p < ctx.s.length) {
|
|
754
|
+
skipVoid(ctx);
|
|
755
|
+
if ((c = ctx.s.charCodeAt(ctx.p)) === 93) {
|
|
756
|
+
ctx.p++;
|
|
757
|
+
return res;
|
|
758
|
+
}
|
|
759
|
+
res.push(extractValue(ctx, 93));
|
|
760
|
+
skipVoid(ctx);
|
|
761
|
+
if ((c = ctx.s.charCodeAt(ctx.p++)) === 93) {
|
|
762
|
+
return res;
|
|
763
|
+
}
|
|
764
|
+
if (c !== 44)
|
|
765
|
+
TomlError.x("expected comma or end of structure", ctx, ctx.p - 1);
|
|
766
|
+
}
|
|
767
|
+
TomlError.x("unfinished array", ctx, startPtr);
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
// node_modules/smol-toml/dist/parse.js
|
|
771
|
+
/*!
|
|
772
|
+
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
773
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
774
|
+
*
|
|
775
|
+
* Redistribution and use in source and binary forms, with or without
|
|
776
|
+
* modification, are permitted provided that the following conditions are met:
|
|
777
|
+
*
|
|
778
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
779
|
+
* list of conditions and the following disclaimer.
|
|
780
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
781
|
+
* this list of conditions and the following disclaimer in the
|
|
782
|
+
* documentation and/or other materials provided with the distribution.
|
|
783
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
784
|
+
* may be used to endorse or promote products derived from this software without
|
|
785
|
+
* specific prior written permission.
|
|
786
|
+
*
|
|
787
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
788
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
789
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
790
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
791
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
792
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
793
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
794
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
795
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
796
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
797
|
+
*/
|
|
798
|
+
function peekTable(ctx, key, table, meta, type) {
|
|
799
|
+
let t = table;
|
|
800
|
+
let m = meta;
|
|
801
|
+
let k;
|
|
802
|
+
let hasOwn = false;
|
|
803
|
+
let state;
|
|
804
|
+
for (let i = 0;i < key.length; i++) {
|
|
805
|
+
if (i) {
|
|
806
|
+
t = hasOwn ? t[k] : t[k] = Object.create(null);
|
|
807
|
+
m = (state = m[k]).c;
|
|
808
|
+
if (type === 0 && (state.t === 1 || state.t === 2)) {
|
|
809
|
+
return null;
|
|
810
|
+
}
|
|
811
|
+
if (state.t === 2) {
|
|
812
|
+
let l = t.length - 1;
|
|
813
|
+
t = t[l];
|
|
814
|
+
m = m[l].c;
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
k = key[i];
|
|
818
|
+
if ((hasOwn = Object.hasOwn(t, k)) && m[k]?.t === 0 && m[k]?.d) {
|
|
819
|
+
return null;
|
|
820
|
+
}
|
|
821
|
+
if (!hasOwn) {
|
|
822
|
+
let unsafe = k === "__proto__";
|
|
823
|
+
if (ctx.uk && (unsafe || k === "constructor"))
|
|
824
|
+
return false;
|
|
825
|
+
if (unsafe) {
|
|
826
|
+
Object.defineProperty(t, k, { enumerable: true, configurable: true, writable: true });
|
|
827
|
+
Object.defineProperty(m, k, { enumerable: true, configurable: true, writable: true });
|
|
828
|
+
}
|
|
829
|
+
m[k] = {
|
|
830
|
+
t: i < key.length - 1 && type === 2 ? 3 : type,
|
|
831
|
+
d: false,
|
|
832
|
+
i: 0,
|
|
833
|
+
c: Object.create(null)
|
|
834
|
+
};
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
state = m[k];
|
|
838
|
+
if (state.t !== type && !(type === 1 && state.t === 3)) {
|
|
839
|
+
return null;
|
|
840
|
+
}
|
|
841
|
+
if (type === 2) {
|
|
842
|
+
if (!state.d) {
|
|
843
|
+
state.d = true;
|
|
844
|
+
t[k] = [];
|
|
845
|
+
}
|
|
846
|
+
t[k].push(t = Object.create(null));
|
|
847
|
+
state.c[state.i++] = state = { t: 1, d: false, i: 0, c: Object.create(null) };
|
|
848
|
+
}
|
|
849
|
+
if (state.d) {
|
|
850
|
+
return null;
|
|
851
|
+
}
|
|
852
|
+
state.d = true;
|
|
853
|
+
if (type === 1) {
|
|
854
|
+
t = hasOwn ? t[k] : t[k] = Object.create(null);
|
|
855
|
+
} else if (type === 0 && hasOwn) {
|
|
856
|
+
return null;
|
|
857
|
+
}
|
|
858
|
+
return [k, t, state.c];
|
|
859
|
+
}
|
|
860
|
+
function validateTablePeek(ctx, peek, ptr) {
|
|
861
|
+
if (peek === null || ctx.uk === 2)
|
|
862
|
+
TomlError.x(peek === null ? "trying to redefine an already defined table or value" : "document contains an unsafe property", ctx, ptr);
|
|
863
|
+
}
|
|
864
|
+
function parse(toml, options = {}) {
|
|
865
|
+
let ctx = {
|
|
866
|
+
s: toml,
|
|
867
|
+
p: 0,
|
|
868
|
+
d: options.maxDepth ?? 1000,
|
|
869
|
+
bi: options.integersAsBigInt ?? false,
|
|
870
|
+
ld: options.useLegacyDate ?? true,
|
|
871
|
+
uk: options.unsafeKeyBehaviour === "throw" ? 2 : options.unsafeKeyBehaviour === "drop" ? 1 : 0
|
|
872
|
+
};
|
|
873
|
+
let res = Object.create(null);
|
|
874
|
+
let meta = Object.create(null);
|
|
875
|
+
let tmp;
|
|
876
|
+
let skipping = false;
|
|
877
|
+
let tbl = res;
|
|
878
|
+
let m = meta;
|
|
879
|
+
if (toml.charCodeAt(0) === 65279)
|
|
880
|
+
ctx.p++;
|
|
881
|
+
skipVoid(ctx);
|
|
882
|
+
while (ctx.p < toml.length) {
|
|
883
|
+
if (toml.charCodeAt(ctx.p) === 91) {
|
|
884
|
+
let isTableArray = toml.charCodeAt(++ctx.p) === 91;
|
|
885
|
+
tmp = ctx.p += +isTableArray;
|
|
886
|
+
skipping = false;
|
|
887
|
+
let k = parseKey(ctx, 93);
|
|
888
|
+
if (isTableArray) {
|
|
889
|
+
if (toml.charCodeAt(ctx.p) !== 93) {
|
|
890
|
+
TomlError.x("expected end of table array declaration", ctx);
|
|
891
|
+
}
|
|
892
|
+
ctx.p++;
|
|
893
|
+
}
|
|
894
|
+
let p = peekTable(ctx, k, res, meta, isTableArray ? 2 : 1);
|
|
895
|
+
if (!p) {
|
|
896
|
+
validateTablePeek(ctx, p, tmp);
|
|
897
|
+
skipping = true;
|
|
898
|
+
} else {
|
|
899
|
+
m = p[2];
|
|
900
|
+
tbl = p[1];
|
|
901
|
+
}
|
|
902
|
+
} else {
|
|
903
|
+
tmp = ctx.p;
|
|
904
|
+
let k = parseKey(ctx);
|
|
905
|
+
let p = peekTable(ctx, k, tbl, m, 0);
|
|
906
|
+
if (!p && !skipping)
|
|
907
|
+
validateTablePeek(ctx, p, tmp);
|
|
908
|
+
skipVoid(ctx, true, true);
|
|
909
|
+
let v = extractValue(ctx, undefined);
|
|
910
|
+
if (p && !skipping)
|
|
911
|
+
p[1][p[0]] = v;
|
|
912
|
+
}
|
|
913
|
+
skipVoid(ctx, true);
|
|
914
|
+
if (ctx.p < toml.length && (tmp = toml.charCodeAt(ctx.p)) !== 10 && (tmp !== 13 || toml.charCodeAt(ctx.p + 1) !== 10)) {
|
|
915
|
+
TomlError.x("each key-value declaration must be followed by an end-of-line", ctx);
|
|
916
|
+
}
|
|
917
|
+
skipVoid(ctx);
|
|
918
|
+
}
|
|
919
|
+
return res;
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
// node_modules/smol-toml/dist/stringify.js
|
|
923
|
+
/*!
|
|
924
|
+
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
925
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
926
|
+
*
|
|
927
|
+
* Redistribution and use in source and binary forms, with or without
|
|
928
|
+
* modification, are permitted provided that the following conditions are met:
|
|
929
|
+
*
|
|
930
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
931
|
+
* list of conditions and the following disclaimer.
|
|
932
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
933
|
+
* this list of conditions and the following disclaimer in the
|
|
934
|
+
* documentation and/or other materials provided with the distribution.
|
|
935
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
936
|
+
* may be used to endorse or promote products derived from this software without
|
|
937
|
+
* specific prior written permission.
|
|
938
|
+
*
|
|
939
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
940
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
941
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
942
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
943
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
944
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
945
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
946
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
947
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
948
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
949
|
+
*/
|
|
950
|
+
var HAS_WELLFORMED = !!"".isWellFormed;
|
|
951
|
+
|
|
952
|
+
// node_modules/smol-toml/dist/index.js
|
|
953
|
+
/*!
|
|
954
|
+
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
955
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
956
|
+
*
|
|
957
|
+
* Redistribution and use in source and binary forms, with or without
|
|
958
|
+
* modification, are permitted provided that the following conditions are met:
|
|
959
|
+
*
|
|
960
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
961
|
+
* list of conditions and the following disclaimer.
|
|
962
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
963
|
+
* this list of conditions and the following disclaimer in the
|
|
964
|
+
* documentation and/or other materials provided with the distribution.
|
|
965
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
966
|
+
* may be used to endorse or promote products derived from this software without
|
|
967
|
+
* specific prior written permission.
|
|
968
|
+
*
|
|
969
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
970
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
971
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
972
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
973
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
974
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
975
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
976
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
977
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
978
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
979
|
+
*/
|
|
980
|
+
|
|
981
|
+
// lib/src/dep-detect.ts
|
|
982
|
+
import { statSync } from "fs";
|
|
983
|
+
var MISSING = "?";
|
|
984
|
+
var REQ_SPLIT = /[[<>=!~;\s]/;
|
|
985
|
+
var REQ_NAME = /^[A-Za-z0-9](?:[A-Za-z0-9._-]*[A-Za-z0-9])?$/;
|
|
986
|
+
var GEM = /^\s*gem\s+(['"])([^'"]+)\1(?:\s*,\s*(['"])([^'"]*)\3)?/;
|
|
987
|
+
function canonical(name) {
|
|
988
|
+
return name.replace(/[-_.]+/g, "-").toLowerCase();
|
|
989
|
+
}
|
|
990
|
+
function isFile(path) {
|
|
991
|
+
try {
|
|
992
|
+
return statSync(path).isFile();
|
|
993
|
+
} catch {
|
|
994
|
+
return false;
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
function isDir(path) {
|
|
998
|
+
try {
|
|
999
|
+
return statSync(path).isDirectory();
|
|
1000
|
+
} catch {
|
|
1001
|
+
return false;
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
function join(root, name) {
|
|
1005
|
+
return root.endsWith("/") ? root + name : `${root}/${name}`;
|
|
1006
|
+
}
|
|
1007
|
+
async function readText(path) {
|
|
1008
|
+
try {
|
|
1009
|
+
if (!isFile(path))
|
|
1010
|
+
return null;
|
|
1011
|
+
const buf = await Bun.file(path).arrayBuffer();
|
|
1012
|
+
let text = new TextDecoder("utf-8").decode(buf);
|
|
1013
|
+
if (text.charCodeAt(0) === 65279)
|
|
1014
|
+
text = text.slice(1);
|
|
1015
|
+
return text;
|
|
1016
|
+
} catch {
|
|
1017
|
+
return null;
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
function scalar(value) {
|
|
1021
|
+
if (value === null || value === undefined || typeof value === "object")
|
|
1022
|
+
return MISSING;
|
|
1023
|
+
return String(value);
|
|
1024
|
+
}
|
|
1025
|
+
function specVersion(spec) {
|
|
1026
|
+
if (spec && typeof spec === "object" && !Array.isArray(spec)) {
|
|
1027
|
+
return scalar(spec.version);
|
|
1028
|
+
}
|
|
1029
|
+
if (Array.isArray(spec)) {
|
|
1030
|
+
for (const item of spec) {
|
|
1031
|
+
if (item && typeof item === "object" && item.version != null) {
|
|
1032
|
+
return scalar(item.version);
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
return MISSING;
|
|
1036
|
+
}
|
|
1037
|
+
return scalar(spec);
|
|
1038
|
+
}
|
|
1039
|
+
function isLocalLockEntry(rec) {
|
|
1040
|
+
if (rec.develop === true)
|
|
1041
|
+
return true;
|
|
1042
|
+
const source = rec.source;
|
|
1043
|
+
if (!source || typeof source !== "object" || Array.isArray(source))
|
|
1044
|
+
return false;
|
|
1045
|
+
const s = source;
|
|
1046
|
+
if (s.editable !== undefined || s.virtual !== undefined || s.directory !== undefined || s.path !== undefined)
|
|
1047
|
+
return true;
|
|
1048
|
+
return s.type === "directory" || s.type === "file";
|
|
1049
|
+
}
|
|
1050
|
+
function parseRequirement(raw) {
|
|
1051
|
+
const first = raw.split("#", 1)[0];
|
|
1052
|
+
if (first === undefined)
|
|
1053
|
+
return ["", ""];
|
|
1054
|
+
let line = first.trim();
|
|
1055
|
+
line = line.replace(/\\+$/, "").trim();
|
|
1056
|
+
if (!line || line.startsWith("-") || line.startsWith(".") || line.startsWith("/")) {
|
|
1057
|
+
return ["", ""];
|
|
1058
|
+
}
|
|
1059
|
+
const beforeSemicolon = line.split(";", 1)[0];
|
|
1060
|
+
if (beforeSemicolon === undefined)
|
|
1061
|
+
return ["", ""];
|
|
1062
|
+
line = beforeSemicolon.trim();
|
|
1063
|
+
const match = REQ_SPLIT.exec(line);
|
|
1064
|
+
if (!match) {
|
|
1065
|
+
return REQ_NAME.test(line) ? [line, MISSING] : ["", ""];
|
|
1066
|
+
}
|
|
1067
|
+
const name = line.slice(0, match.index).trim();
|
|
1068
|
+
if (!REQ_NAME.test(name))
|
|
1069
|
+
return ["", ""];
|
|
1070
|
+
const rest = line.slice(match.index);
|
|
1071
|
+
const version = rest.replace(/\[[^\]]*\]/g, "").trim();
|
|
1072
|
+
return [name, version || MISSING];
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
class Detector {
|
|
1076
|
+
root;
|
|
1077
|
+
map = new Map;
|
|
1078
|
+
notes = [];
|
|
1079
|
+
constructor(root) {
|
|
1080
|
+
this.root = root;
|
|
1081
|
+
}
|
|
1082
|
+
get rows() {
|
|
1083
|
+
const out = [];
|
|
1084
|
+
for (const [key, versions] of this.map) {
|
|
1085
|
+
const tab = key.indexOf("\x00");
|
|
1086
|
+
out.push({ ecosystem: key.slice(0, tab), name: key.slice(tab + 1), ...versions });
|
|
1087
|
+
}
|
|
1088
|
+
return out;
|
|
1089
|
+
}
|
|
1090
|
+
emit(ecosystem, name, declared, resolved = null, direct = true) {
|
|
1091
|
+
if (name)
|
|
1092
|
+
this.map.set(`${ecosystem}\x00${name}`, { declared: declared || MISSING, resolved, direct });
|
|
1093
|
+
}
|
|
1094
|
+
note(msg) {
|
|
1095
|
+
this.notes.push(msg);
|
|
1096
|
+
}
|
|
1097
|
+
async readToml(name) {
|
|
1098
|
+
const body = await readText(join(this.root, name));
|
|
1099
|
+
if (body === null)
|
|
1100
|
+
return null;
|
|
1101
|
+
try {
|
|
1102
|
+
const data = parse(body);
|
|
1103
|
+
return data && typeof data === "object" ? data : null;
|
|
1104
|
+
} catch (exc) {
|
|
1105
|
+
this.note(`detect: ${name} is unreadable (${exc}); skipping`);
|
|
1106
|
+
return null;
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
async readJson(name) {
|
|
1110
|
+
const body = await readText(join(this.root, name));
|
|
1111
|
+
if (body === null)
|
|
1112
|
+
return null;
|
|
1113
|
+
try {
|
|
1114
|
+
const data = JSON.parse(body);
|
|
1115
|
+
return data && typeof data === "object" && !Array.isArray(data) ? data : null;
|
|
1116
|
+
} catch (exc) {
|
|
1117
|
+
this.note(`detect: ${name} is unreadable (${exc}); skipping`);
|
|
1118
|
+
return null;
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
async readLines(name) {
|
|
1122
|
+
const body = await readText(join(this.root, name));
|
|
1123
|
+
if (body === null)
|
|
1124
|
+
return null;
|
|
1125
|
+
return body.split(/\r?\n/);
|
|
1126
|
+
}
|
|
1127
|
+
async scanNode() {
|
|
1128
|
+
const data = await this.readJson("package.json");
|
|
1129
|
+
if (!data)
|
|
1130
|
+
return;
|
|
1131
|
+
const lock = await this.readJson("package-lock.json");
|
|
1132
|
+
const locked = new Map;
|
|
1133
|
+
const packages = lock?.packages;
|
|
1134
|
+
if (packages && typeof packages === "object" && !Array.isArray(packages)) {
|
|
1135
|
+
for (const [path, entry] of Object.entries(packages)) {
|
|
1136
|
+
if (!path.startsWith("node_modules/") || !entry || typeof entry !== "object")
|
|
1137
|
+
continue;
|
|
1138
|
+
const version = entry.version;
|
|
1139
|
+
if (typeof version === "string")
|
|
1140
|
+
locked.set(path.slice("node_modules/".length), version);
|
|
1141
|
+
}
|
|
1142
|
+
} else if (lock) {
|
|
1143
|
+
this.note("detect: package-lock.json has no packages map; declared Node versions remain unresolved");
|
|
1144
|
+
}
|
|
1145
|
+
for (const field of ["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"]) {
|
|
1146
|
+
const block = data[field];
|
|
1147
|
+
if (!block || typeof block !== "object" || Array.isArray(block))
|
|
1148
|
+
continue;
|
|
1149
|
+
for (const [name, spec] of Object.entries(block)) {
|
|
1150
|
+
this.emit("npm", name, scalar(spec), locked.get(name) ?? null);
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
async scanPython() {
|
|
1155
|
+
const declared = new Map;
|
|
1156
|
+
const declare = (name, spec) => {
|
|
1157
|
+
if (!name || /^@\s*file:/i.test(spec))
|
|
1158
|
+
return;
|
|
1159
|
+
const key = canonical(name);
|
|
1160
|
+
if (!declared.has(key))
|
|
1161
|
+
declared.set(key, [name, spec]);
|
|
1162
|
+
};
|
|
1163
|
+
const pyproject = await this.readToml("pyproject.toml");
|
|
1164
|
+
if (pyproject) {
|
|
1165
|
+
this.scanPep621(pyproject.project, declare);
|
|
1166
|
+
this.scanDependencyGroups(pyproject["dependency-groups"], declare);
|
|
1167
|
+
const tool = pyproject.tool;
|
|
1168
|
+
if (tool && typeof tool === "object") {
|
|
1169
|
+
this.scanPoetry(tool.poetry, declare);
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
if (declared.size === 0) {
|
|
1173
|
+
for (const raw of await this.readLines("requirements.txt") ?? []) {
|
|
1174
|
+
const [name, version] = parseRequirement(raw);
|
|
1175
|
+
declare(name, version);
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
const locked = new Map;
|
|
1179
|
+
const local = new Set;
|
|
1180
|
+
for (const lock of ["uv.lock", "poetry.lock"]) {
|
|
1181
|
+
const data = await this.readToml(lock);
|
|
1182
|
+
if (!data)
|
|
1183
|
+
continue;
|
|
1184
|
+
const pkgs = data.package;
|
|
1185
|
+
if (!Array.isArray(pkgs)) {
|
|
1186
|
+
this.note(`detect: ${lock} has no package array; Python versions remain unresolved`);
|
|
1187
|
+
continue;
|
|
1188
|
+
}
|
|
1189
|
+
for (const entry of pkgs) {
|
|
1190
|
+
if (!entry || typeof entry !== "object")
|
|
1191
|
+
continue;
|
|
1192
|
+
const rec = entry;
|
|
1193
|
+
if (typeof rec.name !== "string" || typeof rec.version !== "string")
|
|
1194
|
+
continue;
|
|
1195
|
+
const key = canonical(rec.name);
|
|
1196
|
+
if (isLocalLockEntry(rec))
|
|
1197
|
+
local.add(key);
|
|
1198
|
+
else if (!locked.has(key))
|
|
1199
|
+
locked.set(key, [rec.name, rec.version]);
|
|
1200
|
+
}
|
|
1201
|
+
break;
|
|
1202
|
+
}
|
|
1203
|
+
for (const [key, [name, spec]] of declared) {
|
|
1204
|
+
if (!local.has(key))
|
|
1205
|
+
this.emit("pypi", name, spec, locked.get(key)?.[1] ?? null);
|
|
1206
|
+
}
|
|
1207
|
+
for (const [key, [name, version]] of locked) {
|
|
1208
|
+
if (!declared.has(key))
|
|
1209
|
+
this.emit("pypi", name, MISSING, version, false);
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
scanPep621(project, declare) {
|
|
1213
|
+
if (!project || typeof project !== "object")
|
|
1214
|
+
return;
|
|
1215
|
+
const p = project;
|
|
1216
|
+
for (const req of Array.isArray(p.dependencies) ? p.dependencies : []) {
|
|
1217
|
+
if (typeof req === "string")
|
|
1218
|
+
declare(...parseRequirement(req));
|
|
1219
|
+
}
|
|
1220
|
+
const extras = p["optional-dependencies"];
|
|
1221
|
+
if (extras && typeof extras === "object") {
|
|
1222
|
+
for (const reqs of Object.values(extras)) {
|
|
1223
|
+
for (const req of Array.isArray(reqs) ? reqs : []) {
|
|
1224
|
+
if (typeof req === "string")
|
|
1225
|
+
declare(...parseRequirement(req));
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
scanDependencyGroups(groups, declare) {
|
|
1231
|
+
if (!groups || typeof groups !== "object")
|
|
1232
|
+
return;
|
|
1233
|
+
for (const reqs of Object.values(groups)) {
|
|
1234
|
+
for (const req of Array.isArray(reqs) ? reqs : []) {
|
|
1235
|
+
if (typeof req === "string")
|
|
1236
|
+
declare(...parseRequirement(req));
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1240
|
+
scanPoetry(poetry, declare) {
|
|
1241
|
+
if (!poetry || typeof poetry !== "object")
|
|
1242
|
+
return;
|
|
1243
|
+
const p = poetry;
|
|
1244
|
+
const blocks = [p.dependencies, p["dev-dependencies"]];
|
|
1245
|
+
const groups = p.group;
|
|
1246
|
+
if (groups && typeof groups === "object") {
|
|
1247
|
+
for (const group of Object.values(groups)) {
|
|
1248
|
+
if (group && typeof group === "object") {
|
|
1249
|
+
blocks.push(group.dependencies);
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
for (const block of blocks) {
|
|
1254
|
+
if (!block || typeof block !== "object" || Array.isArray(block))
|
|
1255
|
+
continue;
|
|
1256
|
+
for (const [name, spec] of Object.entries(block)) {
|
|
1257
|
+
if (name === "python")
|
|
1258
|
+
continue;
|
|
1259
|
+
if (spec && typeof spec === "object" && !Array.isArray(spec) && "path" in spec)
|
|
1260
|
+
continue;
|
|
1261
|
+
declare(name, specVersion(spec));
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
async scanRust() {
|
|
1266
|
+
const data = await this.readToml("Cargo.toml");
|
|
1267
|
+
if (!data)
|
|
1268
|
+
return;
|
|
1269
|
+
for (const field of ["dependencies", "dev-dependencies", "build-dependencies"]) {
|
|
1270
|
+
const block = data[field];
|
|
1271
|
+
if (!block || typeof block !== "object" || Array.isArray(block))
|
|
1272
|
+
continue;
|
|
1273
|
+
for (const [name, spec] of Object.entries(block)) {
|
|
1274
|
+
this.emit("cargo", name, specVersion(spec));
|
|
1275
|
+
}
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
async scanGo() {
|
|
1279
|
+
const lines = await this.readLines("go.mod");
|
|
1280
|
+
if (!lines)
|
|
1281
|
+
return;
|
|
1282
|
+
let inBlock = false;
|
|
1283
|
+
for (const raw of lines) {
|
|
1284
|
+
const line = raw.trim();
|
|
1285
|
+
if (line.startsWith("require (") || line === "require(") {
|
|
1286
|
+
inBlock = true;
|
|
1287
|
+
continue;
|
|
1288
|
+
}
|
|
1289
|
+
if (line.startsWith(")")) {
|
|
1290
|
+
inBlock = false;
|
|
1291
|
+
continue;
|
|
1292
|
+
}
|
|
1293
|
+
if (line.startsWith("require ")) {
|
|
1294
|
+
const fields = line.split(/\s+/);
|
|
1295
|
+
this.emit("go", fields[1] ?? "", fields[2] ?? MISSING);
|
|
1296
|
+
continue;
|
|
1297
|
+
}
|
|
1298
|
+
if (inBlock) {
|
|
1299
|
+
if (!line || line.startsWith("//"))
|
|
1300
|
+
continue;
|
|
1301
|
+
const fields = line.split(/\s+/);
|
|
1302
|
+
this.emit("go", fields[0] ?? "", fields[1] ?? MISSING);
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
}
|
|
1306
|
+
async scanRuby() {
|
|
1307
|
+
const lines = await this.readLines("Gemfile");
|
|
1308
|
+
if (!lines)
|
|
1309
|
+
return;
|
|
1310
|
+
for (const raw of lines) {
|
|
1311
|
+
const match = GEM.exec(raw);
|
|
1312
|
+
if (match?.[2])
|
|
1313
|
+
this.emit("rubygems", match[2], match[4] || MISSING);
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
async scanPhp() {
|
|
1317
|
+
const data = await this.readJson("composer.json");
|
|
1318
|
+
if (!data)
|
|
1319
|
+
return;
|
|
1320
|
+
for (const field of ["require", "require-dev"]) {
|
|
1321
|
+
const block = data[field];
|
|
1322
|
+
if (!block || typeof block !== "object" || Array.isArray(block))
|
|
1323
|
+
continue;
|
|
1324
|
+
for (const [rawName, spec] of Object.entries(block)) {
|
|
1325
|
+
const name = String(rawName);
|
|
1326
|
+
if (name === "php" || name.startsWith("ext-") || name.startsWith("lib-") || name.includes(" ")) {
|
|
1327
|
+
continue;
|
|
1328
|
+
}
|
|
1329
|
+
this.emit("packagist", name, scalar(spec));
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
async scanAll() {
|
|
1334
|
+
await this.scanNode();
|
|
1335
|
+
await this.scanPython();
|
|
1336
|
+
await this.scanRust();
|
|
1337
|
+
await this.scanGo();
|
|
1338
|
+
await this.scanRuby();
|
|
1339
|
+
await this.scanPhp();
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
async function detectProject(target) {
|
|
1343
|
+
if (!isDir(target))
|
|
1344
|
+
return { ok: false, exit: 2, rows: [], stderr: `detect: '${target}' is not a directory`, coverage: { gaps: [] } };
|
|
1345
|
+
const detector = new Detector(target);
|
|
1346
|
+
await detector.scanAll();
|
|
1347
|
+
const gaps = ["Cargo.lock", "go.sum", "Pipfile.lock", "Ruby/PHP lockfiles", "workspace children"];
|
|
1348
|
+
const hasPackageLock = isFile(join(target, "package-lock.json"));
|
|
1349
|
+
if (!hasPackageLock)
|
|
1350
|
+
gaps.unshift("Node lockfiles");
|
|
1351
|
+
const notes = [...detector.notes];
|
|
1352
|
+
notes.push(`Coverage: root declarations; resolved versions from uv.lock/poetry.lock${hasPackageLock ? " and package-lock.json" : ""}; undeclared Python lock entries listed as transitive (direct=false). Unscanned: ${gaps.join(", ")}.`);
|
|
1353
|
+
notes.push("");
|
|
1354
|
+
notes.push(`detect: ${detector.rows.length} dependency declaration(s) found in ${target}`);
|
|
1355
|
+
if (detector.rows.length === 0) {
|
|
1356
|
+
notes.push("No supported manifest found (package.json, uv.lock, poetry.lock,");
|
|
1357
|
+
notes.push("requirements.txt, pyproject.toml, Cargo.toml, go.mod, Gemfile,");
|
|
1358
|
+
notes.push("composer.json).");
|
|
1359
|
+
}
|
|
1360
|
+
return { ok: true, exit: 0, rows: detector.rows, stderr: notes.join(`
|
|
1361
|
+
`), coverage: { gaps } };
|
|
1362
|
+
}
|
|
1363
|
+
|
|
1364
|
+
// lib/src/dep-bump.ts
|
|
1365
|
+
var USER_AGENT = "opencode-dep-update (+https://github.com/srobroek/opencode-plugins)";
|
|
1366
|
+
var FETCH_TIMEOUT_MS = 1e4;
|
|
1367
|
+
var SCAN_TIMEOUT_MS = 300000;
|
|
1368
|
+
|
|
1369
|
+
class ScanDeadlineError extends Error {
|
|
1370
|
+
constructor() {
|
|
1371
|
+
super("dependency scan aggregate deadline exceeded");
|
|
1372
|
+
}
|
|
1373
|
+
}
|
|
1374
|
+
|
|
1375
|
+
class RegistryError extends Error {
|
|
1376
|
+
code;
|
|
1377
|
+
constructor(message, code) {
|
|
1378
|
+
super(message);
|
|
1379
|
+
this.code = code;
|
|
1380
|
+
}
|
|
1381
|
+
}
|
|
1382
|
+
function ensureDeadline(deadline) {
|
|
1383
|
+
if (deadline !== undefined && Date.now() >= deadline)
|
|
1384
|
+
throw new ScanDeadlineError;
|
|
1385
|
+
}
|
|
1386
|
+
var NODE_VERSION = /^=?v?(?<major>0|[1-9]\d*)\.(?<minor>0|[1-9]\d*)\.(?<patch>0|[1-9]\d*)(?:-(?<pre>(?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*))*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
|
|
1387
|
+
var PYTHON_VERSION = /^(?:={1,2})?v?(?<major>\d+)(?:\.(?<minor>\d+))?(?:\.(?<patch>\d+))?(?:[-_.]?(?<phase>a|b|rc|alpha|beta|pre|preview)[-_.]?(?<phaseNumber>\d*))?(?:[-_.]?(?<post>post)[-_.]?(?<postNumber>\d*))?(?:[-_.]?(?<dev>dev)[-_.]?(?<devNumber>\d*))?(?:\+[a-z0-9]+(?:[-_.][a-z0-9]+)*)?$/i;
|
|
1388
|
+
var PYTHON_PRE_RANK = { a: 0, alpha: 0, b: 1, beta: 1, rc: 2, pre: 2, preview: 2 };
|
|
1389
|
+
function parseVersion(raw, ecosystem = "npm") {
|
|
1390
|
+
if (typeof raw !== "string")
|
|
1391
|
+
return null;
|
|
1392
|
+
const groups = (ecosystem === "pypi" ? PYTHON_VERSION : NODE_VERSION).exec(raw)?.groups;
|
|
1393
|
+
if (groups === undefined)
|
|
1394
|
+
return null;
|
|
1395
|
+
const { major, minor, patch, ...parts } = groups;
|
|
1396
|
+
const release = [Number(major), Number(minor || 0), Number(patch || 0)];
|
|
1397
|
+
return release.every(Number.isSafeInteger) ? { release, parts } : null;
|
|
1398
|
+
}
|
|
1399
|
+
function normalizeVersion(raw, ecosystem = "npm") {
|
|
1400
|
+
return parseVersion(raw, ecosystem)?.release ?? null;
|
|
1401
|
+
}
|
|
1402
|
+
function isPrerelease(raw, ecosystem = "npm") {
|
|
1403
|
+
const parts = parseVersion(raw, ecosystem)?.parts;
|
|
1404
|
+
if (parts === undefined)
|
|
1405
|
+
return false;
|
|
1406
|
+
return Boolean(ecosystem === "pypi" ? parts.phase || parts.dev : parts.pre);
|
|
1407
|
+
}
|
|
1408
|
+
function compareSuffix(a, b, ecosystem) {
|
|
1409
|
+
if (ecosystem === "pypi") {
|
|
1410
|
+
const key = (v) => {
|
|
1411
|
+
const pre = v.phase ? [PYTHON_PRE_RANK[v.phase.toLowerCase()] ?? 2, Number(v.phaseNumber || 0)] : [v.dev && !v.post ? -1 : 3, 0];
|
|
1412
|
+
return [
|
|
1413
|
+
...pre,
|
|
1414
|
+
v.post ? Number(v.postNumber || 0) : -1,
|
|
1415
|
+
v.dev ? Number(v.devNumber || 0) : Number.POSITIVE_INFINITY
|
|
1416
|
+
];
|
|
1417
|
+
};
|
|
1418
|
+
const ka = key(a);
|
|
1419
|
+
const kb = key(b);
|
|
1420
|
+
for (let i = 0;i < ka.length; i++) {
|
|
1421
|
+
const x = ka[i];
|
|
1422
|
+
const y = kb[i];
|
|
1423
|
+
if (x !== y)
|
|
1424
|
+
return x < y ? -1 : 1;
|
|
1425
|
+
}
|
|
1426
|
+
return 0;
|
|
1427
|
+
}
|
|
1428
|
+
const pa = a.pre?.split(".") ?? [];
|
|
1429
|
+
const pb = b.pre?.split(".") ?? [];
|
|
1430
|
+
if (pa.length === 0 && pb.length === 0)
|
|
1431
|
+
return 0;
|
|
1432
|
+
if (pa.length === 0)
|
|
1433
|
+
return 1;
|
|
1434
|
+
if (pb.length === 0)
|
|
1435
|
+
return -1;
|
|
1436
|
+
for (let i = 0;i < Math.min(pa.length, pb.length); i++) {
|
|
1437
|
+
const x = pa[i];
|
|
1438
|
+
const y = pb[i];
|
|
1439
|
+
if (x === y)
|
|
1440
|
+
continue;
|
|
1441
|
+
const nx = /^\d+$/.test(x);
|
|
1442
|
+
const ny = /^\d+$/.test(y);
|
|
1443
|
+
if (nx && ny)
|
|
1444
|
+
return Math.sign(Number(x) - Number(y));
|
|
1445
|
+
if (nx !== ny)
|
|
1446
|
+
return nx ? -1 : 1;
|
|
1447
|
+
return x < y ? -1 : 1;
|
|
1448
|
+
}
|
|
1449
|
+
return Math.sign(pa.length - pb.length);
|
|
1450
|
+
}
|
|
1451
|
+
function compareVersions(a, b, ecosystem = "npm") {
|
|
1452
|
+
const pa = parseVersion(a, ecosystem);
|
|
1453
|
+
const pb = parseVersion(b, ecosystem);
|
|
1454
|
+
if (pa === null || pb === null)
|
|
1455
|
+
return null;
|
|
1456
|
+
const [na, nb] = [pa.release, pb.release];
|
|
1457
|
+
const triple = Math.sign(na[0] - nb[0] || na[1] - nb[1] || na[2] - nb[2]);
|
|
1458
|
+
if (triple !== 0)
|
|
1459
|
+
return triple;
|
|
1460
|
+
return compareSuffix(pa.parts, pb.parts, ecosystem);
|
|
1461
|
+
}
|
|
1462
|
+
function classify(installed, latest, ecosystem = "npm") {
|
|
1463
|
+
const cur = normalizeVersion(installed, ecosystem);
|
|
1464
|
+
const lat = normalizeVersion(latest, ecosystem);
|
|
1465
|
+
if (cur === null || lat === null)
|
|
1466
|
+
return "UNRESOLVABLE";
|
|
1467
|
+
if (lat[0] > cur[0])
|
|
1468
|
+
return "MAJOR-ADVISORY";
|
|
1469
|
+
if (lat[0] === cur[0] && lat[1] > cur[1])
|
|
1470
|
+
return "MINOR-CHECK";
|
|
1471
|
+
if (lat[0] === cur[0] && lat[1] === cur[1] && lat[2] > cur[2])
|
|
1472
|
+
return "PATCH-SAFE";
|
|
1473
|
+
if (lat[0] === cur[0] && lat[1] === cur[1] && lat[2] === cur[2] && (compareVersions(latest, installed, ecosystem) ?? 0) > 0) {
|
|
1474
|
+
return "PATCH-SAFE";
|
|
1475
|
+
}
|
|
1476
|
+
return "CURRENT";
|
|
1477
|
+
}
|
|
1478
|
+
function pickStable(latest, installed, versions, ecosystem = "npm") {
|
|
1479
|
+
if (!isPrerelease(latest, ecosystem) || isPrerelease(installed, ecosystem))
|
|
1480
|
+
return latest;
|
|
1481
|
+
const stable = versions.filter((v) => !isPrerelease(v, ecosystem) && normalizeVersion(v, ecosystem));
|
|
1482
|
+
if (!stable.length)
|
|
1483
|
+
return latest;
|
|
1484
|
+
stable.sort((a, b) => compareVersions(b, a, ecosystem) ?? 0);
|
|
1485
|
+
return stable[0] ?? latest;
|
|
1486
|
+
}
|
|
1487
|
+
async function fetchJson(ecosystem, name, url, fixtureDir, signal, deadline) {
|
|
1488
|
+
signal?.throwIfAborted();
|
|
1489
|
+
ensureDeadline(deadline);
|
|
1490
|
+
const dir = fixtureDir ?? process.env.DEP_UPDATE_FIXTURE_DIR ?? "";
|
|
1491
|
+
if (dir) {
|
|
1492
|
+
const safe = name.replaceAll("/", "__").replaceAll("@", "__at__");
|
|
1493
|
+
const fixture = join2(dir, `${ecosystem}_${safe}.json`);
|
|
1494
|
+
if (isFile(fixture)) {
|
|
1495
|
+
const data = JSON.parse(await Bun.file(fixture).text());
|
|
1496
|
+
signal?.throwIfAborted();
|
|
1497
|
+
ensureDeadline(deadline);
|
|
1498
|
+
return data;
|
|
1499
|
+
}
|
|
1500
|
+
throw new RegistryError("fixture not found (offline simulation)");
|
|
1501
|
+
}
|
|
1502
|
+
const remaining = deadline === undefined ? FETCH_TIMEOUT_MS : deadline - Date.now();
|
|
1503
|
+
if (remaining <= 0)
|
|
1504
|
+
throw new ScanDeadlineError;
|
|
1505
|
+
const requestDeadline = AbortSignal.timeout(Math.min(FETCH_TIMEOUT_MS, remaining));
|
|
1506
|
+
const res = await fetch(url, {
|
|
1507
|
+
headers: { "User-Agent": USER_AGENT },
|
|
1508
|
+
signal: signal ? AbortSignal.any([signal, requestDeadline]) : requestDeadline
|
|
1509
|
+
});
|
|
1510
|
+
ensureDeadline(deadline);
|
|
1511
|
+
if (!res.ok)
|
|
1512
|
+
throw new RegistryError(`HTTP ${res.status}`, res.status);
|
|
1513
|
+
const data = await res.json();
|
|
1514
|
+
signal?.throwIfAborted();
|
|
1515
|
+
ensureDeadline(deadline);
|
|
1516
|
+
return data;
|
|
1517
|
+
}
|
|
1518
|
+
async function queryRegistry(ecosystem, name, installed, fixtureDir, signal, deadline) {
|
|
1519
|
+
signal?.throwIfAborted();
|
|
1520
|
+
ensureDeadline(deadline);
|
|
1521
|
+
const result = { ecosystem, name, installed, status: "UNRESOLVABLE" };
|
|
1522
|
+
try {
|
|
1523
|
+
let latest = "";
|
|
1524
|
+
let candidates = [];
|
|
1525
|
+
if (ecosystem === "pypi") {
|
|
1526
|
+
const data = await fetchJson(ecosystem, name, `https://pypi.org/pypi/${name}/json`, fixtureDir, signal, deadline);
|
|
1527
|
+
const info = data.info;
|
|
1528
|
+
const ver = info?.version;
|
|
1529
|
+
if (typeof ver !== "string" || !ver) {
|
|
1530
|
+
result.reason = "no info.version";
|
|
1531
|
+
return result;
|
|
1532
|
+
}
|
|
1533
|
+
latest = ver;
|
|
1534
|
+
const releases = data.releases ?? {};
|
|
1535
|
+
const files = releases[latest] || [];
|
|
1536
|
+
if (files.length && files.every((f) => f.yanked)) {
|
|
1537
|
+
result.status = "DISCONFIRMED";
|
|
1538
|
+
result.latest = latest;
|
|
1539
|
+
result.reason = "all files for latest are yanked on PyPI";
|
|
1540
|
+
result.class = "DISCONFIRMED";
|
|
1541
|
+
return result;
|
|
1542
|
+
}
|
|
1543
|
+
candidates = Object.keys(releases);
|
|
1544
|
+
} else if (ecosystem === "npm" || ecosystem === "node") {
|
|
1545
|
+
const data = await fetchJson(ecosystem, name, `https://registry.npmjs.org/${name}`, fixtureDir, signal, deadline);
|
|
1546
|
+
const tags = data["dist-tags"] ?? {};
|
|
1547
|
+
const ver = tags.latest;
|
|
1548
|
+
if (typeof ver !== "string" || !ver) {
|
|
1549
|
+
result.reason = "no dist-tags.latest";
|
|
1550
|
+
return result;
|
|
1551
|
+
}
|
|
1552
|
+
latest = ver;
|
|
1553
|
+
candidates = Object.keys(data.versions ?? {});
|
|
1554
|
+
} else {
|
|
1555
|
+
result.reason = `registry fetch not implemented for ${ecosystem} (advisory-only)`;
|
|
1556
|
+
return result;
|
|
1557
|
+
}
|
|
1558
|
+
ensureDeadline(deadline);
|
|
1559
|
+
latest = pickStable(latest, installed, candidates, ecosystem);
|
|
1560
|
+
const verdict = classify(installed, latest, ecosystem);
|
|
1561
|
+
result.latest = latest;
|
|
1562
|
+
result.status = verdict === "CURRENT" || verdict === "UNRESOLVABLE" ? verdict : "OK";
|
|
1563
|
+
if (verdict === "UNRESOLVABLE")
|
|
1564
|
+
result.reason = "Exact versions are required to classify an upgrade; resolve the declaration before applying.";
|
|
1565
|
+
result.class = verdict;
|
|
1566
|
+
return result;
|
|
1567
|
+
} catch (exc) {
|
|
1568
|
+
if (exc instanceof ScanDeadlineError)
|
|
1569
|
+
throw exc;
|
|
1570
|
+
signal?.throwIfAborted();
|
|
1571
|
+
ensureDeadline(deadline);
|
|
1572
|
+
if (exc instanceof RegistryError && exc.code !== undefined) {
|
|
1573
|
+
result.reason = exc.code === 401 || exc.code === 403 ? "auth-required" : `HTTP ${exc.code}`;
|
|
1574
|
+
return result;
|
|
1575
|
+
}
|
|
1576
|
+
if (exc instanceof RegistryError) {
|
|
1577
|
+
result.reason = `network error: ${exc.message}`;
|
|
1578
|
+
return result;
|
|
1579
|
+
}
|
|
1580
|
+
result.reason = exc instanceof Error ? exc.message : String(exc);
|
|
1581
|
+
return result;
|
|
1582
|
+
}
|
|
1583
|
+
}
|
|
1584
|
+
async function researchProject(target, fixtureDir, signal, timeoutMs = SCAN_TIMEOUT_MS) {
|
|
1585
|
+
const deadline = Date.now() + timeoutMs;
|
|
1586
|
+
const stopReason = () => signal?.aborted ? "cancelled" : Date.now() >= deadline ? "scan deadline reached" : undefined;
|
|
1587
|
+
if (signal?.aborted)
|
|
1588
|
+
return {
|
|
1589
|
+
exit: 0,
|
|
1590
|
+
records: [],
|
|
1591
|
+
stderr: "dep-update/research: PARTIAL: cancelled before any dependency was read.",
|
|
1592
|
+
complete: false
|
|
1593
|
+
};
|
|
1594
|
+
if (!isDir(target))
|
|
1595
|
+
return { exit: 2, records: [], stderr: `research: '${target}' is not a directory`, complete: true };
|
|
1596
|
+
const notes = ["dep-update/research: querying registries...", ""];
|
|
1597
|
+
const detected = await detectProject(target);
|
|
1598
|
+
notes.push(detected.stderr);
|
|
1599
|
+
const tallies = { OK: 0, CURRENT: 0, UNRESOLVABLE: 0, DISCONFIRMED: 0, UNCHECKED: 0 };
|
|
1600
|
+
const records = [];
|
|
1601
|
+
let stopped;
|
|
1602
|
+
const direct = detected.rows.filter((row) => row.direct);
|
|
1603
|
+
const transitive = detected.rows.length - direct.length;
|
|
1604
|
+
for (const { ecosystem, name, declared, resolved } of direct) {
|
|
1605
|
+
if (!ecosystem || !name)
|
|
1606
|
+
continue;
|
|
1607
|
+
const installed = resolved ?? declared;
|
|
1608
|
+
stopped ??= stopReason();
|
|
1609
|
+
let record;
|
|
1610
|
+
if (!stopped) {
|
|
1611
|
+
try {
|
|
1612
|
+
record = await queryRegistry(ecosystem, name, installed, fixtureDir, signal, deadline);
|
|
1613
|
+
} catch (exc) {
|
|
1614
|
+
stopped = stopReason();
|
|
1615
|
+
if (!stopped)
|
|
1616
|
+
throw exc;
|
|
1617
|
+
}
|
|
1618
|
+
}
|
|
1619
|
+
record ??= { ecosystem, name, installed, status: "UNCHECKED", reason: `not checked: ${stopped}` };
|
|
1620
|
+
records.push(record);
|
|
1621
|
+
if (record.status in tallies)
|
|
1622
|
+
tallies[record.status] += 1;
|
|
1623
|
+
}
|
|
1624
|
+
const queried = records.length - tallies.UNCHECKED;
|
|
1625
|
+
notes.push("");
|
|
1626
|
+
notes.push(`dep-update/research: ${queried} dep(s) queried`);
|
|
1627
|
+
notes.push(` classified: ${tallies.OK}`);
|
|
1628
|
+
notes.push(` already-current: ${tallies.CURRENT}`);
|
|
1629
|
+
notes.push(` unresolvable: ${tallies.UNRESOLVABLE + tallies.DISCONFIRMED}`);
|
|
1630
|
+
if (transitive > 0)
|
|
1631
|
+
notes.push(` transitive (not queried): ${transitive}`);
|
|
1632
|
+
if (stopped)
|
|
1633
|
+
notes.push(`PARTIAL: ${stopped}; ${tallies.UNCHECKED} dependenc${tallies.UNCHECKED === 1 ? "y was" : "ies were"} not checked.`);
|
|
1634
|
+
if (queried > 0 && tallies.OK === 0 && tallies.CURRENT === 0 && tallies.UNRESOLVABLE + tallies.DISCONFIRMED === queried) {
|
|
1635
|
+
notes.push("");
|
|
1636
|
+
notes.push("WARNING: no dependency versions could be classified.");
|
|
1637
|
+
notes.push("Resolve declared ranges and inspect each record's reason before planning upgrades.");
|
|
1638
|
+
}
|
|
1639
|
+
return { exit: 0, records, stderr: notes.join(`
|
|
1640
|
+
`), complete: stopped === undefined };
|
|
1641
|
+
}
|
|
1642
|
+
function which(bin) {
|
|
1643
|
+
const path = process.env.PATH ?? "";
|
|
1644
|
+
for (const dir of path.split(":")) {
|
|
1645
|
+
const cand = `${dir}/${bin}`;
|
|
1646
|
+
try {
|
|
1647
|
+
if (statSync2(cand).isFile())
|
|
1648
|
+
return cand;
|
|
1649
|
+
} catch {}
|
|
1650
|
+
}
|
|
1651
|
+
return null;
|
|
1652
|
+
}
|
|
1653
|
+
async function readTomlFile(path) {
|
|
1654
|
+
const body = await readText(path);
|
|
1655
|
+
if (body === null)
|
|
1656
|
+
return null;
|
|
1657
|
+
try {
|
|
1658
|
+
return parse(body);
|
|
1659
|
+
} catch {
|
|
1660
|
+
return null;
|
|
1661
|
+
}
|
|
1662
|
+
}
|
|
1663
|
+
function detectNodePm(root) {
|
|
1664
|
+
const override = process.env.DEP_UPDATE_PKG_MANAGER ?? "";
|
|
1665
|
+
if (override)
|
|
1666
|
+
return override;
|
|
1667
|
+
if (isFile(join2(root, "pnpm-lock.yaml")))
|
|
1668
|
+
return "pnpm";
|
|
1669
|
+
if (isFile(join2(root, "bun.lock")) || isFile(join2(root, "bun.lockb")))
|
|
1670
|
+
return "bun";
|
|
1671
|
+
if (isFile(join2(root, "yarn.lock")))
|
|
1672
|
+
return "yarn";
|
|
1673
|
+
return "npm";
|
|
1674
|
+
}
|
|
1675
|
+
function splitPin(requirement) {
|
|
1676
|
+
const body = (requirement.split(";", 1)[0] ?? "").replace(/[()]/g, "").trim();
|
|
1677
|
+
if (!body.includes("=="))
|
|
1678
|
+
return ["", ""];
|
|
1679
|
+
const idx = body.indexOf("==");
|
|
1680
|
+
const name = body.slice(0, idx).replace(/\[[^\]]*\]/g, "").trim();
|
|
1681
|
+
return [name, body.slice(idx + 2).trim()];
|
|
1682
|
+
}
|
|
1683
|
+
function pyprojectRequirements(data) {
|
|
1684
|
+
const out = [];
|
|
1685
|
+
const project = data.project;
|
|
1686
|
+
if (project && typeof project === "object") {
|
|
1687
|
+
const p = project;
|
|
1688
|
+
for (const r of Array.isArray(p.dependencies) ? p.dependencies : [])
|
|
1689
|
+
if (typeof r === "string")
|
|
1690
|
+
out.push(r);
|
|
1691
|
+
const extras = p["optional-dependencies"];
|
|
1692
|
+
if (extras && typeof extras === "object") {
|
|
1693
|
+
for (const reqs of Object.values(extras)) {
|
|
1694
|
+
for (const r of Array.isArray(reqs) ? reqs : [])
|
|
1695
|
+
if (typeof r === "string")
|
|
1696
|
+
out.push(r);
|
|
1697
|
+
}
|
|
1698
|
+
}
|
|
1699
|
+
}
|
|
1700
|
+
const groups = data["dependency-groups"];
|
|
1701
|
+
if (groups && typeof groups === "object") {
|
|
1702
|
+
for (const reqs of Object.values(groups)) {
|
|
1703
|
+
for (const r of Array.isArray(reqs) ? reqs : [])
|
|
1704
|
+
if (typeof r === "string")
|
|
1705
|
+
out.push(r);
|
|
1706
|
+
}
|
|
1707
|
+
}
|
|
1708
|
+
const tool = data.tool;
|
|
1709
|
+
const poetry = tool && typeof tool === "object" ? tool.poetry : undefined;
|
|
1710
|
+
if (poetry && typeof poetry === "object") {
|
|
1711
|
+
const p = poetry;
|
|
1712
|
+
const blocks = [p.dependencies, p["dev-dependencies"]];
|
|
1713
|
+
if (p.group && typeof p.group === "object") {
|
|
1714
|
+
for (const group of Object.values(p.group)) {
|
|
1715
|
+
if (group && typeof group === "object")
|
|
1716
|
+
blocks.push(group.dependencies);
|
|
1717
|
+
}
|
|
1718
|
+
}
|
|
1719
|
+
for (const block of blocks) {
|
|
1720
|
+
if (!block || typeof block !== "object" || Array.isArray(block))
|
|
1721
|
+
continue;
|
|
1722
|
+
for (const [name, spec] of Object.entries(block)) {
|
|
1723
|
+
const raw = spec && typeof spec === "object" ? spec.version : spec;
|
|
1724
|
+
if (typeof raw === "string")
|
|
1725
|
+
out.push(`${name}==${raw.replace(/^==/, "")}`);
|
|
1726
|
+
}
|
|
1727
|
+
}
|
|
1728
|
+
}
|
|
1729
|
+
return out;
|
|
1730
|
+
}
|
|
1731
|
+
async function checkPythonVersion(root, name, version) {
|
|
1732
|
+
const wanted = canonical(name);
|
|
1733
|
+
const pyproject = join2(root, "pyproject.toml");
|
|
1734
|
+
if (isFile(pyproject)) {
|
|
1735
|
+
const data = await readTomlFile(pyproject);
|
|
1736
|
+
if (data) {
|
|
1737
|
+
for (const requirement of pyprojectRequirements(data)) {
|
|
1738
|
+
const [reqName, reqVersion] = splitPin(requirement);
|
|
1739
|
+
if (reqName && canonical(reqName) === wanted && reqVersion === version)
|
|
1740
|
+
return true;
|
|
1741
|
+
}
|
|
1742
|
+
}
|
|
1743
|
+
}
|
|
1744
|
+
const requirements = join2(root, "requirements.txt");
|
|
1745
|
+
if (isFile(requirements)) {
|
|
1746
|
+
const text = await readText(requirements) ?? "";
|
|
1747
|
+
for (const raw of text.split(/\r?\n/)) {
|
|
1748
|
+
const [reqName, reqVersion] = splitPin((raw.split("#", 1)[0] ?? "").trim());
|
|
1749
|
+
if (reqName && canonical(reqName) === wanted && reqVersion === version)
|
|
1750
|
+
return true;
|
|
1751
|
+
}
|
|
1752
|
+
}
|
|
1753
|
+
const lock = join2(root, "uv.lock");
|
|
1754
|
+
if (isFile(lock)) {
|
|
1755
|
+
const data = await readTomlFile(lock);
|
|
1756
|
+
if (!data)
|
|
1757
|
+
return false;
|
|
1758
|
+
for (const entry of Array.isArray(data.package) ? data.package : []) {
|
|
1759
|
+
if (!entry || typeof entry !== "object")
|
|
1760
|
+
continue;
|
|
1761
|
+
const rec = entry;
|
|
1762
|
+
if (canonical(String(rec.name ?? "")) === wanted)
|
|
1763
|
+
return rec.version === version;
|
|
1764
|
+
}
|
|
1765
|
+
return false;
|
|
1766
|
+
}
|
|
1767
|
+
return false;
|
|
1768
|
+
}
|
|
1769
|
+
async function checkNodeVersion(root, name, version) {
|
|
1770
|
+
const manifest = join2(root, "package.json");
|
|
1771
|
+
if (!isFile(manifest))
|
|
1772
|
+
return false;
|
|
1773
|
+
try {
|
|
1774
|
+
const data = JSON.parse(await readText(manifest) ?? "");
|
|
1775
|
+
if (!data || typeof data !== "object")
|
|
1776
|
+
return false;
|
|
1777
|
+
const rec = data;
|
|
1778
|
+
const accepted = new Set([version, `^${version}`, `~${version}`, `=${version}`]);
|
|
1779
|
+
for (const section of ["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"]) {
|
|
1780
|
+
const block = rec[section];
|
|
1781
|
+
if (!block || typeof block !== "object" || Array.isArray(block) || !Object.hasOwn(block, name))
|
|
1782
|
+
continue;
|
|
1783
|
+
const declared = block[name];
|
|
1784
|
+
if (typeof declared === "string" && accepted.has(declared))
|
|
1785
|
+
return true;
|
|
1786
|
+
}
|
|
1787
|
+
return false;
|
|
1788
|
+
} catch {
|
|
1789
|
+
return false;
|
|
1790
|
+
}
|
|
1791
|
+
}
|
|
1792
|
+
var APPLY_TIMEOUT_MS = 600000;
|
|
1793
|
+
async function runPm(command, root, options) {
|
|
1794
|
+
if (options.signal?.aborted)
|
|
1795
|
+
return { code: 1, log: "Cancelled before spawn; no changes made." };
|
|
1796
|
+
const schedule = options.setTimeout ?? setTimeout;
|
|
1797
|
+
const clear = options.clearTimer ?? clearTimeout;
|
|
1798
|
+
return new Promise((resolve) => {
|
|
1799
|
+
const executable = command[0];
|
|
1800
|
+
if (!executable) {
|
|
1801
|
+
resolve({ code: 1, log: "No package manager command provided" });
|
|
1802
|
+
return;
|
|
1803
|
+
}
|
|
1804
|
+
const proc = spawn(executable, command.slice(1), {
|
|
1805
|
+
cwd: root,
|
|
1806
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
1807
|
+
detached: process.platform !== "win32"
|
|
1808
|
+
});
|
|
1809
|
+
const chunks = [];
|
|
1810
|
+
const limit = Math.max(1, Math.min(options.maxOutputBytes ?? 65536, 65536));
|
|
1811
|
+
let bytes = 0;
|
|
1812
|
+
let stopped = "";
|
|
1813
|
+
let settled = false;
|
|
1814
|
+
let cleanup;
|
|
1815
|
+
const kill = () => {
|
|
1816
|
+
try {
|
|
1817
|
+
if (process.platform !== "win32" && proc.pid)
|
|
1818
|
+
process.kill(-proc.pid, "SIGKILL");
|
|
1819
|
+
else
|
|
1820
|
+
proc.kill("SIGKILL");
|
|
1821
|
+
} catch {}
|
|
1822
|
+
};
|
|
1823
|
+
const finish = (code) => {
|
|
1824
|
+
if (settled)
|
|
1825
|
+
return;
|
|
1826
|
+
settled = true;
|
|
1827
|
+
clear(deadline);
|
|
1828
|
+
if (cleanup)
|
|
1829
|
+
clear(cleanup);
|
|
1830
|
+
options.signal?.removeEventListener("abort", abort);
|
|
1831
|
+
proc.stdout?.destroy();
|
|
1832
|
+
proc.stderr?.destroy();
|
|
1833
|
+
resolve({
|
|
1834
|
+
code,
|
|
1835
|
+
log: [
|
|
1836
|
+
`==> ${command.join(" ")}`,
|
|
1837
|
+
Buffer.concat(chunks).toString("utf8"),
|
|
1838
|
+
stopped && `${stopped}; partial dependency changes may remain. Inspect manifests and lockfiles before retrying.`
|
|
1839
|
+
].filter(Boolean).join(`
|
|
1840
|
+
`)
|
|
1841
|
+
});
|
|
1842
|
+
};
|
|
1843
|
+
const stop = (reason) => {
|
|
1844
|
+
if (stopped || settled)
|
|
1845
|
+
return;
|
|
1846
|
+
stopped = reason;
|
|
1847
|
+
kill();
|
|
1848
|
+
cleanup = schedule(() => finish(1), 1000);
|
|
1849
|
+
};
|
|
1850
|
+
const abort = () => stop("Cancelled");
|
|
1851
|
+
const deadline = schedule(() => stop("Package manager deadline exceeded; partial dependency changes may remain and were reported"), Math.max(1, options.timeoutMs ?? APPLY_TIMEOUT_MS));
|
|
1852
|
+
const collect = (chunk) => {
|
|
1853
|
+
const remaining = limit - bytes;
|
|
1854
|
+
if (remaining > 0) {
|
|
1855
|
+
const kept = chunk.subarray(0, remaining);
|
|
1856
|
+
chunks.push(Buffer.from(kept));
|
|
1857
|
+
bytes += kept.length;
|
|
1858
|
+
}
|
|
1859
|
+
if (chunk.length > remaining)
|
|
1860
|
+
stop("Package manager output limit exceeded");
|
|
1861
|
+
};
|
|
1862
|
+
proc.stdout.on("data", collect);
|
|
1863
|
+
proc.stderr.on("data", collect);
|
|
1864
|
+
proc.on("error", () => {
|
|
1865
|
+
stopped = "Package manager failed to start";
|
|
1866
|
+
finish(1);
|
|
1867
|
+
});
|
|
1868
|
+
proc.on("close", (code) => finish(stopped ? 1 : code ?? 1));
|
|
1869
|
+
options.signal?.addEventListener("abort", abort, { once: true });
|
|
1870
|
+
if (options.signal?.aborted)
|
|
1871
|
+
abort();
|
|
1872
|
+
});
|
|
1873
|
+
}
|
|
1874
|
+
function validOperands(ecosystem, name, version) {
|
|
1875
|
+
const semver = /^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-(?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*))*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
|
|
1876
|
+
if (["npm", "node", "pnpm", "yarn", "bun"].includes(ecosystem)) {
|
|
1877
|
+
return /^(?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*$/.test(name) && name.length <= 214 && semver.test(version);
|
|
1878
|
+
}
|
|
1879
|
+
if (ecosystem === "pypi" || ecosystem === "python") {
|
|
1880
|
+
return REQ_NAME.test(name) && /^(?:\d+!)?\d+(?:\.\d+)*(?:(?:a|b|rc)\d+)?(?:\.post\d+)?(?:\.dev\d+)?(?:\+[a-z0-9]+(?:[._-][a-z0-9]+)*)?$/i.test(version);
|
|
1881
|
+
}
|
|
1882
|
+
if (ecosystem === "cargo" || ecosystem === "rust")
|
|
1883
|
+
return /^[A-Za-z0-9][A-Za-z0-9_-]*$/.test(name) && semver.test(version);
|
|
1884
|
+
if (ecosystem === "go")
|
|
1885
|
+
return /^[A-Za-z0-9][A-Za-z0-9._~/-]*$/.test(name) && semver.test(version.replace(/^v/, ""));
|
|
1886
|
+
return false;
|
|
1887
|
+
}
|
|
1888
|
+
async function runAndConfirm(lines, command, bump, confirm) {
|
|
1889
|
+
const pm = command[0];
|
|
1890
|
+
if (!which(pm)) {
|
|
1891
|
+
lines.push(`ERROR: ${pm} not found; cannot apply dependency bump`);
|
|
1892
|
+
lines.push(` ${command.join(" ")}`);
|
|
1893
|
+
return { exit: 1, text: lines.join(`
|
|
1894
|
+
`) };
|
|
1895
|
+
}
|
|
1896
|
+
const ran = await runPm(command, bump.root, bump.options);
|
|
1897
|
+
lines.push(ran.log);
|
|
1898
|
+
if (ran.code !== 0) {
|
|
1899
|
+
lines.push(`WARN: ${pm} exited with status ${ran.code}; partial changes may remain; bump was not confirmed`);
|
|
1900
|
+
return { exit: 1, text: lines.join(`
|
|
1901
|
+
`) };
|
|
1902
|
+
}
|
|
1903
|
+
if (await confirm()) {
|
|
1904
|
+
lines.push(`OK: ${bump.name} confirmed at ${bump.version}`);
|
|
1905
|
+
return { exit: 0, text: lines.join(`
|
|
1906
|
+
`) };
|
|
1907
|
+
}
|
|
1908
|
+
lines.push(`WARN: ${bump.name}: post-apply manifest check failed - version may not have landed`);
|
|
1909
|
+
return { exit: 1, text: lines.join(`
|
|
1910
|
+
`) };
|
|
1911
|
+
}
|
|
1912
|
+
async function applyBump(ecosystem, name, version, root, options = {}) {
|
|
1913
|
+
if (!validOperands(ecosystem, name, version))
|
|
1914
|
+
return { exit: 2, text: "ERROR: unsupported ecosystem, package name, or exact version; no process started" };
|
|
1915
|
+
if (options.signal?.aborted)
|
|
1916
|
+
return { exit: 1, text: "Cancelled before spawn; no changes made." };
|
|
1917
|
+
if (!isDir(root)) {
|
|
1918
|
+
return { exit: 2, text: `ERROR: '${root}' is not a directory` };
|
|
1919
|
+
}
|
|
1920
|
+
const lines = [`dep-update/apply: ${ecosystem} ${name} -> ${version}`];
|
|
1921
|
+
const bump = { root, name, version, options };
|
|
1922
|
+
if (ecosystem === "pypi" || ecosystem === "python") {
|
|
1923
|
+
const pyprojectPath = join2(root, "pyproject.toml");
|
|
1924
|
+
if (!isFile(pyprojectPath)) {
|
|
1925
|
+
lines.push("MANUAL: no pyproject.toml; dep_apply does not edit requirements files.");
|
|
1926
|
+
lines.push(`To update manually: set ${name}==${version} in the requirements file, then reinstall it in the project's environment.`);
|
|
1927
|
+
return { exit: 0, text: lines.join(`
|
|
1928
|
+
`) };
|
|
1929
|
+
}
|
|
1930
|
+
const pyproject = await readTomlFile(pyprojectPath);
|
|
1931
|
+
const tool = pyproject?.tool;
|
|
1932
|
+
const poetry = isFile(join2(root, "poetry.lock")) || Boolean(tool && typeof tool === "object" && "poetry" in tool);
|
|
1933
|
+
const command = poetry ? ["poetry", "add", `${name}==${version}`] : ["uv", "add", ...isFile(join2(root, "uv.lock")) ? [] : ["--frozen"], `${name}==${version}`];
|
|
1934
|
+
return runAndConfirm(lines, command, bump, () => checkPythonVersion(root, name, version));
|
|
1935
|
+
}
|
|
1936
|
+
if (["npm", "node", "pnpm", "yarn", "bun"].includes(ecosystem)) {
|
|
1937
|
+
let pm = detectNodePm(root);
|
|
1938
|
+
const cmds = {
|
|
1939
|
+
pnpm: ["pnpm", "update", `${name}@${version}`],
|
|
1940
|
+
bun: ["bun", "add", `${name}@${version}`],
|
|
1941
|
+
yarn: ["yarn", "add", `${name}@${version}`],
|
|
1942
|
+
npm: ["npm", "install", `${name}@${version}`]
|
|
1943
|
+
};
|
|
1944
|
+
if (!Object.hasOwn(cmds, pm))
|
|
1945
|
+
pm = "npm";
|
|
1946
|
+
const command = cmds[pm];
|
|
1947
|
+
if (!command)
|
|
1948
|
+
return { exit: 1, text: lines.join(`
|
|
1949
|
+
`) };
|
|
1950
|
+
return runAndConfirm(lines, command, bump, () => checkNodeVersion(root, name, version));
|
|
1951
|
+
}
|
|
1952
|
+
if (ecosystem === "cargo" || ecosystem === "rust") {
|
|
1953
|
+
lines.push("ADVISORY-ONLY: Rust deps are advisory-only in this version.");
|
|
1954
|
+
lines.push(`To update manually: cargo update -p ${name} --precise ${version}`);
|
|
1955
|
+
return { exit: 0, text: lines.join(`
|
|
1956
|
+
`) };
|
|
1957
|
+
}
|
|
1958
|
+
if (ecosystem === "go") {
|
|
1959
|
+
lines.push("ADVISORY-ONLY: Go deps are advisory-only in this version.");
|
|
1960
|
+
lines.push(`To update manually: go get ${name}@${version} && go mod tidy`);
|
|
1961
|
+
return { exit: 0, text: lines.join(`
|
|
1962
|
+
`) };
|
|
1963
|
+
}
|
|
1964
|
+
lines.push(`WARN: unknown ecosystem '${ecosystem}'`);
|
|
1965
|
+
lines.push(`Cannot apply automatically. Check the registry for ${name}@${version}.`);
|
|
1966
|
+
return { exit: 0, text: lines.join(`
|
|
1967
|
+
`) };
|
|
1968
|
+
}
|
|
1969
|
+
|
|
1970
|
+
// lib/src/shell-result.ts
|
|
1971
|
+
function record(value) {
|
|
1972
|
+
return value !== null && typeof value === "object" ? value : undefined;
|
|
1973
|
+
}
|
|
1974
|
+
function shellOutput(result) {
|
|
1975
|
+
const output = record(result?.output)?.output;
|
|
1976
|
+
return typeof output === "string" ? output : undefined;
|
|
1977
|
+
}
|
|
1978
|
+
function appendResultText(result, text) {
|
|
1979
|
+
const content = result.content;
|
|
1980
|
+
if (Array.isArray(content))
|
|
1981
|
+
return { ...result, content: [...content, { type: "text", text }] };
|
|
1982
|
+
const base = typeof content === "string" ? content : shellOutput(result) ?? "";
|
|
1983
|
+
return { ...result, content: base === "" ? text : `${base}${base.endsWith(`
|
|
1984
|
+
`) ? "" : `
|
|
1985
|
+
`}${text}` };
|
|
1986
|
+
}
|
|
1987
|
+
|
|
1988
|
+
// lib/src/shell-tokenizer.ts
|
|
1989
|
+
var SEPARATORS = new Set([";", "&", "|", "(", ")", `
|
|
1990
|
+
`]);
|
|
1991
|
+
function token(value, startsQuoted = false, sawQuote = false) {
|
|
1992
|
+
return { value, startsQuoted, sawQuote };
|
|
1993
|
+
}
|
|
1994
|
+
function tokenizeShell(command, options = {}) {
|
|
1995
|
+
if (typeof command !== "string")
|
|
1996
|
+
return [];
|
|
1997
|
+
const out = [];
|
|
1998
|
+
let current = "";
|
|
1999
|
+
let started = false;
|
|
2000
|
+
let startsQuoted = false;
|
|
2001
|
+
let sawQuote = false;
|
|
2002
|
+
let quote = null;
|
|
2003
|
+
const pending = [];
|
|
2004
|
+
const flush = () => {
|
|
2005
|
+
if (!started)
|
|
2006
|
+
return;
|
|
2007
|
+
out.push(token(current, startsQuoted, sawQuote));
|
|
2008
|
+
current = "";
|
|
2009
|
+
started = false;
|
|
2010
|
+
startsQuoted = false;
|
|
2011
|
+
sawQuote = false;
|
|
2012
|
+
};
|
|
2013
|
+
for (let i = 0;i < command.length; i++) {
|
|
2014
|
+
const ch = command[i];
|
|
2015
|
+
if (quote !== null) {
|
|
2016
|
+
if (ch === quote) {
|
|
2017
|
+
quote = null;
|
|
2018
|
+
continue;
|
|
2019
|
+
}
|
|
2020
|
+
current += ch;
|
|
2021
|
+
started = true;
|
|
2022
|
+
continue;
|
|
2023
|
+
}
|
|
2024
|
+
if (ch === '"' || ch === "'") {
|
|
2025
|
+
if (!started)
|
|
2026
|
+
startsQuoted = true;
|
|
2027
|
+
started = true;
|
|
2028
|
+
sawQuote = true;
|
|
2029
|
+
quote = ch;
|
|
2030
|
+
continue;
|
|
2031
|
+
}
|
|
2032
|
+
if (ch === "\\" && i + 1 < command.length) {
|
|
2033
|
+
if (options.preserveBackslashes)
|
|
2034
|
+
current += ch;
|
|
2035
|
+
current += command[++i];
|
|
2036
|
+
started = true;
|
|
2037
|
+
continue;
|
|
2038
|
+
}
|
|
2039
|
+
if (ch === "$" && command[i + 1] === "(") {
|
|
2040
|
+
flush();
|
|
2041
|
+
out.push(token("$("));
|
|
2042
|
+
i++;
|
|
2043
|
+
continue;
|
|
2044
|
+
}
|
|
2045
|
+
if (ch === "<" && command[i + 1] === "<" && command[i + 2] === "<") {
|
|
2046
|
+
flush();
|
|
2047
|
+
out.push(token("<<<"));
|
|
2048
|
+
i += 2;
|
|
2049
|
+
continue;
|
|
2050
|
+
}
|
|
2051
|
+
if (ch === "<" && command[i + 1] === "<") {
|
|
2052
|
+
const operator = hereDocumentOperator(command, i);
|
|
2053
|
+
if (operator !== null) {
|
|
2054
|
+
flush();
|
|
2055
|
+
pending.push(operator);
|
|
2056
|
+
i = operator.end - 1;
|
|
2057
|
+
continue;
|
|
2058
|
+
}
|
|
2059
|
+
}
|
|
2060
|
+
if (ch === `
|
|
2061
|
+
`) {
|
|
2062
|
+
flush();
|
|
2063
|
+
out.push(token(ch));
|
|
2064
|
+
let bodyStart = i + 1;
|
|
2065
|
+
while (pending.length > 0) {
|
|
2066
|
+
const document = pending.shift();
|
|
2067
|
+
if (document === undefined)
|
|
2068
|
+
break;
|
|
2069
|
+
const body = hereDocumentBody(command, bodyStart, document);
|
|
2070
|
+
if (!document.quoted) {
|
|
2071
|
+
const source = command.slice(bodyStart, body.bodyEnd);
|
|
2072
|
+
if (options.hereDocumentSubstitutionsOnly)
|
|
2073
|
+
out.push(...substitutions(source, options));
|
|
2074
|
+
else
|
|
2075
|
+
out.push(...tokenizeShell(source, options));
|
|
2076
|
+
}
|
|
2077
|
+
i = body.terminatorEnd;
|
|
2078
|
+
bodyStart = i + 1;
|
|
2079
|
+
}
|
|
2080
|
+
continue;
|
|
2081
|
+
}
|
|
2082
|
+
if (/\s/.test(ch)) {
|
|
2083
|
+
flush();
|
|
2084
|
+
continue;
|
|
2085
|
+
}
|
|
2086
|
+
if (SEPARATORS.has(ch)) {
|
|
2087
|
+
flush();
|
|
2088
|
+
out.push(token(ch));
|
|
2089
|
+
continue;
|
|
2090
|
+
}
|
|
2091
|
+
current += ch;
|
|
2092
|
+
started = true;
|
|
2093
|
+
}
|
|
2094
|
+
flush();
|
|
2095
|
+
return out;
|
|
2096
|
+
}
|
|
2097
|
+
function hereDocumentOperator(command, start) {
|
|
2098
|
+
let i = start + 2;
|
|
2099
|
+
const stripTabs = command[i] === "-";
|
|
2100
|
+
if (stripTabs)
|
|
2101
|
+
i++;
|
|
2102
|
+
while (command[i] === " " || command[i] === "\t")
|
|
2103
|
+
i++;
|
|
2104
|
+
let delimiter = "";
|
|
2105
|
+
let quoted = false;
|
|
2106
|
+
let quote = null;
|
|
2107
|
+
while (i < command.length) {
|
|
2108
|
+
const ch = command[i];
|
|
2109
|
+
if (quote !== null) {
|
|
2110
|
+
if (ch === quote) {
|
|
2111
|
+
quote = null;
|
|
2112
|
+
i++;
|
|
2113
|
+
continue;
|
|
2114
|
+
}
|
|
2115
|
+
delimiter += ch;
|
|
2116
|
+
i++;
|
|
2117
|
+
continue;
|
|
2118
|
+
}
|
|
2119
|
+
if (ch === '"' || ch === "'") {
|
|
2120
|
+
quoted = true;
|
|
2121
|
+
quote = ch;
|
|
2122
|
+
i++;
|
|
2123
|
+
continue;
|
|
2124
|
+
}
|
|
2125
|
+
if (ch === "\\" && i + 1 < command.length) {
|
|
2126
|
+
quoted = true;
|
|
2127
|
+
delimiter += command[i + 1];
|
|
2128
|
+
i += 2;
|
|
2129
|
+
continue;
|
|
2130
|
+
}
|
|
2131
|
+
if (/\s|[;&|<>()]/.test(ch))
|
|
2132
|
+
break;
|
|
2133
|
+
delimiter += ch;
|
|
2134
|
+
i++;
|
|
2135
|
+
}
|
|
2136
|
+
if (quote !== null || delimiter.length === 0)
|
|
2137
|
+
return null;
|
|
2138
|
+
return { delimiter, stripTabs, quoted, end: i };
|
|
2139
|
+
}
|
|
2140
|
+
function hereDocumentBody(command, from, document) {
|
|
2141
|
+
let cursor = from;
|
|
2142
|
+
while (cursor < command.length) {
|
|
2143
|
+
let next = command.indexOf(`
|
|
2144
|
+
`, cursor);
|
|
2145
|
+
if (next === -1)
|
|
2146
|
+
next = command.length;
|
|
2147
|
+
let line = command.slice(cursor, next);
|
|
2148
|
+
if (document.stripTabs)
|
|
2149
|
+
line = line.replace(/^\t+/, "");
|
|
2150
|
+
if (line === document.delimiter)
|
|
2151
|
+
return { bodyEnd: cursor, terminatorEnd: next };
|
|
2152
|
+
if (next === command.length)
|
|
2153
|
+
break;
|
|
2154
|
+
cursor = next + 1;
|
|
2155
|
+
}
|
|
2156
|
+
return { bodyEnd: command.length, terminatorEnd: command.length };
|
|
2157
|
+
}
|
|
2158
|
+
function substitutions(body, options) {
|
|
2159
|
+
const out = [];
|
|
2160
|
+
for (let i = 0;i < body.length; i++) {
|
|
2161
|
+
const ch = body[i];
|
|
2162
|
+
if (ch === "\\") {
|
|
2163
|
+
i++;
|
|
2164
|
+
continue;
|
|
2165
|
+
}
|
|
2166
|
+
let inner;
|
|
2167
|
+
if (ch === "$" && body[i + 1] === "(") {
|
|
2168
|
+
const end = substitutionEnd(body, i + 2);
|
|
2169
|
+
inner = body.slice(i + 2, end);
|
|
2170
|
+
i = end;
|
|
2171
|
+
if (inner.startsWith("("))
|
|
2172
|
+
continue;
|
|
2173
|
+
} else if (ch === "`") {
|
|
2174
|
+
let end = i + 1;
|
|
2175
|
+
while (end < body.length && body[end] !== "`")
|
|
2176
|
+
end += body[end] === "\\" ? 2 : 1;
|
|
2177
|
+
inner = body.slice(i + 1, end);
|
|
2178
|
+
i = end;
|
|
2179
|
+
} else {
|
|
2180
|
+
continue;
|
|
2181
|
+
}
|
|
2182
|
+
out.push(token("$("), ...tokenizeShell(inner, options), token(")"));
|
|
2183
|
+
}
|
|
2184
|
+
return out;
|
|
2185
|
+
}
|
|
2186
|
+
function substitutionEnd(body, from) {
|
|
2187
|
+
let depth = 1;
|
|
2188
|
+
let quote = null;
|
|
2189
|
+
for (let i = from;i < body.length; i++) {
|
|
2190
|
+
const ch = body[i];
|
|
2191
|
+
if (quote !== null) {
|
|
2192
|
+
if (ch === quote)
|
|
2193
|
+
quote = null;
|
|
2194
|
+
else if (ch === "\\" && quote === '"')
|
|
2195
|
+
i++;
|
|
2196
|
+
continue;
|
|
2197
|
+
}
|
|
2198
|
+
if (ch === "\\")
|
|
2199
|
+
i++;
|
|
2200
|
+
else if (ch === '"' || ch === "'")
|
|
2201
|
+
quote = ch;
|
|
2202
|
+
else if (ch === "(")
|
|
2203
|
+
depth++;
|
|
2204
|
+
else if (ch === ")" && --depth === 0)
|
|
2205
|
+
return i;
|
|
2206
|
+
}
|
|
2207
|
+
return body.length;
|
|
2208
|
+
}
|
|
2209
|
+
|
|
2210
|
+
// lib/src/command-words.ts
|
|
2211
|
+
var NONE = new Set;
|
|
2212
|
+
var WRAPPERS = new Map([
|
|
2213
|
+
[
|
|
2214
|
+
"sudo",
|
|
2215
|
+
{
|
|
2216
|
+
valued: new Set([
|
|
2217
|
+
"-C",
|
|
2218
|
+
"-D",
|
|
2219
|
+
"-g",
|
|
2220
|
+
"-h",
|
|
2221
|
+
"-p",
|
|
2222
|
+
"-R",
|
|
2223
|
+
"-r",
|
|
2224
|
+
"-T",
|
|
2225
|
+
"-t",
|
|
2226
|
+
"-U",
|
|
2227
|
+
"-u",
|
|
2228
|
+
"--chdir",
|
|
2229
|
+
"--chroot",
|
|
2230
|
+
"--close-from",
|
|
2231
|
+
"--command-timeout",
|
|
2232
|
+
"--group",
|
|
2233
|
+
"--host",
|
|
2234
|
+
"--other-user",
|
|
2235
|
+
"--prompt",
|
|
2236
|
+
"--role",
|
|
2237
|
+
"--type",
|
|
2238
|
+
"--user"
|
|
2239
|
+
]),
|
|
2240
|
+
chdir: new Set(["-D", "--chdir"])
|
|
2241
|
+
}
|
|
2242
|
+
],
|
|
2243
|
+
["doas", { valued: new Set(["-C", "-u"]) }],
|
|
2244
|
+
[
|
|
2245
|
+
"env",
|
|
2246
|
+
{
|
|
2247
|
+
valued: new Set(["-C", "-L", "-P", "-S", "-U", "-u", "--chdir", "--split-string", "--unset"]),
|
|
2248
|
+
chdir: new Set(["-C", "--chdir"]),
|
|
2249
|
+
split: new Set(["-S", "--split-string"]),
|
|
2250
|
+
assignments: true
|
|
2251
|
+
}
|
|
2252
|
+
],
|
|
2253
|
+
["nice", { valued: new Set(["-n", "--adjustment"]) }],
|
|
2254
|
+
["timeout", { valued: new Set(["-k", "-s", "--kill-after", "--signal"]), operands: 1 }],
|
|
2255
|
+
["stdbuf", { valued: new Set(["-e", "-i", "-o", "--error", "--input", "--output"]) }],
|
|
2256
|
+
["exec", { valued: new Set(["-a"]) }],
|
|
2257
|
+
["command", { valued: NONE, lookup: new Set(["-V", "-v"]) }],
|
|
2258
|
+
["time", { valued: new Set(["-f", "-o", "--format", "--output"]) }],
|
|
2259
|
+
["nohup", { valued: NONE }]
|
|
2260
|
+
]);
|
|
2261
|
+
var ASSIGNMENT = /^[A-Za-z_][A-Za-z0-9_]*=/;
|
|
2262
|
+
function readOption(words, at, wrapper) {
|
|
2263
|
+
const word = words[at];
|
|
2264
|
+
if (word.startsWith("--")) {
|
|
2265
|
+
const eq = word.indexOf("=");
|
|
2266
|
+
const name = eq === -1 ? word : word.slice(0, eq);
|
|
2267
|
+
if (!wrapper.valued.has(name))
|
|
2268
|
+
return null;
|
|
2269
|
+
return eq === -1 ? { name, value: words[at + 1], span: 2 } : { name, value: word.slice(eq + 1), span: 1 };
|
|
2270
|
+
}
|
|
2271
|
+
for (let j = 1;j < word.length; j++) {
|
|
2272
|
+
const name = `-${word[j]}`;
|
|
2273
|
+
if (wrapper.lookup?.has(name))
|
|
2274
|
+
return "lookup";
|
|
2275
|
+
if (!wrapper.valued.has(name))
|
|
2276
|
+
continue;
|
|
2277
|
+
const attached = word.slice(j + 1);
|
|
2278
|
+
return attached ? { name, value: attached, span: 1 } : { name, value: words[at + 1], span: 2 };
|
|
2279
|
+
}
|
|
2280
|
+
return null;
|
|
2281
|
+
}
|
|
2282
|
+
function commandWords(input) {
|
|
2283
|
+
const { argv, directories } = stripWrappers(input);
|
|
2284
|
+
return { argv, directories };
|
|
2285
|
+
}
|
|
2286
|
+
function stripWrappers(input) {
|
|
2287
|
+
const words = [...input];
|
|
2288
|
+
const directories = [];
|
|
2289
|
+
const wrappers = [];
|
|
2290
|
+
let i = 0;
|
|
2291
|
+
while (i < words.length) {
|
|
2292
|
+
const word = words[i];
|
|
2293
|
+
if (ASSIGNMENT.test(word) || word === "--") {
|
|
2294
|
+
i++;
|
|
2295
|
+
continue;
|
|
2296
|
+
}
|
|
2297
|
+
const wrapper = WRAPPERS.get(word.slice(word.lastIndexOf("/") + 1));
|
|
2298
|
+
if (wrapper === undefined)
|
|
2299
|
+
break;
|
|
2300
|
+
wrappers.push(word.slice(word.lastIndexOf("/") + 1));
|
|
2301
|
+
i++;
|
|
2302
|
+
while (i < words.length) {
|
|
2303
|
+
const option = words[i];
|
|
2304
|
+
if (option === "--") {
|
|
2305
|
+
i++;
|
|
2306
|
+
break;
|
|
2307
|
+
}
|
|
2308
|
+
if (wrapper.assignments && ASSIGNMENT.test(option)) {
|
|
2309
|
+
i++;
|
|
2310
|
+
continue;
|
|
2311
|
+
}
|
|
2312
|
+
if (!option.startsWith("-"))
|
|
2313
|
+
break;
|
|
2314
|
+
const read = readOption(words, i, wrapper);
|
|
2315
|
+
if (read === "lookup")
|
|
2316
|
+
return { argv: [], directories, wrappers };
|
|
2317
|
+
if (read === null) {
|
|
2318
|
+
i++;
|
|
2319
|
+
continue;
|
|
2320
|
+
}
|
|
2321
|
+
if (read.value === undefined)
|
|
2322
|
+
return { argv: [], directories, wrappers };
|
|
2323
|
+
if (wrapper.split?.has(read.name)) {
|
|
2324
|
+
words.splice(i, read.span, ...tokenizeShell(read.value).map((token) => token.value));
|
|
2325
|
+
continue;
|
|
2326
|
+
}
|
|
2327
|
+
if (wrapper.chdir?.has(read.name))
|
|
2328
|
+
directories.push(read.value);
|
|
2329
|
+
i += read.span;
|
|
2330
|
+
}
|
|
2331
|
+
i += Math.min(wrapper.operands ?? 0, words.length - i);
|
|
2332
|
+
}
|
|
2333
|
+
return { argv: words.slice(i), directories, wrappers };
|
|
2334
|
+
}
|
|
2335
|
+
|
|
2336
|
+
// lib/src/tool-targets.ts
|
|
2337
|
+
var WRITE_TOOLS = new Set(["edit", "write", "patch"]);
|
|
2338
|
+
var READ_TOOLS = new Set(["read"]);
|
|
2339
|
+
var SHELL_TOOL = "shell";
|
|
2340
|
+
var SHELL_ALIASES = new Set(["bash", "Bash"]);
|
|
2341
|
+
function isShellTool(tool) {
|
|
2342
|
+
return tool === SHELL_TOOL || SHELL_ALIASES.has(tool);
|
|
2343
|
+
}
|
|
2344
|
+
var SHELL_EXECUTABLES = new Set(["bash", "sh", "zsh", "dash", "ksh"]);
|
|
2345
|
+
var SAFE_WORD = /^[A-Za-z0-9_@%+=:,./-]+$/;
|
|
2346
|
+
function quoteWord(word) {
|
|
2347
|
+
return SAFE_WORD.test(word) ? word : `'${word.replaceAll("'", `'\\''`)}'`;
|
|
2348
|
+
}
|
|
2349
|
+
function commandText(value) {
|
|
2350
|
+
if (typeof value === "string")
|
|
2351
|
+
return value;
|
|
2352
|
+
if (!Array.isArray(value) || value.length === 0 || !value.every((word) => typeof word === "string"))
|
|
2353
|
+
return;
|
|
2354
|
+
const argv = value;
|
|
2355
|
+
const executable = argv[0]?.split("/").pop() ?? "";
|
|
2356
|
+
if (argv.length === 3 && SHELL_EXECUTABLES.has(executable) && /^-l?c$/.test(argv[1] ?? ""))
|
|
2357
|
+
return argv[2];
|
|
2358
|
+
return argv.map(quoteWord).join(" ");
|
|
2359
|
+
}
|
|
2360
|
+
function flag(value) {
|
|
2361
|
+
if (typeof value === "boolean")
|
|
2362
|
+
return value;
|
|
2363
|
+
if (value === "true")
|
|
2364
|
+
return true;
|
|
2365
|
+
if (value === "false")
|
|
2366
|
+
return false;
|
|
2367
|
+
return;
|
|
2368
|
+
}
|
|
2369
|
+
function milliseconds(value) {
|
|
2370
|
+
const parsed = typeof value === "string" && value.trim() !== "" ? Number(value) : value;
|
|
2371
|
+
return typeof parsed === "number" && Number.isSafeInteger(parsed) && parsed >= 0 ? parsed : undefined;
|
|
2372
|
+
}
|
|
2373
|
+
function shellAliasInput(input) {
|
|
2374
|
+
let raw = input;
|
|
2375
|
+
if (typeof raw === "string") {
|
|
2376
|
+
try {
|
|
2377
|
+
raw = JSON.parse(raw);
|
|
2378
|
+
} catch {
|
|
2379
|
+
return input;
|
|
2380
|
+
}
|
|
2381
|
+
}
|
|
2382
|
+
const value = fields(raw);
|
|
2383
|
+
const command = commandText(value.command ?? value.cmd);
|
|
2384
|
+
if (command === undefined)
|
|
2385
|
+
return input;
|
|
2386
|
+
const out = { command };
|
|
2387
|
+
const workdir = [value.workdir, value.cwd, value.working_directory].find((dir) => typeof dir === "string" && dir !== "");
|
|
2388
|
+
if (workdir !== undefined)
|
|
2389
|
+
out.workdir = workdir;
|
|
2390
|
+
const timeout = milliseconds(value.timeout ?? value.timeout_ms);
|
|
2391
|
+
if (timeout !== undefined)
|
|
2392
|
+
out.timeout = timeout;
|
|
2393
|
+
const background = flag(value.background ?? value.run_in_background);
|
|
2394
|
+
if (background !== undefined)
|
|
2395
|
+
out.background = background;
|
|
2396
|
+
return out;
|
|
2397
|
+
}
|
|
2398
|
+
function fields(input) {
|
|
2399
|
+
return input !== null && typeof input === "object" ? input : {};
|
|
2400
|
+
}
|
|
2401
|
+
function shellCall(tool, input) {
|
|
2402
|
+
if (!isShellTool(tool))
|
|
2403
|
+
return;
|
|
2404
|
+
const value = fields(tool === SHELL_TOOL ? input : shellAliasInput(input));
|
|
2405
|
+
if (typeof value.command !== "string")
|
|
2406
|
+
return;
|
|
2407
|
+
const call = { command: value.command };
|
|
2408
|
+
if (typeof value.workdir === "string" && value.workdir)
|
|
2409
|
+
call.workdir = value.workdir;
|
|
2410
|
+
if (typeof value.timeout === "number")
|
|
2411
|
+
call.timeout = value.timeout;
|
|
2412
|
+
if (typeof value.background === "boolean")
|
|
2413
|
+
call.background = value.background;
|
|
2414
|
+
return call;
|
|
2415
|
+
}
|
|
2416
|
+
function shellCommand(tool, input) {
|
|
2417
|
+
return shellCall(tool, input)?.command;
|
|
2418
|
+
}
|
|
2419
|
+
|
|
2420
|
+
// plugins/dep-update/pi-src/index.ts
|
|
2421
|
+
import { Type } from "typebox";
|
|
2422
|
+
|
|
2423
|
+
// plugins/dep-update/opencode/src/scanner-install.ts
|
|
2424
|
+
var SCANNERS = new Set(["pip-audit", "osv-scanner", "cargo-audit", "govulncheck"]);
|
|
2425
|
+
var SCANNER_ADVISORY = "dep-update: this command installed a CVE scanner persistently. A dependency audit is read-only; " + "say in the report that the toolchain changed. Prefer `uvx pip-audit`, " + "project-pinned `go tool govulncheck ./...` or `osv-scanner scan source -r .` (OSV-Scanner v2), " + "or the package manager's own `bun audit`/`npm audit`/`pnpm audit`/`yarn npm audit`. " + "Never resolve `@latest` during a Go scanner check. `cargo-audit` has no ephemeral runner: use it only when " + "`command -v cargo-audit` finds it. A missing scanner is a reported coverage gap " + "(`scanner not available: <name>`), not a task; an unrun scanner never reads as clean.";
|
|
2426
|
+
var SEPARATORS2 = new Set([";", "&", "|", `
|
|
2427
|
+
`, "(", ")", "$("]);
|
|
2428
|
+
var KEYWORDS = new Set(["then", "do", "else", "elif", "if", "while", "until", "!", "{", "}"]);
|
|
2429
|
+
var MAX_DEPTH = 8;
|
|
2430
|
+
function simpleCommands(command, depth = 0) {
|
|
2431
|
+
if (depth > MAX_DEPTH)
|
|
2432
|
+
return [];
|
|
2433
|
+
const out = [];
|
|
2434
|
+
let words = [];
|
|
2435
|
+
const flush = () => {
|
|
2436
|
+
let at = 0;
|
|
2437
|
+
while (at < words.length && KEYWORDS.has(words[at]))
|
|
2438
|
+
at++;
|
|
2439
|
+
const argv = commandWords(words.slice(at)).argv;
|
|
2440
|
+
if (argv.length > 0)
|
|
2441
|
+
out.push(argv);
|
|
2442
|
+
words = [];
|
|
2443
|
+
};
|
|
2444
|
+
for (const token of tokenizeShell(command, { hereDocumentSubstitutionsOnly: true })) {
|
|
2445
|
+
if (token.sawQuote || !SEPARATORS2.has(token.value))
|
|
2446
|
+
words.push(token.value);
|
|
2447
|
+
else
|
|
2448
|
+
flush();
|
|
2449
|
+
}
|
|
2450
|
+
flush();
|
|
2451
|
+
for (const match of command.matchAll(/`([^`]*)`|\$\(([^()]*)\)/g)) {
|
|
2452
|
+
out.push(...simpleCommands(match[1] ?? match[2] ?? "", depth + 1));
|
|
2453
|
+
}
|
|
2454
|
+
return out;
|
|
2455
|
+
}
|
|
2456
|
+
function packageName(operand) {
|
|
2457
|
+
const bare = operand.split(/[=<>~!@[;]/, 1)[0] ?? "";
|
|
2458
|
+
return bare.slice(bare.lastIndexOf("/") + 1);
|
|
2459
|
+
}
|
|
2460
|
+
function base(word) {
|
|
2461
|
+
return word.slice(word.lastIndexOf("/") + 1);
|
|
2462
|
+
}
|
|
2463
|
+
function installOperands(argv) {
|
|
2464
|
+
const [first, ...rest] = argv;
|
|
2465
|
+
if (first === undefined)
|
|
2466
|
+
return;
|
|
2467
|
+
const name = base(first);
|
|
2468
|
+
const verb = rest.findIndex((word) => !word.startsWith("-"));
|
|
2469
|
+
const sub = rest[verb];
|
|
2470
|
+
const after = rest.slice(verb + 1);
|
|
2471
|
+
if (/^python[\d.]*$/.test(name)) {
|
|
2472
|
+
const module = rest.indexOf("-m");
|
|
2473
|
+
if (module === -1 || rest[module + 1] !== "pip")
|
|
2474
|
+
return;
|
|
2475
|
+
return installOperands(["pip", ...rest.slice(module + 2)]);
|
|
2476
|
+
}
|
|
2477
|
+
if (/^pip[\d.]*$/.test(name) || name === "pipx" || name === "brew")
|
|
2478
|
+
return sub === "install" ? after : undefined;
|
|
2479
|
+
if (name === "uv")
|
|
2480
|
+
return sub === "tool" && after[0] === "install" ? after.slice(1) : undefined;
|
|
2481
|
+
if (name === "cargo")
|
|
2482
|
+
return sub === "install" || sub === "binstall" ? after : undefined;
|
|
2483
|
+
if (name === "go")
|
|
2484
|
+
return sub === "install" ? after : undefined;
|
|
2485
|
+
if (name === "yarn")
|
|
2486
|
+
return sub === "global" && after[0] === "add" ? after.slice(1) : undefined;
|
|
2487
|
+
if (name === "npm" || name === "pnpm" || name === "bun") {
|
|
2488
|
+
const global = rest.some((word) => word === "-g" || word === "--global");
|
|
2489
|
+
return global && (sub === "i" || sub === "install" || sub === "add") ? after : undefined;
|
|
2490
|
+
}
|
|
2491
|
+
return;
|
|
2492
|
+
}
|
|
2493
|
+
function persistentScannerInstall(command) {
|
|
2494
|
+
for (const argv of simpleCommands(command)) {
|
|
2495
|
+
const operands = installOperands(argv);
|
|
2496
|
+
if (operands === undefined)
|
|
2497
|
+
continue;
|
|
2498
|
+
for (const operand of operands) {
|
|
2499
|
+
if (operand.startsWith("-"))
|
|
2500
|
+
continue;
|
|
2501
|
+
const name = packageName(operand);
|
|
2502
|
+
if (SCANNERS.has(name))
|
|
2503
|
+
return name;
|
|
2504
|
+
}
|
|
2505
|
+
}
|
|
2506
|
+
return;
|
|
2507
|
+
}
|
|
2508
|
+
|
|
2509
|
+
// plugins/dep-update/shared/scan.ts
|
|
2510
|
+
var CLASS_ORDER = ["PATCH-SAFE", "MINOR-CHECK", "MAJOR-ADVISORY"];
|
|
2511
|
+
var REPORTED = new Set(["UNRESOLVABLE", "DISCONFIRMED", "UNCHECKED"]);
|
|
2512
|
+
function formatScan(records, stderr) {
|
|
2513
|
+
const upgradable = records.filter((record) => record.status === "OK");
|
|
2514
|
+
const lines = [];
|
|
2515
|
+
for (const classification of CLASS_ORDER) {
|
|
2516
|
+
const bucket = upgradable.filter((record) => record.class === classification).sort((a, b) => a.name.localeCompare(b.name));
|
|
2517
|
+
for (const record of bucket) {
|
|
2518
|
+
lines.push(`${classification.padEnd(15)} ${record.name} ${record.installed} -> ${record.latest} (${record.ecosystem})`);
|
|
2519
|
+
}
|
|
2520
|
+
}
|
|
2521
|
+
for (const record of records) {
|
|
2522
|
+
if (!REPORTED.has(record.status))
|
|
2523
|
+
continue;
|
|
2524
|
+
lines.push(`${record.status.padEnd(15)} ${record.name} ${record.installed} -> ${record.latest ?? "unknown"} (${record.ecosystem}): ${record.reason ?? "not classified"}`);
|
|
2525
|
+
}
|
|
2526
|
+
const unchecked = records.filter((record) => record.status === "UNCHECKED").length;
|
|
2527
|
+
const skipped = records.length - upgradable.length - unchecked;
|
|
2528
|
+
lines.push(`-- ${upgradable.length} upgradable, ${skipped} current/unresolvable, ${unchecked} unchecked --`);
|
|
2529
|
+
if (stderr.trim())
|
|
2530
|
+
lines.push(stderr.trim());
|
|
2531
|
+
return { text: lines.join(`
|
|
2532
|
+
`), summary: { upgradable: upgradable.length, skipped, unchecked } };
|
|
2533
|
+
}
|
|
2534
|
+
|
|
2535
|
+
// plugins/dep-update/pi-src/index.ts
|
|
2536
|
+
function projectDir(base, path) {
|
|
2537
|
+
if (!path)
|
|
2538
|
+
return base;
|
|
2539
|
+
return isAbsolute(path) ? path : resolve(base, path);
|
|
2540
|
+
}
|
|
2541
|
+
var scanParameters = Type.Object({ path: Type.Optional(Type.String({ description: "Project root to scan; defaults to the session directory" })) }, { additionalProperties: false });
|
|
2542
|
+
var applyParameters = Type.Object({
|
|
2543
|
+
ecosystem: Type.String({ description: "pypi, npm, cargo, or go" }),
|
|
2544
|
+
name: Type.String({ description: "Package name" }),
|
|
2545
|
+
version: Type.String({ description: "Exact target version to pin" }),
|
|
2546
|
+
path: Type.Optional(Type.String({ description: "Project root; defaults to the session directory" }))
|
|
2547
|
+
}, { required: ["ecosystem", "name", "version"], additionalProperties: false });
|
|
2548
|
+
async function applyApprovedBump(params, signal, ctx) {
|
|
2549
|
+
const root = projectDir(ctx.cwd, params.path);
|
|
2550
|
+
if (!validOperands(params.ecosystem, params.name, params.version)) {
|
|
2551
|
+
return { text: "dep_apply: unsupported ecosystem, package name, or exact version; no process started", exit: 2 };
|
|
2552
|
+
}
|
|
2553
|
+
if (signal?.aborted)
|
|
2554
|
+
return { text: "dep_apply stopped before it started; no changes made.", exit: 1 };
|
|
2555
|
+
if (!ctx.hasUI)
|
|
2556
|
+
return { text: "dep_apply requires an interactive UI to approve this exact bump; no changes made.", exit: 1 };
|
|
2557
|
+
const resource = `${params.name}@${params.version}`;
|
|
2558
|
+
const approved = await ctx.ui.confirm("Apply dependency bump?", `Apply ${params.ecosystem} bump ${resource} in ${root}? A failed or cancelled package-manager run can leave partial changes.`, { signal });
|
|
2559
|
+
if (!approved)
|
|
2560
|
+
return { text: `dep_apply cancelled; ${resource} was not applied.`, exit: 1 };
|
|
2561
|
+
return applyBump(params.ecosystem, params.name, params.version, root, { signal });
|
|
2562
|
+
}
|
|
2563
|
+
function scannerInstallResult(event) {
|
|
2564
|
+
if (event.isError)
|
|
2565
|
+
return;
|
|
2566
|
+
const command = shellCommand(event.toolName, event.input);
|
|
2567
|
+
if (command === undefined || persistentScannerInstall(command) === undefined)
|
|
2568
|
+
return;
|
|
2569
|
+
const appended = appendResultText({ content: event.content.filter((part) => part.type === "text") }, SCANNER_ADVISORY);
|
|
2570
|
+
if (typeof appended.content === "string")
|
|
2571
|
+
return [...event.content, { type: "text", text: appended.content }];
|
|
2572
|
+
const advisory = appended.content?.at(-1);
|
|
2573
|
+
return advisory?.type === "text" ? [...event.content, { type: "text", text: advisory.text }] : undefined;
|
|
2574
|
+
}
|
|
2575
|
+
function pi_src_default(pi) {
|
|
2576
|
+
pi.registerTool({
|
|
2577
|
+
name: "dep_scan",
|
|
2578
|
+
label: "Dependency Scan",
|
|
2579
|
+
description: "Read-only: classify a project's dependency bumps as PATCH-SAFE, MINOR-CHECK or MAJOR-ADVISORY. Enumerates declared dependencies and queries PyPI/npm for latest versions. A stopped scan returns an incomplete report with unchecked dependencies. Rust and Go deps are advisory-only.",
|
|
2580
|
+
parameters: scanParameters,
|
|
2581
|
+
async execute(_toolCallId, params, signal, _onUpdate, ctx) {
|
|
2582
|
+
const dir = projectDir(ctx.cwd, params.path);
|
|
2583
|
+
const { exit, records, stderr, complete } = await researchProject(dir, undefined, signal);
|
|
2584
|
+
if (exit !== 0) {
|
|
2585
|
+
return { content: [{ type: "text", text: `dep_scan failed (exit ${exit}):
|
|
2586
|
+
${stderr}` }], details: { exit } };
|
|
2587
|
+
}
|
|
2588
|
+
const { text, summary } = formatScan(records, stderr);
|
|
2589
|
+
return { content: [{ type: "text", text }], details: { records, complete, summary } };
|
|
2590
|
+
}
|
|
2591
|
+
});
|
|
2592
|
+
pi.registerTool({
|
|
2593
|
+
name: "dep_apply",
|
|
2594
|
+
label: "Apply Dependency Bump",
|
|
2595
|
+
description: "Apply one exact dependency bump with the ecosystem package manager after explicit user approval. The run is bounded to 10 minutes; failure or cancellation can leave partial changes.",
|
|
2596
|
+
parameters: applyParameters,
|
|
2597
|
+
async execute(_toolCallId, params, signal, _onUpdate, ctx) {
|
|
2598
|
+
const result = await applyApprovedBump(params, signal, ctx);
|
|
2599
|
+
return { content: [{ type: "text", text: result.text }], details: { exit: result.exit } };
|
|
2600
|
+
}
|
|
2601
|
+
});
|
|
2602
|
+
pi.on("tool_result", (event) => {
|
|
2603
|
+
const content = scannerInstallResult(event);
|
|
2604
|
+
return content === undefined ? undefined : { content };
|
|
2605
|
+
});
|
|
2606
|
+
}
|
|
2607
|
+
export {
|
|
2608
|
+
applyApprovedBump,
|
|
2609
|
+
pi_src_default as default,
|
|
2610
|
+
scannerInstallResult
|
|
2611
|
+
};
|