1import * as Effect from "effect/Effect";
2import * as Cause from "effect/Cause";
3import * as Exit from "effect/Exit";
4import { FrameworkServerError } from "alchemy/Website/Server";
5import { registerHooks } from "node:module";
6
7// Simulate an absent optional peer without changing the workspace install.
8let attempts = 0;
9registerHooks({
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
22const providers: string[] = [];
23for (const provider of ["Prisma", "Neon", "Fly", "Hetzner", "Railway"]) {
24 const module = await import(`alchemy/${provider}`);
25 if (module.Website) providers.push(provider);
26}
27const providerImportAttempts = attempts;
28const { loadFrontendCore } = await import("alchemy/Website/FrontendCore");
29const exit = await Effect.runPromiseExit(loadFrontendCore);
30const error = Exit.isFailure(exit) ? Cause.squash(exit.cause) : undefined;
31console.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);