@kaynooo/cli-pkg 0.18.0 → 0.18.2
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/dist/chunk-26yfv47h.js +10 -0
- package/dist/chunk-3sqd2sjj.js +2 -0
- package/dist/chunk-4pczvmv2.js +3 -0
- package/dist/chunk-63sp907v.js +3 -0
- package/dist/chunk-6hee5zwv.js +5 -0
- package/dist/chunk-8r692fbd.js +69 -0
- package/dist/chunk-aewr3ng3.js +4 -0
- package/dist/chunk-e8r5gg6z.js +2 -0
- package/dist/chunk-g0nhwvkx.js +4 -0
- package/dist/chunk-k38f1cnr.js +3 -0
- package/dist/chunk-kkqv33zk.js +3 -0
- package/dist/chunk-qwyrfgsk.js +7 -0
- package/dist/chunk-r39f8sqm.js +2 -0
- package/dist/chunk-x4gvcn9p.js +5 -0
- package/dist/chunk-yzmg1222.js +9 -0
- package/dist/cli.js +3 -4498
- package/package.json +14 -11
package/dist/cli.js
CHANGED
|
@@ -1,4498 +1,3 @@
|
|
|
1
|
-
#!/
|
|
2
|
-
// @bun
|
|
3
|
-
|
|
4
|
-
var __returnValue = (v) => v;
|
|
5
|
-
function __exportSetter(name, newValue) {
|
|
6
|
-
this[name] = __returnValue.bind(null, newValue);
|
|
7
|
-
}
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, {
|
|
11
|
-
get: all[name],
|
|
12
|
-
enumerable: true,
|
|
13
|
-
configurable: true,
|
|
14
|
-
set: __exportSetter.bind(all, name)
|
|
15
|
-
});
|
|
16
|
-
};
|
|
17
|
-
var __esm = (fn, res, err) => () => {
|
|
18
|
-
if (fn)
|
|
19
|
-
try {
|
|
20
|
-
res = fn(fn = 0);
|
|
21
|
-
} catch (e) {
|
|
22
|
-
err = [e];
|
|
23
|
-
}
|
|
24
|
-
if (err)
|
|
25
|
-
throw err[0];
|
|
26
|
-
return res;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
// ../kit/src/advisory.ts
|
|
30
|
-
function severityRank(severity) {
|
|
31
|
-
return SEVERITIES.indexOf(severity);
|
|
32
|
-
}
|
|
33
|
-
function isIgnored(advisory, ignore) {
|
|
34
|
-
return ignore.includes(advisory.ghsa ?? "") || ignore.includes(String(advisory.id));
|
|
35
|
-
}
|
|
36
|
-
var SEVERITIES;
|
|
37
|
-
var init_advisory = __esm(() => {
|
|
38
|
-
SEVERITIES = ["low", "moderate", "high", "critical"];
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rkhsft4a.js
|
|
42
|
-
function G(t, e, { plural: r, zero: n = "singular" } = {}) {
|
|
43
|
-
if (e === 1 || e === 0 && n === "singular")
|
|
44
|
-
return t;
|
|
45
|
-
if (r !== undefined)
|
|
46
|
-
return r;
|
|
47
|
-
if (t.endsWith("y") && !ct.test(t))
|
|
48
|
-
return `${t.slice(0, -1)}ies`;
|
|
49
|
-
if (t.endsWith("s") || t.endsWith("x") || t.endsWith("z") || t.endsWith("ch") || t.endsWith("sh"))
|
|
50
|
-
return `${t}es`;
|
|
51
|
-
if (Ot.test(t))
|
|
52
|
-
return `${t.slice(0, -1)}ves`;
|
|
53
|
-
return Gt.test(t) ? `${t.slice(0, -2)}ves` : `${t}s`;
|
|
54
|
-
}
|
|
55
|
-
function bo(t, e, { zero: r = "plural", ...n } = {}) {
|
|
56
|
-
return `${t} ${G(e, t, { ...n, zero: r })}`;
|
|
57
|
-
}
|
|
58
|
-
function Ao(t, e, r = "...") {
|
|
59
|
-
let { suffix: n = "...", includeSuffix: s = false, wordBoundary: o = false } = typeof r === "string" ? { suffix: r } : r;
|
|
60
|
-
if (t.length <= e)
|
|
61
|
-
return t;
|
|
62
|
-
let l = Math.max(0, e), c = t.substring(0, Math.max(0, s ? l - n.length : l));
|
|
63
|
-
if (o && !Y.test(t[c.length] ?? " "))
|
|
64
|
-
c = c.replace(Nt, "") || c;
|
|
65
|
-
if (o)
|
|
66
|
-
c = c.trimEnd();
|
|
67
|
-
return s ? (c + n).slice(0, l) : c + n;
|
|
68
|
-
}
|
|
69
|
-
var ct, N, Ot, Gt, Nt, Y, be, W;
|
|
70
|
-
var init_chunk_rkhsft4a = __esm(() => {
|
|
71
|
-
ct = /[aeiou]y$/;
|
|
72
|
-
N = new Map;
|
|
73
|
-
Ot = /(?:leaf|loaf|thief|wolf|half|calf|elf|sheaf|scarf|dwarf|hoof|wharf)$/;
|
|
74
|
-
Gt = /(?:knife|life|wife)$/;
|
|
75
|
-
Nt = /\s+\S*$/;
|
|
76
|
-
Y = /\s/;
|
|
77
|
-
be = new Map(["\u20AC", "", "\u201A", "\u0192", "\u201E", "\u2026", "\u2020", "\u2021", "\u02C6", "\u2030", "\u0160", "\u2039", "\u0152", "", "\u017D", "", "", "\u2018", "\u2019", "\u201C", "\u201D", "\u2022", "\u2013", "\u2014", "\u02DC", "\u2122", "\u0161", "\u203A", "\u0153", "", "\u017E", "\u0178"].map((t, e) => [t, 128 + e]).filter(([t]) => t));
|
|
78
|
-
W = new Map;
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/text.js
|
|
82
|
-
var init_text = __esm(() => {
|
|
83
|
-
init_chunk_rkhsft4a();
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
// ../kit/src/mode.ts
|
|
87
|
-
import process2 from "process";
|
|
88
|
-
function isSet(value) {
|
|
89
|
-
return value !== undefined && value !== "" && value !== "0" && value.toLowerCase() !== "false";
|
|
90
|
-
}
|
|
91
|
-
function outputMode(stream = process2.stdout, env = process2.env) {
|
|
92
|
-
const chosen = env.KIT_MODE;
|
|
93
|
-
if (chosen !== undefined && MODES.has(chosen))
|
|
94
|
-
return chosen;
|
|
95
|
-
if (AGENT_VARIABLES.some((name) => isSet(env[name])))
|
|
96
|
-
return "agent";
|
|
97
|
-
if (stream.isTTY === true)
|
|
98
|
-
return "terminal";
|
|
99
|
-
return isSet(env.CI) ? "ci" : "pipe";
|
|
100
|
-
}
|
|
101
|
-
function isInteractive(streams = process2) {
|
|
102
|
-
return streams.stdin?.isTTY === true && streams.stderr?.isTTY === true;
|
|
103
|
-
}
|
|
104
|
-
var MODES, AGENT_VARIABLES;
|
|
105
|
-
var init_mode = __esm(() => {
|
|
106
|
-
MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
107
|
-
AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
|
|
111
|
-
function b(r) {
|
|
112
|
-
let e = r.startsWith("#") ? r.slice(1) : r;
|
|
113
|
-
if (!G2.test(e))
|
|
114
|
-
return [0, 0, 0];
|
|
115
|
-
if (e.length === 3 || e.length === 4)
|
|
116
|
-
return [Number.parseInt(e[0] + e[0], 16), Number.parseInt(e[1] + e[1], 16), Number.parseInt(e[2] + e[2], 16)];
|
|
117
|
-
if (e.length !== 6 && e.length !== 8)
|
|
118
|
-
throw Error(`Invalid hex color length: ${e.length}`);
|
|
119
|
-
return [Number.parseInt(e.slice(0, 2), 16), Number.parseInt(e.slice(2, 4), 16), Number.parseInt(e.slice(4, 6), 16)];
|
|
120
|
-
}
|
|
121
|
-
function C(r, e = globalThis.process?.env ?? {}) {
|
|
122
|
-
if (e.FORCE_COLOR !== undefined)
|
|
123
|
-
return h.has(e.FORCE_COLOR);
|
|
124
|
-
if (e.NO_COLOR !== undefined || e.NODE_DISABLE_COLORS !== undefined || e.TERM === "dumb")
|
|
125
|
-
return false;
|
|
126
|
-
return r?.isTTY === true;
|
|
127
|
-
}
|
|
128
|
-
function f(r, e = []) {
|
|
129
|
-
let l = "", n = "";
|
|
130
|
-
for (let t = 0, i = e.length;t < i; t++)
|
|
131
|
-
l += `\x1B[${e[t][0]}m`, n = `\x1B[${e[t][1]}m${n}`;
|
|
132
|
-
let c = (t) => C(r.stream ?? globalThis.process?.stdout, r.env) ? l + t + n : t, g = new Map;
|
|
133
|
-
return new Proxy(c, { get(t, i) {
|
|
134
|
-
let a = B[i];
|
|
135
|
-
if (Array.isArray(a)) {
|
|
136
|
-
let s = g.get(i);
|
|
137
|
-
if (s === undefined)
|
|
138
|
-
s = f(r, [...e, a]), g.set(i, s);
|
|
139
|
-
return s;
|
|
140
|
-
}
|
|
141
|
-
if (typeof a === "function")
|
|
142
|
-
return (...s) => {
|
|
143
|
-
let y = `${i}:${s.join(",")}`, u = g.get(y);
|
|
144
|
-
if (u === undefined) {
|
|
145
|
-
if (g.size >= 64)
|
|
146
|
-
g.clear();
|
|
147
|
-
u = f(r, [...e, a(...s)]), g.set(y, u);
|
|
148
|
-
}
|
|
149
|
-
return u;
|
|
150
|
-
};
|
|
151
|
-
throw Error(`Unknown style: ${String(i)}`);
|
|
152
|
-
} });
|
|
153
|
-
}
|
|
154
|
-
function Fe(r = {}) {
|
|
155
|
-
return f(r);
|
|
156
|
-
}
|
|
157
|
-
var G2, B, h, o;
|
|
158
|
-
var init_chunk_x450vn3m = __esm(() => {
|
|
159
|
-
G2 = /^[a-f0-9]+$/i;
|
|
160
|
-
B = { 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, 39], red: [31, 39], green: [32, 39], yellow: [33, 39], blue: [34, 39], magenta: [35, 39], cyan: [36, 39], white: [37, 39], gray: [90, 39], grey: [90, 39], blackBright: [90, 39], redBright: [91, 39], greenBright: [92, 39], yellowBright: [93, 39], blueBright: [94, 39], magentaBright: [95, 39], cyanBright: [96, 39], whiteBright: [97, 39], bgBlack: [40, 49], bgRed: [41, 49], bgGreen: [42, 49], bgYellow: [43, 49], bgBlue: [44, 49], bgMagenta: [45, 49], bgCyan: [46, 49], bgWhite: [47, 49], bgBlackBright: [100, 49], bgRedBright: [101, 49], bgGreenBright: [102, 49], bgYellowBright: [103, 49], bgBlueBright: [104, 49], bgMagentaBright: [105, 49], bgCyanBright: [106, 49], bgWhiteBright: [107, 49], rgb: (r, e, l, n = "fg") => [`${n === "fg" ? 38 : 48};2;${r};${e};${l}`, n === "fg" ? 39 : 49], hex: (r, e = "fg") => {
|
|
161
|
-
let [l, n, c] = b(r);
|
|
162
|
-
return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
|
|
163
|
-
}, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
|
|
164
|
-
h = new Set(["", "1", "2", "3", "true"]);
|
|
165
|
-
o = Fe();
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/tools/colors.js
|
|
169
|
-
var init_colors = __esm(() => {
|
|
170
|
-
init_chunk_x450vn3m();
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
// ../kit/src/config.ts
|
|
174
|
-
import { existsSync } from "fs";
|
|
175
|
-
import { dirname, join, resolve } from "path";
|
|
176
|
-
import process3 from "process";
|
|
177
|
-
function findUp(names, from = process3.cwd(), stop = () => false) {
|
|
178
|
-
const wanted = typeof names === "string" ? [names] : names;
|
|
179
|
-
for (let dir = resolve(from);; dir = dirname(dir)) {
|
|
180
|
-
const found = wanted.map((name) => join(dir, name)).find((path) => existsSync(path));
|
|
181
|
-
if (found !== undefined)
|
|
182
|
-
return found;
|
|
183
|
-
if (stop(dir) || dirname(dir) === dir)
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
var init_config = __esm(() => {
|
|
188
|
-
init_args();
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
// ../kit/src/user-config.ts
|
|
192
|
-
import { existsSync as existsSync2, readFileSync } from "fs";
|
|
193
|
-
import { homedir } from "os";
|
|
194
|
-
import { isAbsolute, join as join2 } from "path";
|
|
195
|
-
import process4 from "process";
|
|
196
|
-
function xdgFolder(value, fallback) {
|
|
197
|
-
return value !== undefined && isAbsolute(value) ? value : fallback;
|
|
198
|
-
}
|
|
199
|
-
function configBase(where = {}) {
|
|
200
|
-
const xdg = where.xdg ?? (where.home === undefined ? process4.env.XDG_CONFIG_HOME : undefined);
|
|
201
|
-
return xdgFolder(xdg, join2(where.home ?? homedir(), ".config"));
|
|
202
|
-
}
|
|
203
|
-
function userConfigPath(bin, where = {}) {
|
|
204
|
-
return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
|
|
205
|
-
}
|
|
206
|
-
function userConfigReadPath(bin, legacy = [], where = {}) {
|
|
207
|
-
const current = userConfigPath(bin, where);
|
|
208
|
-
if (existsSync2(current))
|
|
209
|
-
return current;
|
|
210
|
-
const base = configBase(where);
|
|
211
|
-
return legacy.map((parts) => join2(base, ...parts)).find((path) => existsSync2(path)) ?? current;
|
|
212
|
-
}
|
|
213
|
-
function readUserConfig(bin, where = {}, legacy = []) {
|
|
214
|
-
const path = userConfigReadPath(bin, legacy, where);
|
|
215
|
-
if (!existsSync2(path))
|
|
216
|
-
return {};
|
|
217
|
-
try {
|
|
218
|
-
const parsed = Bun.JSONC.parse(readFileSync(path, "utf8"));
|
|
219
|
-
return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? parsed : {};
|
|
220
|
-
} catch {
|
|
221
|
-
return {};
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
var init_user_config = () => {};
|
|
225
|
-
|
|
226
|
-
// ../kit/src/theme.ts
|
|
227
|
-
import { existsSync as existsSync3, readFileSync as readFileSync2, statSync } from "fs";
|
|
228
|
-
import { homedir as homedir2 } from "os";
|
|
229
|
-
import { join as join3, resolve as resolve2 } from "path";
|
|
230
|
-
import process5 from "process";
|
|
231
|
-
function toLinear(channel) {
|
|
232
|
-
const value = channel / 255;
|
|
233
|
-
return value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;
|
|
234
|
-
}
|
|
235
|
-
function toOklab(hex) {
|
|
236
|
-
const [r, g, b] = [1, 3, 5].map((at) => toLinear(Number.parseInt(hex.slice(at, at + 2), 16)));
|
|
237
|
-
const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);
|
|
238
|
-
const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b);
|
|
239
|
-
const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);
|
|
240
|
-
return [0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s, 1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s, 0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s];
|
|
241
|
-
}
|
|
242
|
-
function fromOklab([lightness, a, b]) {
|
|
243
|
-
const l = (lightness + 0.3963377774 * a + 0.2158037573 * b) ** 3;
|
|
244
|
-
const m = (lightness - 0.1055613458 * a - 0.0638541728 * b) ** 3;
|
|
245
|
-
const s = (lightness - 0.0894841775 * a - 1.291485548 * b) ** 3;
|
|
246
|
-
const channels = [4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s, -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s, -0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s];
|
|
247
|
-
return `#${channels.map((channel) => fromLinear(channel).toString(16).padStart(2, "0")).join("")}`;
|
|
248
|
-
}
|
|
249
|
-
function gradientAt(theme, ratio) {
|
|
250
|
-
if (theme.gradient === undefined)
|
|
251
|
-
return;
|
|
252
|
-
const key = theme.gradient.join();
|
|
253
|
-
let ends = ENDS.get(key);
|
|
254
|
-
if (ends === undefined) {
|
|
255
|
-
ends = [toOklab(theme.gradient[0]), toOklab(theme.gradient[1])];
|
|
256
|
-
ENDS.set(key, ends);
|
|
257
|
-
}
|
|
258
|
-
const at = Math.min(1, Math.max(0, ratio));
|
|
259
|
-
const [from, to] = ends;
|
|
260
|
-
return fromOklab(from.map((start, index) => start + (to[index] - start) * at));
|
|
261
|
-
}
|
|
262
|
-
function isColorSpec(spec) {
|
|
263
|
-
if (typeof spec === "number")
|
|
264
|
-
return Number.isInteger(spec) && spec >= 0 && spec <= 255;
|
|
265
|
-
return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
|
|
266
|
-
}
|
|
267
|
-
function cubeLevel(channel) {
|
|
268
|
-
return CUBE.reduce((best, value, level) => Math.abs(value - channel) < Math.abs(CUBE[best] - channel) ? level : best, 0);
|
|
269
|
-
}
|
|
270
|
-
function nearest256(hex) {
|
|
271
|
-
const rgb = [1, 3, 5].map((at) => Number.parseInt(hex.slice(at, at + 2), 16));
|
|
272
|
-
const levels = rgb.map(cubeLevel);
|
|
273
|
-
const cube = levels.map((level) => CUBE[level]);
|
|
274
|
-
const grey = Math.min(23, Math.max(0, Math.round((rgb.reduce((sum, channel) => sum + channel, 0) / 3 - 8) / 10)));
|
|
275
|
-
const greyValue = 8 + grey * 10;
|
|
276
|
-
const distance = (colour) => colour.reduce((sum, channel, at) => sum + (channel - rgb[at]) ** 2, 0);
|
|
277
|
-
return distance([greyValue, greyValue, greyValue]) < distance(cube) ? 232 + grey : 16 + 36 * levels[0] + 6 * levels[1] + levels[2];
|
|
278
|
-
}
|
|
279
|
-
function hasTrueColor(env) {
|
|
280
|
-
return env.COLORTERM === "truecolor" || env.COLORTERM === "24bit";
|
|
281
|
-
}
|
|
282
|
-
function tinted(colors, spec, env = process5.env) {
|
|
283
|
-
if (typeof spec === "number")
|
|
284
|
-
return colors.ansi256(spec);
|
|
285
|
-
return spec.trim().split(SPACES).reduce((chain, token) => {
|
|
286
|
-
if (HEX.test(token))
|
|
287
|
-
return hasTrueColor(env) ? chain.hex(token) : chain.ansi256(nearest256(token));
|
|
288
|
-
return chain[token] ?? chain;
|
|
289
|
-
}, colors);
|
|
290
|
-
}
|
|
291
|
-
function shaded(theme, colors, glyph, cells, width, env = process5.env) {
|
|
292
|
-
return Array.from({ length: cells }, (_, index) => tinted(colors, gradientAt(theme, width <= 1 ? 0 : index / (width - 1)) ?? theme.colors.accent, env)(glyph)).join("");
|
|
293
|
-
}
|
|
294
|
-
function isRecord(value) {
|
|
295
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
296
|
-
}
|
|
297
|
-
function readThemeFile(path, warn) {
|
|
298
|
-
try {
|
|
299
|
-
const stat = statSync(path, { throwIfNoEntry: false });
|
|
300
|
-
if (stat === undefined)
|
|
301
|
-
return;
|
|
302
|
-
if (!stat.isFile() || stat.size > MAX_FILE_BYTES) {
|
|
303
|
-
warn(`${path} is not a regular file under ${MAX_FILE_BYTES / 1024} KiB, theme ignored`);
|
|
304
|
-
return;
|
|
305
|
-
}
|
|
306
|
-
const parsed = JSON.parse(readFileSync2(path, "utf8"));
|
|
307
|
-
if (isRecord(parsed))
|
|
308
|
-
return parsed;
|
|
309
|
-
warn(`${path} is not a JSON object, theme ignored`);
|
|
310
|
-
} catch (error) {
|
|
311
|
-
warn(`${path} does not parse (${error instanceof Error ? error.message : String(error)}), theme ignored`);
|
|
312
|
-
}
|
|
313
|
-
return;
|
|
314
|
-
}
|
|
315
|
-
function applyPreset(theme, name, warn, where) {
|
|
316
|
-
if (name === undefined)
|
|
317
|
-
return;
|
|
318
|
-
if (typeof name !== "string" || !Object.hasOwn(PRESETS, name)) {
|
|
319
|
-
warn(`${where}: no preset ${String(name)}, one of ${Object.keys(PRESETS).join(", ")}`);
|
|
320
|
-
return;
|
|
321
|
-
}
|
|
322
|
-
const preset = PRESETS[name];
|
|
323
|
-
Object.assign(theme.colors, preset.colors);
|
|
324
|
-
Object.assign(theme.glyphs, preset.glyphs);
|
|
325
|
-
if (preset.accents !== undefined)
|
|
326
|
-
theme.accents = [...preset.accents];
|
|
327
|
-
if (Object.hasOwn(preset, "gradient"))
|
|
328
|
-
theme.gradient = preset.gradient;
|
|
329
|
-
return name;
|
|
330
|
-
}
|
|
331
|
-
function applyFile(theme, file, where, warn) {
|
|
332
|
-
if (isRecord(file.colors)) {
|
|
333
|
-
for (const [key, value] of Object.entries(file.colors)) {
|
|
334
|
-
if (!Object.hasOwn(DEFAULT.colors, key))
|
|
335
|
-
warn(`${where}: no colour ${key}, one of ${Object.keys(DEFAULT.colors).join(", ")}`);
|
|
336
|
-
else if (!isColorSpec(value))
|
|
337
|
-
warn(`${where}: colour ${key} is not an ANSI name, \`#rrggbb\` or a number up to 255`);
|
|
338
|
-
else
|
|
339
|
-
theme.colors[key] = value;
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
if (isRecord(file.glyphs)) {
|
|
343
|
-
for (const [key, value] of Object.entries(file.glyphs)) {
|
|
344
|
-
if (!Object.hasOwn(DEFAULT.glyphs, key))
|
|
345
|
-
warn(`${where}: no glyph ${key}, one of ${Object.keys(DEFAULT.glyphs).join(", ")}`);
|
|
346
|
-
else if (typeof value !== "string" || CONTROL.test(value) || Bun.stringWidth(value) !== 1)
|
|
347
|
-
warn(`${where}: glyph ${key} must be one visible character wide, with no control character`);
|
|
348
|
-
else
|
|
349
|
-
theme.glyphs[key] = value;
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
if (Array.isArray(file.accents) && file.accents.length > 0 && file.accents.every(isColorSpec))
|
|
353
|
-
theme.accents = [...file.accents];
|
|
354
|
-
else if (file.accents !== undefined)
|
|
355
|
-
warn(`${where}: accents must be a non-empty list of colours`);
|
|
356
|
-
if (file.gradient === null)
|
|
357
|
-
theme.gradient = undefined;
|
|
358
|
-
else if (Array.isArray(file.gradient) && file.gradient.length === 2 && file.gradient.every((end) => typeof end === "string" && HEX.test(end)))
|
|
359
|
-
theme.gradient = [file.gradient[0], file.gradient[1]];
|
|
360
|
-
else if (file.gradient !== undefined)
|
|
361
|
-
warn(`${where}: gradient must be two \`#rrggbb\` colours, or null for none`);
|
|
362
|
-
if (isRecord(file.bins)) {
|
|
363
|
-
for (const [bin, value] of Object.entries(file.bins)) {
|
|
364
|
-
if (isColorSpec(value))
|
|
365
|
-
theme.bins[bin] = value;
|
|
366
|
-
else
|
|
367
|
-
warn(`${where}: bin ${bin} has no valid colour`);
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
function endsWalk(home) {
|
|
372
|
-
return (dir) => dir === resolve2(home) || existsSync3(join3(dir, ".git"));
|
|
373
|
-
}
|
|
374
|
-
function warnOnce(message) {
|
|
375
|
-
if (warned.has(message))
|
|
376
|
-
return;
|
|
377
|
-
warned.add(message);
|
|
378
|
-
console.error(`warning: theme ${message}`);
|
|
379
|
-
}
|
|
380
|
-
function isPath(chosen) {
|
|
381
|
-
return chosen.includes("/") || chosen.endsWith(".json");
|
|
382
|
-
}
|
|
383
|
-
function loadTheme({ env = process5.env, from = process5.cwd(), home = homedir2(), warn = warnOnce } = {}) {
|
|
384
|
-
const theme = { colors: { ...DEFAULT.colors }, glyphs: { ...DEFAULT.glyphs }, accents: [...DEFAULT.accents], bins: Object.create(null), gradient: DEFAULT.gradient };
|
|
385
|
-
const sources = [];
|
|
386
|
-
const chosen = env.KIT_THEME ?? "";
|
|
387
|
-
const wanted = chosen === "" ? [userConfigPath("theme", { home, xdg: env.XDG_CONFIG_HOME }), findUp(join3(".kaynooo", "theme.json"), from, endsWalk(home))] : [];
|
|
388
|
-
if (isPath(chosen))
|
|
389
|
-
wanted.push(resolve2(from, chosen));
|
|
390
|
-
const files = [];
|
|
391
|
-
for (const path of wanted) {
|
|
392
|
-
const file = path === undefined ? undefined : readThemeFile(path, warn);
|
|
393
|
-
if (path !== undefined && file !== undefined)
|
|
394
|
-
files.push({ path, file });
|
|
395
|
-
}
|
|
396
|
-
let preset = "default";
|
|
397
|
-
if (chosen !== "" && !isPath(chosen)) {
|
|
398
|
-
preset = applyPreset(theme, chosen, warn, "KIT_THEME") ?? preset;
|
|
399
|
-
} else {
|
|
400
|
-
const named = files.findLast(({ file }) => file.preset !== undefined);
|
|
401
|
-
if (named !== undefined)
|
|
402
|
-
preset = applyPreset(theme, named.file.preset, warn, named.path) ?? preset;
|
|
403
|
-
}
|
|
404
|
-
for (const { path, file } of files) {
|
|
405
|
-
applyFile(theme, file, path, warn);
|
|
406
|
-
sources.push(path);
|
|
407
|
-
}
|
|
408
|
-
return { theme, sources, preset };
|
|
409
|
-
}
|
|
410
|
-
function activeTheme() {
|
|
411
|
-
const key = `${process5.cwd()}\x00${process5.env.KIT_THEME ?? ""}\x00${process5.env.XDG_CONFIG_HOME ?? ""}`;
|
|
412
|
-
if (current === undefined || key !== currentKey) {
|
|
413
|
-
current = loadTheme();
|
|
414
|
-
currentKey = key;
|
|
415
|
-
}
|
|
416
|
-
return current;
|
|
417
|
-
}
|
|
418
|
-
var fromLinear = (value) => Math.round(255 * Math.min(1, Math.max(0, value <= 0.0031308 ? value * 12.92 : 1.055 * value ** (1 / 2.4) - 0.055))), ENDS, DEFAULT, BRIGHT, MONO, ASCII, PRESETS, STYLES, HEX, CONTROL, MAX_FILE_BYTES, SPACES, CUBE, warned, current, currentKey = "";
|
|
419
|
-
var init_theme = __esm(() => {
|
|
420
|
-
init_config();
|
|
421
|
-
init_user_config();
|
|
422
|
-
ENDS = new Map;
|
|
423
|
-
DEFAULT = {
|
|
424
|
-
colors: { accent: "cyan", id: "yellow", path: "blue", label: "dim", value: "bold", ok: "green", warn: "yellow", problem: "red", note: "dim", plan: "magenta", passed: "green", failed: "red", running: "cyan", queued: "yellow", skipped: "dim" },
|
|
425
|
-
glyphs: { ok: "\u2713", warn: "\u25B2", problem: "\u2717", note: "\u203A", plan: "\u25C7", passed: "\u2713", failed: "\u2717", running: "\u25CF", queued: "\u25CB", skipped: "-", bar: "\u2501", rule: "\u2500", corner: "\u256D", open: "\u2022", leaf: "\xB7", guide: "\u2502" },
|
|
426
|
-
accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
|
|
427
|
-
bins: {},
|
|
428
|
-
gradient: ["#c084fc", "#67e8f9"]
|
|
429
|
-
};
|
|
430
|
-
BRIGHT = { accent: "cyanBright", id: "yellowBright", path: "blueBright", label: "white", value: "bold whiteBright", ok: "greenBright", warn: "yellowBright", problem: "redBright", note: "white", plan: "magentaBright", passed: "greenBright", failed: "redBright", running: "cyanBright", queued: "yellowBright", skipped: "white" };
|
|
431
|
-
MONO = { accent: "bold", id: "bold", path: "underline", label: "dim", value: "bold", ok: "bold", warn: "bold", problem: "bold", note: "dim", plan: "dim", passed: "bold", failed: "bold", running: "bold", queued: "dim", skipped: "dim" };
|
|
432
|
-
ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
|
|
433
|
-
PRESETS = {
|
|
434
|
-
default: {},
|
|
435
|
-
"high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
|
|
436
|
-
mono: { colors: MONO, accents: ["bold"], gradient: undefined },
|
|
437
|
-
ascii: { glyphs: ASCII }
|
|
438
|
-
};
|
|
439
|
-
STYLES = new Set(["bold", "dim", "italic", "underline", "inverse", "strikethrough", "black", "red", "green", "yellow", "blue", "magenta", "cyan", "white", "gray", "grey", "blackBright", "redBright", "greenBright", "yellowBright", "blueBright", "magentaBright", "cyanBright", "whiteBright"]);
|
|
440
|
-
HEX = /^#[0-9a-f]{6}$/i;
|
|
441
|
-
CONTROL = /\p{Cc}/u;
|
|
442
|
-
MAX_FILE_BYTES = 64 * 1024;
|
|
443
|
-
SPACES = /\s+/;
|
|
444
|
-
CUBE = [0, 95, 135, 175, 215, 255];
|
|
445
|
-
warned = new Set;
|
|
446
|
-
});
|
|
447
|
-
|
|
448
|
-
// ../kit/src/style.ts
|
|
449
|
-
import process6 from "process";
|
|
450
|
-
function takesControlCodes(stream, env = process6.env) {
|
|
451
|
-
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
452
|
-
}
|
|
453
|
-
function paint(stream, env = process6.env) {
|
|
454
|
-
return Fe({ stream: { isTTY: takesControlCodes(stream, env) }, env });
|
|
455
|
-
}
|
|
456
|
-
function marked(mark, text, stream, detail, env = process6.env) {
|
|
457
|
-
const colors = paint(stream, env);
|
|
458
|
-
let head = MARK_WORDS[mark];
|
|
459
|
-
if (takesControlCodes(stream, env)) {
|
|
460
|
-
const { theme } = activeTheme();
|
|
461
|
-
head = tinted(colors.bold, theme.colors[mark], env)(theme.glyphs[mark]);
|
|
462
|
-
}
|
|
463
|
-
return `${head} ${text}${detail === undefined ? "" : ` ${colors.dim(detail)}`}`;
|
|
464
|
-
}
|
|
465
|
-
function ok(text, detail) {
|
|
466
|
-
console.log(marked("ok", text, process6.stdout, detail));
|
|
467
|
-
}
|
|
468
|
-
function note(text, detail) {
|
|
469
|
-
console.log(marked("note", text, process6.stdout, detail));
|
|
470
|
-
}
|
|
471
|
-
function warn(text, detail) {
|
|
472
|
-
console.error(marked("warn", text, process6.stderr, detail));
|
|
473
|
-
}
|
|
474
|
-
function problem(text, detail) {
|
|
475
|
-
console.error(marked("problem", text, process6.stderr, detail));
|
|
476
|
-
}
|
|
477
|
-
function role(name, stream, env = process6.env) {
|
|
478
|
-
const colors = paint(stream, env);
|
|
479
|
-
return takesControlCodes(stream, env) ? tinted(colors, activeTheme().theme.colors[name], env) : colors;
|
|
480
|
-
}
|
|
481
|
-
var MARK_WORDS, STATUS_WORDS, STATUS_OF;
|
|
482
|
-
var init_style = __esm(() => {
|
|
483
|
-
init_colors();
|
|
484
|
-
init_mode();
|
|
485
|
-
init_theme();
|
|
486
|
-
MARK_WORDS = { ok: "ok:", warn: "warning:", problem: "error:", note: "note:", plan: "would:" };
|
|
487
|
-
STATUS_WORDS = {
|
|
488
|
-
passed: ["passed", "success", "succeeded", "ok"],
|
|
489
|
-
failed: ["failed", "failure", "error", "errored"],
|
|
490
|
-
running: ["running", "in_progress", "started", "holding"],
|
|
491
|
-
queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
|
|
492
|
-
skipped: ["skipped", "cancelled", "canceled", "manual"]
|
|
493
|
-
};
|
|
494
|
-
STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
|
|
495
|
-
});
|
|
496
|
-
|
|
497
|
-
// ../kit/src/format.ts
|
|
498
|
-
import process7 from "process";
|
|
499
|
-
function formatSeconds(total) {
|
|
500
|
-
let rest = Math.max(0, Math.round(total));
|
|
501
|
-
const amounts = UNITS.map(([unit, size]) => {
|
|
502
|
-
const amount = Math.floor(rest / size);
|
|
503
|
-
rest -= amount * size;
|
|
504
|
-
return `${amount}${unit}`;
|
|
505
|
-
});
|
|
506
|
-
const first = amounts.findIndex((amount) => !amount.startsWith("0"));
|
|
507
|
-
if (first === -1)
|
|
508
|
-
return "0s";
|
|
509
|
-
const next = amounts[first + 1];
|
|
510
|
-
return next === undefined || next.startsWith("0") ? amounts[first] ?? "0s" : `${amounts[first]} ${next}`;
|
|
511
|
-
}
|
|
512
|
-
function formatDuration(ms) {
|
|
513
|
-
return ms < 60000 ? `${(Math.max(0, ms) / 1000).toFixed(1)}s` : formatSeconds(ms / 1000);
|
|
514
|
-
}
|
|
515
|
-
function formatElapsed(ms) {
|
|
516
|
-
return formatSeconds(Math.floor(Math.max(0, ms) / 1000));
|
|
517
|
-
}
|
|
518
|
-
function upTo(text, separator) {
|
|
519
|
-
const end = text.indexOf(separator);
|
|
520
|
-
return end === -1 ? text : text.slice(0, end);
|
|
521
|
-
}
|
|
522
|
-
function formatAge(date, now = Date.now()) {
|
|
523
|
-
const at = typeof date === "number" ? date : Date.parse(date);
|
|
524
|
-
if (Number.isNaN(at))
|
|
525
|
-
return "-";
|
|
526
|
-
const seconds = (now - at) / 1000;
|
|
527
|
-
return seconds < 60 ? "just now" : `${upTo(formatSeconds(seconds), " ")} ago`;
|
|
528
|
-
}
|
|
529
|
-
function truncate(text, width) {
|
|
530
|
-
return Ao(text, width, { suffix: "\u2026", includeSuffix: true });
|
|
531
|
-
}
|
|
532
|
-
function textWidth(text) {
|
|
533
|
-
return Bun.stringWidth(text);
|
|
534
|
-
}
|
|
535
|
-
function table(rows, { cellWidth, header = false, align = [], fit, stream = process7.stdout, env = process7.env } = {}) {
|
|
536
|
-
const cells = cellWidth === undefined ? rows : rows.map((row) => row.map((cell) => truncate(cell.replaceAll(LINE_BREAKS, " "), cellWidth)));
|
|
537
|
-
if (outputMode(stream, env) === "agent")
|
|
538
|
-
return cells.map((row) => row.map((cell) => Bun.stripANSI(cell).replaceAll(/[\t\r\n]+/g, " ")).join("\t")).join(`
|
|
539
|
-
`);
|
|
540
|
-
const widths = [];
|
|
541
|
-
for (const row of cells) {
|
|
542
|
-
for (const [index, cell] of row.entries())
|
|
543
|
-
widths[index] = Math.max(widths[index] ?? 0, textWidth(cell));
|
|
544
|
-
}
|
|
545
|
-
const shown = fit === undefined ? cells : narrow(cells, widths, fit);
|
|
546
|
-
const colors = paint(stream);
|
|
547
|
-
const lines = shown.map((row) => row.map((cell, index) => {
|
|
548
|
-
const width = widths[index] ?? 0;
|
|
549
|
-
const gap = " ".repeat(Math.max(0, width - textWidth(cell)));
|
|
550
|
-
if (align[index] === "right")
|
|
551
|
-
return `${gap}${cell}`;
|
|
552
|
-
return index === row.length - 1 ? cell : `${cell}${gap}`;
|
|
553
|
-
}).join(" ").trimEnd());
|
|
554
|
-
const rule = header && takesControlCodes(stream) && lines.length > 1 ? [colors.dim("\u2500".repeat(Math.max(...lines.map(textWidth))))] : [];
|
|
555
|
-
return lines.flatMap((line, index) => header && index === 0 ? [colors.bold(line), ...rule] : [line]).join(`
|
|
556
|
-
`);
|
|
557
|
-
}
|
|
558
|
-
function narrow(rows, widths, limit) {
|
|
559
|
-
const used = () => widths.reduce((sum, width) => sum + width, 0) + 2 * Math.max(0, widths.length - 1);
|
|
560
|
-
const cuttable = (index) => rows.every((row) => !(row[index] ?? "").includes(ESCAPE));
|
|
561
|
-
const floor = 8;
|
|
562
|
-
while (used() > limit) {
|
|
563
|
-
let widest = -1;
|
|
564
|
-
for (const [index, width] of widths.entries()) {
|
|
565
|
-
if (cuttable(index) && width > floor && width > (widths[widest] ?? 0))
|
|
566
|
-
widest = index;
|
|
567
|
-
}
|
|
568
|
-
if (widest === -1)
|
|
569
|
-
break;
|
|
570
|
-
widths[widest] = Math.max(floor, (widths[widest] ?? 0) - (used() - limit));
|
|
571
|
-
}
|
|
572
|
-
return rows.map((row) => row.map((cell, index) => textWidth(cell) > (widths[index] ?? 0) ? truncate(cell, widths[index] ?? 0) : cell));
|
|
573
|
-
}
|
|
574
|
-
function jsonText(value, replacer, { stream = process7.stdout, env = process7.env } = {}) {
|
|
575
|
-
return JSON.stringify(value, replacer, outputMode(stream, env) === "agent" ? undefined : 2);
|
|
576
|
-
}
|
|
577
|
-
function printJson(value) {
|
|
578
|
-
console.log(jsonText(value));
|
|
579
|
-
}
|
|
580
|
-
var UNITS, LINE_BREAKS, ESCAPE;
|
|
581
|
-
var init_format = __esm(() => {
|
|
582
|
-
init_text();
|
|
583
|
-
init_mode();
|
|
584
|
-
init_style();
|
|
585
|
-
UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
|
|
586
|
-
LINE_BREAKS = /\s*\n\s*/g;
|
|
587
|
-
ESCAPE = String.fromCharCode(27);
|
|
588
|
-
});
|
|
589
|
-
|
|
590
|
-
// ../kit/src/help.ts
|
|
591
|
-
import process8 from "process";
|
|
592
|
-
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
593
|
-
const lines = usage.replace(USAGE_PREFIX, "").split(`
|
|
594
|
-
`);
|
|
595
|
-
const blank = lines.indexOf("");
|
|
596
|
-
const synopses = blank === -1 ? lines : lines.slice(0, blank);
|
|
597
|
-
const details = blank === -1 ? [] : lines.slice(blank + 1);
|
|
598
|
-
const colon = synopses[0].indexOf(": ");
|
|
599
|
-
const inline = synopses[0].slice(colon + 2);
|
|
600
|
-
const summary = colon === -1 ? details.shift() : `${inline.charAt(0).toUpperCase()}${inline.slice(1)}`;
|
|
601
|
-
if (colon !== -1)
|
|
602
|
-
synopses[0] = synopses[0].slice(0, colon);
|
|
603
|
-
const head = `${colors.bold("Usage:")} ${synopses.map((line) => line.replaceAll(OPTIONAL, (part) => colors.dim(part))).join(`
|
|
604
|
-
`)}`;
|
|
605
|
-
const lead = summary === undefined ? [] : ["", colors.bold(prose(summary, colors))];
|
|
606
|
-
const rest = details.length === 0 ? [] : ["", ...details.map((line) => prose(line, colors))];
|
|
607
|
-
return [head, ...lead, ...rest].join(`
|
|
608
|
-
`);
|
|
609
|
-
}
|
|
610
|
-
function prose(line, colors) {
|
|
611
|
-
if (colors.cyan("x") === "x")
|
|
612
|
-
return line;
|
|
613
|
-
return line.replaceAll(PROSE_MARKS, (match, code, flag) => code === undefined ? colors.cyan(flag ?? match) : colors.bold(code));
|
|
614
|
-
}
|
|
615
|
-
function helpText(usage, options, colors = paint(process8.stdout), { examples = [], exits = [] } = {}) {
|
|
616
|
-
return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
617
|
-
`);
|
|
618
|
-
}
|
|
619
|
-
function exitRows(exits, colors = paint(process8.stdout)) {
|
|
620
|
-
if (exits.length === 0)
|
|
621
|
-
return [];
|
|
622
|
-
return ["", `${colors.bold("Exit codes:")} ${exits.map(([code, meaning]) => `${colors.cyan(String(code))} ${meaning}`).join(", ")}`];
|
|
623
|
-
}
|
|
624
|
-
function wantsHelpJson(env = process8.env) {
|
|
625
|
-
return env.KIT_HELP === "json";
|
|
626
|
-
}
|
|
627
|
-
function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
628
|
-
const lines = usage.replace(USAGE_PREFIX, "").split(`
|
|
629
|
-
`);
|
|
630
|
-
const first = lines[0];
|
|
631
|
-
const colon = first.indexOf(": ");
|
|
632
|
-
const prose = lines[lines.indexOf("") + 1] ?? "";
|
|
633
|
-
const fallback = lines.includes("") ? `${prose.charAt(0).toLowerCase()}${prose.slice(1)}`.replace(FULL_STOP, "") : "";
|
|
634
|
-
return {
|
|
635
|
-
synopsis: colon === -1 ? first : first.slice(0, colon),
|
|
636
|
-
summary: colon === -1 ? fallback : first.slice(colon + 2),
|
|
637
|
-
...replaces === undefined ? {} : { replaces },
|
|
638
|
-
examples: examples.map((example) => typeof example === "string" ? { line: example } : { line: example[0], note: example[1] }),
|
|
639
|
-
...exits === undefined ? {} : { exits: exits.map(([code, meaning]) => ({ code, meaning })) },
|
|
640
|
-
...options === undefined ? {} : { options: Object.entries(options).map(([name, { short, description }]) => ({ name, ...short === undefined ? {} : { short }, ...description === undefined ? {} : { description } })) }
|
|
641
|
-
};
|
|
642
|
-
}
|
|
643
|
-
function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
644
|
-
if (examples.length === 0 || outputMode() === "agent")
|
|
645
|
-
return [];
|
|
646
|
-
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
647
|
-
}
|
|
648
|
-
function optionRows(options, colors = paint(process8.stdout)) {
|
|
649
|
-
const rows = Object.entries(options).map(([name, option]) => {
|
|
650
|
-
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
651
|
-
const choices = option.choices?.join("|");
|
|
652
|
-
const inline = choices !== undefined && choices.length <= MAX_INLINE_CHOICES;
|
|
653
|
-
const named = inline ? `<${choices}>` : "<value>";
|
|
654
|
-
const placeholder = option.optional === undefined ? named : `[${named}]`;
|
|
655
|
-
const value = option.type === "string" ? ` ${colors.dim(placeholder)}` : "";
|
|
656
|
-
const described = choices === undefined || inline ? option.description ?? "" : [option.description, `one of ${option.choices.join(", ")}`].filter(Boolean).join("; ");
|
|
657
|
-
return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: described };
|
|
658
|
-
});
|
|
659
|
-
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
660
|
-
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
661
|
-
}
|
|
662
|
-
var OPTIONAL, USAGE_PREFIX, FULL_STOP, PROSE_MARKS, MAX_INLINE_CHOICES = 24;
|
|
663
|
-
var init_help = __esm(() => {
|
|
664
|
-
init_mode();
|
|
665
|
-
init_style();
|
|
666
|
-
OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
667
|
-
USAGE_PREFIX = /^usage:\s*/i;
|
|
668
|
-
FULL_STOP = /\.$/;
|
|
669
|
-
PROSE_MARKS = /`([^`\n]+)`|(?<![\w-])(--[a-z][\w-]*|-[a-z](?![\w-]))/gi;
|
|
670
|
-
});
|
|
671
|
-
|
|
672
|
-
// ../kit/src/text.ts
|
|
673
|
-
function distance(a, b) {
|
|
674
|
-
const left = [...a];
|
|
675
|
-
const right = [...b];
|
|
676
|
-
let before = [];
|
|
677
|
-
let previous = Array.from({ length: right.length + 1 }, (_, index) => index);
|
|
678
|
-
for (const [i, x] of left.entries()) {
|
|
679
|
-
const current = [i + 1];
|
|
680
|
-
for (const [j, y] of right.entries()) {
|
|
681
|
-
let cost = Math.min((previous[j + 1] ?? 0) + 1, (current[j] ?? 0) + 1, (previous[j] ?? 0) + (x === y ? 0 : 1));
|
|
682
|
-
if (i > 0 && j > 0 && x === right[j - 1] && left[i - 1] === y)
|
|
683
|
-
cost = Math.min(cost, (before[j - 1] ?? 0) + 1);
|
|
684
|
-
current.push(cost);
|
|
685
|
-
}
|
|
686
|
-
before = previous;
|
|
687
|
-
previous = current;
|
|
688
|
-
}
|
|
689
|
-
return previous[right.length] ?? 0;
|
|
690
|
-
}
|
|
691
|
-
function closest(name, names) {
|
|
692
|
-
const started = names.find((known) => known.startsWith(name));
|
|
693
|
-
if (started !== undefined)
|
|
694
|
-
return started;
|
|
695
|
-
const [best] = names.map((known) => ({ known, far: distance(name, known) })).sort((a, b) => a.far - b.far);
|
|
696
|
-
return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
|
|
697
|
-
}
|
|
698
|
-
var init_text2 = () => {};
|
|
699
|
-
|
|
700
|
-
// ../kit/src/input.ts
|
|
701
|
-
import { fstatSync } from "fs";
|
|
702
|
-
import process9 from "process";
|
|
703
|
-
function wholeNumber(value, name, fallback, min = 1) {
|
|
704
|
-
if (value === undefined)
|
|
705
|
-
return fallback;
|
|
706
|
-
const number = Number(value);
|
|
707
|
-
if (!WHOLE.test(value) || !Number.isSafeInteger(number) || number < min)
|
|
708
|
-
badUsage(`${name.startsWith("<") ? name : `--${name}`} takes a whole number from ${min}, not ${value}`);
|
|
709
|
-
return number;
|
|
710
|
-
}
|
|
711
|
-
function durationMs(text, unit) {
|
|
712
|
-
if (BARE_DURATION.test(text))
|
|
713
|
-
return Number(text) * UNIT_MS[unit];
|
|
714
|
-
if (!DURATION.test(text))
|
|
715
|
-
return 0;
|
|
716
|
-
let ms = 0;
|
|
717
|
-
for (const [, amount, part] of text.matchAll(DURATION_PART))
|
|
718
|
-
ms += Number(amount) * UNIT_MS[part];
|
|
719
|
-
return ms;
|
|
720
|
-
}
|
|
721
|
-
function duration(value, name, fallback, unit = "s") {
|
|
722
|
-
if (value === undefined)
|
|
723
|
-
return fallback;
|
|
724
|
-
const ms = durationMs(value.trim(), unit);
|
|
725
|
-
if (ms < 1)
|
|
726
|
-
badUsage(`--${name} takes a duration such as 30s, 5m, 1h or 7d, not ${value}`);
|
|
727
|
-
return ms;
|
|
728
|
-
}
|
|
729
|
-
function isStdinPiped() {
|
|
730
|
-
const stat = fstatSync(0);
|
|
731
|
-
return stat.isFIFO() || stat.isFile();
|
|
732
|
-
}
|
|
733
|
-
async function readInput(path, { noStdin = "nothing is piped on stdin" } = {}) {
|
|
734
|
-
if (path === "-") {
|
|
735
|
-
if (process9.stdin.isTTY)
|
|
736
|
-
fail(noStdin);
|
|
737
|
-
return Bun.stdin.text();
|
|
738
|
-
}
|
|
739
|
-
const file = Bun.file(path);
|
|
740
|
-
if (!await file.exists())
|
|
741
|
-
fail(`no file ${path}`);
|
|
742
|
-
return file.text();
|
|
743
|
-
}
|
|
744
|
-
var WHOLE, BARE_DURATION, DURATION, DURATION_PART, UNIT_MS;
|
|
745
|
-
var init_input = __esm(() => {
|
|
746
|
-
init_args();
|
|
747
|
-
WHOLE = /^\d+$/;
|
|
748
|
-
BARE_DURATION = /^\d+(?:\.\d+)?$/;
|
|
749
|
-
DURATION = /^(?:\d+(?:\.\d+)?(?:ms|min|[smhd]))+$/;
|
|
750
|
-
DURATION_PART = /(\d+(?:\.\d+)?)(ms|min|[smhd])/g;
|
|
751
|
-
UNIT_MS = { ms: 1, s: 1000, m: 60000, min: 60000, h: 3600000, d: 86400000 };
|
|
752
|
-
});
|
|
753
|
-
|
|
754
|
-
// ../kit/src/args.ts
|
|
755
|
-
import process10 from "process";
|
|
756
|
-
import { parseArgs } from "util";
|
|
757
|
-
function jsonOption(holds) {
|
|
758
|
-
return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
|
|
759
|
-
}
|
|
760
|
-
function fail(message, code = 2, hint) {
|
|
761
|
-
throw new Exit(message, code, hint);
|
|
762
|
-
}
|
|
763
|
-
function badUsage(message) {
|
|
764
|
-
throw new UsageError(message);
|
|
765
|
-
}
|
|
766
|
-
|
|
767
|
-
class Completing {
|
|
768
|
-
options;
|
|
769
|
-
positionals;
|
|
770
|
-
candidates;
|
|
771
|
-
constructor(options, positionals = [], candidates = {}) {
|
|
772
|
-
this.options = options;
|
|
773
|
-
this.positionals = positionals;
|
|
774
|
-
this.candidates = candidates;
|
|
775
|
-
}
|
|
776
|
-
}
|
|
777
|
-
function applyOutput(color, plain, env = process10.env) {
|
|
778
|
-
const when = plain === true ? "never" : color ?? "auto";
|
|
779
|
-
if (when === "auto")
|
|
780
|
-
return;
|
|
781
|
-
if (when !== "always" && when !== "never")
|
|
782
|
-
badUsage(`--color takes auto, always or never, not ${when}`);
|
|
783
|
-
if (when === "always") {
|
|
784
|
-
env.FORCE_COLOR = "1";
|
|
785
|
-
delete env.NO_COLOR;
|
|
786
|
-
} else {
|
|
787
|
-
env.NO_COLOR = "1";
|
|
788
|
-
delete env.FORCE_COLOR;
|
|
789
|
-
}
|
|
790
|
-
}
|
|
791
|
-
function parse(args, usage, options, settings = {}) {
|
|
792
|
-
const output = Object.fromEntries(Object.entries(OUTPUT_OPTIONS).filter(([name]) => !(name in options)));
|
|
793
|
-
const all = { ...options, ...output, help: { type: "boolean", short: "h", description: "show this help" } };
|
|
794
|
-
const listing = listed(all, settings.allowNegative === true);
|
|
795
|
-
if (completion.active)
|
|
796
|
-
throw new Completing(listing, settings.positionals, settings.candidates);
|
|
797
|
-
const { own, rest } = settings.trailing === true ? splitTrailing(args, all, settings.positionals?.length ?? 0) : splitRest(args, settings.rest === true);
|
|
798
|
-
let parsed;
|
|
799
|
-
try {
|
|
800
|
-
parsed = parseArgs({ args: joinDashValues(withBare(withAliases(own, all), all), all), options: all, allowPositionals: true, allowNegative: settings.allowNegative === true, strict: true });
|
|
801
|
-
} catch (error) {
|
|
802
|
-
const message = parseError(error);
|
|
803
|
-
throw new UsageError(message, nearestOption(message, all, settings.allowNegative === true));
|
|
804
|
-
}
|
|
805
|
-
const values = parsed.values;
|
|
806
|
-
applyOutput("color" in output ? values.color : undefined, "plain" in output ? values.plain : undefined);
|
|
807
|
-
if (values.help === true) {
|
|
808
|
-
console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings, listing)) : helpText(usage, listing, undefined, settings));
|
|
809
|
-
throw new HelpShown;
|
|
810
|
-
}
|
|
811
|
-
checkChoices(parsed.values, all);
|
|
812
|
-
checkConflicts(parsed.values, all);
|
|
813
|
-
if (settings.positionals !== undefined)
|
|
814
|
-
checkPositionals(parsed.positionals, settings.positionals);
|
|
815
|
-
return { ...parsed, values: parsed.values, positionals: parsed.positionals, rest };
|
|
816
|
-
}
|
|
817
|
-
function splitRest(args, passes) {
|
|
818
|
-
const separator = passes ? args.indexOf("--") : -1;
|
|
819
|
-
return { own: separator === -1 ? args : args.slice(0, separator), rest: separator === -1 ? undefined : args.slice(separator + 1) };
|
|
820
|
-
}
|
|
821
|
-
function splitTrailing(args, options, count) {
|
|
822
|
-
const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
|
|
823
|
-
let seen = 0;
|
|
824
|
-
if (count === 0)
|
|
825
|
-
return { own: args, rest: undefined };
|
|
826
|
-
for (let at = 0;at < args.length; at++) {
|
|
827
|
-
const word = args[at];
|
|
828
|
-
if (word === "--")
|
|
829
|
-
break;
|
|
830
|
-
if (word.startsWith("-")) {
|
|
831
|
-
if (takesValue(word))
|
|
832
|
-
at++;
|
|
833
|
-
continue;
|
|
834
|
-
}
|
|
835
|
-
seen++;
|
|
836
|
-
if (seen === count)
|
|
837
|
-
return { own: args.slice(0, at + 1), rest: args.slice(at + 1) };
|
|
838
|
-
}
|
|
839
|
-
return { own: args, rest: undefined };
|
|
840
|
-
}
|
|
841
|
-
function listed(options, allowNegative) {
|
|
842
|
-
if (!allowNegative)
|
|
843
|
-
return options;
|
|
844
|
-
return Object.fromEntries(Object.entries(options).flatMap(([name, option]) => {
|
|
845
|
-
if (option.type !== "boolean" || option.negative === undefined)
|
|
846
|
-
return [[name, option]];
|
|
847
|
-
return [...option.description === undefined ? [] : [[name, option]], [`no-${name}`, { type: "boolean", description: option.negative }]];
|
|
848
|
-
}));
|
|
849
|
-
}
|
|
850
|
-
function withAliases(args, options) {
|
|
851
|
-
const named = new Map(Object.entries(options).flatMap(([name, { aliases = [] }]) => aliases.map((alias) => [`--${alias}`, `--${name}`])));
|
|
852
|
-
if (named.size === 0)
|
|
853
|
-
return args;
|
|
854
|
-
const separator = args.indexOf("--");
|
|
855
|
-
const own = separator === -1 ? args : args.slice(0, separator);
|
|
856
|
-
return [...own.map((arg) => {
|
|
857
|
-
const at = arg.indexOf("=");
|
|
858
|
-
const current = named.get(at === -1 ? arg : arg.slice(0, at));
|
|
859
|
-
return current === undefined ? arg : `${current}${at === -1 ? "" : arg.slice(at)}`;
|
|
860
|
-
}), ...separator === -1 ? [] : args.slice(separator)];
|
|
861
|
-
}
|
|
862
|
-
function withBare(args, options) {
|
|
863
|
-
const bare = new Map(Object.entries(options).flatMap(([name, { short, optional }]) => optional === undefined ? [] : [[`--${name}`, optional], ...short === undefined ? [] : [[`-${short}`, optional]]]));
|
|
864
|
-
if (bare.size === 0)
|
|
865
|
-
return args;
|
|
866
|
-
const separator = args.indexOf("--");
|
|
867
|
-
const own = separator === -1 ? args : args.slice(0, separator);
|
|
868
|
-
return [...own.flatMap((arg, index) => {
|
|
869
|
-
const optional = bare.get(arg);
|
|
870
|
-
const next = own[index + 1];
|
|
871
|
-
const value = next !== undefined && (optional?.accepts === undefined ? !next.startsWith("-") : optional.accepts.test(next));
|
|
872
|
-
return optional === undefined || value ? [arg] : [arg, optional.bare];
|
|
873
|
-
}), ...separator === -1 ? [] : args.slice(separator)];
|
|
874
|
-
}
|
|
875
|
-
function checkConflicts(values, options) {
|
|
876
|
-
const given = (name) => values[name] !== undefined && values[name] !== false;
|
|
877
|
-
for (const [name, { conflicts = [] }] of Object.entries(options)) {
|
|
878
|
-
const other = given(name) ? conflicts.find(given) : undefined;
|
|
879
|
-
if (other !== undefined)
|
|
880
|
-
badUsage(`--${name} cannot be used with --${other}`);
|
|
881
|
-
}
|
|
882
|
-
}
|
|
883
|
-
function checkChoices(values, options) {
|
|
884
|
-
for (const [name, option] of Object.entries(options)) {
|
|
885
|
-
if (option.choices === undefined)
|
|
886
|
-
continue;
|
|
887
|
-
const given = values[name];
|
|
888
|
-
for (const value of Array.isArray(given) ? given : [given]) {
|
|
889
|
-
if (typeof value === "string")
|
|
890
|
-
oneOf(value, name, option.choices);
|
|
891
|
-
}
|
|
892
|
-
}
|
|
893
|
-
}
|
|
894
|
-
function oneOf(value, name, choices) {
|
|
895
|
-
if (!choices.includes(value))
|
|
896
|
-
badUsage(`${name.startsWith("<") ? name : `--${name}`} takes one of ${choices.join(", ")}, not ${value}`);
|
|
897
|
-
return value;
|
|
898
|
-
}
|
|
899
|
-
function checkPositionals(given, names) {
|
|
900
|
-
const variadic = names.at(-1)?.replace("]", "").endsWith("...") === true;
|
|
901
|
-
const required = names.filter((name) => !name.startsWith("[")).length;
|
|
902
|
-
if (given.length < required)
|
|
903
|
-
badUsage(`missing ${names[given.length]}`);
|
|
904
|
-
if (!variadic && given.length > names.length)
|
|
905
|
-
badUsage(`unexpected argument ${given[names.length]}`);
|
|
906
|
-
}
|
|
907
|
-
function joinDashValues(args, options) {
|
|
908
|
-
const longOf = new Map(Object.entries(options).flatMap(([name, option]) => option.short === undefined ? [[`--${name}`, name]] : [[`--${name}`, name], [`-${option.short}`, name]]));
|
|
909
|
-
const isOption = (arg) => arg === "--" || longOf.has(arg.includes("=") ? arg.slice(0, arg.indexOf("=")) : arg);
|
|
910
|
-
const joined = [];
|
|
911
|
-
for (let i = 0;i < args.length; i++) {
|
|
912
|
-
const arg = args[i] ?? "";
|
|
913
|
-
if (arg === "--")
|
|
914
|
-
return [...joined, ...args.slice(i)];
|
|
915
|
-
const name = longOf.get(arg);
|
|
916
|
-
const next = args[i + 1];
|
|
917
|
-
if (name !== undefined && options[name]?.type === "string" && next !== undefined && next.startsWith("-") && next !== "-" && !isOption(next)) {
|
|
918
|
-
joined.push(`--${name}=${next}`);
|
|
919
|
-
i++;
|
|
920
|
-
} else {
|
|
921
|
-
joined.push(arg);
|
|
922
|
-
}
|
|
923
|
-
}
|
|
924
|
-
return joined;
|
|
925
|
-
}
|
|
926
|
-
function parseError(error) {
|
|
927
|
-
const message = upTo(error instanceof Error ? error.message : String(error), ". ");
|
|
928
|
-
return `${message.charAt(0).toLowerCase()}${message.slice(1)}`;
|
|
929
|
-
}
|
|
930
|
-
function nearestOption(message, options, allowNegative) {
|
|
931
|
-
const typed = UNKNOWN_OPTION.exec(message)?.[1];
|
|
932
|
-
if (typed === undefined)
|
|
933
|
-
return;
|
|
934
|
-
const word = typed.replace(DASHES, "");
|
|
935
|
-
if (word.length < 2 && !typed.startsWith("--"))
|
|
936
|
-
return;
|
|
937
|
-
const known = Object.entries(options).flatMap(([name, option]) => [
|
|
938
|
-
...option.short === undefined ? [] : [`-${option.short}`],
|
|
939
|
-
`--${name}`,
|
|
940
|
-
...allowNegative && option.type === "boolean" ? [`--no-${name}`] : []
|
|
941
|
-
]);
|
|
942
|
-
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
943
|
-
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
944
|
-
}
|
|
945
|
-
var DASHES, EXIT, Exit, UsageError, HelpShown, completion, OUTPUT_OPTIONS, UNKNOWN_OPTION;
|
|
946
|
-
var init_args = __esm(() => {
|
|
947
|
-
init_format();
|
|
948
|
-
init_help();
|
|
949
|
-
init_text2();
|
|
950
|
-
init_help();
|
|
951
|
-
init_input();
|
|
952
|
-
DASHES = /^-+/;
|
|
953
|
-
EXIT = Symbol.for("@kaynooo/cli-kit/Exit");
|
|
954
|
-
Exit = class Exit extends Error {
|
|
955
|
-
code;
|
|
956
|
-
hint;
|
|
957
|
-
[EXIT] = true;
|
|
958
|
-
constructor(message, code, hint) {
|
|
959
|
-
super(message);
|
|
960
|
-
this.code = code;
|
|
961
|
-
this.hint = hint;
|
|
962
|
-
}
|
|
963
|
-
static [Symbol.hasInstance](value) {
|
|
964
|
-
if (this !== Exit)
|
|
965
|
-
return Function.prototype[Symbol.hasInstance].call(this, value);
|
|
966
|
-
return typeof value === "object" && value !== null && value[EXIT] === true;
|
|
967
|
-
}
|
|
968
|
-
};
|
|
969
|
-
UsageError = class UsageError extends Exit {
|
|
970
|
-
constructor(message, hint) {
|
|
971
|
-
super(message, 2, hint);
|
|
972
|
-
}
|
|
973
|
-
};
|
|
974
|
-
HelpShown = class HelpShown extends Exit {
|
|
975
|
-
constructor() {
|
|
976
|
-
super("help shown", 0);
|
|
977
|
-
}
|
|
978
|
-
};
|
|
979
|
-
completion = { active: false };
|
|
980
|
-
OUTPUT_OPTIONS = {
|
|
981
|
-
color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
|
|
982
|
-
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
983
|
-
};
|
|
984
|
-
UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
985
|
-
});
|
|
986
|
-
|
|
987
|
-
// ../kit/src/argv.ts
|
|
988
|
-
import { readFileSync as readFileSync3, realpathSync } from "fs";
|
|
989
|
-
import { resolve as resolve3 } from "path";
|
|
990
|
-
import process11 from "process";
|
|
991
|
-
function commandLine() {
|
|
992
|
-
try {
|
|
993
|
-
return readFileSync3("/proc/self/cmdline", "utf8").split("\x00").slice(0, -1);
|
|
994
|
-
} catch {
|
|
995
|
-
return;
|
|
996
|
-
}
|
|
997
|
-
}
|
|
998
|
-
function realPath(word) {
|
|
999
|
-
try {
|
|
1000
|
-
return realpathSync(resolve3(word));
|
|
1001
|
-
} catch {
|
|
1002
|
-
return;
|
|
1003
|
-
}
|
|
1004
|
-
}
|
|
1005
|
-
function scriptArgs(argv = process11.argv.slice(2), cmdline = commandLine(), script = process11.argv[1]) {
|
|
1006
|
-
const target = script === undefined ? undefined : realPath(script) ?? script;
|
|
1007
|
-
const at = cmdline === undefined || target === undefined ? -1 : cmdline.findIndex((word, index) => index > 0 && (resolve3(word) === script || realPath(word) === target));
|
|
1008
|
-
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
1009
|
-
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
1010
|
-
}
|
|
1011
|
-
var init_argv = () => {};
|
|
1012
|
-
|
|
1013
|
-
// ../kit/src/chart.ts
|
|
1014
|
-
var init_chart = __esm(() => {
|
|
1015
|
-
init_format();
|
|
1016
|
-
init_mode();
|
|
1017
|
-
init_style();
|
|
1018
|
-
init_theme();
|
|
1019
|
-
});
|
|
1020
|
-
|
|
1021
|
-
// ../kit/src/process.ts
|
|
1022
|
-
import { readFileSync as readFileSync4 } from "fs";
|
|
1023
|
-
import { constants } from "os";
|
|
1024
|
-
import process12 from "process";
|
|
1025
|
-
function exitCodeOf(code, signal) {
|
|
1026
|
-
if (code !== null)
|
|
1027
|
-
return code;
|
|
1028
|
-
if (typeof signal === "number")
|
|
1029
|
-
return 128 + signal;
|
|
1030
|
-
return signal === null ? 129 : 128 + constants.signals[signal];
|
|
1031
|
-
}
|
|
1032
|
-
function groupsOf(pid) {
|
|
1033
|
-
try {
|
|
1034
|
-
const stat = readFileSync4(`/proc/${pid}/stat`, "utf8");
|
|
1035
|
-
const fields = stat.slice(stat.lastIndexOf(")") + 2).split(" ");
|
|
1036
|
-
return { group: Number(fields[2]), foreground: Number(fields[5]) };
|
|
1037
|
-
} catch {
|
|
1038
|
-
return;
|
|
1039
|
-
}
|
|
1040
|
-
}
|
|
1041
|
-
function heardTheTerminal(child) {
|
|
1042
|
-
if (child.pid === undefined)
|
|
1043
|
-
return false;
|
|
1044
|
-
const own = groupsOf("self");
|
|
1045
|
-
return own !== undefined && own.group === own.foreground && groupsOf(child.pid)?.group === own.group;
|
|
1046
|
-
}
|
|
1047
|
-
function holdSignals(cleanup) {
|
|
1048
|
-
let received;
|
|
1049
|
-
let child;
|
|
1050
|
-
const held = {
|
|
1051
|
-
get signal() {
|
|
1052
|
-
return received;
|
|
1053
|
-
},
|
|
1054
|
-
forward: (to) => {
|
|
1055
|
-
child = to;
|
|
1056
|
-
},
|
|
1057
|
-
release: () => {
|
|
1058
|
-
for (const signal of SIGNALS)
|
|
1059
|
-
process12.off(signal, onSignal);
|
|
1060
|
-
}
|
|
1061
|
-
};
|
|
1062
|
-
function onSignal(signal) {
|
|
1063
|
-
received = signal;
|
|
1064
|
-
if (child !== undefined) {
|
|
1065
|
-
if (!GROUP_SIGNALS.has(signal) || !heardTheTerminal(child))
|
|
1066
|
-
child.kill(signal);
|
|
1067
|
-
return;
|
|
1068
|
-
}
|
|
1069
|
-
if (cleanup === undefined)
|
|
1070
|
-
return;
|
|
1071
|
-
held.release();
|
|
1072
|
-
cleanup(signal);
|
|
1073
|
-
process12.kill(process12.pid, signal);
|
|
1074
|
-
}
|
|
1075
|
-
for (const signal of SIGNALS)
|
|
1076
|
-
process12.on(signal, onSignal);
|
|
1077
|
-
return held;
|
|
1078
|
-
}
|
|
1079
|
-
async function runCommand(argv, { cwd, env, stdin = "ignore", input, timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
|
|
1080
|
-
const chunks = [];
|
|
1081
|
-
const grouped = timeoutMs !== undefined || signal !== undefined || onStart !== undefined || onChunk !== undefined;
|
|
1082
|
-
const proc = Bun.spawn(argv, { ...cwd === undefined ? {} : { cwd }, ...env === undefined ? {} : { env }, stdin: input === undefined ? stdin : new TextEncoder().encode(input), stdout: "pipe", stderr: "pipe", ...grouped ? { detached: true } : {} });
|
|
1083
|
-
const state = { kept: 0, truncated: false, timedOut: false, failure: undefined, done: false };
|
|
1084
|
-
const timers = [];
|
|
1085
|
-
const killGroup = (killing) => {
|
|
1086
|
-
if (state.done)
|
|
1087
|
-
return;
|
|
1088
|
-
try {
|
|
1089
|
-
if (grouped)
|
|
1090
|
-
process12.kill(-proc.pid, killing);
|
|
1091
|
-
else
|
|
1092
|
-
proc.kill(killing);
|
|
1093
|
-
} catch {}
|
|
1094
|
-
};
|
|
1095
|
-
const stop = () => {
|
|
1096
|
-
killGroup("SIGTERM");
|
|
1097
|
-
timers.push(setTimeout(killGroup, KILL_GRACE_MS, "SIGKILL"));
|
|
1098
|
-
};
|
|
1099
|
-
const onAbort = () => stop();
|
|
1100
|
-
if (timeoutMs !== undefined) {
|
|
1101
|
-
timers.push(setTimeout(() => {
|
|
1102
|
-
state.timedOut = true;
|
|
1103
|
-
stop();
|
|
1104
|
-
}, timeoutMs));
|
|
1105
|
-
}
|
|
1106
|
-
if (signal?.aborted === true)
|
|
1107
|
-
onAbort();
|
|
1108
|
-
else
|
|
1109
|
-
signal?.addEventListener("abort", onAbort, { once: true });
|
|
1110
|
-
onStart?.({ kill: (killing) => killGroup(killing) });
|
|
1111
|
-
const drain = async (stream, name) => {
|
|
1112
|
-
for await (const data of stream) {
|
|
1113
|
-
if (state.failure !== undefined)
|
|
1114
|
-
continue;
|
|
1115
|
-
try {
|
|
1116
|
-
onChunk?.({ stream: name, data });
|
|
1117
|
-
} catch (error) {
|
|
1118
|
-
state.failure = error;
|
|
1119
|
-
stop();
|
|
1120
|
-
continue;
|
|
1121
|
-
}
|
|
1122
|
-
if (state.truncated)
|
|
1123
|
-
continue;
|
|
1124
|
-
let kept = data;
|
|
1125
|
-
if (state.kept + data.length > maxBytes) {
|
|
1126
|
-
let cut = maxBytes - state.kept;
|
|
1127
|
-
while (cut > 0 && ((data[cut] ?? 0) & 192) === 128)
|
|
1128
|
-
cut--;
|
|
1129
|
-
kept = data.subarray(0, cut);
|
|
1130
|
-
state.truncated = true;
|
|
1131
|
-
}
|
|
1132
|
-
state.kept += kept.length;
|
|
1133
|
-
if (kept.length > 0)
|
|
1134
|
-
chunks.push({ stream: name, data: kept });
|
|
1135
|
-
}
|
|
1136
|
-
};
|
|
1137
|
-
try {
|
|
1138
|
-
await Promise.all([drain(proc.stdout, "stdout"), drain(proc.stderr, "stderr")]);
|
|
1139
|
-
await proc.exited;
|
|
1140
|
-
} finally {
|
|
1141
|
-
state.done = true;
|
|
1142
|
-
for (const timer of timers)
|
|
1143
|
-
clearTimeout(timer);
|
|
1144
|
-
signal?.removeEventListener("abort", onAbort);
|
|
1145
|
-
}
|
|
1146
|
-
if (state.failure !== undefined)
|
|
1147
|
-
throw state.failure;
|
|
1148
|
-
const joined = () => Buffer.concat(chunks.map(({ data }) => data));
|
|
1149
|
-
let output;
|
|
1150
|
-
let text;
|
|
1151
|
-
let stdout;
|
|
1152
|
-
return {
|
|
1153
|
-
code: exitCodeOf(proc.exitCode, proc.signalCode),
|
|
1154
|
-
chunks,
|
|
1155
|
-
timedOut: state.timedOut,
|
|
1156
|
-
truncated: state.truncated,
|
|
1157
|
-
get output() {
|
|
1158
|
-
return output ??= joined();
|
|
1159
|
-
},
|
|
1160
|
-
get text() {
|
|
1161
|
-
return text ??= (output ??= joined()).toString();
|
|
1162
|
-
},
|
|
1163
|
-
get stdout() {
|
|
1164
|
-
return stdout ??= Buffer.concat(chunks.filter((chunk) => chunk.stream === "stdout").map((chunk) => chunk.data)).toString();
|
|
1165
|
-
}
|
|
1166
|
-
};
|
|
1167
|
-
}
|
|
1168
|
-
var KILL_GRACE_MS = 2000, SIGNALS, GROUP_SIGNALS;
|
|
1169
|
-
var init_process = __esm(() => {
|
|
1170
|
-
SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
1171
|
-
GROUP_SIGNALS = new Set(["SIGINT", "SIGHUP"]);
|
|
1172
|
-
});
|
|
1173
|
-
|
|
1174
|
-
// ../kit/src/progress.ts
|
|
1175
|
-
import process13 from "process";
|
|
1176
|
-
function liveRegion(render, stream = process13.stderr, env = process13.env) {
|
|
1177
|
-
if (!takesControlCodes(stream, env))
|
|
1178
|
-
return { redraw: () => {
|
|
1179
|
-
return;
|
|
1180
|
-
}, print: (text) => void stream.write(`${text}
|
|
1181
|
-
`), stop: () => {
|
|
1182
|
-
return;
|
|
1183
|
-
}, pause: () => () => {
|
|
1184
|
-
return;
|
|
1185
|
-
} };
|
|
1186
|
-
const write = stream.write.bind(stream);
|
|
1187
|
-
let frame = 0;
|
|
1188
|
-
let drawn = false;
|
|
1189
|
-
let paused = false;
|
|
1190
|
-
let stopped = false;
|
|
1191
|
-
const columns = () => {
|
|
1192
|
-
const now = stream.getWindowSize?.()[0] ?? stream.columns;
|
|
1193
|
-
return now === undefined || now === 0 ? 80 : now;
|
|
1194
|
-
};
|
|
1195
|
-
const clear = () => {
|
|
1196
|
-
if (drawn)
|
|
1197
|
-
write(CLEAR_BELOW);
|
|
1198
|
-
drawn = false;
|
|
1199
|
-
};
|
|
1200
|
-
const draw = () => {
|
|
1201
|
-
if (paused)
|
|
1202
|
-
return;
|
|
1203
|
-
const width = columns() - 1;
|
|
1204
|
-
const height = stream.rows === undefined || stream.rows === 0 ? 24 : stream.rows;
|
|
1205
|
-
const lines = render(FRAMES[frame++ % FRAMES.length]).slice(0, Math.max(1, height - 1)).map((line) => cutToWidth(line, width));
|
|
1206
|
-
if (lines.length === 0) {
|
|
1207
|
-
clear();
|
|
1208
|
-
return;
|
|
1209
|
-
}
|
|
1210
|
-
write(`${CLEAR_BELOW}${lines.join(`
|
|
1211
|
-
`)}${lines.length > 1 ? `\x1B[${lines.length - 1}A` : ""}\r`);
|
|
1212
|
-
drawn = true;
|
|
1213
|
-
};
|
|
1214
|
-
let timer = setInterval(draw, FRAME_MS);
|
|
1215
|
-
stream.on?.("resize", draw);
|
|
1216
|
-
let restore = interceptOutput(clear);
|
|
1217
|
-
let release = swallowInput();
|
|
1218
|
-
const onExit = () => {
|
|
1219
|
-
clear();
|
|
1220
|
-
release();
|
|
1221
|
-
};
|
|
1222
|
-
const signals = holdSignals(stop);
|
|
1223
|
-
function stop() {
|
|
1224
|
-
stopped = true;
|
|
1225
|
-
clearInterval(timer);
|
|
1226
|
-
stream.off?.("resize", draw);
|
|
1227
|
-
clear();
|
|
1228
|
-
restore();
|
|
1229
|
-
release();
|
|
1230
|
-
process13.off("exit", onExit);
|
|
1231
|
-
signals.release();
|
|
1232
|
-
}
|
|
1233
|
-
function pause() {
|
|
1234
|
-
if (paused || stopped)
|
|
1235
|
-
return () => {
|
|
1236
|
-
return;
|
|
1237
|
-
};
|
|
1238
|
-
paused = true;
|
|
1239
|
-
clearInterval(timer);
|
|
1240
|
-
stream.off?.("resize", draw);
|
|
1241
|
-
clear();
|
|
1242
|
-
restore();
|
|
1243
|
-
release();
|
|
1244
|
-
return () => {
|
|
1245
|
-
if (!paused || stopped)
|
|
1246
|
-
return;
|
|
1247
|
-
paused = false;
|
|
1248
|
-
timer = setInterval(draw, FRAME_MS);
|
|
1249
|
-
timer.unref();
|
|
1250
|
-
stream.on?.("resize", draw);
|
|
1251
|
-
restore = interceptOutput(clear);
|
|
1252
|
-
release = swallowInput();
|
|
1253
|
-
draw();
|
|
1254
|
-
};
|
|
1255
|
-
}
|
|
1256
|
-
timer.unref();
|
|
1257
|
-
process13.on("exit", onExit);
|
|
1258
|
-
return {
|
|
1259
|
-
redraw: draw,
|
|
1260
|
-
print: (text) => {
|
|
1261
|
-
clear();
|
|
1262
|
-
write(`${text}
|
|
1263
|
-
`);
|
|
1264
|
-
draw();
|
|
1265
|
-
},
|
|
1266
|
-
stop,
|
|
1267
|
-
pause
|
|
1268
|
-
};
|
|
1269
|
-
}
|
|
1270
|
-
function progressLine(stream = process13.stderr, env = process13.env) {
|
|
1271
|
-
const colors = paint(stream, env);
|
|
1272
|
-
const write = stream.write.bind(stream);
|
|
1273
|
-
const begun = performance.now();
|
|
1274
|
-
let started = begun;
|
|
1275
|
-
let current;
|
|
1276
|
-
const region = liveRegion((spinner) => current === undefined ? [] : [tintedParts(progressParts(current, spinner, performance.now() - started), colors)], stream, env);
|
|
1277
|
-
const end = (line) => {
|
|
1278
|
-
region.stop();
|
|
1279
|
-
write(`${line}
|
|
1280
|
-
`);
|
|
1281
|
-
};
|
|
1282
|
-
return {
|
|
1283
|
-
update: (progress) => {
|
|
1284
|
-
const step = current?.step;
|
|
1285
|
-
current = progress;
|
|
1286
|
-
if (progress.step !== step) {
|
|
1287
|
-
started = performance.now();
|
|
1288
|
-
region.redraw();
|
|
1289
|
-
}
|
|
1290
|
-
},
|
|
1291
|
-
stop: region.stop,
|
|
1292
|
-
pause: region.pause,
|
|
1293
|
-
done: (text) => end(marked("ok", text, stream, formatDuration(performance.now() - begun), env)),
|
|
1294
|
-
failed: (text) => end(marked("problem", text, stream, undefined, env))
|
|
1295
|
-
};
|
|
1296
|
-
}
|
|
1297
|
-
function progressParts({ step, done, total, unit }, spinner, ms) {
|
|
1298
|
-
const { theme } = activeTheme();
|
|
1299
|
-
const parts = [{ text: spinner, tint: (colors) => tinted(colors, theme.colors.accent) }, { text: ` ${step}`, tint: () => plain }];
|
|
1300
|
-
if (total !== undefined && total > 0) {
|
|
1301
|
-
const counted = Math.min(done ?? 0, total);
|
|
1302
|
-
const filled = Math.round(counted / total * BAR_WIDTH);
|
|
1303
|
-
parts.push({ text: " ", tint: () => plain }, { text: theme.glyphs.bar.repeat(filled), tint: (colors) => () => shaded(theme, colors, theme.glyphs.bar, filled, BAR_WIDTH) }, { text: theme.glyphs.bar.repeat(BAR_WIDTH - filled), tint: (colors) => colors.dim }, { text: ` ${counted}/${total}${unit === undefined ? "" : ` ${unit}`}`, tint: (colors) => colors.dim });
|
|
1304
|
-
}
|
|
1305
|
-
parts.push({ text: ` ${formatElapsed(ms)}`, tint: (colors) => colors.dim });
|
|
1306
|
-
return parts;
|
|
1307
|
-
}
|
|
1308
|
-
function plain(text) {
|
|
1309
|
-
return text;
|
|
1310
|
-
}
|
|
1311
|
-
function tintedParts(parts, colors) {
|
|
1312
|
-
return parts.map(({ text, tint }) => tint(colors)(text)).join("");
|
|
1313
|
-
}
|
|
1314
|
-
function cutToWidth(line, width) {
|
|
1315
|
-
if (Bun.stringWidth(line) <= width)
|
|
1316
|
-
return line;
|
|
1317
|
-
let room = width;
|
|
1318
|
-
let kept = "";
|
|
1319
|
-
let index = 0;
|
|
1320
|
-
let linked = false;
|
|
1321
|
-
while (index < line.length) {
|
|
1322
|
-
ESCAPE_CODE.lastIndex = index;
|
|
1323
|
-
const escape = ESCAPE_CODE.exec(line);
|
|
1324
|
-
if (escape !== null) {
|
|
1325
|
-
kept += escape[0];
|
|
1326
|
-
linked ||= escape[0].startsWith(`${ESC}]`);
|
|
1327
|
-
index = ESCAPE_CODE.lastIndex;
|
|
1328
|
-
continue;
|
|
1329
|
-
}
|
|
1330
|
-
const char = String.fromCodePoint(line.codePointAt(index));
|
|
1331
|
-
const columns = Bun.stringWidth(char);
|
|
1332
|
-
if (columns > room)
|
|
1333
|
-
break;
|
|
1334
|
-
kept += char;
|
|
1335
|
-
room -= columns;
|
|
1336
|
-
index += char.length;
|
|
1337
|
-
}
|
|
1338
|
-
return `${kept}${RESET_STYLE}${linked ? CLOSE_LINK : ""}`;
|
|
1339
|
-
}
|
|
1340
|
-
function swallowInput() {
|
|
1341
|
-
const input = process13.stdin;
|
|
1342
|
-
if (!input.isTTY)
|
|
1343
|
-
return () => {
|
|
1344
|
-
return;
|
|
1345
|
-
};
|
|
1346
|
-
const onData = (data) => {
|
|
1347
|
-
if (data.includes(CTRL_C))
|
|
1348
|
-
process13.kill(process13.pid, "SIGINT");
|
|
1349
|
-
};
|
|
1350
|
-
input.setRawMode(true);
|
|
1351
|
-
input.on("data", onData);
|
|
1352
|
-
input.resume();
|
|
1353
|
-
let released = false;
|
|
1354
|
-
return () => {
|
|
1355
|
-
if (released)
|
|
1356
|
-
return;
|
|
1357
|
-
released = true;
|
|
1358
|
-
input.off("data", onData);
|
|
1359
|
-
input.pause();
|
|
1360
|
-
input.setRawMode(false);
|
|
1361
|
-
};
|
|
1362
|
-
}
|
|
1363
|
-
function interceptOutput(clear) {
|
|
1364
|
-
const targets = [...CONSOLE_METHODS.map((name) => [console, name]), [process13.stdout, "write"], [process13.stderr, "write"]];
|
|
1365
|
-
const wrapped = targets.map(([target, name]) => {
|
|
1366
|
-
const original = Reflect.get(target, name);
|
|
1367
|
-
const wrapper = (...args) => {
|
|
1368
|
-
clear();
|
|
1369
|
-
return original.apply(target, args);
|
|
1370
|
-
};
|
|
1371
|
-
Reflect.set(target, name, wrapper);
|
|
1372
|
-
return { target, name, original, wrapper };
|
|
1373
|
-
});
|
|
1374
|
-
return () => {
|
|
1375
|
-
for (const { target, name, original, wrapper } of wrapped) {
|
|
1376
|
-
if (Reflect.get(target, name) === wrapper)
|
|
1377
|
-
Reflect.set(target, name, original);
|
|
1378
|
-
}
|
|
1379
|
-
};
|
|
1380
|
-
}
|
|
1381
|
-
var FRAMES, FRAME_MS = 200, BAR_WIDTH = 20, CLEAR_BELOW = "\r\x1B[J", ESC, ESCAPE_CODE, RESET_STYLE, CTRL_C = 3, CLOSE_LINK, CONSOLE_METHODS;
|
|
1382
|
-
var init_progress = __esm(() => {
|
|
1383
|
-
init_format();
|
|
1384
|
-
init_process();
|
|
1385
|
-
init_style();
|
|
1386
|
-
init_theme();
|
|
1387
|
-
FRAMES = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
|
|
1388
|
-
ESC = String.fromCharCode(27);
|
|
1389
|
-
ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x7E]|\\][^\\u0007${ESC}]*(?:\\u0007|${ESC}\\\\))`, "y");
|
|
1390
|
-
RESET_STYLE = `${ESC}[0m`;
|
|
1391
|
-
CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
1392
|
-
CONSOLE_METHODS = ["log", "info", "warn", "error", "debug", "dir", "dirxml", "table", "trace", "group", "groupCollapsed", "count", "timeEnd", "timeLog", "assert"];
|
|
1393
|
-
});
|
|
1394
|
-
|
|
1395
|
-
// ../kit/src/tool.ts
|
|
1396
|
-
var init_tool = __esm(() => {
|
|
1397
|
-
init_format();
|
|
1398
|
-
init_process();
|
|
1399
|
-
});
|
|
1400
|
-
|
|
1401
|
-
// ../kit/src/ci.ts
|
|
1402
|
-
var init_ci = __esm(() => {
|
|
1403
|
-
init_args();
|
|
1404
|
-
init_format();
|
|
1405
|
-
init_progress();
|
|
1406
|
-
init_style();
|
|
1407
|
-
init_tool();
|
|
1408
|
-
});
|
|
1409
|
-
|
|
1410
|
-
// ../kit/src/askpass.ts
|
|
1411
|
-
import process14 from "process";
|
|
1412
|
-
async function askpassClient(argv) {
|
|
1413
|
-
const socketPath = process14.env[SOCKET_VARIABLE];
|
|
1414
|
-
if (socketPath === undefined)
|
|
1415
|
-
return;
|
|
1416
|
-
const request = { prompt: argv[0] ?? "", ...process14.env.SSH_ASKPASS_PROMPT === "none" ? { notice: true } : {} };
|
|
1417
|
-
const { promise, resolve } = Promise.withResolvers();
|
|
1418
|
-
let received = "";
|
|
1419
|
-
try {
|
|
1420
|
-
await Bun.connect({
|
|
1421
|
-
unix: socketPath,
|
|
1422
|
-
socket: {
|
|
1423
|
-
open: (socket) => void socket.write(`${JSON.stringify(request)}
|
|
1424
|
-
`),
|
|
1425
|
-
data: (_, chunk) => {
|
|
1426
|
-
received += chunk.toString();
|
|
1427
|
-
},
|
|
1428
|
-
close: () => resolve(received),
|
|
1429
|
-
error: () => resolve("")
|
|
1430
|
-
}
|
|
1431
|
-
});
|
|
1432
|
-
} catch {
|
|
1433
|
-
return 1;
|
|
1434
|
-
}
|
|
1435
|
-
const reply = await promise;
|
|
1436
|
-
if (reply === "")
|
|
1437
|
-
return 1;
|
|
1438
|
-
const { answer } = JSON.parse(reply);
|
|
1439
|
-
if (request.notice === true)
|
|
1440
|
-
return 0;
|
|
1441
|
-
if (answer === undefined)
|
|
1442
|
-
return 1;
|
|
1443
|
-
process14.stdout.write(`${answer}
|
|
1444
|
-
`);
|
|
1445
|
-
return 0;
|
|
1446
|
-
}
|
|
1447
|
-
var SOCKET_VARIABLE = "KAYNOOO_ASKPASS_SOCKET";
|
|
1448
|
-
var init_askpass = () => {};
|
|
1449
|
-
|
|
1450
|
-
// ../kit/src/completions.ts
|
|
1451
|
-
function completionScript(shell, bins, header = `# Generated by \`${bins[0]} --completions ${shell}\``) {
|
|
1452
|
-
if (shell === "fish")
|
|
1453
|
-
return `${header}
|
|
1454
|
-
${FISH_FUNCTION}
|
|
1455
|
-
${bins.map((bin) => `complete -c ${bin} -f -a '(__kaynooo_cli_complete ${bin})'
|
|
1456
|
-
`).join("")}`;
|
|
1457
|
-
if (shell === "bash")
|
|
1458
|
-
return `${header}
|
|
1459
|
-
${BASH_FUNCTION}
|
|
1460
|
-
complete -F __kaynooo_cli_complete ${bins.join(" ")}
|
|
1461
|
-
`;
|
|
1462
|
-
return `${header}
|
|
1463
|
-
${ZSH_FUNCTION}
|
|
1464
|
-
compdef __kaynooo_cli_complete ${bins.join(" ")}
|
|
1465
|
-
`;
|
|
1466
|
-
}
|
|
1467
|
-
var COMPLETION_SHELLS, FISH_FUNCTION = `functions -q __kaynooo_cli_complete; or function __kaynooo_cli_complete --argument-names bin --description 'what a @kaynooo/cli-kit bin offers for the word being typed'
|
|
1468
|
-
set -l tokens (commandline -xpc 2>/dev/null; or commandline -opc)
|
|
1469
|
-
set -l current (commandline -ct)
|
|
1470
|
-
for line in ($bin __complete $tokens[2..-1] $current 2>/dev/null)
|
|
1471
|
-
if test "$line" = __files__
|
|
1472
|
-
__fish_complete_path $current
|
|
1473
|
-
else
|
|
1474
|
-
echo $line
|
|
1475
|
-
end
|
|
1476
|
-
end
|
|
1477
|
-
end`, BASH_FUNCTION = `__kaynooo_cli_complete() {
|
|
1478
|
-
local IFS=$'\\n' cur=\${COMP_WORDS[COMP_CWORD]} line words=
|
|
1479
|
-
local -a lines
|
|
1480
|
-
COMPREPLY=()
|
|
1481
|
-
lines=($("\${COMP_WORDS[0]}" __complete "\${COMP_WORDS[@]:1:COMP_CWORD}" 2>/dev/null))
|
|
1482
|
-
for line in "\${lines[@]}"; do
|
|
1483
|
-
if [[ $line == __files__ ]]; then
|
|
1484
|
-
COMPREPLY+=($(compgen -f -- "$cur"))
|
|
1485
|
-
else
|
|
1486
|
-
words+="\${line%%$'\\t'*}"$'\\n'
|
|
1487
|
-
fi
|
|
1488
|
-
done
|
|
1489
|
-
COMPREPLY+=($(compgen -W "$words" -- "$cur"))
|
|
1490
|
-
}`, ZSH_FUNCTION = `__kaynooo_cli_complete() {
|
|
1491
|
-
local line
|
|
1492
|
-
local -a described plain
|
|
1493
|
-
for line in \${(f)"$("\${words[1]}" __complete "\${(@)words[2,CURRENT]}" 2>/dev/null)"}; do
|
|
1494
|
-
if [[ $line == __files__ ]]; then
|
|
1495
|
-
_files
|
|
1496
|
-
elif [[ $line == *$'\\t'* ]]; then
|
|
1497
|
-
described+=("\${\${line%%$'\\t'*}//:/\\\\:}:\${line#*$'\\t'}")
|
|
1498
|
-
else
|
|
1499
|
-
plain+=("$line")
|
|
1500
|
-
fi
|
|
1501
|
-
done
|
|
1502
|
-
(( \${#described} )) && _describe -V value described
|
|
1503
|
-
(( \${#plain} )) && compadd -- "\${plain[@]}"
|
|
1504
|
-
return 0
|
|
1505
|
-
}`;
|
|
1506
|
-
var init_completions = __esm(() => {
|
|
1507
|
-
COMPLETION_SHELLS = ["fish", "bash", "zsh"];
|
|
1508
|
-
});
|
|
1509
|
-
|
|
1510
|
-
// ../kit/src/notify.ts
|
|
1511
|
-
import process15 from "process";
|
|
1512
|
-
function base64(text) {
|
|
1513
|
-
return Buffer.from(text).toString("base64");
|
|
1514
|
-
}
|
|
1515
|
-
function notification(title, body, env = process15.env) {
|
|
1516
|
-
const id = `kit${process15.pid}`;
|
|
1517
|
-
const codes = [`\x1B]99;i=${id}:d=0:o=unfocused:e=1;${base64(title)}\x1B\\`, `\x1B]99;i=${id}:p=body:e=1;${base64(body)}\x1B\\`];
|
|
1518
|
-
return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
|
|
1519
|
-
}
|
|
1520
|
-
function notifyEnd(command, code, ms, { stream = process15.stderr, env = process15.env } = {}) {
|
|
1521
|
-
if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
|
|
1522
|
-
return;
|
|
1523
|
-
stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
|
|
1524
|
-
}
|
|
1525
|
-
var NOTIFY_AFTER_MS = 1e4, CANCELLED = 130;
|
|
1526
|
-
var init_notify = __esm(() => {
|
|
1527
|
-
init_format();
|
|
1528
|
-
init_mode();
|
|
1529
|
-
});
|
|
1530
|
-
|
|
1531
|
-
// ../kit/src/logs.ts
|
|
1532
|
-
var DAY_MS, CLI_FOLDER = "kaynooo-cli";
|
|
1533
|
-
var init_logs = __esm(() => {
|
|
1534
|
-
init_user_config();
|
|
1535
|
-
DAY_MS = 24 * 60 * 60 * 1000;
|
|
1536
|
-
});
|
|
1537
|
-
|
|
1538
|
-
// ../kit/src/usage.ts
|
|
1539
|
-
import { appendFileSync, mkdirSync } from "fs";
|
|
1540
|
-
import { homedir as homedir3 } from "os";
|
|
1541
|
-
import { dirname as dirname2, join as join4 } from "path";
|
|
1542
|
-
import process16 from "process";
|
|
1543
|
-
function noteUsageError(message) {
|
|
1544
|
-
usageError = message;
|
|
1545
|
-
}
|
|
1546
|
-
function stateHome(env = process16.env) {
|
|
1547
|
-
return xdgFolder(env.XDG_STATE_HOME, join4(homedir3(), ".local", "state"));
|
|
1548
|
-
}
|
|
1549
|
-
function usagePath(env = process16.env) {
|
|
1550
|
-
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
1551
|
-
}
|
|
1552
|
-
function usageRecorded(env = process16.env) {
|
|
1553
|
-
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
1554
|
-
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
1555
|
-
}
|
|
1556
|
-
function flagNames(argv) {
|
|
1557
|
-
const end = argv.indexOf("--");
|
|
1558
|
-
const names = (end === -1 ? argv : argv.slice(0, end)).filter((word) => word.startsWith("-") && word !== "-").map((word) => word.includes("=") ? word.slice(0, word.indexOf("=")) : word);
|
|
1559
|
-
return [...new Set(names)].filter((name) => name.length <= LONGEST_NAME && FLAG_NAME.test(name));
|
|
1560
|
-
}
|
|
1561
|
-
function usageEntry(bin, command, argv, code, { ms, now = new Date } = {}) {
|
|
1562
|
-
const unknown = code === 2 && usageError !== undefined ? UNKNOWN_OPTION2.exec(usageError)?.[1] : undefined;
|
|
1563
|
-
usageError = undefined;
|
|
1564
|
-
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown }, ...ms === undefined ? {} : { ms: Math.round(ms) } };
|
|
1565
|
-
}
|
|
1566
|
-
function recordUsage(entry, env = process16.env) {
|
|
1567
|
-
if (!usageRecorded(env))
|
|
1568
|
-
return;
|
|
1569
|
-
try {
|
|
1570
|
-
const path = usagePath(env);
|
|
1571
|
-
mkdirSync(dirname2(path), { recursive: true, mode: 448 });
|
|
1572
|
-
appendFileSync(path, `${JSON.stringify(entry)}
|
|
1573
|
-
`, { mode: 384 });
|
|
1574
|
-
} catch {}
|
|
1575
|
-
}
|
|
1576
|
-
var UNKNOWN_OPTION2, FLAG_NAME, LONGEST_NAME = 40, usageError;
|
|
1577
|
-
var init_usage = __esm(() => {
|
|
1578
|
-
init_logs();
|
|
1579
|
-
init_user_config();
|
|
1580
|
-
UNKNOWN_OPTION2 = /unknown option '(--[a-z][a-z0-9-]*)[=']/;
|
|
1581
|
-
FLAG_NAME = /^(?:--[a-z][a-z0-9-]*|-[a-zA-Z])$/;
|
|
1582
|
-
});
|
|
1583
|
-
|
|
1584
|
-
// ../kit/src/cli.ts
|
|
1585
|
-
import { readFileSync as readFileSync5, realpathSync as realpathSync2 } from "fs";
|
|
1586
|
-
import { dirname as dirname3, join as join5 } from "path";
|
|
1587
|
-
import process17 from "process";
|
|
1588
|
-
async function commandRows(all, colors) {
|
|
1589
|
-
const commands = shown(all);
|
|
1590
|
-
const width = Math.max(0, ...Object.keys(commands).map((name) => name.length));
|
|
1591
|
-
const groups = new Map([["Commands:", []]]);
|
|
1592
|
-
const summaries = await Promise.all(Object.values(commands).map(async ({ summary }) => resolveSummary(summary)));
|
|
1593
|
-
for (const [index, [name, { group }]] of Object.entries(commands).entries()) {
|
|
1594
|
-
const heading = group === undefined ? "Commands:" : `${group}:`;
|
|
1595
|
-
const rows = groups.get(heading) ?? [];
|
|
1596
|
-
rows.push(` ${colors.cyan(name.padEnd(width))} ${colors.dim(summaries[index])}`);
|
|
1597
|
-
groups.set(heading, rows);
|
|
1598
|
-
}
|
|
1599
|
-
return [...groups].filter(([, rows]) => rows.length > 0).flatMap(([heading, rows], index) => [...index === 0 ? [] : [""], colors.bold(heading), ...rows]);
|
|
1600
|
-
}
|
|
1601
|
-
function shown(commands) {
|
|
1602
|
-
return Object.fromEntries(Object.entries(commands).filter(([, { hidden }]) => hidden !== true));
|
|
1603
|
-
}
|
|
1604
|
-
function takeOutputFlags(argv) {
|
|
1605
|
-
let index = 0;
|
|
1606
|
-
for (;index < argv.length; index++) {
|
|
1607
|
-
const word = argv[index];
|
|
1608
|
-
if (word === "--plain")
|
|
1609
|
-
applyOutput(undefined, true);
|
|
1610
|
-
else if (word.startsWith("--color="))
|
|
1611
|
-
applyOutput(word.slice("--color=".length), undefined);
|
|
1612
|
-
else if (word === "--color" && argv[index + 1] !== undefined)
|
|
1613
|
-
applyOutput(argv[++index], undefined);
|
|
1614
|
-
else
|
|
1615
|
-
break;
|
|
1616
|
-
}
|
|
1617
|
-
return argv.slice(index);
|
|
1618
|
-
}
|
|
1619
|
-
async function resolveSummary(summary) {
|
|
1620
|
-
return typeof summary === "string" ? summary : summary();
|
|
1621
|
-
}
|
|
1622
|
-
function lookup({ commands, aliases }, word) {
|
|
1623
|
-
const name = aliases !== undefined && Object.hasOwn(aliases, word) ? aliases[word] ?? word : word;
|
|
1624
|
-
return Object.hasOwn(commands, name) ? commands[name] : undefined;
|
|
1625
|
-
}
|
|
1626
|
-
function scopeOf(commands, extra, aliases) {
|
|
1627
|
-
return { commands: typeof commands === "function" ? {} : commands, lazy: [...typeof commands === "function" ? [commands] : [], ...extra === undefined ? [] : [extra]], aliases };
|
|
1628
|
-
}
|
|
1629
|
-
async function expand(scope, words) {
|
|
1630
|
-
if (scope.lazy.length === 0)
|
|
1631
|
-
return scope;
|
|
1632
|
-
const commands = { ...scope.commands };
|
|
1633
|
-
for (const added of await Promise.all(scope.lazy.map(async (lazy) => lazy(words)))) {
|
|
1634
|
-
for (const [name, command] of Object.entries(added))
|
|
1635
|
-
commands[name] ??= command;
|
|
1636
|
-
}
|
|
1637
|
-
return { ...scope, commands, lazy: [] };
|
|
1638
|
-
}
|
|
1639
|
-
async function help2({ path, header, summary: lazySummary, commands, defaultCommand, examples, replaces }, stream) {
|
|
1640
|
-
const colors = paint(stream);
|
|
1641
|
-
const prefix = path.join(" ");
|
|
1642
|
-
const summary = await resolveSummary(lazySummary);
|
|
1643
|
-
if (wantsHelpJson())
|
|
1644
|
-
return JSON.stringify(description(`${prefix} <command> [options]: ${summary}`, { examples, replaces }));
|
|
1645
|
-
const fallback = defaultCommand === undefined ? undefined : commands[defaultCommand];
|
|
1646
|
-
const options = fallback !== undefined && "run" in fallback ? await optionsOf(fallback.run) : undefined;
|
|
1647
|
-
const own = Object.entries(options ?? {}).filter(([name]) => !(name in TOP_OPTIONS));
|
|
1648
|
-
return [
|
|
1649
|
-
header(colors, summary),
|
|
1650
|
-
"",
|
|
1651
|
-
usageLine(`${prefix} ${defaultCommand === undefined ? colors.cyan("<command>") : `[${colors.cyan("<command>")}]`} [options]`, colors),
|
|
1652
|
-
"",
|
|
1653
|
-
...await commandRows(commands, colors),
|
|
1654
|
-
...own.length === 0 ? [] : ["", `${colors.bold(`Options of ${defaultCommand}:`)} ${colors.dim("the command run when none is named")}`, ...optionRows(Object.fromEntries(own), colors)],
|
|
1655
|
-
"",
|
|
1656
|
-
colors.bold("Options:"),
|
|
1657
|
-
...optionRows(path.length === 1 ? TOP_OPTIONS : LEVEL_OPTIONS, colors),
|
|
1658
|
-
...exampleRows(examples ?? [], colors),
|
|
1659
|
-
"",
|
|
1660
|
-
`${colors.dim("Run")} ${prefix} ${colors.cyan("<command>")} --help ${colors.dim("for its options.")}`
|
|
1661
|
-
].join(`
|
|
1662
|
-
`);
|
|
1663
|
-
}
|
|
1664
|
-
function printError(prefix, message, hint, cause) {
|
|
1665
|
-
const colors = paint(process17.stderr);
|
|
1666
|
-
const styled = takesControlCodes(process17.stderr);
|
|
1667
|
-
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
1668
|
-
const under = (label, text, tint) => text === undefined ? "" : `
|
|
1669
|
-
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
1670
|
-
console.error(`${head} ${message}${under("cause", cause, colors.dim)}${under("hint", hint, colors.yellow)}`);
|
|
1671
|
-
}
|
|
1672
|
-
function printJsonError(message, hint, cause) {
|
|
1673
|
-
console.error(JSON.stringify({ error: message, ...hint === undefined ? {} : { hint }, ...cause === undefined ? {} : { cause } }));
|
|
1674
|
-
}
|
|
1675
|
-
function wantsJson(argv) {
|
|
1676
|
-
const end = argv.indexOf("--");
|
|
1677
|
-
return (end === -1 ? argv : argv.slice(0, end)).includes("--json");
|
|
1678
|
-
}
|
|
1679
|
-
function reportThrown(prefix, error, redact = (text) => text, json = false) {
|
|
1680
|
-
if (error instanceof HelpShown)
|
|
1681
|
-
return 0;
|
|
1682
|
-
const help = error instanceof UsageError ? `run ${prefix} --help for its options` : undefined;
|
|
1683
|
-
const named = error instanceof Error && !(error instanceof Exit) && error.name !== "Error" ? `${error.name}: ${error.message}` : undefined;
|
|
1684
|
-
const cause = error instanceof Error && error.cause instanceof Error ? redact(error.cause.message) : undefined;
|
|
1685
|
-
if (error instanceof Exit && error.code === 2)
|
|
1686
|
-
noteUsageError(error.message);
|
|
1687
|
-
const report = json ? printJsonError : (message, hint, causeText) => printError(prefix, message, hint, causeText);
|
|
1688
|
-
report(redact(named ?? (error instanceof Error ? error.message : String(error))), error instanceof Exit ? error.hint ?? help : undefined, cause);
|
|
1689
|
-
return error instanceof Exit ? error.code : 1;
|
|
1690
|
-
}
|
|
1691
|
-
async function dispatch(level, typed, { version, redact }) {
|
|
1692
|
-
const prefix = level.path.join(" ");
|
|
1693
|
-
let argv;
|
|
1694
|
-
try {
|
|
1695
|
-
argv = takeOutputFlags(typed);
|
|
1696
|
-
} catch (error) {
|
|
1697
|
-
return reportThrown(prefix, error);
|
|
1698
|
-
}
|
|
1699
|
-
const [name, ...args] = argv;
|
|
1700
|
-
const fallback = level.defaultCommand === undefined ? undefined : level.commands[level.defaultCommand];
|
|
1701
|
-
if (name === undefined && level.runBare && fallback !== undefined && "run" in fallback) {
|
|
1702
|
-
try {
|
|
1703
|
-
return await fallback.run([]);
|
|
1704
|
-
} catch (error) {
|
|
1705
|
-
return reportThrown(`${prefix} ${level.defaultCommand}`, error, redact, false);
|
|
1706
|
-
}
|
|
1707
|
-
}
|
|
1708
|
-
if (name === undefined && level.path.length > 1) {
|
|
1709
|
-
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process17.stderr));
|
|
1710
|
-
return 2;
|
|
1711
|
-
}
|
|
1712
|
-
if (name === undefined || name === "help" || name === "--help" || name === "-h") {
|
|
1713
|
-
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process17.stdout));
|
|
1714
|
-
return 0;
|
|
1715
|
-
}
|
|
1716
|
-
if (level.path.length === 1 && (name === "--version" || name === "-v")) {
|
|
1717
|
-
console.log(version);
|
|
1718
|
-
return 0;
|
|
1719
|
-
}
|
|
1720
|
-
let command = lookup(level, name);
|
|
1721
|
-
let rest = args;
|
|
1722
|
-
let ran = name;
|
|
1723
|
-
if (command === undefined && level.lazy.length > 0) {
|
|
1724
|
-
level = await expand(level, [...level.path.slice(1), ...argv]);
|
|
1725
|
-
command = lookup(level, name);
|
|
1726
|
-
}
|
|
1727
|
-
if (command === undefined && level.defaultCommand !== undefined) {
|
|
1728
|
-
command = level.commands[level.defaultCommand];
|
|
1729
|
-
rest = argv;
|
|
1730
|
-
ran = level.defaultCommand;
|
|
1731
|
-
}
|
|
1732
|
-
if (command === undefined) {
|
|
1733
|
-
const meant = closest(name, Object.keys(shown(level.commands)));
|
|
1734
|
-
printError(prefix, `no command ${name}`, meant === undefined ? `run ${prefix} --help for its commands` : `did you mean ${meant}?`);
|
|
1735
|
-
return 2;
|
|
1736
|
-
}
|
|
1737
|
-
if ("commands" in command) {
|
|
1738
|
-
const { summary } = command;
|
|
1739
|
-
return dispatch({ path: [...level.path, name], header: (colors, text) => `${colors.bold(`${prefix} ${name}`)} ${text}`, summary, ...scopeOf(command.commands, command.extraCommands, command.aliases), defaultCommand: undefined, runBare: false, examples: command.examples, replaces: undefined }, rest, { version, redact });
|
|
1740
|
-
}
|
|
1741
|
-
try {
|
|
1742
|
-
return await command.run(rest);
|
|
1743
|
-
} catch (error) {
|
|
1744
|
-
return reportThrown(`${prefix} ${ran}`, error, redact, wantsJson(rest));
|
|
1745
|
-
}
|
|
1746
|
-
}
|
|
1747
|
-
async function completingOf(run) {
|
|
1748
|
-
completion.active = true;
|
|
1749
|
-
try {
|
|
1750
|
-
await run([]);
|
|
1751
|
-
} catch (error) {
|
|
1752
|
-
if (error instanceof Completing)
|
|
1753
|
-
return error;
|
|
1754
|
-
} finally {
|
|
1755
|
-
completion.active = false;
|
|
1756
|
-
}
|
|
1757
|
-
return new Completing({});
|
|
1758
|
-
}
|
|
1759
|
-
async function optionsOf(run) {
|
|
1760
|
-
return (await completingOf(run)).options;
|
|
1761
|
-
}
|
|
1762
|
-
function candidateLine(candidate) {
|
|
1763
|
-
return typeof candidate === "string" ? candidate : candidate.join("\t");
|
|
1764
|
-
}
|
|
1765
|
-
function positionalBeingTyped(before, { options, positionals }) {
|
|
1766
|
-
const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
|
|
1767
|
-
const typed = [];
|
|
1768
|
-
let at = 0;
|
|
1769
|
-
while (at < before.length) {
|
|
1770
|
-
const word = before[at];
|
|
1771
|
-
if (word === "--") {
|
|
1772
|
-
typed.push(...before.slice(at + 1));
|
|
1773
|
-
break;
|
|
1774
|
-
}
|
|
1775
|
-
if (!word.startsWith("-"))
|
|
1776
|
-
typed.push(word);
|
|
1777
|
-
else if (takesValue(word))
|
|
1778
|
-
at++;
|
|
1779
|
-
at++;
|
|
1780
|
-
}
|
|
1781
|
-
const last = positionals.at(-1);
|
|
1782
|
-
if (typed.length < positionals.length)
|
|
1783
|
-
return { name: positionals[typed.length], typed };
|
|
1784
|
-
return { name: last?.replace("]", "").endsWith("...") === true ? last : undefined, typed };
|
|
1785
|
-
}
|
|
1786
|
-
async function leafCandidates(run, words) {
|
|
1787
|
-
const completing = await completingOf(run);
|
|
1788
|
-
if ((words.at(-1) ?? "").startsWith("-"))
|
|
1789
|
-
return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
|
|
1790
|
-
const flag = words.at(-2);
|
|
1791
|
-
const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
|
|
1792
|
-
const { name, typed } = positionalBeingTyped(words.slice(0, -1), completing);
|
|
1793
|
-
if (option?.type === "string") {
|
|
1794
|
-
const values = option.choices === undefined ? await option.candidates?.(typed) : option.choices;
|
|
1795
|
-
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
1796
|
-
}
|
|
1797
|
-
const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
|
|
1798
|
-
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
1799
|
-
}
|
|
1800
|
-
async function candidates(scope, defaultCommand, words, before = []) {
|
|
1801
|
-
const [word = "", ...rest] = words;
|
|
1802
|
-
const listing = rest.length === 0 && !word.startsWith("-");
|
|
1803
|
-
let { commands } = scope;
|
|
1804
|
-
let command = lookup(scope, word);
|
|
1805
|
-
if (listing || command === undefined) {
|
|
1806
|
-
const expanded = await expand(scope, [...before, ...words]);
|
|
1807
|
-
commands = expanded.commands;
|
|
1808
|
-
command = lookup(expanded, word);
|
|
1809
|
-
}
|
|
1810
|
-
if (listing) {
|
|
1811
|
-
const own = await Promise.all(Object.entries(shown(commands)).map(async ([name, { summary }]) => `${name} ${await resolveSummary(summary)}`));
|
|
1812
|
-
const fallback = defaultCommand === undefined ? undefined : commands[defaultCommand];
|
|
1813
|
-
const values = fallback !== undefined && "run" in fallback ? await leafCandidates(fallback.run, [word]) : [];
|
|
1814
|
-
const valueOf = (line) => line.slice(0, line.includes("\t") ? line.indexOf("\t") : undefined);
|
|
1815
|
-
return [...own, ...values.filter((line) => line !== FILES && !Object.hasOwn(commands, valueOf(line)))];
|
|
1816
|
-
}
|
|
1817
|
-
if (command === undefined) {
|
|
1818
|
-
const fallback = defaultCommand === undefined ? undefined : commands[defaultCommand];
|
|
1819
|
-
return fallback !== undefined && "run" in fallback ? leafCandidates(fallback.run, words) : [];
|
|
1820
|
-
}
|
|
1821
|
-
return "commands" in command ? candidates(scopeOf(command.commands, command.extraCommands, command.aliases), undefined, rest, [...before, word]) : leafCandidates(command.run, rest);
|
|
1822
|
-
}
|
|
1823
|
-
function flagValue([flag = "", ...rest]) {
|
|
1824
|
-
return flag.includes("=") ? [flag.slice(flag.indexOf("=") + 1), ...rest] : rest;
|
|
1825
|
-
}
|
|
1826
|
-
function printCompletionScript(name, args) {
|
|
1827
|
-
const shell = COMPLETION_SHELLS.find((each) => each === args[0]);
|
|
1828
|
-
if (shell === undefined || args.length !== 1) {
|
|
1829
|
-
printError(name, `${COMPLETIONS} takes one of ${COMPLETION_SHELLS.join(", ")}`, `${name} ${COMPLETIONS} fish`);
|
|
1830
|
-
return 2;
|
|
1831
|
-
}
|
|
1832
|
-
console.log(completionScript(shell, [name]).trimEnd());
|
|
1833
|
-
return 0;
|
|
1834
|
-
}
|
|
1835
|
-
async function printCandidates(found) {
|
|
1836
|
-
for (const line of await found)
|
|
1837
|
-
console.log(line);
|
|
1838
|
-
return 0;
|
|
1839
|
-
}
|
|
1840
|
-
function packageVersion(entry = Bun.main) {
|
|
1841
|
-
let resolved = entry;
|
|
1842
|
-
try {
|
|
1843
|
-
resolved = realpathSync2(entry);
|
|
1844
|
-
} catch {}
|
|
1845
|
-
for (let dir = dirname3(resolved);; dir = dirname3(dir)) {
|
|
1846
|
-
try {
|
|
1847
|
-
const { version } = JSON.parse(readFileSync5(join5(dir, "package.json"), "utf8"));
|
|
1848
|
-
if (typeof version === "string")
|
|
1849
|
-
return version;
|
|
1850
|
-
} catch {}
|
|
1851
|
-
if (dirname3(dir) === dir)
|
|
1852
|
-
return "0.0.0";
|
|
1853
|
-
}
|
|
1854
|
-
}
|
|
1855
|
-
async function runCli(cli, argv = scriptArgs()) {
|
|
1856
|
-
const version = cli.version ?? packageVersion();
|
|
1857
|
-
const answered = await askpassClient(argv);
|
|
1858
|
-
if (answered !== undefined)
|
|
1859
|
-
return answered;
|
|
1860
|
-
if (argv[0] === COMPLETE)
|
|
1861
|
-
return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
|
|
1862
|
-
if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
|
|
1863
|
-
return printCompletionScript(cli.name, flagValue(argv));
|
|
1864
|
-
const started = performance.now();
|
|
1865
|
-
const code = await dispatch({ path: [cli.name], header: (colors, about) => `${colors.bold(cli.name)} ${colors.dim(version)} ${about}`, summary: cli.about, ...scopeOf(cli.commands, cli.extraCommands, cli.aliases), defaultCommand: cli.defaultCommand, runBare: cli.runBare === true, examples: cli.examples, replaces: cli.replaces }, argv, { version, redact: cli.redact });
|
|
1866
|
-
const command = commandPath(scopeOf(cli.commands, cli.extraCommands, cli.aliases), argv);
|
|
1867
|
-
notifyEnd(command === undefined ? cli.name : `${cli.name} ${command}`, code, performance.now() - started);
|
|
1868
|
-
if (cli.usage !== false) {
|
|
1869
|
-
try {
|
|
1870
|
-
recordUsage(usageEntry(cli.name, command, argv, code, { ms: performance.now() - started }));
|
|
1871
|
-
} catch {}
|
|
1872
|
-
}
|
|
1873
|
-
return code;
|
|
1874
|
-
}
|
|
1875
|
-
function commandPath(scope, argv) {
|
|
1876
|
-
const path = [];
|
|
1877
|
-
let level = scope;
|
|
1878
|
-
for (const word of argv.filter((each) => !each.startsWith("-"))) {
|
|
1879
|
-
const command = lookup(level, word);
|
|
1880
|
-
if (command === undefined)
|
|
1881
|
-
break;
|
|
1882
|
-
path.push(word);
|
|
1883
|
-
if (!("commands" in command))
|
|
1884
|
-
break;
|
|
1885
|
-
level = scopeOf(command.commands, command.extraCommands, command.aliases);
|
|
1886
|
-
}
|
|
1887
|
-
return path.length === 0 ? undefined : path.join(" ");
|
|
1888
|
-
}
|
|
1889
|
-
var LEVEL_OPTIONS, TOP_OPTIONS, COMPLETE = "__complete", FILES = "__files__", COMPLETIONS = "--completions";
|
|
1890
|
-
var init_cli = __esm(() => {
|
|
1891
|
-
init_args();
|
|
1892
|
-
init_argv();
|
|
1893
|
-
init_askpass();
|
|
1894
|
-
init_completions();
|
|
1895
|
-
init_notify();
|
|
1896
|
-
init_style();
|
|
1897
|
-
init_text2();
|
|
1898
|
-
init_usage();
|
|
1899
|
-
LEVEL_OPTIONS = {
|
|
1900
|
-
...OUTPUT_OPTIONS,
|
|
1901
|
-
help: { type: "boolean", short: "h", description: "show this help" }
|
|
1902
|
-
};
|
|
1903
|
-
TOP_OPTIONS = {
|
|
1904
|
-
...LEVEL_OPTIONS,
|
|
1905
|
-
version: { type: "boolean", short: "v", description: "print the version" },
|
|
1906
|
-
completions: { type: "string", choices: COMPLETION_SHELLS, description: "print the shell completion script" }
|
|
1907
|
-
};
|
|
1908
|
-
});
|
|
1909
|
-
// ../kit/src/excerpt.ts
|
|
1910
|
-
var init_excerpt = __esm(() => {
|
|
1911
|
-
init_text2();
|
|
1912
|
-
});
|
|
1913
|
-
|
|
1914
|
-
// ../kit/src/folders.ts
|
|
1915
|
-
function ignoredFolders(extra = [], where = {}) {
|
|
1916
|
-
const configured = readUserConfig("config", where).ignore;
|
|
1917
|
-
const names = Array.isArray(configured) ? configured.filter((name) => typeof name === "string" && name !== "") : [];
|
|
1918
|
-
return new Set([...SKIPPED_FOLDERS, ...extra, ...names]);
|
|
1919
|
-
}
|
|
1920
|
-
var SKIPPED_FOLDERS;
|
|
1921
|
-
var init_folders = __esm(() => {
|
|
1922
|
-
init_user_config();
|
|
1923
|
-
SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
1924
|
-
});
|
|
1925
|
-
|
|
1926
|
-
// ../kit/src/git.ts
|
|
1927
|
-
var init_git = __esm(() => {
|
|
1928
|
-
init_args();
|
|
1929
|
-
init_tool();
|
|
1930
|
-
});
|
|
1931
|
-
|
|
1932
|
-
// ../kit/src/limit.ts
|
|
1933
|
-
function limitOptions(fallback) {
|
|
1934
|
-
return {
|
|
1935
|
-
limit: { type: "string", short: "n", description: `show at most this many rows, the rest counted (${fallback})` },
|
|
1936
|
-
full: { type: "boolean", description: "show every row" }
|
|
1937
|
-
};
|
|
1938
|
-
}
|
|
1939
|
-
function limitOf(values, fallback) {
|
|
1940
|
-
if (values.full === true && values.limit !== undefined)
|
|
1941
|
-
badUsage("--limit and --full exclude each other");
|
|
1942
|
-
if (values.full === true || values.json === true && values.limit === undefined)
|
|
1943
|
-
return Number.POSITIVE_INFINITY;
|
|
1944
|
-
return wholeNumber(values.limit, "limit", fallback);
|
|
1945
|
-
}
|
|
1946
|
-
function moreFooter(more) {
|
|
1947
|
-
return `${more} more, rerun with --full`;
|
|
1948
|
-
}
|
|
1949
|
-
function capped(rows, limit) {
|
|
1950
|
-
const more = rows.length - limit;
|
|
1951
|
-
return more > 0 ? { shown: rows.slice(0, limit), footer: moreFooter(more) } : { shown: [...rows], footer: undefined };
|
|
1952
|
-
}
|
|
1953
|
-
var init_limit = __esm(() => {
|
|
1954
|
-
init_args();
|
|
1955
|
-
});
|
|
1956
|
-
|
|
1957
|
-
// ../kit/src/pool.ts
|
|
1958
|
-
async function pool(items, limit, task, onDone) {
|
|
1959
|
-
const results = Array.from({ length: items.length });
|
|
1960
|
-
let next = 0;
|
|
1961
|
-
let done = 0;
|
|
1962
|
-
async function worker() {
|
|
1963
|
-
while (next < items.length) {
|
|
1964
|
-
const index = next++;
|
|
1965
|
-
results[index] = await task(items[index]);
|
|
1966
|
-
onDone?.(++done, items.length);
|
|
1967
|
-
}
|
|
1968
|
-
}
|
|
1969
|
-
await Promise.all(Array.from({ length: Math.min(limit, items.length) }, worker));
|
|
1970
|
-
return results;
|
|
1971
|
-
}
|
|
1972
|
-
// ../kit/src/report.ts
|
|
1973
|
-
var init_report = __esm(() => {
|
|
1974
|
-
init_cli();
|
|
1975
|
-
init_style();
|
|
1976
|
-
init_text2();
|
|
1977
|
-
});
|
|
1978
|
-
|
|
1979
|
-
// ../kit/src/secrets.ts
|
|
1980
|
-
var SECRET_WORDS, NOT_PASSWORDS;
|
|
1981
|
-
var init_secrets = __esm(() => {
|
|
1982
|
-
SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
1983
|
-
NOT_PASSWORDS = new Set(["compass", "encompass", "bypass", "overpass", "underpass", "surpass", "trespass"]);
|
|
1984
|
-
});
|
|
1985
|
-
|
|
1986
|
-
// ../kit/src/sessions.ts
|
|
1987
|
-
var {Glob } = globalThis.Bun;
|
|
1988
|
-
var SESSION_FILES, ACCOUNT_DIRS;
|
|
1989
|
-
var init_sessions = __esm(() => {
|
|
1990
|
-
SESSION_FILES = new Glob("*.json");
|
|
1991
|
-
ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1992
|
-
});
|
|
1993
|
-
|
|
1994
|
-
// ../kit/src/size.ts
|
|
1995
|
-
var init_size = () => {};
|
|
1996
|
-
|
|
1997
|
-
// ../kit/src/watch.ts
|
|
1998
|
-
var init_watch = __esm(() => {
|
|
1999
|
-
init_args();
|
|
2000
|
-
init_input();
|
|
2001
|
-
init_style();
|
|
2002
|
-
});
|
|
2003
|
-
|
|
2004
|
-
// ../kit/src/workspace-root.ts
|
|
2005
|
-
import { homedir as homedir4 } from "os";
|
|
2006
|
-
import { dirname as dirname4, join as join6, resolve as resolve4 } from "path";
|
|
2007
|
-
import process18 from "process";
|
|
2008
|
-
function expandHome(path, home) {
|
|
2009
|
-
if (path === "~")
|
|
2010
|
-
return home;
|
|
2011
|
-
return path.startsWith("~/") ? join6(home, path.slice(2)) : path;
|
|
2012
|
-
}
|
|
2013
|
-
function configured(env, home) {
|
|
2014
|
-
const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
|
|
2015
|
-
return typeof folder === "string" && folder !== "" ? folder : undefined;
|
|
2016
|
-
}
|
|
2017
|
-
function workspaceRoot({ given, env = process18.env, home = homedir4() } = {}) {
|
|
2018
|
-
const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
|
|
2019
|
-
return resolve4(expandHome(given ?? fromEnv ?? configured(env, home) ?? join6(home, "Workspace"), home));
|
|
2020
|
-
}
|
|
2021
|
-
var init_workspace_root = __esm(() => {
|
|
2022
|
-
init_user_config();
|
|
2023
|
-
});
|
|
2024
|
-
|
|
2025
|
-
// ../kit/src/index.ts
|
|
2026
|
-
var init_src = __esm(() => {
|
|
2027
|
-
init_excerpt();
|
|
2028
|
-
init_advisory();
|
|
2029
|
-
init_args();
|
|
2030
|
-
init_argv();
|
|
2031
|
-
init_chart();
|
|
2032
|
-
init_ci();
|
|
2033
|
-
init_cli();
|
|
2034
|
-
init_completions();
|
|
2035
|
-
init_config();
|
|
2036
|
-
init_folders();
|
|
2037
|
-
init_format();
|
|
2038
|
-
init_git();
|
|
2039
|
-
init_limit();
|
|
2040
|
-
init_logs();
|
|
2041
|
-
init_mode();
|
|
2042
|
-
init_process();
|
|
2043
|
-
init_report();
|
|
2044
|
-
init_secrets();
|
|
2045
|
-
init_sessions();
|
|
2046
|
-
init_size();
|
|
2047
|
-
init_style();
|
|
2048
|
-
init_text2();
|
|
2049
|
-
init_theme();
|
|
2050
|
-
init_tool();
|
|
2051
|
-
init_usage();
|
|
2052
|
-
init_user_config();
|
|
2053
|
-
init_watch();
|
|
2054
|
-
init_workspace_root();
|
|
2055
|
-
});
|
|
2056
|
-
|
|
2057
|
-
// src/semver.ts
|
|
2058
|
-
function isRange(text) {
|
|
2059
|
-
if (text.trim() === "")
|
|
2060
|
-
return true;
|
|
2061
|
-
return text.split(OR).every((alternative) => {
|
|
2062
|
-
const words = alternative.trim().split(WHITESPACE);
|
|
2063
|
-
return words.every((word, index) => word === "-" ? index > 0 && index < words.length - 1 : COMPARATOR.test(word));
|
|
2064
|
-
});
|
|
2065
|
-
}
|
|
2066
|
-
function compare(version, word) {
|
|
2067
|
-
const bound = BOUND.exec(word);
|
|
2068
|
-
if (bound === null)
|
|
2069
|
-
return;
|
|
2070
|
-
const order = Bun.semver.order(version, bound[2] ?? "");
|
|
2071
|
-
const operator = bound[1] ?? "=";
|
|
2072
|
-
if (operator === "<")
|
|
2073
|
-
return order < 0;
|
|
2074
|
-
if (operator === "<=")
|
|
2075
|
-
return order <= 0;
|
|
2076
|
-
if (operator === ">")
|
|
2077
|
-
return order > 0;
|
|
2078
|
-
return operator === ">=" ? order >= 0 : order === 0;
|
|
2079
|
-
}
|
|
2080
|
-
function inRange(version, range) {
|
|
2081
|
-
if (Bun.semver.satisfies(version, range))
|
|
2082
|
-
return true;
|
|
2083
|
-
if (!PRERELEASE.test(version))
|
|
2084
|
-
return false;
|
|
2085
|
-
return range.split(OR).some((alternative) => alternative.trim().split(WHITESPACE).every((word) => compare(version, word) ?? Bun.semver.satisfies(version, word)));
|
|
2086
|
-
}
|
|
2087
|
-
var OR, WHITESPACE, PRERELEASE, PART, COMPARATOR, BOUND, EXACT_VERSION;
|
|
2088
|
-
var init_semver = __esm(() => {
|
|
2089
|
-
OR = /\s*\|\|\s*/;
|
|
2090
|
-
WHITESPACE = /\s+/;
|
|
2091
|
-
PRERELEASE = /-/;
|
|
2092
|
-
PART = String.raw`(?:\d+|[xX*])`;
|
|
2093
|
-
COMPARATOR = new RegExp(String.raw`^(?:[<>]=?|=|\^|~>?)?v?${PART}(?:\.${PART}){0,2}(?:-[\w.-]+)?(?:\+[\w.-]+)?$`);
|
|
2094
|
-
BOUND = /^(<=|>=|[<>=])?v?(\d+\.\d+\.\d+(?:-[\w.-]+)?)$/;
|
|
2095
|
-
EXACT_VERSION = /^\d+\.\d+\.\d+(?:-[\w.-]+)?(?:\+[\w.-]+)?$/;
|
|
2096
|
-
});
|
|
2097
|
-
|
|
2098
|
-
// src/advisories.ts
|
|
2099
|
-
function fixedVersion(vulnerable, version) {
|
|
2100
|
-
const range = vulnerable.split("||").map((each) => each.trim()).find((each) => inRange(version, each));
|
|
2101
|
-
return range === undefined ? undefined : UPPER_BOUND.exec(range)?.[1];
|
|
2102
|
-
}
|
|
2103
|
-
async function fetchAdvisories(versions, registry, fetcher = fetch) {
|
|
2104
|
-
const url = `${registry.url.replace(TRAILING_SLASHES, "")}${BULK_PATH}`;
|
|
2105
|
-
const host = new URL(registry.url).host;
|
|
2106
|
-
let response;
|
|
2107
|
-
try {
|
|
2108
|
-
response = await fetcher(url, {
|
|
2109
|
-
method: "POST",
|
|
2110
|
-
headers: { accept: "application/json", "content-type": "application/json", ...registry.token === undefined ? {} : { authorization: `Bearer ${registry.token}` } },
|
|
2111
|
-
body: JSON.stringify(versions),
|
|
2112
|
-
signal: AbortSignal.timeout(REQUEST_TIMEOUT)
|
|
2113
|
-
});
|
|
2114
|
-
} catch (error) {
|
|
2115
|
-
return { found: {}, unavailable: `cannot reach ${host} for advisories: ${error instanceof Error ? error.message : String(error)}` };
|
|
2116
|
-
}
|
|
2117
|
-
if (NO_ENDPOINT.has(response.status))
|
|
2118
|
-
return { found: {}, isUnsupported: true, unavailable: `${host} has no advisory endpoint` };
|
|
2119
|
-
if (!response.ok)
|
|
2120
|
-
return { found: {}, unavailable: `${host} answered ${response.status} for advisories` };
|
|
2121
|
-
let body;
|
|
2122
|
-
try {
|
|
2123
|
-
body = await response.json();
|
|
2124
|
-
} catch {
|
|
2125
|
-
return { found: {}, unavailable: `${host} answered advisories with something that is not JSON` };
|
|
2126
|
-
}
|
|
2127
|
-
const found = {};
|
|
2128
|
-
for (const [name, raws] of Object.entries(body)) {
|
|
2129
|
-
if (!Array.isArray(raws))
|
|
2130
|
-
continue;
|
|
2131
|
-
found[name] = raws.filter((raw) => SEVERITIES.includes(raw.severity)).map((raw) => ({
|
|
2132
|
-
id: raw.id,
|
|
2133
|
-
ghsa: GHSA.exec(raw.url)?.[0],
|
|
2134
|
-
url: raw.url,
|
|
2135
|
-
title: raw.title,
|
|
2136
|
-
severity: raw.severity,
|
|
2137
|
-
vulnerable: raw.vulnerable_versions
|
|
2138
|
-
}));
|
|
2139
|
-
}
|
|
2140
|
-
return { found };
|
|
2141
|
-
}
|
|
2142
|
-
function advisoriesFor(advisories, version) {
|
|
2143
|
-
return (advisories ?? []).filter((each) => inRange(version, each.vulnerable)).map((each) => ({ ...each, fixed: fixedVersion(each.vulnerable, version) }));
|
|
2144
|
-
}
|
|
2145
|
-
function filterAdvisories(advisories, level, ignore = []) {
|
|
2146
|
-
return advisories.filter((each) => severityRank(each.severity) >= severityRank(level) && !isIgnored(each, ignore));
|
|
2147
|
-
}
|
|
2148
|
-
var BULK_PATH = "/-/npm/v1/security/advisories/bulk", TRAILING_SLASHES, REQUEST_TIMEOUT = 1e4, GHSA, UPPER_BOUND, NO_ENDPOINT;
|
|
2149
|
-
var init_advisories = __esm(() => {
|
|
2150
|
-
init_src();
|
|
2151
|
-
init_semver();
|
|
2152
|
-
TRAILING_SLASHES = /\/+$/;
|
|
2153
|
-
GHSA = /GHSA-[\w-]+$/;
|
|
2154
|
-
UPPER_BOUND = /(?:^|\s)<([\w.+-]+)/;
|
|
2155
|
-
NO_ENDPOINT = new Set([404, 405, 501]);
|
|
2156
|
-
});
|
|
2157
|
-
|
|
2158
|
-
// src/licenses.ts
|
|
2159
|
-
function isLicenseAllowed(expression, allowed) {
|
|
2160
|
-
const known = new Set(allowed.map((each) => each.toLowerCase()));
|
|
2161
|
-
return expression.replace(PARENS, " ").trim().split(OR_SPLIT).some((alternative) => alternative.split(AND_SPLIT).every((term) => known.has(term.replace(WITH_EXCEPTION, "").trim().toLowerCase())));
|
|
2162
|
-
}
|
|
2163
|
-
var OR_SPLIT, AND_SPLIT, WITH_EXCEPTION, PARENS;
|
|
2164
|
-
var init_licenses = __esm(() => {
|
|
2165
|
-
OR_SPLIT = /\s+OR\s+/i;
|
|
2166
|
-
AND_SPLIT = /\s+AND\s+/i;
|
|
2167
|
-
WITH_EXCEPTION = /\s+WITH\s+\S+$/i;
|
|
2168
|
-
PARENS = /[()]/g;
|
|
2169
|
-
});
|
|
2170
|
-
|
|
2171
|
-
// src/popular.json
|
|
2172
|
-
var popular_default;
|
|
2173
|
-
var init_popular = __esm(() => {
|
|
2174
|
-
popular_default = [
|
|
2175
|
-
"semver",
|
|
2176
|
-
"minimatch",
|
|
2177
|
-
"debug",
|
|
2178
|
-
"ansi-styles",
|
|
2179
|
-
"brace-expansion",
|
|
2180
|
-
"strip-ansi",
|
|
2181
|
-
"ansi-regex",
|
|
2182
|
-
"ms",
|
|
2183
|
-
"supports-color",
|
|
2184
|
-
"chalk",
|
|
2185
|
-
"commander",
|
|
2186
|
-
"lru-cache",
|
|
2187
|
-
"string-width",
|
|
2188
|
-
"wrap-ansi",
|
|
2189
|
-
"tslib",
|
|
2190
|
-
"picomatch",
|
|
2191
|
-
"emoji-regex",
|
|
2192
|
-
"glob",
|
|
2193
|
-
"type-fest",
|
|
2194
|
-
"color-name",
|
|
2195
|
-
"eslint-visitor-keys",
|
|
2196
|
-
"color-convert",
|
|
2197
|
-
"ajv",
|
|
2198
|
-
"minipass",
|
|
2199
|
-
"source-map",
|
|
2200
|
-
"balanced-match",
|
|
2201
|
-
"readable-stream",
|
|
2202
|
-
"which",
|
|
2203
|
-
"glob-parent",
|
|
2204
|
-
"escape-string-regexp",
|
|
2205
|
-
"has-flag",
|
|
2206
|
-
"find-up",
|
|
2207
|
-
"locate-path",
|
|
2208
|
-
"json-schema-traverse",
|
|
2209
|
-
"p-limit",
|
|
2210
|
-
"yallist",
|
|
2211
|
-
"safe-buffer",
|
|
2212
|
-
"uuid",
|
|
2213
|
-
"p-locate",
|
|
2214
|
-
"undici-types",
|
|
2215
|
-
"ignore",
|
|
2216
|
-
"iconv-lite",
|
|
2217
|
-
"signal-exit",
|
|
2218
|
-
"esbuild",
|
|
2219
|
-
"is-fullwidth-code-point",
|
|
2220
|
-
"js-yaml",
|
|
2221
|
-
"entities",
|
|
2222
|
-
"globals",
|
|
2223
|
-
"postcss",
|
|
2224
|
-
"isexe",
|
|
2225
|
-
"isarray",
|
|
2226
|
-
"path-key",
|
|
2227
|
-
"string_decoder",
|
|
2228
|
-
"argparse",
|
|
2229
|
-
"ws",
|
|
2230
|
-
"mime-db",
|
|
2231
|
-
"resolve",
|
|
2232
|
-
"agent-base",
|
|
2233
|
-
"@esbuild/linux-x64",
|
|
2234
|
-
"yargs-parser",
|
|
2235
|
-
"mime-types",
|
|
2236
|
-
"acorn",
|
|
2237
|
-
"estraverse",
|
|
2238
|
-
"cross-spawn",
|
|
2239
|
-
"react-is",
|
|
2240
|
-
"picocolors",
|
|
2241
|
-
"fs-extra",
|
|
2242
|
-
"hasown",
|
|
2243
|
-
"nanoid",
|
|
2244
|
-
"yargs",
|
|
2245
|
-
"resolve-from",
|
|
2246
|
-
"shebang-command",
|
|
2247
|
-
"pretty-format",
|
|
2248
|
-
"json5",
|
|
2249
|
-
"https-proxy-agent",
|
|
2250
|
-
"path-to-regexp",
|
|
2251
|
-
"path-exists",
|
|
2252
|
-
"punycode",
|
|
2253
|
-
"js-tokens",
|
|
2254
|
-
"cliui",
|
|
2255
|
-
"shebang-regex",
|
|
2256
|
-
"@babel/types",
|
|
2257
|
-
"chokidar",
|
|
2258
|
-
"strip-json-comments",
|
|
2259
|
-
"inherits",
|
|
2260
|
-
"webidl-conversions",
|
|
2261
|
-
"get-stream",
|
|
2262
|
-
"eslint-scope",
|
|
2263
|
-
"cookie",
|
|
2264
|
-
"@babel/parser",
|
|
2265
|
-
"qs",
|
|
2266
|
-
"is-number",
|
|
2267
|
-
"whatwg-url",
|
|
2268
|
-
"@types/estree",
|
|
2269
|
-
"tr46",
|
|
2270
|
-
"convert-source-map",
|
|
2271
|
-
"is-glob",
|
|
2272
|
-
"braces",
|
|
2273
|
-
"fast-deep-equal",
|
|
2274
|
-
"form-data",
|
|
2275
|
-
"lodash",
|
|
2276
|
-
"@babel/helper-validator-identifier",
|
|
2277
|
-
"electron-to-chromium",
|
|
2278
|
-
"fill-range",
|
|
2279
|
-
"function-bind",
|
|
2280
|
-
"readdirp",
|
|
2281
|
-
"escalade",
|
|
2282
|
-
"graceful-fs",
|
|
2283
|
-
"negotiator",
|
|
2284
|
-
"is-stream",
|
|
2285
|
-
"camelcase",
|
|
2286
|
-
"@babel/runtime",
|
|
2287
|
-
"yocto-queue",
|
|
2288
|
-
"to-regex-range",
|
|
2289
|
-
"node-fetch",
|
|
2290
|
-
"micromatch",
|
|
2291
|
-
"node-releases",
|
|
2292
|
-
"get-intrinsic",
|
|
2293
|
-
"universalify",
|
|
2294
|
-
"path-scurry",
|
|
2295
|
-
"jsesc",
|
|
2296
|
-
"browserslist",
|
|
2297
|
-
"es-errors",
|
|
2298
|
-
"statuses",
|
|
2299
|
-
"@radix-ui/react-primitive",
|
|
2300
|
-
"magic-string",
|
|
2301
|
-
"rimraf",
|
|
2302
|
-
"is-extglob",
|
|
2303
|
-
"@jridgewell/trace-mapping",
|
|
2304
|
-
"@jridgewell/resolve-uri",
|
|
2305
|
-
"http-errors",
|
|
2306
|
-
"onetime",
|
|
2307
|
-
"has-symbols",
|
|
2308
|
-
"es-define-property",
|
|
2309
|
-
"gopd",
|
|
2310
|
-
"util-deprecate",
|
|
2311
|
-
"object-assign",
|
|
2312
|
-
"jiti",
|
|
2313
|
-
"yaml",
|
|
2314
|
-
"dotenv",
|
|
2315
|
-
"@babel/generator",
|
|
2316
|
-
"@babel/template",
|
|
2317
|
-
"imurmurhash",
|
|
2318
|
-
"postcss-selector-parser",
|
|
2319
|
-
"fast-glob",
|
|
2320
|
-
"update-browserslist-db",
|
|
2321
|
-
"@types/node",
|
|
2322
|
-
"@babel/compat-data",
|
|
2323
|
-
"eventemitter3",
|
|
2324
|
-
"callsites",
|
|
2325
|
-
"http-proxy-agent",
|
|
2326
|
-
"detect-libc",
|
|
2327
|
-
"espree",
|
|
2328
|
-
"execa",
|
|
2329
|
-
"@babel/core",
|
|
2330
|
-
"@babel/helpers",
|
|
2331
|
-
"concat-map",
|
|
2332
|
-
"source-map-js",
|
|
2333
|
-
"tinyglobby",
|
|
2334
|
-
"call-bind-apply-helpers",
|
|
2335
|
-
"flat-cache",
|
|
2336
|
-
"fdir",
|
|
2337
|
-
"pify",
|
|
2338
|
-
"@jest/types",
|
|
2339
|
-
"normalize-path",
|
|
2340
|
-
"is-core-module",
|
|
2341
|
-
"eslint",
|
|
2342
|
-
"minimist",
|
|
2343
|
-
"estree-walker",
|
|
2344
|
-
"file-entry-cache",
|
|
2345
|
-
"object-inspect",
|
|
2346
|
-
"buffer",
|
|
2347
|
-
"uri-js",
|
|
2348
|
-
"import-fresh",
|
|
2349
|
-
"@babel/helper-module-transforms",
|
|
2350
|
-
"optionator",
|
|
2351
|
-
"flatted",
|
|
2352
|
-
"math-intrinsics",
|
|
2353
|
-
"safer-buffer",
|
|
2354
|
-
"y18n",
|
|
2355
|
-
"@babel/helper-module-imports",
|
|
2356
|
-
"mkdirp",
|
|
2357
|
-
"dunder-proto",
|
|
2358
|
-
"path-parse",
|
|
2359
|
-
"fastq",
|
|
2360
|
-
"levn",
|
|
2361
|
-
"@babel/helper-compilation-targets",
|
|
2362
|
-
"@babel/helper-string-parser",
|
|
2363
|
-
"keyv",
|
|
2364
|
-
"get-proto",
|
|
2365
|
-
"csstype",
|
|
2366
|
-
"npm-run-path",
|
|
2367
|
-
"fast-json-stable-stringify",
|
|
2368
|
-
"reusify",
|
|
2369
|
-
"@babel/helper-plugin-utils",
|
|
2370
|
-
"kind-of",
|
|
2371
|
-
"mime",
|
|
2372
|
-
"caniuse-lite",
|
|
2373
|
-
"lines-and-columns",
|
|
2374
|
-
"fast-levenshtein",
|
|
2375
|
-
"supports-preserve-symlinks-flag",
|
|
2376
|
-
"make-dir",
|
|
2377
|
-
"slash",
|
|
2378
|
-
"prelude-ls",
|
|
2379
|
-
"typescript",
|
|
2380
|
-
"strip-bom",
|
|
2381
|
-
"parent-module",
|
|
2382
|
-
"esutils",
|
|
2383
|
-
"ci-info",
|
|
2384
|
-
"@smithy/util-utf8",
|
|
2385
|
-
"type-check",
|
|
2386
|
-
"mimic-fn",
|
|
2387
|
-
"@babel/helper-validator-option",
|
|
2388
|
-
"@types/json-schema",
|
|
2389
|
-
"@rolldown/pluginutils",
|
|
2390
|
-
"side-channel-list",
|
|
2391
|
-
"json-buffer",
|
|
2392
|
-
"raw-body",
|
|
2393
|
-
"has-tostringtag",
|
|
2394
|
-
"wrappy",
|
|
2395
|
-
"diff",
|
|
2396
|
-
"jackspeak",
|
|
2397
|
-
"baseline-browser-mapping",
|
|
2398
|
-
"deep-is",
|
|
2399
|
-
"foreground-child",
|
|
2400
|
-
"@eslint/js",
|
|
2401
|
-
"anymatch",
|
|
2402
|
-
"natural-compare",
|
|
2403
|
-
"esquery",
|
|
2404
|
-
"@eslint-community/regexpp",
|
|
2405
|
-
"es-set-tostringtag",
|
|
2406
|
-
"acorn-jsx",
|
|
2407
|
-
"parse5",
|
|
2408
|
-
"finalhandler",
|
|
2409
|
-
"parse-json",
|
|
2410
|
-
"depd",
|
|
2411
|
-
"axios",
|
|
2412
|
-
"run-parallel",
|
|
2413
|
-
"source-map-support",
|
|
2414
|
-
"esrecurse",
|
|
2415
|
-
"call-bound",
|
|
2416
|
-
"content-disposition",
|
|
2417
|
-
"human-signals",
|
|
2418
|
-
"ts-api-utils",
|
|
2419
|
-
"ansi-escapes",
|
|
2420
|
-
"jest-util",
|
|
2421
|
-
"send",
|
|
2422
|
-
"@opentelemetry/core",
|
|
2423
|
-
"type-is",
|
|
2424
|
-
"encodeurl",
|
|
2425
|
-
"once",
|
|
2426
|
-
"cosmiconfig",
|
|
2427
|
-
"lodash.merge",
|
|
2428
|
-
"json-stable-stringify-without-jsonify",
|
|
2429
|
-
"open",
|
|
2430
|
-
"prettier",
|
|
2431
|
-
"@eslint/eslintrc",
|
|
2432
|
-
"is-arrayish",
|
|
2433
|
-
"@jridgewell/sourcemap-codec",
|
|
2434
|
-
"gensync",
|
|
2435
|
-
"word-wrap",
|
|
2436
|
-
"express",
|
|
2437
|
-
"arg",
|
|
2438
|
-
"jsonfile",
|
|
2439
|
-
"schema-utils",
|
|
2440
|
-
"@smithy/is-array-buffer",
|
|
2441
|
-
"@typescript-eslint/types",
|
|
2442
|
-
"chownr",
|
|
2443
|
-
"delayed-stream",
|
|
2444
|
-
"@smithy/util-buffer-from",
|
|
2445
|
-
"asynckit",
|
|
2446
|
-
"tapable",
|
|
2447
|
-
"enhanced-resolve",
|
|
2448
|
-
"aria-query",
|
|
2449
|
-
"indent-string",
|
|
2450
|
-
"bytes",
|
|
2451
|
-
"binary-extensions",
|
|
2452
|
-
"ini",
|
|
2453
|
-
"@radix-ui/react-context",
|
|
2454
|
-
"doctrine",
|
|
2455
|
-
"queue-microtask",
|
|
2456
|
-
"accepts",
|
|
2457
|
-
"merge2",
|
|
2458
|
-
"get-caller-file",
|
|
2459
|
-
"@humanwhocodes/retry",
|
|
2460
|
-
"@jridgewell/gen-mapping",
|
|
2461
|
-
"@typescript-eslint/typescript-estree",
|
|
2462
|
-
"jest-worker",
|
|
2463
|
-
"proxy-from-env",
|
|
2464
|
-
"clsx",
|
|
2465
|
-
"side-channel-map",
|
|
2466
|
-
"@typescript-eslint/visitor-keys",
|
|
2467
|
-
"fresh",
|
|
2468
|
-
"restore-cursor",
|
|
2469
|
-
"on-finished",
|
|
2470
|
-
"is-plain-obj",
|
|
2471
|
-
"ipaddr.js",
|
|
2472
|
-
"pathe",
|
|
2473
|
-
"@jest/schemas",
|
|
2474
|
-
"base64-js",
|
|
2475
|
-
"@smithy/types",
|
|
2476
|
-
"require-directory",
|
|
2477
|
-
"tough-cookie",
|
|
2478
|
-
"is-binary-path",
|
|
2479
|
-
"body-parser",
|
|
2480
|
-
"postcss-value-parser",
|
|
2481
|
-
"media-typer",
|
|
2482
|
-
"setprototypeof",
|
|
2483
|
-
"side-channel-weakmap",
|
|
2484
|
-
"@typescript-eslint/tsconfig-utils",
|
|
2485
|
-
"@isaacs/cliui",
|
|
2486
|
-
"@rollup/rollup-linux-x64-gnu",
|
|
2487
|
-
"is-wsl",
|
|
2488
|
-
"retry",
|
|
2489
|
-
"@aws-sdk/types",
|
|
2490
|
-
"@types/react-dom",
|
|
2491
|
-
"combined-stream",
|
|
2492
|
-
"es-object-atoms",
|
|
2493
|
-
"@eslint/core",
|
|
2494
|
-
"whatwg-mimetype",
|
|
2495
|
-
"domutils",
|
|
2496
|
-
"@rollup/rollup-linux-x64-musl",
|
|
2497
|
-
"core-util-is",
|
|
2498
|
-
"@typescript-eslint/scope-manager",
|
|
2499
|
-
"esprima",
|
|
2500
|
-
"loose-envify",
|
|
2501
|
-
"cookie-signature",
|
|
2502
|
-
"follow-redirects",
|
|
2503
|
-
"cli-cursor",
|
|
2504
|
-
"strip-final-newline",
|
|
2505
|
-
"@typescript-eslint/project-service",
|
|
2506
|
-
"eastasianwidth",
|
|
2507
|
-
"json-parse-even-better-errors",
|
|
2508
|
-
"sprintf-js",
|
|
2509
|
-
"path-type",
|
|
2510
|
-
"content-type",
|
|
2511
|
-
"es-module-lexer",
|
|
2512
|
-
"@nodelib/fs.scandir",
|
|
2513
|
-
"write-file-atomic",
|
|
2514
|
-
"@eslint/plugin-kit",
|
|
2515
|
-
"ieee754",
|
|
2516
|
-
"prop-types",
|
|
2517
|
-
"require-from-string",
|
|
2518
|
-
"dom-serializer",
|
|
2519
|
-
"call-bind",
|
|
2520
|
-
"@eslint/config-array",
|
|
2521
|
-
"has-property-descriptors",
|
|
2522
|
-
"@nodelib/fs.stat",
|
|
2523
|
-
"merge-descriptors",
|
|
2524
|
-
"slice-ansi",
|
|
2525
|
-
"rxjs",
|
|
2526
|
-
"p-map",
|
|
2527
|
-
"toidentifier",
|
|
2528
|
-
"globby",
|
|
2529
|
-
"domhandler",
|
|
2530
|
-
"async",
|
|
2531
|
-
"@babel/helper-globals",
|
|
2532
|
-
"pirates",
|
|
2533
|
-
"@opentelemetry/semantic-conventions",
|
|
2534
|
-
"@typescript-eslint/utils",
|
|
2535
|
-
"date-fns",
|
|
2536
|
-
"is-docker",
|
|
2537
|
-
"tar",
|
|
2538
|
-
"which-typed-array",
|
|
2539
|
-
"ajv-formats",
|
|
2540
|
-
"@opentelemetry/api-logs",
|
|
2541
|
-
"@opentelemetry/resources",
|
|
2542
|
-
"side-channel",
|
|
2543
|
-
"cjs-module-lexer",
|
|
2544
|
-
"range-parser",
|
|
2545
|
-
"@humanfs/node",
|
|
2546
|
-
"define-data-property",
|
|
2547
|
-
"node-addon-api",
|
|
2548
|
-
"pako",
|
|
2549
|
-
"lilconfig",
|
|
2550
|
-
"fast-uri",
|
|
2551
|
-
"ip-address",
|
|
2552
|
-
"fs.realpath",
|
|
2553
|
-
"@img/sharp-libvips-linuxmusl-x64",
|
|
2554
|
-
"cssesc",
|
|
2555
|
-
"@opentelemetry/instrumentation",
|
|
2556
|
-
"domelementtype",
|
|
2557
|
-
"hosted-git-info",
|
|
2558
|
-
"@eslint/object-schema",
|
|
2559
|
-
"etag",
|
|
2560
|
-
"@eslint/config-helpers",
|
|
2561
|
-
"package-json-from-dist",
|
|
2562
|
-
"@humanfs/core",
|
|
2563
|
-
"htmlparser2",
|
|
2564
|
-
"jest-message-util",
|
|
2565
|
-
"for-each",
|
|
2566
|
-
"pkg-dir",
|
|
2567
|
-
"unpipe",
|
|
2568
|
-
"buffer-from",
|
|
2569
|
-
"es-abstract",
|
|
2570
|
-
"is-unicode-supported",
|
|
2571
|
-
"@types/yargs",
|
|
2572
|
-
"is-callable",
|
|
2573
|
-
"fast-xml-parser",
|
|
2574
|
-
"istanbul-lib-instrument",
|
|
2575
|
-
"escape-html",
|
|
2576
|
-
"is-regex",
|
|
2577
|
-
"dom-accessibility-api",
|
|
2578
|
-
"css-tree",
|
|
2579
|
-
"error-ex",
|
|
2580
|
-
"ee-first",
|
|
2581
|
-
"@types/unist",
|
|
2582
|
-
"log-symbols",
|
|
2583
|
-
"path-is-absolute",
|
|
2584
|
-
"end-of-stream",
|
|
2585
|
-
"@vitest/utils",
|
|
2586
|
-
"object.assign",
|
|
2587
|
-
"object-keys",
|
|
2588
|
-
"tinyexec",
|
|
2589
|
-
"scheduler",
|
|
2590
|
-
"p-try",
|
|
2591
|
-
"process-nextick-args",
|
|
2592
|
-
"vary",
|
|
2593
|
-
"@babel/traverse",
|
|
2594
|
-
"@pkgjs/parseargs",
|
|
2595
|
-
"@types/babel__generator",
|
|
2596
|
-
"kleur",
|
|
2597
|
-
"zod",
|
|
2598
|
-
"merge-stream",
|
|
2599
|
-
"available-typed-arrays",
|
|
2600
|
-
"mute-stream",
|
|
2601
|
-
"is-typed-array",
|
|
2602
|
-
"safe-regex-test",
|
|
2603
|
-
"tsconfig-paths",
|
|
2604
|
-
"minizlib",
|
|
2605
|
-
"tar-stream",
|
|
2606
|
-
"@floating-ui/core",
|
|
2607
|
-
"jose",
|
|
2608
|
-
"deepmerge",
|
|
2609
|
-
"get-tsconfig",
|
|
2610
|
-
"set-function-length",
|
|
2611
|
-
"@vitest/spy",
|
|
2612
|
-
"css-select",
|
|
2613
|
-
"@types/babel__core",
|
|
2614
|
-
"forwarded",
|
|
2615
|
-
"react",
|
|
2616
|
-
"@typescript-eslint/parser",
|
|
2617
|
-
"ajv-keywords",
|
|
2618
|
-
"define-properties",
|
|
2619
|
-
"is-generator-function",
|
|
2620
|
-
"regexp.prototype.flags",
|
|
2621
|
-
"acorn-walk",
|
|
2622
|
-
"pump",
|
|
2623
|
-
"data-uri-to-buffer",
|
|
2624
|
-
"object-hash",
|
|
2625
|
-
"jsdom",
|
|
2626
|
-
"nopt",
|
|
2627
|
-
"@babel/plugin-syntax-jsx",
|
|
2628
|
-
"@floating-ui/dom",
|
|
2629
|
-
"tiny-invariant",
|
|
2630
|
-
"strip-indent",
|
|
2631
|
-
"d3-array",
|
|
2632
|
-
"chai",
|
|
2633
|
-
"@babel/code-frame",
|
|
2634
|
-
"@typescript-eslint/eslint-plugin",
|
|
2635
|
-
"proxy-addr",
|
|
2636
|
-
"parseurl",
|
|
2637
|
-
"@floating-ui/utils",
|
|
2638
|
-
"ora",
|
|
2639
|
-
"html-encoding-sniffer",
|
|
2640
|
-
"pnpm",
|
|
2641
|
-
"whatwg-encoding",
|
|
2642
|
-
"events",
|
|
2643
|
-
"@typescript-eslint/type-utils",
|
|
2644
|
-
"env-paths",
|
|
2645
|
-
"internal-slot",
|
|
2646
|
-
"string.prototype.trimend",
|
|
2647
|
-
"extend",
|
|
2648
|
-
"resolve-pkg-maps",
|
|
2649
|
-
"istanbul-lib-coverage",
|
|
2650
|
-
"react-dom",
|
|
2651
|
-
"is-number-object",
|
|
2652
|
-
"@radix-ui/primitive",
|
|
2653
|
-
"is-plain-object",
|
|
2654
|
-
"string.prototype.trimstart",
|
|
2655
|
-
"@babel/plugin-syntax-typescript",
|
|
2656
|
-
"jest-diff",
|
|
2657
|
-
"define-lazy-prop",
|
|
2658
|
-
"globalthis",
|
|
2659
|
-
"which-boxed-primitive",
|
|
2660
|
-
"@vitest/expect",
|
|
2661
|
-
"sax",
|
|
2662
|
-
"@floating-ui/react-dom",
|
|
2663
|
-
"@vitest/pretty-format",
|
|
2664
|
-
"internmap",
|
|
2665
|
-
"@radix-ui/react-compose-refs",
|
|
2666
|
-
"is-symbol",
|
|
2667
|
-
"@eslint-community/eslint-utils",
|
|
2668
|
-
"bl",
|
|
2669
|
-
"serve-static",
|
|
2670
|
-
"get-symbol-description",
|
|
2671
|
-
"is-shared-array-buffer",
|
|
2672
|
-
"functions-have-names",
|
|
2673
|
-
"array-buffer-byte-length",
|
|
2674
|
-
"socks-proxy-agent"
|
|
2675
|
-
];
|
|
2676
|
-
});
|
|
2677
|
-
|
|
2678
|
-
// src/nearmiss.ts
|
|
2679
|
-
function baseName(name) {
|
|
2680
|
-
return name.slice(name.indexOf("/") + 1);
|
|
2681
|
-
}
|
|
2682
|
-
function scopeOf2(name) {
|
|
2683
|
-
return name.startsWith("@") ? name.slice(0, name.indexOf("/")) : "";
|
|
2684
|
-
}
|
|
2685
|
-
function squash(name) {
|
|
2686
|
-
return name.toLowerCase().replace(SEPARATORS, "");
|
|
2687
|
-
}
|
|
2688
|
-
function resemblance(name, popular) {
|
|
2689
|
-
if (scopeOf2(popular) === "" && scopeOf2(name) !== "" && baseName(name) === popular && popular.length >= MIN_LENGTH)
|
|
2690
|
-
return `${popular} under another scope`;
|
|
2691
|
-
if (squash(name) === squash(popular))
|
|
2692
|
-
return `${popular} spelled with other separators or case`;
|
|
2693
|
-
const shortest = Math.min(name.length, popular.length);
|
|
2694
|
-
const allowed = shortest >= MIN_LENGTH * 2 ? 2 : 1;
|
|
2695
|
-
if (shortest < MIN_LENGTH || Math.abs(name.length - popular.length) > allowed)
|
|
2696
|
-
return;
|
|
2697
|
-
const edits = distance(name, popular);
|
|
2698
|
-
return edits <= allowed ? `${popular}, ${edits} ${edits === 1 ? "edit" : "edits"} away` : undefined;
|
|
2699
|
-
}
|
|
2700
|
-
function nearMisses(name, popular = popular_default) {
|
|
2701
|
-
if (popular.includes(name))
|
|
2702
|
-
return [];
|
|
2703
|
-
const found = [];
|
|
2704
|
-
for (const other of popular) {
|
|
2705
|
-
const text = resemblance(name, other);
|
|
2706
|
-
if (text !== undefined)
|
|
2707
|
-
found.push({ text, edits: distance(name, other) });
|
|
2708
|
-
}
|
|
2709
|
-
return found.sort((a, b) => a.edits - b.edits).slice(0, 3).map((match) => match.text);
|
|
2710
|
-
}
|
|
2711
|
-
var SEPARATORS, MIN_LENGTH = 5;
|
|
2712
|
-
var init_nearmiss = __esm(() => {
|
|
2713
|
-
init_src();
|
|
2714
|
-
init_popular();
|
|
2715
|
-
SEPARATORS = /[-_.]/g;
|
|
2716
|
-
});
|
|
2717
|
-
|
|
2718
|
-
// src/registry.ts
|
|
2719
|
-
function isPublic(registry) {
|
|
2720
|
-
return registry.url.replace(TRAILING_SLASHES2, "") === PUBLIC_REGISTRY;
|
|
2721
|
-
}
|
|
2722
|
-
function unreachable(message) {
|
|
2723
|
-
return fail(`could not check: ${message}`, 2);
|
|
2724
|
-
}
|
|
2725
|
-
function requestInit(token) {
|
|
2726
|
-
return { headers: { accept: "application/json", ...token === undefined ? {} : { authorization: `Bearer ${token}` } }, signal: AbortSignal.timeout(REQUEST_TIMEOUT2) };
|
|
2727
|
-
}
|
|
2728
|
-
async function get(fetcher, url, token) {
|
|
2729
|
-
try {
|
|
2730
|
-
return await fetcher(url, requestInit(token));
|
|
2731
|
-
} catch (error) {
|
|
2732
|
-
return unreachable(`cannot reach ${new URL(url).host}: ${error instanceof Error ? error.message : String(error)}`);
|
|
2733
|
-
}
|
|
2734
|
-
}
|
|
2735
|
-
function isValidName(name) {
|
|
2736
|
-
return PACKAGE_NAME.test(name) && name.length <= 214;
|
|
2737
|
-
}
|
|
2738
|
-
async function fetchPackument(name, registry, fetcher = fetch) {
|
|
2739
|
-
if (!isValidName(name))
|
|
2740
|
-
fail(`${name} is not a valid npm package name`);
|
|
2741
|
-
const response = await get(fetcher, `${registry.url.replace(TRAILING_SLASHES2, "")}/${encodeURIComponent(name).replace("%40", "@").replace("%2F", "%2f")}`, registry.token);
|
|
2742
|
-
if (response.status === 404)
|
|
2743
|
-
return;
|
|
2744
|
-
if (!response.ok)
|
|
2745
|
-
unreachable(`${new URL(registry.url).host} answered ${response.status} for ${name}`);
|
|
2746
|
-
let packument;
|
|
2747
|
-
try {
|
|
2748
|
-
packument = await response.json();
|
|
2749
|
-
} catch {
|
|
2750
|
-
return unreachable(`${new URL(registry.url).host} answered ${name} with something that is not JSON`);
|
|
2751
|
-
}
|
|
2752
|
-
if (packument?.name !== name)
|
|
2753
|
-
unreachable(`${new URL(registry.url).host} answered ${name} with the metadata of ${String(packument?.name)}`);
|
|
2754
|
-
return packument;
|
|
2755
|
-
}
|
|
2756
|
-
async function fetchDownloads(name, fetcher = fetch) {
|
|
2757
|
-
const response = await get(fetcher, `${DOWNLOADS_API}/${encodeURIComponent(name)}`);
|
|
2758
|
-
if (!response.ok)
|
|
2759
|
-
return;
|
|
2760
|
-
try {
|
|
2761
|
-
return (await response.json()).downloads;
|
|
2762
|
-
} catch {
|
|
2763
|
-
return;
|
|
2764
|
-
}
|
|
2765
|
-
}
|
|
2766
|
-
var PUBLIC_REGISTRY = "https://registry.npmjs.org", DOWNLOADS_API = "https://api.npmjs.org/downloads/point/last-week", TRAILING_SLASHES2, REQUEST_TIMEOUT2 = 1e4, PACKAGE_NAME;
|
|
2767
|
-
var init_registry = __esm(() => {
|
|
2768
|
-
init_src();
|
|
2769
|
-
TRAILING_SLASHES2 = /\/+$/;
|
|
2770
|
-
PACKAGE_NAME = /^(?:@[\w~-][\w.~-]*\/)?[\w~-][\w.~-]*$/;
|
|
2771
|
-
});
|
|
2772
|
-
|
|
2773
|
-
// src/analyze.ts
|
|
2774
|
-
function parseSpec(text) {
|
|
2775
|
-
const at = text.search(VERSION_SEPARATOR);
|
|
2776
|
-
return at === -1 ? { name: text } : { name: text.slice(0, at), request: text.slice(at + 1) };
|
|
2777
|
-
}
|
|
2778
|
-
function isStable(version) {
|
|
2779
|
-
return !version.includes("-");
|
|
2780
|
-
}
|
|
2781
|
-
function resolve5(packument, request) {
|
|
2782
|
-
const tags = packument["dist-tags"] ?? {};
|
|
2783
|
-
const versions = Object.keys(packument.versions ?? {});
|
|
2784
|
-
const wanted = request === undefined || request === "" ? "latest" : request;
|
|
2785
|
-
if (tags[wanted] !== undefined)
|
|
2786
|
-
return tags[wanted];
|
|
2787
|
-
if (versions.includes(wanted))
|
|
2788
|
-
return wanted;
|
|
2789
|
-
if (!isRange(wanted))
|
|
2790
|
-
return;
|
|
2791
|
-
return versions.filter((version) => Bun.semver.satisfies(version, wanted)).sort(Bun.semver.order).at(-1);
|
|
2792
|
-
}
|
|
2793
|
-
function licenseOf(license) {
|
|
2794
|
-
return typeof license === "string" ? license : license?.type;
|
|
2795
|
-
}
|
|
2796
|
-
function repositoryOf(packument) {
|
|
2797
|
-
const repository = typeof packument.repository === "string" ? packument.repository : packument.repository?.url;
|
|
2798
|
-
return repository?.replace(GIT_PREFIX, "") ?? packument.homepage;
|
|
2799
|
-
}
|
|
2800
|
-
function ageDays(published, now) {
|
|
2801
|
-
const at = Date.parse(published ?? "");
|
|
2802
|
-
return Number.isNaN(at) ? undefined : (now - at) / DAY;
|
|
2803
|
-
}
|
|
2804
|
-
function daysAgo(age) {
|
|
2805
|
-
return age < 1 ? "less than a day" : bo(Math.floor(age), "day");
|
|
2806
|
-
}
|
|
2807
|
-
function installScriptsOf(version) {
|
|
2808
|
-
return Object.fromEntries(INSTALL_SCRIPTS.flatMap((name) => version?.scripts?.[name] === undefined ? [] : [[name, version.scripts[name]]]));
|
|
2809
|
-
}
|
|
2810
|
-
function trustedBy(name, trusted) {
|
|
2811
|
-
return trusted.find((pattern) => pattern === name || new Bun.Glob(pattern).match(name));
|
|
2812
|
-
}
|
|
2813
|
-
function safeRelease(packument, now, minAgeDays) {
|
|
2814
|
-
const old = Object.keys(packument.versions ?? {}).filter((version) => isStable(version) && (ageDays(packument.time?.[version], now) ?? 0) >= minAgeDays && packument.time?.[version] !== undefined);
|
|
2815
|
-
const version = old.sort(Bun.semver.order).at(-1);
|
|
2816
|
-
return version === undefined ? undefined : { version, published: packument.time?.[version] };
|
|
2817
|
-
}
|
|
2818
|
-
function previousRelease(packument, version) {
|
|
2819
|
-
const below = Object.keys(packument.versions ?? {}).filter((each) => (isStable(each) || !isStable(version)) && Bun.semver.order(each, version) < 0).sort(Bun.semver.order).at(-1);
|
|
2820
|
-
return below === undefined ? undefined : packument.versions?.[below];
|
|
2821
|
-
}
|
|
2822
|
-
function publisherWarnings(packument, version) {
|
|
2823
|
-
const current = packument.versions?.[version];
|
|
2824
|
-
const previous = previousRelease(packument, version);
|
|
2825
|
-
const warnings = [];
|
|
2826
|
-
if (current === undefined || previous === undefined)
|
|
2827
|
-
return warnings;
|
|
2828
|
-
const by = current._npmUser?.name;
|
|
2829
|
-
const before = previous._npmUser?.name;
|
|
2830
|
-
const toTrusted = current._npmUser?.trustedPublisher !== undefined && previous._npmUser?.trustedPublisher === undefined;
|
|
2831
|
-
if (by !== undefined && before !== undefined && by !== before && !toTrusted)
|
|
2832
|
-
warnings.push(`${version} was published by ${by}, ${previous.version} by ${before}`);
|
|
2833
|
-
if (previous.dist?.attestations !== undefined && current.dist?.attestations === undefined)
|
|
2834
|
-
warnings.push(`${version} has no provenance attestation, ${previous.version} had one`);
|
|
2835
|
-
return warnings;
|
|
2836
|
-
}
|
|
2837
|
-
function analyze(input) {
|
|
2838
|
-
const { spec, packument, registry, now = Date.now(), minAgeDays = DEFAULT_MIN_AGE_DAYS } = input;
|
|
2839
|
-
const report = { name: spec.name, registry, exists: packument !== undefined, requested: spec.request, installScripts: {}, nearMisses: nearMisses(spec.name), advisories: input.advisories ?? [], fixes: [], warnings: [], blocked: false, downloads: input.downloads };
|
|
2840
|
-
if (report.nearMisses.length > 0)
|
|
2841
|
-
report.warnings.push(`name looks like ${report.nearMisses.join("; ")}, check it is the package meant`);
|
|
2842
|
-
if (packument === undefined) {
|
|
2843
|
-
report.blocked = true;
|
|
2844
|
-
report.warnings.unshift(`${spec.name} is not on ${registry}, the name may be guessed`);
|
|
2845
|
-
return report;
|
|
2846
|
-
}
|
|
2847
|
-
const latest = packument["dist-tags"]?.latest;
|
|
2848
|
-
const version = resolve5(packument, spec.request);
|
|
2849
|
-
const entry = version === undefined ? undefined : packument.versions?.[version];
|
|
2850
|
-
report.description = packument.description;
|
|
2851
|
-
report.license = licenseOf(entry?.license) ?? licenseOf(packument.license);
|
|
2852
|
-
report.repository = repositoryOf(packument);
|
|
2853
|
-
report.latest = latest === undefined ? undefined : { version: latest, published: packument.time?.[latest] };
|
|
2854
|
-
const trust = trustedBy(spec.name, input.trusted ?? DEFAULT_TRUSTED);
|
|
2855
|
-
report.safe = safeRelease(packument, now, trust === undefined ? minAgeDays : 0);
|
|
2856
|
-
report.version = version;
|
|
2857
|
-
report.published = version === undefined ? undefined : packument.time?.[version];
|
|
2858
|
-
report.installScripts = installScriptsOf(entry);
|
|
2859
|
-
report.deprecated = entry?.deprecated;
|
|
2860
|
-
if (version === undefined) {
|
|
2861
|
-
report.blocked = true;
|
|
2862
|
-
report.warnings.push(`no version of ${spec.name} matches ${spec.request}`);
|
|
2863
|
-
return report;
|
|
2864
|
-
}
|
|
2865
|
-
const age = ageDays(report.published, now);
|
|
2866
|
-
const kept = new Set(report.advisories.map((each) => each.id));
|
|
2867
|
-
report.fixes = report.safe?.version === version ? [] : (input.safeAdvisories ?? []).filter((each) => !kept.has(each.id));
|
|
2868
|
-
if (age === undefined) {
|
|
2869
|
-
const isBlocking = minAgeDays > 0 && registry === PUBLIC_HOST && trust === undefined;
|
|
2870
|
-
report.blocked ||= isBlocking;
|
|
2871
|
-
report.warnings.push(`${registry} gives no publish date for ${version}, its age cannot be checked${isBlocking ? " and it is refused" : ""}`);
|
|
2872
|
-
} else if (age < minAgeDays && report.fixes.length > 0) {
|
|
2873
|
-
report.warnings.push(`${version} was published ${daysAgo(age)} ago, under ${minAgeDays} days, but it fixes ${report.fixes.map((each) => `${each.ghsa ?? each.id} (${each.severity})`).join(", ")} that ${report.safe?.version} has, so its age does not hold it back`);
|
|
2874
|
-
} else if (age < minAgeDays && trust !== undefined) {
|
|
2875
|
-
report.warnings.push(`${version} was published ${daysAgo(age)} ago, under ${minAgeDays} days, its age not checked as ${trust} is trusted`);
|
|
2876
|
-
} else if (age < minAgeDays && registry !== PUBLIC_HOST) {
|
|
2877
|
-
report.warnings.push(`${version} was published ${daysAgo(age)} ago, under ${minAgeDays} days, not held back on ${registry}`);
|
|
2878
|
-
} else if (age < minAgeDays) {
|
|
2879
|
-
report.blocked = true;
|
|
2880
|
-
report.warnings.push(`${version} was published ${daysAgo(age)} ago, under ${minAgeDays} days${report.safe === undefined ? ", and no older stable version exists" : `, use ${spec.name}@${report.safe.version}`}`);
|
|
2881
|
-
}
|
|
2882
|
-
const scripts = Object.keys(report.installScripts);
|
|
2883
|
-
if (scripts.length > 0)
|
|
2884
|
-
report.warnings.push(`${version} runs ${scripts.join(", ")} at install`);
|
|
2885
|
-
if (report.deprecated !== undefined)
|
|
2886
|
-
report.warnings.push(`${version} is deprecated: ${report.deprecated}`);
|
|
2887
|
-
report.warnings.push(...publisherWarnings(packument, version));
|
|
2888
|
-
if (input.licenses !== undefined) {
|
|
2889
|
-
const isMissing = report.license === undefined || report.license === "";
|
|
2890
|
-
if (isMissing) {
|
|
2891
|
-
report.blocked = true;
|
|
2892
|
-
report.warnings.push(`${version} declares no licence, and the allowlist needs one`);
|
|
2893
|
-
} else if (!isLicenseAllowed(report.license ?? "", input.licenses)) {
|
|
2894
|
-
report.blocked = true;
|
|
2895
|
-
report.warnings.push(`licence ${report.license} is not in the allowlist (${input.licenses.join(", ")})`);
|
|
2896
|
-
}
|
|
2897
|
-
}
|
|
2898
|
-
if (input.blockSeverity !== undefined) {
|
|
2899
|
-
const blocking = filterAdvisories(report.advisories, input.blockSeverity);
|
|
2900
|
-
if (blocking.length > 0) {
|
|
2901
|
-
report.blocked = true;
|
|
2902
|
-
report.warnings.push(`${version} has ${blocking.length} advisor${blocking.length === 1 ? "y" : "ies"} at ${input.blockSeverity} or above: ${blocking.map((each) => each.ghsa ?? each.id).join(", ")}`);
|
|
2903
|
-
}
|
|
2904
|
-
}
|
|
2905
|
-
return report;
|
|
2906
|
-
}
|
|
2907
|
-
var DEFAULT_MIN_AGE_DAYS = 14, DEFAULT_TRUSTED, DAY = 86400000, PUBLIC_HOST, INSTALL_SCRIPTS, GIT_PREFIX, VERSION_SEPARATOR;
|
|
2908
|
-
var init_analyze = __esm(() => {
|
|
2909
|
-
init_text();
|
|
2910
|
-
init_advisories();
|
|
2911
|
-
init_licenses();
|
|
2912
|
-
init_nearmiss();
|
|
2913
|
-
init_registry();
|
|
2914
|
-
init_semver();
|
|
2915
|
-
DEFAULT_TRUSTED = ["@kaynooo/*", "@kayjs/*"];
|
|
2916
|
-
PUBLIC_HOST = new URL(PUBLIC_REGISTRY).host;
|
|
2917
|
-
INSTALL_SCRIPTS = ["preinstall", "install", "postinstall"];
|
|
2918
|
-
GIT_PREFIX = /^git\+/;
|
|
2919
|
-
VERSION_SEPARATOR = /(?<=.)@/;
|
|
2920
|
-
});
|
|
2921
|
-
|
|
2922
|
-
// src/config.ts
|
|
2923
|
-
import { homedir as homedir5 } from "os";
|
|
2924
|
-
import { dirname as dirname5, join as join7 } from "path";
|
|
2925
|
-
import process20 from "process";
|
|
2926
|
-
function expand2(value, env) {
|
|
2927
|
-
let missing = false;
|
|
2928
|
-
const expanded = value.replace(ENV_REFERENCE, (_, braced, bare) => {
|
|
2929
|
-
const found = env[braced ?? bare ?? ""];
|
|
2930
|
-
missing ||= found === undefined;
|
|
2931
|
-
return found ?? "";
|
|
2932
|
-
});
|
|
2933
|
-
return missing ? undefined : expanded;
|
|
2934
|
-
}
|
|
2935
|
-
function literal(value) {
|
|
2936
|
-
return expand2(value, {}) === value ? value : undefined;
|
|
2937
|
-
}
|
|
2938
|
-
function parseNpmrc(text, env) {
|
|
2939
|
-
const config = { scopes: {}, tokens: {}, scopeTokens: {} };
|
|
2940
|
-
for (const line of text.split(`
|
|
2941
|
-
`)) {
|
|
2942
|
-
const at = line.indexOf("=");
|
|
2943
|
-
if (at === -1 || COMMENT.test(line))
|
|
2944
|
-
continue;
|
|
2945
|
-
const key = line.slice(0, at).trim();
|
|
2946
|
-
const scope = SCOPE_REGISTRY.exec(key)?.[1];
|
|
2947
|
-
const tokenFor = AUTH_TOKEN.exec(key)?.[1];
|
|
2948
|
-
const raw = line.slice(at + 1).trim().replace(QUOTES, "$2");
|
|
2949
|
-
const value = tokenFor === undefined ? literal(raw) : expand2(raw, env);
|
|
2950
|
-
if (value === undefined || value === "")
|
|
2951
|
-
continue;
|
|
2952
|
-
if (scope !== undefined)
|
|
2953
|
-
config.scopes[scope] = value;
|
|
2954
|
-
else if (tokenFor !== undefined)
|
|
2955
|
-
config.tokens[tokenFor] = value;
|
|
2956
|
-
else if (key === "registry")
|
|
2957
|
-
config.registry = value;
|
|
2958
|
-
}
|
|
2959
|
-
return config;
|
|
2960
|
-
}
|
|
2961
|
-
function bunEntry(entry, env) {
|
|
2962
|
-
const url = typeof entry === "string" ? entry : entry.url;
|
|
2963
|
-
const token = typeof entry === "string" || entry.token === undefined ? undefined : expand2(entry.token, env);
|
|
2964
|
-
return { ...url === undefined || literal(url) === undefined ? {} : { url }, ...token === undefined ? {} : { token } };
|
|
2965
|
-
}
|
|
2966
|
-
function parseBunfig(text, env) {
|
|
2967
|
-
const config = { scopes: {}, tokens: {}, scopeTokens: {} };
|
|
2968
|
-
const install = Bun.TOML.parse(text).install;
|
|
2969
|
-
if (install?.registry !== undefined) {
|
|
2970
|
-
const { url, token } = bunEntry(install.registry, env);
|
|
2971
|
-
if (url !== undefined)
|
|
2972
|
-
config.registry = url;
|
|
2973
|
-
if (url !== undefined && token !== undefined)
|
|
2974
|
-
config.tokens[url.replace(PROTOCOL, "")] = token;
|
|
2975
|
-
}
|
|
2976
|
-
for (const [scope, entry] of Object.entries(install?.scopes ?? {})) {
|
|
2977
|
-
const { url, token } = bunEntry(entry, env);
|
|
2978
|
-
if (url !== undefined)
|
|
2979
|
-
config.scopes[scope.startsWith("@") ? scope : `@${scope}`] = url;
|
|
2980
|
-
if (token !== undefined)
|
|
2981
|
-
config.scopeTokens[scope.startsWith("@") ? scope : `@${scope}`] = token;
|
|
2982
|
-
}
|
|
2983
|
-
return config;
|
|
2984
|
-
}
|
|
2985
|
-
function tokenFor(config, url) {
|
|
2986
|
-
const address = `${url.replace(PROTOCOL, "").replace(TRAILING_SLASHES3, "")}/`;
|
|
2987
|
-
const best = Object.keys(config.tokens).filter((key) => address.startsWith(`${key.replace(TRAILING_SLASHES3, "")}/`)).sort((a, b) => b.length - a.length)[0];
|
|
2988
|
-
return best === undefined ? undefined : config.tokens[best];
|
|
2989
|
-
}
|
|
2990
|
-
function mayCarryToken(url) {
|
|
2991
|
-
const { protocol, hostname } = new URL(url);
|
|
2992
|
-
return protocol === "https:" || LOCAL_HOSTS.has(hostname);
|
|
2993
|
-
}
|
|
2994
|
-
function registryFor(name, configs) {
|
|
2995
|
-
const scope = name.startsWith("@") ? name.slice(0, name.indexOf("/")) : undefined;
|
|
2996
|
-
const scoped = scope === undefined ? undefined : configs.find((config) => config.scopes[scope] !== undefined);
|
|
2997
|
-
const url = (scope === undefined ? undefined : scoped?.scopes[scope]) ?? configs.find((config) => config.registry !== undefined)?.registry;
|
|
2998
|
-
if (url === undefined)
|
|
2999
|
-
return { url: PUBLIC_REGISTRY };
|
|
3000
|
-
const token = (scope === undefined ? undefined : scoped?.scopeTokens[scope]) ?? configs.map((other) => tokenFor(other, url)).find((found) => found !== undefined);
|
|
3001
|
-
return { url, token: mayCarryToken(url) ? token : undefined };
|
|
3002
|
-
}
|
|
3003
|
-
function readable(path, parse) {
|
|
3004
|
-
try {
|
|
3005
|
-
return parse();
|
|
3006
|
-
} catch (error) {
|
|
3007
|
-
return unreachable(`${path} cannot be read: ${error instanceof Error ? error.message : String(error)}`);
|
|
3008
|
-
}
|
|
3009
|
-
}
|
|
3010
|
-
async function readIfThere(path) {
|
|
3011
|
-
const file = Bun.file(path);
|
|
3012
|
-
return await file.exists() ? file.text() : undefined;
|
|
3013
|
-
}
|
|
3014
|
-
async function loadConfigs(cwd = process20.cwd(), env = process20.env, home = homedir5()) {
|
|
3015
|
-
const directories = [];
|
|
3016
|
-
for (let dir = cwd;!directories.includes(dir); dir = dirname5(dir))
|
|
3017
|
-
directories.push(dir);
|
|
3018
|
-
if (!directories.includes(home))
|
|
3019
|
-
directories.push(home);
|
|
3020
|
-
const configs = [];
|
|
3021
|
-
for (const dir of directories) {
|
|
3022
|
-
const bunfig = await readIfThere(join7(dir, "bunfig.toml"));
|
|
3023
|
-
const npmrc = await readIfThere(join7(dir, ".npmrc"));
|
|
3024
|
-
if (bunfig !== undefined)
|
|
3025
|
-
configs.push(readable(join7(dir, "bunfig.toml"), () => parseBunfig(bunfig, env)));
|
|
3026
|
-
if (npmrc !== undefined)
|
|
3027
|
-
configs.push(parseNpmrc(npmrc, env));
|
|
3028
|
-
}
|
|
3029
|
-
return configs;
|
|
3030
|
-
}
|
|
3031
|
-
function isSeverity(value) {
|
|
3032
|
-
return SEVERITIES.includes(value);
|
|
3033
|
-
}
|
|
3034
|
-
function parseSettings(text) {
|
|
3035
|
-
const raw = Bun.JSONC.parse(text);
|
|
3036
|
-
const settings = {};
|
|
3037
|
-
if (Array.isArray(raw?.licenses) && raw.licenses.every((each) => typeof each === "string"))
|
|
3038
|
-
settings.licenses = raw.licenses;
|
|
3039
|
-
if (isSeverity(raw?.blockSeverity))
|
|
3040
|
-
settings.blockSeverity = raw.blockSeverity;
|
|
3041
|
-
if (typeof raw?.minAge === "number" && Number.isInteger(raw.minAge) && raw.minAge >= 0)
|
|
3042
|
-
settings.minAge = raw.minAge;
|
|
3043
|
-
if (typeof raw?.concurrency === "number" && Number.isInteger(raw.concurrency) && raw.concurrency > 0)
|
|
3044
|
-
settings.concurrency = raw.concurrency;
|
|
3045
|
-
if (Array.isArray(raw?.trusted) && raw.trusted.every((each) => typeof each === "string"))
|
|
3046
|
-
settings.trusted = raw.trusted;
|
|
3047
|
-
return settings;
|
|
3048
|
-
}
|
|
3049
|
-
async function loadSettings(cwd = process20.cwd(), home) {
|
|
3050
|
-
const files = [];
|
|
3051
|
-
for (let dir = cwd;!files.includes(join7(dir, SETTINGS_FILE)); dir = dirname5(dir))
|
|
3052
|
-
files.push(join7(dir, SETTINGS_FILE));
|
|
3053
|
-
files.push(userConfigReadPath("pkg", [["pkg", "config.json"]], { home }));
|
|
3054
|
-
const settings = {};
|
|
3055
|
-
for (const file of files) {
|
|
3056
|
-
const text = await readIfThere(file);
|
|
3057
|
-
if (text === undefined)
|
|
3058
|
-
continue;
|
|
3059
|
-
const found = readable(file, () => parseSettings(text));
|
|
3060
|
-
settings.licenses ??= found.licenses;
|
|
3061
|
-
settings.blockSeverity ??= found.blockSeverity;
|
|
3062
|
-
settings.minAge ??= found.minAge;
|
|
3063
|
-
settings.concurrency ??= found.concurrency;
|
|
3064
|
-
settings.trusted ??= found.trusted;
|
|
3065
|
-
}
|
|
3066
|
-
return settings;
|
|
3067
|
-
}
|
|
3068
|
-
var ENV_REFERENCE, COMMENT, SCOPE_REGISTRY, AUTH_TOKEN, PROTOCOL, TRAILING_SLASHES3, LOCAL_HOSTS, QUOTES, DEFAULT_BLOCK_SEVERITY = "high", SETTINGS_FILE = ".pkgrc.json";
|
|
3069
|
-
var init_config2 = __esm(() => {
|
|
3070
|
-
init_src();
|
|
3071
|
-
init_registry();
|
|
3072
|
-
ENV_REFERENCE = /\$\{(\w+)\}|\$(\w+)/g;
|
|
3073
|
-
COMMENT = /^\s*[#;]/;
|
|
3074
|
-
SCOPE_REGISTRY = /^(@[^:]+):registry$/;
|
|
3075
|
-
AUTH_TOKEN = /^(\/\/.+?):_authToken$/;
|
|
3076
|
-
PROTOCOL = /^\w+:/;
|
|
3077
|
-
TRAILING_SLASHES3 = /\/+$/;
|
|
3078
|
-
LOCAL_HOSTS = new Set(["localhost", "127.0.0.1", "[::1]"]);
|
|
3079
|
-
QUOTES = /^(["'])(.*)\1$/;
|
|
3080
|
-
});
|
|
3081
|
-
|
|
3082
|
-
// ../kit/src/shell.ts
|
|
3083
|
-
function wrapper(short = "", long = [], operands = 0, runsString = false) {
|
|
3084
|
-
return { short, long, operands, runsString };
|
|
3085
|
-
}
|
|
3086
|
-
var SEPARATORS2, PLAIN_BREAKERS, GLOB_CHARS, COMMENT_PREFIXES, DOUBLE_QUOTED_ESCAPES, KEYWORDS, FISH_COMBINERS, SHELLS, SCANNED_PROGRAMS, COMMAND_STRING_PROGRAMS, POWERSHELL, SHELL_VALUE_OPTIONS, FISH_VALUE_OPTIONS, PRINTERS, FIND_EXEC, RUNNER, WRAPPERS;
|
|
3087
|
-
var init_shell = __esm(() => {
|
|
3088
|
-
SEPARATORS2 = new Set([`
|
|
3089
|
-
`, ";", "|"]);
|
|
3090
|
-
PLAIN_BREAKERS = new Set(["<", ">", "(", ")", "&", "|"]);
|
|
3091
|
-
GLOB_CHARS = new Set(["*", "?", "["]);
|
|
3092
|
-
COMMENT_PREFIXES = new Set([";", "&", "|", "(", ")"]);
|
|
3093
|
-
DOUBLE_QUOTED_ESCAPES = new Set(["$", "`", '"', "\\"]);
|
|
3094
|
-
KEYWORDS = new Set(["then", "do", "else", "if", "elif", "while", "until", "!", "{", "}"]);
|
|
3095
|
-
FISH_COMBINERS = new Set(["and", "or", "not"]);
|
|
3096
|
-
SHELLS = new Set(["sh", "bash", "zsh", "dash", "ash", "ksh", "fish", "csh", "tcsh", "nu", "xonsh", "elvish", "pwsh", "powershell"]);
|
|
3097
|
-
SCANNED_PROGRAMS = new Set(["su", "runuser", "flock"]);
|
|
3098
|
-
COMMAND_STRING_PROGRAMS = new Set([...SHELLS, ...SCANNED_PROGRAMS]);
|
|
3099
|
-
POWERSHELL = new Set(["pwsh", "powershell"]);
|
|
3100
|
-
SHELL_VALUE_OPTIONS = new Set(["-o", "-O", "--rcfile", "--init-file"]);
|
|
3101
|
-
FISH_VALUE_OPTIONS = new Set(["-C", "--init-command"]);
|
|
3102
|
-
PRINTERS = new Set(["echo", "printf"]);
|
|
3103
|
-
FIND_EXEC = new Set(["-exec", "-execdir", "-ok", "-okdir"]);
|
|
3104
|
-
RUNNER = { ...wrapper(), afterDashes: true };
|
|
3105
|
-
WRAPPERS = new Map([
|
|
3106
|
-
["command", wrapper()],
|
|
3107
|
-
["builtin", wrapper()],
|
|
3108
|
-
["nohup", wrapper()],
|
|
3109
|
-
["setsid", wrapper()],
|
|
3110
|
-
["busybox", wrapper()],
|
|
3111
|
-
["exec", wrapper("a")],
|
|
3112
|
-
["time", wrapper("fo", ["--format", "--output"])],
|
|
3113
|
-
["env", wrapper("uCS", ["--unset", "--chdir", "--split-string", "--argv0"])],
|
|
3114
|
-
["sudo", wrapper("ughpCTrtUDR", ["--user", "--group", "--host", "--prompt", "--close-from", "--command-timeout", "--role", "--type", "--other-user", "--chdir", "--chroot"])],
|
|
3115
|
-
["doas", wrapper("uC")],
|
|
3116
|
-
["timeout", wrapper("sk", ["--signal", "--kill-after"], 1)],
|
|
3117
|
-
["nice", wrapper("n", ["--adjustment"])],
|
|
3118
|
-
["ionice", wrapper("cnpPu", ["--class", "--classdata", "--pid", "--pgid", "--uid"])],
|
|
3119
|
-
["stdbuf", wrapper("ioe", ["--input", "--output", "--error"])],
|
|
3120
|
-
["chroot", wrapper("", ["--userspec", "--groups"], 1)],
|
|
3121
|
-
["watch", wrapper("n", ["--interval"], 0, true)],
|
|
3122
|
-
["flock", wrapper("wE", ["--timeout", "--conflict-exit-code"], 1)],
|
|
3123
|
-
["parallel", wrapper("jnNSaIPlLdTsC", ["--jobs", "--max-args", "--max-replace-args", "--sshlogin", "--arg-file", "--delimiter", "--colsep"], 0, true)],
|
|
3124
|
-
["unbuffer", wrapper()],
|
|
3125
|
-
["systemd-run", wrapper("puEMH", ["--property", "--unit", "--description", "--slice", "--setenv", "--machine", "--host", "--uid", "--gid", "--working-directory", "--nice", "--service-type"])],
|
|
3126
|
-
["xargs", wrapper("IndsEaPL", ["--max-args", "--max-procs", "--max-chars", "--delimiter", "--arg-file", "--eof", "--max-lines", "--process-slot-var"])],
|
|
3127
|
-
["strace", wrapper("abeEIoOpPsSuUX", ["--trace", "--output", "--attach", "--string-limit", "--user", "--env", "--columns", "--trace-path", "--signal", "--status", "--summary-sort-by", "--summary-columns", "--const-print-style", "--interruptible", "--detach-on"])],
|
|
3128
|
-
["ltrace", wrapper("aeFlnopsuxX", ["--output", "--user", "--library", "--config", "--align", "--indent"])],
|
|
3129
|
-
["taskset", wrapper("", [], 1)],
|
|
3130
|
-
["fakeroot", wrapper("lsib", ["--lib", "--faked"])],
|
|
3131
|
-
["sshpass", wrapper("pfdP")],
|
|
3132
|
-
["coproc", wrapper()],
|
|
3133
|
-
["proxychains", wrapper("f")],
|
|
3134
|
-
["proxychains4", wrapper("f")],
|
|
3135
|
-
["torsocks", wrapper("upaP", ["--user", "--pass", "--address", "--port"])],
|
|
3136
|
-
["chrt", wrapper("TPD", ["--sched-runtime", "--sched-period", "--sched-deadline"], 1)],
|
|
3137
|
-
["unshare", wrapper("SGRw", ["--setuid", "--setgid", "--root", "--wd", "--map-user", "--map-group", "--map-users", "--map-groups", "--propagation", "--setgroups"])],
|
|
3138
|
-
["nsenter", wrapper("tSG", ["--target", "--setuid", "--setgid"])],
|
|
3139
|
-
["out", RUNNER],
|
|
3140
|
-
["slot", RUNNER],
|
|
3141
|
-
["waitfor", RUNNER],
|
|
3142
|
-
["base", RUNNER]
|
|
3143
|
-
]);
|
|
3144
|
-
});
|
|
3145
|
-
|
|
3146
|
-
// src/pin.ts
|
|
3147
|
-
function actions(byAction) {
|
|
3148
|
-
return new Map(Object.entries(byAction).flatMap(([action, names]) => names.map((name) => [name, action])));
|
|
3149
|
-
}
|
|
3150
|
-
var LOCKFILES, NPM_INSTALLS, NPM_TEST_INSTALLS, ACTIONS, OPTION_FLAGS, DIR_FLAGS, VALUE_FLAGS;
|
|
3151
|
-
var init_pin = __esm(() => {
|
|
3152
|
-
init_shell();
|
|
3153
|
-
LOCKFILES = [
|
|
3154
|
-
["bun.lock", "bun"],
|
|
3155
|
-
["bun.lockb", "bun"],
|
|
3156
|
-
["pnpm-lock.yaml", "pnpm"],
|
|
3157
|
-
["yarn.lock", "yarn"],
|
|
3158
|
-
["package-lock.json", "npm"]
|
|
3159
|
-
];
|
|
3160
|
-
NPM_INSTALLS = ["install", "i", "in", "ins", "inst", "insta", "instal", "isnt", "isnta", "isntal", "isntall"];
|
|
3161
|
-
NPM_TEST_INSTALLS = ["it", "install-test", "cit", "clean-install-test", "install-ci-test"];
|
|
3162
|
-
ACTIONS = {
|
|
3163
|
-
bun: actions({ install: ["install", "i"], add: ["add", "a"], remove: ["remove", "rm"], update: ["update"] }),
|
|
3164
|
-
pnpm: actions({ install: ["install", "i"], add: ["add"], remove: ["remove", "rm"], update: ["update", "up"] }),
|
|
3165
|
-
yarn: new Map([...actions({ install: ["", "install"], add: ["add"], remove: ["remove"], update: ["upgrade"] }), ["upgrade-interactive", null], ["import", null]]),
|
|
3166
|
-
npm: new Map([...actions({
|
|
3167
|
-
install: NPM_INSTALLS,
|
|
3168
|
-
add: ["add"],
|
|
3169
|
-
frozen: ["ci", "clean-install", "ic", "install-clean", "isntall-clean"],
|
|
3170
|
-
remove: ["uninstall", "unlink", "remove", "rm", "r", "un"],
|
|
3171
|
-
update: ["update", "u", "up", "upgrade", "udpate"]
|
|
3172
|
-
}), ...NPM_TEST_INSTALLS.map((name) => [name, null])])
|
|
3173
|
-
};
|
|
3174
|
-
OPTION_FLAGS = new Map([
|
|
3175
|
-
["-D", "dev"],
|
|
3176
|
-
["--save-dev", "dev"],
|
|
3177
|
-
["--dev", "dev"],
|
|
3178
|
-
["-E", "exact"],
|
|
3179
|
-
["--save-exact", "exact"],
|
|
3180
|
-
["--exact", "exact"]
|
|
3181
|
-
]);
|
|
3182
|
-
DIR_FLAGS = new Set(["--cwd", "-C", "--dir", "--prefix"]);
|
|
3183
|
-
VALUE_FLAGS = new Set([...DIR_FLAGS, "--filter", "-F"]);
|
|
3184
|
-
});
|
|
3185
|
-
|
|
3186
|
-
// src/consumers.ts
|
|
3187
|
-
import { existsSync as existsSync4, readdirSync, readFileSync as readFileSync6 } from "fs";
|
|
3188
|
-
import { dirname as dirname6, join as join8, relative } from "path";
|
|
3189
|
-
function packageFiles(dir, depth, found, ignored = ignoredFolders()) {
|
|
3190
|
-
let entries;
|
|
3191
|
-
try {
|
|
3192
|
-
entries = readdirSync(dir, { withFileTypes: true });
|
|
3193
|
-
} catch {
|
|
3194
|
-
return found;
|
|
3195
|
-
}
|
|
3196
|
-
for (const entry of entries) {
|
|
3197
|
-
if (entry.isFile() && entry.name === "package.json")
|
|
3198
|
-
found.push(join8(dir, entry.name));
|
|
3199
|
-
else if (entry.isDirectory() && depth < MAX_DEPTH && !entry.name.startsWith(".") && !ignored.has(entry.name))
|
|
3200
|
-
packageFiles(join8(dir, entry.name), depth + 1, found, ignored);
|
|
3201
|
-
}
|
|
3202
|
-
return found;
|
|
3203
|
-
}
|
|
3204
|
-
function managerFor(dir, root) {
|
|
3205
|
-
for (let at = dir;; at = dirname6(at)) {
|
|
3206
|
-
const lockfile = LOCKFILES.find(([file]) => existsSync4(join8(at, file)));
|
|
3207
|
-
if (lockfile !== undefined)
|
|
3208
|
-
return lockfile[1];
|
|
3209
|
-
if (at === root || at === dirname6(at))
|
|
3210
|
-
return "bun";
|
|
3211
|
-
}
|
|
3212
|
-
}
|
|
3213
|
-
function readManifest(path) {
|
|
3214
|
-
try {
|
|
3215
|
-
return JSON.parse(readFileSync6(path, "utf8"));
|
|
3216
|
-
} catch {
|
|
3217
|
-
return;
|
|
3218
|
-
}
|
|
3219
|
-
}
|
|
3220
|
-
function findConsumers(name, root) {
|
|
3221
|
-
const consumers = [];
|
|
3222
|
-
for (const path of packageFiles(root, 0, []).sort()) {
|
|
3223
|
-
const manifest = readManifest(path);
|
|
3224
|
-
if (manifest === undefined)
|
|
3225
|
-
continue;
|
|
3226
|
-
const seen = new Set;
|
|
3227
|
-
for (const kind of KINDS) {
|
|
3228
|
-
for (const [key, spec] of Object.entries(manifest[kind] ?? {})) {
|
|
3229
|
-
const aliased = typeof spec === "string" && key !== name && ALIAS.exec(spec)?.[1] === name;
|
|
3230
|
-
if (typeof spec === "string" && (key === name || aliased) && !seen.has(key)) {
|
|
3231
|
-
seen.add(key);
|
|
3232
|
-
consumers.push({ dir: relative(root, dirname6(path)) || ".", path, kind, spec, ...aliased ? { alias: key } : {}, manager: managerFor(dirname6(path), root) });
|
|
3233
|
-
}
|
|
3234
|
-
}
|
|
3235
|
-
}
|
|
3236
|
-
}
|
|
3237
|
-
return consumers;
|
|
3238
|
-
}
|
|
3239
|
-
function similarDependencies(name, root) {
|
|
3240
|
-
const base = name.slice(name.lastIndexOf("/") + 1).toLowerCase();
|
|
3241
|
-
const found = new Set;
|
|
3242
|
-
for (const path of packageFiles(root, 0, []).sort()) {
|
|
3243
|
-
const manifest = readManifest(path);
|
|
3244
|
-
for (const kind of KINDS) {
|
|
3245
|
-
for (const [key, spec] of Object.entries(manifest?.[kind] ?? {})) {
|
|
3246
|
-
const target = typeof spec === "string" ? ALIAS.exec(spec)?.[1] : undefined;
|
|
3247
|
-
for (const candidate of [key, target]) {
|
|
3248
|
-
const last = candidate?.slice(candidate.lastIndexOf("/") + 1).toLowerCase();
|
|
3249
|
-
if (candidate !== undefined && last !== undefined && candidate !== name && last.length >= MIN_SIMILAR && base.length >= MIN_SIMILAR && (last.includes(base) || base.includes(last)))
|
|
3250
|
-
found.add(candidate);
|
|
3251
|
-
}
|
|
3252
|
-
}
|
|
3253
|
-
}
|
|
3254
|
-
}
|
|
3255
|
-
return [...found].toSorted().slice(0, 5);
|
|
3256
|
-
}
|
|
3257
|
-
function isLocal(consumer) {
|
|
3258
|
-
return consumer.alias === undefined && LOCAL_SPEC.test(consumer.spec);
|
|
3259
|
-
}
|
|
3260
|
-
function wantedVersion(consumer) {
|
|
3261
|
-
return consumer.alias === undefined ? consumer.spec : ALIAS.exec(consumer.spec)?.[2] ?? consumer.spec;
|
|
3262
|
-
}
|
|
3263
|
-
function addCommand(consumer, name, version) {
|
|
3264
|
-
if (consumer.alias !== undefined) {
|
|
3265
|
-
const prefix = RANGE_PREFIX.exec(wantedVersion(consumer))?.[0] ?? "";
|
|
3266
|
-
return ["bun", "add", ...KIND_FLAGS[consumer.kind], ...prefix === "" ? ["--exact"] : [], "--no-cache", `${consumer.alias}@npm:${name}@${prefix}${version}`];
|
|
3267
|
-
}
|
|
3268
|
-
return ["bun", "add", ...KIND_FLAGS[consumer.kind], "--exact", "--no-cache", `${name}@${version}`];
|
|
3269
|
-
}
|
|
3270
|
-
function registryDependencies(text) {
|
|
3271
|
-
let manifest;
|
|
3272
|
-
try {
|
|
3273
|
-
manifest = JSON.parse(text);
|
|
3274
|
-
} catch {
|
|
3275
|
-
return fail("the package.json is not valid JSON");
|
|
3276
|
-
}
|
|
3277
|
-
return REGISTRY_KINDS.flatMap((kind) => Object.entries(manifest?.[kind] ?? {}).flatMap(([name, spec]) => typeof spec === "string" && !LOCAL_SPEC.test(spec) ? [{ name, kind, spec }] : []));
|
|
3278
|
-
}
|
|
3279
|
-
var KINDS, MAX_DEPTH = 5, LOCAL_SPEC, ALIAS, MIN_SIMILAR = 3, KIND_FLAGS, RANGE_PREFIX, REGISTRY_KINDS;
|
|
3280
|
-
var init_consumers = __esm(() => {
|
|
3281
|
-
init_src();
|
|
3282
|
-
init_pin();
|
|
3283
|
-
KINDS = ["dependencies", "devDependencies", "optionalDependencies", "peerDependencies"];
|
|
3284
|
-
LOCAL_SPEC = /[:/]/;
|
|
3285
|
-
ALIAS = /^npm:(@[^@/]+\/[^@/]+|[^@/]+)@(.+)$/;
|
|
3286
|
-
KIND_FLAGS = { dependencies: [], devDependencies: ["--dev"], optionalDependencies: ["--optional"], peerDependencies: ["--peer"] };
|
|
3287
|
-
RANGE_PREFIX = /^[~^]/;
|
|
3288
|
-
REGISTRY_KINDS = KINDS.filter((kind) => kind !== "peerDependencies");
|
|
3289
|
-
});
|
|
3290
|
-
|
|
3291
|
-
// src/commands/check.ts
|
|
3292
|
-
var exports_check = {};
|
|
3293
|
-
__export(exports_check, {
|
|
3294
|
-
check: () => check,
|
|
3295
|
-
checkPackage: () => checkPackage
|
|
3296
|
-
});
|
|
3297
|
-
async function checkPackage(text, context) {
|
|
3298
|
-
const spec = parseSpec(text);
|
|
3299
|
-
const registry = registryFor(spec.name, context.configs);
|
|
3300
|
-
const packument = await fetchPackument(spec.name, registry, context.fetcher);
|
|
3301
|
-
const downloads = packument !== undefined && isPublic(registry) ? await fetchDownloads(spec.name, context.fetcher) : undefined;
|
|
3302
|
-
const input = { spec, packument, downloads, registry: new URL(registry.url).host, now: context.now, minAgeDays: context.minAgeDays, licenses: context.settings?.licenses, trusted: context.settings?.trusted };
|
|
3303
|
-
const report = analyze(input);
|
|
3304
|
-
const blockSeverity = context.settings?.blockSeverity ?? DEFAULT_BLOCK_SEVERITY;
|
|
3305
|
-
if (report.version === undefined)
|
|
3306
|
-
return report;
|
|
3307
|
-
const safe = report.safe?.version;
|
|
3308
|
-
const { found, unavailable, isUnsupported } = await fetchAdvisories({ [spec.name]: safe === undefined || safe === report.version ? [report.version] : [report.version, safe] }, registry, context.fetcher);
|
|
3309
|
-
if (unavailable !== undefined && isUnsupported !== true)
|
|
3310
|
-
return unreachable(unavailable);
|
|
3311
|
-
const checked = analyze({ ...input, blockSeverity, advisories: advisoriesFor(found[spec.name], report.version), safeAdvisories: safe === undefined ? [] : filterAdvisories(advisoriesFor(found[spec.name], safe), blockSeverity) });
|
|
3312
|
-
if (unavailable !== undefined)
|
|
3313
|
-
checked.warnings.push(`${unavailable}, so its known advisories are not checked`);
|
|
3314
|
-
return checked;
|
|
3315
|
-
}
|
|
3316
|
-
function when(release, now) {
|
|
3317
|
-
return release?.published === undefined ? "" : `, published ${formatAge(release.published, now)} (${release.published.slice(0, 10)})`;
|
|
3318
|
-
}
|
|
3319
|
-
function render(report, now = Date.now(), stream = process.stdout, env = process.env) {
|
|
3320
|
-
const id = role("id", stream, env);
|
|
3321
|
-
const warn = role("warn", stream, env);
|
|
3322
|
-
if (!report.exists)
|
|
3323
|
-
return [id(report.name), ...report.warnings.map((warning) => ` ${warn("warning:")} ${warning}`)].join(`
|
|
3324
|
-
`);
|
|
3325
|
-
const asked = report.requested === undefined ? "" : ` (asked for ${report.requested})`;
|
|
3326
|
-
const rows = [
|
|
3327
|
-
["version", report.version === undefined ? `none${asked}` : `${report.version}${asked}${when(report, now)}`],
|
|
3328
|
-
["latest", report.latest === undefined ? "-" : `${report.latest.version}${when(report.latest, now)}`],
|
|
3329
|
-
["safe", report.safe === undefined ? "-" : `${report.safe.version}${when(report.safe, now)}`],
|
|
3330
|
-
["downloads", report.downloads === undefined ? "-" : `${report.downloads.toLocaleString("en-US")} last week`],
|
|
3331
|
-
["license", report.license ?? "-"],
|
|
3332
|
-
["repository", report.repository ?? "-"],
|
|
3333
|
-
...Object.entries(report.installScripts).map(([name, command]) => [name, command])
|
|
3334
|
-
];
|
|
3335
|
-
return [
|
|
3336
|
-
`${id(report.name)}${report.description === undefined ? "" : `: ${report.description}`}`,
|
|
3337
|
-
table(rows.map(([key, value]) => [` ${key}`, value ?? ""])),
|
|
3338
|
-
...report.warnings.map((warning) => ` ${warn("warning:")} ${warning}`)
|
|
3339
|
-
].join(`
|
|
3340
|
-
`);
|
|
3341
|
-
}
|
|
3342
|
-
async function wanted(positionals, from) {
|
|
3343
|
-
const names = positionals.filter((each) => each !== "-");
|
|
3344
|
-
const fromFile = from === undefined ? [] : registryDependencies(await readInput(from)).map(({ name, spec }) => `${name}@${spec}`);
|
|
3345
|
-
const fromStdin = positionals.includes("-") || names.length === 0 && fromFile.length === 0 && isStdinPiped() ? (await readInput("-")).split(WORDS).filter((each) => each !== "") : [];
|
|
3346
|
-
return [...new Set([...names, ...fromFile, ...fromStdin])];
|
|
3347
|
-
}
|
|
3348
|
-
async function check(args) {
|
|
3349
|
-
const parsed = parse(args, usage2, options, { exits: EXITS });
|
|
3350
|
-
const { values } = parsed;
|
|
3351
|
-
const positionals = await wanted(parsed.positionals, values.from);
|
|
3352
|
-
if (positionals.length === 0)
|
|
3353
|
-
fail(values.from === undefined ? `a package name is needed
|
|
3354
|
-
|
|
3355
|
-
${usage2}` : `${values.from} has no registry dependency to check`);
|
|
3356
|
-
const settings = await loadSettings();
|
|
3357
|
-
const context = { configs: await loadConfigs(), settings, minAgeDays: wholeNumber(values["min-age"], "min-age", settings.minAge ?? DEFAULT_MIN_AGE_DAYS, 0) };
|
|
3358
|
-
const reports = await Promise.all(positionals.map(async (text) => checkPackage(text, context)));
|
|
3359
|
-
if (values.json === true)
|
|
3360
|
-
printJson(reports.length === 1 ? reports[0] : reports);
|
|
3361
|
-
else
|
|
3362
|
-
console.log(reports.map((report) => render(report)).join(`
|
|
3363
|
-
|
|
3364
|
-
`));
|
|
3365
|
-
return reports.some((report) => report.blocked) ? 1 : 0;
|
|
3366
|
-
}
|
|
3367
|
-
var usage2 = `pkg [check] <name>[@version]... | --from <package.json> | -
|
|
3368
|
-
|
|
3369
|
-
Checks npm packages before they are added: the name exists, the newest version at least two weeks old (any age for the \`trusted\` setting's names, \`@kaynooo/*\` and \`@kayjs/*\` by default), downloads, licence, install scripts, a near miss of a popular name, and a changed publisher or lost provenance attestation.
|
|
3370
|
-
Names come from the arguments, from a package.json with --from, or from stdin.
|
|
3371
|
-
A \`.pkgrc.json\` with \`licenses\` refuses a licence outside the list, and \`blockSeverity\` a version with an advisory at that level or above.`, EXITS, options, WORDS;
|
|
3372
|
-
var init_check = __esm(() => {
|
|
3373
|
-
init_src();
|
|
3374
|
-
init_advisories();
|
|
3375
|
-
init_analyze();
|
|
3376
|
-
init_config2();
|
|
3377
|
-
init_consumers();
|
|
3378
|
-
init_registry();
|
|
3379
|
-
EXITS = [[0, "every package passes"], [1, "one is blocked: missing, the version asked for is under the minimum age or has no date, its licence is outside the allowlist or an advisory reaches the threshold"], [2, "it could not check (the registry unreachable, slow or answering badly, a broken .pkgrc.json, bunfig.toml or .npmrc) or a usage error"]];
|
|
3380
|
-
options = {
|
|
3381
|
-
json: jsonOption(),
|
|
3382
|
-
"min-age": { type: "string", description: `days a version must be old (${DEFAULT_MIN_AGE_DAYS}, or the minAge setting)` },
|
|
3383
|
-
from: { type: "string", description: "check the dependencies of this package.json" }
|
|
3384
|
-
};
|
|
3385
|
-
WORDS = /\s+/;
|
|
3386
|
-
});
|
|
3387
|
-
|
|
3388
|
-
// src/lockfile.ts
|
|
3389
|
-
function split(resolution) {
|
|
3390
|
-
const at = resolution.search(VERSION_SEPARATOR2);
|
|
3391
|
-
if (at === -1)
|
|
3392
|
-
return;
|
|
3393
|
-
const target = resolution.slice(at + 1);
|
|
3394
|
-
if (target.startsWith(NPM_ALIAS))
|
|
3395
|
-
return split(target.slice(NPM_ALIAS.length));
|
|
3396
|
-
return NOT_REGISTRY.test(target) ? undefined : { name: resolution.slice(0, at), version: target };
|
|
3397
|
-
}
|
|
3398
|
-
function parseBunLock(text) {
|
|
3399
|
-
const lock = Bun.JSONC.parse(text);
|
|
3400
|
-
const seen = new Map;
|
|
3401
|
-
for (const entry of Object.values(lock?.packages ?? {})) {
|
|
3402
|
-
const resolution = entry[0];
|
|
3403
|
-
if (typeof resolution !== "string")
|
|
3404
|
-
continue;
|
|
3405
|
-
const locked = split(resolution);
|
|
3406
|
-
if (locked !== undefined)
|
|
3407
|
-
seen.set(`${locked.name}@${locked.version}`, locked);
|
|
3408
|
-
}
|
|
3409
|
-
return [...seen.values()].sort((a, b) => a.name.localeCompare(b.name) || Bun.semver.order(a.version, b.version));
|
|
3410
|
-
}
|
|
3411
|
-
function parentKey(key) {
|
|
3412
|
-
const parts = key.split("/");
|
|
3413
|
-
const drop = parts.length > 1 && parts.at(-2)?.startsWith("@") ? 2 : 1;
|
|
3414
|
-
return parts.length > drop ? parts.slice(0, -drop).join("/") : undefined;
|
|
3415
|
-
}
|
|
3416
|
-
function productionPackages(text) {
|
|
3417
|
-
const lock = Bun.JSONC.parse(text);
|
|
3418
|
-
const packages = lock?.packages ?? {};
|
|
3419
|
-
const reached = new Set;
|
|
3420
|
-
const visited = new Set;
|
|
3421
|
-
const pending = [];
|
|
3422
|
-
for (const workspace of Object.values(lock?.workspaces ?? {})) {
|
|
3423
|
-
for (const name of Object.keys({ ...workspace.dependencies, ...workspace.optionalDependencies }))
|
|
3424
|
-
pending.push({ name, from: undefined });
|
|
3425
|
-
}
|
|
3426
|
-
while (pending.length > 0) {
|
|
3427
|
-
const { name, from } = pending.pop();
|
|
3428
|
-
let scope = from;
|
|
3429
|
-
let key = scope === undefined ? name : `${scope}/${name}`;
|
|
3430
|
-
while (!(key in packages) && scope !== undefined) {
|
|
3431
|
-
scope = parentKey(scope);
|
|
3432
|
-
key = scope === undefined ? name : `${scope}/${name}`;
|
|
3433
|
-
}
|
|
3434
|
-
const entry = packages[key];
|
|
3435
|
-
if (entry === undefined || visited.has(key))
|
|
3436
|
-
continue;
|
|
3437
|
-
visited.add(key);
|
|
3438
|
-
const locked = typeof entry[0] === "string" ? split(entry[0]) : undefined;
|
|
3439
|
-
if (locked !== undefined)
|
|
3440
|
-
reached.add(`${locked.name}@${locked.version}`);
|
|
3441
|
-
const info = entry[2] ?? {};
|
|
3442
|
-
for (const dependency of Object.keys({ ...info.dependencies, ...info.optionalDependencies }))
|
|
3443
|
-
pending.push({ name: dependency, from: key });
|
|
3444
|
-
}
|
|
3445
|
-
return reached;
|
|
3446
|
-
}
|
|
3447
|
-
var NOT_REGISTRY, VERSION_SEPARATOR2, NPM_ALIAS = "npm:";
|
|
3448
|
-
var init_lockfile = __esm(() => {
|
|
3449
|
-
NOT_REGISTRY = /^(?:workspace|link|file|github|git|http|https):|^[\w.-]+\/[\w.-]+$/;
|
|
3450
|
-
VERSION_SEPARATOR2 = /(?<=.)@/;
|
|
3451
|
-
});
|
|
3452
|
-
|
|
3453
|
-
// src/commands/audit.ts
|
|
3454
|
-
var exports_audit = {};
|
|
3455
|
-
__export(exports_audit, {
|
|
3456
|
-
audit: () => audit
|
|
3457
|
-
});
|
|
3458
|
-
import { join as join9, resolve as resolve6 } from "path";
|
|
3459
|
-
import process21 from "process";
|
|
3460
|
-
function hasFinding(audited) {
|
|
3461
|
-
return audited.blocked || audited.warnings.length > 0 || audited.advisories.length > 0;
|
|
3462
|
-
}
|
|
3463
|
-
async function auditPackages(packages, context) {
|
|
3464
|
-
const packuments = new Map;
|
|
3465
|
-
const lookup = async (name, registry) => {
|
|
3466
|
-
const key = `${registry.url}|${name}`;
|
|
3467
|
-
if (!packuments.has(key))
|
|
3468
|
-
packuments.set(key, fetchPackument(name, registry, context.fetcher));
|
|
3469
|
-
return packuments.get(key);
|
|
3470
|
-
};
|
|
3471
|
-
const looked = await pool(packages, context.settings.concurrency ?? BATCH, async ({ name, version }) => {
|
|
3472
|
-
const registry = registryFor(name, context.configs);
|
|
3473
|
-
const input = { spec: { name, request: version }, packument: await lookup(name, registry), registry: new URL(registry.url).host, now: context.now, minAgeDays: context.minAgeDays, licenses: context.settings.licenses, trusted: context.settings.trusted };
|
|
3474
|
-
return { name, version, registry, input, safe: analyze(input).safe?.version };
|
|
3475
|
-
}, (done, total) => context.onProgress?.({ step: "looking up", done, total, unit: "packages" }));
|
|
3476
|
-
context.onProgress?.({ step: "reading the advisories" });
|
|
3477
|
-
const registries = new Map;
|
|
3478
|
-
for (const { name, version, registry, safe } of looked) {
|
|
3479
|
-
const group = registries.get(registry.url) ?? { registry, versions: {} };
|
|
3480
|
-
group.versions[name] = [...group.versions[name] ?? [], version, ...safe === undefined || safe === version ? [] : [safe]];
|
|
3481
|
-
registries.set(registry.url, group);
|
|
3482
|
-
}
|
|
3483
|
-
const advisories = {};
|
|
3484
|
-
const unavailable = [];
|
|
3485
|
-
for (const { registry, versions } of registries.values()) {
|
|
3486
|
-
const fetched = await fetchAdvisories(versions, registry, context.fetcher);
|
|
3487
|
-
Object.assign(advisories, fetched.found);
|
|
3488
|
-
if (fetched.unavailable !== undefined)
|
|
3489
|
-
unavailable.push(fetched.unavailable);
|
|
3490
|
-
}
|
|
3491
|
-
const blockSeverity = context.settings.blockSeverity ?? DEFAULT_BLOCK_SEVERITY;
|
|
3492
|
-
const audited = looked.map(({ name, version, input, safe }) => {
|
|
3493
|
-
const found = filterAdvisories(advisoriesFor(advisories[name], version), context.level, context.ignore);
|
|
3494
|
-
const safeAdvisories = safe === undefined ? [] : filterAdvisories(advisoriesFor(advisories[name], safe), blockSeverity, context.ignore);
|
|
3495
|
-
const report = analyze({ ...input, advisories: advisoriesFor(advisories[name], version), safeAdvisories });
|
|
3496
|
-
return { name, version, license: report.license, blocked: report.blocked || found.length > 0, warnings: report.warnings, advisories: found };
|
|
3497
|
-
});
|
|
3498
|
-
return { audited, unavailable };
|
|
3499
|
-
}
|
|
3500
|
-
function renderAudit(findings, total, stream = process21.stdout, env = process21.env) {
|
|
3501
|
-
const id = role("id", stream, env);
|
|
3502
|
-
const label = role("label", stream, env);
|
|
3503
|
-
const warning = role("warn", stream, env);
|
|
3504
|
-
const problem = role("problem", stream, env);
|
|
3505
|
-
const blocking = findings.filter((each) => each.blocked).length;
|
|
3506
|
-
const blocks = findings.map(({ name, version, warnings, advisories }) => [
|
|
3507
|
-
id(`${name}@${version}`),
|
|
3508
|
-
...warnings.map((each) => ` ${warning("warning:")} ${each}`),
|
|
3509
|
-
...advisories.map((each) => ` ${label(String(each.ghsa ?? each.id))} ${(HIGH_SEVERITIES.has(each.severity) ? problem : warning)(each.severity)}: ${each.title}${each.fixed === undefined ? "" : ` ${label(`(fixed in ${each.fixed})`)}`}`)
|
|
3510
|
-
].join(`
|
|
3511
|
-
`));
|
|
3512
|
-
return [...blocks, `${findings.length} of ${total} packages with a finding, ${(blocking === 0 ? label : problem)(`${blocking} blocking`)}`].join(`
|
|
3513
|
-
|
|
3514
|
-
`);
|
|
3515
|
-
}
|
|
3516
|
-
async function audit(args) {
|
|
3517
|
-
const { values, positionals: [asked] } = parse(args, usage3, options2, { positionals: ["[dir]"], exits: EXITS2 });
|
|
3518
|
-
const { level } = values;
|
|
3519
|
-
const dir = resolve6(asked ?? process21.cwd());
|
|
3520
|
-
const lock = Bun.file(join9(dir, "bun.lock"));
|
|
3521
|
-
if (!await lock.exists())
|
|
3522
|
-
fail(`no bun.lock in ${dir}`);
|
|
3523
|
-
const text = await lock.text();
|
|
3524
|
-
const production = values.prod === true ? productionPackages(text) : undefined;
|
|
3525
|
-
const packages = parseBunLock(text).filter(({ name, version }) => production?.has(`${name}@${version}`) ?? true);
|
|
3526
|
-
const settings = await loadSettings(dir);
|
|
3527
|
-
const context = {
|
|
3528
|
-
configs: await loadConfigs(dir),
|
|
3529
|
-
settings,
|
|
3530
|
-
minAgeDays: wholeNumber(values["min-age"], "min-age", settings.minAge ?? DEFAULT_MIN_AGE_DAYS, 0),
|
|
3531
|
-
level,
|
|
3532
|
-
ignore: values.ignore ?? []
|
|
3533
|
-
};
|
|
3534
|
-
const progress = progressLine();
|
|
3535
|
-
let result;
|
|
3536
|
-
try {
|
|
3537
|
-
result = await auditPackages(packages, { ...context, onProgress: progress.update });
|
|
3538
|
-
} finally {
|
|
3539
|
-
progress.stop();
|
|
3540
|
-
}
|
|
3541
|
-
const { audited, unavailable } = result;
|
|
3542
|
-
const findings = audited.filter(hasFinding);
|
|
3543
|
-
if (values.json === true)
|
|
3544
|
-
printJson(findings);
|
|
3545
|
-
else
|
|
3546
|
-
console.log(renderAudit(findings, packages.length));
|
|
3547
|
-
for (const reason of unavailable)
|
|
3548
|
-
warn(`${reason}, so its advisories are not checked`);
|
|
3549
|
-
if (findings.some((each) => each.blocked))
|
|
3550
|
-
return 1;
|
|
3551
|
-
return unavailable.length > 0 ? 2 : 0;
|
|
3552
|
-
}
|
|
3553
|
-
var usage3 = `pkg audit [dir]
|
|
3554
|
-
|
|
3555
|
-
Reads the bun.lock of the folder and runs on every registry package it pins the checks \`pkg check\` runs before an add, and lists the known advisories of each version, with the GHSA, the severity and the fixed version.
|
|
3556
|
-
Reach for it to vet one repository in depth; \`audit\` sweeps many repositories for advisories only.`, EXITS2, options2, BATCH = 8, HIGH_SEVERITIES;
|
|
3557
|
-
var init_audit = __esm(() => {
|
|
3558
|
-
init_src();
|
|
3559
|
-
init_progress();
|
|
3560
|
-
init_advisories();
|
|
3561
|
-
init_analyze();
|
|
3562
|
-
init_config2();
|
|
3563
|
-
init_lockfile();
|
|
3564
|
-
init_registry();
|
|
3565
|
-
EXITS2 = [[0, "nothing blocks"], [1, "a package is missing, too fresh or outside the licence allowlist, or an advisory reaches --level"], [2, "the registry could not be reached or answered badly (a warning says which, and nothing is reported as clean), a usage error or no bun.lock"]];
|
|
3566
|
-
options2 = {
|
|
3567
|
-
json: jsonOption("[{name, version, license, blocked, warnings, advisories}] for the packages with a finding"),
|
|
3568
|
-
"min-age": { type: "string", description: `days a version must be old (${DEFAULT_MIN_AGE_DAYS}, or the minAge setting)` },
|
|
3569
|
-
level: { type: "string", choices: SEVERITIES, default: "moderate", description: "lowest advisory severity listed and failing (moderate)" },
|
|
3570
|
-
prod: { type: "boolean", description: "only the packages a production dependency or an optional one of a workspace reaches" },
|
|
3571
|
-
ignore: { type: "string", multiple: true, description: "an advisory skipped by GHSA or numeric id, repeatable" }
|
|
3572
|
-
};
|
|
3573
|
-
HIGH_SEVERITIES = new Set(["high", "critical"]);
|
|
3574
|
-
});
|
|
3575
|
-
|
|
3576
|
-
// src/commands/outdated.ts
|
|
3577
|
-
var exports_outdated = {};
|
|
3578
|
-
__export(exports_outdated, {
|
|
3579
|
-
outdatedCommand: () => outdatedCommand
|
|
3580
|
-
});
|
|
3581
|
-
import { existsSync as existsSync5 } from "fs";
|
|
3582
|
-
import { join as join10, resolve as resolve7 } from "path";
|
|
3583
|
-
function currentOf(name, spec, locked) {
|
|
3584
|
-
const pinned = locked.filter((each) => each.name === name && Bun.semver.satisfies(each.version, spec)).map((each) => each.version).sort(Bun.semver.order).at(-1);
|
|
3585
|
-
const written = FIRST_VERSION.exec(spec)?.[0];
|
|
3586
|
-
return pinned ?? (written === undefined ? undefined : [...written.split("."), "0", "0"].slice(0, 3).join("."));
|
|
3587
|
-
}
|
|
3588
|
-
function changeOf(current, next) {
|
|
3589
|
-
const [from, to] = [current, next].map((version) => version.split(DOT).map(Number));
|
|
3590
|
-
if (from?.[0] !== to?.[0])
|
|
3591
|
-
return "major";
|
|
3592
|
-
return from?.[1] === to?.[1] ? "patch" : "minor";
|
|
3593
|
-
}
|
|
3594
|
-
async function outdated(manifest, context) {
|
|
3595
|
-
const configs = await loadConfigs();
|
|
3596
|
-
const dependencies = registryDependencies(manifest);
|
|
3597
|
-
const looked = await pool(dependencies, context.concurrency ?? BATCH2, async ({ name, kind, spec }) => {
|
|
3598
|
-
const registry = registryFor(name, configs);
|
|
3599
|
-
const packument = await fetchPackument(name, registry, context.fetcher);
|
|
3600
|
-
if (packument === undefined) {
|
|
3601
|
-
warn(`${name} is not on ${new URL(registry.url).host}`);
|
|
3602
|
-
return;
|
|
3603
|
-
}
|
|
3604
|
-
const { safe, latest } = analyze({ spec: { name }, packument, registry: new URL(registry.url).host, now: context.now, minAgeDays: context.minAgeDays, trusted: context.trusted });
|
|
3605
|
-
const current = currentOf(name, spec, context.locked);
|
|
3606
|
-
if (safe === undefined || current === undefined || Bun.semver.order(safe.version, current) <= 0)
|
|
3607
|
-
return;
|
|
3608
|
-
const row = { name, kind, spec, current, safe: safe.version, change: changeOf(current, safe.version), published: safe.published };
|
|
3609
|
-
return latest !== undefined && latest.version !== safe.version && Bun.semver.order(latest.version, safe.version) > 0 ? { ...row, latest: latest.version } : row;
|
|
3610
|
-
});
|
|
3611
|
-
return looked.filter((row) => row !== undefined).sort((a, b) => a.name.localeCompare(b.name));
|
|
3612
|
-
}
|
|
3613
|
-
async function outdatedCommand(args) {
|
|
3614
|
-
const { values, positionals: [dir = "."] } = parse(args, usage4, options3, { positionals: ["[dir]"], exits: EXITS3 });
|
|
3615
|
-
const folder = resolve7(dir);
|
|
3616
|
-
const manifest = Bun.file(join10(folder, "package.json"));
|
|
3617
|
-
if (!await manifest.exists())
|
|
3618
|
-
fail(`no package.json in ${folder}`);
|
|
3619
|
-
const lockPath = join10(folder, "bun.lock");
|
|
3620
|
-
const locked = existsSync5(lockPath) ? parseBunLock(await Bun.file(lockPath).text()) : [];
|
|
3621
|
-
const settings = await loadSettings(folder);
|
|
3622
|
-
const rows = await outdated(await manifest.text(), { minAgeDays: wholeNumber(values["min-age"], "min-age", settings.minAge ?? DEFAULT_MIN_AGE_DAYS, 0), concurrency: settings.concurrency, locked, trusted: settings.trusted });
|
|
3623
|
-
const { shown, footer } = capped(rows, limitOf(values, OUTDATED_LIMIT));
|
|
3624
|
-
if (values.json === true)
|
|
3625
|
-
printJson(shown);
|
|
3626
|
-
else if (shown.length === 0)
|
|
3627
|
-
console.log(role("ok", process.stdout)("nothing outdated: every dependency is on its safe version"));
|
|
3628
|
-
else
|
|
3629
|
-
console.log([table([["PACKAGE", "KIND", "CURRENT", "SAFE", "CHANGE", "PUBLISHED", "LATEST"], ...shown.map((each) => [each.name, each.kind, each.current, each.safe, each.change, each.published === undefined ? "-" : formatAge(each.published), each.latest ?? ""])], { header: true }), ...footer === undefined ? [] : [footer]].join(`
|
|
3630
|
-
`));
|
|
3631
|
-
return 0;
|
|
3632
|
-
}
|
|
3633
|
-
var usage4 = `pkg outdated [dir]
|
|
3634
|
-
|
|
3635
|
-
Lists the dependencies of the package.json of the folder that have a newer version safe to take: the highest stable one at least --min-age days old (any age for a \`trusted\` name), the \`safe\` of \`pkg check\`.
|
|
3636
|
-
It reads only the registry's metadata, no advisories, and changes nothing: \`bun add --exact name@version\` adopts a row.`, EXITS3, OUTDATED_LIMIT = 50, BATCH2 = 8, FIRST_VERSION, DOT, options3;
|
|
3637
|
-
var init_outdated = __esm(() => {
|
|
3638
|
-
init_src();
|
|
3639
|
-
init_analyze();
|
|
3640
|
-
init_config2();
|
|
3641
|
-
init_consumers();
|
|
3642
|
-
init_lockfile();
|
|
3643
|
-
init_registry();
|
|
3644
|
-
EXITS3 = [[0, "it listed what is outdated, nothing included"], [2, "the registry could not be reached or answered badly, no package.json, or a usage error"]];
|
|
3645
|
-
FIRST_VERSION = /\d+(?:\.\d+){0,2}(?:-[\w.-]+)?/;
|
|
3646
|
-
DOT = /[.-]/;
|
|
3647
|
-
options3 = {
|
|
3648
|
-
"min-age": { type: "string", description: `days a version must be old (${DEFAULT_MIN_AGE_DAYS}, or the minAge setting)` },
|
|
3649
|
-
...limitOptions(OUTDATED_LIMIT),
|
|
3650
|
-
json: jsonOption("[{name, kind, spec, current, safe, change, published, latest?}]")
|
|
3651
|
-
};
|
|
3652
|
-
});
|
|
3653
|
-
|
|
3654
|
-
// ../kit/src/answers.ts
|
|
3655
|
-
var init_answers = __esm(() => {
|
|
3656
|
-
init_folders();
|
|
3657
|
-
});
|
|
3658
|
-
|
|
3659
|
-
// ../kit/src/job.ts
|
|
3660
|
-
import process22 from "process";
|
|
3661
|
-
function stopJob() {
|
|
3662
|
-
process22.kill(0, "SIGTSTP");
|
|
3663
|
-
}
|
|
3664
|
-
var init_job = () => {};
|
|
3665
|
-
|
|
3666
|
-
// ../kit/src/picker/line.ts
|
|
3667
|
-
function isEditKey(key) {
|
|
3668
|
-
return EDIT_KEYS.has(key);
|
|
3669
|
-
}
|
|
3670
|
-
function endsKills(key) {
|
|
3671
|
-
return typeof key !== "object" && !isEditKey(key);
|
|
3672
|
-
}
|
|
3673
|
-
function isWord(char) {
|
|
3674
|
-
return char !== undefined && WORD_CHARACTER.test(char);
|
|
3675
|
-
}
|
|
3676
|
-
function wordStart(chars, from) {
|
|
3677
|
-
let at = from;
|
|
3678
|
-
while (at > 0 && !isWord(chars[at - 1]))
|
|
3679
|
-
at--;
|
|
3680
|
-
while (at > 0 && isWord(chars[at - 1]))
|
|
3681
|
-
at--;
|
|
3682
|
-
return at;
|
|
3683
|
-
}
|
|
3684
|
-
function wordEnd(chars, from) {
|
|
3685
|
-
let at = from;
|
|
3686
|
-
while (at < chars.length && !isWord(chars[at]))
|
|
3687
|
-
at++;
|
|
3688
|
-
while (at < chars.length && isWord(chars[at]))
|
|
3689
|
-
at++;
|
|
3690
|
-
return at;
|
|
3691
|
-
}
|
|
3692
|
-
function spacedStart(chars, from) {
|
|
3693
|
-
let at = from;
|
|
3694
|
-
while (at > 0 && SPACE.test(chars[at - 1] ?? ""))
|
|
3695
|
-
at--;
|
|
3696
|
-
while (at > 0 && !SPACE.test(chars[at - 1] ?? ""))
|
|
3697
|
-
at--;
|
|
3698
|
-
return at;
|
|
3699
|
-
}
|
|
3700
|
-
function cut(chars, from, to) {
|
|
3701
|
-
return { text: [...chars.slice(0, from), ...chars.slice(to)].join(""), caret: from };
|
|
3702
|
-
}
|
|
3703
|
-
function insert(chars, at, text) {
|
|
3704
|
-
const typed = [...text];
|
|
3705
|
-
return { text: [...chars.slice(0, at), ...typed, ...chars.slice(at)].join(""), caret: at + typed.length };
|
|
3706
|
-
}
|
|
3707
|
-
function editLine(line, key) {
|
|
3708
|
-
const { killed = "", chained = false } = line;
|
|
3709
|
-
const chars = [...line.text];
|
|
3710
|
-
const at = Math.min(Math.max(line.caret, 0), chars.length);
|
|
3711
|
-
const edited = edit(chars, at, key, killed);
|
|
3712
|
-
if (typeof key === "object" || !BACKWARD_KILLS.has(key) && !FORWARD_KILLS.has(key))
|
|
3713
|
-
return line.killed === undefined ? edited : { ...edited, killed };
|
|
3714
|
-
const taken = chars.slice(edited.caret, edited.caret + chars.length - [...edited.text].length).join("");
|
|
3715
|
-
if (taken === "")
|
|
3716
|
-
return { ...edited, killed, chained };
|
|
3717
|
-
if (!chained)
|
|
3718
|
-
return { ...edited, killed: taken, chained: true };
|
|
3719
|
-
return { ...edited, killed: BACKWARD_KILLS.has(key) ? taken + killed : killed + taken, chained: true };
|
|
3720
|
-
}
|
|
3721
|
-
function edit(chars, at, key, killed) {
|
|
3722
|
-
const text = chars.join("");
|
|
3723
|
-
if (typeof key === "object")
|
|
3724
|
-
return insert(chars, at, key.text);
|
|
3725
|
-
switch (key) {
|
|
3726
|
-
case "left":
|
|
3727
|
-
return { text, caret: Math.max(at - 1, 0) };
|
|
3728
|
-
case "right":
|
|
3729
|
-
return { text, caret: Math.min(at + 1, chars.length) };
|
|
3730
|
-
case "wordleft":
|
|
3731
|
-
return { text, caret: wordStart(chars, at) };
|
|
3732
|
-
case "wordright":
|
|
3733
|
-
return { text, caret: wordEnd(chars, at) };
|
|
3734
|
-
case "linestart":
|
|
3735
|
-
return { text, caret: 0 };
|
|
3736
|
-
case "lineend":
|
|
3737
|
-
return { text, caret: chars.length };
|
|
3738
|
-
case "erase":
|
|
3739
|
-
return cut(chars, Math.max(at - 1, 0), at);
|
|
3740
|
-
case "delete":
|
|
3741
|
-
return cut(chars, at, Math.min(at + 1, chars.length));
|
|
3742
|
-
case "word":
|
|
3743
|
-
return cut(chars, spacedStart(chars, at), at);
|
|
3744
|
-
case "killword":
|
|
3745
|
-
return cut(chars, wordStart(chars, at), at);
|
|
3746
|
-
case "killnext":
|
|
3747
|
-
return cut(chars, at, wordEnd(chars, at));
|
|
3748
|
-
case "clear":
|
|
3749
|
-
return cut(chars, 0, at);
|
|
3750
|
-
case "killend":
|
|
3751
|
-
return cut(chars, at, chars.length);
|
|
3752
|
-
case "yank":
|
|
3753
|
-
return insert(chars, at, killed);
|
|
3754
|
-
}
|
|
3755
|
-
}
|
|
3756
|
-
function visible({ text, caret }, room) {
|
|
3757
|
-
const chars = [...text];
|
|
3758
|
-
const at = Math.min(Math.max(caret, 0), chars.length);
|
|
3759
|
-
const cells = at === chars.length ? [...chars, " "] : chars;
|
|
3760
|
-
const widths = cells.map((char) => Bun.stringWidth(char));
|
|
3761
|
-
const width = (from, to) => widths.slice(from, to).reduce((sum, size) => sum + size, 0);
|
|
3762
|
-
const fits = (from, to) => (from > 0 ? 1 : 0) + width(from, to) + (to < cells.length ? 1 : 0) <= room;
|
|
3763
|
-
let start = at;
|
|
3764
|
-
let end = at + 1;
|
|
3765
|
-
while (start > 0 && fits(start - 1, end))
|
|
3766
|
-
start--;
|
|
3767
|
-
while (end < cells.length && fits(start, end + 1))
|
|
3768
|
-
end++;
|
|
3769
|
-
const left = start > 0 ? "\u2026" : "";
|
|
3770
|
-
const right = end < cells.length ? "\u2026" : "";
|
|
3771
|
-
return { before: left + chars.slice(start, at).join(""), at: chars[at], after: chars.slice(at + 1, end).join("") + right, column: left.length + width(start, at) };
|
|
3772
|
-
}
|
|
3773
|
-
var EDIT_KEYS, BACKWARD_KILLS, FORWARD_KILLS, WORD_CHARACTER, SPACE;
|
|
3774
|
-
var init_line = __esm(() => {
|
|
3775
|
-
EDIT_KEYS = new Set(["left", "right", "wordleft", "wordright", "linestart", "lineend", "erase", "delete", "word", "killword", "killnext", "clear", "killend", "yank"]);
|
|
3776
|
-
BACKWARD_KILLS = new Set(["word", "killword", "clear"]);
|
|
3777
|
-
FORWARD_KILLS = new Set(["killnext", "killend"]);
|
|
3778
|
-
WORD_CHARACTER = /[\p{L}\p{N}_]/u;
|
|
3779
|
-
SPACE = /\s/;
|
|
3780
|
-
});
|
|
3781
|
-
|
|
3782
|
-
// ../kit/src/picker/score.ts
|
|
3783
|
-
var BOUNDARY_AFTER, NONE;
|
|
3784
|
-
var init_score = __esm(() => {
|
|
3785
|
-
BOUNDARY_AFTER = new Set([" ", "/", "-", "_", ".", ":", "\\", "(", "[", ",", "\t"]);
|
|
3786
|
-
NONE = Number.NEGATIVE_INFINITY;
|
|
3787
|
-
});
|
|
3788
|
-
|
|
3789
|
-
// ../kit/src/picker/state.ts
|
|
3790
|
-
function repeat(value, count) {
|
|
3791
|
-
return Array.from({ length: count }).fill(value);
|
|
3792
|
-
}
|
|
3793
|
-
function parseKeys(input, paste = { active: false }, ctrls = []) {
|
|
3794
|
-
const codes = new Map(ctrls.map((name) => [String.fromCharCode(name.codePointAt(name.length - 1) - 96), name]));
|
|
3795
|
-
return (input.match(KEY_SEQUENCES) ?? []).flatMap((sequence) => {
|
|
3796
|
-
const wheel = MOUSE.exec(sequence)?.[1];
|
|
3797
|
-
if (wheel !== undefined)
|
|
3798
|
-
return repeat(wheel === "64" ? "up" : "down", wheel === "64" || wheel === "65" ? WHEEL_LINES : 0);
|
|
3799
|
-
const named = codes.get(sequence);
|
|
3800
|
-
const key = named === undefined ? KEYS[sequence] : { ctrl: named };
|
|
3801
|
-
if (sequence === PASTE_START || sequence === PASTE_END) {
|
|
3802
|
-
paste.active = sequence === PASTE_START;
|
|
3803
|
-
return [];
|
|
3804
|
-
}
|
|
3805
|
-
if (paste.active && (sequence === "\r" || sequence === `
|
|
3806
|
-
`))
|
|
3807
|
-
return [];
|
|
3808
|
-
if (key !== undefined)
|
|
3809
|
-
return [key];
|
|
3810
|
-
return IS_CONTROL.test(sequence) || sequence.startsWith("\x1B") ? [] : [{ text: sequence }];
|
|
3811
|
-
});
|
|
3812
|
-
}
|
|
3813
|
-
var IS_CONTROL, PASTE_START = "\x1B[200~", PASTE_END = "\x1B[201~", KEY_SEQUENCES, MOUSE, WHEEL_LINES = 3, KEYS;
|
|
3814
|
-
var init_state = __esm(() => {
|
|
3815
|
-
init_text2();
|
|
3816
|
-
init_line();
|
|
3817
|
-
init_score();
|
|
3818
|
-
IS_CONTROL = /[\x00-\x1F\x7F-\x9F]/;
|
|
3819
|
-
KEY_SEQUENCES = /\x1B\[<[0-9;]*[A-Za-z]|\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
|
|
3820
|
-
MOUSE = /^\x1B\[<(\d+);\d+;\d+[a-z]$/i;
|
|
3821
|
-
KEYS = {
|
|
3822
|
-
"\x1B[A": "up",
|
|
3823
|
-
"\x1BOA": "up",
|
|
3824
|
-
"\x10": "up",
|
|
3825
|
-
"\x1B[B": "down",
|
|
3826
|
-
"\x1BOB": "down",
|
|
3827
|
-
"\x0E": "down",
|
|
3828
|
-
"\x1B[5~": "pageup",
|
|
3829
|
-
"\x1B[6~": "pagedown",
|
|
3830
|
-
"\x1B[H": "home",
|
|
3831
|
-
"\x1B[1~": "home",
|
|
3832
|
-
"\x1BOH": "home",
|
|
3833
|
-
"\x1B[F": "end",
|
|
3834
|
-
"\x1B[4~": "end",
|
|
3835
|
-
"\x1BOF": "end",
|
|
3836
|
-
"\r": "enter",
|
|
3837
|
-
"\n": "enter",
|
|
3838
|
-
"\x03": "cancel",
|
|
3839
|
-
"\x1B": "cancel",
|
|
3840
|
-
"\x1B[D": "left",
|
|
3841
|
-
"\x1BOD": "left",
|
|
3842
|
-
"\x1B[C": "right",
|
|
3843
|
-
"\x1BOC": "right",
|
|
3844
|
-
"\x1B[1;5D": "wordleft",
|
|
3845
|
-
"\x1B[1;3D": "wordleft",
|
|
3846
|
-
"\x1Bb": "wordleft",
|
|
3847
|
-
"\x1B[1;5C": "wordright",
|
|
3848
|
-
"\x1B[1;3C": "wordright",
|
|
3849
|
-
"\x1Bf": "wordright",
|
|
3850
|
-
"\x01": "linestart",
|
|
3851
|
-
"\x05": "lineend",
|
|
3852
|
-
"\x7F": "erase",
|
|
3853
|
-
"\x1B[3~": "delete",
|
|
3854
|
-
"\b": "killword",
|
|
3855
|
-
"\x1B\x7F": "killword",
|
|
3856
|
-
"\x1B[3;5~": "killnext",
|
|
3857
|
-
"\x1Bd": "killnext",
|
|
3858
|
-
"\x15": "clear",
|
|
3859
|
-
"\v": "killend",
|
|
3860
|
-
"\x17": "word",
|
|
3861
|
-
"\x19": "yank",
|
|
3862
|
-
"\x1A": "suspend",
|
|
3863
|
-
"\t": "tab",
|
|
3864
|
-
"\x1F": "help",
|
|
3865
|
-
"\x1BOP": "help",
|
|
3866
|
-
"\x1B[11~": "help"
|
|
3867
|
-
};
|
|
3868
|
-
});
|
|
3869
|
-
|
|
3870
|
-
// ../kit/src/redraw.ts
|
|
3871
|
-
function overwrite(lines, columns) {
|
|
3872
|
-
return lines.map((line) => textWidth(line) % columns === 0 ? `\x1B[2K${line}` : `${line}\x1B[K`).join(`
|
|
3873
|
-
`);
|
|
3874
|
-
}
|
|
3875
|
-
function rowsTaken(lines, columns) {
|
|
3876
|
-
return lines.reduce((rows, line) => rows + Math.max(1, Math.ceil(textWidth(line) / columns)), 0);
|
|
3877
|
-
}
|
|
3878
|
-
var SYNC_START = "\x1B[?2026h", SYNC_END = "\x1B[?2026l";
|
|
3879
|
-
var init_redraw = __esm(() => {
|
|
3880
|
-
init_format();
|
|
3881
|
-
});
|
|
3882
|
-
|
|
3883
|
-
// ../kit/src/prompt.ts
|
|
3884
|
-
import process23 from "process";
|
|
3885
|
-
function readKeys(input, paste = { active: false }) {
|
|
3886
|
-
return parseKeys(input, paste).filter((key) => typeof key === "object" ? "text" in key : PROMPT_KEYS.has(key) || isEditKey(key));
|
|
3887
|
-
}
|
|
3888
|
-
function roomAfter(question, columns) {
|
|
3889
|
-
return Math.max(columns - textWidth(`? ${question} `) % columns - 1, 1);
|
|
3890
|
-
}
|
|
3891
|
-
function withCaret(colors, line, room, dim = false) {
|
|
3892
|
-
const { before, at, after } = visible(line, room);
|
|
3893
|
-
const tone = dim ? colors.dim : (text) => text;
|
|
3894
|
-
return `${tone(before)}${at === undefined ? colors.dim("\u2588") : colors.inverse(at)}${tone(after)}`;
|
|
3895
|
-
}
|
|
3896
|
-
function flip(checked, value) {
|
|
3897
|
-
const next = new Set(checked);
|
|
3898
|
-
if (!next.delete(value))
|
|
3899
|
-
next.add(value);
|
|
3900
|
-
return next;
|
|
3901
|
-
}
|
|
3902
|
-
async function checklist(question, choices, { initial = new Set, min = 0, toggle = flip, ...settings } = {}) {
|
|
3903
|
-
const list = new List(choices, 0);
|
|
3904
|
-
let checked = initial;
|
|
3905
|
-
let invalid;
|
|
3906
|
-
const accepted = await ask(question, settings, (colors, state, rows) => state === "asking" ? [asking(colors, question, list.typed(colors, rows.columns, question), "type to filter, space toggles, enter accepts"), ...list.rows(colors, rows, (choice) => checked.has(choice.value) ? `${colors.cyan("\u25C9")} ` : `${colors.dim("\u25EF")} `), ...invalid === undefined ? [] : [` ${colors.red(invalid)}`]] : [answer(colors, question, state, choices.filter((choice) => checked.has(choice.value)).map((choice) => choice.label).join(", ") || "none")], (key) => {
|
|
3907
|
-
if (key === "cancel")
|
|
3908
|
-
return key;
|
|
3909
|
-
invalid = undefined;
|
|
3910
|
-
if (key === "enter") {
|
|
3911
|
-
invalid = checked.size < min ? `pick at least ${min}` : undefined;
|
|
3912
|
-
return invalid === undefined ? "enter" : undefined;
|
|
3913
|
-
}
|
|
3914
|
-
const current = list.current();
|
|
3915
|
-
if (typeof key === "object" && key.text === " ") {
|
|
3916
|
-
if (current !== undefined)
|
|
3917
|
-
checked = toggle(checked, current.value);
|
|
3918
|
-
return;
|
|
3919
|
-
}
|
|
3920
|
-
list.press(key);
|
|
3921
|
-
return;
|
|
3922
|
-
});
|
|
3923
|
-
return accepted ? checked : undefined;
|
|
3924
|
-
}
|
|
3925
|
-
async function confirm(question, { default: fallback, ...settings } = {}) {
|
|
3926
|
-
let answered = fallback;
|
|
3927
|
-
const choices = { true: "Y/n", false: "y/N", undefined: "y/n" }[String(fallback)];
|
|
3928
|
-
const accepted = await ask(question, settings, (colors, state) => [state === "asking" ? asking(colors, question, "", choices) : answer(colors, question, state, answered ? "yes" : "no")], (key) => {
|
|
3929
|
-
if (key === "cancel")
|
|
3930
|
-
return "cancel";
|
|
3931
|
-
if (key === "enter")
|
|
3932
|
-
return answered === undefined ? undefined : "enter";
|
|
3933
|
-
const letter = typeof key === "object" ? key.text.toLowerCase() : "";
|
|
3934
|
-
if (letter !== "y" && letter !== "n")
|
|
3935
|
-
return;
|
|
3936
|
-
answered = letter === "y";
|
|
3937
|
-
return "enter";
|
|
3938
|
-
});
|
|
3939
|
-
return accepted ? answered : undefined;
|
|
3940
|
-
}
|
|
3941
|
-
|
|
3942
|
-
class List {
|
|
3943
|
-
choices;
|
|
3944
|
-
line = { text: "", caret: 0 };
|
|
3945
|
-
matches;
|
|
3946
|
-
cursor;
|
|
3947
|
-
top = 0;
|
|
3948
|
-
width;
|
|
3949
|
-
constructor(choices, initial) {
|
|
3950
|
-
this.choices = choices;
|
|
3951
|
-
this.matches = choices;
|
|
3952
|
-
this.cursor = Math.min(Math.max(initial, 0), choices.length - 1);
|
|
3953
|
-
this.width = Math.max(0, ...choices.map((choice) => choice.label.length));
|
|
3954
|
-
}
|
|
3955
|
-
current() {
|
|
3956
|
-
return this.matches[this.cursor];
|
|
3957
|
-
}
|
|
3958
|
-
press(key) {
|
|
3959
|
-
if (this.line.chained === true && endsKills(key))
|
|
3960
|
-
this.line = { ...this.line, chained: false };
|
|
3961
|
-
if (key === "up" || key === "down") {
|
|
3962
|
-
if (this.matches.length > 0)
|
|
3963
|
-
this.cursor = (this.cursor + (key === "up" ? this.matches.length - 1 : 1)) % this.matches.length;
|
|
3964
|
-
return;
|
|
3965
|
-
}
|
|
3966
|
-
if (key === "home" || key === "end" || key === "pageup" || key === "pagedown") {
|
|
3967
|
-
const last = this.matches.length - 1;
|
|
3968
|
-
const to = { home: 0, end: last, pageup: this.cursor - MAX_ROWS, pagedown: this.cursor + MAX_ROWS }[key];
|
|
3969
|
-
this.cursor = Math.max(0, Math.min(last, to));
|
|
3970
|
-
return;
|
|
3971
|
-
}
|
|
3972
|
-
if (typeof key !== "object" && !isEditKey(key))
|
|
3973
|
-
return;
|
|
3974
|
-
const edited = editLine(this.line, key);
|
|
3975
|
-
if (edited.text !== this.line.text)
|
|
3976
|
-
this.filter(edited.text);
|
|
3977
|
-
this.line = edited;
|
|
3978
|
-
}
|
|
3979
|
-
typed(colors, columns, question) {
|
|
3980
|
-
return this.line.text === "" ? "" : withCaret(colors, this.line, roomAfter(question, columns));
|
|
3981
|
-
}
|
|
3982
|
-
filter(query) {
|
|
3983
|
-
const words = query.toLowerCase().split(WORDS2).filter((word) => word !== "");
|
|
3984
|
-
const current = this.current();
|
|
3985
|
-
this.matches = this.choices.filter(({ label, hint }) => words.every((word) => `${label} ${hint}`.toLowerCase().includes(word)));
|
|
3986
|
-
this.cursor = current === undefined ? 0 : Math.max(this.matches.indexOf(current), 0);
|
|
3987
|
-
this.top = 0;
|
|
3988
|
-
}
|
|
3989
|
-
rows(colors, { columns, rows }, marker) {
|
|
3990
|
-
if (this.matches.length === 0)
|
|
3991
|
-
return [colors.dim(" no match")];
|
|
3992
|
-
const height = Math.max(1, Math.min(MAX_ROWS, rows - 3, this.matches.length));
|
|
3993
|
-
this.top = Math.min(Math.max(this.top, this.cursor - height + 1), this.cursor);
|
|
3994
|
-
const shown = this.matches.slice(this.top, this.top + height).map((choice, index) => {
|
|
3995
|
-
const here = this.top + index === this.cursor;
|
|
3996
|
-
const mark = marker(choice);
|
|
3997
|
-
const head = `${here ? "\u276F" : " "} ${mark}`;
|
|
3998
|
-
const label = choice.label.padEnd(this.width);
|
|
3999
|
-
const room = columns - 5 - (mark === "" ? 0 : 2) - this.width;
|
|
4000
|
-
return `${here ? colors.cyan(head) : head}${here ? colors.cyan(label) : label} ${colors.dim(truncate(choice.hint, Math.max(room, 0)))}`;
|
|
4001
|
-
});
|
|
4002
|
-
const below = this.matches.length - this.top - height;
|
|
4003
|
-
return [...this.top > 0 ? [colors.dim(` \u2026 ${this.top} more`)] : [], ...shown, ...below > 0 ? [colors.dim(` \u2026 ${below} more`)] : []];
|
|
4004
|
-
}
|
|
4005
|
-
}
|
|
4006
|
-
function asking(colors, question, typed, keys) {
|
|
4007
|
-
return `${colors.cyan("?")} ${question} ${typed === "" ? colors.dim(`(${keys})`) : typed}`;
|
|
4008
|
-
}
|
|
4009
|
-
function answer(colors, question, state, picked) {
|
|
4010
|
-
return state === "enter" ? `${colors.green("\u2713")} ${question} ${colors.cyan(picked)}` : `${colors.red("\u2717")} ${question} ${colors.dim("cancelled")}`;
|
|
4011
|
-
}
|
|
4012
|
-
async function ask(question, { hint, terminal = process23 }, render, press) {
|
|
4013
|
-
const { stdin, stderr } = terminal;
|
|
4014
|
-
if (!isInteractive(terminal))
|
|
4015
|
-
fail(`cannot ask "${question}" off a terminal`, 2, hint);
|
|
4016
|
-
const colors = paint(stderr);
|
|
4017
|
-
let current = "asking";
|
|
4018
|
-
let outcome;
|
|
4019
|
-
const columns = () => stderr.columns || 80;
|
|
4020
|
-
const draw = (state, last = false) => {
|
|
4021
|
-
const frame = render(colors, state, { columns: columns(), rows: stderr.rows || 24 });
|
|
4022
|
-
const rows = rowsTaken(frame, columns());
|
|
4023
|
-
stderr.write(`${SYNC_START}\r${overwrite(frame, columns())}\x1B[0J${last || rows < 2 ? "" : `\x1B[${rows - 1}A`}${last ? "" : "\r"}${SYNC_END}`);
|
|
4024
|
-
current = state;
|
|
4025
|
-
};
|
|
4026
|
-
const redraw = () => draw(current);
|
|
4027
|
-
const paste = { active: false };
|
|
4028
|
-
const stop = terminal.stop ?? (terminal === process23 ? stopJob : undefined);
|
|
4029
|
-
const suspend = () => {
|
|
4030
|
-
if (stop === undefined)
|
|
4031
|
-
return;
|
|
4032
|
-
stderr.write("\x1B[0J\x1B[?25h\x1B[?2004l");
|
|
4033
|
-
stdin.setRawMode(false);
|
|
4034
|
-
stop();
|
|
4035
|
-
stdin.setRawMode(true);
|
|
4036
|
-
stderr.write("\x1B[?25l\x1B[?2004h");
|
|
4037
|
-
};
|
|
4038
|
-
try {
|
|
4039
|
-
stderr.on?.("resize", redraw);
|
|
4040
|
-
stdin.setRawMode(true);
|
|
4041
|
-
stdin.resume();
|
|
4042
|
-
stderr.write("\x1B[?25l\x1B[?2004h");
|
|
4043
|
-
draw("asking");
|
|
4044
|
-
return await new Promise((resolve) => {
|
|
4045
|
-
function onData(data) {
|
|
4046
|
-
for (const key of readKeys(data.toString(), paste)) {
|
|
4047
|
-
if (key === "suspend") {
|
|
4048
|
-
suspend();
|
|
4049
|
-
continue;
|
|
4050
|
-
}
|
|
4051
|
-
const pressed = press(key);
|
|
4052
|
-
if (pressed !== undefined) {
|
|
4053
|
-
settle(pressed);
|
|
4054
|
-
return;
|
|
4055
|
-
}
|
|
4056
|
-
}
|
|
4057
|
-
draw("asking");
|
|
4058
|
-
}
|
|
4059
|
-
function onEnd() {
|
|
4060
|
-
settle("cancel");
|
|
4061
|
-
}
|
|
4062
|
-
function settle(settled) {
|
|
4063
|
-
outcome = settled;
|
|
4064
|
-
stdin.off("data", onData);
|
|
4065
|
-
stdin.off("end", onEnd);
|
|
4066
|
-
resolve(settled === "enter");
|
|
4067
|
-
}
|
|
4068
|
-
stdin.on("data", onData);
|
|
4069
|
-
stdin.on("end", onEnd);
|
|
4070
|
-
});
|
|
4071
|
-
} finally {
|
|
4072
|
-
stderr.off?.("resize", redraw);
|
|
4073
|
-
draw(outcome ?? "cancel", true);
|
|
4074
|
-
stderr.write(`
|
|
4075
|
-
\x1B[?25h\x1B[?2004l`);
|
|
4076
|
-
stdin.setRawMode(false);
|
|
4077
|
-
stdin.pause();
|
|
4078
|
-
}
|
|
4079
|
-
}
|
|
4080
|
-
var WORDS2, MAX_ROWS = 10, PROMPT_KEYS;
|
|
4081
|
-
var init_prompt = __esm(() => {
|
|
4082
|
-
init_answers();
|
|
4083
|
-
init_args();
|
|
4084
|
-
init_format();
|
|
4085
|
-
init_job();
|
|
4086
|
-
init_mode();
|
|
4087
|
-
init_line();
|
|
4088
|
-
init_state();
|
|
4089
|
-
init_redraw();
|
|
4090
|
-
init_style();
|
|
4091
|
-
WORDS2 = /\s+/;
|
|
4092
|
-
PROMPT_KEYS = new Set(["up", "down", "pageup", "pagedown", "home", "end", "enter", "cancel", "suspend", "tab"]);
|
|
4093
|
-
});
|
|
4094
|
-
|
|
4095
|
-
// src/excluded.ts
|
|
4096
|
-
import { existsSync as existsSync6, mkdirSync as mkdirSync2, readFileSync as readFileSync7, writeFileSync } from "fs";
|
|
4097
|
-
import { dirname as dirname7 } from "path";
|
|
4098
|
-
function excludedPath(home) {
|
|
4099
|
-
return userConfigPath("pkg-excluded", { home });
|
|
4100
|
-
}
|
|
4101
|
-
function loadExcluded(home) {
|
|
4102
|
-
const path = excludedPath(home);
|
|
4103
|
-
if (!existsSync6(path))
|
|
4104
|
-
return {};
|
|
4105
|
-
try {
|
|
4106
|
-
const raw = JSON.parse(readFileSync7(path, "utf8"));
|
|
4107
|
-
const excluded = {};
|
|
4108
|
-
for (const [name, dirs] of Object.entries(raw)) {
|
|
4109
|
-
if (Array.isArray(dirs))
|
|
4110
|
-
excluded[name] = dirs.filter((dir) => typeof dir === "string");
|
|
4111
|
-
}
|
|
4112
|
-
return excluded;
|
|
4113
|
-
} catch {
|
|
4114
|
-
return;
|
|
4115
|
-
}
|
|
4116
|
-
}
|
|
4117
|
-
function saveExcluded(name, dirs, home) {
|
|
4118
|
-
const path = excludedPath(home);
|
|
4119
|
-
const excluded = loadExcluded(home);
|
|
4120
|
-
if (excluded === undefined)
|
|
4121
|
-
return;
|
|
4122
|
-
if (dirs.length === 0)
|
|
4123
|
-
delete excluded[name];
|
|
4124
|
-
else
|
|
4125
|
-
excluded[name] = [...dirs].toSorted();
|
|
4126
|
-
mkdirSync2(dirname7(path), { recursive: true });
|
|
4127
|
-
writeFileSync(path, `${JSON.stringify(excluded, null, 2)}
|
|
4128
|
-
`);
|
|
4129
|
-
}
|
|
4130
|
-
var init_excluded = __esm(() => {
|
|
4131
|
-
init_src();
|
|
4132
|
-
});
|
|
4133
|
-
|
|
4134
|
-
// src/commands/bump.ts
|
|
4135
|
-
var exports_bump = {};
|
|
4136
|
-
__export(exports_bump, {
|
|
4137
|
-
ROOT_OPTION: () => ROOT_OPTION,
|
|
4138
|
-
bump: () => bump
|
|
4139
|
-
});
|
|
4140
|
-
import { existsSync as existsSync7 } from "fs";
|
|
4141
|
-
import { basename, dirname as dirname8, join as join11, relative as relative2 } from "path";
|
|
4142
|
-
async function lookup2(name, registry, fetcher) {
|
|
4143
|
-
try {
|
|
4144
|
-
return { packument: await fetchPackument(name, registry, fetcher) };
|
|
4145
|
-
} catch (error) {
|
|
4146
|
-
if (error instanceof Exit && error.code === 2)
|
|
4147
|
-
return { error: error.message };
|
|
4148
|
-
throw error;
|
|
4149
|
-
}
|
|
4150
|
-
}
|
|
4151
|
-
async function servedVersion(name, version, settings) {
|
|
4152
|
-
if (!isValidName(name))
|
|
4153
|
-
fail(`${name} is not a valid npm package name`);
|
|
4154
|
-
if (version !== undefined && !EXACT_VERSION.test(version))
|
|
4155
|
-
fail(`bump takes an exact version, not ${version}: leave it out for the latest`);
|
|
4156
|
-
const registry = registryFor(name, settings.configs);
|
|
4157
|
-
const host = new URL(registry.url).host;
|
|
4158
|
-
const started = Date.now();
|
|
4159
|
-
const region = liveRegion((spinner) => [`${spinner} waiting for ${host} to serve ${name}@${version ?? "latest"} ${formatElapsed(Date.now() - started)}`]);
|
|
4160
|
-
let lastError = "";
|
|
4161
|
-
try {
|
|
4162
|
-
for (;; ) {
|
|
4163
|
-
const looked = await lookup2(name, registry, settings.fetcher);
|
|
4164
|
-
if ("error" in looked) {
|
|
4165
|
-
lastError = looked.error;
|
|
4166
|
-
} else {
|
|
4167
|
-
const latest = looked.packument?.["dist-tags"]?.latest;
|
|
4168
|
-
if (looked.packument === undefined)
|
|
4169
|
-
fail(`${host} has no ${name}`, 1);
|
|
4170
|
-
if (version === undefined && latest === undefined)
|
|
4171
|
-
fail(`${host} has no ${name}`, 1);
|
|
4172
|
-
if (version === undefined && latest !== undefined)
|
|
4173
|
-
return latest;
|
|
4174
|
-
if (version !== undefined && looked.packument.versions?.[version] !== undefined)
|
|
4175
|
-
return version;
|
|
4176
|
-
}
|
|
4177
|
-
if (Date.now() - started >= settings.timeout)
|
|
4178
|
-
fail(`${host} does not serve ${name}@${version ?? "latest"} after ${formatDuration(settings.timeout)}${lastError === "" ? "" : `, last error: ${lastError}`}`);
|
|
4179
|
-
region.redraw();
|
|
4180
|
-
await Bun.sleep(settings.poll ?? POLL);
|
|
4181
|
-
}
|
|
4182
|
-
} finally {
|
|
4183
|
-
region.stop();
|
|
4184
|
-
}
|
|
4185
|
-
}
|
|
4186
|
-
async function vet(name, version, settings) {
|
|
4187
|
-
if (settings.isForced === true)
|
|
4188
|
-
return true;
|
|
4189
|
-
const report = await checkPackage(`${name}@${version}`, { configs: settings.configs, fetcher: settings.fetcher, minAgeDays: settings.minAgeDays ?? 0, settings: settings.pkgSettings });
|
|
4190
|
-
if (!report.blocked) {
|
|
4191
|
-
for (const warning of report.warnings)
|
|
4192
|
-
warn(`${name}@${version}`, warning);
|
|
4193
|
-
return true;
|
|
4194
|
-
}
|
|
4195
|
-
for (const warning of report.warnings)
|
|
4196
|
-
problem(`${name}@${version} is refused`, warning);
|
|
4197
|
-
problem(`${name}@${version} is refused`, "no consumer was touched, --force bumps it anyway");
|
|
4198
|
-
return false;
|
|
4199
|
-
}
|
|
4200
|
-
function lockfileOf(dir, root) {
|
|
4201
|
-
for (let at = dir;; at = dirname8(at)) {
|
|
4202
|
-
const found = ["bun.lock", "bun.lockb"].find((file) => existsSync7(join11(at, file)));
|
|
4203
|
-
if (found !== undefined)
|
|
4204
|
-
return relative2(dir, join11(at, found));
|
|
4205
|
-
if (at === root || at === dirname8(at))
|
|
4206
|
-
return;
|
|
4207
|
-
}
|
|
4208
|
-
}
|
|
4209
|
-
async function hasUncommittedChanges(where, root, run) {
|
|
4210
|
-
const lockfile = lockfileOf(where, root);
|
|
4211
|
-
const status = await run(["git", "status", "--porcelain", "--", "package.json", ...lockfile === undefined ? [] : [lockfile]], where);
|
|
4212
|
-
return status.code === 0 && status.text.trim() !== "";
|
|
4213
|
-
}
|
|
4214
|
-
async function checkAndCommit(name, version, where, root, run) {
|
|
4215
|
-
const checked = await run(["check"], where);
|
|
4216
|
-
if (checked.code !== 0)
|
|
4217
|
-
return `check exited ${checked.code}: ${checked.text.trim().split(`
|
|
4218
|
-
`).at(-1) ?? ""}`;
|
|
4219
|
-
const lockfile = lockfileOf(where, root);
|
|
4220
|
-
const committed = await run(["gc", `chore(deps): bump ${name} to ${version}`, "--", "package.json", ...lockfile === undefined ? [] : [lockfile]], where);
|
|
4221
|
-
return committed.code === 0 ? undefined : `gc exited ${committed.code}: ${committed.text.trim().split(`
|
|
4222
|
-
`).at(-1) ?? ""}`;
|
|
4223
|
-
}
|
|
4224
|
-
function matcher(patterns) {
|
|
4225
|
-
const globs = patterns.map((pattern) => new Bun.Glob(pattern));
|
|
4226
|
-
return (dir) => globs.some((glob) => glob.match(dir) || glob.match(basename(dir)));
|
|
4227
|
-
}
|
|
4228
|
-
async function bumpConsumers(name, version, settings) {
|
|
4229
|
-
const everyone = findConsumers(name, settings.root);
|
|
4230
|
-
const isOnly = matcher(settings.only ?? []);
|
|
4231
|
-
const isExcept = matcher(settings.except ?? []);
|
|
4232
|
-
const declined = new Set(settings.declined ?? []);
|
|
4233
|
-
const found = everyone.filter((each) => (settings.only === undefined || settings.only.length === 0 || isOnly(each.dir)) && !isExcept(each.dir) && !declined.has(each.dir));
|
|
4234
|
-
const consumers = found.filter((each) => !isLocal(each));
|
|
4235
|
-
const left = everyone.length - found.length - declined.size;
|
|
4236
|
-
const local = found.length - consumers.length;
|
|
4237
|
-
const run = settings.run ?? (async (argv, cwd) => runCommand(argv, { cwd }));
|
|
4238
|
-
const committed = [];
|
|
4239
|
-
const failing = [];
|
|
4240
|
-
const skipped = [];
|
|
4241
|
-
let isClean = true;
|
|
4242
|
-
if (everyone.length === 0) {
|
|
4243
|
-
const similar = similarDependencies(name, settings.root);
|
|
4244
|
-
note(`nothing under ${settings.root} depends on ${name}`, similar.length === 0 ? undefined : `did you mean ${similar.join(", ")}`);
|
|
4245
|
-
} else if (left > 0) {
|
|
4246
|
-
note(`${bo(left, "folder")} left out by --only or --except`);
|
|
4247
|
-
}
|
|
4248
|
-
if (declined.size > 0)
|
|
4249
|
-
note(`${bo(declined.size, "folder")} left out by your choice`);
|
|
4250
|
-
if (local > 0)
|
|
4251
|
-
note(`${local} non-registry dependenc${local === 1 ? "y" : "ies"} (workspace:, file:, git, URL, alias, catalog:)`, "left as they are");
|
|
4252
|
-
for (const consumer of consumers) {
|
|
4253
|
-
const argv = addCommand(consumer, name, version);
|
|
4254
|
-
const where = join11(settings.root, consumer.dir);
|
|
4255
|
-
if (consumer.kind === "peerDependencies") {
|
|
4256
|
-
skipped.push(consumer.dir);
|
|
4257
|
-
note(consumer.dir, `peer range ${consumer.spec}, left as it is`);
|
|
4258
|
-
} else if ((consumer.alias === undefined ? consumer.spec : wantedVersion(consumer).replace(RANGE_PREFIX, "")) === version) {
|
|
4259
|
-
skipped.push(consumer.dir);
|
|
4260
|
-
note(consumer.dir, `already on ${version}`);
|
|
4261
|
-
} else if (consumer.manager !== "bun") {
|
|
4262
|
-
skipped.push(consumer.dir);
|
|
4263
|
-
warn(consumer.dir, `${consumer.spec}, its lockfile pins ${consumer.manager}: put ${version} in by hand`);
|
|
4264
|
-
} else if (settings.isDryRun === true) {
|
|
4265
|
-
note(consumer.dir, `would run ${[argv.join(" "), ...settings.isAll === true ? ["check", `gc 'chore(deps): bump ${name} to ${version}'`] : []].join(", then ")}`);
|
|
4266
|
-
} else if (settings.isAll === true && await hasUncommittedChanges(where, settings.root, run)) {
|
|
4267
|
-
isClean = false;
|
|
4268
|
-
failing.push(consumer.dir);
|
|
4269
|
-
problem(consumer.dir, "package.json or its lockfile has uncommitted changes, left alone so that gc does not commit them");
|
|
4270
|
-
} else {
|
|
4271
|
-
const ran = await run(argv, where);
|
|
4272
|
-
if (ran.code !== 0) {
|
|
4273
|
-
isClean = false;
|
|
4274
|
-
failing.push(consumer.dir);
|
|
4275
|
-
problem(consumer.dir, `${argv.join(" ")} exited ${ran.code}: ${ran.text.trim().split(`
|
|
4276
|
-
`).at(-1) ?? ""}`);
|
|
4277
|
-
} else if (settings.isAll !== true) {
|
|
4278
|
-
ok(consumer.dir, `${consumer.spec} -> ${version}`);
|
|
4279
|
-
} else {
|
|
4280
|
-
const failure = await checkAndCommit(name, version, where, settings.root, run);
|
|
4281
|
-
if (failure === undefined) {
|
|
4282
|
-
committed.push(consumer.dir);
|
|
4283
|
-
ok(consumer.dir, `${consumer.spec} -> ${version}, checked and committed`);
|
|
4284
|
-
} else {
|
|
4285
|
-
isClean = false;
|
|
4286
|
-
failing.push(consumer.dir);
|
|
4287
|
-
problem(consumer.dir, `${consumer.spec} -> ${version}, left uncommitted: ${failure}`);
|
|
4288
|
-
}
|
|
4289
|
-
}
|
|
4290
|
-
}
|
|
4291
|
-
}
|
|
4292
|
-
if (settings.isAll === true && settings.isDryRun !== true)
|
|
4293
|
-
note("summary", `${committed.length} bumped and committed, ${failing.length} bumped and failing${failing.length > 0 ? ` (${failing.join(", ")})` : ""}, ${skipped.length + local} skipped`);
|
|
4294
|
-
return isClean;
|
|
4295
|
-
}
|
|
4296
|
-
function plannedBumps(name, version, settings) {
|
|
4297
|
-
return findConsumers(name, settings.root).filter((each) => !isLocal(each) && each.kind !== "peerDependencies" && each.manager === "bun" && (each.alias === undefined ? each.spec : wantedVersion(each).replace(RANGE_PREFIX, "")) !== version).map((each) => ({ dir: each.dir, line: `${each.dir} ${each.spec} -> ${version}` }));
|
|
4298
|
-
}
|
|
4299
|
-
async function choosePlan(name, version, settings, chooser = terminalChooser, home) {
|
|
4300
|
-
const plans = plannedBumps(name, version, settings);
|
|
4301
|
-
if (plans.length === 0)
|
|
4302
|
-
return;
|
|
4303
|
-
const excluded = new Set(loadExcluded(home)?.[name] ?? []);
|
|
4304
|
-
const picked = await chooser.pick(name, plans, excluded);
|
|
4305
|
-
if (picked === undefined)
|
|
4306
|
-
return { chosen: [], declined: plans.map((plan) => plan.dir) };
|
|
4307
|
-
const chosen = plans.filter((plan) => picked.has(plan.dir));
|
|
4308
|
-
for (const plan of chosen)
|
|
4309
|
-
note("plan", plan.line);
|
|
4310
|
-
if (chosen.length === 0 || await chooser.confirm(`bump ${name} to ${version} in ${bo(chosen.length, "folder")}?`) !== true)
|
|
4311
|
-
return { chosen: [], declined: plans.map((plan) => plan.dir) };
|
|
4312
|
-
const declined = plans.filter((plan) => !picked.has(plan.dir)).map((plan) => plan.dir);
|
|
4313
|
-
saveExcluded(name, [...excluded].filter((dir) => !plans.some((plan) => plan.dir === dir)).concat(declined), home);
|
|
4314
|
-
return { chosen: chosen.map((plan) => plan.dir), declined };
|
|
4315
|
-
}
|
|
4316
|
-
async function bump(args) {
|
|
4317
|
-
const { values, positionals: [name, asked] } = parse(args, usage5, options4, { exits: EXITS4, positionals: ["<name>", "[version]"] });
|
|
4318
|
-
const settings = {
|
|
4319
|
-
root: workspaceRoot({ given: values.root }),
|
|
4320
|
-
configs: await loadConfigs(),
|
|
4321
|
-
timeout: duration(values.timeout, "timeout", 10 * 60000),
|
|
4322
|
-
isDryRun: values["dry-run"] === true,
|
|
4323
|
-
isAll: values["all-consumers"] === true,
|
|
4324
|
-
isForced: values.force === true,
|
|
4325
|
-
only: values.only,
|
|
4326
|
-
except: values.except,
|
|
4327
|
-
pkgSettings: await loadSettings(),
|
|
4328
|
-
minAgeDays: wholeNumber(values["min-age"], "min-age", 0, 0)
|
|
4329
|
-
};
|
|
4330
|
-
const version = await servedVersion(name, asked, settings);
|
|
4331
|
-
if (!await vet(name, version, settings))
|
|
4332
|
-
return 1;
|
|
4333
|
-
if (settings.isDryRun !== true && values.yes !== true && isInteractive() && (settings.only?.length ?? 0) === 0 && (settings.except?.length ?? 0) === 0) {
|
|
4334
|
-
const plan = await choosePlan(name, version, settings);
|
|
4335
|
-
if (plan?.chosen.length === 0) {
|
|
4336
|
-
note("nothing to bump", "none chosen or not confirmed");
|
|
4337
|
-
return 0;
|
|
4338
|
-
}
|
|
4339
|
-
settings.declined = plan?.declined;
|
|
4340
|
-
}
|
|
4341
|
-
return await bumpConsumers(name, version, settings) ? 0 : 1;
|
|
4342
|
-
}
|
|
4343
|
-
var usage5 = `pkg bump <name> [version]
|
|
4344
|
-
|
|
4345
|
-
Waits until the registry serves the version, vets it as \`pkg check\` does, then runs \`bun add --exact --no-cache\` in each folder under --root whose package.json depends on the package, the kind of dependency kept; a version the vetting blocks is refused before any folder is touched, unless --force is given.
|
|
4346
|
-
A dependency that is not a registry version (\`workspace:\`, \`link:\`, \`file:\`, git, a URL, \`catalog:\`), a peer range, a folder already on the version and one whose lockfile pins another manager are left as they are, each said so.
|
|
4347
|
-
On a terminal with no --only or --except, a checklist asks which consumers to bump, then the plan is printed and confirmed.
|
|
4348
|
-
With --all-consumers, a folder with uncommitted changes in its package.json or lockfile is left alone, and each folder whose install went through runs its own \`check\` and is committed with \`gc\` only when that passes; nothing is ever pushed.`, EXITS4, ROOT_OPTION, options4, POLL = 5000, terminalChooser;
|
|
4349
|
-
var init_bump = __esm(() => {
|
|
4350
|
-
init_src();
|
|
4351
|
-
init_progress();
|
|
4352
|
-
init_prompt();
|
|
4353
|
-
init_text();
|
|
4354
|
-
init_config2();
|
|
4355
|
-
init_consumers();
|
|
4356
|
-
init_excluded();
|
|
4357
|
-
init_registry();
|
|
4358
|
-
init_semver();
|
|
4359
|
-
init_check();
|
|
4360
|
-
EXITS4 = [[0, "every install ran or was left as it is (with --all-consumers, and every check passed and every commit landed)"], [1, "the vetting refuses the version, an install, a check or a commit fails or the registry has no such package"], [2, "the version never shows within the timeout (a registry that cannot be reached is retried until then) or a usage error"]];
|
|
4361
|
-
ROOT_OPTION = { type: "string", description: "the folder holding the repositories (the workspace of the user config or KAYNOOO_WORKSPACE, ~/Workspace by default)" };
|
|
4362
|
-
options4 = {
|
|
4363
|
-
root: ROOT_OPTION,
|
|
4364
|
-
timeout: { type: "string", short: "t", description: "how long to wait for the registry (10m): 30s, 5m, 1h" },
|
|
4365
|
-
"all-consumers": { type: "boolean", description: "after each install run the folder's check and commit it through gc when it passes" },
|
|
4366
|
-
only: { type: "string", multiple: true, description: "bump only the folders matching this name or glob, repeatable" },
|
|
4367
|
-
except: { type: "string", multiple: true, description: "leave the folders matching this name or glob alone, repeatable" },
|
|
4368
|
-
"dry-run": { type: "boolean", description: "print what would run, changing nothing" },
|
|
4369
|
-
yes: { type: "boolean", short: "y", description: "on a terminal, bump every consumer without the checklist and the confirmation" },
|
|
4370
|
-
force: { type: "boolean", description: "bump even when the version is blocked by the vetting" },
|
|
4371
|
-
"min-age": { type: "string", description: "days a version must be old (0: a bump adopts a release on purpose, often one just made)" }
|
|
4372
|
-
};
|
|
4373
|
-
terminalChooser = {
|
|
4374
|
-
pick: async (name, plans, excluded) => checklist(`bump ${name} in`, plans.map((plan) => ({ value: plan.dir, label: plan.line, hint: excluded.has(plan.dir) ? "left out last time" : "" })), { initial: new Set(plans.filter((plan) => !excluded.has(plan.dir)).map((plan) => plan.dir)), hint: "pass --yes to bump every consumer" }),
|
|
4375
|
-
confirm: async (question) => confirm(question, { default: true })
|
|
4376
|
-
};
|
|
4377
|
-
});
|
|
4378
|
-
|
|
4379
|
-
// src/commands/consumers.ts
|
|
4380
|
-
var exports_consumers = {};
|
|
4381
|
-
__export(exports_consumers, {
|
|
4382
|
-
consumers: () => consumers
|
|
4383
|
-
});
|
|
4384
|
-
function consumers(args) {
|
|
4385
|
-
const { values, positionals: [name] } = parse(args, usage6, options5, { exits: EXITS5, positionals: ["<name>"] });
|
|
4386
|
-
const root = workspaceRoot({ given: values.root });
|
|
4387
|
-
const { shown, footer } = capped(findConsumers(name, root), limitOf(values, CONSUMERS_LIMIT));
|
|
4388
|
-
if (values.json === true) {
|
|
4389
|
-
printJson(shown);
|
|
4390
|
-
} else if (shown.length === 0) {
|
|
4391
|
-
const similar = similarDependencies(name, root);
|
|
4392
|
-
console.log(`nothing under ${root} depends on ${name}${similar.length === 0 ? "" : `, did you mean ${similar.join(", ")}`}`);
|
|
4393
|
-
} else {
|
|
4394
|
-
console.log([table([["FOLDER", "KIND", "VERSION", "MANAGER"], ...shown.map((each) => [each.dir, each.alias === undefined ? each.kind : `${each.kind} as ${each.alias}`, each.spec, each.manager])], { header: true }), ...footer === undefined ? [] : [footer]].join(`
|
|
4395
|
-
`));
|
|
4396
|
-
}
|
|
4397
|
-
return 0;
|
|
4398
|
-
}
|
|
4399
|
-
var usage6 = `pkg consumers <name>
|
|
4400
|
-
|
|
4401
|
-
Lists the folders under --root whose package.json depends on the package, by its own name or through an \`npm:\` alias of it (the alias key is shown after the kind): the folder, the kind of dependency, the version it asks for and the manager its lockfile pins, 30 at most with the count of the rest after them (--limit <n>, --full for all; --json is never cut unless --limit is given).`, EXITS5, CONSUMERS_LIMIT = 30, options5;
|
|
4402
|
-
var init_consumers2 = __esm(() => {
|
|
4403
|
-
init_src();
|
|
4404
|
-
init_consumers();
|
|
4405
|
-
init_bump();
|
|
4406
|
-
EXITS5 = [[0, "it listed them"], [2, "a usage error"]];
|
|
4407
|
-
options5 = {
|
|
4408
|
-
root: ROOT_OPTION,
|
|
4409
|
-
...limitOptions(CONSUMERS_LIMIT),
|
|
4410
|
-
json: jsonOption("[{dir, path, kind, spec, manager}]")
|
|
4411
|
-
};
|
|
4412
|
-
});
|
|
4413
|
-
|
|
4414
|
-
// src/manager.ts
|
|
4415
|
-
import { existsSync as existsSync8 } from "fs";
|
|
4416
|
-
import { dirname as dirname9, join as join12 } from "path";
|
|
4417
|
-
function detectManager(from) {
|
|
4418
|
-
let dir = from;
|
|
4419
|
-
while (true) {
|
|
4420
|
-
const found = LOCKFILES2.find(([file]) => existsSync8(join12(dir, file)));
|
|
4421
|
-
if (found !== undefined)
|
|
4422
|
-
return found[1];
|
|
4423
|
-
const parent = dirname9(dir);
|
|
4424
|
-
if (parent === dir)
|
|
4425
|
-
return "bun";
|
|
4426
|
-
dir = parent;
|
|
4427
|
-
}
|
|
4428
|
-
}
|
|
4429
|
-
function commandFor(action, manager) {
|
|
4430
|
-
const { fallback, ...own } = COMMANDS[action];
|
|
4431
|
-
return own[manager] ?? fallback(manager);
|
|
4432
|
-
}
|
|
4433
|
-
var ACTIONS2, LOCKFILES2, COMMANDS;
|
|
4434
|
-
var init_manager = __esm(() => {
|
|
4435
|
-
ACTIONS2 = ["install", "dev", "remove", "update", "exec"];
|
|
4436
|
-
LOCKFILES2 = [["bun.lock", "bun"], ["bun.lockb", "bun"], ["yarn.lock", "yarn"], ["pnpm-lock.yaml", "pnpm"], ["package-lock.json", "npm"], ["composer.json", "composer"], ["uv.lock", "uv"]];
|
|
4437
|
-
COMMANDS = {
|
|
4438
|
-
install: { yarn: "yarn add", uv: "uv sync", fallback: (manager) => `${manager} install` },
|
|
4439
|
-
dev: { bun: "bun add -d", yarn: "yarn add -D", pnpm: "pnpm add -D", composer: "composer require --dev", uv: "uv add --dev", fallback: () => "npm install -D" },
|
|
4440
|
-
remove: { npm: "npm uninstall", fallback: (manager) => `${manager} remove` },
|
|
4441
|
-
update: { yarn: "yarn upgrade", uv: "uv lock --upgrade", fallback: (manager) => `${manager} update` },
|
|
4442
|
-
exec: { bun: "bunx", pnpm: "pnpm dlx", yarn: "yarn dlx", composer: "composer exec", uv: "uvx", fallback: () => "npx" }
|
|
4443
|
-
};
|
|
4444
|
-
});
|
|
4445
|
-
|
|
4446
|
-
// src/commands/manager.ts
|
|
4447
|
-
var exports_manager = {};
|
|
4448
|
-
__export(exports_manager, {
|
|
4449
|
-
manager: () => manager
|
|
4450
|
-
});
|
|
4451
|
-
import process24 from "process";
|
|
4452
|
-
function manager(args) {
|
|
4453
|
-
const { values, positionals } = parse(args, usage7, options6, {
|
|
4454
|
-
exits: EXITS6,
|
|
4455
|
-
positionals: ["<action>"],
|
|
4456
|
-
candidates: { "<action>": () => [...ACTIONS2] },
|
|
4457
|
-
replaces: "telling bun, yarn, pnpm, npm, composer and uv apart by their lockfile before typing an add, remove or dlx",
|
|
4458
|
-
examples: ["pkg manager dev", ["pkg manager exec", "bunx, npx, pnpm dlx... for this folder"]]
|
|
4459
|
-
});
|
|
4460
|
-
const action = oneOf(positionals[0] ?? "", "<action>", ACTIONS2);
|
|
4461
|
-
const found = detectManager(process24.cwd());
|
|
4462
|
-
const command = commandFor(action, found);
|
|
4463
|
-
if (values.json === true)
|
|
4464
|
-
printJson({ manager: found, action, command });
|
|
4465
|
-
else
|
|
4466
|
-
console.log(command);
|
|
4467
|
-
return 0;
|
|
4468
|
-
}
|
|
4469
|
-
var usage7 = `pkg manager <install|dev|remove|update|exec>
|
|
4470
|
-
|
|
4471
|
-
Prints the command the package manager of this folder runs for the action: install is the add or install of a package, dev adds one as a dev dependency, remove drops one, update upgrades them and exec runs a package's bin without installing it. The manager is the one whose lockfile (bun.lock, bun.lockb, yarn.lock, pnpm-lock.yaml, package-lock.json, uv.lock) or composer.json is nearest, here or in a parent folder, bun when none is found.`, EXITS6, options6;
|
|
4472
|
-
var init_manager2 = __esm(() => {
|
|
4473
|
-
init_src();
|
|
4474
|
-
init_manager();
|
|
4475
|
-
EXITS6 = [[0, "it printed the command"], [2, "a usage error"]];
|
|
4476
|
-
options6 = {
|
|
4477
|
-
json: jsonOption("{manager, action, command}")
|
|
4478
|
-
};
|
|
4479
|
-
});
|
|
4480
|
-
|
|
4481
|
-
// src/cli.ts
|
|
4482
|
-
init_src();
|
|
4483
|
-
import process25 from "process";
|
|
4484
|
-
process25.exitCode = await runCli({
|
|
4485
|
-
name: "pkg",
|
|
4486
|
-
about: "checks npm packages before they are added, and moves a lib's consumers onto a new release",
|
|
4487
|
-
replaces: "bun add on trust, and a bun info and sleep loop then a bun add per consumer",
|
|
4488
|
-
examples: [["pkg zod", "the name, the newest version two weeks old, its licence and scripts"], ["pkg bump @kaynooo/cli-kit --dry-run", "the consumers a release would move"]],
|
|
4489
|
-
defaultCommand: "check",
|
|
4490
|
-
commands: {
|
|
4491
|
-
check: { summary: "check packages before they are added (`pkg <name>` alone runs it)", run: async (args) => (await Promise.resolve().then(() => (init_check(), exports_check))).check(args) },
|
|
4492
|
-
audit: { summary: "check every package a bun.lock pins, with its known advisories", run: async (args) => (await Promise.resolve().then(() => (init_audit(), exports_audit))).audit(args) },
|
|
4493
|
-
outdated: { summary: "list the dependencies of this folder that have a newer version safe to take", run: async (args) => (await Promise.resolve().then(() => (init_outdated(), exports_outdated))).outdatedCommand(args) },
|
|
4494
|
-
bump: { summary: "wait for a release on the registry, then bun add it in every consumer", run: async (args) => (await Promise.resolve().then(() => (init_bump(), exports_bump))).bump(args) },
|
|
4495
|
-
consumers: { summary: "list the folders depending on a package, with the version each asks for", run: async (args) => (await Promise.resolve().then(() => (init_consumers2(), exports_consumers))).consumers(args) },
|
|
4496
|
-
manager: { summary: "the command this folder's package manager runs to install, remove, update or exec", run: async (args) => (await Promise.resolve().then(() => (init_manager2(), exports_manager))).manager(args) }
|
|
4497
|
-
}
|
|
4498
|
-
});
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
// @bun 2>/dev/null; exec bun --no-env-file --config=/dev/null "$0" "$@"
|
|
3
|
+
import"./chunk-26yfv47h.js";import{runCli}from"./chunk-8r692fbd.js";import process from"process";process.exitCode=await runCli({name:"pkg",about:"checks npm packages before they are added, and moves a lib's consumers onto a new release",replaces:"bun add on trust, and a bun info and sleep loop then a bun add per consumer",examples:[["pkg zod","the name, the newest version two weeks old, its licence and scripts"],["pkg bump @kaynooo/cli-kit --dry-run","the consumers a release would move"]],defaultCommand:"check",commands:{check:{summary:"check packages before they are added (`pkg <name>` alone runs it)",run:async(args)=>(await import("./chunk-3sqd2sjj.js")).check(args)},audit:{summary:"check every package a bun.lock pins, with its known advisories",run:async(args)=>(await import("./chunk-x4gvcn9p.js")).audit(args)},outdated:{summary:"list the dependencies of this folder that have a newer version safe to take",run:async(args)=>(await import("./chunk-63sp907v.js")).outdatedCommand(args)},bump:{summary:"wait for a release on the registry, then bun add it in every consumer",run:async(args)=>(await import("./chunk-e8r5gg6z.js")).bump(args)},consumers:{summary:"list the folders depending on a package, with the version each asks for",run:async(args)=>(await import("./chunk-4pczvmv2.js")).consumers(args)},manager:{summary:"the command this folder's package manager runs to install, remove, update or exec",run:async(args)=>(await import("./chunk-g0nhwvkx.js")).manager(args)}}});
|