This repository was archived by the owner on Mar 13, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +32
-2
lines changed Expand file tree Collapse file tree 5 files changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ import {
2323 Plugins ,
2424 SERVICE_ENTRY ,
2525 SOCKET_ENTRY ,
26+ maybeGetSitesManifestModule ,
2627 normaliseDurableObject ,
2728} from "./plugins" ;
2829import { HEADER_CUSTOM_SERVICE , getUserServiceName } from "./plugins/core" ;
@@ -33,6 +34,7 @@ import {
3334 Service ,
3435 Socket ,
3536 Worker_Binding ,
37+ Worker_Module ,
3638 getSupportedRuntime ,
3739 serializeConfig ,
3840} from "./runtime" ;
@@ -403,12 +405,20 @@ export class Miniflare {
403405
404406 for ( let i = 0 ; i < allWorkerOpts . length ; i ++ ) {
405407 const workerOpts = allWorkerOpts [ i ] ;
408+
406409 // Collect all bindings from this worker
407410 const workerBindings : Worker_Binding [ ] = [ ] ;
411+ const additionalModules : Worker_Module [ ] = [ ] ;
408412 for ( const [ key , plugin ] of PLUGIN_ENTRIES ) {
409413 const pluginBindings = await plugin . getBindings ( workerOpts [ key ] ) ;
410414 if ( pluginBindings !== undefined ) {
411415 workerBindings . push ( ...pluginBindings ) ;
416+
417+ if ( key === "kv" ) {
418+ // Add "__STATIC_CONTENT_MANIFEST" module if sites enabled
419+ const module = maybeGetSitesManifestModule ( pluginBindings ) ;
420+ if ( module !== undefined ) additionalModules . push ( module ) ;
421+ }
412422 }
413423 }
414424
@@ -421,6 +431,7 @@ export class Miniflare {
421431 workerBindings,
422432 workerIndex : i ,
423433 durableObjectClassNames,
434+ additionalModules,
424435 } ) ;
425436 if ( pluginServices !== undefined ) {
426437 for ( const service of pluginServices ) {
Original file line number Diff line number Diff line change @@ -209,6 +209,7 @@ export const CORE_PLUGIN: Plugin<
209209 workerIndex,
210210 sharedOptions,
211211 durableObjectClassNames,
212+ additionalModules,
212213 } ) {
213214 // Define core/shared services.
214215 // Services get de-duped by name, so only the first worker's
@@ -232,6 +233,11 @@ export const CORE_PLUGIN: Plugin<
232233 // Define regular user worker if script is set
233234 const workerScript = getWorkerScript ( options ) ;
234235 if ( workerScript !== undefined ) {
236+ // Add additional modules (e.g. "__STATIC_CONTENT_MANIFEST") if any
237+ if ( "modules" in workerScript ) {
238+ workerScript . modules . push ( ...additionalModules ) ;
239+ }
240+
235241 const name = getUserServiceName ( options . name ) ;
236242 const classNames = durableObjectClassNames . get ( name ) ?? [ ] ;
237243 const compatibilityDate = validateCompatibilityDate (
Original file line number Diff line number Diff line change @@ -88,4 +88,5 @@ export const KV_PLUGIN: Plugin<
8888} ;
8989
9090export * from "./gateway" ;
91+ export { maybeGetSitesManifestModule } from "./sites" ;
9192export { KV_PLUGIN_NAME } ;
Original file line number Diff line number Diff line change 11import assert from "assert" ;
22import { pathToFileURL } from "url" ;
3- import { Service , Worker_Binding } from "../../runtime" ;
3+ import { Service , Worker_Binding , Worker_Module } from "../../runtime" ;
44import {
55 MatcherRegExps ,
66 deserialiseRegExps ,
@@ -171,6 +171,17 @@ export async function getSitesBindings(
171171 ] ;
172172}
173173
174+ export function maybeGetSitesManifestModule (
175+ bindings : Worker_Binding [ ]
176+ ) : Worker_Module | undefined {
177+ for ( const binding of bindings ) {
178+ if ( binding . name === BINDING_JSON_SITE_MANIFEST ) {
179+ assert ( "json" in binding && binding . json !== undefined ) ;
180+ return { name : BINDING_JSON_SITE_MANIFEST , text : binding . json } ;
181+ }
182+ }
183+ }
184+
174185export function getSitesService ( options : SitesOptions ) : Service {
175186 // `siteRegExps` should've been set in `getSitesBindings()`, and `options`
176187 // should be the same object reference as before.
Original file line number Diff line number Diff line change 11import { z } from "zod" ;
2- import { Service , Worker_Binding } from "../../runtime" ;
2+ import { Service , Worker_Binding , Worker_Module } from "../../runtime" ;
33import { Awaitable , OptionalZodTypeOf } from "../../shared" ;
44import { GatewayConstructor } from "./gateway" ;
55import { RouterConstructor } from "./router" ;
@@ -16,6 +16,7 @@ export interface PluginServicesOptions<
1616 workerBindings : Worker_Binding [ ] ;
1717 workerIndex : number ;
1818 durableObjectClassNames : DurableObjectClassNames ;
19+ additionalModules : Worker_Module [ ] ;
1920}
2021
2122export interface PluginBase <
You can’t perform that action at this time.
0 commit comments