| 1 | import * as Effect from "effect/Effect"; |
| 2 | import * as Cause from "effect/Cause"; |
| 3 | import * as Exit from "effect/Exit"; |
| 4 | import { FrameworkServerError } from "alchemy/Website/Server"; |
| 5 | import { registerHooks } from "node:module"; |
| 6 | |
| 7 | // Simulate an absent optional peer without changing the workspace install. |
| 8 | let attempts = 0; |
| 9 | registerHooks({ |
| 10 | resolve(specifier, context, nextResolve) { |
| 11 | if ( |
| 12 | specifier === "@alchemy.run/frontend-frameworks" || |
| 13 | specifier.startsWith("@alchemy.run/frontend-frameworks/") |
| 14 | ) { |
| 15 | attempts++; |
| 16 | throw new Error(`Cannot find package '${specifier}'`); |
| 17 | } |
| 18 | return nextResolve(specifier, context); |
| 19 | }, |
| 20 | }); |
| 21 | |
| 22 | const providers: string[] = []; |
| 23 | for (const provider of ["Prisma", "Neon", "Fly", "Hetzner", "Railway"]) { |
| 24 | const module = await import(`alchemy/${provider}`); |
| 25 | if (module.Website) providers.push(provider); |
| 26 | } |
| 27 | const providerImportAttempts = attempts; |
| 28 | const { loadFrontendCore } = await import("alchemy/Website/FrontendCore"); |
| 29 | const exit = await Effect.runPromiseExit(loadFrontendCore); |
| 30 | const error = Exit.isFailure(exit) ? Cause.squash(exit.cause) : undefined; |
| 31 | console.log( |
| 32 | JSON.stringify({ |
| 33 | providers, |
| 34 | providerImportAttempts, |
| 35 | loaderImportAttempts: attempts - providerImportAttempts, |
| 36 | defect: |
| 37 | Exit.isFailure(exit) && |
| 38 | exit.cause.reasons.some((reason) => reason._tag === "Die"), |
| 39 | error: |
| 40 | error instanceof FrameworkServerError |
| 41 | ? { |
| 42 | _tag: error._tag, |
| 43 | framework: error.framework, |
| 44 | message: error.message, |
| 45 | cause: |
| 46 | error.cause instanceof Error ? error.cause.message : error.cause, |
| 47 | } |
| 48 | : null, |
| 49 | }), |
| 50 | ); |