@@ -38,6 +38,20 @@ if (dateString.startsWith("'")) {
38
38
dateString = dateString . substr ( 1 , 8 ) ;
39
39
}
40
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.
43
+ //
44
+ // The placeholder version is the same format that the "next" channel uses
45
+ const PLACEHOLDER_REACT_VERSION =
46
+ ReactVersion + '-' + nextChannelLabel + '-' + sha + '-' + dateString ;
47
+
48
+ // TODO: We should inject the React version using a build-time parameter
49
+ // instead of overwriting the source files.
50
+ fs . writeFileSync (
51
+ './packages/shared/ReactVersion.js' ,
52
+ `export default '${ PLACEHOLDER_REACT_VERSION } ';\n`
53
+ ) ;
54
+
41
55
if ( process . env . CIRCLE_NODE_TOTAL ) {
42
56
// In CI, we use multiple concurrent processes. Allocate half the processes to
43
57
// build the stable channel, and the other half for experimental. Override
@@ -48,33 +62,21 @@ if (process.env.CIRCLE_NODE_TOTAL) {
48
62
if ( index < halfTotal ) {
49
63
const nodeTotal = halfTotal ;
50
64
const nodeIndex = index ;
51
- updateTheReactVersionThatDevToolsReads (
52
- ReactVersion + '-' + sha + '-' + dateString
53
- ) ;
54
65
buildForChannel ( 'stable' , nodeTotal , nodeIndex ) ;
55
66
processStable ( './build' ) ;
56
67
} else {
57
68
const nodeTotal = total - halfTotal ;
58
69
const nodeIndex = index - halfTotal ;
59
- updateTheReactVersionThatDevToolsReads (
60
- ReactVersion + '-experimental-' + sha + '-' + dateString
61
- ) ;
62
70
buildForChannel ( 'experimental' , nodeTotal , nodeIndex ) ;
63
71
processExperimental ( './build' ) ;
64
72
}
65
73
} else {
66
74
// Running locally, no concurrency. Move each channel's build artifacts into
67
75
// a temporary directory so that they don't conflict.
68
- updateTheReactVersionThatDevToolsReads (
69
- ReactVersion + '-' + sha + '-' + dateString
70
- ) ;
71
76
buildForChannel ( 'stable' , '' , '' ) ;
72
77
const stableDir = tmp . dirSync ( ) . name ;
73
78
crossDeviceRenameSync ( './build' , stableDir ) ;
74
79
processStable ( stableDir ) ;
75
- updateTheReactVersionThatDevToolsReads (
76
- ReactVersion + '-experimental-' + sha + '-' + dateString
77
- ) ;
78
80
buildForChannel ( 'experimental' , '' , '' ) ;
79
81
const experimentalDir = tmp . dirSync ( ) . name ;
80
82
crossDeviceRenameSync ( './build' , experimentalDir ) ;
@@ -129,6 +131,10 @@ function processStable(buildDir) {
129
131
true
130
132
) ;
131
133
fs . renameSync ( buildDir + '/node_modules' , buildDir + '/oss-stable' ) ;
134
+ updatePlaceholderReactVersionInCompiledArtifacts (
135
+ buildDir + '/oss-stable' ,
136
+ ReactVersion + '-' + nextChannelLabel + '-' + sha + '-' + dateString
137
+ ) ;
132
138
133
139
// Now do the semver ones
134
140
const semverVersionsMap = new Map ( ) ;
@@ -142,6 +148,10 @@ function processStable(buildDir) {
142
148
defaultVersionIfNotFound ,
143
149
false
144
150
) ;
151
+ updatePlaceholderReactVersionInCompiledArtifacts (
152
+ buildDir + '/oss-stable-semver' ,
153
+ ReactVersion
154
+ ) ;
145
155
}
146
156
147
157
if ( fs . existsSync ( buildDir + '/facebook-www' ) ) {
@@ -152,6 +162,10 @@ function processStable(buildDir) {
152
162
fs . renameSync ( filePath , filePath . replace ( '.js' , '.classic.js' ) ) ;
153
163
}
154
164
}
165
+ updatePlaceholderReactVersionInCompiledArtifacts (
166
+ buildDir + '/facebook-www' ,
167
+ ReactVersion + '-www-classic-' + sha + '-' + dateString
168
+ ) ;
155
169
}
156
170
157
171
if ( fs . existsSync ( buildDir + '/sizes' ) ) {
@@ -162,7 +176,7 @@ function processStable(buildDir) {
162
176
function processExperimental ( buildDir , version ) {
163
177
if ( fs . existsSync ( buildDir + '/node_modules' ) ) {
164
178
const defaultVersionIfNotFound =
165
- '0.0.0' + '-' + ' experimental' + ' -' + sha + '-' + dateString ;
179
+ '0.0.0' + '-experimental-' + sha + '-' + dateString ;
166
180
const versionsMap = new Map ( ) ;
167
181
for ( const moduleName in stablePackages ) {
168
182
versionsMap . set ( moduleName , defaultVersionIfNotFound ) ;
@@ -177,6 +191,13 @@ function processExperimental(buildDir, version) {
177
191
true
178
192
) ;
179
193
fs . renameSync ( buildDir + '/node_modules' , buildDir + '/oss-experimental' ) ;
194
+ updatePlaceholderReactVersionInCompiledArtifacts (
195
+ buildDir + '/oss-experimental' ,
196
+ // TODO: The npm version for experimental releases does not include the
197
+ // React version, but the runtime version does so that DevTools can do
198
+ // feature detection. Decide what to do about this later.
199
+ ReactVersion + '-experimental-' + sha + '-' + dateString
200
+ ) ;
180
201
}
181
202
182
203
if ( fs . existsSync ( buildDir + '/facebook-www' ) ) {
@@ -187,6 +208,10 @@ function processExperimental(buildDir, version) {
187
208
fs . renameSync ( filePath , filePath . replace ( '.js' , '.modern.js' ) ) ;
188
209
}
189
210
}
211
+ updatePlaceholderReactVersionInCompiledArtifacts (
212
+ buildDir + '/facebook-www' ,
213
+ ReactVersion + '-www-modern-' + sha + '-' + dateString
214
+ ) ;
190
215
}
191
216
192
217
if ( fs . existsSync ( buildDir + '/sizes' ) ) {
@@ -278,14 +303,32 @@ function updatePackageVersions(
278
303
}
279
304
}
280
305
281
- function updateTheReactVersionThatDevToolsReads ( version ) {
282
- // Overwrite the ReactVersion module before the build script runs so that it
283
- // is included in the final bundles. This only runs in CI, so it's fine to
284
- // edit the source file.
285
- fs . writeFileSync (
286
- './packages/shared/ReactVersion.js' ,
287
- `export default '${ version } ';\n`
288
- ) ;
306
+ function updatePlaceholderReactVersionInCompiledArtifacts (
307
+ artifactsDirectory ,
308
+ newVersion
309
+ ) {
310
+ // Update the version of React in the compiled artifacts by searching for
311
+ // the placeholder string and replacing it with a new one.
312
+ const artifactFilenames = String (
313
+ spawnSync ( 'grep' , [
314
+ '-lr' ,
315
+ PLACEHOLDER_REACT_VERSION ,
316
+ '--' ,
317
+ artifactsDirectory ,
318
+ ] ) . stdout
319
+ )
320
+ . trim ( )
321
+ . split ( '\n' )
322
+ . filter ( filename => filename . endsWith ( '.js' ) ) ;
323
+
324
+ for ( const artifactFilename of artifactFilenames ) {
325
+ const originalText = fs . readFileSync ( artifactFilename , 'utf8' ) ;
326
+ const replacedText = originalText . replace (
327
+ PLACEHOLDER_REACT_VERSION ,
328
+ newVersion
329
+ ) ;
330
+ fs . writeFileSync ( artifactFilename , replacedText ) ;
331
+ }
289
332
}
290
333
291
334
/**
0 commit comments