Skip to content

Commit

Permalink
[skip ci] Fixset-version to also update packages/react-native sou…
Browse files Browse the repository at this point in the history
…rce (facebook#42897)

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.

Reviewed By: huntie

Differential Revision: D53463414
  • Loading branch information
lunaleaps authored and facebook-github-bot committed Feb 10, 2024
1 parent 3c2b2b1 commit 121b065
Show file tree
Hide file tree
Showing 9 changed files with 679 additions and 78 deletions.
12 changes: 8 additions & 4 deletions scripts/releases/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ 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)

### `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 workspace dependencies in the template app`package.json`
27 changes: 22 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,25 @@ 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 === path.join(REPO_ROOT, 'packages/react-native/package.json')
) {
return JSON.stringify({
name: 'react-native',
version: '1000.0.0',
Expand Down Expand Up @@ -60,7 +71,10 @@ describe('setReactNativeVersion', () => {
});

for (const [filePath, contents] of writeFileMock.mock.calls) {
expect(formatGeneratedFile(contents)).toMatchSnapshot(filePath);
// Make snapshot names resilient to platform path sep differences
expect(formatGeneratedFile(contents)).toMatchSnapshot(
path.relative(REPO_ROOT, filePath).split(path.sep).join('/'),
);
}
});

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

for (const [filePath, contents] of writeFileMock.mock.calls) {
expect(formatGeneratedFile(contents)).toMatchSnapshot(filePath);
// Make snapshot names resilient to platform path sep differences
expect(formatGeneratedFile(contents)).toMatchSnapshot(
path.relative(REPO_ROOT, filePath).split(path.sep).join('/'),
);
}
});
});
Expand Down
41 changes: 31 additions & 10 deletions scripts/releases/set-rn-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,17 @@ const updateTemplatePackage = require('./update-template-package');
const {parseVersion, validateBuildType} = require('./utils/version-utils');
const {parseArgs} = require('@pkgjs/parseargs');
const {promises: fs} = require('fs');

const GRADLE_FILE_PATH = 'packages/react-native/ReactAndroid/gradle.properties';
const REACT_NATIVE_PACKAGE_JSON = 'packages/react-native/package.json';
const path = require('path');

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 = path.join(
REPO_ROOT,
'packages/react-native/package.json',
);

const config = {
options: {
Expand Down Expand Up @@ -101,36 +109,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 +160,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 121b065

Please sign in to comment.