@osdlc/repo-cleaner 0.20.4 → 0.22.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/CHANGELOG.md +72 -0
- package/README.md +545 -165
- package/dist/approval.d.ts +91 -0
- package/dist/approval.js +233 -0
- package/dist/archive.d.ts +87 -0
- package/dist/archive.js +252 -0
- package/dist/branches.d.ts +4 -4
- package/dist/branches.js +56 -43
- package/dist/clean.d.ts +30 -70
- package/dist/clean.js +251 -197
- package/dist/cli.d.ts +16 -10
- package/dist/cli.js +252 -103
- package/dist/discover.d.ts +28 -7
- package/dist/discover.js +185 -42
- package/dist/index.d.ts +6 -3
- package/dist/index.js +5 -2
- package/dist/landing.d.ts +10 -5
- package/dist/landing.js +15 -16
- package/dist/plan.d.ts +18 -11
- package/dist/plan.js +33 -13
- package/dist/processes.d.ts +19 -9
- package/dist/processes.js +51 -25
- package/dist/providers/github.d.ts +21 -3
- package/dist/providers/github.js +149 -27
- package/dist/providers/gitlab.js +37 -17
- package/dist/providers/index.d.ts +1 -1
- package/dist/providers/index.js +1 -1
- package/dist/providers/types.d.ts +15 -2
- package/dist/prs.d.ts +19 -10
- package/dist/prs.js +21 -13
- package/dist/receipt.d.ts +68 -3
- package/dist/receipt.js +30 -3
- package/dist/reference.d.ts +1 -1
- package/dist/reference.js +93 -50
- package/dist/remote-mirror.d.ts +2 -1
- package/dist/remote-mirror.js +3 -14
- package/dist/render.d.ts +17 -2
- package/dist/render.js +80 -13
- package/dist/scope.d.ts +15 -0
- package/dist/scope.js +125 -0
- package/dist/size.d.ts +20 -0
- package/dist/size.js +34 -0
- package/dist/status-line.js +1 -0
- package/dist/step-board.js +6 -4
- package/dist/sweep.d.ts +45 -18
- package/dist/sweep.js +151 -127
- package/dist/types.d.ts +89 -10
- package/dist/types.js +50 -6
- package/dist/util.d.ts +2 -0
- package/dist/util.js +25 -0
- package/dist/version.generated.d.ts +1 -1
- package/dist/version.generated.js +1 -1
- package/dist/worktrees.js +87 -11
- package/package.json +6 -5
package/dist/render.js
CHANGED
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
* behind every verdict included.
|
|
8
8
|
*/
|
|
9
9
|
import { ansiColors, paint, stripControls } from '@osdlc/ux';
|
|
10
|
-
import { KINDS, isPrune, isUnfetched, parseRowId, totalOf, } from "./types.js";
|
|
10
|
+
import { KINDS, isPrune, isUnfetched, judgedRemotes, parseRowId, totalOf, } from "./types.js";
|
|
11
|
+
import { formatBytes } from "./size.js";
|
|
11
12
|
import { plural } from "./util.js";
|
|
12
13
|
/** Branches first, then worktrees, then remotes, whatever order they were gathered in. */
|
|
13
14
|
const KIND_ORDER = ['branch', 'worktree', 'remote'];
|
|
@@ -54,20 +55,41 @@ function risksNote(row) {
|
|
|
54
55
|
: name);
|
|
55
56
|
return `needs --allow ${names.join(', ')}`;
|
|
56
57
|
}
|
|
58
|
+
/** What a row's size read gave: bytes, null when `du` could not say, undefined when none was read. */
|
|
59
|
+
function sizeRead(row) {
|
|
60
|
+
return row.kind === 'worktree' ? row.evidence.sizeBytes : undefined;
|
|
61
|
+
}
|
|
62
|
+
/** The bytes a row's size was read as; -1 when none was, so those rows follow the sized ones. */
|
|
63
|
+
function sizeRank(row) {
|
|
64
|
+
return sizeRead(row) ?? -1;
|
|
65
|
+
}
|
|
57
66
|
function sortRows(rows) {
|
|
58
67
|
const kindRank = (r) => KIND_ORDER.indexOf(r.kind);
|
|
59
68
|
const verdictRank = (r) => VERDICT_ORDER.indexOf(r.verdict);
|
|
60
|
-
return [...rows].sort((a, b) => kindRank(a) - kindRank(b) ||
|
|
69
|
+
return [...rows].sort((a, b) => kindRank(a) - kindRank(b) ||
|
|
70
|
+
verdictRank(a) - verdictRank(b) ||
|
|
71
|
+
sizeRank(b) - sizeRank(a) ||
|
|
72
|
+
a.name.localeCompare(b.name));
|
|
73
|
+
}
|
|
74
|
+
function sizeCell(row) {
|
|
75
|
+
const size = sizeRead(row);
|
|
76
|
+
return size === undefined ? '' : size === null ? '?' : formatBytes(size);
|
|
61
77
|
}
|
|
62
78
|
function repoHeader(sweep) {
|
|
63
79
|
const name = sweep.repo?.root ?? sweep.path;
|
|
64
80
|
if (sweep.repo === null)
|
|
65
81
|
return name;
|
|
82
|
+
const repo = sweep.repo;
|
|
83
|
+
// Each remote judged besides the default one, marked when it was not fetched.
|
|
84
|
+
const others = judgedRemotes(repo)
|
|
85
|
+
.filter((r) => r.name !== repo.remote)
|
|
86
|
+
.map((r) => (repo.fetchedRemotes.includes(r.name) ? r.name : `${r.name} not fetched`));
|
|
66
87
|
const bits = [
|
|
67
|
-
|
|
68
|
-
`default ${
|
|
69
|
-
|
|
70
|
-
isUnfetched(
|
|
88
|
+
repo.slug,
|
|
89
|
+
`default ${repo.mainBranch}`,
|
|
90
|
+
repo.remote ?? 'no remote',
|
|
91
|
+
isUnfetched(repo) ? 'not fetched' : null,
|
|
92
|
+
...others,
|
|
71
93
|
];
|
|
72
94
|
return `${name} (${bits.filter((b) => b !== null).join(', ')})`;
|
|
73
95
|
}
|
|
@@ -104,10 +126,12 @@ export function renderRepo(sweep, opts = {}) {
|
|
|
104
126
|
}
|
|
105
127
|
const nameWidth = Math.min(38, Math.max(...shown.map((r) => ellipsize(r.name, 38).length)));
|
|
106
128
|
const kindWidth = Math.max(...shown.map((r) => r.kind.length));
|
|
129
|
+
const sizeWidth = Math.max(...shown.map((r) => sizeCell(r).length));
|
|
107
130
|
for (const row of shown) {
|
|
108
131
|
const word = verdictWord(row);
|
|
109
132
|
const note = risksNote(row);
|
|
110
|
-
|
|
133
|
+
const size = sizeWidth === 0 ? '' : `${sizeCell(row).padStart(sizeWidth)} `;
|
|
134
|
+
lines.push(` ${pad(row.kind, kindWidth)} ${pad(ellipsize(row.name, 38), nameWidth)} ${size}${wordStyle(style, word)(pad(word, 7))} ${row.why}${note ? `; ${note}` : ''}`);
|
|
111
135
|
// A blocked row has no commands; what to do about each blocker goes there instead.
|
|
112
136
|
const detail = row.verdict === 'blocked' ? row.notes : row.commands;
|
|
113
137
|
for (const line of detail)
|
|
@@ -155,7 +179,12 @@ export function renderTotals(sweep, style = PLAIN) {
|
|
|
155
179
|
const suffix = tail.length > 0 ? ` (${tail.join(', ')})` : '';
|
|
156
180
|
const prune = t.prune > 0 ? `${style.prune(`${t.prune} to prune`)}, ` : '';
|
|
157
181
|
const blocked = t.blocked > 0 ? `, ${style.review(`${t.blocked} blocked`)}` : '';
|
|
158
|
-
|
|
182
|
+
const line = `${style.delete(`${t.delete} to delete`)}, ${prune}${style.review(`${t.review} to review`)}${blocked}, across ${repos}${suffix}.`;
|
|
183
|
+
const freed = sweep.reclaimableBytes;
|
|
184
|
+
if (freed === null)
|
|
185
|
+
return line;
|
|
186
|
+
const unsized = freed.unsized > 0 ? ` (${freed.unsized} not measured)` : '';
|
|
187
|
+
return `${line} Reclaimable: ${style.delete(formatBytes(freed.delete))} to delete, ${style.review(formatBytes(freed.review))} to review${unsized}.`;
|
|
159
188
|
}
|
|
160
189
|
const KIND_LABEL = {
|
|
161
190
|
branch: 'local branches',
|
|
@@ -242,6 +271,7 @@ export function renderJson(sweep, extra = {}) {
|
|
|
242
271
|
scan: sweep.scan,
|
|
243
272
|
duplicates: sweep.duplicates,
|
|
244
273
|
counts: sweep.counts,
|
|
274
|
+
reclaimableBytes: sweep.reclaimableBytes,
|
|
245
275
|
totals: totalOf(sweep.counts),
|
|
246
276
|
}, null, 2) + '\n');
|
|
247
277
|
}
|
|
@@ -263,19 +293,36 @@ export function summarizeRun(r) {
|
|
|
263
293
|
gone: 0,
|
|
264
294
|
pruned: 0,
|
|
265
295
|
dropped: {},
|
|
296
|
+
succeeded: 0,
|
|
266
297
|
failed: 0,
|
|
298
|
+
skipped: 0,
|
|
267
299
|
notRun: 0,
|
|
300
|
+
freedBytes: 0,
|
|
301
|
+
unmeasured: 0,
|
|
268
302
|
};
|
|
269
303
|
for (const d of r.dropped)
|
|
270
304
|
out.dropped[d.reason] = (out.dropped[d.reason] ?? 0) + 1;
|
|
271
305
|
for (const s of r.steps) {
|
|
272
306
|
if (s.result === 'failed')
|
|
273
307
|
out.failed += 1;
|
|
308
|
+
if (s.result === 'skipped')
|
|
309
|
+
out.skipped += 1;
|
|
310
|
+
if (s.result === 'ok')
|
|
311
|
+
out.succeeded += 1;
|
|
312
|
+
if (s.result === 'ok' && s.action === 'remove-worktree') {
|
|
313
|
+
if (typeof s.freedBytes === 'number')
|
|
314
|
+
out.freedBytes += s.freedBytes;
|
|
315
|
+
else
|
|
316
|
+
out.unmeasured += 1;
|
|
317
|
+
}
|
|
274
318
|
if (s.result === 'pending') {
|
|
275
319
|
// Rows not reached are rows a run would have deleted; an unlock or a
|
|
276
320
|
// tip check deletes nothing.
|
|
277
|
-
if (s.action !== 'unlock-worktree' &&
|
|
321
|
+
if (s.action !== 'unlock-worktree' &&
|
|
322
|
+
s.action !== 'verify-remote' &&
|
|
323
|
+
s.action !== 'archive') {
|
|
278
324
|
out.notRun += 1;
|
|
325
|
+
}
|
|
279
326
|
continue;
|
|
280
327
|
}
|
|
281
328
|
if (s.result !== 'ok' && s.result !== 'would-run')
|
|
@@ -299,6 +346,21 @@ export function summarizeRun(r) {
|
|
|
299
346
|
export function rowsActedOn(summary) {
|
|
300
347
|
return KINDS.reduce((n, k) => n + summary.deleted[k], 0) + summary.pruned;
|
|
301
348
|
}
|
|
349
|
+
/**
|
|
350
|
+
* What a run's removed worktrees freed, as `freed: 4.2 GB (2 worktrees)`, or
|
|
351
|
+
* null when it removed none.
|
|
352
|
+
*/
|
|
353
|
+
export function renderFreed(s) {
|
|
354
|
+
const removed = s.deleted.worktree;
|
|
355
|
+
if (removed === 0)
|
|
356
|
+
return null;
|
|
357
|
+
const worktrees = plural(removed, 'worktree', 'worktrees');
|
|
358
|
+
if (s.unmeasured === 0)
|
|
359
|
+
return `freed: ${formatBytes(s.freedBytes)} (${worktrees})`;
|
|
360
|
+
if (s.unmeasured === removed)
|
|
361
|
+
return `freed: not measured (${worktrees})`;
|
|
362
|
+
return `freed: at least ${formatBytes(s.freedBytes)} (${worktrees}, ${s.unmeasured} not measured)`;
|
|
363
|
+
}
|
|
302
364
|
/**
|
|
303
365
|
* How to include a dropped row next time, for the reasons a person can act
|
|
304
366
|
* on. A `not-allowed` detail is `needs <risk>, <risk>`.
|
|
@@ -340,13 +402,17 @@ export function renderRunSummary(r, opts = {}) {
|
|
|
340
402
|
});
|
|
341
403
|
lines.push(`skipped ${total}, not deleted: ${counts.join(', ')}`);
|
|
342
404
|
}
|
|
343
|
-
if (s.failed > 0)
|
|
344
|
-
lines.push(
|
|
405
|
+
if (s.failed > 0) {
|
|
406
|
+
lines.push(s.notRun > 0
|
|
407
|
+
? `stopped at a failed step; ${plural(s.notRun, 'row', 'rows')} not run`
|
|
408
|
+
: `${plural(s.succeeded, 'step', 'steps')} ran, ${s.failed} failed, ${s.skipped} skipped`);
|
|
409
|
+
}
|
|
345
410
|
return lines;
|
|
346
411
|
}
|
|
347
412
|
/** The word a preview shows for a step: what it does to the row. */
|
|
348
413
|
export const STEP_VERB = {
|
|
349
414
|
'verify-remote': 'verify',
|
|
415
|
+
archive: 'archive',
|
|
350
416
|
'unlock-worktree': 'unlock',
|
|
351
417
|
'remove-worktree': 'delete',
|
|
352
418
|
'delete-branch': 'delete',
|
|
@@ -360,7 +426,7 @@ function resultWord(step, style) {
|
|
|
360
426
|
return style.delete(word);
|
|
361
427
|
if (step.result === 'ok')
|
|
362
428
|
return style.keep(word);
|
|
363
|
-
if (step.result === 'pending')
|
|
429
|
+
if (step.result === 'pending' || step.result === 'skipped')
|
|
364
430
|
return style.muted(word);
|
|
365
431
|
return step.action === 'prune-worktrees' ? style.prune(word) : style.delete(word);
|
|
366
432
|
}
|
|
@@ -435,7 +501,8 @@ export function renderReceipt(receipt, receiptPath, style = PLAIN, opts = {}) {
|
|
|
435
501
|
const [counts = '', ...rest] = renderRunSummary(receipt, {
|
|
436
502
|
preview: receipt.status === 'dry-run',
|
|
437
503
|
});
|
|
438
|
-
|
|
504
|
+
const freed = receipt.status === 'dry-run' ? null : renderFreed(summarizeRun(receipt));
|
|
505
|
+
lines.push(style.strong(counts), ...(freed === null ? [] : [freed]), ...rest.map(style.review));
|
|
439
506
|
lines.push(style.muted(receiptPath === null
|
|
440
507
|
? `status: ${receipt.status}`
|
|
441
508
|
: `receipt: ${stripControls(receiptPath)} (${receipt.status})`));
|
package/dist/scope.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a sweep is asked to look at, checked before anything is read: the
|
|
3
|
+
* kinds of row, the remote, the provider, the branch, and whether the targets
|
|
4
|
+
* are remote URLs. A plan records the result.
|
|
5
|
+
*/
|
|
6
|
+
import type { Runners, SweepOptions } from './sweep.ts';
|
|
7
|
+
import { type SweptWith } from './types.ts';
|
|
8
|
+
/**
|
|
9
|
+
* The sweep `targets` and `opts` ask for, as a plan records it. Throws a
|
|
10
|
+
* {@link RepoCleanerError} for options that contradict each other or would
|
|
11
|
+
* have no effect, before anything is read.
|
|
12
|
+
*/
|
|
13
|
+
export declare function sweptWith(targets: readonly string[], opts: Omit<SweepOptions, Exclude<keyof Runners, 'git'> | 'annotate' | 'onProgress' | 'onWarn' | 'cacheDir' | 'sizes' | 'sizeTimeoutMs'>): SweptWith & {
|
|
14
|
+
urls: boolean;
|
|
15
|
+
};
|
package/dist/scope.js
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a sweep is asked to look at, checked before anything is read: the
|
|
3
|
+
* kinds of row, the remote, the provider, the branch, and whether the targets
|
|
4
|
+
* are remote URLs. A plan records the result.
|
|
5
|
+
*/
|
|
6
|
+
import { existsSync } from 'node:fs';
|
|
7
|
+
import { resolve } from 'node:path';
|
|
8
|
+
import { Git } from '@osdlc/typed-git';
|
|
9
|
+
import { resolveBranch } from "./branches.js";
|
|
10
|
+
import { PROVIDER_CHOICES } from "./providers/index.js";
|
|
11
|
+
import { isRemoteUrl } from "./remote-mirror.js";
|
|
12
|
+
import { expandTilde } from "./resolve.js";
|
|
13
|
+
import { KINDS, RepoCleanerError } from "./types.js";
|
|
14
|
+
const LOCAL = ['worktree', 'branch'];
|
|
15
|
+
/**
|
|
16
|
+
* The sweep `targets` and `opts` ask for, as a plan records it. Throws a
|
|
17
|
+
* {@link RepoCleanerError} for options that contradict each other or would
|
|
18
|
+
* have no effect, before anything is read.
|
|
19
|
+
*/
|
|
20
|
+
export function sweptWith(targets, opts) {
|
|
21
|
+
const cwd = opts.cwd ?? process.cwd();
|
|
22
|
+
const conflict = (message) => {
|
|
23
|
+
throw new RepoCleanerError('conflict', message);
|
|
24
|
+
};
|
|
25
|
+
if (targets.some((t) => t.trim() === '')) {
|
|
26
|
+
throw new RepoCleanerError('bad-input', 'a target is empty');
|
|
27
|
+
}
|
|
28
|
+
const only = opts.only === undefined ? undefined : [...new Set(opts.only)];
|
|
29
|
+
const unknown = (only ?? []).filter((k) => !KINDS.includes(k));
|
|
30
|
+
if (unknown.length > 0) {
|
|
31
|
+
throw new RepoCleanerError('bad-input', `unknown kind(s) ${unknown.join(', ')}: expected ${KINDS.join(', ')}`);
|
|
32
|
+
}
|
|
33
|
+
if (only !== undefined && only.length === 0) {
|
|
34
|
+
throw new RepoCleanerError('bad-input', 'only names no kind');
|
|
35
|
+
}
|
|
36
|
+
const asked = opts.remotes === undefined ? [] : [...new Set(opts.remotes)];
|
|
37
|
+
const bad = asked.find((r) => r !== r.trim() || r.startsWith('-'));
|
|
38
|
+
if (bad !== undefined) {
|
|
39
|
+
throw new RepoCleanerError('bad-input', `bad remote name ${JSON.stringify(bad)}`);
|
|
40
|
+
}
|
|
41
|
+
if (opts.provider !== undefined &&
|
|
42
|
+
!PROVIDER_CHOICES.includes(opts.provider)) {
|
|
43
|
+
throw new RepoCleanerError('bad-input', `unknown provider ${JSON.stringify(opts.provider)}`);
|
|
44
|
+
}
|
|
45
|
+
const exists = (t) => existsSync(resolve(cwd, expandTilde(t)));
|
|
46
|
+
const isUrl = targets.map((t) => isRemoteUrl(t, exists));
|
|
47
|
+
const urls = isUrl.some(Boolean);
|
|
48
|
+
// `--remote upstream`, with a space, reads `upstream` as a target: refuse a
|
|
49
|
+
// target that names no directory but does name a remote of the checkout here.
|
|
50
|
+
const loose = targets.filter((t, i) => !isUrl[i] && !exists(t));
|
|
51
|
+
if (loose.length > 0) {
|
|
52
|
+
const listed = new Git(cwd, { runner: opts.git }).try.remotes();
|
|
53
|
+
const slip = listed.ok ? loose.find((t) => listed.value.includes(t)) : undefined;
|
|
54
|
+
if (slip !== undefined)
|
|
55
|
+
conflict(`${slip} is a remote, not a directory: write --remote=${slip}`);
|
|
56
|
+
}
|
|
57
|
+
if (urls && !isUrl.every(Boolean)) {
|
|
58
|
+
conflict('a remote URL target sweeps remote branches only; sweep it apart from checkouts');
|
|
59
|
+
}
|
|
60
|
+
if (urls && only !== undefined && only.some((k) => k !== 'remote')) {
|
|
61
|
+
conflict('a remote URL has only remote branches; drop --local, --worktrees and --branches');
|
|
62
|
+
}
|
|
63
|
+
if (urls && opts.branch !== undefined) {
|
|
64
|
+
conflict('--branch reads one branch of a checkout; it does not take a remote URL');
|
|
65
|
+
}
|
|
66
|
+
if (urls && opts.offline === true) {
|
|
67
|
+
conflict('a remote URL target is fetched to be swept; --offline would have no effect');
|
|
68
|
+
}
|
|
69
|
+
if (opts.branch !== undefined && targets.length > 1) {
|
|
70
|
+
conflict(`--branch sweeps one repository; ${targets.length} targets given`);
|
|
71
|
+
}
|
|
72
|
+
// A remote URL is swept through a clone whose only remote is its origin.
|
|
73
|
+
const remotes = urls
|
|
74
|
+
? ['']
|
|
75
|
+
: asked.length > 0
|
|
76
|
+
? asked
|
|
77
|
+
: (only ?? []).includes('remote')
|
|
78
|
+
? ['']
|
|
79
|
+
: [];
|
|
80
|
+
const remote = remotes.length > 0;
|
|
81
|
+
if (asked.length > 0 && only !== undefined && !only.includes('remote')) {
|
|
82
|
+
conflict(`remotes name remote branches, but only ${only.join(',')} leaves them out`);
|
|
83
|
+
}
|
|
84
|
+
if (opts.fetch === true && opts.offline === true) {
|
|
85
|
+
conflict('--fetch and --offline contradict each other');
|
|
86
|
+
}
|
|
87
|
+
if (opts.offline === true && !remote) {
|
|
88
|
+
conflict('--offline has no effect without remote rows (--remote or --all): nothing is fetched anyway');
|
|
89
|
+
}
|
|
90
|
+
if (opts.provider !== undefined && !remote) {
|
|
91
|
+
conflict('--provider has no effect without remote rows (--remote or --all): pull requests are looked up only for them');
|
|
92
|
+
}
|
|
93
|
+
const kinds = urls
|
|
94
|
+
? ['remote']
|
|
95
|
+
: only !== undefined
|
|
96
|
+
? KINDS.filter((k) => only.includes(k))
|
|
97
|
+
: remote
|
|
98
|
+
? [...LOCAL, 'remote']
|
|
99
|
+
: [...LOCAL];
|
|
100
|
+
// `HEAD` is the branch checked out at the target, resolved here so the
|
|
101
|
+
// options checked before the sweep are the ones the plan records.
|
|
102
|
+
let branch = opts.branch ?? null;
|
|
103
|
+
if (branch === 'HEAD') {
|
|
104
|
+
const at = targets[0] === undefined ? cwd : resolve(cwd, expandTilde(targets[0]));
|
|
105
|
+
try {
|
|
106
|
+
branch = resolveBranch('HEAD', new Git(at, { runner: opts.git }));
|
|
107
|
+
}
|
|
108
|
+
catch (err) {
|
|
109
|
+
throw new RepoCleanerError('conflict', err instanceof Error ? err.message : String(err));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (opts.fetch === true && !kinds.some((k) => k !== 'remote')) {
|
|
113
|
+
conflict('--fetch fetches for local rows; remote rows fetch their remotes anyway');
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
only: kinds,
|
|
117
|
+
remotes,
|
|
118
|
+
fetch: opts.fetch === true,
|
|
119
|
+
offline: opts.offline === true,
|
|
120
|
+
against: opts.against ?? null,
|
|
121
|
+
provider: remote ? (opts.provider ?? 'auto') : 'none',
|
|
122
|
+
branch,
|
|
123
|
+
urls,
|
|
124
|
+
};
|
|
125
|
+
}
|
package/dist/size.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Disk usage of a directory, read with `du` through the command seam. */
|
|
2
|
+
import { type CommandRunner } from '@osdlc/command-seam';
|
|
3
|
+
/** What {@link sizeOf} takes. */
|
|
4
|
+
export interface SizeOfOptions {
|
|
5
|
+
/** Cap on the walk, in ms. Default {@link DEFAULT_TIMEOUT_MS}. */
|
|
6
|
+
timeoutMs?: number | undefined;
|
|
7
|
+
/** Runs `du`. Default spawns the real one. */
|
|
8
|
+
du?: CommandRunner | undefined;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Bytes `path` takes on disk (`du -sk`: allocated blocks, not apparent size;
|
|
12
|
+
* a symlink counts as itself; a relative `path` is resolved against the
|
|
13
|
+
* process's directory). Null when the size could not be read: `du`
|
|
14
|
+
* missing, failed, timed out or printed something else. A `du` that hit an
|
|
15
|
+
* unreadable file still prints a total and exits non-zero; that total is
|
|
16
|
+
* used, a floor of what is on disk.
|
|
17
|
+
*/
|
|
18
|
+
export declare function sizeOf(path: string, opts?: SizeOfOptions): number | null;
|
|
19
|
+
/** `bytes` as a short size: `512 B`, `3.4 MB`. */
|
|
20
|
+
export declare function formatBytes(bytes: number): string;
|
package/dist/size.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** Disk usage of a directory, read with `du` through the command seam. */
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import { spawnRunner } from '@osdlc/command-seam';
|
|
4
|
+
const DEFAULT_TIMEOUT_MS = 60_000;
|
|
5
|
+
/**
|
|
6
|
+
* Bytes `path` takes on disk (`du -sk`: allocated blocks, not apparent size;
|
|
7
|
+
* a symlink counts as itself; a relative `path` is resolved against the
|
|
8
|
+
* process's directory). Null when the size could not be read: `du`
|
|
9
|
+
* missing, failed, timed out or printed something else. A `du` that hit an
|
|
10
|
+
* unreadable file still prints a total and exits non-zero; that total is
|
|
11
|
+
* used, a floor of what is on disk.
|
|
12
|
+
*/
|
|
13
|
+
export function sizeOf(path, opts = {}) {
|
|
14
|
+
const du = opts.du ?? spawnRunner('du');
|
|
15
|
+
const r = du.run(['-sk', '--', resolve(path)], {
|
|
16
|
+
cwd: '/',
|
|
17
|
+
timeoutMs: opts.timeoutMs ?? DEFAULT_TIMEOUT_MS,
|
|
18
|
+
});
|
|
19
|
+
if (r.neverExited === true)
|
|
20
|
+
return null;
|
|
21
|
+
const kib = /^(\d+)\s/.exec(r.stdout);
|
|
22
|
+
return kib === null ? null : Number(kib[1]) * 1024;
|
|
23
|
+
}
|
|
24
|
+
/** `bytes` as a short size: `512 B`, `3.4 MB`. */
|
|
25
|
+
export function formatBytes(bytes) {
|
|
26
|
+
const units = ['B', 'KB', 'MB', 'GB', 'TB'];
|
|
27
|
+
let value = bytes;
|
|
28
|
+
let unit = 0;
|
|
29
|
+
while (value >= 1024 && unit < units.length - 1) {
|
|
30
|
+
value /= 1024;
|
|
31
|
+
unit++;
|
|
32
|
+
}
|
|
33
|
+
return unit === 0 ? `${value} B` : `${value.toFixed(1)} ${units[unit]}`;
|
|
34
|
+
}
|
package/dist/status-line.js
CHANGED
package/dist/step-board.js
CHANGED
|
@@ -24,9 +24,11 @@ function stepRow(step, running, width, style) {
|
|
|
24
24
|
? ['█'.repeat(BAR), '✓', style.keep, (t) => t]
|
|
25
25
|
: step.result === 'failed'
|
|
26
26
|
? ['█'.repeat(BAR), '✗', style.delete, (t) => t]
|
|
27
|
-
:
|
|
28
|
-
? ['
|
|
29
|
-
:
|
|
27
|
+
: step.result === 'skipped'
|
|
28
|
+
? ['░'.repeat(BAR), '-', style.muted, style.muted]
|
|
29
|
+
: running
|
|
30
|
+
? ['█'.repeat(BAR / 2) + '░'.repeat(BAR / 2), '›', style.review, style.strong]
|
|
31
|
+
: ['░'.repeat(BAR), ' ', style.muted, style.muted];
|
|
30
32
|
const head = ` ${bar} ${mark} `;
|
|
31
33
|
if (width <= head.length)
|
|
32
34
|
return color(fitWidth(head, width));
|
|
@@ -71,7 +73,7 @@ export function boardLines(steps, running, size, style = PLAIN) {
|
|
|
71
73
|
lines.push(stepRow(steps[i], i === running, width, style));
|
|
72
74
|
if (notes)
|
|
73
75
|
lines.push(note(` … ${steps.length - last} below`));
|
|
74
|
-
const done = steps.filter((s) => s.result === 'ok' || s.result === 'failed').length;
|
|
76
|
+
const done = steps.filter((s) => s.result === 'ok' || s.result === 'failed' || s.result === 'skipped').length;
|
|
75
77
|
const failed = steps.some((s) => s.result === 'failed');
|
|
76
78
|
lines.push(totalRow(done, steps.length, failed, width, style));
|
|
77
79
|
return lines;
|
package/dist/sweep.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ import type { CommandRunner } from '@osdlc/command-seam';
|
|
|
10
10
|
import type { Annotate } from './hooks.ts';
|
|
11
11
|
import { type ProcessProbe } from './processes.ts';
|
|
12
12
|
import { type ProviderChoice } from './providers/index.ts';
|
|
13
|
-
import { type Kind, type RepoSweep, type Row, type Sweep, type SweepProgress, type
|
|
13
|
+
import { type Kind, type RepoSweep, type Row, type Sweep, type SweepProgress, type WorktreeRow } from './types.ts';
|
|
14
14
|
/** Runners and the process probe: what a test or a host injects. */
|
|
15
15
|
export interface Runners {
|
|
16
16
|
/** Defaults spawn the real `git`, `gh` and `glab`. */
|
|
@@ -23,21 +23,39 @@ export interface Runners {
|
|
|
23
23
|
* `lsof`.
|
|
24
24
|
*/
|
|
25
25
|
probe?: ProcessProbe | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Runs `du`: for `sizes`, and for each worktree `run` removes. Default
|
|
28
|
+
* spawns the real one.
|
|
29
|
+
*/
|
|
30
|
+
du?: CommandRunner | undefined;
|
|
26
31
|
}
|
|
27
32
|
export interface SweepOptions extends Runners {
|
|
28
|
-
/**
|
|
33
|
+
/**
|
|
34
|
+
* Only these kinds of row. Default: `worktree` and `branch`, and `remote`
|
|
35
|
+
* with `remotes`. Naming `remote` alone judges the default remote's branches.
|
|
36
|
+
*/
|
|
29
37
|
only?: readonly Kind[] | undefined;
|
|
30
|
-
/**
|
|
31
|
-
|
|
32
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Also judge these remotes' branches: a name, `''` for the default remote,
|
|
40
|
+
* `*` for every remote. Each is fetched first, and its pull requests looked
|
|
41
|
+
* up.
|
|
42
|
+
*/
|
|
43
|
+
remotes?: readonly string[] | undefined;
|
|
44
|
+
/** Fetch the default remote before judging local rows. Remote rows fetch their remotes anyway. */
|
|
45
|
+
fetch?: boolean | undefined;
|
|
46
|
+
/** With `remotes`: do not fetch; judge against the remote-tracking refs on disk. */
|
|
33
47
|
offline?: boolean | undefined;
|
|
34
|
-
/**
|
|
48
|
+
/**
|
|
49
|
+
* Judge every row against this remote's default branch, as a fork against
|
|
50
|
+
* its parent. Without it, a remote's branches are judged against its own
|
|
51
|
+
* default branch, and local rows against the default remote's.
|
|
52
|
+
*/
|
|
35
53
|
against?: string | undefined;
|
|
36
|
-
/** With `
|
|
54
|
+
/** With `remotes`: where pull requests come from. Default `auto`, by each remote's host. */
|
|
37
55
|
provider?: ProviderChoice | undefined;
|
|
38
56
|
/**
|
|
39
|
-
* One branch only: its worktree, its local branch, and its remote
|
|
40
|
-
* with `
|
|
57
|
+
* One branch only: its worktree, its local branch, and its remote branches
|
|
58
|
+
* with `remotes`. `HEAD` is the branch checked out at the target. Takes at
|
|
41
59
|
* most one target, no remote URL, and never the default branch.
|
|
42
60
|
*/
|
|
43
61
|
branch?: string | undefined;
|
|
@@ -49,6 +67,14 @@ export interface SweepOptions extends Runners {
|
|
|
49
67
|
cwd?: string | undefined;
|
|
50
68
|
/** Where remote URL targets' clones are kept. Defaults to {@link defaultCacheDir}. */
|
|
51
69
|
cacheDir?: string | undefined;
|
|
70
|
+
/**
|
|
71
|
+
* Read each on-disk worktree's size into `evidence.sizeBytes`, rank rows
|
|
72
|
+
* largest first, and total what the `delete` and `review` rows free. Off by
|
|
73
|
+
* default: it reads every file under every worktree. Not part of a plan.
|
|
74
|
+
*/
|
|
75
|
+
sizes?: boolean | undefined;
|
|
76
|
+
/** How long one worktree's size may take, in ms. Defaults to {@link sizeOf}'s cap. */
|
|
77
|
+
sizeTimeoutMs?: number | undefined;
|
|
52
78
|
/** A host's re-ranking of each repository's rows. */
|
|
53
79
|
annotate?: Annotate | undefined;
|
|
54
80
|
/** Told before each step, and before each row of a step that walks many. For a status line. */
|
|
@@ -56,14 +82,6 @@ export interface SweepOptions extends Runners {
|
|
|
56
82
|
/** Told, mid-walk, that a target directory is enormous. Defaults to stderr. */
|
|
57
83
|
onWarn?: ((message: string) => void) | undefined;
|
|
58
84
|
}
|
|
59
|
-
/**
|
|
60
|
-
* The sweep `targets` and `opts` ask for, as a plan records it. Throws a
|
|
61
|
-
* {@link RepoCleanerError} for options that contradict each other or would
|
|
62
|
-
* have no effect, before anything is read.
|
|
63
|
-
*/
|
|
64
|
-
export declare function sweptWith(targets: readonly string[], opts: Omit<SweepOptions, Exclude<keyof Runners, 'git'> | 'annotate' | 'onProgress' | 'onWarn' | 'cacheDir'>): SweptWith & {
|
|
65
|
-
urls: boolean;
|
|
66
|
-
};
|
|
67
85
|
/**
|
|
68
86
|
* Sweep `targets`: checkouts, directories to search for checkouts, or remote
|
|
69
87
|
* URLs (swept through a clone kept in `cacheDir`, remote branches only). No
|
|
@@ -80,9 +98,18 @@ export declare function sweep(targets: readonly string[], opts?: SweepOptions):
|
|
|
80
98
|
/** What {@link sweepRepo} takes: a sweep's options, already resolved. */
|
|
81
99
|
interface RepoSweepOptions extends Runners {
|
|
82
100
|
only: readonly Kind[];
|
|
101
|
+
/** As {@link SweepOptions.remotes}; a plan's re-check passes the names it resolved. */
|
|
102
|
+
remotes: readonly string[];
|
|
83
103
|
against?: string | undefined;
|
|
84
104
|
provider: ProviderChoice;
|
|
85
|
-
|
|
105
|
+
sizes?: boolean | undefined;
|
|
106
|
+
sizeTimeoutMs?: number | undefined;
|
|
107
|
+
/**
|
|
108
|
+
* What to fetch first. `scope`: every remote whose branches are judged, and
|
|
109
|
+
* the `against` remote with them. `local`: those, and the default remote.
|
|
110
|
+
* A list: exactly those remotes, as a plan's re-check does. `[]`: nothing.
|
|
111
|
+
*/
|
|
112
|
+
fetch: 'scope' | 'local' | readonly string[];
|
|
86
113
|
/**
|
|
87
114
|
* Read remote tips with `ls-remote` even without a fetch: `clean`'s
|
|
88
115
|
* re-check, which must not delete on the strength of a stale tracking ref.
|