Skip to content

Commit 1d36a99

Browse files
authored
chore!: Build Snaps execution environments with Webpack (#3322)
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.
1 parent f89b99f commit 1d36a99

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1999
-3389
lines changed

.github/workflows/build-lint-test.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
node-version: ${{ matrix.node-version }}
2727
cache-node-modules: ${{ matrix.node-version == '20.x' }}
2828
- name: Prepare "@metamask/snaps-execution-environments" build
29-
run: yarn workspace @metamask/snaps-execution-environments run build:lavamoat
29+
run: yarn workspace @metamask/snaps-execution-environments run build:lavamoat:test
3030
- name: Save "@metamask/snaps-execution-environments" build
3131
id: cache-snaps-execution-environments-build
3232
uses: actions/upload-artifact@v4
@@ -35,7 +35,7 @@ jobs:
3535
retention-days: 1
3636
path: |
3737
.nvmrc
38-
packages/snaps-execution-environments/dist/browserify
38+
packages/snaps-execution-environments/dist/webpack
3939
- name: Fetch workspace package names
4040
id: workspace-package-names
4141
run: |
@@ -95,12 +95,16 @@ jobs:
9595
policy:
9696
name: Generate LavaMoat policy
9797
runs-on: ubuntu-latest
98-
needs: prepare
98+
needs: build
9999
steps:
100100
- name: Checkout and setup environment
101101
uses: MetaMask/action-checkout-and-setup@v1
102102
with:
103103
is-high-risk-environment: false
104+
- name: Restore build files
105+
uses: actions/download-artifact@v4
106+
with:
107+
name: build-source-${{ runner.os }}-${{ github.sha }}
104108
- name: Generate LavaMoat policy
105109
run: yarn workspace @metamask/snaps-execution-environments build:lavamoat:policy
106110
- name: Require clean working directory

.github/workflows/publish-environment.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@ jobs:
3232
aws-region: ${{ vars.AWS_REGION }}
3333
- name: Deploy to `${{ inputs.destination_dir }}` directory of remote storage
3434
run: |
35-
aws s3 cp ./packages/snaps-execution-environments/dist/browserify/iframe s3://${{ vars.AWS_BUCKET_NAME }}/iframe/${{ inputs.destination_dir }} --recursive --acl private
36-
aws s3 cp ./packages/snaps-execution-environments/dist/browserify/webview s3://${{ vars.AWS_BUCKET_NAME }}/webview/${{ inputs.destination_dir }} --recursive --acl private
35+
aws s3 cp ./packages/snaps-execution-environments/dist/webpack/iframe s3://${{ vars.AWS_BUCKET_NAME }}/iframe/${{ inputs.destination_dir }} --recursive --acl private
36+
aws s3 cp ./packages/snaps-execution-environments/dist/webpack/webview s3://${{ vars.AWS_BUCKET_NAME }}/webview/${{ inputs.destination_dir }} --recursive --acl private

.yarn/patches/@lavamoat-lavapack-npm-6.1.1-b81af21193.patch

Lines changed: 0 additions & 22 deletions
This file was deleted.

.yarn/patches/lavamoat-browserify-npm-17.0.5-16c00e9ef9.patch

Lines changed: 0 additions & 39 deletions
This file was deleted.

jest.config.base.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,19 @@ module.exports = {
9696

9797
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
9898
moduleNameMapper: {
99+
'^@metamask/snaps-execution-environments/node-thread': [
100+
'<rootDir>/../snaps-execution-environments/dist/webpack/node-thread/bundle.js',
101+
],
102+
'^@metamask/snaps-execution-environments/node-process': [
103+
'<rootDir>/../snaps-execution-environments/dist/webpack/node-process/bundle.js',
104+
],
99105
'^@metamask/(.+)/production/jsx-runtime': [
100106
'<rootDir>/../$1/src/jsx/production',
101107
],
102108
'^@metamask/(.+)/test-utils$': ['<rootDir>/../$1/src/test-utils'],
109+
'^@metamask/post-message-stream/node$': [
110+
'@metamask/post-message-stream/node',
111+
],
103112
'^@metamask/(.+)/node$': ['<rootDir>/../$1/src/node'],
104113
'^@metamask/(.+)/jsx': ['<rootDir>/../$1/src/jsx'],
105114
'^@metamask/(.+)$': [

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
"resolutions": {
6161
"@babel/core": "patch:@babel/core@npm%3A7.23.2#./.yarn/patches/@babel-core-npm-7.23.2-b93f586907.patch",
6262
"@esbuild-plugins/node-modules-polyfill@^0.2.2": "patch:@esbuild-plugins/node-modules-polyfill@npm%3A0.2.2#./.yarn/patches/@esbuild-plugins-node-modules-polyfill-npm-0.2.2-f612681798.patch",
63-
"@lavamoat/lavapack@^6.1.1": "patch:@lavamoat/lavapack@npm%3A6.1.1#./.yarn/patches/@lavamoat-lavapack-npm-6.1.1-b81af21193.patch",
6463
"@puppeteer/[email protected]": "patch:@puppeteer/browsers@npm%3A1.7.0#./.yarn/patches/@puppeteer-browsers-npm-1.7.0-203cb4f44b.patch",
6564
"@puppeteer/browsers@^1.6.0": "patch:@puppeteer/browsers@npm%3A1.7.0#./.yarn/patches/@puppeteer-browsers-npm-1.7.0-203cb4f44b.patch",
6665
"@types/glob@*": "patch:@types/glob@npm%3A7.1.4#./.yarn/patches/@types-glob-npm-7.1.4-d45247eaa2.patch",
@@ -72,7 +71,6 @@
7271
"jest-fetch-mock@^3.0.3": "patch:jest-fetch-mock@npm:3.0.3#.yarn/patches/jest-fetch-mock-npm-3.0.3-ac072ca8af.patch",
7372
"jest-util@^29.5.0": "patch:jest-util@npm%3A29.6.3#./.yarn/patches/jest-util-npm-29.6.3-6ffdea2c1c.patch",
7473
"jest-util@^29.6.3": "patch:jest-util@npm%3A29.6.3#./.yarn/patches/jest-util-npm-29.6.3-6ffdea2c1c.patch",
75-
"lavamoat-browserify@^17.0.5": "patch:lavamoat-browserify@npm%3A17.0.5#./.yarn/patches/lavamoat-browserify-npm-17.0.5-16c00e9ef9.patch",
7674
"luxon@^3.2.1": "patch:luxon@npm%3A3.3.0#./.yarn/patches/luxon-npm-3.3.0-bdbae9bfd5.patch",
7775
"tsconfig-paths@^3.11.0": "patch:tsconfig-paths@npm%3A3.14.2#./.yarn/patches/tsconfig-paths-npm-3.14.2-90ce75420d.patch",
7876
"tsconfig-paths@^3.14.1": "patch:tsconfig-paths@npm%3A3.14.2#./.yarn/patches/tsconfig-paths-npm-3.14.2-90ce75420d.patch",

packages/examples/packages/bip32/snap.manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"url": "https://github.com/MetaMask/snaps.git"
88
},
99
"source": {
10-
"shasum": "k2lRqMHzUAsSfYAQvfHaotZ+GjevHXfCYq31N6rLbpI=",
10+
"shasum": "S8JJzZaDPhHp16nyJVCPY++KVgOpYSCUrEVp/dmbsRE=",
1111
"location": {
1212
"npm": {
1313
"filePath": "dist/bundle.js",

packages/examples/packages/bip44/snap.manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"url": "https://github.com/MetaMask/snaps.git"
88
},
99
"source": {
10-
"shasum": "OKsspaf6yslVwkh3t0EEkgLe2ZXVUeOSuARHBYh5QO8=",
10+
"shasum": "S9Rxcf90yagtJcBEV2lPs4eSASBPP+KkiACJjkye7ho=",
1111
"location": {
1212
"npm": {
1313
"filePath": "dist/bundle.js",

packages/examples/packages/get-entropy/snap.manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"url": "https://github.com/MetaMask/snaps.git"
88
},
99
"source": {
10-
"shasum": "JuqQZZ60QV9h7WNpCeNCNoomvPVzkoAGMqF+wXMi7vM=",
10+
"shasum": "zip0FTlGFS2oV/Hm6lLWzBAhw/UtphSCFG4kecgojAg=",
1111
"location": {
1212
"npm": {
1313
"filePath": "dist/bundle.js",

packages/examples/packages/invoke-snap/packages/core-signer/snap.manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"url": "https://github.com/MetaMask/snaps.git"
88
},
99
"source": {
10-
"shasum": "5WnCGlClRMxrjPXzuSZybJuEBDfo+oIjkfCRhcvFzzw=",
10+
"shasum": "KaI5if/V5l02632+bVHOa6UtSbmWO+NR/kr8q8Ck1zs=",
1111
"location": {
1212
"npm": {
1313
"filePath": "dist/bundle.js",

0 commit comments

Comments
 (0)