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

[cd] Update `peerDependencies` in prereleases to accept the current prerelease (#98411)

https://github.com/vercel/next.js/pull/98330 revealed theat
`@next/third-parties` never worked with prereleases after 16.0. Now we
[update `peerDependencies` similar to what we do for preview builds
already](https://github.com/vercel/next.js/blob/27f679224e2660971377f855ced51093462734d8/scripts/create-preview-tarballs.js#L130-L132)
(we should unify both eventually to go through the same flow).

Fixes
```
  npm error code ERESOLVE
  npm error ERESOLVE unable to resolve dependency tree
  npm error
  npm error While resolving: undefined@undefined
  npm error Found: next@16.4.0-canary.22
  npm error node_modules/next
  npm error   next@"16.4.0-canary.22" from the root project
  npm error
  npm error Could not resolve dependency:
  npm error peer next@"^13.0.0 || ^14.0.0 || ^15.0.0 || ^16.0.0-beta.0" from @next/third-parties@16.4.0-canary.22
  npm error node_modules/@next/third-parties
  npm error   @next/third-parties@"16.4.0-canary.22" from the root project
```
-- https://github.com/vercel/next.js/actions/runs/34291905918/attempts/2
parent 56b95f41
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
"typescript": "6.0.2" "typescript": "6.0.2"
}, },
"peerDependencies": { "peerDependencies": {
"next": "^13.0.0 || ^14.0.0 || ^15.0.0 || ^16.0.0-beta.0", "next": "^13.0.0 || ^14.0.0 || ^15.0.0 || ^16.0.0",
"react": "^18.2.0 || 19.0.0-rc-de68d2f4-20241204 || ^19.0.0" "react": "^18.2.0 || 19.0.0-rc-de68d2f4-20241204 || ^19.0.0"
} }
} }
...@@ -228,6 +228,60 @@ const publishRetryDelaySeconds = 15 ...@@ -228,6 +228,60 @@ const publishRetryDelaySeconds = 15
JSON.stringify(nextPkg, null, 2) JSON.stringify(nextPkg, null, 2)
) )
if (isPrerelease) {
// Lerna does not update peerDependencies at version time, and a static
// range like "^16.0.0" never satisfies a fresh prerelease version.
// Append the release version to any peer dependency on packages published
// from this repo so the published prerelease accepts its own version while
// keeping the stable ranges.
// Stable releases keep their wide ranges untouched so a published package
// keeps working with newer Next.js minors.
// TODO: Use `|| workspace:*` once pnpm supports that. Only a lone `workspace:*`
// works at the moment
const pnpmListJson = await execa('pnpm', [
'--silent',
'--recursive',
'--filter',
'./packages/**',
'list',
'--depth',
'-1',
'--json',
])
const workspacePackages = JSON.parse(pnpmListJson.stdout)
const publishedPackageNames = new Set(
workspacePackages
.filter((workspacePackage) => !workspacePackage.private)
.map((workspacePackage) => workspacePackage.name)
)
for (const workspacePackage of workspacePackages) {
if (workspacePackage.private) {
continue
}
const packageJsonPath = path.join(workspacePackage.path, 'package.json')
const manifest = JSON.parse(await fs.readFile(packageJsonPath, 'utf-8'))
const peerDependencies = manifest.peerDependencies ?? {}
let updated = false
for (const dependencyName of Object.keys(peerDependencies)) {
if (publishedPackageNames.has(dependencyName)) {
peerDependencies[dependencyName] =
`${peerDependencies[dependencyName]} || ${version}`
updated = true
}
}
if (updated) {
await fs.writeFile(packageJsonPath, JSON.stringify(manifest, null, 2))
console.log(
`Appended ${version} to peer dependencies in ${workspacePackage.name}`
)
}
}
}
await publish('workspace', [ await publish('workspace', [
'--filter', '--filter',
'./packages/**', './packages/**',
......
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