Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

fix(eve/sveltekit): migrate Vercel production routing to the stable services model (#2046)

Simon H271438670e8b
diff --git a/.changeset/sveltekit-stable-vercel-services.md b/.changeset/sveltekit-stable-vercel-services.md
new file mode 100644
index 000000000..531721867
--- /dev/null
+++ b/.changeset/sveltekit-stable-vercel-services.md
@@ -0,0 +1,5 @@
+---
+"eve": minor
+---
+
+`eve/sveltekit` now deploys the agent through Vercel's stable services model. On Vercel builds it generates an eve Build Output service and a `/eve/v1/*` service route instead of writing legacy `experimentalServices` to `vercel.json`. The `configureVercelJson` and `servicePrefix` plugin options and the `EVE_SVELTEKIT_SERVICE_PREFIX` export were removed; delete any generated `experimentalServices` block from `vercel.json`.
diff --git a/apps/frameworks/sveltekit/README.md b/apps/frameworks/sveltekit/README.md
index fd982e5cc..1b3cc7694 100644
--- a/apps/frameworks/sveltekit/README.md
+++ b/apps/frameworks/sveltekit/README.md
@@ -23,8 +23,6 @@ pnpm --filter framework-sveltekit dev
## Deploy
-`vercel.json` declares two services: the SvelteKit app at `/` and eve behind
-the private `/_eve_internal/eve` service prefix, with rewrites exposing the
-public `/eve/v1/*` endpoints. See
-[the SvelteKit frontend docs](../../../docs/guides/frontend/sveltekit.mdx) for
-details.
+On Vercel builds the plugin generates the eve service and its routing in the
+Build Output config, so no `vercel.json` is required. See
+[the SvelteKit frontend docs](../../../docs/guides/frontend/sveltekit.mdx) for details.
diff --git a/apps/frameworks/sveltekit/package.json b/apps/frameworks/sveltekit/package.json
index acf9cd0a4..e5007739f 100644
--- a/apps/frameworks/sveltekit/package.json
+++ b/apps/frameworks/sveltekit/package.json
@@ -4,6 +4,7 @@
"type": "module",
"scripts": {
"build": "pnpm --filter eve build && vite build",
+ "build:sveltekit": "vite build",
"dev": "vite dev",
"preview": "vite preview",
"typecheck": "svelte-kit sync && tsc --noEmit --project ./tsconfig.json"
diff --git a/apps/frameworks/sveltekit/vercel.json b/apps/frameworks/sveltekit/vercel.json
deleted file mode 100644
index e2c02c677..000000000
--- a/apps/frameworks/sveltekit/vercel.json
+++ /dev/null
@@ -1,22 +0,0 @@
-{
- "$schema": "https://openapi.vercel.sh/vercel.json",
- "experimentalServices": {
- "web": {
- "entrypoint": ".",
- "framework": "sveltekit",
- "routePrefix": "/"
- },
- "eve": {
- "buildCommand": "eve build",
- "entrypoint": ".",
- "framework": "eve",
- "routePrefix": "/_eve_internal/eve"
- }
- },
- "rewrites": [
- {
- "source": "/eve/v1/:path*",
- "destination": "/_eve_internal/eve/eve/v1/:path*"
- }
- ]
-}
diff --git a/docs/guides/frontend/sveltekit.mdx b/docs/guides/frontend/sveltekit.mdx
index 2bee15a91..14e32054e 100644
--- a/docs/guides/frontend/sveltekit.mdx
+++ b/docs/guides/frontend/sveltekit.mdx
@@ -74,7 +74,7 @@ The browser still needs a production authentication policy. See [Authenticate br
## Dev vs deploy topology
- **Local dev.** `npm run dev` boots the eve dev server next to SvelteKit and proxies the eve routes to it, so the browser only ever hits the SvelteKit origin. `npm run build && npm run preview` behaves the same way: the preview server gets its own eve route proxy and either reuses the shared eve server or starts one.
-- **Vercel.** The SvelteKit app and the eve runtime deploy as a single project. The web app is public; the eve runtime sits behind it on the same origin. Use `eveBuildCommand` for a project-specific agent build:
+- **Vercel.** The SvelteKit app and the eve runtime deploy as a single project. On Vercel builds the plugin adds Build Output [`services`](https://vercel.com/docs/services) for eve and a `routes` entry that sends `/eve/v1/**` to that service before filesystem routing; the SvelteKit app remains the default app. No `vercel.json` is required. By default the generated service runs the installed eve binary from the SvelteKit app's dependencies, so the agent directory does not need its own `package.json`. When the agent needs its own build step, set `eveBuildCommand`:
```ts
export default defineConfig({
@@ -95,6 +95,27 @@ The browser still needs a production authentication policy. See [Authenticate br
});
```
+## Managing vercel.json yourself
+
+When `vercel.json` declares [`services`](https://vercel.com/docs/services), the plugin generates nothing and your configuration owns routing. It must include the eve service (`framework: "eve"`) and a rewrite that exposes the eve transport, or the build fails:
+
+```json title="vercel.json"
+{
+ "services": {
+ "web": { "root": ".", "framework": "sveltekit" },
+ "eve": { "root": "agent", "framework": "eve", "buildCommand": "eve build" }
+ },
+ "rewrites": [{ "source": "/eve/v1/(.*)", "destination": { "service": "eve" } }]
+}
+```
+
+### Migrating from experimentalServices
+
+Earlier versions of the plugin wrote the legacy `experimentalServices` field into `vercel.json`. Vercel no longer routes that model, so the plugin now ignores the field and warns when it sees one. Migrate either way:
+
+- **Generated (default).** Delete `vercel.json` (or just its `experimentalServices` block) and set the project's Framework Preset back to SvelteKit. The plugin generates the eve service and its routing on every Vercel build.
+- **Hand-maintained.** Replace `experimentalServices` with the stable `services` and `rewrites` shown above, and keep the Services Framework Preset.
+
## What to read next
- [`useEveAgent` (Svelte)](./use-eve-agent-svelte): the binding API
diff --git a/packages/eve/src/internal/testing/scenario-apps/sveltekit-eve-service.ts b/packages/eve/src/internal/testing/scenario-apps/sveltekit-eve-service.ts
new file mode 100644
index 000000000..14cfafd2d
--- /dev/null
+++ b/packages/eve/src/internal/testing/scenario-apps/sveltekit-eve-service.ts
@@ -0,0 +1,56 @@
+import type { ScenarioAppDescriptor } from "#internal/testing/scenario-app.js";
+
+const SVELTEKIT_VERSION = "^2.63.0";
+const SVELTE_VERSION = "^5.0.0";
+const VITE_VERSION = "^8.1.5";
+
+export interface SvelteKitEveServiceDescriptorOptions {
+ readonly installDependencies?: boolean;
+}
+
+/**
+ * A SvelteKit host with a generated eve Vercel service.
+ */
+export function createSvelteKitEveServiceDescriptor(
+ options: SvelteKitEveServiceDescriptorOptions = {},
+): ScenarioAppDescriptor {
+ return {
+ dependencies: {
+ "@sveltejs/adapter-vercel": "^6.3.0",
+ "@sveltejs/kit": SVELTEKIT_VERSION,
+ svelte: SVELTE_VERSION,
+ vite: VITE_VERSION,
+ },
+ files: {
+ "agent/agent.mjs": `import { defineAgent } from "eve";
+
+export default defineAgent({ model: "openai/gpt-5.4" });
+`,
+ "agent/instructions.md": "You are a test agent.\n",
+ "src/app.html": `<!doctype html>
+<html lang="en">
+ <head>
+ <meta charset="utf-8" />
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
+ %sveltekit.head%
+ </head>
+ <body data-sveltekit-preload-data="hover">%sveltekit.body%</body>
+</html>
+`,
+ "src/routes/+page.svelte": "<main>eve SvelteKit deployment</main>\n",
+ "svelte.config.js": `import adapter from "@sveltejs/adapter-vercel";
+
+export default { kit: { adapter: adapter() } };
+`,
+ "vite.config.js": `import { sveltekit } from "@sveltejs/kit/vite";
+import { eveSvelteKit } from "eve/sveltekit";
+import { defineConfig } from "vite";
+
+export default defineConfig({ plugins: [eveSvelteKit({ eveRoot: "agent" }), sveltekit()] });
+`,
+ "pnpm-workspace.yaml": "minimumReleaseAge: 0\n",
+ },
+ installDependencies: options.installDependencies,
+ name: "sveltekit-eve-service",
+ };
+}
diff --git a/packages/eve/src/public/nuxt/module.ts b/packages/eve/src/public/nuxt/module.ts
index 36806e383..9f92cf3eb 100644
--- a/packages/eve/src/public/nuxt/module.ts
+++ b/packages/eve/src/public/nuxt/module.ts
@@ -4,14 +4,14 @@ import { isAbsolute, resolve } from "node:path";
import { addImports, defineNuxtModule, extendRouteRules } from "@nuxt/kit";
import { EVE_ROUTE_PREFIX } from "#protocol/routes.js";
-
-import { EVE_BASE_URL_ENV, resolveSharedEveDevServer } from "./dev-server.js";
-import { joinRoutePrefix, normalizeOrigin, resolveProductionTarget } from "./routing.js";
import {
ensureEveVercelServicesConfig,
mergeEveVercelConfig,
- type NitroVercelBuildConfig,
-} from "./vercel-services.js";
+ type VercelBuildConfig,
+} from "#shared/vercel-services.js";
+
+import { EVE_BASE_URL_ENV, resolveSharedEveDevServer } from "./dev-server.js";
+import { joinRoutePrefix, normalizeOrigin, resolveProductionTarget } from "./routing.js";
/**
* Options for the eve Nuxt module.
@@ -47,7 +47,7 @@ function resolveApplicationRoot(nuxtRoot: string, appPath: string | undefined):
*/
interface NitroVercelConfigHost {
vercel?: {
- config?: NitroVercelBuildConfig;
+ config?: VercelBuildConfig;
[key: string]: unknown;
};
}
@@ -117,7 +117,8 @@ export default defineNuxtModule<EveNuxtModuleOptions>({
const configured = await ensureEveVercelServicesConfig({
appRoot,
eveBuildCommand: options.eveBuildCommand,
- nuxtRoot,
+ frameworkName: "Nuxt",
+ hostRoot: nuxtRoot,
});
if (configured.mode === "generated") {
diff --git a/packages/eve/src/public/sveltekit/index.test.ts b/packages/eve/src/public/sveltekit/index.test.ts
index 7c7f42fab..0b5117a57 100644
--- a/packages/eve/src/public/sveltekit/index.test.ts
+++ b/packages/eve/src/public/sveltekit/index.test.ts
@@ -2,22 +2,23 @@ import { afterEach, describe, expect, it, vi } from "vitest";
import type { ConfigEnv, Plugin, UserConfig } from "vite";
import { EVE_ROUTE_PREFIX } from "#protocol/routes.js";
+import { ensureEveVercelServicesConfig } from "#shared/vercel-services.js";
import { eveSvelteKit } from "./index.js";
import { resolveSharedEveDevServer } from "./dev-server.js";
-import { ensureEveVercelJson } from "./vercel-json.js";
vi.mock("./dev-server.js", () => ({
EVE_BASE_URL_ENV: "EVE_BASE_URL",
resolveSharedEveDevServer: vi.fn(async () => ({ origin: "http://127.0.0.1:49152" })),
}));
-vi.mock("./vercel-json.js", () => ({
- ensureEveVercelJson: vi.fn(async () => ({ servicePrefix: "/_eve_internal/eve" })),
+vi.mock("#shared/vercel-services.js", () => ({
+ ensureEveVercelServicesConfig: vi.fn(async () => ({ mode: "root" })),
+ mergeEveVercelConfig: vi.fn(),
}));
const resolveSharedEveDevServerMock = vi.mocked(resolveSharedEveDevServer);
-const ensureEveVercelJsonMock = vi.mocked(ensureEveVercelJson);
+const ensureEveVercelServicesConfigMock = vi.mocked(ensureEveVercelServicesConfig);
type ConfigHook = (config: UserConfig, env: ConfigEnv) => unknown;
@@ -105,16 +106,17 @@ describe("eveSvelteKit", () => {
});
});
- it("configures vercel.json during production builds", async () => {
+ it("configures a generated Vercel service during Vercel production builds", async () => {
+ vi.stubEnv("VERCEL", "1");
const plugin = eveSvelteKit({ eveBuildCommand: "pnpm build:eve", eveRoot: "agent" });
await getConfigHook(plugin)({}, { command: "build", mode: "production" });
- expect(ensureEveVercelJsonMock).toHaveBeenCalledWith({
+ expect(ensureEveVercelServicesConfigMock).toHaveBeenCalledWith({
appRoot: expect.stringMatching(/agent$/),
eveBuildCommand: "pnpm build:eve",
- servicePrefix: "/_eve_internal/eve",
- svelteKitRoot: process.cwd(),
+ frameworkName: "SvelteKit",
+ hostRoot: process.cwd(),
});
});
});
diff --git a/packages/eve/src/public/sveltekit/index.ts b/packages/eve/src/public/sveltekit/index.ts
index 4ed2464c5..aa4d25391 100644
--- a/packages/eve/src/public/sveltekit/index.ts
+++ b/packages/eve/src/public/sveltekit/index.ts
@@ -1,16 +1,18 @@
-import { isAbsolute, resolve } from "node:path";
+import { readFile, writeFile } from "node:fs/promises";
+import { isAbsolute, join, resolve } from "node:path";
-import type { Plugin, UserConfig } from "vite";
+import type { Plugin, ResolvedConfig, UserConfig } from "vite";
import { EVE_ROUTE_PREFIX } from "#protocol/routes.js";
+import {
+ ensureEveVercelServicesConfig,
+ mergeEveVercelConfig,
+ type EnsureEveVercelServicesConfigResult,
+ type VercelBuildConfig,
+} from "#shared/vercel-services.js";
import { EVE_BASE_URL_ENV, resolveSharedEveDevServer } from "./dev-server.js";
-import { EVE_SVELTEKIT_SERVICE_PREFIX, normalizeOrigin, normalizeRoutePrefix } from "./routing.js";
-import { ensureEveVercelJson } from "./vercel-json.js";
-
-export { EVE_SVELTEKIT_SERVICE_PREFIX };
-
-const DEFAULT_EVE_BUILD_COMMAND = "eve build";
+import { normalizeOrigin } from "./routing.js";
/**
* Options for the eve SvelteKit Vite plugin.
@@ -22,23 +24,11 @@ export interface EveSvelteKitPluginOptions {
*/
readonly eveRoot?: string;
/**
- * Build command for the generated eve Vercel service.
- * Defaults to `"eve build"`.
+ * Command that builds the eve app inside the generated Vercel eve service.
+ * Defaults to running the installed eve binary from the SvelteKit app's
+ * dependencies (`node <path-to>/eve/bin/eve.js build`).
*/
readonly eveBuildCommand?: string;
- /**
- * Set to `false` to skip creating or updating `vercel.json`.
- *
- * By default the plugin ensures `vercel.json` contains `experimentalServices`
- * for the SvelteKit app and eve app.
- */
- readonly configureVercelJson?: boolean;
- /**
- * Private Vercel service prefix for the eve deployment. Must match the
- * eve service's `routePrefix` in `vercel.json`. Defaults to
- * {@link EVE_SVELTEKIT_SERVICE_PREFIX} (`"/_eve_internal/eve"`).
- */
- readonly servicePrefix?: string;
}
function resolveApplicationRoot(svelteKitRoot: string, appPath: string | undefined): string {
@@ -70,6 +60,36 @@ async function resolveEveDevProxyTarget(appRoot: string): Promise<string> {
return (await resolveSharedEveDevServer(appRoot)).origin;
}
+function isRecord(value: unknown): value is Record<string, unknown> {
+ return value !== null && typeof value === "object" && !Array.isArray(value);
+}
+
+async function mergeGeneratedVercelServicesConfig(input: {
+ readonly generated: Extract<EnsureEveVercelServicesConfigResult, { mode: "generated" }>;
+ readonly outputConfigPath: string;
+}): Promise<void> {
+ let outputConfigContents: string;
+
+ try {
+ outputConfigContents = await readFile(input.outputConfigPath, "utf8");
+ } catch (error) {
+ if (error instanceof Error && "code" in error && error.code === "ENOENT") {
+ return;
+ }
+
+ throw error;
+ }
+
+ const outputConfig: unknown = JSON.parse(outputConfigContents);
+
+ if (!isRecord(outputConfig)) {
+ throw new Error("Vercel Build Output config.json must contain a JSON object.");
+ }
+
+ const merged = mergeEveVercelConfig(outputConfig as VercelBuildConfig, input.generated);
+ await writeFile(input.outputConfigPath, `${JSON.stringify(merged, null, 2)}\n`);
+}
+
/**
* Vite plugin for running an eve agent alongside a SvelteKit app.
*
@@ -78,30 +98,35 @@ async function resolveEveDevProxyTarget(appRoot: string): Promise<string> {
* `EVE_BASE_URL` env var if set, then a healthy shared eve dev server already
* running for the app, then a freshly spawned `eve dev --no-ui --port 0`.
*
- * During builds, unless `configureVercelJson` is `false`, it ensures
- * `vercel.json` deploys the SvelteKit app and eve agent as sibling Vercel
- * services.
+ * On Vercel builds, `eveSvelteKit` adds the eve runtime as a sibling Vercel
+ * service and routes its transport requests before SvelteKit filesystem
+ * routing.
*/
export function eveSvelteKit(options: EveSvelteKitPluginOptions = {}): Plugin {
let svelteKitRoot = process.cwd();
let appRoot = resolveApplicationRoot(svelteKitRoot, options.eveRoot);
- const servicePrefix = normalizeRoutePrefix(options.servicePrefix ?? EVE_SVELTEKIT_SERVICE_PREFIX);
- const shouldConfigureVercelJson = options.configureVercelJson !== false;
+ let isSsrBuild = false;
+ let generatedVercelServices:
+ | Extract<EnsureEveVercelServicesConfigResult, { mode: "generated" }>
+ | undefined;
return {
+ enforce: "post",
name: "eve:sveltekit",
async config(config, env) {
svelteKitRoot =
config.root === undefined ? process.cwd() : resolve(process.cwd(), config.root);
appRoot = resolveApplicationRoot(svelteKitRoot, options.eveRoot);
- if (shouldConfigureVercelJson && env.command === "build") {
- await ensureEveVercelJson({
+ if (env.command === "build" && process.env.VERCEL) {
+ const configured = await ensureEveVercelServicesConfig({
appRoot,
- eveBuildCommand: options.eveBuildCommand ?? DEFAULT_EVE_BUILD_COMMAND,
- servicePrefix,
- svelteKitRoot,
+ eveBuildCommand: options.eveBuildCommand,
+ frameworkName: "SvelteKit",
+ hostRoot: svelteKitRoot,
});
+
+ generatedVercelServices = configured.mode === "generated" ? configured : undefined;
}
if (env.command !== "serve") {
@@ -124,5 +149,22 @@ export function eveSvelteKit(options: EveSvelteKitPluginOptions = {}): Plugin {
},
};
},
+ configResolved(config: ResolvedConfig) {
+ isSsrBuild = Boolean(config.build.ssr);
+ svelteKitRoot = config.root;
+ },
+ closeBundle: {
+ sequential: true,
+ async handler() {
+ if (!isSsrBuild || generatedVercelServices === undefined) {
+ return;
+ }
+
+ await mergeGeneratedVercelServicesConfig({
+ generated: generatedVercelServices,
+ outputConfigPath: join(svelteKitRoot, ".vercel", "output", "config.json"),
+ });
+ },
+ },
};
}
diff --git a/packages/eve/src/public/sveltekit/routing.test.ts b/packages/eve/src/public/sveltekit/routing.test.ts
index 3380062c5..82b8d1e5a 100644
--- a/packages/eve/src/public/sveltekit/routing.test.ts
+++ b/packages/eve/src/public/sveltekit/routing.test.ts
@@ -1,49 +1,6 @@
import { describe, expect, it } from "vitest";
-import {
- EVE_SVELTEKIT_SERVICE_PREFIX,
- createEveVercelRewrite,
- joinRoutePrefix,
- normalizeOrigin,
- normalizeRoutePrefix,
-} from "./routing.js";
-
-const EVE_PROTOCOL_PREFIX = "/eve/v1";
-
-describe("normalizeRoutePrefix", () => {
- it("prepends a leading slash when missing", () => {
- expect(normalizeRoutePrefix("internal/eve")).toBe("/internal/eve");
- });
-
- it("strips trailing slashes", () => {
- expect(normalizeRoutePrefix("/internal/eve///")).toBe("/internal/eve");
- });
-
- it("keeps an already-normalized prefix unchanged", () => {
- expect(normalizeRoutePrefix(EVE_SVELTEKIT_SERVICE_PREFIX)).toBe(EVE_SVELTEKIT_SERVICE_PREFIX);
- });
-
- it("throws when the prefix resolves to the root route", () => {
- expect(() => normalizeRoutePrefix("/")).toThrow(/cannot resolve to the root route/);
- expect(() => normalizeRoutePrefix("")).toThrow(/cannot resolve to the root route/);
- });
-});
-
-describe("joinRoutePrefix", () => {
- it("joins with exactly one slash", () => {
- expect(joinRoutePrefix("/_eve_internal/eve", "/eve/v1")).toBe("/_eve_internal/eve/eve/v1");
- });
-
- it("collapses duplicate slashes at the boundary", () => {
- expect(joinRoutePrefix("/prefix/", "//path")).toBe("/prefix/path");
- });
-
- it("joins onto an absolute origin", () => {
- expect(joinRoutePrefix("http://127.0.0.1:4274", "/eve/v1")).toBe(
- "http://127.0.0.1:4274/eve/v1",
- );
- });
-});
+import { normalizeOrigin } from "./routing.js";
describe("normalizeOrigin", () => {
it("reduces a URL with a path to its origin", () => {
@@ -60,19 +17,3 @@ describe("normalizeOrigin", () => {
expect(() => normalizeOrigin("not a url")).toThrow();
});
});
-
-describe("createEveVercelRewrite", () => {
- it("rewrites the eve transport prefix onto the service prefix", () => {
- expect(createEveVercelRewrite(EVE_SVELTEKIT_SERVICE_PREFIX)).toEqual({
- source: `${EVE_PROTOCOL_PREFIX}/:path*`,
- destination: `${EVE_SVELTEKIT_SERVICE_PREFIX}${EVE_PROTOCOL_PREFIX}/:path*`,
- });
- });
-
- it("honors a custom service prefix", () => {
- expect(createEveVercelRewrite("/agent")).toEqual({
- source: `${EVE_PROTOCOL_PREFIX}/:path*`,
- destination: `/agent${EVE_PROTOCOL_PREFIX}/:path*`,
- });
- });
-});
diff --git a/packages/eve/src/public/sveltekit/routing.ts b/packages/eve/src/public/sveltekit/routing.ts
index 68174b465..d4a16574d 100644
--- a/packages/eve/src/public/sveltekit/routing.ts
+++ b/packages/eve/src/public/sveltekit/routing.ts
@@ -1,25 +1,3 @@
-import { EVE_ROUTE_PREFIX } from "#protocol/routes.js";
-
-/**
- * Private route namespace for hosting eve as a separate experimental Vercel
- * service behind the SvelteKit app.
- */
-export const EVE_SVELTEKIT_SERVICE_PREFIX = "/_eve_internal/eve";
-
-/**
- * Normalize a user-supplied service prefix into a leading-slash, no-trailing-
- * slash route. Throws when the prefix resolves to the root route, which would
- * collide with the SvelteKit web service.
- */
-export function normalizeRoutePrefix(prefix: string): string {
- const prefixed = prefix.startsWith("/") ? prefix : `/${prefix}`;
- const normalized = prefixed.replace(/\/+$/, "");
- if (normalized.length === 0) {
- throw new Error("eve SvelteKit service prefix cannot resolve to the root route.");
- }
- return normalized;
-}
-
/**
* Join a route prefix and a path with exactly one separating slash.
*/
@@ -33,23 +11,3 @@ export function joinRoutePrefix(prefix: string, path: string): string {
export function normalizeOrigin(origin: string): string {
return new URL(origin.trim()).origin;
}
-
-/**
- * A Vercel rewrite that forwards eve transport requests (`/eve/v1/**`) to the
- * private eve service prefix (`/_eve_internal/eve/eve/v1/**`).
- */
-export interface EveVercelRewrite {
- readonly destination: string;
- readonly source: string;
-}
-
-/**
- * Build the Vercel rewrite that forwards browser eve transport requests to the
- * sibling eve service.
- */
-export function createEveVercelRewrite(servicePrefix: string): EveVercelRewrite {
- return {
- destination: `${joinRoutePrefix(servicePrefix, EVE_ROUTE_PREFIX)}/:path*`,
- source: `${EVE_ROUTE_PREFIX}/:path*`,
- };
-}
diff --git a/packages/eve/src/public/sveltekit/vercel-json.integration.test.ts b/packages/eve/src/public/sveltekit/vercel-json.integration.test.ts
deleted file mode 100644
index bd6643683..000000000
--- a/packages/eve/src/public/sveltekit/vercel-json.integration.test.ts
+++ /dev/null
@@ -1,170 +0,0 @@
-import { mkdtemp, readFile, writeFile } from "node:fs/promises";
-import { tmpdir } from "node:os";
-import { join } from "node:path";
-
-import { describe, expect, it } from "vitest";
-
-import { EVE_SVELTEKIT_SERVICE_PREFIX } from "./routing.js";
-import { ensureEveVercelJson } from "./vercel-json.js";
-
-async function createTempRoot(): Promise<string> {
- return await mkdtemp(join(tmpdir(), "eve-sveltekit-vercel-"));
-}
-
-async function readJsonFile(path: string): Promise<unknown> {
- return JSON.parse(await readFile(path, "utf8")) as unknown;
-}
-
-describe("ensureEveVercelJson", () => {
- it("creates experimentalServices and rewrites when vercel.json is missing", async () => {
- const svelteKitRoot = await createTempRoot();
-
- const result = await ensureEveVercelJson({
- appRoot: svelteKitRoot,
- eveBuildCommand: "eve build",
- servicePrefix: EVE_SVELTEKIT_SERVICE_PREFIX,
- svelteKitRoot,
- });
-
- expect(result.servicePrefix).toBe(EVE_SVELTEKIT_SERVICE_PREFIX);
- expect(await readJsonFile(join(svelteKitRoot, "vercel.json"))).toEqual({
- $schema: "https://openapi.vercel.sh/vercel.json",
- experimentalServices: {
- eve: {
- buildCommand: "eve build",
- entrypoint: ".",
- framework: "eve",
- routePrefix: EVE_SVELTEKIT_SERVICE_PREFIX,
- },
- web: {
- entrypoint: ".",
- framework: "sveltekit",
- routePrefix: "/",
- },
- },
- rewrites: [
- {
- source: "/eve/v1/:path*",
- destination: `${EVE_SVELTEKIT_SERVICE_PREFIX}/eve/v1/:path*`,
- },
- ],
- });
- });
-
- it("resolves the eve entrypoint relative to the SvelteKit root", async () => {
- const svelteKitRoot = await createTempRoot();
- const appRoot = join(svelteKitRoot, "agent");
-
- await ensureEveVercelJson({
- appRoot,
- eveBuildCommand: "eve build",
- servicePrefix: EVE_SVELTEKIT_SERVICE_PREFIX,
- svelteKitRoot,
- });
-
- expect(await readJsonFile(join(svelteKitRoot, "vercel.json"))).toMatchObject({
- experimentalServices: {
- eve: { entrypoint: "agent" },
- },
- });
- });
-
- it("uses a custom build command", async () => {
- const svelteKitRoot = await createTempRoot();
-
- await ensureEveVercelJson({
- appRoot: svelteKitRoot,
- eveBuildCommand: "pnpm build:eve",
- servicePrefix: EVE_SVELTEKIT_SERVICE_PREFIX,
- svelteKitRoot,
- });
-
- expect(await readJsonFile(join(svelteKitRoot, "vercel.json"))).toMatchObject({
- experimentalServices: {
- eve: { buildCommand: "pnpm build:eve" },
- },
- });
- });
-
- it("preserves an already-configured eve service and reuses its prefix", async () => {
- const svelteKitRoot = await createTempRoot();
- const existing = {
- $schema: "https://openapi.vercel.sh/vercel.json",
- experimentalServices: {
- agent: {
- entrypoint: "agent",
- framework: "eve",
- routePrefix: "/private/agent",
- },
- frontend: {
- entrypoint: ".",
- framework: "sveltekit",
- routePrefix: "/",
- },
- },
- rewrites: [
- {
- source: "/eve/v1/:path*",
- destination: "/private/agent/eve/v1/:path*",
- },
- ],
- };
- await writeFile(join(svelteKitRoot, "vercel.json"), `${JSON.stringify(existing, null, 2)}\n`);
-
- const result = await ensureEveVercelJson({
- appRoot: svelteKitRoot,
- eveBuildCommand: "eve build",
- servicePrefix: EVE_SVELTEKIT_SERVICE_PREFIX,
- svelteKitRoot,
- });
-
- expect(result.servicePrefix).toBe("/private/agent");
- expect(await readJsonFile(join(svelteKitRoot, "vercel.json"))).toEqual(existing);
- });
-
- it("preserves unrelated top-level keys", async () => {
- const svelteKitRoot = await createTempRoot();
- await writeFile(
- join(svelteKitRoot, "vercel.json"),
- `${JSON.stringify({ regions: ["iad1"] }, null, 2)}\n`,
- );
-
- await ensureEveVercelJson({
- appRoot: svelteKitRoot,
- eveBuildCommand: "eve build",
- servicePrefix: EVE_SVELTEKIT_SERVICE_PREFIX,
- svelteKitRoot,
- });
-
- expect(await readJsonFile(join(svelteKitRoot, "vercel.json"))).toMatchObject({
- regions: ["iad1"],
- experimentalServices: {
- eve: { framework: "eve" },
- web: { framework: "sveltekit" },
- },
- rewrites: [
- {
- source: "/eve/v1/:path*",
- destination: `${EVE_SVELTEKIT_SERVICE_PREFIX}/eve/v1/:path*`,
- },
- ],
- });
- });
-
- it("rejects a malformed vercel.json", async () => {
- const svelteKitRoot = await createTempRoot();
- await writeFile(
- join(svelteKitRoot, "vercel.json"),
- `${JSON.stringify(["not", "an", "object"])}\n`,
- );
-
- await expect(
- ensureEveVercelJson({
- appRoot: svelteKitRoot,
- eveBuildCommand: "eve build",
- servicePrefix: EVE_SVELTEKIT_SERVICE_PREFIX,
- svelteKitRoot,
- }),
- ).rejects.toThrow(/must contain a JSON object/);
- });
-});
diff --git a/packages/eve/src/public/sveltekit/vercel-json.ts b/packages/eve/src/public/sveltekit/vercel-json.ts
deleted file mode 100644
index e56527178..000000000
--- a/packages/eve/src/public/sveltekit/vercel-json.ts
+++ /dev/null
@@ -1,135 +0,0 @@
-import { readFile, writeFile } from "node:fs/promises";
-import { join, relative } from "node:path";
-
-import { createEveVercelRewrite, type EveVercelRewrite } from "./routing.js";
-
-const VERCEL_JSON_FILE_NAME = "vercel.json";
-const VERCEL_JSON_SCHEMA = "https://openapi.vercel.sh/vercel.json";
-
-interface VercelServiceConfig {
- readonly buildCommand?: string;
- readonly entrypoint: string;
- readonly framework: string;
- readonly routePrefix: string;
-}
-
-interface VercelJsonConfig {
- readonly $schema?: string;
- readonly experimentalServices?: Record<string, VercelServiceConfig>;
- readonly rewrites?: readonly EveVercelRewrite[];
- readonly [key: string]: unknown;
-}
-
-export interface EnsureVercelJsonResult {
- readonly servicePrefix: string;
-}
-
-function isRecord(value: unknown): value is Record<string, unknown> {
- return value !== null && typeof value === "object" && !Array.isArray(value);
-}
-
-function resolveRelativeEntrypoint(fromRoot: string, toRoot: string): string {
- const relativePath = relative(fromRoot, toRoot);
- return relativePath.length === 0 ? "." : relativePath.replaceAll("\\", "/");
-}
-
-function normalizeVercelJsonConfig(value: unknown): VercelJsonConfig {
- if (!isRecord(value)) {
- throw new Error(`${VERCEL_JSON_FILE_NAME} must contain a JSON object.`);
- }
-
- const experimentalServices = value.experimentalServices;
- if (experimentalServices !== undefined && !isRecord(experimentalServices)) {
- throw new Error(`${VERCEL_JSON_FILE_NAME} experimentalServices must be a JSON object.`);
- }
-
- const rewrites = value.rewrites;
- if (rewrites !== undefined && !Array.isArray(rewrites)) {
- throw new Error(`${VERCEL_JSON_FILE_NAME} rewrites must be an array.`);
- }
-
- return value as VercelJsonConfig;
-}
-
-async function readVercelJsonConfig(path: string): Promise<VercelJsonConfig> {
- try {
- return normalizeVercelJsonConfig(JSON.parse(await readFile(path, "utf8")) as unknown);
- } catch (error) {
- if (error instanceof Error && "code" in error && error.code === "ENOENT") {
- return {};
- }
-
- throw error;
- }
-}
-
-function findServiceByFramework(
- services: Record<string, VercelServiceConfig>,
- framework: string,
-): VercelServiceConfig | undefined {
- return Object.values(services).find((service) => service.framework === framework);
-}
-
-function hasRewrite(rewrites: readonly EveVercelRewrite[], rewrite: EveVercelRewrite): boolean {
- return rewrites.some(
- (existing) =>
- existing.source === rewrite.source && existing.destination === rewrite.destination,
- );
-}
-
-/**
- * Ensure `vercel.json` declares the SvelteKit web service and the eve agent
- * service so a Vercel deployment ships both from one project.
- *
- * Existing services are preserved untouched; an already-configured eve
- * service's `routePrefix` wins over {@link input.servicePrefix}. The file is
- * only rewritten when the resulting config differs from what is on disk.
- */
-export async function ensureEveVercelJson(input: {
- readonly appRoot: string;
- readonly eveBuildCommand: string;
- readonly servicePrefix: string;
- readonly svelteKitRoot: string;
-}): Promise<EnsureVercelJsonResult> {
- const vercelJsonPath = join(input.svelteKitRoot, VERCEL_JSON_FILE_NAME);
- const existingConfig = await readVercelJsonConfig(vercelJsonPath);
- const svelteKitEntrypoint = ".";
- const eveEntrypoint = resolveRelativeEntrypoint(input.svelteKitRoot, input.appRoot);
- const existingServices = existingConfig.experimentalServices ?? {};
- const configuredEveService = findServiceByFramework(existingServices, "eve");
- const configuredSvelteKitService = findServiceByFramework(existingServices, "sveltekit");
- const servicePrefix = configuredEveService?.routePrefix ?? input.servicePrefix;
- const experimentalServices: Record<string, VercelServiceConfig> = { ...existingServices };
-
- if (configuredSvelteKitService === undefined) {
- experimentalServices.web = {
- entrypoint: svelteKitEntrypoint,
- framework: "sveltekit",
- routePrefix: "/",
- };
- }
-
- if (configuredEveService === undefined) {
- experimentalServices.eve = {
- buildCommand: input.eveBuildCommand,
- entrypoint: eveEntrypoint,
- framework: "eve",
- routePrefix: servicePrefix,
- };
- }
-
- const rewrite = createEveVercelRewrite(servicePrefix);
- const rewrites = existingConfig.rewrites ?? [];
- const vercelConfig: VercelJsonConfig = {
- ...existingConfig,
- $schema: existingConfig.$schema ?? VERCEL_JSON_SCHEMA,
- experimentalServices,
- rewrites: hasRewrite(rewrites, rewrite) ? rewrites : [rewrite, ...rewrites],
- };
-
- if (JSON.stringify(existingConfig) !== JSON.stringify(vercelConfig)) {
- await writeFile(vercelJsonPath, `${JSON.stringify(vercelConfig, null, 2)}\n`);
- }
-
- return { servicePrefix };
-}
diff --git a/packages/eve/src/public/nuxt/vercel-services.integration.test.ts b/packages/eve/src/shared/vercel-services.integration.test.ts
similarity index 65%
rename from packages/eve/src/public/nuxt/vercel-services.integration.test.ts
rename to packages/eve/src/shared/vercel-services.integration.test.ts
index 1d6701330..08d2e55fa 100644
--- a/packages/eve/src/public/nuxt/vercel-services.integration.test.ts
+++ b/packages/eve/src/shared/vercel-services.integration.test.ts
@@ -15,10 +15,10 @@ vi.mock("#shared/resolve-eve-binary.js", async () => {
};
});
-import { ensureEveVercelServicesConfig } from "./vercel-services.js";
+import { ensureEveVercelServicesConfig } from "#shared/vercel-services.js";
-async function createTempNuxtRoot(): Promise<string> {
- return await mkdtemp(join(tmpdir(), "eve-nuxt-services-"));
+async function createTempHostRoot(): Promise<string> {
+ return await mkdtemp(join(tmpdir(), "eve-vercel-services-"));
}
async function directoryExists(path: string): Promise<boolean> {
@@ -35,11 +35,12 @@ afterEach(() => {
describe("ensureEveVercelServicesConfig", () => {
it("generates the eve service when vercel.json is missing", async () => {
- const nuxtRoot = await createTempNuxtRoot();
+ const hostRoot = await createTempHostRoot();
const result = await ensureEveVercelServicesConfig({
- appRoot: nuxtRoot,
- nuxtRoot,
+ appRoot: hostRoot,
+ frameworkName: "Test",
+ hostRoot: hostRoot,
});
expect(result).toEqual({
@@ -68,20 +69,25 @@ describe("ensureEveVercelServicesConfig", () => {
});
it("creates the isolated service build root", async () => {
- const nuxtRoot = await createTempNuxtRoot();
+ const hostRoot = await createTempHostRoot();
- await ensureEveVercelServicesConfig({ appRoot: nuxtRoot, nuxtRoot });
+ await ensureEveVercelServicesConfig({
+ appRoot: hostRoot,
+ frameworkName: "Test",
+ hostRoot: hostRoot,
+ });
- expect(await directoryExists(join(nuxtRoot, ".eve", "vercel-services", "eve"))).toBe(true);
+ expect(await directoryExists(join(hostRoot, ".eve", "vercel-services", "eve"))).toBe(true);
});
it("uses a custom eve build command verbatim", async () => {
- const nuxtRoot = await createTempNuxtRoot();
+ const hostRoot = await createTempHostRoot();
const result = await ensureEveVercelServicesConfig({
- appRoot: nuxtRoot,
+ appRoot: hostRoot,
eveBuildCommand: "pnpm build:eve",
- nuxtRoot,
+ frameworkName: "Test",
+ hostRoot: hostRoot,
});
expect(result.mode).toBe("generated");
@@ -91,11 +97,15 @@ describe("ensureEveVercelServicesConfig", () => {
});
it("resolves relative paths for an eve app in a subdirectory", async () => {
- const nuxtRoot = await createTempNuxtRoot();
- const appRoot = join(nuxtRoot, "agent");
+ const hostRoot = await createTempHostRoot();
+ const appRoot = join(hostRoot, "agent");
await mkdir(appRoot, { recursive: true });
- const result = await ensureEveVercelServicesConfig({ appRoot, nuxtRoot });
+ const result = await ensureEveVercelServicesConfig({
+ appRoot,
+ frameworkName: "Test",
+ hostRoot: hostRoot,
+ });
expect(result.mode === "generated" && result.services.eve?.buildCommand).toBe(
"cd '../../../agent' && export EVE_INTERNAL_BUILD_OUTPUT_DIRECTORY='../.eve/vercel-services/eve/.vercel/output' && export EVE_INTERNAL_HOST_BUILD_OUTPUT_DIRECTORY='../.vercel/output' && node '../node_modules/eve/bin/eve.js' build",
@@ -103,11 +113,11 @@ describe("ensureEveVercelServicesConfig", () => {
});
it("reads vercel.json from a linked Vercel project root", async () => {
- const projectRoot = await createTempNuxtRoot();
- const nuxtRoot = join(projectRoot, "apps", "web");
+ const projectRoot = await createTempHostRoot();
+ const hostRoot = join(projectRoot, "apps", "web");
await mkdir(join(projectRoot, ".vercel"), { recursive: true });
await writeFile(join(projectRoot, ".vercel", "project.json"), "{}\n");
- await mkdir(nuxtRoot, { recursive: true });
+ await mkdir(hostRoot, { recursive: true });
await writeFile(
join(projectRoot, "vercel.json"),
`${JSON.stringify({
@@ -118,15 +128,19 @@ describe("ensureEveVercelServicesConfig", () => {
})}\n`,
);
- const result = await ensureEveVercelServicesConfig({ appRoot: nuxtRoot, nuxtRoot });
+ const result = await ensureEveVercelServicesConfig({
+ appRoot: hostRoot,
+ frameworkName: "Test",
+ hostRoot: hostRoot,
+ });
expect(result).toEqual({ mode: "root" });
});
it("generates nothing when vercel.json declares services including eve", async () => {
- const nuxtRoot = await createTempNuxtRoot();
+ const hostRoot = await createTempHostRoot();
await writeFile(
- join(nuxtRoot, "vercel.json"),
+ join(hostRoot, "vercel.json"),
`${JSON.stringify({
services: {
web: { root: ".", framework: "nuxtjs" },
@@ -135,16 +149,20 @@ describe("ensureEveVercelServicesConfig", () => {
})}\n`,
);
- const result = await ensureEveVercelServicesConfig({ appRoot: nuxtRoot, nuxtRoot });
+ const result = await ensureEveVercelServicesConfig({
+ appRoot: hostRoot,
+ frameworkName: "Test",
+ hostRoot: hostRoot,
+ });
expect(result).toEqual({ mode: "root" });
- expect(await directoryExists(join(nuxtRoot, ".eve", "vercel-services"))).toBe(false);
+ expect(await directoryExists(join(hostRoot, ".eve", "vercel-services"))).toBe(false);
});
it("accepts the named service array form", async () => {
- const nuxtRoot = await createTempNuxtRoot();
+ const hostRoot = await createTempHostRoot();
await writeFile(
- join(nuxtRoot, "vercel.json"),
+ join(hostRoot, "vercel.json"),
`${JSON.stringify({
services: [
{ name: "web", root: ".", framework: "nuxtjs" },
@@ -153,28 +171,36 @@ describe("ensureEveVercelServicesConfig", () => {
})}\n`,
);
- await expect(ensureEveVercelServicesConfig({ appRoot: nuxtRoot, nuxtRoot })).resolves.toEqual({
- mode: "root",
- });
+ await expect(
+ ensureEveVercelServicesConfig({
+ appRoot: hostRoot,
+ frameworkName: "Test",
+ hostRoot: hostRoot,
+ }),
+ ).resolves.toEqual({ mode: "root" });
});
it("throws when vercel.json services omit the eve service", async () => {
- const nuxtRoot = await createTempNuxtRoot();
+ const hostRoot = await createTempHostRoot();
await writeFile(
- join(nuxtRoot, "vercel.json"),
+ join(hostRoot, "vercel.json"),
`${JSON.stringify({ services: { web: { root: ".", framework: "nuxtjs" } } })}\n`,
);
- await expect(ensureEveVercelServicesConfig({ appRoot: nuxtRoot, nuxtRoot })).rejects.toThrow(
- /already defines services/,
- );
+ await expect(
+ ensureEveVercelServicesConfig({
+ appRoot: hostRoot,
+ frameworkName: "Test",
+ hostRoot: hostRoot,
+ }),
+ ).rejects.toThrow(/already defines services/);
});
it("warns and generates when vercel.json only has legacy experimentalServices", async () => {
- const nuxtRoot = await createTempNuxtRoot();
+ const hostRoot = await createTempHostRoot();
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
await writeFile(
- join(nuxtRoot, "vercel.json"),
+ join(hostRoot, "vercel.json"),
`${JSON.stringify({
experimentalServices: {
web: { entrypoint: ".", framework: "nuxtjs", routePrefix: "/" },
@@ -183,35 +209,47 @@ describe("ensureEveVercelServicesConfig", () => {
})}\n`,
);
- const result = await ensureEveVercelServicesConfig({ appRoot: nuxtRoot, nuxtRoot });
+ const result = await ensureEveVercelServicesConfig({
+ appRoot: hostRoot,
+ frameworkName: "Test",
+ hostRoot: hostRoot,
+ });
expect(result.mode).toBe("generated");
expect(warn).toHaveBeenCalledWith(expect.stringContaining("experimentalServices"));
});
it("prefers stable services over legacy experimentalServices without warning", async () => {
- const nuxtRoot = await createTempNuxtRoot();
+ const hostRoot = await createTempHostRoot();
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
await writeFile(
- join(nuxtRoot, "vercel.json"),
+ join(hostRoot, "vercel.json"),
`${JSON.stringify({
experimentalServices: { eve: { entrypoint: ".", framework: "eve", routePrefix: "/x" } },
services: { eve: { root: ".", framework: "eve" } },
})}\n`,
);
- const result = await ensureEveVercelServicesConfig({ appRoot: nuxtRoot, nuxtRoot });
+ const result = await ensureEveVercelServicesConfig({
+ appRoot: hostRoot,
+ frameworkName: "Test",
+ hostRoot: hostRoot,
+ });
expect(result).toEqual({ mode: "root" });
expect(warn).not.toHaveBeenCalled();
});
it("rejects a malformed vercel.json", async () => {
- const nuxtRoot = await createTempNuxtRoot();
- await writeFile(join(nuxtRoot, "vercel.json"), `["not", "an", "object"]\n`);
-
- await expect(ensureEveVercelServicesConfig({ appRoot: nuxtRoot, nuxtRoot })).rejects.toThrow(
- /must contain a JSON object/,
- );
+ const hostRoot = await createTempHostRoot();
+ await writeFile(join(hostRoot, "vercel.json"), `["not", "an", "object"]\n`);
+
+ await expect(
+ ensureEveVercelServicesConfig({
+ appRoot: hostRoot,
+ frameworkName: "Test",
+ hostRoot: hostRoot,
+ }),
+ ).rejects.toThrow(/must contain a JSON object/);
});
});
diff --git a/packages/eve/src/public/nuxt/vercel-services.test.ts b/packages/eve/src/shared/vercel-services.test.ts
similarity index 95%
rename from packages/eve/src/public/nuxt/vercel-services.test.ts
rename to packages/eve/src/shared/vercel-services.test.ts
index 6899e513c..338999ad9 100644
--- a/packages/eve/src/public/nuxt/vercel-services.test.ts
+++ b/packages/eve/src/shared/vercel-services.test.ts
@@ -81,7 +81,11 @@ describe("mergeEveVercelConfig", () => {
const merged = mergeEveVercelConfig(
{
services: {
- agent: { framework: "eve", buildCommand: "pnpm build:agent", root: "agent" },
+ agent: {
+ framework: "eve",
+ buildCommand: "pnpm build:agent",
+ root: "agent",
+ },
other: { framework: "hono" },
},
},
diff --git a/packages/eve/src/public/nuxt/vercel-services.ts b/packages/eve/src/shared/vercel-services.ts
similarity index 85%
rename from packages/eve/src/public/nuxt/vercel-services.ts
rename to packages/eve/src/shared/vercel-services.ts
index b962e25c0..bf52a3d2d 100644
--- a/packages/eve/src/public/nuxt/vercel-services.ts
+++ b/packages/eve/src/shared/vercel-services.ts
@@ -87,10 +87,10 @@ export type EveVercelGeneratedService = {
};
/**
- * Minimal shape of the Nitro Vercel build-output config the module merges the
- * generated eve service into.
+ * Minimal shape of a Vercel Build Output config that can carry generated eve
+ * services.
*/
-export interface NitroVercelBuildConfig {
+export interface VercelBuildConfig {
version?: number;
routes?: unknown[];
services?: Record<string, VercelServiceConfig>;
@@ -100,8 +100,8 @@ export interface NitroVercelBuildConfig {
/**
* Result of {@link ensureEveVercelServicesConfig}: `root` when `vercel.json`
* already declares stable services (the user owns routing; nothing is
- * generated), `generated` with the service record to merge into the Nitro
- * Vercel build config otherwise.
+ * generated), `generated` with the service record to merge into a Vercel Build
+ * Output config otherwise.
*/
export type EnsureEveVercelServicesConfigResult =
| { readonly mode: "root" }
@@ -196,10 +196,13 @@ function findEveService(
return Object.values(services).find((service) => service.framework === "eve");
}
-function assertRootServicesIncludeEve(services: Record<string, VercelServiceConfig>): void {
+function assertRootServicesIncludeEve(
+ services: Record<string, VercelServiceConfig>,
+ frameworkName: string,
+): void {
if (findEveService(services) === undefined) {
throw new Error(
- `${VERCEL_JSON_FILE_NAME} already defines services, so the eve Nuxt module cannot add a generated eve service. Add an eve service (framework "eve") and a rewrite from ${EVE_ROUTE_PREFIX}/(.*) to it in ${VERCEL_JSON_FILE_NAME}, or remove services from ${VERCEL_JSON_FILE_NAME}.`,
+ `${VERCEL_JSON_FILE_NAME} already defines services, so the eve ${frameworkName} integration cannot add a generated eve service. Add an eve service (framework "eve") and a rewrite from ${EVE_ROUTE_PREFIX}/(.*) to it in ${VERCEL_JSON_FILE_NAME}, or remove services from ${VERCEL_JSON_FILE_NAME}.`,
);
}
}
@@ -281,57 +284,58 @@ function insertEveServiceRequestPathRoute(
function createGeneratedServiceBuild(input: {
readonly appRoot: string;
readonly eveBuildCommand?: string;
- readonly nuxtRoot: string;
+ readonly hostRoot: string;
}): { readonly buildCommand: string; readonly root: string; readonly rootDirectory: string } {
- const rootDirectory = join(input.nuxtRoot, EVE_VERCEL_SERVICES_DIRECTORY, EVE_SERVICE_NAME);
+ const rootDirectory = join(input.hostRoot, EVE_VERCEL_SERVICES_DIRECTORY, EVE_SERVICE_NAME);
const outputDirectory = join(rootDirectory, ".vercel", "output");
- const hostOutputDirectory = join(input.nuxtRoot, ".vercel", "output");
+ const hostOutputDirectory = join(input.hostRoot, ".vercel", "output");
const workingDirectory = toPosixRelative(rootDirectory, input.appRoot);
const configuredOutputDirectory = toPosixRelative(input.appRoot, outputDirectory);
const configuredHostOutputDirectory = toPosixRelative(input.appRoot, hostOutputDirectory);
const buildCommand =
input.eveBuildCommand ??
- `node ${quoteShellArgument(toPosixRelative(input.appRoot, resolveEveBinaryPath(input.nuxtRoot)))} build`;
+ `node ${quoteShellArgument(toPosixRelative(input.appRoot, resolveEveBinaryPath(input.hostRoot)))} build`;
return {
buildCommand: `cd ${quoteShellArgument(workingDirectory)} && export ${EVE_INTERNAL_BUILD_OUTPUT_DIRECTORY_ENV}=${quoteShellArgument(configuredOutputDirectory)} && export ${EVE_INTERNAL_HOST_BUILD_OUTPUT_DIRECTORY_ENV}=${quoteShellArgument(configuredHostOutputDirectory)} && ${buildCommand}`,
- root: toPosixRelative(input.nuxtRoot, rootDirectory),
+ root: toPosixRelative(input.hostRoot, rootDirectory),
rootDirectory,
};
}
/**
- * Resolve the stable Vercel services configuration for a Nuxt + eve
+ * Resolve the stable Vercel services configuration for a framework + eve
* deployment.
*
* When `vercel.json` (looked up from the linked Vercel project root, falling
- * back to the Nuxt root) already declares stable `services`, it must include
+ * back to the host root) already declares stable `services`, it must include
* an eve service and the module generates nothing. Otherwise this prepares a
* generated eve service — creating its isolated build root under
* `.eve/vercel-services/eve` so the eve build output cannot collide with the
- * Nuxt Build Output — and returns the service record plus the public service
- * route for the caller to merge into the Nitro Vercel build config. A legacy
+ * host Build Output — and returns the service record plus the public service
+ * route for the caller to merge into its Vercel build config. A legacy
* `experimentalServices` field is ignored with a migration warning: Vercel no
* longer routes it.
*/
export async function ensureEveVercelServicesConfig(input: {
readonly appRoot: string;
readonly eveBuildCommand?: string;
- readonly nuxtRoot: string;
+ readonly frameworkName: string;
+ readonly hostRoot: string;
}): Promise<EnsureEveVercelServicesConfigResult> {
- const vercelDirectory = await findClosestLinkedVercelDirectory(input.nuxtRoot);
- const projectRoot = vercelDirectory === undefined ? input.nuxtRoot : dirname(vercelDirectory);
+ const vercelDirectory = await findClosestLinkedVercelDirectory(input.hostRoot);
+ const projectRoot = vercelDirectory === undefined ? input.hostRoot : dirname(vercelDirectory);
const rootVercelConfig = await readVercelJsonConfig(join(projectRoot, VERCEL_JSON_FILE_NAME));
const rootServices = createServiceConfigRecord(rootVercelConfig.services);
if (Object.keys(rootServices).length > 0) {
- assertRootServicesIncludeEve(rootServices);
+ assertRootServicesIncludeEve(rootServices, input.frameworkName);
return { mode: "root" };
}
if (rootVercelConfig.experimentalServices !== undefined) {
console.warn(
- `[eve] ${VERCEL_JSON_FILE_NAME} defines experimentalServices, which Vercel no longer routes. The eve Nuxt module now generates the stable services config automatically — remove experimentalServices from ${VERCEL_JSON_FILE_NAME}.`,
+ `[eve] ${VERCEL_JSON_FILE_NAME} defines experimentalServices, which Vercel no longer routes. The eve ${input.frameworkName} integration now generates the stable services config automatically — remove experimentalServices from ${VERCEL_JSON_FILE_NAME}.`,
);
}
@@ -352,20 +356,18 @@ export async function ensureEveVercelServicesConfig(input: {
}
/**
- * Merge the generated eve service and its public route into a Nitro Vercel
- * build config (`nitro.vercel.config`).
+ * Merge the generated eve service and its public route into a Vercel Build
+ * Output config.
*
* The service route is inserted before an existing `handle: "filesystem"`
- * route, or prepended when none exists — Nitro appends its own generated
- * routes (including the filesystem handle) after this config's routes, so the
- * eve route always resolves before the Nuxt app's filesystem routing. An eve
- * service already configured by the user is preserved and only gains the
- * `request.path` route; everything else passes through untouched.
+ * route, or prepended when none exists. An eve service already configured by
+ * the user is preserved and only gains the `request.path` route; everything
+ * else passes through untouched.
*/
export function mergeEveVercelConfig(
- existing: NitroVercelBuildConfig | undefined,
+ existing: VercelBuildConfig | undefined,
generated: Extract<EnsureEveVercelServicesConfigResult, { mode: "generated" }>,
-): NitroVercelBuildConfig {
+): VercelBuildConfig {
const existingServices = existing?.services ?? {};
const configuredEveEntry = Object.entries(existingServices).find(
([name, service]) => name === EVE_SERVICE_NAME || service.framework === "eve",
diff --git a/packages/eve/test/scenarios/framework-sveltekit-build.scenario.test.ts b/packages/eve/test/scenarios/framework-sveltekit-build.scenario.test.ts
new file mode 100644
index 000000000..4e03ff05d
--- /dev/null
+++ b/packages/eve/test/scenarios/framework-sveltekit-build.scenario.test.ts
@@ -0,0 +1,101 @@
+import { readFile } from "node:fs/promises";
+import { join } from "node:path";
+import { fileURLToPath } from "node:url";
+
+import { describe, expect, it } from "vitest";
+
+import { createSvelteKitEveServiceDescriptor } from "../../src/internal/testing/scenario-apps/sveltekit-eve-service.js";
+import { useScenarioApp } from "../../src/internal/testing/scenario-app.js";
+import { runPnpmCommand } from "../../src/internal/testing/run-pnpm-command.js";
+
+const REPO_ROOT = fileURLToPath(new URL("../../../..", import.meta.url));
+const scenarioApp = useScenarioApp();
+
+const SVELTEKIT_EVE_SERVICE_DESCRIPTOR = createSvelteKitEveServiceDescriptor({
+ installDependencies: true,
+});
+
+async function readVercelOutputConfig(outputRoot: string): Promise<{
+ readonly routes: readonly unknown[];
+ readonly services: Record<string, unknown>;
+}> {
+ const config: unknown = JSON.parse(await readFile(join(outputRoot, "config.json"), "utf8"));
+
+ if (
+ typeof config !== "object" ||
+ config === null ||
+ !("routes" in config) ||
+ !Array.isArray(config.routes)
+ ) {
+ throw new Error("Expected Vercel Build Output config.json to contain a routes array.");
+ }
+
+ const services =
+ "services" in config && typeof config.services === "object" && config.services !== null
+ ? (config.services as Record<string, unknown>)
+ : {};
+
+ return { routes: config.routes, services };
+}
+
+describe("framework-sveltekit build", () => {
+ it("builds the SvelteKit framework fixture against the workspace eve dist", async () => {
+ // Runs `build:sveltekit` rather than the fixture's `build` script: `build`
+ // regenerates the shared workspace `dist/`, which would corrupt scenario
+ // files running in parallel workers. The scenario globalSetup already
+ // rebuilt `dist/` before any worker forked.
+ await runPnpmCommand({
+ args: ["--filter", "framework-sveltekit", "build:sveltekit"],
+ cwd: REPO_ROOT,
+ });
+ }, 300_000);
+
+ it("emits the eve service and route into the Vercel Build Output", async () => {
+ const app = await scenarioApp(SVELTEKIT_EVE_SERVICE_DESCRIPTOR);
+
+ await runPnpmCommand({
+ args: ["exec", "vite", "build"],
+ cwd: app.appRoot,
+ env: {
+ ...process.env,
+ VERCEL: "1",
+ VERCEL_ENV: "production",
+ },
+ });
+
+ const { routes, services } = await readVercelOutputConfig(
+ join(app.appRoot, ".vercel", "output"),
+ );
+ const eveRouteIndex = routes.findIndex(
+ (route) =>
+ typeof route === "object" &&
+ route !== null &&
+ "src" in route &&
+ route.src === "^/eve/v1/(.*)$" &&
+ "destination" in route,
+ );
+ const filesystemIndex = routes.findIndex(
+ (route) =>
+ typeof route === "object" &&
+ route !== null &&
+ "handle" in route &&
+ route.handle === "filesystem",
+ );
+
+ expect(routes[eveRouteIndex]).toEqual(
+ expect.objectContaining({
+ destination: { service: "eve", type: "service" },
+ src: "^/eve/v1/(.*)$",
+ }),
+ );
+ if (filesystemIndex !== -1) {
+ expect(eveRouteIndex).toBeLessThan(filesystemIndex);
+ }
+ expect(services.eve).toEqual(
+ expect.objectContaining({
+ framework: "eve",
+ root: ".eve/vercel-services/eve",
+ }),
+ );
+ }, 300_000);
+});