Prechádzať zdrojové kódy

fix(cli): deduplicate Node asset destinations (#39900)

Kit Langton 2 týždňov pred
rodič
commit
6c37842520

+ 3 - 2
packages/cli/script/node-assets.ts

@@ -58,8 +58,9 @@ export async function collectNodeAssets(target: NodeTarget) {
         source: path.join(ptyRoot, relative),
       })),
   ]
-  await Promise.all(assets.map((asset) => stat(asset.source)))
-  return assets
+  const unique = [...new Map(assets.map((asset) => [asset.key, asset])).values()]
+  await Promise.all(unique.map((asset) => stat(asset.source)))
+  return unique
 }
 
 export async function hashNodeAssets(assets: readonly NodeAsset[]) {

+ 17 - 0
packages/cli/test/node-assets.test.ts

@@ -0,0 +1,17 @@
+import { expect, test } from "bun:test"
+import { fileURLToPath } from "node:url"
+import { collectNodeAssets } from "../script/node-assets"
+import { nodeTarget, shellParserWasmAssets } from "../src/node/target"
+
+test("collects each SEA asset key once", async () => {
+  const assets = await collectNodeAssets(nodeTarget(process.platform, process.arch))
+  const keys = assets.map((asset) => asset.key)
+
+  expect(new Set(keys).size).toBe(keys.length)
+  expect(assets.filter((asset) => asset.key === shellParserWasmAssets.runtime)).toEqual([
+    {
+      key: shellParserWasmAssets.runtime,
+      source: fileURLToPath(import.meta.resolve(shellParserWasmAssets.runtime)),
+    },
+  ])
+})