11import { kCurrentWorker , Miniflare } from "miniflare" ;
22import { getAssetsOptions } from "../../../assets" ;
3- import { readConfig } from "../../../config" ;
3+ import { formatConfigSnippet , readConfig } from "../../../config" ;
44import { partitionDurableObjectBindings } from "../../../deployment-bundle/entry" ;
55import { DEFAULT_MODULE_RULES } from "../../../deployment-bundle/rules" ;
66import { getBindings } from "../../../dev" ;
@@ -109,7 +109,8 @@ export async function getPlatformProxy<
109109 MULTIWORKER : false ,
110110 RESOURCES_PROVISION : false ,
111111 } ,
112- ( ) => getMiniflareOptionsFromConfig ( rawConfig , env , options )
112+ ( ) =>
113+ getMiniflareOptionsFromConfig ( rawConfig , env , options , options . configPath )
113114 ) ;
114115
115116 const mf = new Miniflare ( {
@@ -136,7 +137,8 @@ export async function getPlatformProxy<
136137async function getMiniflareOptionsFromConfig (
137138 rawConfig : Config ,
138139 env : string | undefined ,
139- options : GetPlatformProxyOptions
140+ options : GetPlatformProxyOptions ,
141+ configPath : string | undefined
140142) : Promise < Partial < MiniflareOptions > > {
141143 const bindings = getBindings ( rawConfig , env , true , { } ) ;
142144
@@ -149,8 +151,36 @@ async function getMiniflareOptionsFromConfig(
149151 These will not work in local development, but they should work in production.
150152
151153 If you want to develop these locally, you can define your DO "externally" in another Worker.
152- To do this, create another Worker and Wrangler config file. Export your DO from there.
153- Then, set the \`script_name\` field in your original DO binding to equal the \`name\` field from your new external DO config.
154+ To do this, create another Worker, e.g.
155+
156+ export class MyDurableObject extends DurableObject {
157+ // DO code goes here
158+ }
159+ export default {
160+ fetch() {
161+ // doesn't have to do anything, but DO cannot be the default export
162+ }
163+ }
164+
165+ Also create a new Wrangler config file for this Worker, e.g.
166+
167+ ${ formatConfigSnippet ( { name : "external-do-worker" , main : "src/index.ts" , compatibility_date : "XXXX-XX-XX" } , configPath ) }
168+
169+ Then, update your original DO bindings to include the script_name field, e.g.
170+ ${ formatConfigSnippet (
171+ {
172+ durable_objects : {
173+ bindings : [
174+ {
175+ name : "BINDING" ,
176+ class_name : "MyDurableObject" ,
177+ script_name : "external-do-worker" ,
178+ } ,
179+ ] ,
180+ } ,
181+ } ,
182+ configPath
183+ ) }
154184
155185 You will be able to develop this locally by running:
156186 npx wrangler dev -c path/to/original/wrangler.jsonc -c path/to/external-do/wrangler.jsonc
0 commit comments