dustclaw 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md 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
  {
@@ -170,29 +204,51 @@ Items marked `safe: false` (Docker, Android Emulators, pnpm Store) are always sh
170
204
 
171
205
  | Flag | Available on | What it does |
172
206
  |------|-------------|-------------|
173
- | `--json` | all commands | Output as JSON for scripting |
207
+ | `--json` | overview, scan, wasteland | Output as JSON for scripting |
208
+ | `-p, --path <path>` | overview | Path to analyze (same as the positional path) |
174
209
  | `--older-than <age>` | scan | Filter by age: `30d`, `6m`, `1y` |
175
210
  | `-n, --top <count>` | overview, scan | Number of items to show |
176
- | `-d, --depth <depth>` | scan | Max directory depth |
211
+ | `-d, --depth <depth>` | scan | Max directory depth, `0` for top-level items only |
177
212
  | `--files-only` | scan | Show only files |
178
213
  | `--dirs-only` | scan | Show only directories |
179
214
  | `--node-modules <path>` | wasteland | Also search for node_modules recursively |
180
215
  | `--force` | clean | Actually delete (prompts per item) |
181
216
  | `--only <name>` | clean | Filter to entries matching this name |
182
217
 
218
+ Invalid values are rejected before any scanning starts, followed by usage examples:
219
+
220
+ ```
221
+ $ dustclaw scan . -n abc
222
+ error: option '-n, --top <count>' argument 'abc' is invalid. Must be a whole number of 1 or more.
223
+ ```
224
+
225
+ Run `dustclaw --help` or `dustclaw <command> --help` for all options and examples.
226
+
183
227
  ## Configuration
184
228
 
185
- Dustclaw reads `~/.dustclaw.json` for user overrides. All defaults can be changed:
229
+ 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.
230
+
231
+ | Key | Default | What it does |
232
+ |-----|---------|--------------|
233
+ | `overviewTopCount` | `10` | Items shown by `dustclaw` |
234
+ | `overviewDepth` | `1` | Directory depth for `dustclaw` |
235
+ | `scanTopCount` | `20` | Items shown by `scan` |
236
+ | `scanDepth` | `3` | Directory depth for `scan` |
237
+ | `minCacheSizeMb` | `50` | Smallest `~/Library/Caches` entry listed by `wasteland` (macOS) |
238
+ | `nodeModulesMaxDepth` | `5` | How deep `wasteland --node-modules` searches |
239
+ | `staleThresholdHours` | `24` | `clean` warns when the last scan is older than this |
240
+ | `cachesPath` | `Library/Caches` | Cache folder under your home directory, broken down per app (macOS) |
241
+ | `cacheSkipList` | Homebrew, CocoaPods, ... | Caches skipped in the breakdown because a known target already covers them |
242
+ | `opaqueDirectories` | `node_modules`, `.git` | Folders measured as one item instead of being opened |
243
+ | `blockSize` | `512` | Bytes per disk block when sizing files |
244
+ | `encoding` | `utf-8` | Encoding of the saved scan file |
245
+
246
+ Example `~/.dustclaw.json`:
186
247
 
187
248
  ```json
188
249
  {
189
- "minCacheSizeMb": 50,
190
- "staleThresholdHours": 24,
191
- "nodeModulesMaxDepth": 5,
192
- "encoding": "utf-8",
193
- "scanDepth": 3,
194
- "overviewTopCount": 10,
195
- "scanTopCount": 20,
250
+ "overviewTopCount": 15,
251
+ "scanDepth": 4,
196
252
  "overrides": {
197
253
  "pnpm Store": { "safe": true }
198
254
  },
@@ -217,9 +273,14 @@ Dustclaw writes two things to your home directory:
217
273
 
218
274
  Nothing else is written. To reset state, delete `~/.dustclaw/last-scan.json`.
219
275
 
276
+ `~` 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 `~\`.
277
+
220
278
  ## Project Structure
221
279
 
222
280
  ```
281
+ .github/
282
+ workflows/
283
+ ci.yml # lint, build, tests and CLI runs on macOS, Linux and Windows
223
284
  data/
224
285
  config.json # default configuration (minCacheSizeMb, scanDepth, encoding, ...)
225
286
  targets.json # known waste targets and cache display names
@@ -231,12 +292,19 @@ src/
231
292
  clean.ts # interactive cleanup from last wasteland scan
232
293
  utils/
233
294
  config.ts # loads and merges config.json with ~/.dustclaw.json
234
- disk.ts # disk info via df
295
+ disk.ts # disk info via df (macOS, Linux) and statfs (Windows)
235
296
  format.ts # table rendering and size formatting
236
297
  scan.ts # recursive directory walker and dirSize
237
298
  state.ts # persists last wasteland scan to ~/.dustclaw/last-scan.json
238
299
  wasteland.ts # finds known waste targets and Library/Caches entries
239
300
  index.ts # CLI entry point
301
+ tests/
302
+ setup/
303
+ isolate-home.ts # runs tests against a temporary HOME
304
+ cli.test.ts # runs the real command line
305
+ *.test.ts # Vitest suites
306
+ .gitattributes # LF line endings on every platform
307
+ CHANGELOG.md # release notes
240
308
  ```
241
309
 
242
310
  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,6 +332,12 @@ pnpm test
264
332
  pnpm lint
265
333
  ```
266
334
 
335
+ Tests run with `HOME` pointed at a temporary folder, so they never read or delete your real `~/.dustclaw` data.
336
+
337
+ ## Changelog
338
+
339
+ See [CHANGELOG.md](./CHANGELOG.md) for release notes.
340
+
267
341
  ## Roadmap
268
342
 
269
343
  - **spinner**: progress indicator during slow scans
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
  }
@@ -12,6 +12,8 @@ export async function wasteland(opts) {
12
12
  }
13
13
  const allEntries = [...waste, ...nmEntries];
14
14
  const totalSize = allEntries.reduce((sum, e) => sum + e.size, 0);
15
+ // Always saved, even for --json or an empty result, so clean never acts on an older scan.
16
+ saveLastScan(allEntries);
15
17
  if (opts.json) {
16
18
  console.log(JSON.stringify({
17
19
  total: totalSize,
@@ -28,7 +30,6 @@ export async function wasteland(opts) {
28
30
  console.log(chalk.green("\n No wasteland found. Your disk is clean!\n"));
29
31
  return;
30
32
  }
31
- saveLastScan(allEntries);
32
33
  console.log(chalk.bold("\n Wasteland Report\n"));
33
34
  if (waste.length > 0) {
34
35
  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 {
@@ -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.
@@ -59,20 +66,28 @@ function loadTargetsFile() {
59
66
  export function resolveCacheNames() {
60
67
  return loadTargetsFile().cacheNames;
61
68
  }
69
+ // join, not string replace, so Windows paths get backslashes throughout.
70
+ function expandHome(path) {
71
+ if (path === "~")
72
+ return homedir();
73
+ if (path.startsWith("~/") || path.startsWith("~\\"))
74
+ return join(homedir(), path.slice(2));
75
+ return path;
76
+ }
62
77
  export function resolveTargets() {
63
- const platform = process.platform === "darwin" ? "mac" : "linux";
78
+ const platform = currentPlatform();
64
79
  const base = loadTargetsFile().targets.filter((t) => t.platform === platform || t.platform === "all");
65
80
  const user = loadUserConfig();
66
81
  const overrides = user.overrides ?? {};
67
82
  const merged = base.map((t) => {
68
- const expanded = { ...t, path: t.path.replace(/^~/, homedir()) };
83
+ const expanded = { ...t, path: expandHome(t.path) };
69
84
  return overrides[t.name] !== undefined
70
85
  ? { ...expanded, safe: overrides[t.name].safe }
71
86
  : expanded;
72
87
  });
73
88
  const custom = (user.targets ?? []).map((t) => ({
74
89
  name: t.name,
75
- path: t.path.replace(/^~/, homedir()),
90
+ path: expandHome(t.path),
76
91
  description: t.description ?? "",
77
92
  platform: "all",
78
93
  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,4 @@
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) {
@@ -19,7 +19,7 @@ export function scanDir(root, opts = {}, currentDepth = 0) {
19
19
  const fullPath = join(root, name);
20
20
  let stat;
21
21
  try {
22
- stat = lstatSync(fullPath);
22
+ stat = statSync(fullPath);
23
23
  }
24
24
  catch {
25
25
  continue;
@@ -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,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";
@@ -103,7 +103,7 @@ function searchNodeModules(dir, results, depth, maxDepth, opaqueSet) {
103
103
  if (opaqueSet.has(name))
104
104
  continue;
105
105
  try {
106
- const stat = lstatSync(fullPath);
106
+ const stat = statSync(fullPath);
107
107
  if (stat.isDirectory()) {
108
108
  searchNodeModules(fullPath, results, depth + 1, maxDepth, opaqueSet);
109
109
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dustclaw",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "Disk space monitoring, analysis, and cleanup CLI",
5
5
  "engines": {
6
6
  "node": ">=22.12.0"