Skip to content

Commit 8fb4e05

Browse files
emily-shenpenalosa
andcommitted
fix: fix banner regressions in 3.93.0 (#7493)
* telemetry banner fix * pass configpath into readRawConfig * changeset * Don't print banner when --json is provided to versions list and versions view * fix lint 🤦 * Add tests asserting that versions view and versions list hide the Wrangler banner when --json is passed * add telemetry test --------- Co-authored-by: Samuel Macleod <[email protected]>
1 parent 3b48231 commit 8fb4e05

File tree

21 files changed

+141
-60
lines changed

21 files changed

+141
-60
lines changed

.changeset/old-garlics-judge.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
fix: remove non-json output in json mode commands
6+
7+
Fixes regressions in 3.93.0 where unwanted text (wrangler banner, telemetry notice) was printing in commands that should only output valid json.

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,32 @@ describe("metrics", () => {
426426
const { permission } = readMetricsConfig();
427427
expect(permission?.bannerLastShown).toBeUndefined();
428428
});
429+
430+
it("should *not* print the banner if command is not dev/deploy/docs", async () => {
431+
writeMetricsConfig({
432+
permission: {
433+
enabled: true,
434+
date: new Date(2022, 6, 4),
435+
bannerLastShown: "1.2.1",
436+
},
437+
});
438+
const requests = mockMetricRequest();
439+
440+
await runWrangler("telemetry status");
441+
expect(std.out).toMatchInlineSnapshot(`
442+
"Status: Enabled
443+
444+
To configure telemetry globally on this machine, you can run \`wrangler telemetry disable / enable\`.
445+
You can override this for individual projects with the environment variable \`WRANGLER_SEND_METRICS=true/false\`.
446+
Learn more at https://github.com/cloudflare/workers-sdk/tree/main/telemetry.md
447+
"
448+
`);
449+
expect(std.out).not.toContain(
450+
"Cloudflare collects anonymous telemetry about your usage of Wrangler. Learn more at https://github.com/cloudflare/workers-sdk/tree/main/packages/wrangler/telemetry.md"
451+
);
452+
453+
expect(requests.count).toBe(2);
454+
});
429455
});
430456
});
431457

packages/wrangler/src/__tests__/versions/versions.list.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@ import { runInTempDir } from "../helpers/run-in-tmp";
77
import { runWrangler } from "../helpers/run-wrangler";
88
import { writeWranglerConfig } from "../helpers/write-wrangler-config";
99

10+
vi.unmock("../../wrangler-banner");
11+
1012
describe("versions list", () => {
1113
mockAccountId();
1214
mockApiToken();
1315
runInTempDir();
1416
mockConsoleMethods();
17+
const cnsl = mockConsoleMethods();
18+
1519
const std = collectCLIOutput();
1620

1721
beforeEach(() => {
@@ -72,6 +76,13 @@ describe("versions list", () => {
7276
"
7377
`);
7478

79+
expect(cnsl.out).toMatchInlineSnapshot(`
80+
"
81+
⛅️ wrangler 3.93.0
82+
-------------------
83+
"
84+
`);
85+
7586
expect(std.err).toMatchInlineSnapshot(`""`);
7687
});
7788

@@ -148,6 +159,8 @@ describe("versions list", () => {
148159
"
149160
`);
150161

162+
expect(cnsl.out).toMatchInlineSnapshot(`""`);
163+
151164
expect(std.err).toMatchInlineSnapshot(`""`);
152165
});
153166
});

packages/wrangler/src/__tests__/versions/versions.view.test.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,21 @@ import { runInTempDir } from "../helpers/run-in-tmp";
77
import { runWrangler } from "../helpers/run-wrangler";
88
import { writeWranglerConfig } from "../helpers/write-wrangler-config";
99

10+
vi.unmock("../../wrangler-banner");
11+
1012
describe("versions view", () => {
1113
mockAccountId();
1214
mockApiToken();
1315
runInTempDir();
14-
mockConsoleMethods();
16+
const cnsl = mockConsoleMethods();
1517
const std = collectCLIOutput();
1618

1719
describe("without wrangler.toml", () => {
1820
beforeEach(() => msw.use(mswGetVersion()));
1921

2022
test("fails with no args", async () => {
2123
const result = runWrangler(
22-
"versions view --experimental-gradual-rollouts"
24+
"versions view --experimental-gradual-rollouts"
2325
);
2426

2527
await expect(result).rejects.toMatchInlineSnapshot(
@@ -89,6 +91,13 @@ describe("versions view", () => {
8991
"
9092
`);
9193

94+
expect(cnsl.out).toMatchInlineSnapshot(`
95+
"
96+
⛅️ wrangler 3.93.0
97+
-------------------
98+
"
99+
`);
100+
92101
expect(normalizeOutput(std.err)).toMatchInlineSnapshot(`""`);
93102
});
94103

@@ -99,6 +108,8 @@ describe("versions view", () => {
99108

100109
await expect(result).resolves.toBeUndefined();
101110

111+
expect(cnsl.out).toMatchInlineSnapshot(`""`);
112+
102113
expect(std.out).toMatchInlineSnapshot(`
103114
"{
104115
\\"id\\": \\"10000000-0000-0000-0000-000000000000\\",

packages/wrangler/src/__tests__/vitest.setup.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ vi.mock("undici", async (importOriginal) => {
8383
vi.mock("../package-manager");
8484

8585
vi.mock("../update-check");
86+
vi.mock("../wrangler-banner");
8687

8788
beforeAll(() => {
8889
msw.listen({

packages/wrangler/src/__tests__/worker-namespace.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { http, HttpResponse } from "msw";
2-
import { printWranglerBanner } from "../update-check";
2+
import { printWranglerBanner } from "../wrangler-banner";
33
import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
44
import { mockConsoleMethods } from "./helpers/mock-console";
55
import {

packages/wrangler/src/core/register-yargs-command.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { readConfig } from "../config";
33
import { defaultWranglerConfig } from "../config/config";
44
import { FatalError, UserError } from "../errors";
55
import { logger } from "../logger";
6-
import { printWranglerBanner } from "../update-check";
6+
import { printWranglerBanner } from "../wrangler-banner";
77
import { demandSingleValue } from "./helpers";
88
import type { CommonYargsArgv, SubHelp } from "../yargs-types";
99
import type {
@@ -64,7 +64,18 @@ function createHandler(def: CommandDefinition) {
6464
return async function handler(args: HandlerArgs<NamedArgDefinitions>) {
6565
// eslint-disable-next-line no-useless-catch
6666
try {
67-
if (def.behaviour?.printBanner !== false) {
67+
const shouldPrintBanner = def.behaviour?.printBanner;
68+
69+
if (
70+
/* No defautl behaviour override: show the banner */
71+
shouldPrintBanner === undefined ||
72+
/* Explicit opt in: show the banner */
73+
(typeof shouldPrintBanner === "boolean" &&
74+
shouldPrintBanner !== false) ||
75+
/* Hook resolves to true */
76+
(typeof shouldPrintBanner === "function" &&
77+
shouldPrintBanner(args) === true)
78+
) {
6879
await printWranglerBanner();
6980
}
7081

packages/wrangler/src/core/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export type CommandDefinition<
9393
*
9494
* @default true
9595
*/
96-
printBanner?: boolean;
96+
printBanner?: boolean | ((args: HandlerArgs<NamedArgDefs>) => boolean);
9797

9898
/**
9999
* By default, wrangler will print warnings about the Wrangler configuration file.

packages/wrangler/src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ import {
148148
import { tailHandler, tailOptions } from "./tail";
149149
import registerTriggersSubcommands from "./triggers";
150150
import { typesHandler, typesOptions } from "./type-generation";
151-
import { printWranglerBanner, updateCheck } from "./update-check";
151+
import { updateCheck } from "./update-check";
152152
import { getAuthFromEnv } from "./user";
153153
import { loginCommand, logoutCommand, whoamiCommand } from "./user/commands";
154154
import { whoami } from "./user/whoami";
@@ -176,6 +176,7 @@ import { workflowsInstancesResumeCommand } from "./workflows/commands/instances/
176176
import { workflowsInstancesTerminateCommand } from "./workflows/commands/instances/terminate";
177177
import { workflowsListCommand } from "./workflows/commands/list";
178178
import { workflowsTriggerCommand } from "./workflows/commands/trigger";
179+
import { printWranglerBanner } from "./wrangler-banner";
179180
import { asJson } from "./yargs-types";
180181
import type { Config } from "./config";
181182
import type { LoggerLevel } from "./logger";
@@ -1110,7 +1111,7 @@ export async function main(argv: string[]): Promise<void> {
11101111

11111112
try {
11121113
const configPath = resolveWranglerConfigPath(args);
1113-
const rawConfig = readRawConfig(args.config);
1114+
const rawConfig = readRawConfig(configPath);
11141115
dispatcher = getMetricsDispatcher({
11151116
sendMetrics: rawConfig.send_metrics,
11161117
configPath,

packages/wrangler/src/metrics/metrics-dispatcher.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,15 @@ export function getMetricsDispatcher(options: MetricsConfigOptions) {
8282
) {
8383
return;
8484
}
85-
printMetricsBanner();
85+
if (
86+
properties.command === "wrangler deploy" ||
87+
properties.command === "wrangler dev" ||
88+
// for testing purposes
89+
properties.command === "wrangler docs"
90+
) {
91+
printMetricsBanner();
92+
}
93+
8694
const argsUsed = sanitiseUserInput(properties.args ?? {});
8795
const argsCombination = argsUsed.sort().join(", ");
8896
const commonEventProperties: CommonEventProperties = {

0 commit comments

Comments
 (0)