Skip to content

Commit b7b5585

Browse files
huntiefacebook-github-bot
authored andcommittedJan 31, 2024··
Enable Flow on misc release scripts (#42736)
Summary: Pull Request resolved: #42736 - Minimally enable Flow in these scripts. This would have caught outdated imports in D53001971 and D53228096. - Update `publish-npm` script with async `main()` function. - Also delete leftover `ReactNativeVersion.js.template` file. Changelog: [Internal] Reviewed By: cortinico Differential Revision: D53225162 fbshipit-source-id: 9521291b7c84728e3e05af510ebf3244a9a189e5
1 parent 0bbc311 commit b7b5585

6 files changed

+63
-52
lines changed
 

‎scripts/__tests__/publish-npm-test.js

+19-19
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jest
4444

4545
const date = new Date('2023-04-20T23:52:39.543Z');
4646

47-
const publishNpm = require('../publish-npm');
47+
const {publishNpm} = require('../publish-npm');
4848
let consoleError;
4949

5050
describe('publish-npm', () => {
@@ -68,15 +68,15 @@ describe('publish-npm', () => {
6868

6969
describe('publish-npm.js', () => {
7070
it('Fails when invalid build type is passed', () => {
71-
expect(() => publishNpm('invalid')).toThrowError(
71+
expect(publishNpm('invalid')).rejects.toThrow(
7272
'Unsupported build type: invalid',
7373
);
7474
});
7575
});
7676

7777
describe('dry-run', () => {
78-
it('should set version and not publish', () => {
79-
publishNpm('dry-run');
78+
it('should set version and not publish', async () => {
79+
await publishNpm('dry-run');
8080

8181
expect(removeNewArchFlags).not.toHaveBeenCalled();
8282
expect(exitMock).toHaveBeenCalledWith(0);
@@ -93,13 +93,13 @@ describe('publish-npm', () => {
9393
});
9494

9595
describe('nightly', () => {
96-
it('should publish', () => {
96+
it('should publish', async () => {
9797
execMock
9898
.mockReturnValueOnce({stdout: '0.81.0-rc.1\n', code: 0})
9999
.mockReturnValueOnce({code: 0});
100100
const expectedVersion = '0.82.0-nightly-20230420-currentco';
101101

102-
publishNpm('nightly');
102+
await publishNpm('nightly');
103103

104104
expect(removeNewArchFlags).not.toHaveBeenCalled();
105105
expect(publishAndroidArtifactsToMavenMock).toHaveBeenCalledWith(
@@ -116,14 +116,14 @@ describe('publish-npm', () => {
116116
expect(exitMock).toHaveBeenCalledWith(0);
117117
});
118118

119-
it('should fail to set version', () => {
119+
it('should fail to set version', async () => {
120120
execMock.mockReturnValueOnce({stdout: '0.81.0-rc.1\n', code: 0});
121121
const expectedVersion = '0.82.0-nightly-20230420-currentco';
122122
setReactNativeVersionMock.mockImplementation(() => {
123123
throw new Error('something went wrong');
124124
});
125125

126-
publishNpm('nightly');
126+
await publishNpm('nightly');
127127

128128
expect(removeNewArchFlags).not.toHaveBeenCalled();
129129
expect(publishAndroidArtifactsToMavenMock).not.toBeCalled();
@@ -140,19 +140,19 @@ describe('publish-npm', () => {
140140
describe('release', () => {
141141
it('should fail with invalid release version', () => {
142142
process.env.CIRCLE_TAG = '1.0.1';
143-
expect(() => {
144-
publishNpm('release');
145-
}).toThrow('Version 1.0.1 is not valid for Release');
143+
expect(publishNpm('release')).rejects.toThrow(
144+
'Version 1.0.1 is not valid for Release',
145+
);
146146
expect(publishAndroidArtifactsToMavenMock).not.toBeCalled();
147147
});
148148

149-
it('should publish non-latest', () => {
149+
it('should publish non-latest', async () => {
150150
execMock.mockReturnValueOnce({code: 0});
151151
isTaggedLatestMock.mockReturnValueOnce(false);
152152
process.env.CIRCLE_TAG = '0.81.1';
153153
process.env.NPM_CONFIG_OTP = 'otp';
154154

155-
publishNpm('release');
155+
await publishNpm('release');
156156

157157
expect(removeNewArchFlags).not.toHaveBeenCalled();
158158
const expectedVersion = '0.81.1';
@@ -171,13 +171,13 @@ describe('publish-npm', () => {
171171
expect(execMock.mock.calls).toHaveLength(1);
172172
});
173173

174-
it('should publish latest stable', () => {
174+
it('should publish latest stable', async () => {
175175
execMock.mockReturnValueOnce({code: 0});
176176
isTaggedLatestMock.mockReturnValueOnce(true);
177177
process.env.CIRCLE_TAG = '0.81.1';
178178
process.env.NPM_CONFIG_OTP = 'otp';
179179

180-
publishNpm('release');
180+
await publishNpm('release');
181181

182182
expect(removeNewArchFlags).not.toHaveBeenCalled();
183183
const expectedVersion = '0.81.1';
@@ -196,13 +196,13 @@ describe('publish-npm', () => {
196196
expect(execMock.mock.calls).toHaveLength(1);
197197
});
198198

199-
it('should fail to publish latest stable', () => {
199+
it('should fail to publish latest stable', async () => {
200200
execMock.mockReturnValueOnce({code: 1});
201201
isTaggedLatestMock.mockReturnValueOnce(true);
202202
process.env.CIRCLE_TAG = '0.81.1';
203203
process.env.NPM_CONFIG_OTP = 'otp';
204204

205-
publishNpm('release');
205+
await publishNpm('release');
206206

207207
expect(removeNewArchFlags).not.toHaveBeenCalled();
208208
const expectedVersion = '0.81.1';
@@ -219,13 +219,13 @@ describe('publish-npm', () => {
219219
expect(execMock.mock.calls).toHaveLength(1);
220220
});
221221

222-
it('should publish next', () => {
222+
it('should publish next', async () => {
223223
execMock.mockReturnValueOnce({code: 0});
224224
isTaggedLatestMock.mockReturnValueOnce(true);
225225
process.env.CIRCLE_TAG = '0.81.0-rc.4';
226226
process.env.NPM_CONFIG_OTP = 'otp';
227227

228-
publishNpm('release');
228+
await publishNpm('release');
229229

230230
expect(removeNewArchFlags).not.toHaveBeenCalled();
231231
const expectedVersion = '0.81.0-rc.4';

‎scripts/prepare-package-for-release.js

+9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7+
* @flow
78
* @format
89
*/
910

@@ -45,11 +46,19 @@ const argv = yargs
4546
}).argv;
4647

4748
const branch = process.env.CIRCLE_BRANCH;
49+
// $FlowFixMe[prop-missing]
4850
const remote = argv.remote;
51+
// $FlowFixMe[prop-missing]
4952
const releaseVersion = argv.toVersion;
53+
// $FlowFixMe[prop-missing]
5054
const isLatest = argv.latest;
55+
// $FlowFixMe[prop-missing]
5156
const isDryRun = argv.dryRun;
5257

58+
if (branch == null) {
59+
throw new Error('process.env.CIRCLE_BRANCH is not set');
60+
}
61+
5362
const buildType = isDryRun
5463
? 'dry-run'
5564
: isReleaseBranch(branch)

‎scripts/publish-npm.js

+20-5
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@
55
* LICENSE file in the root directory of this source tree.
66
*
77
* @format
8+
* @flow
89
*/
910

1011
'use strict';
1112

13+
/*::
14+
import type {BuildType} from './releases/version-utils';
15+
*/
16+
1217
const getAndUpdatePackages = require('./monorepo/get-and-update-packages');
1318
const {getNpmInfo, publishPackage} = require('./npm-utils');
1419
const {
@@ -43,7 +48,7 @@ const yargs = require('yargs');
4348
* * or otherwise `{major}.{minor}-stable`
4449
*/
4550

46-
if (require.main === module) {
51+
async function main() {
4752
const argv = yargs
4853
.option('t', {
4954
alias: 'builtType',
@@ -53,12 +58,13 @@ if (require.main === module) {
5358
})
5459
.strict().argv;
5560

61+
// $FlowFixMe[prop-missing]
5662
const buildType = argv.builtType;
5763

58-
publishNpm(buildType);
64+
await publishNpm(buildType);
5965
}
6066

61-
function publishNpm(buildType) {
67+
async function publishNpm(buildType /*: BuildType */) /*: Promise<void> */ {
6268
const {version, tag} = getNpmInfo(buildType);
6369

6470
if (buildType === 'prealpha') {
@@ -70,12 +76,13 @@ function publishNpm(buildType) {
7076
if (['dry-run', 'nightly', 'prealpha'].includes(buildType)) {
7177
// Publish monorepo nightlies and prealphas if there are updates, returns the new version for each package
7278
const monorepoVersions =
79+
// $FlowFixMe[incompatible-call]
7380
buildType === 'dry-run' ? null : getAndUpdatePackages(version, buildType);
7481

7582
try {
7683
// Update the react-native and template packages with the react-native version
7784
// and nightly versions of monorepo deps
78-
setReactNativeVersion(version, monorepoVersions, buildType);
85+
await setReactNativeVersion(version, monorepoVersions, buildType);
7986
} catch (e) {
8087
console.error(`Failed to set version number to ${version}`);
8188
console.error(e);
@@ -96,6 +103,7 @@ function publishNpm(buildType) {
96103

97104
const packagePath = path.join(__dirname, '..', 'packages', 'react-native');
98105
const result = publishPackage(packagePath, {
106+
// $FlowFixMe[incompatible-call]
99107
tags: [tag],
100108
otp: process.env.NPM_CONFIG_OTP,
101109
});
@@ -109,4 +117,11 @@ function publishNpm(buildType) {
109117
}
110118
}
111119

112-
module.exports = publishNpm;
120+
module.exports = {
121+
publishNpm,
122+
};
123+
124+
if (require.main === module) {
125+
// eslint-disable-next-line no-void
126+
void main();
127+
}

‎scripts/scm-utils.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ function exitIfNotOnGit /*::<T>*/(
3838
command /*: () => T */,
3939
errorMessage /*: string */,
4040
gracefulExit /*: boolean */ = false,
41-
) /*: ?T */ {
41+
// $FlowFixMe[incompatible-return] Asserts return value
42+
) /*: T */ {
4243
if (isGitRepo()) {
4344
return command();
4445
} else {

‎scripts/trigger-react-native-release.js

+13-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* This source code is licensed under the MIT license found in the
66
* LICENSE file in the root directory of this source tree.
77
*
8+
* @flow
89
* @format
910
*/
1011

@@ -54,7 +55,7 @@ let argv = yargs
5455
return true;
5556
}).argv;
5657

57-
function exitIfNotOnReleaseBranch(branch) {
58+
function exitIfNotOnReleaseBranch(branch /*: string */) {
5859
if (!isReleaseBranch(branch)) {
5960
console.log(
6061
'This script must be run in a react-native git repository checkout and on a release branch',
@@ -64,7 +65,11 @@ function exitIfNotOnReleaseBranch(branch) {
6465
}
6566

6667
const buildExecutor =
67-
(packageAbsolutePath, packageRelativePathFromRoot, packageManifest) =>
68+
(
69+
packageAbsolutePath /*: string */,
70+
packageRelativePathFromRoot /*: string */,
71+
packageManifest /*: $FlowFixMe */,
72+
) =>
6873
async () => {
6974
const {name: packageName} = packageManifest;
7075
if (packageManifest.private) {
@@ -109,7 +114,7 @@ async function exitIfUnreleasedPackages() {
109114
}
110115
}
111116

112-
function triggerReleaseWorkflow(options) {
117+
function triggerReleaseWorkflow(options /*: $FlowFixMe */) {
113118
return new Promise((resolve, reject) => {
114119
request(options, function (error, response, body) {
115120
if (error) {
@@ -144,7 +149,9 @@ async function main() {
144149
exit(1);
145150
}
146151

152+
// $FlowFixMe[prop-missing]
147153
const token = argv.token;
154+
// $FlowFixMe[prop-missing]
148155
const releaseVersion = argv.toVersion;
149156
failIfTagExists(releaseVersion, 'release');
150157

@@ -155,6 +162,7 @@ async function main() {
155162
});
156163

157164
if (!pushed) {
165+
// $FlowFixMe[prop-missing]
158166
console.log(`Please run 'git push ${argv.remote} ${branch}'`);
159167
exit(1);
160168
return;
@@ -206,6 +214,7 @@ async function main() {
206214
// See response: https://circleci.com/docs/api/v2/#operation/triggerPipeline
207215
const body = await triggerReleaseWorkflow(options);
208216
console.log(
217+
// $FlowFixMe[incompatible-use]
209218
`Monitor your release workflow: https://app.circleci.com/pipelines/github/facebook/react-native/${body.number}`,
210219
);
211220

@@ -215,6 +224,7 @@ async function main() {
215224
// - Verify RN-diff publish is through
216225
}
217226

227+
// $FlowFixMe[unused-promise]
218228
main().then(() => {
219229
exit(0);
220230
});

‎scripts/versiontemplates/ReactNativeVersion.js.template

-24
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.