Skip to content

Commit cb076b5

Browse files
authored
Change to content hash for RN canary VERSION strings (facebook#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.
1 parent 9c75cd5 commit cb076b5

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed

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

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -173,25 +173,17 @@ function processStable(buildDir) {
173173
);
174174
}
175175

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+
);
185185
}
186-
updatePlaceholderReactVersionInCompiledArtifacts(
187-
reactNativeBuildDir,
188-
ReactVersion +
189-
'-' +
190-
canaryChannelLabel +
191-
'-' +
192-
hash.digest('hex').slice(0, 8)
193-
);
194-
}
186+
});
195187

196188
// Update remaining placeholders with canary channel version
197189
updatePlaceholderReactVersionInCompiledArtifacts(
@@ -362,9 +354,11 @@ function updatePlaceholderReactVersionInCompiledArtifacts(
362354

363355
for (const artifactFilename of artifactFilenames) {
364356
const originalText = fs.readFileSync(artifactFilename, 'utf8');
357+
const fileHash = crypto.createHash('sha1');
358+
fileHash.update(originalText);
365359
const replacedText = originalText.replaceAll(
366360
PLACEHOLDER_REACT_VERSION,
367-
newVersion
361+
newVersion.replace(/%FILEHASH%/g, fileHash.digest('hex').slice(0, 8))
368362
);
369363
fs.writeFileSync(artifactFilename, replacedText);
370364
}

0 commit comments

Comments
 (0)