Skip to content

Commit

Permalink
Fixset-version to also update packages/react-native source (#42897)
Browse files Browse the repository at this point in the history
Summary:

Changelog: [Internal] - Update nightly flow to use set-version

This change fixes `set-version` to update the `packages/react-native` native source and build files (as `set-rn-version` does) -- this was an oversight but not an issue as `set-version` isn't actually used anywhere right now.

Differential Revision: D53463414
  • Loading branch information
lunaleaps authored and facebook-github-bot committed Feb 6, 2024
1 parent 8da1da2 commit 98d023c
Show file tree
Hide file tree
Showing 8 changed files with 675 additions and 56 deletions.
16 changes: 12 additions & 4 deletions scripts/releases/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,22 @@ Scripts related to creating a React Native release. These are the lower level en

For information on command arguments, run `node <command> --help`.

### `remove-new-arch-flags.js`
### `remove-new-arch-flags`

Updates native build files to disable the New Architecture.

### `set-rn-version.js`
### `set-version`

Sets a singular version for the entire monorepo (including `react-native` package). In detail:
* Update all public npm packages under `<root>/packages` to specified version
* Update all npm dependencies of a `<root>/packages` package to specified version
* Update npm dependencies of the template app (`packages/react-native/template`) to specified version
* Update `packages/react-native` native source and build files to specified version

### `set-rn-version`

Updates relevant files in the `react-native` package and template to materialize the given release version.

### `update-template-package.js`
### `update-template-package`

Updates local dependencies in the template `package.json`.
Updates `<root>/packages` dependencies in the template app`package.json`
23 changes: 18 additions & 5 deletions scripts/releases/__tests__/set-rn-version-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,23 @@ jest.mock('fs', () => ({
jest.mock('./../update-template-package', () => updateTemplatePackageMock);

const {setReactNativeVersion} = require('../set-rn-version');
const path = require('path');

const REPO_ROOT = path.resolve(__filename, '../../../..');

describe('setReactNativeVersion', () => {
beforeAll(() => {
readFileMock.mockImplementation(path => {
if (path === 'packages/react-native/ReactAndroid/gradle.properties') {
readFileMock.mockImplementation(filePath => {
if (
filePath ===
path.join(
REPO_ROOT,
'packages/react-native/ReactAndroid/gradle.properties',
)
) {
return 'VERSION_NAME=1000.0.0\n';
}
if (path === 'packages/react-native/package.json') {
if (filePath === 'packages/react-native/package.json') {
return JSON.stringify({
name: 'react-native',
version: '1000.0.0',
Expand Down Expand Up @@ -60,7 +69,9 @@ describe('setReactNativeVersion', () => {
});

for (const [filePath, contents] of writeFileMock.mock.calls) {
expect(formatGeneratedFile(contents)).toMatchSnapshot(filePath);
expect(formatGeneratedFile(contents)).toMatchSnapshot(
path.relative(REPO_ROOT, filePath),
);
}
});

Expand All @@ -73,7 +84,9 @@ describe('setReactNativeVersion', () => {
});

for (const [filePath, contents] of writeFileMock.mock.calls) {
expect(formatGeneratedFile(contents)).toMatchSnapshot(filePath);
expect(formatGeneratedFile(contents)).toMatchSnapshot(
path.relative(REPO_ROOT, filePath),
);
}
});
});
Expand Down
34 changes: 26 additions & 8 deletions scripts/releases/set-rn-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@ const updateTemplatePackage = require('./update-template-package');
const {parseVersion, validateBuildType} = require('./utils/version-utils');
const {parseArgs} = require('@pkgjs/parseargs');
const {promises: fs} = require('fs');
const path = require('path');

const GRADLE_FILE_PATH = 'packages/react-native/ReactAndroid/gradle.properties';
const REPO_ROOT = path.join(path.dirname(__filename), '..', '..');
const GRADLE_FILE_PATH = path.join(
REPO_ROOT,
'packages/react-native/ReactAndroid/gradle.properties',
);
const REACT_NATIVE_PACKAGE_JSON = 'packages/react-native/package.json';

const config = {
Expand Down Expand Up @@ -101,36 +106,47 @@ async function setReactNativePackageVersion(
packageJson.version = version;

await fs.writeFile(
'packages/react-native/package.json',
path.join(REPO_ROOT, 'packages/react-native/package.json'),
JSON.stringify(packageJson, null, 2),
'utf-8',
);
}

function updateSourceFiles(versionInfo /*: Version */) {
function updateSourceFiles(
versionInfo /*: Version */,
) /*: Promise<Array<void>>*/ {
const templateData = {version: versionInfo};

return Promise.all([
fs.writeFile(
'packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/ReactNativeVersion.java',
path.join(
REPO_ROOT,
'packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/ReactNativeVersion.java',
),
require('./templates/ReactNativeVersion.java-template')(templateData),
),
fs.writeFile(
'packages/react-native/React/Base/RCTVersion.m',
path.join(REPO_ROOT, 'packages/react-native/React/Base/RCTVersion.m'),
require('./templates/RCTVersion.m-template')(templateData),
),
fs.writeFile(
'packages/react-native/ReactCommon/cxxreact/ReactNativeVersion.h',
path.join(
REPO_ROOT,
'packages/react-native/ReactCommon/cxxreact/ReactNativeVersion.h',
),
require('./templates/ReactNativeVersion.h-template')(templateData),
),
fs.writeFile(
'packages/react-native/Libraries/Core/ReactNativeVersion.js',
path.join(
REPO_ROOT,
'packages/react-native/Libraries/Core/ReactNativeVersion.js',
),
require('./templates/ReactNativeVersion.js-template')(templateData),
),
]);
}

async function updateGradleFile(version /*: string */) {
async function updateGradleFile(version /*: string */) /*: Promise<void> */ {
const contents = await fs.readFile(GRADLE_FILE_PATH, 'utf-8');

return fs.writeFile(
Expand All @@ -141,6 +157,8 @@ async function updateGradleFile(version /*: string */) {

module.exports = {
setReactNativeVersion,
updateGradleFile,
updateSourceFiles,
};

if (require.main === module) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VERSION_NAME=1000.0.0
Loading

0 comments on commit 98d023c

Please sign in to comment.