@@ -158,34 +158,25 @@ export async function setupIsolatedFixture(options: {
158
158
filter : ( src ) => ! src . includes ( 'node_modules' ) ,
159
159
} )
160
160
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
+ / o v e r r i d e s : \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 ,
177
179
)
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
- } )
189
180
190
181
// install
191
182
await x ( 'pnpm' , [ 'i' ] , {
@@ -201,17 +192,6 @@ export async function setupIsolatedFixture(options: {
201
192
} )
202
193
}
203
194
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
-
215
195
// inspired by
216
196
// https://github.com/remix-run/react-router/blob/433872f6ab098eaf946cc6c9cf80abf137420ad2/integration/helpers/vite.ts#L239
217
197
// for syntax highlighting of /* js */, use this extension
0 commit comments