Skip to content

Commit 04df252

Browse files
hoxyqfacebook-github-bot
authored andcommitted
RN [refactor]: bump and realign package versions by running a single script (facebook#36568)
Summary: Pull Request resolved: facebook#36568 Changelog: [Internal] Okay, so before the monorepo migration we had to use two scripts separately: 1. Bumping every package with `npm run bump-all-updated-packages` 2. Aligning other packages versions with `npm run align-package-versions` The reason for it is that *before the monorepo* in a release branch cutoff process we had a step, which was removing `workspaces` keyword from `react-native` package. Without this keyword all new versions of packages will be resolved from npm (where they will be not available yet, because we have to publish them prior to it) This is not the case for our current setup, and we can actually bump packages versions and they will be resolved as a workspaces successfully Reviewed By: cortinico, cipolleschi Differential Revision: D44261057 fbshipit-source-id: 31c2157be2d3b33bc073651d6045efcef2e8f5c5
1 parent 5ff01bc commit 04df252

File tree

3 files changed

+78
-96
lines changed

3 files changed

+78
-96
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"test-typescript": "dtslint packages/react-native/types",
4242
"test-typescript-offline": "dtslint --localTs node_modules/typescript/lib packages/react-native/types",
4343
"bump-all-updated-packages": "node ./scripts/monorepo/bump-all-updated-packages",
44-
"align-package-versions": "node ./scripts/monorepo/align-package-versions.js"
44+
"align-package-versions": "node -e \"require('./scripts/monorepo/align-package-versions')()\""
4545
},
4646
"workspaces": [
4747
"packages/*"

scripts/monorepo/align-package-versions.js

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77
* @format
88
*/
99

10-
const {spawnSync} = require('child_process');
1110
const {writeFileSync, readFileSync} = require('fs');
1211
const path = require('path');
1312

14-
const checkForGitChanges = require('./check-for-git-changes');
1513
const forEachPackage = require('./for-each-package');
1614

1715
const ROOT_LOCATION = path.join(__dirname, '..', '..');
1816
const TEMPLATE_LOCATION = path.join(
1917
ROOT_LOCATION,
20-
'packages/react-native/template',
18+
'packages',
19+
'react-native',
20+
'template',
2121
);
2222

2323
const readJSONFile = pathToFile => JSON.parse(readFileSync(pathToFile));
@@ -93,14 +93,6 @@ const checkIfShouldUpdateDependencyPackageVersion = (
9393
};
9494

9595
const alignPackageVersions = () => {
96-
if (checkForGitChanges()) {
97-
console.log(
98-
'\u274c Found uncommitted changes. Please commit or stash them before running this script',
99-
);
100-
101-
process.exit(1);
102-
}
103-
10496
forEachPackage((_, __, packageManifest) => {
10597
checkIfShouldUpdateDependencyPackageVersion(
10698
ROOT_LOCATION,
@@ -124,21 +116,6 @@ const alignPackageVersions = () => {
124116
{includeReactNative: true},
125117
);
126118
});
127-
128-
if (!checkForGitChanges()) {
129-
console.log(
130-
'\u2705 There were no changes. Every consumer package uses the actual version of dependency package.',
131-
);
132-
return;
133-
}
134-
135-
console.log('Running yarn to update lock file...');
136-
spawnSync('yarn', ['install'], {
137-
cwd: ROOT_LOCATION,
138-
shell: true,
139-
stdio: 'inherit',
140-
encoding: 'utf-8',
141-
});
142119
};
143120

144-
alignPackageVersions();
121+
module.exports = alignPackageVersions;

scripts/monorepo/bump-all-updated-packages/index.js

Lines changed: 73 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const path = require('path');
1414
const {echo, exec, exit} = require('shelljs');
1515
const yargs = require('yargs');
1616

17+
const alignPackageVersions = require('../align-package-versions');
1718
const {
1819
PUBLISH_PACKAGES_TAG,
1920
GENERIC_COMMIT_MESSAGE,
@@ -157,76 +158,80 @@ const main = async () => {
157158
.then(() => echo());
158159
}
159160

160-
if (checkForGitChanges()) {
161-
await inquirer
162-
.prompt([
163-
{
164-
type: 'list',
165-
name: 'commitChoice',
166-
message: 'Do you want to submit a commit with these changes?',
167-
choices: [
168-
{
169-
name: 'Yes, with generic message',
170-
value: COMMIT_WITH_GENERIC_MESSAGE_CHOICE,
171-
},
172-
{
173-
name: 'Yes, with custom message',
174-
value: COMMIT_WITH_CUSTOM_MESSAGE_CHOICE,
175-
},
176-
{
177-
name: 'No',
178-
value: NO_COMMIT_CHOICE,
179-
},
180-
],
181-
},
182-
])
183-
.then(({commitChoice}) => {
184-
switch (commitChoice) {
185-
case NO_COMMIT_CHOICE: {
186-
echo('Not submitting a commit, but keeping all changes');
187-
188-
break;
189-
}
190-
191-
case COMMIT_WITH_GENERIC_MESSAGE_CHOICE: {
192-
exec(`git commit -am "${GENERIC_COMMIT_MESSAGE}"`, {
193-
cwd: ROOT_LOCATION,
194-
silent: true,
195-
});
196-
197-
break;
198-
}
199-
200-
case COMMIT_WITH_CUSTOM_MESSAGE_CHOICE: {
201-
// exec from shelljs currently does not support interactive input
202-
// https://github.com/shelljs/shelljs/wiki/FAQ#running-interactive-programs-with-exec
203-
execSync('git commit -a', {cwd: ROOT_LOCATION, stdio: 'inherit'});
204-
205-
const enteredCommitMessage = exec(
206-
'git log -n 1 --format=format:%B',
207-
{
208-
cwd: ROOT_LOCATION,
209-
silent: true,
210-
},
211-
).stdout.trim();
212-
const commitMessageWithTag =
213-
enteredCommitMessage + `\n\n${PUBLISH_PACKAGES_TAG}`;
214-
215-
exec(`git commit --amend -m "${commitMessageWithTag}"`, {
216-
cwd: ROOT_LOCATION,
217-
silent: true,
218-
});
219-
220-
break;
221-
}
222-
223-
default:
224-
throw new Error('');
225-
}
226-
})
227-
.then(() => echo());
161+
if (!checkForGitChanges()) {
162+
echo('No changes have been made. Finishing the process...');
163+
exit(0);
228164
}
229165

166+
echo('Aligning new versions across monorepo...');
167+
alignPackageVersions();
168+
echo(chalk.green('Done!\n'));
169+
170+
await inquirer
171+
.prompt([
172+
{
173+
type: 'list',
174+
name: 'commitChoice',
175+
message: 'Do you want to submit a commit with these changes?',
176+
choices: [
177+
{
178+
name: 'Yes, with generic message',
179+
value: COMMIT_WITH_GENERIC_MESSAGE_CHOICE,
180+
},
181+
{
182+
name: 'Yes, with custom message',
183+
value: COMMIT_WITH_CUSTOM_MESSAGE_CHOICE,
184+
},
185+
{
186+
name: 'No',
187+
value: NO_COMMIT_CHOICE,
188+
},
189+
],
190+
},
191+
])
192+
.then(({commitChoice}) => {
193+
switch (commitChoice) {
194+
case NO_COMMIT_CHOICE: {
195+
echo('Not submitting a commit, but keeping all changes');
196+
197+
break;
198+
}
199+
200+
case COMMIT_WITH_GENERIC_MESSAGE_CHOICE: {
201+
exec(`git commit -am "${GENERIC_COMMIT_MESSAGE}"`, {
202+
cwd: ROOT_LOCATION,
203+
silent: true,
204+
});
205+
206+
break;
207+
}
208+
209+
case COMMIT_WITH_CUSTOM_MESSAGE_CHOICE: {
210+
// exec from shelljs currently does not support interactive input
211+
// https://github.com/shelljs/shelljs/wiki/FAQ#running-interactive-programs-with-exec
212+
execSync('git commit -a', {cwd: ROOT_LOCATION, stdio: 'inherit'});
213+
214+
const enteredCommitMessage = exec('git log -n 1 --format=format:%B', {
215+
cwd: ROOT_LOCATION,
216+
silent: true,
217+
}).stdout.trim();
218+
const commitMessageWithTag =
219+
enteredCommitMessage + `\n\n${PUBLISH_PACKAGES_TAG}`;
220+
221+
exec(`git commit --amend -m "${commitMessageWithTag}"`, {
222+
cwd: ROOT_LOCATION,
223+
silent: true,
224+
});
225+
226+
break;
227+
}
228+
229+
default:
230+
throw new Error('');
231+
}
232+
})
233+
.then(() => echo());
234+
230235
echo(chalk.green('Successfully finished the process of bumping packages'));
231236
exit(0);
232237
};

0 commit comments

Comments
 (0)