import { readFileSync, realpathSync } from "node:fs"; import path from "node:path"; import { describe, expect, it } from "vitest"; import { bundledPackages, normalizeModuleId } from "../../scripts/lib/vite-module-inventory.ts"; // 13-12. The inventory recorded dependency modules as `external:`, // so nothing listed which package versions ship in the public bundle. describe("vite module inventory", () => { const root = process.cwd(); const zodCore = realpathSync(path.join(root, "node_modules/zod/v4/core/core.js")); const zodVersion = ( JSON.parse(readFileSync(path.join(root, "node_modules/zod/package.json"), "utf8")) as { version: string } ).version; it("names a dependency module by package and version", () => { expect(normalizeModuleId(zodCore, root)).toBe(`npm:zod@${zodVersion}/v4/core/core.js`); expect(normalizeModuleId(path.join(root, "src/bootstrap/main.tsx"), root)).toBe("src/bootstrap/main.tsx"); expect(normalizeModuleId("\0vite/preload-helper.js", root)).toBe("vite/preload-helper.js"); }); it("lists each bundled package once", () => { expect( bundledPackages([ { fileName: "a.js", modules: ["npm:zod@4.4.3/v4/core/core.js", "src/a.ts"] }, { fileName: "b.js", modules: ["npm:@tanstack/query-core@5.0.0/build/a.js", "npm:zod@4.4.3/index.js"] }, ]), ).toEqual(["@tanstack/query-core@5.0.0", "zod@4.4.3"]); }); });