dir-analysis-tool 3.3.0 → 3.3.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/dist/cli.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { B as parseBudget, C as MAX_EXPLAIN_LIMIT, E as compare, H as parseSize, J as DatError, K as parsePointInTime, M as joinRelative, P as Excluder, T as explainSkips, V as formatBytes, W as VERSION, X as errorMessage, Y as errorCode, a as renderComparisonCsv, c as renderAnalysis, d as escapeControlInLines, f as formatCount, h as supportsColor, i as renderAnalysisCsv, j as listDirectories, k as analyze, l as renderComparison, m as createStyle, n as renderSkipsExplanation, o as renderAnalysisMarkdown, p as stringifyJson, q as AbortError, r as renderAnalysisHtml, s as renderComparisonMarkdown, t as renderPathExplanation, u as escapeControl, v as loadConfig, w as explainPath, z as formatBudgetActual } from "./shared-DfKY8fSl.js";
2
+ import { C as MAX_EXPLAIN_LIMIT, D as outsideRootError, E as isOutside, H as parseBudget, I as Excluder, J as parsePointInTime, K as VERSION, N as listDirectories, O as compare, P as joinRelative, Q as errorMessage, T as explainSkips, U as formatBytes, V as formatBudgetActual, W as parseSize, X as DatError, Y as AbortError, Z as errorCode, a as renderComparisonCsv, c as renderAnalysis, d as escapeControlInLines, f as formatCount, h as supportsColor, i as renderAnalysisCsv, j as analyze, 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-NtYCFeUO.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";
@@ -1028,7 +1028,9 @@ function registerExplain(program, ctx) {
1028
1028
  const style = ctx.outputStyle(read.boolean(cli["color"]), false);
1029
1029
  const width = terminalWidth(ctx.io);
1030
1030
  if (path !== void 0) {
1031
- const result = await explainPath(root, ctx.resolvePath(path), {
1031
+ const target = ctx.resolvePath(path);
1032
+ if (isOutside(root, target)) throw outsideRootError(path, root);
1033
+ const result = await explainPath(root, target, {
1032
1034
  ...settings,
1033
1035
  signal: ctx.io.signal
1034
1036
  });
package/dist/index.d.ts CHANGED
@@ -333,6 +333,24 @@ 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
+ /**
337
+ * An expected, user-facing failure (bad input, missing directory, invalid
338
+ * config). The CLI prints its message without a stack trace.
339
+ */
340
+ export declare class DatError extends Error {
341
+ override readonly name = "DatError";
342
+ /** Optional hint printed after the message. */
343
+ readonly hint: string | undefined;
344
+ constructor(message: string, options?: {
345
+ hint?: string;
346
+ cause?: unknown;
347
+ });
348
+ }
349
+ /** Thrown when an operation is cancelled through its `AbortSignal`. */
350
+ export declare class AbortError extends Error {
351
+ override readonly name = "AbortError";
352
+ constructor(message?: string);
353
+ }
336
354
  /** Version of the `explain` JSON shape, independent of the analysis `schemaVersion`. */
337
355
  export declare const EXPLAIN_VERSION = 1;
338
356
  /** Default number of entries listed per group by {@link explainSkips}. */
@@ -637,23 +655,5 @@ interface ExplainRenderOptions {
637
655
  export declare function renderPathExplanation(result: PathExplanation, options?: ExplainRenderOptions): string;
638
656
  /** Human-readable summary of everything a scan left out. */
639
657
  export declare function renderSkipsExplanation(result: SkipsExplanation, options?: ExplainRenderOptions): string;
640
- /**
641
- * An expected, user-facing failure (bad input, missing directory, invalid
642
- * config). The CLI prints its message without a stack trace.
643
- */
644
- export declare class DatError extends Error {
645
- override readonly name = "DatError";
646
- /** Optional hint printed after the message. */
647
- readonly hint: string | undefined;
648
- constructor(message: string, options?: {
649
- hint?: string;
650
- cause?: unknown;
651
- });
652
- }
653
- /** Thrown when an operation is cancelled through its `AbortSignal`. */
654
- export declare class AbortError extends Error {
655
- override readonly name = "AbortError";
656
- constructor(message?: string);
657
- }
658
658
  export declare const VERSION: string;
659
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 { 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";
1
+ export { Y as AbortError, z as BUDGET_METRICS, G as CATEGORIES, g as CONFIG_FILE_NAMES, M as DEFAULT_CONCURRENCY, F as DEFAULT_EXCLUDES, x as DEFAULT_EXPLAIN_LIMIT, k as DEFAULT_LARGE_FILE_THRESHOLD, A as DEFAULT_STALE_AGE, X as DatError, S as EXPLAIN_VERSION, C as MAX_EXPLAIN_LIMIT, K as VERSION, j as analyze, y as buildJsonSchema, L as classify, O as compare, m as createStyle, B as evaluateBudgets, w as explainPath, T as explainSkips, R as extensionOf, _ as findConfigFile, U as formatBytes, N as listDirectories, v as loadConfig, H as parseBudget, q as parseDuration, J as parsePointInTime, W 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-NtYCFeUO.js";
@@ -2980,6 +2980,15 @@ function entryType(stats) {
2980
2980
  function isSpecial(entry) {
2981
2981
  return entry.isBlockDevice() || entry.isCharacterDevice() || entry.isFIFO() || entry.isSocket();
2982
2982
  }
2983
+ /** Whether an absolute `target` lies outside the absolute directory `root`. */
2984
+ function isOutside(root, target) {
2985
+ const fromRoot = relative(root, target);
2986
+ return fromRoot === ".." || fromRoot.startsWith(`..${sep}`) || isAbsolute(fromRoot);
2987
+ }
2988
+ /** The error for a path outside the root, naming the path as the caller gave it. */
2989
+ function outsideRootError(path, root) {
2990
+ return new DatError(`${path} is outside the root ${root}.`, { hint: "Pass the directory that contains it with --root." });
2991
+ }
2983
2992
  /**
2984
2993
  * Explains what a scan of `root` with these settings does with one path:
2985
2994
  * whether it is counted, and if not, which rule or limit decided and where.
@@ -3001,9 +3010,8 @@ async function explainPath(root, path, settings = {}) {
3001
3010
  const { options, settings: resolved } = await resolveScan(root, settings, Date.now());
3002
3011
  const absRoot = options.root;
3003
3012
  const target = resolve(absRoot, path);
3004
- const fromRoot = relative(absRoot, target);
3005
- if (fromRoot === ".." || fromRoot.startsWith(`..${sep}`) || isAbsolute(fromRoot)) throw new DatError(`${path} is outside the root ${absRoot}.`, { hint: "Pass the directory that contains it with --root." });
3006
- const relPath = fromRoot.split(sep).join("/");
3013
+ if (isOutside(absRoot, target)) throw outsideRootError(path, absRoot);
3014
+ const relPath = relative(absRoot, target).split(sep).join("/");
3007
3015
  const segments = relPath ? relPath.split("/") : [];
3008
3016
  const excluder = options.excluder;
3009
3017
  const book = new RuleBook(excluder, absRoot, resolved.exclude);
@@ -4767,7 +4775,7 @@ function renderSkipsExplanation(result, options = {}) {
4767
4775
  result.groups.forEach((group, i) => {
4768
4776
  lines.push(` ${padEndVisible(labels[i], labelWidth)} ${s.bold(formatCount(group.count).padStart(countWidth))}`);
4769
4777
  for (const entry of group.entries) lines.push(` ${fitPath(entry, width - 6)}`);
4770
- if (group.truncated) {
4778
+ if (group.truncated && result.limit > 0) {
4771
4779
  const rest = group.count - group.entries.length;
4772
4780
  lines.push(s.dim(` … and ${formatCount(rest)} more (raise --limit, up to 1000, to list more)`));
4773
4781
  }
@@ -4785,4 +4793,4 @@ function renderSkipsExplanation(result, options = {}) {
4785
4793
  }
4786
4794
  return `${lines.join("\n")}\n`;
4787
4795
  }
4788
- export { DEFAULT_CONCURRENCY as A, parseBudget as B, MAX_EXPLAIN_LIMIT as C, DEFAULT_LARGE_FILE_THRESHOLD as D, compare as E, classify as F, parseDuration as G, parseSize as H, extensionOf as I, DatError as J, parsePointInTime as K, BUDGET_METRICS as L, joinRelative as M, DEFAULT_EXCLUDES as N, DEFAULT_STALE_AGE as O, Excluder as P, evaluateBudgets as R, EXPLAIN_VERSION as S, explainSkips as T, CATEGORIES as U, formatBytes as V, VERSION as W, errorMessage as X, errorCode as Y, findConfigFile as _, renderComparisonCsv as a, validateConfig as b, renderAnalysis as c, escapeControlInLines as d, formatCount as f, CONFIG_FILE_NAMES as g, supportsColor as h, renderAnalysisCsv as i, listDirectories as j, analyze as k, renderComparison as l, createStyle as m, renderSkipsExplanation as n, renderAnalysisMarkdown as o, stringifyJson as p, AbortError as q, renderAnalysisHtml as r, renderComparisonMarkdown as s, renderPathExplanation as t, escapeControl as u, loadConfig as v, explainPath as w, DEFAULT_EXPLAIN_LIMIT as x, buildJsonSchema as y, formatBudgetActual as z };
4796
+ export { DEFAULT_STALE_AGE as A, evaluateBudgets as B, MAX_EXPLAIN_LIMIT as C, outsideRootError as D, isOutside as E, DEFAULT_EXCLUDES as F, CATEGORIES as G, parseBudget as H, Excluder as I, parsePointInTime as J, VERSION as K, classify as L, DEFAULT_CONCURRENCY as M, listDirectories as N, compare as O, joinRelative as P, errorMessage as Q, extensionOf as R, EXPLAIN_VERSION as S, explainSkips as T, formatBytes as U, formatBudgetActual as V, parseSize as W, DatError as X, AbortError as Y, errorCode as Z, findConfigFile as _, renderComparisonCsv as a, validateConfig as b, renderAnalysis as c, escapeControlInLines as d, formatCount as f, CONFIG_FILE_NAMES as g, supportsColor as h, renderAnalysisCsv as i, analyze as j, DEFAULT_LARGE_FILE_THRESHOLD as k, renderComparison as l, createStyle as m, renderSkipsExplanation as n, renderAnalysisMarkdown as o, stringifyJson as p, parseDuration as q, renderAnalysisHtml as r, renderComparisonMarkdown as s, renderPathExplanation as t, escapeControl as u, loadConfig as v, explainPath as w, DEFAULT_EXPLAIN_LIMIT as x, buildJsonSchema as y, BUDGET_METRICS as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dir-analysis-tool",
3
- "version": "3.3.0",
3
+ "version": "3.3.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": {