Skip to content

Commit

Permalink
Revert Build Versions from Content Hash to Commit Hash
Browse files Browse the repository at this point in the history
  • Loading branch information
yungsters committed May 30, 2024
1 parent c2b45ef commit 5d89f8c
Showing 1 changed file with 25 additions and 27 deletions.
52 changes: 25 additions & 27 deletions scripts/rollup/build-all-release-channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,30 +158,40 @@ function processStable(buildDir) {
}

if (fs.existsSync(buildDir + '/facebook-www')) {
const hash = crypto.createHash('sha1');
for (const fileName of fs.readdirSync(buildDir + '/facebook-www').sort()) {
const filePath = buildDir + '/facebook-www/' + fileName;
const stats = fs.statSync(filePath);
if (!stats.isDirectory()) {
hash.update(fs.readFileSync(filePath));
fs.renameSync(filePath, filePath.replace('.js', '.classic.js'));
}
}
updatePlaceholderReactVersionInCompiledArtifacts(
buildDir + '/facebook-www',
ReactVersion + '-www-classic-%FILEHASH%'
ReactVersion + '-www-classic-' + hash.digest('hex').slice(0, 8)
);
}

[
buildDir + '/react-native/implementations/',
buildDir + '/facebook-react-native/',
].forEach(reactNativeBuildDir => {
if (fs.existsSync(reactNativeBuildDir)) {
updatePlaceholderReactVersionInCompiledArtifacts(
reactNativeBuildDir,
ReactVersion + '-' + canaryChannelLabel + '-%FILEHASH%'
);
const reactNativeBuildDir = buildDir + '/react-native/implementations/';
if (fs.existsSync(reactNativeBuildDir)) {
const hash = crypto.createHash('sha1');
for (const fileName of fs.readdirSync(reactNativeBuildDir).sort()) {
const filePath = reactNativeBuildDir + fileName;
const stats = fs.statSync(filePath);
if (!stats.isDirectory()) {
hash.update(fs.readFileSync(filePath));
}
}
});
updatePlaceholderReactVersionInCompiledArtifacts(
reactNativeBuildDir,
ReactVersion +
'-' +
canaryChannelLabel +
'-' +
hash.digest('hex').slice(0, 8)
);
}

// Update remaining placeholders with canary channel version
updatePlaceholderReactVersionInCompiledArtifacts(
Expand Down Expand Up @@ -222,31 +232,21 @@ function processExperimental(buildDir, version) {
}

if (fs.existsSync(buildDir + '/facebook-www')) {
const hash = crypto.createHash('sha1');
for (const fileName of fs.readdirSync(buildDir + '/facebook-www').sort()) {
const filePath = buildDir + '/facebook-www/' + fileName;
const stats = fs.statSync(filePath);
if (!stats.isDirectory()) {
hash.update(fs.readFileSync(filePath));
fs.renameSync(filePath, filePath.replace('.js', '.modern.js'));
}
}
updatePlaceholderReactVersionInCompiledArtifacts(
buildDir + '/facebook-www',
ReactVersion + '-www-modern-%FILEHASH%'
ReactVersion + '-www-modern-' + hash.digest('hex').slice(0, 8)
);
}

[
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,
Expand Down Expand Up @@ -362,11 +362,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);
}
Expand Down

0 comments on commit 5d89f8c

Please sign in to comment.