This document outlines the process for migrating a MetaMask library into the metamask module template. The migration target is assumed to comply with the requirements defined by metamask-module-template
and module-lint
.
<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/metamask-design-system"><code>metamask-design-system</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 metamask module template.</p></td></tr></table>
2. Add the source repo to the ZenHub workspace repo filter so that its issues/PRs show up on the board
[PR#2] 3. Align dependency versions and TypeScript, ESLint, Prettier configurations with the core monorepo
- If the dependency versions of the migration target are ahead of metamask design system, consider updating the metamask design system dependencies first.
- Apply the configurations of the metamask module template to the source repo files.
- Preserve any TypeScript compiler flags that are enabled in the source repo but not in metamask design system.
- Resolve any errors or issues resulting from these changes.
- Example PR
[PR#4] 5. Rename the migration target package so that it is prepended by the @metamask/
namespace (skip if not applicable)
- Modify the "name" field in
package.json
. - Update the title of the README.md.
- Add a CHANGELOG entry for the rename.
- All subsequent releases of the migration target will be made from the metamask design system monorepo.
- Example PR
[PR#6] 1. Migrate the source repo's git history into the merged-packages/
temporary directory in metamask design system
- Install
git-filter-repo
. This tool is like Git'sfilter-branch
command, but much easier to use and much less error-prone. - Navigate to a temporary directory:
cd /tmp
- Clone the repo for the library you want to migrate:
git clone https://github.com/MetaMask/<repo-name>
(e.g.<repo-name>
=utils
). Do NOT use an existing clone. cd
into the newly cloned repo.- Run
git filter-repo --to-subdirectory-filter merged-packages/<package-name>
(e.g.<package-name>
=utils
). This will rewrite all history to move all files tomerged-packages/<package-name>
. (This is why we're making a fresh clone in a temporary directory — this action is irreversible.) cd
to wherever you keep themetamask-design-system
repo on your machine.- Add the library as a remote:
git remote add <package-name> /tmp/<package-name>
. - Fetch history:
git fetch <package-name> --no-tags
- Make a new branch:
git checkout -b migrate-<package-name>
- Merge the library into the monorepo:
git merge --allow-unrelated-histories <package-name>/<primary-branch>
(e.g.<primary-branch>
=main
) - Open a pull request in the metamask module template that reflects the above changes.
Warning
- DO NOT rebase the
migrate-<package-name>
branch, as this will disrupt the git history. - Ensure that superfluous merge commits to the main branch don't pollute the migrated git history.
- Coordinate with the team to minimize the time that this PR stays open.
- If necessary, replace the PR branch with a cleaned-up commit history by rerunning the git history migration steps before merging the PR.
- For further context on this: MetaMask/core#1804 (comment)
- Merge PR without squashing to preserve the migrated git commit history.
- Contact a maintainer to temporarily enable merge commits into main.
[PR#7] 2. Update the CHANGELOG tag diff links so that they follow the metamask module template's tag naming convention
- The metamask module template tags for non-root packages should be formatted as:
<package-name>@[version-number]
.- For all releases following the migration, the package name should be prepended with the
@metamask/
namespace.
- For all releases following the migration, the package name should be prepended with the
- Make updates to the CHANGELOG tag diff links so that they follow this naming scheme:
- Navigate to
merged-packages/<package-name>
- Run this command:
../../scripts/validate-changelog.sh @metamask/<package-name>
- Apply the diffs outputted by the script.
- Navigate to
- If the package has been renamed or needs to be renamed with the
@metamask/
namespace, supply two arguments to the script:--version-before-package-rename
,--tag-prefix-before-package-rename
. - For further instructions on using the script, see: https://github.com/MetaMask/auto-changelog#validate.
- Following these instructions, use the
scripts/migrate-tags.sh
tool to port the source repo's release tags onto the migrated git history in metamask design system.
- Port the tags locally.
- Use the script to ensure that the tags have the correct package name prefixes.
- Create a fork of the metamask design system for testing, and push the ported tags to the test fork.
- Do not run the script against
MetaMask/metamask-design-system
before testing it on a fork.
- From the fork, verify that the tag diff links in CHANGELOG are working.
- Note: The diff between any tag before migration and any tag after will always include the entire history of the monorepo. This is due to the nature of the process we use for git history migration, and is a WONTFIX issue.
- The correct diff can be derived using
git log --ancestry-path
, but GitHub compare links don't support --ancestry-path.
-
Push the ported tags to the metamask-design-system.
-
From the metamask-design-system, verify that the tag diff links in CHANGELOG are working.
-
Manually create tags for release commits that were never tagged in the original repo.
[PR#8] 4. Remove files and directories that will be replaced by files in the monorepo root directory
- Remove:
.github/
,.git*
,scripts/
,.depcheckrc.json
,.yarn/
,.yarnrc.yml
,yarn.lock
,.editorconfig
,.eslint*
,.prettier*
,.nvm*
. - Keep:
src/
,tests/
,CHANGELOG.md
,LICENSE
,package.json
,README.md
,jest.config.js
,tsconfig*.json
- Example PR
- Update
tsconfig*.json
,jest.config.js
to extend from the corresponding files in the root directory by copying the contents of these files from other non-root packages. - Preserve TypeScript compiler flags and its compilation target.
- Add tsconfig reference paths for non-root packages that are upstream dependencies of the migration target.
- Preserve Jest coverage threshold values.
- Add
deepmerge
as a devDependency. - Example PR
- Remove redundant build scripts that are already listed in the root package.json (including
prepack
) - Remove redundant dependencies that are already listed in the root package.json.
- Exception: do not remove TypeScript.
- Align dependency versions with other non-root packages.
- If migration target dependency version is ahead: Decrement to match monorepo packages.
- If it's behind:
- Bump if it's an internal dependency (i.e. the dependency is another sub-package in the monorepo).
- If it's external, bump only if there are no resulting breaking changes that need to be resolved.
- Example PR
- If the migration target uses a non-MIT license, add exception entries in the root
constraints.pro
file.- In the license section of
constraints.pro
: Exclude (\=
) and include (==
) the package in the appropriate license rules.
- In the license section of
- Make sure the new rule doesn't break any of the existing package.json files by running
yarn constraints
. - Example PR
- Preserve the opening sentence/paragraph that introduces the package.
- Add or modify an "Installation" section (see the READMEs of other non-root packages for examples).
- Preserve the "Usage" section.
- Remove "Test", "Build" and other instructions on common development tasks.
- Add a "Contributing" section (see the READMEs of other non-root packages for examples).
- The following steps of "Phase C" need to happen in a single PR.
- Coordinate with the team to minimize the time that this PR stays open to avoid merge conflicts with the main branch from accumulating.
- Example PR
- Run
yarn install
in the root directory. - Check that all tests are passing in migration target by running
yarn workspace @metamask/<package-name> test
.
- IMPORTANT Add reference paths for the migration target in the root
tsconfig.json
andtsconfig.build.json
files.- This step is essential to avoid build failure for the migration target during release workflow.
- Add tsconfig reference paths for the migration target in downstream packages.
- Bump the migration target version in downstream packages and root.
- Notes on why this version bump needs to happen as part of this PR (import module shadowing): MetaMask/core#1738 (comment)
- Apply yarn constraints fixes to migration target package.json file:
yarn constraints --fix
. - Add the
changelog:validate
build script to the package.json file.
- If introducing the migration target breaks any downstream repos:
- Resolve simple errors as part of this PR.
- Mark and ignore complex/blocked errors using
@ts-expect-error TODO:
annotations.
- Create a separate issue for resolving the marked errors as soon as the migration is completed.
- e.g. MetaMask/core#1823
5. Record changes made to any metamask design system package in its CHANGELOG, under the ## [Unreleased]
heading
- CHANGELOG entries should be recorded in the migration target's downstream packages for version bumps to the migration target's current release.
- Example PR: this step can be performed either as a part of Phase C, or in a separate, subsequent PR.
- Check that all tests are passing in all subpackages of metamask design system and CI.
- Double-check that dependency version bumps or other changes made to main while the PR was open are correctly merged and reflected.
-
Transfer open issues from the source repo into the metamask module template using GitHub's
Transfer issue
feature (prepend the title with the package name:[<package-name>]
). -
For open PRs in the source repo, lock conversation (do not provide a reason), and leave a comment requesting that authors reopen the PR in metamask design system with a link pointing to the discussion in the original PR. For important PRs, manually migrate into metamask design system or create tickets for follow-up.
This library has now been migrated into the [metamask module template](https://github.com/metamask/metamask-design-system/). 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 metamask module template.
- Please push this branch to metamask design system and open a new PR there.
- Optionally, add a link pointing to the discussion in this PR to provide context.
- [PR#14] Leave a note in the source repo's README announcing the migration and pointing to metamask design system.
- This note should replace the notice added in step A-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/metamask-design-system"
><code>metamask-design-system</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/metamask-design-system"
><code>metamask-design-system</code></a
>
repository.
</p>
</td>
</tr>
</table>
- Archive the source repo to prevent any changes from being pushed to it going forward.
- Contact a maintainer to perform this step.
- [PR#15] Add migration target to the list of packages in the README as well as the dependency graph in the README by running
yarn update-readme-content
. - Fix downstream errors that were marked with
@ts-expect-error TODO:
during the migration process.
- If possible, perform this step before the first post-migration release of the migrated package.
- [PR#16] Use the
yarn create-release-branch
tool to publish a release of metamask design system with a new version for the migrated package and any updated downstream packages.