Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix RN version string in builds #29787

Merged
merged 2 commits into from
Jun 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 48 additions & 6 deletions scripts/rollup/build-all-release-channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,19 @@ function processStable(buildDir) {
);
}

const rnVersionString =
ReactVersion + '-native-fb-' + sha + '-' + dateString;
if (fs.existsSync(buildDir + '/facebook-react-native')) {
const versionString =
ReactVersion + '-native-fb-' + sha + '-' + dateString;
updatePlaceholderReactVersionInCompiledArtifacts(
buildDir + '/facebook-react-native',
versionString
rnVersionString
);
}

if (fs.existsSync(buildDir + '/react-native')) {
updatePlaceholderReactVersionInCompiledArtifactsFb(
buildDir + '/react-native',
rnVersionString
);
}

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

const rnVersionString = ReactVersion + '-native-fb-' + sha + '-' + dateString;
if (fs.existsSync(buildDir + '/facebook-react-native')) {
const versionString = ReactVersion + '-native-fb-' + sha + '-' + dateString;
updatePlaceholderReactVersionInCompiledArtifacts(
buildDir + '/facebook-react-native',
versionString
rnVersionString
);

// Also save a file with the version number
fs.writeFileSync(
buildDir + '/facebook-react-native/VERSION_NATIVE_FB',
versionString
rnVersionString
);
}

if (fs.existsSync(buildDir + '/react-native')) {
updatePlaceholderReactVersionInCompiledArtifactsFb(
buildDir + '/react-native',
rnVersionString
);
}

Expand Down Expand Up @@ -396,6 +410,34 @@ function updatePlaceholderReactVersionInCompiledArtifacts(
}
}

function updatePlaceholderReactVersionInCompiledArtifactsFb(
artifactsDirectory,
newVersion
) {
// Update the version of React in the compiled artifacts by searching for
// the placeholder string and replacing it with a new one.
const artifactFilenames = String(
spawnSync('grep', [
'-lr',
PLACEHOLDER_REACT_VERSION,
'--',
artifactsDirectory,
]).stdout
)
.trim()
.split('\n')
.filter(filename => filename.endsWith('.fb.js'));

for (const artifactFilename of artifactFilenames) {
const originalText = fs.readFileSync(artifactFilename, 'utf8');
const replacedText = originalText.replaceAll(
PLACEHOLDER_REACT_VERSION,
newVersion
);
fs.writeFileSync(artifactFilename, replacedText);
}
}

/**
* cross-platform alternative to `rsync -ar`
* @param {string} source
Expand Down