Skip to content

Commit 1914b87

Browse files
slightly improve wrangler dev bindings loggings (#9507)
* slightly improve wrangler dev bindings loggings * fixup! slightly improve wrangler dev bindings loggings update dev-mixed-mode snapshot
1 parent 80b8bd9 commit 1914b87

File tree

4 files changed

+31
-10
lines changed

4 files changed

+31
-10
lines changed

.changeset/clean-eyes-lead.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
slightly improve wrangler dev bindings loggings
6+
7+
improve the bindings loggings by:
8+
9+
- removing the unnecessary (and potentially incorrect) `[connected]` suffix for remote bindings
10+
- making sure that the modes presented in the bindings logs are correctly aligned

packages/wrangler/e2e/dev-mixed-mode.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ describe("wrangler dev - mixed mode", () => {
186186
expect(normalizeOutput(worker.currentOutput)).toMatchInlineSnapshot(`
187187
"Your Worker has access to the following bindings:
188188
Binding Resource Mode
189-
env.AI AI remote
189+
env.AI AI remote
190190
[wrangler:info] Ready on http://<HOST>:<PORT>
191191
▲ [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.
192192
⎔ Starting local server...

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1585,8 +1585,8 @@ describe.sequential("wrangler dev", () => {
15851585
expect(std.out).toMatchInlineSnapshot(`
15861586
"Your Worker has access to the following bindings:
15871587
Binding Resource Mode
1588-
env.WorkerA (A) Worker local [not connected]
1589-
env.WorkerB (B) Worker local [not connected]
1588+
env.WorkerA (A) Worker local [not connected]
1589+
env.WorkerB (B) Worker local [not connected]
15901590
15911591
"
15921592
`);
@@ -1607,8 +1607,8 @@ describe.sequential("wrangler dev", () => {
16071607
expect(std.out).toMatchInlineSnapshot(`
16081608
"Your Worker has access to the following bindings:
16091609
Binding Resource Mode
1610-
env.WorkerA (A) Worker local [not connected]
1611-
env.WorkerB (B) Worker local [not connected]
1610+
env.WorkerA (A) Worker local [not connected]
1611+
env.WorkerB (B) Worker local [not connected]
16121612
16131613
"
16141614
`);
@@ -1756,7 +1756,7 @@ describe.sequential("wrangler dev", () => {
17561756
env.MY_QUEUE_PRODUCES (my-queue) Queue remote
17571757
env.MY_D1 (xxx) D1 Database remote
17581758
env.MY_R2 (my-bucket) R2 Bucket remote
1759-
env.WorkerA (A) Worker remote [connected]
1759+
env.WorkerA (A) Worker remote
17601760
17611761
"
17621762
`);

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ export function printBindings(
349349
}
350350

351351
if (remote) {
352-
mode = getMode({ isSimulatedLocally: false, connected: true });
352+
mode = getMode({ isSimulatedLocally: false });
353353
} else if (context.local && context.registry !== null) {
354354
const registryDefinition = context.registry?.[service];
355355
hasConnectionStatus = true;
@@ -585,15 +585,26 @@ export function printBindings(
585585
title = "Your Worker has access to the following bindings:";
586586
}
587587

588+
const headings = {
589+
binding: "Binding",
590+
resource: "Resource",
591+
mode: "Mode",
592+
} as const;
593+
588594
const maxValueLength = Math.max(
589595
...output.map((b) =>
590596
typeof b.value === "symbol" ? "inherited".length : b.value?.length ?? 0
591597
)
592598
);
593599
const maxNameLength = Math.max(...output.map((b) => b.name.length));
594-
const maxTypeLength = Math.max(...output.map((b) => b.type.length));
600+
const maxTypeLength = Math.max(
601+
...output.map((b) => b.type.length),
602+
headings.resource.length
603+
);
595604
const maxModeLength = Math.max(
596-
...output.map((b) => (b.mode ? stripAnsi(b.mode).length : "Mode".length))
605+
...output.map((b) =>
606+
b.mode ? stripAnsi(b.mode).length : headings.mode.length
607+
)
597608
);
598609

599610
const hasMode = output.some((b) => b.mode);
@@ -622,7 +633,7 @@ export function printBindings(
622633
: " ".repeat(columnGapSpaces);
623634

624635
logger.log(
625-
`${padEndAnsi(dim("Binding"), shouldWrap ? bindingPrefix.length + maxNameLength : bindingLength)}${columnGap}${padEndAnsi(dim("Resource"), maxTypeLength)}${columnGap}${hasMode ? dim("Mode") : ""}`
636+
`${padEndAnsi(dim(headings.binding), shouldWrap ? bindingPrefix.length + maxNameLength : bindingLength)}${columnGap}${padEndAnsi(dim(headings.resource), maxTypeLength)}${columnGap}${hasMode ? dim(headings.mode) : ""}`
626637
);
627638

628639
for (const binding of output) {

0 commit comments

Comments
 (0)