Change to content hash for RN canary VERSION strings (#28582)
With this change, the different files in RN will have *different* hashes. This replaces the git hash and means that the file content (including version) is only updated when the rest of the file content actually changes. This should remove "noop" changes that need to be synced that only update the version string. A difference to the www implementation here is (and I'd be looking at updating www as well if this lands well) that each file has an individual hash instead of a combined content hash. This further reduces the number of updated files and I couldn't find a reason we need to have these in sync. The best I can gather is that this hash is used so folks don't directly compare version string and make future updates harder.
Jan Kassens committed
Mar 19, 2024 at 16:16 UTC
cb076b593cec3a92338958f58468cce19cb8f0d9
1 file changed
+13
-19
scripts/rollup/build-all-release-channels.js
+13
-19
@@ -173,25 +173,17 @@ function processStable(buildDir) {
173
);
174
}
175
176
- const reactNativeBuildDir = buildDir + '/react-native/implementations/';
177
- if (fs.existsSync(reactNativeBuildDir)) {
178
- const hash = crypto.createHash('sha1');
179
- for (const fileName of fs.readdirSync(reactNativeBuildDir).sort()) {
180
- const filePath = reactNativeBuildDir + fileName;
181
- const stats = fs.statSync(filePath);
182
- if (!stats.isDirectory()) {
183
- hash.update(fs.readFileSync(filePath));
184
- }
176
+ [
177
+ buildDir + '/react-native/implementations/',
178
+ buildDir + '/facebook-react-native/',
179
+ ].forEach(reactNativeBuildDir => {
180
+ if (fs.existsSync(reactNativeBuildDir)) {
181
+ updatePlaceholderReactVersionInCompiledArtifacts(
182
+ reactNativeBuildDir,
183
+ ReactVersion + '-' + canaryChannelLabel + '-%FILEHASH%'
184
+ );
185
}
186
- updatePlaceholderReactVersionInCompiledArtifacts(
187
- reactNativeBuildDir,
188
- ReactVersion +
189
- '-' +
190
- canaryChannelLabel +
191
- '-' +
192
- hash.digest('hex').slice(0, 8)
193
- );
194
- }
186
+ });
187
188
// Update remaining placeholders with canary channel version
189
updatePlaceholderReactVersionInCompiledArtifacts(
@@ -362,9 +354,11 @@ function updatePlaceholderReactVersionInCompiledArtifacts(
354
355
for (const artifactFilename of artifactFilenames) {
356
const originalText = fs.readFileSync(artifactFilename, 'utf8');
357
+ const fileHash = crypto.createHash('sha1');
358
+ fileHash.update(originalText);
359
const replacedText = originalText.replaceAll(
360
PLACEHOLDER_REACT_VERSION,
367
- newVersion
361
+ newVersion.replace(/%FILEHASH%/g, fileHash.digest('hex').slice(0, 8))
362
);
363
fs.writeFileSync(artifactFilename, replacedText);
364
}