Skip to content

Commit 7035804

Browse files
authored
Use autoconfig in c3 (#11251)
* Support the WRANGLER_HIDE_BANNER environment variable across Wrangler & C3 * Reduce C3 framework test timeout. Previously it was 25 mins, now it should be 3 mins * Remove dev server from C3 command. To make this consistent across frameworks we were injecting extra dev commands into package.json files, which meant that generated C3 projects often had both a `start` and a `develop` script. * Reduce logging in package-manager detection * Expand autoconfig & use it in C3 for gatsby * Expand framework configuration and support dry-running * Address comments * Address comments * longer timeout 😢
1 parent c5c4ee5 commit 7035804

File tree

28 files changed

+338
-269
lines changed

28 files changed

+338
-269
lines changed

.changeset/eager-pans-hang.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
"wrangler": minor
3+
---
4+
5+
When the `WRANGLER_HIDE_BANNER` environment variable is provided, Wrangler will no longer display a version banner. This applies to all commands.
6+
7+
For instance, previously running `wrangler docs` would give the following output:
8+
9+
```
10+
> wrangler docs
11+
⛅️ wrangler 4.47.0
12+
───────────────────
13+
Opening a link in your default browser: https://developers.cloudflare.com/workers/wrangler/commands/
14+
```
15+
16+
With `WRANGLER_HIDE_BANNER`, this is now:
17+
18+
```
19+
> WRANGLER_HIDE_BANNER=true wrangler docs
20+
Opening a link in your default browser: https://developers.cloudflare.com/workers/wrangler/commands/
21+
```

.changeset/ninety-monkeys-turn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"create-cloudflare": minor
3+
---
4+
5+
When the `--experimental` flag is passed to `create-cloudflare`, use `wrangler setup` for configuring a project to work on Cloudflare rather than the existing `create-cloudflare` logic. Only Gatsby is supported right now, with more frameworks to be added in future. There should be no functional change to applications created via `create-cloudflare` when using the `--experimental` flag.

packages/create-cloudflare/e2e/helpers/framework-helpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,9 @@ export async function verifyPreviewScript(
283283

284284
try {
285285
// Some frameworks take quite a long time to build the application (e.g. Docusaurus)
286-
// so wait up to 5 mins for the dev-server to be ready.
286+
// so wait some time for the dev-server to be ready.
287287
await retry(
288-
{ times: 300, sleepMs: 5000 },
288+
{ times: 60, sleepMs: 5000 },
289289
async () => await fetch(`http://localhost:${port}${verifyPreview.route}`),
290290
);
291291

packages/create-cloudflare/e2e/tests/cli/cli.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ describe("Create Cloudflare CLI", () => {
464464
);
465465
expect(normalizeOutput(output)).toMatchInlineSnapshot(`
466466
"create-cloudflare <version>
467-
The create-cloudflare cli (also known as C3) is a command-line tool designed to help you set up and deploy new applications to Cloudflare. In addition to speed, it leverages officially developed templates for Workers and framework-specific setup guides to ensure each new application that you set up follows Cloudflare and any third-party best practices for deployment on the Cloudflare network.
467+
The create-cloudflare CLI (also known as C3) is a command-line tool designed to help you set up and deploy new applications to Cloudflare. In addition to speed, it leverages officially developed templates for Workers and framework-specific setup guides to ensure each new application that you set up follows Cloudflare and any third-party best practices for deployment on the Cloudflare network.
468468
USAGE
469469
<USAGE>
470470
OPTIONS
@@ -486,6 +486,8 @@ describe("Create Cloudflare CLI", () => {
486486
You may specify additional arguments to be passed directly to these underlying tools by adding them after a "--" argument, like so:
487487
npm create cloudflare -- --framework next -- --ts
488488
pnpm create cloudflare --framework next -- --ts
489+
Allowed Values:
490+
gatsby
489491
--platform=<value>
490492
Whether the application should be deployed to Pages or Workers. This is only applicable for Frameworks templates that support both Pages and Workers.
491493
Allowed Values:
@@ -536,7 +538,7 @@ describe("Create Cloudflare CLI", () => {
536538
const { output } = await runC3(["--help"], [], logStream);
537539
expect(normalizeOutput(output)).toMatchInlineSnapshot(`
538540
"create-cloudflare <version>
539-
The create-cloudflare cli (also known as C3) is a command-line tool designed to help you set up and deploy new applications to Cloudflare. In addition to speed, it leverages officially developed templates for Workers and framework-specific setup guides to ensure each new application that you set up follows Cloudflare and any third-party best practices for deployment on the Cloudflare network.
541+
The create-cloudflare CLI (also known as C3) is a command-line tool designed to help you set up and deploy new applications to Cloudflare. In addition to speed, it leverages officially developed templates for Workers and framework-specific setup guides to ensure each new application that you set up follows Cloudflare and any third-party best practices for deployment on the Cloudflare network.
540542
USAGE
541543
<USAGE>
542544
OPTIONS

packages/create-cloudflare/e2e/tests/frameworks/test-config.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,29 @@ function getFrameworkTestConfig(pm: string): NamedFrameworkTestConfig[] {
610610
*/
611611
function getExperimentalFrameworkTestConfig() {
612612
return [
613-
// None right now
613+
{
614+
name: "gatsby:workers",
615+
argv: ["--platform", "workers"],
616+
unsupportedPms: ["bun", "pnpm", "yarn"],
617+
promptHandlers: [
618+
{
619+
matcher: /Would you like to use a template\?/,
620+
input: ["n"],
621+
},
622+
],
623+
testCommitMessage: true,
624+
timeout: LONG_TIMEOUT,
625+
verifyDeploy: {
626+
route: "/",
627+
expectedText: "Gatsby!",
628+
},
629+
verifyPreview: {
630+
previewArgs: ["--inspector-port=0"],
631+
route: "/",
632+
expectedText: "Gatsby!",
633+
},
634+
nodeCompat: false,
635+
},
614636
];
615637
}
616638

packages/create-cloudflare/src/__tests__/dialog.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ describe("dialog helpers", () => {
125125
Dash: https://dash.cloudflare.com/?to=/:account/workers/services/view/test-project
126126
127127
💻 Continue Developing
128-
Start dev server: pnpm run start
129128
Deploy again: pnpm run deploy
130129
131130
📖 Explore Documentation
@@ -160,7 +159,6 @@ describe("dialog helpers", () => {
160159
161160
💻 Continue Developing
162161
Change directories: cd ../example
163-
Start dev server: pnpm run start
164162
Deploy: pnpm run deploy
165163
166164
📖 Explore Documentation

packages/create-cloudflare/src/cli.ts

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ const create = async (ctx: C3Context) => {
144144
await template.generate(ctx);
145145
}
146146

147-
await copyTemplateFiles(ctx);
147+
if (!ctx.args.experimental) {
148+
await copyTemplateFiles(ctx);
149+
}
148150
await updatePackageName(ctx);
149151

150152
chdir(ctx.project.path);
@@ -155,25 +157,37 @@ const create = async (ctx: C3Context) => {
155157
};
156158

157159
const configure = async (ctx: C3Context) => {
158-
startSection("Configuring your application for Cloudflare", "Step 2 of 3");
160+
startSection(
161+
"Configuring your application for Cloudflare via `wrangler setup`",
162+
"Step 2 of 3",
163+
);
159164

165+
// This is kept even in the autoconfig case because autoconfig will ultimately end up installing Wrangler anyway
166+
// If we _didn't_ install Wrangler when using autoconfig we'd end up with a double install (one from `npx` and one from autoconfig)
160167
await installWrangler();
161168

162-
// Note: This _must_ be called before the configure phase since
163-
// pre-existing workers assume its presence in their configure phase
164-
await updateWranglerConfig(ctx);
169+
if (ctx.args.experimental) {
170+
const { npx } = detectPackageManager();
165171

166-
const { template } = ctx;
167-
if (template.configure) {
168-
await template.configure({ ...ctx });
169-
}
172+
await runCommand([npx, "wrangler", "setup", "--yes"]);
173+
} else {
174+
// Note: This _must_ be called before the configure phase since
175+
// pre-existing workers assume its presence in their configure phase
176+
await updateWranglerConfig(ctx);
170177

171-
addWranglerToGitIgnore(ctx);
178+
const { template } = ctx;
179+
if (template.configure) {
180+
await template.configure({ ...ctx });
181+
}
182+
183+
addWranglerToGitIgnore(ctx);
172184

173-
await updatePackageScripts(ctx);
185+
await updatePackageScripts(ctx);
174186

175-
await addTypes(ctx);
187+
await addTypes(ctx);
188+
}
176189

190+
// Autoconfig doesn't mess with version control, so C3 runs this after autoconfig
177191
await offerGit(ctx);
178192
await gitCommit(ctx);
179193

packages/create-cloudflare/src/dialog.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,7 @@ export const printSummary = (ctx: C3Context) => {
6565
const relativePath = relative(ctx.originalCWD, ctx.project.path);
6666
const cdCommand = relativePath ? `cd ${relativePath}` : null;
6767
const { npm } = detectPackageManager();
68-
const devServerCommand = quoteShellArgs([
69-
npm,
70-
"run",
71-
ctx.template.devScript ?? "start",
72-
]);
68+
7369
const deployCommand = quoteShellArgs([
7470
npm,
7571
"run",
@@ -98,7 +94,6 @@ export const printSummary = (ctx: C3Context) => {
9894
lines.push(
9995
`💻 Continue Developing`,
10096
...(cdCommand ? [`${gray("Change directories:")} ${blue(cdCommand)}`] : []),
101-
`${gray("Start dev server:")} ${blue(devServerCommand)}`,
10297
`${gray(ctx.deployment.url ? `Deploy again:` : "Deploy:")} ${blue(deployCommand)}`,
10398
``,
10499
`📖 Explore Documentation`,

packages/create-cloudflare/src/helpers/args.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export type ArgumentsDefinition = {
4444

4545
export const cliDefinition: ArgumentsDefinition = {
4646
intro: `
47-
The create-cloudflare cli (also known as C3) is a command-line tool designed to help you set up and deploy new applications to Cloudflare. In addition to speed, it leverages officially developed templates for Workers and framework-specific setup guides to ensure each new application that you set up follows Cloudflare and any third-party best practices for deployment on the Cloudflare network.
47+
The create-cloudflare CLI (also known as C3) is a command-line tool designed to help you set up and deploy new applications to Cloudflare. In addition to speed, it leverages officially developed templates for Workers and framework-specific setup guides to ensure each new application that you set up follows Cloudflare and any third-party best practices for deployment on the Cloudflare network.
4848
`,
4949
positionals: [
5050
{

packages/create-cloudflare/src/helpers/command.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,12 @@ export const runCommand = async (
5656
// Don't send metrics data on any wrangler commands if telemetry is disabled in C3
5757
// If telemetry is disabled separately for wrangler, wrangler will handle that
5858
if (args[0] === "wrangler") {
59+
opts.env ??= {};
5960
const metrics = readMetricsConfig();
6061
if (metrics.c3permission?.enabled === false) {
61-
opts.env ??= {};
6262
opts.env["WRANGLER_SEND_METRICS"] = "false";
6363
}
64+
opts.env["WRANGLER_HIDE_BANNER"] = "true";
6465
}
6566
const abortController = new AbortController();
6667
const cmd = spawn(executable, [...args], {

0 commit comments

Comments
 (0)