Skip to content

Commit ec21f5d

Browse files
feat(remix-dev/vite): pass entire remixConfig to buildEnd (#8595)
1 parent e4aab77 commit ec21f5d

File tree

3 files changed

+57
-45
lines changed

3 files changed

+57
-45
lines changed

integration/vite-adapter-test.ts

Lines changed: 48 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,18 @@ test.describe(async () => {
3838
},
3939
async buildEnd(args) {
4040
let fs = await import("node:fs/promises");
41-
await fs.writeFile("BUILD_END_ARGS.json", JSON.stringify(args, null, 2), "utf-8");
41+
await fs.writeFile(
42+
"BUILD_END_ARGS.json",
43+
JSON.stringify(
44+
args,
45+
function replacer(key, value) {
46+
return typeof value === "function"
47+
? value.toString()
48+
: value;
49+
},
50+
2,
51+
),
52+
"utf-8");
4253
}
4354
}),
4455
@@ -68,34 +79,45 @@ test.describe(async () => {
6879
// Rewrite path args to be relative and normalized for snapshot test
6980
remixConfig.buildDirectory = relativeToCwd(remixConfig.buildDirectory);
7081

71-
expect(buildEndArgs).toEqual({
72-
remixConfig: {
73-
buildDirectory: "build",
74-
serverBuildFile: "index.js",
75-
unstable_ssr: true,
82+
expect(Object.keys(buildEndArgs)).toEqual(["buildManifest", "remixConfig"]);
83+
84+
// Smoke test the resolved config
85+
expect(Object.keys(buildEndArgs.remixConfig)).toEqual([
86+
"adapter",
87+
"appDirectory",
88+
"buildDirectory",
89+
"future",
90+
"manifest",
91+
"publicPath",
92+
"routes",
93+
"serverBuildFile",
94+
"serverBundles",
95+
"serverModuleFormat",
96+
"unstable_ssr",
97+
]);
98+
99+
// Ensure we get a valid build manifest
100+
expect(buildEndArgs.buildManifest).toEqual({
101+
routeIdToServerBundleId: {
102+
"routes/_index": "user-options--adapter-options",
76103
},
77-
buildManifest: {
78-
routeIdToServerBundleId: {
79-
"routes/_index": "user-options--adapter-options",
104+
routes: {
105+
root: {
106+
file: "app/root.tsx",
107+
id: "root",
108+
path: "",
80109
},
81-
routes: {
82-
root: {
83-
file: "app/root.tsx",
84-
id: "root",
85-
path: "",
86-
},
87-
"routes/_index": {
88-
file: "app/routes/_index.tsx",
89-
id: "routes/_index",
90-
index: true,
91-
parentId: "root",
92-
},
110+
"routes/_index": {
111+
file: "app/routes/_index.tsx",
112+
id: "routes/_index",
113+
index: true,
114+
parentId: "root",
93115
},
94-
serverBundles: {
95-
"user-options--adapter-options": {
96-
file: "build/server/user-options--adapter-options/index.js",
97-
id: "user-options--adapter-options",
98-
},
116+
},
117+
serverBundles: {
118+
"user-options--adapter-options": {
119+
file: "build/server/user-options--adapter-options/index.js",
120+
id: "user-options--adapter-options",
99121
},
100122
},
101123
});

packages/remix-dev/vite/build.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -289,14 +289,8 @@ export async function build(
289289
);
290290
}
291291

292-
let { buildDirectory, serverBuildFile, ssr } = remixConfig;
293-
294292
await remixConfig.adapter?.buildEnd?.({
295293
buildManifest,
296-
remixConfig: {
297-
buildDirectory,
298-
serverBuildFile,
299-
unstable_ssr: ssr,
300-
},
294+
remixConfig,
301295
});
302296
}

packages/remix-dev/vite/plugin.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,7 @@ export type VitePluginConfig = RemixEsbuildUserConfigJsdocOverrides &
175175
};
176176

177177
type BuildEndHook = (args: {
178-
remixConfig: Pick<
179-
ResolvedVitePluginConfig,
180-
"buildDirectory" | "serverBuildFile"
181-
> & { unstable_ssr: boolean };
178+
remixConfig: ResolvedVitePluginConfig;
182179
buildManifest: BuildManifest | undefined;
183180
}) => void | Promise<void>;
184181

@@ -191,7 +188,7 @@ export type ResolvedVitePluginConfig = Pick<
191188
manifest: boolean;
192189
serverBuildFile: string;
193190
serverBundles?: ServerBundlesFunction;
194-
ssr: boolean;
191+
unstable_ssr: boolean;
195192
};
196193

197194
export type ServerBundleBuildConfig = {
@@ -473,9 +470,8 @@ export const remixVitePlugin: RemixVitePlugin = (remixUserConfig = {}) => {
473470
let rootDirectory =
474471
viteUserConfig.root ?? process.env.REMIX_ROOT ?? process.cwd();
475472

476-
let { manifest, unstable_ssr: ssr } = resolvedRemixUserConfig;
477-
478-
let isSpaMode = !ssr;
473+
let { manifest, unstable_ssr } = resolvedRemixUserConfig;
474+
let isSpaMode = !unstable_ssr;
479475

480476
// Only select the Remix esbuild config options that the Vite plugin uses
481477
let {
@@ -531,7 +527,7 @@ export const remixVitePlugin: RemixVitePlugin = (remixUserConfig = {}) => {
531527
serverBuildFile,
532528
serverBundles,
533529
serverModuleFormat,
534-
ssr,
530+
unstable_ssr,
535531
};
536532

537533
let serverContext: RemixPluginServerContext =
@@ -579,7 +575,7 @@ export const remixVitePlugin: RemixVitePlugin = (remixUserConfig = {}) => {
579575
)
580576
)};
581577
export const future = ${JSON.stringify(ctx.remixConfig.future)};
582-
export const isSpaMode = ${!ctx.remixConfig.ssr};
578+
export const isSpaMode = ${!ctx.remixConfig.unstable_ssr};
583579
export const publicPath = ${JSON.stringify(ctx.remixConfig.publicPath)};
584580
export const entry = { module: entryServer };
585581
export const routes = {
@@ -1093,7 +1089,7 @@ export const remixVitePlugin: RemixVitePlugin = (remixUserConfig = {}) => {
10931089
);
10941090
}
10951091

1096-
if (!ctx.remixConfig.ssr) {
1092+
if (!ctx.remixConfig.unstable_ssr) {
10971093
await handleSpaMode(
10981094
serverBuildDirectory,
10991095
ctx.remixConfig.serverBuildFile,
@@ -1234,7 +1230,7 @@ export const remixVitePlugin: RemixVitePlugin = (remixUserConfig = {}) => {
12341230
let route = getRoute(ctx.remixConfig, id);
12351231
if (!route) return;
12361232

1237-
if (!ctx.remixConfig.ssr) {
1233+
if (!ctx.remixConfig.unstable_ssr) {
12381234
let serverOnlyExports = esModuleLexer(code)[1]
12391235
.map((exp) => exp.n)
12401236
.filter((exp) => SERVER_ONLY_ROUTE_EXPORTS.includes(exp));

0 commit comments

Comments
 (0)