dir-analysis-tool 3.3.1 → 3.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -11
- package/dist/cli.js +13 -3
- package/dist/index.d.ts +34 -1
- package/dist/index.js +1 -1
- package/dist/{shared-NtYCFeUO.js → shared-CyXKu5cI.js} +1234 -1099
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -92,6 +92,7 @@ dat explain -g # what a scan skips, and which rule skippe
|
|
|
92
92
|
dat . -b "size<=200MB" -b "duplicates=0" # fail CI when a budget is exceeded
|
|
93
93
|
dat . --html report.html # a self-contained HTML report
|
|
94
94
|
dat . --json | jq '.largestFiles[0]' # machine-readable output
|
|
95
|
+
dat . -d --compact # bounded one-line JSON for scripts and agents
|
|
95
96
|
```
|
|
96
97
|
|
|
97
98
|
## What it shows
|
|
@@ -184,17 +185,18 @@ A size tree (`dat src -t --tree-depth 2`):
|
|
|
184
185
|
|
|
185
186
|
**Output options:**
|
|
186
187
|
|
|
187
|
-
| Option | Description
|
|
188
|
-
| ----------------------- |
|
|
189
|
-
| `-f, --format <format>` | `pretty` (default), `json`, `markdown`, `csv`, or `html`.
|
|
190
|
-
| `-j, --json` | Same as `--format json`.
|
|
191
|
-
|
|
|
192
|
-
|
|
|
193
|
-
| `--
|
|
194
|
-
| `--
|
|
195
|
-
| `--
|
|
196
|
-
| `--no-
|
|
197
|
-
|
|
|
188
|
+
| Option | Description |
|
|
189
|
+
| ----------------------- | -------------------------------------------------------------------------------------- |
|
|
190
|
+
| `-f, --format <format>` | `pretty` (default), `json`, `markdown`, `csv`, or `html`. |
|
|
191
|
+
| `-j, --json` | Same as `--format json`. |
|
|
192
|
+
| `--compact` | One-line JSON with every list cut to `--top` items. See [Compact JSON](#compact-json). |
|
|
193
|
+
| `-o, --output <file>` | Write the report to a file instead of stdout. |
|
|
194
|
+
| `--html [file.html]` | Also write an HTML report. Default name `directory-analysis-<date>.html`. |
|
|
195
|
+
| `--csv [file.csv]` | Also write a CSV export. Default name `directory-analysis.csv`. |
|
|
196
|
+
| `--si` | Decimal units (kB, MB, powers of 1000) instead of binary (KiB, MiB, powers of 1024). |
|
|
197
|
+
| `--color`, `--no-color` | Force colors on or off. `NO_COLOR` and `FORCE_COLOR` are honored. |
|
|
198
|
+
| `--no-progress` | Hide the progress line. It is only ever drawn on an interactive stderr. |
|
|
199
|
+
| `-q, --quiet` | Print only the report and errors. |
|
|
198
200
|
|
|
199
201
|
### `dat compare`
|
|
200
202
|
|
|
@@ -399,6 +401,28 @@ JSON is versioned (`"schemaVersion": 3`). Sizes are raw bytes, dates are ISO 860
|
|
|
399
401
|
}
|
|
400
402
|
```
|
|
401
403
|
|
|
404
|
+
### Compact JSON
|
|
405
|
+
|
|
406
|
+
Large trees can produce very long lists, mostly duplicate groups: 650 KB of JSON for a `node_modules` folder with `-d`. `--compact` (3.4 or later) prints the same document on one line with every list cut to the `--top` value (10 when `--top` is unset or 0), so a script or an agent gets the facts without the bulk. The example above shrinks to 11 KB.
|
|
407
|
+
|
|
408
|
+
- **Totals stay complete.** `summary`, `types`, `budgets`, and every `count`, `bytes`, `files`, and `wastedBytes` are the same as without `--compact`. Only the item lists are shorter, and they keep their order, so each list is the start of the full one.
|
|
409
|
+
- **Cut lists are named.** A top-level `compact` object says what was left out:
|
|
410
|
+
|
|
411
|
+
```jsonc
|
|
412
|
+
"compact": {
|
|
413
|
+
"limit": 10,
|
|
414
|
+
"truncated": true,
|
|
415
|
+
"omitted": { "extensions": 44, "duplicates.items": 1679, "errors": 3 }
|
|
416
|
+
}
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
`omitted` has an entry only for a list that was cut, with the number of items not listed. A duplicate group whose copies were cut also has `omittedFiles`, and `duplicates.items[].files` in `omitted` is the sum. A missing section means its report was off; `count: 0` with `items: []` means nothing was found.
|
|
420
|
+
|
|
421
|
+
- **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`.
|
|
422
|
+
- **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.
|
|
423
|
+
|
|
424
|
+
`--compact` implies `--json` and cannot be combined with another `--format`. Without it, JSON output is unchanged.
|
|
425
|
+
|
|
402
426
|
Optional sections appear only when their report is on: `largeFiles`, `duplicates`, `emptyFiles`, `emptyDirectories`, `staleFiles`, `tree`, and `budgets`.
|
|
403
427
|
|
|
404
428
|
## Configuration
|
|
@@ -469,6 +493,7 @@ await writeFile('report.md', renderAnalysisMarkdown(result));
|
|
|
469
493
|
| ------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
470
494
|
| `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. |
|
|
471
495
|
| `compare(left, right, options?)` | Diff two trees. |
|
|
496
|
+
| `compactAnalysis(result, { limit })` | The `--compact` form of a result: lists cut to `limit`, totals kept, cuts listed in `compact`. Returns a new object. |
|
|
472
497
|
| `listDirectories(path, options?)` | The folders a scan would enter. |
|
|
473
498
|
| `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`. |
|
|
474
499
|
| `renderAnalysis`, `renderAnalysisMarkdown`, `renderAnalysisCsv`, `renderAnalysisHtml` | Render a result in any format. `renderComparison*` does the same for comparisons. |
|
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { C as MAX_EXPLAIN_LIMIT, D as outsideRootError, E as isOutside,
|
|
2
|
+
import { $ as errorMessage, C as MAX_EXPLAIN_LIMIT, D as outsideRootError, E as isOutside, G as parseSize, H as formatBudgetActual, I as Excluder, L as joinRelative, M as analyze, O as compare, P as listDirectories, Q as errorCode, T as explainSkips, U as parseBudget, W as formatBytes, X as AbortError, Y as parsePointInTime, Z as DatError, a as renderComparisonCsv, c as renderAnalysis, d as escapeControlInLines, 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, q as VERSION, r as renderAnalysisHtml, s as renderComparisonMarkdown, t as renderPathExplanation, u as escapeControl, v as loadConfig, w as explainPath } from "./shared-CyXKu5cI.js";
|
|
3
3
|
import { existsSync, watch } from "node:fs";
|
|
4
4
|
import { mkdir, writeFile } from "node:fs/promises";
|
|
5
5
|
import { dirname, join, relative, resolve, sep } from "node:path";
|
|
@@ -716,6 +716,10 @@ function addReportOptions(command) {
|
|
|
716
716
|
function addOutputOptions(command, formats = FORMATS) {
|
|
717
717
|
return command.addOption(option("-f, --format <format>", "output format", OUTPUT_GROUP).choices(formats)).addOption(option("-j, --json", "same as --format json", OUTPUT_GROUP)).addOption(option("-o, --output <file>", "write the report to a file instead of stdout", OUTPUT_GROUP)).addOption(option("--si", "use decimal units (kB, MB) instead of binary (KiB, MiB)", OUTPUT_GROUP)).addOption(option("--color", "force colors", OUTPUT_GROUP)).addOption(option("--no-color", "disable colors (also honors NO_COLOR)", OUTPUT_GROUP)).addOption(option("--no-progress", "hide the progress line", OUTPUT_GROUP)).addOption(option("-q, --quiet", "print only the report and errors", OUTPUT_GROUP));
|
|
718
718
|
}
|
|
719
|
+
/** Bounded JSON for scripts and agents. Analyze only. */
|
|
720
|
+
function addCompactOption(command) {
|
|
721
|
+
return command.addOption(option("--compact", "print one-line JSON with every list cut to --top items (implies --json)", OUTPUT_GROUP));
|
|
722
|
+
}
|
|
719
723
|
/** Legacy file outputs kept from v2: they write a file in addition to the normal output. */
|
|
720
724
|
function addFileReportOptions(command) {
|
|
721
725
|
return command.addOption(option("--html [file]", "also write a self-contained HTML report", OUTPUT_GROUP)).addOption(option("--csv [file]", "also write a CSV export", OUTPUT_GROUP));
|
|
@@ -787,8 +791,12 @@ function resolveAnalyzeOptions(cli, config) {
|
|
|
787
791
|
};
|
|
788
792
|
}
|
|
789
793
|
function resolveDisplay(cli, config) {
|
|
794
|
+
const compact = cli["compact"] === true;
|
|
795
|
+
const requested = FORMATS.find((f) => f === cli["format"]);
|
|
796
|
+
if (compact && requested !== void 0 && requested !== "json") throw new DatError(`--compact prints JSON; remove --format ${requested}.`);
|
|
790
797
|
return {
|
|
791
|
-
format: cli["json"] === true ? "json" :
|
|
798
|
+
format: cli["json"] === true || compact ? "json" : requested ?? "pretty",
|
|
799
|
+
compact,
|
|
792
800
|
output: read.string(cli["output"]),
|
|
793
801
|
units: cli["si"] === true ? "si" : config.units ?? "iec",
|
|
794
802
|
color: read.boolean(cli["color"]),
|
|
@@ -864,6 +872,7 @@ Examples:
|
|
|
864
872
|
enforce budgets in CI (exit code 2 on failure)
|
|
865
873
|
$ dat . -f markdown >> "$GITHUB_STEP_SUMMARY"
|
|
866
874
|
$ dat . --json | jq '.largestFiles[0]'
|
|
875
|
+
$ dat . -d --compact bounded one-line JSON for scripts and agents
|
|
867
876
|
$ dat . --html report.html self-contained HTML report
|
|
868
877
|
`;
|
|
869
878
|
function registerAnalyze(program, ctx) {
|
|
@@ -871,6 +880,7 @@ function registerAnalyze(program, ctx) {
|
|
|
871
880
|
addScanOptions(command);
|
|
872
881
|
addReportOptions(command);
|
|
873
882
|
addOutputOptions(command);
|
|
883
|
+
addCompactOption(command);
|
|
874
884
|
addFileReportOptions(command);
|
|
875
885
|
command.addHelpText("after", EXAMPLES$3);
|
|
876
886
|
command.action(async (directory, _options, cmd) => {
|
|
@@ -909,7 +919,7 @@ async function emit(ctx, result, display, limit) {
|
|
|
909
919
|
}
|
|
910
920
|
let output = display.output;
|
|
911
921
|
if (!output && display.format === "html" && ctx.io.stdout.isTTY) output = `directory-analysis-${today}.html`;
|
|
912
|
-
const text = renderAnalysisAs(display.format, result, {
|
|
922
|
+
const text = display.compact ? stringifyJson(compactAnalysis(result, { limit })) : renderAnalysisAs(display.format, result, {
|
|
913
923
|
style: ctx.outputStyle(display.color, output !== void 0),
|
|
914
924
|
units: display.units,
|
|
915
925
|
width: terminalWidth(ctx.io),
|
package/dist/index.d.ts
CHANGED
|
@@ -66,6 +66,8 @@ export interface DuplicateGroup {
|
|
|
66
66
|
/** Space reclaimable by keeping one copy: `bytes * (files.length - 1)`. */
|
|
67
67
|
wastedBytes: number;
|
|
68
68
|
files: string[];
|
|
69
|
+
/** Copies not listed in `files`; present only on a group cut by compact output. */
|
|
70
|
+
omittedFiles?: number;
|
|
69
71
|
}
|
|
70
72
|
export interface ItemList<T> {
|
|
71
73
|
/** Number of matching items. */
|
|
@@ -172,6 +174,21 @@ export interface AnalysisResult {
|
|
|
172
174
|
budgets?: BudgetResult[];
|
|
173
175
|
/** At most 100 entries; `summary.errors` has the full count. */
|
|
174
176
|
errors: ScanError[];
|
|
177
|
+
/** Present only in compact output (`--compact`, `compactAnalysis`): what was cut. */
|
|
178
|
+
compact?: CompactInfo;
|
|
179
|
+
}
|
|
180
|
+
/** Lists that compact output can cut, named by their JSON path. */
|
|
181
|
+
export type CompactList = "extensions" | "errors" | "largeFiles.items" | "duplicates.items" | "duplicates.items[].files" | "emptyFiles.items" | "emptyDirectories.items" | "staleFiles.items";
|
|
182
|
+
export interface CompactInfo {
|
|
183
|
+
/** Maximum number of items kept in each list. */
|
|
184
|
+
limit: number;
|
|
185
|
+
/** Whether any list was cut. */
|
|
186
|
+
truncated: boolean;
|
|
187
|
+
/**
|
|
188
|
+
* Items not listed, per cut list, in document order. A list that is absent
|
|
189
|
+
* here was not cut. `duplicates.items[].files` is the sum over listed groups.
|
|
190
|
+
*/
|
|
191
|
+
omitted: Partial<Record<CompactList, number>>;
|
|
175
192
|
}
|
|
176
193
|
export interface ChangedFile {
|
|
177
194
|
path: string;
|
|
@@ -314,6 +331,22 @@ type AnalysisProgress = {
|
|
|
314
331
|
* ```
|
|
315
332
|
*/
|
|
316
333
|
export declare function analyze(path: string, options?: AnalyzeOptions): Promise<AnalysisResult>;
|
|
334
|
+
interface CompactOptions {
|
|
335
|
+
/** Maximum number of items kept in each list (a whole number of at least 0). */
|
|
336
|
+
limit: number;
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Bounds every list in an analysis result to `limit` items, for scripts and
|
|
340
|
+
* agents that read the JSON. Counts and sizes stay the full totals; what was
|
|
341
|
+
* cut is listed in `compact.omitted`. Returns a new result and leaves the
|
|
342
|
+
* input untouched.
|
|
343
|
+
*
|
|
344
|
+
* Cut: `extensions`, the `items` of `largeFiles`, `duplicates`, `emptyFiles`,
|
|
345
|
+
* `emptyDirectories`, and `staleFiles`, the `files` of each listed duplicate
|
|
346
|
+
* group, and `errors`. Not cut: `summary`, `types`, `budgets`, and the lists
|
|
347
|
+
* already bounded by `top` or by the tree's own per-folder limit.
|
|
348
|
+
*/
|
|
349
|
+
export declare function compactAnalysis(result: AnalysisResult, options: CompactOptions): AnalysisResult;
|
|
317
350
|
interface CompareOptions extends ScanSettings {
|
|
318
351
|
/** Also compare the contents of same-sized files (SHA-256). Default: `false`, size only. */
|
|
319
352
|
content?: boolean | undefined;
|
|
@@ -656,4 +689,4 @@ export declare function renderPathExplanation(result: PathExplanation, options?:
|
|
|
656
689
|
/** Human-readable summary of everything a scan left out. */
|
|
657
690
|
export declare function renderSkipsExplanation(result: SkipsExplanation, options?: ExplainRenderOptions): string;
|
|
658
691
|
export declare const VERSION: string;
|
|
659
|
-
export type { AnalysisProgress, AnalyzeOptions, Budget, ByteUnits, CompareOptions, DatConfig, ExplainDecision, ExplainEntryType, ExplainGroup, ExplainNote, ExplainNoteCode, ExplainReason, ExplainRenderOptions, ExplainSkipsOptions, ExplainSource, ExplainTotals, LoadedConfig, PathExplanation, PrettyOptions, ScanSettings, SkipsExplanation, Style };
|
|
692
|
+
export type { AnalysisProgress, AnalyzeOptions, Budget, ByteUnits, CompactOptions, CompareOptions, DatConfig, ExplainDecision, ExplainEntryType, ExplainGroup, ExplainNote, ExplainNoteCode, ExplainReason, ExplainRenderOptions, ExplainSkipsOptions, ExplainSource, ExplainTotals, LoadedConfig, PathExplanation, PrettyOptions, ScanSettings, SkipsExplanation, Style };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { X as AbortError, B as BUDGET_METRICS, K as CATEGORIES, g as CONFIG_FILE_NAMES, N as DEFAULT_CONCURRENCY, F as DEFAULT_EXCLUDES, x as DEFAULT_EXPLAIN_LIMIT, A as DEFAULT_LARGE_FILE_THRESHOLD, j as DEFAULT_STALE_AGE, Z as DatError, S as EXPLAIN_VERSION, C as MAX_EXPLAIN_LIMIT, q as VERSION, M as analyze, y as buildJsonSchema, R as classify, k as compactAnalysis, O as compare, m as createStyle, V as evaluateBudgets, w as explainPath, T as explainSkips, z as extensionOf, _ as findConfigFile, W as formatBytes, P as listDirectories, v as loadConfig, U as parseBudget, J as parseDuration, Y as parsePointInTime, G 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-CyXKu5cI.js";
|