Skip to content

Commit e0f09b4

Browse files
authored
fix(eve): resolve dev schedule loader at build time (#761)
Signed-off-by: Rui Conti <[email protected]>
1 parent d194243 commit e0f09b4

6 files changed

Lines changed: 49 additions & 16 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eve": patch
3+
---
4+
5+
The `eve dev` schedule dispatch route now reuses the module loader path resolved when the server is built, preventing module resolution failures in the bundled Windows dev server.

packages/eve/src/internal/nitro/host/configure-nitro-routes.test.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ vi.mock("../../application/paths.js", () => ({
8585
}));
8686

8787
const { configureNitroRoutes } = await import("./configure-nitro-routes.js");
88-
const { EVE_HEALTH_ROUTE_PATH, EVE_INFO_ROUTE_PATH } = await import("#protocol/routes.js");
88+
const { EVE_DEV_DISPATCH_SCHEDULE_ROUTE_PATTERN, EVE_HEALTH_ROUTE_PATH, EVE_INFO_ROUTE_PATH } =
89+
await import("#protocol/routes.js");
8990

9091
function createNitroStub(
9192
input: { buildDir?: string; dev?: boolean; rootDir?: string } = {},
@@ -310,6 +311,18 @@ describe("configureNitroRoutes", () => {
310311
);
311312
});
312313

314+
it("bakes the module map loader into the dev schedule handler", async () => {
315+
const nitro = createNitroStub({ dev: true });
316+
317+
await configureNitroRoutes(nitro, createPreparedHost(), {
318+
surface: "app",
319+
});
320+
321+
const source = nitro.options.virtual[`#eve-route${EVE_DEV_DISPATCH_SCHEDULE_ROUTE_PATTERN}`];
322+
expect(source).toContain('"moduleMapLoaderPath"');
323+
expect(source).toContain("authored-module-map-loader.js");
324+
});
325+
313326
it("registers the agent info route for dev and production app builds", async () => {
314327
const devNitro = createNitroStub({ dev: true });
315328
const prodNitro = createNitroStub({ dev: false });

packages/eve/src/internal/nitro/host/configure-nitro-routes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ export async function configureNitroRoutes(
373373
route: EVE_DEV_RUNTIME_ARTIFACTS_ROUTE_PATH,
374374
});
375375
addFrameworkVirtualHandler(nitro, {
376-
args: JSON.stringify({ appRoot: artifactsConfig.appRoot }),
376+
args: JSON.stringify(artifactsConfig),
377377
handlerExport: "handleDevScheduleDispatchRequest",
378378
method: "POST",
379379
modulePath: resolvePackageSourceFilePath(

packages/eve/src/internal/nitro/host/dispatch-schedule-in-dev.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { createNitroArtifactsConfig } from "#internal/nitro/host/artifacts-config.js";
2-
import { createAuthoredSourceRuntimeCompiledArtifactsSource } from "#internal/application/runtime-compiled-artifacts-source.js";
1+
import type { NitroArtifactsConfigInput } from "#internal/nitro/host/artifacts-config.js";
2+
import { createDiskRuntimeCompiledArtifactsSource } from "#runtime/compiled-artifacts-source.js";
33
import { createScheduleRegistrations } from "#runtime/schedules/register.js";
44
import { loadResolvedCompiledSchedules } from "#runtime/schedules/resolve-schedule.js";
55

@@ -51,12 +51,25 @@ export class UnknownDevScheduleError extends Error {
5151
* Re-resolves authored schedule registrations from disk on every call so
5252
* the route picks up edits made by the authored-source watcher without a
5353
* dev-server restart.
54+
*
55+
* The artifacts config is resolved before Nitro bundles this module and
56+
* baked into the virtual handler. Re-deriving its loader path here would
57+
* resolve relative to the app instead of the installed eve package.
5458
*/
5559
export async function dispatchScheduleInDev(input: {
56-
readonly appRoot: string;
60+
readonly artifactsConfig: NitroArtifactsConfigInput;
5761
readonly scheduleId: string;
5862
}): Promise<DispatchScheduleInDevResult> {
59-
const compiledArtifactsSource = createAuthoredSourceRuntimeCompiledArtifactsSource(input.appRoot);
63+
const { appRoot, moduleMapLoaderPath } = input.artifactsConfig;
64+
if (appRoot === undefined || moduleMapLoaderPath === undefined) {
65+
throw new Error(
66+
'Dev schedule dispatch requires "appRoot" and "moduleMapLoaderPath" in the artifacts config.',
67+
);
68+
}
69+
70+
const compiledArtifactsSource = createDiskRuntimeCompiledArtifactsSource(appRoot, {
71+
moduleMapLoaderPath,
72+
});
6073
const schedules = await loadResolvedCompiledSchedules({ compiledArtifactsSource });
6174
const registrations = createScheduleRegistrations(schedules);
6275
const registration = registrations.find((candidate) => candidate.scheduleId === input.scheduleId);
@@ -69,11 +82,7 @@ export async function dispatchScheduleInDev(input: {
6982
}
7083

7184
const { dispatchScheduleTask } = await import("#internal/nitro/routes/schedule-task.js");
72-
const artifactsConfig = createNitroArtifactsConfig({
73-
appRoot: input.appRoot,
74-
dev: true,
75-
});
76-
const result = await dispatchScheduleTask(registration.taskName, artifactsConfig);
85+
const result = await dispatchScheduleTask(registration.taskName, input.artifactsConfig);
7786

7887
return {
7988
scheduleId: result.scheduleId,

packages/eve/src/internal/nitro/routes/dev-schedule-dispatch.test.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ vi.mock("#internal/nitro/host/dispatch-schedule-in-dev.js", async () => {
1515
});
1616

1717
const APP_ROOT = "/tmp/eve-test";
18+
const ARTIFACTS_CONFIG = {
19+
appRoot: APP_ROOT,
20+
dev: true,
21+
moduleMapLoaderPath: "/tmp/eve-test/module-map-loader.js",
22+
};
1823

1924
async function importHandler() {
2025
return await import("#internal/nitro/routes/dev-schedule-dispatch.js");
@@ -25,7 +30,7 @@ async function postSchedule(scheduleIdInUrl: string): Promise<Response> {
2530
const request = new Request(`http://localhost:3000/eve/v1/dev/schedules/${scheduleIdInUrl}`, {
2631
method: "POST",
2732
});
28-
return await handleDevScheduleDispatchRequest({ appRoot: APP_ROOT }, request);
33+
return await handleDevScheduleDispatchRequest(ARTIFACTS_CONFIG, request);
2934
}
3035

3136
describe("handleDevScheduleDispatchRequest", () => {
@@ -44,7 +49,7 @@ describe("handleDevScheduleDispatchRequest", () => {
4449
sessionIds: ["sess-1", "sess-2"],
4550
});
4651
expect(mocks.dispatchScheduleInDev).toHaveBeenCalledWith({
47-
appRoot: APP_ROOT,
52+
artifactsConfig: ARTIFACTS_CONFIG,
4853
scheduleId: "heartbeat",
4954
});
5055
});
@@ -59,7 +64,7 @@ describe("handleDevScheduleDispatchRequest", () => {
5964

6065
expect(response.status).toBe(200);
6166
expect(mocks.dispatchScheduleInDev).toHaveBeenCalledWith({
62-
appRoot: APP_ROOT,
67+
artifactsConfig: ARTIFACTS_CONFIG,
6368
scheduleId: "weird/name",
6469
});
6570
});

packages/eve/src/internal/nitro/routes/dev-schedule-dispatch.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
dispatchScheduleInDev,
33
UnknownDevScheduleError,
44
} from "#internal/nitro/host/dispatch-schedule-in-dev.js";
5+
import type { NitroArtifactsConfigInput } from "#internal/nitro/host/artifacts-config.js";
56
import { EVE_ROUTE_PREFIX } from "#protocol/routes.js";
67

78
/**
@@ -29,7 +30,7 @@ const DEV_DISPATCH_SCHEDULE_PATH_PATTERN = new RegExp(
2930
* Auth: none. The dev server is local-only and the route is dev-only.
3031
*/
3132
export async function handleDevScheduleDispatchRequest(
32-
input: { appRoot: string },
33+
input: NitroArtifactsConfigInput,
3334
request: Request,
3435
): Promise<Response> {
3536
const url = new URL(request.url);
@@ -52,7 +53,7 @@ export async function handleDevScheduleDispatchRequest(
5253

5354
try {
5455
const result = await dispatchScheduleInDev({
55-
appRoot: input.appRoot,
56+
artifactsConfig: input,
5657
scheduleId,
5758
});
5859
return Response.json({

0 commit comments

Comments
 (0)