dir-analysis-tool 3.4.1 → 3.5.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 +35 -7
- package/dist/cli.js +61 -12
- package/dist/index.d.ts +8 -3
- package/dist/index.js +1 -1
- package/dist/{shared-CyXKu5cI.js → shared-zG-LAgcd.js} +53 -12
- package/package.json +5 -2
- package/report.schema.json +1117 -0
- package/schema.json +5 -5
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<div align="center">
|
|
2
2
|
|
|
3
3
|
<a href="https://www.npmjs.com/package/dir-analysis-tool">
|
|
4
|
-
<img src=".github/assets/dir-analysis-tool-banner.png" alt="dir-analysis-tool: fast, memory-bounded directory analysis for your terminal and CI" width="100%" />
|
|
4
|
+
<img src="https://raw.githubusercontent.com/KhaledSaeed18/dir-analysis-tool/main/.github/assets/dir-analysis-tool-banner.png" alt="dir-analysis-tool: fast, memory-bounded directory analysis for your terminal and CI" width="100%" />
|
|
5
5
|
</a>
|
|
6
6
|
|
|
7
7
|
<h1>dir-analysis-tool</h1>
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
<a href="https://www.npmjs.com/package/dir-analysis-tool"><img src="https://shieldcn.dev/npm/dw/dir-analysis-tool.svg" alt="npm downloads" /></a>
|
|
14
14
|
<a href="https://github.com/KhaledSaeed18/dir-analysis-tool/actions/workflows/ci.yml"><img src="https://shieldcn.dev/github/ci/KhaledSaeed18/dir-analysis-tool.svg" alt="CI status" /></a>
|
|
15
15
|
<a href="https://www.npmjs.com/package/dir-analysis-tool"><img src="https://shieldcn.dev/npm/types/dir-analysis-tool.svg" alt="TypeScript types" /></a>
|
|
16
|
-
<a href="LICENSE"><img src="https://shieldcn.dev/npm/license/dir-analysis-tool.svg?variant=secondary" alt="License: MIT" /></a>
|
|
16
|
+
<a href="https://github.com/KhaledSaeed18/dir-analysis-tool/blob/main/LICENSE"><img src="https://shieldcn.dev/npm/license/dir-analysis-tool.svg?variant=secondary" alt="License: MIT" /></a>
|
|
17
17
|
</p>
|
|
18
18
|
|
|
19
19
|
<p>
|
|
@@ -55,6 +55,7 @@ npx dir-analysis-tool
|
|
|
55
55
|
- [Agent skill](#agent-skill)
|
|
56
56
|
- [How it works](#how-it-works)
|
|
57
57
|
- [Exit codes](#exit-codes)
|
|
58
|
+
- [Stability](#stability)
|
|
58
59
|
- [Migrating from v2](#migrating-from-v2)
|
|
59
60
|
- [FAQ](#faq)
|
|
60
61
|
|
|
@@ -318,7 +319,7 @@ All scan, report, and output options are accepted too (`pretty` and `json` forma
|
|
|
318
319
|
| `1.5M`, `1.5MiB` | 1.5 × 1,024² bytes |
|
|
319
320
|
| `10kB`, `500MB`, `1GB` | Decimal: 10,000, 500,000,000, and 1,000,000,000 bytes |
|
|
320
321
|
|
|
321
|
-
**Ages and dates:** an age counts back from now (`45s`, `30min`, `12h`, `90d`, `2w`, `6mo`, `1y`). A date is `YYYY-MM-DD` in local time, or
|
|
322
|
+
**Ages and dates:** an age counts back from now (`45s`, `30min`, `12h`, `90d`, `2w`, `6mo`, `1y`) and always needs a unit: `--stale 12` is an error, not 12 months. A date is `YYYY-MM-DD` in local time, or an ISO 8601 timestamp such as `2024-01-31T10:00:00Z` (local time without an offset). Nothing else is read as a date.
|
|
322
323
|
|
|
323
324
|
**Patterns** use [gitignore syntax](https://git-scm.com/docs/gitignore#_pattern_format) relative to the analyzed directory: `*.log` matches at any depth, `build/` matches only directories, `/out` matches only at the top, `docs/**/*.pdf` matches nested files, and `!keep.log` re-includes a file that an earlier pattern in the same list excluded. A negation cannot re-include a file inside an excluded folder, a default exclude such as `node_modules` (use `--all`), or a file that `.gitignore` excludes, because exclude patterns are checked first. `dat explain <path>` shows which rule decided.
|
|
324
325
|
|
|
@@ -363,7 +364,7 @@ A GitHub Actions step that posts a report to the job summary and enforces a budg
|
|
|
363
364
|
|
|
364
365
|
Only the report goes to stdout. Progress, warnings, and status messages go to stderr, so `dat . --json > out.json` and pipes always get clean data.
|
|
365
366
|
|
|
366
|
-
JSON is versioned (`"schemaVersion": 3`). Sizes are raw bytes, dates are ISO 8601, and paths are relative to `root` with `/` separators on every platform.
|
|
367
|
+
JSON is versioned (`"schemaVersion": 3`). Sizes are raw bytes, dates are ISO 8601, and paths are relative to `root` with `/` separators on every platform. Every field is described by a JSON Schema that ships in the package as `dir-analysis-tool/report.schema.json` ([view it](https://unpkg.com/dir-analysis-tool@3/report.schema.json)), covering `analyze`, `compare`, `explain`, and compact output, and by the [types](https://github.com/KhaledSaeed18/dir-analysis-tool/blob/main/src/types.ts). In short:
|
|
367
368
|
|
|
368
369
|
```jsonc
|
|
369
370
|
{
|
|
@@ -464,6 +465,8 @@ The `$schema` line gives you autocompletion and validation in most editors. Ever
|
|
|
464
465
|
| `units` | `"iec"` or `"si"` | `"iec"` | `--si` |
|
|
465
466
|
| `budgets` | `string[]` | `[]` | `--budget` |
|
|
466
467
|
|
|
468
|
+
A size without a unit is bytes in the config, as in the table above: `"largeFiles": 15` is 15 bytes, while `-l 15` on the command line still means 15 MiB, as it did in v2. Write the unit (`"largeFiles": "15MiB"`); dat warns about a `largeFiles` without a unit below 1 MiB, and `dat init` asks for a unit.
|
|
469
|
+
|
|
467
470
|
Invalid values stop the run with a precise message. Unknown keys produce a warning. Config files from v1 and v2 still work: their keys are translated, with a deprecation warning.
|
|
468
471
|
|
|
469
472
|
## Library API
|
|
@@ -512,7 +515,7 @@ An official [Agent Skill](https://agentskills.io) lets coding agents such as Cla
|
|
|
512
515
|
npx skills add KhaledSaeed18/dir-analysis-tool --skill dir-analysis-tool
|
|
513
516
|
```
|
|
514
517
|
|
|
515
|
-
Then ask in your own words, for example "why is this repo so big?" or "fail CI if `dist` goes over 2 MB". See [skills/README.md](skills/README.md) for other ways to install it, tested agents, and the evals.
|
|
518
|
+
Then ask in your own words, for example "why is this repo so big?" or "fail CI if `dist` goes over 2 MB". See [skills/README.md](https://github.com/KhaledSaeed18/dir-analysis-tool/blob/main/skills/README.md) for other ways to install it, tested agents, and the evals.
|
|
516
519
|
|
|
517
520
|
## How it works
|
|
518
521
|
|
|
@@ -549,6 +552,18 @@ The benchmark script reports scan and duplicate timings plus process peak RSS (n
|
|
|
549
552
|
| `2` | A budget failed |
|
|
550
553
|
| `130` | Interrupted (Ctrl+C) |
|
|
551
554
|
|
|
555
|
+
A reader that stops early (`dat . --json | head`) doesn't change the exit code: a failed budget still exits `2`.
|
|
556
|
+
|
|
557
|
+
## Stability
|
|
558
|
+
|
|
559
|
+
dir-analysis-tool follows semantic versioning, and these hold for every 3.x release:
|
|
560
|
+
|
|
561
|
+
- **Commands, options and exit codes.** Commands, options, budget metrics, config keys and exit codes stay as they are. New ones may be added, and old spellings that still work keep working.
|
|
562
|
+
- **JSON.** `schemaVersion` stays `3`, and `dat explain --json` keeps `explainVersion: 1`. Fields are only added, never removed, renamed or given a new type, and [`report.schema.json`](https://unpkg.com/dir-analysis-tool@3/report.schema.json) describes every one. Validate against it, and allow fields you don't know.
|
|
563
|
+
- **Library.** Exports keep their names and signatures; options and result fields are only added.
|
|
564
|
+
- **What a number means.** A metric keeps its definition (`bytes` is the apparent size, `diskBytes` the allocated size, hard links count once). A release that fixes a wrong count is a patch, and the changelog says what changed.
|
|
565
|
+
- **Not covered.** The wording and layout of the pretty, Markdown and HTML reports, and of messages on stderr, are for people and may change. CSV keeps its columns and only adds new ones at the end. Scripts should read `--json`.
|
|
566
|
+
|
|
552
567
|
## Migrating from v2
|
|
553
568
|
|
|
554
569
|
v3 is a rewrite with a new output format. Most commands keep working unchanged.
|
|
@@ -566,6 +581,7 @@ v3 is a rewrite with a new output format. Most commands keep working unchanged.
|
|
|
566
581
|
| `dist/`, `build/`, `.cache/` excluded by default | Only `.git`, `.hg`, `.svn`, and `node_modules` are; use `--gitignore` or `-e` for more |
|
|
567
582
|
| Sizes in decimal units (`MB`) | Binary units by default (`MiB`); `--si` switches to decimal |
|
|
568
583
|
| Config keys `excludePatterns`, `topN`, `largeSizeThresholdMB`, … | `exclude`, `top`, `largeFiles`, …, read with a deprecation warning |
|
|
584
|
+
| `"maxDepth": -1` for unlimited depth | Leave `maxDepth` out. `-1` still means unlimited, with a deprecation warning |
|
|
569
585
|
|
|
570
586
|
## FAQ
|
|
571
587
|
|
|
@@ -577,8 +593,20 @@ v3 is a rewrite with a new output format. Most commands keep working unchanged.
|
|
|
577
593
|
|
|
578
594
|
## Contributing
|
|
579
595
|
|
|
580
|
-
Bug reports and pull requests are welcome.
|
|
596
|
+
Bug reports and pull requests are welcome. The most useful report is a result you believe is wrong: open a [wrong result issue](https://github.com/KhaledSaeed18/dir-analysis-tool/issues/new?template=wrong_result.yml) with the command, a small directory layout and the `--json` report. For a crash, an idea for a new report or a gap in these docs, [choose an issue form](https://github.com/KhaledSaeed18/dir-analysis-tool/issues/new/choose).
|
|
597
|
+
|
|
598
|
+
Development needs Node.js 22.18 or later and pnpm (the version is pinned in `package.json`), on macOS, Linux or Windows:
|
|
599
|
+
|
|
600
|
+
```bash
|
|
601
|
+
pnpm install
|
|
602
|
+
pnpm dev ~/Downloads -d # run the CLI from source
|
|
603
|
+
pnpm check # everything CI runs
|
|
604
|
+
```
|
|
605
|
+
|
|
606
|
+
[CONTRIBUTING.md](https://github.com/KhaledSaeed18/dir-analysis-tool/blob/main/CONTRIBUTING.md) covers the setup, the product rules, commit messages and how releases work; [AGENTS.md](https://github.com/KhaledSaeed18/dir-analysis-tool/blob/main/AGENTS.md) maps the code. Every `feat` or `fix` merged to `main` is released to npm.
|
|
607
|
+
|
|
608
|
+
Everyone taking part follows the [Code of Conduct](https://github.com/KhaledSaeed18/dir-analysis-tool/blob/main/CODE_OF_CONDUCT.md). Report security vulnerabilities privately, as [SECURITY.md](https://github.com/KhaledSaeed18/dir-analysis-tool/blob/main/SECURITY.md) describes, and accessibility barriers as [ACCESSIBILITY.md](https://github.com/KhaledSaeed18/dir-analysis-tool/blob/main/ACCESSIBILITY.md) describes.
|
|
581
609
|
|
|
582
610
|
## License
|
|
583
611
|
|
|
584
|
-
[MIT](LICENSE), by [Khaled Saeed](https://github.com/KhaledSaeed18).
|
|
612
|
+
[MIT](https://github.com/KhaledSaeed18/dir-analysis-tool/blob/main/LICENSE), by [Khaled Saeed](https://github.com/KhaledSaeed18).
|
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
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-
|
|
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-zG-LAgcd.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";
|
|
@@ -23,10 +23,40 @@ const ExitCode = {
|
|
|
23
23
|
BudgetFailed: 2,
|
|
24
24
|
Interrupted: 130
|
|
25
25
|
};
|
|
26
|
-
|
|
26
|
+
const closedStreams = /* @__PURE__ */ new WeakSet();
|
|
27
|
+
/** Errors that mean the reader went away (`dat --json | head`), which is not a failure of dat. */
|
|
28
|
+
function isClosedPipe(error) {
|
|
29
|
+
const code = errorCode(error);
|
|
30
|
+
return code === "EPIPE" || code === "ERR_STREAM_DESTROYED";
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Treats a closed pipe on `stream` as the end of its output instead of an
|
|
34
|
+
* error: later writes are dropped, and the run still ends with its own exit
|
|
35
|
+
* code (a failed budget stays 2). Any other stream error is rethrown.
|
|
36
|
+
*/
|
|
37
|
+
function ignoreClosedPipe(stream) {
|
|
38
|
+
stream.on("error", (error) => {
|
|
39
|
+
if (!isClosedPipe(error)) throw error;
|
|
40
|
+
closedStreams.add(stream);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/** True once a reader closed the stream early. */
|
|
44
|
+
function isClosed(stream) {
|
|
45
|
+
return closedStreams.has(stream);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Writes to a stream and waits until the data is flushed (important for large
|
|
49
|
+
* piped output). Resolves without writing once the reader has closed the pipe.
|
|
50
|
+
*/
|
|
27
51
|
function write(stream, text) {
|
|
52
|
+
if (closedStreams.has(stream)) return Promise.resolve();
|
|
28
53
|
return new Promise((resolve, reject) => {
|
|
29
|
-
stream.write(text, (error) =>
|
|
54
|
+
stream.write(text, (error) => {
|
|
55
|
+
if (!error) return resolve();
|
|
56
|
+
if (!isClosedPipe(error)) return reject(error);
|
|
57
|
+
closedStreams.add(stream);
|
|
58
|
+
resolve();
|
|
59
|
+
});
|
|
30
60
|
});
|
|
31
61
|
}
|
|
32
62
|
function terminalWidth(io) {
|
|
@@ -1255,7 +1285,7 @@ async function ask(ctx, confirmOverwrite) {
|
|
|
1255
1285
|
const large = bail(await p.text({
|
|
1256
1286
|
message: "Report files at least this large (leave empty to skip)",
|
|
1257
1287
|
placeholder: "100MiB",
|
|
1258
|
-
validate: (value) => validateWith(value,
|
|
1288
|
+
validate: (value) => validateWith(value, parseSizeWithUnit)
|
|
1259
1289
|
}));
|
|
1260
1290
|
const duplicates = bail(await p.confirm({
|
|
1261
1291
|
message: "Look for duplicate files on every run?",
|
|
@@ -1296,6 +1326,14 @@ async function ask(ctx, confirmOverwrite) {
|
|
|
1296
1326
|
}
|
|
1297
1327
|
}
|
|
1298
1328
|
var CancelledError = class extends Error {};
|
|
1329
|
+
/**
|
|
1330
|
+
* A size for the config file, which reads a number without a unit as bytes while `-l 15` reads
|
|
1331
|
+
* it as MiB. The answer must say which, so that "15" can't silently mean 15 bytes.
|
|
1332
|
+
*/
|
|
1333
|
+
function parseSizeWithUnit(value) {
|
|
1334
|
+
if (/^(\d+(\.\d+)?|\.\d+)$/.test(value)) throw new RangeError(`Add a unit: ${value}MiB (what -l ${value} means) or ${value}MB. Without one, the config reads ${value} as bytes.`);
|
|
1335
|
+
return parseSize(value);
|
|
1336
|
+
}
|
|
1299
1337
|
function splitList(value) {
|
|
1300
1338
|
return value.split(",").map((item) => item.trim()).filter(Boolean);
|
|
1301
1339
|
}
|
|
@@ -1427,6 +1465,9 @@ function registerWatch(program, ctx) {
|
|
|
1427
1465
|
const status = previous ? describeChange(previous, result, display.units) : "initial scan";
|
|
1428
1466
|
ctx.info(ctx.err.dim(`watching ${escapeControl(target)} · ${status} · ${(/* @__PURE__ */ new Date()).toLocaleTimeString()} · Ctrl+C to stop`), display.quiet);
|
|
1429
1467
|
};
|
|
1468
|
+
let stopWatching = () => {};
|
|
1469
|
+
const stopped = new Promise((resolve) => stopWatching = resolve);
|
|
1470
|
+
const readerGone = () => ctx.stdoutClosed;
|
|
1430
1471
|
let watcher = null;
|
|
1431
1472
|
const run = async () => {
|
|
1432
1473
|
if (running) {
|
|
@@ -1441,7 +1482,13 @@ function registerWatch(program, ctx) {
|
|
|
1441
1482
|
...display,
|
|
1442
1483
|
progress: display.progress && previous === null
|
|
1443
1484
|
});
|
|
1444
|
-
if (!polling || !previous || changes > 0 || fingerprint(previous) !== fingerprint(result))
|
|
1485
|
+
if (!polling || !previous || changes > 0 || fingerprint(previous) !== fingerprint(result)) {
|
|
1486
|
+
await render(result);
|
|
1487
|
+
if (readerGone()) {
|
|
1488
|
+
stopWatching();
|
|
1489
|
+
break;
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1445
1492
|
previous = result;
|
|
1446
1493
|
changes = 0;
|
|
1447
1494
|
if (watcher && !watcher.recursive) watcher.sync(await listDirectories(target, options));
|
|
@@ -1460,7 +1507,7 @@ function registerWatch(program, ctx) {
|
|
|
1460
1507
|
timer = setTimeout(() => void run(), debounce);
|
|
1461
1508
|
};
|
|
1462
1509
|
await run();
|
|
1463
|
-
if (signal?.aborted) return;
|
|
1510
|
+
if (signal?.aborted || readerGone()) return;
|
|
1464
1511
|
let poller = null;
|
|
1465
1512
|
const startPolling = (seconds) => {
|
|
1466
1513
|
polling = true;
|
|
@@ -1481,11 +1528,11 @@ function registerWatch(program, ctx) {
|
|
|
1481
1528
|
});
|
|
1482
1529
|
watcher.sync(watcher.recursive ? [] : await listDirectories(target, options));
|
|
1483
1530
|
}
|
|
1484
|
-
await new Promise((resolve) => {
|
|
1531
|
+
await Promise.race([stopped, new Promise((resolve) => {
|
|
1485
1532
|
if (!signal) return;
|
|
1486
1533
|
if (signal.aborted) resolve();
|
|
1487
1534
|
signal.addEventListener("abort", () => resolve(), { once: true });
|
|
1488
|
-
});
|
|
1535
|
+
})]);
|
|
1489
1536
|
if (timer) clearTimeout(timer);
|
|
1490
1537
|
if (poller) clearInterval(poller);
|
|
1491
1538
|
watcher?.close();
|
|
@@ -1552,6 +1599,10 @@ var Context = class {
|
|
|
1552
1599
|
stdout(text) {
|
|
1553
1600
|
return write(this.io.stdout, text);
|
|
1554
1601
|
}
|
|
1602
|
+
/** True once the reader of stdout went away (`dat watch --json | head -1`). */
|
|
1603
|
+
get stdoutClosed() {
|
|
1604
|
+
return isClosed(this.io.stdout);
|
|
1605
|
+
}
|
|
1555
1606
|
};
|
|
1556
1607
|
// src/cli/program.ts
|
|
1557
1608
|
function createProgram(ctx) {
|
|
@@ -1605,10 +1656,8 @@ function handleError(error, ctx) {
|
|
|
1605
1656
|
return ExitCode.Error;
|
|
1606
1657
|
}
|
|
1607
1658
|
// src/cli/main.ts
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
throw error;
|
|
1611
|
-
});
|
|
1659
|
+
ignoreClosedPipe(process.stdout);
|
|
1660
|
+
ignoreClosedPipe(process.stderr);
|
|
1612
1661
|
const controller = new AbortController();
|
|
1613
1662
|
process.on("SIGINT", () => {
|
|
1614
1663
|
if (controller.signal.aborted) process.exit(130);
|
package/dist/index.d.ts
CHANGED
|
@@ -260,7 +260,10 @@ interface ScanSettings {
|
|
|
260
260
|
minSize?: number | string | undefined;
|
|
261
261
|
/** Only include files at most this large. */
|
|
262
262
|
maxSize?: number | string | undefined;
|
|
263
|
-
/**
|
|
263
|
+
/**
|
|
264
|
+
* Only include files modified at or after this time: a `Date`, epoch ms, `YYYY-MM-DD`, an ISO 8601
|
|
265
|
+
* timestamp, or an age with a unit such as `"30d"`. A string without a unit (`"12"`) is rejected.
|
|
266
|
+
*/
|
|
264
267
|
modifiedAfter?: Date | number | string | undefined;
|
|
265
268
|
/** Only include files modified at or before this time. Date-only values include the whole day. */
|
|
266
269
|
modifiedBefore?: Date | number | string | undefined;
|
|
@@ -609,8 +612,10 @@ interface PointInTimeOptions {
|
|
|
609
612
|
}
|
|
610
613
|
/**
|
|
611
614
|
* Resolves a point in time from either an age relative to now (`30d` means
|
|
612
|
-
* "30 days ago") or an absolute date
|
|
613
|
-
*
|
|
615
|
+
* "30 days ago") or an absolute date: `YYYY-MM-DD` in local time, or an ISO
|
|
616
|
+
* 8601 timestamp such as `2024-01-31T10:00:00Z` (local time without an
|
|
617
|
+
* offset). Anything else throws a `RangeError`, including bare numbers, which
|
|
618
|
+
* have no unit. Returns epoch milliseconds.
|
|
614
619
|
*/
|
|
615
620
|
export declare function parsePointInTime(input: string, options?: PointInTimeOptions): number;
|
|
616
621
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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-
|
|
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-zG-LAgcd.js";
|
|
@@ -49,6 +49,10 @@ const MS_PER_UNIT = {
|
|
|
49
49
|
};
|
|
50
50
|
const DURATION_PATTERN = /^\s*(\d+(?:\.\d+)?)\s*(ms|s|min|mo|m|h|d|w|y)\s*$/i;
|
|
51
51
|
const DATE_ONLY_PATTERN = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
52
|
+
/** `YYYY-MM-DDTHH:mm`, with optional seconds and fraction, and an optional `Z` or `±HH:mm` offset. */
|
|
53
|
+
const TIMESTAMP_PATTERN = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2})(?:\.\d+)?)?(?:Z|[+-](\d{2}):(\d{2}))?$/i;
|
|
54
|
+
const BARE_NUMBER_PATTERN = /^\d+(?:\.\d+)?$/;
|
|
55
|
+
const LOOSE_DATE_PATTERN = /^(\d{4})-(\d{1,2})-(\d{1,2})$/;
|
|
52
56
|
/** Parses a duration such as `90d`, `2w`, `6mo`, `1y`, `12h`, or `30min` into milliseconds. */
|
|
53
57
|
function parseDuration(input) {
|
|
54
58
|
const match = DURATION_PATTERN.exec(input);
|
|
@@ -57,23 +61,46 @@ function parseDuration(input) {
|
|
|
57
61
|
}
|
|
58
62
|
/**
|
|
59
63
|
* Resolves a point in time from either an age relative to now (`30d` means
|
|
60
|
-
* "30 days ago") or an absolute date
|
|
61
|
-
*
|
|
64
|
+
* "30 days ago") or an absolute date: `YYYY-MM-DD` in local time, or an ISO
|
|
65
|
+
* 8601 timestamp such as `2024-01-31T10:00:00Z` (local time without an
|
|
66
|
+
* offset). Anything else throws a `RangeError`, including bare numbers, which
|
|
67
|
+
* have no unit. Returns epoch milliseconds.
|
|
62
68
|
*/
|
|
63
69
|
function parsePointInTime(input, options = {}) {
|
|
64
70
|
const now = options.now ?? Date.now();
|
|
65
71
|
if (DURATION_PATTERN.test(input)) return now - parseDuration(input);
|
|
66
|
-
const
|
|
72
|
+
const text = input.trim();
|
|
73
|
+
const dateOnly = DATE_ONLY_PATTERN.exec(text);
|
|
67
74
|
if (dateOnly) {
|
|
68
75
|
const [, y, m, d] = dateOnly;
|
|
69
|
-
|
|
70
|
-
|
|
76
|
+
if (!isCalendarDate(Number(y), Number(m), Number(d))) throw new RangeError(`Invalid date "${input}".`);
|
|
77
|
+
const date = new Date(2e3, Number(m) - 1, Number(d));
|
|
78
|
+
date.setFullYear(Number(y));
|
|
71
79
|
if (options.endOfDay) date.setHours(23, 59, 59, 999);
|
|
72
80
|
return date.getTime();
|
|
73
81
|
}
|
|
74
|
-
const
|
|
75
|
-
if (
|
|
76
|
-
|
|
82
|
+
const timestamp = TIMESTAMP_PATTERN.exec(text);
|
|
83
|
+
if (timestamp) {
|
|
84
|
+
const [, y, m, d, hour, minute, second = "0", offsetHours = "0", offsetMinutes = "0"] = timestamp;
|
|
85
|
+
const parsed = Date.parse(text.toUpperCase());
|
|
86
|
+
if (!isCalendarDate(Number(y), Number(m), Number(d)) || Number(hour) > 23 || Number(minute) > 59 || Number(second) > 59 || Number(offsetHours) > 23 || Number(offsetMinutes) > 59 || Number.isNaN(parsed)) throw new RangeError(`Invalid timestamp "${input}".`);
|
|
87
|
+
return parsed;
|
|
88
|
+
}
|
|
89
|
+
if (/^\d{4}$/.test(text) && Number(text) >= 1900) throw new RangeError(`Invalid date or age "${input}". For a date, write YYYY-MM-DD, for example ${text}-01-01; for an age, add a unit, for example 30d.`);
|
|
90
|
+
if (BARE_NUMBER_PATTERN.test(text)) throw new RangeError(`Invalid date or age "${input}": an age needs a unit. Add one, for example ${text}mo (months) or ${text}d (days).`);
|
|
91
|
+
if (TIMESTAMP_PATTERN.test(text.replace(" ", "T"))) throw new RangeError(`Invalid timestamp "${input}". Separate the date and the time with T, for example ${text.replace(" ", "T")}.`);
|
|
92
|
+
const loose = LOOSE_DATE_PATTERN.exec(text);
|
|
93
|
+
if (loose) {
|
|
94
|
+
const [, y, m, d] = loose;
|
|
95
|
+
throw new RangeError(`Invalid date "${input}". Write dates as YYYY-MM-DD, for example ${y}-${m.padStart(2, "0")}-${d.padStart(2, "0")}.`);
|
|
96
|
+
}
|
|
97
|
+
throw new RangeError(`Invalid date or age "${input}". Use an age such as 30d, a date as YYYY-MM-DD, or an ISO 8601 timestamp such as 2024-01-31T10:00:00Z.`);
|
|
98
|
+
}
|
|
99
|
+
/** True for a real day of the Gregorian calendar (no February 30). */
|
|
100
|
+
function isCalendarDate(year, month, day) {
|
|
101
|
+
const date = new Date(Date.UTC(2e3, month - 1, day));
|
|
102
|
+
date.setUTCFullYear(year);
|
|
103
|
+
return date.getUTCFullYear() === year && date.getUTCMonth() === month - 1 && date.getUTCDate() === day;
|
|
77
104
|
}
|
|
78
105
|
/** Formats an elapsed duration compactly: `840ms`, `3.2s`, `2m 05s`. */
|
|
79
106
|
function formatElapsed(ms) {
|
|
@@ -3495,7 +3522,7 @@ async function explainSkips(root, options = {}) {
|
|
|
3495
3522
|
}
|
|
3496
3523
|
// src/config/schema.ts
|
|
3497
3524
|
const SIZE_HINT = "Bytes, or a size such as \"512k\", \"25MiB\", or \"1GB\".";
|
|
3498
|
-
const TIME_HINT = "An age such as \"30d\", \"6mo\", or \"1y\",
|
|
3525
|
+
const TIME_HINT = "An age with a unit such as \"30d\", \"6mo\", or \"1y\", a date (YYYY-MM-DD), or an ISO 8601 timestamp such as \"2024-01-31T10:00:00Z\".";
|
|
3499
3526
|
/** Single source of truth for config validation, docs, and `schema.json`. */
|
|
3500
3527
|
const CONFIG_FIELDS = {
|
|
3501
3528
|
exclude: {
|
|
@@ -3520,7 +3547,7 @@ const CONFIG_FIELDS = {
|
|
|
3520
3547
|
kind: "integer",
|
|
3521
3548
|
min: 0
|
|
3522
3549
|
},
|
|
3523
|
-
description: "Directory levels to descend; 0 scans only the top-level files. Default: unlimited."
|
|
3550
|
+
description: "Directory levels to descend; 0 scans only the top-level files. Default: unlimited (leave it out; the v2 value -1 still works, with a deprecation warning)."
|
|
3524
3551
|
},
|
|
3525
3552
|
followSymlinks: {
|
|
3526
3553
|
type: { kind: "boolean" },
|
|
@@ -3558,7 +3585,7 @@ const CONFIG_FIELDS = {
|
|
|
3558
3585
|
kind: "size",
|
|
3559
3586
|
allowBoolean: true
|
|
3560
3587
|
},
|
|
3561
|
-
description: `Report files at least this large; true uses 100 MiB. ${SIZE_HINT}
|
|
3588
|
+
description: `Report files at least this large; true uses 100 MiB. ${SIZE_HINT} A number without a unit is bytes here, while the -l flag reads it as MiB.`,
|
|
3562
3589
|
examples: ["50MB"]
|
|
3563
3590
|
},
|
|
3564
3591
|
duplicates: {
|
|
@@ -3665,7 +3692,11 @@ function validateConfig(raw) {
|
|
|
3665
3692
|
};
|
|
3666
3693
|
const input = Object.fromEntries(Object.entries(raw));
|
|
3667
3694
|
delete input["$schema"];
|
|
3668
|
-
|
|
3695
|
+
const largeFilesWritten = "largeFiles" in input;
|
|
3696
|
+
if (input["maxDepth"] === -1) {
|
|
3697
|
+
delete input["maxDepth"];
|
|
3698
|
+
warnings.push("\"maxDepth\": -1 is deprecated; leave maxDepth out for unlimited depth");
|
|
3699
|
+
}
|
|
3669
3700
|
for (const [key, translate] of Object.entries(LEGACY_KEYS)) {
|
|
3670
3701
|
if (!(key in input)) continue;
|
|
3671
3702
|
const value = input[key];
|
|
@@ -3689,12 +3720,22 @@ function validateConfig(raw) {
|
|
|
3689
3720
|
if (problem) errors.push(`"${key}" ${problem}`);
|
|
3690
3721
|
else config[key] = value;
|
|
3691
3722
|
}
|
|
3723
|
+
const small = largeFilesWritten ? smallUnitlessSize(config["largeFiles"]) : null;
|
|
3724
|
+
if (small !== null) warnings.push(`"largeFiles": ${JSON.stringify(config["largeFiles"])} is ${small} ${small === 1 ? "byte" : "bytes"}: a size without a unit is bytes in the config, unlike -l ${small}, which means ${small} MiB. Write "${small}MiB" if you meant MiB, or add a unit to silence this warning.`);
|
|
3692
3725
|
return {
|
|
3693
3726
|
config,
|
|
3694
3727
|
warnings,
|
|
3695
3728
|
errors
|
|
3696
3729
|
};
|
|
3697
3730
|
}
|
|
3731
|
+
/**
|
|
3732
|
+
* The byte count of a unitless size below 1 MiB, which is more likely a v2-style MiB count
|
|
3733
|
+
* (`-l 15`) than a deliberate byte threshold for "large" files; null otherwise.
|
|
3734
|
+
*/
|
|
3735
|
+
function smallUnitlessSize(value) {
|
|
3736
|
+
const bytes = typeof value === "number" ? value : typeof value === "string" && /^\s*(\d+(\.\d+)?|\.\d+)\s*$/.test(value) ? Number(value) : null;
|
|
3737
|
+
return bytes !== null && bytes > 0 && bytes < 1024 ** 2 ? bytes : null;
|
|
3738
|
+
}
|
|
3698
3739
|
function checkValue(type, value) {
|
|
3699
3740
|
const got = `(got ${JSON.stringify(value)})`;
|
|
3700
3741
|
switch (type.kind) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dir-analysis-tool",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.1",
|
|
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": {
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
"default": "./dist/index.js"
|
|
10
10
|
},
|
|
11
11
|
"./schema.json": "./schema.json",
|
|
12
|
+
"./report.schema.json": "./report.schema.json",
|
|
12
13
|
"./package.json": "./package.json"
|
|
13
14
|
},
|
|
14
15
|
"main": "./dist/index.js",
|
|
@@ -19,7 +20,8 @@
|
|
|
19
20
|
},
|
|
20
21
|
"files": [
|
|
21
22
|
"dist",
|
|
22
|
-
"schema.json"
|
|
23
|
+
"schema.json",
|
|
24
|
+
"report.schema.json"
|
|
23
25
|
],
|
|
24
26
|
"sideEffects": false,
|
|
25
27
|
"scripts": {
|
|
@@ -90,6 +92,7 @@
|
|
|
90
92
|
"@semantic-release/release-notes-generator": "^14.1.1",
|
|
91
93
|
"@types/node": "^22.20.5",
|
|
92
94
|
"@vitest/coverage-v8": "^5.0.5",
|
|
95
|
+
"ajv": "^8.20.0",
|
|
93
96
|
"conventional-changelog-conventionalcommits": "^9.3.1",
|
|
94
97
|
"husky": "^9.1.7",
|
|
95
98
|
"oxlint": "^1.88.0",
|