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

Change to content hash for RN canary VERSION strings #28582

Merged
merged 1 commit into from
Mar 19, 2024
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: 13 additions & 19 deletions scripts/rollup/build-all-release-channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,25 +173,17 @@ function processStable(buildDir) {
);
}

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));
}
[
buildDir + '/react-native/implementations/',
buildDir + '/facebook-react-native/',
].forEach(reactNativeBuildDir => {
if (fs.existsSync(reactNativeBuildDir)) {
updatePlaceholderReactVersionInCompiledArtifacts(
reactNativeBuildDir,
ReactVersion + '-' + canaryChannelLabel + '-%FILEHASH%'
);
}
updatePlaceholderReactVersionInCompiledArtifacts(
reactNativeBuildDir,
ReactVersion +
'-' +
canaryChannelLabel +
'-' +
hash.digest('hex').slice(0, 8)
);
}
});

// Update remaining placeholders with canary channel version
updatePlaceholderReactVersionInCompiledArtifacts(
Expand Down Expand Up @@ -362,9 +354,11 @@ 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
newVersion.replace(/%FILEHASH%/g, fileHash.digest('hex').slice(0, 8))
);
fs.writeFileSync(artifactFilename, replacedText);
}
Expand Down