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

react-sync: Automatically update peer dependencies in libraries (#71636)

parent 08cd0e6e
...@@ -20,8 +20,11 @@ const filesReferencingReactPeerDependencyVersion = [ ...@@ -20,8 +20,11 @@ const filesReferencingReactPeerDependencyVersion = [
'packages/create-next-app/templates/index.ts', 'packages/create-next-app/templates/index.ts',
'test/lib/next-modes/base.ts', 'test/lib/next-modes/base.ts',
] ]
const appManifestsInstallingNextjsPeerDependencies = [ const libraryManifestsSupportingNextjsReact = [
'packages/third-parties/package.json', 'packages/third-parties/package.json',
'packages/next/package.json',
]
const appManifestsInstallingNextjsPeerDependencies = [
'examples/reproduction-template/package.json', 'examples/reproduction-template/package.json',
'test/.stats-app/package.json', 'test/.stats-app/package.json',
// TODO: These should use the usual test helpers that automatically install the right React version // TODO: These should use the usual test helpers that automatically install the right React version
...@@ -322,25 +325,6 @@ Or, run this command with no arguments to use the most recently published versio ...@@ -322,25 +325,6 @@ Or, run this command with no arguments to use the most recently published versio
} }
} }
const nextjsPackageJsonPath = path.join(
process.cwd(),
'packages',
'next',
'package.json'
)
const nextjsPackageJson = JSON.parse(
await fsp.readFile(nextjsPackageJsonPath, 'utf-8')
)
nextjsPackageJson.peerDependencies.react = `^18.2.0 || ${newVersionStr}`
nextjsPackageJson.peerDependencies['react-dom'] =
`^18.2.0 || ${newVersionStr}`
await fsp.writeFile(
nextjsPackageJsonPath,
JSON.stringify(nextjsPackageJson, null, 2) +
// Prettier would add a newline anyway so do it manually to skip the additional `pnpm prettier-write`
'\n'
)
for (const fileName of appManifestsInstallingNextjsPeerDependencies) { for (const fileName of appManifestsInstallingNextjsPeerDependencies) {
const packageJsonPath = path.join(cwd, fileName) const packageJsonPath = path.join(cwd, fileName)
const packageJson = await fsp.readFile(packageJsonPath, 'utf-8') const packageJson = await fsp.readFile(packageJsonPath, 'utf-8')
...@@ -360,7 +344,29 @@ Or, run this command with no arguments to use the most recently published versio ...@@ -360,7 +344,29 @@ Or, run this command with no arguments to use the most recently published versio
} }
if (commit) { if (commit) {
await commitEverything('Updated peer dependency references') await commitEverything('Updated peer dependency references in apps')
}
for (const fileName of libraryManifestsSupportingNextjsReact) {
const packageJsonPath = path.join(cwd, fileName)
const packageJson = await fsp.readFile(packageJsonPath, 'utf-8')
const manifest = JSON.parse(packageJson)
if (manifest.peerDependencies['react']) {
manifest.peerDependencies['react'] = `^18.2.0 || ${newVersionStr}`
}
if (manifest.peerDependencies['react-dom']) {
manifest.peerDependencies['react-dom'] = `^18.2.0 || ${newVersionStr}`
}
await fsp.writeFile(
packageJsonPath,
JSON.stringify(manifest, null, 2) +
// Prettier would add a newline anyway so do it manually to skip the additional `pnpm prettier-write`
'\n'
)
}
if (commit) {
await commitEverything('Updated peer dependency references in libraries')
} }
// Install the updated dependencies and build the vendored React files. // Install the updated dependencies and build the vendored React files.
......
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