Skip to content

Commit 7a3ce53

Browse files
committed
Suppress some Wrangler output when running wrangler setup from C3
1 parent 94db9bc commit 7a3ce53

File tree

6 files changed

+90
-6
lines changed

6 files changed

+90
-6
lines changed

.changeset/plain-cameras-cheer.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"create-cloudflare": minor
3+
"wrangler": minor
4+
---
5+
6+
Suppress some Wrangler output when running wrangler setup from C3

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__/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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export async function runAutoConfig(
107107
`Running autoconfig with:\n${JSON.stringify(autoConfigDetails, null, 2)}...`
108108
);
109109

110-
if (autoConfigSummary.wranglerInstall) {
110+
if (autoConfigSummary.wranglerInstall && autoConfigOptions.installWrangler) {
111111
await installWrangler();
112112
}
113113

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+
installWrangler?: 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+
installWrangler: 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)