Skip to content

Commit 90499a7

Browse files
authored
Fix RN version string in builds (#29787)
The version was set for React but not the renderers
1 parent 29b1278 commit 90499a7

File tree

1 file changed

+48
-6
lines changed

1 file changed

+48
-6
lines changed

scripts/rollup/build-all-release-channels.js

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,19 @@ function processStable(buildDir) {
168168
);
169169
}
170170

171+
const rnVersionString =
172+
ReactVersion + '-native-fb-' + sha + '-' + dateString;
171173
if (fs.existsSync(buildDir + '/facebook-react-native')) {
172-
const versionString =
173-
ReactVersion + '-native-fb-' + sha + '-' + dateString;
174174
updatePlaceholderReactVersionInCompiledArtifacts(
175175
buildDir + '/facebook-react-native',
176-
versionString
176+
rnVersionString
177+
);
178+
}
179+
180+
if (fs.existsSync(buildDir + '/react-native')) {
181+
updatePlaceholderReactVersionInCompiledArtifactsFb(
182+
buildDir + '/react-native',
183+
rnVersionString
177184
);
178185
}
179186

@@ -265,17 +272,24 @@ function processExperimental(buildDir, version) {
265272
fs.writeFileSync(buildDir + '/facebook-www/VERSION_MODERN', versionString);
266273
}
267274

275+
const rnVersionString = ReactVersion + '-native-fb-' + sha + '-' + dateString;
268276
if (fs.existsSync(buildDir + '/facebook-react-native')) {
269-
const versionString = ReactVersion + '-native-fb-' + sha + '-' + dateString;
270277
updatePlaceholderReactVersionInCompiledArtifacts(
271278
buildDir + '/facebook-react-native',
272-
versionString
279+
rnVersionString
273280
);
274281

275282
// Also save a file with the version number
276283
fs.writeFileSync(
277284
buildDir + '/facebook-react-native/VERSION_NATIVE_FB',
278-
versionString
285+
rnVersionString
286+
);
287+
}
288+
289+
if (fs.existsSync(buildDir + '/react-native')) {
290+
updatePlaceholderReactVersionInCompiledArtifactsFb(
291+
buildDir + '/react-native',
292+
rnVersionString
279293
);
280294
}
281295

@@ -396,6 +410,34 @@ function updatePlaceholderReactVersionInCompiledArtifacts(
396410
}
397411
}
398412

413+
function updatePlaceholderReactVersionInCompiledArtifactsFb(
414+
artifactsDirectory,
415+
newVersion
416+
) {
417+
// Update the version of React in the compiled artifacts by searching for
418+
// the placeholder string and replacing it with a new one.
419+
const artifactFilenames = String(
420+
spawnSync('grep', [
421+
'-lr',
422+
PLACEHOLDER_REACT_VERSION,
423+
'--',
424+
artifactsDirectory,
425+
]).stdout
426+
)
427+
.trim()
428+
.split('\n')
429+
.filter(filename => filename.endsWith('.fb.js'));
430+
431+
for (const artifactFilename of artifactFilenames) {
432+
const originalText = fs.readFileSync(artifactFilename, 'utf8');
433+
const replacedText = originalText.replaceAll(
434+
PLACEHOLDER_REACT_VERSION,
435+
newVersion
436+
);
437+
fs.writeFileSync(artifactFilename, replacedText);
438+
}
439+
}
440+
399441
/**
400442
* cross-platform alternative to `rsync -ar`
401443
* @param {string} source

0 commit comments

Comments
 (0)