Skip to content
Merged
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
7 changes: 7 additions & 0 deletions .changeset/tender-dryers-ask.md
Original file line number Diff line number Diff line change
@@ -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).
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
});
});
44 changes: 19 additions & 25 deletions packages/wrangler/src/autoconfig/details/framework-detection.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -285,34 +284,29 @@ function maybeFindDetectedFramework(
}

if (settingsForOnlyKnownFrameworks.length === 2) {
const frameworkIdsFound = new Set<string>(
settings.map(({ framework }) => framework.id)
const settingsForOnlyKnownFrameworksIds = new Set<string>(
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
Expand Down
Loading