@tanziro/plumbline-core 0.0.0-stage → 1.1.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/LICENSE +22 -0
- package/dist/chunk-VGYWIRJJ.js +201 -0
- package/dist/chunk-VGYWIRJJ.js.map +1 -0
- package/dist/graph/worker.d.ts +2 -0
- package/dist/graph/worker.js +12 -0
- package/dist/graph/worker.js.map +1 -0
- package/dist/index.d.ts +664 -0
- package/dist/index.js +1805 -0
- package/dist/index.js.map +1 -0
- package/package.json +47 -3
- package/schema/report.v1.json +219 -0
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Mohamed Ashref Ben Abdallah
|
|
4
|
+
Copyright (c) 2026 Tanzir (tanziro.com)
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
// src/git.ts
|
|
2
|
+
import { execFileSync, spawn } from "child_process";
|
|
3
|
+
import { mkdirSync } from "fs";
|
|
4
|
+
import { writeFile } from "fs/promises";
|
|
5
|
+
import { dirname, join } from "path";
|
|
6
|
+
var MAX_BUFFER = 256 * 1024 * 1024;
|
|
7
|
+
function git(cwd, args) {
|
|
8
|
+
return execFileSync("git", args, {
|
|
9
|
+
cwd,
|
|
10
|
+
encoding: "utf8",
|
|
11
|
+
maxBuffer: MAX_BUFFER,
|
|
12
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
13
|
+
windowsHide: true
|
|
14
|
+
}).trimEnd();
|
|
15
|
+
}
|
|
16
|
+
function tryGit(cwd, args) {
|
|
17
|
+
try {
|
|
18
|
+
return git(cwd, args);
|
|
19
|
+
} catch {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function refExists(cwd, ref) {
|
|
24
|
+
return tryGit(cwd, ["rev-parse", "--verify", "--quiet", `${ref}^{commit}`]) !== null;
|
|
25
|
+
}
|
|
26
|
+
function repoRoot(cwd) {
|
|
27
|
+
const root = tryGit(cwd, ["rev-parse", "--show-toplevel"]);
|
|
28
|
+
if (!root) throw new Error("not inside a git repository");
|
|
29
|
+
return root;
|
|
30
|
+
}
|
|
31
|
+
function shortSha(cwd, ref) {
|
|
32
|
+
return tryGit(cwd, ["rev-parse", "--short", ref]) ?? ref;
|
|
33
|
+
}
|
|
34
|
+
function showFile(cwd, ref, path) {
|
|
35
|
+
return tryGit(cwd, ["show", `${ref}:${path}`]);
|
|
36
|
+
}
|
|
37
|
+
var SKIP_DIR = /(^|\/)(node_modules|dist|build|out|coverage|vendor|\.git|\.next|\.nuxt|\.astro|\.plumbline|\.turbo|\.cache)\//;
|
|
38
|
+
var SOURCE = /\.(?:[cm]?[jt]s|[jt]sx|vue|svelte)$/;
|
|
39
|
+
var CONFIG = /(^|\/)(?:tsconfig[^/]*\.json|jsconfig\.json|package\.json)$/;
|
|
40
|
+
function isGraphPath(path) {
|
|
41
|
+
return !SKIP_DIR.test(path) && !path.endsWith(".d.ts") && SOURCE.test(path);
|
|
42
|
+
}
|
|
43
|
+
async function exportTree(cwd, ref, dest) {
|
|
44
|
+
const entries = git(cwd, ["ls-tree", "-r", "-z", "--full-tree", ref]).split("\0").filter(Boolean).flatMap((line) => {
|
|
45
|
+
const tab = line.indexOf(" ");
|
|
46
|
+
const [mode, type, sha] = line.slice(0, tab).split(" ");
|
|
47
|
+
const path = line.slice(tab + 1);
|
|
48
|
+
if (type !== "blob" || mode === "120000" || !sha) return [];
|
|
49
|
+
if (SKIP_DIR.test(path) || !(isGraphPath(path) || CONFIG.test(path))) return [];
|
|
50
|
+
return [{ sha, path }];
|
|
51
|
+
});
|
|
52
|
+
if (entries.length === 0) return 0;
|
|
53
|
+
const chunks = [];
|
|
54
|
+
await new Promise((resolvePromise, reject) => {
|
|
55
|
+
const child = spawn("git", ["cat-file", "--batch"], { cwd, stdio: ["pipe", "pipe", "ignore"], windowsHide: true });
|
|
56
|
+
child.stdout.on("data", (c) => chunks.push(c));
|
|
57
|
+
child.on("error", reject);
|
|
58
|
+
child.on("close", (code) => code === 0 ? resolvePromise() : reject(new Error(`git cat-file exited with ${code}`)));
|
|
59
|
+
child.stdin.end(entries.map((e) => e.sha).join("\n") + "\n");
|
|
60
|
+
});
|
|
61
|
+
const out = Buffer.concat(chunks);
|
|
62
|
+
const writes = [];
|
|
63
|
+
const dirs = /* @__PURE__ */ new Set();
|
|
64
|
+
let at = 0;
|
|
65
|
+
for (const entry of entries) {
|
|
66
|
+
const eol = out.indexOf(10, at);
|
|
67
|
+
const size = Number(out.subarray(at, eol).toString("utf8").split(" ")[2]);
|
|
68
|
+
const start = eol + 1;
|
|
69
|
+
const file = join(dest, entry.path);
|
|
70
|
+
dirs.add(dirname(file));
|
|
71
|
+
writes.push({ file, body: out.subarray(start, start + size) });
|
|
72
|
+
at = start + size + 1;
|
|
73
|
+
}
|
|
74
|
+
for (const dir of dirs) mkdirSync(dir, { recursive: true });
|
|
75
|
+
let next = 0;
|
|
76
|
+
const worker = async () => {
|
|
77
|
+
while (next < writes.length) {
|
|
78
|
+
const item = writes[next++];
|
|
79
|
+
await writeFile(item.file, item.body);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
await Promise.all(Array.from({ length: 32 }, worker));
|
|
83
|
+
return entries.length;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// src/graph/build.ts
|
|
87
|
+
import { fork } from "child_process";
|
|
88
|
+
import { existsSync, mkdtempSync, rmSync } from "fs";
|
|
89
|
+
import { tmpdir } from "os";
|
|
90
|
+
import { join as join2 } from "path";
|
|
91
|
+
import { fileURLToPath } from "url";
|
|
92
|
+
import { cruise } from "dependency-cruiser";
|
|
93
|
+
import extractTSConfig from "dependency-cruiser/config-utl/extract-ts-config";
|
|
94
|
+
var EXCLUDE = "(^|/)(node_modules|dist|build|out|coverage|vendor|\\.git|\\.next|\\.nuxt|\\.astro|\\.plumbline|\\.turbo|\\.cache)/|\\.d\\.ts$";
|
|
95
|
+
var toPosix = (p) => p.replaceAll("\\", "/").replace(/^\.\//, "");
|
|
96
|
+
function isLocal(resolved, coreModule, couldNotResolve) {
|
|
97
|
+
return !coreModule && !couldNotResolve && !toPosix(resolved).includes("node_modules/");
|
|
98
|
+
}
|
|
99
|
+
var cruising = Promise.resolve();
|
|
100
|
+
function fromDirectory(dir, work) {
|
|
101
|
+
const next = cruising.then(async () => {
|
|
102
|
+
const previous = process.cwd();
|
|
103
|
+
process.chdir(dir);
|
|
104
|
+
try {
|
|
105
|
+
return await work();
|
|
106
|
+
} finally {
|
|
107
|
+
process.chdir(previous);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
cruising = next.catch(() => void 0);
|
|
111
|
+
return next;
|
|
112
|
+
}
|
|
113
|
+
async function buildGraph(dir) {
|
|
114
|
+
const options = {
|
|
115
|
+
baseDir: dir,
|
|
116
|
+
exclude: { path: EXCLUDE },
|
|
117
|
+
doNotFollow: { path: "node_modules" },
|
|
118
|
+
tsPreCompilationDeps: true,
|
|
119
|
+
combinedDependencies: false,
|
|
120
|
+
// Plumbline does its own cycle and rule analysis, so skip dependency-cruiser's.
|
|
121
|
+
skipAnalysisNotInRules: true,
|
|
122
|
+
moduleSystems: ["es6", "cjs"],
|
|
123
|
+
metrics: false,
|
|
124
|
+
validate: false
|
|
125
|
+
};
|
|
126
|
+
let transpile;
|
|
127
|
+
const tsconfig = join2(dir, "tsconfig.json");
|
|
128
|
+
if (existsSync(tsconfig)) {
|
|
129
|
+
try {
|
|
130
|
+
transpile = { tsConfig: extractTSConfig(tsconfig) };
|
|
131
|
+
options.tsConfig = { fileName: tsconfig };
|
|
132
|
+
} catch {
|
|
133
|
+
transpile = void 0;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
const { output } = await fromDirectory(dir, () => cruise(["."], options, {}, transpile));
|
|
137
|
+
const result = output;
|
|
138
|
+
const files = /* @__PURE__ */ new Set();
|
|
139
|
+
const edges = /* @__PURE__ */ new Map();
|
|
140
|
+
for (const mod of result.modules) {
|
|
141
|
+
const from = toPosix(mod.source);
|
|
142
|
+
if (mod.coreModule || from.includes("node_modules/") || mod.couldNotResolve) continue;
|
|
143
|
+
files.add(from);
|
|
144
|
+
for (const dep of mod.dependencies) {
|
|
145
|
+
if (!isLocal(dep.resolved, dep.coreModule, dep.couldNotResolve)) continue;
|
|
146
|
+
const to = toPosix(dep.resolved);
|
|
147
|
+
const typeOnly = dep.dependencyTypes.includes("type-only") || dep.dependencyTypes.includes("pre-compilation-only");
|
|
148
|
+
const key = `${from}\0${to}`;
|
|
149
|
+
const prior = edges.get(key);
|
|
150
|
+
edges.set(key, { from, to, typeOnly: prior ? prior.typeOnly && typeOnly : typeOnly });
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return {
|
|
154
|
+
files: [...files].sort(),
|
|
155
|
+
edges: [...edges.values()].sort((a, b) => a.from.localeCompare(b.from) || a.to.localeCompare(b.to))
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
function buildGraphIsolated(dir) {
|
|
159
|
+
const worker = fileURLToPath(new URL("./graph/worker.js", import.meta.url));
|
|
160
|
+
if (!existsSync(worker)) return buildGraph(dir);
|
|
161
|
+
return new Promise((resolvePromise, reject) => {
|
|
162
|
+
const child = fork(worker, [], { stdio: ["ignore", "ignore", "pipe", "ipc"], serialization: "advanced" });
|
|
163
|
+
let settled = false;
|
|
164
|
+
let stderr = "";
|
|
165
|
+
child.stderr?.on("data", (chunk) => stderr += chunk.toString());
|
|
166
|
+
child.once("message", (reply) => {
|
|
167
|
+
settled = true;
|
|
168
|
+
if (reply.ok) resolvePromise(reply.graph);
|
|
169
|
+
else reject(new Error(reply.error));
|
|
170
|
+
});
|
|
171
|
+
child.once("error", reject);
|
|
172
|
+
child.once("exit", (code) => {
|
|
173
|
+
if (!settled) reject(new Error(`graph worker exited with ${code}: ${stderr.trim()}`));
|
|
174
|
+
});
|
|
175
|
+
child.send({ dir });
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
async function buildGraphAtRef(repo, ref) {
|
|
179
|
+
const dest = mkdtempSync(join2(tmpdir(), "plumbline-graph-"));
|
|
180
|
+
try {
|
|
181
|
+
const written = await exportTree(repo, ref, dest);
|
|
182
|
+
if (written === 0) return { files: [], edges: [] };
|
|
183
|
+
return await buildGraphIsolated(dest);
|
|
184
|
+
} finally {
|
|
185
|
+
rmSync(dest, { recursive: true, force: true });
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export {
|
|
190
|
+
git,
|
|
191
|
+
tryGit,
|
|
192
|
+
refExists,
|
|
193
|
+
repoRoot,
|
|
194
|
+
shortSha,
|
|
195
|
+
showFile,
|
|
196
|
+
exportTree,
|
|
197
|
+
buildGraph,
|
|
198
|
+
buildGraphIsolated,
|
|
199
|
+
buildGraphAtRef
|
|
200
|
+
};
|
|
201
|
+
//# sourceMappingURL=chunk-VGYWIRJJ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/git.ts","../src/graph/build.ts"],"sourcesContent":["import { execFileSync, spawn } from \"node:child_process\";\nimport { mkdirSync } from \"node:fs\";\nimport { writeFile } from \"node:fs/promises\";\nimport { dirname, join } from \"node:path\";\n\nconst MAX_BUFFER = 256 * 1024 * 1024;\n\n/** Run git with an argument array. No shell is involved, so refs and paths cannot inject commands. */\nexport function git(cwd: string, args: string[]): string {\n return execFileSync(\"git\", args, {\n cwd,\n encoding: \"utf8\",\n maxBuffer: MAX_BUFFER,\n stdio: [\"ignore\", \"pipe\", \"pipe\"],\n windowsHide: true,\n }).trimEnd();\n}\n\nexport function tryGit(cwd: string, args: string[]): string | null {\n try {\n return git(cwd, args);\n } catch {\n return null;\n }\n}\n\nexport function refExists(cwd: string, ref: string): boolean {\n return tryGit(cwd, [\"rev-parse\", \"--verify\", \"--quiet\", `${ref}^{commit}`]) !== null;\n}\n\nexport function repoRoot(cwd: string): string {\n const root = tryGit(cwd, [\"rev-parse\", \"--show-toplevel\"]);\n if (!root) throw new Error(\"not inside a git repository\");\n return root;\n}\n\nexport function shortSha(cwd: string, ref: string): string {\n return tryGit(cwd, [\"rev-parse\", \"--short\", ref]) ?? ref;\n}\n\n/** Read one file at a ref, or null when it does not exist there. */\nexport function showFile(cwd: string, ref: string, path: string): string | null {\n return tryGit(cwd, [\"show\", `${ref}:${path}`]);\n}\n\nconst SKIP_DIR = /(^|\\/)(node_modules|dist|build|out|coverage|vendor|\\.git|\\.next|\\.nuxt|\\.astro|\\.plumbline|\\.turbo|\\.cache)\\//;\nconst SOURCE = /\\.(?:[cm]?[jt]s|[jt]sx|vue|svelte)$/;\nconst CONFIG = /(^|\\/)(?:tsconfig[^/]*\\.json|jsconfig\\.json|package\\.json)$/;\n\nexport function isGraphPath(path: string): boolean {\n return !SKIP_DIR.test(path) && !path.endsWith(\".d.ts\") && SOURCE.test(path);\n}\n\n/**\n * Write a ref's source and config files into `dest` using `git cat-file --batch`.\n * This never touches the working tree, the index or the worktree list.\n */\nexport async function exportTree(cwd: string, ref: string, dest: string): Promise<number> {\n const entries = git(cwd, [\"ls-tree\", \"-r\", \"-z\", \"--full-tree\", ref])\n .split(\"\\0\")\n .filter(Boolean)\n .flatMap((line) => {\n const tab = line.indexOf(\"\\t\");\n const [mode, type, sha] = line.slice(0, tab).split(\" \");\n const path = line.slice(tab + 1);\n if (type !== \"blob\" || mode === \"120000\" || !sha) return [];\n if (SKIP_DIR.test(path) || !(isGraphPath(path) || CONFIG.test(path))) return [];\n return [{ sha, path }];\n });\n if (entries.length === 0) return 0;\n\n const chunks: Buffer[] = [];\n await new Promise<void>((resolvePromise, reject) => {\n const child = spawn(\"git\", [\"cat-file\", \"--batch\"], { cwd, stdio: [\"pipe\", \"pipe\", \"ignore\"], windowsHide: true });\n child.stdout.on(\"data\", (c: Buffer) => chunks.push(c));\n child.on(\"error\", reject);\n child.on(\"close\", (code) => (code === 0 ? resolvePromise() : reject(new Error(`git cat-file exited with ${code}`))));\n child.stdin.end(entries.map((e) => e.sha).join(\"\\n\") + \"\\n\");\n });\n\n const out = Buffer.concat(chunks);\n const writes: { file: string; body: Buffer }[] = [];\n const dirs = new Set<string>();\n let at = 0;\n for (const entry of entries) {\n const eol = out.indexOf(0x0a, at);\n const size = Number(out.subarray(at, eol).toString(\"utf8\").split(\" \")[2]);\n const start = eol + 1;\n const file = join(dest, entry.path);\n dirs.add(dirname(file));\n writes.push({ file, body: out.subarray(start, start + size) });\n at = start + size + 1;\n }\n for (const dir of dirs) mkdirSync(dir, { recursive: true });\n\n // Per-file open and close dominates on Windows, so write with bounded concurrency.\n let next = 0;\n const worker = async () => {\n while (next < writes.length) {\n const item = writes[next++] as { file: string; body: Buffer };\n await writeFile(item.file, item.body);\n }\n };\n await Promise.all(Array.from({ length: 32 }, worker));\n return entries.length;\n}\n","import { fork } from \"node:child_process\";\nimport { existsSync, mkdtempSync, rmSync } from \"node:fs\";\nimport { tmpdir } from \"node:os\";\nimport { join } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { cruise, type ICruiseOptions, type ICruiseResult } from \"dependency-cruiser\";\nimport extractTSConfig from \"dependency-cruiser/config-utl/extract-ts-config\";\nimport { exportTree } from \"../git.js\";\nimport type { GraphEdge, ImportGraph } from \"../types.js\";\n\nconst EXCLUDE =\n \"(^|/)(node_modules|dist|build|out|coverage|vendor|\\\\.git|\\\\.next|\\\\.nuxt|\\\\.astro|\\\\.plumbline|\\\\.turbo|\\\\.cache)/|\\\\.d\\\\.ts$\";\n\nconst toPosix = (p: string) => p.replaceAll(\"\\\\\", \"/\").replace(/^\\.\\//, \"\");\n\nfunction isLocal(resolved: string, coreModule: boolean, couldNotResolve: boolean): boolean {\n return !coreModule && !couldNotResolve && !toPosix(resolved).includes(\"node_modules/\");\n}\n\nlet cruising: Promise<unknown> = Promise.resolve();\n\n/**\n * dependency-cruiser resolves tsconfig `paths` without a `baseUrl` from the process working directory.\n * Run one pass at a time from the graph's own folder, so aliases cannot resolve into another checkout.\n */\nfunction fromDirectory<T>(dir: string, work: () => Promise<T>): Promise<T> {\n const next = cruising.then(async () => {\n const previous = process.cwd();\n process.chdir(dir);\n try {\n return await work();\n } finally {\n process.chdir(previous);\n }\n });\n cruising = next.catch(() => undefined);\n return next;\n}\n\n/** Build the file-level import graph of a directory with dependency-cruiser. */\nexport async function buildGraph(dir: string): Promise<ImportGraph> {\n const options: ICruiseOptions = {\n baseDir: dir,\n exclude: { path: EXCLUDE },\n doNotFollow: { path: \"node_modules\" },\n tsPreCompilationDeps: true,\n combinedDependencies: false,\n // Plumbline does its own cycle and rule analysis, so skip dependency-cruiser's.\n skipAnalysisNotInRules: true,\n moduleSystems: [\"es6\", \"cjs\"],\n metrics: false,\n validate: false,\n };\n\n let transpile: { tsConfig: ReturnType<typeof extractTSConfig> } | undefined;\n const tsconfig = join(dir, \"tsconfig.json\");\n if (existsSync(tsconfig)) {\n try {\n transpile = { tsConfig: extractTSConfig(tsconfig) };\n options.tsConfig = { fileName: tsconfig };\n } catch {\n // An `extends` into an uninstalled package is common on an exported tree.\n // Relative imports still resolve, so carry on without path aliases.\n transpile = undefined;\n }\n }\n\n const { output } = await fromDirectory(dir, () => cruise([\".\"], options, {}, transpile));\n const result = output as ICruiseResult;\n const files = new Set<string>();\n const edges = new Map<string, GraphEdge>();\n\n for (const mod of result.modules) {\n const from = toPosix(mod.source);\n if (mod.coreModule || from.includes(\"node_modules/\") || mod.couldNotResolve) continue;\n files.add(from);\n for (const dep of mod.dependencies) {\n if (!isLocal(dep.resolved, dep.coreModule, dep.couldNotResolve)) continue;\n const to = toPosix(dep.resolved);\n const typeOnly = dep.dependencyTypes.includes(\"type-only\") || dep.dependencyTypes.includes(\"pre-compilation-only\");\n const key = `${from}\\0${to}`;\n const prior = edges.get(key);\n // A pair imported both ways counts as a runtime edge.\n edges.set(key, { from, to, typeOnly: prior ? prior.typeOnly && typeOnly : typeOnly });\n }\n }\n\n return {\n files: [...files].sort(),\n edges: [...edges.values()].sort((a, b) => a.from.localeCompare(b.from) || a.to.localeCompare(b.to)),\n };\n}\n\n/** Build a graph in a child process when the built worker is available, otherwise in this process. */\nexport function buildGraphIsolated(dir: string): Promise<ImportGraph> {\n const worker = fileURLToPath(new URL(\"./graph/worker.js\", import.meta.url));\n if (!existsSync(worker)) return buildGraph(dir);\n\n return new Promise((resolvePromise, reject) => {\n const child = fork(worker, [], { stdio: [\"ignore\", \"ignore\", \"pipe\", \"ipc\"], serialization: \"advanced\" });\n let settled = false;\n let stderr = \"\";\n child.stderr?.on(\"data\", (chunk: Buffer) => (stderr += chunk.toString()));\n child.once(\"message\", (reply: { ok: true; graph: ImportGraph } | { ok: false; error: string }) => {\n settled = true;\n if (reply.ok) resolvePromise(reply.graph);\n else reject(new Error(reply.error));\n });\n child.once(\"error\", reject);\n child.once(\"exit\", (code) => {\n if (!settled) reject(new Error(`graph worker exited with ${code}: ${stderr.trim()}`));\n });\n child.send({ dir });\n });\n}\n\n/** Build the graph of a git ref without touching the working tree. */\nexport async function buildGraphAtRef(repo: string, ref: string): Promise<ImportGraph> {\n const dest = mkdtempSync(join(tmpdir(), \"plumbline-graph-\"));\n try {\n const written = await exportTree(repo, ref, dest);\n if (written === 0) return { files: [], edges: [] };\n return await buildGraphIsolated(dest);\n } finally {\n rmSync(dest, { recursive: true, force: true });\n }\n}\n"],"mappings":";AAAA,SAAS,cAAc,aAAa;AACpC,SAAS,iBAAiB;AAC1B,SAAS,iBAAiB;AAC1B,SAAS,SAAS,YAAY;AAE9B,IAAM,aAAa,MAAM,OAAO;AAGzB,SAAS,IAAI,KAAa,MAAwB;AACvD,SAAO,aAAa,OAAO,MAAM;AAAA,IAC/B;AAAA,IACA,UAAU;AAAA,IACV,WAAW;AAAA,IACX,OAAO,CAAC,UAAU,QAAQ,MAAM;AAAA,IAChC,aAAa;AAAA,EACf,CAAC,EAAE,QAAQ;AACb;AAEO,SAAS,OAAO,KAAa,MAA+B;AACjE,MAAI;AACF,WAAO,IAAI,KAAK,IAAI;AAAA,EACtB,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEO,SAAS,UAAU,KAAa,KAAsB;AAC3D,SAAO,OAAO,KAAK,CAAC,aAAa,YAAY,WAAW,GAAG,GAAG,WAAW,CAAC,MAAM;AAClF;AAEO,SAAS,SAAS,KAAqB;AAC5C,QAAM,OAAO,OAAO,KAAK,CAAC,aAAa,iBAAiB,CAAC;AACzD,MAAI,CAAC,KAAM,OAAM,IAAI,MAAM,6BAA6B;AACxD,SAAO;AACT;AAEO,SAAS,SAAS,KAAa,KAAqB;AACzD,SAAO,OAAO,KAAK,CAAC,aAAa,WAAW,GAAG,CAAC,KAAK;AACvD;AAGO,SAAS,SAAS,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ACnC,QAAO,IAAI,MAAM,MAAM,KAAK,CAAC;AAAA,IACpC,CAAC;AACD,UAAM,KAAK,SAAS,MAAM;AAC1B,UAAM,KAAK,QAAQ,CAAC,SAAS;AAC3B,UAAI,CAAC,QAAS,QAAO,IAAI,MAAM,4BAA4B,IAAI,KAAK,OAAO,KAAK,CAAC,EAAE,CAAC;AAAA,IACtF,CAAC;AACD,UAAM,KAAK,EAAE,IAAI,CAAC;AAAA,EACpB,CAAC;AACH;AAGA,eAAsB,gBAAgB,MAAc,KAAmC;AACrF,QAAM,OAAO,YAAYA,MAAK,OAAO,GAAG,kBAAkB,CAAC;AAC3D,MAAI;AACF,UAAM,UAAU,MAAM,WAAW,MAAM,KAAK,IAAI;AAChD,QAAI,YAAY,EAAG,QAAO,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,EAAE;AACjD,WAAO,MAAM,mBAAmB,IAAI;AAAA,EACtC,UAAE;AACA,WAAO,MAAM,EAAE,WAAW,MAAM,OAAO,KAAK,CAAC;AAAA,EAC/C;AACF;","names":["join","join"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {
|
|
2
|
+
buildGraph
|
|
3
|
+
} from "../chunk-VGYWIRJJ.js";
|
|
4
|
+
|
|
5
|
+
// src/graph/worker.ts
|
|
6
|
+
var reply = (message) => {
|
|
7
|
+
process.send?.(message, void 0, void 0, () => process.disconnect?.());
|
|
8
|
+
};
|
|
9
|
+
process.once("message", (message) => {
|
|
10
|
+
buildGraph(message.dir).then((graph) => reply({ ok: true, graph })).catch((error) => reply({ ok: false, error: error instanceof Error ? error.message : String(error) }));
|
|
11
|
+
});
|
|
12
|
+
//# sourceMappingURL=worker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/graph/worker.ts"],"sourcesContent":["import { buildGraph } from \"./build.js\";\n\n// Disconnect only after the reply is flushed. Otherwise a large graph can be lost when the process exits.\nconst reply = (message: unknown) => {\n process.send?.(message, undefined, undefined, () => process.disconnect?.());\n};\n\n// Runs one dependency-cruiser pass in its own process, so base and HEAD can use separate cores.\nprocess.once(\"message\", (message: { dir: string }) => {\n buildGraph(message.dir)\n .then((graph) => reply({ ok: true, graph }))\n .catch((error: unknown) => reply({ ok: false, error: error instanceof Error ? error.message : String(error) }));\n});\n"],"mappings":";;;;;AAGA,IAAM,QAAQ,CAAC,YAAqB;AAClC,UAAQ,OAAO,SAAS,QAAW,QAAW,MAAM,QAAQ,aAAa,CAAC;AAC5E;AAGA,QAAQ,KAAK,WAAW,CAAC,YAA6B;AACpD,aAAW,QAAQ,GAAG,EACnB,KAAK,CAAC,UAAU,MAAM,EAAE,IAAI,MAAM,MAAM,CAAC,CAAC,EAC1C,MAAM,CAAC,UAAmB,MAAM,EAAE,IAAI,OAAO,OAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,EAAE,CAAC,CAAC;AAClH,CAAC;","names":[]}
|