Skip to content

Commit

Permalink
fix: check for @react-router/dev as proxy for RR7 framework mode
Browse files Browse the repository at this point in the history
  • Loading branch information
serhalp committed Dec 15, 2024
1 parent 6cd1370 commit 84028a6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
28 changes: 27 additions & 1 deletion packages/build-info/src/frameworks/react-router.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Project } from '../project.js'
beforeEach((ctx) => {
ctx.fs = new NodeFS()
})
test('detects a React Router v7 site', async ({ fs }) => {
test('detects a site using React Router v7 as a framework', async ({ fs }) => {
const cwd = mockFileSystem({
'react-router.config.ts': '',
'vite.config.ts': '',
Expand Down Expand Up @@ -46,6 +46,32 @@ test('detects a React Router v7 site', async ({ fs }) => {
expect(detected?.[0]?.dev?.port).toBe(5173)
})

test('does NOT detect a site using React Router v7 as a library', async ({ fs }) => {
const cwd = mockFileSystem({
'rollup.config.ts': '',
'package.json': JSON.stringify({
scripts: {
build: 'rollup build',
dev: 'rollup dev',
typecheck: 'react-router typegen && tsc',
},
dependencies: {
react: '^18.3.1',
'react-dom': '^18.3.1',
'react-router': '^7.0.2',
},
devDependencies: {
rollup: '^4.28.1',
typescript: '^5.6.3',
},
}),
})
const detected = await new Project(fs, cwd).detectFrameworks()

const detectedFrameworks = (detected ?? []).map((framework) => framework.id)
expect(detectedFrameworks).not.toContain('react-router')
})

test('does NOT detect a React Router <v7 site', async ({ fs }) => {
const cwd = mockFileSystem({
'vite.config.ts': '',
Expand Down
5 changes: 4 additions & 1 deletion packages/build-info/src/frameworks/react-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import { BaseFramework, Category, DetectedFramework, Framework } from './framewo
export class ReactRouter extends BaseFramework implements Framework {
readonly id = 'react-router'
name = 'React Router'
// React Router 7+ can be used either as a library or as a framework. We want to ignore lib mode (and possibly let
// other frameworks/bundlers/runners be detected). There isn't a perfect way to identify a site's mode, but at the
// time of writing both `@react-router/dev` and `react-router.config` should only be present in framework mode.
npmDependencies = ['@react-router/dev']
configFiles = ['react-router.config.ts', 'react-router.config.js']
npmDependencies = ['react-router']
category = Category.SSG

dev = {
Expand Down

0 comments on commit 84028a6

Please sign in to comment.