|
| 1 | +--- |
| 2 | +id: Updating packages |
| 3 | +title: Updating packages |
| 4 | +--- |
| 5 | + |
| 6 | +This page contains relevant information about how to update packages in the `react-native` [monorepo](https://github.com/react-native-community/discussions-and-proposals/pull/480). |
| 7 | + |
| 8 | +## Finding all packages that have unpublished changes |
| 9 | +#### Use case |
| 10 | +1. You want to identify each package with unpublished (on npm) changes and update its version. This can be used in release cycle if you have merged some fixes to `*-stable` branch. |
| 11 | +2. You want to force-bump each public package to the next minor version. This happens usually before release branch cutoff. In this case, please specify `release-branch-cutoff` argument before executing the script. |
| 12 | + |
| 13 | +#### How to execute |
| 14 | +`npm run bump-all-updated-packages` or `npm run bump-all-updated-packages --release-branch-cutoff` |
| 15 | + |
| 16 | +#### Pseudocode |
| 17 | +``` |
| 18 | +check that no git changes are present |
| 19 | +
|
| 20 | +for each package: |
| 21 | + if package is private -> skip |
| 22 | +
|
| 23 | + if release-branch-cutoff argument is provided: |
| 24 | + bump package version to the next minor |
| 25 | + return |
| 26 | +
|
| 27 | + grep id of the last commit that changed package |
| 28 | + grep id of the last commit that changed version of the package |
| 29 | +
|
| 30 | + if these ids are different: |
| 31 | + bump package version (minor or patch) |
| 32 | +
|
| 33 | +commit changes if required |
| 34 | +``` |
| 35 | + |
| 36 | +### Notes |
| 37 | +At the final step you will be asked if you want to commit all these changes. Always select `Yes` if you want these packages to be published then on CircleCI, because the workflow that does this [will check that commit has a tag inside its message](https://github.com/facebook/react-native/wiki/Release-and-its-automated-processes#notes-1). |
| 38 | + |
| 39 | +## Publishing an updated package to npm |
| 40 | +We have a [CircleCI workflow](https://github.com/facebook/react-native/blob/292268ea3fa429cd1a1245b6239e0a85b59da02a/.circleci/config.yml#L1801-L1804), which runs **only on main or stable-\* branches**. |
| 41 | + |
| 42 | +#### Pseudocode |
| 43 | +``` |
| 44 | +for each package: |
| 45 | + if last commit contains version change: |
| 46 | + if this commit has specific message: |
| 47 | + publish package to npm |
| 48 | +``` |
| 49 | + |
| 50 | +#### Notes |
| 51 | +This workflow explicitly checks that commit has a specific [tag](https://github.com/facebook/react-native/blob/main/scripts/monorepo/constants.js#L11) inside its message. This is used to prevent accidental publishes. To create such specific commit you should use [script from above](https://github.com/facebook/react-native/wiki/Release-and-its-automated-processes#finding-all-packages-that-have-unpublished-changes). |
| 52 | + |
| 53 | +If you want to bump package version and publish it to npm registry, your version change should be exactly in the last commit. This is because of two things: |
| 54 | +1. If multiple commits are merged to `main` branch at the same time, CircleCI will execute workflows only once on top of the latest commit. |
| 55 | +2. To determine that version was changed we [evaluate the difference between HEAD and HEAD~1](https://github.com/facebook/react-native/blob/daeee2a6619db59391de3b7c6e08db0dbe2331aa/scripts/monorepo/find-and-publish-all-bumped-packages.js#L32-L35). |
| 56 | + |
| 57 | +Example script output, where no package versions were changed: |
| 58 | +<img width="800" alt="Screenshot 2023-01-03 at 12 21 01" src="https://user-images.githubusercontent.com/28902667/210362611-97530b4d-0405-499c-9a3c-5542e069e929.png"> |
| 59 | + |
| 60 | +## Align package versions across monorepo |
| 61 | +#### Use case |
| 62 | +You (or someone from release cycle team) have recently used a script to bump versions of updated packages and now these versions are available on npm. You want to align these versions across every package inside monorepo including `repo-config` and `template`. |
| 63 | + |
| 64 | +#### How to execute |
| 65 | +`npm run align-package-versions` |
| 66 | + |
| 67 | +#### Pseudocode |
| 68 | +``` |
| 69 | +check that no git changes are present |
| 70 | +
|
| 71 | +for each package x: |
| 72 | + for each package y: |
| 73 | + if y has x as dependency: |
| 74 | + validate that y uses the latest version of x |
| 75 | +
|
| 76 | +if some changes were made: |
| 77 | + run yarn |
| 78 | +``` |
| 79 | + |
| 80 | +#### Notes |
| 81 | +Usually, if this script is executed on `main` branch, a pull request with the changes should be imported by an engineer from Meta to update yarn lockfiles. This is only if you merging these changes to `main` branch. |
| 82 | + |
| 83 | +## Q&A |
| 84 | +#### Why there are two different scripts to update versions everywhere? |
| 85 | +For `*-stable` branches, there are no yarn workspaces and all packages are specified as direct dependencies, so for instance, if we update `@react-native/assets-registry` to the next version, we won't be able to run yarn for react-native root package, because updated version is not yet published to npm. This is caused by the nature of the repository and the code structure, which is currently getting reworked as per [this RFC](https://github.com/react-native-community/discussions-and-proposals/pull/480). |
| 86 | + |
| 87 | +To avoid this, we first need publish new versions and then update them in consumer packages. |
0 commit comments