Skip to content

Commit

Permalink
RSC: Set React resolutions during setup (#11152)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobbe authored Aug 4, 2024
1 parent 8889d1f commit fcc0351
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions packages/cli/src/commands/experimental/setupRscHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,24 +367,34 @@ export const handler = async ({ force, verbose }) => {
const response = await fetch(canaryWebPackageJsonUrl)
const canaryPackageJson = await response.json()

// Parse the current package.json in the web side
const currentPackageJsonPath = path.join(
// Read current package.json files
const currentRootPackageJsonPath = path.join(
rwPaths.base,
'package.json',
)
const currentRootPackageJson = JSON.parse(
fs.readFileSync(currentRootPackageJsonPath, 'utf-8'),
)
const currentWebPackageJsonPath = path.join(
rwPaths.web.base,
'package.json',
)
const currentPackageJson = JSON.parse(
fs.readFileSync(currentPackageJsonPath, 'utf-8'),
const currentWebPackageJson = JSON.parse(
fs.readFileSync(currentWebPackageJsonPath, 'utf-8'),
)

// Update the versions to match
const packagesToUpdate = ['react', 'react-dom']
for (const packageName of packagesToUpdate) {
currentPackageJson.dependencies[packageName] =
currentRootPackageJson.resolutions ||= {}
currentRootPackageJson.resolutions[packageName] =
canaryPackageJson.dependencies[packageName]
currentWebPackageJson.dependencies[packageName] =
canaryPackageJson.dependencies[packageName]
}
writeFile(
currentPackageJsonPath,
JSON.stringify(currentPackageJson, null, 2),
currentWebPackageJsonPath,
JSON.stringify(currentWebPackageJson, null, 2),
{
overwriteExisting: true,
},
Expand Down

0 comments on commit fcc0351

Please sign in to comment.