dir-analysis-tool 3.5.2 → 3.5.4
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 +25 -25
- package/dist/cli.js +101 -25
- package/dist/index.d.ts +7 -2
- package/dist/index.js +1 -1
- package/dist/{shared-CwIrKaAV.js → shared-c7R0EX5i.js} +41 -16
- package/package.json +1 -1
- package/report.schema.json +8 -0
package/README.md
CHANGED
|
@@ -186,18 +186,18 @@ A size tree (`dat src -t --tree-depth 2`):
|
|
|
186
186
|
|
|
187
187
|
**Output options:**
|
|
188
188
|
|
|
189
|
-
| Option | Description
|
|
190
|
-
| ----------------------- |
|
|
191
|
-
| `-f, --format <format>` | `pretty` (default), `json`, `markdown`, `csv`, or `html`.
|
|
192
|
-
| `-j, --json` | Same as `--format json`.
|
|
193
|
-
| `--compact` | One-line JSON with every list cut to `--top` items. See [Compact JSON](#compact-json).
|
|
194
|
-
| `-o, --output <file>` | Write the report to a file instead of stdout.
|
|
195
|
-
| `--html [file.html]` | Also write an HTML report. Default name `directory-analysis-<date>.html`.
|
|
196
|
-
| `--csv [file.csv]` | Also write a CSV export. Default name `directory-analysis.csv`.
|
|
197
|
-
| `--si` | Decimal units (kB, MB, powers of 1000) instead of binary (KiB, MiB, powers of 1024).
|
|
198
|
-
| `--color`, `--no-color` | Force colors on or off. `NO_COLOR` and `FORCE_COLOR` are honored.
|
|
199
|
-
| `--no-progress` | Hide the progress line. It is only ever drawn on an interactive stderr.
|
|
200
|
-
| `-q, --quiet` | Print only the report and errors.
|
|
189
|
+
| Option | Description |
|
|
190
|
+
| ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
191
|
+
| `-f, --format <format>` | `pretty` (default), `json`, `markdown`, `csv`, or `html`. |
|
|
192
|
+
| `-j, --json` | Same as `--format json`. |
|
|
193
|
+
| `--compact` | One-line JSON with every list cut to `--top` items. See [Compact JSON](#compact-json). |
|
|
194
|
+
| `-o, --output <file>` | Write the report to a file instead of stdout. Missing folders are created. A path that can't be written (a directory, a read-only folder) is an error before the scan starts, as for `--html` and `--csv`. |
|
|
195
|
+
| `--html [file.html]` | Also write an HTML report. Default name `directory-analysis-<date>.html`. |
|
|
196
|
+
| `--csv [file.csv]` | Also write a CSV export. Default name `directory-analysis.csv`. |
|
|
197
|
+
| `--si` | Decimal units (kB, MB, powers of 1000) instead of binary (KiB, MiB, powers of 1024). |
|
|
198
|
+
| `--color`, `--no-color` | Force colors on or off. `NO_COLOR` and `FORCE_COLOR` are honored. |
|
|
199
|
+
| `--no-progress` | Hide the progress line. It is only ever drawn on an interactive stderr. |
|
|
200
|
+
| `-q, --quiet` | Print only the report and errors. |
|
|
201
201
|
|
|
202
202
|
### `dat compare`
|
|
203
203
|
|
|
@@ -228,11 +228,11 @@ A size tree (`dat src -t --tree-depth 2`):
|
|
|
228
228
|
2 files unchanged (compared by size)
|
|
229
229
|
```
|
|
230
230
|
|
|
231
|
-
| Option | Description
|
|
232
|
-
| ----------------------- |
|
|
233
|
-
| `--content` | Also compare same-sized files by content (SHA-256). By default, files are compared by size.
|
|
234
|
-
| `-n, --top <n>` | Items per list. Default `10
|
|
235
|
-
| `-f, --format <format>` | `pretty`, `json`, `markdown`, or `csv`.
|
|
231
|
+
| Option | Description |
|
|
232
|
+
| ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
233
|
+
| `--content` | Also compare same-sized files by content (SHA-256). By default, files are compared by size. |
|
|
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
|
+
| `-f, --format <format>` | `pretty`, `json`, `markdown`, or `csv`. |
|
|
236
236
|
|
|
237
237
|
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
238
|
|
|
@@ -253,7 +253,7 @@ build/keep/k.txt: excluded
|
|
|
253
253
|
Note Git's global excludes file (core.excludesFile, usually ~/.config/git/ignore) is not read; Git may ignore more than dat does.
|
|
254
254
|
```
|
|
255
255
|
|
|
256
|
-
Without a path, it runs one scan and groups everything left out by the rule that skipped it: default excludes, each exclude pattern, each `.gitignore` line, size and date filters, `--max-depth`, and symbolic links that were not followed. Counts are complete and equal `summary.excluded` and `summary.filtered` from `analyze`; each group lists its first 20 entries in path order.
|
|
256
|
+
Without a path, it runs one scan and groups everything left out by the rule that skipped it: default excludes, each exclude pattern, each `.gitignore` line, size and date filters, `--max-depth`, and symbolic links that were not followed. With `-L`, links that can't be followed are grouped by why: `ENOENT` (the target is missing) or `ELOOP` (the link loops); they count in `summary.symlinks`, not in `errors`, and the group's `code` field says which. Counts are complete and equal `summary.excluded` and `summary.filtered` from `analyze`; each group lists its first 20 entries in path order.
|
|
257
257
|
|
|
258
258
|
```text
|
|
259
259
|
$ dat explain -g
|
|
@@ -280,7 +280,7 @@ Sizes inside skipped directories are unknown. Measure one with: dat <dir> --all
|
|
|
280
280
|
|
|
281
281
|
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
282
|
|
|
283
|
-
- **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, 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.
|
|
283
|
+
- **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
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 counts that depend on scan order (hard links, followed symlinks).
|
|
285
285
|
- **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
286
|
- `--max-depth` skips are reported only here (`totals.depthSkipped`); `analyze` does not count them.
|
|
@@ -551,12 +551,12 @@ The benchmark script reports scan and duplicate timings plus process peak RSS (n
|
|
|
551
551
|
|
|
552
552
|
## Exit codes
|
|
553
553
|
|
|
554
|
-
| Code | Meaning
|
|
555
|
-
| ----- |
|
|
556
|
-
| `0` | Success, including every `dat explain` decision
|
|
557
|
-
| `1` | Error: invalid option or config, missing directory, and so on |
|
|
558
|
-
| `2` | A budget failed
|
|
559
|
-
| `130` | Interrupted (Ctrl+C), including stopping `dat watch`
|
|
554
|
+
| Code | Meaning |
|
|
555
|
+
| ----- | -------------------------------------------------------------------------------------------------- |
|
|
556
|
+
| `0` | Success, including every `dat explain` decision |
|
|
557
|
+
| `1` | Error: invalid option or config, missing directory, a report file that can't be written, and so on |
|
|
558
|
+
| `2` | A budget failed |
|
|
559
|
+
| `130` | Interrupted (Ctrl+C), including stopping `dat watch` |
|
|
560
560
|
|
|
561
561
|
A reader that stops early (`dat . --json | head`) doesn't change the exit code: a failed budget still exits `2`.
|
|
562
562
|
|
package/dist/cli.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { $ as errorCode, C as MAX_EXPLAIN_LIMIT, D as outsideRootError, E as isOutside, F as listDirectories, G as formatBytes, J as VERSION, K as parseSize, L as Excluder, M as analyze, O as compare, P as assertDirectory, Q as DatError, R as joinRelative, T as explainSkips, U as formatBudgetActual, W as parseBudget, X as parsePointInTime, Z as AbortError, a as renderComparisonCsv, c as renderAnalysis, d as escapeControlInLines, et as errorMessage, f as formatCount, h as supportsColor, i as renderAnalysisCsv, k as compactAnalysis, l as renderComparison, m as createStyle, n as renderSkipsExplanation, o as renderAnalysisMarkdown, p as stringifyJson, r as renderAnalysisHtml, s as renderComparisonMarkdown, t as renderPathExplanation, u as escapeControl, v as loadConfig, w as explainPath } from "./shared-
|
|
3
|
-
import { existsSync, watch } from "node:fs";
|
|
4
|
-
import { mkdir, realpath, stat, writeFile } from "node:fs/promises";
|
|
2
|
+
import { $ as errorCode, C as MAX_EXPLAIN_LIMIT, D as outsideRootError, E as isOutside, F as listDirectories, G as formatBytes, J as VERSION, K as parseSize, L as Excluder, M as analyze, O as compare, P as assertDirectory, Q as DatError, R as joinRelative, T as explainSkips, U as formatBudgetActual, W as parseBudget, X as parsePointInTime, Z as AbortError, a as renderComparisonCsv, c as renderAnalysis, d as escapeControlInLines, et as errorMessage, f as formatCount, h as supportsColor, i as renderAnalysisCsv, k as compactAnalysis, l as renderComparison, m as createStyle, n as renderSkipsExplanation, o as renderAnalysisMarkdown, p as stringifyJson, r as renderAnalysisHtml, s as renderComparisonMarkdown, t as renderPathExplanation, u as escapeControl, v as loadConfig, w as explainPath } from "./shared-c7R0EX5i.js";
|
|
3
|
+
import { constants, existsSync, watch } from "node:fs";
|
|
4
|
+
import { access, mkdir, realpath, stat, writeFile } from "node:fs/promises";
|
|
5
5
|
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
6
6
|
import { createInterface } from "node:readline";
|
|
7
7
|
// src/cli/io.ts
|
|
@@ -920,6 +920,7 @@ function registerAnalyze(program, ctx) {
|
|
|
920
920
|
const { config } = await ctx.loadConfig(cli, target);
|
|
921
921
|
const display = resolveDisplay(cli, config);
|
|
922
922
|
const options = resolveAnalyzeOptions(cli, config);
|
|
923
|
+
await checkOutputs(ctx, display);
|
|
923
924
|
const result = await runAnalysis(ctx, target, options, display);
|
|
924
925
|
await emit(ctx, result, display, listLimit(options.top));
|
|
925
926
|
reportBudgets(ctx, result, display);
|
|
@@ -937,18 +938,34 @@ async function runAnalysis(ctx, target, options, display) {
|
|
|
937
938
|
progress.clear();
|
|
938
939
|
}
|
|
939
940
|
}
|
|
940
|
-
|
|
941
|
+
/** The files a run writes, with the name each error message uses. */
|
|
942
|
+
function outputFiles(ctx, display) {
|
|
941
943
|
const today = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
944
|
+
const output = display.output ?? (display.format === "html" && ctx.io.stdout.isTTY ? `directory-analysis-${today}.html` : void 0);
|
|
945
|
+
return {
|
|
946
|
+
...display.html ? { html: display.html === true ? `directory-analysis-${today}.html` : display.html } : {},
|
|
947
|
+
...display.csv ? { csv: display.csv === true ? "directory-analysis.csv" : display.csv } : {},
|
|
948
|
+
...output ? { output } : {}
|
|
949
|
+
};
|
|
950
|
+
}
|
|
951
|
+
/** Fails before the scan when a report file can't be written, instead of after it. */
|
|
952
|
+
async function checkOutputs(ctx, display) {
|
|
953
|
+
const files = outputFiles(ctx, display);
|
|
954
|
+
if (files.html) await ctx.checkOutput(files.html, "the HTML report");
|
|
955
|
+
if (files.csv) await ctx.checkOutput(files.csv, "the CSV export");
|
|
956
|
+
if (files.output) await ctx.checkOutput(files.output);
|
|
957
|
+
}
|
|
958
|
+
async function emit(ctx, result, display, limit) {
|
|
959
|
+
const files = outputFiles(ctx, display);
|
|
960
|
+
if (files.html) {
|
|
961
|
+
const file = await ctx.writeFile(files.html, renderAnalysisHtml(result, { units: display.units }), "the HTML report");
|
|
962
|
+
ctx.info(`${ctx.err.green("✔")} HTML report written to ${ctx.displayPath(file)}`, display.quiet);
|
|
945
963
|
}
|
|
946
|
-
if (
|
|
947
|
-
const file = await ctx.writeFile(
|
|
948
|
-
ctx.info(`${ctx.err.green("✔")} CSV written to ${displayPath(
|
|
964
|
+
if (files.csv) {
|
|
965
|
+
const file = await ctx.writeFile(files.csv, renderAnalysisCsv(result), "the CSV export");
|
|
966
|
+
ctx.info(`${ctx.err.green("✔")} CSV written to ${ctx.displayPath(file)}`, display.quiet);
|
|
949
967
|
}
|
|
950
|
-
|
|
951
|
-
if (!output && display.format === "html" && ctx.io.stdout.isTTY) output = `directory-analysis-${today}.html`;
|
|
968
|
+
const output = files.output;
|
|
952
969
|
const text = display.compact ? stringifyJson(compactAnalysis(result, { limit })) : renderAnalysisAs(display.format, result, {
|
|
953
970
|
style: ctx.outputStyle(display.color, output !== void 0),
|
|
954
971
|
units: display.units,
|
|
@@ -959,7 +976,7 @@ async function emit(ctx, result, display, limit) {
|
|
|
959
976
|
});
|
|
960
977
|
if (output) {
|
|
961
978
|
const file = await ctx.writeFile(output, text);
|
|
962
|
-
ctx.info(`${ctx.err.green("✔")} Report written to ${displayPath(
|
|
979
|
+
ctx.info(`${ctx.err.green("✔")} Report written to ${ctx.displayPath(file)}`, display.quiet);
|
|
963
980
|
} else await ctx.stdout(text.endsWith("\n") ? text : `${text}\n`);
|
|
964
981
|
}
|
|
965
982
|
function reportBudgets(ctx, result, display) {
|
|
@@ -972,10 +989,6 @@ function reportBudgets(ctx, result, display) {
|
|
|
972
989
|
ctx.io.stderr.write(`${ctx.err.red("budget failed")} ${budget.rule} (actual ${actual})\n`);
|
|
973
990
|
}
|
|
974
991
|
}
|
|
975
|
-
function displayPath(ctx, file) {
|
|
976
|
-
const rel = relative(ctx.io.cwd, file);
|
|
977
|
-
return escapeControl(rel && !rel.startsWith("..") ? rel : file);
|
|
978
|
-
}
|
|
979
992
|
/** Items printed per list: the --top value, or 10 when the top lists are turned off. */
|
|
980
993
|
function listLimit(top) {
|
|
981
994
|
return top !== void 0 && top > 0 ? top : 10;
|
|
@@ -991,7 +1004,7 @@ Examples:
|
|
|
991
1004
|
function registerCompare(program, ctx) {
|
|
992
1005
|
const command = program.command("compare").description("compare two directories: added, removed, and changed files, and size changes").argument("<left>", "the baseline directory").argument("<right>", "the directory to compare against the baseline");
|
|
993
1006
|
addScanOptions(command);
|
|
994
|
-
command.addOption(new Option("--content", "compare same-size files by content (SHA-256)").helpGroup("Report options:")).addOption(new Option("-n, --top <n>", "items per list (default: 10)").argParser(integer(0)).helpGroup("Report options:"));
|
|
1007
|
+
command.addOption(new Option("--content", "compare same-size files by content (SHA-256)").helpGroup("Report options:")).addOption(new Option("-n, --top <n>", "items per list (default: 10; 0 lists none); JSON and CSV list every file").argParser(integer(0)).helpGroup("Report options:"));
|
|
995
1008
|
addOutputOptions(command, [
|
|
996
1009
|
"pretty",
|
|
997
1010
|
"json",
|
|
@@ -1004,6 +1017,7 @@ function registerCompare(program, ctx) {
|
|
|
1004
1017
|
const { config } = await ctx.loadConfig(cli, ctx.io.cwd);
|
|
1005
1018
|
const display = resolveDisplay(cli, config);
|
|
1006
1019
|
const top = read.number(cli["top"]) ?? config.top;
|
|
1020
|
+
if (display.output) await ctx.checkOutput(display.output);
|
|
1007
1021
|
const progress = new ProgressLine(ctx.io.stderr, display.progress && ctx.io.stderr.isTTY === true, ctx.err, display.units);
|
|
1008
1022
|
let result;
|
|
1009
1023
|
try {
|
|
@@ -1021,13 +1035,13 @@ function registerCompare(program, ctx) {
|
|
|
1021
1035
|
style: ctx.outputStyle(display.color, display.output !== void 0),
|
|
1022
1036
|
units: display.units,
|
|
1023
1037
|
width: terminalWidth(ctx.io),
|
|
1024
|
-
limit:
|
|
1038
|
+
limit: top ?? 10,
|
|
1025
1039
|
types: display.types,
|
|
1026
1040
|
extensions: false
|
|
1027
1041
|
});
|
|
1028
1042
|
if (display.output) {
|
|
1029
1043
|
const file = await ctx.writeFile(display.output, text);
|
|
1030
|
-
ctx.info(`${ctx.err.green("✔")} Comparison written to ${
|
|
1044
|
+
ctx.info(`${ctx.err.green("✔")} Comparison written to ${ctx.displayPath(file)}`, display.quiet);
|
|
1031
1045
|
} else await ctx.stdout(text.endsWith("\n") ? text : `${text}\n`);
|
|
1032
1046
|
});
|
|
1033
1047
|
}
|
|
@@ -1232,7 +1246,9 @@ var Prompter = class {
|
|
|
1232
1246
|
const SCHEMA_URL = "https://unpkg.com/dir-analysis-tool@3/schema.json";
|
|
1233
1247
|
function registerInit(program, ctx) {
|
|
1234
1248
|
program.command("init").description("create a .dir-analyzer.json config file").argument("[directory]", "where to create the file", ".").addOption(new Option("-y, --yes", "skip the questions and write a starter config")).addOption(new Option("--force", "overwrite an existing config file")).action(async (directory, options) => {
|
|
1235
|
-
const
|
|
1249
|
+
const folder = ctx.resolvePath(directory);
|
|
1250
|
+
if (await isFile(folder)) throw new DatError(`dat init: ${ctx.displayPath(folder)} is not a directory`);
|
|
1251
|
+
const path = join(folder, ".dir-analyzer.json");
|
|
1236
1252
|
const exists = existsSync(path);
|
|
1237
1253
|
if (exists && !options.force && (options.yes || !ctx.io.stdinIsTTY)) throw new DatError(`${path} already exists.`, { hint: "Use --force to overwrite it." });
|
|
1238
1254
|
let config;
|
|
@@ -1249,7 +1265,7 @@ function registerInit(program, ctx) {
|
|
|
1249
1265
|
const file = await ctx.writeFile(path, `${JSON.stringify({
|
|
1250
1266
|
$schema: SCHEMA_URL,
|
|
1251
1267
|
...config
|
|
1252
|
-
}, null, 4)}\n
|
|
1268
|
+
}, null, 4)}\n`, "the config file");
|
|
1253
1269
|
ctx.info(`${ctx.err.green("✔")} Wrote ${escapeControl(file)}`, false);
|
|
1254
1270
|
});
|
|
1255
1271
|
}
|
|
@@ -1346,6 +1362,10 @@ function validateWith(value, parse) {
|
|
|
1346
1362
|
return errorMessage(error);
|
|
1347
1363
|
}
|
|
1348
1364
|
}
|
|
1365
|
+
/** True when `path` exists and is not a directory (dat init creates a missing one). */
|
|
1366
|
+
async function isFile(path) {
|
|
1367
|
+
return stat(path).then((stats) => !stats.isDirectory(), () => false);
|
|
1368
|
+
}
|
|
1349
1369
|
// src/cli/watcher.ts
|
|
1350
1370
|
/**
|
|
1351
1371
|
* Watches a directory tree with the platform's native facility.
|
|
@@ -1443,6 +1463,11 @@ function registerWatch(program, ctx) {
|
|
|
1443
1463
|
const clear = cli["clear"] !== false && display.format === "pretty" && ctx.io.stdout.isTTY === true;
|
|
1444
1464
|
const signal = ctx.io.signal;
|
|
1445
1465
|
await assertDirectory(target);
|
|
1466
|
+
await checkOutputs(ctx, {
|
|
1467
|
+
...display,
|
|
1468
|
+
html: void 0,
|
|
1469
|
+
csv: void 0
|
|
1470
|
+
});
|
|
1446
1471
|
let previous = null;
|
|
1447
1472
|
let previousKey = "";
|
|
1448
1473
|
let running = false;
|
|
@@ -1691,12 +1716,36 @@ var Context = class {
|
|
|
1691
1716
|
for (const warning of loaded.warnings) this.warn(warning);
|
|
1692
1717
|
return loaded;
|
|
1693
1718
|
}
|
|
1694
|
-
|
|
1719
|
+
/** A path for messages: relative to the working directory when inside it, escaped. */
|
|
1720
|
+
displayPath(file) {
|
|
1721
|
+
const rel = relative(this.io.cwd, file);
|
|
1722
|
+
return escapeControl(rel && !rel.startsWith("..") ? rel : file);
|
|
1723
|
+
}
|
|
1724
|
+
/**
|
|
1725
|
+
* Fails before any work starts when `path` can't be written: it is a directory, a parent is a
|
|
1726
|
+
* file, or the folder is read-only. Creates nothing. `what` names the file in the message.
|
|
1727
|
+
*/
|
|
1728
|
+
async checkOutput(path, what = "the report") {
|
|
1729
|
+
const absolute = this.resolvePath(path);
|
|
1730
|
+
const problem = await outputProblem(absolute, (p) => this.displayPath(p));
|
|
1731
|
+
if (problem) throw this.#outputError(absolute, what, problem);
|
|
1732
|
+
}
|
|
1733
|
+
async writeFile(path, content, what = "the report") {
|
|
1695
1734
|
const absolute = this.resolvePath(path);
|
|
1696
|
-
|
|
1697
|
-
|
|
1735
|
+
try {
|
|
1736
|
+
await mkdir(dirname(absolute), { recursive: true });
|
|
1737
|
+
await writeFile(absolute, content);
|
|
1738
|
+
} catch (error) {
|
|
1739
|
+
const problem = await outputProblem(absolute, (p) => this.displayPath(p)) ?? errorMessage(error);
|
|
1740
|
+
throw this.#outputError(absolute, what, problem);
|
|
1741
|
+
}
|
|
1698
1742
|
return absolute;
|
|
1699
1743
|
}
|
|
1744
|
+
#outputError(absolute, what, problem) {
|
|
1745
|
+
const shown = this.displayPath(absolute);
|
|
1746
|
+
const hint = problem === "it is a directory" ? `Give a file name, for example ${shown}${sep}${exampleName(what)}.` : void 0;
|
|
1747
|
+
return new DatError(`Cannot write ${what} to ${shown}: ${problem}`, hint ? { hint } : {});
|
|
1748
|
+
}
|
|
1700
1749
|
stdout(text) {
|
|
1701
1750
|
return write(this.io.stdout, text);
|
|
1702
1751
|
}
|
|
@@ -1705,6 +1754,33 @@ var Context = class {
|
|
|
1705
1754
|
return isClosed(this.io.stdout);
|
|
1706
1755
|
}
|
|
1707
1756
|
};
|
|
1757
|
+
/** Why `file` can't be written, or null when it can (as far as can be told without writing). */
|
|
1758
|
+
async function outputProblem(file, show) {
|
|
1759
|
+
try {
|
|
1760
|
+
if ((await stat(file)).isDirectory()) return "it is a directory";
|
|
1761
|
+
return await writable(file) ? null : "permission denied";
|
|
1762
|
+
} catch (error) {
|
|
1763
|
+
const code = errorCode(error);
|
|
1764
|
+
if (code === "EACCES" || code === "EPERM") return "permission denied";
|
|
1765
|
+
if (code !== "ENOENT" && code !== "ENOTDIR") return errorMessage(error);
|
|
1766
|
+
}
|
|
1767
|
+
for (let dir = dirname(file);; dir = dirname(dir)) try {
|
|
1768
|
+
if (!(await stat(dir)).isDirectory()) return `${show(dir)} is not a directory`;
|
|
1769
|
+
return await writable(dir) ? null : "permission denied";
|
|
1770
|
+
} catch (error) {
|
|
1771
|
+
const code = errorCode(error);
|
|
1772
|
+
if (code !== "ENOENT" && code !== "ENOTDIR") return code === "EACCES" || code === "EPERM" ? "permission denied" : errorMessage(error);
|
|
1773
|
+
if (dirname(dir) === dir) return null;
|
|
1774
|
+
}
|
|
1775
|
+
}
|
|
1776
|
+
async function writable(path) {
|
|
1777
|
+
return access(path, constants.W_OK).then(() => true, () => false);
|
|
1778
|
+
}
|
|
1779
|
+
function exampleName(what) {
|
|
1780
|
+
if (what.includes("HTML")) return "report.html";
|
|
1781
|
+
if (what.includes("CSV")) return "report.csv";
|
|
1782
|
+
return "report.txt";
|
|
1783
|
+
}
|
|
1708
1784
|
// src/cli/program.ts
|
|
1709
1785
|
function createProgram(ctx) {
|
|
1710
1786
|
const { io } = ctx;
|
package/dist/index.d.ts
CHANGED
|
@@ -222,15 +222,18 @@ export interface ComparisonResult {
|
|
|
222
222
|
files: number;
|
|
223
223
|
directories: number;
|
|
224
224
|
};
|
|
225
|
+
/** Every added file, whatever `top` is; the CLI cuts only pretty and Markdown output. */
|
|
225
226
|
added: ItemList<FileEntry>;
|
|
227
|
+
/** Every removed file, whatever `top` is. */
|
|
226
228
|
removed: ItemList<FileEntry>;
|
|
229
|
+
/** Every changed file, whatever `top` is. */
|
|
227
230
|
changed: {
|
|
228
231
|
count: number;
|
|
229
232
|
delta: number;
|
|
230
233
|
items: ChangedFile[];
|
|
231
234
|
};
|
|
232
235
|
unchanged: number;
|
|
233
|
-
/**
|
|
236
|
+
/** At most `top` directories with the largest size change, largest absolute change first. */
|
|
234
237
|
directories: DirectoryDelta[];
|
|
235
238
|
}
|
|
236
239
|
interface DuplicateProgress {
|
|
@@ -472,6 +475,8 @@ interface ExplainGroup {
|
|
|
472
475
|
rule: string | null;
|
|
473
476
|
index: number | null;
|
|
474
477
|
limit: number | string | null;
|
|
478
|
+
/** `symlink` with followSymlinks: `ENOENT` (target missing) or `ELOOP` (a loop); else `null`. */
|
|
479
|
+
code: string | null;
|
|
475
480
|
count: number;
|
|
476
481
|
/** The first entries in path order, at most `limit` of them. */
|
|
477
482
|
entries: string[];
|
|
@@ -642,7 +647,7 @@ interface PrettyOptions {
|
|
|
642
647
|
units?: ByteUnits;
|
|
643
648
|
/** Terminal width used to fit paths. Default: 100. */
|
|
644
649
|
width?: number;
|
|
645
|
-
/** Maximum items printed per list. Default: 10. */
|
|
650
|
+
/** Maximum items printed per list. Default: 10. A comparison lists none with 0. */
|
|
646
651
|
limit?: number;
|
|
647
652
|
/** Show the file type breakdown. Default: true. */
|
|
648
653
|
types?: boolean;
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { Z as AbortError, V as BUDGET_METRICS, q as CATEGORIES, g as CONFIG_FILE_NAMES, N as DEFAULT_CONCURRENCY, I as DEFAULT_EXCLUDES, x as DEFAULT_EXPLAIN_LIMIT, A as DEFAULT_LARGE_FILE_THRESHOLD, j as DEFAULT_STALE_AGE, Q as DatError, S as EXPLAIN_VERSION, C as MAX_EXPLAIN_LIMIT, J as VERSION, M as analyze, y as buildJsonSchema, z as classify, k as compactAnalysis, O as compare, m as createStyle, H as evaluateBudgets, w as explainPath, T as explainSkips, B as extensionOf, _ as findConfigFile, G as formatBytes, F as listDirectories, v as loadConfig, W as parseBudget, Y as parseDuration, X as parsePointInTime, K as parseSize, c as renderAnalysis, i as renderAnalysisCsv, r as renderAnalysisHtml, o as renderAnalysisMarkdown, l as renderComparison, a as renderComparisonCsv, s as renderComparisonMarkdown, t as renderPathExplanation, n as renderSkipsExplanation, b as validateConfig } from "./shared-
|
|
1
|
+
export { Z as AbortError, V as BUDGET_METRICS, q as CATEGORIES, g as CONFIG_FILE_NAMES, N as DEFAULT_CONCURRENCY, I as DEFAULT_EXCLUDES, x as DEFAULT_EXPLAIN_LIMIT, A as DEFAULT_LARGE_FILE_THRESHOLD, j as DEFAULT_STALE_AGE, Q as DatError, S as EXPLAIN_VERSION, C as MAX_EXPLAIN_LIMIT, J as VERSION, M as analyze, y as buildJsonSchema, z as classify, k as compactAnalysis, O as compare, m as createStyle, H as evaluateBudgets, w as explainPath, T as explainSkips, B as extensionOf, _ as findConfigFile, G as formatBytes, F as listDirectories, v as loadConfig, W as parseBudget, Y as parseDuration, X as parsePointInTime, K as parseSize, c as renderAnalysis, i as renderAnalysisCsv, r as renderAnalysisHtml, o as renderAnalysisMarkdown, l as renderComparison, a as renderComparisonCsv, s as renderComparisonMarkdown, t as renderPathExplanation, n as renderSkipsExplanation, b as validateConfig } from "./shared-c7R0EX5i.js";
|
|
@@ -1000,6 +1000,12 @@ var Scanner = class {
|
|
|
1000
1000
|
const code = errorCode(error);
|
|
1001
1001
|
if (isSymlink && (code === "ENOENT" || code === "ELOOP")) {
|
|
1002
1002
|
this.counters.symlinks++;
|
|
1003
|
+
this.#options.onSkip?.({
|
|
1004
|
+
kind: "broken-symlink",
|
|
1005
|
+
dir: dirIndex,
|
|
1006
|
+
name,
|
|
1007
|
+
code
|
|
1008
|
+
});
|
|
1003
1009
|
return;
|
|
1004
1010
|
}
|
|
1005
1011
|
this.recordError(this.relativePath(dirIndex, name), error);
|
|
@@ -2357,7 +2363,7 @@ var Collector = class {
|
|
|
2357
2363
|
if (this.#scanner.dirs[dir].depth < features.tree.depth) {
|
|
2358
2364
|
let heap = this.#treeFiles.get(dir);
|
|
2359
2365
|
if (!heap) {
|
|
2360
|
-
heap = new TopK(features.tree.limit, (a, b) => a.name
|
|
2366
|
+
heap = new TopK(features.tree.limit, (a, b) => comparePaths(a.name, b.name));
|
|
2361
2367
|
this.#treeFiles.set(dir, heap);
|
|
2362
2368
|
}
|
|
2363
2369
|
if (heap.accepts(bytes)) heap.push(bytes, makeRef());
|
|
@@ -2452,7 +2458,7 @@ var Collector = class {
|
|
|
2452
2458
|
extensions: [...this.#extensions].map(([extension, stat]) => ({
|
|
2453
2459
|
extension,
|
|
2454
2460
|
...stat
|
|
2455
|
-
})).sort((a, b) => b.bytes - a.bytes || b.files - a.files || a.extension
|
|
2461
|
+
})).sort((a, b) => b.bytes - a.bytes || b.files - a.files || comparePaths(a.extension, b.extension)),
|
|
2456
2462
|
largestDirectories: this.#largestDirectories(scanner),
|
|
2457
2463
|
largestFiles: this.#topFiles.sorted().map(toEntry),
|
|
2458
2464
|
errors: [...scanner.errors].sort((a, b) => comparePaths(a.path, b.path))
|
|
@@ -2533,7 +2539,7 @@ var Collector = class {
|
|
|
2533
2539
|
};
|
|
2534
2540
|
}
|
|
2535
2541
|
});
|
|
2536
|
-
candidates.sort((a, b) => b.bytes - a.bytes || a.key
|
|
2542
|
+
candidates.sort((a, b) => b.bytes - a.bytes || comparePaths(a.key, b.key));
|
|
2537
2543
|
const shown = candidates.slice(0, limit);
|
|
2538
2544
|
result.children = shown.map((c) => c.build());
|
|
2539
2545
|
const omittedEntries = (subdirs?.length ?? 0) + node.ownFiles - shown.length;
|
|
@@ -3416,7 +3422,8 @@ async function explainSkips(root, options = {}) {
|
|
|
3416
3422
|
line: null,
|
|
3417
3423
|
rule: null,
|
|
3418
3424
|
index: null,
|
|
3419
|
-
limit: null
|
|
3425
|
+
limit: null,
|
|
3426
|
+
code: null
|
|
3420
3427
|
});
|
|
3421
3428
|
let scanner = null;
|
|
3422
3429
|
const onSkip = (event) => {
|
|
@@ -3474,6 +3481,12 @@ async function explainSkips(root, options = {}) {
|
|
|
3474
3481
|
case "symlink":
|
|
3475
3482
|
groupFor("symlink", () => base("symlink")).add(rel);
|
|
3476
3483
|
return;
|
|
3484
|
+
case "broken-symlink":
|
|
3485
|
+
groupFor(`symlink\0${event.code}`, () => ({
|
|
3486
|
+
...base("symlink"),
|
|
3487
|
+
code: event.code
|
|
3488
|
+
})).add(rel);
|
|
3489
|
+
return;
|
|
3477
3490
|
}
|
|
3478
3491
|
};
|
|
3479
3492
|
scanner = new Scanner({
|
|
@@ -3500,7 +3513,7 @@ async function explainSkips(root, options = {}) {
|
|
|
3500
3513
|
count: sample.count,
|
|
3501
3514
|
entries: sample.items,
|
|
3502
3515
|
truncated: sample.count > sample.items.length
|
|
3503
|
-
})).toSorted((a, b) => b.count - a.count || SOURCE_ORDER.indexOf(a.source) - SOURCE_ORDER.indexOf(b.source) || comparePaths(a.file ?? "", b.file ?? "") || (a.line ?? 0) - (b.line ?? 0) || (a.index ?? 0) - (b.index ?? 0) || comparePaths(a.rule ?? "", b.rule ?? ""));
|
|
3516
|
+
})).toSorted((a, b) => b.count - a.count || SOURCE_ORDER.indexOf(a.source) - SOURCE_ORDER.indexOf(b.source) || comparePaths(a.file ?? "", b.file ?? "") || (a.line ?? 0) - (b.line ?? 0) || (a.index ?? 0) - (b.index ?? 0) || comparePaths(a.rule ?? "", b.rule ?? "") || comparePaths(a.code ?? "", b.code ?? ""));
|
|
3504
3517
|
return {
|
|
3505
3518
|
explainVersion: 1,
|
|
3506
3519
|
root: absRoot,
|
|
@@ -4180,6 +4193,8 @@ function renderTree(r, root) {
|
|
|
4180
4193
|
function renderComparison(result, options = {}) {
|
|
4181
4194
|
const r = new Renderer(options);
|
|
4182
4195
|
const { s } = r;
|
|
4196
|
+
const limit = Math.max(0, options.limit ?? 10);
|
|
4197
|
+
const more = (shown, total) => limit === 0 ? r.more(0, total, `${total === 1 ? "file" : "files"} not listed (--top 0)`) : r.more(shown, total);
|
|
4183
4198
|
const signed = (n) => n > 0 ? s.green(`+${r.bytes(n)}`) : n < 0 ? s.red(r.bytes(n)) : s.dim("±0");
|
|
4184
4199
|
const signedCount = (n) => n > 0 ? s.green(`+${formatCount(n)}`) : n < 0 ? s.red(`-${formatCount(-n)}`) : s.dim("±0");
|
|
4185
4200
|
const pct = (left, right) => {
|
|
@@ -4212,22 +4227,22 @@ function renderComparison(result, options = {}) {
|
|
|
4212
4227
|
const fileSection = (title, list, mark) => {
|
|
4213
4228
|
if (list.count === 0) return;
|
|
4214
4229
|
r.heading(title, `${plural(list.count, "file")} · ${r.bytes(list.bytes)}`);
|
|
4215
|
-
for (const f of list.items.slice(0,
|
|
4216
|
-
|
|
4230
|
+
for (const f of list.items.slice(0, limit)) r.line(` ${mark} ${r.size(f.bytes)} ${fitPath(f.path, r.room(17))}`);
|
|
4231
|
+
more(Math.min(limit, list.items.length), list.count);
|
|
4217
4232
|
};
|
|
4218
4233
|
fileSection("Added", result.added, s.green("+"));
|
|
4219
4234
|
fileSection("Removed", result.removed, s.red("-"));
|
|
4220
4235
|
if (result.changed.count > 0) {
|
|
4221
4236
|
r.heading("Changed", `${plural(result.changed.count, "file")} · ${result.changed.delta > 0 ? "+" : ""}${formatBytes(result.changed.delta, r.units)} net`);
|
|
4222
|
-
for (const c of result.changed.items.slice(0,
|
|
4237
|
+
for (const c of result.changed.items.slice(0, limit)) {
|
|
4223
4238
|
const detail = c.delta === 0 ? "content" : `${r.bytes(c.leftBytes)} → ${r.bytes(c.rightBytes)}`;
|
|
4224
4239
|
r.line(` ${s.yellow("~")} ${padStartVisible(signed(c.delta), SIZE_WIDTH)} ${fitPath(c.path, r.room(19 + detail.length))} ${s.dim(detail)}`);
|
|
4225
4240
|
}
|
|
4226
|
-
|
|
4241
|
+
more(Math.min(limit, result.changed.items.length), result.changed.count);
|
|
4227
4242
|
}
|
|
4228
4243
|
if (result.directories.length > 0) {
|
|
4229
4244
|
r.heading("Folders that changed most");
|
|
4230
|
-
for (const d of result.directories.slice(0,
|
|
4245
|
+
for (const d of result.directories.slice(0, limit)) r.line(` ${padStartVisible(signed(d.delta), 12)} ${fitPath(`${d.path}/`, r.room(17))}`);
|
|
4231
4246
|
}
|
|
4232
4247
|
r.line("");
|
|
4233
4248
|
const identical = result.added.count + result.removed.count + result.changed.count === 0;
|
|
@@ -4426,16 +4441,22 @@ function renderComparisonMarkdown(result, options = {}) {
|
|
|
4426
4441
|
"r",
|
|
4427
4442
|
"r"
|
|
4428
4443
|
]));
|
|
4444
|
+
const notListed = (count) => {
|
|
4445
|
+
if (limit > 0) return false;
|
|
4446
|
+
out.push(`<sub>${plural(count, "file")} not listed (--top 0)</sub>`);
|
|
4447
|
+
return true;
|
|
4448
|
+
};
|
|
4429
4449
|
const section = (title, list) => {
|
|
4430
4450
|
if (list.count === 0) return;
|
|
4431
4451
|
out.push("", `### ${title}: ${plural(list.count, "file")}, ${b(list.bytes)}`, "");
|
|
4452
|
+
if (notListed(list.count)) return;
|
|
4432
4453
|
out.push(...table(["Size", "Path"], list.items.slice(0, limit).map((f) => [b(f.bytes), mdCode(f.path)]), ["r", "l"]));
|
|
4433
4454
|
if (list.count > limit) out.push("", `<sub>…and ${formatCount(list.count - limit)} more</sub>`);
|
|
4434
4455
|
};
|
|
4435
4456
|
section("Added", result.added);
|
|
4436
4457
|
section("Removed", result.removed);
|
|
4437
|
-
if (result.changed.count > 0) {
|
|
4438
|
-
|
|
4458
|
+
if (result.changed.count > 0) out.push("", `### Changed: ${plural(result.changed.count, "file")}, ${signed(result.changed.delta)} net`, "");
|
|
4459
|
+
if (result.changed.count > 0 && !notListed(result.changed.count)) {
|
|
4439
4460
|
out.push(...table([
|
|
4440
4461
|
"Change",
|
|
4441
4462
|
"Path",
|
|
@@ -4856,7 +4877,7 @@ function ruleLabel(group, units) {
|
|
|
4856
4877
|
case "size": return `${flagOf(group.rule)} ${sizeOf(group.limit, units)}`;
|
|
4857
4878
|
case "date": return `${flagOf(group.rule)} ${String(group.limit)}`;
|
|
4858
4879
|
case "max-depth": return `--max-depth ${String(group.limit)}`;
|
|
4859
|
-
case "symlink": return "symbolic links (not followed)"
|
|
4880
|
+
case "symlink": return group.code === null ? "symbolic links (not followed)" : group.code === "ELOOP" ? `symbolic links in a loop (${group.code})` : `symbolic links to nothing (${escapeControl(group.code)})`;
|
|
4860
4881
|
case "special-file": return "special files";
|
|
4861
4882
|
case "error": return "unreadable";
|
|
4862
4883
|
case "unknown": return "no single rule identified";
|
|
@@ -4888,7 +4909,7 @@ function reasonLines(reason, units, s) {
|
|
|
4888
4909
|
rows.push(["Rule", `--max-depth ${String(reason.limit)}; ${at} is at depth ${String(reason.actual)}`]);
|
|
4889
4910
|
break;
|
|
4890
4911
|
case "symlink":
|
|
4891
|
-
rows.push(["Rule", reason.code ? `symbolic link to nothing (${reason.code}); counted, not followed` : "symbolic link; counted, not followed (use -L to follow)"]);
|
|
4912
|
+
rows.push(["Rule", reason.code === "ELOOP" ? `symbolic link in a loop (${reason.code}); counted, not followed` : reason.code ? `symbolic link to nothing (${escapeControl(reason.code)}); counted, not followed` : "symbolic link; counted, not followed (use -L to follow)"]);
|
|
4892
4913
|
break;
|
|
4893
4914
|
case "special-file":
|
|
4894
4915
|
rows.push(["Rule", "special file (socket, FIFO, or device); never counted"]);
|
|
@@ -4938,8 +4959,11 @@ function renderSkipsExplanation(result, options = {}) {
|
|
|
4938
4959
|
if (totals.excluded > 0) parts.push(`${plural(totals.excluded, "entry", "entries")} excluded`);
|
|
4939
4960
|
if (totals.filtered > 0) parts.push(`${plural(totals.filtered, "file")} filtered`);
|
|
4940
4961
|
if (totals.depthSkipped > 0) parts.push(`${plural(totals.depthSkipped, "directory", "directories")} beyond --max-depth`);
|
|
4941
|
-
const
|
|
4962
|
+
const links = result.groups.filter((g) => g.source === "symlink");
|
|
4963
|
+
const unfollowed = links.find((g) => g.code === null)?.count ?? 0;
|
|
4964
|
+
const broken = links.reduce((sum, g) => sum + (g.code === null ? 0 : g.count), 0);
|
|
4942
4965
|
if (unfollowed > 0) parts.push(`${plural(unfollowed, "symbolic link")} not followed`);
|
|
4966
|
+
if (broken > 0) parts.push(plural(broken, "broken symbolic link"));
|
|
4943
4967
|
if (totals.errors > 0) parts.push(`${plural(totals.errors, "entry", "entries")} unreadable`);
|
|
4944
4968
|
const lines = [];
|
|
4945
4969
|
lines.push(parts.length > 0 ? s.bold(`Skipped: ${parts.join(", ")}`) : s.bold("Nothing was skipped: every entry is counted."));
|
|
@@ -4962,7 +4986,8 @@ function renderSkipsExplanation(result, options = {}) {
|
|
|
4962
4986
|
for (const error of result.errors) lines.push(` ${fitPath(error.path, width - 20)} ${s.dim(error.code)}`);
|
|
4963
4987
|
}
|
|
4964
4988
|
const notes = result.notes.map(noteText);
|
|
4965
|
-
|
|
4989
|
+
const skipsDirectories = (g) => g.source !== "size" && g.source !== "date" && !(g.source === "symlink" && g.code !== null);
|
|
4990
|
+
if (result.groups.some(skipsDirectories)) notes.push("Sizes inside skipped directories are unknown. Measure one with: dat <dir> --all");
|
|
4966
4991
|
if (notes.length > 0) {
|
|
4967
4992
|
lines.push("");
|
|
4968
4993
|
for (const note of notes) lines.push(s.dim(note));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dir-analysis-tool",
|
|
3
|
-
"version": "3.5.
|
|
3
|
+
"version": "3.5.4",
|
|
4
4
|
"description": "Fast, zero-dependency directory analysis for your terminal and CI: largest folders and files, type and extension breakdowns, staged duplicate detection, size budgets, directory diffs, and self-contained HTML, Markdown, JSON, and CSV reports.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
package/report.schema.json
CHANGED
|
@@ -739,12 +739,15 @@
|
|
|
739
739
|
}
|
|
740
740
|
},
|
|
741
741
|
"added": {
|
|
742
|
+
"description": "Every added file, whatever --top is.",
|
|
742
743
|
"$ref": "#/$defs/fileList"
|
|
743
744
|
},
|
|
744
745
|
"removed": {
|
|
746
|
+
"description": "Every removed file, whatever --top is.",
|
|
745
747
|
"$ref": "#/$defs/fileList"
|
|
746
748
|
},
|
|
747
749
|
"changed": {
|
|
750
|
+
"description": "Every changed file, whatever --top is.",
|
|
748
751
|
"type": "object",
|
|
749
752
|
"required": ["count", "delta", "items"],
|
|
750
753
|
"properties": {
|
|
@@ -785,6 +788,7 @@
|
|
|
785
788
|
"minimum": 0
|
|
786
789
|
},
|
|
787
790
|
"directories": {
|
|
791
|
+
"description": "At most --top folders with the largest size change; none with --top 0.",
|
|
788
792
|
"type": "array",
|
|
789
793
|
"items": {
|
|
790
794
|
"type": "object",
|
|
@@ -1008,6 +1012,10 @@
|
|
|
1008
1012
|
"limit": {
|
|
1009
1013
|
"type": ["number", "string", "null"]
|
|
1010
1014
|
},
|
|
1015
|
+
"code": {
|
|
1016
|
+
"type": ["string", "null"],
|
|
1017
|
+
"description": "For a symlink group with --follow-symlinks: ENOENT (the target is missing) or ELOOP (the link loops). Null otherwise. Added in 3.5.4."
|
|
1018
|
+
},
|
|
1011
1019
|
"count": {
|
|
1012
1020
|
"type": "integer",
|
|
1013
1021
|
"minimum": 0
|