Skip to content

Commit

Permalink
Fix prepare-prerelease script (#31159)
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon authored Oct 10, 2024
1 parent b781c9f commit 16ac71a
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ const run = async ({skipPackages}, versionsMap) => {

let version = bestGuessVersion;
if (
skipPackages.some(skipPackageName =>
packageNames.includes(skipPackageName)
)
skipPackages.some(skipPackageName => packages.includes(skipPackageName))
) {
await confirm(
theme`{spinnerSuccess ✓} Version for ${packageNames} will remain {version ${bestGuessVersion}}`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,62 +111,68 @@ const run = async ({cwd, packages, version}, versionsMap) => {

clear();

// A separate "React version" is used for the embedded renderer version to support DevTools,
// since it needs to distinguish between different version ranges of React.
// We need to replace it as well as the "next" version number.
const buildInfoPath = join(nodeModulesPath, 'react', 'build-info.json');
const {reactVersion} = await readJson(buildInfoPath);

if (!reactVersion) {
console.error(
theme`{error Unsupported or invalid build metadata in} {path build/node_modules/react/build-info.json}` +
theme`{error . This could indicate that you have specified an outdated "next" version.}`
);
process.exit(1);
}

// We print the diff to the console for review,
// but it can be large so let's also write it to disk.
const diffPath = join(cwd, 'build', 'temp.diff');
let diff = '';
let numFilesModified = 0;

// Find-and-replace hardcoded version (in built JS) for renderers.
for (let i = 0; i < packages.length; i++) {
const packageName = packages[i];
const packagePath = join(nodeModulesPath, packageName);
if (packages.includes('react')) {
// A separate "React version" is used for the embedded renderer version to support DevTools,
// since it needs to distinguish between different version ranges of React.
// We need to replace it as well as the "next" version number.
const buildInfoPath = join(nodeModulesPath, 'react', 'build-info.json');
const {reactVersion} = await readJson(buildInfoPath);

if (!reactVersion) {
console.error(
theme`{error Unsupported or invalid build metadata in} {path build/node_modules/react/build-info.json}` +
theme`{error . This could indicate that you have specified an outdated "next" version.}`
);
process.exit(1);
}

let files = await execRead(
`find ${packagePath} -name '*.js' -exec echo {} \\;`,
{cwd}
// We print the diff to the console for review,
// but it can be large so let's also write it to disk.
const diffPath = join(cwd, 'build', 'temp.diff');
let diff = '';
let numFilesModified = 0;

// Find-and-replace hardcoded version (in built JS) for renderers.
for (let i = 0; i < packages.length; i++) {
const packageName = packages[i];
const packagePath = join(nodeModulesPath, packageName);

let files = await execRead(
`find ${packagePath} -name '*.js' -exec echo {} \\;`,
{cwd}
);
files = files.split('\n');
files.forEach(path => {
const newStableVersion = versionsMap.get(packageName);
const beforeContents = readFileSync(path, 'utf8', {cwd});
let afterContents = beforeContents;
// Replace all "next" version numbers (e.g. header @license).
while (afterContents.indexOf(version) >= 0) {
afterContents = afterContents.replace(version, newStableVersion);
}
// Replace inline renderer version numbers (e.g. shared/ReactVersion).
while (afterContents.indexOf(reactVersion) >= 0) {
afterContents = afterContents.replace(reactVersion, newStableVersion);
}
if (beforeContents !== afterContents) {
numFilesModified++;
// Using a relative path for diff helps with the snapshot test
diff += printDiff(relative(cwd, path), beforeContents, afterContents);
writeFileSync(path, afterContents, {cwd});
}
});
}
writeFileSync(diffPath, diff, {cwd});
console.log(theme.header(`\n${numFilesModified} files have been updated.`));
console.log(
theme`A full diff is available at {path ${relative(cwd, diffPath)}}.`
);
await confirm('Do the changes above look correct?');
} else {
console.log(
theme`Skipping React renderer version update because React is not included in the release.`
);
files = files.split('\n');
files.forEach(path => {
const newStableVersion = versionsMap.get(packageName);
const beforeContents = readFileSync(path, 'utf8', {cwd});
let afterContents = beforeContents;
// Replace all "next" version numbers (e.g. header @license).
while (afterContents.indexOf(version) >= 0) {
afterContents = afterContents.replace(version, newStableVersion);
}
// Replace inline renderer version numbers (e.g. shared/ReactVersion).
while (afterContents.indexOf(reactVersion) >= 0) {
afterContents = afterContents.replace(reactVersion, newStableVersion);
}
if (beforeContents !== afterContents) {
numFilesModified++;
// Using a relative path for diff helps with the snapshot test
diff += printDiff(relative(cwd, path), beforeContents, afterContents);
writeFileSync(path, afterContents, {cwd});
}
});
}
writeFileSync(diffPath, diff, {cwd});
console.log(theme.header(`\n${numFilesModified} files have been updated.`));
console.log(
theme`A full diff is available at {path ${relative(cwd, diffPath)}}.`
);
await confirm('Do the changes above look correct?');

clear();
};
Expand Down
3 changes: 3 additions & 0 deletions scripts/release/prepare-release-from-npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ const run = async () => {
}

params.packages = await getPublicPackages(isExperimental);
params.packages = params.packages.filter(packageName => {
return !params.skipPackages.includes(packageName);
});

// Map of package name to upcoming stable version.
// This Map is initially populated with guesses based on local versions.
Expand Down

0 comments on commit 16ac71a

Please sign in to comment.