dir-analysis-tool 3.5.2 → 3.5.3
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 +23 -23
- package/dist/cli.js +101 -25
- package/dist/index.d.ts +5 -2
- package/dist/index.js +1 -1
- package/dist/{shared-CwIrKaAV.js → shared-BJ-V9aTZ.js} +15 -7
- package/package.json +1 -1
- package/report.schema.json +4 -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
|
|
|
@@ -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-BJ-V9aTZ.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 {
|
|
@@ -642,7 +645,7 @@ interface PrettyOptions {
|
|
|
642
645
|
units?: ByteUnits;
|
|
643
646
|
/** Terminal width used to fit paths. Default: 100. */
|
|
644
647
|
width?: number;
|
|
645
|
-
/** Maximum items printed per list. Default: 10. */
|
|
648
|
+
/** Maximum items printed per list. Default: 10. A comparison lists none with 0. */
|
|
646
649
|
limit?: number;
|
|
647
650
|
/** Show the file type breakdown. Default: true. */
|
|
648
651
|
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-BJ-V9aTZ.js";
|
|
@@ -4180,6 +4180,8 @@ function renderTree(r, root) {
|
|
|
4180
4180
|
function renderComparison(result, options = {}) {
|
|
4181
4181
|
const r = new Renderer(options);
|
|
4182
4182
|
const { s } = r;
|
|
4183
|
+
const limit = Math.max(0, options.limit ?? 10);
|
|
4184
|
+
const more = (shown, total) => limit === 0 ? r.more(0, total, `${total === 1 ? "file" : "files"} not listed (--top 0)`) : r.more(shown, total);
|
|
4183
4185
|
const signed = (n) => n > 0 ? s.green(`+${r.bytes(n)}`) : n < 0 ? s.red(r.bytes(n)) : s.dim("±0");
|
|
4184
4186
|
const signedCount = (n) => n > 0 ? s.green(`+${formatCount(n)}`) : n < 0 ? s.red(`-${formatCount(-n)}`) : s.dim("±0");
|
|
4185
4187
|
const pct = (left, right) => {
|
|
@@ -4212,22 +4214,22 @@ function renderComparison(result, options = {}) {
|
|
|
4212
4214
|
const fileSection = (title, list, mark) => {
|
|
4213
4215
|
if (list.count === 0) return;
|
|
4214
4216
|
r.heading(title, `${plural(list.count, "file")} · ${r.bytes(list.bytes)}`);
|
|
4215
|
-
for (const f of list.items.slice(0,
|
|
4216
|
-
|
|
4217
|
+
for (const f of list.items.slice(0, limit)) r.line(` ${mark} ${r.size(f.bytes)} ${fitPath(f.path, r.room(17))}`);
|
|
4218
|
+
more(Math.min(limit, list.items.length), list.count);
|
|
4217
4219
|
};
|
|
4218
4220
|
fileSection("Added", result.added, s.green("+"));
|
|
4219
4221
|
fileSection("Removed", result.removed, s.red("-"));
|
|
4220
4222
|
if (result.changed.count > 0) {
|
|
4221
4223
|
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,
|
|
4224
|
+
for (const c of result.changed.items.slice(0, limit)) {
|
|
4223
4225
|
const detail = c.delta === 0 ? "content" : `${r.bytes(c.leftBytes)} → ${r.bytes(c.rightBytes)}`;
|
|
4224
4226
|
r.line(` ${s.yellow("~")} ${padStartVisible(signed(c.delta), SIZE_WIDTH)} ${fitPath(c.path, r.room(19 + detail.length))} ${s.dim(detail)}`);
|
|
4225
4227
|
}
|
|
4226
|
-
|
|
4228
|
+
more(Math.min(limit, result.changed.items.length), result.changed.count);
|
|
4227
4229
|
}
|
|
4228
4230
|
if (result.directories.length > 0) {
|
|
4229
4231
|
r.heading("Folders that changed most");
|
|
4230
|
-
for (const d of result.directories.slice(0,
|
|
4232
|
+
for (const d of result.directories.slice(0, limit)) r.line(` ${padStartVisible(signed(d.delta), 12)} ${fitPath(`${d.path}/`, r.room(17))}`);
|
|
4231
4233
|
}
|
|
4232
4234
|
r.line("");
|
|
4233
4235
|
const identical = result.added.count + result.removed.count + result.changed.count === 0;
|
|
@@ -4426,16 +4428,22 @@ function renderComparisonMarkdown(result, options = {}) {
|
|
|
4426
4428
|
"r",
|
|
4427
4429
|
"r"
|
|
4428
4430
|
]));
|
|
4431
|
+
const notListed = (count) => {
|
|
4432
|
+
if (limit > 0) return false;
|
|
4433
|
+
out.push(`<sub>${plural(count, "file")} not listed (--top 0)</sub>`);
|
|
4434
|
+
return true;
|
|
4435
|
+
};
|
|
4429
4436
|
const section = (title, list) => {
|
|
4430
4437
|
if (list.count === 0) return;
|
|
4431
4438
|
out.push("", `### ${title}: ${plural(list.count, "file")}, ${b(list.bytes)}`, "");
|
|
4439
|
+
if (notListed(list.count)) return;
|
|
4432
4440
|
out.push(...table(["Size", "Path"], list.items.slice(0, limit).map((f) => [b(f.bytes), mdCode(f.path)]), ["r", "l"]));
|
|
4433
4441
|
if (list.count > limit) out.push("", `<sub>…and ${formatCount(list.count - limit)} more</sub>`);
|
|
4434
4442
|
};
|
|
4435
4443
|
section("Added", result.added);
|
|
4436
4444
|
section("Removed", result.removed);
|
|
4437
|
-
if (result.changed.count > 0) {
|
|
4438
|
-
|
|
4445
|
+
if (result.changed.count > 0) out.push("", `### Changed: ${plural(result.changed.count, "file")}, ${signed(result.changed.delta)} net`, "");
|
|
4446
|
+
if (result.changed.count > 0 && !notListed(result.changed.count)) {
|
|
4439
4447
|
out.push(...table([
|
|
4440
4448
|
"Change",
|
|
4441
4449
|
"Path",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dir-analysis-tool",
|
|
3
|
-
"version": "3.5.
|
|
3
|
+
"version": "3.5.3",
|
|
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",
|