@kaynooo/cli-workspace 0.10.0 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/audit-cli.js +37 -29
- package/dist/cli.js +71 -58
- package/dist/repos-cli.js +39 -31
- package/dist/sweep-cli.js +57 -44
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -30,6 +30,8 @@ Without `--fetch` the ahead and behind counts are those of the last fetch. The w
|
|
|
30
30
|
{ "skip": ["archived-thing", "vendored-clone"] }
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
+
`concurrency` (a positive whole number, 8 by default) in the same file sets how many repositories are read at once. `audit` reads the same key from `~/.config/kaynooo-cli/audit.json` (4 by default, the repositories audited at once).
|
|
34
|
+
|
|
33
35
|
## sweep
|
|
34
36
|
|
|
35
37
|
`sweep` reclaims disk across many repos: it lists the regenerable folders and clean git worktrees under a root, largest first, and deletes them only on `--apply`.
|
package/dist/audit-cli.js
CHANGED
|
@@ -18,6 +18,7 @@ import { parseArgs } from "util";
|
|
|
18
18
|
|
|
19
19
|
// ../kit/src/format.ts
|
|
20
20
|
import process7 from "process";
|
|
21
|
+
|
|
21
22
|
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rxztfxgv.js
|
|
22
23
|
var N = new Map;
|
|
23
24
|
var Nt = /\s+\S*$/;
|
|
@@ -35,6 +36,7 @@ function ko(t, e, r = "...") {
|
|
|
35
36
|
}
|
|
36
37
|
var be = new Map(["\u20AC", "", "\u201A", "\u0192", "\u201E", "\u2026", "\u2020", "\u2021", "\u02C6", "\u2030", "\u0160", "\u2039", "\u0152", "", "\u017D", "", "", "\u2018", "\u2019", "\u201C", "\u201D", "\u2022", "\u2013", "\u2014", "\u02DC", "\u2122", "\u0161", "\u203A", "\u0153", "", "\u017E", "\u0178"].map((t, e) => [t, 128 + e]).filter(([t]) => t));
|
|
37
38
|
var z = new Map;
|
|
39
|
+
|
|
38
40
|
// ../kit/src/mode.ts
|
|
39
41
|
import process2 from "process";
|
|
40
42
|
var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
@@ -83,7 +85,7 @@ function C(r, e = globalThis.process?.env ?? {}) {
|
|
|
83
85
|
return false;
|
|
84
86
|
return r?.isTTY === true;
|
|
85
87
|
}
|
|
86
|
-
function
|
|
88
|
+
function f(r, e = []) {
|
|
87
89
|
let l = "", n = "";
|
|
88
90
|
for (let t = 0, i = e.length;t < i; t++)
|
|
89
91
|
l += `\x1B[${e[t][0]}m`, n = `\x1B[${e[t][1]}m${n}`;
|
|
@@ -93,7 +95,7 @@ function f2(r, e = []) {
|
|
|
93
95
|
if (Array.isArray(a)) {
|
|
94
96
|
let s = g.get(i);
|
|
95
97
|
if (s === undefined)
|
|
96
|
-
s =
|
|
98
|
+
s = f(r, [...e, a]), g.set(i, s);
|
|
97
99
|
return s;
|
|
98
100
|
}
|
|
99
101
|
if (typeof a === "function")
|
|
@@ -102,20 +104,20 @@ function f2(r, e = []) {
|
|
|
102
104
|
if (u === undefined) {
|
|
103
105
|
if (g.size >= 64)
|
|
104
106
|
g.clear();
|
|
105
|
-
u =
|
|
107
|
+
u = f(r, [...e, a(...s)]), g.set(y, u);
|
|
106
108
|
}
|
|
107
109
|
return u;
|
|
108
110
|
};
|
|
109
111
|
throw Error(`Unknown style: ${String(i)}`);
|
|
110
112
|
} });
|
|
111
113
|
}
|
|
112
|
-
function
|
|
113
|
-
return
|
|
114
|
+
function Fe(r = {}) {
|
|
115
|
+
return f(r);
|
|
114
116
|
}
|
|
115
|
-
var
|
|
117
|
+
var o = Fe();
|
|
116
118
|
|
|
117
119
|
// ../kit/src/theme.ts
|
|
118
|
-
import { existsSync as existsSync3, readFileSync, statSync } from "fs";
|
|
120
|
+
import { existsSync as existsSync3, readFileSync as readFileSync2, statSync } from "fs";
|
|
119
121
|
import { homedir as homedir2 } from "os";
|
|
120
122
|
import { join as join3, resolve as resolve2 } from "path";
|
|
121
123
|
import process5 from "process";
|
|
@@ -136,7 +138,7 @@ function findUp(names, from = process3.cwd(), stop = () => false) {
|
|
|
136
138
|
}
|
|
137
139
|
|
|
138
140
|
// ../kit/src/user-config.ts
|
|
139
|
-
import { existsSync as existsSync2 } from "fs";
|
|
141
|
+
import { existsSync as existsSync2, readFileSync } from "fs";
|
|
140
142
|
import { homedir } from "os";
|
|
141
143
|
import { join as join2 } from "path";
|
|
142
144
|
import process4 from "process";
|
|
@@ -154,6 +156,21 @@ function userConfigReadPath(bin, legacy = [], where = {}) {
|
|
|
154
156
|
const base = configBase(where);
|
|
155
157
|
return legacy.map((parts) => join2(base, ...parts)).find((path) => existsSync2(path)) ?? current;
|
|
156
158
|
}
|
|
159
|
+
function readUserConfig(bin, where = {}, legacy = []) {
|
|
160
|
+
const path = userConfigReadPath(bin, legacy, where);
|
|
161
|
+
if (!existsSync2(path))
|
|
162
|
+
return {};
|
|
163
|
+
try {
|
|
164
|
+
const parsed = Bun.JSONC.parse(readFileSync(path, "utf8"));
|
|
165
|
+
return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? parsed : {};
|
|
166
|
+
} catch {
|
|
167
|
+
return {};
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
function configuredNumber(bin, key, fallback, where = {}, legacy = []) {
|
|
171
|
+
const value = readUserConfig(bin, where, legacy)[key];
|
|
172
|
+
return typeof value === "number" && Number.isInteger(value) && value > 0 ? value : fallback;
|
|
173
|
+
}
|
|
157
174
|
|
|
158
175
|
// ../kit/src/theme.ts
|
|
159
176
|
var ENDS = new Map;
|
|
@@ -220,7 +237,7 @@ function readThemeFile(path, warn) {
|
|
|
220
237
|
warn(`${path} is not a regular file under ${MAX_FILE_BYTES / 1024} KiB, theme ignored`);
|
|
221
238
|
return;
|
|
222
239
|
}
|
|
223
|
-
const parsed = JSON.parse(
|
|
240
|
+
const parsed = JSON.parse(readFileSync2(path, "utf8"));
|
|
224
241
|
if (isRecord(parsed))
|
|
225
242
|
return parsed;
|
|
226
243
|
warn(`${path} is not a JSON object, theme ignored`);
|
|
@@ -342,7 +359,7 @@ function takesControlCodes(stream, env = process6.env) {
|
|
|
342
359
|
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
343
360
|
}
|
|
344
361
|
function paint(stream, env = process6.env) {
|
|
345
|
-
return
|
|
362
|
+
return Fe({ stream: { isTTY: takesControlCodes(stream, env) }, env });
|
|
346
363
|
}
|
|
347
364
|
function marked(mark, text, stream, detail, env = process6.env) {
|
|
348
365
|
const colors = paint(stream, env);
|
|
@@ -916,7 +933,7 @@ async function runTool(label, argv, { timeoutMs, cwd, onStart } = {}) {
|
|
|
916
933
|
return { code: ran.code, ...streams };
|
|
917
934
|
}
|
|
918
935
|
// ../kit/src/cli.ts
|
|
919
|
-
import { readFileSync as
|
|
936
|
+
import { readFileSync as readFileSync3, realpathSync } from "fs";
|
|
920
937
|
import { dirname as dirname3, join as join5 } from "path";
|
|
921
938
|
import process13 from "process";
|
|
922
939
|
|
|
@@ -1217,7 +1234,7 @@ async function printCandidates(found) {
|
|
|
1217
1234
|
function packageVersion(entry = Bun.main) {
|
|
1218
1235
|
for (let dir = dirname3(realpathSync(entry));; dir = dirname3(dir)) {
|
|
1219
1236
|
try {
|
|
1220
|
-
const { version } = JSON.parse(
|
|
1237
|
+
const { version } = JSON.parse(readFileSync3(join5(dir, "package.json"), "utf8"));
|
|
1221
1238
|
if (typeof version === "string")
|
|
1222
1239
|
return version;
|
|
1223
1240
|
} catch {}
|
|
@@ -1356,7 +1373,6 @@ async function watching(value, step, stream = process14.stdout, sleep = Bun.slee
|
|
|
1356
1373
|
return code;
|
|
1357
1374
|
}
|
|
1358
1375
|
// ../kit/src/workspace-root.ts
|
|
1359
|
-
import { existsSync as existsSync4, mkdirSync as mkdirSync2, readFileSync as readFileSync3, writeFileSync } from "fs";
|
|
1360
1376
|
import { homedir as homedir4 } from "os";
|
|
1361
1377
|
import { dirname as dirname4, join as join6, resolve as resolve3 } from "path";
|
|
1362
1378
|
import process15 from "process";
|
|
@@ -1366,29 +1382,21 @@ function expandHome(path, home) {
|
|
|
1366
1382
|
return path.startsWith("~/") ? join6(home, path.slice(2)) : path;
|
|
1367
1383
|
}
|
|
1368
1384
|
function configured(env, home) {
|
|
1369
|
-
const
|
|
1370
|
-
|
|
1371
|
-
return;
|
|
1372
|
-
try {
|
|
1373
|
-
const parsed = JSON.parse(readFileSync3(path, "utf8"));
|
|
1374
|
-
const folder = typeof parsed === "object" && parsed !== null ? parsed.workspace : undefined;
|
|
1375
|
-
return typeof folder === "string" && folder !== "" ? folder : undefined;
|
|
1376
|
-
} catch {
|
|
1377
|
-
return;
|
|
1378
|
-
}
|
|
1385
|
+
const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
|
|
1386
|
+
return typeof folder === "string" && folder !== "" ? folder : undefined;
|
|
1379
1387
|
}
|
|
1380
1388
|
function workspaceRoot({ given, env = process15.env, home = homedir4() } = {}) {
|
|
1381
1389
|
const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
|
|
1382
1390
|
return resolve3(expandHome(given ?? fromEnv ?? configured(env, home) ?? join6(home, "Workspace"), home));
|
|
1383
1391
|
}
|
|
1384
1392
|
// src/audit.ts
|
|
1385
|
-
import { existsSync as
|
|
1393
|
+
import { existsSync as existsSync5, readdirSync, readFileSync as readFileSync5, statSync as statSync2 } from "fs";
|
|
1386
1394
|
import { readdir } from "fs/promises";
|
|
1387
1395
|
import { join as join8, relative, resolve as resolve4 } from "path";
|
|
1388
1396
|
import process17 from "process";
|
|
1389
1397
|
|
|
1390
1398
|
// src/report.ts
|
|
1391
|
-
import { existsSync as
|
|
1399
|
+
import { existsSync as existsSync4, readFileSync as readFileSync4 } from "fs";
|
|
1392
1400
|
import { join as join7 } from "path";
|
|
1393
1401
|
var UPPER_BOUND = /<\s*(\d[\w.+-]*)/;
|
|
1394
1402
|
var DEPENDENCY_KINDS = ["dependencies", "devDependencies", "optionalDependencies", "peerDependencies"];
|
|
@@ -1472,7 +1480,7 @@ function reachedFrom(graph, direct, targets) {
|
|
|
1472
1480
|
}
|
|
1473
1481
|
function readManifest(path) {
|
|
1474
1482
|
try {
|
|
1475
|
-
return
|
|
1483
|
+
return existsSync4(path) ? JSON.parse(readFileSync4(path, "utf8")) : {};
|
|
1476
1484
|
} catch {
|
|
1477
1485
|
return {};
|
|
1478
1486
|
}
|
|
@@ -1525,7 +1533,7 @@ function countAdvisories(findings) {
|
|
|
1525
1533
|
return findings.reduce((sum, found) => sum + found.advisories.length, 0);
|
|
1526
1534
|
}
|
|
1527
1535
|
function holdsLock(dir) {
|
|
1528
|
-
return
|
|
1536
|
+
return existsSync5(join8(dir, "bun.lock")) || existsSync5(join8(dir, "bun.lockb"));
|
|
1529
1537
|
}
|
|
1530
1538
|
async function findRepos(root) {
|
|
1531
1539
|
if (holdsLock(root))
|
|
@@ -1615,13 +1623,13 @@ function rows(findings) {
|
|
|
1615
1623
|
async function audit(args) {
|
|
1616
1624
|
const { values, positionals } = parse(args, USAGE, OPTIONS, { positionals: ["[root]"], exits: EXITS, replaces: "a bun audit run in each repository and a read of every advisory to find what is worth fixing", examples: ["audit", "audit ~/Workspace --level high --prod"] });
|
|
1617
1625
|
const root = resolve4(positionals[0] ?? ".");
|
|
1618
|
-
if (!
|
|
1626
|
+
if (!existsSync5(root) || !statSync2(root).isDirectory())
|
|
1619
1627
|
fail(`no folder ${root}`);
|
|
1620
1628
|
const level = oneOf(values.level, "level", SEVERITIES);
|
|
1621
1629
|
const paths = await findRepos(root);
|
|
1622
1630
|
if (paths.length === 0)
|
|
1623
1631
|
fail(`no bun.lock under ${root}`);
|
|
1624
|
-
const audits = await pool(paths, CONCURRENCY, async (path) => audited(path, relative(root, path) || ".", level, values.ignore ?? []));
|
|
1632
|
+
const audits = await pool(paths, configuredNumber("audit", "concurrency", CONCURRENCY), async (path) => audited(path, relative(root, path) || ".", level, values.ignore ?? []));
|
|
1625
1633
|
const kept = audits.map((each) => ({ ...each, findings: values.prod === true ? each.findings.filter((found) => found.scope === "prod") : each.findings }));
|
|
1626
1634
|
if (values.json === true)
|
|
1627
1635
|
printJson(kept);
|
package/dist/cli.js
CHANGED
|
@@ -32,6 +32,7 @@ function y(e, t) {
|
|
|
32
32
|
n = new Intl.NumberFormat(e, t), i.set(o, n);
|
|
33
33
|
return n;
|
|
34
34
|
}
|
|
35
|
+
|
|
35
36
|
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rxztfxgv.js
|
|
36
37
|
var N = new Map;
|
|
37
38
|
var Nt = /\s+\S*$/;
|
|
@@ -49,6 +50,7 @@ function ko(t, e, r = "...") {
|
|
|
49
50
|
}
|
|
50
51
|
var be = new Map(["\u20AC", "", "\u201A", "\u0192", "\u201E", "\u2026", "\u2020", "\u2021", "\u02C6", "\u2030", "\u0160", "\u2039", "\u0152", "", "\u017D", "", "", "\u2018", "\u2019", "\u201C", "\u201D", "\u2022", "\u2013", "\u2014", "\u02DC", "\u2122", "\u0161", "\u203A", "\u0153", "", "\u017E", "\u0178"].map((t, e) => [t, 128 + e]).filter(([t]) => t));
|
|
51
52
|
var z = new Map;
|
|
53
|
+
|
|
52
54
|
// ../kit/src/mode.ts
|
|
53
55
|
import process2 from "process";
|
|
54
56
|
var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
@@ -97,7 +99,7 @@ function C(r, e = globalThis.process?.env ?? {}) {
|
|
|
97
99
|
return false;
|
|
98
100
|
return r?.isTTY === true;
|
|
99
101
|
}
|
|
100
|
-
function
|
|
102
|
+
function f(r, e = []) {
|
|
101
103
|
let l = "", n = "";
|
|
102
104
|
for (let t = 0, i = e.length;t < i; t++)
|
|
103
105
|
l += `\x1B[${e[t][0]}m`, n = `\x1B[${e[t][1]}m${n}`;
|
|
@@ -107,7 +109,7 @@ function f2(r, e = []) {
|
|
|
107
109
|
if (Array.isArray(a)) {
|
|
108
110
|
let s = g.get(i);
|
|
109
111
|
if (s === undefined)
|
|
110
|
-
s =
|
|
112
|
+
s = f(r, [...e, a]), g.set(i, s);
|
|
111
113
|
return s;
|
|
112
114
|
}
|
|
113
115
|
if (typeof a === "function")
|
|
@@ -116,20 +118,20 @@ function f2(r, e = []) {
|
|
|
116
118
|
if (u === undefined) {
|
|
117
119
|
if (g.size >= 64)
|
|
118
120
|
g.clear();
|
|
119
|
-
u =
|
|
121
|
+
u = f(r, [...e, a(...s)]), g.set(y, u);
|
|
120
122
|
}
|
|
121
123
|
return u;
|
|
122
124
|
};
|
|
123
125
|
throw Error(`Unknown style: ${String(i)}`);
|
|
124
126
|
} });
|
|
125
127
|
}
|
|
126
|
-
function
|
|
127
|
-
return
|
|
128
|
+
function Fe(r = {}) {
|
|
129
|
+
return f(r);
|
|
128
130
|
}
|
|
129
|
-
var
|
|
131
|
+
var o = Fe();
|
|
130
132
|
|
|
131
133
|
// ../kit/src/theme.ts
|
|
132
|
-
import { existsSync as existsSync3, readFileSync, statSync } from "fs";
|
|
134
|
+
import { existsSync as existsSync3, readFileSync as readFileSync2, statSync } from "fs";
|
|
133
135
|
import { homedir as homedir2 } from "os";
|
|
134
136
|
import { join as join3, resolve as resolve2 } from "path";
|
|
135
137
|
import process5 from "process";
|
|
@@ -150,7 +152,7 @@ function findUp(names, from = process3.cwd(), stop = () => false) {
|
|
|
150
152
|
}
|
|
151
153
|
|
|
152
154
|
// ../kit/src/user-config.ts
|
|
153
|
-
import { existsSync as existsSync2 } from "fs";
|
|
155
|
+
import { existsSync as existsSync2, readFileSync } from "fs";
|
|
154
156
|
import { homedir } from "os";
|
|
155
157
|
import { join as join2 } from "path";
|
|
156
158
|
import process4 from "process";
|
|
@@ -168,6 +170,21 @@ function userConfigReadPath(bin, legacy = [], where = {}) {
|
|
|
168
170
|
const base = configBase(where);
|
|
169
171
|
return legacy.map((parts) => join2(base, ...parts)).find((path) => existsSync2(path)) ?? current;
|
|
170
172
|
}
|
|
173
|
+
function readUserConfig(bin, where = {}, legacy = []) {
|
|
174
|
+
const path = userConfigReadPath(bin, legacy, where);
|
|
175
|
+
if (!existsSync2(path))
|
|
176
|
+
return {};
|
|
177
|
+
try {
|
|
178
|
+
const parsed = Bun.JSONC.parse(readFileSync(path, "utf8"));
|
|
179
|
+
return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? parsed : {};
|
|
180
|
+
} catch {
|
|
181
|
+
return {};
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
function configuredNumber(bin, key, fallback, where = {}, legacy = []) {
|
|
185
|
+
const value = readUserConfig(bin, where, legacy)[key];
|
|
186
|
+
return typeof value === "number" && Number.isInteger(value) && value > 0 ? value : fallback;
|
|
187
|
+
}
|
|
171
188
|
|
|
172
189
|
// ../kit/src/theme.ts
|
|
173
190
|
var ENDS = new Map;
|
|
@@ -234,7 +251,7 @@ function readThemeFile(path, warn) {
|
|
|
234
251
|
warn(`${path} is not a regular file under ${MAX_FILE_BYTES / 1024} KiB, theme ignored`);
|
|
235
252
|
return;
|
|
236
253
|
}
|
|
237
|
-
const parsed = JSON.parse(
|
|
254
|
+
const parsed = JSON.parse(readFileSync2(path, "utf8"));
|
|
238
255
|
if (isRecord(parsed))
|
|
239
256
|
return parsed;
|
|
240
257
|
warn(`${path} is not a JSON object, theme ignored`);
|
|
@@ -356,7 +373,7 @@ function takesControlCodes(stream, env = process6.env) {
|
|
|
356
373
|
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
357
374
|
}
|
|
358
375
|
function paint(stream, env = process6.env) {
|
|
359
|
-
return
|
|
376
|
+
return Fe({ stream: { isTTY: takesControlCodes(stream, env) }, env });
|
|
360
377
|
}
|
|
361
378
|
function marked(mark, text, stream, detail, env = process6.env) {
|
|
362
379
|
const colors = paint(stream, env);
|
|
@@ -404,7 +421,7 @@ function printHeader(bin, context, stream = process6.stdout, env = process6.env)
|
|
|
404
421
|
console.log(line);
|
|
405
422
|
}
|
|
406
423
|
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-knqbxp56.js
|
|
407
|
-
function
|
|
424
|
+
function tt(i, { units: r = "iec", dp: t = 1, locale: n } = {}) {
|
|
408
425
|
let e = r === "si" ? 1000 : 1024;
|
|
409
426
|
if (Math.abs(i) < e)
|
|
410
427
|
return `${i} B`;
|
|
@@ -941,7 +958,7 @@ async function runTool(label, argv, { timeoutMs, cwd, onStart } = {}) {
|
|
|
941
958
|
return { code: ran.code, ...streams };
|
|
942
959
|
}
|
|
943
960
|
// ../kit/src/cli.ts
|
|
944
|
-
import { readFileSync as
|
|
961
|
+
import { readFileSync as readFileSync3, realpathSync } from "fs";
|
|
945
962
|
import { dirname as dirname3, join as join5 } from "path";
|
|
946
963
|
import process13 from "process";
|
|
947
964
|
|
|
@@ -1242,7 +1259,7 @@ async function printCandidates(found) {
|
|
|
1242
1259
|
function packageVersion(entry = Bun.main) {
|
|
1243
1260
|
for (let dir = dirname3(realpathSync(entry));; dir = dirname3(dir)) {
|
|
1244
1261
|
try {
|
|
1245
|
-
const { version } = JSON.parse(
|
|
1262
|
+
const { version } = JSON.parse(readFileSync3(join5(dir, "package.json"), "utf8"));
|
|
1246
1263
|
if (typeof version === "string")
|
|
1247
1264
|
return version;
|
|
1248
1265
|
} catch {}
|
|
@@ -1381,7 +1398,6 @@ async function watching(value, step, stream = process14.stdout, sleep = Bun.slee
|
|
|
1381
1398
|
return code;
|
|
1382
1399
|
}
|
|
1383
1400
|
// ../kit/src/workspace-root.ts
|
|
1384
|
-
import { existsSync as existsSync4, mkdirSync as mkdirSync2, readFileSync as readFileSync3, writeFileSync } from "fs";
|
|
1385
1401
|
import { homedir as homedir4 } from "os";
|
|
1386
1402
|
import { dirname as dirname4, join as join6, resolve as resolve3 } from "path";
|
|
1387
1403
|
import process15 from "process";
|
|
@@ -1391,29 +1407,21 @@ function expandHome(path, home) {
|
|
|
1391
1407
|
return path.startsWith("~/") ? join6(home, path.slice(2)) : path;
|
|
1392
1408
|
}
|
|
1393
1409
|
function configured(env, home) {
|
|
1394
|
-
const
|
|
1395
|
-
|
|
1396
|
-
return;
|
|
1397
|
-
try {
|
|
1398
|
-
const parsed = JSON.parse(readFileSync3(path, "utf8"));
|
|
1399
|
-
const folder = typeof parsed === "object" && parsed !== null ? parsed.workspace : undefined;
|
|
1400
|
-
return typeof folder === "string" && folder !== "" ? folder : undefined;
|
|
1401
|
-
} catch {
|
|
1402
|
-
return;
|
|
1403
|
-
}
|
|
1410
|
+
const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
|
|
1411
|
+
return typeof folder === "string" && folder !== "" ? folder : undefined;
|
|
1404
1412
|
}
|
|
1405
1413
|
function workspaceRoot({ given, env = process15.env, home = homedir4() } = {}) {
|
|
1406
1414
|
const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
|
|
1407
1415
|
return resolve3(expandHome(given ?? fromEnv ?? configured(env, home) ?? join6(home, "Workspace"), home));
|
|
1408
1416
|
}
|
|
1409
1417
|
// src/audit.ts
|
|
1410
|
-
import { existsSync as
|
|
1418
|
+
import { existsSync as existsSync5, readdirSync, readFileSync as readFileSync5, statSync as statSync2 } from "fs";
|
|
1411
1419
|
import { readdir } from "fs/promises";
|
|
1412
1420
|
import { join as join8, relative, resolve as resolve4 } from "path";
|
|
1413
1421
|
import process17 from "process";
|
|
1414
1422
|
|
|
1415
1423
|
// src/report.ts
|
|
1416
|
-
import { existsSync as
|
|
1424
|
+
import { existsSync as existsSync4, readFileSync as readFileSync4 } from "fs";
|
|
1417
1425
|
import { join as join7 } from "path";
|
|
1418
1426
|
var UPPER_BOUND = /<\s*(\d[\w.+-]*)/;
|
|
1419
1427
|
var DEPENDENCY_KINDS = ["dependencies", "devDependencies", "optionalDependencies", "peerDependencies"];
|
|
@@ -1497,7 +1505,7 @@ function reachedFrom(graph, direct, targets) {
|
|
|
1497
1505
|
}
|
|
1498
1506
|
function readManifest(path) {
|
|
1499
1507
|
try {
|
|
1500
|
-
return
|
|
1508
|
+
return existsSync4(path) ? JSON.parse(readFileSync4(path, "utf8")) : {};
|
|
1501
1509
|
} catch {
|
|
1502
1510
|
return {};
|
|
1503
1511
|
}
|
|
@@ -1550,7 +1558,7 @@ function countAdvisories(findings) {
|
|
|
1550
1558
|
return findings.reduce((sum, found) => sum + found.advisories.length, 0);
|
|
1551
1559
|
}
|
|
1552
1560
|
function holdsLock(dir) {
|
|
1553
|
-
return
|
|
1561
|
+
return existsSync5(join8(dir, "bun.lock")) || existsSync5(join8(dir, "bun.lockb"));
|
|
1554
1562
|
}
|
|
1555
1563
|
async function findRepos(root) {
|
|
1556
1564
|
if (holdsLock(root))
|
|
@@ -1640,13 +1648,13 @@ function rows(findings) {
|
|
|
1640
1648
|
async function audit(args) {
|
|
1641
1649
|
const { values, positionals } = parse(args, USAGE, OPTIONS, { positionals: ["[root]"], exits: EXITS, replaces: "a bun audit run in each repository and a read of every advisory to find what is worth fixing", examples: ["audit", "audit ~/Workspace --level high --prod"] });
|
|
1642
1650
|
const root = resolve4(positionals[0] ?? ".");
|
|
1643
|
-
if (!
|
|
1651
|
+
if (!existsSync5(root) || !statSync2(root).isDirectory())
|
|
1644
1652
|
fail(`no folder ${root}`);
|
|
1645
1653
|
const level = oneOf(values.level, "level", SEVERITIES);
|
|
1646
1654
|
const paths = await findRepos(root);
|
|
1647
1655
|
if (paths.length === 0)
|
|
1648
1656
|
fail(`no bun.lock under ${root}`);
|
|
1649
|
-
const audits = await pool(paths, CONCURRENCY, async (path) => audited(path, relative(root, path) || ".", level, values.ignore ?? []));
|
|
1657
|
+
const audits = await pool(paths, configuredNumber("audit", "concurrency", CONCURRENCY), async (path) => audited(path, relative(root, path) || ".", level, values.ignore ?? []));
|
|
1650
1658
|
const kept = audits.map((each) => ({ ...each, findings: values.prod === true ? each.findings.filter((found) => found.scope === "prod") : each.findings }));
|
|
1651
1659
|
if (values.json === true)
|
|
1652
1660
|
printJson(kept);
|
|
@@ -1678,12 +1686,12 @@ function show(audits, total) {
|
|
|
1678
1686
|
}
|
|
1679
1687
|
|
|
1680
1688
|
// src/repos.ts
|
|
1681
|
-
import { existsSync as
|
|
1689
|
+
import { existsSync as existsSync7, statSync as statSync3 } from "fs";
|
|
1682
1690
|
import { basename as basename2, relative as relative2 } from "path";
|
|
1683
1691
|
import process19 from "process";
|
|
1684
1692
|
|
|
1685
1693
|
// src/repos-scan.ts
|
|
1686
|
-
import { existsSync as
|
|
1694
|
+
import { existsSync as existsSync6 } from "fs";
|
|
1687
1695
|
import { readdir as readdir2 } from "fs/promises";
|
|
1688
1696
|
import { basename, join as join9 } from "path";
|
|
1689
1697
|
import process18 from "process";
|
|
@@ -1708,7 +1716,7 @@ function reasonsOf(repo) {
|
|
|
1708
1716
|
return reasons;
|
|
1709
1717
|
}
|
|
1710
1718
|
async function findRepos2(root, skip) {
|
|
1711
|
-
if (
|
|
1719
|
+
if (existsSync6(join9(root, ".git")))
|
|
1712
1720
|
return [root];
|
|
1713
1721
|
const found = [];
|
|
1714
1722
|
async function walk(dir, depth) {
|
|
@@ -1722,7 +1730,7 @@ async function findRepos2(root, skip) {
|
|
|
1722
1730
|
if (!entry.isDirectory() || entry.name === "node_modules" || entry.name.startsWith(".") || skip.has(entry.name))
|
|
1723
1731
|
continue;
|
|
1724
1732
|
const path = join9(dir, entry.name);
|
|
1725
|
-
if (
|
|
1733
|
+
if (existsSync6(join9(path, ".git")))
|
|
1726
1734
|
found.push(path);
|
|
1727
1735
|
else if (depth < MAX_DEPTH2)
|
|
1728
1736
|
await walk(path, depth + 1);
|
|
@@ -1752,7 +1760,7 @@ async function packageReleases(path) {
|
|
|
1752
1760
|
names.add(name);
|
|
1753
1761
|
}
|
|
1754
1762
|
const releases = await pool([...names].toSorted(), PACKAGE_CONCURRENCY, async (name) => {
|
|
1755
|
-
const folder = [join9("packages", name), name].find((candidate) =>
|
|
1763
|
+
const folder = [join9("packages", name), name].find((candidate) => existsSync6(join9(path, candidate)));
|
|
1756
1764
|
const tag = folder === undefined ? undefined : await read(path, ["describe", "--tags", "--abbrev=0", "--match", `${name}-v*`]);
|
|
1757
1765
|
return folder !== undefined && tag !== undefined && tag !== "" ? { name, tag, unreleased: await commitsSince(path, tag, folder) } : undefined;
|
|
1758
1766
|
});
|
|
@@ -1839,7 +1847,7 @@ var OPTIONS2 = {
|
|
|
1839
1847
|
};
|
|
1840
1848
|
async function skipped() {
|
|
1841
1849
|
const file = userConfigReadPath("repos");
|
|
1842
|
-
if (!
|
|
1850
|
+
if (!existsSync7(file))
|
|
1843
1851
|
return new Set;
|
|
1844
1852
|
try {
|
|
1845
1853
|
const config = await Bun.file(file).json();
|
|
@@ -1890,11 +1898,11 @@ async function repos(args) {
|
|
|
1890
1898
|
if (values.watch !== undefined)
|
|
1891
1899
|
return watching(values.watch, async () => repos(withoutWatch(args)));
|
|
1892
1900
|
const root = workspaceRoot({ given: positionals[0] });
|
|
1893
|
-
if (!
|
|
1901
|
+
if (!existsSync7(root) || !statSync3(root).isDirectory())
|
|
1894
1902
|
fail(`no folder ${root}`);
|
|
1895
1903
|
const only = values.only === undefined ? undefined : oneOf(values.only, "only", REASONS);
|
|
1896
1904
|
const paths = await findRepos2(root, await skipped());
|
|
1897
|
-
const states = await pool(paths, CONCURRENCY2, async (path) => inspect(path, values.fetch === true || values.pull === true));
|
|
1905
|
+
const states = await pool(paths, configuredNumber("repos", "concurrency", CONCURRENCY2), async (path) => inspect(path, values.fetch === true || values.pull === true));
|
|
1898
1906
|
const keeps = (repo) => {
|
|
1899
1907
|
const reasons = reasonsOf(repo);
|
|
1900
1908
|
return only === undefined ? values.all === true || reasons.length > 0 || repo.unreadable : reasons.includes(only);
|
|
@@ -1944,7 +1952,7 @@ async function repos(args) {
|
|
|
1944
1952
|
}
|
|
1945
1953
|
|
|
1946
1954
|
// src/sweep.ts
|
|
1947
|
-
import { existsSync as
|
|
1955
|
+
import { existsSync as existsSync10, statSync as statSync4 } from "fs";
|
|
1948
1956
|
import { homedir as homedir6 } from "os";
|
|
1949
1957
|
import { relative as relative3 } from "path";
|
|
1950
1958
|
|
|
@@ -1959,7 +1967,9 @@ var NONE = Number.NEGATIVE_INFINITY;
|
|
|
1959
1967
|
var IS_CONTROL = /[\x00-\x1F\x7F-\x9F]/;
|
|
1960
1968
|
var PASTE_START = "\x1B[200~";
|
|
1961
1969
|
var PASTE_END = "\x1B[201~";
|
|
1962
|
-
var KEY_SEQUENCES = /\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
|
|
1970
|
+
var KEY_SEQUENCES = /\x1B\[<[0-9;]*[A-Za-z]|\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
|
|
1971
|
+
var MOUSE = /^\x1B\[<(\d+);\d+;\d+[a-z]$/i;
|
|
1972
|
+
var WHEEL_LINES = 3;
|
|
1963
1973
|
var KEYS = {
|
|
1964
1974
|
"\x1B[A": "up",
|
|
1965
1975
|
"\x1BOA": "up",
|
|
@@ -1988,9 +1998,15 @@ var KEYS = {
|
|
|
1988
1998
|
"\x1BOP": "help",
|
|
1989
1999
|
"\x1B[11~": "help"
|
|
1990
2000
|
};
|
|
2001
|
+
function repeat(value, count) {
|
|
2002
|
+
return Array.from({ length: count }).fill(value);
|
|
2003
|
+
}
|
|
1991
2004
|
function parseKeys(input, paste = { active: false }, ctrls = []) {
|
|
1992
2005
|
const codes = new Map(ctrls.map((name) => [String.fromCharCode(name.codePointAt(name.length - 1) - 96), name]));
|
|
1993
2006
|
return (input.match(KEY_SEQUENCES) ?? []).flatMap((sequence) => {
|
|
2007
|
+
const wheel = MOUSE.exec(sequence)?.[1];
|
|
2008
|
+
if (wheel !== undefined)
|
|
2009
|
+
return repeat(wheel === "64" ? "up" : "down", wheel === "64" || wheel === "65" ? WHEEL_LINES : 0);
|
|
1994
2010
|
const named = codes.get(sequence);
|
|
1995
2011
|
const key = named === undefined ? KEYS[sequence] : { ctrl: named };
|
|
1996
2012
|
if (sequence === PASTE_START || sequence === PASTE_END) {
|
|
@@ -2038,16 +2054,13 @@ async function ask(question, { hint, terminal = process20 }, render, press) {
|
|
|
2038
2054
|
if (!isInteractive(terminal))
|
|
2039
2055
|
fail(`cannot ask "${question}" off a terminal`, 2, hint);
|
|
2040
2056
|
const colors = paint(stderr);
|
|
2041
|
-
let drawn = [];
|
|
2042
2057
|
let current = "asking";
|
|
2043
2058
|
let outcome;
|
|
2044
2059
|
const columns = () => stderr.columns || 80;
|
|
2045
|
-
const draw = (state) => {
|
|
2060
|
+
const draw = (state, last = false) => {
|
|
2046
2061
|
const frame = render(colors, state, { columns: columns(), rows: stderr.rows || 24 });
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
`)}`);
|
|
2050
|
-
drawn = frame;
|
|
2062
|
+
stderr.write(`\r\x1B[0J${frame.join(`
|
|
2063
|
+
`)}${last || frame.length < 2 ? "" : `\x1B[${frame.length - 1}A`}${last ? "" : "\r"}`);
|
|
2051
2064
|
current = state;
|
|
2052
2065
|
};
|
|
2053
2066
|
const redraw = () => draw(current);
|
|
@@ -2083,7 +2096,7 @@ async function ask(question, { hint, terminal = process20 }, render, press) {
|
|
|
2083
2096
|
});
|
|
2084
2097
|
} finally {
|
|
2085
2098
|
stderr.off?.("resize", redraw);
|
|
2086
|
-
draw(outcome ?? "cancel");
|
|
2099
|
+
draw(outcome ?? "cancel", true);
|
|
2087
2100
|
stderr.write(`
|
|
2088
2101
|
\x1B[?25h\x1B[?2004l`);
|
|
2089
2102
|
stdin.setRawMode(false);
|
|
@@ -2092,12 +2105,12 @@ async function ask(question, { hint, terminal = process20 }, render, press) {
|
|
|
2092
2105
|
}
|
|
2093
2106
|
|
|
2094
2107
|
// src/apply.ts
|
|
2095
|
-
import { existsSync as
|
|
2108
|
+
import { existsSync as existsSync9 } from "fs";
|
|
2096
2109
|
import { lstat as lstat3, rm } from "fs/promises";
|
|
2097
2110
|
import { basename as basename4, join as join12 } from "path";
|
|
2098
2111
|
|
|
2099
2112
|
// src/sweep-scan.ts
|
|
2100
|
-
import { existsSync as
|
|
2113
|
+
import { existsSync as existsSync8 } from "fs";
|
|
2101
2114
|
import { lstat as lstat2, readdir as readdir4, realpath } from "fs/promises";
|
|
2102
2115
|
import { homedir as homedir5 } from "os";
|
|
2103
2116
|
import { basename as basename3, dirname as dirname5, join as join11 } from "path";
|
|
@@ -2223,7 +2236,7 @@ async function findCandidates(root, home = homedir5(), withGlobal = true) {
|
|
|
2223
2236
|
}
|
|
2224
2237
|
continue;
|
|
2225
2238
|
}
|
|
2226
|
-
if (FOLDER_NAMES.has(entry.name) && (entry.name !== "target" ||
|
|
2239
|
+
if (FOLDER_NAMES.has(entry.name) && (entry.name !== "target" || existsSync8(join11(dir, "Cargo.toml")))) {
|
|
2227
2240
|
if (entry.isSymbolicLink()) {
|
|
2228
2241
|
found.skipped.push({ path, reason: "symlink" });
|
|
2229
2242
|
} else if (entry.isDirectory()) {
|
|
@@ -2309,7 +2322,7 @@ async function judgeFolder(path, kind, inside) {
|
|
|
2309
2322
|
const located = await toplevelOf(parent);
|
|
2310
2323
|
if (located === "failed")
|
|
2311
2324
|
return { skip: "git failed" };
|
|
2312
|
-
if (
|
|
2325
|
+
if (existsSync8(join11(path, ".git")))
|
|
2313
2326
|
return { skip: "holds a git repository" };
|
|
2314
2327
|
if (located === "none")
|
|
2315
2328
|
return name === "node_modules" || inside !== undefined ? { entry: { path, kind, committedAt: undefined, action: "remove", inside } } : { skip: "not in a git repository" };
|
|
@@ -2377,7 +2390,7 @@ async function removeFolder(entry) {
|
|
|
2377
2390
|
const stat = await lstat3(entry.path);
|
|
2378
2391
|
if (stat.isSymbolicLink() || !stat.isDirectory() || !(FOLDER_NAMES.has(basename4(entry.path)) || entry.kind === "cache" && isCachePath(entry.path)))
|
|
2379
2392
|
return { path: entry.path, removed: false, error: "no longer a plain folder" };
|
|
2380
|
-
if (
|
|
2393
|
+
if (existsSync9(join12(entry.path, ".git")))
|
|
2381
2394
|
return { path: entry.path, removed: false, error: "holds a git repository" };
|
|
2382
2395
|
await rm(entry.path, { recursive: true, force: true });
|
|
2383
2396
|
return { path: entry.path, removed: true };
|
|
@@ -2440,7 +2453,7 @@ async function sweep(args) {
|
|
|
2440
2453
|
if (positionals.length > 1)
|
|
2441
2454
|
badUsage("give one root");
|
|
2442
2455
|
const root = workspaceRoot({ given: positionals[0] });
|
|
2443
|
-
if (!
|
|
2456
|
+
if (!existsSync10(root) || !statSync4(root).isDirectory())
|
|
2444
2457
|
fail(`${root} is not a folder`);
|
|
2445
2458
|
if (values.only !== undefined && !Object.hasOwn(ONLY_KINDS, values.only))
|
|
2446
2459
|
badUsage(`--only takes worktrees, folders or caches, not ${values.only}`);
|
|
@@ -2460,7 +2473,7 @@ async function sweep(args) {
|
|
|
2460
2473
|
if (values.apply === true && removable.length > 0 && values.yes !== true) {
|
|
2461
2474
|
if (!json)
|
|
2462
2475
|
print(root, entries, skipped.length, reclaimable, now);
|
|
2463
|
-
const agreed = await confirm(`Delete ${removable.length} ${removable.length === 1 ? "entry" : "entries"} (${
|
|
2476
|
+
const agreed = await confirm(`Delete ${removable.length} ${removable.length === 1 ? "entry" : "entries"} (${tt(reclaimable)})?`, { default: false, hint: "pass --yes to skip the confirm" });
|
|
2464
2477
|
if (agreed !== true) {
|
|
2465
2478
|
if (json)
|
|
2466
2479
|
fail("nothing deleted: the confirm was declined", 1, "pass --yes to skip the confirm");
|
|
@@ -2480,7 +2493,7 @@ async function sweep(args) {
|
|
|
2480
2493
|
console.log("dry run, pass --apply to delete");
|
|
2481
2494
|
} else {
|
|
2482
2495
|
const bytes = new Map(removable.map((entry) => [entry.path, entry.bytes]));
|
|
2483
|
-
note(`freed ${
|
|
2496
|
+
note(`freed ${tt(outcomes.reduce((sum, outcome) => sum + (outcome.removed ? bytes.get(outcome.path) ?? 0 : 0), 0))}`);
|
|
2484
2497
|
}
|
|
2485
2498
|
if (docker !== undefined)
|
|
2486
2499
|
console.log(`
|
|
@@ -2505,12 +2518,12 @@ function print(root, entries, skipped, reclaimable, now) {
|
|
|
2505
2518
|
const path = role("path", process.stdout);
|
|
2506
2519
|
const sized = (bytes) => {
|
|
2507
2520
|
if (bytes >= BIG)
|
|
2508
|
-
return colors.red(
|
|
2509
|
-
return bytes >= LARGE ? colors.yellow(
|
|
2521
|
+
return colors.red(tt(bytes));
|
|
2522
|
+
return bytes >= LARGE ? colors.yellow(tt(bytes)) : tt(bytes);
|
|
2510
2523
|
};
|
|
2511
2524
|
console.log(table([["size", "age", "what", "path", "note"], ...entries.map((entry) => [sized(entry.bytes), entry.committedAt === undefined ? colors.dim("-") : colors.dim(formatAge(entry.committedAt, now)), entry.kind, path(relative3(root, entry.path)), entry.action === "keep" ? colors.dim(`kept: ${entry.reason}`) : ""])], { header: true, align: ["right", "right", "left", "left", "left"] }));
|
|
2512
2525
|
console.log(`
|
|
2513
|
-
${
|
|
2526
|
+
${tt(reclaimable)} reclaimable${skipped === 0 ? "" : `, ${skipped} skipped (symlinks, tracked or not ignored by git)`}`);
|
|
2514
2527
|
}
|
|
2515
2528
|
|
|
2516
2529
|
// src/cli.ts
|
package/dist/repos-cli.js
CHANGED
|
@@ -18,6 +18,7 @@ import { parseArgs } from "util";
|
|
|
18
18
|
|
|
19
19
|
// ../kit/src/format.ts
|
|
20
20
|
import process7 from "process";
|
|
21
|
+
|
|
21
22
|
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rxztfxgv.js
|
|
22
23
|
var N = new Map;
|
|
23
24
|
var Nt = /\s+\S*$/;
|
|
@@ -35,6 +36,7 @@ function ko(t, e, r = "...") {
|
|
|
35
36
|
}
|
|
36
37
|
var be = new Map(["\u20AC", "", "\u201A", "\u0192", "\u201E", "\u2026", "\u2020", "\u2021", "\u02C6", "\u2030", "\u0160", "\u2039", "\u0152", "", "\u017D", "", "", "\u2018", "\u2019", "\u201C", "\u201D", "\u2022", "\u2013", "\u2014", "\u02DC", "\u2122", "\u0161", "\u203A", "\u0153", "", "\u017E", "\u0178"].map((t, e) => [t, 128 + e]).filter(([t]) => t));
|
|
37
38
|
var z = new Map;
|
|
39
|
+
|
|
38
40
|
// ../kit/src/mode.ts
|
|
39
41
|
import process2 from "process";
|
|
40
42
|
var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
@@ -83,7 +85,7 @@ function C(r, e = globalThis.process?.env ?? {}) {
|
|
|
83
85
|
return false;
|
|
84
86
|
return r?.isTTY === true;
|
|
85
87
|
}
|
|
86
|
-
function
|
|
88
|
+
function f(r, e = []) {
|
|
87
89
|
let l = "", n = "";
|
|
88
90
|
for (let t = 0, i = e.length;t < i; t++)
|
|
89
91
|
l += `\x1B[${e[t][0]}m`, n = `\x1B[${e[t][1]}m${n}`;
|
|
@@ -93,7 +95,7 @@ function f2(r, e = []) {
|
|
|
93
95
|
if (Array.isArray(a)) {
|
|
94
96
|
let s = g.get(i);
|
|
95
97
|
if (s === undefined)
|
|
96
|
-
s =
|
|
98
|
+
s = f(r, [...e, a]), g.set(i, s);
|
|
97
99
|
return s;
|
|
98
100
|
}
|
|
99
101
|
if (typeof a === "function")
|
|
@@ -102,20 +104,20 @@ function f2(r, e = []) {
|
|
|
102
104
|
if (u === undefined) {
|
|
103
105
|
if (g.size >= 64)
|
|
104
106
|
g.clear();
|
|
105
|
-
u =
|
|
107
|
+
u = f(r, [...e, a(...s)]), g.set(y, u);
|
|
106
108
|
}
|
|
107
109
|
return u;
|
|
108
110
|
};
|
|
109
111
|
throw Error(`Unknown style: ${String(i)}`);
|
|
110
112
|
} });
|
|
111
113
|
}
|
|
112
|
-
function
|
|
113
|
-
return
|
|
114
|
+
function Fe(r = {}) {
|
|
115
|
+
return f(r);
|
|
114
116
|
}
|
|
115
|
-
var
|
|
117
|
+
var o = Fe();
|
|
116
118
|
|
|
117
119
|
// ../kit/src/theme.ts
|
|
118
|
-
import { existsSync as existsSync3, readFileSync, statSync } from "fs";
|
|
120
|
+
import { existsSync as existsSync3, readFileSync as readFileSync2, statSync } from "fs";
|
|
119
121
|
import { homedir as homedir2 } from "os";
|
|
120
122
|
import { join as join3, resolve as resolve2 } from "path";
|
|
121
123
|
import process5 from "process";
|
|
@@ -136,7 +138,7 @@ function findUp(names, from = process3.cwd(), stop = () => false) {
|
|
|
136
138
|
}
|
|
137
139
|
|
|
138
140
|
// ../kit/src/user-config.ts
|
|
139
|
-
import { existsSync as existsSync2 } from "fs";
|
|
141
|
+
import { existsSync as existsSync2, readFileSync } from "fs";
|
|
140
142
|
import { homedir } from "os";
|
|
141
143
|
import { join as join2 } from "path";
|
|
142
144
|
import process4 from "process";
|
|
@@ -154,6 +156,21 @@ function userConfigReadPath(bin, legacy = [], where = {}) {
|
|
|
154
156
|
const base = configBase(where);
|
|
155
157
|
return legacy.map((parts) => join2(base, ...parts)).find((path) => existsSync2(path)) ?? current;
|
|
156
158
|
}
|
|
159
|
+
function readUserConfig(bin, where = {}, legacy = []) {
|
|
160
|
+
const path = userConfigReadPath(bin, legacy, where);
|
|
161
|
+
if (!existsSync2(path))
|
|
162
|
+
return {};
|
|
163
|
+
try {
|
|
164
|
+
const parsed = Bun.JSONC.parse(readFileSync(path, "utf8"));
|
|
165
|
+
return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? parsed : {};
|
|
166
|
+
} catch {
|
|
167
|
+
return {};
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
function configuredNumber(bin, key, fallback, where = {}, legacy = []) {
|
|
171
|
+
const value = readUserConfig(bin, where, legacy)[key];
|
|
172
|
+
return typeof value === "number" && Number.isInteger(value) && value > 0 ? value : fallback;
|
|
173
|
+
}
|
|
157
174
|
|
|
158
175
|
// ../kit/src/theme.ts
|
|
159
176
|
var ENDS = new Map;
|
|
@@ -220,7 +237,7 @@ function readThemeFile(path, warn) {
|
|
|
220
237
|
warn(`${path} is not a regular file under ${MAX_FILE_BYTES / 1024} KiB, theme ignored`);
|
|
221
238
|
return;
|
|
222
239
|
}
|
|
223
|
-
const parsed = JSON.parse(
|
|
240
|
+
const parsed = JSON.parse(readFileSync2(path, "utf8"));
|
|
224
241
|
if (isRecord(parsed))
|
|
225
242
|
return parsed;
|
|
226
243
|
warn(`${path} is not a JSON object, theme ignored`);
|
|
@@ -342,7 +359,7 @@ function takesControlCodes(stream, env = process6.env) {
|
|
|
342
359
|
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
343
360
|
}
|
|
344
361
|
function paint(stream, env = process6.env) {
|
|
345
|
-
return
|
|
362
|
+
return Fe({ stream: { isTTY: takesControlCodes(stream, env) }, env });
|
|
346
363
|
}
|
|
347
364
|
function marked(mark, text, stream, detail, env = process6.env) {
|
|
348
365
|
const colors = paint(stream, env);
|
|
@@ -916,7 +933,7 @@ async function runTool(label, argv, { timeoutMs, cwd, onStart } = {}) {
|
|
|
916
933
|
return { code: ran.code, ...streams };
|
|
917
934
|
}
|
|
918
935
|
// ../kit/src/cli.ts
|
|
919
|
-
import { readFileSync as
|
|
936
|
+
import { readFileSync as readFileSync3, realpathSync } from "fs";
|
|
920
937
|
import { dirname as dirname3, join as join5 } from "path";
|
|
921
938
|
import process13 from "process";
|
|
922
939
|
|
|
@@ -1217,7 +1234,7 @@ async function printCandidates(found) {
|
|
|
1217
1234
|
function packageVersion(entry = Bun.main) {
|
|
1218
1235
|
for (let dir = dirname3(realpathSync(entry));; dir = dirname3(dir)) {
|
|
1219
1236
|
try {
|
|
1220
|
-
const { version } = JSON.parse(
|
|
1237
|
+
const { version } = JSON.parse(readFileSync3(join5(dir, "package.json"), "utf8"));
|
|
1221
1238
|
if (typeof version === "string")
|
|
1222
1239
|
return version;
|
|
1223
1240
|
} catch {}
|
|
@@ -1356,7 +1373,6 @@ async function watching(value, step, stream = process14.stdout, sleep = Bun.slee
|
|
|
1356
1373
|
return code;
|
|
1357
1374
|
}
|
|
1358
1375
|
// ../kit/src/workspace-root.ts
|
|
1359
|
-
import { existsSync as existsSync4, mkdirSync as mkdirSync2, readFileSync as readFileSync3, writeFileSync } from "fs";
|
|
1360
1376
|
import { homedir as homedir4 } from "os";
|
|
1361
1377
|
import { dirname as dirname4, join as join6, resolve as resolve3 } from "path";
|
|
1362
1378
|
import process15 from "process";
|
|
@@ -1366,28 +1382,20 @@ function expandHome(path, home) {
|
|
|
1366
1382
|
return path.startsWith("~/") ? join6(home, path.slice(2)) : path;
|
|
1367
1383
|
}
|
|
1368
1384
|
function configured(env, home) {
|
|
1369
|
-
const
|
|
1370
|
-
|
|
1371
|
-
return;
|
|
1372
|
-
try {
|
|
1373
|
-
const parsed = JSON.parse(readFileSync3(path, "utf8"));
|
|
1374
|
-
const folder = typeof parsed === "object" && parsed !== null ? parsed.workspace : undefined;
|
|
1375
|
-
return typeof folder === "string" && folder !== "" ? folder : undefined;
|
|
1376
|
-
} catch {
|
|
1377
|
-
return;
|
|
1378
|
-
}
|
|
1385
|
+
const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
|
|
1386
|
+
return typeof folder === "string" && folder !== "" ? folder : undefined;
|
|
1379
1387
|
}
|
|
1380
1388
|
function workspaceRoot({ given, env = process15.env, home = homedir4() } = {}) {
|
|
1381
1389
|
const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
|
|
1382
1390
|
return resolve3(expandHome(given ?? fromEnv ?? configured(env, home) ?? join6(home, "Workspace"), home));
|
|
1383
1391
|
}
|
|
1384
1392
|
// src/repos.ts
|
|
1385
|
-
import { existsSync as
|
|
1393
|
+
import { existsSync as existsSync5, statSync as statSync2 } from "fs";
|
|
1386
1394
|
import { basename as basename2, relative } from "path";
|
|
1387
1395
|
import process18 from "process";
|
|
1388
1396
|
|
|
1389
1397
|
// src/repos-scan.ts
|
|
1390
|
-
import { existsSync as
|
|
1398
|
+
import { existsSync as existsSync4 } from "fs";
|
|
1391
1399
|
import { readdir } from "fs/promises";
|
|
1392
1400
|
import { basename, join as join7 } from "path";
|
|
1393
1401
|
import process17 from "process";
|
|
@@ -1412,7 +1420,7 @@ function reasonsOf(repo) {
|
|
|
1412
1420
|
return reasons;
|
|
1413
1421
|
}
|
|
1414
1422
|
async function findRepos(root, skip) {
|
|
1415
|
-
if (
|
|
1423
|
+
if (existsSync4(join7(root, ".git")))
|
|
1416
1424
|
return [root];
|
|
1417
1425
|
const found = [];
|
|
1418
1426
|
async function walk(dir, depth) {
|
|
@@ -1426,7 +1434,7 @@ async function findRepos(root, skip) {
|
|
|
1426
1434
|
if (!entry.isDirectory() || entry.name === "node_modules" || entry.name.startsWith(".") || skip.has(entry.name))
|
|
1427
1435
|
continue;
|
|
1428
1436
|
const path = join7(dir, entry.name);
|
|
1429
|
-
if (
|
|
1437
|
+
if (existsSync4(join7(path, ".git")))
|
|
1430
1438
|
found.push(path);
|
|
1431
1439
|
else if (depth < MAX_DEPTH)
|
|
1432
1440
|
await walk(path, depth + 1);
|
|
@@ -1456,7 +1464,7 @@ async function packageReleases(path) {
|
|
|
1456
1464
|
names.add(name);
|
|
1457
1465
|
}
|
|
1458
1466
|
const releases = await pool([...names].toSorted(), PACKAGE_CONCURRENCY, async (name) => {
|
|
1459
|
-
const folder = [join7("packages", name), name].find((candidate) =>
|
|
1467
|
+
const folder = [join7("packages", name), name].find((candidate) => existsSync4(join7(path, candidate)));
|
|
1460
1468
|
const tag = folder === undefined ? undefined : await read(path, ["describe", "--tags", "--abbrev=0", "--match", `${name}-v*`]);
|
|
1461
1469
|
return folder !== undefined && tag !== undefined && tag !== "" ? { name, tag, unreleased: await commitsSince(path, tag, folder) } : undefined;
|
|
1462
1470
|
});
|
|
@@ -1543,7 +1551,7 @@ var OPTIONS = {
|
|
|
1543
1551
|
};
|
|
1544
1552
|
async function skipped() {
|
|
1545
1553
|
const file = userConfigReadPath("repos");
|
|
1546
|
-
if (!
|
|
1554
|
+
if (!existsSync5(file))
|
|
1547
1555
|
return new Set;
|
|
1548
1556
|
try {
|
|
1549
1557
|
const config = await Bun.file(file).json();
|
|
@@ -1594,11 +1602,11 @@ async function repos(args) {
|
|
|
1594
1602
|
if (values.watch !== undefined)
|
|
1595
1603
|
return watching(values.watch, async () => repos(withoutWatch(args)));
|
|
1596
1604
|
const root = workspaceRoot({ given: positionals[0] });
|
|
1597
|
-
if (!
|
|
1605
|
+
if (!existsSync5(root) || !statSync2(root).isDirectory())
|
|
1598
1606
|
fail(`no folder ${root}`);
|
|
1599
1607
|
const only = values.only === undefined ? undefined : oneOf(values.only, "only", REASONS);
|
|
1600
1608
|
const paths = await findRepos(root, await skipped());
|
|
1601
|
-
const states = await pool(paths, CONCURRENCY, async (path) => inspect(path, values.fetch === true || values.pull === true));
|
|
1609
|
+
const states = await pool(paths, configuredNumber("repos", "concurrency", CONCURRENCY), async (path) => inspect(path, values.fetch === true || values.pull === true));
|
|
1602
1610
|
const keeps = (repo) => {
|
|
1603
1611
|
const reasons = reasonsOf(repo);
|
|
1604
1612
|
return only === undefined ? values.all === true || reasons.length > 0 || repo.unreadable : reasons.includes(only);
|
package/dist/sweep-cli.js
CHANGED
|
@@ -32,6 +32,7 @@ function y(e, t) {
|
|
|
32
32
|
n = new Intl.NumberFormat(e, t), i.set(o, n);
|
|
33
33
|
return n;
|
|
34
34
|
}
|
|
35
|
+
|
|
35
36
|
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rxztfxgv.js
|
|
36
37
|
var N = new Map;
|
|
37
38
|
var Nt = /\s+\S*$/;
|
|
@@ -49,6 +50,7 @@ function ko(t, e, r = "...") {
|
|
|
49
50
|
}
|
|
50
51
|
var be = new Map(["\u20AC", "", "\u201A", "\u0192", "\u201E", "\u2026", "\u2020", "\u2021", "\u02C6", "\u2030", "\u0160", "\u2039", "\u0152", "", "\u017D", "", "", "\u2018", "\u2019", "\u201C", "\u201D", "\u2022", "\u2013", "\u2014", "\u02DC", "\u2122", "\u0161", "\u203A", "\u0153", "", "\u017E", "\u0178"].map((t, e) => [t, 128 + e]).filter(([t]) => t));
|
|
51
52
|
var z = new Map;
|
|
53
|
+
|
|
52
54
|
// ../kit/src/mode.ts
|
|
53
55
|
import process2 from "process";
|
|
54
56
|
var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
@@ -97,7 +99,7 @@ function C(r, e = globalThis.process?.env ?? {}) {
|
|
|
97
99
|
return false;
|
|
98
100
|
return r?.isTTY === true;
|
|
99
101
|
}
|
|
100
|
-
function
|
|
102
|
+
function f(r, e = []) {
|
|
101
103
|
let l = "", n = "";
|
|
102
104
|
for (let t = 0, i = e.length;t < i; t++)
|
|
103
105
|
l += `\x1B[${e[t][0]}m`, n = `\x1B[${e[t][1]}m${n}`;
|
|
@@ -107,7 +109,7 @@ function f2(r, e = []) {
|
|
|
107
109
|
if (Array.isArray(a)) {
|
|
108
110
|
let s = g.get(i);
|
|
109
111
|
if (s === undefined)
|
|
110
|
-
s =
|
|
112
|
+
s = f(r, [...e, a]), g.set(i, s);
|
|
111
113
|
return s;
|
|
112
114
|
}
|
|
113
115
|
if (typeof a === "function")
|
|
@@ -116,20 +118,20 @@ function f2(r, e = []) {
|
|
|
116
118
|
if (u === undefined) {
|
|
117
119
|
if (g.size >= 64)
|
|
118
120
|
g.clear();
|
|
119
|
-
u =
|
|
121
|
+
u = f(r, [...e, a(...s)]), g.set(y, u);
|
|
120
122
|
}
|
|
121
123
|
return u;
|
|
122
124
|
};
|
|
123
125
|
throw Error(`Unknown style: ${String(i)}`);
|
|
124
126
|
} });
|
|
125
127
|
}
|
|
126
|
-
function
|
|
127
|
-
return
|
|
128
|
+
function Fe(r = {}) {
|
|
129
|
+
return f(r);
|
|
128
130
|
}
|
|
129
|
-
var
|
|
131
|
+
var o = Fe();
|
|
130
132
|
|
|
131
133
|
// ../kit/src/theme.ts
|
|
132
|
-
import { existsSync as existsSync3, readFileSync, statSync } from "fs";
|
|
134
|
+
import { existsSync as existsSync3, readFileSync as readFileSync2, statSync } from "fs";
|
|
133
135
|
import { homedir as homedir2 } from "os";
|
|
134
136
|
import { join as join3, resolve as resolve2 } from "path";
|
|
135
137
|
import process5 from "process";
|
|
@@ -150,7 +152,7 @@ function findUp(names, from = process3.cwd(), stop = () => false) {
|
|
|
150
152
|
}
|
|
151
153
|
|
|
152
154
|
// ../kit/src/user-config.ts
|
|
153
|
-
import { existsSync as existsSync2 } from "fs";
|
|
155
|
+
import { existsSync as existsSync2, readFileSync } from "fs";
|
|
154
156
|
import { homedir } from "os";
|
|
155
157
|
import { join as join2 } from "path";
|
|
156
158
|
import process4 from "process";
|
|
@@ -168,6 +170,21 @@ function userConfigReadPath(bin, legacy = [], where = {}) {
|
|
|
168
170
|
const base = configBase(where);
|
|
169
171
|
return legacy.map((parts) => join2(base, ...parts)).find((path) => existsSync2(path)) ?? current;
|
|
170
172
|
}
|
|
173
|
+
function readUserConfig(bin, where = {}, legacy = []) {
|
|
174
|
+
const path = userConfigReadPath(bin, legacy, where);
|
|
175
|
+
if (!existsSync2(path))
|
|
176
|
+
return {};
|
|
177
|
+
try {
|
|
178
|
+
const parsed = Bun.JSONC.parse(readFileSync(path, "utf8"));
|
|
179
|
+
return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? parsed : {};
|
|
180
|
+
} catch {
|
|
181
|
+
return {};
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
function configuredNumber(bin, key, fallback, where = {}, legacy = []) {
|
|
185
|
+
const value = readUserConfig(bin, where, legacy)[key];
|
|
186
|
+
return typeof value === "number" && Number.isInteger(value) && value > 0 ? value : fallback;
|
|
187
|
+
}
|
|
171
188
|
|
|
172
189
|
// ../kit/src/theme.ts
|
|
173
190
|
var ENDS = new Map;
|
|
@@ -234,7 +251,7 @@ function readThemeFile(path, warn) {
|
|
|
234
251
|
warn(`${path} is not a regular file under ${MAX_FILE_BYTES / 1024} KiB, theme ignored`);
|
|
235
252
|
return;
|
|
236
253
|
}
|
|
237
|
-
const parsed = JSON.parse(
|
|
254
|
+
const parsed = JSON.parse(readFileSync2(path, "utf8"));
|
|
238
255
|
if (isRecord(parsed))
|
|
239
256
|
return parsed;
|
|
240
257
|
warn(`${path} is not a JSON object, theme ignored`);
|
|
@@ -356,7 +373,7 @@ function takesControlCodes(stream, env = process6.env) {
|
|
|
356
373
|
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
357
374
|
}
|
|
358
375
|
function paint(stream, env = process6.env) {
|
|
359
|
-
return
|
|
376
|
+
return Fe({ stream: { isTTY: takesControlCodes(stream, env) }, env });
|
|
360
377
|
}
|
|
361
378
|
function marked(mark, text, stream, detail, env = process6.env) {
|
|
362
379
|
const colors = paint(stream, env);
|
|
@@ -404,7 +421,7 @@ function printHeader(bin, context, stream = process6.stdout, env = process6.env)
|
|
|
404
421
|
console.log(line);
|
|
405
422
|
}
|
|
406
423
|
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-knqbxp56.js
|
|
407
|
-
function
|
|
424
|
+
function tt(i, { units: r = "iec", dp: t = 1, locale: n } = {}) {
|
|
408
425
|
let e = r === "si" ? 1000 : 1024;
|
|
409
426
|
if (Math.abs(i) < e)
|
|
410
427
|
return `${i} B`;
|
|
@@ -941,7 +958,7 @@ async function runTool(label, argv, { timeoutMs, cwd, onStart } = {}) {
|
|
|
941
958
|
return { code: ran.code, ...streams };
|
|
942
959
|
}
|
|
943
960
|
// ../kit/src/cli.ts
|
|
944
|
-
import { readFileSync as
|
|
961
|
+
import { readFileSync as readFileSync3, realpathSync } from "fs";
|
|
945
962
|
import { dirname as dirname3, join as join5 } from "path";
|
|
946
963
|
import process13 from "process";
|
|
947
964
|
|
|
@@ -1242,7 +1259,7 @@ async function printCandidates(found) {
|
|
|
1242
1259
|
function packageVersion(entry = Bun.main) {
|
|
1243
1260
|
for (let dir = dirname3(realpathSync(entry));; dir = dirname3(dir)) {
|
|
1244
1261
|
try {
|
|
1245
|
-
const { version } = JSON.parse(
|
|
1262
|
+
const { version } = JSON.parse(readFileSync3(join5(dir, "package.json"), "utf8"));
|
|
1246
1263
|
if (typeof version === "string")
|
|
1247
1264
|
return version;
|
|
1248
1265
|
} catch {}
|
|
@@ -1381,7 +1398,6 @@ async function watching(value, step, stream = process14.stdout, sleep = Bun.slee
|
|
|
1381
1398
|
return code;
|
|
1382
1399
|
}
|
|
1383
1400
|
// ../kit/src/workspace-root.ts
|
|
1384
|
-
import { existsSync as existsSync4, mkdirSync as mkdirSync2, readFileSync as readFileSync3, writeFileSync } from "fs";
|
|
1385
1401
|
import { homedir as homedir4 } from "os";
|
|
1386
1402
|
import { dirname as dirname4, join as join6, resolve as resolve3 } from "path";
|
|
1387
1403
|
import process15 from "process";
|
|
@@ -1391,23 +1407,15 @@ function expandHome(path, home) {
|
|
|
1391
1407
|
return path.startsWith("~/") ? join6(home, path.slice(2)) : path;
|
|
1392
1408
|
}
|
|
1393
1409
|
function configured(env, home) {
|
|
1394
|
-
const
|
|
1395
|
-
|
|
1396
|
-
return;
|
|
1397
|
-
try {
|
|
1398
|
-
const parsed = JSON.parse(readFileSync3(path, "utf8"));
|
|
1399
|
-
const folder = typeof parsed === "object" && parsed !== null ? parsed.workspace : undefined;
|
|
1400
|
-
return typeof folder === "string" && folder !== "" ? folder : undefined;
|
|
1401
|
-
} catch {
|
|
1402
|
-
return;
|
|
1403
|
-
}
|
|
1410
|
+
const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
|
|
1411
|
+
return typeof folder === "string" && folder !== "" ? folder : undefined;
|
|
1404
1412
|
}
|
|
1405
1413
|
function workspaceRoot({ given, env = process15.env, home = homedir4() } = {}) {
|
|
1406
1414
|
const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
|
|
1407
1415
|
return resolve3(expandHome(given ?? fromEnv ?? configured(env, home) ?? join6(home, "Workspace"), home));
|
|
1408
1416
|
}
|
|
1409
1417
|
// src/sweep.ts
|
|
1410
|
-
import { existsSync as
|
|
1418
|
+
import { existsSync as existsSync6, statSync as statSync2 } from "fs";
|
|
1411
1419
|
import { homedir as homedir6 } from "os";
|
|
1412
1420
|
import { relative } from "path";
|
|
1413
1421
|
|
|
@@ -1422,7 +1430,9 @@ var NONE = Number.NEGATIVE_INFINITY;
|
|
|
1422
1430
|
var IS_CONTROL = /[\x00-\x1F\x7F-\x9F]/;
|
|
1423
1431
|
var PASTE_START = "\x1B[200~";
|
|
1424
1432
|
var PASTE_END = "\x1B[201~";
|
|
1425
|
-
var KEY_SEQUENCES = /\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
|
|
1433
|
+
var KEY_SEQUENCES = /\x1B\[<[0-9;]*[A-Za-z]|\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
|
|
1434
|
+
var MOUSE = /^\x1B\[<(\d+);\d+;\d+[a-z]$/i;
|
|
1435
|
+
var WHEEL_LINES = 3;
|
|
1426
1436
|
var KEYS = {
|
|
1427
1437
|
"\x1B[A": "up",
|
|
1428
1438
|
"\x1BOA": "up",
|
|
@@ -1451,9 +1461,15 @@ var KEYS = {
|
|
|
1451
1461
|
"\x1BOP": "help",
|
|
1452
1462
|
"\x1B[11~": "help"
|
|
1453
1463
|
};
|
|
1464
|
+
function repeat(value, count) {
|
|
1465
|
+
return Array.from({ length: count }).fill(value);
|
|
1466
|
+
}
|
|
1454
1467
|
function parseKeys(input, paste = { active: false }, ctrls = []) {
|
|
1455
1468
|
const codes = new Map(ctrls.map((name) => [String.fromCharCode(name.codePointAt(name.length - 1) - 96), name]));
|
|
1456
1469
|
return (input.match(KEY_SEQUENCES) ?? []).flatMap((sequence) => {
|
|
1470
|
+
const wheel = MOUSE.exec(sequence)?.[1];
|
|
1471
|
+
if (wheel !== undefined)
|
|
1472
|
+
return repeat(wheel === "64" ? "up" : "down", wheel === "64" || wheel === "65" ? WHEEL_LINES : 0);
|
|
1457
1473
|
const named = codes.get(sequence);
|
|
1458
1474
|
const key = named === undefined ? KEYS[sequence] : { ctrl: named };
|
|
1459
1475
|
if (sequence === PASTE_START || sequence === PASTE_END) {
|
|
@@ -1501,16 +1517,13 @@ async function ask(question, { hint, terminal = process17 }, render, press) {
|
|
|
1501
1517
|
if (!isInteractive(terminal))
|
|
1502
1518
|
fail(`cannot ask "${question}" off a terminal`, 2, hint);
|
|
1503
1519
|
const colors = paint(stderr);
|
|
1504
|
-
let drawn = [];
|
|
1505
1520
|
let current = "asking";
|
|
1506
1521
|
let outcome;
|
|
1507
1522
|
const columns = () => stderr.columns || 80;
|
|
1508
|
-
const draw = (state) => {
|
|
1523
|
+
const draw = (state, last = false) => {
|
|
1509
1524
|
const frame = render(colors, state, { columns: columns(), rows: stderr.rows || 24 });
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
`)}`);
|
|
1513
|
-
drawn = frame;
|
|
1525
|
+
stderr.write(`\r\x1B[0J${frame.join(`
|
|
1526
|
+
`)}${last || frame.length < 2 ? "" : `\x1B[${frame.length - 1}A`}${last ? "" : "\r"}`);
|
|
1514
1527
|
current = state;
|
|
1515
1528
|
};
|
|
1516
1529
|
const redraw = () => draw(current);
|
|
@@ -1546,7 +1559,7 @@ async function ask(question, { hint, terminal = process17 }, render, press) {
|
|
|
1546
1559
|
});
|
|
1547
1560
|
} finally {
|
|
1548
1561
|
stderr.off?.("resize", redraw);
|
|
1549
|
-
draw(outcome ?? "cancel");
|
|
1562
|
+
draw(outcome ?? "cancel", true);
|
|
1550
1563
|
stderr.write(`
|
|
1551
1564
|
\x1B[?25h\x1B[?2004l`);
|
|
1552
1565
|
stdin.setRawMode(false);
|
|
@@ -1555,12 +1568,12 @@ async function ask(question, { hint, terminal = process17 }, render, press) {
|
|
|
1555
1568
|
}
|
|
1556
1569
|
|
|
1557
1570
|
// src/apply.ts
|
|
1558
|
-
import { existsSync as
|
|
1571
|
+
import { existsSync as existsSync5 } from "fs";
|
|
1559
1572
|
import { lstat as lstat3, rm } from "fs/promises";
|
|
1560
1573
|
import { basename as basename2, join as join9 } from "path";
|
|
1561
1574
|
|
|
1562
1575
|
// src/sweep-scan.ts
|
|
1563
|
-
import { existsSync as
|
|
1576
|
+
import { existsSync as existsSync4 } from "fs";
|
|
1564
1577
|
import { lstat as lstat2, readdir as readdir2, realpath } from "fs/promises";
|
|
1565
1578
|
import { homedir as homedir5 } from "os";
|
|
1566
1579
|
import { basename, dirname as dirname5, join as join8 } from "path";
|
|
@@ -1686,7 +1699,7 @@ async function findCandidates(root, home = homedir5(), withGlobal = true) {
|
|
|
1686
1699
|
}
|
|
1687
1700
|
continue;
|
|
1688
1701
|
}
|
|
1689
|
-
if (FOLDER_NAMES.has(entry.name) && (entry.name !== "target" ||
|
|
1702
|
+
if (FOLDER_NAMES.has(entry.name) && (entry.name !== "target" || existsSync4(join8(dir, "Cargo.toml")))) {
|
|
1690
1703
|
if (entry.isSymbolicLink()) {
|
|
1691
1704
|
found.skipped.push({ path, reason: "symlink" });
|
|
1692
1705
|
} else if (entry.isDirectory()) {
|
|
@@ -1772,7 +1785,7 @@ async function judgeFolder(path, kind, inside) {
|
|
|
1772
1785
|
const located = await toplevelOf(parent);
|
|
1773
1786
|
if (located === "failed")
|
|
1774
1787
|
return { skip: "git failed" };
|
|
1775
|
-
if (
|
|
1788
|
+
if (existsSync4(join8(path, ".git")))
|
|
1776
1789
|
return { skip: "holds a git repository" };
|
|
1777
1790
|
if (located === "none")
|
|
1778
1791
|
return name === "node_modules" || inside !== undefined ? { entry: { path, kind, committedAt: undefined, action: "remove", inside } } : { skip: "not in a git repository" };
|
|
@@ -1840,7 +1853,7 @@ async function removeFolder(entry) {
|
|
|
1840
1853
|
const stat = await lstat3(entry.path);
|
|
1841
1854
|
if (stat.isSymbolicLink() || !stat.isDirectory() || !(FOLDER_NAMES.has(basename2(entry.path)) || entry.kind === "cache" && isCachePath(entry.path)))
|
|
1842
1855
|
return { path: entry.path, removed: false, error: "no longer a plain folder" };
|
|
1843
|
-
if (
|
|
1856
|
+
if (existsSync5(join9(entry.path, ".git")))
|
|
1844
1857
|
return { path: entry.path, removed: false, error: "holds a git repository" };
|
|
1845
1858
|
await rm(entry.path, { recursive: true, force: true });
|
|
1846
1859
|
return { path: entry.path, removed: true };
|
|
@@ -1903,7 +1916,7 @@ async function sweep(args) {
|
|
|
1903
1916
|
if (positionals.length > 1)
|
|
1904
1917
|
badUsage("give one root");
|
|
1905
1918
|
const root = workspaceRoot({ given: positionals[0] });
|
|
1906
|
-
if (!
|
|
1919
|
+
if (!existsSync6(root) || !statSync2(root).isDirectory())
|
|
1907
1920
|
fail(`${root} is not a folder`);
|
|
1908
1921
|
if (values.only !== undefined && !Object.hasOwn(ONLY_KINDS, values.only))
|
|
1909
1922
|
badUsage(`--only takes worktrees, folders or caches, not ${values.only}`);
|
|
@@ -1923,7 +1936,7 @@ async function sweep(args) {
|
|
|
1923
1936
|
if (values.apply === true && removable.length > 0 && values.yes !== true) {
|
|
1924
1937
|
if (!json)
|
|
1925
1938
|
print(root, entries, skipped.length, reclaimable, now);
|
|
1926
|
-
const agreed = await confirm(`Delete ${removable.length} ${removable.length === 1 ? "entry" : "entries"} (${
|
|
1939
|
+
const agreed = await confirm(`Delete ${removable.length} ${removable.length === 1 ? "entry" : "entries"} (${tt(reclaimable)})?`, { default: false, hint: "pass --yes to skip the confirm" });
|
|
1927
1940
|
if (agreed !== true) {
|
|
1928
1941
|
if (json)
|
|
1929
1942
|
fail("nothing deleted: the confirm was declined", 1, "pass --yes to skip the confirm");
|
|
@@ -1943,7 +1956,7 @@ async function sweep(args) {
|
|
|
1943
1956
|
console.log("dry run, pass --apply to delete");
|
|
1944
1957
|
} else {
|
|
1945
1958
|
const bytes = new Map(removable.map((entry) => [entry.path, entry.bytes]));
|
|
1946
|
-
note(`freed ${
|
|
1959
|
+
note(`freed ${tt(outcomes.reduce((sum, outcome) => sum + (outcome.removed ? bytes.get(outcome.path) ?? 0 : 0), 0))}`);
|
|
1947
1960
|
}
|
|
1948
1961
|
if (docker !== undefined)
|
|
1949
1962
|
console.log(`
|
|
@@ -1968,12 +1981,12 @@ function print(root, entries, skipped, reclaimable, now) {
|
|
|
1968
1981
|
const path = role("path", process.stdout);
|
|
1969
1982
|
const sized = (bytes) => {
|
|
1970
1983
|
if (bytes >= BIG)
|
|
1971
|
-
return colors.red(
|
|
1972
|
-
return bytes >= LARGE ? colors.yellow(
|
|
1984
|
+
return colors.red(tt(bytes));
|
|
1985
|
+
return bytes >= LARGE ? colors.yellow(tt(bytes)) : tt(bytes);
|
|
1973
1986
|
};
|
|
1974
1987
|
console.log(table([["size", "age", "what", "path", "note"], ...entries.map((entry) => [sized(entry.bytes), entry.committedAt === undefined ? colors.dim("-") : colors.dim(formatAge(entry.committedAt, now)), entry.kind, path(relative(root, entry.path)), entry.action === "keep" ? colors.dim(`kept: ${entry.reason}`) : ""])], { header: true, align: ["right", "right", "left", "left", "left"] }));
|
|
1975
1988
|
console.log(`
|
|
1976
|
-
${
|
|
1989
|
+
${tt(reclaimable)} reclaimable${skipped === 0 ? "" : `, ${skipped} skipped (symlinks, tracked or not ignored by git)`}`);
|
|
1977
1990
|
}
|
|
1978
1991
|
|
|
1979
1992
|
// src/sweep-cli.ts
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaynooo/cli-workspace",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.10.
|
|
4
|
+
"version": "0.10.1",
|
|
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.37.0"
|
|
38
38
|
}
|
|
39
39
|
}
|