Skip to content

Commit

Permalink
react-sync: Automatically update peer dependencies
Browse files Browse the repository at this point in the history
We only updated `dependencies` in apps but didn't
abstract the case for libraries.
`next` was already special cased but we forgot `@next/third-parties`.
Not both go through the same generic logic.
  • Loading branch information
eps1lon committed Oct 22, 2024
1 parent 236e001 commit 0ad6de6
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions scripts/sync-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -322,24 +325,27 @@ 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 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')
}

for (const fileName of appManifestsInstallingNextjsPeerDependencies) {
const packageJsonPath = path.join(cwd, fileName)
Expand All @@ -360,7 +366,7 @@ 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')
}

// Install the updated dependencies and build the vendored React files.
Expand Down

0 comments on commit 0ad6de6

Please sign in to comment.