2
3
/* eslint-disable no-for-of-loops/no-for-of-loops */
4
5
-const crypto = require('node:crypto');
5
const fs = require('fs');
6
const fse = require('fs-extra');
7
const {spawnSync} = require('child_process');
40
41
// Build the artifacts using a placeholder React version. We'll then do a string
42
// replace to swap it with the correct version per release channel.
44
-const PLACEHOLDER_REACT_VERSION = ReactVersion + '-PLACEHOLDER';
43
+//
44
+// The placeholder version is the same format that the "next" channel uses
45
+const PLACEHOLDER_REACT_VERSION =
46
+ ReactVersion + '-' + canaryChannelLabel + '-' + sha + '-' + dateString;
47
48
// TODO: We should inject the React version using a build-time parameter
49
// instead of overwriting the source files.
160
}
161
162
if (fs.existsSync(buildDir + '/facebook-www')) {
161
- for (const fileName of fs.readdirSync(buildDir + '/facebook-www').sort()) {
163
+ for (const fileName of fs.readdirSync(buildDir + '/facebook-www')) {
164
const filePath = buildDir + '/facebook-www/' + fileName;
165
const stats = fs.statSync(filePath);
166
if (!stats.isDirectory()) {
169
}
170
updatePlaceholderReactVersionInCompiledArtifacts(
171
buildDir + '/facebook-www',
170
- ReactVersion + '-www-classic-%FILEHASH%'
172
+ ReactVersion + '-www-classic-' + sha + '-' + dateString
173
);
174
}
175
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
- );
183
- }
184
- });
185
-
186
- // Update remaining placeholders with canary channel version
187
- updatePlaceholderReactVersionInCompiledArtifacts(
188
- buildDir,
189
- ReactVersion + '-' + canaryChannelLabel + '-' + sha + '-' + dateString
190
- );
191
-
176
if (fs.existsSync(buildDir + '/sizes')) {
177
fs.renameSync(buildDir + '/sizes', buildDir + '/sizes-stable');
178
}
206
}
207
208
if (fs.existsSync(buildDir + '/facebook-www')) {
225
- for (const fileName of fs.readdirSync(buildDir + '/facebook-www').sort()) {
209
+ for (const fileName of fs.readdirSync(buildDir + '/facebook-www')) {
210
const filePath = buildDir + '/facebook-www/' + fileName;
211
const stats = fs.statSync(filePath);
212
if (!stats.isDirectory()) {
215
}
216
updatePlaceholderReactVersionInCompiledArtifacts(
217
buildDir + '/facebook-www',
234
- ReactVersion + '-www-modern-%FILEHASH%'
218
+ ReactVersion + '-www-modern-' + sha + '-' + dateString
219
);
220
}
221
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
-
250
- // Update remaining placeholders with canary channel version
251
- updatePlaceholderReactVersionInCompiledArtifacts(
252
- buildDir,
253
- ReactVersion + '-' + canaryChannelLabel + '-' + sha + '-' + dateString
254
- );
255
-
222
if (fs.existsSync(buildDir + '/sizes')) {
223
fs.renameSync(buildDir + '/sizes', buildDir + '/sizes-experimental');
224
}
328
329
for (const artifactFilename of artifactFilenames) {
330
const originalText = fs.readFileSync(artifactFilename, 'utf8');
365
- const fileHash = crypto.createHash('sha1');
366
- fileHash.update(originalText);
331
const replacedText = originalText.replaceAll(
332
PLACEHOLDER_REACT_VERSION,
369
- newVersion.replace(/%FILEHASH%/g, fileHash.digest('hex').slice(0, 8))
333
+ newVersion
334
);
335
fs.writeFileSync(artifactFilename, replacedText);
336
}