88 Log ,
99 Mutex ,
1010 Options ,
11+ PluginContext ,
1112 PluginEntries ,
1213 PluginOptions ,
1314 PluginOptionsUnion ,
@@ -182,7 +183,6 @@ export interface MiniflareCoreContext {
182183 scriptRunner ?: ScriptRunner ;
183184 scriptRequired ?: boolean ;
184185 scriptRunForModuleExports ?: boolean ;
185- defaultConfigPath ?: string ;
186186}
187187
188188export class ReloadEvent < Plugins extends PluginSignatures > extends Event {
@@ -209,9 +209,9 @@ export class MiniflareCore<
209209 readonly #scriptRunner?: ScriptRunner ;
210210 readonly #scriptRequired?: boolean ;
211211 readonly #scriptRunForModuleExports?: boolean ;
212- readonly #defaultConfigPath: string ;
213212
214213 #compat?: Compatibility ;
214+ #previousRootPath?: string ;
215215 #instances?: PluginInstances < Plugins > ;
216216
217217 #wranglerConfigPath?: string ;
@@ -243,7 +243,6 @@ export class MiniflareCore<
243243 this . #scriptRunner = ctx . scriptRunner ;
244244 this . #scriptRequired = ctx . scriptRequired ;
245245 this . #scriptRunForModuleExports = ctx . scriptRunForModuleExports ;
246- this . #defaultConfigPath = ctx . defaultConfigPath ?? "wrangler.toml" ;
247246
248247 this . #initPromise = this . #init( ) . then ( ( ) => this . #reload( ) ) ;
249248 }
@@ -288,12 +287,14 @@ export class MiniflareCore<
288287 const previous = this . #previousOptions;
289288 let options = this . #overrides;
290289
290+ const rootPath = options . CorePlugin . rootPath ?? process . cwd ( ) ;
291+
291292 // Merge in wrangler config if defined
292293 const originalConfigPath = options . CorePlugin . wranglerConfigPath ;
293294 const configEnv = options . CorePlugin . wranglerConfigEnv ;
294295 let configPath =
295296 originalConfigPath === true
296- ? this . #defaultConfigPath
297+ ? path . join ( rootPath , "wrangler.toml" )
297298 : originalConfigPath ;
298299 if ( configPath ) {
299300 configPath = path . resolve ( configPath ) ;
@@ -330,14 +331,23 @@ export class MiniflareCore<
330331 this . #watching ??= options . CorePlugin . watch ?? false ;
331332
332333 // Build compatibility manager, rebuild all plugins if compatibility data
333- // has changed
334+ // or root path has changed
334335 const { compatibilityDate, compatibilityFlags } = options . CorePlugin ;
335- let compatUpdate = false ;
336+ let ctxUpdate =
337+ this . #previousRootPath && this . #previousRootPath !== rootPath ;
338+ this . #previousRootPath = rootPath ;
336339 if ( this . #compat) {
337- compatUpdate = this . #compat. update ( compatibilityDate , compatibilityFlags ) ;
340+ if ( this . #compat. update ( compatibilityDate , compatibilityFlags ) ) {
341+ ctxUpdate = true ;
342+ }
338343 } else {
339344 this . #compat = new Compatibility ( compatibilityDate , compatibilityFlags ) ;
340345 }
346+ const ctx : PluginContext = {
347+ log : this . log ,
348+ compat : this . #compat,
349+ rootPath,
350+ } ;
341351
342352 // Create plugin instances and run beforeSetup hooks, recreating any plugins
343353 // with changed options
@@ -347,7 +357,7 @@ export class MiniflareCore<
347357 for ( const [ name , plugin ] of this . #plugins) {
348358 if (
349359 previous !== undefined &&
350- ! compatUpdate &&
360+ ! ctxUpdate &&
351361 _deepEqual ( previous [ name ] , options [ name ] )
352362 ) {
353363 continue ;
@@ -360,7 +370,7 @@ export class MiniflareCore<
360370 await existingInstance . dispose ( ) ;
361371 }
362372
363- const instance = new plugin ( this . log , this . #compat , options [ name ] ) ;
373+ const instance = new plugin ( ctx , options [ name ] ) ;
364374 this . #instances[ name ] = instance as any ;
365375 if ( await this . #runBeforeSetup( name ) ) ranBeforeSetup = true ;
366376 }
@@ -371,7 +381,7 @@ export class MiniflareCore<
371381 for ( const [ name ] of this . #plugins) {
372382 if (
373383 previous !== undefined &&
374- ! compatUpdate &&
384+ ! ctxUpdate &&
375385 _deepEqual ( previous [ name ] , options [ name ] ) &&
376386 // Make sure if we ran any beforeSetups and this plugin previously
377387 // returned scripts, that we rerun its setup
0 commit comments