22
33/* eslint-disable no-for-of-loops/no-for-of-loops */
44
5- const crypto = require ( 'node:crypto' ) ;
65const fs = require ( 'fs' ) ;
76const fse = require ( 'fs-extra' ) ;
87const { spawnSync} = require ( 'child_process' ) ;
@@ -41,7 +40,10 @@ if (dateString.startsWith("'")) {
4140
4241// Build the artifacts using a placeholder React version. We'll then do a string
4342// 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 ;
4547
4648// TODO: We should inject the React version using a build-time parameter
4749// instead of overwriting the source files.
@@ -158,7 +160,7 @@ function processStable(buildDir) {
158160 }
159161
160162 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' ) ) {
162164 const filePath = buildDir + '/facebook-www/' + fileName ;
163165 const stats = fs . statSync ( filePath ) ;
164166 if ( ! stats . isDirectory ( ) ) {
@@ -167,28 +169,10 @@ function processStable(buildDir) {
167169 }
168170 updatePlaceholderReactVersionInCompiledArtifacts (
169171 buildDir + '/facebook-www' ,
170- ReactVersion + '-www-classic-%FILEHASH%'
172+ ReactVersion + '-www-classic-' + sha + '-' + dateString
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- ) ;
183- }
184- } ) ;
185-
186- // Update remaining placeholders with canary channel version
187- updatePlaceholderReactVersionInCompiledArtifacts (
188- buildDir ,
189- ReactVersion + '-' + canaryChannelLabel + '-' + sha + '-' + dateString
190- ) ;
191-
192176 if ( fs . existsSync ( buildDir + '/sizes' ) ) {
193177 fs . renameSync ( buildDir + '/sizes' , buildDir + '/sizes-stable' ) ;
194178 }
@@ -222,7 +206,7 @@ function processExperimental(buildDir, version) {
222206 }
223207
224208 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' ) ) {
226210 const filePath = buildDir + '/facebook-www/' + fileName ;
227211 const stats = fs . statSync ( filePath ) ;
228212 if ( ! stats . isDirectory ( ) ) {
@@ -231,28 +215,10 @@ function processExperimental(buildDir, version) {
231215 }
232216 updatePlaceholderReactVersionInCompiledArtifacts (
233217 buildDir + '/facebook-www' ,
234- ReactVersion + '-www-modern-%FILEHASH%'
218+ ReactVersion + '-www-modern-' + sha + '-' + dateString
235219 ) ;
236220 }
237221
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-
256222 if ( fs . existsSync ( buildDir + '/sizes' ) ) {
257223 fs . renameSync ( buildDir + '/sizes' , buildDir + '/sizes-experimental' ) ;
258224 }
@@ -362,11 +328,9 @@ function updatePlaceholderReactVersionInCompiledArtifacts(
362328
363329 for ( const artifactFilename of artifactFilenames ) {
364330 const originalText = fs . readFileSync ( artifactFilename , 'utf8' ) ;
365- const fileHash = crypto . createHash ( 'sha1' ) ;
366- fileHash . update ( originalText ) ;
367331 const replacedText = originalText . replaceAll (
368332 PLACEHOLDER_REACT_VERSION ,
369- newVersion . replace ( / % F I L E H A S H % / g , fileHash . digest ( 'hex' ) . slice ( 0 , 8 ) )
333+ newVersion
370334 ) ;
371335 fs . writeFileSync ( artifactFilename , replacedText ) ;
372336 }
0 commit comments