diff --git a/src/application/javascript/JavaScriptArtifactGraphBundlers.ts b/src/application/javascript/JavaScriptArtifactGraphBundlers.ts index 134cc9a1516..f5a2e4f2b83 100644 --- a/src/application/javascript/JavaScriptArtifactGraphBundlers.ts +++ b/src/application/javascript/JavaScriptArtifactGraphBundlers.ts @@ -191,62 +191,44 @@ const addBundlerRuntimeEdges = ( ): number => { let selfAsyncChunks = 0; const { file, registration, chunk, coverage } = record; - for (const moduleKey of registration.entry_module_keys) { - const resolved = context.moduleNodes.get( - bundlerLookupKey(file.path, registration.runtime, moduleKey), - ); - const target = - resolved ?? unresolvedBundlerNode(context, record, "module", moduleKey); - context.accumulator.addEdge({ - source_node_id: chunk.node_id, - target_node_id: target.node_id, - relation: "loads", - properties: { - kind: "bundler-entry-module", - bundler: registration.bundler, - runtime: registration.runtime, - module_key: moduleKey, - resolution_status: resolved === undefined ? "not-found" : "resolved", - }, - evidence: staticInferenceEvidence({ - sha256: file.sha256, - path: file.path, - range: registration.location, - operation: "resolve-bundler-entry-module", - coverage, - confidence: resolved === undefined ? "low" : "high", - }), - }); - } - for (const chunkKey of registration.async_chunk_keys) { - const lookup = bundlerLookupKey(file.path, registration.runtime, chunkKey); - const resolved = context.chunkNodes.get(lookup); - if (resolved?.node_id === chunk.node_id) { - selfAsyncChunks++; - continue; + for (const kind of ["module", "chunk"] as const) { + const asyncChunk = kind === "chunk"; + const keys = asyncChunk + ? registration.async_chunk_keys + : registration.entry_module_keys; + const nodes = asyncChunk ? context.chunkNodes : context.moduleNodes; + const reference = asyncChunk ? "async-chunk" : "entry-module"; + for (const key of keys) { + const resolved = nodes.get( + bundlerLookupKey(file.path, registration.runtime, key), + ); + if (asyncChunk && resolved?.node_id === chunk.node_id) { + selfAsyncChunks++; + continue; + } + const target = + resolved ?? unresolvedBundlerNode(context, record, kind, key); + context.accumulator.addEdge({ + source_node_id: chunk.node_id, + target_node_id: target.node_id, + relation: asyncChunk ? "imports" : "loads", + properties: { + kind: `bundler-${reference}`, + bundler: registration.bundler, + runtime: registration.runtime, + [`${kind}_key`]: key, + resolution_status: resolved === undefined ? "not-found" : "resolved", + }, + evidence: staticInferenceEvidence({ + sha256: file.sha256, + path: file.path, + range: registration.location, + operation: `resolve-bundler-${reference}`, + coverage, + confidence: resolved === undefined ? "low" : "high", + }), + }); } - const target = - resolved ?? unresolvedBundlerNode(context, record, "chunk", chunkKey); - context.accumulator.addEdge({ - source_node_id: chunk.node_id, - target_node_id: target.node_id, - relation: "imports", - properties: { - kind: "bundler-async-chunk", - bundler: registration.bundler, - runtime: registration.runtime, - chunk_key: chunkKey, - resolution_status: resolved === undefined ? "not-found" : "resolved", - }, - evidence: staticInferenceEvidence({ - sha256: file.sha256, - path: file.path, - range: registration.location, - operation: "resolve-bundler-async-chunk", - coverage, - confidence: resolved === undefined ? "low" : "high", - }), - }); } return selfAsyncChunks; };