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

This commit is contained in:
Sebastian "Sebbie" Silbermann
2024-10-22 18:05:19 +00:00
committed by GitHub
parent 08cd0e6ec8
commit fe4e4d2c33
+27 -21
View File
@@ -20,8 +20,11 @@ const filesReferencingReactPeerDependencyVersion = [
'packages/create-next-app/templates/index.ts',
'test/lib/next-modes/base.ts',
]
const appManifestsInstallingNextjsPeerDependencies = [
const libraryManifestsSupportingNextjsReact = [
'packages/third-parties/package.json',
'packages/next/package.json',
]
const appManifestsInstallingNextjsPeerDependencies = [
'examples/reproduction-template/package.json',
'test/.stats-app/package.json',
// 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
}
}
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) {
const packageJsonPath = path.join(cwd, fileName)
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
}
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.