@kaynooo/pkg-tools 0.0.0-stage → 0.2.1
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/LICENSE +21 -0
- package/README.md +25 -2
- package/dist/cli.js +1355 -0
- package/package.json +33 -4
package/dist/cli.js
ADDED
|
@@ -0,0 +1,1355 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
// @bun
|
|
3
|
+
|
|
4
|
+
// src/cli.ts
|
|
5
|
+
import process7 from "process";
|
|
6
|
+
|
|
7
|
+
// ../kit/src/args.ts
|
|
8
|
+
import process3 from "process";
|
|
9
|
+
import { parseArgs } from "util";
|
|
10
|
+
|
|
11
|
+
// ../kit/src/format.ts
|
|
12
|
+
import process2 from "process";
|
|
13
|
+
|
|
14
|
+
// ../kit/src/style.ts
|
|
15
|
+
import process from "process";
|
|
16
|
+
|
|
17
|
+
// ../../node_modules/.bun/@kaynooo+utils@2.31.0+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-mtetydvc.js
|
|
18
|
+
function x(s) {
|
|
19
|
+
let r = s.startsWith("#") ? s.slice(1).toLowerCase() : s.toLowerCase();
|
|
20
|
+
if (!/^[a-f0-9]+$/.test(r))
|
|
21
|
+
return [0, 0, 0];
|
|
22
|
+
let t = r.length, n = (c) => Number.parseInt(c, 16);
|
|
23
|
+
if (t === 3 || t === 4) {
|
|
24
|
+
let c = n(r[0] + r[0]), u = n(r[1] + r[1]), h = n(r[2] + r[2]), g = t === 4 ? n(r[3] + r[3]) : undefined;
|
|
25
|
+
return g !== undefined ? [c, u, h, g] : [c, u, h];
|
|
26
|
+
}
|
|
27
|
+
if (t !== 6 && t !== 8)
|
|
28
|
+
throw Error(`Invalid hex color length: ${t}`);
|
|
29
|
+
let a = n(r.slice(0, 2)), b = n(r.slice(2, 4)), o = n(r.slice(4, 6)), y = t === 8 ? n(r.slice(6, 8)) : undefined;
|
|
30
|
+
if ([a, b, o].some(Number.isNaN) || y !== undefined && Number.isNaN(y))
|
|
31
|
+
throw Error(`Invalid hex color value: ${s}`);
|
|
32
|
+
return y !== undefined ? [a, b, o, y] : [a, b, o];
|
|
33
|
+
}
|
|
34
|
+
function A(s) {
|
|
35
|
+
let [r, t, n, a] = s;
|
|
36
|
+
if (a)
|
|
37
|
+
return `#${(r << 24 | t << 16 | n << 8 | Math.round((a ?? 1) * 255)).toString(16).padStart(8, "0").toUpperCase()}`;
|
|
38
|
+
return `#${(r << 16 | t << 8 | n).toString(16).padStart(6, "0").toUpperCase()}`;
|
|
39
|
+
}
|
|
40
|
+
function R(s, r, t) {
|
|
41
|
+
s = (s % 360 + 360) % 360, t /= 100;
|
|
42
|
+
let n = r * Math.min(t, 1 - t) / 100, a = (b) => {
|
|
43
|
+
let o = (b + s / 30) % 12, y = t - n * Math.max(Math.min(o - 3, 9 - o, 1), -1);
|
|
44
|
+
return Math.round(255 * y);
|
|
45
|
+
};
|
|
46
|
+
return [a(0), a(8), a(4)];
|
|
47
|
+
}
|
|
48
|
+
function k(s) {
|
|
49
|
+
let [r, t, n] = s;
|
|
50
|
+
r /= 255, t /= 255, n /= 255;
|
|
51
|
+
let a = Math.max(r, t, n), b = Math.min(r, t, n), o = 0, y = 0, c = (a + b) / 2;
|
|
52
|
+
if (a !== b) {
|
|
53
|
+
let u = a - b;
|
|
54
|
+
if (y = c > 0 && c < 1 ? u / (1 - Math.abs(2 * c - 1)) : 0, a === r)
|
|
55
|
+
o = (t - n) / u + (t < n ? 6 : 0);
|
|
56
|
+
else if (a === t)
|
|
57
|
+
o = (n - r) / u + 2;
|
|
58
|
+
else
|
|
59
|
+
o = (r - t) / u + 4;
|
|
60
|
+
o /= 6;
|
|
61
|
+
}
|
|
62
|
+
return [Math.round(o * 360), Math.round(y * 100), Math.round(c * 100)];
|
|
63
|
+
}
|
|
64
|
+
function H(s, r, t) {
|
|
65
|
+
s = (s % 360 + 360) % 360, r /= 100, t /= 100;
|
|
66
|
+
let n = (a) => {
|
|
67
|
+
let b = (a + s / 60) % 6, o = t - t * r * Math.max(Math.min(b, 4 - b, 1), 0);
|
|
68
|
+
return Math.round(255 * o);
|
|
69
|
+
};
|
|
70
|
+
return [n(5), n(3), n(1)];
|
|
71
|
+
}
|
|
72
|
+
function f(s) {
|
|
73
|
+
let [r, t, n] = s;
|
|
74
|
+
r /= 255, t /= 255, n /= 255;
|
|
75
|
+
let a = Math.max(r, t, n), b = Math.min(r, t, n), o = a - b, y = 0, c = a === 0 ? 0 : o / a, u = a;
|
|
76
|
+
if (o !== 0) {
|
|
77
|
+
if (a === r)
|
|
78
|
+
y = (t - n) / o + (t < n ? 6 : 0);
|
|
79
|
+
else if (a === t)
|
|
80
|
+
y = (n - r) / o + 2;
|
|
81
|
+
else
|
|
82
|
+
y = (r - t) / o + 4;
|
|
83
|
+
y /= 6;
|
|
84
|
+
}
|
|
85
|
+
return [Math.round(y * 360), Math.round(c * 100), Math.round(u * 100)];
|
|
86
|
+
}
|
|
87
|
+
function O(s) {
|
|
88
|
+
let r = s[0] / 255, t = s[1] / 255, n = s[2] / 255, a = 1 - Math.max(r, t, n);
|
|
89
|
+
if (a === 1)
|
|
90
|
+
return [0, 0, 0, 100];
|
|
91
|
+
let b = (1 - r - a) / (1 - a), o = (1 - t - a) / (1 - a), y = (1 - n - a) / (1 - a);
|
|
92
|
+
return [Math.round(b * 100), Math.round(o * 100), Math.round(y * 100), Math.round(a * 100)];
|
|
93
|
+
}
|
|
94
|
+
function v(s, r, t, n) {
|
|
95
|
+
return s /= 100, r /= 100, t /= 100, n /= 100, [Math.round(255 * (1 - s) * (1 - n)), Math.round(255 * (1 - r) * (1 - n)), Math.round(255 * (1 - t) * (1 - n))];
|
|
96
|
+
}
|
|
97
|
+
var m = (s) => s <= 0.04045 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
|
|
98
|
+
var p = (s) => s <= 0.0031308 ? 12.92 * s : 1.055 * s ** 0.4166666666666667 - 0.055;
|
|
99
|
+
var i = (s, r) => Math.round(s * 10 ** r) / 10 ** r;
|
|
100
|
+
function T(s) {
|
|
101
|
+
let r = m(s[0] / 255), t = m(s[1] / 255), n = m(s[2] / 255), a = Math.cbrt(0.4122214708 * r + 0.5363325363 * t + 0.0514459929 * n), b = Math.cbrt(0.2119034982 * r + 0.6806995451 * t + 0.1073969566 * n), o = Math.cbrt(0.0883024619 * r + 0.2817188376 * t + 0.6299787005 * n);
|
|
102
|
+
return [i(0.2104542553 * a + 0.793617785 * b - 0.0040720468 * o, 4), i(1.9779984951 * a - 2.428592205 * b + 0.4505937099 * o, 4), i(0.0259040371 * a + 0.7827717662 * b - 0.808675766 * o, 4)];
|
|
103
|
+
}
|
|
104
|
+
function M(s, r, t) {
|
|
105
|
+
let n = (s + 0.3963377774 * r + 0.2158037573 * t) ** 3, a = (s - 0.1055613458 * r - 0.0638541728 * t) ** 3, b = (s - 0.0894841775 * r - 1.291485548 * t) ** 3, o = p(4.0767416621 * n - 3.3077115913 * a + 0.2309699292 * b), y = p(-1.2684380046 * n + 2.6097574011 * a - 0.3413193965 * b), c = p(-0.0041960863 * n - 0.7034186147 * a + 1.707614701 * b), u = (h) => Math.min(255, Math.max(0, Math.round(h * 255)));
|
|
106
|
+
return [u(o), u(y), u(c)];
|
|
107
|
+
}
|
|
108
|
+
function d(s) {
|
|
109
|
+
let [r, t, n] = T(s), a = Math.sqrt(t * t + n * n), b = (Math.atan2(n, t) * 180 / Math.PI + 360) % 360;
|
|
110
|
+
return [i(r, 4), i(a, 4), i(b, 2)];
|
|
111
|
+
}
|
|
112
|
+
function C(s, r, t) {
|
|
113
|
+
let n = t * Math.PI / 180;
|
|
114
|
+
return M(s, r * Math.cos(n), r * Math.sin(n));
|
|
115
|
+
}
|
|
116
|
+
function l(s) {
|
|
117
|
+
let r = s / 255;
|
|
118
|
+
return r <= 0.03928 ? r / 12.92 : ((r + 0.055) / 1.055) ** 2.4;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
class e {
|
|
122
|
+
r;
|
|
123
|
+
g;
|
|
124
|
+
b;
|
|
125
|
+
a;
|
|
126
|
+
constructor(s, r, t, n = 1) {
|
|
127
|
+
this.r = s, this.g = r, this.b = t, this.a = n;
|
|
128
|
+
}
|
|
129
|
+
static from(s, r) {
|
|
130
|
+
if (s === "hex") {
|
|
131
|
+
let [t, n, a, b] = x(r);
|
|
132
|
+
return new e(t, n, a, b);
|
|
133
|
+
}
|
|
134
|
+
if (s === "rgb") {
|
|
135
|
+
if (Array.isArray(r)) {
|
|
136
|
+
let [o, y, c, u] = r;
|
|
137
|
+
return new e(o, y, c, u);
|
|
138
|
+
}
|
|
139
|
+
let { r: t, g: n, b: a, a: b } = r;
|
|
140
|
+
return new e(t, n, a, b);
|
|
141
|
+
}
|
|
142
|
+
if (s === "hsl") {
|
|
143
|
+
let t, n, a, b;
|
|
144
|
+
if (Array.isArray(r))
|
|
145
|
+
[t, n, a, b] = r;
|
|
146
|
+
else
|
|
147
|
+
({ h: t, s: n, l: a, a: b } = r);
|
|
148
|
+
let [o, y, c] = R(t, n, a);
|
|
149
|
+
return new e(o, y, c, b);
|
|
150
|
+
}
|
|
151
|
+
if (s === "hsv") {
|
|
152
|
+
let t, n, a, b;
|
|
153
|
+
if (Array.isArray(r))
|
|
154
|
+
[t, n, a, b] = r;
|
|
155
|
+
else
|
|
156
|
+
({ h: t, s: n, v: a, a: b } = r);
|
|
157
|
+
let [o, y, c] = H(t, n, a);
|
|
158
|
+
return new e(o, y, c, b);
|
|
159
|
+
}
|
|
160
|
+
if (s === "cmyk") {
|
|
161
|
+
let t, n, a, b, o;
|
|
162
|
+
if (Array.isArray(r))
|
|
163
|
+
[t, n, a, b, o] = r;
|
|
164
|
+
else
|
|
165
|
+
({ c: t, m: n, y: a, k: b, a: o } = r);
|
|
166
|
+
let [y, c, u] = v(t, n, a, b);
|
|
167
|
+
return new e(y, c, u, o);
|
|
168
|
+
}
|
|
169
|
+
if (s === "oklch") {
|
|
170
|
+
let t, n, a, b;
|
|
171
|
+
if (Array.isArray(r))
|
|
172
|
+
[t, n, a, b] = r;
|
|
173
|
+
else
|
|
174
|
+
({ l: t, c: n, h: a, a: b } = r);
|
|
175
|
+
let [o, y, c] = C(t, n, a);
|
|
176
|
+
return new e(o, y, c, b);
|
|
177
|
+
}
|
|
178
|
+
if (s === "oklab") {
|
|
179
|
+
let t, n, a, b;
|
|
180
|
+
if (Array.isArray(r))
|
|
181
|
+
[t, n, a, b] = r;
|
|
182
|
+
else
|
|
183
|
+
({ l: t, a: n, b: a, alpha: b } = r);
|
|
184
|
+
let [o, y, c] = M(t, n, a);
|
|
185
|
+
return new e(o, y, c, b);
|
|
186
|
+
}
|
|
187
|
+
throw Error("Invalid input");
|
|
188
|
+
}
|
|
189
|
+
to(s) {
|
|
190
|
+
switch (s) {
|
|
191
|
+
case "rgb":
|
|
192
|
+
return [this.r, this.g, this.b];
|
|
193
|
+
case "rgba":
|
|
194
|
+
return [this.r, this.g, this.b, this.a];
|
|
195
|
+
case "hex":
|
|
196
|
+
return A([this.r, this.g, this.b]);
|
|
197
|
+
case "hexa":
|
|
198
|
+
return A([this.r, this.g, this.b, this.a]);
|
|
199
|
+
case "hsl":
|
|
200
|
+
return k([this.r, this.g, this.b]);
|
|
201
|
+
case "hsla":
|
|
202
|
+
return [...k([this.r, this.g, this.b]), this.a];
|
|
203
|
+
case "hsv":
|
|
204
|
+
return f([this.r, this.g, this.b]);
|
|
205
|
+
case "hsva":
|
|
206
|
+
return [...f([this.r, this.g, this.b]), this.a];
|
|
207
|
+
case "cmyk":
|
|
208
|
+
return O([this.r, this.g, this.b]);
|
|
209
|
+
case "cmyka":
|
|
210
|
+
return [...O([this.r, this.g, this.b]), this.a];
|
|
211
|
+
case "oklch":
|
|
212
|
+
return d([this.r, this.g, this.b]);
|
|
213
|
+
case "oklcha":
|
|
214
|
+
return [...d([this.r, this.g, this.b]), this.a];
|
|
215
|
+
case "oklab":
|
|
216
|
+
return T([this.r, this.g, this.b]);
|
|
217
|
+
case "oklaba":
|
|
218
|
+
return [...T([this.r, this.g, this.b]), this.a];
|
|
219
|
+
default:
|
|
220
|
+
return [this.r, this.g, this.b];
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
getLuminance() {
|
|
224
|
+
let s = l(this.r), r = l(this.g), t = l(this.b);
|
|
225
|
+
return 0.2126 * s + 0.7152 * r + 0.0722 * t;
|
|
226
|
+
}
|
|
227
|
+
contrastRatio(s) {
|
|
228
|
+
let r = this.getLuminance(), t = s.getLuminance(), [n, a] = r >= t ? [r, t] : [t, r];
|
|
229
|
+
return (n + 0.05) / (a + 0.05);
|
|
230
|
+
}
|
|
231
|
+
bestContrastForeground() {
|
|
232
|
+
let s = new e(255, 255, 255, 1), r = new e(0, 0, 0, 1), t = this.contrastRatio(s), n = this.contrastRatio(r);
|
|
233
|
+
return t >= n ? s : r;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// ../../node_modules/.bun/@kaynooo+utils@2.31.0+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-y1msbssb.js
|
|
238
|
+
var r = 39;
|
|
239
|
+
var o = 49;
|
|
240
|
+
var f2 = "\x1B[";
|
|
241
|
+
var C2 = { reset: [0, 0], bold: [1, 22], dim: [2, 22], italic: [3, 23], underline: [4, 24], inverse: [7, 27], hidden: [8, 28], strikethrough: [9, 29], black: [30, r], red: [31, r], green: [32, r], yellow: [33, r], blue: [34, r], magenta: [35, r], cyan: [36, r], white: [37, r], gray: [90, r], grey: [90, r], blackBright: [90, r], redBright: [91, r], greenBright: [92, r], yellowBright: [93, r], blueBright: [94, r], magentaBright: [95, r], cyanBright: [96, r], whiteBright: [97, r], bgBlack: [40, o], bgRed: [41, o], bgGreen: [42, o], bgYellow: [43, o], bgBlue: [44, o], bgMagenta: [45, o], bgCyan: [46, o], bgWhite: [47, o], bgBlackBright: [100, o], bgRedBright: [101, o], bgGreenBright: [102, o], bgYellowBright: [103, o], bgBlueBright: [104, o], bgMagentaBright: [105, o], bgCyanBright: [106, o], bgWhiteBright: [107, o], rgb: (i, n, a, l = "fg") => [`${l === "fg" ? 38 : 48};2;${i};${n};${a}`, l === "fg" ? r : o], hex: (i, n = "fg") => {
|
|
242
|
+
let [a, l, s] = e.from("hex", i).to("rgb");
|
|
243
|
+
return [`${n === "fg" ? 38 : 48};2;${a};${l};${s}`, n === "fg" ? r : o];
|
|
244
|
+
}, ansi256: (i, n = "fg") => [`${n === "fg" ? 38 : 48};5;${i}`, n === "fg" ? r : o] };
|
|
245
|
+
var b = new Set(["", "1", "2", "3", "true"]);
|
|
246
|
+
function h(i, n = globalThis.process?.env ?? {}) {
|
|
247
|
+
if (n.FORCE_COLOR !== undefined)
|
|
248
|
+
return b.has(n.FORCE_COLOR);
|
|
249
|
+
if (n.NO_COLOR !== undefined || n.NODE_DISABLE_COLORS !== undefined || n.TERM === "dumb")
|
|
250
|
+
return false;
|
|
251
|
+
return i?.isTTY === true;
|
|
252
|
+
}
|
|
253
|
+
function d2(i, n, a) {
|
|
254
|
+
if (!h(a.stream ?? globalThis.process?.stdout, a.env))
|
|
255
|
+
return n;
|
|
256
|
+
let l = "", s = "";
|
|
257
|
+
for (let g = 0, y = i.length;g < y; g++) {
|
|
258
|
+
let [c, p] = i[g];
|
|
259
|
+
l += `${f2}${c}m`, s = `${f2}${p}m${s}`;
|
|
260
|
+
}
|
|
261
|
+
return l + n + s;
|
|
262
|
+
}
|
|
263
|
+
function u(i, n = []) {
|
|
264
|
+
return new Proxy((l) => d2(n, l, i), { get(l, s) {
|
|
265
|
+
let g = C2[s];
|
|
266
|
+
if (Array.isArray(g))
|
|
267
|
+
return u(i, [...n, g]);
|
|
268
|
+
if (typeof g === "function")
|
|
269
|
+
return (...y) => u(i, [...n, g(...y)]);
|
|
270
|
+
throw Error(`Unknown style: ${String(s)}`);
|
|
271
|
+
} });
|
|
272
|
+
}
|
|
273
|
+
function le(i = {}) {
|
|
274
|
+
return u(i);
|
|
275
|
+
}
|
|
276
|
+
var t = le();
|
|
277
|
+
|
|
278
|
+
// ../kit/src/style.ts
|
|
279
|
+
function takesControlCodes(stream, env = process.env) {
|
|
280
|
+
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb";
|
|
281
|
+
}
|
|
282
|
+
function paint(stream, env = process.env) {
|
|
283
|
+
return le({ stream: { isTTY: takesControlCodes(stream, env) }, env });
|
|
284
|
+
}
|
|
285
|
+
var STATUSES = {
|
|
286
|
+
passed: { symbol: "\u2713", words: ["passed", "success", "succeeded", "ok"], paint: (colors) => colors.green },
|
|
287
|
+
failed: { symbol: "\u2717", words: ["failed", "failure", "error", "errored"], paint: (colors) => colors.red },
|
|
288
|
+
running: { symbol: "\u25CF", words: ["running", "in_progress", "started"], paint: (colors) => colors.cyan },
|
|
289
|
+
queued: { symbol: "\u25CB", words: ["queued", "waiting", "pending", "created", "blocked", "scheduled"], paint: (colors) => colors.yellow },
|
|
290
|
+
skipped: { symbol: "-", words: ["skipped", "cancelled", "canceled", "manual"], paint: (colors) => colors.dim }
|
|
291
|
+
};
|
|
292
|
+
var STATUS_OF = new Map(Object.entries(STATUSES).flatMap(([status, { words }]) => words.map((word) => [word, status])));
|
|
293
|
+
|
|
294
|
+
// ../kit/src/format.ts
|
|
295
|
+
var UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
|
|
296
|
+
function formatSeconds(total) {
|
|
297
|
+
let rest = Math.max(0, Math.round(total));
|
|
298
|
+
const amounts = UNITS.map(([unit, size]) => {
|
|
299
|
+
const amount = Math.floor(rest / size);
|
|
300
|
+
rest -= amount * size;
|
|
301
|
+
return `${amount}${unit}`;
|
|
302
|
+
});
|
|
303
|
+
const first = amounts.findIndex((amount) => !amount.startsWith("0"));
|
|
304
|
+
if (first === -1)
|
|
305
|
+
return "0s";
|
|
306
|
+
const next = amounts[first + 1];
|
|
307
|
+
return next === undefined || next.startsWith("0") ? amounts[first] ?? "0s" : `${amounts[first]} ${next}`;
|
|
308
|
+
}
|
|
309
|
+
function upTo(text, separator) {
|
|
310
|
+
const end = text.indexOf(separator);
|
|
311
|
+
return end === -1 ? text : text.slice(0, end);
|
|
312
|
+
}
|
|
313
|
+
function formatAge(date, now = Date.now()) {
|
|
314
|
+
const at = typeof date === "number" ? date : Date.parse(date);
|
|
315
|
+
if (Number.isNaN(at))
|
|
316
|
+
return "-";
|
|
317
|
+
const seconds = (now - at) / 1000;
|
|
318
|
+
return seconds < 60 ? "just now" : `${upTo(formatSeconds(seconds), " ")} ago`;
|
|
319
|
+
}
|
|
320
|
+
function truncate(text, width) {
|
|
321
|
+
return text.length <= width ? text : `${text.slice(0, Math.max(0, width - 1))}\u2026`;
|
|
322
|
+
}
|
|
323
|
+
var LINE_BREAKS = /\s*\n\s*/g;
|
|
324
|
+
var ESCAPE = String.fromCharCode(27);
|
|
325
|
+
function textWidth(text) {
|
|
326
|
+
return Bun.stringWidth(text);
|
|
327
|
+
}
|
|
328
|
+
function table(rows, { cellWidth, header = false, align = [], fit } = {}) {
|
|
329
|
+
const cells = cellWidth === undefined ? rows : rows.map((row) => row.map((cell) => truncate(cell.replaceAll(LINE_BREAKS, " "), cellWidth)));
|
|
330
|
+
const widths = [];
|
|
331
|
+
for (const row of cells) {
|
|
332
|
+
for (const [index, cell] of row.entries())
|
|
333
|
+
widths[index] = Math.max(widths[index] ?? 0, textWidth(cell));
|
|
334
|
+
}
|
|
335
|
+
const shown = fit === undefined ? cells : narrow(cells, widths, fit);
|
|
336
|
+
const colors = paint(process2.stdout);
|
|
337
|
+
const lines = shown.map((row) => row.map((cell, index) => {
|
|
338
|
+
const width = widths[index] ?? 0;
|
|
339
|
+
const gap = " ".repeat(Math.max(0, width - textWidth(cell)));
|
|
340
|
+
if (align[index] === "right")
|
|
341
|
+
return `${gap}${cell}`;
|
|
342
|
+
return index === row.length - 1 ? cell : `${cell}${gap}`;
|
|
343
|
+
}).join(" ").trimEnd());
|
|
344
|
+
return lines.map((line, index) => header && index === 0 ? colors.bold(line) : line).join(`
|
|
345
|
+
`);
|
|
346
|
+
}
|
|
347
|
+
function narrow(rows, widths, limit) {
|
|
348
|
+
const used = () => widths.reduce((sum, width) => sum + width, 0) + 2 * Math.max(0, widths.length - 1);
|
|
349
|
+
const cuttable = (index) => rows.every((row) => !(row[index] ?? "").includes(ESCAPE));
|
|
350
|
+
const floor = 8;
|
|
351
|
+
while (used() > limit) {
|
|
352
|
+
let widest = -1;
|
|
353
|
+
for (const [index, width] of widths.entries()) {
|
|
354
|
+
if (cuttable(index) && width > floor && width > (widths[widest] ?? 0))
|
|
355
|
+
widest = index;
|
|
356
|
+
}
|
|
357
|
+
if (widest === -1)
|
|
358
|
+
break;
|
|
359
|
+
widths[widest] = Math.max(floor, (widths[widest] ?? 0) - (used() - limit));
|
|
360
|
+
}
|
|
361
|
+
return rows.map((row) => row.map((cell, index) => textWidth(cell) > (widths[index] ?? 0) ? truncate(cell, widths[index] ?? 0) : cell));
|
|
362
|
+
}
|
|
363
|
+
function printJson(value) {
|
|
364
|
+
console.log(JSON.stringify(value, undefined, 2));
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// ../kit/src/args.ts
|
|
368
|
+
function jsonOption(holds) {
|
|
369
|
+
return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
class Exit extends Error {
|
|
373
|
+
code;
|
|
374
|
+
hint;
|
|
375
|
+
constructor(message, code, hint) {
|
|
376
|
+
super(message);
|
|
377
|
+
this.code = code;
|
|
378
|
+
this.hint = hint;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
function fail(message, code = 2, hint) {
|
|
382
|
+
throw new Exit(message, code, hint);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
class UsageError extends Exit {
|
|
386
|
+
constructor(message) {
|
|
387
|
+
super(message, 2);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
function badUsage(message) {
|
|
391
|
+
throw new UsageError(message);
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
class HelpShown extends Exit {
|
|
395
|
+
constructor() {
|
|
396
|
+
super("help shown", 0);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
class Completing {
|
|
401
|
+
options;
|
|
402
|
+
constructor(options) {
|
|
403
|
+
this.options = options;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
var completion = { active: false };
|
|
407
|
+
var OPTIONAL = /\[[^\]]+\]/g;
|
|
408
|
+
var USAGE_PREFIX = /^usage:\s*/i;
|
|
409
|
+
function usageLine(usage, colors = paint(process3.stdout)) {
|
|
410
|
+
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
411
|
+
}
|
|
412
|
+
function helpText(usage, options, colors = paint(process3.stdout)) {
|
|
413
|
+
return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors)].join(`
|
|
414
|
+
`);
|
|
415
|
+
}
|
|
416
|
+
function optionRows(options, colors = paint(process3.stdout)) {
|
|
417
|
+
const rows = Object.entries(options).map(([name, option]) => {
|
|
418
|
+
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
419
|
+
const value = option.type === "string" ? ` ${colors.dim("<value>")}` : "";
|
|
420
|
+
return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? " <value>".length : 0), description: option.description };
|
|
421
|
+
});
|
|
422
|
+
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
423
|
+
return rows.map((row) => ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
424
|
+
}
|
|
425
|
+
function parse(args, usage, options, settings = {}) {
|
|
426
|
+
const all = { ...options, help: { type: "boolean", short: "h", description: "show this help" } };
|
|
427
|
+
if (completion.active)
|
|
428
|
+
throw new Completing(all);
|
|
429
|
+
const separator = settings.rest === true ? args.indexOf("--") : -1;
|
|
430
|
+
const own = separator === -1 ? args : args.slice(0, separator);
|
|
431
|
+
const rest = separator === -1 ? undefined : args.slice(separator + 1);
|
|
432
|
+
let parsed;
|
|
433
|
+
try {
|
|
434
|
+
parsed = parseArgs({ args: own, options: all, allowPositionals: true, allowNegative: settings.allowNegative === true, strict: true });
|
|
435
|
+
} catch (error) {
|
|
436
|
+
badUsage(parseError(error));
|
|
437
|
+
}
|
|
438
|
+
if (parsed.values.help === true) {
|
|
439
|
+
console.log(helpText(usage, all));
|
|
440
|
+
throw new HelpShown;
|
|
441
|
+
}
|
|
442
|
+
if (settings.positionals !== undefined)
|
|
443
|
+
checkPositionals(parsed.positionals, settings.positionals);
|
|
444
|
+
return { ...parsed, positionals: parsed.positionals, rest };
|
|
445
|
+
}
|
|
446
|
+
function checkPositionals(given, names) {
|
|
447
|
+
const variadic = names.at(-1)?.replace("]", "").endsWith("...") === true;
|
|
448
|
+
const required = names.filter((name) => !name.startsWith("[")).length;
|
|
449
|
+
if (given.length < required)
|
|
450
|
+
badUsage(`missing ${names[given.length]}`);
|
|
451
|
+
if (!variadic && given.length > names.length)
|
|
452
|
+
badUsage(`unexpected argument ${given[names.length]}`);
|
|
453
|
+
}
|
|
454
|
+
function parseError(error) {
|
|
455
|
+
const message = upTo(error instanceof Error ? error.message : String(error), ". ");
|
|
456
|
+
return `${message.charAt(0).toLowerCase()}${message.slice(1)}`;
|
|
457
|
+
}
|
|
458
|
+
function wholeNumber(value, name, fallback, min = 1) {
|
|
459
|
+
if (value === undefined)
|
|
460
|
+
return fallback;
|
|
461
|
+
const number = Number(value);
|
|
462
|
+
if (!Number.isInteger(number) || number < min)
|
|
463
|
+
badUsage(`--${name} takes a whole number from ${min}, not ${value}`);
|
|
464
|
+
return number;
|
|
465
|
+
}
|
|
466
|
+
// ../kit/src/cli.ts
|
|
467
|
+
import process4 from "process";
|
|
468
|
+
|
|
469
|
+
// ../kit/src/text.ts
|
|
470
|
+
var ANSI = new RegExp(`${String.fromCharCode(27)}\\[[\\d;?]*[a-z]`, "gi");
|
|
471
|
+
function distance(a, b) {
|
|
472
|
+
let previous = Array.from({ length: b.length + 1 }, (_, index) => index);
|
|
473
|
+
for (const [i, left] of [...a].entries()) {
|
|
474
|
+
const current = [i + 1];
|
|
475
|
+
for (const [j, right] of [...b].entries())
|
|
476
|
+
current.push(Math.min((previous[j + 1] ?? 0) + 1, (current[j] ?? 0) + 1, (previous[j] ?? 0) + (left === right ? 0 : 1)));
|
|
477
|
+
previous = current;
|
|
478
|
+
}
|
|
479
|
+
return previous[b.length] ?? 0;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
// ../kit/src/cli.ts
|
|
483
|
+
function printError(prefix, message, hint, cause) {
|
|
484
|
+
const colors = paint(process4.stderr);
|
|
485
|
+
const styled = takesControlCodes(process4.stderr);
|
|
486
|
+
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
487
|
+
const under = (label, text, tint) => text === undefined ? "" : `
|
|
488
|
+
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
489
|
+
console.error(`${head} ${message}${under("cause", cause, colors.dim)}${under("hint", hint, colors.yellow)}`);
|
|
490
|
+
}
|
|
491
|
+
function reportThrown(prefix, error, redact = (text) => text) {
|
|
492
|
+
if (error instanceof HelpShown)
|
|
493
|
+
return 0;
|
|
494
|
+
const help = error instanceof UsageError ? `run ${prefix} --help for its options` : undefined;
|
|
495
|
+
const named = error instanceof Error && !(error instanceof Exit) && error.name !== "Error" ? `${error.name}: ${error.message}` : undefined;
|
|
496
|
+
const cause = error instanceof Error && error.cause instanceof Error ? redact(error.cause.message) : undefined;
|
|
497
|
+
printError(prefix, redact(named ?? (error instanceof Error ? error.message : String(error))), error instanceof Exit ? error.hint ?? help : undefined, cause);
|
|
498
|
+
return error instanceof Exit ? error.code : 1;
|
|
499
|
+
}
|
|
500
|
+
var COMPLETE = "__complete";
|
|
501
|
+
var FILES = "__files__";
|
|
502
|
+
async function optionsOf(run) {
|
|
503
|
+
completion.active = true;
|
|
504
|
+
try {
|
|
505
|
+
await run([]);
|
|
506
|
+
} catch (error) {
|
|
507
|
+
if (error instanceof Completing)
|
|
508
|
+
return error.options;
|
|
509
|
+
} finally {
|
|
510
|
+
completion.active = false;
|
|
511
|
+
}
|
|
512
|
+
return {};
|
|
513
|
+
}
|
|
514
|
+
async function leafCandidates(run, words) {
|
|
515
|
+
if (!(words.at(-1) ?? "").startsWith("-"))
|
|
516
|
+
return [FILES];
|
|
517
|
+
return Object.entries(await optionsOf(run)).map(([name, option]) => `--${name} ${option.description}`);
|
|
518
|
+
}
|
|
519
|
+
async function printCandidates(found) {
|
|
520
|
+
for (const line of await found)
|
|
521
|
+
console.log(line);
|
|
522
|
+
return 0;
|
|
523
|
+
}
|
|
524
|
+
async function runMain({ name, version, run, redact }, argv = process4.argv.slice(2)) {
|
|
525
|
+
if (argv[0] === COMPLETE)
|
|
526
|
+
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
527
|
+
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
528
|
+
console.log(version);
|
|
529
|
+
return 0;
|
|
530
|
+
}
|
|
531
|
+
try {
|
|
532
|
+
return await run(argv);
|
|
533
|
+
} catch (error) {
|
|
534
|
+
return reportThrown(name, error, redact);
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
// package.json
|
|
538
|
+
var version = "0.2.1";
|
|
539
|
+
|
|
540
|
+
// src/popular.json
|
|
541
|
+
var popular_default = [
|
|
542
|
+
"semver",
|
|
543
|
+
"minimatch",
|
|
544
|
+
"debug",
|
|
545
|
+
"ansi-styles",
|
|
546
|
+
"brace-expansion",
|
|
547
|
+
"strip-ansi",
|
|
548
|
+
"ansi-regex",
|
|
549
|
+
"ms",
|
|
550
|
+
"supports-color",
|
|
551
|
+
"chalk",
|
|
552
|
+
"commander",
|
|
553
|
+
"lru-cache",
|
|
554
|
+
"string-width",
|
|
555
|
+
"wrap-ansi",
|
|
556
|
+
"tslib",
|
|
557
|
+
"picomatch",
|
|
558
|
+
"emoji-regex",
|
|
559
|
+
"glob",
|
|
560
|
+
"type-fest",
|
|
561
|
+
"color-name",
|
|
562
|
+
"eslint-visitor-keys",
|
|
563
|
+
"color-convert",
|
|
564
|
+
"ajv",
|
|
565
|
+
"minipass",
|
|
566
|
+
"source-map",
|
|
567
|
+
"balanced-match",
|
|
568
|
+
"readable-stream",
|
|
569
|
+
"which",
|
|
570
|
+
"glob-parent",
|
|
571
|
+
"escape-string-regexp",
|
|
572
|
+
"has-flag",
|
|
573
|
+
"find-up",
|
|
574
|
+
"locate-path",
|
|
575
|
+
"json-schema-traverse",
|
|
576
|
+
"p-limit",
|
|
577
|
+
"yallist",
|
|
578
|
+
"safe-buffer",
|
|
579
|
+
"uuid",
|
|
580
|
+
"p-locate",
|
|
581
|
+
"undici-types",
|
|
582
|
+
"ignore",
|
|
583
|
+
"iconv-lite",
|
|
584
|
+
"signal-exit",
|
|
585
|
+
"esbuild",
|
|
586
|
+
"is-fullwidth-code-point",
|
|
587
|
+
"js-yaml",
|
|
588
|
+
"entities",
|
|
589
|
+
"globals",
|
|
590
|
+
"postcss",
|
|
591
|
+
"isexe",
|
|
592
|
+
"isarray",
|
|
593
|
+
"path-key",
|
|
594
|
+
"string_decoder",
|
|
595
|
+
"argparse",
|
|
596
|
+
"ws",
|
|
597
|
+
"mime-db",
|
|
598
|
+
"resolve",
|
|
599
|
+
"agent-base",
|
|
600
|
+
"@esbuild/linux-x64",
|
|
601
|
+
"yargs-parser",
|
|
602
|
+
"mime-types",
|
|
603
|
+
"acorn",
|
|
604
|
+
"estraverse",
|
|
605
|
+
"cross-spawn",
|
|
606
|
+
"react-is",
|
|
607
|
+
"picocolors",
|
|
608
|
+
"fs-extra",
|
|
609
|
+
"hasown",
|
|
610
|
+
"nanoid",
|
|
611
|
+
"yargs",
|
|
612
|
+
"resolve-from",
|
|
613
|
+
"shebang-command",
|
|
614
|
+
"pretty-format",
|
|
615
|
+
"json5",
|
|
616
|
+
"https-proxy-agent",
|
|
617
|
+
"path-to-regexp",
|
|
618
|
+
"path-exists",
|
|
619
|
+
"punycode",
|
|
620
|
+
"js-tokens",
|
|
621
|
+
"cliui",
|
|
622
|
+
"shebang-regex",
|
|
623
|
+
"@babel/types",
|
|
624
|
+
"chokidar",
|
|
625
|
+
"strip-json-comments",
|
|
626
|
+
"inherits",
|
|
627
|
+
"webidl-conversions",
|
|
628
|
+
"get-stream",
|
|
629
|
+
"eslint-scope",
|
|
630
|
+
"cookie",
|
|
631
|
+
"@babel/parser",
|
|
632
|
+
"qs",
|
|
633
|
+
"is-number",
|
|
634
|
+
"whatwg-url",
|
|
635
|
+
"@types/estree",
|
|
636
|
+
"tr46",
|
|
637
|
+
"convert-source-map",
|
|
638
|
+
"is-glob",
|
|
639
|
+
"braces",
|
|
640
|
+
"fast-deep-equal",
|
|
641
|
+
"form-data",
|
|
642
|
+
"lodash",
|
|
643
|
+
"@babel/helper-validator-identifier",
|
|
644
|
+
"electron-to-chromium",
|
|
645
|
+
"fill-range",
|
|
646
|
+
"function-bind",
|
|
647
|
+
"readdirp",
|
|
648
|
+
"escalade",
|
|
649
|
+
"graceful-fs",
|
|
650
|
+
"negotiator",
|
|
651
|
+
"is-stream",
|
|
652
|
+
"camelcase",
|
|
653
|
+
"@babel/runtime",
|
|
654
|
+
"yocto-queue",
|
|
655
|
+
"to-regex-range",
|
|
656
|
+
"node-fetch",
|
|
657
|
+
"micromatch",
|
|
658
|
+
"node-releases",
|
|
659
|
+
"get-intrinsic",
|
|
660
|
+
"universalify",
|
|
661
|
+
"path-scurry",
|
|
662
|
+
"jsesc",
|
|
663
|
+
"browserslist",
|
|
664
|
+
"es-errors",
|
|
665
|
+
"statuses",
|
|
666
|
+
"@radix-ui/react-primitive",
|
|
667
|
+
"magic-string",
|
|
668
|
+
"rimraf",
|
|
669
|
+
"is-extglob",
|
|
670
|
+
"@jridgewell/trace-mapping",
|
|
671
|
+
"@jridgewell/resolve-uri",
|
|
672
|
+
"http-errors",
|
|
673
|
+
"onetime",
|
|
674
|
+
"has-symbols",
|
|
675
|
+
"es-define-property",
|
|
676
|
+
"gopd",
|
|
677
|
+
"util-deprecate",
|
|
678
|
+
"object-assign",
|
|
679
|
+
"jiti",
|
|
680
|
+
"yaml",
|
|
681
|
+
"dotenv",
|
|
682
|
+
"@babel/generator",
|
|
683
|
+
"@babel/template",
|
|
684
|
+
"imurmurhash",
|
|
685
|
+
"postcss-selector-parser",
|
|
686
|
+
"fast-glob",
|
|
687
|
+
"update-browserslist-db",
|
|
688
|
+
"@types/node",
|
|
689
|
+
"@babel/compat-data",
|
|
690
|
+
"eventemitter3",
|
|
691
|
+
"callsites",
|
|
692
|
+
"http-proxy-agent",
|
|
693
|
+
"detect-libc",
|
|
694
|
+
"espree",
|
|
695
|
+
"execa",
|
|
696
|
+
"@babel/core",
|
|
697
|
+
"@babel/helpers",
|
|
698
|
+
"concat-map",
|
|
699
|
+
"source-map-js",
|
|
700
|
+
"tinyglobby",
|
|
701
|
+
"call-bind-apply-helpers",
|
|
702
|
+
"flat-cache",
|
|
703
|
+
"fdir",
|
|
704
|
+
"pify",
|
|
705
|
+
"@jest/types",
|
|
706
|
+
"normalize-path",
|
|
707
|
+
"is-core-module",
|
|
708
|
+
"eslint",
|
|
709
|
+
"minimist",
|
|
710
|
+
"estree-walker",
|
|
711
|
+
"file-entry-cache",
|
|
712
|
+
"object-inspect",
|
|
713
|
+
"buffer",
|
|
714
|
+
"uri-js",
|
|
715
|
+
"import-fresh",
|
|
716
|
+
"@babel/helper-module-transforms",
|
|
717
|
+
"optionator",
|
|
718
|
+
"flatted",
|
|
719
|
+
"math-intrinsics",
|
|
720
|
+
"safer-buffer",
|
|
721
|
+
"y18n",
|
|
722
|
+
"@babel/helper-module-imports",
|
|
723
|
+
"mkdirp",
|
|
724
|
+
"dunder-proto",
|
|
725
|
+
"path-parse",
|
|
726
|
+
"fastq",
|
|
727
|
+
"levn",
|
|
728
|
+
"@babel/helper-compilation-targets",
|
|
729
|
+
"@babel/helper-string-parser",
|
|
730
|
+
"keyv",
|
|
731
|
+
"get-proto",
|
|
732
|
+
"csstype",
|
|
733
|
+
"npm-run-path",
|
|
734
|
+
"fast-json-stable-stringify",
|
|
735
|
+
"reusify",
|
|
736
|
+
"@babel/helper-plugin-utils",
|
|
737
|
+
"kind-of",
|
|
738
|
+
"mime",
|
|
739
|
+
"caniuse-lite",
|
|
740
|
+
"lines-and-columns",
|
|
741
|
+
"fast-levenshtein",
|
|
742
|
+
"supports-preserve-symlinks-flag",
|
|
743
|
+
"make-dir",
|
|
744
|
+
"slash",
|
|
745
|
+
"prelude-ls",
|
|
746
|
+
"typescript",
|
|
747
|
+
"strip-bom",
|
|
748
|
+
"parent-module",
|
|
749
|
+
"esutils",
|
|
750
|
+
"ci-info",
|
|
751
|
+
"@smithy/util-utf8",
|
|
752
|
+
"type-check",
|
|
753
|
+
"mimic-fn",
|
|
754
|
+
"@babel/helper-validator-option",
|
|
755
|
+
"@types/json-schema",
|
|
756
|
+
"@rolldown/pluginutils",
|
|
757
|
+
"side-channel-list",
|
|
758
|
+
"json-buffer",
|
|
759
|
+
"raw-body",
|
|
760
|
+
"has-tostringtag",
|
|
761
|
+
"wrappy",
|
|
762
|
+
"diff",
|
|
763
|
+
"jackspeak",
|
|
764
|
+
"baseline-browser-mapping",
|
|
765
|
+
"deep-is",
|
|
766
|
+
"foreground-child",
|
|
767
|
+
"@eslint/js",
|
|
768
|
+
"anymatch",
|
|
769
|
+
"natural-compare",
|
|
770
|
+
"esquery",
|
|
771
|
+
"@eslint-community/regexpp",
|
|
772
|
+
"es-set-tostringtag",
|
|
773
|
+
"acorn-jsx",
|
|
774
|
+
"parse5",
|
|
775
|
+
"finalhandler",
|
|
776
|
+
"parse-json",
|
|
777
|
+
"depd",
|
|
778
|
+
"axios",
|
|
779
|
+
"run-parallel",
|
|
780
|
+
"source-map-support",
|
|
781
|
+
"esrecurse",
|
|
782
|
+
"call-bound",
|
|
783
|
+
"content-disposition",
|
|
784
|
+
"human-signals",
|
|
785
|
+
"ts-api-utils",
|
|
786
|
+
"ansi-escapes",
|
|
787
|
+
"jest-util",
|
|
788
|
+
"send",
|
|
789
|
+
"@opentelemetry/core",
|
|
790
|
+
"type-is",
|
|
791
|
+
"encodeurl",
|
|
792
|
+
"once",
|
|
793
|
+
"cosmiconfig",
|
|
794
|
+
"lodash.merge",
|
|
795
|
+
"json-stable-stringify-without-jsonify",
|
|
796
|
+
"open",
|
|
797
|
+
"prettier",
|
|
798
|
+
"@eslint/eslintrc",
|
|
799
|
+
"is-arrayish",
|
|
800
|
+
"@jridgewell/sourcemap-codec",
|
|
801
|
+
"gensync",
|
|
802
|
+
"word-wrap",
|
|
803
|
+
"express",
|
|
804
|
+
"arg",
|
|
805
|
+
"jsonfile",
|
|
806
|
+
"schema-utils",
|
|
807
|
+
"@smithy/is-array-buffer",
|
|
808
|
+
"@typescript-eslint/types",
|
|
809
|
+
"chownr",
|
|
810
|
+
"delayed-stream",
|
|
811
|
+
"@smithy/util-buffer-from",
|
|
812
|
+
"asynckit",
|
|
813
|
+
"tapable",
|
|
814
|
+
"enhanced-resolve",
|
|
815
|
+
"aria-query",
|
|
816
|
+
"indent-string",
|
|
817
|
+
"bytes",
|
|
818
|
+
"binary-extensions",
|
|
819
|
+
"ini",
|
|
820
|
+
"@radix-ui/react-context",
|
|
821
|
+
"doctrine",
|
|
822
|
+
"queue-microtask",
|
|
823
|
+
"accepts",
|
|
824
|
+
"merge2",
|
|
825
|
+
"get-caller-file",
|
|
826
|
+
"@humanwhocodes/retry",
|
|
827
|
+
"@jridgewell/gen-mapping",
|
|
828
|
+
"@typescript-eslint/typescript-estree",
|
|
829
|
+
"jest-worker",
|
|
830
|
+
"proxy-from-env",
|
|
831
|
+
"clsx",
|
|
832
|
+
"side-channel-map",
|
|
833
|
+
"@typescript-eslint/visitor-keys",
|
|
834
|
+
"fresh",
|
|
835
|
+
"restore-cursor",
|
|
836
|
+
"on-finished",
|
|
837
|
+
"is-plain-obj",
|
|
838
|
+
"ipaddr.js",
|
|
839
|
+
"pathe",
|
|
840
|
+
"@jest/schemas",
|
|
841
|
+
"base64-js",
|
|
842
|
+
"@smithy/types",
|
|
843
|
+
"require-directory",
|
|
844
|
+
"tough-cookie",
|
|
845
|
+
"is-binary-path",
|
|
846
|
+
"body-parser",
|
|
847
|
+
"postcss-value-parser",
|
|
848
|
+
"media-typer",
|
|
849
|
+
"setprototypeof",
|
|
850
|
+
"side-channel-weakmap",
|
|
851
|
+
"@typescript-eslint/tsconfig-utils",
|
|
852
|
+
"@isaacs/cliui",
|
|
853
|
+
"@rollup/rollup-linux-x64-gnu",
|
|
854
|
+
"is-wsl",
|
|
855
|
+
"retry",
|
|
856
|
+
"@aws-sdk/types",
|
|
857
|
+
"@types/react-dom",
|
|
858
|
+
"combined-stream",
|
|
859
|
+
"es-object-atoms",
|
|
860
|
+
"@eslint/core",
|
|
861
|
+
"whatwg-mimetype",
|
|
862
|
+
"domutils",
|
|
863
|
+
"@rollup/rollup-linux-x64-musl",
|
|
864
|
+
"core-util-is",
|
|
865
|
+
"@typescript-eslint/scope-manager",
|
|
866
|
+
"esprima",
|
|
867
|
+
"loose-envify",
|
|
868
|
+
"cookie-signature",
|
|
869
|
+
"follow-redirects",
|
|
870
|
+
"cli-cursor",
|
|
871
|
+
"strip-final-newline",
|
|
872
|
+
"@typescript-eslint/project-service",
|
|
873
|
+
"eastasianwidth",
|
|
874
|
+
"json-parse-even-better-errors",
|
|
875
|
+
"sprintf-js",
|
|
876
|
+
"path-type",
|
|
877
|
+
"content-type",
|
|
878
|
+
"es-module-lexer",
|
|
879
|
+
"@nodelib/fs.scandir",
|
|
880
|
+
"write-file-atomic",
|
|
881
|
+
"@eslint/plugin-kit",
|
|
882
|
+
"ieee754",
|
|
883
|
+
"prop-types",
|
|
884
|
+
"require-from-string",
|
|
885
|
+
"dom-serializer",
|
|
886
|
+
"call-bind",
|
|
887
|
+
"@eslint/config-array",
|
|
888
|
+
"has-property-descriptors",
|
|
889
|
+
"@nodelib/fs.stat",
|
|
890
|
+
"merge-descriptors",
|
|
891
|
+
"slice-ansi",
|
|
892
|
+
"rxjs",
|
|
893
|
+
"p-map",
|
|
894
|
+
"toidentifier",
|
|
895
|
+
"globby",
|
|
896
|
+
"domhandler",
|
|
897
|
+
"async",
|
|
898
|
+
"@babel/helper-globals",
|
|
899
|
+
"pirates",
|
|
900
|
+
"@opentelemetry/semantic-conventions",
|
|
901
|
+
"@typescript-eslint/utils",
|
|
902
|
+
"date-fns",
|
|
903
|
+
"is-docker",
|
|
904
|
+
"tar",
|
|
905
|
+
"which-typed-array",
|
|
906
|
+
"ajv-formats",
|
|
907
|
+
"@opentelemetry/api-logs",
|
|
908
|
+
"@opentelemetry/resources",
|
|
909
|
+
"side-channel",
|
|
910
|
+
"cjs-module-lexer",
|
|
911
|
+
"range-parser",
|
|
912
|
+
"@humanfs/node",
|
|
913
|
+
"define-data-property",
|
|
914
|
+
"node-addon-api",
|
|
915
|
+
"pako",
|
|
916
|
+
"lilconfig",
|
|
917
|
+
"fast-uri",
|
|
918
|
+
"ip-address",
|
|
919
|
+
"fs.realpath",
|
|
920
|
+
"@img/sharp-libvips-linuxmusl-x64",
|
|
921
|
+
"cssesc",
|
|
922
|
+
"@opentelemetry/instrumentation",
|
|
923
|
+
"domelementtype",
|
|
924
|
+
"hosted-git-info",
|
|
925
|
+
"@eslint/object-schema",
|
|
926
|
+
"etag",
|
|
927
|
+
"@eslint/config-helpers",
|
|
928
|
+
"package-json-from-dist",
|
|
929
|
+
"@humanfs/core",
|
|
930
|
+
"htmlparser2",
|
|
931
|
+
"jest-message-util",
|
|
932
|
+
"for-each",
|
|
933
|
+
"pkg-dir",
|
|
934
|
+
"unpipe",
|
|
935
|
+
"buffer-from",
|
|
936
|
+
"es-abstract",
|
|
937
|
+
"is-unicode-supported",
|
|
938
|
+
"@types/yargs",
|
|
939
|
+
"is-callable",
|
|
940
|
+
"fast-xml-parser",
|
|
941
|
+
"istanbul-lib-instrument",
|
|
942
|
+
"escape-html",
|
|
943
|
+
"is-regex",
|
|
944
|
+
"dom-accessibility-api",
|
|
945
|
+
"css-tree",
|
|
946
|
+
"error-ex",
|
|
947
|
+
"ee-first",
|
|
948
|
+
"@types/unist",
|
|
949
|
+
"log-symbols",
|
|
950
|
+
"path-is-absolute",
|
|
951
|
+
"end-of-stream",
|
|
952
|
+
"@vitest/utils",
|
|
953
|
+
"object.assign",
|
|
954
|
+
"object-keys",
|
|
955
|
+
"tinyexec",
|
|
956
|
+
"scheduler",
|
|
957
|
+
"p-try",
|
|
958
|
+
"process-nextick-args",
|
|
959
|
+
"vary",
|
|
960
|
+
"@babel/traverse",
|
|
961
|
+
"@pkgjs/parseargs",
|
|
962
|
+
"@types/babel__generator",
|
|
963
|
+
"kleur",
|
|
964
|
+
"zod",
|
|
965
|
+
"merge-stream",
|
|
966
|
+
"available-typed-arrays",
|
|
967
|
+
"mute-stream",
|
|
968
|
+
"is-typed-array",
|
|
969
|
+
"safe-regex-test",
|
|
970
|
+
"tsconfig-paths",
|
|
971
|
+
"minizlib",
|
|
972
|
+
"tar-stream",
|
|
973
|
+
"@floating-ui/core",
|
|
974
|
+
"jose",
|
|
975
|
+
"deepmerge",
|
|
976
|
+
"get-tsconfig",
|
|
977
|
+
"set-function-length",
|
|
978
|
+
"@vitest/spy",
|
|
979
|
+
"css-select",
|
|
980
|
+
"@types/babel__core",
|
|
981
|
+
"forwarded",
|
|
982
|
+
"react",
|
|
983
|
+
"@typescript-eslint/parser",
|
|
984
|
+
"ajv-keywords",
|
|
985
|
+
"define-properties",
|
|
986
|
+
"is-generator-function",
|
|
987
|
+
"regexp.prototype.flags",
|
|
988
|
+
"acorn-walk",
|
|
989
|
+
"pump",
|
|
990
|
+
"data-uri-to-buffer",
|
|
991
|
+
"object-hash",
|
|
992
|
+
"jsdom",
|
|
993
|
+
"nopt",
|
|
994
|
+
"@babel/plugin-syntax-jsx",
|
|
995
|
+
"@floating-ui/dom",
|
|
996
|
+
"tiny-invariant",
|
|
997
|
+
"strip-indent",
|
|
998
|
+
"d3-array",
|
|
999
|
+
"chai",
|
|
1000
|
+
"@babel/code-frame",
|
|
1001
|
+
"@typescript-eslint/eslint-plugin",
|
|
1002
|
+
"proxy-addr",
|
|
1003
|
+
"parseurl",
|
|
1004
|
+
"@floating-ui/utils",
|
|
1005
|
+
"ora",
|
|
1006
|
+
"html-encoding-sniffer",
|
|
1007
|
+
"pnpm",
|
|
1008
|
+
"whatwg-encoding",
|
|
1009
|
+
"events",
|
|
1010
|
+
"@typescript-eslint/type-utils",
|
|
1011
|
+
"env-paths",
|
|
1012
|
+
"internal-slot",
|
|
1013
|
+
"string.prototype.trimend",
|
|
1014
|
+
"extend",
|
|
1015
|
+
"resolve-pkg-maps",
|
|
1016
|
+
"istanbul-lib-coverage",
|
|
1017
|
+
"react-dom",
|
|
1018
|
+
"is-number-object",
|
|
1019
|
+
"@radix-ui/primitive",
|
|
1020
|
+
"is-plain-object",
|
|
1021
|
+
"string.prototype.trimstart",
|
|
1022
|
+
"@babel/plugin-syntax-typescript",
|
|
1023
|
+
"jest-diff",
|
|
1024
|
+
"define-lazy-prop",
|
|
1025
|
+
"globalthis",
|
|
1026
|
+
"which-boxed-primitive",
|
|
1027
|
+
"@vitest/expect",
|
|
1028
|
+
"sax",
|
|
1029
|
+
"@floating-ui/react-dom",
|
|
1030
|
+
"@vitest/pretty-format",
|
|
1031
|
+
"internmap",
|
|
1032
|
+
"@radix-ui/react-compose-refs",
|
|
1033
|
+
"is-symbol",
|
|
1034
|
+
"@eslint-community/eslint-utils",
|
|
1035
|
+
"bl",
|
|
1036
|
+
"serve-static",
|
|
1037
|
+
"get-symbol-description",
|
|
1038
|
+
"is-shared-array-buffer",
|
|
1039
|
+
"functions-have-names",
|
|
1040
|
+
"array-buffer-byte-length",
|
|
1041
|
+
"socks-proxy-agent"
|
|
1042
|
+
];
|
|
1043
|
+
|
|
1044
|
+
// src/nearmiss.ts
|
|
1045
|
+
var SEPARATORS = /[-_.]/g;
|
|
1046
|
+
var MIN_LENGTH = 5;
|
|
1047
|
+
function baseName(name) {
|
|
1048
|
+
return name.slice(name.indexOf("/") + 1);
|
|
1049
|
+
}
|
|
1050
|
+
function scopeOf(name) {
|
|
1051
|
+
return name.startsWith("@") ? name.slice(0, name.indexOf("/")) : "";
|
|
1052
|
+
}
|
|
1053
|
+
function squash(name) {
|
|
1054
|
+
return name.toLowerCase().replace(SEPARATORS, "");
|
|
1055
|
+
}
|
|
1056
|
+
function resemblance(name, popular) {
|
|
1057
|
+
if (scopeOf(name) !== scopeOf(popular) && baseName(name) === baseName(popular) && baseName(name).length >= MIN_LENGTH)
|
|
1058
|
+
return `${popular} under another scope`;
|
|
1059
|
+
if (squash(name) === squash(popular))
|
|
1060
|
+
return `${popular} spelled with other separators or case`;
|
|
1061
|
+
const edits = distance(name, popular);
|
|
1062
|
+
const allowed = Math.min(name.length, popular.length) >= MIN_LENGTH * 2 ? 2 : 1;
|
|
1063
|
+
return Math.min(name.length, popular.length) >= MIN_LENGTH && edits <= allowed ? `${popular}, ${edits} ${edits === 1 ? "edit" : "edits"} away` : undefined;
|
|
1064
|
+
}
|
|
1065
|
+
function nearMisses(name, popular = popular_default) {
|
|
1066
|
+
if (popular.includes(name))
|
|
1067
|
+
return [];
|
|
1068
|
+
const found = [];
|
|
1069
|
+
for (const other of popular) {
|
|
1070
|
+
const text = resemblance(name, other);
|
|
1071
|
+
if (text !== undefined)
|
|
1072
|
+
found.push({ text, edits: distance(name, other) });
|
|
1073
|
+
}
|
|
1074
|
+
return found.sort((a, b) => a.edits - b.edits).slice(0, 3).map((match) => match.text);
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
// src/analyze.ts
|
|
1078
|
+
var DEFAULT_MIN_AGE_DAYS = 14;
|
|
1079
|
+
var DAY = 86400000;
|
|
1080
|
+
var INSTALL_SCRIPTS = ["preinstall", "install", "postinstall"];
|
|
1081
|
+
var GIT_PREFIX = /^git\+/;
|
|
1082
|
+
var VERSION_SEPARATOR = /(?<=.)@/;
|
|
1083
|
+
function parseSpec(text) {
|
|
1084
|
+
const at = text.search(VERSION_SEPARATOR);
|
|
1085
|
+
return at === -1 ? { name: text } : { name: text.slice(0, at), request: text.slice(at + 1) };
|
|
1086
|
+
}
|
|
1087
|
+
function isStable(version) {
|
|
1088
|
+
return !version.includes("-");
|
|
1089
|
+
}
|
|
1090
|
+
function resolve(packument, request) {
|
|
1091
|
+
const tags = packument["dist-tags"] ?? {};
|
|
1092
|
+
const versions = Object.keys(packument.versions ?? {});
|
|
1093
|
+
const wanted = request === undefined || request === "" ? "latest" : request;
|
|
1094
|
+
if (tags[wanted] !== undefined)
|
|
1095
|
+
return tags[wanted];
|
|
1096
|
+
if (versions.includes(wanted))
|
|
1097
|
+
return wanted;
|
|
1098
|
+
return versions.filter((version) => Bun.semver.satisfies(version, wanted)).sort(Bun.semver.order).at(-1);
|
|
1099
|
+
}
|
|
1100
|
+
function licenseOf(license) {
|
|
1101
|
+
return typeof license === "string" ? license : license?.type;
|
|
1102
|
+
}
|
|
1103
|
+
function repositoryOf(packument) {
|
|
1104
|
+
const repository = typeof packument.repository === "string" ? packument.repository : packument.repository?.url;
|
|
1105
|
+
return repository?.replace(GIT_PREFIX, "") ?? packument.homepage;
|
|
1106
|
+
}
|
|
1107
|
+
function ageDays(published, now) {
|
|
1108
|
+
const at = Date.parse(published ?? "");
|
|
1109
|
+
return Number.isNaN(at) ? undefined : (now - at) / DAY;
|
|
1110
|
+
}
|
|
1111
|
+
function installScriptsOf(version) {
|
|
1112
|
+
return Object.fromEntries(INSTALL_SCRIPTS.flatMap((name) => version?.scripts?.[name] === undefined ? [] : [[name, version.scripts[name]]]));
|
|
1113
|
+
}
|
|
1114
|
+
function safeRelease(packument, now, minAgeDays) {
|
|
1115
|
+
const old = Object.keys(packument.versions ?? {}).filter((version) => isStable(version) && (ageDays(packument.time?.[version], now) ?? 0) >= minAgeDays && packument.time?.[version] !== undefined);
|
|
1116
|
+
const version = old.sort(Bun.semver.order).at(-1);
|
|
1117
|
+
return version === undefined ? undefined : { version, published: packument.time?.[version] };
|
|
1118
|
+
}
|
|
1119
|
+
function analyze(input) {
|
|
1120
|
+
const { spec, packument, registry, now = Date.now(), minAgeDays = DEFAULT_MIN_AGE_DAYS } = input;
|
|
1121
|
+
const report = { name: spec.name, registry, exists: packument !== undefined, requested: spec.request, installScripts: {}, nearMisses: nearMisses(spec.name), warnings: [], blocked: false, downloads: input.downloads };
|
|
1122
|
+
if (report.nearMisses.length > 0)
|
|
1123
|
+
report.warnings.push(`name looks like ${report.nearMisses.join("; ")}, check it is the package meant`);
|
|
1124
|
+
if (packument === undefined) {
|
|
1125
|
+
report.blocked = true;
|
|
1126
|
+
report.warnings.unshift(`${spec.name} is not on ${registry}, the name may be guessed`);
|
|
1127
|
+
return report;
|
|
1128
|
+
}
|
|
1129
|
+
const latest = packument["dist-tags"]?.latest;
|
|
1130
|
+
const version = resolve(packument, spec.request);
|
|
1131
|
+
const entry = version === undefined ? undefined : packument.versions?.[version];
|
|
1132
|
+
report.description = packument.description;
|
|
1133
|
+
report.license = licenseOf(entry?.license) ?? licenseOf(packument.license);
|
|
1134
|
+
report.repository = repositoryOf(packument);
|
|
1135
|
+
report.latest = latest === undefined ? undefined : { version: latest, published: packument.time?.[latest] };
|
|
1136
|
+
report.safe = safeRelease(packument, now, minAgeDays);
|
|
1137
|
+
report.version = version;
|
|
1138
|
+
report.published = version === undefined ? undefined : packument.time?.[version];
|
|
1139
|
+
report.installScripts = installScriptsOf(entry);
|
|
1140
|
+
report.deprecated = entry?.deprecated;
|
|
1141
|
+
if (version === undefined) {
|
|
1142
|
+
report.blocked = true;
|
|
1143
|
+
report.warnings.push(`no version of ${spec.name} matches ${spec.request}`);
|
|
1144
|
+
return report;
|
|
1145
|
+
}
|
|
1146
|
+
const age = ageDays(report.published, now);
|
|
1147
|
+
if (age === undefined) {
|
|
1148
|
+
report.warnings.push(`${registry} gives no publish date for ${version}, its age cannot be checked`);
|
|
1149
|
+
} else if (age < minAgeDays) {
|
|
1150
|
+
report.blocked = true;
|
|
1151
|
+
report.warnings.push(`${version} was published ${age < 1 ? "less than a day" : `${Math.floor(age)} day${Math.floor(age) === 1 ? "" : "s"}`} ago, under ${minAgeDays} days${report.safe === undefined ? ", and no older stable version exists" : `, use ${spec.name}@${report.safe.version}`}`);
|
|
1152
|
+
}
|
|
1153
|
+
const scripts = Object.keys(report.installScripts);
|
|
1154
|
+
if (scripts.length > 0)
|
|
1155
|
+
report.warnings.push(`${version} runs ${scripts.join(", ")} at install`);
|
|
1156
|
+
if (report.deprecated !== undefined)
|
|
1157
|
+
report.warnings.push(`${version} is deprecated: ${report.deprecated}`);
|
|
1158
|
+
return report;
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
// src/config.ts
|
|
1162
|
+
import { homedir } from "os";
|
|
1163
|
+
import { dirname, join } from "path";
|
|
1164
|
+
import process6 from "process";
|
|
1165
|
+
|
|
1166
|
+
// src/registry.ts
|
|
1167
|
+
var PUBLIC_REGISTRY = "https://registry.npmjs.org";
|
|
1168
|
+
var DOWNLOADS_API = "https://api.npmjs.org/downloads/point/last-week";
|
|
1169
|
+
var TRAILING_SLASHES = /\/+$/;
|
|
1170
|
+
function isPublic(registry) {
|
|
1171
|
+
return registry.url.replace(TRAILING_SLASHES, "") === PUBLIC_REGISTRY;
|
|
1172
|
+
}
|
|
1173
|
+
async function get(fetcher, url, token) {
|
|
1174
|
+
try {
|
|
1175
|
+
return await fetcher(url, { headers: { accept: "application/json", ...token === undefined ? {} : { authorization: `Bearer ${token}` } } });
|
|
1176
|
+
} catch (error) {
|
|
1177
|
+
return fail(`cannot reach ${new URL(url).host}: ${error instanceof Error ? error.message : String(error)}`, 1);
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
async function fetchPackument(name, registry, fetcher = fetch) {
|
|
1181
|
+
const response = await get(fetcher, `${registry.url.replace(TRAILING_SLASHES, "")}/${name.replace("/", "%2f")}`, registry.token);
|
|
1182
|
+
if (response.status === 404)
|
|
1183
|
+
return;
|
|
1184
|
+
if (!response.ok)
|
|
1185
|
+
fail(`${new URL(registry.url).host} answered ${response.status} for ${name}`, 1);
|
|
1186
|
+
return await response.json();
|
|
1187
|
+
}
|
|
1188
|
+
async function fetchDownloads(name, fetcher = fetch) {
|
|
1189
|
+
const response = await get(fetcher, `${DOWNLOADS_API}/${name}`);
|
|
1190
|
+
if (!response.ok)
|
|
1191
|
+
return;
|
|
1192
|
+
const body = await response.json();
|
|
1193
|
+
return body.downloads;
|
|
1194
|
+
}
|
|
1195
|
+
|
|
1196
|
+
// src/config.ts
|
|
1197
|
+
var ENV_REFERENCE = /\$\{(\w+)\}|\$(\w+)/g;
|
|
1198
|
+
var COMMENT = /^\s*[#;]/;
|
|
1199
|
+
var SCOPE_REGISTRY = /^(@[^:]+):registry$/;
|
|
1200
|
+
var AUTH_TOKEN = /^(\/\/.+?):_authToken$/;
|
|
1201
|
+
var PROTOCOL = /^\w+:/;
|
|
1202
|
+
var QUOTES = /^(["'])(.*)\1$/;
|
|
1203
|
+
function expand(value, env) {
|
|
1204
|
+
let missing = false;
|
|
1205
|
+
const expanded = value.replace(ENV_REFERENCE, (_, braced, bare) => {
|
|
1206
|
+
const found = env[braced ?? bare ?? ""];
|
|
1207
|
+
missing ||= found === undefined;
|
|
1208
|
+
return found ?? "";
|
|
1209
|
+
});
|
|
1210
|
+
return missing ? undefined : expanded;
|
|
1211
|
+
}
|
|
1212
|
+
function parseNpmrc(text, env) {
|
|
1213
|
+
const config = { scopes: {}, tokens: {}, scopeTokens: {} };
|
|
1214
|
+
for (const line of text.split(`
|
|
1215
|
+
`)) {
|
|
1216
|
+
const at = line.indexOf("=");
|
|
1217
|
+
if (at === -1 || COMMENT.test(line))
|
|
1218
|
+
continue;
|
|
1219
|
+
const key = line.slice(0, at).trim();
|
|
1220
|
+
const value = expand(line.slice(at + 1).trim().replace(QUOTES, "$2"), env);
|
|
1221
|
+
if (value === undefined || value === "")
|
|
1222
|
+
continue;
|
|
1223
|
+
const scope = SCOPE_REGISTRY.exec(key)?.[1];
|
|
1224
|
+
const tokenFor = AUTH_TOKEN.exec(key)?.[1];
|
|
1225
|
+
if (scope !== undefined)
|
|
1226
|
+
config.scopes[scope] = value;
|
|
1227
|
+
else if (tokenFor !== undefined)
|
|
1228
|
+
config.tokens[tokenFor] = value;
|
|
1229
|
+
else if (key === "registry")
|
|
1230
|
+
config.registry = value;
|
|
1231
|
+
}
|
|
1232
|
+
return config;
|
|
1233
|
+
}
|
|
1234
|
+
function bunEntry(entry, env) {
|
|
1235
|
+
const url = typeof entry === "string" ? entry : entry.url;
|
|
1236
|
+
const token = typeof entry === "string" || entry.token === undefined ? undefined : expand(entry.token, env);
|
|
1237
|
+
return { ...url === undefined ? {} : { url: expand(url, env) ?? url }, ...token === undefined ? {} : { token } };
|
|
1238
|
+
}
|
|
1239
|
+
function parseBunfig(text, env) {
|
|
1240
|
+
const config = { scopes: {}, tokens: {}, scopeTokens: {} };
|
|
1241
|
+
const install = Bun.TOML.parse(text).install;
|
|
1242
|
+
if (install?.registry !== undefined) {
|
|
1243
|
+
const { url, token } = bunEntry(install.registry, env);
|
|
1244
|
+
if (url !== undefined)
|
|
1245
|
+
config.registry = url;
|
|
1246
|
+
if (url !== undefined && token !== undefined)
|
|
1247
|
+
config.tokens[url.replace(PROTOCOL, "")] = token;
|
|
1248
|
+
}
|
|
1249
|
+
for (const [scope, entry] of Object.entries(install?.scopes ?? {})) {
|
|
1250
|
+
const { url, token } = bunEntry(entry, env);
|
|
1251
|
+
if (url !== undefined)
|
|
1252
|
+
config.scopes[scope.startsWith("@") ? scope : `@${scope}`] = url;
|
|
1253
|
+
if (token !== undefined)
|
|
1254
|
+
config.scopeTokens[scope.startsWith("@") ? scope : `@${scope}`] = token;
|
|
1255
|
+
}
|
|
1256
|
+
return config;
|
|
1257
|
+
}
|
|
1258
|
+
function tokenFor(config, url) {
|
|
1259
|
+
const address = url.replace(PROTOCOL, "");
|
|
1260
|
+
const best = Object.keys(config.tokens).filter((key) => address.startsWith(key)).sort((a, b) => b.length - a.length)[0];
|
|
1261
|
+
return best === undefined ? undefined : config.tokens[best];
|
|
1262
|
+
}
|
|
1263
|
+
function registryFor(name, configs) {
|
|
1264
|
+
const scope = name.startsWith("@") ? name.slice(0, name.indexOf("/")) : undefined;
|
|
1265
|
+
for (const config of configs) {
|
|
1266
|
+
const url = scope === undefined ? config.registry : config.scopes[scope] ?? config.registry;
|
|
1267
|
+
if (url === undefined)
|
|
1268
|
+
continue;
|
|
1269
|
+
const token = (scope === undefined ? undefined : config.scopeTokens[scope]) ?? tokenFor(config, url) ?? configs.map((other) => tokenFor(other, url)).find((found) => found !== undefined);
|
|
1270
|
+
return { url, token };
|
|
1271
|
+
}
|
|
1272
|
+
return { url: PUBLIC_REGISTRY };
|
|
1273
|
+
}
|
|
1274
|
+
async function readIfThere(path) {
|
|
1275
|
+
const file = Bun.file(path);
|
|
1276
|
+
return await file.exists() ? file.text() : undefined;
|
|
1277
|
+
}
|
|
1278
|
+
async function loadConfigs(cwd = process6.cwd(), env = process6.env, home = homedir()) {
|
|
1279
|
+
const directories = [];
|
|
1280
|
+
for (let dir = cwd;!directories.includes(dir); dir = dirname(dir))
|
|
1281
|
+
directories.push(dir);
|
|
1282
|
+
if (!directories.includes(home))
|
|
1283
|
+
directories.push(home);
|
|
1284
|
+
const configs = [];
|
|
1285
|
+
for (const dir of directories) {
|
|
1286
|
+
const bunfig = await readIfThere(join(dir, "bunfig.toml"));
|
|
1287
|
+
const npmrc = await readIfThere(join(dir, ".npmrc"));
|
|
1288
|
+
if (bunfig !== undefined)
|
|
1289
|
+
configs.push(parseBunfig(bunfig, env));
|
|
1290
|
+
if (npmrc !== undefined)
|
|
1291
|
+
configs.push(parseNpmrc(npmrc, env));
|
|
1292
|
+
}
|
|
1293
|
+
return configs;
|
|
1294
|
+
}
|
|
1295
|
+
|
|
1296
|
+
// src/commands/check.ts
|
|
1297
|
+
var usage = `pkg <name>[@version]...
|
|
1298
|
+
|
|
1299
|
+
Checks npm packages before they are added: whether the name exists, the latest and the newest version at least two weeks old, weekly downloads, licence, repository, install scripts and a near miss of a popular name.
|
|
1300
|
+
Exits 1 when a package is missing or the version asked for is under the minimum age.`;
|
|
1301
|
+
var options = {
|
|
1302
|
+
json: jsonOption(),
|
|
1303
|
+
"min-age": { type: "string", description: `days a version must be old (${DEFAULT_MIN_AGE_DAYS})` }
|
|
1304
|
+
};
|
|
1305
|
+
async function checkPackage(text, context) {
|
|
1306
|
+
const spec = parseSpec(text);
|
|
1307
|
+
const registry = registryFor(spec.name, context.configs);
|
|
1308
|
+
const packument = await fetchPackument(spec.name, registry, context.fetcher);
|
|
1309
|
+
const downloads = packument !== undefined && isPublic(registry) ? await fetchDownloads(spec.name, context.fetcher) : undefined;
|
|
1310
|
+
return analyze({ spec, packument, downloads, registry: new URL(registry.url).host, now: context.now, minAgeDays: context.minAgeDays });
|
|
1311
|
+
}
|
|
1312
|
+
function when(release, now) {
|
|
1313
|
+
return release?.published === undefined ? "" : `, published ${formatAge(release.published, now)} (${release.published.slice(0, 10)})`;
|
|
1314
|
+
}
|
|
1315
|
+
function render(report, now = Date.now()) {
|
|
1316
|
+
if (!report.exists)
|
|
1317
|
+
return [report.name, ...report.warnings.map((warning) => ` warning: ${warning}`)].join(`
|
|
1318
|
+
`);
|
|
1319
|
+
const asked = report.requested === undefined ? "" : ` (asked for ${report.requested})`;
|
|
1320
|
+
const rows = [
|
|
1321
|
+
["version", report.version === undefined ? `none${asked}` : `${report.version}${asked}${when(report, now)}`],
|
|
1322
|
+
["latest", report.latest === undefined ? "-" : `${report.latest.version}${when(report.latest, now)}`],
|
|
1323
|
+
["safe", report.safe === undefined ? "-" : `${report.safe.version}${when(report.safe, now)}`],
|
|
1324
|
+
["downloads", report.downloads === undefined ? "-" : `${report.downloads.toLocaleString("en-US")} last week`],
|
|
1325
|
+
["license", report.license ?? "-"],
|
|
1326
|
+
["repository", report.repository ?? "-"],
|
|
1327
|
+
...Object.entries(report.installScripts).map(([name, command]) => [name, command])
|
|
1328
|
+
];
|
|
1329
|
+
return [
|
|
1330
|
+
`${report.name}${report.description === undefined ? "" : `: ${report.description}`}`,
|
|
1331
|
+
table(rows.map(([key, value]) => [` ${key}`, value ?? ""])),
|
|
1332
|
+
...report.warnings.map((warning) => ` warning: ${warning}`)
|
|
1333
|
+
].join(`
|
|
1334
|
+
`);
|
|
1335
|
+
}
|
|
1336
|
+
async function check(args) {
|
|
1337
|
+
const parsed = parse(args, usage, options);
|
|
1338
|
+
const { values, positionals } = parsed;
|
|
1339
|
+
if (positionals.length === 0)
|
|
1340
|
+
fail(`a package name is needed
|
|
1341
|
+
|
|
1342
|
+
${usage}`);
|
|
1343
|
+
const context = { configs: await loadConfigs(), minAgeDays: wholeNumber(values["min-age"], "min-age", DEFAULT_MIN_AGE_DAYS, 0) };
|
|
1344
|
+
const reports = await Promise.all(positionals.map(async (text) => checkPackage(text, context)));
|
|
1345
|
+
if (values.json === true)
|
|
1346
|
+
printJson(reports.length === 1 ? reports[0] : reports);
|
|
1347
|
+
else
|
|
1348
|
+
console.log(reports.map((report) => render(report)).join(`
|
|
1349
|
+
|
|
1350
|
+
`));
|
|
1351
|
+
return reports.some((report) => report.blocked) ? 1 : 0;
|
|
1352
|
+
}
|
|
1353
|
+
|
|
1354
|
+
// src/cli.ts
|
|
1355
|
+
process7.exitCode = await runMain({ name: "pkg", version, run: check });
|