dir-analysis-tool 3.2.1 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,16 @@
1
- //#region src/format/bytes.d.ts
1
+ /**
2
+ * dir-analysis-tool: fast, memory-bounded directory analysis.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * import { analyze, compare, formatBytes } from 'dir-analysis-tool';
7
+ *
8
+ * const result = await analyze('./dist', { top: 5, budgets: ['size<=2MB'] });
9
+ * console.log(formatBytes(result.summary.bytes));
10
+ * ```
11
+ *
12
+ * @packageDocumentation
13
+ */
2
14
  /**
3
15
  * Byte formatting and parsing.
4
16
  *
@@ -23,8 +35,6 @@ export declare function formatBytes(bytes: number, units?: ByteUnits): string;
23
35
  * Suffixes are case-insensitive. Throws a `RangeError` for anything else.
24
36
  */
25
37
  export declare function parseSize(input: string | number): number;
26
- //#endregion
27
- //#region src/types.d.ts
28
38
  export declare const CATEGORIES: readonly ["code", "documents", "images", "videos", "audio", "archives", "fonts", "data", "other"];
29
39
  export type Category = (typeof CATEGORIES)[number];
30
40
  export interface SizeStat {
@@ -206,19 +216,13 @@ export interface ComparisonResult {
206
216
  /** Directories with the largest size change, largest absolute change first. */
207
217
  directories: DirectoryDelta[];
208
218
  }
209
- //#endregion
210
- //#region src/core/duplicates.d.ts
211
219
  interface DuplicateProgress {
212
220
  stage: "sample" | "full";
213
221
  done: number;
214
222
  total: number;
215
223
  }
216
- //#endregion
217
- //#region src/core/exclude.d.ts
218
224
  /** Directories skipped unless default excludes are turned off. */
219
225
  export declare const DEFAULT_EXCLUDES: readonly string[];
220
- //#endregion
221
- //#region src/core/options.d.ts
222
226
  /** Default number of concurrent filesystem operations. */
223
227
  export declare const DEFAULT_CONCURRENCY: number;
224
228
  /** Options shared by every operation that walks a directory tree. */
@@ -253,8 +257,6 @@ interface ScanSettings {
253
257
  * root-relative `/` paths (the root itself is `""`). Files are not examined.
254
258
  */
255
259
  export declare function listDirectories(path: string, settings?: ScanSettings): Promise<string[]>;
256
- //#endregion
257
- //#region src/core/analyze.d.ts
258
260
  /** Default size for "large file" detection: 100 MiB. */
259
261
  export declare const DEFAULT_LARGE_FILE_THRESHOLD: number;
260
262
  /** Default age for stale-file detection. */
@@ -312,8 +314,6 @@ type AnalysisProgress = {
312
314
  * ```
313
315
  */
314
316
  export declare function analyze(path: string, options?: AnalyzeOptions): Promise<AnalysisResult>;
315
- //#endregion
316
- //#region src/core/compare.d.ts
317
317
  interface CompareOptions extends ScanSettings {
318
318
  /** Also compare the contents of same-sized files (SHA-256). Default: `false`, size only. */
319
319
  content?: boolean | undefined;
@@ -333,8 +333,142 @@ interface CompareOptions extends ScanSettings {
333
333
  * rules and filters. Memory grows with the number of files in both trees.
334
334
  */
335
335
  export declare function compare(left: string, right: string, options?: CompareOptions): Promise<ComparisonResult>;
336
- //#endregion
337
- //#region src/core/classify.d.ts
336
+ /** Version of the `explain` JSON shape, independent of the analysis `schemaVersion`. */
337
+ export declare const EXPLAIN_VERSION = 1;
338
+ /** Default number of entries listed per group by {@link explainSkips}. */
339
+ export declare const DEFAULT_EXPLAIN_LIMIT = 20;
340
+ /** Largest accepted `limit` for {@link explainSkips}. */
341
+ export declare const MAX_EXPLAIN_LIMIT = 1e3;
342
+ /** What a scan with the given settings does with a path. */
343
+ type ExplainDecision = "included" | "excluded" | "filtered" | "skipped" | "not-found";
344
+ /** What made the decision. */
345
+ type ExplainSource = "default" | "pattern" | "gitignore" | "info-exclude" | "size" | "date" | "max-depth" | "symlink" | "special-file" | "error" | "unknown";
346
+ type ExplainEntryType = "file" | "directory" | "symlink" | "other";
347
+ type ExplainNoteCode = "negation-blocked-by-parent" | "negation-cannot-reach-default" | "negation-cannot-reach-gitignore" | "root-ignored-by-git" | "global-excludes-not-read" | "nested-repository" | "hardlink-order-dependent" | "symlink-order-dependent" | "case-rule-from-platform" | "not-found" | "explanation-unavailable";
348
+ /** The rule or limit that decided. Fields that do not apply to the source are `null`. */
349
+ interface ExplainReason {
350
+ source: ExplainSource;
351
+ /** Root-relative path of the entry the rule applied to: the path itself or an ancestor. */
352
+ at: string;
353
+ /** True when `at` is an ancestor, so the path itself was never visited. */
354
+ ancestor: boolean;
355
+ /** `gitignore` and `info-exclude`: the file, relative to the root, `/`-separated. */
356
+ file: string | null;
357
+ /** `gitignore` and `info-exclude`: the 1-based line. */
358
+ line: number | null;
359
+ /**
360
+ * The rule text for `pattern`, `gitignore`, and `info-exclude`; the directory
361
+ * name for `default`; the setting name (`minSize`, `maxSize`, `modifiedAfter`,
362
+ * `modifiedBefore`, `maxDepth`) for `size`, `date`, and `max-depth`.
363
+ */
364
+ rule: string | null;
365
+ /** `pattern`: index into `settings.exclude` (config patterns first, then command-line ones). */
366
+ index: number | null;
367
+ /** `size`, `date`, `max-depth`: the bound (bytes, ISO time, or depth). */
368
+ limit: number | string | null;
369
+ /** `size`, `date`, `max-depth`: the observed value. */
370
+ actual: number | string | null;
371
+ /** `error`, and a dangling `symlink`: the error code. */
372
+ code: string | null;
373
+ }
374
+ /** Something the explanation cannot settle on its own, or a rule that did not do what it seems to. */
375
+ interface ExplainNote {
376
+ code: ExplainNoteCode;
377
+ message: string;
378
+ path?: string;
379
+ file?: string;
380
+ line?: number;
381
+ rule?: string;
382
+ index?: number;
383
+ }
384
+ interface PathExplanation {
385
+ explainVersion: 1;
386
+ root: string;
387
+ /** Root-relative path, `/`-separated; `""` for the root itself. */
388
+ path: string;
389
+ /** Type on disk, or `null` when the path does not exist. */
390
+ type: ExplainEntryType | null;
391
+ decision: ExplainDecision;
392
+ /** `null` when the path is included or not found. */
393
+ reason: ExplainReason | null;
394
+ /** Always `null`: a directory that is never entered is never measured. */
395
+ descendants: null;
396
+ notes: ExplainNote[];
397
+ ignoreCase: boolean;
398
+ settings: AnalysisSettings;
399
+ }
400
+ interface ExplainTotals {
401
+ /** Topmost excluded entries, as in `summary.excluded`. */
402
+ excluded: number;
403
+ /** Files dropped by size and date filters, as in `summary.filtered`. */
404
+ filtered: number;
405
+ /** Directories not entered because of `maxDepth`. Not reported by `analyze`. */
406
+ depthSkipped: number;
407
+ /** Symbolic links seen, as in `summary.symlinks`. */
408
+ symlinks: number;
409
+ /** Extra hard links not counted again, as in `summary.hardlinks`. */
410
+ hardlinks: number;
411
+ errors: number;
412
+ }
413
+ /** Entries skipped for the same reason. */
414
+ interface ExplainGroup {
415
+ source: ExplainSource;
416
+ file: string | null;
417
+ line: number | null;
418
+ rule: string | null;
419
+ index: number | null;
420
+ limit: number | string | null;
421
+ count: number;
422
+ /** The first entries in path order, at most `limit` of them. */
423
+ entries: string[];
424
+ truncated: boolean;
425
+ }
426
+ interface SkipsExplanation {
427
+ explainVersion: 1;
428
+ root: string;
429
+ totals: ExplainTotals;
430
+ /** Largest groups first. */
431
+ groups: ExplainGroup[];
432
+ /** Unreadable entries, at most `limit` (and at most 100) of them. */
433
+ errors: ScanError[];
434
+ notes: ExplainNote[];
435
+ limit: number;
436
+ ignoreCase: boolean;
437
+ settings: AnalysisSettings;
438
+ }
439
+ interface ExplainSkipsOptions extends ScanSettings {
440
+ /** Entries listed per group. Counts are always complete. Default: 20, maximum 1000. */
441
+ limit?: number | undefined;
442
+ }
443
+ /**
444
+ * Explains what a scan of `root` with these settings does with one path:
445
+ * whether it is counted, and if not, which rule or limit decided and where.
446
+ *
447
+ * Runs no full scan. It walks from the root down to the path the way the
448
+ * scanner does, reading only the directories on the way, and stops at the
449
+ * first ancestor the scan would not enter. `path` is relative to `root` or
450
+ * absolute; it must be inside `root`.
451
+ *
452
+ * @example
453
+ * ```ts
454
+ * import { explainPath } from 'dir-analysis-tool';
455
+ *
456
+ * const result = await explainPath('.', 'build/keep/k.txt', { gitignore: true });
457
+ * console.log(result.decision, result.reason?.file, result.reason?.line);
458
+ * ```
459
+ */
460
+ export declare function explainPath(root: string, path: string, settings?: ScanSettings): Promise<PathExplanation>;
461
+ /**
462
+ * Runs one scan and reports everything it left out, grouped by the rule or
463
+ * limit that decided: default excludes, each `exclude` pattern, each
464
+ * `.gitignore` line, size and date filters, `maxDepth`, and symbolic links
465
+ * that were not followed. Counts are complete; each group lists at most
466
+ * `limit` entries, the first in path order.
467
+ *
468
+ * Totals equal the `summary` counters of {@link analyze} with the same
469
+ * settings. Sizes inside excluded directories are never measured.
470
+ */
471
+ export declare function explainSkips(root: string, options?: ExplainSkipsOptions): Promise<SkipsExplanation>;
338
472
  /**
339
473
  * Extracts the lowercased extension (with the dot) from a file name.
340
474
  * Dotfiles such as `.env` have no extension; `archive.tar.gz` has `.gz`.
@@ -342,8 +476,6 @@ export declare function compare(left: string, right: string, options?: CompareOp
342
476
  export declare function extensionOf(fileName: string): string;
343
477
  /** Classifies a file by its well-known name first, then by extension. */
344
478
  export declare function classify(fileName: string, extension?: string): Category;
345
- //#endregion
346
- //#region src/core/budgets.d.ts
347
479
  /** A feature a metric depends on; requesting the metric turns the feature on. */
348
480
  type BudgetFeature = "largeFiles" | "duplicates" | "empty" | "stale";
349
481
  interface MetricSpec {
@@ -362,8 +494,6 @@ interface Budget {
362
494
  /** Parses a rule such as `size<=500MB`, `duplicates=0`, or `files < 10000`. */
363
495
  export declare function parseBudget(rule: string): Budget;
364
496
  export declare function evaluateBudgets(budgets: readonly Budget[], result: AnalysisResult): BudgetResult[];
365
- //#endregion
366
- //#region src/config/schema.d.ts
367
497
  /** Settings accepted in a config file. CLI flags always take precedence. */
368
498
  interface DatConfig {
369
499
  exclude?: string[];
@@ -397,8 +527,6 @@ interface ValidationResult {
397
527
  export declare function validateConfig(raw: unknown): ValidationResult;
398
528
  /** Builds the JSON Schema published as `dir-analysis-tool/schema.json`. */
399
529
  export declare function buildJsonSchema(): Record<string, unknown>;
400
- //#endregion
401
- //#region src/config/load.d.ts
402
530
  /** File names recognized during discovery, in priority order. */
403
531
  export declare const CONFIG_FILE_NAMES: readonly string[];
404
532
  interface LoadedConfig {
@@ -417,8 +545,6 @@ export declare function loadConfig(options: {
417
545
  file?: string;
418
546
  searchFrom: string;
419
547
  }): Promise<LoadedConfig>;
420
- //#endregion
421
- //#region src/format/time.d.ts
422
548
  /** Parses a duration such as `90d`, `2w`, `6mo`, `1y`, `12h`, or `30min` into milliseconds. */
423
549
  export declare function parseDuration(input: string): number;
424
550
  interface PointInTimeOptions {
@@ -436,8 +562,6 @@ interface PointInTimeOptions {
436
562
  * Date-only values are interpreted in local time. Returns epoch milliseconds.
437
563
  */
438
564
  export declare function parsePointInTime(input: string, options?: PointInTimeOptions): number;
439
- //#endregion
440
- //#region src/format/style.d.ts
441
565
  /**
442
566
  * Minimal ANSI styling with standard color detection.
443
567
  *
@@ -457,8 +581,6 @@ interface Style {
457
581
  cyan(text: string): string;
458
582
  }
459
583
  export declare function createStyle(enabled: boolean): Style;
460
- //#endregion
461
- //#region src/reporters/pretty.d.ts
462
584
  interface PrettyOptions {
463
585
  style?: Style;
464
586
  units?: ByteUnits;
@@ -477,8 +599,6 @@ interface PrettyOptions {
477
599
  export declare function renderAnalysis(result: AnalysisResult, options?: PrettyOptions): string;
478
600
  /** Renders a directory comparison for a terminal. */
479
601
  export declare function renderComparison(result: ComparisonResult, options?: PrettyOptions): string;
480
- //#endregion
481
- //#region src/reporters/markdown.d.ts
482
602
  interface MarkdownOptions {
483
603
  units?: ByteUnits;
484
604
  /** Maximum rows per table. Default: 10. */
@@ -488,8 +608,6 @@ interface MarkdownOptions {
488
608
  export declare function renderAnalysisMarkdown(result: AnalysisResult, options?: MarkdownOptions): string;
489
609
  /** Renders a directory comparison as GitHub-flavored Markdown. */
490
610
  export declare function renderComparisonMarkdown(result: ComparisonResult, options?: MarkdownOptions): string;
491
- //#endregion
492
- //#region src/reporters/csv.d.ts
493
611
  /**
494
612
  * Flattens an analysis into one table. The `section` column tells rows apart:
495
613
  * summary, type, extension, largest-directory, largest-file, large-file,
@@ -498,8 +616,6 @@ export declare function renderComparisonMarkdown(result: ComparisonResult, optio
498
616
  export declare function renderAnalysisCsv(result: AnalysisResult): string;
499
617
  /** Flattens a comparison: one row per added, removed, or changed file. */
500
618
  export declare function renderComparisonCsv(result: ComparisonResult): string;
501
- //#endregion
502
- //#region src/reporters/html.d.ts
503
619
  interface HtmlOptions {
504
620
  units?: ByteUnits;
505
621
  /** Maximum rows per table. Default: 500. */
@@ -511,8 +627,16 @@ interface HtmlOptions {
511
627
  * all network access, so the file is safe to open and share offline.
512
628
  */
513
629
  export declare function renderAnalysisHtml(result: AnalysisResult, options?: HtmlOptions): string;
514
- //#endregion
515
- //#region src/errors.d.ts
630
+ interface ExplainRenderOptions {
631
+ style?: Style | undefined;
632
+ units?: ByteUnits | undefined;
633
+ /** Terminal width; long paths are shortened to fit. Default: 100. */
634
+ width?: number | undefined;
635
+ }
636
+ /** Human-readable explanation of one path. */
637
+ export declare function renderPathExplanation(result: PathExplanation, options?: ExplainRenderOptions): string;
638
+ /** Human-readable summary of everything a scan left out. */
639
+ export declare function renderSkipsExplanation(result: SkipsExplanation, options?: ExplainRenderOptions): string;
516
640
  /**
517
641
  * An expected, user-facing failure (bad input, missing directory, invalid
518
642
  * config). The CLI prints its message without a stack trace.
@@ -531,8 +655,5 @@ export declare class AbortError extends Error {
531
655
  override readonly name = "AbortError";
532
656
  constructor(message?: string);
533
657
  }
534
- //#endregion
535
- //#region src/version.d.ts
536
658
  export declare const VERSION: string;
537
- //#endregion
538
- export type { AnalysisProgress, AnalyzeOptions, Budget, ByteUnits, CompareOptions, DatConfig, LoadedConfig, PrettyOptions, ScanSettings, Style };
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 };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export { B as AbortError, A as BUDGET_METRICS, I as CATEGORIES, m as CONFIG_FILE_NAMES, C as DEFAULT_CONCURRENCY, E as DEFAULT_EXCLUDES, b as DEFAULT_LARGE_FILE_THRESHOLD, x as DEFAULT_STALE_AGE, V as DatError, L as VERSION, S as analyze, _ as buildJsonSchema, O as classify, y as compare, f as createStyle, j as evaluateBudgets, k as extensionOf, h as findConfigFile, P as formatBytes, w as listDirectories, g as loadConfig, N as parseBudget, R as parseDuration, z as parsePointInTime, F as parseSize, o as renderAnalysis, n as renderAnalysisCsv, t as renderAnalysisHtml, i as renderAnalysisMarkdown, s as renderComparison, r as renderComparisonCsv, a as renderComparisonMarkdown, v as validateConfig } from "./shared-30qR-AM1.js";
1
+ export { q as AbortError, L as BUDGET_METRICS, U as CATEGORIES, g as CONFIG_FILE_NAMES, A as DEFAULT_CONCURRENCY, N as DEFAULT_EXCLUDES, x as DEFAULT_EXPLAIN_LIMIT, D as DEFAULT_LARGE_FILE_THRESHOLD, O as DEFAULT_STALE_AGE, J as DatError, S as EXPLAIN_VERSION, C as MAX_EXPLAIN_LIMIT, W as VERSION, k as analyze, y as buildJsonSchema, F as classify, E as compare, m as createStyle, R as evaluateBudgets, w as explainPath, T as explainSkips, I as extensionOf, _ as findConfigFile, V as formatBytes, j as listDirectories, v as loadConfig, B as parseBudget, G as parseDuration, K as parsePointInTime, H 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-DfKY8fSl.js";