Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 8049440

Browse files
committed
Allow missing parent script with mounted workers
1 parent 9f539d8 commit 8049440

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

packages/core/src/index.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -430,14 +430,6 @@ export class MiniflareCore<
430430
// changes
431431
this.#previousOptions = options;
432432

433-
// Make sure we've got a script if it's required
434-
if (
435-
this.#ctx.scriptRequired &&
436-
!this.#setupResults.get("CorePlugin")?.script
437-
) {
438-
throwNoScriptError(options.CorePlugin.modules);
439-
}
440-
441433
// Update mounts
442434
this.#mounts ??= new Map();
443435
const mounts = options.CorePlugin
@@ -543,6 +535,16 @@ export class MiniflareCore<
543535
}
544536
}
545537
await this.#updateRouter();
538+
539+
// Make sure we've got a script if it's required (if we've got mounts,
540+
// allow no script, as we might always route to those)
541+
if (
542+
this.#ctx.scriptRequired &&
543+
!this.#setupResults.get("CorePlugin")?.script &&
544+
this.#mounts.size === 0
545+
) {
546+
throwNoScriptError(options.CorePlugin.modules);
547+
}
546548
}
547549

548550
async #updateRouter(): Promise<void> {

packages/core/test/index.mounts.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
BindingsPlugin,
1010
CorePlugin,
1111
MiniflareCore,
12+
MiniflareCoreContext,
1213
MiniflareCoreError,
1314
ReloadEvent,
1415
} from "@miniflare/core";
@@ -319,6 +320,20 @@ test("MiniflareCore: #init: disposes removed mounts", async (t) => {
319320
res = await mf.dispatchFetch("http://localhost/b");
320321
t.is(await res.text(), "b");
321322
});
323+
test("MiniflareCore: #init: doesn't throw if script required, parent script not provided, but has mounts", async (t) => {
324+
const ctx: MiniflareCoreContext = {
325+
log: new NoOpLog(),
326+
storageFactory: new MemoryStorageFactory(),
327+
scriptRunner: new VMScriptRunner(),
328+
scriptRequired: true,
329+
};
330+
331+
const mf = new MiniflareCore({ CorePlugin }, ctx, {
332+
mounts: { a: { script: constantBodyScript("a") } },
333+
});
334+
await mf.getPlugins();
335+
t.pass();
336+
});
322337

323338
test("MiniflareCore: #reload: includes mounted module exports when calling plugin reload hooks", async (t) => {
324339
const mf = useMiniflare(

0 commit comments

Comments
 (0)