dustclaw 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -83,14 +83,14 @@ npx dustclaw clean --force
83
83
 
84
84
  | Command | What it does |
85
85
  |---------|-------------|
86
- | `dustclaw` | Quick overview: disk usage, free space, top 10 biggest items |
86
+ | `dustclaw [path]` | Quick overview: disk usage, free space, top 10 biggest items |
87
87
  | `dustclaw scan [path]` | Deep scan: ranked list of largest files and folders |
88
88
  | `dustclaw wasteland` | Finds known space wasters: caches, build artifacts, Trash, Docker |
89
89
  | `dustclaw clean` | Clean safe items from last wasteland scan (dry run by default) |
90
90
 
91
91
  ## Requirements
92
92
 
93
- - Node.js 18+
93
+ - Node.js 22.12+
94
94
  - macOS or Linux
95
95
 
96
96
  ## Install
@@ -111,8 +111,8 @@ npx dustclaw
111
111
 
112
112
  ```bash
113
113
  dustclaw
114
+ dustclaw ~/Projects # overview of a specific path
114
115
  dustclaw -n 20 # show top 20 instead of 10
115
- dustclaw -p ~/Projects # scan a specific path
116
116
  ```
117
117
 
118
118
  ### Scan
@@ -220,11 +220,15 @@ Nothing else is written. To reset state, delete `~/.dustclaw/last-scan.json`.
220
220
  ## Project Structure
221
221
 
222
222
  ```
223
+ data/
224
+ config.json # default configuration (minCacheSizeMb, scanDepth, encoding, ...)
225
+ targets.json # known waste targets and cache display names
223
226
  src/
224
- commands/ # CLI commands (overview, scan, wasteland, clean)
225
- data/
226
- config.json # default configuration (minCacheSizeMb, scanDepth, encoding, ...)
227
- targets.json # known waste targets and cache display names
227
+ commands/
228
+ overview.ts # disk usage summary and top N items
229
+ scan.ts # deep recursive scan ranked by size
230
+ wasteland.ts # known space waster report
231
+ clean.ts # interactive cleanup from last wasteland scan
228
232
  utils/
229
233
  config.ts # loads and merges config.json with ~/.dustclaw.json
230
234
  disk.ts # disk info via df
@@ -235,7 +239,7 @@ src/
235
239
  index.ts # CLI entry point
236
240
  ```
237
241
 
238
- All behavior is driven by `src/data/config.json` and `src/data/targets.json`. To add a new waste target or change defaults, edit those files — no code changes needed.
242
+ 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.
239
243
 
240
244
  ## Standing on the Shoulders of Giants
241
245
 
@@ -0,0 +1,23 @@
1
+ {
2
+ "minCacheSizeMb": 50,
3
+ "staleThresholdHours": 24,
4
+ "nodeModulesMaxDepth": 5,
5
+ "encoding": "utf-8",
6
+ "scanDepth": 3,
7
+ "overviewDepth": 1,
8
+ "overviewTopCount": 10,
9
+ "scanTopCount": 20,
10
+ "blockSize": 512,
11
+ "cachesPath": "Library/Caches",
12
+ "cacheSkipList": [
13
+ "Homebrew",
14
+ "CocoaPods",
15
+ "Yarn",
16
+ "pip",
17
+ "ms-playwright",
18
+ "Cypress",
19
+ "pypoetry",
20
+ "composer"
21
+ ],
22
+ "opaqueDirectories": ["node_modules", ".git"]
23
+ }
@@ -0,0 +1,326 @@
1
+ {
2
+ "targets": [
3
+ {
4
+ "name": "Xcode DerivedData",
5
+ "path": "~/Library/Developer/Xcode/DerivedData",
6
+ "description": "Xcode build artifacts, fully regenerated on next build",
7
+ "platform": "mac",
8
+ "safe": true
9
+ },
10
+ {
11
+ "name": "Xcode Device Support",
12
+ "path": "~/Library/Developer/Xcode/iOS DeviceSupport",
13
+ "description": "iOS device debug symbols, re-downloaded when device connects",
14
+ "platform": "mac",
15
+ "safe": true
16
+ },
17
+ {
18
+ "name": "Xcode Archives",
19
+ "path": "~/Library/Developer/Xcode/Archives",
20
+ "description": "Archived app builds, may contain your only copy of a release",
21
+ "platform": "mac",
22
+ "safe": false
23
+ },
24
+ {
25
+ "name": "Xcode Simulators",
26
+ "path": "~/Library/Developer/CoreSimulator/Devices",
27
+ "description": "iOS simulator device data, can be recreated but takes time",
28
+ "platform": "mac",
29
+ "safe": false
30
+ },
31
+ {
32
+ "name": "npm Cache",
33
+ "path": "~/.npm/_cacache",
34
+ "description": "npm download cache, fully regenerated on next install",
35
+ "platform": "all",
36
+ "safe": true
37
+ },
38
+ {
39
+ "name": "pnpm Store",
40
+ "path": "~/Library/pnpm/store",
41
+ "description": "pnpm content-addressable store shared across all projects",
42
+ "platform": "mac",
43
+ "safe": false
44
+ },
45
+ {
46
+ "name": "pnpm Store",
47
+ "path": "~/.local/share/pnpm/store",
48
+ "description": "pnpm content-addressable store shared across all projects",
49
+ "platform": "linux",
50
+ "safe": false
51
+ },
52
+ {
53
+ "name": "Yarn Cache",
54
+ "path": "~/.cache/yarn",
55
+ "description": "Yarn download cache, fully regenerated on next install",
56
+ "platform": "all",
57
+ "safe": true
58
+ },
59
+ {
60
+ "name": "Bun Cache",
61
+ "path": "~/.bun/install/cache",
62
+ "description": "Bun package cache, fully regenerated on next install",
63
+ "platform": "all",
64
+ "safe": true
65
+ },
66
+ {
67
+ "name": "Gradle Cache",
68
+ "path": "~/.gradle/caches",
69
+ "description": "Gradle build and dependency cache, re-downloaded on next build",
70
+ "platform": "all",
71
+ "safe": true
72
+ },
73
+ {
74
+ "name": "Gradle Daemon",
75
+ "path": "~/.gradle/daemon",
76
+ "description": "Gradle daemon logs and metadata",
77
+ "platform": "all",
78
+ "safe": true
79
+ },
80
+ {
81
+ "name": "Maven Cache",
82
+ "path": "~/.m2/repository",
83
+ "description": "Maven local repository, re-downloaded on next build",
84
+ "platform": "all",
85
+ "safe": true
86
+ },
87
+ {
88
+ "name": "Android Emulators",
89
+ "path": "~/.android/avd",
90
+ "description": "Android emulator images and user data",
91
+ "platform": "all",
92
+ "safe": false
93
+ },
94
+ {
95
+ "name": "Android Cache",
96
+ "path": "~/.android/cache",
97
+ "description": "Android SDK download cache",
98
+ "platform": "all",
99
+ "safe": true
100
+ },
101
+ {
102
+ "name": "Cargo Registry",
103
+ "path": "~/.cargo/registry",
104
+ "description": "Rust crate source cache, re-downloaded on next build",
105
+ "platform": "all",
106
+ "safe": true
107
+ },
108
+ {
109
+ "name": "Cargo Git",
110
+ "path": "~/.cargo/git",
111
+ "description": "Rust git dependency cache, re-downloaded on next build",
112
+ "platform": "all",
113
+ "safe": true
114
+ },
115
+ {
116
+ "name": "pip Cache",
117
+ "path": "~/Library/Caches/pip",
118
+ "description": "pip download cache, fully regenerated on next install",
119
+ "platform": "mac",
120
+ "safe": true
121
+ },
122
+ {
123
+ "name": "pip Cache",
124
+ "path": "~/.cache/pip",
125
+ "description": "pip download cache, fully regenerated on next install",
126
+ "platform": "linux",
127
+ "safe": true
128
+ },
129
+ {
130
+ "name": "pypoetry Cache",
131
+ "path": "~/Library/Caches/pypoetry",
132
+ "description": "Poetry package cache, fully regenerated on next install",
133
+ "platform": "mac",
134
+ "safe": true
135
+ },
136
+ {
137
+ "name": "pypoetry Cache",
138
+ "path": "~/.cache/pypoetry",
139
+ "description": "Poetry package cache, fully regenerated on next install",
140
+ "platform": "linux",
141
+ "safe": true
142
+ },
143
+ {
144
+ "name": "Bundler Cache",
145
+ "path": "~/.bundle/cache",
146
+ "description": "Bundler gem cache, re-downloaded on next bundle install",
147
+ "platform": "all",
148
+ "safe": true
149
+ },
150
+ {
151
+ "name": "CocoaPods Cache",
152
+ "path": "~/Library/Caches/CocoaPods",
153
+ "description": "CocoaPods download cache, re-downloaded on next pod install",
154
+ "platform": "mac",
155
+ "safe": true
156
+ },
157
+ {
158
+ "name": "Go Module Cache",
159
+ "path": "~/go/pkg/mod",
160
+ "description": "Go module cache, re-downloaded on next go build",
161
+ "platform": "all",
162
+ "safe": true
163
+ },
164
+ {
165
+ "name": "Go Build Cache",
166
+ "path": "~/Library/Caches/go-build",
167
+ "description": "Go build cache, fully regenerated on next build",
168
+ "platform": "mac",
169
+ "safe": true
170
+ },
171
+ {
172
+ "name": "Go Build Cache",
173
+ "path": "~/.cache/go-build",
174
+ "description": "Go build cache, fully regenerated on next build",
175
+ "platform": "linux",
176
+ "safe": true
177
+ },
178
+ {
179
+ "name": "Composer Cache",
180
+ "path": "~/Library/Caches/composer",
181
+ "description": "Composer package cache, re-downloaded on next install",
182
+ "platform": "mac",
183
+ "safe": true
184
+ },
185
+ {
186
+ "name": "Composer Cache",
187
+ "path": "~/.cache/composer",
188
+ "description": "Composer package cache, re-downloaded on next install",
189
+ "platform": "linux",
190
+ "safe": true
191
+ },
192
+ {
193
+ "name": "Homebrew Cache",
194
+ "path": "~/Library/Caches/Homebrew",
195
+ "description": "Homebrew downloaded package cache, re-downloaded on next install",
196
+ "platform": "mac",
197
+ "safe": true
198
+ },
199
+ {
200
+ "name": "Docker Desktop",
201
+ "path": "~/Library/Containers/com.docker.docker/Data",
202
+ "description": "Docker images, containers, and volumes",
203
+ "platform": "mac",
204
+ "safe": false
205
+ },
206
+ {
207
+ "name": "Playwright Browsers",
208
+ "path": "~/Library/Caches/ms-playwright",
209
+ "description": "Playwright browser binaries, re-downloaded on next install",
210
+ "platform": "mac",
211
+ "safe": true
212
+ },
213
+ {
214
+ "name": "Playwright Browsers",
215
+ "path": "~/.cache/ms-playwright",
216
+ "description": "Playwright browser binaries, re-downloaded on next install",
217
+ "platform": "linux",
218
+ "safe": true
219
+ },
220
+ {
221
+ "name": "Cypress Cache",
222
+ "path": "~/Library/Caches/Cypress",
223
+ "description": "Cypress browser binaries, re-downloaded on next install",
224
+ "platform": "mac",
225
+ "safe": true
226
+ },
227
+ {
228
+ "name": "Cypress Cache",
229
+ "path": "~/.cache/Cypress",
230
+ "description": "Cypress browser binaries, re-downloaded on next install",
231
+ "platform": "linux",
232
+ "safe": true
233
+ },
234
+ {
235
+ "name": "Puppeteer Cache",
236
+ "path": "~/.cache/puppeteer",
237
+ "description": "Puppeteer Chrome binaries, re-downloaded on next install",
238
+ "platform": "all",
239
+ "safe": true
240
+ },
241
+ {
242
+ "name": "Terraform Plugins",
243
+ "path": "~/.terraform.d/plugin-cache",
244
+ "description": "Terraform provider plugin cache, re-downloaded on next init",
245
+ "platform": "all",
246
+ "safe": true
247
+ },
248
+ {
249
+ "name": "Helm Cache",
250
+ "path": "~/Library/Caches/helm",
251
+ "description": "Helm chart repository cache, rebuilt by helm repo update",
252
+ "platform": "mac",
253
+ "safe": true
254
+ },
255
+ {
256
+ "name": "Helm Cache",
257
+ "path": "~/.cache/helm",
258
+ "description": "Helm chart repository cache, rebuilt by helm repo update",
259
+ "platform": "linux",
260
+ "safe": true
261
+ },
262
+ {
263
+ "name": "Ollama Models",
264
+ "path": "~/.ollama/models",
265
+ "description": "Downloaded Ollama AI models, safe only if willing to re-download",
266
+ "platform": "all",
267
+ "safe": false
268
+ },
269
+ {
270
+ "name": "Hugging Face Cache",
271
+ "path": "~/.cache/huggingface",
272
+ "description": "Hugging Face model cache, re-downloaded on next use",
273
+ "platform": "all",
274
+ "safe": true
275
+ },
276
+ {
277
+ "name": "Trash",
278
+ "path": "~/.Trash",
279
+ "description": "Files waiting in Trash",
280
+ "platform": "mac",
281
+ "safe": true
282
+ },
283
+ {
284
+ "name": "System Logs",
285
+ "path": "~/Library/Logs",
286
+ "description": "Application and system log files",
287
+ "platform": "mac",
288
+ "safe": true
289
+ },
290
+ {
291
+ "name": "Thumbnail Cache",
292
+ "path": "~/.cache/thumbnails",
293
+ "description": "File manager thumbnail cache, rebuilt as you browse",
294
+ "platform": "linux",
295
+ "safe": true
296
+ }
297
+ ],
298
+ "cacheNames": {
299
+ "com.spotify.client": "Spotify",
300
+ "com.apple.Safari": "Safari",
301
+ "com.google.Chrome": "Chrome",
302
+ "Google": "Google/Chrome",
303
+ "com.docker.docker": "Docker",
304
+ "com.microsoft.VSCode": "VS Code",
305
+ "com.todesktop.230313mzl4w4u92": "Cursor",
306
+ "com.todesktop.230313mzl4w4u92.ShipIt": "Cursor Updates",
307
+ "com.google.antigravity.ShipIt": "Chrome Updates",
308
+ "icloudmailagent": "iCloud Mail",
309
+ "com.apple.callintelligenced": "Apple Call Intelligence",
310
+ "ms-playwright": "Playwright Browsers",
311
+ "ms-playwright-go": "Playwright Go Browsers",
312
+ "pip": "pip",
313
+ "Cypress": "Cypress",
314
+ "node-gyp": "node-gyp",
315
+ "typescript": "TypeScript",
316
+ "pnpm": "pnpm",
317
+ "colima": "Colima",
318
+ "com.openai.chat": "ChatGPT",
319
+ "com.openai.codex": "OpenAI Codex",
320
+ "ollama": "Ollama",
321
+ "pypoetry": "pypoetry",
322
+ "composer": "Composer",
323
+ "us.zoom.xos": "Zoom",
324
+ "GeoServices": "GeoServices"
325
+ }
326
+ }
@@ -1,5 +1,5 @@
1
1
  interface OverviewOptions {
2
- top: string;
2
+ top: number;
3
3
  path: string;
4
4
  json?: boolean;
5
5
  }
@@ -1,12 +1,12 @@
1
1
  import { resolve } from "node:path";
2
2
  import chalk from "chalk";
3
3
  import { resolveConfig } from "../utils/config.js";
4
- import { getDiskInfo } from "../utils/disk.js";
4
+ import { getDiskInfo, usedRatio } from "../utils/disk.js";
5
5
  import { boxTable, colorSize, formatPercent, formatSize } from "../utils/format.js";
6
6
  import { scanDir } from "../utils/scan.js";
7
7
  export function overview(opts) {
8
8
  const { overviewDepth } = resolveConfig();
9
- const count = Number.parseInt(opts.top, 10);
9
+ const count = opts.top;
10
10
  const targetPath = resolve(opts.path);
11
11
  const disks = getDiskInfo();
12
12
  const entries = scanDir(targetPath, { depth: overviewDepth });
@@ -33,7 +33,7 @@ export function overview(opts) {
33
33
  formatSize(d.total),
34
34
  colorSize(d.used),
35
35
  colorSize(d.available),
36
- formatPercent(d.used / d.total),
36
+ formatPercent(usedRatio(d)),
37
37
  ]);
38
38
  console.log(boxTable(["Mount", "Total", "Used", "Available", "Use%"], diskRows));
39
39
  console.log(chalk.bold(`\n Top ${count} in ${targetPath}\n`));
@@ -1,7 +1,7 @@
1
1
  interface ScanCommandOptions {
2
- top: string;
3
- depth: string;
4
- olderThan?: string;
2
+ top: number;
3
+ depth: number;
4
+ olderThan?: Date;
5
5
  filesOnly?: boolean;
6
6
  dirsOnly?: boolean;
7
7
  json?: boolean;
@@ -1,18 +1,16 @@
1
1
  import { resolve } from "node:path";
2
2
  import chalk from "chalk";
3
3
  import { boxTable, colorSize } from "../utils/format.js";
4
- import { parseAge, scanDir } from "../utils/scan.js";
4
+ import { scanDir } from "../utils/scan.js";
5
5
  export function scan(path, opts) {
6
6
  const targetPath = resolve(path ?? ".");
7
- const count = Number.parseInt(opts.top, 10);
7
+ const count = opts.top;
8
8
  const scanOpts = {
9
- depth: Number.parseInt(opts.depth, 10),
9
+ depth: opts.depth,
10
10
  filesOnly: opts.filesOnly,
11
11
  dirsOnly: opts.dirsOnly,
12
+ olderThan: opts.olderThan,
12
13
  };
13
- if (opts.olderThan) {
14
- scanOpts.olderThan = parseAge(opts.olderThan);
15
- }
16
14
  const entries = scanDir(targetPath, scanOpts);
17
15
  const sorted = entries.sort((a, b) => b.size - a.size).slice(0, count);
18
16
  if (opts.json) {
package/dist/index.js CHANGED
@@ -1,32 +1,65 @@
1
1
  #!/usr/bin/env node
2
2
  import { readFileSync } from "node:fs";
3
3
  import { fileURLToPath } from "node:url";
4
- import { Command } from "commander";
4
+ import { Command, InvalidArgumentError } from "commander";
5
5
  import { clean } from "./commands/clean.js";
6
6
  import { overview } from "./commands/overview.js";
7
7
  import { scan } from "./commands/scan.js";
8
8
  import { wasteland } from "./commands/wasteland.js";
9
9
  import { resolveConfig } from "./utils/config.js";
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;
17
+ }
18
+ function ageOption(value) {
19
+ try {
20
+ return parseAge(value);
21
+ }
22
+ catch (err) {
23
+ throw new InvalidArgumentError(err.message);
24
+ }
25
+ }
10
26
  const { version } = JSON.parse(readFileSync(fileURLToPath(new URL("../package.json", import.meta.url)), "utf-8"));
11
27
  const { overviewTopCount, scanTopCount, scanDepth } = resolveConfig();
12
28
  const program = new Command();
13
29
  program
14
30
  .name("dustclaw")
15
31
  .description("Disk space monitoring, analysis, and cleanup CLI")
16
- .version(version);
32
+ .version(version)
33
+ .showHelpAfterError(`
34
+ Examples:
35
+ dustclaw ../.. overview of a path
36
+ dustclaw scan ~/Projects -n 20 top 20 largest items in a path
37
+ dustclaw wasteland find caches and build junk
38
+ dustclaw clean dry run cleanup
39
+
40
+ Run dustclaw <command> --help for all options.`)
41
+ .addHelpText("after", `
42
+ Examples:
43
+ dustclaw overview of the current directory
44
+ dustclaw ../.. overview of a path
45
+ dustclaw scan ~/Projects -n 20 top 20 largest items in a path
46
+ dustclaw scan --older-than 6m items not modified in 6 months
47
+ dustclaw wasteland find caches and build junk
48
+ dustclaw clean dry run cleanup
49
+ dustclaw clean --force delete safe items, prompts per item`);
17
50
  program
18
- .command("overview", { isDefault: true })
19
- .description("Quick overview: disk usage, free space, top 10 biggest dirs")
20
- .option("-n, --top <count>", "Number of top items to show", String(overviewTopCount))
21
- .option("-p, --path <path>", "Path to analyze", ".")
51
+ .command("overview [path]", { isDefault: true })
52
+ .description(`Quick overview: disk usage, free space, top ${overviewTopCount} biggest items`)
53
+ .option("-n, --top <count>", "Number of top items to show", positiveIntOption, overviewTopCount)
54
+ .option("-p, --path <path>", "Path to analyze (same as the positional path)", ".")
22
55
  .option("--json", "Output as JSON")
23
- .action(overview);
56
+ .action((path, opts) => overview({ ...opts, path: path ?? opts.path }));
24
57
  program
25
58
  .command("scan [path]")
26
59
  .description("Deep scan: ranked list of largest files and folders")
27
- .option("-n, --top <count>", "Number of top items to show", String(scanTopCount))
28
- .option("-d, --depth <depth>", "Max directory depth", String(scanDepth))
29
- .option("--older-than <age>", "Filter by age (e.g. 30d, 6m, 1y)")
60
+ .option("-n, --top <count>", "Number of top items to show", positiveIntOption, scanTopCount)
61
+ .option("-d, --depth <depth>", "Max directory depth", positiveIntOption, scanDepth)
62
+ .option("--older-than <age>", "Filter by age (e.g. 30d, 6m, 1y)", ageOption)
30
63
  .option("--files-only", "Show only files, not directories")
31
64
  .option("--dirs-only", "Show only directories, not files")
32
65
  .option("--json", "Output as JSON")
@@ -3,9 +3,14 @@ import { homedir } from "node:os";
3
3
  import { join } from "node:path";
4
4
  import { fileURLToPath } from "node:url";
5
5
  const USER_CONFIG_PATH = join(homedir(), ".dustclaw.json");
6
+ // Bundled defaults live in <package root>/data. This file runs from either
7
+ // src/utils (dev, tests) or dist/utils (build), both two levels below the root.
8
+ const DATA_DIR = fileURLToPath(new URL("../../data/", import.meta.url));
9
+ function loadDataFile(name) {
10
+ return JSON.parse(readFileSync(join(DATA_DIR, name), "utf-8"));
11
+ }
6
12
  function loadDefaultConfig() {
7
- const file = fileURLToPath(new URL("../data/config.json", import.meta.url));
8
- return JSON.parse(readFileSync(file, "utf-8"));
13
+ return loadDataFile("config.json");
9
14
  }
10
15
  function loadUserConfig() {
11
16
  if (!existsSync(USER_CONFIG_PATH))
@@ -17,7 +22,15 @@ function loadUserConfig() {
17
22
  return {};
18
23
  }
19
24
  }
25
+ // Config is read once per process. The scanners call resolveConfig() for every
26
+ // directory they visit, so re-reading the JSON files each time is very slow.
27
+ let cachedConfig;
28
+ let cachedTargetsFile;
20
29
  export function resolveConfig() {
30
+ cachedConfig ??= buildConfig();
31
+ return cachedConfig;
32
+ }
33
+ function buildConfig() {
21
34
  const defaults = loadDefaultConfig();
22
35
  const user = loadUserConfig();
23
36
  const minCacheSizeMb = user.minCacheSizeMb ?? defaults.minCacheSizeMb;
@@ -40,8 +53,8 @@ export function resolveConfig() {
40
53
  };
41
54
  }
42
55
  function loadTargetsFile() {
43
- const file = fileURLToPath(new URL("../data/targets.json", import.meta.url));
44
- return JSON.parse(readFileSync(file, "utf-8"));
56
+ cachedTargetsFile ??= loadDataFile("targets.json");
57
+ return cachedTargetsFile;
45
58
  }
46
59
  export function resolveCacheNames() {
47
60
  return loadTargetsFile().cacheNames;
@@ -6,3 +6,4 @@ export interface DiskInfo {
6
6
  mountpoint: string;
7
7
  }
8
8
  export declare function getDiskInfo(): DiskInfo[];
9
+ export declare function usedRatio(disk: DiskInfo): number;
@@ -27,3 +27,9 @@ export function getDiskInfo() {
27
27
  }
28
28
  return disks;
29
29
  }
30
+ // Same as df's Capacity column. Dividing by total is wrong on APFS, where every
31
+ // volume reports the whole shared container as its total.
32
+ export function usedRatio(disk) {
33
+ const usable = disk.used + disk.available;
34
+ return usable === 0 ? 0 : disk.used / usable;
35
+ }
@@ -36,7 +36,7 @@ function padEndVis(str, width) {
36
36
  }
37
37
  export function boxTable(headers, rows) {
38
38
  const colWidths = headers.map((h, i) => Math.max(visLen(h), ...rows.map((r) => visLen(r[i] ?? ""))));
39
- const sep = `┼${colWidths.map((w) => "─".repeat(w + 2)).join("┼")}┼`;
39
+ const sep = `├${colWidths.map((w) => "─".repeat(w + 2)).join("┼")}┤`;
40
40
  const top = `┌${colWidths.map((w) => "─".repeat(w + 2)).join("┬")}┐`;
41
41
  const bot = `└${colWidths.map((w) => "─".repeat(w + 2)).join("┴")}┘`;
42
42
  const fmtRow = (cells) => `│${cells.map((c, i) => ` ${padEndVis(c, colWidths[i])} `).join("│")}│`;
@@ -1,4 +1,4 @@
1
- import { readdirSync, statSync } from "node:fs";
1
+ import { lstatSync, readdirSync } 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 = statSync(fullPath);
22
+ stat = lstatSync(fullPath);
23
23
  }
24
24
  catch {
25
25
  continue;
@@ -63,7 +63,11 @@ export function scanDir(root, opts = {}, currentDepth = 0) {
63
63
  return entries;
64
64
  }
65
65
  export function dirSize(dirPath) {
66
- const { blockSize } = resolveConfig();
66
+ return sumDir(dirPath, resolveConfig().blockSize);
67
+ }
68
+ // lstat, not stat: symlinks are not followed, matching du. Following them
69
+ // double-counts linked data and loops forever on a link to a parent folder.
70
+ function sumDir(dirPath, blockSize) {
67
71
  let total = 0;
68
72
  let items;
69
73
  try {
@@ -75,12 +79,12 @@ export function dirSize(dirPath) {
75
79
  for (const name of items) {
76
80
  const fullPath = join(dirPath, name);
77
81
  try {
78
- const stat = statSync(fullPath);
82
+ const stat = lstatSync(fullPath);
79
83
  if (stat.isFile()) {
80
84
  total += stat.blocks * blockSize;
81
85
  }
82
86
  else if (stat.isDirectory()) {
83
- total += dirSize(fullPath);
87
+ total += sumDir(fullPath, blockSize);
84
88
  }
85
89
  }
86
90
  catch { }
@@ -1,4 +1,4 @@
1
- import { existsSync, readdirSync, statSync } from "node:fs";
1
+ import { existsSync, lstatSync, 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";
@@ -68,16 +68,14 @@ export function findWaste() {
68
68
  return results.sort((a, b) => b.size - a.size);
69
69
  }
70
70
  export function findNodeModules(root, maxDepth) {
71
- const depth = maxDepth ?? resolveConfig().nodeModulesMaxDepth;
71
+ const { nodeModulesMaxDepth, opaqueDirectories } = resolveConfig();
72
72
  const results = [];
73
- searchNodeModules(root, results, 0, depth);
73
+ searchNodeModules(root, results, 0, maxDepth ?? nodeModulesMaxDepth, new Set(opaqueDirectories));
74
74
  return results.sort((a, b) => b.size - a.size);
75
75
  }
76
- function searchNodeModules(dir, results, depth, maxDepth) {
76
+ function searchNodeModules(dir, results, depth, maxDepth, opaqueSet) {
77
77
  if (depth > maxDepth)
78
78
  return;
79
- const { opaqueDirectories } = resolveConfig();
80
- const opaqueSet = new Set(opaqueDirectories);
81
79
  let items;
82
80
  try {
83
81
  items = readdirSync(dir);
@@ -105,9 +103,9 @@ function searchNodeModules(dir, results, depth, maxDepth) {
105
103
  if (opaqueSet.has(name))
106
104
  continue;
107
105
  try {
108
- const stat = statSync(fullPath);
106
+ const stat = lstatSync(fullPath);
109
107
  if (stat.isDirectory()) {
110
- searchNodeModules(fullPath, results, depth + 1, maxDepth);
108
+ searchNodeModules(fullPath, results, depth + 1, maxDepth, opaqueSet);
111
109
  }
112
110
  }
113
111
  catch { }
package/package.json CHANGED
@@ -1,7 +1,10 @@
1
1
  {
2
2
  "name": "dustclaw",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Disk space monitoring, analysis, and cleanup CLI",
5
+ "engines": {
6
+ "node": ">=22.12.0"
7
+ },
5
8
  "homepage": "https://github.com/psandis/dustclaw",
6
9
  "type": "module",
7
10
  "repository": {
@@ -13,6 +16,7 @@
13
16
  },
14
17
  "files": [
15
18
  "dist",
19
+ "data",
16
20
  "README.md",
17
21
  "LICENSE",
18
22
  "assets/dustclaw.png"
@@ -37,22 +41,19 @@
37
41
  "license": "MIT",
38
42
  "packageManager": "pnpm@10.12.1",
39
43
  "dependencies": {
40
- "better-sqlite3": "^12.8.0",
41
- "chalk": "^5.6.2",
42
- "commander": "^14.0.3"
44
+ "chalk": "^6.0.1",
45
+ "commander": "^15.0.0"
43
46
  },
44
47
  "pnpm": {
45
48
  "onlyBuiltDependencies": [
46
- "better-sqlite3",
47
49
  "esbuild"
48
50
  ]
49
51
  },
50
52
  "devDependencies": {
51
- "@biomejs/biome": "^2.4.8",
52
- "@types/better-sqlite3": "^7.6.13",
53
- "@types/node": "^25.5.0",
54
- "tsx": "^4.21.0",
55
- "typescript": "^6.0.2",
56
- "vitest": "^4.1.1"
53
+ "@biomejs/biome": "^2.5.15",
54
+ "@types/node": "^26.6.5",
55
+ "tsx": "^4.23.15",
56
+ "typescript": "^7.0.2",
57
+ "vitest": "^5.0.3"
57
58
  }
58
59
  }