Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build: use content hash for facebook-react-native build #27577

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions scripts/rollup/build-all-release-channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const fse = require('fs-extra');
const {spawnSync} = require('child_process');
const path = require('path');
const tmp = require('tmp');
const glob = require('glob');

const {
ReactVersion,
Expand Down Expand Up @@ -235,19 +236,28 @@ 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 facebookWwwDir = path.join(buildDir, 'facebook-www');
if (fs.existsSync(facebookWwwDir)) {
for (const fileName of fs.readdirSync(facebookWwwDir).sort()) {
const filePath = path.join(facebookWwwDir, fileName);
const stats = fs.statSync(filePath);
if (!stats.isDirectory()) {
hash.update(fs.readFileSync(filePath));
fs.renameSync(filePath, filePath.replace('.js', '.modern.js'));
}
}
const contentHash = hashJSFilesInDirectory(facebookWwwDir);
updatePlaceholderReactVersionInCompiledArtifacts(
buildDir + '/facebook-www',
ReactVersion + '-www-modern-' + hash.digest('hex').slice(0, 8)
facebookWwwDir,
ReactVersion + '-www-modern-' + contentHash
);
}

const facebookReactNativeDir = path.join(buildDir, 'facebook-react-native');
if (fs.existsSync(facebookReactNativeDir)) {
const contentHash = hashJSFilesInDirectory(facebookReactNativeDir);
updatePlaceholderReactVersionInCompiledArtifacts(
facebookReactNativeDir,
ReactVersion + '-react-native-' + contentHash
);
}

Expand Down Expand Up @@ -346,6 +356,14 @@ function updatePackageVersions(
}
}

function hashJSFilesInDirectory(directory) {
const hash = crypto.createHash('sha1');
for (const filePath of glob.sync(directory + '/**/*.js').sort()) {
hash.update(fs.readFileSync(filePath));
}
return hash.digest('hex').slice(0, 8);
}

Comment on lines +359 to +366
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we hash based on only JS files? Not important now, but hashing on non-directories seems more reliable, in case we will distribute non-js files at some point

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm actually not sure if we even need this version string anyway? I think devtools use them in some capacity, but I'm not sure what the exact requirements are.

function updatePlaceholderReactVersionInCompiledArtifacts(
artifactsDirectory,
newVersion
Expand Down