Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
0fc762c7
Unverified
Commit
0fc762c7
authored
Aug 22, 2024
by
Sebastian "Sebbie" Silbermann
Committed by
GitHub
Aug 22, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sync-react: Automatically update all references to the React peer dependency version (#69194)
parent
e1b889fd
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
91 additions
and
7 deletions
+91
-7
index.ts
packages/create-next-app/templates/index.ts
+6
-2
run-tests.js
run-tests.js
+5
-1
sync-react.js
scripts/sync-react.js
+75
-3
base.ts
test/lib/next-modes/base.ts
+5
-1
No files found.
packages/create-next-app/templates/index.ts
View file @
0fc762c7
...
@@ -11,6 +11,10 @@ import pkg from "../package.json";
...
@@ -11,6 +11,10 @@ import pkg from "../package.json";
import
{
GetTemplateFileArgs
,
InstallTemplateArgs
}
from
"./types"
;
import
{
GetTemplateFileArgs
,
InstallTemplateArgs
}
from
"./types"
;
// Do not rename or format. sync-react script relies on this line.
// prettier-ignore
const
nextjsReactPeerVersion
=
"19.0.0-rc-1eaccd82-20240816"
;
/**
/**
* Get the file path for a given file in a template, e.g. "next.config.js".
* Get the file path for a given file in a template, e.g. "next.config.js".
*/
*/
...
@@ -184,8 +188,8 @@ export const installTemplate = async ({
...
@@ -184,8 +188,8 @@ export const installTemplate = async ({
* Default dependencies.
* Default dependencies.
*/
*/
dependencies
:
{
dependencies
:
{
react
:
"19.0.0-rc-1eaccd82-20240816"
,
react
:
nextjsReactPeerVersion
,
"react-dom"
:
"19.0.0-rc-1eaccd82-20240816"
,
"react-dom"
:
nextjsReactPeerVersion
,
next
:
version
,
next
:
version
,
},
},
devDependencies
:
{},
devDependencies
:
{},
...
...
run-tests.js
View file @
0fc762c7
...
@@ -18,6 +18,10 @@ const exec = promisify(execOrig)
...
@@ -18,6 +18,10 @@ const exec = promisify(execOrig)
const
core
=
require
(
'@actions/core'
)
const
core
=
require
(
'@actions/core'
)
const
{
getTestFilter
}
=
require
(
'./test/get-test-filter'
)
const
{
getTestFilter
}
=
require
(
'./test/get-test-filter'
)
// Do not rename or format. sync-react script relies on this line.
// prettier-ignore
const
nextjsReactPeerVersion
=
"19.0.0-rc-1eaccd82-20240816"
;
let
argv
=
require
(
'yargs/yargs'
)(
process
.
argv
.
slice
(
2
))
let
argv
=
require
(
'yargs/yargs'
)(
process
.
argv
.
slice
(
2
))
.
string
(
'type'
)
.
string
(
'type'
)
.
string
(
'test-pattern'
)
.
string
(
'test-pattern'
)
...
@@ -409,7 +413,7 @@ ${ENDGROUP}`)
...
@@ -409,7 +413,7 @@ ${ENDGROUP}`)
// run `pnpm install` each time.
// run `pnpm install` each time.
console
.
log
(
`
${
GROUP
}
Creating shared Next.js install`
)
console
.
log
(
`
${
GROUP
}
Creating shared Next.js install`
)
const
reactVersion
=
const
reactVersion
=
process
.
env
.
NEXT_TEST_REACT_VERSION
||
'19.0.0-rc-1eaccd82-20240816'
process
.
env
.
NEXT_TEST_REACT_VERSION
||
nextjsReactPeerVersion
const
{
installDir
,
pkgPaths
,
tmpRepoDir
}
=
await
createNextInstall
({
const
{
installDir
,
pkgPaths
,
tmpRepoDir
}
=
await
createNextInstall
({
parentSpan
:
mockTrace
(),
parentSpan
:
mockTrace
(),
dependencies
:
{
dependencies
:
{
...
...
scripts/sync-react.js
View file @
0fc762c7
...
@@ -7,6 +7,19 @@ const execa = require('execa')
...
@@ -7,6 +7,19 @@ const execa = require('execa')
/** @type {any} */
/** @type {any} */
const
fetch
=
require
(
'node-fetch'
)
const
fetch
=
require
(
'node-fetch'
)
const
filesReferencingReactPeerDependencyVersion
=
[
'run-tests.js'
,
'packages/create-next-app/templates/index.ts'
,
'test/lib/next-modes/base.ts'
,
]
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
'test/e2e/next-test/first-time-setup-js/package.json'
,
'test/e2e/next-test/first-time-setup-ts/package.json'
,
]
// Use this script to update Next's vendored copy of React and related packages:
// Use this script to update Next's vendored copy of React and related packages:
//
//
// Basic usage (defaults to most recent React canary version):
// Basic usage (defaults to most recent React canary version):
...
@@ -15,7 +28,9 @@ const fetch = require('node-fetch')
...
@@ -15,7 +28,9 @@ const fetch = require('node-fetch')
// Update package.json but skip installing the dependencies automatically:
// Update package.json but skip installing the dependencies automatically:
// pnpm run sync-react --no-install
// pnpm run sync-react --no-install
async
function
sync
(
channel
=
'next'
)
{
async
function
sync
({
channel
,
useAsPeerDependency
})
{
const
errors
=
[]
const
noInstall
=
readBoolArg
(
process
.
argv
,
'no-install'
)
const
noInstall
=
readBoolArg
(
process
.
argv
,
'no-install'
)
const
useExperimental
=
channel
===
'experimental'
const
useExperimental
=
channel
===
'experimental'
let
newVersionStr
=
readStringArg
(
process
.
argv
,
'version'
)
let
newVersionStr
=
readStringArg
(
process
.
argv
,
'version'
)
...
@@ -110,6 +125,58 @@ Or, run this command with no arguments to use the most recently published versio
...
@@ -110,6 +125,58 @@ Or, run this command with no arguments to use the most recently published versio
)
)
console
.
log
(
'Successfully updated React dependencies in package.json.
\
n'
)
console
.
log
(
'Successfully updated React dependencies in package.json.
\
n'
)
if
(
useAsPeerDependency
)
{
for
(
const
fileName
of
filesReferencingReactPeerDependencyVersion
)
{
const
filePath
=
path
.
join
(
cwd
,
fileName
)
const
previousSource
=
await
fsp
.
readFile
(
filePath
,
'utf-8'
)
const
updatedSource
=
previousSource
.
replace
(
`const nextjsReactPeerVersion = "
${
baseVersionStr
}
";`
,
`const nextjsReactPeerVersion = "
${
newVersionStr
}
";`
)
if
(
updatedSource
===
previousSource
)
{
errors
.
push
(
new
Error
(
`
${
fileName
}
: Failed to update
${
baseVersionStr
}
to
${
newVersionStr
}
. Is this file still referencing the React peer dependency version?`
)
)
}
else
{
await
fsp
.
writeFile
(
filePath
,
updatedSource
)
}
}
const
nextjsPackageJsonPath
=
path
.
join
(
cwd
,
'packages'
,
'next'
,
'package.json'
)
const
nextjsPackageJson
=
JSON
.
parse
(
await
fsp
.
readFile
(
nextjsPackageJsonPath
,
'utf-8'
)
)
nextjsPackageJson
.
peerDependencies
.
react
=
`
${
newVersionStr
}
`
nextjsPackageJson
.
peerDependencies
[
'react-dom'
]
=
`
${
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'
)
const
manifest
=
JSON
.
parse
(
packageJson
)
manifest
.
dependencies
[
'react'
]
=
newVersionStr
manifest
.
dependencies
[
'react-dom'
]
=
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'
)
}
}
// Install the updated dependencies and build the vendored React files.
// Install the updated dependencies and build the vendored React files.
if
(
noInstall
)
{
if
(
noInstall
)
{
console
.
log
(
'Skipping install step because --no-install flag was passed.
\
n'
)
console
.
log
(
'Skipping install step because --no-install flag was passed.
\
n'
)
...
@@ -179,6 +246,11 @@ Or run this command again without the --no-install flag to do both automatically
...
@@ -179,6 +246,11 @@ Or run this command again without the --no-install flag to do both automatically
await
fsp
.
writeFile
(
path
.
join
(
cwd
,
'.github/.react-version'
),
newVersionStr
)
await
fsp
.
writeFile
(
path
.
join
(
cwd
,
'.github/.react-version'
),
newVersionStr
)
if
(
errors
.
length
)
{
// eslint-disable-next-line no-undef -- Defined in Node.js
throw
new
AggregateError
(
errors
)
}
console
.
log
(
console
.
log
(
`Successfully updated React from
${
baseSha
}
to
${
newSha
}
.\n`
+
`Successfully updated React from
${
baseSha
}
to
${
newSha
}
.\n`
+
`Don't forget to find & replace all references to the React version '
${
baseVersionStr
}
' with '
${
newVersionStr
}
':\n`
+
`Don't forget to find & replace all references to the React version '
${
baseVersionStr
}
' with '
${
newVersionStr
}
':\n`
+
...
@@ -255,8 +327,8 @@ async function getChangelogFromGitHub(baseSha, newSha) {
...
@@ -255,8 +327,8 @@ async function getChangelogFromGitHub(baseSha, newSha) {
return
changelog
.
length
>
0
?
changelog
.
join
(
'
\
n'
)
:
null
return
changelog
.
length
>
0
?
changelog
.
join
(
'
\
n'
)
:
null
}
}
sync
(
'experimental'
)
sync
(
{
channel
:
'experimental'
,
useAsPeerDependency
:
false
}
)
.
then
(()
=>
sync
(
'rc'
))
.
then
(()
=>
sync
(
{
channel
:
'rc'
,
useAsPeerDependency
:
true
}
))
.
catch
((
error
)
=>
{
.
catch
((
error
)
=>
{
console
.
error
(
error
)
console
.
error
(
error
)
process
.
exit
(
1
)
process
.
exit
(
1
)
...
...
test/lib/next-modes/base.ts
View file @
0fc762c7
...
@@ -49,6 +49,10 @@ type OmitFirstArgument<F> = F extends (
...
@@ -49,6 +49,10 @@ type OmitFirstArgument<F> = F extends (
?
(...
args
:
P
)
=>
R
?
(...
args
:
P
)
=>
R
:
never
:
never
// Do not rename or format. sync-react script relies on this line.
// prettier-ignore
const
nextjsReactPeerVersion
=
"19.0.0-rc-1eaccd82-20240816"
;
export
class
NextInstance
{
export
class
NextInstance
{
protected
files
:
FileRef
|
{
[
filename
:
string
]:
string
|
FileRef
}
protected
files
:
FileRef
|
{
[
filename
:
string
]:
string
|
FileRef
}
protected
nextConfig
?:
NextConfig
protected
nextConfig
?:
NextConfig
...
@@ -163,7 +167,7 @@ export class NextInstance {
...
@@ -163,7 +167,7 @@ export class NextInstance {
)
)
const
reactVersion
=
const
reactVersion
=
process
.
env
.
NEXT_TEST_REACT_VERSION
||
'19.0.0-rc-1eaccd82-20240816'
process
.
env
.
NEXT_TEST_REACT_VERSION
||
nextjsReactPeerVersion
const
finalDependencies
=
{
const
finalDependencies
=
{
react
:
reactVersion
,
react
:
reactVersion
,
'react-dom'
:
reactVersion
,
'react-dom'
:
reactVersion
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment