@kaynooo/cli-proc 0.7.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/pid-cli.js +281 -58
- package/dist/ports-cli.js +303 -74
- package/dist/proc-cli.js +324 -93
- package/dist/procs-cli.js +295 -70
- package/package.json +2 -2
- package/src/ports.ts +7 -6
- package/src/procs.ts +6 -4
package/dist/pid-cli.js
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/pid-cli.ts
|
|
5
|
-
import
|
|
5
|
+
import process16 from "process";
|
|
6
6
|
// ../kit/src/args.ts
|
|
7
|
-
import
|
|
7
|
+
import process9 from "process";
|
|
8
8
|
import { parseArgs } from "util";
|
|
9
9
|
|
|
10
10
|
// ../kit/src/format.ts
|
|
11
|
-
import
|
|
11
|
+
import process7 from "process";
|
|
12
12
|
|
|
13
13
|
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-n6z2kk96.js
|
|
14
14
|
var r = new Map;
|
|
@@ -23,6 +23,7 @@ function y(e, t) {
|
|
|
23
23
|
n = new Intl.NumberFormat(e, t), i.set(o, n);
|
|
24
24
|
return n;
|
|
25
25
|
}
|
|
26
|
+
|
|
26
27
|
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rxztfxgv.js
|
|
27
28
|
var N = new Map;
|
|
28
29
|
var Nt = /\s+\S*$/;
|
|
@@ -40,6 +41,7 @@ function ko(t, e, r = "...") {
|
|
|
40
41
|
}
|
|
41
42
|
var 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));
|
|
42
43
|
var z = new Map;
|
|
44
|
+
|
|
43
45
|
// ../kit/src/mode.ts
|
|
44
46
|
import process2 from "process";
|
|
45
47
|
var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
@@ -62,7 +64,7 @@ function isInteractive(streams = process2) {
|
|
|
62
64
|
}
|
|
63
65
|
|
|
64
66
|
// ../kit/src/style.ts
|
|
65
|
-
import
|
|
67
|
+
import process6 from "process";
|
|
66
68
|
|
|
67
69
|
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
|
|
68
70
|
var G2 = /^[a-f0-9]+$/i;
|
|
@@ -88,7 +90,7 @@ function C(r, e = globalThis.process?.env ?? {}) {
|
|
|
88
90
|
return false;
|
|
89
91
|
return r?.isTTY === true;
|
|
90
92
|
}
|
|
91
|
-
function
|
|
93
|
+
function f(r, e = []) {
|
|
92
94
|
let l = "", n = "";
|
|
93
95
|
for (let t = 0, i = e.length;t < i; t++)
|
|
94
96
|
l += `\x1B[${e[t][0]}m`, n = `\x1B[${e[t][1]}m${n}`;
|
|
@@ -98,7 +100,7 @@ function f2(r, e = []) {
|
|
|
98
100
|
if (Array.isArray(a)) {
|
|
99
101
|
let s = g.get(i);
|
|
100
102
|
if (s === undefined)
|
|
101
|
-
s =
|
|
103
|
+
s = f(r, [...e, a]), g.set(i, s);
|
|
102
104
|
return s;
|
|
103
105
|
}
|
|
104
106
|
if (typeof a === "function")
|
|
@@ -107,30 +109,251 @@ function f2(r, e = []) {
|
|
|
107
109
|
if (u === undefined) {
|
|
108
110
|
if (g.size >= 64)
|
|
109
111
|
g.clear();
|
|
110
|
-
u =
|
|
112
|
+
u = f(r, [...e, a(...s)]), g.set(y, u);
|
|
111
113
|
}
|
|
112
114
|
return u;
|
|
113
115
|
};
|
|
114
116
|
throw Error(`Unknown style: ${String(i)}`);
|
|
115
117
|
} });
|
|
116
118
|
}
|
|
117
|
-
function
|
|
118
|
-
return
|
|
119
|
+
function Fe(r = {}) {
|
|
120
|
+
return f(r);
|
|
121
|
+
}
|
|
122
|
+
var o = Fe();
|
|
123
|
+
|
|
124
|
+
// ../kit/src/theme.ts
|
|
125
|
+
import { existsSync as existsSync2, readFileSync, statSync } from "fs";
|
|
126
|
+
import { homedir as homedir2 } from "os";
|
|
127
|
+
import { join as join3, resolve as resolve2 } from "path";
|
|
128
|
+
import process5 from "process";
|
|
129
|
+
|
|
130
|
+
// ../kit/src/config.ts
|
|
131
|
+
import { existsSync } from "fs";
|
|
132
|
+
import { dirname, join, resolve } from "path";
|
|
133
|
+
import process3 from "process";
|
|
134
|
+
function findUp(names, from = process3.cwd(), stop = () => false) {
|
|
135
|
+
const wanted = typeof names === "string" ? [names] : names;
|
|
136
|
+
for (let dir = resolve(from);; dir = dirname(dir)) {
|
|
137
|
+
const found = wanted.map((name) => join(dir, name)).find((path) => existsSync(path));
|
|
138
|
+
if (found !== undefined)
|
|
139
|
+
return found;
|
|
140
|
+
if (stop(dir) || dirname(dir) === dir)
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// ../kit/src/user-config.ts
|
|
146
|
+
import { homedir } from "os";
|
|
147
|
+
import { join as join2 } from "path";
|
|
148
|
+
import process4 from "process";
|
|
149
|
+
function configBase(where = {}) {
|
|
150
|
+
const xdg = where.xdg ?? (where.home === undefined ? process4.env.XDG_CONFIG_HOME : undefined);
|
|
151
|
+
return xdg !== undefined && xdg !== "" ? xdg : join2(where.home ?? homedir(), ".config");
|
|
152
|
+
}
|
|
153
|
+
function userConfigPath(bin, where = {}) {
|
|
154
|
+
return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
|
|
119
155
|
}
|
|
120
|
-
var o2 = Fe2();
|
|
121
156
|
|
|
122
157
|
// ../kit/src/theme.ts
|
|
123
158
|
var ENDS = new Map;
|
|
159
|
+
var DEFAULT = {
|
|
160
|
+
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" },
|
|
161
|
+
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" },
|
|
162
|
+
accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
|
|
163
|
+
bins: {},
|
|
164
|
+
gradient: ["#c084fc", "#67e8f9"]
|
|
165
|
+
};
|
|
166
|
+
var 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" };
|
|
167
|
+
var 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" };
|
|
168
|
+
var ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
|
|
169
|
+
var PRESETS = {
|
|
170
|
+
default: {},
|
|
171
|
+
"high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
|
|
172
|
+
mono: { colors: MONO, accents: ["bold"], gradient: undefined },
|
|
173
|
+
ascii: { glyphs: ASCII }
|
|
174
|
+
};
|
|
124
175
|
var 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"]);
|
|
176
|
+
var HEX = /^#[0-9a-f]{6}$/i;
|
|
177
|
+
var CONTROL = /\p{Cc}/u;
|
|
125
178
|
var MAX_FILE_BYTES = 64 * 1024;
|
|
179
|
+
var SPACES = /\s+/;
|
|
180
|
+
function isColorSpec(spec) {
|
|
181
|
+
if (typeof spec === "number")
|
|
182
|
+
return Number.isInteger(spec) && spec >= 0 && spec <= 255;
|
|
183
|
+
return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
|
|
184
|
+
}
|
|
185
|
+
var CUBE = [0, 95, 135, 175, 215, 255];
|
|
186
|
+
function cubeLevel(channel) {
|
|
187
|
+
return CUBE.reduce((best, value, level) => Math.abs(value - channel) < Math.abs(CUBE[best] - channel) ? level : best, 0);
|
|
188
|
+
}
|
|
189
|
+
function nearest256(hex) {
|
|
190
|
+
const rgb = [1, 3, 5].map((at) => Number.parseInt(hex.slice(at, at + 2), 16));
|
|
191
|
+
const levels = rgb.map(cubeLevel);
|
|
192
|
+
const cube = levels.map((level) => CUBE[level]);
|
|
193
|
+
const grey = Math.min(23, Math.max(0, Math.round((rgb.reduce((sum, channel) => sum + channel, 0) / 3 - 8) / 10)));
|
|
194
|
+
const greyValue = 8 + grey * 10;
|
|
195
|
+
const distance = (colour) => colour.reduce((sum, channel, at) => sum + (channel - rgb[at]) ** 2, 0);
|
|
196
|
+
return distance([greyValue, greyValue, greyValue]) < distance(cube) ? 232 + grey : 16 + 36 * levels[0] + 6 * levels[1] + levels[2];
|
|
197
|
+
}
|
|
198
|
+
function hasTrueColor(env) {
|
|
199
|
+
return env.COLORTERM === "truecolor" || env.COLORTERM === "24bit";
|
|
200
|
+
}
|
|
201
|
+
function tinted(colors, spec, env = process5.env) {
|
|
202
|
+
if (typeof spec === "number")
|
|
203
|
+
return colors.ansi256(spec);
|
|
204
|
+
return spec.trim().split(SPACES).reduce((chain, token) => {
|
|
205
|
+
if (HEX.test(token))
|
|
206
|
+
return hasTrueColor(env) ? chain.hex(token) : chain.ansi256(nearest256(token));
|
|
207
|
+
return chain[token] ?? chain;
|
|
208
|
+
}, colors);
|
|
209
|
+
}
|
|
210
|
+
function isRecord(value) {
|
|
211
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
212
|
+
}
|
|
213
|
+
function readThemeFile(path, warn) {
|
|
214
|
+
try {
|
|
215
|
+
const stat = statSync(path, { throwIfNoEntry: false });
|
|
216
|
+
if (stat === undefined)
|
|
217
|
+
return;
|
|
218
|
+
if (!stat.isFile() || stat.size > MAX_FILE_BYTES) {
|
|
219
|
+
warn(`${path} is not a regular file under ${MAX_FILE_BYTES / 1024} KiB, theme ignored`);
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
const parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
223
|
+
if (isRecord(parsed))
|
|
224
|
+
return parsed;
|
|
225
|
+
warn(`${path} is not a JSON object, theme ignored`);
|
|
226
|
+
} catch (error) {
|
|
227
|
+
warn(`${path} does not parse (${error instanceof Error ? error.message : String(error)}), theme ignored`);
|
|
228
|
+
}
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
function applyPreset(theme, name, warn, where) {
|
|
232
|
+
if (name === undefined)
|
|
233
|
+
return;
|
|
234
|
+
if (typeof name !== "string" || !Object.hasOwn(PRESETS, name)) {
|
|
235
|
+
warn(`${where}: no preset ${String(name)}, one of ${Object.keys(PRESETS).join(", ")}`);
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
const preset = PRESETS[name];
|
|
239
|
+
Object.assign(theme.colors, preset.colors);
|
|
240
|
+
Object.assign(theme.glyphs, preset.glyphs);
|
|
241
|
+
if (preset.accents !== undefined)
|
|
242
|
+
theme.accents = [...preset.accents];
|
|
243
|
+
if (Object.hasOwn(preset, "gradient"))
|
|
244
|
+
theme.gradient = preset.gradient;
|
|
245
|
+
return name;
|
|
246
|
+
}
|
|
247
|
+
function applyFile(theme, file, where, warn) {
|
|
248
|
+
if (isRecord(file.colors)) {
|
|
249
|
+
for (const [key, value] of Object.entries(file.colors)) {
|
|
250
|
+
if (!Object.hasOwn(DEFAULT.colors, key))
|
|
251
|
+
warn(`${where}: no colour ${key}, one of ${Object.keys(DEFAULT.colors).join(", ")}`);
|
|
252
|
+
else if (!isColorSpec(value))
|
|
253
|
+
warn(`${where}: colour ${key} is not an ANSI name, \`#rrggbb\` or a number up to 255`);
|
|
254
|
+
else
|
|
255
|
+
theme.colors[key] = value;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
if (isRecord(file.glyphs)) {
|
|
259
|
+
for (const [key, value] of Object.entries(file.glyphs)) {
|
|
260
|
+
if (!Object.hasOwn(DEFAULT.glyphs, key))
|
|
261
|
+
warn(`${where}: no glyph ${key}, one of ${Object.keys(DEFAULT.glyphs).join(", ")}`);
|
|
262
|
+
else if (typeof value !== "string" || CONTROL.test(value) || Bun.stringWidth(value) !== 1)
|
|
263
|
+
warn(`${where}: glyph ${key} must be one visible character wide, with no control character`);
|
|
264
|
+
else
|
|
265
|
+
theme.glyphs[key] = value;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
if (Array.isArray(file.accents) && file.accents.length > 0 && file.accents.every(isColorSpec))
|
|
269
|
+
theme.accents = [...file.accents];
|
|
270
|
+
else if (file.accents !== undefined)
|
|
271
|
+
warn(`${where}: accents must be a non-empty list of colours`);
|
|
272
|
+
if (file.gradient === null)
|
|
273
|
+
theme.gradient = undefined;
|
|
274
|
+
else if (Array.isArray(file.gradient) && file.gradient.length === 2 && file.gradient.every((end) => typeof end === "string" && HEX.test(end)))
|
|
275
|
+
theme.gradient = [file.gradient[0], file.gradient[1]];
|
|
276
|
+
else if (file.gradient !== undefined)
|
|
277
|
+
warn(`${where}: gradient must be two \`#rrggbb\` colours, or null for none`);
|
|
278
|
+
if (isRecord(file.bins)) {
|
|
279
|
+
for (const [bin, value] of Object.entries(file.bins)) {
|
|
280
|
+
if (isColorSpec(value))
|
|
281
|
+
theme.bins[bin] = value;
|
|
282
|
+
else
|
|
283
|
+
warn(`${where}: bin ${bin} has no valid colour`);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
function endsWalk(home) {
|
|
288
|
+
return (dir) => dir === resolve2(home) || existsSync2(join3(dir, ".git"));
|
|
289
|
+
}
|
|
126
290
|
var warned = new Set;
|
|
291
|
+
function warnOnce(message) {
|
|
292
|
+
if (warned.has(message))
|
|
293
|
+
return;
|
|
294
|
+
warned.add(message);
|
|
295
|
+
console.error(`warning: theme ${message}`);
|
|
296
|
+
}
|
|
297
|
+
function isPath(chosen) {
|
|
298
|
+
return chosen.includes("/") || chosen.endsWith(".json");
|
|
299
|
+
}
|
|
300
|
+
function loadTheme({ env = process5.env, from = process5.cwd(), home = homedir2(), warn = warnOnce } = {}) {
|
|
301
|
+
const theme = { colors: { ...DEFAULT.colors }, glyphs: { ...DEFAULT.glyphs }, accents: [...DEFAULT.accents], bins: Object.create(null), gradient: DEFAULT.gradient };
|
|
302
|
+
const sources = [];
|
|
303
|
+
const chosen = env.KIT_THEME ?? "";
|
|
304
|
+
const wanted = chosen === "" ? [userConfigPath("theme", { home, xdg: env.XDG_CONFIG_HOME }), findUp(join3(".kaynooo", "theme.json"), from, endsWalk(home))] : [];
|
|
305
|
+
if (isPath(chosen))
|
|
306
|
+
wanted.push(resolve2(from, chosen));
|
|
307
|
+
const files = [];
|
|
308
|
+
for (const path of wanted) {
|
|
309
|
+
const file = path === undefined ? undefined : readThemeFile(path, warn);
|
|
310
|
+
if (path !== undefined && file !== undefined)
|
|
311
|
+
files.push({ path, file });
|
|
312
|
+
}
|
|
313
|
+
let preset = "default";
|
|
314
|
+
if (chosen !== "" && !isPath(chosen)) {
|
|
315
|
+
preset = applyPreset(theme, chosen, warn, "KIT_THEME") ?? preset;
|
|
316
|
+
} else {
|
|
317
|
+
const named = files.findLast(({ file }) => file.preset !== undefined);
|
|
318
|
+
if (named !== undefined)
|
|
319
|
+
preset = applyPreset(theme, named.file.preset, warn, named.path) ?? preset;
|
|
320
|
+
}
|
|
321
|
+
for (const { path, file } of files) {
|
|
322
|
+
applyFile(theme, file, path, warn);
|
|
323
|
+
sources.push(path);
|
|
324
|
+
}
|
|
325
|
+
return { theme, sources, preset };
|
|
326
|
+
}
|
|
327
|
+
var current;
|
|
328
|
+
var currentKey = "";
|
|
329
|
+
function activeTheme() {
|
|
330
|
+
const key = `${process5.cwd()}\x00${process5.env.KIT_THEME ?? ""}\x00${process5.env.XDG_CONFIG_HOME ?? ""}`;
|
|
331
|
+
if (current === undefined || key !== currentKey) {
|
|
332
|
+
current = loadTheme();
|
|
333
|
+
currentKey = key;
|
|
334
|
+
}
|
|
335
|
+
return current;
|
|
336
|
+
}
|
|
127
337
|
|
|
128
338
|
// ../kit/src/style.ts
|
|
129
|
-
|
|
339
|
+
var MARK_WORDS = { ok: "ok:", warn: "warning:", problem: "error:", note: "note:", plan: "would:" };
|
|
340
|
+
function takesControlCodes(stream, env = process6.env) {
|
|
130
341
|
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
131
342
|
}
|
|
132
|
-
function paint(stream, env =
|
|
133
|
-
return
|
|
343
|
+
function paint(stream, env = process6.env) {
|
|
344
|
+
return Fe({ stream: { isTTY: takesControlCodes(stream, env) }, env });
|
|
345
|
+
}
|
|
346
|
+
function marked(mark, text, stream, detail, env = process6.env) {
|
|
347
|
+
const colors = paint(stream, env);
|
|
348
|
+
let head = MARK_WORDS[mark];
|
|
349
|
+
if (takesControlCodes(stream, env)) {
|
|
350
|
+
const { theme } = activeTheme();
|
|
351
|
+
head = tinted(colors.bold, theme.colors[mark], env)(theme.glyphs[mark]);
|
|
352
|
+
}
|
|
353
|
+
return `${head} ${text}${detail === undefined ? "" : ` ${colors.dim(detail)}`}`;
|
|
354
|
+
}
|
|
355
|
+
function problem(text, detail) {
|
|
356
|
+
console.error(marked("problem", text, process6.stderr, detail));
|
|
134
357
|
}
|
|
135
358
|
var STATUS_WORDS = {
|
|
136
359
|
passed: ["passed", "success", "succeeded", "ok"],
|
|
@@ -141,7 +364,7 @@ var STATUS_WORDS = {
|
|
|
141
364
|
};
|
|
142
365
|
var STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
|
|
143
366
|
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-knqbxp56.js
|
|
144
|
-
function
|
|
367
|
+
function tt(i, { units: r = "iec", dp: t = 1, locale: n } = {}) {
|
|
145
368
|
let e = r === "si" ? 1000 : 1024;
|
|
146
369
|
if (Math.abs(i) < e)
|
|
147
370
|
return `${i} B`;
|
|
@@ -179,7 +402,7 @@ var ESCAPE = String.fromCharCode(27);
|
|
|
179
402
|
function textWidth(text) {
|
|
180
403
|
return Bun.stringWidth(text);
|
|
181
404
|
}
|
|
182
|
-
function table(rows, { cellWidth, header = false, align = [], fit, stream =
|
|
405
|
+
function table(rows, { cellWidth, header = false, align = [], fit, stream = process7.stdout, env = process7.env } = {}) {
|
|
183
406
|
const cells = cellWidth === undefined ? rows : rows.map((row) => row.map((cell) => truncate(cell.replaceAll(LINE_BREAKS, " "), cellWidth)));
|
|
184
407
|
if (outputMode(stream, env) === "agent")
|
|
185
408
|
return cells.map((row) => row.map((cell) => Bun.stripANSI(cell).replaceAll(/[\t\r\n]+/g, " ")).join("\t")).join(`
|
|
@@ -218,7 +441,7 @@ function narrow(rows, widths, limit) {
|
|
|
218
441
|
}
|
|
219
442
|
return rows.map((row) => row.map((cell, index) => textWidth(cell) > (widths[index] ?? 0) ? truncate(cell, widths[index] ?? 0) : cell));
|
|
220
443
|
}
|
|
221
|
-
function jsonText(value, replacer, { stream =
|
|
444
|
+
function jsonText(value, replacer, { stream = process7.stdout, env = process7.env } = {}) {
|
|
222
445
|
return JSON.stringify(value, replacer, outputMode(stream, env) === "agent" ? undefined : 2);
|
|
223
446
|
}
|
|
224
447
|
function printJson(value) {
|
|
@@ -226,27 +449,27 @@ function printJson(value) {
|
|
|
226
449
|
}
|
|
227
450
|
|
|
228
451
|
// ../kit/src/help.ts
|
|
229
|
-
import
|
|
452
|
+
import process8 from "process";
|
|
230
453
|
var OPTIONAL = /\[[^\]]+\]/g;
|
|
231
454
|
var USAGE_PREFIX = /^usage:\s*/i;
|
|
232
455
|
var FULL_STOP = /\.$/;
|
|
233
|
-
function usageLine(usage, colors = paint(
|
|
456
|
+
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
234
457
|
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
235
458
|
}
|
|
236
|
-
function helpText(usage, options, colors = paint(
|
|
459
|
+
function helpText(usage, options, colors = paint(process8.stdout), { examples = [], replaces, exits = [] } = {}) {
|
|
237
460
|
return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
238
461
|
`);
|
|
239
462
|
}
|
|
240
|
-
function exitRows(exits, colors = paint(
|
|
463
|
+
function exitRows(exits, colors = paint(process8.stdout)) {
|
|
241
464
|
if (exits.length === 0)
|
|
242
465
|
return [];
|
|
243
466
|
const width = Math.max(...exits.map(([code]) => String(code).length));
|
|
244
467
|
return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
|
|
245
468
|
}
|
|
246
|
-
function replacesRows(replaces, colors = paint(
|
|
469
|
+
function replacesRows(replaces, colors = paint(process8.stdout)) {
|
|
247
470
|
return replaces === undefined || outputMode() === "agent" ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
248
471
|
}
|
|
249
|
-
function wantsHelpJson(env =
|
|
472
|
+
function wantsHelpJson(env = process8.env) {
|
|
250
473
|
return env.KIT_HELP === "json";
|
|
251
474
|
}
|
|
252
475
|
function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
@@ -265,12 +488,12 @@ function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
|
265
488
|
...options === undefined ? {} : { options: Object.entries(options).map(([name, { short, description }]) => ({ name, ...short === undefined ? {} : { short }, ...description === undefined ? {} : { description } })) }
|
|
266
489
|
};
|
|
267
490
|
}
|
|
268
|
-
function exampleRows(examples, colors = paint(
|
|
491
|
+
function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
269
492
|
if (examples.length === 0 || outputMode() === "agent")
|
|
270
493
|
return [];
|
|
271
494
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
272
495
|
}
|
|
273
|
-
function optionRows(options, colors = paint(
|
|
496
|
+
function optionRows(options, colors = paint(process8.stdout)) {
|
|
274
497
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
275
498
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
276
499
|
const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
|
|
@@ -371,7 +594,7 @@ var OUTPUT_OPTIONS = {
|
|
|
371
594
|
color: { type: "string", description: "auto (on a terminal alone), always or never" },
|
|
372
595
|
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
373
596
|
};
|
|
374
|
-
function applyOutput(color, plain, env =
|
|
597
|
+
function applyOutput(color, plain, env = process9.env) {
|
|
375
598
|
const when = plain === true ? "never" : color ?? "auto";
|
|
376
599
|
if (when === "auto")
|
|
377
600
|
return;
|
|
@@ -542,7 +765,7 @@ function nearestOption(message, options, allowNegative) {
|
|
|
542
765
|
}
|
|
543
766
|
// ../kit/src/process.ts
|
|
544
767
|
import { constants } from "os";
|
|
545
|
-
import
|
|
768
|
+
import process10 from "process";
|
|
546
769
|
var KILL_GRACE_MS = 2000;
|
|
547
770
|
function exitCodeOf(code, signal) {
|
|
548
771
|
if (code !== null)
|
|
@@ -562,7 +785,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
562
785
|
return;
|
|
563
786
|
try {
|
|
564
787
|
if (grouped)
|
|
565
|
-
|
|
788
|
+
process10.kill(-proc.pid, killing);
|
|
566
789
|
else
|
|
567
790
|
proc.kill(killing);
|
|
568
791
|
} catch {}
|
|
@@ -636,15 +859,15 @@ var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x
|
|
|
636
859
|
var RESET_STYLE = `${ESC}[0m`;
|
|
637
860
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
638
861
|
// ../kit/src/cli.ts
|
|
639
|
-
import { readFileSync, realpathSync } from "fs";
|
|
640
|
-
import { dirname as
|
|
641
|
-
import
|
|
862
|
+
import { readFileSync as readFileSync2, realpathSync } from "fs";
|
|
863
|
+
import { dirname as dirname3, join as join5 } from "path";
|
|
864
|
+
import process12 from "process";
|
|
642
865
|
|
|
643
866
|
// ../kit/src/usage.ts
|
|
644
867
|
import { appendFileSync, mkdirSync } from "fs";
|
|
645
|
-
import { homedir } from "os";
|
|
646
|
-
import { dirname, isAbsolute, join } from "path";
|
|
647
|
-
import
|
|
868
|
+
import { homedir as homedir3 } from "os";
|
|
869
|
+
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
870
|
+
import process11 from "process";
|
|
648
871
|
|
|
649
872
|
// ../kit/src/logs.ts
|
|
650
873
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -658,14 +881,14 @@ var usageError;
|
|
|
658
881
|
function noteUsageError(message) {
|
|
659
882
|
usageError = message;
|
|
660
883
|
}
|
|
661
|
-
function stateHome(env =
|
|
884
|
+
function stateHome(env = process11.env) {
|
|
662
885
|
const dir = env.XDG_STATE_HOME;
|
|
663
|
-
return dir !== undefined && isAbsolute(dir) ? dir :
|
|
886
|
+
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
664
887
|
}
|
|
665
|
-
function usagePath(env =
|
|
666
|
-
return
|
|
888
|
+
function usagePath(env = process11.env) {
|
|
889
|
+
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
667
890
|
}
|
|
668
|
-
function usageRecorded(env =
|
|
891
|
+
function usageRecorded(env = process11.env) {
|
|
669
892
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
670
893
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
671
894
|
}
|
|
@@ -679,12 +902,12 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
679
902
|
usageError = undefined;
|
|
680
903
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
681
904
|
}
|
|
682
|
-
function recordUsage(entry, env =
|
|
905
|
+
function recordUsage(entry, env = process11.env) {
|
|
683
906
|
if (!usageRecorded(env))
|
|
684
907
|
return;
|
|
685
908
|
try {
|
|
686
909
|
const path = usagePath(env);
|
|
687
|
-
mkdirSync(
|
|
910
|
+
mkdirSync(dirname2(path), { recursive: true, mode: 448 });
|
|
688
911
|
appendFileSync(path, `${JSON.stringify(entry)}
|
|
689
912
|
`, { mode: 384 });
|
|
690
913
|
} catch {}
|
|
@@ -770,8 +993,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
770
993
|
`);
|
|
771
994
|
}
|
|
772
995
|
function printError(prefix, message, hint, cause) {
|
|
773
|
-
const colors = paint(
|
|
774
|
-
const styled = takesControlCodes(
|
|
996
|
+
const colors = paint(process12.stderr);
|
|
997
|
+
const styled = takesControlCodes(process12.stderr);
|
|
775
998
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
776
999
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
777
1000
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -814,11 +1037,11 @@ async function dispatch(level, typed, { version, redact }) {
|
|
|
814
1037
|
}
|
|
815
1038
|
}
|
|
816
1039
|
if (name === undefined && level.path.length > 1) {
|
|
817
|
-
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1040
|
+
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process12.stderr));
|
|
818
1041
|
return 2;
|
|
819
1042
|
}
|
|
820
1043
|
if (name === undefined || name === "help" || name === "--help" || name === "-h") {
|
|
821
|
-
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1044
|
+
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process12.stdout));
|
|
822
1045
|
return 0;
|
|
823
1046
|
}
|
|
824
1047
|
if (level.path.length === 1 && (name === "--version" || name === "-v")) {
|
|
@@ -935,17 +1158,17 @@ async function printCandidates(found) {
|
|
|
935
1158
|
return 0;
|
|
936
1159
|
}
|
|
937
1160
|
function packageVersion(entry = Bun.main) {
|
|
938
|
-
for (let dir =
|
|
1161
|
+
for (let dir = dirname3(realpathSync(entry));; dir = dirname3(dir)) {
|
|
939
1162
|
try {
|
|
940
|
-
const { version } = JSON.parse(
|
|
1163
|
+
const { version } = JSON.parse(readFileSync2(join5(dir, "package.json"), "utf8"));
|
|
941
1164
|
if (typeof version === "string")
|
|
942
1165
|
return version;
|
|
943
1166
|
} catch {}
|
|
944
|
-
if (
|
|
1167
|
+
if (dirname3(dir) === dir)
|
|
945
1168
|
return "0.0.0";
|
|
946
1169
|
}
|
|
947
1170
|
}
|
|
948
|
-
async function runCli(cli, argv =
|
|
1171
|
+
async function runCli(cli, argv = process12.argv.slice(2)) {
|
|
949
1172
|
const version = cli.version ?? packageVersion();
|
|
950
1173
|
if (argv[0] === COMPLETE)
|
|
951
1174
|
return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
|
|
@@ -972,7 +1195,7 @@ function commandPath(scope, argv) {
|
|
|
972
1195
|
}
|
|
973
1196
|
return path.length === 0 ? undefined : path.join(" ");
|
|
974
1197
|
}
|
|
975
|
-
async function runMain({ name, version, run, redact, usage }, argv =
|
|
1198
|
+
async function runMain({ name, version, run, redact, usage }, argv = process12.argv.slice(2)) {
|
|
976
1199
|
if (argv[0] === COMPLETE)
|
|
977
1200
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
978
1201
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
@@ -1016,7 +1239,7 @@ function parseSize(text, bareUnit = 1) {
|
|
|
1016
1239
|
return Math.round(Number(match[1]) * (suffix === "" ? bareUnit : 1024 ** POWERS[suffix]));
|
|
1017
1240
|
}
|
|
1018
1241
|
// ../kit/src/watch.ts
|
|
1019
|
-
import
|
|
1242
|
+
import process13 from "process";
|
|
1020
1243
|
import { format } from "util";
|
|
1021
1244
|
var CLEAR_SCREEN = "\x1B[H\x1B[2J";
|
|
1022
1245
|
var DEFAULT_SECONDS = 2;
|
|
@@ -1038,7 +1261,7 @@ function withoutWatch(args) {
|
|
|
1038
1261
|
}
|
|
1039
1262
|
return rest;
|
|
1040
1263
|
}
|
|
1041
|
-
async function watching(value, step, stream =
|
|
1264
|
+
async function watching(value, step, stream = process13.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
|
|
1042
1265
|
const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
|
|
1043
1266
|
if (!takesControlCodes(stream))
|
|
1044
1267
|
badUsage("--watch redraws the screen, so it needs a terminal");
|
|
@@ -1046,12 +1269,12 @@ async function watching(value, step, stream = process10.stdout, sleep = Bun.slee
|
|
|
1046
1269
|
for (let round = 0;round < rounds; round++) {
|
|
1047
1270
|
const held = [];
|
|
1048
1271
|
const { log, info } = console;
|
|
1049
|
-
const write =
|
|
1272
|
+
const write = process13.stdout.write.bind(process13.stdout);
|
|
1050
1273
|
const hold = (...parts) => void held.push(`${format(...parts)}
|
|
1051
1274
|
`);
|
|
1052
1275
|
console.log = hold;
|
|
1053
1276
|
console.info = hold;
|
|
1054
|
-
|
|
1277
|
+
process13.stdout.write = (text) => {
|
|
1055
1278
|
held.push(typeof text === "string" ? text : Buffer.from(text).toString());
|
|
1056
1279
|
return true;
|
|
1057
1280
|
};
|
|
@@ -1060,7 +1283,7 @@ async function watching(value, step, stream = process10.stdout, sleep = Bun.slee
|
|
|
1060
1283
|
} finally {
|
|
1061
1284
|
console.log = log;
|
|
1062
1285
|
console.info = info;
|
|
1063
|
-
|
|
1286
|
+
process13.stdout.write = write;
|
|
1064
1287
|
}
|
|
1065
1288
|
stream.write(`${CLEAR_SCREEN}${held.join("")}`);
|
|
1066
1289
|
await sleep(interval);
|
|
@@ -1068,7 +1291,7 @@ async function watching(value, step, stream = process10.stdout, sleep = Bun.slee
|
|
|
1068
1291
|
return code;
|
|
1069
1292
|
}
|
|
1070
1293
|
// src/pid.ts
|
|
1071
|
-
import
|
|
1294
|
+
import process15 from "process";
|
|
1072
1295
|
|
|
1073
1296
|
// src/mask.ts
|
|
1074
1297
|
import { basename } from "path";
|
|
@@ -1459,9 +1682,9 @@ function limitLine(limits, name) {
|
|
|
1459
1682
|
return limit === undefined ? "-" : `soft ${limit.soft}, hard ${limit.hard}`;
|
|
1460
1683
|
}
|
|
1461
1684
|
function render(info, showEnv) {
|
|
1462
|
-
const colors = paint(
|
|
1685
|
+
const colors = paint(process15.stdout);
|
|
1463
1686
|
const memory = info.memory;
|
|
1464
|
-
const size = (bytes) => bytes === undefined ? "-" :
|
|
1687
|
+
const size = (bytes) => bytes === undefined ? "-" : tt(bytes);
|
|
1465
1688
|
const rows = [
|
|
1466
1689
|
["Executable", info.exe ?? "-"],
|
|
1467
1690
|
["Directory", info.cwd ?? "-"],
|
|
@@ -1511,4 +1734,4 @@ async function pid(args) {
|
|
|
1511
1734
|
}
|
|
1512
1735
|
|
|
1513
1736
|
// src/pid-cli.ts
|
|
1514
|
-
|
|
1737
|
+
process16.exitCode = await runMain({ name: "pid", run: pid });
|