MCPcopy Create free account
hub / github.com/OpenHands/OpenHands / imageScriptGraph

Function imageScriptGraph

__tests__/scripts/docker-script-imports.test.ts:40–74  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

38// the entrypoint runs must come with a COPY line, or the container crashes on
39// start with ERR_MODULE_NOT_FOUND (#18342).
40function imageScriptGraph(): { scripts: Set<string>; packages: Set<string> } {
41 const scripts = new Set<string>();
42 const packages = new Set<string>();
43 const queue = [
44 ...entrypoint.matchAll(/\bnode \/opt\/agent-canvas\/([\w.-]+\.mjs)/g),
45 ].map((match) => match[1]);
46
47 while (queue.length > 0) {
48 const script = queue.pop()!;
49 if (scripts.has(script)) continue;
50 scripts.add(script);
51
52 // Drop block comments so JSDoc `import("electron")` types don't count.
53 const source = readFileSync(
54 path.join(repoRoot, "scripts", script),
55 "utf-8",
56 ).replace(/\/\*[\s\S]*?\*\//g, "");
57 const specifiers = [
58 ...source.matchAll(/^\s*(?:import|export)\b[^;]*?\bfrom\s+"([^"]+)"/gm),
59 ...source.matchAll(/^\s*import\s+"([^"]+)"/gm),
60 ...source.matchAll(/\bimport\(\s*"([^"]+)"\s*\)/g),
61 ].map((match) => match[1]);
62
63 for (const specifier of specifiers) {
64 if (specifier.startsWith("./")) {
65 queue.push(specifier.slice(2));
66 } else if (!specifier.startsWith("node:")) {
67 const [scope, name] = specifier.split("/");
68 packages.add(scope.startsWith("@") ? `${scope}/${name}` : scope);
69 }
70 }
71 }
72
73 return { scripts, packages };
74}
75
76describe("Docker image script imports", () => {
77 const { scripts, packages } = imageScriptGraph();

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected