Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): Update react versions during RSC setup command #11140

Merged
merged 2 commits into from
Aug 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion packages/cli/src/commands/experimental/setupRscHandler.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import path from 'path'

import execa from 'execa'
import fs from 'fs-extra'
import { Listr } from 'listr2'

Expand Down Expand Up @@ -324,7 +325,7 @@ export const handler = async ({ force, verbose }) => {
},
},
{
title: 'Add React experimental types',
title: 'Add React experimental types...',
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was just to make it match the other titles

task: async () => {
const tsconfigPath = path.join(rwPaths.web.base, 'tsconfig.json')
const tsconfig = JSON.parse(fs.readFileSync(tsconfigPath, 'utf-8'))
Expand Down Expand Up @@ -357,6 +358,44 @@ export const handler = async ({ force, verbose }) => {
})
},
},
{
title: 'Updating React version...',
task: async () => {
// Fetch the web package.json from the main branch
const canaryWebPackageJsonUrl =
'https://raw.githubusercontent.com/redwoodjs/redwood/main/packages/create-redwood-app/templates/ts/web/package.json'
const response = await fetch(canaryWebPackageJsonUrl)
const canaryPackageJson = await response.json()

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

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

// Run yarn install to apply the changes
await execa('yarn', [], {
cwd: getPaths().web.base,
})
},
},
{
task: () => {
printTaskEpilogue(command, description, EXPERIMENTAL_TOPIC_ID)
Expand Down
Loading