dustclaw 0.4.1 → 0.4.2
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 +16 -1
- package/data/config.json +5 -0
- package/dist/commands/overview.js +2 -1
- package/dist/commands/scan.js +2 -1
- package/dist/commands/wasteland.js +3 -2
- package/dist/utils/config.d.ts +5 -0
- package/dist/utils/config.js +5 -0
- package/dist/utils/format.d.ts +1 -0
- package/dist/utils/format.js +3 -0
- package/dist/utils/progress.d.ts +40 -0
- package/dist/utils/progress.js +87 -0
- package/dist/utils/scan.d.ts +3 -1
- package/dist/utils/scan.js +42 -40
- package/dist/utils/wasteland.d.ts +4 -3
- package/dist/utils/wasteland.js +45 -37
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -200,6 +200,16 @@ Items marked `safe: false` (for example Docker Desktop, Android Emulators, pnpm
|
|
|
200
200
|
}
|
|
201
201
|
```
|
|
202
202
|
|
|
203
|
+
### Progress
|
|
204
|
+
|
|
205
|
+
`overview`, `scan` and `wasteland` show a progress line while they work: a bar, how many top-level items are done, the files and size counted so far, and the item being measured. The bar follows items, not bytes, so inside one huge folder the bar waits while the file count keeps moving.
|
|
206
|
+
|
|
207
|
+
```text
|
|
208
|
+
Scanning [█████░░░░░░░░░░░░░░░] 7/27 (25%) 35,396 files 2.0 GB asiakas
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
The line is drawn on stderr and only when stderr is a terminal. Piped or redirected output, `--json` and CI runs get nothing extra. The line is cleared before the results are printed.
|
|
212
|
+
|
|
203
213
|
## Flags
|
|
204
214
|
|
|
205
215
|
| Flag | Available on | What it does |
|
|
@@ -237,6 +247,11 @@ Defaults ship in `data/config.json`. Dustclaw reads `~/.dustclaw.json` for user
|
|
|
237
247
|
| `minCacheSizeMb` | `50` | Smallest `~/Library/Caches` entry listed by `wasteland` (macOS) |
|
|
238
248
|
| `nodeModulesMaxDepth` | `5` | How deep `wasteland --node-modules` searches |
|
|
239
249
|
| `staleThresholdHours` | `24` | `clean` warns when the last scan is older than this |
|
|
250
|
+
| `progressIntervalMs` | `250` | Minimum time between progress line updates |
|
|
251
|
+
| `progressBarWidth` | `20` | Width of the progress bar in characters |
|
|
252
|
+
| `progressFillChar` | `█` | Character for the completed part of the bar |
|
|
253
|
+
| `progressEmptyChar` | `░` | Character for the remaining part of the bar |
|
|
254
|
+
| `progressFallbackColumns` | `80` | Line width used when the terminal width is unknown |
|
|
240
255
|
| `cachesPath` | `Library/Caches` | Cache folder under your home directory, broken down per app (macOS) |
|
|
241
256
|
| `cacheSkipList` | Homebrew, CocoaPods, ... | Caches skipped in the breakdown because a known target already covers them |
|
|
242
257
|
| `opaqueDirectories` | `node_modules`, `.git` | Folders measured as one item instead of being opened |
|
|
@@ -294,6 +309,7 @@ src/
|
|
|
294
309
|
config.ts # loads and merges config.json with ~/.dustclaw.json
|
|
295
310
|
disk.ts # disk info via df (macOS, Linux) and statfs (Windows)
|
|
296
311
|
format.ts # table rendering and size formatting
|
|
312
|
+
progress.ts # progress line on stderr for slow scans
|
|
297
313
|
scan.ts # recursive directory walker and dirSize
|
|
298
314
|
state.ts # persists last wasteland scan to ~/.dustclaw/last-scan.json
|
|
299
315
|
wasteland.ts # finds known waste targets and Library/Caches entries
|
|
@@ -340,7 +356,6 @@ See [CHANGELOG.md](./CHANGELOG.md) for release notes.
|
|
|
340
356
|
|
|
341
357
|
## Roadmap
|
|
342
358
|
|
|
343
|
-
- **spinner**: progress indicator during slow scans
|
|
344
359
|
- **watch**: track disk usage over time, spot trends before you run out of space
|
|
345
360
|
- **duplicates**: find duplicate large files by hash
|
|
346
361
|
|
package/data/config.json
CHANGED
|
@@ -8,6 +8,11 @@
|
|
|
8
8
|
"overviewTopCount": 10,
|
|
9
9
|
"scanTopCount": 20,
|
|
10
10
|
"blockSize": 512,
|
|
11
|
+
"progressIntervalMs": 250,
|
|
12
|
+
"progressBarWidth": 20,
|
|
13
|
+
"progressFillChar": "█",
|
|
14
|
+
"progressEmptyChar": "░",
|
|
15
|
+
"progressFallbackColumns": 80,
|
|
11
16
|
"cachesPath": "Library/Caches",
|
|
12
17
|
"cacheSkipList": [
|
|
13
18
|
"Homebrew",
|
|
@@ -3,13 +3,14 @@ import chalk from "chalk";
|
|
|
3
3
|
import { resolveConfig } from "../utils/config.js";
|
|
4
4
|
import { getDiskInfo, usedRatio } from "../utils/disk.js";
|
|
5
5
|
import { boxTable, colorSize, formatPercent, formatSize } from "../utils/format.js";
|
|
6
|
+
import { withProgress } from "../utils/progress.js";
|
|
6
7
|
import { scanDir } from "../utils/scan.js";
|
|
7
8
|
export function overview(opts) {
|
|
8
9
|
const { overviewDepth } = resolveConfig();
|
|
9
10
|
const count = opts.top;
|
|
10
11
|
const targetPath = resolve(opts.path);
|
|
11
12
|
const disks = getDiskInfo();
|
|
12
|
-
const entries = scanDir(targetPath, { depth: overviewDepth });
|
|
13
|
+
const entries = withProgress("Scanning", (progress) => scanDir(targetPath, { depth: overviewDepth, progress }));
|
|
13
14
|
const topEntries = entries.sort((a, b) => b.size - a.size).slice(0, count);
|
|
14
15
|
if (opts.json) {
|
|
15
16
|
console.log(JSON.stringify({
|
package/dist/commands/scan.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { resolve } from "node:path";
|
|
2
2
|
import chalk from "chalk";
|
|
3
3
|
import { boxTable, colorSize } from "../utils/format.js";
|
|
4
|
+
import { withProgress } from "../utils/progress.js";
|
|
4
5
|
import { scanDir } from "../utils/scan.js";
|
|
5
6
|
export function scan(path, opts) {
|
|
6
7
|
const targetPath = resolve(path ?? ".");
|
|
@@ -11,7 +12,7 @@ export function scan(path, opts) {
|
|
|
11
12
|
dirsOnly: opts.dirsOnly,
|
|
12
13
|
olderThan: opts.olderThan,
|
|
13
14
|
};
|
|
14
|
-
const entries = scanDir(targetPath, scanOpts);
|
|
15
|
+
const entries = withProgress("Scanning", (progress) => scanDir(targetPath, { ...scanOpts, progress }));
|
|
15
16
|
const sorted = entries.sort((a, b) => b.size - a.size).slice(0, count);
|
|
16
17
|
if (opts.json) {
|
|
17
18
|
console.log(JSON.stringify(sorted.map((e) => ({
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { resolve } from "node:path";
|
|
2
2
|
import chalk from "chalk";
|
|
3
3
|
import { boxTable, colorSize, formatSize } from "../utils/format.js";
|
|
4
|
+
import { withProgress } from "../utils/progress.js";
|
|
4
5
|
import { saveLastScan } from "../utils/state.js";
|
|
5
6
|
import { findNodeModules, findWaste } from "../utils/wasteland.js";
|
|
6
7
|
export async function wasteland(opts) {
|
|
7
|
-
const waste = findWaste();
|
|
8
|
+
const waste = withProgress("Scanning", (progress) => findWaste(progress));
|
|
8
9
|
let nmEntries = [];
|
|
9
10
|
if (opts.nodeModules) {
|
|
10
11
|
const searchPath = resolve(opts.nodeModules);
|
|
11
|
-
nmEntries = findNodeModules(searchPath);
|
|
12
|
+
nmEntries = withProgress("Searching node_modules", (progress) => findNodeModules(searchPath, undefined, progress));
|
|
12
13
|
}
|
|
13
14
|
const allEntries = [...waste, ...nmEntries];
|
|
14
15
|
const totalSize = allEntries.reduce((sum, e) => sum + e.size, 0);
|
package/dist/utils/config.d.ts
CHANGED
|
@@ -19,6 +19,11 @@ export interface DustclawConfig {
|
|
|
19
19
|
overviewTopCount: number;
|
|
20
20
|
scanTopCount: number;
|
|
21
21
|
blockSize: number;
|
|
22
|
+
progressIntervalMs: number;
|
|
23
|
+
progressBarWidth: number;
|
|
24
|
+
progressFillChar: string;
|
|
25
|
+
progressEmptyChar: string;
|
|
26
|
+
progressFallbackColumns: number;
|
|
22
27
|
cachesPath: string;
|
|
23
28
|
cacheSkipList: string[];
|
|
24
29
|
opaqueDirectories: string[];
|
package/dist/utils/config.js
CHANGED
|
@@ -54,6 +54,11 @@ function buildConfig() {
|
|
|
54
54
|
overviewTopCount: user.overviewTopCount ?? defaults.overviewTopCount,
|
|
55
55
|
scanTopCount: user.scanTopCount ?? defaults.scanTopCount,
|
|
56
56
|
blockSize: user.blockSize ?? defaults.blockSize,
|
|
57
|
+
progressIntervalMs: user.progressIntervalMs ?? defaults.progressIntervalMs,
|
|
58
|
+
progressBarWidth: user.progressBarWidth ?? defaults.progressBarWidth,
|
|
59
|
+
progressFillChar: user.progressFillChar ?? defaults.progressFillChar,
|
|
60
|
+
progressEmptyChar: user.progressEmptyChar ?? defaults.progressEmptyChar,
|
|
61
|
+
progressFallbackColumns: user.progressFallbackColumns ?? defaults.progressFallbackColumns,
|
|
57
62
|
cachesPath: user.cachesPath ?? defaults.cachesPath,
|
|
58
63
|
cacheSkipList: user.cacheSkipList ?? defaults.cacheSkipList,
|
|
59
64
|
opaqueDirectories: user.opaqueDirectories ?? defaults.opaqueDirectories,
|
package/dist/utils/format.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export declare function formatSize(bytes: number): string;
|
|
2
|
+
export declare function formatCount(count: number): string;
|
|
2
3
|
export declare function colorSize(bytes: number): string;
|
|
3
4
|
export declare function formatPercent(ratio: number): string;
|
|
4
5
|
export declare function boxTable(headers: string[], rows: string[][]): string;
|
package/dist/utils/format.js
CHANGED
|
@@ -10,6 +10,9 @@ export function formatSize(bytes) {
|
|
|
10
10
|
return `${(bytes / 1024 ** 3).toFixed(1)} GB`;
|
|
11
11
|
return `${(bytes / 1024 ** 4).toFixed(1)} TB`;
|
|
12
12
|
}
|
|
13
|
+
export function formatCount(count) {
|
|
14
|
+
return count.toLocaleString("en-US");
|
|
15
|
+
}
|
|
13
16
|
export function colorSize(bytes) {
|
|
14
17
|
const text = formatSize(bytes);
|
|
15
18
|
if (bytes >= 1024 ** 3)
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export declare const CLEAR_LINE = "\r\u001B[K";
|
|
2
|
+
export interface ProgressSink {
|
|
3
|
+
addItems(count: number): void;
|
|
4
|
+
startItem(label: string): void;
|
|
5
|
+
addFile(bytes: number): void;
|
|
6
|
+
finishItem(): void;
|
|
7
|
+
}
|
|
8
|
+
export interface ProgressStream {
|
|
9
|
+
isTTY?: boolean;
|
|
10
|
+
columns?: number;
|
|
11
|
+
write(text: string): unknown;
|
|
12
|
+
}
|
|
13
|
+
export interface ProgressOptions {
|
|
14
|
+
stream?: ProgressStream;
|
|
15
|
+
now?: () => number;
|
|
16
|
+
}
|
|
17
|
+
export declare class Progress implements ProgressSink {
|
|
18
|
+
readonly enabled: boolean;
|
|
19
|
+
private readonly title;
|
|
20
|
+
private readonly stream;
|
|
21
|
+
private readonly now;
|
|
22
|
+
private readonly config;
|
|
23
|
+
private total;
|
|
24
|
+
private done;
|
|
25
|
+
private files;
|
|
26
|
+
private bytes;
|
|
27
|
+
private label;
|
|
28
|
+
private lastDraw;
|
|
29
|
+
private drawn;
|
|
30
|
+
constructor(title: string, { stream, now }?: ProgressOptions);
|
|
31
|
+
addItems(count: number): void;
|
|
32
|
+
startItem(label: string): void;
|
|
33
|
+
addFile(bytes: number): void;
|
|
34
|
+
finishItem(): void;
|
|
35
|
+
stop(): void;
|
|
36
|
+
private refresh;
|
|
37
|
+
private draw;
|
|
38
|
+
private bar;
|
|
39
|
+
}
|
|
40
|
+
export declare function withProgress<T>(title: string, fn: (progress: Progress) => T, options?: ProgressOptions): T;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { resolveConfig } from "./config.js";
|
|
2
|
+
import { formatCount, formatSize } from "./format.js";
|
|
3
|
+
export const CLEAR_LINE = "\r\x1b[K";
|
|
4
|
+
export class Progress {
|
|
5
|
+
enabled;
|
|
6
|
+
title;
|
|
7
|
+
stream;
|
|
8
|
+
now;
|
|
9
|
+
config;
|
|
10
|
+
total = 0;
|
|
11
|
+
done = 0;
|
|
12
|
+
files = 0;
|
|
13
|
+
bytes = 0;
|
|
14
|
+
label = "";
|
|
15
|
+
lastDraw = Number.NEGATIVE_INFINITY;
|
|
16
|
+
drawn = false;
|
|
17
|
+
constructor(title, { stream = process.stderr, now = () => performance.now() } = {}) {
|
|
18
|
+
this.title = title;
|
|
19
|
+
this.stream = stream;
|
|
20
|
+
this.now = now;
|
|
21
|
+
this.config = resolveConfig();
|
|
22
|
+
this.enabled = stream.isTTY === true;
|
|
23
|
+
}
|
|
24
|
+
addItems(count) {
|
|
25
|
+
this.total += count;
|
|
26
|
+
}
|
|
27
|
+
startItem(label) {
|
|
28
|
+
if (!this.enabled)
|
|
29
|
+
return;
|
|
30
|
+
this.label = label;
|
|
31
|
+
this.refresh();
|
|
32
|
+
}
|
|
33
|
+
addFile(bytes) {
|
|
34
|
+
if (!this.enabled)
|
|
35
|
+
return;
|
|
36
|
+
this.files++;
|
|
37
|
+
this.bytes += bytes;
|
|
38
|
+
this.refresh();
|
|
39
|
+
}
|
|
40
|
+
finishItem() {
|
|
41
|
+
if (!this.enabled)
|
|
42
|
+
return;
|
|
43
|
+
this.done++;
|
|
44
|
+
this.refresh();
|
|
45
|
+
}
|
|
46
|
+
stop() {
|
|
47
|
+
if (!this.drawn)
|
|
48
|
+
return;
|
|
49
|
+
this.stream.write(CLEAR_LINE);
|
|
50
|
+
this.drawn = false;
|
|
51
|
+
}
|
|
52
|
+
refresh() {
|
|
53
|
+
const time = this.now();
|
|
54
|
+
if (time - this.lastDraw < this.config.progressIntervalMs)
|
|
55
|
+
return;
|
|
56
|
+
this.lastDraw = time;
|
|
57
|
+
this.draw();
|
|
58
|
+
}
|
|
59
|
+
draw() {
|
|
60
|
+
const width = (this.stream.columns || this.config.progressFallbackColumns) - 1;
|
|
61
|
+
const lead = this.total > 0 ? `${this.title} ${this.bar()}` : this.title;
|
|
62
|
+
const head = ` ${lead} ${formatCount(this.files)} files ${formatSize(this.bytes)}`;
|
|
63
|
+
const room = width - head.length - 2;
|
|
64
|
+
const tail = room > 1 ? ` ${fitTail(this.label, room)}` : "";
|
|
65
|
+
this.stream.write(`${CLEAR_LINE}${(head + tail).slice(0, width)}`);
|
|
66
|
+
this.drawn = true;
|
|
67
|
+
}
|
|
68
|
+
bar() {
|
|
69
|
+
const { progressBarWidth, progressFillChar, progressEmptyChar } = this.config;
|
|
70
|
+
const ratio = Math.min(this.done / this.total, 1);
|
|
71
|
+
const filled = Math.floor(ratio * progressBarWidth);
|
|
72
|
+
const cells = progressFillChar.repeat(filled) + progressEmptyChar.repeat(progressBarWidth - filled);
|
|
73
|
+
return `[${cells}] ${this.done}/${this.total} (${Math.floor(ratio * 100)}%)`;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function fitTail(label, room) {
|
|
77
|
+
return label.length <= room ? label : `…${label.slice(label.length - (room - 1))}`;
|
|
78
|
+
}
|
|
79
|
+
export function withProgress(title, fn, options = {}) {
|
|
80
|
+
const progress = new Progress(title, options);
|
|
81
|
+
try {
|
|
82
|
+
return fn(progress);
|
|
83
|
+
}
|
|
84
|
+
finally {
|
|
85
|
+
progress.stop();
|
|
86
|
+
}
|
|
87
|
+
}
|
package/dist/utils/scan.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ProgressSink } from "./progress.js";
|
|
1
2
|
export interface ScanEntry {
|
|
2
3
|
path: string;
|
|
3
4
|
size: number;
|
|
@@ -9,7 +10,8 @@ export interface ScanOptions {
|
|
|
9
10
|
olderThan?: Date;
|
|
10
11
|
filesOnly?: boolean;
|
|
11
12
|
dirsOnly?: boolean;
|
|
13
|
+
progress?: ProgressSink;
|
|
12
14
|
}
|
|
13
15
|
export declare function scanDir(root: string, opts?: ScanOptions, currentDepth?: number): ScanEntry[];
|
|
14
|
-
export declare function dirSize(dirPath: string): number;
|
|
16
|
+
export declare function dirSize(dirPath: string, progress?: ProgressSink): number;
|
|
15
17
|
export declare function parseAge(age: string): Date;
|
package/dist/utils/scan.js
CHANGED
|
@@ -3,8 +3,10 @@ import { join } from "node:path";
|
|
|
3
3
|
import { resolveConfig } from "./config.js";
|
|
4
4
|
export function scanDir(root, opts = {}, currentDepth = 0) {
|
|
5
5
|
const { scanDepth, blockSize, opaqueDirectories } = resolveConfig();
|
|
6
|
+
const { progress } = opts;
|
|
6
7
|
const maxDepth = opts.depth ?? scanDepth;
|
|
7
8
|
const opaqueSet = new Set(opaqueDirectories);
|
|
9
|
+
const isRoot = currentDepth === 0;
|
|
8
10
|
const entries = [];
|
|
9
11
|
let items;
|
|
10
12
|
try {
|
|
@@ -13,61 +15,59 @@ export function scanDir(root, opts = {}, currentDepth = 0) {
|
|
|
13
15
|
catch {
|
|
14
16
|
return entries;
|
|
15
17
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
if (isRoot) {
|
|
19
|
+
items = items.filter((name) => !name.startsWith("."));
|
|
20
|
+
progress?.addItems(items.length);
|
|
21
|
+
}
|
|
22
|
+
const isOldEnough = (mtime) => !opts.olderThan || mtime < opts.olderThan;
|
|
23
|
+
const visit = (name) => {
|
|
19
24
|
const fullPath = join(root, name);
|
|
20
25
|
let stat;
|
|
21
26
|
try {
|
|
22
27
|
stat = statSync(fullPath);
|
|
23
28
|
}
|
|
24
29
|
catch {
|
|
25
|
-
|
|
30
|
+
return;
|
|
26
31
|
}
|
|
27
32
|
if (stat.isDirectory()) {
|
|
28
|
-
if (opaqueSet.has(name)) {
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
entries.push({ path: fullPath, size, isDirectory: true, mtime: stat.mtime });
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
continue;
|
|
36
|
-
}
|
|
37
|
-
if (currentDepth < maxDepth) {
|
|
38
|
-
const childEntries = scanDir(fullPath, opts, currentDepth + 1);
|
|
39
|
-
entries.push(...childEntries);
|
|
33
|
+
if (!opaqueSet.has(name) && currentDepth < maxDepth) {
|
|
34
|
+
for (const child of scanDir(fullPath, opts, currentDepth + 1))
|
|
35
|
+
entries.push(child);
|
|
36
|
+
return;
|
|
40
37
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
else if (stat.isFile()) {
|
|
51
|
-
if (!opts.dirsOnly) {
|
|
52
|
-
if (!opts.olderThan || stat.mtime < opts.olderThan) {
|
|
53
|
-
entries.push({
|
|
54
|
-
path: fullPath,
|
|
55
|
-
size: stat.blocks * blockSize,
|
|
56
|
-
isDirectory: false,
|
|
57
|
-
mtime: stat.mtime,
|
|
58
|
-
});
|
|
59
|
-
}
|
|
38
|
+
if (!opts.filesOnly && isOldEnough(stat.mtime)) {
|
|
39
|
+
entries.push({
|
|
40
|
+
path: fullPath,
|
|
41
|
+
size: dirSize(fullPath, progress),
|
|
42
|
+
isDirectory: true,
|
|
43
|
+
mtime: stat.mtime,
|
|
44
|
+
});
|
|
60
45
|
}
|
|
46
|
+
return;
|
|
61
47
|
}
|
|
48
|
+
if (!stat.isFile())
|
|
49
|
+
return;
|
|
50
|
+
const size = stat.blocks * blockSize;
|
|
51
|
+
progress?.addFile(size);
|
|
52
|
+
if (opts.dirsOnly || !isOldEnough(stat.mtime))
|
|
53
|
+
return;
|
|
54
|
+
entries.push({ path: fullPath, size, isDirectory: false, mtime: stat.mtime });
|
|
55
|
+
};
|
|
56
|
+
for (const name of items) {
|
|
57
|
+
if (isRoot)
|
|
58
|
+
progress?.startItem(name);
|
|
59
|
+
visit(name);
|
|
60
|
+
if (isRoot)
|
|
61
|
+
progress?.finishItem();
|
|
62
62
|
}
|
|
63
63
|
return entries;
|
|
64
64
|
}
|
|
65
|
-
export function dirSize(dirPath) {
|
|
66
|
-
return sumDir(dirPath, resolveConfig().blockSize);
|
|
65
|
+
export function dirSize(dirPath, progress) {
|
|
66
|
+
return sumDir(dirPath, resolveConfig().blockSize, progress);
|
|
67
67
|
}
|
|
68
68
|
// lstat, not stat: symlinks are not followed, matching du. Following them
|
|
69
69
|
// double-counts linked data and loops forever on a link to a parent folder.
|
|
70
|
-
function sumDir(dirPath, blockSize) {
|
|
70
|
+
function sumDir(dirPath, blockSize, progress) {
|
|
71
71
|
let total = 0;
|
|
72
72
|
let items;
|
|
73
73
|
try {
|
|
@@ -81,10 +81,12 @@ function sumDir(dirPath, blockSize) {
|
|
|
81
81
|
try {
|
|
82
82
|
const stat = lstatSync(fullPath);
|
|
83
83
|
if (stat.isFile()) {
|
|
84
|
-
|
|
84
|
+
const size = stat.blocks * blockSize;
|
|
85
|
+
total += size;
|
|
86
|
+
progress?.addFile(size);
|
|
85
87
|
}
|
|
86
88
|
else if (stat.isDirectory()) {
|
|
87
|
-
total += sumDir(fullPath, blockSize);
|
|
89
|
+
total += sumDir(fullPath, blockSize, progress);
|
|
88
90
|
}
|
|
89
91
|
}
|
|
90
92
|
catch { }
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ProgressSink } from "./progress.js";
|
|
1
2
|
export interface WasteEntry {
|
|
2
3
|
name: string;
|
|
3
4
|
path: string;
|
|
@@ -5,6 +6,6 @@ export interface WasteEntry {
|
|
|
5
6
|
description: string;
|
|
6
7
|
safe: boolean;
|
|
7
8
|
}
|
|
8
|
-
export declare function findCaches(): WasteEntry[];
|
|
9
|
-
export declare function findWaste(): WasteEntry[];
|
|
10
|
-
export declare function findNodeModules(root: string, maxDepth?: number): WasteEntry[];
|
|
9
|
+
export declare function findCaches(progress?: ProgressSink): WasteEntry[];
|
|
10
|
+
export declare function findWaste(progress?: ProgressSink): WasteEntry[];
|
|
11
|
+
export declare function findNodeModules(root: string, maxDepth?: number, progress?: ProgressSink): WasteEntry[];
|
package/dist/utils/wasteland.js
CHANGED
|
@@ -7,14 +7,32 @@ const home = homedir();
|
|
|
7
7
|
function friendlyName(dirName, cacheNames) {
|
|
8
8
|
return cacheNames[dirName] ?? dirName;
|
|
9
9
|
}
|
|
10
|
-
|
|
11
|
-
const { minCacheSize
|
|
10
|
+
function cacheEntry(cachesDir, name, progress) {
|
|
11
|
+
const { minCacheSize } = resolveConfig();
|
|
12
|
+
const fullPath = join(cachesDir, name);
|
|
13
|
+
try {
|
|
14
|
+
if (!statSync(fullPath).isDirectory())
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
const size = dirSize(fullPath, progress);
|
|
21
|
+
if (size < minCacheSize)
|
|
22
|
+
return undefined;
|
|
23
|
+
return {
|
|
24
|
+
name: `Cache: ${friendlyName(name, resolveCacheNames())}`,
|
|
25
|
+
path: fullPath,
|
|
26
|
+
size,
|
|
27
|
+
description: `${name} application cache`,
|
|
28
|
+
safe: true,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export function findCaches(progress) {
|
|
32
|
+
const { cachesPath, cacheSkipList } = resolveConfig();
|
|
12
33
|
const cachesDir = join(home, cachesPath);
|
|
13
34
|
if (!existsSync(cachesDir))
|
|
14
35
|
return [];
|
|
15
|
-
const skip = new Set(cacheSkipList);
|
|
16
|
-
const cacheNames = resolveCacheNames();
|
|
17
|
-
const results = [];
|
|
18
36
|
let items;
|
|
19
37
|
try {
|
|
20
38
|
items = readdirSync(cachesDir);
|
|
@@ -22,38 +40,26 @@ export function findCaches() {
|
|
|
22
40
|
catch {
|
|
23
41
|
return [];
|
|
24
42
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
continue;
|
|
36
|
-
}
|
|
37
|
-
const size = dirSize(fullPath);
|
|
38
|
-
if (size >= minCacheSize) {
|
|
39
|
-
results.push({
|
|
40
|
-
name: `Cache: ${friendlyName(name, cacheNames)}`,
|
|
41
|
-
path: fullPath,
|
|
42
|
-
size,
|
|
43
|
-
description: `${name} application cache`,
|
|
44
|
-
safe: true,
|
|
45
|
-
});
|
|
46
|
-
}
|
|
43
|
+
const skip = new Set(cacheSkipList);
|
|
44
|
+
const candidates = items.filter((name) => !skip.has(name));
|
|
45
|
+
progress?.addItems(candidates.length);
|
|
46
|
+
const results = [];
|
|
47
|
+
for (const name of candidates) {
|
|
48
|
+
progress?.startItem(name);
|
|
49
|
+
const entry = cacheEntry(cachesDir, name, progress);
|
|
50
|
+
if (entry)
|
|
51
|
+
results.push(entry);
|
|
52
|
+
progress?.finishItem();
|
|
47
53
|
}
|
|
48
54
|
return results.sort((a, b) => b.size - a.size);
|
|
49
55
|
}
|
|
50
|
-
export function findWaste() {
|
|
56
|
+
export function findWaste(progress) {
|
|
51
57
|
const targets = resolveTargets();
|
|
52
58
|
const results = [];
|
|
59
|
+
progress?.addItems(targets.length);
|
|
53
60
|
for (const target of targets) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const size = dirSize(target.path);
|
|
61
|
+
progress?.startItem(target.name);
|
|
62
|
+
const size = existsSync(target.path) ? dirSize(target.path, progress) : 0;
|
|
57
63
|
if (size > 0) {
|
|
58
64
|
results.push({
|
|
59
65
|
name: target.name,
|
|
@@ -63,17 +69,18 @@ export function findWaste() {
|
|
|
63
69
|
safe: target.safe,
|
|
64
70
|
});
|
|
65
71
|
}
|
|
72
|
+
progress?.finishItem();
|
|
66
73
|
}
|
|
67
|
-
results.push(...findCaches());
|
|
74
|
+
results.push(...findCaches(progress));
|
|
68
75
|
return results.sort((a, b) => b.size - a.size);
|
|
69
76
|
}
|
|
70
|
-
export function findNodeModules(root, maxDepth) {
|
|
77
|
+
export function findNodeModules(root, maxDepth, progress) {
|
|
71
78
|
const { nodeModulesMaxDepth, opaqueDirectories } = resolveConfig();
|
|
72
79
|
const results = [];
|
|
73
|
-
searchNodeModules(root, results, 0, maxDepth ?? nodeModulesMaxDepth, new Set(opaqueDirectories));
|
|
80
|
+
searchNodeModules(root, results, 0, maxDepth ?? nodeModulesMaxDepth, new Set(opaqueDirectories), progress);
|
|
74
81
|
return results.sort((a, b) => b.size - a.size);
|
|
75
82
|
}
|
|
76
|
-
function searchNodeModules(dir, results, depth, maxDepth, opaqueSet) {
|
|
83
|
+
function searchNodeModules(dir, results, depth, maxDepth, opaqueSet, progress) {
|
|
77
84
|
if (depth > maxDepth)
|
|
78
85
|
return;
|
|
79
86
|
let items;
|
|
@@ -83,12 +90,13 @@ function searchNodeModules(dir, results, depth, maxDepth, opaqueSet) {
|
|
|
83
90
|
catch {
|
|
84
91
|
return;
|
|
85
92
|
}
|
|
93
|
+
progress?.startItem(dir);
|
|
86
94
|
for (const name of items) {
|
|
87
95
|
if (name.startsWith("."))
|
|
88
96
|
continue;
|
|
89
97
|
const fullPath = join(dir, name);
|
|
90
98
|
if (name === "node_modules") {
|
|
91
|
-
const size = dirSize(fullPath);
|
|
99
|
+
const size = dirSize(fullPath, progress);
|
|
92
100
|
if (size > 0) {
|
|
93
101
|
results.push({
|
|
94
102
|
name: "node_modules",
|
|
@@ -105,7 +113,7 @@ function searchNodeModules(dir, results, depth, maxDepth, opaqueSet) {
|
|
|
105
113
|
try {
|
|
106
114
|
const stat = statSync(fullPath);
|
|
107
115
|
if (stat.isDirectory()) {
|
|
108
|
-
searchNodeModules(fullPath, results, depth + 1, maxDepth, opaqueSet);
|
|
116
|
+
searchNodeModules(fullPath, results, depth + 1, maxDepth, opaqueSet, progress);
|
|
109
117
|
}
|
|
110
118
|
}
|
|
111
119
|
catch { }
|