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.
Prerequisites:
internal-snapshas 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. Installgit-filter-repo.
Add this banner to the top of README.md:
<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>[PR#2] Align dependency versions and TypeScript / ESLint / Prettier / Oxfmt configurations with internal-snaps
- If the snap's dependency versions are ahead of
internal-snaps, update the monorepo root first; otherwise, bump the snap to match. - Copy the relevant tooling configs (
tsconfig.base.jsoncompiler flags,.prettierrc.js,.oxfmtrc.json, the shared ESLint config) so the snap satisfies them on the monorepo's tooling. - Preserve any TypeScript compiler flags enabled in the snap but not in the monorepo.
- Yarn version: if the source repo (or the
packages/snap/package.json) pinsyarn@3.x, upgrade to Yarn 4 (yarn set version berry && yarn set version stable) and re-resolveyarn.lockbefore 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. - Resolve any errors that result from the alignment.
Compare <original-repo>/packages/snap against the current sample-snap from internal-snaps and add anything missing: eslint, jest config, LICENSE, etc.
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.
Warning
- Do not rebase the migration branch: it will disrupt the imported history.
- Merge the PR without squashing. Contact a maintainer to temporarily enable merge commits into
main. - Coordinate with the team to minimise the time the PR stays open; superfluous merge commits to
mainwill pollute the migrated git history. If history pollution occurs, replay the migration on a fresh branch before merging.
- Navigate to a temporary directory:
cd /tmp. - 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. cd snap-tron-wallet.- Rewrite history so the snap package lives at the staging path:
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.bash git filter-repo \\ --path packages/snap/ \\ --path-rename packages/snap/:merged-packages/tron-wallet-snap/ cdinto your local checkout ofinternal-snaps.- Add the rewritten repo as a remote:
git remote add tron-wallet-snap /tmp/snap-tron-wallet. - Fetch history without tags:
git fetch tron-wallet-snap --no-tags. - Create the migration branch:
git checkout -b migrate-tron-wallet-snap. - Merge the snap into the monorepo:
git merge --allow-unrelated-histories tron-wallet-snap/main. - Open a pull request in
internal-snapsthat reflects the above changes.
In merged-packages/tron-wallet-snap/CHANGELOG.md:
- Replace the file with a fresh CHANGELOG that contains only an empty
## [Unreleased]section (no historical releases). - Add a
### Changedentry under## [Unreleased]explaining that the package was migrated, and include a link to the old changelog:This package was migrated from
MetaMask/snap-tron-wallet. See the source repository for the original changelog.
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.
Inside merged-packages/tron-wallet-snap/:
- Remove:
.github/,.git*,.depcheckrc.{json,yml},.yarn/,.yarnrc.yml,yarn.lock,.editorconfig,.eslint*,.prettier*,.oxfmtrc*,.nvm*,lavamoat/,simple-git-hooksconfig,node_modules/,dist/,coverage/, real.envfiles (keep.env.example/.env.sample), and top-levelLICENSEif present alongsideLICENSE.MIT0/LICENSE.APACHE2. - Keep:
src/,tests/,integration-test/(if present),docs/(snap-internal docs),scripts/(snap-internal helpers likebuild-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.
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.)
tsconfig.json: See sample-snap config.jest.config.js: keep the snap's existing config (it already does what@metamask/snaps-jestexpects). Verify itspreset/transform/ customsetupFilesAfterEnv/ custom transformer references (e.g.<rootDir>/svg-transformer.js) still resolve under the monorepo's hoisted dependencies. Preserve anycoverageThreshold,collectCoverageFrom,coveragePathIgnorePatterns, andtestMatchoverrides.- If
jest.integration.config.js(or any other config file) uses ESMexport defaultwhile the rest of the snap is CommonJS, convert it tomodule.exports(or rename to.mjs); ESLint in the monorepo rejects the mismatch. - Keep
babel.config.jsif jest uses babel for transformation. - Add tsconfig reference paths for upstream dependencies: snaps in
internal-snapsare leaf packages and do not consume monorepo workspaces, but this may change in the future.
- Remove redundant build scripts already provided by the monorepo root.
- Remove redundant dev dependencies already listed at the monorepo root. Exception: do not remove
typescript. - Align dependency versions with the monorepo:
- If the snap version is ahead, decrement to match the monorepo (or bump the monorepo in a preceding PR).
- If behind, bump only when there are no resulting breaking changes to resolve.
- Migrate root-level
resolutions: copy any entries from the source repo's rootpackage.json#resolutionsinto the monorepo rootpackage.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. - Migrate LavaMoat allow-list entries: Run
yarn allow-scripts autoto - Move
crowdin.ymlfrom the source repo root (orpackages/snap/) into the package directory so the monorepo's per-package Crowdin tooling treats it independently. - Snap-specific: keep
scripts.buildstarting withmm-snap build(the monorepo constraint only requires the prefix; chaining&& yarn locale:build && yarn build-preinstalled-snap: orbuild:locale, depending on the snap: is supported). Addscripts.prepublishOnly: mm-snap manifestso the manifest shasum stays in sync at publish time. - Edit
package.jsonmetadata:repository.url→https://github.com/MetaMask/internal-snaps.git.homepage→https://github.com/MetaMask/internal-snaps/tree/main/packages/tron-wallet-snap#readme.bugs.url→https://github.com/MetaMask/internal-snaps/issues.license→(MIT-0 OR Apache-2.0).files: includesdist/,snap.manifest.json,images/,locales/.- Add
scripts.changelog:update:../../scripts/update-changelog.sh @metamask/tron-wallet-snap. - Add
scripts.changelog:validate:../../scripts/validate-changelog.sh @metamask/tron-wallet-snap. - Add
scripts.since-latest-release:../../scripts/since-latest-release.sh.
- Preserve the opening sentence/paragraph that introduces the snap.
- Add or modify an "Installation" section (see other snap READMEs once they exist, or model after a core non-root package).
- Preserve the "Usage" section.
- Remove "Test", "Build" and other instructions for common development tasks (these now live in the monorepo's
docs/processes/). - Add a "Contributing" section that links to the monorepo's
docs/processes/.
All Phase C steps go in a single PR. Coordinate with the team to minimise the time it stays open.
git mv merged-packages/tron-wallet-snap packages/tron-wallet-snap
yarn installCheck the snap's tests pass: yarn workspace @metamask/tron-wallet-snap run test.
yarn constraints --fixthenyarn constraintsuntil clean.- Verify
scripts.changelog:validateis present inpackage.json(added in PR#10). yarn allow-scripts autoif the snap brought new lifecycle scripts. Commit the LavaMoat policy update.yarn lint:eslint --fix --suppress-allto absorb existing snap-side findings intoeslint-suppressions.json, thenyarn lintto confirm clean.- Update
teams.json: add"metamask/tron-wallet-snap": "@MetaMask/networks"(or the owning team). - Update
.github/CODEOWNERS: append/packages/tron-wallet-snap/ @MetaMask/networks.
If the migration breaks anything inside the monorepo (rare, since snaps are leaf packages):
- Resolve simple errors in this PR.
- Mark complex/blocked errors with
@ts-expect-error TODO:and file a follow-up issue.
In packages/tron-wallet-snap/CHANGELOG.md under ## [Unreleased], e.g.:
### Changed- Migrated package from
MetaMask/snap-tron-wallettoMetaMask/internal-snaps(no consumer-visible behaviour change). - Re-licensed split into
LICENSE.MIT0+LICENSE.APACHE2files (SPDX expression unchanged).
- Migrated package from
- Confirm all tests pass for the snap and for the rest of the monorepo (CI must be green).
- Double-check that any changes that landed on
mainwhile the PR was open are correctly merged in.
-
Transfer open issues from the source repo into
internal-snapsusing GitHub's Transfer issue feature. Prepend the title with[tron-wallet-snap]. -
Lock open PRs (do not provide a reason). Leave this comment:
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. - Please push this branch to internal-snaps and open a new PR there. - Optionally, add a link pointing to the discussion in this PR to provide context.
For important PRs, manually migrate them into
internal-snapsor create follow-up tickets. -
[PR#12] Replace the migration notice in
snap-tron-wallet/README.mdwith the archive notice (this replaces the banner added in PR#1):<table> <tr> <td> <p align="center"><b>⚠️ PLEASE READ ⚠️</b></p> <p align="center"> This package has been migrated to our <a href="<https://github.com/MetaMask/internal-snaps>" ><code>internal-snaps</code></a > monorepo, and this repository has been archived. Please note that all future development and feature releases will take place in the <a href="<https://github.com/MetaMask/internal-snaps>" ><code>internal-snaps</code></a > repository. </p> </td> </tr> </table>
-
Archive the source repository. Contact a maintainer to perform this step. Keep tags and the final release intact for npm-package history continuity.
- Fix any
@ts-expect-error TODO:annotations added during PR#12. Do this before the first post-migration release if possible. - [PR#13] Cut the first post-migration release with
yarn create-release-branch -i. - Verify the preview-build workflow by opening a no-op PR against the new package and confirming the preview-publish job posts.