|
1 | 1 | import { mkdir, readFile, rename, rm, writeFile } from "node:fs/promises"; |
2 | 2 | import path from "node:path"; |
3 | 3 | import { build as esbuild } from "esbuild"; |
4 | | -import { createBuilder } from "vite"; |
| 4 | +import { createBuilder, type Rolldown } from "vite"; |
5 | 5 | import { ZuploEnv } from "../app/env.js"; |
6 | 6 | import { getZudokuRootDir } from "../cli/common/package-json.js"; |
7 | | -import { |
8 | | - findOutputPathOfServerConfig, |
9 | | - loadZudokuConfig, |
10 | | -} from "../config/loader.js"; |
| 7 | +import { type ConfigWithMeta, loadZudokuConfig } from "../config/loader.js"; |
11 | 8 | import { getIssuer } from "../lib/auth/issuer.js"; |
12 | 9 | import invariant from "../lib/util/invariant.js"; |
13 | 10 | import { joinUrl } from "../lib/util/joinUrl.js"; |
@@ -46,7 +43,11 @@ export async function runBuild(options: BuildOptions) { |
46 | 43 | clientResult && !Array.isArray(clientResult) && "output" in clientResult, |
47 | 44 | "Client build failed to produce valid output", |
48 | 45 | ); |
49 | | - invariant(serverResult, "SSR build failed to produce valid output"); |
| 46 | + |
| 47 | + invariant( |
| 48 | + serverResult && !Array.isArray(serverResult) && "output" in serverResult, |
| 49 | + "SSR build failed to produce valid output", |
| 50 | + ); |
50 | 51 |
|
51 | 52 | const { config } = await loadZudokuConfig( |
52 | 53 | { mode: "production", command: "build" }, |
@@ -102,18 +103,27 @@ export async function runBuild(options: BuildOptions) { |
102 | 103 |
|
103 | 104 | type PrerenderOptions = { |
104 | 105 | dir: string; |
105 | | - config: Awaited<ReturnType<typeof loadZudokuConfig>>["config"]; |
| 106 | + config: ConfigWithMeta; |
106 | 107 | html: string; |
107 | 108 | clientOutDir: string; |
108 | 109 | serverOutDir: string; |
109 | | - serverResult: Awaited<ReturnType<typeof import("vite").build>>; |
| 110 | + serverResult: Rolldown.RolldownOutput; |
| 111 | +}; |
| 112 | + |
| 113 | +const findServerConfigFilename = (result: Rolldown.RolldownOutput) => { |
| 114 | + const entry = result.output.find( |
| 115 | + (o) => o.type === "chunk" && o.isEntry && o.fileName === "zudoku.config.js", |
| 116 | + ); |
| 117 | + invariant(entry, "Could not find zudoku.config entry in server build output"); |
| 118 | + |
| 119 | + return entry.fileName; |
110 | 120 | }; |
111 | 121 |
|
112 | 122 | const runPrerender = async (options: PrerenderOptions) => { |
113 | 123 | const { dir, config, html, clientOutDir, serverOutDir, serverResult } = |
114 | 124 | options; |
115 | 125 | const issuer = await getIssuer(config); |
116 | | - const serverConfigFilename = findOutputPathOfServerConfig(serverResult); |
| 126 | + const serverConfigFilename = findServerConfigFilename(serverResult); |
117 | 127 |
|
118 | 128 | try { |
119 | 129 | const { workerResults, rewrites } = await prerender({ |
|
0 commit comments