|
1 | | -import assert from "node:assert"; |
2 | 1 | import { existsSync, statSync } from "node:fs"; |
3 | 2 | import { join, resolve } from "node:path"; |
4 | 3 | import { FatalError, UserError } from "@cloudflare/workers-utils"; |
@@ -285,34 +284,29 @@ function maybeFindDetectedFramework( |
285 | 284 | } |
286 | 285 |
|
287 | 286 | 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) |
290 | 289 | ); |
291 | 290 |
|
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 | + } |
304 | 308 | } |
305 | 309 | } |
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 | | - } |
316 | 310 | } |
317 | 311 |
|
318 | 312 | // 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