Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/pretty-days-find.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": minor
---

feat: `wrangler init --from-dash` now generates `wrangler.jsonc` config files instead of `wrangler.toml` files
9 changes: 6 additions & 3 deletions packages/create-cloudflare/e2e/tests/cli/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,11 +442,14 @@ describe("Create Cloudflare CLI", () => {
);
expect(output).toContain("Pre-existing Worker (from Dashboard)");
expect(output).toContain("Application created successfully!");
expect(fs.existsSync(join(project.path, "wrangler.jsonc"))).toBe(false);
expect(fs.existsSync(join(project.path, "wrangler.jsonc"))).toBe(true);
expect(fs.existsSync(join(project.path, "wrangler.json"))).toBe(false);
expect(fs.existsSync(join(project.path, "wrangler.toml"))).toBe(false);
expect(
fs.readFileSync(join(project.path, "wrangler.toml"), "utf8"),
).toContain('FOO = "bar"');
JSON.parse(
fs.readFileSync(join(project.path, "wrangler.jsonc"), "utf8"),
),
).toMatchObject({ vars: { FOO: "bar" } });
},
);
});
Expand Down
24 changes: 19 additions & 5 deletions packages/create-cloudflare/templates/pre-existing/c3.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { existsSync } from "fs";
import { cp, mkdtemp } from "fs/promises";
import { tmpdir } from "os";
import { join } from "path";
Expand Down Expand Up @@ -57,11 +58,24 @@ export async function copyExistingWorkerFiles(ctx: C3Context) {
{ recursive: true },
);

// copy ./wrangler.toml from the downloaded Worker
await cp(
join(tempdir, ctx.args.existingScript, "wrangler.toml"),
join(ctx.project.path, "wrangler.toml"),
);
// copy wrangler config file from the downloaded Worker
const configFiles = ["wrangler.jsonc", "wrangler.json", "wrangler.toml"];
let configFileCopied = false;

for (const configFile of configFiles) {
const sourcePath = join(tempdir, ctx.args.existingScript, configFile);
if (existsSync(sourcePath)) {
await cp(sourcePath, join(ctx.project.path, configFile));
configFileCopied = true;
break;
}
}

if (!configFileCopied) {
throw new Error(
`No wrangler configuration file found in downloaded worker. Expected one of: ${configFiles.join(", ")}`,
);
}
}

const config: TemplateConfig = {
Expand Down
Loading
Loading