Skip to content

Commit b8fa700

Browse files
committed
fix: use qwik add cloudflare-workers instead of cloudflare-pages for Workers targets
Switch both the wrangler autoconfig and C3 Workers template for Qwik from 'qwik add cloudflare-pages' to 'qwik add cloudflare-workers'. The cloudflare-workers adapter generates the correct Workers-specific scaffolding (adapters/cloudflare-workers/, .assetsignore, wrangler.jsonc with main + assets fields), removing the need for post-hoc cleanup of Pages-specific files. Also adds --skipConfirmation=true to all qwik add invocations so the interactive prompt is skipped in automated contexts.
1 parent f3871f8 commit b8fa700

4 files changed

Lines changed: 40 additions & 22 deletions

File tree

.changeset/fix-qwik-adapter.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
"wrangler": patch
3+
"create-cloudflare": patch
4+
---
5+
6+
Use `qwik add cloudflare-workers` instead of `qwik add cloudflare-pages` for Workers targets
7+
8+
Both the wrangler autoconfig and C3 Workers template for Qwik were running
9+
`qwik add cloudflare-pages` even when targeting Cloudflare Workers. This
10+
caused the wrong adapter directory structure to be scaffolded
11+
(`adapters/cloudflare-pages/` instead of `adapters/cloudflare-workers/`),
12+
and required post-hoc cleanup of Pages-specific files like `_routes.json`.
13+
14+
Qwik now provides a dedicated `cloudflare-workers` adapter that generates
15+
the correct Workers configuration, including `wrangler.jsonc` with `main`
16+
and `assets` fields, a `public/.assetsignore` file, and the correct
17+
`adapters/cloudflare-workers/vite.config.ts`.
18+
19+
Also adds `--skipConfirmation=true` to all `qwik add` invocations so the
20+
interactive prompt is skipped in automated contexts.

packages/create-cloudflare/templates/qwik/pages/c3.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ const generate = async (ctx: C3Context) => {
1919
const configure = async (ctx: C3Context) => {
2020
// Add the pages integration
2121
// For some reason `pnpx qwik add` fails for qwik so we use `pnpm qwik add` instead.
22-
const cmd = [name === "pnpm" ? npm : npx, "qwik", "add", "cloudflare-pages"];
22+
const cmd = [
23+
name === "pnpm" ? npm : npx,
24+
"qwik",
25+
"add",
26+
"cloudflare-pages",
27+
"--skipConfirmation=true",
28+
];
2329
endSection(`Running ${quoteShellArgs(cmd)}`);
2430
await runCommand(cmd);
2531

packages/create-cloudflare/templates/qwik/workers/c3.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { spinner } from "@cloudflare/cli/interactive";
44
import { runFrameworkGenerator } from "frameworks/index";
55
import { loadTemplateSnippets, transformFile } from "helpers/codemod";
66
import { quoteShellArgs, runCommand } from "helpers/command";
7-
import { removeFile, usesTypescript } from "helpers/files";
7+
import { usesTypescript } from "helpers/files";
88
import { detectPackageManager } from "helpers/packageManagers";
99
import * as recast from "recast";
1010
import type { TemplateConfig } from "../../../src/templates";
@@ -17,15 +17,18 @@ const generate = async (ctx: C3Context) => {
1717
};
1818

1919
const configure = async (ctx: C3Context) => {
20-
// Add the pages integration
20+
// Add the workers integration
2121
// For some reason `pnpx qwik add` fails for qwik so we use `pnpm qwik add` instead.
22-
const cmd = [name === "pnpm" ? npm : npx, "qwik", "add", "cloudflare-pages"];
22+
const cmd = [
23+
name === "pnpm" ? npm : npx,
24+
"qwik",
25+
"add",
26+
"cloudflare-workers",
27+
"--skipConfirmation=true",
28+
];
2329
endSection(`Running ${quoteShellArgs(cmd)}`);
2430
await runCommand(cmd);
2531

26-
// Remove the extraneous Pages files
27-
removeFile("./public/_routes.json");
28-
2932
addBindingsProxy(ctx);
3033
};
3134

packages/wrangler/src/autoconfig/frameworks/qwik.ts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { writeFile } from "node:fs/promises";
21
import { endSection } from "@cloudflare/cli";
32
import { brandColor } from "@cloudflare/cli/colors";
43
import { spinner } from "@cloudflare/cli/interactive";
@@ -18,22 +17,21 @@ export class Qwik extends Framework {
1817
packageManager,
1918
}: ConfigurationOptions): Promise<ConfigurationResults> {
2019
if (!dryRun) {
21-
// Add the pages integration
20+
// Add the workers integration
2221
const cmd = [
2322
// For some reason `pnpx qwik add` fails for qwik so we use `pnpm qwik add` instead.
2423
packageManager.type === "pnpm"
2524
? packageManager.type
2625
: packageManager.npx,
2726
"qwik",
2827
"add",
29-
"cloudflare-pages",
28+
"cloudflare-workers",
29+
"--skipConfirmation=true",
3030
];
3131
endSection(`Running ${quoteShellArgs(cmd)}`);
3232
await runCommand(cmd);
3333

3434
addBindingsProxy(projectPath);
35-
36-
await addAssetsIgnoreFile(projectPath);
3735
}
3836
return {
3937
wranglerConfig: {
@@ -52,7 +50,7 @@ export class Qwik extends Framework {
5250
}
5351

5452
configurationDescription =
55-
'Configuring project for Qwik with "qwik add cloudflare-pages"';
53+
'Configuring project for Qwik with "qwik add cloudflare-workers"';
5654
}
5755

5856
function addBindingsProxy(projectPath: string) {
@@ -129,12 +127,3 @@ function addBindingsProxy(projectPath: string) {
129127

130128
s.stop(`${brandColor("updated")} \`vite.config.ts\``);
131129
}
132-
133-
async function addAssetsIgnoreFile(projectPath: string) {
134-
const toAdd = ["_worker.js", "_routes.json", "_headers", "_redirects"];
135-
136-
await writeFile(
137-
`${projectPath}/public/.assetsignore`,
138-
`${toAdd.join("\n")}\n`
139-
);
140-
}

0 commit comments

Comments
 (0)