dir-analysis-tool 3.5.7 → 3.6.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 +18 -7
- package/dist/cli.js +458 -10
- package/dist/index.d.ts +39 -21
- package/dist/index.js +1 -1
- package/dist/{shared-bXznpAvJ.js → shared-CR5IVm-D.js} +466 -130
- package/package.json +5 -5
- package/report.schema.json +42 -4
package/README.md
CHANGED
|
@@ -233,6 +233,7 @@ A size tree (`dat src -t --tree-depth 2`):
|
|
|
233
233
|
| `--content` | Also compare same-sized files by content, byte by byte, stopping at the first difference. By default, files are compared by size. |
|
|
234
234
|
| `-n, --top <n>` | Items per list. Default `10`; `0` lists no files and keeps the counts. JSON and CSV list every added, removed and changed file; the changed-folders list follows `--top` in every format. |
|
|
235
235
|
| `-f, --format <format>` | `pretty`, `json`, `markdown`, or `csv`. |
|
|
236
|
+
| `--compact` | One-line JSON with the added, removed and changed lists cut to `--top` items (3.6 or later). See [Compact JSON](#compact-json). |
|
|
236
237
|
|
|
237
238
|
All scan options and shared output options above are accepted too; `--html`, `--csv`, and HTML format are analyze-only. Use `--format csv` to export a comparison.
|
|
238
239
|
|
|
@@ -281,7 +282,7 @@ Sizes inside skipped directories are unknown. Measure one with: dat <dir> --all
|
|
|
281
282
|
All scan options are accepted, as are `--si`, `--color`, `--no-color`, `--no-progress`, and `-q`. The path is relative to the current directory and must be inside the root.
|
|
282
283
|
|
|
283
284
|
- **Decisions:** `included`, `excluded` (a default, a pattern, `.gitignore`, or `.git/info/exclude`), `filtered` (size or date), `skipped` (beyond `--max-depth`, a symbolic link that is not followed or, with `-L`, leads nowhere, a socket or device, or an unreadable folder), and `not-found`. The exit code is `0` for all of them, so read `decision`; `1` means an error, such as a path outside the root.
|
|
284
|
-
- **What it cannot know** is said, not guessed. dat never enters an excluded directory, so the size and count below one stay unknown (`descendants` is always `null`). Notes flag a negation that cannot work (`!build/keep/` under an ignored `build/`, `-e '!node_modules'`, or `-e '!x.log'` against a `.gitignore` rule), a scan root that Git ignores, nested repositories, matches that depend on the platform's case-insensitivity, and
|
|
285
|
+
- **What it cannot know** is said, not guessed. dat never enters an excluded directory, so the size and count below one stay unknown (`descendants` is always `null`). Notes flag a negation that cannot work (`!build/keep/` under an ignored `build/`, `-e '!node_modules'`, or `-e '!x.log'` against a `.gitignore` rule), a scan root that Git ignores, nested repositories, matches that depend on the platform's case-insensitivity, and data reached by several paths (hard links, followed symlinks), which is counted once under a fixed path: the real path first, then the path that sorts first. The codes `hardlink-order-dependent` and `symlink-order-dependent` keep their names from before 3.6, when that choice depended on scan order.
|
|
285
286
|
- **Not read:** Git's global excludes file (`core.excludesFile`, usually `~/.config/git/ignore`). Every `-g` explanation inside a repository says so. A `.git` file, which links a worktree or submodule to its repository, is counted as an ordinary file, because default excludes only skip directories.
|
|
286
287
|
- `--max-depth` skips are reported only here (`totals.depthSkipped`); `analyze` does not count them.
|
|
287
288
|
|
|
@@ -298,7 +299,9 @@ dat watch . -j -o report.json # keep report.json up to date
|
|
|
298
299
|
```
|
|
299
300
|
|
|
300
301
|
- **Output.** Without `-o`, each report goes to stdout: pretty reports replace the previous one on a terminal (`--no-clear` keeps them), and JSON reports are printed one per line (NDJSON). With `-o`, the file is rewritten with the latest report on each change, in either format. The report file counts in the analysis like any other file, but writing it never starts a new scan, even inside the watched folder.
|
|
301
|
-
-
|
|
302
|
+
- **Only what changed is read again.** After the first scan, `watch` keeps what each folder contributes (its totals, file types and extensions, its largest files, and its entries in the reports you asked for) and re-reads only the folders a change touched, so a saved file shows up in milliseconds however large the tree is. Every report is still exactly what a full scan would print. With `-d`, only files that changed are hashed again. A full scan happens anyway when a change touches more than 1,000 paths or a tenth of the folders, when a `.gitignore` changes with `-g`, after the watched directory comes back, and at least every 10 minutes while changes keep coming, because file watching can miss events without saying so. With `-L` or a relative date (`--stale 1y`, `--newer-than 30d`), every report is a full scan.
|
|
303
|
+
- **Memory.** The per-folder state takes about 2 KiB per folder, more for folders with many large files in view, and `-d` keeps one record per candidate file. A full scan of the same tree needs neither between reports.
|
|
304
|
+
- **`--poll`.** Polling has no events to go on, so each poll is a full scan, and a new report is printed only when it would differ from the previous one, for any reason: a size, a date, a stale or empty file, a duplicate.
|
|
302
305
|
- **A missing root.** A directory that doesn't exist (or isn't a directory) when `watch` starts is an error: one message, exit code `1`. If the watched directory is deleted later, `watch` says so once and waits; when it comes back, it reports again and resumes watching, on every platform and with `--poll`.
|
|
303
306
|
- **Stopping.** Ctrl+C stops `watch` with exit code `130`, as for every command. It also stops on its own, with exit code `0`, when the reader of its output goes away (`dat watch --json | head -1`).
|
|
304
307
|
|
|
@@ -428,7 +431,13 @@ Large trees can produce very long lists, mostly duplicate groups: 650 KB of JSON
|
|
|
428
431
|
- **Lists that are cut:** `extensions`, the `items` of `largeFiles`, `duplicates`, `emptyFiles`, `emptyDirectories`, and `staleFiles`, the `files` of each listed duplicate group, and `errors` (counted against `summary.errors`). `largestFiles` and `largestDirectories` follow `--top` as always, and the tree keeps its own `omitted`.
|
|
429
432
|
- **Follow up** with a focused scan when you need more: `dat . -d --compact -n 50` for more items, `dat . -d -n 0 --json | jq .duplicates` for one full section, `dat ./assets -d --compact` for a smaller scope, and `dat explain` for what was skipped.
|
|
430
433
|
|
|
431
|
-
|
|
434
|
+
**Comparisons** (3.6 or later). `dat compare <left> <right> --compact` does the same for a comparison: the `items` of `added`, `removed`, and `changed` are cut to the limit, while both sides' `summary` and `types`, `delta`, `unchanged`, and every `count`, `bytes`, and `delta` stay complete. `directories` already follows `--top`. Comparing an empty folder with a `node_modules` folder of 17,412 files gives 3.2 MB of JSON, or 4.5 KB with `--compact`:
|
|
435
|
+
|
|
436
|
+
```jsonc
|
|
437
|
+
"compact": { "limit": 10, "truncated": true, "omitted": { "added.items": 17402 } }
|
|
438
|
+
```
|
|
439
|
+
|
|
440
|
+
`--compact` implies `--json` and cannot be combined with another `--format`. Without it, JSON output is unchanged. It is a flag rather than a config key, so a config file never turns a person's report into JSON.
|
|
432
441
|
|
|
433
442
|
Optional sections appear only when their report is on: `largeFiles`, `duplicates`, `emptyFiles`, `emptyDirectories`, `staleFiles`, `tree`, and `budgets`.
|
|
434
443
|
|
|
@@ -503,6 +512,7 @@ await writeFile('report.md', renderAnalysisMarkdown(result));
|
|
|
503
512
|
| `analyze(path, options?)` | Analyze a tree. Options mirror the CLI flags: `exclude`, `gitignore`, `maxDepth`, `minSize`, `modifiedAfter`, `top`, `largeFiles`, `duplicates`, `empty`, `stale`, `tree`, `budgets`, `concurrency`, `signal`, `onProgress`, and more. |
|
|
504
513
|
| `compare(left, right, options?)` | Diff two trees. |
|
|
505
514
|
| `compactAnalysis(result, { limit })` | The `--compact` form of a result: lists cut to `limit`, totals kept, cuts listed in `compact`. Returns a new object. |
|
|
515
|
+
| `compactComparison(result, { limit })` | The same for a comparison (`compare --compact`): `added`, `removed`, and `changed` items cut to `limit`, totals kept. Returns a new object. |
|
|
506
516
|
| `listDirectories(path, options?)` | The folders a scan would enter. |
|
|
507
517
|
| `explainPath(root, path, options?)`, `explainSkips(root, options?)` | Why a scan counts or skips one path, and everything a scan skips grouped by rule (`limit` caps listed entries). Render with `renderPathExplanation` and `renderSkipsExplanation`. |
|
|
508
518
|
| `renderAnalysis`, `renderAnalysisMarkdown`, `renderAnalysisCsv`, `renderAnalysisHtml` | Render a result in any format. `renderComparison*` does the same for comparisons. |
|
|
@@ -527,15 +537,16 @@ Then ask in your own words, for example "why is this repo so big?" or "fail CI i
|
|
|
527
537
|
|
|
528
538
|
- **Scanning.** Directories are read with `readdir({ withFileTypes })`, so they never need a `stat`, and each regular file is `lstat`ed once. All filesystem calls go through one concurrency limiter (32 operations in flight by default), so no tree, however wide, can exhaust file handles. Work is scheduled depth-first to keep the queue small.
|
|
529
539
|
- **Patterns.** Exclude patterns and `.gitignore` files are compiled by a built-in matcher: consecutive rules become a few regular expressions, and plain names and `*.ext` rules are resolved with hash lookups, reducing pattern-matching overhead without caching results per path. Rules with several wildcards use a matcher whose time grows linearly with the path length, so an unusual `.gitignore` cannot stall a scan.
|
|
530
|
-
- **Memory.** Totals, type and extension statistics, folder sizes, and the top-N lists are computed while scanning; the lists use bounded heaps. Reports you opt into keep only what they match. Duplicate detection keeps one small record per file that shares its size with another.
|
|
540
|
+
- **Memory.** Totals, type and extension statistics, folder sizes, and the top-N lists are computed while scanning; the lists use bounded heaps. Reports you opt into keep only what they match. Duplicate detection keeps one small record per file that shares its size with another. A file with several hard links (and, with `-L`, one reached through a symlink) is held as a small record until the walk ends, so it can be counted under a fixed path.
|
|
531
541
|
- **Largest folders.** Folders are ranked by the total size below them. A folder whose size comes almost entirely (95% or more) from one subfolder is folded into that subfolder, so the list points to where the data actually lives instead of repeating every parent.
|
|
532
542
|
- **Duplicates,** in stages so most files are never read in full:
|
|
533
543
|
1. Only sizes shared by at least two files are considered. Empty files are excluded, and hard links to the same data are not copies.
|
|
534
544
|
2. Files over 256 KiB are compared by a SHA-256 sample of their first and last 64 KiB.
|
|
535
545
|
3. Remaining candidates are hashed in full: small files in a single read, large files streamed through reusable buffers. A stage with 4,096 files or more is hashed by up to four worker threads (no more than the CPU cores less one), each with one reusable buffer, so SHA-256 runs in parallel; the results are the same as on the main thread. Each size group is finished as soon as its last file is hashed, so intermediate hash maps are retained only for groups in flight; candidates and results still use memory proportional to their count.
|
|
536
546
|
- **Comparing contents.** `dat compare --content` reads each pair of same-size files side by side, in 256 KiB chunks through a fixed set of reusable buffers, and stops at the first byte that differs. No hash is computed, and the comparison itself uses a fixed amount of memory however large the files are.
|
|
547
|
+
- **Watching.** `dat watch` keeps a collector per folder and builds each report by merging them with the same code a full scan uses, so the two can't drift apart. A change re-reads the folders it touched and scans any new subfolder; hard links are counted once, under the link whose path sorts first.
|
|
537
548
|
- **Disk usage.** Sizes are apparent sizes (file lengths). `On disk` is the space allocated in blocks, which is what `du` reports.
|
|
538
|
-
- **Determinism.** Results are sorted by size and then by path, so the same tree always produces the same output, whatever order the filesystem returned it in. Equal sizes are ordered by comparing paths where they first differ, without building them, so deep trees full of same-size files rank them as fast as shallow ones.
|
|
549
|
+
- **Determinism.** Results are sorted by size and then by path, so the same tree always produces the same output, whatever order the filesystem returned it in. Data that several paths lead to is counted once under a fixed path: a hard-linked file under the link whose path sorts first, and with `-L` a folder or file through its real path when there is one, otherwise through the symlink whose path sorts first (3.6 or later; before, the first path the scan reached). Equal sizes are ordered by comparing paths where they first differ, without building them, so deep trees full of same-size files rank them as fast as shallow ones.
|
|
539
550
|
|
|
540
551
|
**Benchmarks** (Apple M4, warm cache, best of three; measurements from the optimization work, not performance guarantees). On the Linux kernel source tree, 96,127 files and 1.53 GiB:
|
|
541
552
|
|
|
@@ -546,7 +557,7 @@ Then ask in your own words, for example "why is this repo so big?" or "fail CI i
|
|
|
546
557
|
| Scan and find duplicates | 2.64 s | **1.20 s** | |
|
|
547
558
|
| Peak heap while finding duplicates | 118 MB | **45 MB** | |
|
|
548
559
|
|
|
549
|
-
On a synthetic tree of 1,000,000 files, v3.1 scans in 8.9 s where `du -s` takes 13 s. On a 500-level chain of folders holding 2,000 files of one size, 3.5.5 scans in 44 ms where 3.5.4 took 90 ms (Linux in Docker on the same M4, median of nine), the same as with the largest-files list turned off. In a 93,000-file, 1.7 GiB project folder where 92% of the files share their size with another, 3.5.6 finds duplicates in 0.91 s where 3.5.5 took 2.2 s (Linux in Docker), and in 1.22 s where it took 1.50 s on macOS, where file-system calls are the limit; `dat compare --content` of that folder against a copy takes 3.5 s where it took 6.0 s (Linux). Compared with v2.0.7 on a 140,237-file tree, v3 scans about 3× faster and finds duplicates about 4× faster, with identical results. Run `pnpm bench` (or `pnpm bench <directory>`) to measure on your machine.
|
|
560
|
+
On a synthetic tree of 1,000,000 files, v3.1 scans in 8.9 s where `du -s` takes 13 s. On a 500-level chain of folders holding 2,000 files of one size, 3.5.5 scans in 44 ms where 3.5.4 took 90 ms (Linux in Docker on the same M4, median of nine), the same as with the largest-files list turned off. In a 93,000-file, 1.7 GiB project folder where 92% of the files share their size with another, 3.5.6 finds duplicates in 0.91 s where 3.5.5 took 2.2 s (Linux in Docker), and in 1.22 s where it took 1.50 s on macOS, where file-system calls are the limit; `dat compare --content` of that folder against a copy takes 3.5 s where it took 6.0 s (Linux). In 300,000 files, `dat watch` prints the report for a saved file 11–20 ms after the write, where re-scanning the tree took 1.2–1.4 s (Linux in Docker). Compared with v2.0.7 on a 140,237-file tree, v3 scans about 3× faster and finds duplicates about 4× faster, with identical results. Run `pnpm bench` (or `pnpm bench <directory>`) to measure on your machine.
|
|
550
561
|
|
|
551
562
|
The benchmark script reports scan and duplicate timings plus process peak RSS (not JavaScript heap). Results vary with storage, cache state, tree shape, and Node.js version. `du` measures allocated disk space and does not produce the same reports.
|
|
552
563
|
|
|
@@ -594,7 +605,7 @@ v3 is a rewrite with a new output format. Most commands keep working unchanged.
|
|
|
594
605
|
|
|
595
606
|
**Why does the total differ from `du`?** `du` reports blocks allocated on disk, while the headline size is the sum of file lengths. The `On disk` line matches `du`. Also check what was skipped: `.git` and `node_modules` are excluded by default (`--all` includes them), and hard-linked data is counted once, as `du` does. `dat explain` lists everything a scan skipped and why.
|
|
596
607
|
|
|
597
|
-
**Is it safe to run on a huge directory?** Yes. The default scan keeps bounded top-N file lists, but folder metadata, hard-link tracking, and symlink tracking still require memory. Duplicate detection, directory comparisons, and optional file lists use additional memory (duplicate detection on thousands of files also starts up to four worker threads, a fixed few megabytes each), filesystem concurrency is bounded, and unreadable paths are reported rather than fatal. Press Ctrl+C at any time.
|
|
608
|
+
**Is it safe to run on a huge directory?** Yes. The default scan keeps bounded top-N file lists, but folder metadata, hard-link tracking, and symlink tracking still require memory. Duplicate detection, directory comparisons, and optional file lists use additional memory (duplicate detection on thousands of files also starts up to four worker threads, a fixed few megabytes each, and `dat watch` keeps about 2 KiB per folder between reports), filesystem concurrency is bounded, and unreadable paths are reported rather than fatal. Press Ctrl+C at any time.
|
|
598
609
|
|
|
599
610
|
**Does it modify anything?** `dat` reads the scanned files. It writes report files when requested, and `dat init` writes a configuration file.
|
|
600
611
|
|