Skip to content

Conversation

@Mrtenz
Copy link
Member

@Mrtenz Mrtenz commented Apr 15, 2025

This updates the Snaps execution environments build to use Webpack instead of Browserify. The existing Browserify script was updated to build with Webpack. In the future we may be able to use Webpack from the CLI directly, but right now for compatibility with LavaMoat Node we need to use a custom script.

I've added a new script build:lavamoat:test which builds the execution environments for testing locally or in CI. The main difference with this script is that it uses tsconfig paths, which are now disabled for the production build. Doing so results in much better tree shaking, so a smaller bundle.

Breaking changes

  • The node-process and node-thread bundles are now exported as @metamask/snaps-execution-environments/node-process and @metamask/snaps-execution-environments/node-thread respectively.

@socket-security
Copy link

socket-security bot commented Apr 15, 2025

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​lavamoat/​webpack@​0.9.0-beta.0751009989100
Updated@​babel/​generator@​7.23.6 ⏵ 7.27.010010078 +197100
Updated@​babel/​traverse@​7.24.6 ⏵ 7.26.9100 +110078 +197100
Updatedlavamoat@​8.0.7 ⏵ 9.0.881 +110010089100
Addedts-loader@​9.5.29910010081100
Updated@​metamask/​post-message-stream@​9.0.0 ⏵ 10.0.098 +110010090100

View full report

"@swc/core>@swc/core-linux-x64-gnu": true
}
},
"html-webpack-plugin": {
Copy link
Member Author

Choose a reason for hiding this comment

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

All the additions in the policy override here are necessary because of how Webpack loads loaders. A future update to LavaMoat should make this obsolete.

@codecov
Copy link

codecov bot commented Apr 15, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.03%. Comparing base (8120ab0) to head (e499c17).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3322      +/-   ##
==========================================
- Coverage   98.03%   98.03%   -0.01%     
==========================================
  Files         402      402              
  Lines       11109    11107       -2     
  Branches     1754     1754              
==========================================
- Hits        10891    10889       -2     
  Misses        218      218              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Mrtenz Mrtenz force-pushed the mrtenz/snaps-execution-environments-webpack branch from e775b0c to 69b64c4 Compare April 16, 2025 20:29
"@metamask/json-rpc-engine": "^10.0.2",
"@metamask/object-multiplex": "^2.1.0",
"@metamask/post-message-stream": "^9.0.0",
"@metamask/post-message-stream": "^10.0.0",
Copy link
Member Author

Choose a reason for hiding this comment

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

@metamask/post-message-stream only had a CJS version, and since it's using @metamask/utils, it caused Webpack to use the CJS version of @metamask/utils while an ESM version was available. After bumping this to 10.0.0, we can use the ESM version of both @metamask/post-message-stream and @metamask/utils, resulting in a smaller bundle.

@socket-security
Copy link

socket-security bot commented Apr 22, 2025

All alerts resolved. Learn more about Socket for GitHub.

This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored.

Ignoring alerts on:

View full report

@Mrtenz Mrtenz force-pushed the mrtenz/snaps-execution-environments-webpack branch from 5bdeb37 to 974b038 Compare April 22, 2025 09:02
@Mrtenz Mrtenz marked this pull request as ready for review April 22, 2025 09:50
@Mrtenz Mrtenz requested a review from a team as a code owner April 22, 2025 09:50
hmalik88
hmalik88 previously approved these changes Apr 23, 2025
Copy link
Contributor

@hmalik88 hmalik88 left a comment

Choose a reason for hiding this comment

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

LGTM

@Mrtenz Mrtenz force-pushed the mrtenz/snaps-execution-environments-webpack branch 2 times, most recently from 5871aee to 355864e Compare April 24, 2025 11:08
@Mrtenz Mrtenz marked this pull request as draft April 24, 2025 12:00
github-merge-queue bot pushed a commit that referenced this pull request Apr 28, 2025
…3357)" (#3359)

This reverts commit 042d2fa.

To avoid multiple major releases shortly after each other, we should
group this closer with the merge of #3322.
@Mrtenz Mrtenz force-pushed the mrtenz/snaps-execution-environments-webpack branch from 8f08a47 to 6908166 Compare April 28, 2025 14:21
@Mrtenz
Copy link
Member Author

Mrtenz commented Apr 29, 2025

@SocketSecurity ignore npm/[email protected]

Network access ok.

@SocketSecurity ignore npm/[email protected]

This doesn't affect us.

@Mrtenz Mrtenz force-pushed the mrtenz/snaps-execution-environments-webpack branch from bfae935 to 59b4b0f Compare April 29, 2025 10:45
@Mrtenz Mrtenz marked this pull request as ready for review April 29, 2025 11:51
"build:lavamoat:policy": "yarn build:lavamoat --writeAutoPolicy && node scripts/build.js --writeAutoPolicy",
"build:lavamoat": "lavamoat --policy lavamoat/build-system/policy.json --override lavamoat/build-system/policy-override.json ./scripts/build.js",
"build:lavamoat:policy": "yarn build:lavamoat --writeAutoPolicy && LAVAMOAT_GENERATE_POLICY=true node scripts/build.js",
"build:lavamoat:test": "NODE_ENV=test yarn build:lavamoat",
Copy link
Member

Choose a reason for hiding this comment

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

Not entirely sure how to feel about this, seems somewhat problematic that we aren't actually testing with prod builds in CI?

Copy link
Member Author

Choose a reason for hiding this comment

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

The only difference is using tsconfig paths for testing, but not for production.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, yeah I understand. Maybe worth the tradeoff

@Mrtenz Mrtenz force-pushed the mrtenz/snaps-execution-environments-webpack branch from f14dff9 to 57e6670 Compare May 2, 2025 08:39
inlineBundle: true,

scuttleGlobalThis: true,
scuttleGlobalThisExceptions: ['JSON', 'ReactNativeWebView', 'String'],
Copy link
Member

Choose a reason for hiding this comment

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

We need to verify that this works in mobile

Copy link
Member

Choose a reason for hiding this comment

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

It does 🎉

Comment on lines +253 to +256
'Object',
'postMessage',
'Reflect',
'Set',
Copy link
Member

Choose a reason for hiding this comment

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

Set, Object and Reflect are new exceptions, do we know why?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, these are introduced by LavaMoat boilerplate IIRC. These are safe to add, and we may be able to remove them with a future LavaMoat update.

@Mrtenz Mrtenz added this pull request to the merge queue May 2, 2025
Merged via the queue into main with commit 1d36a99 May 2, 2025
119 checks passed
@Mrtenz Mrtenz deleted the mrtenz/snaps-execution-environments-webpack branch May 2, 2025 11:04
github-merge-queue bot pushed a commit that referenced this pull request May 2, 2025
This is a redo of #3357, which was reverted in #3359 to avoid two
breaking changes in a row. Now that #3322 is merged, we can do this
again.

The original PR description can be found below.

---

This removes the web worker execution service and execution environment,
as they were unused. We can revert this PR in the future to add them
again, if needed.

## Breaking changes

### `@metamask/snaps-controllers`

- Remove web worker execution service.

### `@metamask/snaps-execution-environments`

- Remove web worker pool execution environment.
- Remove web worker executor execution environment.
github-merge-queue bot pushed a commit that referenced this pull request May 2, 2025
Browserify is not actively maintained and we should stop recommending
it. With the removal of Browserify from #3322, we can now completely
remove Browserify from the repo.

`@metamask/snaps-browserify-plugin` should be deprecated on NPM after
merging this.
github-merge-queue bot pushed a commit that referenced this pull request May 7, 2025
After #3322, generating LavaMoat policies requires the build files to be
present. Since the examples step requires build files as well, I've
moved the build to a new job which is now a requirement for the other
steps.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants