| 1 | import * as Effect from "effect/Effect"; |
| 2 | import { join } from "node:path"; |
| 3 | import { pathToFileURL } from "node:url"; |
| 4 | import { |
| 5 | ModuleLoadError, |
| 6 | resolveProjectPackageDirectory, |
| 7 | } from "../core/Loader.ts"; |
| 8 | |
| 9 | /** Vinext exposes import-only entrypoints that require.resolve cannot resolve. */ |
| 10 | export const loadVinextModule = <T>(root: string, file: string) => |
| 11 | resolveProjectPackageDirectory(root, "vinext").pipe( |
| 12 | Effect.flatMap((directory) => |
| 13 | Effect.tryPromise({ |
| 14 | try: () => |
| 15 | import( |
| 16 | /* @vite-ignore */ pathToFileURL(join(directory, "dist", file)).href |
| 17 | ) as Promise<T>, |
| 18 | catch: (cause) => |
| 19 | new ModuleLoadError({ root, specifier: `vinext/${file}`, cause }), |
| 20 | }), |
| 21 | ), |
| 22 | ); |