@pruddiman/hem 0.0.1-beta-9f44128 → 0.0.1-beta-72c22cf

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.
@@ -35,7 +35,8 @@ export interface ImportAnalysis {
35
35
  }
36
36
  /**
37
37
  * Build the import graph for a set of files. Files that fail to read are
38
- * silently skipped (they contribute no edges).
38
+ * silently skipped (they contribute no edges). Reads run in parallel with
39
+ * a bounded concurrency to keep wall-clock time low on large projects.
39
40
  */
40
41
  export declare function buildImportGraph(files: FileInfo[]): Promise<ImportAnalysis>;
41
42
  /**
@@ -11,6 +11,15 @@
11
11
  * integration catalog with file:line citations.
12
12
  */
13
13
  import { readFile } from "node:fs/promises";
14
+ import pLimit from "p-limit";
15
+ /**
16
+ * Files larger than this byte count are skipped when building the import
17
+ * graph. Huge generated files (lockfiles, bundled output) rarely contain
18
+ * useful import edges and reading them can stall the pipeline for minutes.
19
+ */
20
+ const MAX_FILE_BYTES = 2 * 1024 * 1024; // 2 MB
21
+ /** Parallel file reads when building the graph. */
22
+ const READ_CONCURRENCY = 32;
14
23
  // ── Regexes ─────────────────────────────────────────────────────────────
15
24
  // Static: `import ... from "x"` or `export ... from "x"`
16
25
  const STATIC_RE = /(?:import|export)\s+[^;'"`]*?\s+from\s+["']([^"']+)["']/g;
@@ -19,21 +28,25 @@ const DYNAMIC_RE = /(?:import|require)\s*\(\s*["']([^"']+)["']\s*\)/g;
19
28
  // ── Public API ──────────────────────────────────────────────────────────
20
29
  /**
21
30
  * Build the import graph for a set of files. Files that fail to read are
22
- * silently skipped (they contribute no edges).
31
+ * silently skipped (they contribute no edges). Reads run in parallel with
32
+ * a bounded concurrency to keep wall-clock time low on large projects.
23
33
  */
24
34
  export async function buildImportGraph(files) {
25
35
  const known = new Set(files.map((f) => f.path));
26
36
  const localEdges = new Map();
27
37
  const externalImports = new Map();
28
- for (const file of files) {
38
+ const limit = pLimit(READ_CONCURRENCY);
39
+ await Promise.all(files.map((file) => limit(async () => {
29
40
  if (file.isBinary)
30
- continue;
41
+ return;
42
+ if (file.size > MAX_FILE_BYTES)
43
+ return;
31
44
  let content;
32
45
  try {
33
46
  content = await readFile(file.absolutePath, "utf-8");
34
47
  }
35
48
  catch {
36
- continue;
49
+ return;
37
50
  }
38
51
  const local = [];
39
52
  const external = [];
@@ -55,7 +68,7 @@ export async function buildImportGraph(files) {
55
68
  if (external.length > 0) {
56
69
  externalImports.set(file.path, external);
57
70
  }
58
- }
71
+ })));
59
72
  return { localEdges, externalImports };
60
73
  }
61
74
  /**
package/dist/index.js CHANGED
@@ -519,9 +519,14 @@ export async function handleGenerate(opts, deps = defaultDeps) {
519
519
  .map((p) => p.name)
520
520
  .join(", ")}`);
521
521
  }
522
+ if (cliOptions.verbose) {
523
+ verboseLog(`[grouping] building import graph from ${textFiles.length} files...`);
524
+ }
525
+ const importGraphStart = Date.now();
522
526
  const importAnalysis = await buildImportGraph(textFiles);
523
527
  if (cliOptions.verbose) {
524
- verboseLog(`[grouping] import graph: ${importAnalysis.localEdges.size} files with local edges, ` +
528
+ const elapsed = ((Date.now() - importGraphStart) / 1000).toFixed(1);
529
+ verboseLog(`[grouping] import graph built in ${elapsed}s: ${importAnalysis.localEdges.size} files with local edges, ` +
525
530
  `${importAnalysis.externalImports.size} with external imports`);
526
531
  }
527
532
  const groups = deps.groupFiles(textFiles, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pruddiman/hem",
3
- "version": "0.0.1-beta-9f44128",
3
+ "version": "0.0.1-beta-72c22cf",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "hem": "./dist/index.js"