Skip to content

Commit a607fbd

Browse files
author
Cass Fridkin
committed
nits from code review
1 parent 3faddc0 commit a607fbd

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

packages/wrangler/src/entry.ts

+18-15
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ export async function getEntry(
5151

5252
if (format === "service-worker" && hasDurableObjectImplementations(config)) {
5353
const errorMessage =
54-
"You seem to be trying to use Durable Objects with Service Worker syntax.";
54+
"You seem to be trying to use Durable Objects in a Worker written with Service Worker syntax.";
5555
const addScriptName =
56-
"You can use Durable Objects defined in other (Module) Workers from a Service Worker by specifying a `script_name` in your wrangler.toml,where `script_name` is the name of the worker that implements that Durable Object. For example:";
56+
"You can use Durable Objects defined in other Workers by specifying a `script_name` in your wrangler.toml,where `script_name` is the name of the Worker that implements that Durable Object. For example:";
5757
const addScriptNameExamples = generateAddScriptNameExamples(config);
5858
const migrateText =
59-
"Alternatively, migrate your worker to Module format to implement a new Durable Object:";
59+
"Alternatively, migrate your worker to ES Module syntax to implement a Durable Object in this Worker:";
6060
const migrateUrl =
6161
"https://developers.cloudflare.com/workers/learning/migrating-to-module-workers/";
6262
throw new Error(
@@ -180,12 +180,7 @@ export function fileExists(filePath: string): boolean {
180180
* property in wrangler.toml
181181
*/
182182
function hasDurableObjectImplementations(config: Config): boolean {
183-
const allBindings = [
184-
...config.durable_objects.bindings,
185-
...Object.values(config.env)
186-
.map((env) => env.durable_objects.bindings)
187-
.flat(),
188-
];
183+
const allBindings = getDurableObjectBindings(config);
189184

190185
return allBindings.some((binding) => binding.script_name === undefined);
191186
}
@@ -196,12 +191,7 @@ function hasDurableObjectImplementations(config: Config): boolean {
196191
* externally defined Durable Object.
197192
*/
198193
function generateAddScriptNameExamples(config: Config): string {
199-
const allBindings = [
200-
...config.durable_objects.bindings,
201-
...Object.values(config.env)
202-
.map((env) => env.durable_objects.bindings)
203-
.flat(),
204-
];
194+
const allBindings = getDurableObjectBindings(config);
205195

206196
function exampleScriptName(binding_name: string): string {
207197
return `${binding_name.toLowerCase().replaceAll("_", "-")}-worker`;
@@ -218,3 +208,16 @@ function generateAddScriptNameExamples(config: Config): string {
218208
})
219209
.join("\n");
220210
}
211+
212+
/**
213+
* Get the Durable Object bindings in a given config, including those
214+
* specified in different environments
215+
*/
216+
function getDurableObjectBindings(config: Config) {
217+
return [
218+
...config.durable_objects.bindings,
219+
...Object.values(config.env)
220+
.map((env) => env.durable_objects.bindings)
221+
.flat(),
222+
];
223+
}

0 commit comments

Comments
 (0)