@kaynooo/cli-workspace 0.5.0 → 0.7.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 +61 -10
- package/dist/cli.js +129 -31
- package/dist/repos-cli.js +73 -19
- package/dist/sweep-cli.js +107 -12
- package/package.json +2 -2
package/dist/audit-cli.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/audit-cli.ts
|
|
5
|
-
import
|
|
5
|
+
import process18 from "process";
|
|
6
6
|
|
|
7
7
|
// ../kit/src/advisory.ts
|
|
8
8
|
var SEVERITIES = ["low", "moderate", "high", "critical"];
|
|
@@ -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;
|
|
@@ -1467,11 +1466,63 @@ function parseSize(text, bareUnit = 1) {
|
|
|
1467
1466
|
const suffix = match[2].toLowerCase();
|
|
1468
1467
|
return Math.round(Number(match[1]) * (suffix === "" ? bareUnit : 1024 ** POWERS[suffix]));
|
|
1469
1468
|
}
|
|
1469
|
+
// ../kit/src/watch.ts
|
|
1470
|
+
import process14 from "process";
|
|
1471
|
+
import { format } from "util";
|
|
1472
|
+
var CLEAR_SCREEN = "\x1B[H\x1B[2J";
|
|
1473
|
+
var DEFAULT_SECONDS = 2;
|
|
1474
|
+
var ATTACHED_SHORT = /^-w./;
|
|
1475
|
+
var INTERVAL = /^\d+(?:\.\d+)?(?:ms|[smh])?$/;
|
|
1476
|
+
function watchOption(what) {
|
|
1477
|
+
return { type: "string", short: "w", optional: { bare: "", accepts: INTERVAL }, description: `redraw ${what} every 2s, or every interval given (500ms, 5s), until ctrl-c` };
|
|
1478
|
+
}
|
|
1479
|
+
function withoutWatch(args) {
|
|
1480
|
+
const rest = [];
|
|
1481
|
+
for (let at = 0;at < args.length; at++) {
|
|
1482
|
+
const arg = args[at];
|
|
1483
|
+
if (arg === "--watch" || arg === "-w") {
|
|
1484
|
+
if (args[at + 1] !== undefined && INTERVAL.test(args[at + 1]))
|
|
1485
|
+
at++;
|
|
1486
|
+
} else if (!arg.startsWith("--watch=") && !ATTACHED_SHORT.test(arg)) {
|
|
1487
|
+
rest.push(arg);
|
|
1488
|
+
}
|
|
1489
|
+
}
|
|
1490
|
+
return rest;
|
|
1491
|
+
}
|
|
1492
|
+
async function watching(value, step, stream = process14.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
|
|
1493
|
+
const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
|
|
1494
|
+
if (!takesControlCodes(stream))
|
|
1495
|
+
badUsage("--watch redraws the screen, so it needs a terminal");
|
|
1496
|
+
let code = 0;
|
|
1497
|
+
for (let round = 0;round < rounds; round++) {
|
|
1498
|
+
const held = [];
|
|
1499
|
+
const { log, info } = console;
|
|
1500
|
+
const write = process14.stdout.write.bind(process14.stdout);
|
|
1501
|
+
const hold = (...parts) => void held.push(`${format(...parts)}
|
|
1502
|
+
`);
|
|
1503
|
+
console.log = hold;
|
|
1504
|
+
console.info = hold;
|
|
1505
|
+
process14.stdout.write = (text) => {
|
|
1506
|
+
held.push(typeof text === "string" ? text : Buffer.from(text).toString());
|
|
1507
|
+
return true;
|
|
1508
|
+
};
|
|
1509
|
+
try {
|
|
1510
|
+
code = await step();
|
|
1511
|
+
} finally {
|
|
1512
|
+
console.log = log;
|
|
1513
|
+
console.info = info;
|
|
1514
|
+
process14.stdout.write = write;
|
|
1515
|
+
}
|
|
1516
|
+
stream.write(`${CLEAR_SCREEN}${held.join("")}`);
|
|
1517
|
+
await sleep(interval);
|
|
1518
|
+
}
|
|
1519
|
+
return code;
|
|
1520
|
+
}
|
|
1470
1521
|
// ../kit/src/workspace-root.ts
|
|
1471
1522
|
import { existsSync as existsSync4, mkdirSync as mkdirSync2, readFileSync as readFileSync3, writeFileSync } from "fs";
|
|
1472
1523
|
import { homedir as homedir4 } from "os";
|
|
1473
1524
|
import { dirname as dirname4, join as join6, resolve as resolve3 } from "path";
|
|
1474
|
-
import
|
|
1525
|
+
import process15 from "process";
|
|
1475
1526
|
function expandHome(path, home) {
|
|
1476
1527
|
if (path === "~")
|
|
1477
1528
|
return home;
|
|
@@ -1489,7 +1540,7 @@ function configured(env, home) {
|
|
|
1489
1540
|
return;
|
|
1490
1541
|
}
|
|
1491
1542
|
}
|
|
1492
|
-
function workspaceRoot({ given, env =
|
|
1543
|
+
function workspaceRoot({ given, env = process15.env, home = homedir4() } = {}) {
|
|
1493
1544
|
const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
|
|
1494
1545
|
return resolve3(expandHome(given ?? fromEnv ?? configured(env, home) ?? join6(home, "Workspace"), home));
|
|
1495
1546
|
}
|
|
@@ -1497,7 +1548,7 @@ function workspaceRoot({ given, env = process14.env, home = homedir4() } = {}) {
|
|
|
1497
1548
|
import { existsSync as existsSync6, readdirSync, readFileSync as readFileSync5, statSync as statSync2 } from "fs";
|
|
1498
1549
|
import { readdir } from "fs/promises";
|
|
1499
1550
|
import { join as join8, relative, resolve as resolve4 } from "path";
|
|
1500
|
-
import
|
|
1551
|
+
import process17 from "process";
|
|
1501
1552
|
|
|
1502
1553
|
// src/report.ts
|
|
1503
1554
|
import { existsSync as existsSync5, readFileSync as readFileSync4 } from "fs";
|
|
@@ -1626,7 +1677,7 @@ var OPTIONS = {
|
|
|
1626
1677
|
level: { type: "string", choices: SEVERITIES, default: "moderate", description: "only the advisories at least this severe: low, moderate, high or critical" },
|
|
1627
1678
|
prod: { type: "boolean", description: "only the packages a production dependency needs" },
|
|
1628
1679
|
ignore: { type: "string", multiple: true, description: "an advisory skipped by GHSA or numeric id, repeatable" },
|
|
1629
|
-
json: jsonOption("[{repo, path, findings: [{package, severity, scope, direct, via, fix, advisories: [{id, ghsa, url, title, severity, fixed}]}], error}]")
|
|
1680
|
+
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}]")
|
|
1630
1681
|
};
|
|
1631
1682
|
var MAX_DEPTH = 3;
|
|
1632
1683
|
var CONCURRENCY = 4;
|
|
@@ -1709,7 +1760,7 @@ function failure(ran) {
|
|
|
1709
1760
|
`).at(-1) ?? `exit ${ran.code}`;
|
|
1710
1761
|
}
|
|
1711
1762
|
function tint(severity) {
|
|
1712
|
-
const colors = paint(
|
|
1763
|
+
const colors = paint(process17.stdout);
|
|
1713
1764
|
if (severity === "critical" || severity === "high")
|
|
1714
1765
|
return colors.red;
|
|
1715
1766
|
return severity === "moderate" ? colors.yellow : colors.dim;
|
|
@@ -1744,8 +1795,8 @@ async function audit(args) {
|
|
|
1744
1795
|
return kept.some((each) => each.findings.length > 0) ? 1 : 0;
|
|
1745
1796
|
}
|
|
1746
1797
|
function show(audits, total) {
|
|
1747
|
-
const label = role("label",
|
|
1748
|
-
const path = role("path",
|
|
1798
|
+
const label = role("label", process17.stdout);
|
|
1799
|
+
const path = role("path", process17.stdout);
|
|
1749
1800
|
const flagged = audits.filter((each) => each.error !== undefined || each.findings.length > 0);
|
|
1750
1801
|
if (flagged.length === 0) {
|
|
1751
1802
|
console.log(label(`no advisory in ${total} ${total === 1 ? "repository" : "repositories"}`));
|
|
@@ -1765,4 +1816,4 @@ function show(audits, total) {
|
|
|
1765
1816
|
}
|
|
1766
1817
|
|
|
1767
1818
|
// src/audit-cli.ts
|
|
1768
|
-
|
|
1819
|
+
process18.exitCode = await runMain({ name: "audit", run: audit });
|
package/dist/cli.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/cli.ts
|
|
5
|
-
import
|
|
5
|
+
import process21 from "process";
|
|
6
6
|
|
|
7
7
|
// ../kit/src/advisory.ts
|
|
8
8
|
var SEVERITIES = ["low", "moderate", "high", "critical"];
|
|
@@ -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;
|
|
@@ -1478,11 +1477,63 @@ function parseSize(text, bareUnit = 1) {
|
|
|
1478
1477
|
const suffix = match[2].toLowerCase();
|
|
1479
1478
|
return Math.round(Number(match[1]) * (suffix === "" ? bareUnit : 1024 ** POWERS[suffix]));
|
|
1480
1479
|
}
|
|
1480
|
+
// ../kit/src/watch.ts
|
|
1481
|
+
import process14 from "process";
|
|
1482
|
+
import { format } from "util";
|
|
1483
|
+
var CLEAR_SCREEN = "\x1B[H\x1B[2J";
|
|
1484
|
+
var DEFAULT_SECONDS = 2;
|
|
1485
|
+
var ATTACHED_SHORT = /^-w./;
|
|
1486
|
+
var INTERVAL = /^\d+(?:\.\d+)?(?:ms|[smh])?$/;
|
|
1487
|
+
function watchOption(what) {
|
|
1488
|
+
return { type: "string", short: "w", optional: { bare: "", accepts: INTERVAL }, description: `redraw ${what} every 2s, or every interval given (500ms, 5s), until ctrl-c` };
|
|
1489
|
+
}
|
|
1490
|
+
function withoutWatch(args) {
|
|
1491
|
+
const rest = [];
|
|
1492
|
+
for (let at = 0;at < args.length; at++) {
|
|
1493
|
+
const arg = args[at];
|
|
1494
|
+
if (arg === "--watch" || arg === "-w") {
|
|
1495
|
+
if (args[at + 1] !== undefined && INTERVAL.test(args[at + 1]))
|
|
1496
|
+
at++;
|
|
1497
|
+
} else if (!arg.startsWith("--watch=") && !ATTACHED_SHORT.test(arg)) {
|
|
1498
|
+
rest.push(arg);
|
|
1499
|
+
}
|
|
1500
|
+
}
|
|
1501
|
+
return rest;
|
|
1502
|
+
}
|
|
1503
|
+
async function watching(value, step, stream = process14.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
|
|
1504
|
+
const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
|
|
1505
|
+
if (!takesControlCodes(stream))
|
|
1506
|
+
badUsage("--watch redraws the screen, so it needs a terminal");
|
|
1507
|
+
let code = 0;
|
|
1508
|
+
for (let round = 0;round < rounds; round++) {
|
|
1509
|
+
const held = [];
|
|
1510
|
+
const { log, info } = console;
|
|
1511
|
+
const write = process14.stdout.write.bind(process14.stdout);
|
|
1512
|
+
const hold = (...parts) => void held.push(`${format(...parts)}
|
|
1513
|
+
`);
|
|
1514
|
+
console.log = hold;
|
|
1515
|
+
console.info = hold;
|
|
1516
|
+
process14.stdout.write = (text) => {
|
|
1517
|
+
held.push(typeof text === "string" ? text : Buffer.from(text).toString());
|
|
1518
|
+
return true;
|
|
1519
|
+
};
|
|
1520
|
+
try {
|
|
1521
|
+
code = await step();
|
|
1522
|
+
} finally {
|
|
1523
|
+
console.log = log;
|
|
1524
|
+
console.info = info;
|
|
1525
|
+
process14.stdout.write = write;
|
|
1526
|
+
}
|
|
1527
|
+
stream.write(`${CLEAR_SCREEN}${held.join("")}`);
|
|
1528
|
+
await sleep(interval);
|
|
1529
|
+
}
|
|
1530
|
+
return code;
|
|
1531
|
+
}
|
|
1481
1532
|
// ../kit/src/workspace-root.ts
|
|
1482
1533
|
import { existsSync as existsSync4, mkdirSync as mkdirSync2, readFileSync as readFileSync3, writeFileSync } from "fs";
|
|
1483
1534
|
import { homedir as homedir4 } from "os";
|
|
1484
1535
|
import { dirname as dirname4, join as join6, resolve as resolve3 } from "path";
|
|
1485
|
-
import
|
|
1536
|
+
import process15 from "process";
|
|
1486
1537
|
function expandHome(path, home) {
|
|
1487
1538
|
if (path === "~")
|
|
1488
1539
|
return home;
|
|
@@ -1500,7 +1551,7 @@ function configured(env, home) {
|
|
|
1500
1551
|
return;
|
|
1501
1552
|
}
|
|
1502
1553
|
}
|
|
1503
|
-
function workspaceRoot({ given, env =
|
|
1554
|
+
function workspaceRoot({ given, env = process15.env, home = homedir4() } = {}) {
|
|
1504
1555
|
const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
|
|
1505
1556
|
return resolve3(expandHome(given ?? fromEnv ?? configured(env, home) ?? join6(home, "Workspace"), home));
|
|
1506
1557
|
}
|
|
@@ -1508,7 +1559,7 @@ function workspaceRoot({ given, env = process14.env, home = homedir4() } = {}) {
|
|
|
1508
1559
|
import { existsSync as existsSync6, readdirSync, readFileSync as readFileSync5, statSync as statSync2 } from "fs";
|
|
1509
1560
|
import { readdir } from "fs/promises";
|
|
1510
1561
|
import { join as join8, relative, resolve as resolve4 } from "path";
|
|
1511
|
-
import
|
|
1562
|
+
import process17 from "process";
|
|
1512
1563
|
|
|
1513
1564
|
// src/report.ts
|
|
1514
1565
|
import { existsSync as existsSync5, readFileSync as readFileSync4 } from "fs";
|
|
@@ -1637,7 +1688,7 @@ var OPTIONS = {
|
|
|
1637
1688
|
level: { type: "string", choices: SEVERITIES, default: "moderate", description: "only the advisories at least this severe: low, moderate, high or critical" },
|
|
1638
1689
|
prod: { type: "boolean", description: "only the packages a production dependency needs" },
|
|
1639
1690
|
ignore: { type: "string", multiple: true, description: "an advisory skipped by GHSA or numeric id, repeatable" },
|
|
1640
|
-
json: jsonOption("[{repo, path, findings: [{package, severity, scope, direct, via, fix, advisories: [{id, ghsa, url, title, severity, fixed}]}], error}]")
|
|
1691
|
+
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}]")
|
|
1641
1692
|
};
|
|
1642
1693
|
var MAX_DEPTH = 3;
|
|
1643
1694
|
var CONCURRENCY = 4;
|
|
@@ -1720,7 +1771,7 @@ function failure(ran) {
|
|
|
1720
1771
|
`).at(-1) ?? `exit ${ran.code}`;
|
|
1721
1772
|
}
|
|
1722
1773
|
function tint(severity) {
|
|
1723
|
-
const colors = paint(
|
|
1774
|
+
const colors = paint(process17.stdout);
|
|
1724
1775
|
if (severity === "critical" || severity === "high")
|
|
1725
1776
|
return colors.red;
|
|
1726
1777
|
return severity === "moderate" ? colors.yellow : colors.dim;
|
|
@@ -1755,8 +1806,8 @@ async function audit(args) {
|
|
|
1755
1806
|
return kept.some((each) => each.findings.length > 0) ? 1 : 0;
|
|
1756
1807
|
}
|
|
1757
1808
|
function show(audits, total) {
|
|
1758
|
-
const label = role("label",
|
|
1759
|
-
const path = role("path",
|
|
1809
|
+
const label = role("label", process17.stdout);
|
|
1810
|
+
const path = role("path", process17.stdout);
|
|
1760
1811
|
const flagged = audits.filter((each) => each.error !== undefined || each.findings.length > 0);
|
|
1761
1812
|
if (flagged.length === 0) {
|
|
1762
1813
|
console.log(label(`no advisory in ${total} ${total === 1 ? "repository" : "repositories"}`));
|
|
@@ -1778,13 +1829,13 @@ function show(audits, total) {
|
|
|
1778
1829
|
// src/repos.ts
|
|
1779
1830
|
import { existsSync as existsSync8, statSync as statSync3 } from "fs";
|
|
1780
1831
|
import { relative as relative2 } from "path";
|
|
1781
|
-
import
|
|
1832
|
+
import process19 from "process";
|
|
1782
1833
|
|
|
1783
1834
|
// src/repos-scan.ts
|
|
1784
1835
|
import { existsSync as existsSync7 } from "fs";
|
|
1785
1836
|
import { readdir as readdir2 } from "fs/promises";
|
|
1786
1837
|
import { basename, join as join9 } from "path";
|
|
1787
|
-
import
|
|
1838
|
+
import process18 from "process";
|
|
1788
1839
|
var MAX_DEPTH2 = 3;
|
|
1789
1840
|
var CONCURRENCY2 = 8;
|
|
1790
1841
|
var PACKAGE_CONCURRENCY = 4;
|
|
@@ -1831,7 +1882,7 @@ async function findRepos2(root, skip) {
|
|
|
1831
1882
|
}
|
|
1832
1883
|
async function read(path, args, timeoutMs = GIT_MS) {
|
|
1833
1884
|
try {
|
|
1834
|
-
const ran = await runCommand(["git", "--no-optional-locks", ...args], { cwd: path, env: { ...
|
|
1885
|
+
const ran = await runCommand(["git", "--no-optional-locks", ...args], { cwd: path, env: { ...process18.env, GIT_TERMINAL_PROMPT: "0" }, timeoutMs });
|
|
1835
1886
|
return ran.code === 0 && !ran.timedOut ? ran.text.trim() : undefined;
|
|
1836
1887
|
} catch {
|
|
1837
1888
|
return;
|
|
@@ -1908,7 +1959,7 @@ function firstLine(text) {
|
|
|
1908
1959
|
}
|
|
1909
1960
|
async function fastForward(path) {
|
|
1910
1961
|
try {
|
|
1911
|
-
const ran = await runCommand(["git", "--no-optional-locks", "merge", "--ff-only", "--quiet", "@{upstream}"], { cwd: path, env: { ...
|
|
1962
|
+
const ran = await runCommand(["git", "--no-optional-locks", "merge", "--ff-only", "--quiet", "@{upstream}"], { cwd: path, env: { ...process18.env, GIT_TERMINAL_PROMPT: "0" }, timeoutMs: GIT_MS });
|
|
1912
1963
|
if (ran.timedOut)
|
|
1913
1964
|
return "timed out";
|
|
1914
1965
|
return ran.code === 0 ? undefined : firstLine(ran.text.trim()) || `exit ${ran.code}`;
|
|
@@ -1929,8 +1980,9 @@ var EXITS2 = [[0, "it listed the repositories, including when none needs attenti
|
|
|
1929
1980
|
var OPTIONS2 = {
|
|
1930
1981
|
all: { type: "boolean", short: "a", description: "list the repositories with nothing to report too" },
|
|
1931
1982
|
only: { type: "string", choices: REASONS, description: "only the repositories with this reason: dirty, unpushed, unreleased or behind" },
|
|
1932
|
-
|
|
1933
|
-
|
|
1983
|
+
watch: watchOption("the repositories"),
|
|
1984
|
+
fetch: { type: "boolean", conflicts: ["watch"], description: "refresh the upstreams first (reaches the remote)" },
|
|
1985
|
+
pull: { type: "boolean", conflicts: ["watch"], description: "fetch, then fast-forward the clean repositories listed that are only behind their upstream (reaches the remote)" },
|
|
1934
1986
|
path: { type: "boolean", conflicts: ["json"], description: "print only the paths of the repositories listed, one per line" },
|
|
1935
1987
|
json: jsonOption("[{name, path, branch, upstream, dirty, ahead, behind, worktrees, tag, unreleased, packages, reasons, fetchFailed, unreadable}]")
|
|
1936
1988
|
};
|
|
@@ -1950,7 +2002,7 @@ function releasedCell(repo) {
|
|
|
1950
2002
|
return repo.packages.filter((release) => release.unreleased > 0).map((release) => `${release.name} ${release.unreleased}`).join(", ") || "-";
|
|
1951
2003
|
return repo.tag === null || repo.unreleased === 0 ? "-" : `${repo.unreleased} since ${repo.tag}`;
|
|
1952
2004
|
}
|
|
1953
|
-
function syncCell(repo, stream =
|
|
2005
|
+
function syncCell(repo, stream = process19.stdout) {
|
|
1954
2006
|
const colors = paint(stream);
|
|
1955
2007
|
const ahead = repo.ahead ?? 0;
|
|
1956
2008
|
const behind = repo.behind ?? 0;
|
|
@@ -1961,7 +2013,7 @@ function syncCell(repo, stream = process18.stdout) {
|
|
|
1961
2013
|
return parts.length === 0 ? colors.dim("-") : `${parts.join(" ")}${diverged ? colors.yellow(" diverged") : ""}`;
|
|
1962
2014
|
}
|
|
1963
2015
|
var DEFAULT_BRANCHES = new Set(["main", "master"]);
|
|
1964
|
-
function branchCell(repo, stream =
|
|
2016
|
+
function branchCell(repo, stream = process19.stdout) {
|
|
1965
2017
|
const colors = paint(stream);
|
|
1966
2018
|
if (repo.unreadable)
|
|
1967
2019
|
return colors.red("? (unreadable)");
|
|
@@ -1970,8 +2022,8 @@ function branchCell(repo, stream = process18.stdout) {
|
|
|
1970
2022
|
return DEFAULT_BRANCHES.has(repo.branch) ? repo.branch : role("accent", stream)(repo.branch);
|
|
1971
2023
|
}
|
|
1972
2024
|
function row(repo, shown) {
|
|
1973
|
-
const colors = paint(
|
|
1974
|
-
const tint = role("path",
|
|
2025
|
+
const colors = paint(process19.stdout);
|
|
2026
|
+
const tint = role("path", process19.stdout);
|
|
1975
2027
|
const unreleased = releasedCell(repo);
|
|
1976
2028
|
return [
|
|
1977
2029
|
tint(shown),
|
|
@@ -1984,6 +2036,8 @@ function row(repo, shown) {
|
|
|
1984
2036
|
}
|
|
1985
2037
|
async function repos(args) {
|
|
1986
2038
|
const { values, positionals } = parse(args, USAGE2, OPTIONS2, { positionals: ["[root]"], exits: EXITS2, replaces: "a cd, git status, git log and git tag loop over each repository of the workspace", examples: ["repos", "repos ~/Workspace --only unreleased --fetch", ["repos --only behind --pull", "fast-forward what is behind and clean"], ["repos --only dirty --path", "the paths, for xargs"]] });
|
|
2039
|
+
if (values.watch !== undefined)
|
|
2040
|
+
return watching(values.watch, async () => repos(withoutWatch(args)));
|
|
1987
2041
|
const root = workspaceRoot({ given: positionals[0] });
|
|
1988
2042
|
if (!existsSync8(root) || !statSync3(root).isDirectory())
|
|
1989
2043
|
fail(`no folder ${root}`);
|
|
@@ -2003,12 +2057,12 @@ async function repos(args) {
|
|
|
2003
2057
|
const blocker = pullBlocker(repo);
|
|
2004
2058
|
const refused = blocker === undefined ? await fastForward(repo.path) : undefined;
|
|
2005
2059
|
if (blocker !== undefined) {
|
|
2006
|
-
log(marked("note", `${repo.name} skipped`,
|
|
2060
|
+
log(marked("note", `${repo.name} skipped`, process19.stdout, blocker));
|
|
2007
2061
|
} else if (refused !== undefined) {
|
|
2008
2062
|
failedPulls++;
|
|
2009
|
-
log(marked("problem", `${repo.name} not pulled`,
|
|
2063
|
+
log(marked("problem", `${repo.name} not pulled`, process19.stdout, refused));
|
|
2010
2064
|
} else {
|
|
2011
|
-
log(marked("ok", `${repo.name} pulled`,
|
|
2065
|
+
log(marked("ok", `${repo.name} pulled`, process19.stdout, `${repo.behind} ${repo.behind === 1 ? "commit" : "commits"}`));
|
|
2012
2066
|
states[index] = await inspect(repo.path, false);
|
|
2013
2067
|
}
|
|
2014
2068
|
}
|
|
@@ -2023,7 +2077,7 @@ async function repos(args) {
|
|
|
2023
2077
|
printJson(kept.map((repo) => ({ ...repo, reasons: reasonsOf(repo) })));
|
|
2024
2078
|
return failedPulls > 0 ? 1 : 0;
|
|
2025
2079
|
}
|
|
2026
|
-
const label = role("label",
|
|
2080
|
+
const label = role("label", process19.stdout);
|
|
2027
2081
|
if (kept.length === 0) {
|
|
2028
2082
|
console.log(label(`nothing needs attention in ${states.length} repositories`));
|
|
2029
2083
|
return failedPulls > 0 ? 1 : 0;
|
|
@@ -2043,14 +2097,50 @@ import { homedir as homedir6 } from "os";
|
|
|
2043
2097
|
import { relative as relative3 } from "path";
|
|
2044
2098
|
|
|
2045
2099
|
// ../kit/src/prompt.ts
|
|
2046
|
-
import
|
|
2047
|
-
|
|
2048
|
-
|
|
2100
|
+
import process20 from "process";
|
|
2101
|
+
|
|
2102
|
+
// ../kit/src/picker/score.ts
|
|
2103
|
+
var BOUNDARY_AFTER = new Set([" ", "/", "-", "_", ".", ":", "\\", "(", "[", ",", "\t"]);
|
|
2104
|
+
var NONE = Number.NEGATIVE_INFINITY;
|
|
2105
|
+
|
|
2106
|
+
// ../kit/src/picker/state.ts
|
|
2107
|
+
var IS_CONTROL = /[\x00-\x1F\x7F-\x9F]/;
|
|
2049
2108
|
var PASTE_START = "\x1B[200~";
|
|
2050
2109
|
var PASTE_END = "\x1B[201~";
|
|
2051
|
-
var
|
|
2052
|
-
|
|
2110
|
+
var KEY_SEQUENCES = /\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
|
|
2111
|
+
var KEYS = {
|
|
2112
|
+
"\x1B[A": "up",
|
|
2113
|
+
"\x1BOA": "up",
|
|
2114
|
+
"\x10": "up",
|
|
2115
|
+
"\x1B[B": "down",
|
|
2116
|
+
"\x1BOB": "down",
|
|
2117
|
+
"\x0E": "down",
|
|
2118
|
+
"\x1B[5~": "pageup",
|
|
2119
|
+
"\x1B[6~": "pagedown",
|
|
2120
|
+
"\x1B[H": "home",
|
|
2121
|
+
"\x1B[1~": "home",
|
|
2122
|
+
"\x1BOH": "home",
|
|
2123
|
+
"\x1B[F": "end",
|
|
2124
|
+
"\x1B[4~": "end",
|
|
2125
|
+
"\x1BOF": "end",
|
|
2126
|
+
"\r": "enter",
|
|
2127
|
+
"\n": "enter",
|
|
2128
|
+
"\x03": "cancel",
|
|
2129
|
+
"\x1B": "cancel",
|
|
2130
|
+
"\x7F": "erase",
|
|
2131
|
+
"\b": "erase",
|
|
2132
|
+
"\x15": "clear",
|
|
2133
|
+
"\x17": "word",
|
|
2134
|
+
"\t": "tab",
|
|
2135
|
+
"\x1F": "help",
|
|
2136
|
+
"\x1BOP": "help",
|
|
2137
|
+
"\x1B[11~": "help"
|
|
2138
|
+
};
|
|
2139
|
+
function parseKeys(input, paste = { active: false }, ctrls = []) {
|
|
2140
|
+
const codes = new Map(ctrls.map((name) => [String.fromCharCode(name.codePointAt(name.length - 1) - 96), name]));
|
|
2053
2141
|
return (input.match(KEY_SEQUENCES) ?? []).flatMap((sequence) => {
|
|
2142
|
+
const named = codes.get(sequence);
|
|
2143
|
+
const key = named === undefined ? KEYS[sequence] : { ctrl: named };
|
|
2054
2144
|
if (sequence === PASTE_START || sequence === PASTE_END) {
|
|
2055
2145
|
paste.active = sequence === PASTE_START;
|
|
2056
2146
|
return [];
|
|
@@ -2058,9 +2148,17 @@ function readKeys(input, paste = { active: false }) {
|
|
|
2058
2148
|
if (paste.active && (sequence === "\r" || sequence === `
|
|
2059
2149
|
`))
|
|
2060
2150
|
return [];
|
|
2061
|
-
|
|
2151
|
+
if (key !== undefined)
|
|
2152
|
+
return [key];
|
|
2153
|
+
return IS_CONTROL.test(sequence) || sequence.startsWith("\x1B") ? [] : [{ text: sequence }];
|
|
2062
2154
|
});
|
|
2063
2155
|
}
|
|
2156
|
+
|
|
2157
|
+
// ../kit/src/prompt.ts
|
|
2158
|
+
var PROMPT_KEYS = new Set(["up", "down", "pageup", "pagedown", "home", "end", "enter", "cancel", "erase"]);
|
|
2159
|
+
function readKeys(input, paste = { active: false }) {
|
|
2160
|
+
return parseKeys(input, paste).filter((key) => typeof key === "object" ? "text" in key : PROMPT_KEYS.has(key));
|
|
2161
|
+
}
|
|
2064
2162
|
async function confirm(question, { default: fallback, ...settings } = {}) {
|
|
2065
2163
|
let answered = fallback;
|
|
2066
2164
|
const choices = { true: "Y/n", false: "y/N", undefined: "y/n" }[String(fallback)];
|
|
@@ -2083,7 +2181,7 @@ function asking(colors, question, typed, keys) {
|
|
|
2083
2181
|
function answer(colors, question, state, picked) {
|
|
2084
2182
|
return state === "enter" ? `${colors.green("\u2713")} ${question} ${colors.cyan(picked)}` : `${colors.red("\u2717")} ${question} ${colors.dim("cancelled")}`;
|
|
2085
2183
|
}
|
|
2086
|
-
async function ask(question, { hint, terminal =
|
|
2184
|
+
async function ask(question, { hint, terminal = process20 }, render, press) {
|
|
2087
2185
|
const { stdin, stderr } = terminal;
|
|
2088
2186
|
if (!isInteractive(terminal))
|
|
2089
2187
|
fail(`cannot ask "${question}" off a terminal`, 2, hint);
|
|
@@ -2564,7 +2662,7 @@ ${$e(reclaimable)} reclaimable${skipped === 0 ? "" : `, ${skipped} skipped (syml
|
|
|
2564
2662
|
}
|
|
2565
2663
|
|
|
2566
2664
|
// src/cli.ts
|
|
2567
|
-
|
|
2665
|
+
process21.exitCode = await runCli({
|
|
2568
2666
|
name: "ws",
|
|
2569
2667
|
about: "the repositories under a root: the ones needing attention, the folders worth reclaiming and their known vulnerabilities",
|
|
2570
2668
|
replaces: "a cd, git status and du loop over each repository of the workspace, and a bun audit run in each",
|
package/dist/repos-cli.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/repos-cli.ts
|
|
5
|
-
import
|
|
5
|
+
import process19 from "process";
|
|
6
6
|
|
|
7
7
|
// ../kit/src/advisory.ts
|
|
8
8
|
var SEVERITIES = ["low", "moderate", "high", "critical"];
|
|
@@ -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;
|
|
@@ -1467,11 +1466,63 @@ function parseSize(text, bareUnit = 1) {
|
|
|
1467
1466
|
const suffix = match[2].toLowerCase();
|
|
1468
1467
|
return Math.round(Number(match[1]) * (suffix === "" ? bareUnit : 1024 ** POWERS[suffix]));
|
|
1469
1468
|
}
|
|
1469
|
+
// ../kit/src/watch.ts
|
|
1470
|
+
import process14 from "process";
|
|
1471
|
+
import { format } from "util";
|
|
1472
|
+
var CLEAR_SCREEN = "\x1B[H\x1B[2J";
|
|
1473
|
+
var DEFAULT_SECONDS = 2;
|
|
1474
|
+
var ATTACHED_SHORT = /^-w./;
|
|
1475
|
+
var INTERVAL = /^\d+(?:\.\d+)?(?:ms|[smh])?$/;
|
|
1476
|
+
function watchOption(what) {
|
|
1477
|
+
return { type: "string", short: "w", optional: { bare: "", accepts: INTERVAL }, description: `redraw ${what} every 2s, or every interval given (500ms, 5s), until ctrl-c` };
|
|
1478
|
+
}
|
|
1479
|
+
function withoutWatch(args) {
|
|
1480
|
+
const rest = [];
|
|
1481
|
+
for (let at = 0;at < args.length; at++) {
|
|
1482
|
+
const arg = args[at];
|
|
1483
|
+
if (arg === "--watch" || arg === "-w") {
|
|
1484
|
+
if (args[at + 1] !== undefined && INTERVAL.test(args[at + 1]))
|
|
1485
|
+
at++;
|
|
1486
|
+
} else if (!arg.startsWith("--watch=") && !ATTACHED_SHORT.test(arg)) {
|
|
1487
|
+
rest.push(arg);
|
|
1488
|
+
}
|
|
1489
|
+
}
|
|
1490
|
+
return rest;
|
|
1491
|
+
}
|
|
1492
|
+
async function watching(value, step, stream = process14.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
|
|
1493
|
+
const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
|
|
1494
|
+
if (!takesControlCodes(stream))
|
|
1495
|
+
badUsage("--watch redraws the screen, so it needs a terminal");
|
|
1496
|
+
let code = 0;
|
|
1497
|
+
for (let round = 0;round < rounds; round++) {
|
|
1498
|
+
const held = [];
|
|
1499
|
+
const { log, info } = console;
|
|
1500
|
+
const write = process14.stdout.write.bind(process14.stdout);
|
|
1501
|
+
const hold = (...parts) => void held.push(`${format(...parts)}
|
|
1502
|
+
`);
|
|
1503
|
+
console.log = hold;
|
|
1504
|
+
console.info = hold;
|
|
1505
|
+
process14.stdout.write = (text) => {
|
|
1506
|
+
held.push(typeof text === "string" ? text : Buffer.from(text).toString());
|
|
1507
|
+
return true;
|
|
1508
|
+
};
|
|
1509
|
+
try {
|
|
1510
|
+
code = await step();
|
|
1511
|
+
} finally {
|
|
1512
|
+
console.log = log;
|
|
1513
|
+
console.info = info;
|
|
1514
|
+
process14.stdout.write = write;
|
|
1515
|
+
}
|
|
1516
|
+
stream.write(`${CLEAR_SCREEN}${held.join("")}`);
|
|
1517
|
+
await sleep(interval);
|
|
1518
|
+
}
|
|
1519
|
+
return code;
|
|
1520
|
+
}
|
|
1470
1521
|
// ../kit/src/workspace-root.ts
|
|
1471
1522
|
import { existsSync as existsSync4, mkdirSync as mkdirSync2, readFileSync as readFileSync3, writeFileSync } from "fs";
|
|
1472
1523
|
import { homedir as homedir4 } from "os";
|
|
1473
1524
|
import { dirname as dirname4, join as join6, resolve as resolve3 } from "path";
|
|
1474
|
-
import
|
|
1525
|
+
import process15 from "process";
|
|
1475
1526
|
function expandHome(path, home) {
|
|
1476
1527
|
if (path === "~")
|
|
1477
1528
|
return home;
|
|
@@ -1489,20 +1540,20 @@ function configured(env, home) {
|
|
|
1489
1540
|
return;
|
|
1490
1541
|
}
|
|
1491
1542
|
}
|
|
1492
|
-
function workspaceRoot({ given, env =
|
|
1543
|
+
function workspaceRoot({ given, env = process15.env, home = homedir4() } = {}) {
|
|
1493
1544
|
const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
|
|
1494
1545
|
return resolve3(expandHome(given ?? fromEnv ?? configured(env, home) ?? join6(home, "Workspace"), home));
|
|
1495
1546
|
}
|
|
1496
1547
|
// src/repos.ts
|
|
1497
1548
|
import { existsSync as existsSync6, statSync as statSync2 } from "fs";
|
|
1498
1549
|
import { relative } from "path";
|
|
1499
|
-
import
|
|
1550
|
+
import process18 from "process";
|
|
1500
1551
|
|
|
1501
1552
|
// src/repos-scan.ts
|
|
1502
1553
|
import { existsSync as existsSync5 } from "fs";
|
|
1503
1554
|
import { readdir } from "fs/promises";
|
|
1504
1555
|
import { basename, join as join7 } from "path";
|
|
1505
|
-
import
|
|
1556
|
+
import process17 from "process";
|
|
1506
1557
|
var MAX_DEPTH = 3;
|
|
1507
1558
|
var CONCURRENCY = 8;
|
|
1508
1559
|
var PACKAGE_CONCURRENCY = 4;
|
|
@@ -1549,7 +1600,7 @@ async function findRepos(root, skip) {
|
|
|
1549
1600
|
}
|
|
1550
1601
|
async function read(path, args, timeoutMs = GIT_MS) {
|
|
1551
1602
|
try {
|
|
1552
|
-
const ran = await runCommand(["git", "--no-optional-locks", ...args], { cwd: path, env: { ...
|
|
1603
|
+
const ran = await runCommand(["git", "--no-optional-locks", ...args], { cwd: path, env: { ...process17.env, GIT_TERMINAL_PROMPT: "0" }, timeoutMs });
|
|
1553
1604
|
return ran.code === 0 && !ran.timedOut ? ran.text.trim() : undefined;
|
|
1554
1605
|
} catch {
|
|
1555
1606
|
return;
|
|
@@ -1626,7 +1677,7 @@ function firstLine(text) {
|
|
|
1626
1677
|
}
|
|
1627
1678
|
async function fastForward(path) {
|
|
1628
1679
|
try {
|
|
1629
|
-
const ran = await runCommand(["git", "--no-optional-locks", "merge", "--ff-only", "--quiet", "@{upstream}"], { cwd: path, env: { ...
|
|
1680
|
+
const ran = await runCommand(["git", "--no-optional-locks", "merge", "--ff-only", "--quiet", "@{upstream}"], { cwd: path, env: { ...process17.env, GIT_TERMINAL_PROMPT: "0" }, timeoutMs: GIT_MS });
|
|
1630
1681
|
if (ran.timedOut)
|
|
1631
1682
|
return "timed out";
|
|
1632
1683
|
return ran.code === 0 ? undefined : firstLine(ran.text.trim()) || `exit ${ran.code}`;
|
|
@@ -1647,8 +1698,9 @@ var EXITS = [[0, "it listed the repositories, including when none needs attentio
|
|
|
1647
1698
|
var OPTIONS = {
|
|
1648
1699
|
all: { type: "boolean", short: "a", description: "list the repositories with nothing to report too" },
|
|
1649
1700
|
only: { type: "string", choices: REASONS, description: "only the repositories with this reason: dirty, unpushed, unreleased or behind" },
|
|
1650
|
-
|
|
1651
|
-
|
|
1701
|
+
watch: watchOption("the repositories"),
|
|
1702
|
+
fetch: { type: "boolean", conflicts: ["watch"], description: "refresh the upstreams first (reaches the remote)" },
|
|
1703
|
+
pull: { type: "boolean", conflicts: ["watch"], description: "fetch, then fast-forward the clean repositories listed that are only behind their upstream (reaches the remote)" },
|
|
1652
1704
|
path: { type: "boolean", conflicts: ["json"], description: "print only the paths of the repositories listed, one per line" },
|
|
1653
1705
|
json: jsonOption("[{name, path, branch, upstream, dirty, ahead, behind, worktrees, tag, unreleased, packages, reasons, fetchFailed, unreadable}]")
|
|
1654
1706
|
};
|
|
@@ -1668,7 +1720,7 @@ function releasedCell(repo) {
|
|
|
1668
1720
|
return repo.packages.filter((release) => release.unreleased > 0).map((release) => `${release.name} ${release.unreleased}`).join(", ") || "-";
|
|
1669
1721
|
return repo.tag === null || repo.unreleased === 0 ? "-" : `${repo.unreleased} since ${repo.tag}`;
|
|
1670
1722
|
}
|
|
1671
|
-
function syncCell(repo, stream =
|
|
1723
|
+
function syncCell(repo, stream = process18.stdout) {
|
|
1672
1724
|
const colors = paint(stream);
|
|
1673
1725
|
const ahead = repo.ahead ?? 0;
|
|
1674
1726
|
const behind = repo.behind ?? 0;
|
|
@@ -1679,7 +1731,7 @@ function syncCell(repo, stream = process17.stdout) {
|
|
|
1679
1731
|
return parts.length === 0 ? colors.dim("-") : `${parts.join(" ")}${diverged ? colors.yellow(" diverged") : ""}`;
|
|
1680
1732
|
}
|
|
1681
1733
|
var DEFAULT_BRANCHES = new Set(["main", "master"]);
|
|
1682
|
-
function branchCell(repo, stream =
|
|
1734
|
+
function branchCell(repo, stream = process18.stdout) {
|
|
1683
1735
|
const colors = paint(stream);
|
|
1684
1736
|
if (repo.unreadable)
|
|
1685
1737
|
return colors.red("? (unreadable)");
|
|
@@ -1688,8 +1740,8 @@ function branchCell(repo, stream = process17.stdout) {
|
|
|
1688
1740
|
return DEFAULT_BRANCHES.has(repo.branch) ? repo.branch : role("accent", stream)(repo.branch);
|
|
1689
1741
|
}
|
|
1690
1742
|
function row(repo, shown) {
|
|
1691
|
-
const colors = paint(
|
|
1692
|
-
const tint = role("path",
|
|
1743
|
+
const colors = paint(process18.stdout);
|
|
1744
|
+
const tint = role("path", process18.stdout);
|
|
1693
1745
|
const unreleased = releasedCell(repo);
|
|
1694
1746
|
return [
|
|
1695
1747
|
tint(shown),
|
|
@@ -1702,6 +1754,8 @@ function row(repo, shown) {
|
|
|
1702
1754
|
}
|
|
1703
1755
|
async function repos(args) {
|
|
1704
1756
|
const { values, positionals } = parse(args, USAGE, OPTIONS, { positionals: ["[root]"], exits: EXITS, replaces: "a cd, git status, git log and git tag loop over each repository of the workspace", examples: ["repos", "repos ~/Workspace --only unreleased --fetch", ["repos --only behind --pull", "fast-forward what is behind and clean"], ["repos --only dirty --path", "the paths, for xargs"]] });
|
|
1757
|
+
if (values.watch !== undefined)
|
|
1758
|
+
return watching(values.watch, async () => repos(withoutWatch(args)));
|
|
1705
1759
|
const root = workspaceRoot({ given: positionals[0] });
|
|
1706
1760
|
if (!existsSync6(root) || !statSync2(root).isDirectory())
|
|
1707
1761
|
fail(`no folder ${root}`);
|
|
@@ -1721,12 +1775,12 @@ async function repos(args) {
|
|
|
1721
1775
|
const blocker = pullBlocker(repo);
|
|
1722
1776
|
const refused = blocker === undefined ? await fastForward(repo.path) : undefined;
|
|
1723
1777
|
if (blocker !== undefined) {
|
|
1724
|
-
log(marked("note", `${repo.name} skipped`,
|
|
1778
|
+
log(marked("note", `${repo.name} skipped`, process18.stdout, blocker));
|
|
1725
1779
|
} else if (refused !== undefined) {
|
|
1726
1780
|
failedPulls++;
|
|
1727
|
-
log(marked("problem", `${repo.name} not pulled`,
|
|
1781
|
+
log(marked("problem", `${repo.name} not pulled`, process18.stdout, refused));
|
|
1728
1782
|
} else {
|
|
1729
|
-
log(marked("ok", `${repo.name} pulled`,
|
|
1783
|
+
log(marked("ok", `${repo.name} pulled`, process18.stdout, `${repo.behind} ${repo.behind === 1 ? "commit" : "commits"}`));
|
|
1730
1784
|
states[index] = await inspect(repo.path, false);
|
|
1731
1785
|
}
|
|
1732
1786
|
}
|
|
@@ -1741,7 +1795,7 @@ async function repos(args) {
|
|
|
1741
1795
|
printJson(kept.map((repo) => ({ ...repo, reasons: reasonsOf(repo) })));
|
|
1742
1796
|
return failedPulls > 0 ? 1 : 0;
|
|
1743
1797
|
}
|
|
1744
|
-
const label = role("label",
|
|
1798
|
+
const label = role("label", process18.stdout);
|
|
1745
1799
|
if (kept.length === 0) {
|
|
1746
1800
|
console.log(label(`nothing needs attention in ${states.length} repositories`));
|
|
1747
1801
|
return failedPulls > 0 ? 1 : 0;
|
|
@@ -1756,4 +1810,4 @@ async function repos(args) {
|
|
|
1756
1810
|
}
|
|
1757
1811
|
|
|
1758
1812
|
// src/repos-cli.ts
|
|
1759
|
-
|
|
1813
|
+
process19.exitCode = await runMain({ name: "repos", run: repos });
|
package/dist/sweep-cli.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/sweep-cli.ts
|
|
5
|
-
import
|
|
5
|
+
import process18 from "process";
|
|
6
6
|
|
|
7
7
|
// ../kit/src/advisory.ts
|
|
8
8
|
var SEVERITIES = ["low", "moderate", "high", "critical"];
|
|
@@ -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;
|
|
@@ -1478,11 +1477,63 @@ function parseSize(text, bareUnit = 1) {
|
|
|
1478
1477
|
const suffix = match[2].toLowerCase();
|
|
1479
1478
|
return Math.round(Number(match[1]) * (suffix === "" ? bareUnit : 1024 ** POWERS[suffix]));
|
|
1480
1479
|
}
|
|
1480
|
+
// ../kit/src/watch.ts
|
|
1481
|
+
import process14 from "process";
|
|
1482
|
+
import { format } from "util";
|
|
1483
|
+
var CLEAR_SCREEN = "\x1B[H\x1B[2J";
|
|
1484
|
+
var DEFAULT_SECONDS = 2;
|
|
1485
|
+
var ATTACHED_SHORT = /^-w./;
|
|
1486
|
+
var INTERVAL = /^\d+(?:\.\d+)?(?:ms|[smh])?$/;
|
|
1487
|
+
function watchOption(what) {
|
|
1488
|
+
return { type: "string", short: "w", optional: { bare: "", accepts: INTERVAL }, description: `redraw ${what} every 2s, or every interval given (500ms, 5s), until ctrl-c` };
|
|
1489
|
+
}
|
|
1490
|
+
function withoutWatch(args) {
|
|
1491
|
+
const rest = [];
|
|
1492
|
+
for (let at = 0;at < args.length; at++) {
|
|
1493
|
+
const arg = args[at];
|
|
1494
|
+
if (arg === "--watch" || arg === "-w") {
|
|
1495
|
+
if (args[at + 1] !== undefined && INTERVAL.test(args[at + 1]))
|
|
1496
|
+
at++;
|
|
1497
|
+
} else if (!arg.startsWith("--watch=") && !ATTACHED_SHORT.test(arg)) {
|
|
1498
|
+
rest.push(arg);
|
|
1499
|
+
}
|
|
1500
|
+
}
|
|
1501
|
+
return rest;
|
|
1502
|
+
}
|
|
1503
|
+
async function watching(value, step, stream = process14.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
|
|
1504
|
+
const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
|
|
1505
|
+
if (!takesControlCodes(stream))
|
|
1506
|
+
badUsage("--watch redraws the screen, so it needs a terminal");
|
|
1507
|
+
let code = 0;
|
|
1508
|
+
for (let round = 0;round < rounds; round++) {
|
|
1509
|
+
const held = [];
|
|
1510
|
+
const { log, info } = console;
|
|
1511
|
+
const write = process14.stdout.write.bind(process14.stdout);
|
|
1512
|
+
const hold = (...parts) => void held.push(`${format(...parts)}
|
|
1513
|
+
`);
|
|
1514
|
+
console.log = hold;
|
|
1515
|
+
console.info = hold;
|
|
1516
|
+
process14.stdout.write = (text) => {
|
|
1517
|
+
held.push(typeof text === "string" ? text : Buffer.from(text).toString());
|
|
1518
|
+
return true;
|
|
1519
|
+
};
|
|
1520
|
+
try {
|
|
1521
|
+
code = await step();
|
|
1522
|
+
} finally {
|
|
1523
|
+
console.log = log;
|
|
1524
|
+
console.info = info;
|
|
1525
|
+
process14.stdout.write = write;
|
|
1526
|
+
}
|
|
1527
|
+
stream.write(`${CLEAR_SCREEN}${held.join("")}`);
|
|
1528
|
+
await sleep(interval);
|
|
1529
|
+
}
|
|
1530
|
+
return code;
|
|
1531
|
+
}
|
|
1481
1532
|
// ../kit/src/workspace-root.ts
|
|
1482
1533
|
import { existsSync as existsSync4, mkdirSync as mkdirSync2, readFileSync as readFileSync3, writeFileSync } from "fs";
|
|
1483
1534
|
import { homedir as homedir4 } from "os";
|
|
1484
1535
|
import { dirname as dirname4, join as join6, resolve as resolve3 } from "path";
|
|
1485
|
-
import
|
|
1536
|
+
import process15 from "process";
|
|
1486
1537
|
function expandHome(path, home) {
|
|
1487
1538
|
if (path === "~")
|
|
1488
1539
|
return home;
|
|
@@ -1500,7 +1551,7 @@ function configured(env, home) {
|
|
|
1500
1551
|
return;
|
|
1501
1552
|
}
|
|
1502
1553
|
}
|
|
1503
|
-
function workspaceRoot({ given, env =
|
|
1554
|
+
function workspaceRoot({ given, env = process15.env, home = homedir4() } = {}) {
|
|
1504
1555
|
const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
|
|
1505
1556
|
return resolve3(expandHome(given ?? fromEnv ?? configured(env, home) ?? join6(home, "Workspace"), home));
|
|
1506
1557
|
}
|
|
@@ -1510,14 +1561,50 @@ import { homedir as homedir6 } from "os";
|
|
|
1510
1561
|
import { relative } from "path";
|
|
1511
1562
|
|
|
1512
1563
|
// ../kit/src/prompt.ts
|
|
1513
|
-
import
|
|
1514
|
-
|
|
1515
|
-
|
|
1564
|
+
import process17 from "process";
|
|
1565
|
+
|
|
1566
|
+
// ../kit/src/picker/score.ts
|
|
1567
|
+
var BOUNDARY_AFTER = new Set([" ", "/", "-", "_", ".", ":", "\\", "(", "[", ",", "\t"]);
|
|
1568
|
+
var NONE = Number.NEGATIVE_INFINITY;
|
|
1569
|
+
|
|
1570
|
+
// ../kit/src/picker/state.ts
|
|
1571
|
+
var IS_CONTROL = /[\x00-\x1F\x7F-\x9F]/;
|
|
1516
1572
|
var PASTE_START = "\x1B[200~";
|
|
1517
1573
|
var PASTE_END = "\x1B[201~";
|
|
1518
|
-
var
|
|
1519
|
-
|
|
1574
|
+
var KEY_SEQUENCES = /\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
|
|
1575
|
+
var KEYS = {
|
|
1576
|
+
"\x1B[A": "up",
|
|
1577
|
+
"\x1BOA": "up",
|
|
1578
|
+
"\x10": "up",
|
|
1579
|
+
"\x1B[B": "down",
|
|
1580
|
+
"\x1BOB": "down",
|
|
1581
|
+
"\x0E": "down",
|
|
1582
|
+
"\x1B[5~": "pageup",
|
|
1583
|
+
"\x1B[6~": "pagedown",
|
|
1584
|
+
"\x1B[H": "home",
|
|
1585
|
+
"\x1B[1~": "home",
|
|
1586
|
+
"\x1BOH": "home",
|
|
1587
|
+
"\x1B[F": "end",
|
|
1588
|
+
"\x1B[4~": "end",
|
|
1589
|
+
"\x1BOF": "end",
|
|
1590
|
+
"\r": "enter",
|
|
1591
|
+
"\n": "enter",
|
|
1592
|
+
"\x03": "cancel",
|
|
1593
|
+
"\x1B": "cancel",
|
|
1594
|
+
"\x7F": "erase",
|
|
1595
|
+
"\b": "erase",
|
|
1596
|
+
"\x15": "clear",
|
|
1597
|
+
"\x17": "word",
|
|
1598
|
+
"\t": "tab",
|
|
1599
|
+
"\x1F": "help",
|
|
1600
|
+
"\x1BOP": "help",
|
|
1601
|
+
"\x1B[11~": "help"
|
|
1602
|
+
};
|
|
1603
|
+
function parseKeys(input, paste = { active: false }, ctrls = []) {
|
|
1604
|
+
const codes = new Map(ctrls.map((name) => [String.fromCharCode(name.codePointAt(name.length - 1) - 96), name]));
|
|
1520
1605
|
return (input.match(KEY_SEQUENCES) ?? []).flatMap((sequence) => {
|
|
1606
|
+
const named = codes.get(sequence);
|
|
1607
|
+
const key = named === undefined ? KEYS[sequence] : { ctrl: named };
|
|
1521
1608
|
if (sequence === PASTE_START || sequence === PASTE_END) {
|
|
1522
1609
|
paste.active = sequence === PASTE_START;
|
|
1523
1610
|
return [];
|
|
@@ -1525,9 +1612,17 @@ function readKeys(input, paste = { active: false }) {
|
|
|
1525
1612
|
if (paste.active && (sequence === "\r" || sequence === `
|
|
1526
1613
|
`))
|
|
1527
1614
|
return [];
|
|
1528
|
-
|
|
1615
|
+
if (key !== undefined)
|
|
1616
|
+
return [key];
|
|
1617
|
+
return IS_CONTROL.test(sequence) || sequence.startsWith("\x1B") ? [] : [{ text: sequence }];
|
|
1529
1618
|
});
|
|
1530
1619
|
}
|
|
1620
|
+
|
|
1621
|
+
// ../kit/src/prompt.ts
|
|
1622
|
+
var PROMPT_KEYS = new Set(["up", "down", "pageup", "pagedown", "home", "end", "enter", "cancel", "erase"]);
|
|
1623
|
+
function readKeys(input, paste = { active: false }) {
|
|
1624
|
+
return parseKeys(input, paste).filter((key) => typeof key === "object" ? "text" in key : PROMPT_KEYS.has(key));
|
|
1625
|
+
}
|
|
1531
1626
|
async function confirm(question, { default: fallback, ...settings } = {}) {
|
|
1532
1627
|
let answered = fallback;
|
|
1533
1628
|
const choices = { true: "Y/n", false: "y/N", undefined: "y/n" }[String(fallback)];
|
|
@@ -1550,7 +1645,7 @@ function asking(colors, question, typed, keys) {
|
|
|
1550
1645
|
function answer(colors, question, state, picked) {
|
|
1551
1646
|
return state === "enter" ? `${colors.green("\u2713")} ${question} ${colors.cyan(picked)}` : `${colors.red("\u2717")} ${question} ${colors.dim("cancelled")}`;
|
|
1552
1647
|
}
|
|
1553
|
-
async function ask(question, { hint, terminal =
|
|
1648
|
+
async function ask(question, { hint, terminal = process17 }, render, press) {
|
|
1554
1649
|
const { stdin, stderr } = terminal;
|
|
1555
1650
|
if (!isInteractive(terminal))
|
|
1556
1651
|
fail(`cannot ask "${question}" off a terminal`, 2, hint);
|
|
@@ -2031,4 +2126,4 @@ ${$e(reclaimable)} reclaimable${skipped === 0 ? "" : `, ${skipped} skipped (syml
|
|
|
2031
2126
|
}
|
|
2032
2127
|
|
|
2033
2128
|
// src/sweep-cli.ts
|
|
2034
|
-
|
|
2129
|
+
process18.exitCode = await runMain({ name: "sweep", run: sweep });
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaynooo/cli-workspace",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.7.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.
|
|
37
|
+
"@kaynooo/cli-kit": "0.26.0"
|
|
38
38
|
}
|
|
39
39
|
}
|