@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 75 lines 3.2 KB
Raw
1 import * as Effect from "effect/Effect";
2 import type { PluginOption } from "vite";
3 import { loadVinextModule } from "./Modules.ts";
4
5 interface NextConfigModule {
6 PHASE_PRODUCTION_BUILD: string;
7 findVinextNextConfigInPlugins(plugins: PluginOption[] | undefined): Promise<unknown>;
8 resolveNextConfigInput(config: unknown, phase: string): Promise<unknown>;
9 loadNextConfig(root: string, phase: string): Promise<unknown>;
10 resolveNextConfig(
11 config: unknown,
12 root: string,
13 ): Promise<{
14 buildId: string;
15 output?: "standalone" | "export";
16 }>;
17 createRscCompatibilityId(config: unknown): string;
18 }
19
20 /** The `vinext()` options that locate the app and its build outputs. */
21 export interface VinextRouteRootConfig {
22 readonly appDir?: string;
23 readonly clientOutDir?: string;
24 readonly rscOutDir?: string;
25 readonly ssrOutDir?: string;
26 }
27
28 interface PrerenderConfigModule {
29 findVinextPrerenderConfigInPlugins(
30 plugins: PluginOption[] | undefined,
31 ): Promise<{ readonly concurrency?: number } | null>;
32 findVinextRouteRootConfigInPlugins(
33 plugins: PluginOption[] | undefined,
34 ): Promise<VinextRouteRootConfig | null>;
35 findVinextCacheConfigInPlugins(plugins: PluginOption[] | undefined): Promise<unknown>;
36 hasBuildIdentityResponseHeader(cache: unknown): boolean;
37 hasVerbatimResponseVary(cache: unknown): boolean;
38 hasUncachedRequestRouting(cache: unknown): boolean;
39 isConfiguredCdnResponsePolicyHeader(cache: unknown, name: string): boolean;
40 }
41
42 /** Keep native configuration objects intact when forwarding them between build phases. */
43 export const loadVinextBuildConfig = Effect.fn(function* (
44 root: string,
45 plugins: PluginOption[] | undefined,
46 ) {
47 const next = yield* loadVinextModule<NextConfigModule>(root, "config/next-config.js");
48 const prerender = yield* loadVinextModule<PrerenderConfigModule>(root, "config/prerender.js");
49 return yield* Effect.tryPromise(async () => {
50 const input = await next.findVinextNextConfigInPlugins(plugins);
51 const raw = input
52 ? await next.resolveNextConfigInput(input, next.PHASE_PRODUCTION_BUILD)
53 : await next.loadNextConfig(root, next.PHASE_PRODUCTION_BUILD);
54 const nextConfig = await next.resolveNextConfig(raw, root);
55 const cache = await prerender.findVinextCacheConfigInPlugins(plugins);
56 return {
57 /** Inline `vinext({ nextConfig })` before resolution, or undefined for a next.config file. */
58 nextConfigInput: input ?? undefined,
59 cacheConfig: cache,
60 nextConfig,
61 rscCompatibilityId: next.createRscCompatibilityId(nextConfig),
62 prerenderConfig: await prerender.findVinextPrerenderConfigInPlugins(plugins),
63 routeRootConfig: await prerender.findVinextRouteRootConfigInPlugins(plugins),
64 buildIdentity: prerender.hasBuildIdentityResponseHeader(cache)
65 ? "response-header"
66 : undefined,
67 responseVary: prerender.hasVerbatimResponseVary(cache) ? "verbatim" : undefined,
68 requestRouting: prerender.hasUncachedRequestRouting(cache) ? "uncached-stage" : undefined,
69 isResponsePolicyHeader: (name: string) =>
70 prerender.isConfiguredCdnResponsePolicyHeader(cache, name),
71 };
72 });
73 });
74
75 export type VinextBuildConfig = Effect.Success<ReturnType<typeof loadVinextBuildConfig>>;