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
20 changes: 20 additions & 0 deletions .changeset/fix-qwik-adapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
"wrangler": patch
"create-cloudflare": patch
---

Use `qwik add cloudflare-workers` instead of `qwik add cloudflare-pages` for Workers targets

Both the wrangler autoconfig and C3 Workers template for Qwik were running
`qwik add cloudflare-pages` even when targeting Cloudflare Workers. This
caused the wrong adapter directory structure to be scaffolded
(`adapters/cloudflare-pages/` instead of `adapters/cloudflare-workers/`),
and required post-hoc cleanup of Pages-specific files like `_routes.json`.

Qwik now provides a dedicated `cloudflare-workers` adapter that generates
the correct Workers configuration, including `wrangler.jsonc` with `main`
and `assets` fields, a `public/.assetsignore` file, and the correct
`adapters/cloudflare-workers/vite.config.ts`.

Also adds `--skipConfirmation=true` to all `qwik add` invocations so the
interactive prompt is skipped in automated contexts.
8 changes: 7 additions & 1 deletion packages/create-cloudflare/templates/qwik/pages/c3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ const generate = async (ctx: C3Context) => {
const configure = async (ctx: C3Context) => {
// Add the pages integration
// For some reason `pnpx qwik add` fails for qwik so we use `pnpm qwik add` instead.
const cmd = [name === "pnpm" ? npm : npx, "qwik", "add", "cloudflare-pages"];
const cmd = [
name === "pnpm" ? npm : npx,
"qwik",
"add",
"cloudflare-pages",
"--skipConfirmation=true",
];
endSection(`Running ${quoteShellArgs(cmd)}`);
await runCommand(cmd);

Expand Down
15 changes: 9 additions & 6 deletions packages/create-cloudflare/templates/qwik/workers/c3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { spinner } from "@cloudflare/cli/interactive";
import { runFrameworkGenerator } from "frameworks/index";
import { loadTemplateSnippets, transformFile } from "helpers/codemod";
import { quoteShellArgs, runCommand } from "helpers/command";
import { removeFile, usesTypescript } from "helpers/files";
import { usesTypescript } from "helpers/files";
import { detectPackageManager } from "helpers/packageManagers";
import * as recast from "recast";
import type { TemplateConfig } from "../../../src/templates";
Expand All @@ -17,15 +17,18 @@ const generate = async (ctx: C3Context) => {
};

const configure = async (ctx: C3Context) => {
// Add the pages integration
// Add the workers integration
// For some reason `pnpx qwik add` fails for qwik so we use `pnpm qwik add` instead.
const cmd = [name === "pnpm" ? npm : npx, "qwik", "add", "cloudflare-pages"];
const cmd = [
name === "pnpm" ? npm : npx,
"qwik",
"add",
"cloudflare-workers",
"--skipConfirmation=true",
];
endSection(`Running ${quoteShellArgs(cmd)}`);
await runCommand(cmd);

// Remove the extraneous Pages files
removeFile("./public/_routes.json");

addBindingsProxy(ctx);
};

Expand Down
19 changes: 4 additions & 15 deletions packages/wrangler/src/autoconfig/frameworks/qwik.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { writeFile } from "node:fs/promises";
import { endSection } from "@cloudflare/cli";
import { brandColor } from "@cloudflare/cli/colors";
import { spinner } from "@cloudflare/cli/interactive";
Expand All @@ -18,22 +17,21 @@ export class Qwik extends Framework {
packageManager,
}: ConfigurationOptions): Promise<ConfigurationResults> {
if (!dryRun) {
// Add the pages integration
// Add the workers integration
const cmd = [
// For some reason `pnpx qwik add` fails for qwik so we use `pnpm qwik add` instead.
packageManager.type === "pnpm"
? packageManager.type
: packageManager.npx,
"qwik",
"add",
"cloudflare-pages",
"cloudflare-workers",
"--skipConfirmation=true",
];
endSection(`Running ${quoteShellArgs(cmd)}`);
await runCommand(cmd);

addBindingsProxy(projectPath);

await addAssetsIgnoreFile(projectPath);
}
return {
wranglerConfig: {
Expand All @@ -52,7 +50,7 @@ export class Qwik extends Framework {
}

configurationDescription =
'Configuring project for Qwik with "qwik add cloudflare-pages"';
'Configuring project for Qwik with "qwik add cloudflare-workers"';
}

function addBindingsProxy(projectPath: string) {
Expand Down Expand Up @@ -129,12 +127,3 @@ function addBindingsProxy(projectPath: string) {

s.stop(`${brandColor("updated")} \`vite.config.ts\``);
}

async function addAssetsIgnoreFile(projectPath: string) {
const toAdd = ["_worker.js", "_routes.json", "_headers", "_redirects"];

await writeFile(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assets ignore gets added by the qwik adapter already

`${projectPath}/public/.assetsignore`,
`${toAdd.join("\n")}\n`
);
}
Loading