From 04df252aa7bff34a02b24f8381b3f2f1dd122c2f Mon Sep 17 00:00:00 2001 From: Ruslan Lesiutin Date: Mon, 27 Mar 2023 07:31:45 -0700 Subject: [PATCH] RN [refactor]: bump and realign package versions by running a single script (#36568) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/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 --- package.json | 2 +- scripts/monorepo/align-package-versions.js | 31 +--- .../bump-all-updated-packages/index.js | 141 +++++++++--------- 3 files changed, 78 insertions(+), 96 deletions(-) diff --git a/package.json b/package.json index 9715de4c44a316..1e6df0a9f9455c 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "test-typescript": "dtslint packages/react-native/types", "test-typescript-offline": "dtslint --localTs node_modules/typescript/lib packages/react-native/types", "bump-all-updated-packages": "node ./scripts/monorepo/bump-all-updated-packages", - "align-package-versions": "node ./scripts/monorepo/align-package-versions.js" + "align-package-versions": "node -e \"require('./scripts/monorepo/align-package-versions')()\"" }, "workspaces": [ "packages/*" diff --git a/scripts/monorepo/align-package-versions.js b/scripts/monorepo/align-package-versions.js index 9641af295f3d4d..8037f76ba79e5f 100644 --- a/scripts/monorepo/align-package-versions.js +++ b/scripts/monorepo/align-package-versions.js @@ -7,17 +7,17 @@ * @format */ -const {spawnSync} = require('child_process'); const {writeFileSync, readFileSync} = require('fs'); const path = require('path'); -const checkForGitChanges = require('./check-for-git-changes'); const forEachPackage = require('./for-each-package'); const ROOT_LOCATION = path.join(__dirname, '..', '..'); const TEMPLATE_LOCATION = path.join( ROOT_LOCATION, - 'packages/react-native/template', + 'packages', + 'react-native', + 'template', ); const readJSONFile = pathToFile => JSON.parse(readFileSync(pathToFile)); @@ -93,14 +93,6 @@ const checkIfShouldUpdateDependencyPackageVersion = ( }; const alignPackageVersions = () => { - if (checkForGitChanges()) { - console.log( - '\u274c Found uncommitted changes. Please commit or stash them before running this script', - ); - - process.exit(1); - } - forEachPackage((_, __, packageManifest) => { checkIfShouldUpdateDependencyPackageVersion( ROOT_LOCATION, @@ -124,21 +116,6 @@ const alignPackageVersions = () => { {includeReactNative: true}, ); }); - - if (!checkForGitChanges()) { - console.log( - '\u2705 There were no changes. Every consumer package uses the actual version of dependency package.', - ); - return; - } - - console.log('Running yarn to update lock file...'); - spawnSync('yarn', ['install'], { - cwd: ROOT_LOCATION, - shell: true, - stdio: 'inherit', - encoding: 'utf-8', - }); }; -alignPackageVersions(); +module.exports = alignPackageVersions; diff --git a/scripts/monorepo/bump-all-updated-packages/index.js b/scripts/monorepo/bump-all-updated-packages/index.js index 09291c0d723423..d32e3ea1b5a744 100644 --- a/scripts/monorepo/bump-all-updated-packages/index.js +++ b/scripts/monorepo/bump-all-updated-packages/index.js @@ -14,6 +14,7 @@ const path = require('path'); const {echo, exec, exit} = require('shelljs'); const yargs = require('yargs'); +const alignPackageVersions = require('../align-package-versions'); const { PUBLISH_PACKAGES_TAG, GENERIC_COMMIT_MESSAGE, @@ -157,76 +158,80 @@ const main = async () => { .then(() => echo()); } - if (checkForGitChanges()) { - await inquirer - .prompt([ - { - type: 'list', - name: 'commitChoice', - message: 'Do you want to submit a commit with these changes?', - choices: [ - { - name: 'Yes, with generic message', - value: COMMIT_WITH_GENERIC_MESSAGE_CHOICE, - }, - { - name: 'Yes, with custom message', - value: COMMIT_WITH_CUSTOM_MESSAGE_CHOICE, - }, - { - name: 'No', - value: NO_COMMIT_CHOICE, - }, - ], - }, - ]) - .then(({commitChoice}) => { - switch (commitChoice) { - case NO_COMMIT_CHOICE: { - echo('Not submitting a commit, but keeping all changes'); - - break; - } - - case COMMIT_WITH_GENERIC_MESSAGE_CHOICE: { - exec(`git commit -am "${GENERIC_COMMIT_MESSAGE}"`, { - cwd: ROOT_LOCATION, - silent: true, - }); - - break; - } - - case COMMIT_WITH_CUSTOM_MESSAGE_CHOICE: { - // exec from shelljs currently does not support interactive input - // https://github.com/shelljs/shelljs/wiki/FAQ#running-interactive-programs-with-exec - execSync('git commit -a', {cwd: ROOT_LOCATION, stdio: 'inherit'}); - - const enteredCommitMessage = exec( - 'git log -n 1 --format=format:%B', - { - cwd: ROOT_LOCATION, - silent: true, - }, - ).stdout.trim(); - const commitMessageWithTag = - enteredCommitMessage + `\n\n${PUBLISH_PACKAGES_TAG}`; - - exec(`git commit --amend -m "${commitMessageWithTag}"`, { - cwd: ROOT_LOCATION, - silent: true, - }); - - break; - } - - default: - throw new Error(''); - } - }) - .then(() => echo()); + if (!checkForGitChanges()) { + echo('No changes have been made. Finishing the process...'); + exit(0); } + echo('Aligning new versions across monorepo...'); + alignPackageVersions(); + echo(chalk.green('Done!\n')); + + await inquirer + .prompt([ + { + type: 'list', + name: 'commitChoice', + message: 'Do you want to submit a commit with these changes?', + choices: [ + { + name: 'Yes, with generic message', + value: COMMIT_WITH_GENERIC_MESSAGE_CHOICE, + }, + { + name: 'Yes, with custom message', + value: COMMIT_WITH_CUSTOM_MESSAGE_CHOICE, + }, + { + name: 'No', + value: NO_COMMIT_CHOICE, + }, + ], + }, + ]) + .then(({commitChoice}) => { + switch (commitChoice) { + case NO_COMMIT_CHOICE: { + echo('Not submitting a commit, but keeping all changes'); + + break; + } + + case COMMIT_WITH_GENERIC_MESSAGE_CHOICE: { + exec(`git commit -am "${GENERIC_COMMIT_MESSAGE}"`, { + cwd: ROOT_LOCATION, + silent: true, + }); + + break; + } + + case COMMIT_WITH_CUSTOM_MESSAGE_CHOICE: { + // exec from shelljs currently does not support interactive input + // https://github.com/shelljs/shelljs/wiki/FAQ#running-interactive-programs-with-exec + execSync('git commit -a', {cwd: ROOT_LOCATION, stdio: 'inherit'}); + + const enteredCommitMessage = exec('git log -n 1 --format=format:%B', { + cwd: ROOT_LOCATION, + silent: true, + }).stdout.trim(); + const commitMessageWithTag = + enteredCommitMessage + `\n\n${PUBLISH_PACKAGES_TAG}`; + + exec(`git commit --amend -m "${commitMessageWithTag}"`, { + cwd: ROOT_LOCATION, + silent: true, + }); + + break; + } + + default: + throw new Error(''); + } + }) + .then(() => echo()); + echo(chalk.green('Successfully finished the process of bumping packages')); exit(0); };