Skip to content

Commit 78758a3

Browse files
committed
test: tweak
1 parent 30a263e commit 78758a3

File tree

2 files changed

+19
-38
lines changed

2 files changed

+19
-38
lines changed

packages/plugin-rsc/e2e/fixture.ts

Lines changed: 18 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -158,34 +158,25 @@ export async function setupIsolatedFixture(options: {
158158
filter: (src) => !src.includes('node_modules'),
159159
})
160160

161-
// setup package.json overrides
162-
const packagesDir = path.join(import.meta.dirname, '..', '..')
163-
164-
// override workspace packages
165-
const overrides: Record<string, string> = {
166-
'@vitejs/plugin-rsc': `file:${path.join(packagesDir, 'plugin-rsc')}`,
167-
'@vitejs/plugin-react': `file:${path.join(packagesDir, 'plugin-react')}`,
168-
}
169-
170-
// inherit current overrides
171-
const listResult = await x(
172-
'pnpm',
173-
['list', '--json', '--depth=0', 'react', 'vite'],
174-
{
175-
nodeOptions: { cwd: path.join(import.meta.dirname, '..') },
176-
},
161+
// extract workspace overrides
162+
const rootDir = path.join(import.meta.dirname, '..', '..', '..')
163+
const workspaceYaml = fs.readFileSync(
164+
path.join(rootDir, 'pnpm-workspace.yaml'),
165+
'utf-8',
166+
)
167+
const overridesMatch = workspaceYaml.match(
168+
/overrides:\s*([\s\S]*?)(?=\n\w|\n*$)/,
169+
)
170+
const overridesSection = overridesMatch ? overridesMatch[0] : 'overrides:'
171+
const tempWorkspaceYaml = `\
172+
${overridesSection}
173+
'@vitejs/plugin-rsc': file:${path.join(rootDir, 'packages/plugin-rsc')}
174+
'@vitejs/plugin-react': file:${path.join(rootDir, 'packages/plugin-react')}
175+
`
176+
fs.writeFileSync(
177+
path.join(options.dest, 'pnpm-workspace.yaml'),
178+
tempWorkspaceYaml,
177179
)
178-
const pkg = JSON.parse(listResult.stdout)[0]
179-
const allDeps = { ...pkg.dependencies, ...pkg.devDependencies }
180-
overrides.react = allDeps.react.version
181-
overrides['react-dom'] = allDeps.react.version
182-
overrides['react-server-dom-webpack'] = allDeps.react.version
183-
overrides.vite = allDeps.vite.version
184-
185-
editFileJson(path.join(options.dest, 'package.json'), (pkg: any) => {
186-
Object.assign(((pkg.pnpm ??= {}).overrides ??= {}), overrides)
187-
return pkg
188-
})
189180

190181
// install
191182
await x('pnpm', ['i'], {
@@ -201,17 +192,6 @@ export async function setupIsolatedFixture(options: {
201192
})
202193
}
203194

204-
function editFileJson(filepath: string, edit: (s: string) => string) {
205-
fs.writeFileSync(
206-
filepath,
207-
JSON.stringify(
208-
edit(JSON.parse(fs.readFileSync(filepath, 'utf-8'))),
209-
null,
210-
2,
211-
),
212-
)
213-
}
214-
215195
// inspired by
216196
// https://github.com/remix-run/react-router/blob/433872f6ab098eaf946cc6c9cf80abf137420ad2/integration/helpers/vite.ts#L239
217197
// for syntax highlighting of /* js */, use this extension

pnpm-workspace.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ catalogs:
1010

1111
overrides:
1212
'@types/estree': ^1.0.8
13+
vite: "npm:rolldown-vite@latest"
1314

1415
dedupeInjectedDeps: false

0 commit comments

Comments
 (0)