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

[sync-react] Allow syncing from a React commit (#90283)

parent 09135201
...@@ -19,6 +19,8 @@ const yargs = require('yargs') ...@@ -19,6 +19,8 @@ const yargs = require('yargs')
// //
// Sync from a local checkout of React (requires having React built first): // Sync from a local checkout of React (requires having React built first):
// pnpm run sync-react --version /path/to/react/checkout/ // pnpm run sync-react --version /path/to/react/checkout/
// Sync from a React commit (can be a commit on a PR)
// pnpm run sync-react --version vp:///commit-sha
const repoOwner = 'vercel' const repoOwner = 'vercel'
const repoName = 'next.js' const repoName = 'next.js'
...@@ -57,6 +59,9 @@ async function getSchedulerVersion(reactVersion) { ...@@ -57,6 +59,9 @@ async function getSchedulerVersion(reactVersion) {
if (reactVersion.startsWith('file://')) { if (reactVersion.startsWith('file://')) {
return reactVersion return reactVersion
} }
if (reactVersion.startsWith('vp:')) {
return reactVersion
}
const url = `https://registry.npmjs.org/react-dom/${reactVersion}` const url = `https://registry.npmjs.org/react-dom/${reactVersion}`
const response = await fetch(url, { const response = await fetch(url, {
...@@ -84,6 +89,14 @@ function getPackageVersion(packageName, versionStr) { ...@@ -84,6 +89,14 @@ function getPackageVersion(packageName, versionStr) {
if (versionStr.startsWith('file://')) { if (versionStr.startsWith('file://')) {
return new URL(packageName, versionStr).href return new URL(packageName, versionStr).href
} }
if (versionStr.startsWith('vp:')) {
const { pathname } = new URL(versionStr)
const [, commit, releaseChannel] = pathname.split('/')
return new URL(
`/react/commits/${commit}/${packageName}@${releaseChannel}`,
'https://vercel-packages.vercel.app'
).href
}
return `npm:${packageName}@${versionStr}` return `npm:${packageName}@${versionStr}`
} }
...@@ -139,10 +152,14 @@ async function sync({ channel, newVersionStr, noInstall }) { ...@@ -139,10 +152,14 @@ async function sync({ channel, newVersionStr, noInstall }) {
// TODO: Should be handled like the other React packages // TODO: Should be handled like the other React packages
devDependencies['react-is-builtin'] = newVersionStr.startsWith('file://') devDependencies['react-is-builtin'] = newVersionStr.startsWith('file://')
? new URL('react-is', newVersionStr).href ? new URL('react-is', newVersionStr).href
: `npm:react-is@${newVersionStr}` : newVersionStr.startsWith('vp:')
? getPackageVersion('react-is', newVersionStr)
: `npm:react-is@${newVersionStr}`
pnpmOverrides['react-is'] = newVersionStr.startsWith('file://') pnpmOverrides['react-is'] = newVersionStr.startsWith('file://')
? new URL('react-is', newVersionStr).href ? new URL('react-is', newVersionStr).href
: `npm:react-is@${newVersionStr}` : newVersionStr.startsWith('vp:')
? getPackageVersion('react-is', newVersionStr)
: `npm:react-is@${newVersionStr}`
} }
await fsp.writeFile( await fsp.writeFile(
...@@ -170,6 +187,32 @@ function extractInfoFromReactVersion(versionStr) { ...@@ -170,6 +187,32 @@ function extractInfoFromReactVersion(versionStr) {
sha: 'local', sha: 'local',
} }
} }
if (versionStr.startsWith('vp:')) {
const { pathname } = new URL(versionStr)
const [, commit] = pathname.split('/')
return {
dateString: new Date().toISOString().split('T')[0],
releaseLabel: 'vercel-packages',
semverVersion: '0.0.0',
sha: commit,
}
}
if (versionStr.startsWith('https:')) {
const url = new URL(versionStr)
if (url.hostname === 'vercel-packages.vercel.app') {
// e.g https://vercel-packages.vercel.app/react/commits/bc50ab4bffa17f507386554a8ef3c3ed4f37fe1b/react@canary
const [, , , commit] = url.pathname.split('/')
return {
dateString: new Date().toISOString().split('T')[0],
releaseLabel: `vercel-packages`,
semverVersion: '0.0.0',
sha: commit,
}
}
throw new Error(
`Unsupported URL '${versionStr}'. Only vercel-packages.vercel.app URLs are supported.`
)
}
const match = versionStr.match( const match = versionStr.match(
/(?<semverVersion>.*)-(?<releaseLabel>.*)-(?<sha>.*)-(?<dateString>.*)$/ /(?<semverVersion>.*)-(?<releaseLabel>.*)-(?<sha>.*)-(?<dateString>.*)$/
...@@ -276,7 +319,12 @@ async function main() { ...@@ -276,7 +319,12 @@ async function main() {
'Creates commits for each intermediate step. Useful to create better diffs for GitHub.', 'Creates commits for each intermediate step. Useful to create better diffs for GitHub.',
}) })
.options('install', { default: true, type: 'boolean' }) .options('install', { default: true, type: 'boolean' })
.options('version', { default: null, type: 'string' }).argv .options('version', {
default: null,
type: 'string',
description:
'e.g. 19.3.0-canary-?-? or vp:///commit-sha for a build from a specific React commit (can be a commit on a PR)',
}).argv
let { actor, createPull, commit, install, version } = argv let { actor, createPull, commit, install, version } = argv
if (version !== null && version.startsWith('/')) { if (version !== null && version.startsWith('/')) {
version = pathToFileURL(version).href version = pathToFileURL(version).href
...@@ -334,12 +382,19 @@ Or, run this command with no arguments to use the most recently published versio ...@@ -334,12 +382,19 @@ Or, run this command with no arguments to use the most recently published versio
` `
) )
} }
const { sha: newSha, dateString: newDateString } = newVersionInfo const {
sha: newSha,
const branchName = newVersionStr.startsWith('file://') dateString: newDateString,
? // left to user to name their local sync branch releaseLabel,
`update/react/local` } = newVersionInfo
: `update/react/${newVersionStr}`
const branchName =
releaseLabel === 'local'
? // left to user to name their local sync branch
`update/react/local`
: releaseLabel === 'vercel-packages'
? `update/react/remote/vercel-packages/${newSha}`
: `update/react/${newVersionStr}`
if (createPull) { if (createPull) {
const { exitCode, all, command } = await execa( const { exitCode, all, command } = await execa(
'git', 'git',
...@@ -381,6 +436,9 @@ Or, run this command with no arguments to use the most recently published versio ...@@ -381,6 +436,9 @@ Or, run this command with no arguments to use the most recently published versio
if (version !== null && version.startsWith('file://')) { if (version !== null && version.startsWith('file://')) {
experimentalNewVersionStr = new URL('build/oss-experimental/', version).href experimentalNewVersionStr = new URL('build/oss-experimental/', version).href
newVersionStr = new URL('build/oss-stable/', version).href newVersionStr = new URL('build/oss-stable/', version).href
} else if (releaseLabel === 'vercel-packages') {
experimentalNewVersionStr = `vp:///${newSha}/experimental`
newVersionStr = `vp:///${newSha}/canary`
} }
await sync({ await sync({
......
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