|
| 1 | +--- |
| 2 | +id: release-updating-packages |
| 3 | +title: Updating monorepo 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 | + |
| 10 | +#### Use case |
| 11 | + |
| 12 | +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. |
| 13 | +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. |
| 14 | + |
| 15 | +#### How to execute |
| 16 | + |
| 17 | +`yarn bump-all-updated-packages` or `yarn bump-all-updated-packages --release-branch-cutoff` |
| 18 | + |
| 19 | +#### Pseudocode |
| 20 | + |
| 21 | +``` |
| 22 | +check that no git changes are present |
| 23 | +
|
| 24 | +for each package: |
| 25 | + if package is private -> skip |
| 26 | +
|
| 27 | + if release-branch-cutoff argument is provided: |
| 28 | + bump package version to the next minor |
| 29 | + return |
| 30 | +
|
| 31 | + grep id of the last commit that changed package |
| 32 | + grep id of the last commit that changed version of the package |
| 33 | +
|
| 34 | + if these ids are different: |
| 35 | + bump package version (minor or patch) |
| 36 | +
|
| 37 | +align packages versions across whole monorepo |
| 38 | +commit changes if required |
| 39 | +``` |
| 40 | + |
| 41 | +### Notes |
| 42 | + |
| 43 | +At the final step you will be asked if you want to commit all these changes. Always confirm committing 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). |
| 44 | + |
| 45 | +Updated versions will also be updated in packages consumers. This means if `@react-native/x` has `@react-native/y` as a dependency and we bump version of `@react-native/y`, then `@react-native/x` will have updated version of `@react-native/y` specified. |
| 46 | + |
| 47 | +## Publishing an updated package to npm |
| 48 | + |
| 49 | +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**. |
| 50 | + |
| 51 | +#### Pseudocode |
| 52 | + |
| 53 | +``` |
| 54 | +for each package: |
| 55 | + if last commit contains version change: |
| 56 | + if this commit has specific message: |
| 57 | + publish package to npm |
| 58 | +``` |
| 59 | + |
| 60 | +#### Notes |
| 61 | + |
| 62 | +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). |
| 63 | + |
| 64 | +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: |
| 65 | + |
| 66 | +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. |
| 67 | +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). |
| 68 | + |
| 69 | +Example script output, where no package versions were changed: |
| 70 | +<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" /> |
| 71 | + |
| 72 | +## Align package versions across monorepo |
| 73 | + |
| 74 | +> Side note: We do not anticipate that this script might be useful in future. With current monorepo setup, all packages versions should be updated and aligned by using `bump-all-updated-packages` script, both in `main` and `*-stable` branches. |
| 75 | +
|
| 76 | +#### Use case |
| 77 | + |
| 78 | +You (or someone from release cycle team) want to verify that the latest versions of @react-native/\* packages are specified across monorepo, including `template`. |
| 79 | + |
| 80 | +#### How to execute |
| 81 | + |
| 82 | +`yarn align-package-versions` |
| 83 | + |
| 84 | +#### Pseudocode |
| 85 | + |
| 86 | +``` |
| 87 | +check that no git changes are present |
| 88 | +
|
| 89 | +for each package x: |
| 90 | + for each package y: |
| 91 | + if y has x as dependency: |
| 92 | + validate that y uses the latest version of x |
| 93 | +``` |
0 commit comments