|
2 | 2 |
|
3 | 3 | /* eslint-disable no-for-of-loops/no-for-of-loops */ |
4 | 4 |
|
| 5 | +const crypto = require('node:crypto'); |
5 | 6 | const fs = require('fs'); |
6 | 7 | const fse = require('fs-extra'); |
7 | 8 | const {spawnSync} = require('child_process'); |
@@ -40,10 +41,7 @@ if (dateString.startsWith("'")) { |
40 | 41 |
|
41 | 42 | // Build the artifacts using a placeholder React version. We'll then do a string |
42 | 43 | // replace to swap it with the correct version per release channel. |
43 | | -// |
44 | | -// The placeholder version is the same format that the "next" channel uses |
45 | | -const PLACEHOLDER_REACT_VERSION = |
46 | | - ReactVersion + '-' + nextChannelLabel + '-' + sha + '-' + dateString; |
| 44 | +const PLACEHOLDER_REACT_VERSION = ReactVersion + '-PLACEHOLDER'; |
47 | 45 |
|
48 | 46 | // TODO: We should inject the React version using a build-time parameter |
49 | 47 | // instead of overwriting the source files. |
@@ -164,19 +162,27 @@ function processStable(buildDir) { |
164 | 162 | } |
165 | 163 |
|
166 | 164 | if (fs.existsSync(buildDir + '/facebook-www')) { |
167 | | - for (const fileName of fs.readdirSync(buildDir + '/facebook-www')) { |
| 165 | + const hash = crypto.createHash('sha1'); |
| 166 | + for (const fileName of fs.readdirSync(buildDir + '/facebook-www').sort()) { |
168 | 167 | const filePath = buildDir + '/facebook-www/' + fileName; |
169 | 168 | const stats = fs.statSync(filePath); |
170 | 169 | if (!stats.isDirectory()) { |
| 170 | + hash.update(fs.readFileSync(filePath)); |
171 | 171 | fs.renameSync(filePath, filePath.replace('.js', '.classic.js')); |
172 | 172 | } |
173 | 173 | } |
174 | 174 | updatePlaceholderReactVersionInCompiledArtifacts( |
175 | 175 | buildDir + '/facebook-www', |
176 | | - ReactVersion + '-www-classic-' + sha + '-' + dateString |
| 176 | + ReactVersion + '-www-classic-' + hash.digest('hex').substr(0, 8) |
177 | 177 | ); |
178 | 178 | } |
179 | 179 |
|
| 180 | + // Update remaining placeholders with next channel version |
| 181 | + updatePlaceholderReactVersionInCompiledArtifacts( |
| 182 | + buildDir, |
| 183 | + ReactVersion + '-' + nextChannelLabel + '-' + sha + '-' + dateString |
| 184 | + ); |
| 185 | + |
180 | 186 | if (fs.existsSync(buildDir + '/sizes')) { |
181 | 187 | fs.renameSync(buildDir + '/sizes', buildDir + '/sizes-stable'); |
182 | 188 | } |
@@ -210,19 +216,27 @@ function processExperimental(buildDir, version) { |
210 | 216 | } |
211 | 217 |
|
212 | 218 | if (fs.existsSync(buildDir + '/facebook-www')) { |
213 | | - for (const fileName of fs.readdirSync(buildDir + '/facebook-www')) { |
| 219 | + const hash = crypto.createHash('sha1'); |
| 220 | + for (const fileName of fs.readdirSync(buildDir + '/facebook-www').sort()) { |
214 | 221 | const filePath = buildDir + '/facebook-www/' + fileName; |
215 | 222 | const stats = fs.statSync(filePath); |
216 | 223 | if (!stats.isDirectory()) { |
| 224 | + hash.update(fs.readFileSync(filePath)); |
217 | 225 | fs.renameSync(filePath, filePath.replace('.js', '.modern.js')); |
218 | 226 | } |
219 | 227 | } |
220 | 228 | updatePlaceholderReactVersionInCompiledArtifacts( |
221 | 229 | buildDir + '/facebook-www', |
222 | | - ReactVersion + '-www-modern-' + sha + '-' + dateString |
| 230 | + ReactVersion + '-www-modern-' + hash.digest('hex').substr(0, 8) |
223 | 231 | ); |
224 | 232 | } |
225 | 233 |
|
| 234 | + // Update remaining placeholders with next channel version |
| 235 | + updatePlaceholderReactVersionInCompiledArtifacts( |
| 236 | + buildDir, |
| 237 | + ReactVersion + '-' + nextChannelLabel + '-' + sha + '-' + dateString |
| 238 | + ); |
| 239 | + |
226 | 240 | if (fs.existsSync(buildDir + '/sizes')) { |
227 | 241 | fs.renameSync(buildDir + '/sizes', buildDir + '/sizes-experimental'); |
228 | 242 | } |
|
0 commit comments