Skip to content

Commit 51ffd35

Browse files
authored
Build: use content hash for facebook-react-native build (#27577)
Similar to #26734, this switches the RN builds for Meta to a content hash instead of git commit number to make the builds reproducible and avoid creating sync commits if the bundled content didn't change.
1 parent 960ed6e commit 51ffd35

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

scripts/rollup/build-all-release-channels.js

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const fse = require('fs-extra');
88
const {spawnSync} = require('child_process');
99
const path = require('path');
1010
const tmp = require('tmp');
11+
const glob = require('glob');
1112

1213
const {
1314
ReactVersion,
@@ -235,19 +236,28 @@ function processExperimental(buildDir, version) {
235236
);
236237
}
237238

238-
if (fs.existsSync(buildDir + '/facebook-www')) {
239-
const hash = crypto.createHash('sha1');
240-
for (const fileName of fs.readdirSync(buildDir + '/facebook-www').sort()) {
241-
const filePath = buildDir + '/facebook-www/' + fileName;
239+
const facebookWwwDir = path.join(buildDir, 'facebook-www');
240+
if (fs.existsSync(facebookWwwDir)) {
241+
for (const fileName of fs.readdirSync(facebookWwwDir).sort()) {
242+
const filePath = path.join(facebookWwwDir, fileName);
242243
const stats = fs.statSync(filePath);
243244
if (!stats.isDirectory()) {
244-
hash.update(fs.readFileSync(filePath));
245245
fs.renameSync(filePath, filePath.replace('.js', '.modern.js'));
246246
}
247247
}
248+
const contentHash = hashJSFilesInDirectory(facebookWwwDir);
248249
updatePlaceholderReactVersionInCompiledArtifacts(
249-
buildDir + '/facebook-www',
250-
ReactVersion + '-www-modern-' + hash.digest('hex').slice(0, 8)
250+
facebookWwwDir,
251+
ReactVersion + '-www-modern-' + contentHash
252+
);
253+
}
254+
255+
const facebookReactNativeDir = path.join(buildDir, 'facebook-react-native');
256+
if (fs.existsSync(facebookReactNativeDir)) {
257+
const contentHash = hashJSFilesInDirectory(facebookReactNativeDir);
258+
updatePlaceholderReactVersionInCompiledArtifacts(
259+
facebookReactNativeDir,
260+
ReactVersion + '-react-native-' + contentHash
251261
);
252262
}
253263

@@ -346,6 +356,14 @@ function updatePackageVersions(
346356
}
347357
}
348358

359+
function hashJSFilesInDirectory(directory) {
360+
const hash = crypto.createHash('sha1');
361+
for (const filePath of glob.sync(directory + '/**/*.js').sort()) {
362+
hash.update(fs.readFileSync(filePath));
363+
}
364+
return hash.digest('hex').slice(0, 8);
365+
}
366+
349367
function updatePlaceholderReactVersionInCompiledArtifacts(
350368
artifactsDirectory,
351369
newVersion

0 commit comments

Comments
 (0)