From 175a0790ee98eb3b99c3ece03625631c61e02f25 Mon Sep 17 00:00:00 2001 From: Jan Kassens Date: Mon, 18 Mar 2024 19:45:10 -0400 Subject: [PATCH] Change to content hash for RN canary VERSION strings --- scripts/rollup/build-all-release-channels.js | 32 ++++++++------------ 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/scripts/rollup/build-all-release-channels.js b/scripts/rollup/build-all-release-channels.js index b7427d135bcc6..fed1bb8c460ca 100644 --- a/scripts/rollup/build-all-release-channels.js +++ b/scripts/rollup/build-all-release-channels.js @@ -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( @@ -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); }