Skip to content

Commit 8fd82db

Browse files
committed
[RN][Releases] Use the right package.json when comparing react-native's versions
1 parent f097ed2 commit 8fd82db

3 files changed

Lines changed: 20 additions & 9 deletions

File tree

scripts/releases-ci/__tests__/publish-npm-test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ describe('publish-npm', () => {
9696
beforeEach(() => {
9797
jest.mock('../../shared/monorepoUtils', () => ({
9898
...jest.requireActual('../../shared/monorepoUtils'),
99-
getWorkspaceRoot: jest.fn().mockResolvedValue({version: '1000.0.0'}),
99+
getReactNativePackage: jest
100+
.fn()
101+
.mockResolvedValue({version: '1000.0.0'}),
100102
}));
101103
});
102104

@@ -167,7 +169,7 @@ describe('publish-npm', () => {
167169
getBranchName.mockReturnValueOnce('0.83-stable');
168170
jest.mock('../../shared/monorepoUtils', () => ({
169171
...jest.requireActual('../../shared/monorepoUtils'),
170-
getWorkspaceRoot: jest
172+
getReactNativePackage: jest
171173
.fn()
172174
.mockResolvedValue({version: '0.83.0-rc.0'}),
173175
}));

scripts/releases-ci/publish-npm.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ const {
2727
publishExternalArtifactsToMaven,
2828
} = require('../releases/utils/release-utils');
2929
const {getBranchName} = require('../releases/utils/scm-utils');
30-
const {REPO_ROOT} = require('../shared/consts');
31-
const {getPackages, getWorkspaceRoot} = require('../shared/monorepoUtils');
32-
const path = require('path');
30+
const {REACT_NATIVE_PACKAGE_DIR} = require('../shared/consts');
31+
const {getPackages, getReactNativePackage} = require('../shared/monorepoUtils');
3332
const yargs = require('yargs');
3433

3534
/**
@@ -109,7 +108,7 @@ async function publishNpm(buildType /*: BuildType */) /*: Promise<void> */ {
109108
// Before updating React Native artifacts versions for dry-run, we check if the version has already been set.
110109
// If it has, we don't need to update the artifacts at all (at this will revert them back to 1000.0.0)
111110
// If it hasn't, we can update the native artifacts accordingly.
112-
const projectInfo = await getWorkspaceRoot();
111+
const projectInfo = await getReactNativePackage();
113112

114113
if (projectInfo.version === '1000.0.0') {
115114
// Set hermes versions to latest available if not on a stable branch
@@ -135,8 +134,7 @@ async function publishNpm(buildType /*: BuildType */) /*: Promise<void> */ {
135134
// NPM publishing is done just after.
136135
publishExternalArtifactsToMaven(version, buildType);
137136

138-
const packagePath = path.join(REPO_ROOT, 'packages', 'react-native');
139-
const result = publishPackage(packagePath, {
137+
const result = publishPackage(REACT_NATIVE_PACKAGE_DIR, {
140138
tags: [tag],
141139
});
142140

scripts/shared/monorepoUtils.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* @format
99
*/
1010

11-
const {REPO_ROOT} = require('./consts');
11+
const {REACT_NATIVE_PACKAGE_DIR, REPO_ROOT} = require('./consts');
1212
const {promises: fs} = require('fs');
1313
const glob = require('glob');
1414
const path = require('path');
@@ -103,6 +103,16 @@ async function getWorkspaceRoot() /*: Promise<PackageInfo> */ {
103103
return packageInfo;
104104
}
105105

106+
/**
107+
* Get the parsed package metadata for the main react-native package.
108+
*/
109+
async function getReactNativePackage() /*: Promise<PackageInfo> */ {
110+
const [, packageInfo] = await parsePackageInfo(
111+
path.join(REACT_NATIVE_PACKAGE_DIR, 'package.json'),
112+
);
113+
return packageInfo;
114+
}
115+
106116
async function parsePackageInfo(
107117
packageJsonPath /*: string */,
108118
) /*: Promise<[string, PackageInfo]> */ {
@@ -172,4 +182,5 @@ module.exports = {
172182
getPackages,
173183
getWorkspaceRoot,
174184
updatePackageJson,
185+
getReactNativePackage,
175186
};

0 commit comments

Comments
 (0)