Skip to content

Commit c794935

Browse files
authored
Add (local) indicator to bindings using local data (#6972)
1 parent 381d04f commit c794935

File tree

8 files changed

+77
-58
lines changed

8 files changed

+77
-58
lines changed

.changeset/wet-dryers-pretend.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
Add ` (local)` indicator to bindings using local data

packages/wrangler/e2e/__snapshots__/pages-dev.test.ts.snap

+18-18
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ Your worker has access to the following bindings:
1414
- DO_BINDING_2_TOML: DO_2_TOML (defined in 🔴 DO_SCRIPT_2_TOML)
1515
- DO_BINDING_3_ARGS: DO_3_ARGS (defined in 🔴 DO_SCRIPT_3_ARGS)
1616
- KV Namespaces:
17-
- KV_BINDING_1_TOML: NEW_KV_ID_1
18-
- KV_BINDING_2_TOML: KV_ID_2_TOML
19-
- KV_BINDING_3_ARGS: KV_ID_3_ARGS
17+
- KV_BINDING_1_TOML: NEW_KV_ID_1 (local)
18+
- KV_BINDING_2_TOML: KV_ID_2_TOML (local)
19+
- KV_BINDING_3_ARGS: KV_ID_3_ARGS (local)
2020
- D1 Databases:
21-
- D1_BINDING_1_TOML: local-D1_BINDING_1_TOML=NEW_D1_NAME_1 (NEW_D1_NAME_1)
22-
- D1_BINDING_2_TOML: D1_NAME_2_TOML (D1_ID_2_TOML)
23-
- D1_BINDING_3_ARGS: local-D1_BINDING_3_ARGS=D1_NAME_3_ARGS (D1_NAME_3_ARGS)
21+
- D1_BINDING_1_TOML: local-D1_BINDING_1_TOML=NEW_D1_NAME_1 (NEW_D1_NAME_1) (local)
22+
- D1_BINDING_2_TOML: D1_NAME_2_TOML (D1_ID_2_TOML) (local)
23+
- D1_BINDING_3_ARGS: local-D1_BINDING_3_ARGS=D1_NAME_3_ARGS (D1_NAME_3_ARGS) (local)
2424
- R2 Buckets:
25-
- R2_BINDING_1_TOML: NEW_R2_BUCKET_1
26-
- R2_BINDING_2_TOML: R2_BUCKET_2_TOML
27-
- R2_BINDING_3_TOML: R2_BUCKET_3_ARGS
25+
- R2_BINDING_1_TOML: NEW_R2_BUCKET_1 (local)
26+
- R2_BINDING_2_TOML: R2_BUCKET_2_TOML (local)
27+
- R2_BINDING_3_TOML: R2_BUCKET_3_ARGS (local)
2828
- Services:
2929
- SERVICE_BINDING_1_TOML: 🔴 NEW_SERVICE_NAME_1
3030
- SERVICE_BINDING_2_TOML: 🔴 SERVICE_NAME_2_TOML
@@ -53,17 +53,17 @@ Your worker has access to the following bindings:
5353
- DO_BINDING_2_TOML: DO_2_TOML (defined in 🔴 DO_SCRIPT_2_TOML)
5454
- DO_BINDING_3_ARGS: DO_3_ARGS (defined in 🔴 DO_SCRIPT_3_ARGS)
5555
- KV Namespaces:
56-
- KV_BINDING_1_TOML: NEW_KV_ID_1
57-
- KV_BINDING_2_TOML: KV_ID_2_TOML
58-
- KV_BINDING_3_ARGS: KV_ID_3_ARGS
56+
- KV_BINDING_1_TOML: NEW_KV_ID_1 (local)
57+
- KV_BINDING_2_TOML: KV_ID_2_TOML (local)
58+
- KV_BINDING_3_ARGS: KV_ID_3_ARGS (local)
5959
- D1 Databases:
60-
- D1_BINDING_1_TOML: local-D1_BINDING_1_TOML=NEW_D1_NAME_1 (NEW_D1_NAME_1)
61-
- D1_BINDING_2_TOML: D1_NAME_2_TOML (D1_ID_2_TOML)
62-
- D1_BINDING_3_ARGS: local-D1_BINDING_3_ARGS=D1_NAME_3_ARGS (D1_NAME_3_ARGS)
60+
- D1_BINDING_1_TOML: local-D1_BINDING_1_TOML=NEW_D1_NAME_1 (NEW_D1_NAME_1) (local)
61+
- D1_BINDING_2_TOML: D1_NAME_2_TOML (D1_ID_2_TOML) (local)
62+
- D1_BINDING_3_ARGS: local-D1_BINDING_3_ARGS=D1_NAME_3_ARGS (D1_NAME_3_ARGS) (local)
6363
- R2 Buckets:
64-
- R2_BINDING_1_TOML: NEW_R2_BUCKET_1
65-
- R2_BINDING_2_TOML: R2_BUCKET_2_TOML
66-
- R2_BINDING_3_TOML: R2_BUCKET_3_ARGS
64+
- R2_BINDING_1_TOML: NEW_R2_BUCKET_1 (local)
65+
- R2_BINDING_2_TOML: R2_BUCKET_2_TOML (local)
66+
- R2_BINDING_3_TOML: R2_BUCKET_3_ARGS (local)
6767
- Services:
6868
- SERVICE_BINDING_1_TOML: 🔴 NEW_SERVICE_NAME_1
6969
- SERVICE_BINDING_2_TOML: 🔴 SERVICE_NAME_2_TOML

packages/wrangler/e2e/pages-dev.test.ts

+18-20
Original file line numberDiff line numberDiff line change
@@ -117,20 +117,19 @@ describe.each([
117117
`${cmd} . --port ${port} --service TEST_SERVICE=test-worker --kv TEST_KV --do TEST_DO=TestDurableObject@a --d1 TEST_D1 --r2 TEST_R2`
118118
);
119119
await worker.waitForReady();
120-
expect(normalizeOutput(worker.currentOutput).replace(/\s/g, "")).toContain(
121-
`
122-
Your worker has access to the following bindings:
123-
- Durable Objects:
124-
- TEST_DO: TestDurableObject (defined in 🔴 a)
125-
- KV Namespaces:
126-
- TEST_KV: TEST_KV
127-
- D1 Databases:
128-
- TEST_D1: local-TEST_D1 (TEST_D1)
129-
- R2 Buckets:
130-
- TEST_R2: TEST_R2
131-
- Services:
132-
- TEST_SERVICE: 🔴 test-worker
133-
`.replace(/\s/g, "")
120+
expect(normalizeOutput(worker.currentOutput)).toContain(
121+
dedent`Your worker has access to the following bindings:
122+
- Durable Objects:
123+
- TEST_DO: TestDurableObject (defined in 🔴 a)
124+
- KV Namespaces:
125+
- TEST_KV: TEST_KV (local)
126+
- D1 Databases:
127+
- TEST_D1: local-TEST_D1 (TEST_D1) (local)
128+
- R2 Buckets:
129+
- TEST_R2: TEST_R2 (local)
130+
- Services:
131+
- TEST_SERVICE: 🔴 test-worker
132+
`
134133
);
135134
});
136135

@@ -320,14 +319,13 @@ describe.each([
320319
const text = await fetchText(url);
321320

322321
expect(text).toBe("⚡️ Pages ⚡️ supports wrangler.toml");
323-
expect(normalizeOutput(worker.currentOutput).replace(/\s/g, "")).toContain(
324-
`
325-
Your worker has access to the following bindings:
322+
expect(normalizeOutput(worker.currentOutput)).toContain(
323+
dedent`Your worker has access to the following bindings:
326324
- KV Namespaces:
327-
- KV_BINDING_TOML: KV_ID_TOML
325+
- KV_BINDING_TOML: KV_ID_TOML (local)
328326
- Vars:
329-
- PAGES: "⚡️ Pages ⚡️"
330-
`.replace(/\s/g, "")
327+
- PAGES: "⚡️ Pages ⚡️"
328+
`
331329
);
332330
});
333331

packages/wrangler/src/__tests__/deploy.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -8189,7 +8189,7 @@ addEventListener('fetch', event => {});`
81898189
"Total Upload: xx KiB / gzip: xx KiB
81908190
Worker Startup Time: 100 ms
81918191
Your worker has access to the following bindings:
8192-
- dispatch namespaces:
8192+
- Dispatch Namespaces:
81938193
- foo: Foo
81948194
Uploaded test-name (TIMINGS)
81958195
Deployed test-name triggers (TIMINGS)
@@ -8247,7 +8247,7 @@ addEventListener('fetch', event => {});`
82478247
"Total Upload: xx KiB / gzip: xx KiB
82488248
Worker Startup Time: 100 ms
82498249
Your worker has access to the following bindings:
8250-
- dispatch namespaces:
8250+
- Dispatch Namespaces:
82518251
- foo: Foo (outbound -> foo_outbound)
82528252
- bar: Bar (outbound -> bar_outbound)
82538253
Uploaded test-name (TIMINGS)
@@ -8304,7 +8304,7 @@ addEventListener('fetch', event => {});`
83048304
"Total Upload: xx KiB / gzip: xx KiB
83058305
Worker Startup Time: 100 ms
83068306
Your worker has access to the following bindings:
8307-
- dispatch namespaces:
8307+
- Dispatch Namespaces:
83088308
- foo: Foo (outbound -> foo_outbound)
83098309
Uploaded test-name (TIMINGS)
83108310
Deployed test-name triggers (TIMINGS)

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ async function resolveBindings(
163163
...bindings,
164164
vars: maskedVars,
165165
},
166-
input.dev?.registry
166+
{ registry: input.dev?.registry, local: !input.dev?.remote }
167167
);
168168

169169
return {

packages/wrangler/src/config/index.ts

+18-11
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,19 @@ export function findWranglerToml(
192192
return findUpSync(`wrangler.toml`, { cwd: referencePath });
193193
}
194194

195+
function addLocalSuffix(id: string, local: boolean = false) {
196+
return `${id}${local ? " (local)" : ""}`;
197+
}
198+
195199
/**
196200
* Print all the bindings a worker using a given config would have access to
197201
*/
198202
export function printBindings(
199203
bindings: CfWorkerInit["bindings"],
200-
registry?: WorkerRegistry
204+
context: {
205+
registry?: WorkerRegistry;
206+
local?: boolean;
207+
} = {}
201208
) {
202209
const truncate = (item: string | Record<string, unknown>) => {
203210
const s = typeof item === "string" ? item : JSON.stringify(item);
@@ -257,7 +264,7 @@ export function printBindings(
257264
({ name, class_name, script_name }) => {
258265
let value = class_name;
259266
if (script_name) {
260-
const registryDefinition = registry?.[script_name];
267+
const registryDefinition = context.registry?.[script_name];
261268
if (
262269
registryDefinition &&
263270
registryDefinition.durableObjects.some(
@@ -302,7 +309,7 @@ export function printBindings(
302309
entries: kv_namespaces.map(({ binding, id }) => {
303310
return {
304311
key: binding,
305-
value: id,
312+
value: addLocalSuffix(id, context.local),
306313
};
307314
}),
308315
});
@@ -331,7 +338,7 @@ export function printBindings(
331338
entries: queues.map(({ binding, queue_name }) => {
332339
return {
333340
key: binding,
334-
value: queue_name,
341+
value: addLocalSuffix(queue_name, context.local),
335342
};
336343
}),
337344
});
@@ -352,7 +359,7 @@ export function printBindings(
352359
}
353360
return {
354361
key: binding,
355-
value: databaseValue,
362+
value: addLocalSuffix(databaseValue, context.local),
356363
};
357364
}
358365
),
@@ -365,7 +372,7 @@ export function printBindings(
365372
entries: vectorize.map(({ binding, index_name }) => {
366373
return {
367374
key: binding,
368-
value: index_name,
375+
value: addLocalSuffix(index_name, context.local),
369376
};
370377
}),
371378
});
@@ -377,7 +384,7 @@ export function printBindings(
377384
entries: hyperdrive.map(({ binding, id }) => {
378385
return {
379386
key: binding,
380-
value: id,
387+
value: addLocalSuffix(id, context.local),
381388
};
382389
}),
383390
});
@@ -392,7 +399,7 @@ export function printBindings(
392399
}
393400
return {
394401
key: binding,
395-
value: bucket_name,
402+
value: addLocalSuffix(bucket_name, context.local),
396403
};
397404
}),
398405
});
@@ -419,7 +426,7 @@ export function printBindings(
419426
value += `#${entrypoint}`;
420427
}
421428

422-
const registryDefinition = registry?.[service];
429+
const registryDefinition = context.registry?.[service];
423430
if (
424431
registryDefinition &&
425432
(!entrypoint || registryDefinition.entrypointAddresses?.[entrypoint])
@@ -478,7 +485,7 @@ export function printBindings(
478485

479486
output.push({
480487
type: "AI",
481-
entries: entries,
488+
entries,
482489
});
483490
}
484491

@@ -541,7 +548,7 @@ export function printBindings(
541548

542549
if (dispatch_namespaces !== undefined && dispatch_namespaces.length > 0) {
543550
output.push({
544-
type: "dispatch namespaces",
551+
type: "Dispatch Namespaces",
545552
entries: dispatch_namespaces.map(({ binding, namespace, outbound }) => {
546553
return {
547554
key: binding,

packages/wrangler/src/dev.tsx

+7-4
Original file line numberDiff line numberDiff line change
@@ -1414,10 +1414,13 @@ export function getResolvedBindings(
14141414

14151415
const maskedVars = maskVars(bindings, configParam);
14161416

1417-
printBindings({
1418-
...bindings,
1419-
vars: maskedVars,
1420-
});
1417+
printBindings(
1418+
{
1419+
...bindings,
1420+
vars: maskedVars,
1421+
},
1422+
{ local: !args.remote }
1423+
);
14211424

14221425
return bindings;
14231426
}

packages/wrangler/src/paths.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,13 @@ export function getWranglerTmpDir(
9999
const tmpPrefix = path.join(tmpRoot, `${prefix}-`);
100100
const tmpDir = fs.realpathSync(fs.mkdtempSync(tmpPrefix));
101101

102-
const removeDir = () => fs.rmSync(tmpDir, { recursive: true, force: true });
102+
const removeDir = () => {
103+
try {
104+
return fs.rmSync(tmpDir, { recursive: true, force: true });
105+
} catch (e) {
106+
// This sometimes fails on Windows with EBUSY
107+
}
108+
};
103109
const removeExitListener = onExit(removeDir);
104110

105111
return {

0 commit comments

Comments
 (0)