@samitouri / QOS-React-1 / commits / 16ac71a650

Fix prepare-prerelease script (#31159)

Sebastian "Sebbie" Silbermann committed Oct 10, 2024 at 17:24 UTC 16ac71a650d8ec9f24cd0bd6ebbe9c6d2edf9cb8
3 files changed +63 -56
scripts/release/prepare-release-from-npm-commands/confirm-stable-version-numbers.js
+1 -3
@@ -30,9 +30,7 @@ const run = async ({skipPackages}, versionsMap) => {
30
31 let version = bestGuessVersion;
32 if (
33 - skipPackages.some(skipPackageName =>
34 - packageNames.includes(skipPackageName)
35 - )
33 + skipPackages.some(skipPackageName => packages.includes(skipPackageName))
34 ) {
35 await confirm(
36 theme`{spinnerSuccess ✓} Version for ${packageNames} will remain {version ${bestGuessVersion}}`
scripts/release/prepare-release-from-npm-commands/update-stable-version-numbers.js
+59 -53
@@ -111,62 +111,68 @@ const run = async ({cwd, packages, version}, versionsMap) => {
111
112 clear();
113
114 - // A separate "React version" is used for the embedded renderer version to support DevTools,
115 - // since it needs to distinguish between different version ranges of React.
116 - // We need to replace it as well as the "next" version number.
117 - const buildInfoPath = join(nodeModulesPath, 'react', 'build-info.json');
118 - const {reactVersion} = await readJson(buildInfoPath);
119 -
120 - if (!reactVersion) {
121 - console.error(
122 - theme`{error Unsupported or invalid build metadata in} {path build/node_modules/react/build-info.json}` +
123 - theme`{error . This could indicate that you have specified an outdated "next" version.}`
124 - );
125 - process.exit(1);
126 - }
127 -
128 - // We print the diff to the console for review,
129 - // but it can be large so let's also write it to disk.
130 - const diffPath = join(cwd, 'build', 'temp.diff');
131 - let diff = '';
132 - let numFilesModified = 0;
133 -
134 - // Find-and-replace hardcoded version (in built JS) for renderers.
135 - for (let i = 0; i < packages.length; i++) {
136 - const packageName = packages[i];
137 - const packagePath = join(nodeModulesPath, packageName);
114 + if (packages.includes('react')) {
115 + // A separate "React version" is used for the embedded renderer version to support DevTools,
116 + // since it needs to distinguish between different version ranges of React.
117 + // We need to replace it as well as the "next" version number.
118 + const buildInfoPath = join(nodeModulesPath, 'react', 'build-info.json');
119 + const {reactVersion} = await readJson(buildInfoPath);
120 +
121 + if (!reactVersion) {
122 + console.error(
123 + theme`{error Unsupported or invalid build metadata in} {path build/node_modules/react/build-info.json}` +
124 + theme`{error . This could indicate that you have specified an outdated "next" version.}`
125 + );
126 + process.exit(1);
127 + }
128
139 - let files = await execRead(
140 - `find ${packagePath} -name '*.js' -exec echo {} \\;`,
141 - {cwd}
129 + // We print the diff to the console for review,
130 + // but it can be large so let's also write it to disk.
131 + const diffPath = join(cwd, 'build', 'temp.diff');
132 + let diff = '';
133 + let numFilesModified = 0;
134 +
135 + // Find-and-replace hardcoded version (in built JS) for renderers.
136 + for (let i = 0; i < packages.length; i++) {
137 + const packageName = packages[i];
138 + const packagePath = join(nodeModulesPath, packageName);
139 +
140 + let files = await execRead(
141 + `find ${packagePath} -name '*.js' -exec echo {} \\;`,
142 + {cwd}
143 + );
144 + files = files.split('\n');
145 + files.forEach(path => {
146 + const newStableVersion = versionsMap.get(packageName);
147 + const beforeContents = readFileSync(path, 'utf8', {cwd});
148 + let afterContents = beforeContents;
149 + // Replace all "next" version numbers (e.g. header @license).
150 + while (afterContents.indexOf(version) >= 0) {
151 + afterContents = afterContents.replace(version, newStableVersion);
152 + }
153 + // Replace inline renderer version numbers (e.g. shared/ReactVersion).
154 + while (afterContents.indexOf(reactVersion) >= 0) {
155 + afterContents = afterContents.replace(reactVersion, newStableVersion);
156 + }
157 + if (beforeContents !== afterContents) {
158 + numFilesModified++;
159 + // Using a relative path for diff helps with the snapshot test
160 + diff += printDiff(relative(cwd, path), beforeContents, afterContents);
161 + writeFileSync(path, afterContents, {cwd});
162 + }
163 + });
164 + }
165 + writeFileSync(diffPath, diff, {cwd});
166 + console.log(theme.header(`\n${numFilesModified} files have been updated.`));
167 + console.log(
168 + theme`A full diff is available at {path ${relative(cwd, diffPath)}}.`
169 + );
170 + await confirm('Do the changes above look correct?');
171 + } else {
172 + console.log(
173 + theme`Skipping React renderer version update because React is not included in the release.`
174 );
143 - files = files.split('\n');
144 - files.forEach(path => {
145 - const newStableVersion = versionsMap.get(packageName);
146 - const beforeContents = readFileSync(path, 'utf8', {cwd});
147 - let afterContents = beforeContents;
148 - // Replace all "next" version numbers (e.g. header @license).
149 - while (afterContents.indexOf(version) >= 0) {
150 - afterContents = afterContents.replace(version, newStableVersion);
151 - }
152 - // Replace inline renderer version numbers (e.g. shared/ReactVersion).
153 - while (afterContents.indexOf(reactVersion) >= 0) {
154 - afterContents = afterContents.replace(reactVersion, newStableVersion);
155 - }
156 - if (beforeContents !== afterContents) {
157 - numFilesModified++;
158 - // Using a relative path for diff helps with the snapshot test
159 - diff += printDiff(relative(cwd, path), beforeContents, afterContents);
160 - writeFileSync(path, afterContents, {cwd});
161 - }
162 - });
175 }
164 - writeFileSync(diffPath, diff, {cwd});
165 - console.log(theme.header(`\n${numFilesModified} files have been updated.`));
166 - console.log(
167 - theme`A full diff is available at {path ${relative(cwd, diffPath)}}.`
168 - );
169 - await confirm('Do the changes above look correct?');
176
177 clear();
178 };
scripts/release/prepare-release-from-npm.js
+3
@@ -27,6 +27,9 @@ const run = async () => {
27 }
28
29 params.packages = await getPublicPackages(isExperimental);
30 + params.packages = params.packages.filter(packageName => {
31 + return !params.skipPackages.includes(packageName);
32 + });
33
34 // Map of package name to upcoming stable version.
35 // This Map is initially populated with guesses based on local versions.