| 1 | import { RuntimeSubpathExportPlugin } from "../../internal/build-tools/RuntimeSubpathExportPlugin.ts"; |
| 2 | import { describe, expect, it } from "vitest"; |
| 3 | |
| 4 | describe("runtime subpath exports", () => { |
| 5 | it.each([ |
| 6 | [ |
| 7 | "shared wire constants", |
| 8 | "../../core/globals/EntryOptions.shared.ts", |
| 9 | "/workspace/packages/cloudflare-runtime/src/vite/module-runner/constants.shared.ts", |
| 10 | "@alchemy.run/cloudflare-runtime/core/globals/EntryOptions", |
| 11 | ], |
| 12 | [ |
| 13 | "POSIX", |
| 14 | "../core/index.ts", |
| 15 | "/workspace/packages/cloudflare-runtime/src/vite/plugin.ts", |
| 16 | "@alchemy.run/cloudflare-runtime/core", |
| 17 | ], |
| 18 | [ |
| 19 | "Windows", |
| 20 | "..\\rolldown\\options.ts", |
| 21 | "D:\\a\\alchemy\\alchemy\\packages\\cloudflare-runtime\\src\\vite\\plugin.ts", |
| 22 | "@alchemy.run/cloudflare-runtime/rolldown/options", |
| 23 | ], |
| 24 | ])( |
| 25 | "maps %s relative imports to public package exports", |
| 26 | (_, source, importer, expected) => { |
| 27 | const resolveId = RuntimeSubpathExportPlugin().resolveId; |
| 28 | expect(resolveId).toBeTypeOf("function"); |
| 29 | if (typeof resolveId !== "function") { |
| 30 | return; |
| 31 | } |
| 32 | |
| 33 | expect( |
| 34 | resolveId.call({} as never, source, importer, {} as never), |
| 35 | ).toEqual({ |
| 36 | id: expected, |
| 37 | external: true, |
| 38 | }); |
| 39 | }, |
| 40 | ); |
| 41 | }); |