Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/snaps-execution-environments/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@
"vite-tsconfig-paths": "^4.0.5",
"vitest": "^3.1.1",
"webpack": "^5.97.1",
"webpack-merge": "^5.9.0"
"webpack-merge": "^5.9.0",
"webpack-sources": "^3.3.3"
},
"engines": {
"node": "^20 || >=22"
Expand Down
2 changes: 2 additions & 0 deletions packages/snaps-execution-environments/src/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
<meta charset="utf-8" />

<title>MetaMask Snaps Execution Environment</title>
<% if (typeof lockdownScript !== 'undefined') { %>
<script><%= lockdownScript %></script>
<% } %>
</head>
<body>
<% if (typeof inlineSource !== 'undefined') { %>
Expand Down
45 changes: 40 additions & 5 deletions packages/snaps-execution-environments/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const { resolve } = require('path');
const { TsconfigPathsPlugin } = require('tsconfig-paths-webpack-plugin');
const { ProvidePlugin, Compilation } = require('webpack');
const { merge } = require('webpack-merge');
const { RawSource } = require('webpack-sources');

/**
* Whether to generate a policy file for the build.
Expand Down Expand Up @@ -64,11 +65,6 @@ const DEFAULT_WEB_CONFIG = {
plugins: [
new HtmlWebpackPlugin({
template: './src/index.ejs',
templateParameters: () => {
return {
lockdownScript: SES_BUNDLE,
};
},
}),
],
};
Expand Down Expand Up @@ -272,6 +268,45 @@ const configs = ENTRY_POINTS.map(
});
},
},

{
/**
* A custom plugin to add SES to the build.
*
* @param {import('webpack').Compiler} compiler - The Webpack compiler.
*/
apply(compiler) {
const PLUGIN_NAME = 'AddSESPlugin';
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
compilation.hooks.processAssets.tap(
{
name: PLUGIN_NAME,
stage: compilation.PROCESS_ASSETS_STAGE_REPORT,
},
() => {
compilation.emitAsset('ses.js', new RawSource(SES_BUNDLE), {
minimized: true,
});
},
);

HtmlWebpackPlugin.getHooks(
compilation,
).alterAssetTagGroups.tapAsync(PLUGIN_NAME, (data, callback) => {
// Add the SES script tag to the HTML files.
data.headTags.unshift({
tagName: 'script',
voidTag: false,
attributes: {
src: 'ses.js',
},
});

callback(null, data);
});
});
},
},
],
}),
);
Expand Down
9 changes: 5 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4376,6 +4376,7 @@ __metadata:
vitest: "npm:^3.1.1"
webpack: "npm:^5.97.1"
webpack-merge: "npm:^5.9.0"
webpack-sources: "npm:^3.3.3"
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -18875,10 +18876,10 @@ __metadata:
languageName: node
linkType: hard

"webpack-sources@npm:^3.2.3":
version: 3.2.3
resolution: "webpack-sources@npm:3.2.3"
checksum: 10/a661f41795d678b7526ae8a88cd1b3d8ce71a7d19b6503da8149b2e667fc7a12f9b899041c1665d39e38245ed3a59ab68de648ea31040c3829aa695a5a45211d
"webpack-sources@npm:^3.2.3, webpack-sources@npm:^3.3.3":
version: 3.3.3
resolution: "webpack-sources@npm:3.3.3"
checksum: 10/ec5d72607e8068467370abccbfff855c596c098baedbe9d198a557ccf198e8546a322836a6f74241492576adba06100286592993a62b63196832cdb53c8bae91
languageName: node
linkType: hard

Expand Down
Loading