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/bright-walls-serve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"cf": patch
---

Forward an explicitly selected auth profile from `cf dev` to Cloudflare dev-server implementations.
34 changes: 34 additions & 0 deletions packages/cli/src/__tests__/commands/dev/index.test.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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({
Expand Down
13 changes: 9 additions & 4 deletions packages/cli/src/commands/dev/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const devCommand: CommandModule<CommonYargsOptions, DevArgs> = {
`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<DevArgs>
);
},
Expand All @@ -68,6 +68,8 @@ const devCommand: CommandModule<CommonYargsOptions, DevArgs> = {
// 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(
Expand All @@ -91,9 +93,12 @@ const devCommand: CommandModule<CommonYargsOptions, DevArgs> = {

// 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 });
},
};
Expand Down
Loading