Unverified Commit 21565ff6 authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

sync-react: Handle version bumps across SemVer minors and release channels (#74091)

parent 58d3982e
...@@ -21,6 +21,7 @@ const pullRequestReviewers = ['eps1lon'] ...@@ -21,6 +21,7 @@ const pullRequestReviewers = ['eps1lon']
*/ */
const pagesRouterReact = '^19.0.0' const pagesRouterReact = '^19.0.0'
const defaultLatestChannel = 'canary'
const filesReferencingReactPeerDependencyVersion = [ const filesReferencingReactPeerDependencyVersion = [
'run-tests.js', 'run-tests.js',
'packages/create-next-app/templates/index.ts', 'packages/create-next-app/templates/index.ts',
...@@ -38,6 +39,24 @@ const appManifestsInstallingNextjsPeerDependencies = [ ...@@ -38,6 +39,24 @@ const appManifestsInstallingNextjsPeerDependencies = [
'test/e2e/next-test/first-time-setup-ts/package.json', 'test/e2e/next-test/first-time-setup-ts/package.json',
] ]
async function getSchedulerVersion(reactVersion) {
const url = `https://registry.npmjs.org/react-dom/${reactVersion}`
const response = await fetch(url, {
headers: {
Accept: 'application/json',
},
})
if (!response.ok) {
throw new Error(
`${url}: ${response.status} ${response.statusText}\n${await response.text()}`
)
}
const manifest = await response.json()
return manifest.dependencies['scheduler']
}
// Use this script to update Next's vendored copy of React and related packages: // Use this script to update Next's vendored copy of React and related packages:
// //
// Basic usage (defaults to most recent React canary version): // Basic usage (defaults to most recent React canary version):
...@@ -46,13 +65,7 @@ const appManifestsInstallingNextjsPeerDependencies = [ ...@@ -46,13 +65,7 @@ const appManifestsInstallingNextjsPeerDependencies = [
// Update package.json but skip installing the dependencies automatically: // Update package.json but skip installing the dependencies automatically:
// pnpm run sync-react --no-install // pnpm run sync-react --no-install
async function sync({ async function sync({ channel, newVersionStr, noInstall }) {
channel,
newVersionStr,
newSha,
newDateString,
noInstall,
}) {
const useExperimental = channel === 'experimental' const useExperimental = channel === 'experimental'
const cwd = process.cwd() const cwd = process.cwd()
const pkgJson = JSON.parse( const pkgJson = JSON.parse(
...@@ -64,38 +77,35 @@ async function sync({ ...@@ -64,38 +77,35 @@ async function sync({
useExperimental ? 'react-experimental-builtin' : 'react-builtin' useExperimental ? 'react-experimental-builtin' : 'react-builtin'
].replace(/^npm:react@/, '') ].replace(/^npm:react@/, '')
const baseVersionInfo = extractInfoFromReactVersion(baseVersionStr) console.log(`Updating "react@${channel}" to ${newVersionStr}...`)
if (!baseVersionInfo) { if (newVersionStr === baseVersionStr) {
throw new Error(
'Base react version does not match expected format: ' + baseVersionStr
)
}
const {
sha: baseSha,
releaseLabel: baseReleaseLabel,
dateString: baseDateString,
} = baseVersionInfo
console.log(`Updating "react@${channel}" to ${newSha}...\n`)
if (newSha === baseSha) {
console.log('Already up to date.') console.log('Already up to date.')
return return
} }
const baseSchedulerVersionStr = devDependencies[
useExperimental ? 'scheduler-experimental-builtin' : 'scheduler-builtin'
].replace(/^npm:scheduler@/, '')
const newSchedulerVersionStr = await getSchedulerVersion(newVersionStr)
console.log(`Updating "scheduler@${channel}" to ${newSchedulerVersionStr}...`)
for (const [dep, version] of Object.entries(devDependencies)) { for (const [dep, version] of Object.entries(devDependencies)) {
if (version.endsWith(`${baseReleaseLabel}-${baseSha}-${baseDateString}`)) { if (version.endsWith(baseVersionStr)) {
devDependencies[dep] = version.replace(baseVersionStr, newVersionStr)
} else if (version.endsWith(baseSchedulerVersionStr)) {
devDependencies[dep] = version.replace( devDependencies[dep] = version.replace(
`${baseReleaseLabel}-${baseSha}-${baseDateString}`, baseSchedulerVersionStr,
`${channel}-${newSha}-${newDateString}` newSchedulerVersionStr
) )
} }
} }
for (const [dep, version] of Object.entries(pnpmOverrides)) { for (const [dep, version] of Object.entries(pnpmOverrides)) {
if (version.endsWith(`${baseReleaseLabel}-${baseSha}-${baseDateString}`)) { if (version.endsWith(baseVersionStr)) {
pnpmOverrides[dep] = version.replace(baseVersionStr, newVersionStr)
} else if (version.endsWith(baseSchedulerVersionStr)) {
pnpmOverrides[dep] = version.replace( pnpmOverrides[dep] = version.replace(
`${baseReleaseLabel}-${baseSha}-${baseDateString}`, baseSchedulerVersionStr,
`${channel}-${newSha}-${newDateString}` newSchedulerVersionStr
) )
} }
} }
...@@ -224,7 +234,7 @@ async function main() { ...@@ -224,7 +234,7 @@ async function main() {
) { ) {
const { stdout, stderr } = await execa( const { stdout, stderr } = await execa(
'npm', 'npm',
['--silent', 'view', 'react@canary', 'version'], ['--silent', 'view', `react@${defaultLatestChannel}`, 'version'],
{ {
// Avoid "Usage Error: This project is configured to use pnpm". // Avoid "Usage Error: This project is configured to use pnpm".
cwd: '/tmp', cwd: '/tmp',
...@@ -236,7 +246,7 @@ async function main() { ...@@ -236,7 +246,7 @@ async function main() {
} }
newVersionStr = stdout.trim() newVersionStr = stdout.trim()
console.log( console.log(
`--version was not provided. Using react@canary: ${newVersionStr}` `--version was not provided. Using react@${defaultLatestChannel}: ${newVersionStr}`
) )
} }
...@@ -253,7 +263,7 @@ Or, run this command with no arguments to use the most recently published versio ...@@ -253,7 +263,7 @@ Or, run this command with no arguments to use the most recently published versio
} }
const { sha: newSha, dateString: newDateString } = newVersionInfo const { sha: newSha, dateString: newDateString } = newVersionInfo
const branchName = `update/react/${newSha}-${newDateString}` const branchName = `update/react/${newVersionStr}`
if (createPull) { if (createPull) {
const { exitCode, all, command } = await execa( const { exitCode, all, command } = await execa(
'git', 'git',
...@@ -292,9 +302,7 @@ Or, run this command with no arguments to use the most recently published versio ...@@ -292,9 +302,7 @@ Or, run this command with no arguments to use the most recently published versio
) )
await sync({ await sync({
newDateString, newVersionStr: `0.0.0-experimental-${newSha}-${newDateString}`,
newSha,
newVersionStr,
noInstall: !install, noInstall: !install,
channel: 'experimental', channel: 'experimental',
}) })
...@@ -302,14 +310,12 @@ Or, run this command with no arguments to use the most recently published versio ...@@ -302,14 +310,12 @@ Or, run this command with no arguments to use the most recently published versio
await commitEverything('Update `react@experimental`') await commitEverything('Update `react@experimental`')
} }
await sync({ await sync({
newDateString,
newSha,
newVersionStr, newVersionStr,
noInstall: !install, noInstall: !install,
channel: 'rc', channel: '<framework-stable>',
}) })
if (commit) { if (commit) {
await commitEverything('Update `react@rc`') await commitEverything('Update `react`')
} }
const baseVersionInfo = extractInfoFromReactVersion(baseVersionStr) const baseVersionInfo = extractInfoFromReactVersion(baseVersionStr)
...@@ -394,9 +400,9 @@ Or, run this command with no arguments to use the most recently published versio ...@@ -394,9 +400,9 @@ Or, run this command with no arguments to use the most recently published versio
// Install the updated dependencies and build the vendored React files. // Install the updated dependencies and build the vendored React files.
if (!install) { if (!install) {
console.log('Skipping install step because --no-install flag was passed.\n') console.log('Skipping install step because --no-install flag was passed.')
} else { } else {
console.log('Installing dependencies...\n') console.log('Installing dependencies...')
const installSubprocess = execa('pnpm', [ const installSubprocess = execa('pnpm', [
'install', 'install',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment