From bd3c9d04159e457a4fdefa369c91ac925572010a Mon Sep 17 00:00:00 2001 From: Leo Ostera Date: Wed, 14 Oct 2026 15:37:18 +0100 Subject: [PATCH] fix(cli): forward profile to dev server --- .changeset/bright-walls-serve.md | 5 +++ .../src/__tests__/commands/dev/index.test.ts | 34 +++++++++++++++++++ packages/cli/src/commands/dev/index.ts | 13 ++++--- 3 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 .changeset/bright-walls-serve.md diff --git a/.changeset/bright-walls-serve.md b/.changeset/bright-walls-serve.md new file mode 100644 index 0000000000..2c5bb7be9d --- /dev/null +++ b/.changeset/bright-walls-serve.md @@ -0,0 +1,5 @@ +--- +"cf": patch +--- + +Forward an explicitly selected auth profile from `cf dev` to Cloudflare dev-server implementations. diff --git a/packages/cli/src/__tests__/commands/dev/index.test.ts b/packages/cli/src/__tests__/commands/dev/index.test.ts index a3d917cc82..d81eabf971 100644 --- a/packages/cli/src/__tests__/commands/dev/index.test.ts +++ b/packages/cli/src/__tests__/commands/dev/index.test.ts @@ -1,6 +1,7 @@ import { readFileSync } from "node:fs"; import { resolve } from "node:path"; import * as clack from "@clack/prompts"; +import { writeAuthConfigFile } from "@cloudflare/workers-auth/cf"; import { mockConsoleMethods, runInTempDir, @@ -628,6 +629,39 @@ describe("cf dev", () => { expect(result.exitCode).toBe(17); }); + it("forwards an explicitly selected auth profile to the impl", async () => { + for (const profile of ["personal", "work"]) { + writeAuthConfigFile( + { + oauth_token: `${profile}-token`, + expiration_time: "2999-01-01T00:00:00.000Z", + }, + profile + ); + } + await runCf(["auth", "activate", "personal"]); + await seed({ + "package.json": JSON.stringify({ + devDependencies: { "@cloudflare/vite-plugin": "beta" }, + }), + "node_modules/@cloudflare/vite-plugin/package.json": JSON.stringify({ + name: "@cloudflare/vite-plugin", + version: "2.0.0-beta.sha-805ec1ff3", + }), + "node_modules/@cloudflare/vite-plugin/bin/cf-vite": nodeScript( + 'require("node:fs").writeFileSync("argv.out", process.argv.slice(2).join("\\n") + "\\n");' + ), + }); + makeExecutable("node_modules/@cloudflare/vite-plugin/bin/cf-vite"); + + const result = await runCf(["dev", "--profile", "work"]); + + expect(result.exitCode).toBe(0); + expect(readFileSync(resolve(process.cwd(), "argv.out"), "utf8")).toBe( + "dev\n--profile\nwork\n" + ); + }); + it("forwards unknown flags to the impl", async () => { // The delegate inherits stdout, so write argv to a file for inspection. await seed({ diff --git a/packages/cli/src/commands/dev/index.ts b/packages/cli/src/commands/dev/index.ts index 2cb855f0a8..6fd9e381e5 100644 --- a/packages/cli/src/commands/dev/index.ts +++ b/packages/cli/src/commands/dev/index.ts @@ -51,7 +51,7 @@ const devCommand: CommandModule = { `cf dev starts the appropriate development server for your project. ` + `It runs your framework's dev command when available, falling back to an installed Cloudflare dev server.\n\n` + `Only ${theme.brand("--mode")} is forwarded to supported framework development servers. ` + - `Other arguments are forwarded only to Cloudflare dev-server implementations.` + `${theme.brand("--profile")} and other arguments are forwarded only to Cloudflare dev-server implementations.` ) as Argv ); }, @@ -68,6 +68,8 @@ const devCommand: CommandModule = { // to be strings. const implArgs = (argv.implArgs ?? []).map(String); const modeArgs = argv.mode ? ["--mode", argv.mode] : []; + const profileArgs = + argv.profile !== undefined ? ["--profile", argv.profile] : []; if (details?.devCommand) { if (implArgs.length > 0) { throw new Error( @@ -91,9 +93,12 @@ const devCommand: CommandModule = { // Spawn and propagate the impl's exit code and termination signal. // CliExit flows up to main() which lets bin/cf map to process.exit(code). - const result = await spawnImpl(picked, "dev", [...modeArgs, ...implArgs], { - output: "inherit", - }); + const result = await spawnImpl( + picked, + "dev", + [...profileArgs, ...modeArgs, ...implArgs], + { output: "inherit" } + ); throw new CliExit(result.exitCode, { signal: result.signal }); }, };