Skip to content

Conversation

@mcmire
Copy link
Contributor

@mcmire mcmire commented Jan 23, 2026

Description

Some MetaMask repos (e.g. core) allow upcoming package changes to be tested in Extension and/or Mobile prior to release by publishing "preview builds".

However, using a preview build can be complicated, as care must be taken to accurately simulate what the dependency tree of a project will look like when a new production version is released.

To make this process easier, this commit adds a Yarn plugin. The plugin works like this:

  1. First, you must tell the plugin which preview builds you want to use for which dependencies. You do this by adding an entry to a previewBuilds section in package.json. For instance, to specify that version 29.0.0-preview-3ec2a74 should be used to test non-breaking changes to @metamask/network-controller, you would add:

     "previewBuilds": {
       "@metamask/network-controller": {
         "type": "non-breaking",
         "previewVersion": "29.0.0-preview-3ec2a74"
       }
     }
    

    Similarly, you could set type to "breaking" to test breaking changes.

    By default the plugin will assume the NPM scope of the preview build to be metamask-previews, but you can change this with previewScope:

     "previewBuilds": {
       "@metamask/network-controller": {
         "type": "non-breaking",
         "previewScope": "my-custom-scope"
         "previewVersion": "29.0.0-preview-3ec2a74",
       }
     }
    
  2. Next, run yarn install. The plugin will read the previewBuilds section to determine how the dependencies you've specified should be resolved. If the type of an entry is "non-breaking", all version ranges of that dependency in the dependency tree that are major-compatible with the corresponding entry in dependencies will resolve to the preview build. If the type is "breaking", then only the version range of the corresponding entry in dependencies will resolve to the preview build. Finally, if a dependency is patched, the preview build will be patched in the same way.

Changelog

CHANGELOG entry: null

Related issues

https://consensyssoftware.atlassian.net/browse/WPC-199

Manual testing steps

  • Add the following section to package.json:
    "previewBuilds": {
      "@metamask/network-controller": {
        "type": "breaking",
        "previewVersion": "29.0.0-preview-3ec2a74"
      }
    },
    
  • Run yarn install. You should see a message at the end of the installation steps:
    [plugin-preview-builds] The following dependencies were mapped to preview builds:
    - metamask@workspace:./@metamask/network-controller@npm:^29.0.0 -> npm:@metamask-previews/[email protected]
    
  • Run yarn why @metamask-previews/network-controller. You should see only one entry:
    └─ metamask@workspace:.
       └─ @metamask-previews/network-controller@npm:29.0.0-preview-3ec2a74 (via npm:@metamask-previews/[email protected])
    
    This proves that only the root instance of @metamask/network-controller was updated to use the preview build.
  • Update previewBuilds in package.json to read:
    "previewBuilds": {
      "@metamask/network-controller": {
        "type": "non-breaking",
        "previewVersion": "29.0.0-preview-3ec2a74"
      }
    },
    
  • Run yarn install. You should see a message at the end of the installation steps:
    [plugin-preview-builds] The following dependencies were mapped to preview builds:
    - @metamask/network-controller@npm:^29.0.0 -> npm:@metamask-previews/[email protected]
    
  • Run yarn why @metamask-previews/network-controller. You should see a bunch of entries:
    ├─ @metamask/accounts-controller@npm:35.0.2
    │  └─ @metamask-previews/network-controller@npm:29.0.0-preview-3ec2a74 (via npm:@metamask-previews/[email protected])
    │
    ├─ @metamask/accounts-controller@npm:35.0.2 [2d27a]
    │  └─ @metamask-previews/network-controller@npm:29.0.0-preview-3ec2a74 (via npm:@metamask-previews/[email protected])
    │
    ├─ @metamask/accounts-controller@npm:35.0.2 [30658]
    │  └─ @metamask-previews/network-controller@npm:29.0.0-preview-3ec2a74 (via npm:@metamask-previews/[email protected])
    ...
    
    This proves that all instances of @metamask/network-controller matching ^29.0.0 were updated to use the preview build.
  • Now take away previewBuilds and re-run yarn install.
  • Now run yarn patch @metamask/network-controller@npm:29.0.0. Open the resulting patch directory and make a modification to any file. Run yarn patch-commit -s <directory> to generate the patch and update package.json, then run yarn install to apply the patch.
  • Now add the following section back to package.json:
    "previewBuilds": {
      "@metamask/network-controller": {
        "type": "breaking",
        "previewVersion": "29.0.0-preview-3ec2a74"
      }
    },
    
  • Run yarn install. You should see a message at the end of the installation steps:
    [plugin-preview-builds] The following dependencies were mapped to preview builds:
    - metamask@workspace:./@metamask/network-controller@patch:@metamask/network-controller@npm%3A29.0.0#~/.yarn/patches/@metamask-network-controller-npm-29.0.0-51af044f37.patch
      -> patch:@metamask-previews/network-controller@npm%3A29.0.0-preview-3ec2a74#~/.yarn/patches/@metamask-network-controller-npm-29.0.0-51af044f37.patch
    
  • Run yarn why @metamask/network-controller. You should see a bunch of entries:
    ├─ @metamask/accounts-controller@npm:35.0.2
    │  └─ @metamask/network-controller@patch:@metamask/network-controller@npm%3A29.0.0#~/.yarn/patches/@metamask-network-controller-npm-29.0.0-51af044f37.patch::version=29.0.0&hash=3e054c (via patch:@metamask/network-controller@npm%3A29.0.0#~/.yarn/patches/@metamask-network-controller-npm-29.0.0-51af044f37.patch)
    │
    ├─ @metamask/accounts-controller@npm:35.0.2 [2d27a]
    │  └─ @metamask/network-controller@patch:@metamask/network-controller@npm%3A29.0.0#~/.yarn/patches/@metamask-network-controller-npm-29.0.0-51af044f37.patch::version=29.0.0&hash=3e054c (via patch:@metamask/network-controller@npm%3A29.0.0#~/.yarn/patches/@metamask-network-controller-npm-29.0.0-51af044f37.patch)
    │
    ├─ @metamask/accounts-controller@npm:35.0.2 [30658]
    │  └─ @metamask/network-controller@patch:@metamask/network-controller@npm%3A29.0.0#~/.yarn/patches/@metamask-network-controller-npm-29.0.0-51af044f37.patch::version=29.0.0&hash=3e054c (via patch:@metamask/network-controller@npm%3A29.0.0#~/.yarn/patches/@metamask-network-controller-npm-29.0.0-51af044f37.patch)
    │
    
    This proves that the preview build is patched.

Screenshots/Recordings

(N/A)

Before

After

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Note

Introduces a Yarn v4 plugin to map @metamask/* dependencies to preview packages (e.g., @metamask-previews/*) based on a previewBuilds config in package.json.

  • New @yarnpkg/plugin-preview-builds.cjs implements validateProject, reduceDependency, and afterAllInstalled hooks; supports type (breaking vs non-breaking), optional previewScope, preserves patch: descriptors, and logs mapped resolutions
  • Updates .yarnrc.yml to register the plugin and preapprove @metamask/*, @metamask-previews/*, @lavamoat/*, and @consensys/* for age-gate bypass
  • Adds @yarnpkg/core to .depcheckrc.yml ignores for plugin usage

Written by Cursor Bugbot for commit c400892. This will update automatically on new commits. Configure here.

@github-actions
Copy link
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@metamaskbot metamaskbot added the team-core-platform Core Platform team label Jan 23, 2026
@mcmire mcmire changed the title Add Yarn plugin for using preview builds chore: Add Yarn plugin for using preview builds Jan 23, 2026
@mcmire mcmire force-pushed the add-use-preview-build-yarn-plugin branch 2 times, most recently from c9dc800 to ad045c2 Compare January 23, 2026 05:04
Some MetaMask repos (e.g. `core`) allow upcoming package changes to be
tested in Extension and/or Mobile prior to release by publishing
"preview builds".

However, using a preview build can be complicated, as care must be taken
to accurately simulate what the dependency tree of a project will look
like when a new production version is released.

To make this process easier, this commit adds a Yarn plugin. The plugin
works like this:

1. First, you must tell the plugin which preview builds you want to use
   for which dependencies. You do this by adding an entry to a
   `previewBuilds` section in `package.json`. For instance, to specify
   that version `29.0.0-preview-3ec2a74` should be used to test
   non-breaking changes to `@metamask/network-controller`, you would
   add:

        "previewBuilds": {
          "@metamask/network-controller": {
            "type": "non-breaking",
            "previewVersion": "29.0.0-preview-3ec2a74"
          }
        }

    Similarly, you could set `type` to "breaking" to test breaking
    changes.

    By default the plugin will assume the NPM scope of the preview build
    to be `@metamask-previews`, but you can change this with
    `previewScope`:

        "previewBuilds": {
          "@metamask/network-controller": {
            "type": "non-breaking",
            "previewScope": "my-custom-scope"
            "previewVersion": "29.0.0-preview-3ec2a74",
          }
        }

2. Next, run `yarn install`. The plugin will read the `previewBuilds`
   section to determine how the dependencies you've specified should be
   resolved. If the `type` of an entry is "non-breaking", all version
   ranges of that dependency in the dependency tree that are
   major-compatible with the corresponding entry in `dependencies` will
   resolve to the preview build. If the `type` is "breaking", then only
   the version range of the corresponding entry in `dependencies` will
   resolve to the preview build. Finally, if a dependency is patched,
   the preview build will be patched in the same way.
@mcmire mcmire marked this pull request as ready for review January 23, 2026 05:44
cursor[bot]

This comment was marked as outdated.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Co-authored-by: cryptodev-2s <[email protected]>
Copy link
Contributor

@cryptodev-2s cryptodev-2s left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@github-actions
Copy link
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: None (no tests recommended)
  • Risk Level: low
  • AI Confidence: 95%
click to see 🤖 AI reasoning details

The changes in this PR are purely related to Yarn dependency management infrastructure:

  1. .depcheckrc.yml: Adds @yarnpkg/core to the ignore list for dependency checking - this is a configuration change for the depcheck tool.

  2. .yarn/plugins/@yarnpkg/plugin-preview-builds.cjs: A new Yarn plugin that allows engineers to use preview builds of MetaMask packages. This plugin only activates when there's a previewBuilds key in package.json, which is NOT being added in this PR.

  3. .yarnrc.yml: Registers the new plugin with Yarn.

Key observations:

  • No application code is modified
  • No E2E test infrastructure is affected
  • No UI components or user flows are changed
  • The plugin is dormant until a previewBuilds configuration is added to package.json (which isn't happening in this PR)
  • No CI workflows reference these files
  • This is purely a developer tooling enhancement for testing preview builds in the future

Since these changes don't affect any runtime behavior of the application and the plugin won't be active without additional configuration, no E2E tests are needed to validate this PR.

View GitHub Actions results

@sonarqubecloud
Copy link

Copy link
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Seems to work great, I just tested it out as well

@mcmire mcmire added this pull request to the merge queue Jan 30, 2026
Merged via the queue into main with commit 81bc815 Jan 30, 2026
58 checks passed
@mcmire mcmire deleted the add-use-preview-build-yarn-plugin branch January 30, 2026 18:54
@github-actions github-actions bot locked and limited conversation to collaborators Jan 30, 2026
@metamaskbot metamaskbot added the release-7.65.0 Issue or pull request that will be included in release 7.65.0 label Jan 30, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.65.0 Issue or pull request that will be included in release 7.65.0 size-L team-core-platform Core Platform team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants