Skip to content

Commit 78cbe37

Browse files
During autoconfig filter out Hono when there are 2 detected frameworks (#13193)
Co-authored-by: Matt Kane <m@mk.gg>
1 parent 448fec8 commit 78cbe37

3 files changed

Lines changed: 41 additions & 25 deletions

File tree

.changeset/tender-dryers-ask.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
During autoconfig filter out Hono when there are 2 detected frameworks
6+
7+
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).

packages/wrangler/src/__tests__/autoconfig/details/framework-detection/multiple-frameworks-detected.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,5 +147,20 @@ describe("detectFramework() / multiple frameworks detected", () => {
147147

148148
expect(result.detectedFramework?.framework.id).toBe("astro");
149149
});
150+
151+
it("does not throw when Hono and another known framework are detected (Hono is filtered out)", async ({
152+
expect,
153+
}) => {
154+
await seed({
155+
"package.json": JSON.stringify({
156+
dependencies: { "@tanstack/react-start": "1.132.0", hono: "4" },
157+
}),
158+
"package-lock.json": JSON.stringify({ lockfileVersion: 3 }),
159+
});
160+
161+
const result = await detectFramework(process.cwd());
162+
163+
expect(result.detectedFramework?.framework.id).toBe("tanstack-start");
164+
});
150165
});
151166
});

packages/wrangler/src/autoconfig/details/framework-detection.ts

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import assert from "node:assert";
21
import { existsSync, statSync } from "node:fs";
32
import { join, resolve } from "node:path";
43
import { FatalError, UserError } from "@cloudflare/workers-utils";
@@ -285,34 +284,29 @@ function maybeFindDetectedFramework(
285284
}
286285

287286
if (settingsForOnlyKnownFrameworks.length === 2) {
288-
const frameworkIdsFound = new Set<string>(
289-
settings.map(({ framework }) => framework.id)
287+
const settingsForOnlyKnownFrameworksIds = new Set<string>(
288+
settingsForOnlyKnownFrameworks.map(({ framework }) => framework.id)
290289
);
291290

292-
const viteId = "vite";
293-
294-
if (frameworkIdsFound.has(viteId)) {
295-
const knownNonViteSettings = settingsForOnlyKnownFrameworks.find(
296-
({ framework }) => framework.id !== viteId
297-
);
298-
299-
// Here knownNonViteSettings should always be defined, it only could be undefined if the detected frameworks are both Vite.
300-
if (knownNonViteSettings) {
301-
// If we've found a known framework and Vite, then most likely the Vite is there only either as an extra build tool
302-
// or as part of a Vitest installation, so it's pretty safe to ignore it in this case
303-
return knownNonViteSettings;
291+
// Some frameworks (e.g. Vite, Hono) can serve as auxiliary tooling for a primary
292+
// framework (e.g. Vite with React, Hono with Waku). When exactly two frameworks
293+
// are detected and one is auxiliary, we discard it and return the primary one.
294+
const idsOfAuxiliaryFrameworks = ["vite", "hono"];
295+
296+
for (const auxiliaryFrameworkId of idsOfAuxiliaryFrameworks) {
297+
if (settingsForOnlyKnownFrameworksIds.has(auxiliaryFrameworkId)) {
298+
const nonAuxiliaryFrameworkSettings =
299+
settingsForOnlyKnownFrameworks.find(
300+
({ framework }) => framework.id !== auxiliaryFrameworkId
301+
);
302+
303+
// Note: here nonAuxiliaryFrameworkSettings should always be defined, it could be undefined only if the
304+
// same framework is actually detected twice (which shouldn't be possible).
305+
if (nonAuxiliaryFrameworkSettings) {
306+
return nonAuxiliaryFrameworkSettings;
307+
}
304308
}
305309
}
306-
307-
if (frameworkIdsFound.has("waku") && frameworkIdsFound.has("hono")) {
308-
// The waku framework has a tight integration with hono, so it's likely that hono can also
309-
// be detected in waku projects, if that's the case let's filter hono out
310-
const wakuSettings = settingsForOnlyKnownFrameworks.find(
311-
({ framework }) => framework.id === "waku"
312-
);
313-
assert(wakuSettings);
314-
return wakuSettings;
315-
}
316310
}
317311

318312
// 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

0 commit comments

Comments
 (0)