|
| 1 | +# Beta Release Process (`@bitgo-beta/*`) |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +BitGoJS publishes beta releases under the `@bitgo-beta` scope on npm. The `scripts/prepare-release.ts` |
| 6 | +script transforms the entire monorepo — re-scoping all `@bitgo/*` packages to `@bitgo-beta/*`, computing |
| 7 | +prerelease versions, and pinning all inter-module dependency versions. This enables publishing beta/alpha |
| 8 | +releases without conflicting with stable releases. |
| 9 | + |
| 10 | +## How `prepare-release.ts` Works |
| 11 | + |
| 12 | +``` |
| 13 | +CLI: npx tsx scripts/prepare-release.ts [preid] --scope [scope] --root-dir [dir] |
| 14 | + Defaults: preid=beta, scope=@bitgo-beta, root-dir=<repo-root> |
| 15 | +``` |
| 16 | + |
| 17 | +### Step 1: Scope Replacement |
| 18 | + |
| 19 | +The script walks all `.ts`, `.tsx`, `.js`, `.json` files in `modules/` and `webpack/` (skipping |
| 20 | +`node_modules/`), performing a global regex replacement of every `@bitgo/X` reference with |
| 21 | +`@bitgo-beta/X`. This covers: |
| 22 | + |
| 23 | +- `package.json` dependency entries |
| 24 | +- TypeScript/JavaScript import statements |
| 25 | +- Any other string references to `@bitgo/` scoped packages |
| 26 | + |
| 27 | +**Special case**: The `modules/bitgo` package is the only one published without an `@bitgo/` prefix. |
| 28 | +Its `package.json` name is explicitly set to `@bitgo-beta/bitgo`. |
| 29 | + |
| 30 | +Implementation: `scripts/prepareRelease/changeScopeInFile.ts` |
| 31 | + |
| 32 | +### Step 2: Version Computation |
| 33 | + |
| 34 | +For each module, the script: |
| 35 | + |
| 36 | +1. Fetches dist-tags from npm (`https://registry.npmjs.org/-/package/<name>/dist-tags`) |
| 37 | +2. Determines the previous prerelease version: |
| 38 | + - If a beta tag exists and its base version >= latest, use the beta tag as base |
| 39 | + - If the beta tag's base version < latest, start a new prerelease from latest |
| 40 | + - If no beta tag exists, create one from latest |
| 41 | +3. Computes the next version via `semver.inc(prevTag, 'prerelease', preid)` |
| 42 | + |
| 43 | +Example: `8.2.1-beta.1009` → `8.2.1-beta.1010` |
| 44 | + |
| 45 | +The dist-tag fetch can be cached via `BITGO_PREPARE_RELEASE_CACHE_DIST_TAGS` env var pointing to a |
| 46 | +JSON file, avoiding repeated npm registry calls. |
| 47 | + |
| 48 | +Implementation: `scripts/prepareRelease/distTags.ts` |
| 49 | + |
| 50 | +### Step 3: Cross-Module Version Pinning |
| 51 | + |
| 52 | +After each module's version is bumped, all other modules that depend on it have their dependency |
| 53 | +version updated to the exact new version. This **removes semver ranges** (`^`, `~`), resulting in |
| 54 | +pinned versions: |
| 55 | + |
| 56 | +``` |
| 57 | +Before: "@bitgo/sdk-core": "^31.2.1" |
| 58 | +After: "@bitgo-beta/sdk-core": "8.2.1-beta.1010" |
| 59 | +``` |
| 60 | + |
| 61 | +Implementation: `scripts/prepareRelease/changePackageJson.ts` |
| 62 | + |
| 63 | +## Side Effects for Consumers |
| 64 | + |
| 65 | +Because all dependency versions are pinned (no ranges), consumers of `@bitgo-beta/*` packages must |
| 66 | +**explicitly bump** to new versions when they are published. The `@bitgo/beta-tools` package provides |
| 67 | +a canonical CLI and library for this — see its README for usage. |
| 68 | + |
| 69 | +Key behaviors to understand: |
| 70 | + |
| 71 | +- Each `@bitgo-beta` package has its own **independent prerelease counter** (e.g., |
| 72 | + `sdk-core@8.2.1-beta.788`, `statics@15.1.1-beta.791`). There is no shared suffix — |
| 73 | + what ties a release together is the CI publish run. |
| 74 | +- The `beta` dist-tag on npm always points to the latest published prerelease for each package. |
| 75 | +- Fetching dist-tags individually during a multi-package publish can yield inconsistent versions |
| 76 | + (a race condition): some packages may have the new version while others still show the old one. |
| 77 | + Use `--versions-file` with a CI-generated manifest to avoid this. |
| 78 | + |
| 79 | +## Helper Modules (`scripts/prepareRelease/`) |
| 80 | + |
| 81 | +| File | Purpose | |
| 82 | +|------|---------| |
| 83 | +| `changeScopeInFile.ts` | Regex replacement of `@bitgo/*` → target scope in file contents | |
| 84 | +| `changePackageJson.ts` | Updates dependency versions in `package.json` objects | |
| 85 | +| `distTags.ts` | Fetches/caches npm dist-tags for all modules | |
| 86 | +| `getLernaModules.ts` | Runs `lerna list --json --all` to discover all modules | |
| 87 | +| `walk.ts` | Recursively walks directories, filtering by file extension | |
| 88 | +| `index.ts` | Barrel export | |
| 89 | + |
| 90 | +## Known Limitations |
| 91 | + |
| 92 | +- `setDependencyVersion` in `changePackageJson.ts` only updates `dependencies` and `devDependencies`. |
| 93 | + It does **not** update `peerDependencies` or `buildDependencies` (marked with a FIXME). |
| 94 | +- Three packages are skipped during dist-tag fetch: `@bitgo-beta/express`, `@bitgo-beta/web-demo`, |
| 95 | + `@bitgo-beta/sdk-test` (not published to npm). |
| 96 | + |
| 97 | +## Related Scripts |
| 98 | + |
| 99 | +| Script | Purpose | |
| 100 | +|--------|---------| |
| 101 | +| `scripts/prepare-release.ts` | Main transformation script (this document) | |
| 102 | +| `@bitgo/beta-tools` (`modules/beta-tools`) | Canonical tool for consumers to bump `@bitgo-beta/*` versions | |
0 commit comments