@kaynooo/pkg-tools 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +11 -0
  2. package/dist/cli.js +1284 -617
  3. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -1,18 +1,30 @@
1
1
  #!/usr/bin/env bun
2
2
  // @bun
3
-
4
- // src/cli.ts
5
- import process7 from "process";
6
-
7
- // ../kit/src/args.ts
8
- import process3 from "process";
9
- import { parseArgs } from "util";
10
-
11
- // ../kit/src/format.ts
12
- import process2 from "process";
13
-
14
- // ../kit/src/style.ts
15
- import process from "process";
3
+ var __defProp = Object.defineProperty;
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
+ };
16
28
 
17
29
  // ../../node_modules/.bun/@kaynooo+utils@2.31.0+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-mtetydvc.js
18
30
  function x(s) {
@@ -94,9 +106,6 @@ function O(s) {
94
106
  function v(s, r, t, n) {
95
107
  return s /= 100, r /= 100, t /= 100, n /= 100, [Math.round(255 * (1 - s) * (1 - n)), Math.round(255 * (1 - r) * (1 - n)), Math.round(255 * (1 - t) * (1 - n))];
96
108
  }
97
- var m = (s) => s <= 0.04045 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
98
- var p = (s) => s <= 0.0031308 ? 12.92 * s : 1.055 * s ** 0.4166666666666667 - 0.055;
99
- var i = (s, r) => Math.round(s * 10 ** r) / 10 ** r;
100
109
  function T(s) {
101
110
  let r = m(s[0] / 255), t = m(s[1] / 255), n = m(s[2] / 255), a = Math.cbrt(0.4122214708 * r + 0.5363325363 * t + 0.0514459929 * n), b = Math.cbrt(0.2119034982 * r + 0.6806995451 * t + 0.1073969566 * n), o = Math.cbrt(0.0883024619 * r + 0.2817188376 * t + 0.6299787005 * n);
102
111
  return [i(0.2104542553 * a + 0.793617785 * b - 0.0040720468 * o, 4), i(1.9779984951 * a - 2.428592205 * b + 0.4505937099 * o, 4), i(0.0259040371 * a + 0.7827717662 * b - 0.808675766 * o, 4)];
@@ -233,16 +242,10 @@ class e {
233
242
  return t >= n ? s : r;
234
243
  }
235
244
  }
245
+ var m = (s) => s <= 0.04045 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4, p = (s) => s <= 0.0031308 ? 12.92 * s : 1.055 * s ** 0.4166666666666667 - 0.055, i = (s, r) => Math.round(s * 10 ** r) / 10 ** r;
246
+ var init_chunk_mtetydvc = () => {};
236
247
 
237
248
  // ../../node_modules/.bun/@kaynooo+utils@2.31.0+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-y1msbssb.js
238
- var r = 39;
239
- var o = 49;
240
- var f2 = "\x1B[";
241
- var C2 = { reset: [0, 0], bold: [1, 22], dim: [2, 22], italic: [3, 23], underline: [4, 24], inverse: [7, 27], hidden: [8, 28], strikethrough: [9, 29], black: [30, r], red: [31, r], green: [32, r], yellow: [33, r], blue: [34, r], magenta: [35, r], cyan: [36, r], white: [37, r], gray: [90, r], grey: [90, r], blackBright: [90, r], redBright: [91, r], greenBright: [92, r], yellowBright: [93, r], blueBright: [94, r], magentaBright: [95, r], cyanBright: [96, r], whiteBright: [97, r], bgBlack: [40, o], bgRed: [41, o], bgGreen: [42, o], bgYellow: [43, o], bgBlue: [44, o], bgMagenta: [45, o], bgCyan: [46, o], bgWhite: [47, o], bgBlackBright: [100, o], bgRedBright: [101, o], bgGreenBright: [102, o], bgYellowBright: [103, o], bgBlueBright: [104, o], bgMagentaBright: [105, o], bgCyanBright: [106, o], bgWhiteBright: [107, o], rgb: (i, n, a, l = "fg") => [`${l === "fg" ? 38 : 48};2;${i};${n};${a}`, l === "fg" ? r : o], hex: (i, n = "fg") => {
242
- let [a, l, s] = e.from("hex", i).to("rgb");
243
- return [`${n === "fg" ? 38 : 48};2;${a};${l};${s}`, n === "fg" ? r : o];
244
- }, ansi256: (i, n = "fg") => [`${n === "fg" ? 38 : 48};5;${i}`, n === "fg" ? r : o] };
245
- var b = new Set(["", "1", "2", "3", "true"]);
246
249
  function h(i, n = globalThis.process?.env ?? {}) {
247
250
  if (n.FORCE_COLOR !== undefined)
248
251
  return b.has(n.FORCE_COLOR);
@@ -273,26 +276,69 @@ function u(i, n = []) {
273
276
  function le(i = {}) {
274
277
  return u(i);
275
278
  }
276
- var t = le();
279
+ var r = 39, o = 49, f2 = "\x1B[", C2, b, t;
280
+ var init_chunk_y1msbssb = __esm(() => {
281
+ init_chunk_mtetydvc();
282
+ C2 = { reset: [0, 0], bold: [1, 22], dim: [2, 22], italic: [3, 23], underline: [4, 24], inverse: [7, 27], hidden: [8, 28], strikethrough: [9, 29], black: [30, r], red: [31, r], green: [32, r], yellow: [33, r], blue: [34, r], magenta: [35, r], cyan: [36, r], white: [37, r], gray: [90, r], grey: [90, r], blackBright: [90, r], redBright: [91, r], greenBright: [92, r], yellowBright: [93, r], blueBright: [94, r], magentaBright: [95, r], cyanBright: [96, r], whiteBright: [97, r], bgBlack: [40, o], bgRed: [41, o], bgGreen: [42, o], bgYellow: [43, o], bgBlue: [44, o], bgMagenta: [45, o], bgCyan: [46, o], bgWhite: [47, o], bgBlackBright: [100, o], bgRedBright: [101, o], bgGreenBright: [102, o], bgYellowBright: [103, o], bgBlueBright: [104, o], bgMagentaBright: [105, o], bgCyanBright: [106, o], bgWhiteBright: [107, o], rgb: (i, n, a, l = "fg") => [`${l === "fg" ? 38 : 48};2;${i};${n};${a}`, l === "fg" ? r : o], hex: (i, n = "fg") => {
283
+ let [a, l, s] = e.from("hex", i).to("rgb");
284
+ return [`${n === "fg" ? 38 : 48};2;${a};${l};${s}`, n === "fg" ? r : o];
285
+ }, ansi256: (i, n = "fg") => [`${n === "fg" ? 38 : 48};5;${i}`, n === "fg" ? r : o] };
286
+ b = new Set(["", "1", "2", "3", "true"]);
287
+ t = le();
288
+ });
289
+
290
+ // ../../node_modules/.bun/@kaynooo+utils@2.31.0+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/tools/colors.js
291
+ var init_colors = __esm(() => {
292
+ init_chunk_y1msbssb();
293
+ });
277
294
 
278
295
  // ../kit/src/style.ts
296
+ import process from "process";
279
297
  function takesControlCodes(stream, env = process.env) {
280
298
  return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb";
281
299
  }
282
300
  function paint(stream, env = process.env) {
283
301
  return le({ stream: { isTTY: takesControlCodes(stream, env) }, env });
284
302
  }
285
- var STATUSES = {
286
- passed: { symbol: "\u2713", words: ["passed", "success", "succeeded", "ok"], paint: (colors) => colors.green },
287
- failed: { symbol: "\u2717", words: ["failed", "failure", "error", "errored"], paint: (colors) => colors.red },
288
- running: { symbol: "\u25CF", words: ["running", "in_progress", "started"], paint: (colors) => colors.cyan },
289
- queued: { symbol: "\u25CB", words: ["queued", "waiting", "pending", "created", "blocked", "scheduled"], paint: (colors) => colors.yellow },
290
- skipped: { symbol: "-", words: ["skipped", "cancelled", "canceled", "manual"], paint: (colors) => colors.dim }
291
- };
292
- var STATUS_OF = new Map(Object.entries(STATUSES).flatMap(([status, { words }]) => words.map((word) => [word, status])));
303
+ function marked(mark, text, stream, detail, env = process.env) {
304
+ const colors = paint(stream, env);
305
+ const { symbol, word, paint: tint } = MARKS[mark];
306
+ const head = takesControlCodes(stream, env) ? tint(colors)(symbol) : word;
307
+ return `${head} ${text}${detail === undefined ? "" : ` ${colors.dim(detail)}`}`;
308
+ }
309
+ function ok(text, detail) {
310
+ console.log(marked("ok", text, process.stdout, detail));
311
+ }
312
+ function note(text, detail) {
313
+ console.log(marked("note", text, process.stdout, detail));
314
+ }
315
+ function warn(text, detail) {
316
+ console.error(marked("warn", text, process.stderr, detail));
317
+ }
318
+ function problem(text, detail) {
319
+ console.error(marked("problem", text, process.stderr, detail));
320
+ }
321
+ var MARKS, STATUSES, STATUS_OF;
322
+ var init_style = __esm(() => {
323
+ init_colors();
324
+ MARKS = {
325
+ ok: { symbol: "\u2713", word: "ok:", paint: (colors) => colors.green },
326
+ warn: { symbol: "!", word: "warning:", paint: (colors) => colors.yellow },
327
+ problem: { symbol: "\u2717", word: "error:", paint: (colors) => colors.red },
328
+ note: { symbol: "\xB7", word: "note:", paint: (colors) => colors.dim }
329
+ };
330
+ STATUSES = {
331
+ passed: { symbol: "\u2713", words: ["passed", "success", "succeeded", "ok"], paint: (colors) => colors.green },
332
+ failed: { symbol: "\u2717", words: ["failed", "failure", "error", "errored"], paint: (colors) => colors.red },
333
+ running: { symbol: "\u25CF", words: ["running", "in_progress", "started"], paint: (colors) => colors.cyan },
334
+ queued: { symbol: "\u25CB", words: ["queued", "waiting", "pending", "created", "blocked", "scheduled"], paint: (colors) => colors.yellow },
335
+ skipped: { symbol: "-", words: ["skipped", "cancelled", "canceled", "manual"], paint: (colors) => colors.dim }
336
+ };
337
+ STATUS_OF = new Map(Object.entries(STATUSES).flatMap(([status, { words }]) => words.map((word) => [word, status])));
338
+ });
293
339
 
294
340
  // ../kit/src/format.ts
295
- var UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
341
+ import process2 from "process";
296
342
  function formatSeconds(total) {
297
343
  let rest = Math.max(0, Math.round(total));
298
344
  const amounts = UNITS.map(([unit, size]) => {
@@ -306,6 +352,9 @@ function formatSeconds(total) {
306
352
  const next = amounts[first + 1];
307
353
  return next === undefined || next.startsWith("0") ? amounts[first] ?? "0s" : `${amounts[first]} ${next}`;
308
354
  }
355
+ function formatDuration(ms) {
356
+ return ms < 60000 ? `${(Math.max(0, ms) / 1000).toFixed(1)}s` : formatSeconds(ms / 1000);
357
+ }
309
358
  function upTo(text, separator) {
310
359
  const end = text.indexOf(separator);
311
360
  return end === -1 ? text : text.slice(0, end);
@@ -320,8 +369,6 @@ function formatAge(date, now = Date.now()) {
320
369
  function truncate(text, width) {
321
370
  return text.length <= width ? text : `${text.slice(0, Math.max(0, width - 1))}\u2026`;
322
371
  }
323
- var LINE_BREAKS = /\s*\n\s*/g;
324
- var ESCAPE = String.fromCharCode(27);
325
372
  function textWidth(text) {
326
373
  return Bun.stringWidth(text);
327
374
  }
@@ -363,56 +410,45 @@ function narrow(rows, widths, limit) {
363
410
  function printJson(value) {
364
411
  console.log(JSON.stringify(value, undefined, 2));
365
412
  }
413
+ var UNITS, LINE_BREAKS, ESCAPE;
414
+ var init_format = __esm(() => {
415
+ init_style();
416
+ UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
417
+ LINE_BREAKS = /\s*\n\s*/g;
418
+ ESCAPE = String.fromCharCode(27);
419
+ });
366
420
 
367
421
  // ../kit/src/args.ts
422
+ import process3 from "process";
423
+ import { parseArgs } from "util";
368
424
  function jsonOption(holds) {
369
425
  return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
370
426
  }
371
-
372
- class Exit extends Error {
373
- code;
374
- hint;
375
- constructor(message, code, hint) {
376
- super(message);
377
- this.code = code;
378
- this.hint = hint;
379
- }
380
- }
381
427
  function fail(message, code = 2, hint) {
382
428
  throw new Exit(message, code, hint);
383
429
  }
384
-
385
- class UsageError extends Exit {
386
- constructor(message) {
387
- super(message, 2);
388
- }
389
- }
390
430
  function badUsage(message) {
391
431
  throw new UsageError(message);
392
432
  }
393
433
 
394
- class HelpShown extends Exit {
395
- constructor() {
396
- super("help shown", 0);
397
- }
398
- }
399
-
400
434
  class Completing {
401
435
  options;
402
436
  constructor(options) {
403
437
  this.options = options;
404
438
  }
405
439
  }
406
- var completion = { active: false };
407
- var OPTIONAL = /\[[^\]]+\]/g;
408
- var USAGE_PREFIX = /^usage:\s*/i;
409
440
  function usageLine(usage, colors = paint(process3.stdout)) {
410
441
  return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
411
442
  }
412
- function helpText(usage, options, colors = paint(process3.stdout)) {
413
- return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors)].join(`
443
+ function helpText(usage, options, colors = paint(process3.stdout), examples = []) {
444
+ return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exampleRows(examples, colors)].join(`
414
445
  `);
415
446
  }
447
+ function exampleRows(examples, colors = paint(process3.stdout)) {
448
+ if (examples.length === 0)
449
+ return [];
450
+ return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
451
+ }
416
452
  function optionRows(options, colors = paint(process3.stdout)) {
417
453
  const rows = Object.entries(options).map(([name, option]) => {
418
454
  const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
@@ -422,8 +458,23 @@ function optionRows(options, colors = paint(process3.stdout)) {
422
458
  const width = Math.max(0, ...rows.map((row) => row.width));
423
459
  return rows.map((row) => ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
424
460
  }
461
+ function applyOutput(color, plain, env = process3.env) {
462
+ const when = plain === true ? "never" : color ?? "auto";
463
+ if (when === "auto")
464
+ return;
465
+ if (when !== "always" && when !== "never")
466
+ badUsage(`--color takes auto, always or never, not ${when}`);
467
+ if (when === "always") {
468
+ env.FORCE_COLOR = "1";
469
+ delete env.NO_COLOR;
470
+ } else {
471
+ env.NO_COLOR = "1";
472
+ delete env.FORCE_COLOR;
473
+ }
474
+ }
425
475
  function parse(args, usage, options, settings = {}) {
426
- const all = { ...options, help: { type: "boolean", short: "h", description: "show this help" } };
476
+ const output = Object.fromEntries(Object.entries(OUTPUT_OPTIONS).filter(([name]) => !(name in options)));
477
+ const all = { ...options, ...output, help: { type: "boolean", short: "h", description: "show this help" } };
427
478
  if (completion.active)
428
479
  throw new Completing(all);
429
480
  const separator = settings.rest === true ? args.indexOf("--") : -1;
@@ -435,8 +486,10 @@ function parse(args, usage, options, settings = {}) {
435
486
  } catch (error) {
436
487
  badUsage(parseError(error));
437
488
  }
438
- if (parsed.values.help === true) {
439
- console.log(helpText(usage, all));
489
+ const values = parsed.values;
490
+ applyOutput("color" in output ? values.color : undefined, "plain" in output ? values.plain : undefined);
491
+ if (values.help === true) {
492
+ console.log(helpText(usage, all, undefined, settings.examples));
440
493
  throw new HelpShown;
441
494
  }
442
495
  if (settings.positionals !== undefined)
@@ -463,11 +516,56 @@ function wholeNumber(value, name, fallback, min = 1) {
463
516
  badUsage(`--${name} takes a whole number from ${min}, not ${value}`);
464
517
  return number;
465
518
  }
466
- // ../kit/src/cli.ts
467
- import process4 from "process";
519
+ function duration(value, name, fallback, unit = "s") {
520
+ if (value === undefined)
521
+ return fallback;
522
+ const match = DURATION.exec(value.trim());
523
+ const ms = match === null ? 0 : Number(match[1]) * UNIT_MS[match[2] ?? unit];
524
+ if (ms < 1)
525
+ badUsage(`--${name} takes a duration such as 30s, 5m or 1h, not ${value}`);
526
+ return ms;
527
+ }
528
+ var Exit, UsageError, HelpShown, completion, OPTIONAL, USAGE_PREFIX, OUTPUT_OPTIONS, DURATION, UNIT_MS;
529
+ var init_args = __esm(() => {
530
+ init_format();
531
+ init_style();
532
+ Exit = class Exit extends Error {
533
+ code;
534
+ hint;
535
+ constructor(message, code, hint) {
536
+ super(message);
537
+ this.code = code;
538
+ this.hint = hint;
539
+ }
540
+ };
541
+ UsageError = class UsageError extends Exit {
542
+ constructor(message) {
543
+ super(message, 2);
544
+ }
545
+ };
546
+ HelpShown = class HelpShown extends Exit {
547
+ constructor() {
548
+ super("help shown", 0);
549
+ }
550
+ };
551
+ completion = { active: false };
552
+ OPTIONAL = /\[[^\]]+\]/g;
553
+ USAGE_PREFIX = /^usage:\s*/i;
554
+ OUTPUT_OPTIONS = {
555
+ color: { type: "string", description: "auto (on a terminal alone), always or never" },
556
+ plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
557
+ };
558
+ DURATION = /^(\d+(?:\.\d+)?)(ms|[smh])?$/;
559
+ UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000 };
560
+ });
561
+
562
+ // ../kit/src/chart.ts
563
+ var init_chart = __esm(() => {
564
+ init_format();
565
+ init_style();
566
+ });
468
567
 
469
568
  // ../kit/src/text.ts
470
- var ANSI = new RegExp(`${String.fromCharCode(27)}\\[[\\d;?]*[a-z]`, "gi");
471
569
  function distance(a, b) {
472
570
  let previous = Array.from({ length: b.length + 1 }, (_, index) => index);
473
571
  for (const [i, left] of [...a].entries()) {
@@ -478,8 +576,68 @@ function distance(a, b) {
478
576
  }
479
577
  return previous[b.length] ?? 0;
480
578
  }
579
+ var ANSI;
580
+ var init_text = __esm(() => {
581
+ ANSI = new RegExp(`${String.fromCharCode(27)}\\[[\\d;?]*[a-z]`, "gi");
582
+ });
481
583
 
482
584
  // ../kit/src/cli.ts
585
+ import process4 from "process";
586
+ function commandRows(commands, colors) {
587
+ const width = Math.max(...Object.keys(commands).map((name) => name.length));
588
+ const groups = new Map([["Commands:", []]]);
589
+ for (const [name, { summary, group }] of Object.entries(commands)) {
590
+ const heading = group === undefined ? "Commands:" : `${group}:`;
591
+ const rows = groups.get(heading) ?? [];
592
+ rows.push(` ${colors.cyan(name.padEnd(width))} ${colors.dim(summary)}`);
593
+ groups.set(heading, rows);
594
+ }
595
+ return [...groups].filter(([, rows]) => rows.length > 0).flatMap(([heading, rows], index) => [...index === 0 ? [] : [""], colors.bold(heading), ...rows]);
596
+ }
597
+ function takeOutputFlags(argv) {
598
+ let index = 0;
599
+ for (;index < argv.length; index++) {
600
+ const word = argv[index];
601
+ if (word === "--plain")
602
+ applyOutput(undefined, true);
603
+ else if (word.startsWith("--color="))
604
+ applyOutput(word.slice("--color=".length), undefined);
605
+ else if (word === "--color" && argv[index + 1] !== undefined)
606
+ applyOutput(argv[++index], undefined);
607
+ else
608
+ break;
609
+ }
610
+ return argv.slice(index);
611
+ }
612
+ function closest(name, names) {
613
+ const started = names.find((known) => known.startsWith(name));
614
+ if (started !== undefined)
615
+ return started;
616
+ const [best] = names.map((known) => ({ known, far: distance(name, known) })).sort((a, b) => a.far - b.far);
617
+ return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
618
+ }
619
+ async function help({ path, header, commands, defaultCommand, examples }, stream) {
620
+ const colors = paint(stream);
621
+ const prefix = path.join(" ");
622
+ const fallback = defaultCommand === undefined ? undefined : commands[defaultCommand];
623
+ const options = fallback !== undefined && "run" in fallback ? await optionsOf(fallback.run) : undefined;
624
+ const own = Object.entries(options ?? {}).filter(([name]) => !(name in TOP_OPTIONS));
625
+ return [
626
+ header(colors),
627
+ "",
628
+ usageLine(`${prefix} ${defaultCommand === undefined ? colors.cyan("<command>") : `[${colors.cyan("<command>")}]`} [options]`, colors),
629
+ "",
630
+ ...commandRows(commands, colors),
631
+ ...own.length === 0 ? [] : ["", `${colors.bold(`Options of ${defaultCommand}:`)} ${colors.dim("the command run when none is named")}`, ...optionRows(Object.fromEntries(own), colors)],
632
+ "",
633
+ colors.bold("Options:"),
634
+ ...optionRows(path.length === 1 ? TOP_OPTIONS : LEVEL_OPTIONS, colors),
635
+ ...exampleRows(examples ?? [], colors),
636
+ "",
637
+ `${colors.dim("Run")} ${prefix} ${colors.cyan("<command>")} --help ${colors.dim("for its options.")}`
638
+ ].join(`
639
+ `);
640
+ }
483
641
  function printError(prefix, message, hint, cause) {
484
642
  const colors = paint(process4.stderr);
485
643
  const styled = takesControlCodes(process4.stderr);
@@ -497,8 +655,48 @@ function reportThrown(prefix, error, redact = (text) => text) {
497
655
  printError(prefix, redact(named ?? (error instanceof Error ? error.message : String(error))), error instanceof Exit ? error.hint ?? help : undefined, cause);
498
656
  return error instanceof Exit ? error.code : 1;
499
657
  }
500
- var COMPLETE = "__complete";
501
- var FILES = "__files__";
658
+ async function dispatch(level, typed, { version, redact }) {
659
+ const prefix = level.path.join(" ");
660
+ let argv;
661
+ try {
662
+ argv = takeOutputFlags(typed);
663
+ } catch (error) {
664
+ return reportThrown(prefix, error);
665
+ }
666
+ const [name, ...args] = argv;
667
+ if (name === undefined && level.path.length > 1) {
668
+ console.error(await help(level, process4.stderr));
669
+ return 2;
670
+ }
671
+ if (name === undefined || name === "help" || name === "--help" || name === "-h") {
672
+ console.log(await help(level, process4.stdout));
673
+ return 0;
674
+ }
675
+ if (level.path.length === 1 && (name === "--version" || name === "-v")) {
676
+ console.log(version);
677
+ return 0;
678
+ }
679
+ let command = level.commands[level.aliases?.[name] ?? name];
680
+ let rest = args;
681
+ if (command === undefined && level.defaultCommand !== undefined) {
682
+ command = level.commands[level.defaultCommand];
683
+ rest = argv;
684
+ }
685
+ if (command === undefined) {
686
+ const meant = closest(name, Object.keys(level.commands));
687
+ printError(prefix, `no command ${name}`, meant === undefined ? `run ${prefix} --help for its commands` : `did you mean ${meant}?`);
688
+ return 2;
689
+ }
690
+ if ("commands" in command) {
691
+ const { summary } = command;
692
+ return dispatch({ path: [...level.path, name], header: (colors) => `${colors.bold(`${prefix} ${name}`)} ${summary}`, commands: command.commands, aliases: command.aliases, defaultCommand: undefined, examples: command.examples }, rest, { version, redact });
693
+ }
694
+ try {
695
+ return await command.run(rest);
696
+ } catch (error) {
697
+ return reportThrown(`${prefix} ${name}`, error, redact);
698
+ }
699
+ }
502
700
  async function optionsOf(run) {
503
701
  completion.active = true;
504
702
  try {
@@ -516,534 +714,622 @@ async function leafCandidates(run, words) {
516
714
  return [FILES];
517
715
  return Object.entries(await optionsOf(run)).map(([name, option]) => `--${name} ${option.description}`);
518
716
  }
717
+ async function candidates(commands, aliases, defaultCommand, words) {
718
+ const [word = "", ...rest] = words;
719
+ const command = commands[aliases?.[word] ?? word];
720
+ if (rest.length === 0 && !word.startsWith("-"))
721
+ return Object.entries(commands).map(([name, { summary }]) => `${name} ${summary}`);
722
+ if (command === undefined) {
723
+ const fallback = defaultCommand === undefined ? undefined : commands[defaultCommand];
724
+ return fallback !== undefined && "run" in fallback ? leafCandidates(fallback.run, words) : [];
725
+ }
726
+ return "commands" in command ? candidates(command.commands, command.aliases, undefined, rest) : leafCandidates(command.run, rest);
727
+ }
519
728
  async function printCandidates(found) {
520
729
  for (const line of await found)
521
730
  console.log(line);
522
731
  return 0;
523
732
  }
524
- async function runMain({ name, version, run, redact }, argv = process4.argv.slice(2)) {
733
+ async function runCli(cli, argv = process4.argv.slice(2)) {
525
734
  if (argv[0] === COMPLETE)
526
- return printCandidates(leafCandidates(run, argv.slice(1)));
527
- if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
528
- console.log(version);
529
- return 0;
530
- }
531
- try {
532
- return await run(argv);
533
- } catch (error) {
534
- return reportThrown(name, error, redact);
735
+ return printCandidates(candidates(cli.commands, cli.aliases, cli.defaultCommand, argv.slice(1)));
736
+ return dispatch({ path: [cli.name], header: (colors) => `${colors.bold(cli.name)} ${colors.dim(cli.version)} ${cli.about}`, commands: cli.commands, aliases: cli.aliases, defaultCommand: cli.defaultCommand, examples: cli.examples }, argv, { version: cli.version, redact: cli.redact });
737
+ }
738
+ var LEVEL_OPTIONS, TOP_OPTIONS, COMPLETE = "__complete", FILES = "__files__";
739
+ var init_cli = __esm(() => {
740
+ init_args();
741
+ init_style();
742
+ init_text();
743
+ LEVEL_OPTIONS = {
744
+ ...OUTPUT_OPTIONS,
745
+ help: { type: "boolean", short: "h", description: "show this help" }
746
+ };
747
+ TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
748
+ });
749
+
750
+ // ../kit/src/config.ts
751
+ var init_config = __esm(() => {
752
+ init_args();
753
+ });
754
+
755
+ // ../kit/src/process.ts
756
+ import { constants } from "os";
757
+ import process5 from "process";
758
+ async function collect(stream, name, chunks) {
759
+ for await (const data of stream)
760
+ chunks.push({ stream: name, data });
761
+ }
762
+ function exitCodeOf(code, signal) {
763
+ if (code !== null)
764
+ return code;
765
+ if (typeof signal === "number")
766
+ return 128 + signal;
767
+ return signal === null ? 129 : 128 + constants.signals[signal];
768
+ }
769
+ function holdSignals(cleanup) {
770
+ let received;
771
+ let child;
772
+ const held = {
773
+ get signal() {
774
+ return received;
775
+ },
776
+ forward: (to) => {
777
+ child = to;
778
+ },
779
+ release: () => {
780
+ for (const signal of SIGNALS)
781
+ process5.off(signal, onSignal);
782
+ }
783
+ };
784
+ function onSignal(signal) {
785
+ received = signal;
786
+ if (child !== undefined) {
787
+ child.kill(signal);
788
+ return;
789
+ }
790
+ if (cleanup === undefined)
791
+ return;
792
+ held.release();
793
+ cleanup(signal);
794
+ process5.kill(process5.pid, signal);
535
795
  }
536
- }
537
- // package.json
538
- var version = "0.2.1";
796
+ for (const signal of SIGNALS)
797
+ process5.on(signal, onSignal);
798
+ return held;
799
+ }
800
+ async function runCommand(argv, { cwd, env, stdin = "ignore" } = {}) {
801
+ const chunks = [];
802
+ const proc = Bun.spawn(argv, { ...cwd === undefined ? {} : { cwd }, ...env === undefined ? {} : { env }, stdin, stdout: "pipe", stderr: "pipe" });
803
+ await Promise.all([collect(proc.stdout, "stdout", chunks), collect(proc.stderr, "stderr", chunks)]);
804
+ await proc.exited;
805
+ const output = Buffer.concat(chunks.map(({ data }) => data));
806
+ return { code: exitCodeOf(proc.exitCode, proc.signalCode), chunks, output, text: output.toString() };
807
+ }
808
+ var SIGNALS;
809
+ var init_process = __esm(() => {
810
+ SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
811
+ });
812
+
813
+ // ../kit/src/index.ts
814
+ var init_src = __esm(() => {
815
+ init_args();
816
+ init_chart();
817
+ init_cli();
818
+ init_config();
819
+ init_format();
820
+ init_process();
821
+ init_style();
822
+ init_text();
823
+ });
539
824
 
540
825
  // src/popular.json
541
- var popular_default = [
542
- "semver",
543
- "minimatch",
544
- "debug",
545
- "ansi-styles",
546
- "brace-expansion",
547
- "strip-ansi",
548
- "ansi-regex",
549
- "ms",
550
- "supports-color",
551
- "chalk",
552
- "commander",
553
- "lru-cache",
554
- "string-width",
555
- "wrap-ansi",
556
- "tslib",
557
- "picomatch",
558
- "emoji-regex",
559
- "glob",
560
- "type-fest",
561
- "color-name",
562
- "eslint-visitor-keys",
563
- "color-convert",
564
- "ajv",
565
- "minipass",
566
- "source-map",
567
- "balanced-match",
568
- "readable-stream",
569
- "which",
570
- "glob-parent",
571
- "escape-string-regexp",
572
- "has-flag",
573
- "find-up",
574
- "locate-path",
575
- "json-schema-traverse",
576
- "p-limit",
577
- "yallist",
578
- "safe-buffer",
579
- "uuid",
580
- "p-locate",
581
- "undici-types",
582
- "ignore",
583
- "iconv-lite",
584
- "signal-exit",
585
- "esbuild",
586
- "is-fullwidth-code-point",
587
- "js-yaml",
588
- "entities",
589
- "globals",
590
- "postcss",
591
- "isexe",
592
- "isarray",
593
- "path-key",
594
- "string_decoder",
595
- "argparse",
596
- "ws",
597
- "mime-db",
598
- "resolve",
599
- "agent-base",
600
- "@esbuild/linux-x64",
601
- "yargs-parser",
602
- "mime-types",
603
- "acorn",
604
- "estraverse",
605
- "cross-spawn",
606
- "react-is",
607
- "picocolors",
608
- "fs-extra",
609
- "hasown",
610
- "nanoid",
611
- "yargs",
612
- "resolve-from",
613
- "shebang-command",
614
- "pretty-format",
615
- "json5",
616
- "https-proxy-agent",
617
- "path-to-regexp",
618
- "path-exists",
619
- "punycode",
620
- "js-tokens",
621
- "cliui",
622
- "shebang-regex",
623
- "@babel/types",
624
- "chokidar",
625
- "strip-json-comments",
626
- "inherits",
627
- "webidl-conversions",
628
- "get-stream",
629
- "eslint-scope",
630
- "cookie",
631
- "@babel/parser",
632
- "qs",
633
- "is-number",
634
- "whatwg-url",
635
- "@types/estree",
636
- "tr46",
637
- "convert-source-map",
638
- "is-glob",
639
- "braces",
640
- "fast-deep-equal",
641
- "form-data",
642
- "lodash",
643
- "@babel/helper-validator-identifier",
644
- "electron-to-chromium",
645
- "fill-range",
646
- "function-bind",
647
- "readdirp",
648
- "escalade",
649
- "graceful-fs",
650
- "negotiator",
651
- "is-stream",
652
- "camelcase",
653
- "@babel/runtime",
654
- "yocto-queue",
655
- "to-regex-range",
656
- "node-fetch",
657
- "micromatch",
658
- "node-releases",
659
- "get-intrinsic",
660
- "universalify",
661
- "path-scurry",
662
- "jsesc",
663
- "browserslist",
664
- "es-errors",
665
- "statuses",
666
- "@radix-ui/react-primitive",
667
- "magic-string",
668
- "rimraf",
669
- "is-extglob",
670
- "@jridgewell/trace-mapping",
671
- "@jridgewell/resolve-uri",
672
- "http-errors",
673
- "onetime",
674
- "has-symbols",
675
- "es-define-property",
676
- "gopd",
677
- "util-deprecate",
678
- "object-assign",
679
- "jiti",
680
- "yaml",
681
- "dotenv",
682
- "@babel/generator",
683
- "@babel/template",
684
- "imurmurhash",
685
- "postcss-selector-parser",
686
- "fast-glob",
687
- "update-browserslist-db",
688
- "@types/node",
689
- "@babel/compat-data",
690
- "eventemitter3",
691
- "callsites",
692
- "http-proxy-agent",
693
- "detect-libc",
694
- "espree",
695
- "execa",
696
- "@babel/core",
697
- "@babel/helpers",
698
- "concat-map",
699
- "source-map-js",
700
- "tinyglobby",
701
- "call-bind-apply-helpers",
702
- "flat-cache",
703
- "fdir",
704
- "pify",
705
- "@jest/types",
706
- "normalize-path",
707
- "is-core-module",
708
- "eslint",
709
- "minimist",
710
- "estree-walker",
711
- "file-entry-cache",
712
- "object-inspect",
713
- "buffer",
714
- "uri-js",
715
- "import-fresh",
716
- "@babel/helper-module-transforms",
717
- "optionator",
718
- "flatted",
719
- "math-intrinsics",
720
- "safer-buffer",
721
- "y18n",
722
- "@babel/helper-module-imports",
723
- "mkdirp",
724
- "dunder-proto",
725
- "path-parse",
726
- "fastq",
727
- "levn",
728
- "@babel/helper-compilation-targets",
729
- "@babel/helper-string-parser",
730
- "keyv",
731
- "get-proto",
732
- "csstype",
733
- "npm-run-path",
734
- "fast-json-stable-stringify",
735
- "reusify",
736
- "@babel/helper-plugin-utils",
737
- "kind-of",
738
- "mime",
739
- "caniuse-lite",
740
- "lines-and-columns",
741
- "fast-levenshtein",
742
- "supports-preserve-symlinks-flag",
743
- "make-dir",
744
- "slash",
745
- "prelude-ls",
746
- "typescript",
747
- "strip-bom",
748
- "parent-module",
749
- "esutils",
750
- "ci-info",
751
- "@smithy/util-utf8",
752
- "type-check",
753
- "mimic-fn",
754
- "@babel/helper-validator-option",
755
- "@types/json-schema",
756
- "@rolldown/pluginutils",
757
- "side-channel-list",
758
- "json-buffer",
759
- "raw-body",
760
- "has-tostringtag",
761
- "wrappy",
762
- "diff",
763
- "jackspeak",
764
- "baseline-browser-mapping",
765
- "deep-is",
766
- "foreground-child",
767
- "@eslint/js",
768
- "anymatch",
769
- "natural-compare",
770
- "esquery",
771
- "@eslint-community/regexpp",
772
- "es-set-tostringtag",
773
- "acorn-jsx",
774
- "parse5",
775
- "finalhandler",
776
- "parse-json",
777
- "depd",
778
- "axios",
779
- "run-parallel",
780
- "source-map-support",
781
- "esrecurse",
782
- "call-bound",
783
- "content-disposition",
784
- "human-signals",
785
- "ts-api-utils",
786
- "ansi-escapes",
787
- "jest-util",
788
- "send",
789
- "@opentelemetry/core",
790
- "type-is",
791
- "encodeurl",
792
- "once",
793
- "cosmiconfig",
794
- "lodash.merge",
795
- "json-stable-stringify-without-jsonify",
796
- "open",
797
- "prettier",
798
- "@eslint/eslintrc",
799
- "is-arrayish",
800
- "@jridgewell/sourcemap-codec",
801
- "gensync",
802
- "word-wrap",
803
- "express",
804
- "arg",
805
- "jsonfile",
806
- "schema-utils",
807
- "@smithy/is-array-buffer",
808
- "@typescript-eslint/types",
809
- "chownr",
810
- "delayed-stream",
811
- "@smithy/util-buffer-from",
812
- "asynckit",
813
- "tapable",
814
- "enhanced-resolve",
815
- "aria-query",
816
- "indent-string",
817
- "bytes",
818
- "binary-extensions",
819
- "ini",
820
- "@radix-ui/react-context",
821
- "doctrine",
822
- "queue-microtask",
823
- "accepts",
824
- "merge2",
825
- "get-caller-file",
826
- "@humanwhocodes/retry",
827
- "@jridgewell/gen-mapping",
828
- "@typescript-eslint/typescript-estree",
829
- "jest-worker",
830
- "proxy-from-env",
831
- "clsx",
832
- "side-channel-map",
833
- "@typescript-eslint/visitor-keys",
834
- "fresh",
835
- "restore-cursor",
836
- "on-finished",
837
- "is-plain-obj",
838
- "ipaddr.js",
839
- "pathe",
840
- "@jest/schemas",
841
- "base64-js",
842
- "@smithy/types",
843
- "require-directory",
844
- "tough-cookie",
845
- "is-binary-path",
846
- "body-parser",
847
- "postcss-value-parser",
848
- "media-typer",
849
- "setprototypeof",
850
- "side-channel-weakmap",
851
- "@typescript-eslint/tsconfig-utils",
852
- "@isaacs/cliui",
853
- "@rollup/rollup-linux-x64-gnu",
854
- "is-wsl",
855
- "retry",
856
- "@aws-sdk/types",
857
- "@types/react-dom",
858
- "combined-stream",
859
- "es-object-atoms",
860
- "@eslint/core",
861
- "whatwg-mimetype",
862
- "domutils",
863
- "@rollup/rollup-linux-x64-musl",
864
- "core-util-is",
865
- "@typescript-eslint/scope-manager",
866
- "esprima",
867
- "loose-envify",
868
- "cookie-signature",
869
- "follow-redirects",
870
- "cli-cursor",
871
- "strip-final-newline",
872
- "@typescript-eslint/project-service",
873
- "eastasianwidth",
874
- "json-parse-even-better-errors",
875
- "sprintf-js",
876
- "path-type",
877
- "content-type",
878
- "es-module-lexer",
879
- "@nodelib/fs.scandir",
880
- "write-file-atomic",
881
- "@eslint/plugin-kit",
882
- "ieee754",
883
- "prop-types",
884
- "require-from-string",
885
- "dom-serializer",
886
- "call-bind",
887
- "@eslint/config-array",
888
- "has-property-descriptors",
889
- "@nodelib/fs.stat",
890
- "merge-descriptors",
891
- "slice-ansi",
892
- "rxjs",
893
- "p-map",
894
- "toidentifier",
895
- "globby",
896
- "domhandler",
897
- "async",
898
- "@babel/helper-globals",
899
- "pirates",
900
- "@opentelemetry/semantic-conventions",
901
- "@typescript-eslint/utils",
902
- "date-fns",
903
- "is-docker",
904
- "tar",
905
- "which-typed-array",
906
- "ajv-formats",
907
- "@opentelemetry/api-logs",
908
- "@opentelemetry/resources",
909
- "side-channel",
910
- "cjs-module-lexer",
911
- "range-parser",
912
- "@humanfs/node",
913
- "define-data-property",
914
- "node-addon-api",
915
- "pako",
916
- "lilconfig",
917
- "fast-uri",
918
- "ip-address",
919
- "fs.realpath",
920
- "@img/sharp-libvips-linuxmusl-x64",
921
- "cssesc",
922
- "@opentelemetry/instrumentation",
923
- "domelementtype",
924
- "hosted-git-info",
925
- "@eslint/object-schema",
926
- "etag",
927
- "@eslint/config-helpers",
928
- "package-json-from-dist",
929
- "@humanfs/core",
930
- "htmlparser2",
931
- "jest-message-util",
932
- "for-each",
933
- "pkg-dir",
934
- "unpipe",
935
- "buffer-from",
936
- "es-abstract",
937
- "is-unicode-supported",
938
- "@types/yargs",
939
- "is-callable",
940
- "fast-xml-parser",
941
- "istanbul-lib-instrument",
942
- "escape-html",
943
- "is-regex",
944
- "dom-accessibility-api",
945
- "css-tree",
946
- "error-ex",
947
- "ee-first",
948
- "@types/unist",
949
- "log-symbols",
950
- "path-is-absolute",
951
- "end-of-stream",
952
- "@vitest/utils",
953
- "object.assign",
954
- "object-keys",
955
- "tinyexec",
956
- "scheduler",
957
- "p-try",
958
- "process-nextick-args",
959
- "vary",
960
- "@babel/traverse",
961
- "@pkgjs/parseargs",
962
- "@types/babel__generator",
963
- "kleur",
964
- "zod",
965
- "merge-stream",
966
- "available-typed-arrays",
967
- "mute-stream",
968
- "is-typed-array",
969
- "safe-regex-test",
970
- "tsconfig-paths",
971
- "minizlib",
972
- "tar-stream",
973
- "@floating-ui/core",
974
- "jose",
975
- "deepmerge",
976
- "get-tsconfig",
977
- "set-function-length",
978
- "@vitest/spy",
979
- "css-select",
980
- "@types/babel__core",
981
- "forwarded",
982
- "react",
983
- "@typescript-eslint/parser",
984
- "ajv-keywords",
985
- "define-properties",
986
- "is-generator-function",
987
- "regexp.prototype.flags",
988
- "acorn-walk",
989
- "pump",
990
- "data-uri-to-buffer",
991
- "object-hash",
992
- "jsdom",
993
- "nopt",
994
- "@babel/plugin-syntax-jsx",
995
- "@floating-ui/dom",
996
- "tiny-invariant",
997
- "strip-indent",
998
- "d3-array",
999
- "chai",
1000
- "@babel/code-frame",
1001
- "@typescript-eslint/eslint-plugin",
1002
- "proxy-addr",
1003
- "parseurl",
1004
- "@floating-ui/utils",
1005
- "ora",
1006
- "html-encoding-sniffer",
1007
- "pnpm",
1008
- "whatwg-encoding",
1009
- "events",
1010
- "@typescript-eslint/type-utils",
1011
- "env-paths",
1012
- "internal-slot",
1013
- "string.prototype.trimend",
1014
- "extend",
1015
- "resolve-pkg-maps",
1016
- "istanbul-lib-coverage",
1017
- "react-dom",
1018
- "is-number-object",
1019
- "@radix-ui/primitive",
1020
- "is-plain-object",
1021
- "string.prototype.trimstart",
1022
- "@babel/plugin-syntax-typescript",
1023
- "jest-diff",
1024
- "define-lazy-prop",
1025
- "globalthis",
1026
- "which-boxed-primitive",
1027
- "@vitest/expect",
1028
- "sax",
1029
- "@floating-ui/react-dom",
1030
- "@vitest/pretty-format",
1031
- "internmap",
1032
- "@radix-ui/react-compose-refs",
1033
- "is-symbol",
1034
- "@eslint-community/eslint-utils",
1035
- "bl",
1036
- "serve-static",
1037
- "get-symbol-description",
1038
- "is-shared-array-buffer",
1039
- "functions-have-names",
1040
- "array-buffer-byte-length",
1041
- "socks-proxy-agent"
1042
- ];
826
+ var popular_default;
827
+ var init_popular = __esm(() => {
828
+ popular_default = [
829
+ "semver",
830
+ "minimatch",
831
+ "debug",
832
+ "ansi-styles",
833
+ "brace-expansion",
834
+ "strip-ansi",
835
+ "ansi-regex",
836
+ "ms",
837
+ "supports-color",
838
+ "chalk",
839
+ "commander",
840
+ "lru-cache",
841
+ "string-width",
842
+ "wrap-ansi",
843
+ "tslib",
844
+ "picomatch",
845
+ "emoji-regex",
846
+ "glob",
847
+ "type-fest",
848
+ "color-name",
849
+ "eslint-visitor-keys",
850
+ "color-convert",
851
+ "ajv",
852
+ "minipass",
853
+ "source-map",
854
+ "balanced-match",
855
+ "readable-stream",
856
+ "which",
857
+ "glob-parent",
858
+ "escape-string-regexp",
859
+ "has-flag",
860
+ "find-up",
861
+ "locate-path",
862
+ "json-schema-traverse",
863
+ "p-limit",
864
+ "yallist",
865
+ "safe-buffer",
866
+ "uuid",
867
+ "p-locate",
868
+ "undici-types",
869
+ "ignore",
870
+ "iconv-lite",
871
+ "signal-exit",
872
+ "esbuild",
873
+ "is-fullwidth-code-point",
874
+ "js-yaml",
875
+ "entities",
876
+ "globals",
877
+ "postcss",
878
+ "isexe",
879
+ "isarray",
880
+ "path-key",
881
+ "string_decoder",
882
+ "argparse",
883
+ "ws",
884
+ "mime-db",
885
+ "resolve",
886
+ "agent-base",
887
+ "@esbuild/linux-x64",
888
+ "yargs-parser",
889
+ "mime-types",
890
+ "acorn",
891
+ "estraverse",
892
+ "cross-spawn",
893
+ "react-is",
894
+ "picocolors",
895
+ "fs-extra",
896
+ "hasown",
897
+ "nanoid",
898
+ "yargs",
899
+ "resolve-from",
900
+ "shebang-command",
901
+ "pretty-format",
902
+ "json5",
903
+ "https-proxy-agent",
904
+ "path-to-regexp",
905
+ "path-exists",
906
+ "punycode",
907
+ "js-tokens",
908
+ "cliui",
909
+ "shebang-regex",
910
+ "@babel/types",
911
+ "chokidar",
912
+ "strip-json-comments",
913
+ "inherits",
914
+ "webidl-conversions",
915
+ "get-stream",
916
+ "eslint-scope",
917
+ "cookie",
918
+ "@babel/parser",
919
+ "qs",
920
+ "is-number",
921
+ "whatwg-url",
922
+ "@types/estree",
923
+ "tr46",
924
+ "convert-source-map",
925
+ "is-glob",
926
+ "braces",
927
+ "fast-deep-equal",
928
+ "form-data",
929
+ "lodash",
930
+ "@babel/helper-validator-identifier",
931
+ "electron-to-chromium",
932
+ "fill-range",
933
+ "function-bind",
934
+ "readdirp",
935
+ "escalade",
936
+ "graceful-fs",
937
+ "negotiator",
938
+ "is-stream",
939
+ "camelcase",
940
+ "@babel/runtime",
941
+ "yocto-queue",
942
+ "to-regex-range",
943
+ "node-fetch",
944
+ "micromatch",
945
+ "node-releases",
946
+ "get-intrinsic",
947
+ "universalify",
948
+ "path-scurry",
949
+ "jsesc",
950
+ "browserslist",
951
+ "es-errors",
952
+ "statuses",
953
+ "@radix-ui/react-primitive",
954
+ "magic-string",
955
+ "rimraf",
956
+ "is-extglob",
957
+ "@jridgewell/trace-mapping",
958
+ "@jridgewell/resolve-uri",
959
+ "http-errors",
960
+ "onetime",
961
+ "has-symbols",
962
+ "es-define-property",
963
+ "gopd",
964
+ "util-deprecate",
965
+ "object-assign",
966
+ "jiti",
967
+ "yaml",
968
+ "dotenv",
969
+ "@babel/generator",
970
+ "@babel/template",
971
+ "imurmurhash",
972
+ "postcss-selector-parser",
973
+ "fast-glob",
974
+ "update-browserslist-db",
975
+ "@types/node",
976
+ "@babel/compat-data",
977
+ "eventemitter3",
978
+ "callsites",
979
+ "http-proxy-agent",
980
+ "detect-libc",
981
+ "espree",
982
+ "execa",
983
+ "@babel/core",
984
+ "@babel/helpers",
985
+ "concat-map",
986
+ "source-map-js",
987
+ "tinyglobby",
988
+ "call-bind-apply-helpers",
989
+ "flat-cache",
990
+ "fdir",
991
+ "pify",
992
+ "@jest/types",
993
+ "normalize-path",
994
+ "is-core-module",
995
+ "eslint",
996
+ "minimist",
997
+ "estree-walker",
998
+ "file-entry-cache",
999
+ "object-inspect",
1000
+ "buffer",
1001
+ "uri-js",
1002
+ "import-fresh",
1003
+ "@babel/helper-module-transforms",
1004
+ "optionator",
1005
+ "flatted",
1006
+ "math-intrinsics",
1007
+ "safer-buffer",
1008
+ "y18n",
1009
+ "@babel/helper-module-imports",
1010
+ "mkdirp",
1011
+ "dunder-proto",
1012
+ "path-parse",
1013
+ "fastq",
1014
+ "levn",
1015
+ "@babel/helper-compilation-targets",
1016
+ "@babel/helper-string-parser",
1017
+ "keyv",
1018
+ "get-proto",
1019
+ "csstype",
1020
+ "npm-run-path",
1021
+ "fast-json-stable-stringify",
1022
+ "reusify",
1023
+ "@babel/helper-plugin-utils",
1024
+ "kind-of",
1025
+ "mime",
1026
+ "caniuse-lite",
1027
+ "lines-and-columns",
1028
+ "fast-levenshtein",
1029
+ "supports-preserve-symlinks-flag",
1030
+ "make-dir",
1031
+ "slash",
1032
+ "prelude-ls",
1033
+ "typescript",
1034
+ "strip-bom",
1035
+ "parent-module",
1036
+ "esutils",
1037
+ "ci-info",
1038
+ "@smithy/util-utf8",
1039
+ "type-check",
1040
+ "mimic-fn",
1041
+ "@babel/helper-validator-option",
1042
+ "@types/json-schema",
1043
+ "@rolldown/pluginutils",
1044
+ "side-channel-list",
1045
+ "json-buffer",
1046
+ "raw-body",
1047
+ "has-tostringtag",
1048
+ "wrappy",
1049
+ "diff",
1050
+ "jackspeak",
1051
+ "baseline-browser-mapping",
1052
+ "deep-is",
1053
+ "foreground-child",
1054
+ "@eslint/js",
1055
+ "anymatch",
1056
+ "natural-compare",
1057
+ "esquery",
1058
+ "@eslint-community/regexpp",
1059
+ "es-set-tostringtag",
1060
+ "acorn-jsx",
1061
+ "parse5",
1062
+ "finalhandler",
1063
+ "parse-json",
1064
+ "depd",
1065
+ "axios",
1066
+ "run-parallel",
1067
+ "source-map-support",
1068
+ "esrecurse",
1069
+ "call-bound",
1070
+ "content-disposition",
1071
+ "human-signals",
1072
+ "ts-api-utils",
1073
+ "ansi-escapes",
1074
+ "jest-util",
1075
+ "send",
1076
+ "@opentelemetry/core",
1077
+ "type-is",
1078
+ "encodeurl",
1079
+ "once",
1080
+ "cosmiconfig",
1081
+ "lodash.merge",
1082
+ "json-stable-stringify-without-jsonify",
1083
+ "open",
1084
+ "prettier",
1085
+ "@eslint/eslintrc",
1086
+ "is-arrayish",
1087
+ "@jridgewell/sourcemap-codec",
1088
+ "gensync",
1089
+ "word-wrap",
1090
+ "express",
1091
+ "arg",
1092
+ "jsonfile",
1093
+ "schema-utils",
1094
+ "@smithy/is-array-buffer",
1095
+ "@typescript-eslint/types",
1096
+ "chownr",
1097
+ "delayed-stream",
1098
+ "@smithy/util-buffer-from",
1099
+ "asynckit",
1100
+ "tapable",
1101
+ "enhanced-resolve",
1102
+ "aria-query",
1103
+ "indent-string",
1104
+ "bytes",
1105
+ "binary-extensions",
1106
+ "ini",
1107
+ "@radix-ui/react-context",
1108
+ "doctrine",
1109
+ "queue-microtask",
1110
+ "accepts",
1111
+ "merge2",
1112
+ "get-caller-file",
1113
+ "@humanwhocodes/retry",
1114
+ "@jridgewell/gen-mapping",
1115
+ "@typescript-eslint/typescript-estree",
1116
+ "jest-worker",
1117
+ "proxy-from-env",
1118
+ "clsx",
1119
+ "side-channel-map",
1120
+ "@typescript-eslint/visitor-keys",
1121
+ "fresh",
1122
+ "restore-cursor",
1123
+ "on-finished",
1124
+ "is-plain-obj",
1125
+ "ipaddr.js",
1126
+ "pathe",
1127
+ "@jest/schemas",
1128
+ "base64-js",
1129
+ "@smithy/types",
1130
+ "require-directory",
1131
+ "tough-cookie",
1132
+ "is-binary-path",
1133
+ "body-parser",
1134
+ "postcss-value-parser",
1135
+ "media-typer",
1136
+ "setprototypeof",
1137
+ "side-channel-weakmap",
1138
+ "@typescript-eslint/tsconfig-utils",
1139
+ "@isaacs/cliui",
1140
+ "@rollup/rollup-linux-x64-gnu",
1141
+ "is-wsl",
1142
+ "retry",
1143
+ "@aws-sdk/types",
1144
+ "@types/react-dom",
1145
+ "combined-stream",
1146
+ "es-object-atoms",
1147
+ "@eslint/core",
1148
+ "whatwg-mimetype",
1149
+ "domutils",
1150
+ "@rollup/rollup-linux-x64-musl",
1151
+ "core-util-is",
1152
+ "@typescript-eslint/scope-manager",
1153
+ "esprima",
1154
+ "loose-envify",
1155
+ "cookie-signature",
1156
+ "follow-redirects",
1157
+ "cli-cursor",
1158
+ "strip-final-newline",
1159
+ "@typescript-eslint/project-service",
1160
+ "eastasianwidth",
1161
+ "json-parse-even-better-errors",
1162
+ "sprintf-js",
1163
+ "path-type",
1164
+ "content-type",
1165
+ "es-module-lexer",
1166
+ "@nodelib/fs.scandir",
1167
+ "write-file-atomic",
1168
+ "@eslint/plugin-kit",
1169
+ "ieee754",
1170
+ "prop-types",
1171
+ "require-from-string",
1172
+ "dom-serializer",
1173
+ "call-bind",
1174
+ "@eslint/config-array",
1175
+ "has-property-descriptors",
1176
+ "@nodelib/fs.stat",
1177
+ "merge-descriptors",
1178
+ "slice-ansi",
1179
+ "rxjs",
1180
+ "p-map",
1181
+ "toidentifier",
1182
+ "globby",
1183
+ "domhandler",
1184
+ "async",
1185
+ "@babel/helper-globals",
1186
+ "pirates",
1187
+ "@opentelemetry/semantic-conventions",
1188
+ "@typescript-eslint/utils",
1189
+ "date-fns",
1190
+ "is-docker",
1191
+ "tar",
1192
+ "which-typed-array",
1193
+ "ajv-formats",
1194
+ "@opentelemetry/api-logs",
1195
+ "@opentelemetry/resources",
1196
+ "side-channel",
1197
+ "cjs-module-lexer",
1198
+ "range-parser",
1199
+ "@humanfs/node",
1200
+ "define-data-property",
1201
+ "node-addon-api",
1202
+ "pako",
1203
+ "lilconfig",
1204
+ "fast-uri",
1205
+ "ip-address",
1206
+ "fs.realpath",
1207
+ "@img/sharp-libvips-linuxmusl-x64",
1208
+ "cssesc",
1209
+ "@opentelemetry/instrumentation",
1210
+ "domelementtype",
1211
+ "hosted-git-info",
1212
+ "@eslint/object-schema",
1213
+ "etag",
1214
+ "@eslint/config-helpers",
1215
+ "package-json-from-dist",
1216
+ "@humanfs/core",
1217
+ "htmlparser2",
1218
+ "jest-message-util",
1219
+ "for-each",
1220
+ "pkg-dir",
1221
+ "unpipe",
1222
+ "buffer-from",
1223
+ "es-abstract",
1224
+ "is-unicode-supported",
1225
+ "@types/yargs",
1226
+ "is-callable",
1227
+ "fast-xml-parser",
1228
+ "istanbul-lib-instrument",
1229
+ "escape-html",
1230
+ "is-regex",
1231
+ "dom-accessibility-api",
1232
+ "css-tree",
1233
+ "error-ex",
1234
+ "ee-first",
1235
+ "@types/unist",
1236
+ "log-symbols",
1237
+ "path-is-absolute",
1238
+ "end-of-stream",
1239
+ "@vitest/utils",
1240
+ "object.assign",
1241
+ "object-keys",
1242
+ "tinyexec",
1243
+ "scheduler",
1244
+ "p-try",
1245
+ "process-nextick-args",
1246
+ "vary",
1247
+ "@babel/traverse",
1248
+ "@pkgjs/parseargs",
1249
+ "@types/babel__generator",
1250
+ "kleur",
1251
+ "zod",
1252
+ "merge-stream",
1253
+ "available-typed-arrays",
1254
+ "mute-stream",
1255
+ "is-typed-array",
1256
+ "safe-regex-test",
1257
+ "tsconfig-paths",
1258
+ "minizlib",
1259
+ "tar-stream",
1260
+ "@floating-ui/core",
1261
+ "jose",
1262
+ "deepmerge",
1263
+ "get-tsconfig",
1264
+ "set-function-length",
1265
+ "@vitest/spy",
1266
+ "css-select",
1267
+ "@types/babel__core",
1268
+ "forwarded",
1269
+ "react",
1270
+ "@typescript-eslint/parser",
1271
+ "ajv-keywords",
1272
+ "define-properties",
1273
+ "is-generator-function",
1274
+ "regexp.prototype.flags",
1275
+ "acorn-walk",
1276
+ "pump",
1277
+ "data-uri-to-buffer",
1278
+ "object-hash",
1279
+ "jsdom",
1280
+ "nopt",
1281
+ "@babel/plugin-syntax-jsx",
1282
+ "@floating-ui/dom",
1283
+ "tiny-invariant",
1284
+ "strip-indent",
1285
+ "d3-array",
1286
+ "chai",
1287
+ "@babel/code-frame",
1288
+ "@typescript-eslint/eslint-plugin",
1289
+ "proxy-addr",
1290
+ "parseurl",
1291
+ "@floating-ui/utils",
1292
+ "ora",
1293
+ "html-encoding-sniffer",
1294
+ "pnpm",
1295
+ "whatwg-encoding",
1296
+ "events",
1297
+ "@typescript-eslint/type-utils",
1298
+ "env-paths",
1299
+ "internal-slot",
1300
+ "string.prototype.trimend",
1301
+ "extend",
1302
+ "resolve-pkg-maps",
1303
+ "istanbul-lib-coverage",
1304
+ "react-dom",
1305
+ "is-number-object",
1306
+ "@radix-ui/primitive",
1307
+ "is-plain-object",
1308
+ "string.prototype.trimstart",
1309
+ "@babel/plugin-syntax-typescript",
1310
+ "jest-diff",
1311
+ "define-lazy-prop",
1312
+ "globalthis",
1313
+ "which-boxed-primitive",
1314
+ "@vitest/expect",
1315
+ "sax",
1316
+ "@floating-ui/react-dom",
1317
+ "@vitest/pretty-format",
1318
+ "internmap",
1319
+ "@radix-ui/react-compose-refs",
1320
+ "is-symbol",
1321
+ "@eslint-community/eslint-utils",
1322
+ "bl",
1323
+ "serve-static",
1324
+ "get-symbol-description",
1325
+ "is-shared-array-buffer",
1326
+ "functions-have-names",
1327
+ "array-buffer-byte-length",
1328
+ "socks-proxy-agent"
1329
+ ];
1330
+ });
1043
1331
 
1044
1332
  // src/nearmiss.ts
1045
- var SEPARATORS = /[-_.]/g;
1046
- var MIN_LENGTH = 5;
1047
1333
  function baseName(name) {
1048
1334
  return name.slice(name.indexOf("/") + 1);
1049
1335
  }
@@ -1073,13 +1359,14 @@ function nearMisses(name, popular = popular_default) {
1073
1359
  }
1074
1360
  return found.sort((a, b) => a.edits - b.edits).slice(0, 3).map((match) => match.text);
1075
1361
  }
1362
+ var SEPARATORS, MIN_LENGTH = 5;
1363
+ var init_nearmiss = __esm(() => {
1364
+ init_src();
1365
+ init_popular();
1366
+ SEPARATORS = /[-_.]/g;
1367
+ });
1076
1368
 
1077
1369
  // src/analyze.ts
1078
- var DEFAULT_MIN_AGE_DAYS = 14;
1079
- var DAY = 86400000;
1080
- var INSTALL_SCRIPTS = ["preinstall", "install", "postinstall"];
1081
- var GIT_PREFIX = /^git\+/;
1082
- var VERSION_SEPARATOR = /(?<=.)@/;
1083
1370
  function parseSpec(text) {
1084
1371
  const at = text.search(VERSION_SEPARATOR);
1085
1372
  return at === -1 ? { name: text } : { name: text.slice(0, at), request: text.slice(at + 1) };
@@ -1157,16 +1444,15 @@ function analyze(input) {
1157
1444
  report.warnings.push(`${version} is deprecated: ${report.deprecated}`);
1158
1445
  return report;
1159
1446
  }
1160
-
1161
- // src/config.ts
1162
- import { homedir } from "os";
1163
- import { dirname, join } from "path";
1164
- import process6 from "process";
1447
+ var DEFAULT_MIN_AGE_DAYS = 14, DAY = 86400000, INSTALL_SCRIPTS, GIT_PREFIX, VERSION_SEPARATOR;
1448
+ var init_analyze = __esm(() => {
1449
+ init_nearmiss();
1450
+ INSTALL_SCRIPTS = ["preinstall", "install", "postinstall"];
1451
+ GIT_PREFIX = /^git\+/;
1452
+ VERSION_SEPARATOR = /(?<=.)@/;
1453
+ });
1165
1454
 
1166
1455
  // src/registry.ts
1167
- var PUBLIC_REGISTRY = "https://registry.npmjs.org";
1168
- var DOWNLOADS_API = "https://api.npmjs.org/downloads/point/last-week";
1169
- var TRAILING_SLASHES = /\/+$/;
1170
1456
  function isPublic(registry) {
1171
1457
  return registry.url.replace(TRAILING_SLASHES, "") === PUBLIC_REGISTRY;
1172
1458
  }
@@ -1192,14 +1478,16 @@ async function fetchDownloads(name, fetcher = fetch) {
1192
1478
  const body = await response.json();
1193
1479
  return body.downloads;
1194
1480
  }
1481
+ var PUBLIC_REGISTRY = "https://registry.npmjs.org", DOWNLOADS_API = "https://api.npmjs.org/downloads/point/last-week", TRAILING_SLASHES;
1482
+ var init_registry = __esm(() => {
1483
+ init_src();
1484
+ TRAILING_SLASHES = /\/+$/;
1485
+ });
1195
1486
 
1196
1487
  // src/config.ts
1197
- var ENV_REFERENCE = /\$\{(\w+)\}|\$(\w+)/g;
1198
- var COMMENT = /^\s*[#;]/;
1199
- var SCOPE_REGISTRY = /^(@[^:]+):registry$/;
1200
- var AUTH_TOKEN = /^(\/\/.+?):_authToken$/;
1201
- var PROTOCOL = /^\w+:/;
1202
- var QUOTES = /^(["'])(.*)\1$/;
1488
+ import { homedir } from "os";
1489
+ import { dirname, join } from "path";
1490
+ import process7 from "process";
1203
1491
  function expand(value, env) {
1204
1492
  let missing = false;
1205
1493
  const expanded = value.replace(ENV_REFERENCE, (_, braced, bare) => {
@@ -1275,7 +1563,7 @@ async function readIfThere(path) {
1275
1563
  const file = Bun.file(path);
1276
1564
  return await file.exists() ? file.text() : undefined;
1277
1565
  }
1278
- async function loadConfigs(cwd = process6.cwd(), env = process6.env, home = homedir()) {
1566
+ async function loadConfigs(cwd = process7.cwd(), env = process7.env, home = homedir()) {
1279
1567
  const directories = [];
1280
1568
  for (let dir = cwd;!directories.includes(dir); dir = dirname(dir))
1281
1569
  directories.push(dir);
@@ -1292,16 +1580,22 @@ async function loadConfigs(cwd = process6.cwd(), env = process6.env, home = home
1292
1580
  }
1293
1581
  return configs;
1294
1582
  }
1583
+ var ENV_REFERENCE, COMMENT, SCOPE_REGISTRY, AUTH_TOKEN, PROTOCOL, QUOTES;
1584
+ var init_config2 = __esm(() => {
1585
+ init_registry();
1586
+ ENV_REFERENCE = /\$\{(\w+)\}|\$(\w+)/g;
1587
+ COMMENT = /^\s*[#;]/;
1588
+ SCOPE_REGISTRY = /^(@[^:]+):registry$/;
1589
+ AUTH_TOKEN = /^(\/\/.+?):_authToken$/;
1590
+ PROTOCOL = /^\w+:/;
1591
+ QUOTES = /^(["'])(.*)\1$/;
1592
+ });
1295
1593
 
1296
1594
  // src/commands/check.ts
1297
- var usage = `pkg <name>[@version]...
1298
-
1299
- Checks npm packages before they are added: whether the name exists, the latest and the newest version at least two weeks old, weekly downloads, licence, repository, install scripts and a near miss of a popular name.
1300
- Exits 1 when a package is missing or the version asked for is under the minimum age.`;
1301
- var options = {
1302
- json: jsonOption(),
1303
- "min-age": { type: "string", description: `days a version must be old (${DEFAULT_MIN_AGE_DAYS})` }
1304
- };
1595
+ var exports_check = {};
1596
+ __export(exports_check, {
1597
+ check: () => check
1598
+ });
1305
1599
  async function checkPackage(text, context) {
1306
1600
  const spec = parseSpec(text);
1307
1601
  const registry = registryFor(spec.name, context.configs);
@@ -1350,6 +1644,379 @@ ${usage}`);
1350
1644
  `));
1351
1645
  return reports.some((report) => report.blocked) ? 1 : 0;
1352
1646
  }
1647
+ var usage = `pkg [check] <name>[@version]...
1648
+
1649
+ Checks npm packages before they are added: whether the name exists, the latest and the newest version at least two weeks old, weekly downloads, licence, repository, install scripts and a near miss of a popular name.
1650
+ Exits 1 when a package is missing or the version asked for is under the minimum age.`, options;
1651
+ var init_check = __esm(() => {
1652
+ init_src();
1653
+ init_analyze();
1654
+ init_config2();
1655
+ init_registry();
1656
+ options = {
1657
+ json: jsonOption(),
1658
+ "min-age": { type: "string", description: `days a version must be old (${DEFAULT_MIN_AGE_DAYS})` }
1659
+ };
1660
+ });
1661
+
1662
+ // ../kit/src/progress.ts
1663
+ import process8 from "process";
1664
+ function liveRegion(render, stream = process8.stderr, env = process8.env) {
1665
+ if (!takesControlCodes(stream, env))
1666
+ return { redraw: () => {
1667
+ return;
1668
+ }, print: (text) => void stream.write(`${text}
1669
+ `), stop: () => {
1670
+ return;
1671
+ } };
1672
+ const write = stream.write.bind(stream);
1673
+ let frame = 0;
1674
+ let drawn = 0;
1675
+ const clear = () => {
1676
+ if (drawn > 0)
1677
+ write(`${CLEAR_LINE}${LINE_UP.repeat(drawn - 1)}`);
1678
+ drawn = 0;
1679
+ };
1680
+ const draw = () => {
1681
+ const width = (stream.columns === undefined || stream.columns === 0 ? 80 : stream.columns) - 1;
1682
+ const height = stream.rows === undefined || stream.rows === 0 ? 24 : stream.rows;
1683
+ const lines = render(FRAMES[frame++ % FRAMES.length]).slice(0, Math.max(1, height - 1)).map((line) => cutToWidth(line, width));
1684
+ if (lines.length === 0) {
1685
+ clear();
1686
+ return;
1687
+ }
1688
+ write(`${drawn > 0 ? `${CLEAR_LINE}${LINE_UP.repeat(drawn - 1)}` : CLEAR_LINE}${lines.join(`
1689
+ `)}`);
1690
+ drawn = lines.length;
1691
+ };
1692
+ const timer = setInterval(draw, FRAME_MS);
1693
+ const restore = interceptOutput(clear);
1694
+ const onExit = () => clear();
1695
+ const signals = holdSignals(stop);
1696
+ function stop() {
1697
+ clearInterval(timer);
1698
+ clear();
1699
+ restore();
1700
+ process8.off("exit", onExit);
1701
+ signals.release();
1702
+ }
1703
+ timer.unref();
1704
+ process8.on("exit", onExit);
1705
+ return {
1706
+ redraw: draw,
1707
+ print: (text) => {
1708
+ clear();
1709
+ write(`${text}
1710
+ `);
1711
+ draw();
1712
+ },
1713
+ stop
1714
+ };
1715
+ }
1716
+ function cutToWidth(line, width) {
1717
+ if (Bun.stringWidth(line) <= width)
1718
+ return line;
1719
+ let room = width;
1720
+ let kept = "";
1721
+ let index = 0;
1722
+ let linked = false;
1723
+ while (index < line.length) {
1724
+ ESCAPE_CODE.lastIndex = index;
1725
+ const escape = ESCAPE_CODE.exec(line);
1726
+ if (escape !== null) {
1727
+ kept += escape[0];
1728
+ linked ||= escape[0].startsWith(`${ESC}]`);
1729
+ index = ESCAPE_CODE.lastIndex;
1730
+ continue;
1731
+ }
1732
+ const char = String.fromCodePoint(line.codePointAt(index));
1733
+ const columns = Bun.stringWidth(char);
1734
+ if (columns > room)
1735
+ break;
1736
+ kept += char;
1737
+ room -= columns;
1738
+ index += char.length;
1739
+ }
1740
+ return `${kept}${RESET_STYLE}${linked ? CLOSE_LINK : ""}`;
1741
+ }
1742
+ function interceptOutput(clear) {
1743
+ const targets = [...CONSOLE_METHODS.map((name) => [console, name]), [process8.stdout, "write"], [process8.stderr, "write"]];
1744
+ const wrapped = targets.map(([target, name]) => {
1745
+ const original = Reflect.get(target, name);
1746
+ const wrapper = (...args) => {
1747
+ clear();
1748
+ return original.apply(target, args);
1749
+ };
1750
+ Reflect.set(target, name, wrapper);
1751
+ return { target, name, original, wrapper };
1752
+ });
1753
+ return () => {
1754
+ for (const { target, name, original, wrapper } of wrapped) {
1755
+ if (Reflect.get(target, name) === wrapper)
1756
+ Reflect.set(target, name, original);
1757
+ }
1758
+ };
1759
+ }
1760
+ var FRAMES, FRAME_MS = 80, CLEAR_LINE = "\r\x1B[2K", LINE_UP = "\x1B[1A\x1B[2K", ESC, ESCAPE_CODE, RESET_STYLE, CLOSE_LINK, CONSOLE_METHODS;
1761
+ var init_progress = __esm(() => {
1762
+ init_format();
1763
+ init_process();
1764
+ init_style();
1765
+ FRAMES = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
1766
+ ESC = String.fromCharCode(27);
1767
+ ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x7E]|\\][^\\u0007${ESC}]*(?:\\u0007|${ESC}\\\\))`, "y");
1768
+ RESET_STYLE = `${ESC}[0m`;
1769
+ CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
1770
+ CONSOLE_METHODS = ["log", "info", "warn", "error", "debug", "dir", "dirxml", "table", "trace", "group", "groupCollapsed", "count", "timeEnd", "timeLog", "assert"];
1771
+ });
1772
+
1773
+ // ../kit/src/shell.ts
1774
+ var SEPARATORS2, PLAIN_BREAKERS, DOUBLE_QUOTED_ESCAPES, WRAPPERS;
1775
+ var init_shell = __esm(() => {
1776
+ SEPARATORS2 = new Set([`
1777
+ `, ";", "|"]);
1778
+ PLAIN_BREAKERS = new Set(["<", ">", "(", ")", "&", "|"]);
1779
+ DOUBLE_QUOTED_ESCAPES = new Set(["$", "`", '"', "\\"]);
1780
+ WRAPPERS = new Set(["command", "env", "sudo", "exec", "nohup", "time"]);
1781
+ });
1782
+
1783
+ // src/pin.ts
1784
+ function actions(byAction) {
1785
+ return new Map(Object.entries(byAction).flatMap(([action, names]) => names.map((name) => [name, action])));
1786
+ }
1787
+ var LOCKFILES, ACTIONS, OPTION_FLAGS, DIR_FLAGS, VALUE_FLAGS;
1788
+ var init_pin = __esm(() => {
1789
+ init_shell();
1790
+ LOCKFILES = [
1791
+ ["bun.lock", "bun"],
1792
+ ["bun.lockb", "bun"],
1793
+ ["pnpm-lock.yaml", "pnpm"],
1794
+ ["yarn.lock", "yarn"],
1795
+ ["package-lock.json", "npm"]
1796
+ ];
1797
+ ACTIONS = {
1798
+ bun: actions({ install: ["install", "i"], add: ["add", "a"], remove: ["remove", "rm"], update: ["update"] }),
1799
+ pnpm: actions({ install: ["install", "i"], add: ["add"], remove: ["remove", "rm"], update: ["update", "up"] }),
1800
+ yarn: new Map([...actions({ install: ["", "install"], add: ["add"], remove: ["remove"], update: ["upgrade"] }), ["upgrade-interactive", null], ["import", null]]),
1801
+ npm: actions({
1802
+ install: ["install", "i", "in", "ins", "inst", "insta", "instal", "isnt", "isnta", "isntal", "isntall"],
1803
+ add: ["add"],
1804
+ frozen: ["ci", "clean-install", "ic", "install-clean", "isntall-clean"],
1805
+ remove: ["uninstall", "unlink", "remove", "rm", "r", "un"],
1806
+ update: ["update", "u", "up", "upgrade", "udpate"]
1807
+ })
1808
+ };
1809
+ OPTION_FLAGS = new Map([
1810
+ ["-D", "dev"],
1811
+ ["--save-dev", "dev"],
1812
+ ["--dev", "dev"],
1813
+ ["-E", "exact"],
1814
+ ["--save-exact", "exact"],
1815
+ ["--exact", "exact"]
1816
+ ]);
1817
+ DIR_FLAGS = new Set(["--cwd", "-C", "--dir", "--prefix"]);
1818
+ VALUE_FLAGS = new Set([...DIR_FLAGS, "--filter", "-F"]);
1819
+ });
1820
+
1821
+ // src/consumers.ts
1822
+ import { existsSync, readdirSync, readFileSync } from "fs";
1823
+ import { dirname as dirname2, join as join2, relative } from "path";
1824
+ function packageFiles(dir, depth, found) {
1825
+ let entries;
1826
+ try {
1827
+ entries = readdirSync(dir, { withFileTypes: true });
1828
+ } catch {
1829
+ return found;
1830
+ }
1831
+ for (const entry of entries) {
1832
+ if (entry.isFile() && entry.name === "package.json")
1833
+ found.push(join2(dir, entry.name));
1834
+ else if (entry.isDirectory() && depth < MAX_DEPTH && !entry.name.startsWith(".") && !SKIPPED.has(entry.name))
1835
+ packageFiles(join2(dir, entry.name), depth + 1, found);
1836
+ }
1837
+ return found;
1838
+ }
1839
+ function managerFor(dir, root) {
1840
+ for (let at = dir;; at = dirname2(at)) {
1841
+ const lockfile = LOCKFILES.find(([file]) => existsSync(join2(at, file)));
1842
+ if (lockfile !== undefined)
1843
+ return lockfile[1];
1844
+ if (at === root || at === dirname2(at))
1845
+ return "bun";
1846
+ }
1847
+ }
1848
+ function findConsumers(name, root) {
1849
+ const consumers = [];
1850
+ for (const path of packageFiles(root, 0, []).sort()) {
1851
+ let manifest;
1852
+ try {
1853
+ manifest = JSON.parse(readFileSync(path, "utf8"));
1854
+ } catch {
1855
+ continue;
1856
+ }
1857
+ const kind = KINDS.find((each) => typeof manifest[each]?.[name] === "string");
1858
+ const spec = kind === undefined ? undefined : manifest[kind]?.[name];
1859
+ if (kind !== undefined && spec !== undefined)
1860
+ consumers.push({ dir: relative(root, dirname2(path)) || ".", path, kind, spec, manager: managerFor(dirname2(path), root) });
1861
+ }
1862
+ return consumers;
1863
+ }
1864
+ function isLocal(consumer) {
1865
+ return LOCAL_SPEC.test(consumer.spec);
1866
+ }
1867
+ function addCommand(consumer, name, version) {
1868
+ return ["bun", "add", ...KIND_FLAGS[consumer.kind], "--exact", "--no-cache", `${name}@${version}`];
1869
+ }
1870
+ var KINDS, SKIPPED, MAX_DEPTH = 5, LOCAL_SPEC, KIND_FLAGS;
1871
+ var init_consumers = __esm(() => {
1872
+ init_pin();
1873
+ KINDS = ["dependencies", "devDependencies", "optionalDependencies", "peerDependencies"];
1874
+ SKIPPED = new Set(["node_modules", "dist", "build", "vendor", "target", "coverage"]);
1875
+ LOCAL_SPEC = /^(?:workspace|link|file|portal):/;
1876
+ KIND_FLAGS = { dependencies: [], devDependencies: ["--dev"], optionalDependencies: ["--optional"], peerDependencies: ["--peer"] };
1877
+ });
1878
+
1879
+ // src/commands/bump.ts
1880
+ var exports_bump = {};
1881
+ __export(exports_bump, {
1882
+ ROOT_OPTION: () => ROOT_OPTION,
1883
+ bump: () => bump
1884
+ });
1885
+ import { homedir as homedir2 } from "os";
1886
+ import { join as join3 } from "path";
1887
+ async function servedVersion(name, version, settings) {
1888
+ const registry = registryFor(name, settings.configs);
1889
+ const host = new URL(registry.url).host;
1890
+ const started = Date.now();
1891
+ const region = liveRegion((spinner) => [`${spinner} waiting for ${host} to serve ${name}@${version} ${formatDuration(Date.now() - started)}`]);
1892
+ try {
1893
+ for (;; ) {
1894
+ const packument = await fetchPackument(name, registry, settings.fetcher);
1895
+ const latest = packument?.["dist-tags"]?.latest;
1896
+ if (version === undefined && latest !== undefined)
1897
+ return latest;
1898
+ if (version === undefined)
1899
+ fail(`${host} has no ${name}`, 1);
1900
+ if (packument?.versions?.[version] !== undefined)
1901
+ return version;
1902
+ if (Date.now() - started >= settings.timeout)
1903
+ fail(`${host} does not serve ${name}@${version} after ${formatDuration(settings.timeout)}`, 1);
1904
+ region.redraw();
1905
+ await Bun.sleep(settings.poll ?? POLL);
1906
+ }
1907
+ } finally {
1908
+ region.stop();
1909
+ }
1910
+ }
1911
+ async function bumpConsumers(name, version, settings) {
1912
+ const found = findConsumers(name, settings.root);
1913
+ const consumers = found.filter((each) => !isLocal(each));
1914
+ const local = found.length - consumers.length;
1915
+ const run = settings.run ?? (async (argv, cwd) => runCommand(argv, { cwd }));
1916
+ let isClean = true;
1917
+ if (found.length === 0)
1918
+ note(`nothing under ${settings.root} depends on ${name}`);
1919
+ if (local > 0)
1920
+ note(`${local} workspace:, link: or file: dependenc${local === 1 ? "y" : "ies"}`, "left as they are");
1921
+ for (const consumer of consumers) {
1922
+ const argv = addCommand(consumer, name, version);
1923
+ const where = join3(settings.root, consumer.dir);
1924
+ if (consumer.spec === version) {
1925
+ note(consumer.dir, `already on ${version}`);
1926
+ } else if (consumer.manager !== "bun") {
1927
+ warn(consumer.dir, `${consumer.spec}, its lockfile pins ${consumer.manager}: put ${version} in by hand`);
1928
+ } else if (settings.isDryRun === true) {
1929
+ note(consumer.dir, `would run ${argv.join(" ")}`);
1930
+ } else {
1931
+ const ran = await run(argv, where);
1932
+ if (ran.code === 0) {
1933
+ ok(consumer.dir, `${consumer.spec} -> ${version}`);
1934
+ } else {
1935
+ isClean = false;
1936
+ problem(consumer.dir, `${argv.join(" ")} exited ${ran.code}: ${ran.text.trim().split(`
1937
+ `).at(-1) ?? ""}`);
1938
+ }
1939
+ }
1940
+ }
1941
+ return isClean;
1942
+ }
1943
+ async function bump(args) {
1944
+ const { values, positionals: [name, asked] } = parse(args, usage2, options2, { positionals: ["<name>", "[version]"] });
1945
+ const settings = {
1946
+ root: values.root ?? join3(homedir2(), "Workspace"),
1947
+ configs: await loadConfigs(),
1948
+ timeout: duration(values.timeout, "timeout", 10 * 60000),
1949
+ isDryRun: values["dry-run"] === true
1950
+ };
1951
+ const version = await servedVersion(name, asked, settings);
1952
+ return await bumpConsumers(name, version, settings) ? 0 : 1;
1953
+ }
1954
+ var usage2 = `pkg bump <name> [version]
1955
+
1956
+ Waits until the registry serves the version (the latest when none is given), 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 line per folder.
1957
+ A workspace:, link: or file: dependency, a folder already on the version and one whose lockfile pins another manager are left as they are, each said so.
1958
+ Exits 1 when an install fails or the version never shows, 2 on a usage error.`, ROOT_OPTION, options2, POLL = 5000;
1959
+ var init_bump = __esm(() => {
1960
+ init_src();
1961
+ init_progress();
1962
+ init_config2();
1963
+ init_consumers();
1964
+ init_registry();
1965
+ ROOT_OPTION = { type: "string", description: "the folder holding the repositories (~/Workspace)" };
1966
+ options2 = {
1967
+ root: ROOT_OPTION,
1968
+ timeout: { type: "string", short: "t", description: "how long to wait for the registry (10m): 30s, 5m, 1h" },
1969
+ "dry-run": { type: "boolean", description: "print what would run, changing nothing" }
1970
+ };
1971
+ });
1972
+
1973
+ // src/commands/consumers.ts
1974
+ var exports_consumers = {};
1975
+ __export(exports_consumers, {
1976
+ consumers: () => consumers
1977
+ });
1978
+ import { homedir as homedir3 } from "os";
1979
+ import { join as join4 } from "path";
1980
+ function consumers(args) {
1981
+ const { values, positionals: [name] } = parse(args, usage3, options3, { positionals: ["<name>"] });
1982
+ const root = values.root ?? join4(homedir3(), "Workspace");
1983
+ const found = findConsumers(name, root);
1984
+ if (values.json === true)
1985
+ printJson(found);
1986
+ else if (found.length === 0)
1987
+ console.log(`nothing under ${root} depends on ${name}`);
1988
+ else
1989
+ console.log(table([["FOLDER", "KIND", "VERSION", "MANAGER"], ...found.map((each) => [each.dir, each.kind, each.spec, each.manager])], { header: true }));
1990
+ return 0;
1991
+ }
1992
+ var usage3 = `pkg consumers <name>
1993
+
1994
+ Lists the folders under --root whose package.json depends on the package: the folder, the kind of dependency, the version it asks for and the manager its lockfile pins.`, options3;
1995
+ var init_consumers2 = __esm(() => {
1996
+ init_src();
1997
+ init_consumers();
1998
+ init_bump();
1999
+ options3 = {
2000
+ root: ROOT_OPTION,
2001
+ json: jsonOption("[{dir, path, kind, spec, manager}]")
2002
+ };
2003
+ });
1353
2004
 
1354
2005
  // src/cli.ts
1355
- process7.exitCode = await runMain({ name: "pkg", version, run: check });
2006
+ init_src();
2007
+ import process9 from "process";
2008
+ // package.json
2009
+ var version = "0.3.0";
2010
+
2011
+ // src/cli.ts
2012
+ process9.exitCode = await runCli({
2013
+ name: "pkg",
2014
+ version,
2015
+ about: "checks npm packages before they are added, and moves a lib's consumers onto a new release",
2016
+ defaultCommand: "check",
2017
+ commands: {
2018
+ 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) },
2019
+ 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) },
2020
+ 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) }
2021
+ }
2022
+ });