MetaMask / core

This monorepo is a collection of packages used across multiple MetaMask clients
MIT License
294 stars 190 forks source link

Migrate libraries into core monorepo #1079

Open Gudahtt opened 1 year ago

Gudahtt commented 1 year ago

We would like to migrate most MetaMask libraries into this monorepo to make them easier to maintain. We may want to exclude libraries that are:

Here is the list of libraries that seem like a good fit today:

See https://github.com/MetaMask/core/issues/1079#issuecomment-1700126302 for instructions on accomplishing this.

mcmire commented 1 year ago

I propose we focus on the following libraries for Q3:

mcmire commented 1 year ago

I went through the list of existing repos and found some that were omitted from the list above:

mcmire commented 1 year ago

UPDATE October 17, 2023:

Before starting work on future library migrations, please make sure to consult @MajorLift's migration checklist here. The instructions here only cover step B.0 in this checklist.


One thing we want to absolutely make sure to do when we migrate a library to this repo is to preserve all of the Git history.

I experimented with this using @metamask/utils and came up with a process. At a high level, we need to:

  1. Clone the repo for the library somewhere.
  2. Rewrite the entire history of the library as though the entire project had been located in a merged-packages/<library-name> directory all along. (You will soon see why.)
  3. Navigate to core.
  4. Add the library repo as a (local) remote, and fetch its history.
  5. Create a merge commit that connects the primary branch of the library with core's main branch (ignoring unrelated history).
  6. Done! Now we can submit a pull request.

Now we see why we performed step 2: because we want the library to initially be located in core under merged-packages/<library-name>. This directory is special in that ESLint and Prettier will ignore it. This allows us to follow up with another pull request that moves the library into packages and incorporate it into the release workflow.

Here is a list of detailed steps:

  1. Install git-filter-repo. This tool is like Git's filter-branch command, but much easier to use and much less error-prone.
  2. Navigate to a temporary directory: cd /tmp
  3. 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.
  4. cd into the newly cloned repo.
  5. 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 to merged-packages/<package-name>. (This is why we're making a fresh clone in a temporary directory — this action is irreversible.)
  6. cd to wherever you keep the core repo on your machine.
  7. Add the library as a remote: git remote add <package-name> /tmp/<package-name>.
  8. Fetch history: git fetch <package-name> --no-tags
  9. Make a new branch: git checkout -b migrate-<package-name>
  10. Merge the library into the monorepo: git merge --allow-unrelated-histories <package-name>/<primary-branch> (e.g. <primary-branch> = main)
  11. Make a pull request.

The resulting pull request should look like this: https://github.com/MetaMask/core/pull/1520

desi commented 1 year ago

browser-passworder, post-message-stream, web3-stream-provider — Not included because it's extension only Snap-related libraries (eth-snap-keyring, keyring-snaps-registry, snap-simple-keyring, snaps-registry) —not included because Snaps only. object-multiplex, swappable-obj-proxy, and safe-event-emitter - Not included because its not really wallet related, they are more general purpose ppom-validator — Team decided to keep out of core for now - maybe revisit