Skip to content

Commit b0dbf1a

Browse files
Suppress some Wrangler output when running wrangler setup from C3 (#11524)
* Suppress some Wrangler output when running wrangler setup from C3 * Fix tests * fix shapshots * Add hidden flags to suppress output in wrangler setup Two new hidden flags have been added to `wrangler setup` to suppress output and skip installation. --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent b827893 commit b0dbf1a

File tree

8 files changed

+125
-29
lines changed

8 files changed

+125
-29
lines changed

.changeset/plain-cameras-cheer.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
"create-cloudflare": minor
3+
"wrangler": minor
4+
---
5+
6+
Add hidden CLI flags to `wrangler setup` for suppressing output
7+
8+
Two new hidden flags have been added to `wrangler setup`:
9+
10+
- `--no-completion-message`: Suppresses the deployment details message after setup completes
11+
- `--no-install-wrangler`: Skips Wrangler installation during project setup
12+
13+
These flags allow `create-cloudflare` to call `wrangler setup` without redundant output.

packages/create-cloudflare/src/cli.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,14 @@ const configure = async (ctx: C3Context) => {
169169
if (ctx.args.experimental) {
170170
const { npx } = detectPackageManager();
171171

172-
await runCommand([npx, "wrangler", "setup", "--yes"]);
172+
await runCommand([
173+
npx,
174+
"wrangler",
175+
"setup",
176+
"--yes",
177+
"--no-completion-message",
178+
"--no-install-wrangler",
179+
]);
173180
} else {
174181
// Note: This _must_ be called before the configure phase since
175182
// pre-existing workers assume its presence in their configure phase

packages/wrangler/src/__tests__/autoconfig/details/confirm-auto-config-details.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ describe("autoconfig details - confirmAutoConfigDetails()", () => {
3131
});
3232

3333
expect(updatedAutoConfigDetails).toMatchInlineSnapshot(`
34-
Object {
35-
"buildCommand": "npm run build",
36-
"configured": false,
37-
"projectPath": "<PROJECT_PATH>",
38-
"workerName": "worker-name",
39-
}
40-
`);
34+
Object {
35+
"buildCommand": "npm run build",
36+
"configured": false,
37+
"projectPath": "<PROJECT_PATH>",
38+
"workerName": "worker-name",
39+
}
40+
`);
4141
});
4242

4343
test("settings can be updated in a plain static site without a framework nor a build script", async () => {

packages/wrangler/src/__tests__/autoconfig/run.test.ts

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -154,24 +154,27 @@ describe("autoconfig (deploy)", () => {
154154
assets: { directory: outputDir },
155155
},
156156
}));
157-
await run.runAutoConfig({
158-
projectPath: process.cwd(),
159-
buildCommand: "echo 'built' > build.txt",
160-
configured: false,
161-
workerName: "my-worker",
162-
framework: {
163-
name: "Fake",
164-
configure: configureSpy,
165-
isConfigured: () => false,
166-
autoConfigSupported: true,
167-
} as Framework,
168-
outputDir: "dist",
169-
packageJson: {
170-
dependencies: {
171-
astro: "5",
157+
await run.runAutoConfig(
158+
{
159+
projectPath: process.cwd(),
160+
buildCommand: "echo 'built' > build.txt",
161+
configured: false,
162+
workerName: "my-worker",
163+
framework: {
164+
name: "Fake",
165+
configure: configureSpy,
166+
isConfigured: () => false,
167+
autoConfigSupported: true,
168+
} as Framework,
169+
outputDir: "dist",
170+
packageJson: {
171+
dependencies: {
172+
astro: "5",
173+
},
172174
},
173175
},
174-
});
176+
{ enableWranglerInstallation: true }
177+
);
175178

176179
expect(std.out).toMatchInlineSnapshot(`
177180
"

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

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,13 @@ describe("wrangler setup", () => {
6161
test("should run autoconfig when project is not configured", async () => {
6262
await seed({
6363
"public/index.html": `<h1>Hello World</h1>`,
64+
"package.json": JSON.stringify({}),
6465
});
6566

6667
// Let's not actually install Wrangler, to speed up tests
67-
vi.spyOn(c3, "installWrangler").mockImplementation(async () => {});
68+
const installSpy = vi
69+
.spyOn(c3, "installWrangler")
70+
.mockImplementation(async () => {});
6871

6972
const runSpy = vi.spyOn(run, "runAutoConfig");
7073

@@ -73,11 +76,51 @@ describe("wrangler setup", () => {
7376
// autoconfig should have been run
7477
expect(runSpy).toHaveBeenCalled();
7578

79+
expect(installSpy).toHaveBeenCalled();
80+
7681
expect(std.out).toContain(
7782
"🎉 Your project is now setup to deploy to Cloudflare"
7883
);
7984
});
8085

86+
test("should not display completion message when disabled", async () => {
87+
await seed({
88+
"public/index.html": `<h1>Hello World</h1>`,
89+
});
90+
91+
// Let's not actually install Wrangler, to speed up tests
92+
vi.spyOn(c3, "installWrangler").mockImplementation(async () => {});
93+
94+
const runSpy = vi.spyOn(run, "runAutoConfig");
95+
96+
await runWrangler("setup --no-completion-message");
97+
98+
// autoconfig should have been run
99+
expect(runSpy).toHaveBeenCalled();
100+
101+
expect(std.out).not.toContain("🎉 Your project");
102+
});
103+
104+
test("should not install Wrangler when skipped", async () => {
105+
await seed({
106+
"public/index.html": `<h1>Hello World</h1>`,
107+
"package.json": JSON.stringify({}),
108+
});
109+
110+
const installSpy = vi
111+
.spyOn(c3, "installWrangler")
112+
.mockImplementation(async () => {});
113+
114+
const runSpy = vi.spyOn(run, "runAutoConfig");
115+
116+
await runWrangler("setup --no-install-wrangler");
117+
118+
// autoconfig should have been run
119+
expect(runSpy).toHaveBeenCalled();
120+
121+
expect(installSpy).not.toHaveBeenCalled();
122+
});
123+
81124
describe("--dry-run", () => {
82125
test("should stop before running autoconfig when project is already configured", async () => {
83126
await seed({

packages/wrangler/src/autoconfig/run.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ export async function runAutoConfig(
3535
const runBuild = !dryRun && (autoConfigOptions.runBuild ?? true);
3636
const skipConfirmations =
3737
dryRun || autoConfigOptions.skipConfirmations === true;
38+
const enableWranglerInstallation =
39+
autoConfigOptions.enableWranglerInstallation ?? true;
3840

3941
const detected: AutoConfigMetrics = {
4042
buildCommand: autoConfigDetails.buildCommand,
@@ -120,7 +122,7 @@ export async function runAutoConfig(
120122
`Running autoconfig with:\n${JSON.stringify(autoConfigDetails, null, 2)}...`
121123
);
122124

123-
if (autoConfigSummary.wranglerInstall) {
125+
if (autoConfigSummary.wranglerInstall && enableWranglerInstallation) {
124126
await installWrangler();
125127
}
126128

packages/wrangler/src/autoconfig/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ export type AutoConfigOptions = {
3333
* Note: When `dryRun` is `true` the the confirmation prompts are always skipped.
3434
*/
3535
skipConfirmations?: boolean;
36+
/**
37+
* Whether to install Wrangler during autoconfig
38+
*/
39+
enableWranglerInstallation?: boolean;
3640
};
3741

3842
export type AutoConfigSummary = {

packages/wrangler/src/setup.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,53 @@ export const setupCommand = createCommand({
2828
"Runs the command without applying any filesystem modifications",
2929
type: "boolean",
3030
},
31+
"completion-message": {
32+
describe:
33+
"Display a message with deployment details after `wrangler setup` is complete",
34+
type: "boolean",
35+
default: true,
36+
hidden: true,
37+
},
38+
"install-wrangler": {
39+
describe: "Install Wrangler during project setup",
40+
type: "boolean",
41+
default: true,
42+
hidden: true,
43+
},
3144
},
3245

3346
async handler(args, { config }) {
3447
const details = await getDetailsForAutoConfig({
3548
wranglerConfig: config,
3649
});
3750

51+
function logCompletionMessage(message: string) {
52+
if (args.completionMessage) {
53+
logger.log(message);
54+
}
55+
}
56+
3857
// Only run auto config if the project is not already configured
3958
if (!details.configured) {
4059
await runAutoConfig(details, {
4160
runBuild: args.build,
4261
skipConfirmations: args.yes,
4362
dryRun: args.dryRun,
63+
enableWranglerInstallation: args.installWrangler,
4464
});
4565
if (!args.dryRun) {
46-
logger.log("🎉 Your project is now setup to deploy to Cloudflare");
66+
logCompletionMessage(
67+
"🎉 Your project is now setup to deploy to Cloudflare"
68+
);
4769
}
4870
} else {
49-
logger.log("🎉 Your project is already setup to deploy to Cloudflare");
71+
logCompletionMessage(
72+
"🎉 Your project is already setup to deploy to Cloudflare"
73+
);
5074
}
5175
if (!args.dryRun) {
5276
const { type } = await getPackageManager();
53-
logger.log(
77+
logCompletionMessage(
5478
`You can now deploy with ${brandColor(details.packageJson ? `${type} run deploy` : "wrangler deploy")}`
5579
);
5680
}

0 commit comments

Comments
 (0)