@metamask/snaps-cli 0.37.0-flask.1 → 0.38.0-flask.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (256) hide show
  1. package/.browserslistrc +3 -0
  2. package/CHANGELOG.md +20 -426
  3. package/README.md +539 -63
  4. package/dist/cjs/builders.js +40 -41
  5. package/dist/cjs/builders.js.map +1 -1
  6. package/dist/cjs/cli.js +14 -14
  7. package/dist/cjs/cli.js.map +1 -1
  8. package/dist/cjs/commands/build/build.js +54 -0
  9. package/dist/cjs/commands/build/build.js.map +1 -0
  10. package/dist/cjs/commands/build/implementation.js +31 -0
  11. package/dist/cjs/commands/build/implementation.js.map +1 -0
  12. package/dist/cjs/{cmds → commands}/build/index.js +18 -5
  13. package/dist/cjs/commands/build/index.js.map +1 -0
  14. package/dist/cjs/commands/eval/eval.js +57 -0
  15. package/dist/cjs/commands/eval/eval.js.map +1 -0
  16. package/dist/cjs/commands/eval/implementation.js +27 -0
  17. package/dist/cjs/commands/eval/implementation.js.map +1 -0
  18. package/dist/cjs/commands/eval/index.js +50 -0
  19. package/dist/cjs/commands/eval/index.js.map +1 -0
  20. package/dist/cjs/commands/index.js.map +1 -0
  21. package/dist/cjs/commands/manifest/implementation.js +34 -0
  22. package/dist/cjs/commands/manifest/implementation.js.map +1 -0
  23. package/dist/cjs/commands/manifest/index.js +50 -0
  24. package/dist/cjs/commands/manifest/index.js.map +1 -0
  25. package/dist/cjs/commands/manifest/manifest.js +55 -0
  26. package/dist/cjs/commands/manifest/manifest.js.map +1 -0
  27. package/dist/cjs/{cmds → commands}/serve/index.js +4 -2
  28. package/dist/cjs/commands/serve/index.js.map +1 -0
  29. package/dist/cjs/commands/serve/serve.js +21 -0
  30. package/dist/cjs/commands/serve/serve.js.map +1 -0
  31. package/dist/cjs/commands/watch/implementation.js +35 -0
  32. package/dist/cjs/commands/watch/implementation.js.map +1 -0
  33. package/dist/cjs/{cmds → commands}/watch/index.js +19 -4
  34. package/dist/cjs/commands/watch/index.js.map +1 -0
  35. package/dist/cjs/commands/watch/watch.js +51 -0
  36. package/dist/cjs/commands/watch/watch.js.map +1 -0
  37. package/dist/cjs/config.js +290 -0
  38. package/dist/cjs/config.js.map +1 -0
  39. package/dist/cjs/errors.js +37 -0
  40. package/dist/cjs/errors.js.map +1 -0
  41. package/dist/cjs/index.js +28 -3
  42. package/dist/cjs/index.js.map +1 -1
  43. package/dist/cjs/main.js +6 -7
  44. package/dist/cjs/main.js.map +1 -1
  45. package/dist/cjs/utils/cli.js +61 -0
  46. package/dist/cjs/utils/cli.js.map +1 -0
  47. package/dist/cjs/utils/errors.js +42 -0
  48. package/dist/cjs/utils/errors.js.map +1 -0
  49. package/dist/cjs/utils/index.js +6 -2
  50. package/dist/cjs/utils/index.js.map +1 -1
  51. package/dist/cjs/utils/legacy.js +48 -0
  52. package/dist/cjs/utils/legacy.js.map +1 -0
  53. package/dist/cjs/utils/logging.js +46 -0
  54. package/dist/cjs/utils/logging.js.map +1 -0
  55. package/dist/cjs/utils/path.js +16 -0
  56. package/dist/cjs/utils/path.js.map +1 -0
  57. package/dist/cjs/utils/steps.js +52 -0
  58. package/dist/cjs/utils/steps.js.map +1 -0
  59. package/dist/cjs/webpack/compiler.js +96 -0
  60. package/dist/cjs/webpack/compiler.js.map +1 -0
  61. package/dist/cjs/webpack/config.js +234 -0
  62. package/dist/cjs/webpack/config.js.map +1 -0
  63. package/dist/cjs/webpack/index.js +22 -0
  64. package/dist/cjs/webpack/index.js.map +1 -0
  65. package/dist/cjs/webpack/loaders/browserify.js +97 -0
  66. package/dist/cjs/webpack/loaders/browserify.js.map +1 -0
  67. package/dist/cjs/webpack/loaders/wasm.js +36 -0
  68. package/dist/cjs/webpack/loaders/wasm.js.map +1 -0
  69. package/dist/cjs/webpack/plugins.js +340 -0
  70. package/dist/cjs/webpack/plugins.js.map +1 -0
  71. package/dist/cjs/webpack/utils.js +133 -0
  72. package/dist/cjs/webpack/utils.js.map +1 -0
  73. package/dist/esm/builders.js +40 -41
  74. package/dist/esm/builders.js.map +1 -1
  75. package/dist/esm/cli.js +15 -15
  76. package/dist/esm/cli.js.map +1 -1
  77. package/dist/esm/commands/build/build.js +51 -0
  78. package/dist/esm/commands/build/build.js.map +1 -0
  79. package/dist/esm/commands/build/implementation.js +27 -0
  80. package/dist/esm/commands/build/implementation.js.map +1 -0
  81. package/dist/esm/{cmds → commands}/build/index.js +5 -5
  82. package/dist/esm/commands/build/index.js.map +1 -0
  83. package/dist/esm/commands/eval/eval.js +54 -0
  84. package/dist/esm/commands/eval/eval.js.map +1 -0
  85. package/dist/esm/commands/eval/implementation.js +24 -0
  86. package/dist/esm/commands/eval/implementation.js.map +1 -0
  87. package/dist/esm/commands/eval/index.js +22 -0
  88. package/dist/esm/commands/eval/index.js.map +1 -0
  89. package/dist/esm/commands/index.js +15 -0
  90. package/dist/esm/commands/index.js.map +1 -0
  91. package/dist/esm/commands/manifest/implementation.js +33 -0
  92. package/dist/esm/commands/manifest/implementation.js.map +1 -0
  93. package/dist/esm/commands/manifest/index.js +22 -0
  94. package/dist/esm/commands/manifest/index.js.map +1 -0
  95. package/dist/esm/commands/manifest/manifest.js +52 -0
  96. package/dist/esm/commands/manifest/manifest.js.map +1 -0
  97. package/dist/esm/{cmds → commands}/serve/index.js +4 -2
  98. package/dist/esm/commands/serve/index.js.map +1 -0
  99. package/dist/esm/commands/serve/serve.js +17 -0
  100. package/dist/esm/commands/serve/serve.js.map +1 -0
  101. package/dist/esm/commands/watch/implementation.js +34 -0
  102. package/dist/esm/commands/watch/implementation.js.map +1 -0
  103. package/dist/esm/{cmds → commands}/watch/index.js +6 -4
  104. package/dist/esm/commands/watch/index.js.map +1 -0
  105. package/dist/esm/commands/watch/watch.js +50 -0
  106. package/dist/esm/commands/watch/watch.js.map +1 -0
  107. package/dist/esm/config.js +294 -0
  108. package/dist/esm/config.js.map +1 -0
  109. package/dist/esm/errors.js +30 -0
  110. package/dist/esm/errors.js.map +1 -0
  111. package/dist/esm/index.js +3 -0
  112. package/dist/esm/index.js.map +1 -1
  113. package/dist/esm/main.js +6 -7
  114. package/dist/esm/main.js.map +1 -1
  115. package/dist/esm/utils/cli.js +43 -0
  116. package/dist/esm/utils/cli.js.map +1 -0
  117. package/dist/esm/utils/errors.js +43 -0
  118. package/dist/esm/utils/errors.js.map +1 -0
  119. package/dist/esm/utils/index.js +6 -2
  120. package/dist/esm/utils/index.js.map +1 -1
  121. package/dist/esm/utils/legacy.js +47 -0
  122. package/dist/esm/utils/legacy.js.map +1 -0
  123. package/dist/esm/utils/logging.js +40 -0
  124. package/dist/esm/utils/logging.js.map +1 -0
  125. package/dist/esm/utils/path.js +13 -0
  126. package/dist/esm/utils/path.js.map +1 -0
  127. package/dist/esm/utils/steps.js +43 -0
  128. package/dist/esm/utils/steps.js.map +1 -0
  129. package/dist/esm/webpack/compiler.js +89 -0
  130. package/dist/esm/webpack/compiler.js.map +1 -0
  131. package/dist/esm/webpack/config.js +236 -0
  132. package/dist/esm/webpack/config.js.map +1 -0
  133. package/dist/esm/webpack/index.js +5 -0
  134. package/dist/esm/webpack/index.js.map +1 -0
  135. package/dist/esm/webpack/loaders/browserify.js +82 -0
  136. package/dist/esm/webpack/loaders/browserify.js.map +1 -0
  137. package/dist/esm/webpack/loaders/wasm.js +26 -0
  138. package/dist/esm/webpack/loaders/wasm.js.map +1 -0
  139. package/dist/esm/webpack/plugins.js +343 -0
  140. package/dist/esm/webpack/plugins.js.map +1 -0
  141. package/dist/esm/webpack/utils.js +160 -0
  142. package/dist/esm/webpack/utils.js.map +1 -0
  143. package/dist/types/__fixtures__/configs/cjs.d.ts +1 -0
  144. package/dist/types/__fixtures__/configs/esm.d.ts +3 -0
  145. package/dist/types/__fixtures__/configs/invalid.d.ts +3 -0
  146. package/dist/types/__fixtures__/configs/javascript/snap.config.d.ts +0 -0
  147. package/dist/types/__fixtures__/configs/typescript/snap.config.d.ts +3 -0
  148. package/dist/types/builders.d.ts +2 -21
  149. package/dist/types/cli.d.ts +1 -1
  150. package/dist/types/commands/build/build.d.ts +10 -0
  151. package/dist/types/commands/build/implementation.d.ts +10 -0
  152. package/dist/types/{cmds/eval → commands/build}/index.d.ts +1 -0
  153. package/dist/types/commands/eval/__test__/browserify/bad/snap.config.d.ts +3 -0
  154. package/dist/types/commands/eval/__test__/browserify/good/snap.config.d.ts +3 -0
  155. package/dist/types/commands/eval/__test__/webpack/bad/snap.config.d.ts +3 -0
  156. package/dist/types/commands/eval/__test__/webpack/good/snap.config.d.ts +3 -0
  157. package/dist/types/commands/eval/__test__/webpack/snap.config.d.ts +3 -0
  158. package/dist/types/commands/eval/eval.d.ts +14 -0
  159. package/dist/types/commands/eval/implementation.d.ts +9 -0
  160. package/dist/types/{cmds/serve → commands/eval}/index.d.ts +1 -0
  161. package/dist/types/commands/manifest/implementation.d.ts +12 -0
  162. package/dist/types/{cmds → commands}/manifest/index.d.ts +1 -0
  163. package/dist/types/commands/manifest/manifest.d.ts +14 -0
  164. package/dist/types/commands/serve/serve.d.ts +16 -0
  165. package/dist/types/commands/watch/implementation.d.ts +14 -0
  166. package/dist/types/commands/watch/index.d.ts +10 -0
  167. package/dist/types/commands/watch/watch.d.ts +19 -0
  168. package/dist/types/config.d.ts +626 -0
  169. package/dist/types/errors.d.ts +25 -0
  170. package/dist/types/index.d.ts +4 -0
  171. package/dist/types/utils/cli.d.ts +17 -0
  172. package/dist/types/utils/errors.d.ts +23 -0
  173. package/dist/types/utils/index.d.ts +6 -2
  174. package/dist/types/utils/legacy.d.ts +27 -0
  175. package/dist/types/utils/logging.d.ts +22 -0
  176. package/dist/types/utils/path.d.ts +9 -0
  177. package/dist/types/utils/steps.d.ts +17 -0
  178. package/dist/types/webpack/compiler.d.ts +29 -0
  179. package/dist/types/webpack/config.d.ts +37 -0
  180. package/dist/types/webpack/index.d.ts +3 -0
  181. package/dist/types/webpack/loaders/browserify.d.ts +16 -0
  182. package/dist/types/webpack/loaders/wasm.d.ts +20 -0
  183. package/dist/types/webpack/plugins.d.ts +147 -0
  184. package/dist/types/webpack/utils.d.ts +156 -0
  185. package/package.json +15 -7
  186. package/dist/cjs/cmds/build/buildHandler.js +0 -36
  187. package/dist/cjs/cmds/build/buildHandler.js.map +0 -1
  188. package/dist/cjs/cmds/build/bundle.js +0 -83
  189. package/dist/cjs/cmds/build/bundle.js.map +0 -1
  190. package/dist/cjs/cmds/build/index.js.map +0 -1
  191. package/dist/cjs/cmds/build/utils.js +0 -79
  192. package/dist/cjs/cmds/build/utils.js.map +0 -1
  193. package/dist/cjs/cmds/eval/evalHandler.js +0 -24
  194. package/dist/cjs/cmds/eval/evalHandler.js.map +0 -1
  195. package/dist/cjs/cmds/eval/index.js +0 -31
  196. package/dist/cjs/cmds/eval/index.js.map +0 -1
  197. package/dist/cjs/cmds/index.js.map +0 -1
  198. package/dist/cjs/cmds/manifest/index.js +0 -44
  199. package/dist/cjs/cmds/manifest/index.js.map +0 -1
  200. package/dist/cjs/cmds/manifest/manifestHandler.js +0 -47
  201. package/dist/cjs/cmds/manifest/manifestHandler.js.map +0 -1
  202. package/dist/cjs/cmds/serve/index.js.map +0 -1
  203. package/dist/cjs/cmds/serve/serveHandler.js +0 -62
  204. package/dist/cjs/cmds/serve/serveHandler.js.map +0 -1
  205. package/dist/cjs/cmds/serve/serveUtils.js +0 -37
  206. package/dist/cjs/cmds/serve/serveUtils.js.map +0 -1
  207. package/dist/cjs/cmds/watch/index.js.map +0 -1
  208. package/dist/cjs/cmds/watch/watchHandler.js +0 -91
  209. package/dist/cjs/cmds/watch/watchHandler.js.map +0 -1
  210. package/dist/cjs/utils/misc.js +0 -142
  211. package/dist/cjs/utils/misc.js.map +0 -1
  212. package/dist/cjs/utils/snap-config.js +0 -104
  213. package/dist/cjs/utils/snap-config.js.map +0 -1
  214. package/dist/esm/cmds/build/buildHandler.js +0 -36
  215. package/dist/esm/cmds/build/buildHandler.js.map +0 -1
  216. package/dist/esm/cmds/build/bundle.js +0 -81
  217. package/dist/esm/cmds/build/bundle.js.map +0 -1
  218. package/dist/esm/cmds/build/index.js.map +0 -1
  219. package/dist/esm/cmds/build/utils.js +0 -88
  220. package/dist/esm/cmds/build/utils.js.map +0 -1
  221. package/dist/esm/cmds/eval/evalHandler.js +0 -20
  222. package/dist/esm/cmds/eval/evalHandler.js.map +0 -1
  223. package/dist/esm/cmds/eval/index.js +0 -16
  224. package/dist/esm/cmds/eval/index.js.map +0 -1
  225. package/dist/esm/cmds/index.js +0 -15
  226. package/dist/esm/cmds/index.js.map +0 -1
  227. package/dist/esm/cmds/manifest/index.js +0 -29
  228. package/dist/esm/cmds/manifest/index.js.map +0 -1
  229. package/dist/esm/cmds/manifest/manifestHandler.js +0 -44
  230. package/dist/esm/cmds/manifest/manifestHandler.js.map +0 -1
  231. package/dist/esm/cmds/serve/index.js.map +0 -1
  232. package/dist/esm/cmds/serve/serveHandler.js +0 -54
  233. package/dist/esm/cmds/serve/serveHandler.js.map +0 -1
  234. package/dist/esm/cmds/serve/serveUtils.js +0 -30
  235. package/dist/esm/cmds/serve/serveUtils.js.map +0 -1
  236. package/dist/esm/cmds/watch/index.js.map +0 -1
  237. package/dist/esm/cmds/watch/watchHandler.js +0 -87
  238. package/dist/esm/cmds/watch/watchHandler.js.map +0 -1
  239. package/dist/esm/utils/misc.js +0 -139
  240. package/dist/esm/utils/misc.js.map +0 -1
  241. package/dist/esm/utils/snap-config.js +0 -107
  242. package/dist/esm/utils/snap-config.js.map +0 -1
  243. package/dist/types/cmds/build/buildHandler.d.ts +0 -13
  244. package/dist/types/cmds/build/bundle.d.ts +0 -15
  245. package/dist/types/cmds/build/utils.d.ts +0 -56
  246. package/dist/types/cmds/eval/evalHandler.d.ts +0 -9
  247. package/dist/types/cmds/manifest/manifestHandler.d.ts +0 -10
  248. package/dist/types/cmds/serve/serveHandler.d.ts +0 -10
  249. package/dist/types/cmds/serve/serveUtils.d.ts +0 -22
  250. package/dist/types/cmds/watch/index.d.ts +0 -9
  251. package/dist/types/cmds/watch/watchHandler.d.ts +0 -14
  252. package/dist/types/utils/misc.d.ts +0 -53
  253. package/dist/types/utils/snap-config.d.ts +0 -48
  254. /package/dist/cjs/{cmds → commands}/index.js +0 -0
  255. /package/dist/types/{cmds → commands}/index.d.ts +0 -0
  256. /package/dist/types/{cmds/build → commands/serve}/index.d.ts +0 -0
package/README.md CHANGED
@@ -7,10 +7,10 @@ A CLI for developing MetaMask Snaps.
7
7
  Use Node.js `16.0.0` or later.
8
8
  We recommend [nvm](https://github.com/nvm-sh/nvm) for managing Node.js versions.
9
9
 
10
- Install a dev dependency in your snap project or globally using `yarn` or `npm`:
10
+ Install a dev dependency in your snap project using `yarn` or `npm`:
11
11
 
12
- - `npm install -g @metamask/snaps-cli`
13
- - `yarn global add @metamask/snaps-cli`
12
+ - `npm install --save-dev @metamask/snaps-cli`
13
+ - `yarn add -D @metamask/snaps-cli`
14
14
 
15
15
  ## Usage
16
16
 
@@ -18,49 +18,50 @@ Install a dev dependency in your snap project or globally using `yarn` or `npm`:
18
18
  Usage: mm-snap <command> [options]
19
19
 
20
20
  Commands:
21
- mm-snap build Build Snap from source [aliases: b]
22
- mm-snap eval Attempt to evaluate Snap bundle in SES [aliases: e]
21
+ mm-snap build Build snap from source [aliases: b]
22
+ mm-snap eval Attempt to evaluate snap bundle in SES [aliases: e]
23
23
  mm-snap manifest Validate the snap.manifest.json file [aliases: m]
24
24
  mm-snap serve Locally serve Snap file(s) for testing [aliases: s]
25
25
  mm-snap watch Build Snap on change [aliases: w]
26
26
 
27
27
  Options:
28
28
  --version Show version number [boolean]
29
- --verboseErrors Display original errors [boolean] [default: true]
30
- --suppressWarnings Whether to suppress warnings[boolean] [default: false]
29
+ -c, --config Path to config file [string]
30
+ --verboseErrors Display original errors [deprecated] [boolean]
31
+ --suppressWarnings Whether to suppress warnings [deprecated] [boolean]
31
32
  -h, --help Show help [boolean]
32
33
 
33
34
  Examples:
34
- mm-snap init Initialize a snap project in the
35
- current directory
36
- mm-snap init my-snap Initialize a snap project in the
37
- 'my-snap' directory
38
- mm-snap build -s src/index.js -d out Build 'src/index.js' as
39
- './out/bundle.js'
40
- mm-snap build -s src/index.js -d out -n Build 'src/index.js' as
41
- snap.js './out/snap.js'
42
- mm-snap serve -r out Serve files in './out' on port 8080
43
- mm-snap serve -r out -p 9000 Serve files in './out' on port 9000
44
- mm-snap watch -s src/index.js -d out Rebuild './out/bundle.js' on changes
45
- to files in 'src/index.js' parent
46
- and child directories
35
+ mm-snap build Build './src/index.js' as
36
+ './dist/bundle.js'
37
+ mm-snap build --config Build './src/index.js' as
38
+ ./snap.config.build.ts './dist/bundle.js' using the config
39
+ in './snap.config.build.ts'
40
+ mm-snap manifest --fix Check the snap manifest, and fix any
41
+ errors
42
+ mm-snap watch --port 8000 The snap input file for changes, and
43
+ serve it on port 8000
44
+ mm-snap serve --port 8000 Serve the snap bundle on port 8000
47
45
  ```
48
46
 
49
47
  ## MetaMask Snaps
50
48
 
51
- MetaMask Snaps enables trustlessly extending the functionality of MetaMask at runtime.
52
- A Snap consist of two things: a JSON manifest and a JavaScript bundle.
53
- At present, Snaps can be published as npm packages on the public npm registry, or hosted locally during development.
54
- In the future, it will be possible to publish snaps on many different platforms, including arbitrary npm registries and IPFS.
49
+ MetaMask Snaps enables trustlessly extending the functionality of MetaMask at
50
+ runtime. A snap consist of two things: a JSON manifest and a JavaScript bundle.
51
+ At present, snaps can be published as npm packages on the public npm registry,
52
+ or hosted locally during development. In the future, it will be possible to
53
+ publish snaps on many different platforms, including arbitrary npm registries
54
+ and IPFS.
55
55
 
56
- We recommend building your Snap using this tool.
57
- You can bundle your Snap using your own tools, but it must run in SES and only use the global APIs that MetaMask exposes at runtime.
58
- Although Snaps currently execute in the browser, some browser APIs are not available to Snaps, and Snaps do not have DOM access.
56
+ We recommend building your snap using this tool. You can bundle your snap using
57
+ your own tools, but it must run in SES and only use the global APIs that
58
+ MetaMask exposes at runtime. Although snaps currently execute in the browser,
59
+ some browser APIs are not available to snaps, and snaps do not have DOM access.
59
60
 
60
61
  ### The Snap Manifest
61
62
 
62
- Your manifest must be named `snap.manifest.json` and located in the root directory of your npm package.
63
- Here's an example manifest:
63
+ Your manifest must be named `snap.manifest.json` and located in the root
64
+ directory of your npm package. Here's an example manifest:
64
65
 
65
66
  ```json
66
67
  {
@@ -89,9 +90,11 @@ Here's an example manifest:
89
90
  }
90
91
  ```
91
92
 
92
- Refer to [the Snaps publishing specification](https://github.com/MetaMask/specifications/blob/main/snaps/publishing.md) and the [manifest JSON schema](https://github.com/MetaMask/snaps-monorepo/blob/main/packages/controllers/src/snaps/json-schemas/snap-manifest.schema.json) for details.
93
+ Refer to [the Snaps publishing specification](https://github.com/MetaMask/specifications/blob/main/snaps/publishing.md)
94
+ for more information about the manifest.
93
95
 
94
- > **ATTN:** If your Snap is not compatible with the publishing specification, your Snap may not work properly or install at all.
96
+ > **Note**: If your snap is not compatible with the publishing specification,
97
+ > your snap may not work properly or install at all.
95
98
 
96
99
  ### Assumed Project Structure
97
100
 
@@ -108,56 +111,529 @@ snap-project/
108
111
  ├─ ... (all other project files and folders)
109
112
  ```
110
113
 
111
- Source files other than `index.js` are located through its imports.
112
- The defaults can be overwritten using the `snap.config.js` [config file](#configuration-file).
114
+ Source files other than `index.js` are located through its imports. The
115
+ defaults can be overwritten using the `snap.config.js` or (`snap.config.ts`)
116
+ [config file](#configuration-file).
113
117
 
114
- ### Configuration File
118
+ ## Configuration
115
119
 
116
- `snap.config.js` should be placed in the project root directory. It can override cli options - the property `cliOptions` should have string keys matching command arguments. Values become argument defaults, which can still be overridden on the command line.
120
+ The MetaMask Snaps CLI supports a configuration file. It can be either:
117
121
 
118
- Example:
122
+ - `snap.config.js` - a CommonJS module.
123
+ - `snap.config.ts` - a TypeScript module.
124
+
125
+ The file should be placed in the project root directory.
126
+
127
+ ### Example
128
+
129
+ #### JavaScript
119
130
 
120
131
  ```javascript
121
132
  module.exports = {
122
- cliOptions: {
123
- src: 'lib/index.js',
124
- dist: 'out',
133
+ bundler: 'webpack', // default: 'browserify'
134
+ input: 'src/index.js',
135
+ output: {
136
+ path: 'dist',
137
+ },
138
+ server: {
125
139
  port: 9000,
126
140
  },
127
141
  };
128
142
  ```
129
143
 
130
- If you want to customize the Browserify build process, you can provide `bundlerCustomizer` property. It's a function that takes one argument - [browserify object](https://github.com/browserify/browserify#api-example) which we use internally to bundle the snap. You can transform it in any way you want, for example adding plugins.
144
+ #### TypeScript
131
145
 
132
- Example:
146
+ The CLI has full support for TypeScript out of the box. `@metamask/snaps-cli`
147
+ exports a `SnapConfig` type that can be used to type the configuration object.
133
148
 
134
- ```javascript
135
- const brfs = require('brfs');
149
+ ```typescript
150
+ import type { SnapConfig } from '@metamask/snaps-cli';
136
151
 
137
- module.exports = {
138
- cliOptions: {
139
- /* ... */
152
+ const config: SnapConfig = {
153
+ bundler: 'webpack', // default: 'browserify'
154
+ input: 'src/index.js',
155
+ output: {
156
+ path: 'dist',
140
157
  },
141
- bundlerCustomizer: (bundler) => {
142
- bundler.transform(brfs);
158
+ server: {
159
+ port: 9000,
143
160
  },
144
161
  };
162
+
163
+ export default config;
145
164
  ```
146
165
 
147
166
  The configuration file should not be published.
148
167
 
149
- ### Gotchas
150
-
151
- - Commands
152
- - `watch --src ... --dist ...` rebuilds on all changes in the parent directory
153
- of `src` and its children except:
154
- - `node_modules/`
155
- - `test/`, `tests/`, `**/*.test.js`, and `**/*.test.ts`
156
- - The specified `dist` directory
157
- - Dotfiles
158
- - `serve --root ... --port ...` serves the `root` directory on `localhost:port`
159
- - By default, `root` serves the current working directory: `.`
160
- - Arguments
161
- - `src` must be a file path when specified
162
- - `dist` and `root` must be directory paths when specified
163
- - `transpilationMode` must be at least `localOnly` for TypeScript Snaps
168
+ ### Options
169
+
170
+ - [`bundler`](#bundler)
171
+ - [`input`](#input)
172
+ - [`output`](#output)
173
+ - [`output.path`](#outputpath)
174
+ - [`output.filename`](#outputfilename)
175
+ - [`output.clean`](#outputclean)
176
+ - [`output.minimize`](#outputminimize)
177
+ - [`server`](#server)
178
+ - [`server.enabled`](#serverenabled)
179
+ - [`server.root`](#serverroot)
180
+ - [`server.port`](#serverport)
181
+ - [`environment`](#environment)
182
+ - [`stats`](#stats)
183
+ - [`stats.verbose`](#statsverbose)
184
+ - [`stats.builtIns`](#statsbuiltins)
185
+ - [`stats.buffer`](#statsbuffer)
186
+ - [`customizeWebpackConfig`](#customizewebpackconfig)
187
+ - [`experimental`](#experimental)
188
+ - [`experimental.wasm`](#experimentalwasm)
189
+
190
+ #### `bundler`
191
+
192
+ - Type: `"browserify"` | `"webpack"`
193
+ - Default: `"browserify"`
194
+
195
+ The bundler to use. The MetaMask Snaps CLI supports both Browserify and
196
+ Webpack. For backwards compatibility, Browserify is the default, but we
197
+ recommend using Webpack. Browserify support will be removed in the future.
198
+
199
+ This section describes the options for the Webpack bundler. For Browserify,
200
+ refer to the [legacy options](#legacy-options) section.
201
+
202
+ #### `input`
203
+
204
+ - Type: `string`
205
+ - Default: `"src/index.js"`
206
+
207
+ The entry point of your snap. This is the file that will be bundled.
208
+
209
+ #### `output`
210
+
211
+ - Type: `object`
212
+
213
+ The output configuration.
214
+
215
+ ##### `output.path`
216
+
217
+ - Type: `string`
218
+ - Default: `"dist"`
219
+
220
+ The output directory.
221
+
222
+ ##### `output.filename`
223
+
224
+ - Type: `string`
225
+ - Default: `"bundle.js"`
226
+
227
+ The output filename.
228
+
229
+ ##### `output.clean`
230
+
231
+ - Type: `boolean`
232
+ - Default: `false`
233
+
234
+ Whether to clean the output directory before building.
235
+
236
+ ##### `output.minimize`
237
+
238
+ - Type: `boolean`
239
+ - Default: `true`
240
+
241
+ Whether to minimize the bundle. This will remove comments and whitespace from
242
+ the bundle, mangle variable names, and perform other optimizations.
243
+
244
+ #### `sourceMap`
245
+
246
+ - Type: `boolean | "inline"`
247
+ - Default: `true`
248
+
249
+ Whether to generate a source map. If `"inline"`, the source map will be
250
+ inlined in the bundle. Otherwise, it will be written to a separate file.
251
+
252
+ #### `evaluate`
253
+
254
+ - Type: `boolean`
255
+
256
+ Whether to evaluate the bundle. This will check the bundle for compatibility
257
+ issues with the MetaMask Snaps runtime. If there are any issues, the CLI will
258
+ exit with an error.
259
+
260
+ #### `manifest`
261
+
262
+ - Type: `object`
263
+
264
+ The snap manifest configuration.
265
+
266
+ ##### `manifest.path`
267
+
268
+ - Type: `string`
269
+ - Default: `"snap.manifest.json"`
270
+
271
+ The path to the snap manifest, i.e., `snap.manifest.json`.
272
+
273
+ ##### `manifest.update`
274
+
275
+ - Type: `boolean`
276
+ - Default: `true`
277
+
278
+ Whether to update the manifest with the bundle shasum, and any other possible
279
+ updates. If `false`, the manifest will not be updated, and an error will be
280
+ thrown if the manifest is not up-to-date.
281
+
282
+ #### `server`
283
+
284
+ - Type: `object`
285
+
286
+ The development server configuration. The development server is used to test
287
+ your snap during development, using the `watch` and `serve` commands.
288
+
289
+ ##### `server.enabled`
290
+
291
+ - Type: `boolean`
292
+ - Default: `true`
293
+
294
+ Whether to enable the development server. If `false`, the development server
295
+ will not be started when running the `watch` command. This option has no effect
296
+ on the `serve` command.
297
+
298
+ ##### `server.root`
299
+
300
+ - Type: `string`
301
+ - Default: `process.cwd()`
302
+
303
+ The root directory of the development server. This is the directory that will
304
+ be served by the development server.
305
+
306
+ ##### `server.port`
307
+
308
+ - Type: `number`
309
+ - Default: `8081`
310
+
311
+ The port to run the development server on. If set to `0`, a random port will
312
+ be used.
313
+
314
+ #### `environment`
315
+
316
+ - Type: `Record<string, unknown>`
317
+
318
+ The environment configuration. This is used to set environment variables for
319
+ the snap, which can be accessed using `process.env`.
320
+
321
+ In addition to the environment variables set by the user, the following
322
+ environment variables are set by the CLI:
323
+
324
+ - `NODE_ENV` - `"production"`.
325
+ - `NODE_DEBUG` - `false`.
326
+ - `DEBUG` - `false`.
327
+
328
+ #### `stats`
329
+
330
+ - Type: `object`
331
+
332
+ The stats configuration, which controls the log output of the CLI.
333
+
334
+ ##### `stats.verbose`
335
+
336
+ - Type: `boolean`
337
+ - Default: `false`
338
+
339
+ Whether to enable verbose logging. If `true`, the CLI will log more
340
+ information.
341
+
342
+ ##### `stats.builtIns`
343
+
344
+ - Type: `false | object`
345
+ - Default: `{ ignore: [] }`
346
+
347
+ Whether to check for missing built-in modules. The MetaMask Snaps CLI does not
348
+ support Node.js built-ins out of the box, and any used built-ins must be
349
+ provided through the `customizeWebpackConfig` option. When enabled, the CLI
350
+ shows a warning if a built-in module is used, but not provided.
351
+
352
+ ###### `stats.builtIns.ignore`
353
+
354
+ - Type: `string[]`
355
+
356
+ A list of built-in modules to ignore. This is useful if the built-in module is
357
+ not actually used in the snap, but is added by a dependency.
358
+
359
+ ###### `stats.buffer`
360
+
361
+ - Type: `boolean`
362
+ - Default: `true`
363
+
364
+ Whether to show a warning if `Buffer` is used, but not provided. The `Buffer`
365
+ global is not available in the MetaMask Snaps runtime by default, and must
366
+ be provided through the `customizeWebpackConfig` option.
367
+
368
+ #### `customizeWebpackConfig`
369
+
370
+ - Type: `(config: webpack.Configuration) => webpack.Configuration`
371
+
372
+ A function that can be used to customize the Webpack configuration. This is
373
+ useful if you need to add a Webpack plugin, provide a polyfill, add a loader,
374
+ and so on.
375
+
376
+ The function receives the Webpack configuration object, and should return the
377
+ modified configuration object. For convenience, `@metamask/snaps-cli` exports
378
+ a `merge` function (re-exported from `webpack-merge`) that can be used to merge
379
+ the configuration object with the default configuration.
380
+
381
+ The default configuration can be found in [`src/webpack/config.ts`](./src/webpack/config.ts).
382
+
383
+ ```typescript
384
+ import type { SnapConfig } from '@metamask/snaps-cli';
385
+ import { merge } from '@metamask/snaps-cli';
386
+
387
+ const config: SnapConfig = {
388
+ customizeWebpackConfig: (config) =>
389
+ merge(config, {
390
+ plugins: [
391
+ // Add a plugin.
392
+ ],
393
+ module: {
394
+ rules: [
395
+ // Add a loader.
396
+ ],
397
+ },
398
+ }),
399
+ };
400
+
401
+ export default config;
402
+ ```
403
+
404
+ #### `experimental`
405
+
406
+ - Type: `object`
407
+
408
+ Experimental features. These features are not stable, and may change in the
409
+ future.
410
+
411
+ ##### `experimental.wasm`
412
+
413
+ - Type: `boolean`
414
+
415
+ Whether to enable WebAssembly support. When this is enabled, WebAssembly files
416
+ can be imported in the snap, for example:
417
+
418
+ ```typescript
419
+ import program from './program.wasm';
420
+
421
+ const module = await WebAssembly.instantiate(program, {});
422
+ // ...
423
+ ```
424
+
425
+ ### Legacy Options
426
+
427
+ > **Warning**: Using the Browserify-based build system is deprecated, and will
428
+ > be removed in a future version. Please migrate to the Webpack-based build
429
+ > system.
430
+
431
+ - [`bundler`](#bundler)
432
+ - [`cliOptions`](#clioptions)
433
+ - [`cliOptions.bundle`](#clioptionsbundle)
434
+ - [`cliOptions.dist`](#clioptionsdist)
435
+ - [`cliOptions.eval`](#clioptionseval)
436
+ - [`cliOptions.manifest`](#clioptionsmanifest)
437
+ - [`cliOptions.outfileName`](#clioptionsoutfilename)
438
+ - [`cliOptions.port`](#clioptionsport)
439
+ - [`cliOptions.root`](#clioptionsroot)
440
+ - [`cliOptions.sourceMaps`](#clioptionssourcemaps)
441
+ - [`cliOptions.src`](#clioptionssrc)
442
+ - [`cliOptions.stripComments`](#clioptionsstripcomments)
443
+ - [`cliOptions.transpilationMode`](#clioptionstranspilationmode)
444
+ - [`cliOptions.depsToTranspile`](#clioptionsdepstotranspile)
445
+ - [`cliOptions.writeManifest`](#clioptionswritemanifest)
446
+ - [`cliOptions.serve`](#clioptionsserve)
447
+ - [`cliOptions.verboseErrors`](#clioptionsverboseerrors)
448
+ - [`cliOptions.suppressWarnings`](#clioptionssuppresswarnings)
449
+ - [`bundlerCustomizer`](#bundlercustomizer)
450
+
451
+ #### `bundler`
452
+
453
+ - Type: `"browserify"` | `"webpack"`
454
+ - Default: `"browserify"`
455
+
456
+ The bundler to use. The MetaMask Snaps CLI supports both Browserify and
457
+ Webpack. For backwards compatibility, Browserify is the default, but we
458
+ recommend using Webpack. Browserify support will be removed in the future.
459
+
460
+ This section describes the options for the Browserify bundler. For Webpack,
461
+ refer to the [options](#options) section.
462
+
463
+ #### `cliOptions`
464
+
465
+ - Type: `object`
466
+
467
+ The CLI options. These can be specified using the CLI, but can also be
468
+ specified in the configuration file. For example, the `--port` option can be
469
+ specified in the configuration file as follows:
470
+
471
+ ```ts
472
+ export default {
473
+ cliOptions: {
474
+ port: 8081,
475
+ },
476
+ };
477
+ ```
478
+
479
+ But can also be specified using the CLI:
480
+
481
+ ```bash
482
+ $ mm-snap serve --port 8081
483
+ ```
484
+
485
+ If the same option is specified in both the configuration file and the CLI,
486
+ the CLI option takes precedence.
487
+
488
+ ##### `cliOptions.bundle`
489
+
490
+ - Type: `string`
491
+ - Default: `dist/bundle.js`
492
+
493
+ The path to the bundle file. This is where the bundle will be written to.
494
+
495
+ ##### `cliOptions.dist`
496
+
497
+ - Type: `string`
498
+ - Default: `dist`
499
+
500
+ The path to the distribution directory. This is where the bundle file will be
501
+ written to, if the `bundle` option is not specified.
502
+
503
+ ##### `cliOptions.eval`
504
+
505
+ - Type: `boolean`
506
+ - Default: `true`
507
+
508
+ Whether to evaluate the bundle. If `true`, the bundle will be evaluated in the
509
+ MetaMask Snaps runtime, to check for any compatibility issues.
510
+
511
+ ##### `cliOptions.manifest`
512
+
513
+ - Type: `boolean`
514
+ - Default: `true`
515
+
516
+ Whether to validate the snap manifest. If `true`, the snap manifest will be
517
+ validated, and any errors or warnings will be shown.
518
+
519
+ ##### `cliOptions.outfileName`
520
+
521
+ - Type: `string`
522
+ - Default: `bundle.js`
523
+
524
+ The name of the bundle file. This is used to generate the bundle file path,
525
+ using the `dist` option. For example, if `dist` is `dist`, and `outfileName`
526
+ is `bundle.js`, the bundle file path will be `dist/bundle.js`. This option is
527
+ ignored if the `bundle` option is specified.
528
+
529
+ ##### `cliOptions.port`
530
+
531
+ - Type: `number`
532
+ - Default: `8081`
533
+
534
+ The port to use for the development server.
535
+
536
+ ##### `cliOptions.root`
537
+
538
+ - Type: `string`
539
+ - Default: `.`
540
+
541
+ The root directory. This should be the directory that contains the snap
542
+ manifest, and the `dist` directory. This will be served by the development
543
+ server.
544
+
545
+ ##### `cliOptions.sourceMaps`
546
+
547
+ - Type: `boolean`
548
+ - Default: `false`
549
+
550
+ Whether to generate source maps. If `true`, source maps will be generated for
551
+ the bundle.
552
+
553
+ ##### `cliOptions.src`
554
+
555
+ - Type: `string`
556
+ - Default: `src/index.js`
557
+
558
+ The path to the entry file. This is the file that will be bundled.
559
+
560
+ ##### `cliOptions.stripComments`
561
+
562
+ - Type: `boolean`
563
+ - Default: `true`
564
+
565
+ Whether to strip comments from the bundle. If `true`, comments will be stripped
566
+ from the bundle, and the bundle will be minified.
567
+
568
+ ##### `cliOptions.transpilationMode`
569
+
570
+ - Type: `'localAndDeps' | 'localOnly' | 'none'`
571
+ - Default: `'localOnly'`
572
+
573
+ The transpilation mode to use. This determines which files will be transpiled
574
+ by Babel. The possible values are:
575
+
576
+ - `'localAndDeps'`: Transpile all files, including dependencies.
577
+ - `'localOnly'`: Transpile only local files.
578
+ - `'none'`: Do not transpile any files.
579
+
580
+ ##### `cliOptions.depsToTranspile`
581
+
582
+ - Type: `string[]`
583
+ - Default: `[]`
584
+
585
+ If `transpilationMode` is `'localAndDeps'`, this option can be used to specify
586
+ which dependencies should be transpiled. This is useful if you want to transpile
587
+ a limited set of dependencies, but not all of them.
588
+
589
+ ##### `cliOptions.writeManifest`
590
+
591
+ - Type: `boolean`
592
+ - Default: `true`
593
+
594
+ Whether to write the snap manifest. If `true`, the snap manifest will be written
595
+ with any changes made by the CLI, if the manifest is invalid.
596
+
597
+ ##### `cliOptions.serve`
598
+
599
+ - Type: `boolean`
600
+ - Default: `true`
601
+
602
+ Whether to serve the snap. If `true`, the snap will be served by the development
603
+ server, when running `mm-snap watch`.
604
+
605
+ ##### `cliOptions.suppressWarnings`
606
+
607
+ - Type: `boolean`
608
+ - Default: `false`
609
+
610
+ This option exists for backwards compatibility, and is ignored.
611
+
612
+ ##### `cliOptions.verboseErrors`
613
+
614
+ - Type: `boolean`
615
+ - Default: `false`
616
+
617
+ This option exists for backwards compatibility, and is ignored.
618
+
619
+ #### `bundlerCustomizer`
620
+
621
+ - Type: `(bundler: BrowserifyObject) => void`
622
+
623
+ A function that customizes the bundler. This function is called after the
624
+ bundler is created, but before the bundle is written to disk. This can be used
625
+ to customize the bundler, for example to add plugins or transforms.
626
+
627
+ ```typescript
628
+ import type { SnapConfig } from '@metamask/snaps-cli';
629
+ import type { BrowserifyObject } from 'browserify';
630
+
631
+ const config: SnapConfig = {
632
+ bundlerCustomizer: (bundler: BrowserifyObject) => {
633
+ // Add the BRFS transform to Browserify.
634
+ bundler.transform('brfs');
635
+ },
636
+ };
637
+
638
+ export default config;
639
+ ```