@kaynooo/cli-workspace 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/audit-cli.js CHANGED
@@ -732,7 +732,6 @@ var DASHES = /^-+/;
732
732
  function jsonOption(holds) {
733
733
  return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
734
734
  }
735
-
736
735
  class Exit extends Error {
737
736
  code;
738
737
  hint;
@@ -1494,7 +1493,7 @@ function workspaceRoot({ given, env = process14.env, home = homedir4() } = {}) {
1494
1493
  return resolve3(expandHome(given ?? fromEnv ?? configured(env, home) ?? join6(home, "Workspace"), home));
1495
1494
  }
1496
1495
  // src/audit.ts
1497
- import { existsSync as existsSync6, readdirSync, statSync as statSync2 } from "fs";
1496
+ import { existsSync as existsSync6, readdirSync, readFileSync as readFileSync5, statSync as statSync2 } from "fs";
1498
1497
  import { readdir } from "fs/promises";
1499
1498
  import { join as join8, relative, resolve as resolve4 } from "path";
1500
1499
  import process16 from "process";
@@ -1525,7 +1524,7 @@ function fixFor(advisories) {
1525
1524
  return;
1526
1525
  return fixes.reduce((highest, fix) => Bun.semver.order(fix, highest) > 0 ? fix : highest);
1527
1526
  }
1528
- function findingsOf(audit, reaching, direct, level, ignore = []) {
1527
+ function findingsOf(audit, reaching, direct, level, ignore = [], via = new Map) {
1529
1528
  const found = [];
1530
1529
  for (const [name, all] of Object.entries(audit)) {
1531
1530
  const kept = all.filter((advisory) => severityRank(advisory.severity) >= severityRank(level) && !isIgnored({ id: advisory.id, ghsa: GHSA.exec(advisory.url)?.[0] }, ignore));
@@ -1538,11 +1537,50 @@ function findingsOf(audit, reaching, direct, level, ignore = []) {
1538
1537
  advisories,
1539
1538
  scope: reaching.has(name) ? "prod" : "dev",
1540
1539
  direct: direct.has(name),
1540
+ via: direct.has(name) ? [] : via.get(name) ?? [],
1541
1541
  fix: fixFor(kept)
1542
1542
  });
1543
1543
  }
1544
1544
  return found.toSorted((a, b) => severityRank(b.severity) - severityRank(a.severity) || Number(b.scope === "prod") - Number(a.scope === "prod") || a.package.localeCompare(b.package));
1545
1545
  }
1546
+ function lockGraph(lockText) {
1547
+ const graph = new Map;
1548
+ let lock;
1549
+ try {
1550
+ lock = Bun.JSONC.parse(lockText);
1551
+ } catch {
1552
+ return graph;
1553
+ }
1554
+ for (const entry of Object.values(lock?.packages ?? {})) {
1555
+ const resolution = entry[0];
1556
+ const info = entry[2];
1557
+ if (typeof resolution !== "string" || typeof info !== "object" || info === null)
1558
+ continue;
1559
+ const at = resolution.indexOf("@", 1);
1560
+ const name = at === -1 ? resolution : resolution.slice(0, at);
1561
+ const wanted = DEPENDENCY_KINDS.flatMap((kind) => Object.keys(info[kind] ?? {}));
1562
+ graph.set(name, [...new Set([...graph.get(name) ?? [], ...wanted])]);
1563
+ }
1564
+ return graph;
1565
+ }
1566
+ function reachedFrom(graph, direct, targets) {
1567
+ const from = new Map;
1568
+ for (const start of direct) {
1569
+ const seen = new Set([start]);
1570
+ const queue = [start];
1571
+ for (let name = queue.shift();name !== undefined; name = queue.shift()) {
1572
+ if (name !== start && targets.has(name))
1573
+ from.set(name, [...from.get(name) ?? [], start]);
1574
+ for (const next of graph.get(name) ?? []) {
1575
+ if (!seen.has(next)) {
1576
+ seen.add(next);
1577
+ queue.push(next);
1578
+ }
1579
+ }
1580
+ }
1581
+ }
1582
+ return new Map([...from].map(([name, starts]) => [name, starts.toSorted()]));
1583
+ }
1546
1584
  function readManifest(path) {
1547
1585
  try {
1548
1586
  return existsSync5(path) ? JSON.parse(readFileSync4(path, "utf8")) : {};
@@ -1578,8 +1616,8 @@ function workspaceFolders(root, children) {
1578
1616
  // src/audit.ts
1579
1617
  var USAGE = `audit [options] [root]: the known vulnerabilities of the Bun repositories under root (the current folder by default), one table per repository
1580
1618
 
1581
- Each package with an advisory is one row: its worst severity, how many advisories, whether a production dependency needs it (prod) or only a development one (dev), whether the repository asks for it itself (direct) or a dependency does (the row then says via), and the version that fixes every advisory at once, "-" when an advisory names none. The worst and the production ones come first.
1582
- It runs \`bun audit --json\` in each repository holding a bun.lock, which reaches the registry; the walk goes three levels deep, stops at a bun.lock and skips node_modules and hidden folders.
1619
+ Each package with an advisory is one row: its worst severity, how many advisories, whether a production dependency needs it (prod) or only a development one (dev), whether the repository asks for it itself (direct) or a dependency does (the row then says via and the direct dependencies leading to it, upgrading one of which is what fixes it), and the version that fixes every advisory at once, "-" when an advisory names none. The worst and the production ones come first.
1620
+ Advisories under --level (moderate by default) are counted under the table, and what \`bun audit\` warned about, such as a private registry that would not audit its packages, is repeated there. It runs \`bun audit --json\` in each repository holding a bun.lock, which reaches the registry; the walk goes three levels deep, stops at a bun.lock and skips node_modules and hidden folders.
1583
1621
 
1584
1622
  Reach for it to sweep many repositories at once; \`pkg audit\` vets the one repository in a folder (package age, install scripts, licences) as well as its advisories, and shares --level, --prod and --ignore.`;
1585
1623
  var EXITS = [[0, "no repository has an advisory at the level asked"], [1, "one has"], [2, "a repository's audit failed, no bun.lock sits under root, a usage error or a root that is no folder"]];
@@ -1587,11 +1625,16 @@ var OPTIONS = {
1587
1625
  level: { type: "string", choices: SEVERITIES, default: "moderate", description: "only the advisories at least this severe: low, moderate, high or critical" },
1588
1626
  prod: { type: "boolean", description: "only the packages a production dependency needs" },
1589
1627
  ignore: { type: "string", multiple: true, description: "an advisory skipped by GHSA or numeric id, repeatable" },
1590
- json: jsonOption("[{repo, path, findings: [{package, severity, scope, direct, fix, advisories: [{id, ghsa, url, title, severity, fixed}]}], error}]")
1628
+ json: jsonOption("[{repo, path, findings: [{package, severity, scope, direct, via, fix, advisories: [{id, ghsa, url, title, severity, fixed}]}], below: advisories under --level, warnings: what bun audit could not audit, error}]")
1591
1629
  };
1592
1630
  var MAX_DEPTH = 3;
1593
1631
  var CONCURRENCY = 4;
1594
1632
  var AUDIT_MS = 60000;
1633
+ var WARNING = /^warn: .+$/gm;
1634
+ var VIA_SHOWN = 2;
1635
+ function countAdvisories(findings) {
1636
+ return findings.reduce((sum, found) => sum + found.advisories.length, 0);
1637
+ }
1595
1638
  function holdsLock(dir) {
1596
1639
  return existsSync6(join8(dir, "bun.lock")) || existsSync6(join8(dir, "bun.lockb"));
1597
1640
  }
@@ -1636,10 +1679,26 @@ async function audited(path, shown, level, ignore) {
1636
1679
  const audit = parseAudit(stdoutOf(all));
1637
1680
  const reached = parseAudit(stdoutOf(production));
1638
1681
  if (audit === undefined || reached === undefined)
1639
- return { repo: shown, path, findings: [], error: failure(audit === undefined ? all : production) };
1682
+ return { repo: shown, path, findings: [], below: 0, warnings: [], error: failure(audit === undefined ? all : production) };
1640
1683
  const reaching = new Set(Object.keys(reached));
1641
1684
  const direct = directDependencies(path, workspaceFolders(path, children(path)));
1642
- return { repo: shown, path, findings: findingsOf(audit, reaching, direct, level, ignore), error: undefined };
1685
+ const via = reachedFrom(lockGraph(lockText(path)), direct, new Set(Object.keys(audit)));
1686
+ const findings = findingsOf(audit, reaching, direct, level, ignore, via);
1687
+ return { repo: shown, path, findings, below: countAdvisories(findingsOf(audit, reaching, direct, "low", ignore)) - countAdvisories(findings), warnings: [...new Set(all.text.match(WARNING) ?? [])], error: undefined };
1688
+ }
1689
+ function lockText(path) {
1690
+ try {
1691
+ return readFileSync5(join8(path, "bun.lock"), "utf8");
1692
+ } catch {
1693
+ return "";
1694
+ }
1695
+ }
1696
+ function originOf(found) {
1697
+ if (found.direct)
1698
+ return "direct";
1699
+ if (found.via.length === 0)
1700
+ return "via";
1701
+ return `via ${found.via.slice(0, VIA_SHOWN).join(", ")}${found.via.length > VIA_SHOWN ? ` +${found.via.length - VIA_SHOWN}` : ""}`;
1643
1702
  }
1644
1703
  function stdoutOf(ran) {
1645
1704
  return Buffer.concat(ran.chunks.filter((chunk) => chunk.stream === "stdout").map((chunk) => chunk.data)).toString();
@@ -1660,7 +1719,7 @@ function rows(findings) {
1660
1719
  tint(found.severity)(found.severity),
1661
1720
  String(found.advisories.length),
1662
1721
  found.scope,
1663
- found.direct ? "direct" : "via",
1722
+ originOf(found),
1664
1723
  found.fix ?? "-"
1665
1724
  ]);
1666
1725
  }
@@ -1695,6 +1754,12 @@ function show(audits, total) {
1695
1754
  console.log(`${path(each.repo)} ${label(each.error === undefined ? `${each.findings.length} ${each.findings.length === 1 ? "package" : "packages"}` : `audit failed: ${each.error}`)}`);
1696
1755
  if (each.findings.length > 0)
1697
1756
  console.log(table([["package", "severity", "advisories", "scope", "origin", "fix"], ...rows(each.findings)], { header: true, align: ["left", "left", "right", "left", "left", "left"] }));
1757
+ if (each.findings.some((found) => !found.direct))
1758
+ console.log(label("via: a dependency of the ones named, fixed by upgrading one of them to a release that depends on the fixed version"));
1759
+ if (each.below > 0)
1760
+ console.log(label(`${each.below} ${each.below === 1 ? "advisory" : "advisories"} below the level left out, --level low lists them`));
1761
+ for (const warning of each.warnings)
1762
+ console.log(label(warning));
1698
1763
  }
1699
1764
  }
1700
1765
 
package/dist/cli.js CHANGED
@@ -743,7 +743,6 @@ var DASHES = /^-+/;
743
743
  function jsonOption(holds) {
744
744
  return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
745
745
  }
746
-
747
746
  class Exit extends Error {
748
747
  code;
749
748
  hint;
@@ -1505,7 +1504,7 @@ function workspaceRoot({ given, env = process14.env, home = homedir4() } = {}) {
1505
1504
  return resolve3(expandHome(given ?? fromEnv ?? configured(env, home) ?? join6(home, "Workspace"), home));
1506
1505
  }
1507
1506
  // src/audit.ts
1508
- import { existsSync as existsSync6, readdirSync, statSync as statSync2 } from "fs";
1507
+ import { existsSync as existsSync6, readdirSync, readFileSync as readFileSync5, statSync as statSync2 } from "fs";
1509
1508
  import { readdir } from "fs/promises";
1510
1509
  import { join as join8, relative, resolve as resolve4 } from "path";
1511
1510
  import process16 from "process";
@@ -1536,7 +1535,7 @@ function fixFor(advisories) {
1536
1535
  return;
1537
1536
  return fixes.reduce((highest, fix) => Bun.semver.order(fix, highest) > 0 ? fix : highest);
1538
1537
  }
1539
- function findingsOf(audit, reaching, direct, level, ignore = []) {
1538
+ function findingsOf(audit, reaching, direct, level, ignore = [], via = new Map) {
1540
1539
  const found = [];
1541
1540
  for (const [name, all] of Object.entries(audit)) {
1542
1541
  const kept = all.filter((advisory) => severityRank(advisory.severity) >= severityRank(level) && !isIgnored({ id: advisory.id, ghsa: GHSA.exec(advisory.url)?.[0] }, ignore));
@@ -1549,11 +1548,50 @@ function findingsOf(audit, reaching, direct, level, ignore = []) {
1549
1548
  advisories,
1550
1549
  scope: reaching.has(name) ? "prod" : "dev",
1551
1550
  direct: direct.has(name),
1551
+ via: direct.has(name) ? [] : via.get(name) ?? [],
1552
1552
  fix: fixFor(kept)
1553
1553
  });
1554
1554
  }
1555
1555
  return found.toSorted((a, b) => severityRank(b.severity) - severityRank(a.severity) || Number(b.scope === "prod") - Number(a.scope === "prod") || a.package.localeCompare(b.package));
1556
1556
  }
1557
+ function lockGraph(lockText) {
1558
+ const graph = new Map;
1559
+ let lock;
1560
+ try {
1561
+ lock = Bun.JSONC.parse(lockText);
1562
+ } catch {
1563
+ return graph;
1564
+ }
1565
+ for (const entry of Object.values(lock?.packages ?? {})) {
1566
+ const resolution = entry[0];
1567
+ const info = entry[2];
1568
+ if (typeof resolution !== "string" || typeof info !== "object" || info === null)
1569
+ continue;
1570
+ const at = resolution.indexOf("@", 1);
1571
+ const name = at === -1 ? resolution : resolution.slice(0, at);
1572
+ const wanted = DEPENDENCY_KINDS.flatMap((kind) => Object.keys(info[kind] ?? {}));
1573
+ graph.set(name, [...new Set([...graph.get(name) ?? [], ...wanted])]);
1574
+ }
1575
+ return graph;
1576
+ }
1577
+ function reachedFrom(graph, direct, targets) {
1578
+ const from = new Map;
1579
+ for (const start of direct) {
1580
+ const seen = new Set([start]);
1581
+ const queue = [start];
1582
+ for (let name = queue.shift();name !== undefined; name = queue.shift()) {
1583
+ if (name !== start && targets.has(name))
1584
+ from.set(name, [...from.get(name) ?? [], start]);
1585
+ for (const next of graph.get(name) ?? []) {
1586
+ if (!seen.has(next)) {
1587
+ seen.add(next);
1588
+ queue.push(next);
1589
+ }
1590
+ }
1591
+ }
1592
+ }
1593
+ return new Map([...from].map(([name, starts]) => [name, starts.toSorted()]));
1594
+ }
1557
1595
  function readManifest(path) {
1558
1596
  try {
1559
1597
  return existsSync5(path) ? JSON.parse(readFileSync4(path, "utf8")) : {};
@@ -1589,8 +1627,8 @@ function workspaceFolders(root, children) {
1589
1627
  // src/audit.ts
1590
1628
  var USAGE = `audit [options] [root]: the known vulnerabilities of the Bun repositories under root (the current folder by default), one table per repository
1591
1629
 
1592
- Each package with an advisory is one row: its worst severity, how many advisories, whether a production dependency needs it (prod) or only a development one (dev), whether the repository asks for it itself (direct) or a dependency does (the row then says via), and the version that fixes every advisory at once, "-" when an advisory names none. The worst and the production ones come first.
1593
- It runs \`bun audit --json\` in each repository holding a bun.lock, which reaches the registry; the walk goes three levels deep, stops at a bun.lock and skips node_modules and hidden folders.
1630
+ Each package with an advisory is one row: its worst severity, how many advisories, whether a production dependency needs it (prod) or only a development one (dev), whether the repository asks for it itself (direct) or a dependency does (the row then says via and the direct dependencies leading to it, upgrading one of which is what fixes it), and the version that fixes every advisory at once, "-" when an advisory names none. The worst and the production ones come first.
1631
+ Advisories under --level (moderate by default) are counted under the table, and what \`bun audit\` warned about, such as a private registry that would not audit its packages, is repeated there. It runs \`bun audit --json\` in each repository holding a bun.lock, which reaches the registry; the walk goes three levels deep, stops at a bun.lock and skips node_modules and hidden folders.
1594
1632
 
1595
1633
  Reach for it to sweep many repositories at once; \`pkg audit\` vets the one repository in a folder (package age, install scripts, licences) as well as its advisories, and shares --level, --prod and --ignore.`;
1596
1634
  var EXITS = [[0, "no repository has an advisory at the level asked"], [1, "one has"], [2, "a repository's audit failed, no bun.lock sits under root, a usage error or a root that is no folder"]];
@@ -1598,11 +1636,16 @@ var OPTIONS = {
1598
1636
  level: { type: "string", choices: SEVERITIES, default: "moderate", description: "only the advisories at least this severe: low, moderate, high or critical" },
1599
1637
  prod: { type: "boolean", description: "only the packages a production dependency needs" },
1600
1638
  ignore: { type: "string", multiple: true, description: "an advisory skipped by GHSA or numeric id, repeatable" },
1601
- json: jsonOption("[{repo, path, findings: [{package, severity, scope, direct, fix, advisories: [{id, ghsa, url, title, severity, fixed}]}], error}]")
1639
+ json: jsonOption("[{repo, path, findings: [{package, severity, scope, direct, via, fix, advisories: [{id, ghsa, url, title, severity, fixed}]}], below: advisories under --level, warnings: what bun audit could not audit, error}]")
1602
1640
  };
1603
1641
  var MAX_DEPTH = 3;
1604
1642
  var CONCURRENCY = 4;
1605
1643
  var AUDIT_MS = 60000;
1644
+ var WARNING = /^warn: .+$/gm;
1645
+ var VIA_SHOWN = 2;
1646
+ function countAdvisories(findings) {
1647
+ return findings.reduce((sum, found) => sum + found.advisories.length, 0);
1648
+ }
1606
1649
  function holdsLock(dir) {
1607
1650
  return existsSync6(join8(dir, "bun.lock")) || existsSync6(join8(dir, "bun.lockb"));
1608
1651
  }
@@ -1647,10 +1690,26 @@ async function audited(path, shown, level, ignore) {
1647
1690
  const audit = parseAudit(stdoutOf(all));
1648
1691
  const reached = parseAudit(stdoutOf(production));
1649
1692
  if (audit === undefined || reached === undefined)
1650
- return { repo: shown, path, findings: [], error: failure(audit === undefined ? all : production) };
1693
+ return { repo: shown, path, findings: [], below: 0, warnings: [], error: failure(audit === undefined ? all : production) };
1651
1694
  const reaching = new Set(Object.keys(reached));
1652
1695
  const direct = directDependencies(path, workspaceFolders(path, children(path)));
1653
- return { repo: shown, path, findings: findingsOf(audit, reaching, direct, level, ignore), error: undefined };
1696
+ const via = reachedFrom(lockGraph(lockText(path)), direct, new Set(Object.keys(audit)));
1697
+ const findings = findingsOf(audit, reaching, direct, level, ignore, via);
1698
+ return { repo: shown, path, findings, below: countAdvisories(findingsOf(audit, reaching, direct, "low", ignore)) - countAdvisories(findings), warnings: [...new Set(all.text.match(WARNING) ?? [])], error: undefined };
1699
+ }
1700
+ function lockText(path) {
1701
+ try {
1702
+ return readFileSync5(join8(path, "bun.lock"), "utf8");
1703
+ } catch {
1704
+ return "";
1705
+ }
1706
+ }
1707
+ function originOf(found) {
1708
+ if (found.direct)
1709
+ return "direct";
1710
+ if (found.via.length === 0)
1711
+ return "via";
1712
+ return `via ${found.via.slice(0, VIA_SHOWN).join(", ")}${found.via.length > VIA_SHOWN ? ` +${found.via.length - VIA_SHOWN}` : ""}`;
1654
1713
  }
1655
1714
  function stdoutOf(ran) {
1656
1715
  return Buffer.concat(ran.chunks.filter((chunk) => chunk.stream === "stdout").map((chunk) => chunk.data)).toString();
@@ -1671,7 +1730,7 @@ function rows(findings) {
1671
1730
  tint(found.severity)(found.severity),
1672
1731
  String(found.advisories.length),
1673
1732
  found.scope,
1674
- found.direct ? "direct" : "via",
1733
+ originOf(found),
1675
1734
  found.fix ?? "-"
1676
1735
  ]);
1677
1736
  }
@@ -1706,6 +1765,12 @@ function show(audits, total) {
1706
1765
  console.log(`${path(each.repo)} ${label(each.error === undefined ? `${each.findings.length} ${each.findings.length === 1 ? "package" : "packages"}` : `audit failed: ${each.error}`)}`);
1707
1766
  if (each.findings.length > 0)
1708
1767
  console.log(table([["package", "severity", "advisories", "scope", "origin", "fix"], ...rows(each.findings)], { header: true, align: ["left", "left", "right", "left", "left", "left"] }));
1768
+ if (each.findings.some((found) => !found.direct))
1769
+ console.log(label("via: a dependency of the ones named, fixed by upgrading one of them to a release that depends on the fixed version"));
1770
+ if (each.below > 0)
1771
+ console.log(label(`${each.below} ${each.below === 1 ? "advisory" : "advisories"} below the level left out, --level low lists them`));
1772
+ for (const warning of each.warnings)
1773
+ console.log(label(warning));
1709
1774
  }
1710
1775
  }
1711
1776
 
@@ -1980,9 +2045,20 @@ import { relative as relative3 } from "path";
1980
2045
  import process19 from "process";
1981
2046
  var KEY_SEQUENCES = /\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|[\s\S]/giu;
1982
2047
  var CONTROL2 = /^[\x00-\x1F\x7F]/;
1983
- var KEYS = { "\x1B[A": "up", "\x1BOA": "up", "\x1B[B": "down", "\x1BOB": "down", "\r": "enter", "\n": "enter", "\x03": "cancel", "\x1B": "cancel", "\x7F": "erase", "\b": "erase" };
1984
- function readKeys(input) {
1985
- return (input.match(KEY_SEQUENCES) ?? []).flatMap((sequence) => KEYS[sequence] ?? (CONTROL2.test(sequence) ? [] : [{ text: sequence }]));
2048
+ var PASTE_START = "\x1B[200~";
2049
+ var PASTE_END = "\x1B[201~";
2050
+ var KEYS = { "\x1B[A": "up", "\x1BOA": "up", "\x1B[B": "down", "\x1BOB": "down", "\x1B[5~": "pageup", "\x1B[6~": "pagedown", "\x1B[H": "home", "\x1B[1~": "home", "\x1BOH": "home", "\x1B[F": "end", "\x1B[4~": "end", "\x1BOF": "end", "\r": "enter", "\n": "enter", "\x03": "cancel", "\x1B": "cancel", "\x7F": "erase", "\b": "erase" };
2051
+ function readKeys(input, paste = { active: false }) {
2052
+ return (input.match(KEY_SEQUENCES) ?? []).flatMap((sequence) => {
2053
+ if (sequence === PASTE_START || sequence === PASTE_END) {
2054
+ paste.active = sequence === PASTE_START;
2055
+ return [];
2056
+ }
2057
+ if (paste.active && (sequence === "\r" || sequence === `
2058
+ `))
2059
+ return [];
2060
+ return KEYS[sequence] ?? (CONTROL2.test(sequence) ? [] : [{ text: sequence }]);
2061
+ });
1986
2062
  }
1987
2063
  async function confirm(question, { default: fallback, ...settings } = {}) {
1988
2064
  let answered = fallback;
@@ -2011,22 +2087,29 @@ async function ask(question, { hint, terminal = process19 }, render, press) {
2011
2087
  if (!isInteractive(terminal))
2012
2088
  fail(`cannot ask "${question}" off a terminal`, 2, hint);
2013
2089
  const colors = paint(stderr);
2014
- let drawn = 0;
2090
+ let drawn = [];
2091
+ let current = "asking";
2015
2092
  let outcome;
2093
+ const columns = () => stderr.columns || 80;
2016
2094
  const draw = (state) => {
2017
- const frame = render(colors, state, { columns: stderr.columns || 80, rows: stderr.rows || 24 });
2018
- stderr.write(`${drawn > 1 ? `\x1B[${drawn - 1}A` : ""}\r\x1B[0J${frame.join(`
2095
+ const frame = render(colors, state, { columns: columns(), rows: stderr.rows || 24 });
2096
+ const rows = drawn.reduce((sum, line) => sum + Math.max(1, Math.ceil(Bun.stringWidth(line) / columns())), 0);
2097
+ stderr.write(`${rows > 1 ? `\x1B[${rows - 1}A` : ""}\r\x1B[0J${frame.join(`
2019
2098
  `)}`);
2020
- drawn = frame.length;
2099
+ drawn = frame;
2100
+ current = state;
2021
2101
  };
2102
+ const redraw = () => draw(current);
2103
+ const paste = { active: false };
2022
2104
  try {
2105
+ stderr.on?.("resize", redraw);
2023
2106
  stdin.setRawMode(true);
2024
2107
  stdin.resume();
2025
- stderr.write("\x1B[?25l");
2108
+ stderr.write("\x1B[?25l\x1B[?2004h");
2026
2109
  draw("asking");
2027
2110
  return await new Promise((resolve) => {
2028
2111
  function onData(data) {
2029
- for (const key of readKeys(data.toString())) {
2112
+ for (const key of readKeys(data.toString(), paste)) {
2030
2113
  const pressed = press(key);
2031
2114
  if (pressed !== undefined) {
2032
2115
  settle(pressed);
@@ -2048,9 +2131,10 @@ async function ask(question, { hint, terminal = process19 }, render, press) {
2048
2131
  stdin.on("end", onEnd);
2049
2132
  });
2050
2133
  } finally {
2134
+ stderr.off?.("resize", redraw);
2051
2135
  draw(outcome ?? "cancel");
2052
2136
  stderr.write(`
2053
- \x1B[?25h`);
2137
+ \x1B[?25h\x1B[?2004l`);
2054
2138
  stdin.setRawMode(false);
2055
2139
  stdin.pause();
2056
2140
  }
package/dist/repos-cli.js CHANGED
@@ -732,7 +732,6 @@ var DASHES = /^-+/;
732
732
  function jsonOption(holds) {
733
733
  return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
734
734
  }
735
-
736
735
  class Exit extends Error {
737
736
  code;
738
737
  hint;
package/dist/sweep-cli.js CHANGED
@@ -743,7 +743,6 @@ var DASHES = /^-+/;
743
743
  function jsonOption(holds) {
744
744
  return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
745
745
  }
746
-
747
746
  class Exit extends Error {
748
747
  code;
749
748
  hint;
@@ -1513,9 +1512,20 @@ import { relative } from "path";
1513
1512
  import process16 from "process";
1514
1513
  var KEY_SEQUENCES = /\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|[\s\S]/giu;
1515
1514
  var CONTROL2 = /^[\x00-\x1F\x7F]/;
1516
- var KEYS = { "\x1B[A": "up", "\x1BOA": "up", "\x1B[B": "down", "\x1BOB": "down", "\r": "enter", "\n": "enter", "\x03": "cancel", "\x1B": "cancel", "\x7F": "erase", "\b": "erase" };
1517
- function readKeys(input) {
1518
- return (input.match(KEY_SEQUENCES) ?? []).flatMap((sequence) => KEYS[sequence] ?? (CONTROL2.test(sequence) ? [] : [{ text: sequence }]));
1515
+ var PASTE_START = "\x1B[200~";
1516
+ var PASTE_END = "\x1B[201~";
1517
+ var KEYS = { "\x1B[A": "up", "\x1BOA": "up", "\x1B[B": "down", "\x1BOB": "down", "\x1B[5~": "pageup", "\x1B[6~": "pagedown", "\x1B[H": "home", "\x1B[1~": "home", "\x1BOH": "home", "\x1B[F": "end", "\x1B[4~": "end", "\x1BOF": "end", "\r": "enter", "\n": "enter", "\x03": "cancel", "\x1B": "cancel", "\x7F": "erase", "\b": "erase" };
1518
+ function readKeys(input, paste = { active: false }) {
1519
+ return (input.match(KEY_SEQUENCES) ?? []).flatMap((sequence) => {
1520
+ if (sequence === PASTE_START || sequence === PASTE_END) {
1521
+ paste.active = sequence === PASTE_START;
1522
+ return [];
1523
+ }
1524
+ if (paste.active && (sequence === "\r" || sequence === `
1525
+ `))
1526
+ return [];
1527
+ return KEYS[sequence] ?? (CONTROL2.test(sequence) ? [] : [{ text: sequence }]);
1528
+ });
1519
1529
  }
1520
1530
  async function confirm(question, { default: fallback, ...settings } = {}) {
1521
1531
  let answered = fallback;
@@ -1544,22 +1554,29 @@ async function ask(question, { hint, terminal = process16 }, render, press) {
1544
1554
  if (!isInteractive(terminal))
1545
1555
  fail(`cannot ask "${question}" off a terminal`, 2, hint);
1546
1556
  const colors = paint(stderr);
1547
- let drawn = 0;
1557
+ let drawn = [];
1558
+ let current = "asking";
1548
1559
  let outcome;
1560
+ const columns = () => stderr.columns || 80;
1549
1561
  const draw = (state) => {
1550
- const frame = render(colors, state, { columns: stderr.columns || 80, rows: stderr.rows || 24 });
1551
- stderr.write(`${drawn > 1 ? `\x1B[${drawn - 1}A` : ""}\r\x1B[0J${frame.join(`
1562
+ const frame = render(colors, state, { columns: columns(), rows: stderr.rows || 24 });
1563
+ const rows = drawn.reduce((sum, line) => sum + Math.max(1, Math.ceil(Bun.stringWidth(line) / columns())), 0);
1564
+ stderr.write(`${rows > 1 ? `\x1B[${rows - 1}A` : ""}\r\x1B[0J${frame.join(`
1552
1565
  `)}`);
1553
- drawn = frame.length;
1566
+ drawn = frame;
1567
+ current = state;
1554
1568
  };
1569
+ const redraw = () => draw(current);
1570
+ const paste = { active: false };
1555
1571
  try {
1572
+ stderr.on?.("resize", redraw);
1556
1573
  stdin.setRawMode(true);
1557
1574
  stdin.resume();
1558
- stderr.write("\x1B[?25l");
1575
+ stderr.write("\x1B[?25l\x1B[?2004h");
1559
1576
  draw("asking");
1560
1577
  return await new Promise((resolve) => {
1561
1578
  function onData(data) {
1562
- for (const key of readKeys(data.toString())) {
1579
+ for (const key of readKeys(data.toString(), paste)) {
1563
1580
  const pressed = press(key);
1564
1581
  if (pressed !== undefined) {
1565
1582
  settle(pressed);
@@ -1581,9 +1598,10 @@ async function ask(question, { hint, terminal = process16 }, render, press) {
1581
1598
  stdin.on("end", onEnd);
1582
1599
  });
1583
1600
  } finally {
1601
+ stderr.off?.("resize", redraw);
1584
1602
  draw(outcome ?? "cancel");
1585
1603
  stderr.write(`
1586
- \x1B[?25h`);
1604
+ \x1B[?25h\x1B[?2004l`);
1587
1605
  stdin.setRawMode(false);
1588
1606
  stdin.pause();
1589
1607
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kaynooo/cli-workspace",
3
3
  "type": "module",
4
- "version": "0.4.0",
4
+ "version": "0.6.0",
5
5
  "description": "ws, repos, sweep, audit: the repositories of the workspace that need attention, the folders worth reclaiming and their known vulnerabilities.",
6
6
  "author": "Kaynooo <contact@kaynooo.fr>",
7
7
  "license": "MIT",
@@ -34,6 +34,6 @@
34
34
  "audit": "$npm_execpath src/audit-cli.ts"
35
35
  },
36
36
  "devDependencies": {
37
- "@kaynooo/cli-kit": "0.23.0"
37
+ "@kaynooo/cli-kit": "0.25.0"
38
38
  }
39
39
  }