Skip to content

Commit 81c33fd

Browse files
authored
feat: Add snaps-sandbox package and integrate into CLI (#3306)
This adds a new package, `@metamask/snaps-sandbox`, which is a tool to interact with Snaps through a web app. It's a replacement for the Snaps Simulator, but doesn't simulate any functionality. Instead, it calls MetaMask through the usual JSON-RPC methods. The sandbox can be used from the Snaps CLI by running `mm-snap sandbox`.
1 parent 0c476de commit 81c33fd

File tree

119 files changed

+6148
-640
lines changed

Some content is hidden

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

119 files changed

+6148
-640
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
diff --git a/esm/vs/base/common/marked/marked.js b/esm/vs/base/common/marked/marked.js
2+
index 56333ffeb738907f144d15c6ebe44494d1b13330..d743087aa2640d6e3c629907a16cf67f3bb1a498 100644
3+
--- a/esm/vs/base/common/marked/marked.js
4+
+++ b/esm/vs/base/common/marked/marked.js
5+
@@ -2534,5 +2534,3 @@ export var setOptions = (__marked_exports.setOptions || exports.setOptions);
6+
export var use = (__marked_exports.use || exports.use);
7+
export var walkTokens = (__marked_exports.walkTokens || exports.walkTokens);
8+
// ESM-uncomment-end
9+
-
10+
-//# sourceMappingURL=marked.umd.js.map

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ This repository contains the following packages [^fn1]:
1717
- [`@metamask/snaps-jest`](packages/snaps-jest)
1818
- [`@metamask/snaps-rollup-plugin`](packages/snaps-rollup-plugin)
1919
- [`@metamask/snaps-rpc-methods`](packages/snaps-rpc-methods)
20+
- [`@metamask/snaps-sandbox`](packages/snaps-sandbox)
2021
- [`@metamask/snaps-sdk`](packages/snaps-sdk)
2122
- [`@metamask/snaps-simulation`](packages/snaps-simulation)
2223
- [`@metamask/snaps-utils`](packages/snaps-utils)
@@ -40,12 +41,14 @@ linkStyle default opacity:0.5
4041
snaps_jest(["@metamask/snaps-jest"]);
4142
snaps_rollup_plugin(["@metamask/snaps-rollup-plugin"]);
4243
snaps_rpc_methods(["@metamask/snaps-rpc-methods"]);
44+
snaps_sandbox(["@metamask/snaps-sandbox"]);
4345
snaps_sdk(["@metamask/snaps-sdk"]);
4446
snaps_simulation(["@metamask/snaps-simulation"]);
4547
snaps_utils(["@metamask/snaps-utils"]);
4648
snaps_webpack_plugin(["@metamask/snaps-webpack-plugin"]);
4749
create_snap --> snaps_utils;
4850
snaps_browserify_plugin --> snaps_utils;
51+
snaps_cli --> snaps_sandbox;
4952
snaps_cli --> snaps_sdk;
5053
snaps_cli --> snaps_utils;
5154
snaps_cli --> snaps_webpack_plugin;

eslint.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ const config = createConfig([
325325
'packages/snaps-controllers/src/services/iframe/**/*',
326326
'packages/snaps-controllers/src/services/webworker/**/*',
327327
'packages/snaps-execution-environments/src/**/*',
328+
'packages/snaps-sandbox/src/**/*',
328329
'packages/test-snaps/src/**/*',
329330
'**/*.test.browser.ts',
330331
],

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
"scripts": {
1616
"build": "ts-bridge --project tsconfig.build.json --verbose",
1717
"build:ci": "ts-bridge --project tsconfig.build.json --verbose",
18+
"build:ci:post": "yarn build:sandbox",
1819
"build:examples": "yarn workspace @metamask/example-snaps build",
1920
"build:execution-environments": "yarn workspace @metamask/snaps-execution-environments build:lavamoat",
20-
"build:post": "yarn build:examples && yarn build:execution-environments",
21+
"build:post": "yarn build:examples && yarn build:execution-environments && yarn build:sandbox",
22+
"build:sandbox": "yarn workspace @metamask/snaps-sandbox build",
2123
"changelog:update": "yarn workspaces foreach --all --parallel --interlaced --verbose run changelog:update",
2224
"changelog:validate": "yarn workspaces foreach --all --parallel --interlaced --verbose run changelog:validate",
2325
"child-workspace-package-names-as-json": "ts-node scripts/child-workspace-package-names-as-json.ts",

packages/snaps-cli/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Add `sandbox` command to run sandbox tool ([#3306](https://github.com/MetaMask/snaps/pull/3306))
13+
- This command allows you to run the Snaps sandbox tool, which is useful for
14+
quickly testing and debugging Snaps.
15+
1016
## [7.0.0]
1117

1218
### Changed

packages/snaps-cli/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Commands:
2121
mm-snap build Build snap from source [aliases: b]
2222
mm-snap eval Attempt to evaluate snap bundle in SES [aliases: e]
2323
mm-snap manifest Validate the snap.manifest.json file [aliases: m]
24+
mm-snap sandbox Start a sandbox server to interact with the Snap
2425
mm-snap serve Locally serve Snap file(s) for testing [aliases: s]
2526
mm-snap watch Build Snap on change [aliases: w]
2627

packages/snaps-cli/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"test:watch": "jest --watch"
6565
},
6666
"dependencies": {
67+
"@metamask/snaps-sandbox": "workspace:^",
6768
"@metamask/snaps-sdk": "workspace:^",
6869
"@metamask/snaps-utils": "workspace:^",
6970
"@metamask/snaps-webpack-plugin": "workspace:^",
@@ -79,6 +80,7 @@
7980
"crypto-browserify": "^3.12.0",
8081
"domain-browser": "^4.22.0",
8182
"events": "^3.3.0",
83+
"express": "^5.1.0",
8284
"fork-ts-checker-webpack-plugin": "^9.0.2",
8385
"https-browserify": "^1.0.0",
8486
"ora": "^5.4.1",
@@ -89,7 +91,6 @@
8991
"querystring-es3": "^0.2.1",
9092
"readable-stream": "^3.6.2",
9193
"semver": "^7.5.4",
92-
"serve-handler": "^6.1.5",
9394
"stream-browserify": "^3.0.0",
9495
"stream-http": "^3.2.0",
9596
"string_decoder": "^1.3.0",
@@ -111,9 +112,9 @@
111112
"@metamask/auto-changelog": "^5.0.1",
112113
"@swc/jest": "^0.2.26",
113114
"@ts-bridge/cli": "^0.6.1",
115+
"@types/express": "^5.0.1",
114116
"@types/jest": "^27.5.1",
115117
"@types/node": "18.14.2",
116-
"@types/serve-handler": "^6.1.0",
117118
"@types/yargs": "^17.0.24",
118119
"cross-fetch": "^3.1.5",
119120
"deepmerge": "^4.2.2",

packages/snaps-cli/src/builders.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ const builders = {
66
type: 'boolean',
77
},
88

9+
build: {
10+
describe: 'Build the Snap bundle',
11+
type: 'boolean',
12+
default: true,
13+
},
14+
915
config: {
1016
alias: 'c',
1117
describe: 'Path to config file',

packages/snaps-cli/src/commands/build/build.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@ import type { Steps } from '../../utils';
1010
import { success, executeSteps, info } from '../../utils';
1111
import { evaluate } from '../eval';
1212

13-
type BuildContext = {
13+
export type BuildContext = {
1414
analyze: boolean;
15+
build: boolean;
1516
config: ProcessedConfig;
1617
port?: number;
1718
};
1819

19-
const steps: Steps<BuildContext> = [
20+
export const steps: Steps<BuildContext> = [
2021
{
2122
name: 'Checking the input file.',
23+
condition: ({ build }) => build,
2224
task: async ({ config }) => {
2325
const { input } = config;
2426

@@ -31,7 +33,8 @@ const steps: Steps<BuildContext> = [
3133
},
3234
{
3335
name: 'Building the snap bundle.',
34-
task: async ({ analyze, config, spinner }) => {
36+
condition: ({ build }) => build,
37+
task: async ({ analyze, build: enableBuild, config, spinner }) => {
3538
// We don't evaluate the bundle here, because it's done in a separate
3639
// step.
3740
const compiler = await build(config, {
@@ -43,6 +46,7 @@ const steps: Steps<BuildContext> = [
4346
if (analyze) {
4447
return {
4548
analyze,
49+
build: enableBuild,
4650
config,
4751
spinner,
4852
port: await getBundleAnalyzerPort(compiler),
@@ -54,7 +58,7 @@ const steps: Steps<BuildContext> = [
5458
},
5559
{
5660
name: 'Evaluating the snap bundle.',
57-
condition: ({ config }) => config.evaluate,
61+
condition: ({ build, config }) => build && config.evaluate,
5862
task: async ({ config, spinner }) => {
5963
const path = pathResolve(
6064
process.cwd(),
@@ -94,6 +98,7 @@ export async function buildHandler(
9498
analyze = false,
9599
): Promise<void> {
96100
return await executeSteps(steps, {
101+
build: true,
97102
config,
98103
analyze,
99104
});

packages/snaps-cli/src/commands/build/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ const command = {
1616
};
1717

1818
export * from './implementation';
19+
export { steps } from './build';
1920
export default command;

0 commit comments

Comments
 (0)