From 83d89ef66f8d37f1a773427b926c1f0ca9c35514 Mon Sep 17 00:00:00 2001 From: Matt 'TK' Taylor Date: Mon, 16 Feb 2026 16:27:17 +0800 Subject: [PATCH] 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. --- .changeset/fix-qwik-adapter.md | 20 +++++++++++++++++++ .../templates/qwik/pages/c3.ts | 8 +++++++- .../templates/qwik/workers/c3.ts | 15 ++++++++------ .../src/autoconfig/frameworks/qwik.ts | 19 ++++-------------- 4 files changed, 40 insertions(+), 22 deletions(-) create mode 100644 .changeset/fix-qwik-adapter.md diff --git a/.changeset/fix-qwik-adapter.md b/.changeset/fix-qwik-adapter.md new file mode 100644 index 000000000000..8b2ffad6c4b2 --- /dev/null +++ b/.changeset/fix-qwik-adapter.md @@ -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. diff --git a/packages/create-cloudflare/templates/qwik/pages/c3.ts b/packages/create-cloudflare/templates/qwik/pages/c3.ts index 05637075aafb..d87ce6199de0 100644 --- a/packages/create-cloudflare/templates/qwik/pages/c3.ts +++ b/packages/create-cloudflare/templates/qwik/pages/c3.ts @@ -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); diff --git a/packages/create-cloudflare/templates/qwik/workers/c3.ts b/packages/create-cloudflare/templates/qwik/workers/c3.ts index 03440311e120..f89374cca3db 100644 --- a/packages/create-cloudflare/templates/qwik/workers/c3.ts +++ b/packages/create-cloudflare/templates/qwik/workers/c3.ts @@ -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"; @@ -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); }; diff --git a/packages/wrangler/src/autoconfig/frameworks/qwik.ts b/packages/wrangler/src/autoconfig/frameworks/qwik.ts index 02f65698898a..5ec010ad6087 100644 --- a/packages/wrangler/src/autoconfig/frameworks/qwik.ts +++ b/packages/wrangler/src/autoconfig/frameworks/qwik.ts @@ -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"; @@ -18,7 +17,7 @@ export class Qwik extends Framework { packageManager, }: ConfigurationOptions): Promise { 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" @@ -26,14 +25,13 @@ export class Qwik extends Framework { : packageManager.npx, "qwik", "add", - "cloudflare-pages", + "cloudflare-workers", + "--skipConfirmation=true", ]; endSection(`Running ${quoteShellArgs(cmd)}`); await runCommand(cmd); addBindingsProxy(projectPath); - - await addAssetsIgnoreFile(projectPath); } return { wranglerConfig: { @@ -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) { @@ -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( - `${projectPath}/public/.assetsignore`, - `${toAdd.join("\n")}\n` - ); -}