Skip to content

Commit 9660968

Browse files
committed
docs: add snap migration process guide
1 parent 381ba82 commit 9660968

3 files changed

Lines changed: 230 additions & 0 deletions

File tree

‎README.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

33
This monorepo hosts MetaMask's first-party Snaps along with shared tooling and infrastructure for building, testing, and releasing them.
44

5+
## Contributing
6+
7+
See the [Contributor Documentation](./docs) for help on:
8+
9+
- Setting up your development environment
10+
- Working with the monorepo
11+
- Testing changes in clients
12+
- Issuing new releases
13+
- Creating a new package
14+
515
## Installation/Usage
616

717
Each snap in this repository has its own README with installation and usage instructions. See `packages/` for more.

‎docs/README.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Contributor Documentation
2+
3+
Hi! Welcome to the contributor documentation for the `internal-snaps` monorepo.
4+
5+
## Processes
6+
7+
- [Migrating external snaps to the monorepo](./processes/package-migration-process-guide.md)
Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
# Snap migration process guide
2+
3+
This document outlines the process for migrating a MetaMask first-party Snap into the `internal-snaps` monorepo. The migration target is assumed to be based off template-snap-monorepo.
4+
5+
> Prerequisites: `internal-snaps` has been created and prepared to host snaps, its CI is green, and the host repo grants merge access for the migration PRs. The migration target must be in a clean state with all in-flight work merged or rebased. Install `git-filter-repo`.
6+
7+
---
8+
9+
## Phase A: Preparation in the original repository
10+
11+
### [PR#1] Add the migration notice to the README
12+
13+
Add this banner to the top of `README.md`:
14+
15+
```markdown
16+
<table><tr><td><p align="center"><b>⚠️ PLEASE READ ⚠️</b></p><p align="center">This package is currently being migrated to our <a href="<https://github.com/MetaMask/internal-snaps>"><code>internal-snaps</code></a> monorepo. Please do not make any commits to this repository while this migration is taking place, as they will not be transferred over. Also, please re-open PRs that are under active development in the <code>internal-snaps</code> repo.</p></td></tr></table>
17+
```
18+
19+
### [PR#2] Align dependency versions and TypeScript / ESLint / Prettier / Oxfmt configurations with `internal-snaps`
20+
21+
- If the snap's dependency versions are ahead of `internal-snaps`, update the monorepo root first; otherwise, bump the snap to match.
22+
- Copy the relevant tooling configs (`tsconfig.base.json` compiler flags, `.prettierrc.js`, `.oxfmtrc.json`, the shared ESLint config) so the snap satisfies them on the monorepo's tooling.
23+
- Preserve any TypeScript compiler flags enabled in the snap but not in the monorepo.
24+
- **Yarn version**: if the source repo (or the `packages/snap/package.json`) pins `[email protected]`, upgrade to Yarn 4 (`yarn set version berry && yarn set version stable`) and re-resolve `yarn.lock` before merging. The monorepo runs Yarn 4; a yarn-3 lockfile will be re-generated on first install in the monorepo regardless, but bumping in the source repo first avoids surprise dependency-resolution diffs at integration time.
25+
- Resolve any errors that result from the alignment.
26+
27+
### [PR#3] Reconcile with `template-snap-monorepo`
28+
29+
Compare `<original-repo>/packages/snap` against the current sample-snap from `internal-snaps` and add anything missing: eslint, jest config, `LICENSE`, etc.
30+
31+
### [PR#4] Cut a final release from the source repo
32+
33+
Cut and publish a final release of the package from the original repository. All subsequent releases happen from `internal-snaps`. Keep the release tag for the changelog link in PR#7.
34+
35+
---
36+
37+
## Phase B: Staging from `internal-snaps`'s `merged-packages/`
38+
39+
### [PR#5] Migrate the source repo's git history into `merged-packages/`
40+
41+
> [!WARNING]
42+
>
43+
> - **Do not rebase** the migration branch: it will disrupt the imported history.
44+
> - **Merge the PR without squashing.** Contact a maintainer to temporarily enable merge commits into `main`.
45+
> - Coordinate with the team to minimise the time the PR stays open; superfluous merge commits to `main` will pollute the migrated git history. If history pollution occurs, replay the migration on a fresh branch before merging.
46+
1. Navigate to a temporary directory: `cd /tmp`.
47+
2. Clone a fresh copy of the source repo: `git clone <https://github.com/MetaMask/snap-tron-wallet`>. **Do not** reuse an existing clone: the next step rewrites history irreversibly.
48+
3. `cd snap-tron-wallet`.
49+
4. Rewrite history so the snap package lives at the staging path:
50+
This both isolates the snap package (drops the `packages/site/` test-dapp and any other top-level files) and moves it into the staging directory in a single rewrite. If the source repo is **not** itself a monorepo (i.e. the snap lives at the repo root), use `-path-rename :merged-packages/<name>-snap/` instead.
51+
52+
```bash
53+
git filter-repo \\
54+
--path packages/snap/ \\
55+
--path-rename packages/snap/:merged-packages/tron-wallet-snap/
56+
```
57+
58+
5. `cd` into your local checkout of `internal-snaps`.
59+
6. Add the rewritten repo as a remote: `git remote add tron-wallet-snap /tmp/snap-tron-wallet`.
60+
7. Fetch history without tags: `git fetch tron-wallet-snap --no-tags`.
61+
8. Create the migration branch: `git checkout -b migrate-tron-wallet-snap`.
62+
9. Merge the snap into the monorepo: `git merge --allow-unrelated-histories tron-wallet-snap/main`.
63+
10. Open a pull request in `internal-snaps` that reflects the above changes.
64+
65+
### [PR#6] Reset the CHANGELOG, linking back to the old repository
66+
67+
In `merged-packages/tron-wallet-snap/CHANGELOG.md`:
68+
69+
- Replace the file with a fresh CHANGELOG that contains only an empty `## [Unreleased]` section (no historical releases).
70+
- Add a `### Changed` entry under `## [Unreleased]` explaining that the package was migrated, and include a link to the old changelog:
71+
72+
> This package was migrated from `MetaMask/snap-tron-wallet`. See the source repository for the original changelog.
73+
>
74+
75+
do **not** try to rewrite the old tag-diff links to point at `internal-snaps`. The old tags do not exist in the new repo, so the links would 404.
76+
77+
### [PR#7] Remove files and directories replaced by the monorepo root
78+
79+
Inside `merged-packages/tron-wallet-snap/`:
80+
81+
- **Remove**: `.github/`, `.git*`, `.depcheckrc.{json,yml}`, `.yarn/`, `.yarnrc.yml`, `yarn.lock`, `.editorconfig`, `.eslint*`, `.prettier*`, `.oxfmtrc*`, `.nvm*`, `lavamoat/`, `simple-git-hooks` config, `node_modules/`, `dist/`, `coverage/`, real `.env` files (keep `.env.example` / `.env.sample`), and top-level `LICENSE` if present alongside `LICENSE.MIT0` / `LICENSE.APACHE2`.
82+
- **Keep**: `src/`, `tests/`, `integration-test/` (if present), `docs/` (snap-internal docs), `scripts/` (snap-internal helpers like `build-preinstalled-snap.js`, `populate-en-locale.js` / `populate-locale.js`, `update-manifest-local.js`), `CHANGELOG.md`, `package.json`, `README.md`, `jest.config.js`, `jest.integration.config.js`, `jest.setup.ts` (if present), custom jest transformers (e.g. `svg-transformer.js`), `babel.config.js` (if jest uses babel), `tsconfig*.json`, `snap.manifest.json`, `snap.config.ts`, `messages.json`, `openrpc.json`, `keyring.openrpc.json`, `images/`, `locales/`, `crowdin.yml`, `.env.example` / `.env.sample`, `LICENSE.MIT0`, `LICENSE.APACHE2`.
83+
84+
Carry over any snap-specific Yarn patches into the monorepo root `.yarn/patches/`. For Tron, this means `tronweb-npm-6.1.0-771b242b6a.patch`. (e.g., Solana and Bitcoin have no patches; this step is no-op for them.)
85+
86+
### [PR#8] Replace config files
87+
88+
- `tsconfig.json`: See sample-snap config.
89+
- `jest.config.js`: keep the snap's existing config (it already does what `@metamask/snaps-jest` expects). Verify its `preset` / `transform` / custom `setupFilesAfterEnv` / custom transformer references (e.g. `<rootDir>/svg-transformer.js`) still resolve under the monorepo's hoisted dependencies. Preserve any `coverageThreshold`, `collectCoverageFrom`, `coveragePathIgnorePatterns`, and `testMatch` overrides.
90+
- If `jest.integration.config.js` (or any other config file) uses ESM `export default` while the rest of the snap is CommonJS, convert it to `module.exports` (or rename to `.mjs`); ESLint in the monorepo rejects the mismatch.
91+
- Keep `babel.config.js` if jest uses babel for transformation.
92+
- Add tsconfig reference paths for upstream dependencies: snaps in `internal-snaps` are leaf packages and do not consume monorepo workspaces, but this may change in the future.
93+
94+
### [PR#9] Align dependencies and build scripts with the monorepo
95+
96+
- Remove redundant build scripts already provided by the monorepo root.
97+
- Remove redundant dev dependencies already listed at the monorepo root. **Exception**: do not remove `typescript`.
98+
- Align dependency versions with the monorepo:
99+
- If the snap version is ahead, decrement to match the monorepo (or bump the monorepo in a preceding PR).
100+
- If behind, bump only when there are no resulting breaking changes to resolve.
101+
- **Migrate root-level `resolutions`**: copy any entries from the source repo's root `package.json#resolutions` into the monorepo root `package.json#resolutions`, merging with the existing set. Common offenders: `@metamask/snaps-sdk` (Solana, Bitcoin), `@types/react` / `@types/react-dom` (Solana). If snaps in the monorepo disagree on a pinned version, raise it to a coordination decision before merging.
102+
- **Migrate LavaMoat allow-list entries**: Run `yarn allow-scripts auto` to
103+
- **Move `crowdin.yml`** from the source repo root (or `packages/snap/`) into the package directory so the monorepo's per-package Crowdin tooling treats it independently.
104+
- **Snap-specific**: keep `scripts.build` starting with `mm-snap build` (the monorepo constraint only requires the prefix; chaining `&& yarn locale:build && yarn build-preinstalled-snap`: or `build:locale`, depending on the snap: is supported). Add `scripts.prepublishOnly: mm-snap manifest` so the manifest shasum stays in sync at publish time.
105+
- Edit `package.json` metadata:
106+
- `repository.url` → `https://github.com/MetaMask/internal-snaps.git`.
107+
- `homepage` → `https://github.com/MetaMask/internal-snaps/tree/main/packages/tron-wallet-snap#readme`.
108+
- `bugs.url` → `https://github.com/MetaMask/internal-snaps/issues`.
109+
- `license` → `(MIT-0 OR Apache-2.0)`.
110+
- `files`: includes `dist/`, `snap.manifest.json`, `images/`, `locales/`.
111+
- Add `scripts.changelog:update`: `../../scripts/update-changelog.sh @metamask/tron-wallet-snap`.
112+
- Add `scripts.changelog:validate`: `../../scripts/validate-changelog.sh @metamask/tron-wallet-snap`.
113+
- Add `scripts.since-latest-release`: `../../scripts/since-latest-release.sh`.
114+
115+
### [PR#10] Update the README to reflect non-root-package status
116+
117+
- Preserve the opening sentence/paragraph that introduces the snap.
118+
- Add or modify an "Installation" section (see other snap READMEs once they exist, or model after a core non-root package).
119+
- Preserve the "Usage" section.
120+
- Remove "Test", "Build" and other instructions for common development tasks (these now live in the monorepo's `docs/processes/`).
121+
- Add a "Contributing" section that links to the monorepo's `docs/processes/`.
122+
123+
---
124+
125+
## [PR#11] Phase C: Integration into `packages/`
126+
127+
All Phase C steps go in a **single** PR. Coordinate with the team to minimise the time it stays open.
128+
129+
### 1. Move the package from `merged-packages/` to `packages/`
130+
131+
```bash
132+
git mv merged-packages/tron-wallet-snap packages/tron-wallet-snap
133+
yarn install
134+
```
135+
136+
Check the snap's tests pass: `yarn workspace @metamask/tron-wallet-snap run test`.
137+
138+
### 2. Linter and constraints fixes
139+
140+
- `yarn constraints --fix` then `yarn constraints` until clean.
141+
- Verify `scripts.changelog:validate` is present in `package.json` (added in PR#10).
142+
- `yarn allow-scripts auto` if the snap brought new lifecycle scripts. Commit the LavaMoat policy update.
143+
- `yarn lint:eslint --fix --suppress-all` to absorb existing snap-side findings into `eslint-suppressions.json`, then `yarn lint` to confirm clean.
144+
- Update `teams.json`: add `"metamask/tron-wallet-snap": "@MetaMask/networks"` (or the owning team).
145+
- Update `.github/CODEOWNERS`: append `/packages/tron-wallet-snap/ @MetaMask/networks`.
146+
147+
### 4. Resolve or TODO downstream errors
148+
149+
If the migration breaks anything inside the monorepo (rare, since snaps are leaf packages):
150+
151+
- Resolve simple errors in this PR.
152+
- Mark complex/blocked errors with `@ts-expect-error TODO:` and file a follow-up issue.
153+
154+
### 5. Record changes in CHANGELOG `[Unreleased]`
155+
156+
In `packages/tron-wallet-snap/CHANGELOG.md` under `## [Unreleased]`, e.g.:
157+
158+
- `### Changed`
159+
- Migrated package from `MetaMask/snap-tron-wallet` to `MetaMask/internal-snaps` (no consumer-visible behaviour change).
160+
- Re-licensed split into `LICENSE.MIT0` + `LICENSE.APACHE2` files (SPDX expression unchanged).
161+
162+
### 6. Finalize merge
163+
164+
- Confirm all tests pass for the snap and for the rest of the monorepo (CI must be green).
165+
- Double-check that any changes that landed on `main` while the PR was open are correctly merged in.
166+
167+
---
168+
169+
## Phase D: Clean-up and release
170+
171+
### Source repo (`snap-tron-wallet`)
172+
173+
1. **Transfer open issues** from the source repo into `internal-snaps` using GitHub's *Transfer issue* feature. Prepend the title with `[tron-wallet-snap]`.
174+
2. **Lock open PRs** (do not provide a reason). Leave this comment:
175+
176+
```markdown
177+
This library has now been migrated into the internal-snaps monorepo. This PR has been locked and this repo will be archived shortly. Going forward, releases of this library will only include changes made in the internal-snaps repo.
178+
179+
- Please push this branch to internal-snaps and open a new PR there.
180+
- Optionally, add a link pointing to the discussion in this PR to provide context.
181+
```
182+
183+
For important PRs, manually migrate them into `internal-snaps` or create follow-up tickets.
184+
185+
3. **[PR#12] Replace the migration notice in `snap-tron-wallet/README.md`** with the archive notice (this replaces the banner added in PR#1):
186+
187+
```html
188+
<table>
189+
<tr>
190+
<td>
191+
<p align="center"><b>⚠️ PLEASE READ ⚠️</b></p>
192+
<p align="center">
193+
This package has been migrated to our
194+
<a href="<https://github.com/MetaMask/internal-snaps>"><code>internal-snaps</code></a>
195+
monorepo, and this repository has been archived. Please note that all
196+
future development and feature releases will take place in the
197+
<a href="<https://github.com/MetaMask/internal-snaps>"><code>internal-snaps</code></a>
198+
repository.
199+
</p>
200+
</td>
201+
</tr>
202+
</table>
203+
```
204+
205+
4. **Archive the source repository**. Contact a maintainer to perform this step. Keep tags and the final release intact for npm-package history continuity.
206+
207+
### `internal-snaps`
208+
209+
1. **[PR#13] Update `README.md` package list** to include `@metamask/tron-wallet-snap`.
210+
- The canonical guide instructs running `yarn update-readme-content`. That script was removed during bootstrap (see `BOOTSTRAP.md` step 2). **Update the package list manually.** If/when a dependency graph is reintroduced, document a replacement script and update this step.
211+
2. **Fix any `@ts-expect-error TODO:` annotations** added during PR#12. Do this before the first post-migration release if possible.
212+
3. **[PR#14] Cut the first post-migration release** with `yarn create-release-branch` (follow `docs/processes/releasing.md`).
213+
4. **Verify the preview-build workflow** by opening a no-op PR against the new package and confirming the preview-publish job posts.

0 commit comments

Comments
 (0)