Skip to content

Commit 940b44d

Browse files
[wrangler] feat: generate wrangler.jsonc in init --from-dash instead of wrangler.toml (#10911)
* feat: generate wrangler.jsonc in init --from-dash instead of wrangler.toml - Remove TOML import from init.ts (no longer needed) - Change init.ts to write wrangler.jsonc using JSON.stringify - Update all tests to expect wrangler.jsonc instead of wrangler.toml - Convert test snapshots from TOML to JSON format - Add changeset for minor version bump Fixes #8270 Co-Authored-By: smacleod@cloudflare.com <smacleod@cloudflare.com> * revert: remove unnecessary changes to unrelated test files Address PR feedback from @penalosa to revert changes to test files that don't test the init --from-dash functionality: - get-entry.test.ts - index.test.ts - deployments.status.test.ts These files now reference wrangler.toml again since they test functionality unrelated to the init command's config generation. Co-Authored-By: smacleod@cloudflare.com <smacleod@cloudflare.com> * fix: update C3 test to expect wrangler.jsonc from init --from-dash Update the --existing-script test expectations to check for wrangler.jsonc with JSON content instead of wrangler.toml with TOML content, since wrangler init --from-dash now generates JSON config files. Co-Authored-By: smacleod@cloudflare.com <smacleod@cloudflare.com> * fix: update C3 pre-existing template to copy wrangler.jsonc The --existing-script flow runs wrangler init --from-dash which now generates wrangler.jsonc instead of wrangler.toml. Update the file copy logic to check for and copy wrangler.jsonc, wrangler.json, or wrangler.toml (in that preference order) to support both new and legacy workers. Co-Authored-By: smacleod@cloudflare.com <smacleod@cloudflare.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: smacleod@cloudflare.com <smacleod@cloudflare.com>
1 parent a5f7904 commit 940b44d

File tree

5 files changed

+245
-167
lines changed

5 files changed

+245
-167
lines changed

.changeset/pretty-days-find.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": minor
3+
---
4+
5+
feat: `wrangler init --from-dash` now generates `wrangler.jsonc` config files instead of `wrangler.toml` files

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -442,11 +442,14 @@ describe("Create Cloudflare CLI", () => {
442442
);
443443
expect(output).toContain("Pre-existing Worker (from Dashboard)");
444444
expect(output).toContain("Application created successfully!");
445-
expect(fs.existsSync(join(project.path, "wrangler.jsonc"))).toBe(false);
445+
expect(fs.existsSync(join(project.path, "wrangler.jsonc"))).toBe(true);
446446
expect(fs.existsSync(join(project.path, "wrangler.json"))).toBe(false);
447+
expect(fs.existsSync(join(project.path, "wrangler.toml"))).toBe(false);
447448
expect(
448-
fs.readFileSync(join(project.path, "wrangler.toml"), "utf8"),
449-
).toContain('FOO = "bar"');
449+
JSON.parse(
450+
fs.readFileSync(join(project.path, "wrangler.jsonc"), "utf8"),
451+
),
452+
).toMatchObject({ vars: { FOO: "bar" } });
450453
},
451454
);
452455
});

packages/create-cloudflare/templates/pre-existing/c3.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { existsSync } from "fs";
12
import { cp, mkdtemp } from "fs/promises";
23
import { tmpdir } from "os";
34
import { join } from "path";
@@ -57,11 +58,24 @@ export async function copyExistingWorkerFiles(ctx: C3Context) {
5758
{ recursive: true },
5859
);
5960

60-
// copy ./wrangler.toml from the downloaded Worker
61-
await cp(
62-
join(tempdir, ctx.args.existingScript, "wrangler.toml"),
63-
join(ctx.project.path, "wrangler.toml"),
64-
);
61+
// copy wrangler config file from the downloaded Worker
62+
const configFiles = ["wrangler.jsonc", "wrangler.json", "wrangler.toml"];
63+
let configFileCopied = false;
64+
65+
for (const configFile of configFiles) {
66+
const sourcePath = join(tempdir, ctx.args.existingScript, configFile);
67+
if (existsSync(sourcePath)) {
68+
await cp(sourcePath, join(ctx.project.path, configFile));
69+
configFileCopied = true;
70+
break;
71+
}
72+
}
73+
74+
if (!configFileCopied) {
75+
throw new Error(
76+
`No wrangler configuration file found in downloaded worker. Expected one of: ${configFiles.join(", ")}`,
77+
);
78+
}
6579
}
6680

6781
const config: TemplateConfig = {

0 commit comments

Comments
 (0)