dustclaw 0.4.0 → 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 CHANGED
@@ -1,6 +1,7 @@
1
1
  # Dustclaw 🦀
2
2
 
3
3
  [![npm](https://img.shields.io/npm/v/dustclaw?style=flat-square)](https://www.npmjs.com/package/dustclaw)
4
+ [![CI](https://img.shields.io/github/actions/workflow/status/psandis/dustclaw/ci.yml?branch=main&style=flat-square&label=CI)](https://github.com/psandis/dustclaw/actions/workflows/ci.yml)
4
5
 
5
6
  Find out what is eating your disk space and where the bloat is hiding.
6
7
 
@@ -36,7 +37,7 @@ npx dustclaw wasteland
36
37
 
37
38
  ┌─────────────────────────────────────┬──────────┬───────────────────────────────────────────────────────────────────┐
38
39
  │ Name │ Size │ Path │
39
- ┼─────────────────────────────────────┼──────────┼───────────────────────────────────────────────────────────────────┼
40
+ ├─────────────────────────────────────┼──────────┼───────────────────────────────────────────────────────────────────┤
40
41
  │ Docker Desktop │ 50.9 GB │ /Users/you/Library/Containers/com.docker.docker/Data │
41
42
  │ Android Emulators │ 7.7 GB │ /Users/you/.android/avd │
42
43
  │ Puppeteer Cache │ 4.0 GB │ /Users/you/.cache/puppeteer │
@@ -65,7 +66,7 @@ npx dustclaw clean --force
65
66
 
66
67
  ┌──────────────────────┬────────┬──────────────────────────────────┐
67
68
  │ Name │ Size │ Path │
68
- ┼──────────────────────┼────────┼──────────────────────────────────┼
69
+ ├──────────────────────┼────────┼──────────────────────────────────┤
69
70
  │ Gradle Cache │ 2.5 GB │ /Users/you/.gradle/caches │
70
71
  │ Puppeteer Cache │ 4.0 GB │ /Users/you/.cache/puppeteer │
71
72
  │ Playwright Browsers │ 2.2 GB │ /Users/you/Library/Caches/ms-... │
@@ -91,7 +92,9 @@ npx dustclaw clean --force
91
92
  ## Requirements
92
93
 
93
94
  - Node.js 22.12+
94
- - macOS or Linux
95
+ - macOS, Linux or Windows
96
+
97
+ CI runs lint, build, tests and the built CLI on all three with Node.js 22 and 24 for every push.
95
98
 
96
99
  ## Install
97
100
 
@@ -112,14 +115,37 @@ npx dustclaw
112
115
  ```bash
113
116
  dustclaw
114
117
  dustclaw ~/Projects # overview of a specific path
118
+ dustclaw -p ~/Projects # same, as an option
115
119
  dustclaw -n 20 # show top 20 instead of 10
116
120
  ```
117
121
 
122
+ If you pass both a path and `-p`, the path after the command is used.
123
+
124
+ ```
125
+ Disk Usage
126
+
127
+ ┌────────────────────────────┬──────────┬──────────┬───────────┬───────┐
128
+ │ Mount │ Total │ Used │ Available │ Use% │
129
+ ├────────────────────────────┼──────────┼──────────┼───────────┼───────┤
130
+ │ / │ 460.4 GB │ 11.8 GB │ 56.0 GB │ 17.4% │
131
+ │ /System/Volumes/VM │ 460.4 GB │ 18.0 GB │ 56.0 GB │ 24.3% │
132
+ │ /System/Volumes/Preboot │ 460.4 GB │ 8.4 GB │ 56.0 GB │ 13.0% │
133
+ │ /System/Volumes/Update │ 460.4 GB │ 2.1 MB │ 56.0 GB │ 0.0% │
134
+ │ /System/Volumes/xarts │ 500.0 MB │ 6.0 MB │ 481.1 MB │ 1.2% │
135
+ │ /System/Volumes/iSCPreboot │ 500.0 MB │ 5.6 MB │ 481.1 MB │ 1.1% │
136
+ │ /System/Volumes/Hardware │ 500.0 MB │ 2.6 MB │ 481.1 MB │ 0.5% │
137
+ │ /System/Volumes/Data │ 460.4 GB │ 364.9 GB │ 56.0 GB │ 86.7% │
138
+ └────────────────────────────┴──────────┴──────────┴───────────┴───────┘
139
+ ```
140
+
141
+ Use% is calculated like `df`: used / (used + available). On macOS, volumes in the same APFS container share its space, so they all report the same total and the same free space (the 460.4 GB rows above, and separately the 500 MB rows). `/System/Volumes/Data` holds your files and apps and is the row that matters. The others are macOS system volumes.
142
+
118
143
  ### Scan
119
144
 
120
145
  ```bash
121
146
  dustclaw scan ~/Projects
122
147
  dustclaw scan -n 30 -d 5 # top 30, depth 5
148
+ dustclaw scan -d 0 # each top-level item with its total size
123
149
  dustclaw scan --older-than 30d # only items older than 30 days
124
150
  dustclaw scan --files-only # only files, no directories
125
151
  dustclaw scan --dirs-only # only directories, no files
@@ -140,11 +166,16 @@ Scans known locations where dev tools and macOS pile up gigabytes:
140
166
  - Every application cache in `~/Library/Caches`, broken down individually
141
167
  - Trash and system logs
142
168
 
169
+ On Windows, wasteland checks the npm, pnpm, Yarn, pip, Poetry, Go, Composer, Playwright and Cypress caches in `AppData\Local`, plus the tools that use your home folder on every platform (Gradle, Maven, Cargo, Go modules, Bun, Android, Ollama, Hugging Face). The per-app cache breakdown, Trash, logs, Xcode and Docker Desktop are macOS only. On Windows, the disk usage table shows one row per drive.
170
+
143
171
  ```bash
144
172
  dustclaw wasteland
145
173
  dustclaw wasteland --node-modules ~/Projects # also find all node_modules
174
+ dustclaw wasteland --json # JSON output, the scan is still saved for clean
146
175
  ```
147
176
 
177
+ Every run saves its result for `clean`, including `--json` runs and runs that find nothing.
178
+
148
179
  ### Clean
149
180
 
150
181
  Reads the last wasteland scan and removes safe items. Dry run by default.
@@ -154,9 +185,12 @@ dustclaw clean # preview what would be removed
154
185
  dustclaw clean --force # delete safe items, prompts per item
155
186
  dustclaw clean --only "gradle cache" # filter to a specific entry
156
187
  dustclaw clean --only playwright --force
188
+ printf 'y\nn\n' | dustclaw clean --force # answers can be piped, one per line
157
189
  ```
158
190
 
159
- Items marked `safe: false` (Docker, Android Emulators, pnpm Store) are always shown but never auto-deleted. To override, add to `~/.dustclaw.json`:
191
+ If a delete fails, for example because of permissions, `clean` reports it and continues with the next item. Deleted items are removed from the saved scan, so running `clean` again only shows what is left.
192
+
193
+ Items marked `safe: false` (for example Docker Desktop, Android Emulators, pnpm Store, Xcode Archives and Ollama Models) are always shown but never auto-deleted. To override, add to `~/.dustclaw.json`:
160
194
 
161
195
  ```json
162
196
  {
@@ -166,33 +200,70 @@ Items marked `safe: false` (Docker, Android Emulators, pnpm Store) are always sh
166
200
  }
167
201
  ```
168
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
+
169
213
  ## Flags
170
214
 
171
215
  | Flag | Available on | What it does |
172
216
  |------|-------------|-------------|
173
- | `--json` | all commands | Output as JSON for scripting |
217
+ | `--json` | overview, scan, wasteland | Output as JSON for scripting |
218
+ | `-p, --path <path>` | overview | Path to analyze (same as the positional path) |
174
219
  | `--older-than <age>` | scan | Filter by age: `30d`, `6m`, `1y` |
175
220
  | `-n, --top <count>` | overview, scan | Number of items to show |
176
- | `-d, --depth <depth>` | scan | Max directory depth |
221
+ | `-d, --depth <depth>` | scan | Max directory depth, `0` for top-level items only |
177
222
  | `--files-only` | scan | Show only files |
178
223
  | `--dirs-only` | scan | Show only directories |
179
224
  | `--node-modules <path>` | wasteland | Also search for node_modules recursively |
180
225
  | `--force` | clean | Actually delete (prompts per item) |
181
226
  | `--only <name>` | clean | Filter to entries matching this name |
182
227
 
228
+ Invalid values are rejected before any scanning starts, followed by usage examples:
229
+
230
+ ```
231
+ $ dustclaw scan . -n abc
232
+ error: option '-n, --top <count>' argument 'abc' is invalid. Must be a whole number of 1 or more.
233
+ ```
234
+
235
+ Run `dustclaw --help` or `dustclaw <command> --help` for all options and examples.
236
+
183
237
  ## Configuration
184
238
 
185
- Dustclaw reads `~/.dustclaw.json` for user overrides. All defaults can be changed:
239
+ Defaults ship in `data/config.json`. Dustclaw reads `~/.dustclaw.json` for user overrides, and any key you set replaces the default. Command line flags such as `-n` override both.
240
+
241
+ | Key | Default | What it does |
242
+ |-----|---------|--------------|
243
+ | `overviewTopCount` | `10` | Items shown by `dustclaw` |
244
+ | `overviewDepth` | `1` | Directory depth for `dustclaw` |
245
+ | `scanTopCount` | `20` | Items shown by `scan` |
246
+ | `scanDepth` | `3` | Directory depth for `scan` |
247
+ | `minCacheSizeMb` | `50` | Smallest `~/Library/Caches` entry listed by `wasteland` (macOS) |
248
+ | `nodeModulesMaxDepth` | `5` | How deep `wasteland --node-modules` searches |
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 |
255
+ | `cachesPath` | `Library/Caches` | Cache folder under your home directory, broken down per app (macOS) |
256
+ | `cacheSkipList` | Homebrew, CocoaPods, ... | Caches skipped in the breakdown because a known target already covers them |
257
+ | `opaqueDirectories` | `node_modules`, `.git` | Folders measured as one item instead of being opened |
258
+ | `blockSize` | `512` | Bytes per disk block when sizing files |
259
+ | `encoding` | `utf-8` | Encoding of the saved scan file |
260
+
261
+ Example `~/.dustclaw.json`:
186
262
 
187
263
  ```json
188
264
  {
189
- "minCacheSizeMb": 50,
190
- "staleThresholdHours": 24,
191
- "nodeModulesMaxDepth": 5,
192
- "encoding": "utf-8",
193
- "scanDepth": 3,
194
- "overviewTopCount": 10,
195
- "scanTopCount": 20,
265
+ "overviewTopCount": 15,
266
+ "scanDepth": 4,
196
267
  "overrides": {
197
268
  "pnpm Store": { "safe": true }
198
269
  },
@@ -217,9 +288,14 @@ Dustclaw writes two things to your home directory:
217
288
 
218
289
  Nothing else is written. To reset state, delete `~/.dustclaw/last-scan.json`.
219
290
 
291
+ `~` is your home folder: `/Users/<you>` on macOS, `/home/<you>` on Linux and `C:\Users\<you>` on Windows. Paths in `~/.dustclaw.json` can start with `~/` or `~\`.
292
+
220
293
  ## Project Structure
221
294
 
222
295
  ```
296
+ .github/
297
+ workflows/
298
+ ci.yml # lint, build, tests and CLI runs on macOS, Linux and Windows
223
299
  data/
224
300
  config.json # default configuration (minCacheSizeMb, scanDepth, encoding, ...)
225
301
  targets.json # known waste targets and cache display names
@@ -231,12 +307,20 @@ src/
231
307
  clean.ts # interactive cleanup from last wasteland scan
232
308
  utils/
233
309
  config.ts # loads and merges config.json with ~/.dustclaw.json
234
- disk.ts # disk info via df
310
+ disk.ts # disk info via df (macOS, Linux) and statfs (Windows)
235
311
  format.ts # table rendering and size formatting
312
+ progress.ts # progress line on stderr for slow scans
236
313
  scan.ts # recursive directory walker and dirSize
237
314
  state.ts # persists last wasteland scan to ~/.dustclaw/last-scan.json
238
315
  wasteland.ts # finds known waste targets and Library/Caches entries
239
316
  index.ts # CLI entry point
317
+ tests/
318
+ setup/
319
+ isolate-home.ts # runs tests against a temporary HOME
320
+ cli.test.ts # runs the real command line
321
+ *.test.ts # Vitest suites
322
+ .gitattributes # LF line endings on every platform
323
+ CHANGELOG.md # release notes
240
324
  ```
241
325
 
242
326
  All behavior is driven by `data/config.json` and `data/targets.json`. To add a new waste target or change defaults, edit those files. No code changes needed.
@@ -264,9 +348,14 @@ pnpm test
264
348
  pnpm lint
265
349
  ```
266
350
 
351
+ Tests run with `HOME` pointed at a temporary folder, so they never read or delete your real `~/.dustclaw` data.
352
+
353
+ ## Changelog
354
+
355
+ See [CHANGELOG.md](./CHANGELOG.md) for release notes.
356
+
267
357
  ## Roadmap
268
358
 
269
- - **spinner**: progress indicator during slow scans
270
359
  - **watch**: track disk usage over time, spot trends before you run out of space
271
360
  - **duplicates**: find duplicate large files by hash
272
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",
package/data/targets.json CHANGED
@@ -49,6 +49,13 @@
49
49
  "platform": "linux",
50
50
  "safe": false
51
51
  },
52
+ {
53
+ "name": "Yarn Cache",
54
+ "path": "~/Library/Caches/Yarn",
55
+ "description": "Yarn download cache, fully regenerated on next install",
56
+ "platform": "mac",
57
+ "safe": true
58
+ },
52
59
  {
53
60
  "name": "Yarn Cache",
54
61
  "path": "~/.cache/yarn",
@@ -293,6 +300,69 @@
293
300
  "description": "File manager thumbnail cache, rebuilt as you browse",
294
301
  "platform": "linux",
295
302
  "safe": true
303
+ },
304
+ {
305
+ "name": "npm Cache",
306
+ "path": "~/AppData/Local/npm-cache/_cacache",
307
+ "description": "npm download cache, fully regenerated on next install",
308
+ "platform": "windows",
309
+ "safe": true
310
+ },
311
+ {
312
+ "name": "pnpm Store",
313
+ "path": "~/AppData/Local/pnpm/store",
314
+ "description": "pnpm content-addressable store shared across all projects",
315
+ "platform": "windows",
316
+ "safe": false
317
+ },
318
+ {
319
+ "name": "Yarn Cache",
320
+ "path": "~/AppData/Local/Yarn/Cache",
321
+ "description": "Yarn download cache, fully regenerated on next install",
322
+ "platform": "windows",
323
+ "safe": true
324
+ },
325
+ {
326
+ "name": "pip Cache",
327
+ "path": "~/AppData/Local/pip/Cache",
328
+ "description": "pip download cache, fully regenerated on next install",
329
+ "platform": "windows",
330
+ "safe": true
331
+ },
332
+ {
333
+ "name": "pypoetry Cache",
334
+ "path": "~/AppData/Local/pypoetry/Cache",
335
+ "description": "Poetry package cache, fully regenerated on next install",
336
+ "platform": "windows",
337
+ "safe": true
338
+ },
339
+ {
340
+ "name": "Go Build Cache",
341
+ "path": "~/AppData/Local/go-build",
342
+ "description": "Go build cache, fully regenerated on next build",
343
+ "platform": "windows",
344
+ "safe": true
345
+ },
346
+ {
347
+ "name": "Composer Cache",
348
+ "path": "~/AppData/Local/Composer",
349
+ "description": "Composer package cache, re-downloaded on next install",
350
+ "platform": "windows",
351
+ "safe": true
352
+ },
353
+ {
354
+ "name": "Playwright Browsers",
355
+ "path": "~/AppData/Local/ms-playwright",
356
+ "description": "Playwright browser binaries, re-downloaded on next install",
357
+ "platform": "windows",
358
+ "safe": true
359
+ },
360
+ {
361
+ "name": "Cypress Cache",
362
+ "path": "~/AppData/Local/Cypress/Cache",
363
+ "description": "Cypress browser binaries, re-downloaded on next install",
364
+ "platform": "windows",
365
+ "safe": true
296
366
  }
297
367
  ],
298
368
  "cacheNames": {
@@ -2,15 +2,20 @@ import { rmSync } from "node:fs";
2
2
  import { createInterface } from "node:readline";
3
3
  import chalk from "chalk";
4
4
  import { boxTable, colorSize, formatSize } from "../utils/format.js";
5
- import { loadLastScan, scanAgePath, staleThresholdMs } from "../utils/state.js";
6
- function ask(question) {
7
- const rl = createInterface({ input: process.stdin, output: process.stdout });
8
- return new Promise((resolve) => {
9
- rl.question(question, (answer) => {
10
- rl.close();
11
- resolve(answer.trim().toLowerCase());
12
- });
13
- });
5
+ import { loadLastScan, scanAgePath, staleThresholdMs, writeScanState } from "../utils/state.js";
6
+ // One reader for the whole session. A new reader per question loses piped
7
+ // input: the first one buffers every line and the rest are dropped.
8
+ function createPrompter() {
9
+ const rl = createInterface({ input: process.stdin, terminal: false });
10
+ const lines = rl[Symbol.asyncIterator]();
11
+ return {
12
+ ask: async (question) => {
13
+ process.stdout.write(question);
14
+ const { value, done } = await lines.next();
15
+ return done ? "" : String(value).trim().toLowerCase();
16
+ },
17
+ close: () => rl.close(),
18
+ };
14
19
  }
15
20
  function deleteEntry(entry) {
16
21
  rmSync(entry.path, { recursive: true, force: true });
@@ -60,16 +65,33 @@ export async function clean(opts) {
60
65
  }
61
66
  console.log(chalk.red.bold(" WARNING: Deletion is permanent. There is no undo.\n"));
62
67
  let freed = 0;
63
- for (const entry of safe) {
64
- const answer = await ask(` Delete ${chalk.bold(entry.name)} (${formatSize(entry.size)})? [y/N] `);
65
- if (answer === "y") {
66
- deleteEntry(entry);
68
+ const deleted = new Set();
69
+ const prompter = createPrompter();
70
+ try {
71
+ for (const entry of safe) {
72
+ const answer = await prompter.ask(` Delete ${chalk.bold(entry.name)} (${formatSize(entry.size)})? [y/N] `);
73
+ if (answer !== "y") {
74
+ console.log(chalk.gray(` Skipped: ${entry.path}`));
75
+ continue;
76
+ }
77
+ try {
78
+ deleteEntry(entry);
79
+ }
80
+ catch (err) {
81
+ console.log(chalk.red(` Failed: ${entry.path} (${err.message})`));
82
+ continue;
83
+ }
84
+ deleted.add(entry.path);
67
85
  freed += entry.size;
68
86
  console.log(chalk.green(` Deleted: ${entry.path}`));
69
87
  }
70
- else {
71
- console.log(chalk.gray(` Skipped: ${entry.path}`));
72
- }
88
+ }
89
+ finally {
90
+ prompter.close();
91
+ }
92
+ // Keep the original scan time so the stale warning stays accurate.
93
+ if (deleted.size > 0) {
94
+ writeScanState({ ...state, entries: state.entries.filter((e) => !deleted.has(e.path)) });
73
95
  }
74
96
  console.log(chalk.bold(`\n Freed: ${colorSize(freed)}\n`));
75
97
  }
@@ -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({
@@ -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,17 +1,20 @@
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);
16
+ // Always saved, even for --json or an empty result, so clean never acts on an older scan.
17
+ saveLastScan(allEntries);
15
18
  if (opts.json) {
16
19
  console.log(JSON.stringify({
17
20
  total: totalSize,
@@ -28,7 +31,6 @@ export async function wasteland(opts) {
28
31
  console.log(chalk.green("\n No wasteland found. Your disk is clean!\n"));
29
32
  return;
30
33
  }
31
- saveLastScan(allEntries);
32
34
  console.log(chalk.bold("\n Wasteland Report\n"));
33
35
  if (waste.length > 0) {
34
36
  console.log(chalk.bold(" Known space wasters:\n"));
package/dist/index.js CHANGED
@@ -8,13 +8,18 @@ import { scan } from "./commands/scan.js";
8
8
  import { wasteland } from "./commands/wasteland.js";
9
9
  import { resolveConfig } from "./utils/config.js";
10
10
  import { parseAge } from "./utils/scan.js";
11
- function positiveIntOption(value) {
12
- const n = Number(value);
13
- if (!Number.isInteger(n) || n < 1) {
14
- throw new InvalidArgumentError("Must be a whole number of 1 or more.");
15
- }
16
- return n;
11
+ function intOption(min) {
12
+ return (value) => {
13
+ const n = Number(value);
14
+ if (!Number.isInteger(n) || n < min) {
15
+ throw new InvalidArgumentError(`Must be a whole number of ${min} or more.`);
16
+ }
17
+ return n;
18
+ };
17
19
  }
20
+ // Depth 0 is valid: each top-level item is listed with its total size.
21
+ const countOption = intOption(1);
22
+ const depthOption = intOption(0);
18
23
  function ageOption(value) {
19
24
  try {
20
25
  return parseAge(value);
@@ -50,15 +55,15 @@ Examples:
50
55
  program
51
56
  .command("overview [path]", { isDefault: true })
52
57
  .description(`Quick overview: disk usage, free space, top ${overviewTopCount} biggest items`)
53
- .option("-n, --top <count>", "Number of top items to show", positiveIntOption, overviewTopCount)
58
+ .option("-n, --top <count>", "Number of top items to show", countOption, overviewTopCount)
54
59
  .option("-p, --path <path>", "Path to analyze (same as the positional path)", ".")
55
60
  .option("--json", "Output as JSON")
56
61
  .action((path, opts) => overview({ ...opts, path: path ?? opts.path }));
57
62
  program
58
63
  .command("scan [path]")
59
64
  .description("Deep scan: ranked list of largest files and folders")
60
- .option("-n, --top <count>", "Number of top items to show", positiveIntOption, scanTopCount)
61
- .option("-d, --depth <depth>", "Max directory depth", positiveIntOption, scanDepth)
65
+ .option("-n, --top <count>", "Number of top items to show", countOption, scanTopCount)
66
+ .option("-d, --depth <depth>", "Max directory depth", depthOption, scanDepth)
62
67
  .option("--older-than <age>", "Filter by age (e.g. 30d, 6m, 1y)", ageOption)
63
68
  .option("--files-only", "Show only files, not directories")
64
69
  .option("--dirs-only", "Show only directories, not files")
@@ -1,8 +1,10 @@
1
+ export type Platform = "mac" | "linux" | "windows";
2
+ export declare function currentPlatform(): Platform;
1
3
  export interface TargetDef {
2
4
  name: string;
3
5
  path: string;
4
6
  description: string;
5
- platform: "mac" | "linux" | "all";
7
+ platform: Platform | "all";
6
8
  safe: boolean;
7
9
  }
8
10
  export interface DustclawConfig {
@@ -17,6 +19,11 @@ export interface DustclawConfig {
17
19
  overviewTopCount: number;
18
20
  scanTopCount: number;
19
21
  blockSize: number;
22
+ progressIntervalMs: number;
23
+ progressBarWidth: number;
24
+ progressFillChar: string;
25
+ progressEmptyChar: string;
26
+ progressFallbackColumns: number;
20
27
  cachesPath: string;
21
28
  cacheSkipList: string[];
22
29
  opaqueDirectories: string[];
@@ -2,6 +2,13 @@ import { existsSync, readFileSync } from "node:fs";
2
2
  import { homedir } from "node:os";
3
3
  import { join } from "node:path";
4
4
  import { fileURLToPath } from "node:url";
5
+ export function currentPlatform() {
6
+ if (process.platform === "darwin")
7
+ return "mac";
8
+ if (process.platform === "win32")
9
+ return "windows";
10
+ return "linux";
11
+ }
5
12
  const USER_CONFIG_PATH = join(homedir(), ".dustclaw.json");
6
13
  // Bundled defaults live in <package root>/data. This file runs from either
7
14
  // src/utils (dev, tests) or dist/utils (build), both two levels below the root.
@@ -47,6 +54,11 @@ function buildConfig() {
47
54
  overviewTopCount: user.overviewTopCount ?? defaults.overviewTopCount,
48
55
  scanTopCount: user.scanTopCount ?? defaults.scanTopCount,
49
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,
50
62
  cachesPath: user.cachesPath ?? defaults.cachesPath,
51
63
  cacheSkipList: user.cacheSkipList ?? defaults.cacheSkipList,
52
64
  opaqueDirectories: user.opaqueDirectories ?? defaults.opaqueDirectories,
@@ -59,20 +71,28 @@ function loadTargetsFile() {
59
71
  export function resolveCacheNames() {
60
72
  return loadTargetsFile().cacheNames;
61
73
  }
74
+ // join, not string replace, so Windows paths get backslashes throughout.
75
+ function expandHome(path) {
76
+ if (path === "~")
77
+ return homedir();
78
+ if (path.startsWith("~/") || path.startsWith("~\\"))
79
+ return join(homedir(), path.slice(2));
80
+ return path;
81
+ }
62
82
  export function resolveTargets() {
63
- const platform = process.platform === "darwin" ? "mac" : "linux";
83
+ const platform = currentPlatform();
64
84
  const base = loadTargetsFile().targets.filter((t) => t.platform === platform || t.platform === "all");
65
85
  const user = loadUserConfig();
66
86
  const overrides = user.overrides ?? {};
67
87
  const merged = base.map((t) => {
68
- const expanded = { ...t, path: t.path.replace(/^~/, homedir()) };
88
+ const expanded = { ...t, path: expandHome(t.path) };
69
89
  return overrides[t.name] !== undefined
70
90
  ? { ...expanded, safe: overrides[t.name].safe }
71
91
  : expanded;
72
92
  });
73
93
  const custom = (user.targets ?? []).map((t) => ({
74
94
  name: t.name,
75
- path: t.path.replace(/^~/, homedir()),
95
+ path: expandHome(t.path),
76
96
  description: t.description ?? "",
77
97
  platform: "all",
78
98
  safe: t.safe,
@@ -1,7 +1,10 @@
1
1
  import { execSync } from "node:child_process";
2
+ import { statfsSync } from "node:fs";
2
3
  import { platform } from "node:os";
3
4
  export function getDiskInfo() {
4
5
  const os = platform();
6
+ if (os === "win32")
7
+ return getWindowsDiskInfo();
5
8
  if (os !== "darwin" && os !== "linux") {
6
9
  throw new Error(`Unsupported platform: ${os}`);
7
10
  }
@@ -27,6 +30,26 @@ export function getDiskInfo() {
27
30
  }
28
31
  return disks;
29
32
  }
33
+ // Windows has no df. statfs reads each drive's volume information directly.
34
+ // A: and B: are skipped because they are reserved for floppy drives.
35
+ function getWindowsDiskInfo() {
36
+ const disks = [];
37
+ for (const letter of "CDEFGHIJKLMNOPQRSTUVWXYZ") {
38
+ const root = `${letter}:\\`;
39
+ try {
40
+ const fs = statfsSync(root);
41
+ disks.push({
42
+ filesystem: `${letter}:`,
43
+ total: fs.blocks * fs.bsize,
44
+ used: (fs.blocks - fs.bfree) * fs.bsize,
45
+ available: fs.bavail * fs.bsize,
46
+ mountpoint: root,
47
+ });
48
+ }
49
+ catch { }
50
+ }
51
+ return disks;
52
+ }
30
53
  // Same as df's Capacity column. Dividing by total is wrong on APFS, where every
31
54
  // volume reports the whole shared container as its total.
32
55
  export function usedRatio(disk) {
@@ -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;
@@ -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
+ }
@@ -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;
@@ -1,10 +1,12 @@
1
- import { lstatSync, readdirSync } from "node:fs";
1
+ import { lstatSync, readdirSync, statSync } from "node:fs";
2
2
  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
- for (const name of items) {
17
- if (name.startsWith(".") && currentDepth === 0)
18
- continue;
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
- stat = lstatSync(fullPath);
27
+ stat = statSync(fullPath);
23
28
  }
24
29
  catch {
25
- continue;
30
+ return;
26
31
  }
27
32
  if (stat.isDirectory()) {
28
- if (opaqueSet.has(name)) {
29
- const size = dirSize(fullPath);
30
- if (!opts.filesOnly) {
31
- if (!opts.olderThan || stat.mtime < opts.olderThan) {
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
- else {
42
- const size = dirSize(fullPath);
43
- if (!opts.filesOnly) {
44
- if (!opts.olderThan || stat.mtime < opts.olderThan) {
45
- entries.push({ path: fullPath, size, isDirectory: true, mtime: stat.mtime });
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
- total += stat.blocks * blockSize;
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 { }
@@ -4,6 +4,7 @@ export interface ScanState {
4
4
  entries: WasteEntry[];
5
5
  }
6
6
  export declare function saveLastScan(entries: WasteEntry[]): void;
7
+ export declare function writeScanState(state: ScanState): void;
7
8
  export declare function loadLastScan(): ScanState | null;
8
9
  export declare function scanAgePath(state: ScanState): number;
9
10
  export declare function staleThresholdMs(): number;
@@ -5,12 +5,11 @@ import { resolveConfig } from "./config.js";
5
5
  const STATE_DIR = join(homedir(), ".dustclaw");
6
6
  const SCAN_FILE = join(STATE_DIR, "last-scan.json");
7
7
  export function saveLastScan(entries) {
8
+ writeScanState({ scannedAt: new Date().toISOString(), entries });
9
+ }
10
+ export function writeScanState(state) {
8
11
  const { encoding } = resolveConfig();
9
12
  mkdirSync(STATE_DIR, { recursive: true });
10
- const state = {
11
- scannedAt: new Date().toISOString(),
12
- entries,
13
- };
14
13
  writeFileSync(SCAN_FILE, JSON.stringify(state, null, 2), encoding);
15
14
  }
16
15
  export function loadLastScan() {
@@ -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[];
@@ -1,4 +1,4 @@
1
- import { existsSync, lstatSync, readdirSync, statSync } from "node:fs";
1
+ import { existsSync, readdirSync, statSync } from "node:fs";
2
2
  import { homedir } from "node:os";
3
3
  import { join } from "node:path";
4
4
  import { resolveCacheNames, resolveConfig, resolveTargets } from "./config.js";
@@ -7,14 +7,32 @@ const home = homedir();
7
7
  function friendlyName(dirName, cacheNames) {
8
8
  return cacheNames[dirName] ?? dirName;
9
9
  }
10
- export function findCaches() {
11
- const { minCacheSize, cachesPath, cacheSkipList } = resolveConfig();
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
- for (const name of items) {
26
- if (skip.has(name))
27
- continue;
28
- const fullPath = join(cachesDir, name);
29
- try {
30
- const stat = statSync(fullPath);
31
- if (!stat.isDirectory())
32
- continue;
33
- }
34
- catch {
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
- if (!existsSync(target.path))
55
- continue;
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",
@@ -103,9 +111,9 @@ function searchNodeModules(dir, results, depth, maxDepth, opaqueSet) {
103
111
  if (opaqueSet.has(name))
104
112
  continue;
105
113
  try {
106
- const stat = lstatSync(fullPath);
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 { }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dustclaw",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "Disk space monitoring, analysis, and cleanup CLI",
5
5
  "engines": {
6
6
  "node": ">=22.12.0"