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
6 changes: 6 additions & 0 deletions .changeset/plain-cameras-cheer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"create-cloudflare": minor
"wrangler": minor
---

Suppress some Wrangler output when running wrangler setup from C3
9 changes: 8 additions & 1 deletion packages/create-cloudflare/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,14 @@ const configure = async (ctx: C3Context) => {
if (ctx.args.experimental) {
const { npx } = detectPackageManager();

await runCommand([npx, "wrangler", "setup", "--yes"]);
await runCommand([
npx,
"wrangler",
"setup",
"--yes",
"--no-completion-message",
"--no-install-wrangler",
]);
} else {
// Note: This _must_ be called before the configure phase since
// pre-existing workers assume its presence in their configure phase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ describe("autoconfig details - confirmAutoConfigDetails()", () => {
});

expect(updatedAutoConfigDetails).toMatchInlineSnapshot(`
Object {
"buildCommand": "npm run build",
"configured": false,
"projectPath": "<PROJECT_PATH>",
"workerName": "worker-name",
}
`);
Object {
"buildCommand": "npm run build",
"configured": false,
"projectPath": "<PROJECT_PATH>",
"workerName": "worker-name",
}
`);
});

test("settings can be updated in a plain static site without a framework nor a build script", async () => {
Expand Down
31 changes: 17 additions & 14 deletions packages/wrangler/src/__tests__/autoconfig/run.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,22 +154,25 @@ describe("autoconfig (deploy)", () => {
assets: { directory: outputDir },
},
}));
await run.runAutoConfig({
projectPath: process.cwd(),
buildCommand: "echo 'built' > build.txt",
configured: false,
workerName: "my-worker",
framework: {
name: "Fake",
configure: configureSpy,
} as unknown as Framework,
outputDir: "dist",
packageJson: {
dependencies: {
astro: "5",
await run.runAutoConfig(
{
projectPath: process.cwd(),
buildCommand: "echo 'built' > build.txt",
configured: false,
workerName: "my-worker",
framework: {
name: "Fake",
configure: configureSpy,
} as unknown as Framework,
outputDir: "dist",
packageJson: {
dependencies: {
astro: "5",
},
},
},
});
{ enableWranglerInstallation: true }
);

expect(std.out).toMatchInlineSnapshot(`
"
Expand Down
45 changes: 44 additions & 1 deletion packages/wrangler/src/__tests__/setup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,13 @@ describe("wrangler setup", () => {
test("should run autoconfig when project is not configured", async () => {
await seed({
"public/index.html": `<h1>Hello World</h1>`,
"package.json": JSON.stringify({}),
});

// Let's not actually install Wrangler, to speed up tests
vi.spyOn(c3, "installWrangler").mockImplementation(async () => {});
const installSpy = vi
.spyOn(c3, "installWrangler")
.mockImplementation(async () => {});

const runSpy = vi.spyOn(run, "runAutoConfig");

Expand All @@ -73,11 +76,51 @@ describe("wrangler setup", () => {
// autoconfig should have been run
expect(runSpy).toHaveBeenCalled();

expect(installSpy).toHaveBeenCalled();

expect(std.out).toContain(
"🎉 Your project is now setup to deploy to Cloudflare"
);
});

test("should not display completion message when disabled", async () => {
await seed({
"public/index.html": `<h1>Hello World</h1>`,
});

// Let's not actually install Wrangler, to speed up tests
vi.spyOn(c3, "installWrangler").mockImplementation(async () => {});

const runSpy = vi.spyOn(run, "runAutoConfig");

await runWrangler("setup --no-completion-message");

// autoconfig should have been run
expect(runSpy).toHaveBeenCalled();

expect(std.out).not.toContain("🎉 Your project");
});

test("should not install Wrangler when skipped", async () => {
await seed({
"public/index.html": `<h1>Hello World</h1>`,
"package.json": JSON.stringify({}),
});

const installSpy = vi
.spyOn(c3, "installWrangler")
.mockImplementation(async () => {});

const runSpy = vi.spyOn(run, "runAutoConfig");

await runWrangler("setup --no-install-wrangler");

// autoconfig should have been run
expect(runSpy).toHaveBeenCalled();

expect(installSpy).not.toHaveBeenCalled();
});

describe("--dry-run", () => {
test("should stop before running autoconfig when project is already configured", async () => {
await seed({
Expand Down
4 changes: 3 additions & 1 deletion packages/wrangler/src/autoconfig/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export async function runAutoConfig(
const runBuild = !dryRun && (autoConfigOptions.runBuild ?? true);
const skipConfirmations =
dryRun || autoConfigOptions.skipConfirmations === true;
const enableWranglerInstallation =
autoConfigOptions.enableWranglerInstallation ?? true;

const detected: AutoConfigMetrics = {
buildCommand: autoConfigDetails.buildCommand,
Expand Down Expand Up @@ -110,7 +112,7 @@ export async function runAutoConfig(
`Running autoconfig with:\n${JSON.stringify(autoConfigDetails, null, 2)}...`
);

if (autoConfigSummary.wranglerInstall) {
if (autoConfigSummary.wranglerInstall && enableWranglerInstallation) {
await installWrangler();
}

Expand Down
4 changes: 4 additions & 0 deletions packages/wrangler/src/autoconfig/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ export type AutoConfigOptions = {
* Note: When `dryRun` is `true` the the confirmation prompts are always skipped.
*/
skipConfirmations?: boolean;
/**
* Whether to install Wrangler during autoconfig
*/
enableWranglerInstallation?: boolean;
};

export type AutoConfigSummary = {
Expand Down
30 changes: 27 additions & 3 deletions packages/wrangler/src/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,53 @@ export const setupCommand = createCommand({
"Runs the command without applying any filesystem modifications",
type: "boolean",
},
"completion-message": {
describe:
"Display a message with deployment details after `wrangler setup` is complete",
type: "boolean",
default: true,
hidden: true,
},
"install-wrangler": {
describe: "Install Wrangler during project setup",
type: "boolean",
default: true,
hidden: true,
},
},

async handler(args, { config }) {
const details = await getDetailsForAutoConfig({
wranglerConfig: config,
});

function logCompletionMessage(message: string) {
if (args.completionMessage) {
logger.log(message);
}
}

// Only run auto config if the project is not already configured
if (!details.configured) {
await runAutoConfig(details, {
runBuild: args.build,
skipConfirmations: args.yes,
dryRun: args.dryRun,
enableWranglerInstallation: args.installWrangler,
});
if (!args.dryRun) {
logger.log("🎉 Your project is now setup to deploy to Cloudflare");
logCompletionMessage(
"🎉 Your project is now setup to deploy to Cloudflare"
);
}
} else {
logger.log("🎉 Your project is already setup to deploy to Cloudflare");
logCompletionMessage(
"🎉 Your project is already setup to deploy to Cloudflare"
);
}
if (!args.dryRun) {
const { type } = await getPackageManager();
logger.log(
logCompletionMessage(
`You can now deploy with ${brandColor(details.packageJson ? `${type} run deploy` : "wrangler deploy")}`
);
}
Expand Down
Loading