Revert Build Versions from Content Hash to Commit Hash (#29663)

https://github.com/facebook/react/pull/29236 caused issues for internal
syncs at Meta, because we were computing version numbers using file
hashes (to eliminate "no-op" internal sync commits). The problem is that
since version numbers may not be consistent across synced files (e.g. if
some files have not changed in recent commits), the newly introduced
version mismatch check fails.

There's some more work that needs to be done here to restore the
benefits of file-specific hashing, but for now this simply reverts the
content hash changes from the following PRs:

- https://github.com/facebook/react/pull/28633
(80b7ef781b)
- https://github.com/facebook/react/pull/28590
(e39ba5e6dc)
- https://github.com/facebook/react/pull/28582
(3cf34f5fdf)
- https://github.com/facebook/react/pull/26734
(2364dbe131)
- https://github.com/facebook/react/pull/26331
(c85f644468)
This commit is contained in:
Timothy Yung
2024-05-30 07:26:12 -07:00
committed by GitHub
parent 8e63197453
commit 06be6e2d64
2 changed files with 12 additions and 65 deletions
+9 -45
View File
@@ -2,7 +2,6 @@
/* eslint-disable no-for-of-loops/no-for-of-loops */
const crypto = require('node:crypto');
const fs = require('fs');
const fse = require('fs-extra');
const {spawnSync} = require('child_process');
@@ -41,7 +40,10 @@ if (dateString.startsWith("'")) {
// Build the artifacts using a placeholder React version. We'll then do a string
// replace to swap it with the correct version per release channel.
const PLACEHOLDER_REACT_VERSION = ReactVersion + '-PLACEHOLDER';
//
// The placeholder version is the same format that the "next" channel uses
const PLACEHOLDER_REACT_VERSION =
ReactVersion + '-' + canaryChannelLabel + '-' + sha + '-' + dateString;
// TODO: We should inject the React version using a build-time parameter
// instead of overwriting the source files.
@@ -158,7 +160,7 @@ function processStable(buildDir) {
}
if (fs.existsSync(buildDir + '/facebook-www')) {
for (const fileName of fs.readdirSync(buildDir + '/facebook-www').sort()) {
for (const fileName of fs.readdirSync(buildDir + '/facebook-www')) {
const filePath = buildDir + '/facebook-www/' + fileName;
const stats = fs.statSync(filePath);
if (!stats.isDirectory()) {
@@ -167,28 +169,10 @@ function processStable(buildDir) {
}
updatePlaceholderReactVersionInCompiledArtifacts(
buildDir + '/facebook-www',
ReactVersion + '-www-classic-%FILEHASH%'
ReactVersion + '-www-classic-' + sha + '-' + dateString
);
}
[
buildDir + '/react-native/implementations/',
buildDir + '/facebook-react-native/',
].forEach(reactNativeBuildDir => {
if (fs.existsSync(reactNativeBuildDir)) {
updatePlaceholderReactVersionInCompiledArtifacts(
reactNativeBuildDir,
ReactVersion + '-' + canaryChannelLabel + '-%FILEHASH%'
);
}
});
// Update remaining placeholders with canary channel version
updatePlaceholderReactVersionInCompiledArtifacts(
buildDir,
ReactVersion + '-' + canaryChannelLabel + '-' + sha + '-' + dateString
);
if (fs.existsSync(buildDir + '/sizes')) {
fs.renameSync(buildDir + '/sizes', buildDir + '/sizes-stable');
}
@@ -222,7 +206,7 @@ function processExperimental(buildDir, version) {
}
if (fs.existsSync(buildDir + '/facebook-www')) {
for (const fileName of fs.readdirSync(buildDir + '/facebook-www').sort()) {
for (const fileName of fs.readdirSync(buildDir + '/facebook-www')) {
const filePath = buildDir + '/facebook-www/' + fileName;
const stats = fs.statSync(filePath);
if (!stats.isDirectory()) {
@@ -231,28 +215,10 @@ function processExperimental(buildDir, version) {
}
updatePlaceholderReactVersionInCompiledArtifacts(
buildDir + '/facebook-www',
ReactVersion + '-www-modern-%FILEHASH%'
ReactVersion + '-www-modern-' + sha + '-' + dateString
);
}
[
buildDir + '/react-native/implementations/',
buildDir + '/facebook-react-native/',
].forEach(reactNativeBuildDir => {
if (fs.existsSync(reactNativeBuildDir)) {
updatePlaceholderReactVersionInCompiledArtifacts(
reactNativeBuildDir,
ReactVersion + '-' + canaryChannelLabel + '-%FILEHASH%'
);
}
});
// Update remaining placeholders with canary channel version
updatePlaceholderReactVersionInCompiledArtifacts(
buildDir,
ReactVersion + '-' + canaryChannelLabel + '-' + sha + '-' + dateString
);
if (fs.existsSync(buildDir + '/sizes')) {
fs.renameSync(buildDir + '/sizes', buildDir + '/sizes-experimental');
}
@@ -362,11 +328,9 @@ function updatePlaceholderReactVersionInCompiledArtifacts(
for (const artifactFilename of artifactFilenames) {
const originalText = fs.readFileSync(artifactFilename, 'utf8');
const fileHash = crypto.createHash('sha1');
fileHash.update(originalText);
const replacedText = originalText.replaceAll(
PLACEHOLDER_REACT_VERSION,
newVersion.replace(/%FILEHASH%/g, fileHash.digest('hex').slice(0, 8))
newVersion
);
fs.writeFileSync(artifactFilename, replacedText);
}