2
2
3
3
/* eslint-disable no-for-of-loops/no-for-of-loops */
4
4
5
- const crypto = require ( 'node:crypto' ) ;
6
5
const fs = require ( 'fs' ) ;
7
6
const fse = require ( 'fs-extra' ) ;
8
7
const { spawnSync} = require ( 'child_process' ) ;
@@ -41,7 +40,10 @@ if (dateString.startsWith("'")) {
41
40
42
41
// Build the artifacts using a placeholder React version. We'll then do a string
43
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 ;
45
47
46
48
// TODO: We should inject the React version using a build-time parameter
47
49
// instead of overwriting the source files.
@@ -158,7 +160,7 @@ function processStable(buildDir) {
158
160
}
159
161
160
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' ) ) {
162
164
const filePath = buildDir + '/facebook-www/' + fileName ;
163
165
const stats = fs . statSync ( filePath ) ;
164
166
if ( ! stats . isDirectory ( ) ) {
@@ -167,28 +169,10 @@ function processStable(buildDir) {
167
169
}
168
170
updatePlaceholderReactVersionInCompiledArtifacts (
169
171
buildDir + '/facebook-www' ,
170
- ReactVersion + '-www-classic-%FILEHASH%'
172
+ ReactVersion + '-www-classic-' + sha + '-' + dateString
171
173
) ;
172
174
}
173
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
-
192
176
if ( fs . existsSync ( buildDir + '/sizes' ) ) {
193
177
fs . renameSync ( buildDir + '/sizes' , buildDir + '/sizes-stable' ) ;
194
178
}
@@ -222,7 +206,7 @@ function processExperimental(buildDir, version) {
222
206
}
223
207
224
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' ) ) {
226
210
const filePath = buildDir + '/facebook-www/' + fileName ;
227
211
const stats = fs . statSync ( filePath ) ;
228
212
if ( ! stats . isDirectory ( ) ) {
@@ -231,28 +215,10 @@ function processExperimental(buildDir, version) {
231
215
}
232
216
updatePlaceholderReactVersionInCompiledArtifacts (
233
217
buildDir + '/facebook-www' ,
234
- ReactVersion + '-www-modern-%FILEHASH%'
218
+ ReactVersion + '-www-modern-' + sha + '-' + dateString
235
219
) ;
236
220
}
237
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
-
256
222
if ( fs . existsSync ( buildDir + '/sizes' ) ) {
257
223
fs . renameSync ( buildDir + '/sizes' , buildDir + '/sizes-experimental' ) ;
258
224
}
@@ -362,11 +328,9 @@ function updatePlaceholderReactVersionInCompiledArtifacts(
362
328
363
329
for ( const artifactFilename of artifactFilenames ) {
364
330
const originalText = fs . readFileSync ( artifactFilename , 'utf8' ) ;
365
- const fileHash = crypto . createHash ( 'sha1' ) ;
366
- fileHash . update ( originalText ) ;
367
331
const replacedText = originalText . replaceAll (
368
332
PLACEHOLDER_REACT_VERSION ,
369
- newVersion . replace ( / % F I L E H A S H % / g , fileHash . digest ( 'hex' ) . slice ( 0 , 8 ) )
333
+ newVersion
370
334
) ;
371
335
fs . writeFileSync ( artifactFilename , replacedText ) ;
372
336
}
0 commit comments