diff --git a/.changeset/tender-dryers-ask.md b/.changeset/tender-dryers-ask.md new file mode 100644 index 0000000000..995ad9033d --- /dev/null +++ b/.changeset/tender-dryers-ask.md @@ -0,0 +1,7 @@ +--- +"wrangler": patch +--- + +During autoconfig filter out Hono when there are 2 detected frameworks + +During the auto-configuration process Hono is now treated as an auxiliary framework (like Vite) and automatically filtered out when two frameworks are detected (before Hono was being filtered out only when the other framework was Waku). diff --git a/packages/wrangler/src/__tests__/autoconfig/details/framework-detection/multiple-frameworks-detected.test.ts b/packages/wrangler/src/__tests__/autoconfig/details/framework-detection/multiple-frameworks-detected.test.ts index ef54e79c38..0b48a36cd0 100644 --- a/packages/wrangler/src/__tests__/autoconfig/details/framework-detection/multiple-frameworks-detected.test.ts +++ b/packages/wrangler/src/__tests__/autoconfig/details/framework-detection/multiple-frameworks-detected.test.ts @@ -147,5 +147,20 @@ describe("detectFramework() / multiple frameworks detected", () => { expect(result.detectedFramework?.framework.id).toBe("astro"); }); + + it("does not throw when Hono and another known framework are detected (Hono is filtered out)", async ({ + expect, + }) => { + await seed({ + "package.json": JSON.stringify({ + dependencies: { "@tanstack/react-start": "1.132.0", hono: "4" }, + }), + "package-lock.json": JSON.stringify({ lockfileVersion: 3 }), + }); + + const result = await detectFramework(process.cwd()); + + expect(result.detectedFramework?.framework.id).toBe("tanstack-start"); + }); }); }); diff --git a/packages/wrangler/src/autoconfig/details/framework-detection.ts b/packages/wrangler/src/autoconfig/details/framework-detection.ts index 9d7193b4b3..4ded7362cd 100644 --- a/packages/wrangler/src/autoconfig/details/framework-detection.ts +++ b/packages/wrangler/src/autoconfig/details/framework-detection.ts @@ -1,4 +1,3 @@ -import assert from "node:assert"; import { existsSync, statSync } from "node:fs"; import { join, resolve } from "node:path"; import { FatalError, UserError } from "@cloudflare/workers-utils"; @@ -285,34 +284,29 @@ function maybeFindDetectedFramework( } if (settingsForOnlyKnownFrameworks.length === 2) { - const frameworkIdsFound = new Set( - settings.map(({ framework }) => framework.id) + const settingsForOnlyKnownFrameworksIds = new Set( + settingsForOnlyKnownFrameworks.map(({ framework }) => framework.id) ); - const viteId = "vite"; - - if (frameworkIdsFound.has(viteId)) { - const knownNonViteSettings = settingsForOnlyKnownFrameworks.find( - ({ framework }) => framework.id !== viteId - ); - - // Here knownNonViteSettings should always be defined, it only could be undefined if the detected frameworks are both Vite. - if (knownNonViteSettings) { - // If we've found a known framework and Vite, then most likely the Vite is there only either as an extra build tool - // or as part of a Vitest installation, so it's pretty safe to ignore it in this case - return knownNonViteSettings; + // Some frameworks (e.g. Vite, Hono) can serve as auxiliary tooling for a primary + // framework (e.g. Vite with React, Hono with Waku). When exactly two frameworks + // are detected and one is auxiliary, we discard it and return the primary one. + const idsOfAuxiliaryFrameworks = ["vite", "hono"]; + + for (const auxiliaryFrameworkId of idsOfAuxiliaryFrameworks) { + if (settingsForOnlyKnownFrameworksIds.has(auxiliaryFrameworkId)) { + const nonAuxiliaryFrameworkSettings = + settingsForOnlyKnownFrameworks.find( + ({ framework }) => framework.id !== auxiliaryFrameworkId + ); + + // Note: here nonAuxiliaryFrameworkSettings should always be defined, it could be undefined only if the + // same framework is actually detected twice (which shouldn't be possible). + if (nonAuxiliaryFrameworkSettings) { + return nonAuxiliaryFrameworkSettings; + } } } - - if (frameworkIdsFound.has("waku") && frameworkIdsFound.has("hono")) { - // The waku framework has a tight integration with hono, so it's likely that hono can also - // be detected in waku projects, if that's the case let's filter hono out - const wakuSettings = settingsForOnlyKnownFrameworks.find( - ({ framework }) => framework.id === "waku" - ); - assert(wakuSettings); - return wakuSettings; - } } // If we've detected multiple frameworks, and we're in a non interactive session (e.g. CI) let's stay on the safe side and error