1import path from "node:path";
2import type * as vite from "vite";
3import { assert, describe, expect, it } from "vitest";
4import { optionsPlugin } from "../plugins/options.ts";
5
6describe("vite worker entry resolution", () => {
7 const callConfig = async (userConfig: vite.UserConfig) => {
8 const plugin = optionsPlugin.vite({ compatibilityDate: "2025-07-01" });
9 assert(
10 typeof plugin.config === "function",
11 "plugin.config is not a function",
12 );
13 return (await plugin.config.call({ meta: {} } as never, userConfig, {
14 command: "build",
15 mode: "production",
16 } as vite.ConfigEnv)) as vite.UserConfig;
17 };
18
19 it("resolves a relative ssr input against the vite root", async () => {
20 // The user entry is resolved with no importer, so without this a relative
21 // input resolves against `process.cwd()` — the wrong base when the build
22 // runs outside the project root (e.g. a monorepo infra package).
23 const config = await callConfig({
24 root: "/project",
25 environments: {
26 ssr: { build: { rollupOptions: { input: "./workers/app.ts" } } },
27 },
28 });
29 expect(config.environments?.ssr?.build?.rollupOptions?.input).toEqual({
30 app: `\0distilled:worker-entry:${path.resolve("/project", "./workers/app.ts").replaceAll("\\", "/")}`,
31 });
32 });
33
34 it("leaves virtual module inputs untouched", async () => {
35 const config = await callConfig({
36 root: "/project",
37 environments: {
38 ssr: {
39 build: {
40 rollupOptions: { input: "virtual:react-router/server-build" },
41 },
42 },
43 },
44 });
45 expect(config.environments?.ssr?.build?.rollupOptions?.input).toEqual({
46 "server-build":
47 "\0distilled:worker-entry:virtual:react-router/server-build",
48 });
49 });
50});