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

sync-react: Add affordance to stop syncing Pages Router (#73533)

parent 6b393477
...@@ -14,6 +14,12 @@ const repoOwner = 'vercel' ...@@ -14,6 +14,12 @@ const repoOwner = 'vercel'
const repoName = 'next.js' const repoName = 'next.js'
const pullRequestLabels = ['type: react-sync'] const pullRequestLabels = ['type: react-sync']
const pullRequestReviewers = ['eps1lon'] const pullRequestReviewers = ['eps1lon']
/**
* Set to `null` to automatically sync the React version of Pages Router with App Router React version.
* Set to a specific version to override the Pages Router React version e.g. `^19.0.0`.
* @type {string | null}
*/
const pagesRouterReact = null
const filesReferencingReactPeerDependencyVersion = [ const filesReferencingReactPeerDependencyVersion = [
'run-tests.js', 'run-tests.js',
...@@ -187,7 +193,14 @@ async function main() { ...@@ -187,7 +193,14 @@ async function main() {
async function commitEverything(message) { async function commitEverything(message) {
await execa('git', ['add', '-A']) await execa('git', ['add', '-A'])
await execa('git', ['commit', '--message', message, '--no-verify']) await execa('git', [
'commit',
'--message',
message,
'--no-verify',
// Some steps can be empty, e.g. when we don't sync Pages router
'--allow-empty',
])
} }
if (createPull && !actor) { if (createPull && !actor) {
...@@ -306,22 +319,29 @@ Or, run this command with no arguments to use the most recently published versio ...@@ -306,22 +319,29 @@ Or, run this command with no arguments to use the most recently published versio
) )
} }
const syncPagesRouterReact = pagesRouterReact === null
const pagesRouterReactVersion = syncPagesRouterReact
? newVersionStr
: pagesRouterReact
const { sha: baseSha, dateString: baseDateString } = baseVersionInfo const { sha: baseSha, dateString: baseDateString } = baseVersionInfo
for (const fileName of filesReferencingReactPeerDependencyVersion) {
const filePath = path.join(cwd, fileName) if (syncPagesRouterReact) {
const previousSource = await fsp.readFile(filePath, 'utf-8') for (const fileName of filesReferencingReactPeerDependencyVersion) {
const updatedSource = previousSource.replace( const filePath = path.join(cwd, fileName)
`const nextjsReactPeerVersion = "${baseVersionStr}";`, const previousSource = await fsp.readFile(filePath, 'utf-8')
`const nextjsReactPeerVersion = "${newVersionStr}";` const updatedSource = previousSource.replace(
) `const nextjsReactPeerVersion = "${baseVersionStr}";`,
if (updatedSource === previousSource) { `const nextjsReactPeerVersion = "${pagesRouterReactVersion}";`
errors.push(
new Error(
`${fileName}: Failed to update ${baseVersionStr} to ${newVersionStr}. Is this file still referencing the React peer dependency version?`
)
) )
} else { if (pagesRouterReact === null && updatedSource === previousSource) {
await fsp.writeFile(filePath, updatedSource) errors.push(
new Error(
`${fileName}: Failed to update ${baseVersionStr} to ${pagesRouterReactVersion}. Is this file still referencing the React peer dependency version?`
)
)
} else {
await fsp.writeFile(filePath, updatedSource)
}
} }
} }
...@@ -330,10 +350,10 @@ Or, run this command with no arguments to use the most recently published versio ...@@ -330,10 +350,10 @@ Or, run this command with no arguments to use the most recently published versio
const packageJson = await fsp.readFile(packageJsonPath, 'utf-8') const packageJson = await fsp.readFile(packageJsonPath, 'utf-8')
const manifest = JSON.parse(packageJson) const manifest = JSON.parse(packageJson)
if (manifest.dependencies['react']) { if (manifest.dependencies['react']) {
manifest.dependencies['react'] = newVersionStr manifest.dependencies['react'] = pagesRouterReactVersion
} }
if (manifest.dependencies['react-dom']) { if (manifest.dependencies['react-dom']) {
manifest.dependencies['react-dom'] = newVersionStr manifest.dependencies['react-dom'] = pagesRouterReactVersion
} }
await fsp.writeFile( await fsp.writeFile(
packageJsonPath, packageJsonPath,
...@@ -352,10 +372,12 @@ Or, run this command with no arguments to use the most recently published versio ...@@ -352,10 +372,12 @@ Or, run this command with no arguments to use the most recently published versio
const packageJson = await fsp.readFile(packageJsonPath, 'utf-8') const packageJson = await fsp.readFile(packageJsonPath, 'utf-8')
const manifest = JSON.parse(packageJson) const manifest = JSON.parse(packageJson)
if (manifest.peerDependencies['react']) { if (manifest.peerDependencies['react']) {
manifest.peerDependencies['react'] = `^18.2.0 || ${newVersionStr}` manifest.peerDependencies['react'] =
`^18.2.0 || ${pagesRouterReactVersion}`
} }
if (manifest.peerDependencies['react-dom']) { if (manifest.peerDependencies['react-dom']) {
manifest.peerDependencies['react-dom'] = `^18.2.0 || ${newVersionStr}` manifest.peerDependencies['react-dom'] =
`^18.2.0 || ${pagesRouterReactVersion}`
} }
await fsp.writeFile( await fsp.writeFile(
packageJsonPath, packageJsonPath,
...@@ -417,7 +439,10 @@ Or, run this command with no arguments to use the most recently published versio ...@@ -417,7 +439,10 @@ Or, run this command with no arguments to use the most recently published versio
console.log() console.log()
} }
let prDescription = `**breaking change for canary users: Bumps peer dependency of React from \`${baseVersionStr}\` to \`${newVersionStr}\`**\n\n` let prDescription = ''
if (syncPagesRouterReact) {
prDescription += `**breaking change for canary users: Bumps peer dependency of React from \`${baseVersionStr}\` to \`${pagesRouterReactVersion}\`**\n\n`
}
// Fetch the changelog from GitHub and print it to the console. // Fetch the changelog from GitHub and print it to the console.
prDescription += `[diff facebook/react@${baseSha}...${newSha}](https://github.com/facebook/react/compare/${baseSha}...${newSha})\n\n` prDescription += `[diff facebook/react@${baseSha}...${newSha}](https://github.com/facebook/react/compare/${baseSha}...${newSha})\n\n`
......
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