Skip to content

Commit 5d89f8c

Browse files
committed
Revert Build Versions from Content Hash to Commit Hash
1 parent c2b45ef commit 5d89f8c

File tree

1 file changed

+25
-27
lines changed

1 file changed

+25
-27
lines changed

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

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -158,30 +158,40 @@ function processStable(buildDir) {
158158
}
159159

160160
if (fs.existsSync(buildDir + '/facebook-www')) {
161+
const hash = crypto.createHash('sha1');
161162
for (const fileName of fs.readdirSync(buildDir + '/facebook-www').sort()) {
162163
const filePath = buildDir + '/facebook-www/' + fileName;
163164
const stats = fs.statSync(filePath);
164165
if (!stats.isDirectory()) {
166+
hash.update(fs.readFileSync(filePath));
165167
fs.renameSync(filePath, filePath.replace('.js', '.classic.js'));
166168
}
167169
}
168170
updatePlaceholderReactVersionInCompiledArtifacts(
169171
buildDir + '/facebook-www',
170-
ReactVersion + '-www-classic-%FILEHASH%'
172+
ReactVersion + '-www-classic-' + hash.digest('hex').slice(0, 8)
171173
);
172174
}
173175

174-
[
175-
buildDir + '/react-native/implementations/',
176-
buildDir + '/facebook-react-native/',
177-
].forEach(reactNativeBuildDir => {
178-
if (fs.existsSync(reactNativeBuildDir)) {
179-
updatePlaceholderReactVersionInCompiledArtifacts(
180-
reactNativeBuildDir,
181-
ReactVersion + '-' + canaryChannelLabel + '-%FILEHASH%'
182-
);
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+
}
183185
}
184-
});
186+
updatePlaceholderReactVersionInCompiledArtifacts(
187+
reactNativeBuildDir,
188+
ReactVersion +
189+
'-' +
190+
canaryChannelLabel +
191+
'-' +
192+
hash.digest('hex').slice(0, 8)
193+
);
194+
}
185195

186196
// Update remaining placeholders with canary channel version
187197
updatePlaceholderReactVersionInCompiledArtifacts(
@@ -222,31 +232,21 @@ function processExperimental(buildDir, version) {
222232
}
223233

224234
if (fs.existsSync(buildDir + '/facebook-www')) {
235+
const hash = crypto.createHash('sha1');
225236
for (const fileName of fs.readdirSync(buildDir + '/facebook-www').sort()) {
226237
const filePath = buildDir + '/facebook-www/' + fileName;
227238
const stats = fs.statSync(filePath);
228239
if (!stats.isDirectory()) {
240+
hash.update(fs.readFileSync(filePath));
229241
fs.renameSync(filePath, filePath.replace('.js', '.modern.js'));
230242
}
231243
}
232244
updatePlaceholderReactVersionInCompiledArtifacts(
233245
buildDir + '/facebook-www',
234-
ReactVersion + '-www-modern-%FILEHASH%'
246+
ReactVersion + '-www-modern-' + hash.digest('hex').slice(0, 8)
235247
);
236248
}
237249

238-
[
239-
buildDir + '/react-native/implementations/',
240-
buildDir + '/facebook-react-native/',
241-
].forEach(reactNativeBuildDir => {
242-
if (fs.existsSync(reactNativeBuildDir)) {
243-
updatePlaceholderReactVersionInCompiledArtifacts(
244-
reactNativeBuildDir,
245-
ReactVersion + '-' + canaryChannelLabel + '-%FILEHASH%'
246-
);
247-
}
248-
});
249-
250250
// Update remaining placeholders with canary channel version
251251
updatePlaceholderReactVersionInCompiledArtifacts(
252252
buildDir,
@@ -362,11 +362,9 @@ function updatePlaceholderReactVersionInCompiledArtifacts(
362362

363363
for (const artifactFilename of artifactFilenames) {
364364
const originalText = fs.readFileSync(artifactFilename, 'utf8');
365-
const fileHash = crypto.createHash('sha1');
366-
fileHash.update(originalText);
367365
const replacedText = originalText.replaceAll(
368366
PLACEHOLDER_REACT_VERSION,
369-
newVersion.replace(/%FILEHASH%/g, fileHash.digest('hex').slice(0, 8))
367+
newVersion
370368
);
371369
fs.writeFileSync(artifactFilename, replacedText);
372370
}

0 commit comments

Comments
 (0)