()
| 38 | // the entrypoint runs must come with a COPY line, or the container crashes on |
| 39 | // start with ERR_MODULE_NOT_FOUND (#18342). |
| 40 | function 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 | |
| 76 | describe("Docker image script imports", () => { |
| 77 | const { scripts, packages } = imageScriptGraph(); |
no outgoing calls
no test coverage detected