Skip to content

Commit 2230f82

Browse files
fixup! Update the description of the --local flag for the wrangler dev command to clarify that it disables remote bindings, also un-deprecate and un-hide it
fix incorrect implementation
1 parent 70383ae commit 2230f82

File tree

6 files changed

+43
-39
lines changed

6 files changed

+43
-39
lines changed

packages/wrangler/e2e/remote-binding/dev-remote-bindings.test.ts

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -174,30 +174,17 @@ describe.skipIf(!CLOUDFLARE_ACCOUNT_ID)(
174174
);
175175

176176
// This should only include logs from the user Wrangler session (i.e. a single list of attached bindings, and only one ready message)
177-
// Logs order are not deterministic, so we match against to possible outputs.
178-
const output1 = dedent`
179-
Your Worker has access to the following bindings:
180-
Binding Resource Mode
181-
env.AI AI remote
182-
▲ [WARNING] AI bindings always access remote resources, and so may incur usage charges even in local dev. To suppress this warning, set \`remote: true\` for the binding definition in your configuration file.
183-
⎔ Starting local server...
184-
[wrangler:info] Ready on http://<HOST>:<PORT>
185-
[wrangler:info] GET / 200 OK (TIMINGS)`;
186-
187-
const output2 = dedent`
188-
Your Worker has access to the following bindings:
189-
Binding Resource Mode
190-
env.AI AI remote
191-
▲ [WARNING] AI bindings always access remote resources, and so may incur usage charges even in local dev. To suppress this warning, set \`remote: true\` for the binding definition in your configuration file.
192-
⎔ Starting local server...
193-
[wrangler:info] Ready on http://<HOST>:<PORT>
194-
[wrangler:info] GET / 200 OK (TIMINGS)`;
195-
196177
const normalizedOutput = normalizeOutput(worker.currentOutput);
197178

198-
expect(
199-
normalizedOutput === output1 || normalizedOutput === output2
200-
).toEqual(true);
179+
expect(normalizedOutput).toMatchInlineSnapshot(`
180+
"Your Worker has access to the following bindings:
181+
Binding Resource Mode
182+
env.AI AI remote
183+
▲ [WARNING] AI bindings always access remote resources, and so may incur usage charges even in local dev. To suppress this warning, set \`remote: true\` for the binding definition in your configuration file.
184+
⎔ Starting local server...
185+
[wrangler:info] Ready on http://<HOST>:<PORT>
186+
[wrangler:info] GET / 200 OK (TIMINGS)"
187+
`);
201188
});
202189

203190
describe("shows helpful error logs", () => {

packages/wrangler/src/api/startDevWorker/ConfigController.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ async function resolveBindings(
218218
{
219219
registry,
220220
local: !input.dev?.remote,
221+
localBindingsOnly: !!input.dev?.localBindingsOnly,
221222
name: config.name,
222223
}
223224
);

packages/wrangler/src/api/startDevWorker/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ export interface StartDevWorkerInput {
166166
* - undefined (default): Run your Worker's code locally, and any configured remote bindings remotely
167167
*/
168168
remote?: boolean | "minimal";
169+
/** Whether only local bindings (no remote ones) should be used during local development */
170+
localBindingsOnly?: boolean;
169171
/** Cloudflare Account credentials. Can be provided upfront or as a function which will be called only when required. */
170172
auth?: AsyncHook<CfAccount, [Pick<Config, "account_id">]>; // provide config.account_id as a hook param
171173
/** Whether local storage (KV, Durable Objects, R2, D1, etc) is persisted. You can also specify the directory to persist data to. */

packages/wrangler/src/dev.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ export const dev = createCommand({
286286
}
287287
},
288288
async handler(args) {
289-
const devInstance = await startDev(args);
289+
const devInstance = await startDev({ ...args, forceLocal: args.local });
290290
assert(devInstance.devEnv !== undefined);
291291
await events.once(devInstance.devEnv, "teardown");
292292
await Promise.all(devInstance.secondary.map((d) => d.teardown()));

packages/wrangler/src/dev/start-dev.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ async function setupDevEnv(
249249
auth,
250250
remote:
251251
args.remote || (args.forceLocal || args.local ? false : undefined),
252+
localBindingsOnly: !!args.forceLocal,
252253
server: {
253254
hostname: args.ip,
254255
port: args.port,

packages/wrangler/src/utils/print-bindings.ts

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export function printBindings(
1616
context: {
1717
registry?: WorkerRegistry | null;
1818
local?: boolean;
19+
localBindingsOnly?: boolean;
1920
name?: string;
2021
provisioning?: boolean;
2122
warnIfNoBindings?: boolean;
@@ -139,7 +140,8 @@ export function printBindings(
139140
type: friendlyBindingNames.workflows,
140141
value: value,
141142
mode: getMode({
142-
isSimulatedLocally: script_name ? !remote : true,
143+
isSimulatedLocally:
144+
script_name && !context.localBindingsOnly ? !remote : true,
143145
}),
144146
};
145147
})
@@ -154,7 +156,7 @@ export function printBindings(
154156
type: friendlyBindingNames.kv_namespaces,
155157
value: id,
156158
mode: getMode({
157-
isSimulatedLocally: !remote,
159+
isSimulatedLocally: context.localBindingsOnly || !remote,
158160
}),
159161
};
160162
})
@@ -189,7 +191,8 @@ export function printBindings(
189191
type: friendlyBindingNames.send_email,
190192
value,
191193
mode: getMode({
192-
isSimulatedLocally: !emailBinding.remote,
194+
isSimulatedLocally:
195+
context.localBindingsOnly || !emailBinding.remote,
193196
}),
194197
};
195198
})
@@ -204,7 +207,7 @@ export function printBindings(
204207
type: friendlyBindingNames.queues,
205208
value: queue_name,
206209
mode: getMode({
207-
isSimulatedLocally: !remote,
210+
isSimulatedLocally: context.localBindingsOnly || !remote,
208211
}),
209212
};
210213
})
@@ -230,7 +233,7 @@ export function printBindings(
230233
name: binding,
231234
type: friendlyBindingNames.d1_databases,
232235
mode: getMode({
233-
isSimulatedLocally: !remote,
236+
isSimulatedLocally: context.localBindingsOnly || !remote,
234237
}),
235238
value,
236239
};
@@ -247,7 +250,8 @@ export function printBindings(
247250
type: friendlyBindingNames.vectorize,
248251
value: index_name,
249252
mode: getMode({
250-
isSimulatedLocally: remote ? false : undefined,
253+
isSimulatedLocally:
254+
remote && !context.localBindingsOnly ? false : undefined,
251255
}),
252256
};
253257
})
@@ -274,7 +278,10 @@ export function printBindings(
274278
name: binding,
275279
type: friendlyBindingNames.vpc_services,
276280
value: service_id,
277-
mode: getMode({ isSimulatedLocally: remote ? false : undefined }),
281+
mode: getMode({
282+
isSimulatedLocally:
283+
remote && !context.localBindingsOnly ? false : undefined,
284+
}),
278285
};
279286
})
280287
);
@@ -295,7 +302,7 @@ export function printBindings(
295302
type: friendlyBindingNames.r2_buckets,
296303
value: value,
297304
mode: getMode({
298-
isSimulatedLocally: !remote,
305+
isSimulatedLocally: context.localBindingsOnly || !remote,
299306
}),
300307
};
301308
})
@@ -418,7 +425,7 @@ export function printBindings(
418425
type: friendlyBindingNames.browser,
419426
value: undefined,
420427
mode: getMode({
421-
isSimulatedLocally: !browser.remote,
428+
isSimulatedLocally: context.localBindingsOnly || !browser.remote,
422429
}),
423430
});
424431
}
@@ -429,7 +436,7 @@ export function printBindings(
429436
type: friendlyBindingNames.images,
430437
value: undefined,
431438
mode: getMode({
432-
isSimulatedLocally: !images.remote,
439+
isSimulatedLocally: context.localBindingsOnly || !images.remote,
433440
}),
434441
});
435442
}
@@ -441,7 +448,8 @@ export function printBindings(
441448
value: undefined,
442449
mode: getMode({
443450
isSimulatedLocally:
444-
media.remote === true || media.remote === undefined
451+
(media.remote === true || media.remote === undefined) &&
452+
!context.localBindingsOnly
445453
? false
446454
: undefined,
447455
}),
@@ -455,7 +463,10 @@ export function printBindings(
455463
value: ai.staging ? `staging` : undefined,
456464
mode: getMode({
457465
isSimulatedLocally:
458-
ai.remote === true || ai.remote === undefined ? false : undefined,
466+
(ai.remote === true || ai.remote === undefined) &&
467+
!context.localBindingsOnly
468+
? false
469+
: undefined,
459470
}),
460471
});
461472
}
@@ -467,7 +478,7 @@ export function printBindings(
467478
type: friendlyBindingNames.pipelines,
468479
value: pipeline,
469480
mode: getMode({
470-
isSimulatedLocally: !remote,
481+
isSimulatedLocally: context.localBindingsOnly || !remote,
471482
}),
472483
}))
473484
);
@@ -561,7 +572,8 @@ export function printBindings(
561572
? `${namespace} (outbound -> ${outbound.service})`
562573
: namespace,
563574
mode: getMode({
564-
isSimulatedLocally: remote ? false : undefined,
575+
isSimulatedLocally:
576+
remote && !context.localBindingsOnly ? false : undefined,
565577
}),
566578
};
567579
})
@@ -576,7 +588,8 @@ export function printBindings(
576588
type: friendlyBindingNames.mtls_certificates,
577589
value: certificate_id,
578590
mode: getMode({
579-
isSimulatedLocally: remote ? false : undefined,
591+
isSimulatedLocally:
592+
remote && !context.localBindingsOnly ? false : undefined,
580593
}),
581594
};
582595
})
@@ -759,7 +772,7 @@ function createGetMode({
759772
return dim("not supported");
760773
}
761774

762-
return `${isSimulatedLocally || isLocalDev ? chalk.blue("local") : chalk.yellow("remote")}${connected === undefined ? "" : connected ? chalk.green(" [connected]") : chalk.red(" [not connected]")}`;
775+
return `${isSimulatedLocally ? chalk.blue("local") : chalk.yellow("remote")}${connected === undefined ? "" : connected ? chalk.green(" [connected]") : chalk.red(" [not connected]")}`;
763776
};
764777
}
765778

0 commit comments

Comments
 (0)