Implementation:Cypress io Cypress DetectFramework
| Knowledge Sources | |
|---|---|
| Domains | Configuration, Component_Testing |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
Concrete tool for automatically detecting the UI framework and bundler in a project provided by the @packages/scaffold-config module.
Description
The detectFramework function iterates through known framework definitions (CT_FRAMEWORKS), checking if required dependencies are installed at satisfying versions. It uses resolve-package-path for fast dependency resolution and semver for version constraint matching. The function prioritizes template frameworks over library frameworks.
Usage
Call this function during the Cypress setup wizard or programmatically when auto-configuring component testing. It requires access to the project's node_modules directory.
Code Reference
Source Location
- Repository: cypress-io/cypress
- File: packages/scaffold-config/src/detect.ts
- Lines: L35-82
Signature
export async function detectFramework(
projectPath: string,
frameworks: Cypress.ResolvedComponentFrameworkDefinition[]
): Promise<DetectFramework>
// Return type
interface DetectFramework {
framework?: ResolvedComponentFrameworkDefinition
bundler?: 'vite' | 'webpack'
}
Import
import { detectFramework } from '@packages/scaffold-config'
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| projectPath | string | Yes | Absolute path to the project root |
| frameworks | ResolvedComponentFrameworkDefinition[] | Yes | List of known frameworks to detect (CT_FRAMEWORKS) |
Outputs
| Name | Type | Description |
|---|---|---|
| framework | ResolvedComponentFrameworkDefinition or undefined | Detected framework definition |
| bundler | 'vite' or 'webpack' or undefined | Detected bundler type |
Usage Examples
Detecting Project Framework
import { detectFramework } from '@packages/scaffold-config'
import { CT_FRAMEWORKS } from '@packages/scaffold-config/src/frameworks'
const result = await detectFramework('/path/to/project', CT_FRAMEWORKS)
if (result.framework) {
console.log(`Detected: ${result.framework.name} with ${result.bundler}`)
} else {
console.log('No framework detected')
}