@@ -20,7 +20,7 @@ export type Entry = { file: string; directory: string; format: CfScriptFormat };
20
20
export async function getEntry (
21
21
args : { script ?: string ; format ?: CfScriptFormat | undefined } ,
22
22
config : Config ,
23
- command : string
23
+ command : "dev" | "publish"
24
24
) : Promise < Entry > {
25
25
let file : string ;
26
26
let directory = process . cwd ( ) ;
@@ -49,7 +49,19 @@ export async function getEntry(
49
49
args . format ?? config . build ?. upload ?. format
50
50
) ;
51
51
52
- if ( format === "service-worker" && hasDurableObjectImplementations ( config ) ) {
52
+ const { localBindings, remoteBindings } =
53
+ partitionDurableObjectBindings ( config ) ;
54
+
55
+ if ( command === "dev" && remoteBindings . length > 0 ) {
56
+ console . warn (
57
+ "WARNING: You have Durable Object bindings, which are not defined locally in the worker being developed.\n" +
58
+ "Be aware that changes to the data stored in these Durable Objects will be permanent and affect the live instances.\n" +
59
+ "Remote Durable Objects that are affected:\n" +
60
+ remoteBindings . map ( ( b ) => `- ${ JSON . stringify ( b ) } ` ) . join ( "\n" )
61
+ ) ;
62
+ }
63
+
64
+ if ( format === "service-worker" && localBindings . length > 0 ) {
53
65
const errorMessage =
54
66
"You seem to be trying to use Durable Objects in a Worker written with Service Worker syntax." ;
55
67
const addScriptName =
@@ -174,15 +186,26 @@ export function fileExists(filePath: string): boolean {
174
186
return false ;
175
187
}
176
188
189
+ type DurableObjectBindings = Config [ "durable_objects" ] [ "bindings" ] ;
190
+
177
191
/**
178
- * Returns true if the given config contains Durable Object bindings that are implemented
179
- * in this worker instead of being implemented elsewhere, and bound via a `script_name`
180
- * property in wrangler.toml
192
+ * Groups the durable object bindings into two lists:
193
+ * those that are defined locally and those that refer to a durable object defined in another script.
181
194
*/
182
- function hasDurableObjectImplementations ( config : Config ) : boolean {
183
- return config . durable_objects . bindings . some (
184
- ( binding ) => binding . script_name === undefined
185
- ) ;
195
+ function partitionDurableObjectBindings ( config : Config ) : {
196
+ localBindings : DurableObjectBindings ;
197
+ remoteBindings : DurableObjectBindings ;
198
+ } {
199
+ const localBindings : DurableObjectBindings = [ ] ;
200
+ const remoteBindings : DurableObjectBindings = [ ] ;
201
+ for ( const binding of config . durable_objects . bindings ) {
202
+ if ( binding . script_name === undefined ) {
203
+ localBindings . push ( binding ) ;
204
+ } else {
205
+ remoteBindings . push ( binding ) ;
206
+ }
207
+ }
208
+ return { localBindings, remoteBindings } ;
186
209
}
187
210
188
211
/**
0 commit comments