@metamask/snaps-cli 0.38.1-flask.1 → 1.0.0

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 (253) hide show
  1. package/CHANGELOG.md +377 -19
  2. package/README.md +67 -542
  3. package/dist/builders.d.ts +27 -0
  4. package/dist/{esm/builders.js → builders.js} +51 -48
  5. package/dist/builders.js.map +1 -0
  6. package/dist/{types/cli.d.ts → cli.d.ts} +1 -1
  7. package/dist/cli.js +51 -0
  8. package/dist/cli.js.map +1 -0
  9. package/dist/cmds/build/buildHandler.d.ts +13 -0
  10. package/dist/cmds/build/buildHandler.js +37 -0
  11. package/dist/cmds/build/buildHandler.js.map +1 -0
  12. package/dist/cmds/build/bundle.d.ts +15 -0
  13. package/dist/cmds/build/bundle.js +80 -0
  14. package/dist/cmds/build/bundle.js.map +1 -0
  15. package/dist/{types/commands/serve → cmds/build}/index.d.ts +4 -4
  16. package/dist/cmds/build/index.js +29 -0
  17. package/dist/cmds/build/index.js.map +1 -0
  18. package/dist/cmds/build/utils.d.ts +56 -0
  19. package/dist/cmds/build/utils.js +100 -0
  20. package/dist/cmds/build/utils.js.map +1 -0
  21. package/dist/cmds/eval/evalHandler.d.ts +9 -0
  22. package/dist/cmds/eval/evalHandler.js +25 -0
  23. package/dist/cmds/eval/evalHandler.js.map +1 -0
  24. package/dist/cmds/eval/index.d.ts +9 -0
  25. package/dist/cmds/eval/index.js +15 -0
  26. package/dist/cmds/eval/index.js.map +1 -0
  27. package/dist/cmds/index.js +14 -0
  28. package/dist/cmds/index.js.map +1 -0
  29. package/dist/cmds/init/index.d.ts +9 -0
  30. package/dist/cmds/init/index.js +34 -0
  31. package/dist/cmds/init/index.js.map +1 -0
  32. package/dist/cmds/init/initHandler.d.ts +26 -0
  33. package/dist/cmds/init/initHandler.js +69 -0
  34. package/dist/cmds/init/initHandler.js.map +1 -0
  35. package/dist/cmds/init/initUtils.d.ts +39 -0
  36. package/dist/cmds/init/initUtils.js +122 -0
  37. package/dist/cmds/init/initUtils.js.map +1 -0
  38. package/dist/cmds/manifest/index.d.ts +9 -0
  39. package/dist/cmds/manifest/index.js +24 -0
  40. package/dist/cmds/manifest/index.js.map +1 -0
  41. package/dist/cmds/manifest/manifestHandler.d.ts +10 -0
  42. package/dist/cmds/manifest/manifestHandler.js +50 -0
  43. package/dist/cmds/manifest/manifestHandler.js.map +1 -0
  44. package/dist/cmds/serve/index.d.ts +9 -0
  45. package/dist/cmds/serve/index.js +15 -0
  46. package/dist/cmds/serve/index.js.map +1 -0
  47. package/dist/cmds/serve/serveHandler.d.ts +10 -0
  48. package/dist/cmds/serve/serveHandler.js +59 -0
  49. package/dist/cmds/serve/serveHandler.js.map +1 -0
  50. package/dist/cmds/serve/serveUtils.d.ts +22 -0
  51. package/dist/cmds/serve/serveUtils.js +39 -0
  52. package/dist/cmds/serve/serveUtils.js.map +1 -0
  53. package/dist/cmds/watch/index.d.ts +9 -0
  54. package/dist/cmds/watch/index.js +32 -0
  55. package/dist/cmds/watch/index.js.map +1 -0
  56. package/dist/cmds/watch/watchHandler.d.ts +14 -0
  57. package/dist/cmds/watch/watchHandler.js +100 -0
  58. package/dist/cmds/watch/watchHandler.js.map +1 -0
  59. package/dist/main.js +15 -0
  60. package/dist/main.js.map +1 -0
  61. package/dist/utils/index.d.ts +2 -0
  62. package/dist/utils/index.js +19 -0
  63. package/dist/utils/index.js.map +1 -0
  64. package/dist/utils/misc.d.ts +53 -0
  65. package/dist/utils/misc.js +156 -0
  66. package/dist/utils/misc.js.map +1 -0
  67. package/dist/utils/snap-config.d.ts +48 -0
  68. package/dist/utils/snap-config.js +117 -0
  69. package/dist/utils/snap-config.js.map +1 -0
  70. package/package.json +35 -54
  71. package/.browserslistrc +0 -3
  72. package/dist/cjs/builders.js +0 -148
  73. package/dist/cjs/builders.js.map +0 -1
  74. package/dist/cjs/cli.js +0 -35
  75. package/dist/cjs/cli.js.map +0 -1
  76. package/dist/cjs/commands/build/build.js +0 -54
  77. package/dist/cjs/commands/build/build.js.map +0 -1
  78. package/dist/cjs/commands/build/implementation.js +0 -31
  79. package/dist/cjs/commands/build/implementation.js.map +0 -1
  80. package/dist/cjs/commands/build/index.js +0 -45
  81. package/dist/cjs/commands/build/index.js.map +0 -1
  82. package/dist/cjs/commands/eval/eval.js +0 -57
  83. package/dist/cjs/commands/eval/eval.js.map +0 -1
  84. package/dist/cjs/commands/eval/implementation.js +0 -27
  85. package/dist/cjs/commands/eval/implementation.js.map +0 -1
  86. package/dist/cjs/commands/eval/index.js +0 -50
  87. package/dist/cjs/commands/eval/index.js.map +0 -1
  88. package/dist/cjs/commands/index.js +0 -30
  89. package/dist/cjs/commands/index.js.map +0 -1
  90. package/dist/cjs/commands/manifest/implementation.js +0 -34
  91. package/dist/cjs/commands/manifest/implementation.js.map +0 -1
  92. package/dist/cjs/commands/manifest/index.js +0 -50
  93. package/dist/cjs/commands/manifest/index.js.map +0 -1
  94. package/dist/cjs/commands/manifest/manifest.js +0 -55
  95. package/dist/cjs/commands/manifest/manifest.js.map +0 -1
  96. package/dist/cjs/commands/serve/index.js +0 -33
  97. package/dist/cjs/commands/serve/index.js.map +0 -1
  98. package/dist/cjs/commands/serve/serve.js +0 -21
  99. package/dist/cjs/commands/serve/serve.js.map +0 -1
  100. package/dist/cjs/commands/watch/implementation.js +0 -35
  101. package/dist/cjs/commands/watch/implementation.js.map +0 -1
  102. package/dist/cjs/commands/watch/index.js +0 -47
  103. package/dist/cjs/commands/watch/index.js.map +0 -1
  104. package/dist/cjs/commands/watch/watch.js +0 -51
  105. package/dist/cjs/commands/watch/watch.js.map +0 -1
  106. package/dist/cjs/config.js +0 -290
  107. package/dist/cjs/config.js.map +0 -1
  108. package/dist/cjs/errors.js +0 -37
  109. package/dist/cjs/errors.js.map +0 -1
  110. package/dist/cjs/index.js +0 -77
  111. package/dist/cjs/index.js.map +0 -1
  112. package/dist/cjs/main.js +0 -19
  113. package/dist/cjs/main.js.map +0 -1
  114. package/dist/cjs/utils/cli.js +0 -61
  115. package/dist/cjs/utils/cli.js.map +0 -1
  116. package/dist/cjs/utils/errors.js +0 -42
  117. package/dist/cjs/utils/errors.js.map +0 -1
  118. package/dist/cjs/utils/index.js +0 -25
  119. package/dist/cjs/utils/index.js.map +0 -1
  120. package/dist/cjs/utils/legacy.js +0 -48
  121. package/dist/cjs/utils/legacy.js.map +0 -1
  122. package/dist/cjs/utils/logging.js +0 -46
  123. package/dist/cjs/utils/logging.js.map +0 -1
  124. package/dist/cjs/utils/path.js +0 -16
  125. package/dist/cjs/utils/path.js.map +0 -1
  126. package/dist/cjs/utils/steps.js +0 -52
  127. package/dist/cjs/utils/steps.js.map +0 -1
  128. package/dist/cjs/webpack/compiler.js +0 -96
  129. package/dist/cjs/webpack/compiler.js.map +0 -1
  130. package/dist/cjs/webpack/config.js +0 -234
  131. package/dist/cjs/webpack/config.js.map +0 -1
  132. package/dist/cjs/webpack/index.js +0 -22
  133. package/dist/cjs/webpack/index.js.map +0 -1
  134. package/dist/cjs/webpack/loaders/browserify.js +0 -97
  135. package/dist/cjs/webpack/loaders/browserify.js.map +0 -1
  136. package/dist/cjs/webpack/loaders/wasm.js +0 -36
  137. package/dist/cjs/webpack/loaders/wasm.js.map +0 -1
  138. package/dist/cjs/webpack/plugins.js +0 -340
  139. package/dist/cjs/webpack/plugins.js.map +0 -1
  140. package/dist/cjs/webpack/utils.js +0 -133
  141. package/dist/cjs/webpack/utils.js.map +0 -1
  142. package/dist/esm/builders.js.map +0 -1
  143. package/dist/esm/cli.js +0 -26
  144. package/dist/esm/cli.js.map +0 -1
  145. package/dist/esm/commands/build/build.js +0 -51
  146. package/dist/esm/commands/build/build.js.map +0 -1
  147. package/dist/esm/commands/build/implementation.js +0 -27
  148. package/dist/esm/commands/build/implementation.js.map +0 -1
  149. package/dist/esm/commands/build/index.js +0 -17
  150. package/dist/esm/commands/build/index.js.map +0 -1
  151. package/dist/esm/commands/eval/eval.js +0 -54
  152. package/dist/esm/commands/eval/eval.js.map +0 -1
  153. package/dist/esm/commands/eval/implementation.js +0 -24
  154. package/dist/esm/commands/eval/implementation.js.map +0 -1
  155. package/dist/esm/commands/eval/index.js +0 -22
  156. package/dist/esm/commands/eval/index.js.map +0 -1
  157. package/dist/esm/commands/index.js +0 -15
  158. package/dist/esm/commands/index.js.map +0 -1
  159. package/dist/esm/commands/manifest/implementation.js +0 -33
  160. package/dist/esm/commands/manifest/implementation.js.map +0 -1
  161. package/dist/esm/commands/manifest/index.js +0 -22
  162. package/dist/esm/commands/manifest/index.js.map +0 -1
  163. package/dist/esm/commands/manifest/manifest.js +0 -52
  164. package/dist/esm/commands/manifest/manifest.js.map +0 -1
  165. package/dist/esm/commands/serve/index.js +0 -18
  166. package/dist/esm/commands/serve/index.js.map +0 -1
  167. package/dist/esm/commands/serve/serve.js +0 -17
  168. package/dist/esm/commands/serve/serve.js.map +0 -1
  169. package/dist/esm/commands/watch/implementation.js +0 -34
  170. package/dist/esm/commands/watch/implementation.js.map +0 -1
  171. package/dist/esm/commands/watch/index.js +0 -19
  172. package/dist/esm/commands/watch/index.js.map +0 -1
  173. package/dist/esm/commands/watch/watch.js +0 -50
  174. package/dist/esm/commands/watch/watch.js.map +0 -1
  175. package/dist/esm/config.js +0 -294
  176. package/dist/esm/config.js.map +0 -1
  177. package/dist/esm/errors.js +0 -30
  178. package/dist/esm/errors.js.map +0 -1
  179. package/dist/esm/index.js +0 -6
  180. package/dist/esm/index.js.map +0 -1
  181. package/dist/esm/main.js +0 -10
  182. package/dist/esm/main.js.map +0 -1
  183. package/dist/esm/utils/cli.js +0 -43
  184. package/dist/esm/utils/cli.js.map +0 -1
  185. package/dist/esm/utils/errors.js +0 -43
  186. package/dist/esm/utils/errors.js.map +0 -1
  187. package/dist/esm/utils/index.js +0 -8
  188. package/dist/esm/utils/index.js.map +0 -1
  189. package/dist/esm/utils/legacy.js +0 -47
  190. package/dist/esm/utils/legacy.js.map +0 -1
  191. package/dist/esm/utils/logging.js +0 -40
  192. package/dist/esm/utils/logging.js.map +0 -1
  193. package/dist/esm/utils/path.js +0 -13
  194. package/dist/esm/utils/path.js.map +0 -1
  195. package/dist/esm/utils/steps.js +0 -43
  196. package/dist/esm/utils/steps.js.map +0 -1
  197. package/dist/esm/webpack/compiler.js +0 -89
  198. package/dist/esm/webpack/compiler.js.map +0 -1
  199. package/dist/esm/webpack/config.js +0 -236
  200. package/dist/esm/webpack/config.js.map +0 -1
  201. package/dist/esm/webpack/index.js +0 -5
  202. package/dist/esm/webpack/index.js.map +0 -1
  203. package/dist/esm/webpack/loaders/browserify.js +0 -82
  204. package/dist/esm/webpack/loaders/browserify.js.map +0 -1
  205. package/dist/esm/webpack/loaders/wasm.js +0 -26
  206. package/dist/esm/webpack/loaders/wasm.js.map +0 -1
  207. package/dist/esm/webpack/plugins.js +0 -343
  208. package/dist/esm/webpack/plugins.js.map +0 -1
  209. package/dist/esm/webpack/utils.js +0 -160
  210. package/dist/esm/webpack/utils.js.map +0 -1
  211. package/dist/types/__fixtures__/configs/cjs.d.ts +0 -1
  212. package/dist/types/__fixtures__/configs/esm.d.ts +0 -3
  213. package/dist/types/__fixtures__/configs/invalid.d.ts +0 -3
  214. package/dist/types/__fixtures__/configs/javascript/snap.config.d.ts +0 -0
  215. package/dist/types/__fixtures__/configs/typescript/snap.config.d.ts +0 -3
  216. package/dist/types/builders.d.ts +0 -8
  217. package/dist/types/commands/build/build.d.ts +0 -10
  218. package/dist/types/commands/build/implementation.d.ts +0 -10
  219. package/dist/types/commands/build/index.d.ts +0 -10
  220. package/dist/types/commands/eval/__test__/browserify/bad/snap.config.d.ts +0 -3
  221. package/dist/types/commands/eval/__test__/browserify/good/snap.config.d.ts +0 -3
  222. package/dist/types/commands/eval/__test__/webpack/bad/snap.config.d.ts +0 -3
  223. package/dist/types/commands/eval/__test__/webpack/good/snap.config.d.ts +0 -3
  224. package/dist/types/commands/eval/__test__/webpack/snap.config.d.ts +0 -3
  225. package/dist/types/commands/eval/eval.d.ts +0 -14
  226. package/dist/types/commands/eval/implementation.d.ts +0 -9
  227. package/dist/types/commands/eval/index.d.ts +0 -10
  228. package/dist/types/commands/manifest/implementation.d.ts +0 -12
  229. package/dist/types/commands/manifest/index.d.ts +0 -10
  230. package/dist/types/commands/manifest/manifest.d.ts +0 -14
  231. package/dist/types/commands/serve/serve.d.ts +0 -16
  232. package/dist/types/commands/watch/implementation.d.ts +0 -14
  233. package/dist/types/commands/watch/index.d.ts +0 -10
  234. package/dist/types/commands/watch/watch.d.ts +0 -19
  235. package/dist/types/config.d.ts +0 -626
  236. package/dist/types/errors.d.ts +0 -25
  237. package/dist/types/index.d.ts +0 -5
  238. package/dist/types/utils/cli.d.ts +0 -17
  239. package/dist/types/utils/errors.d.ts +0 -23
  240. package/dist/types/utils/index.d.ts +0 -6
  241. package/dist/types/utils/legacy.d.ts +0 -27
  242. package/dist/types/utils/logging.d.ts +0 -22
  243. package/dist/types/utils/path.d.ts +0 -9
  244. package/dist/types/utils/steps.d.ts +0 -17
  245. package/dist/types/webpack/compiler.d.ts +0 -29
  246. package/dist/types/webpack/config.d.ts +0 -37
  247. package/dist/types/webpack/index.d.ts +0 -3
  248. package/dist/types/webpack/loaders/browserify.d.ts +0 -16
  249. package/dist/types/webpack/loaders/wasm.d.ts +0 -20
  250. package/dist/types/webpack/plugins.d.ts +0 -147
  251. package/dist/types/webpack/utils.d.ts +0 -156
  252. /package/dist/{types/commands → cmds}/index.d.ts +0 -0
  253. /package/dist/{types/main.d.ts → main.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 using `yarn` or `npm`:
10
+ Install a dev dependency in your snap project or globally using `yarn` or `npm`:
11
11
 
12
- - `npm install --save-dev @metamask/snaps-cli`
13
- - `yarn add -D @metamask/snaps-cli`
12
+ - `npm install -g @metamask/snaps-cli`
13
+ - `yarn global add @metamask/snaps-cli`
14
14
 
15
15
  ## Usage
16
16
 
@@ -18,50 +18,50 @@ Install a dev dependency in your snap project 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]
23
- mm-snap manifest Validate the snap.manifest.json file [aliases: m]
24
- mm-snap serve Locally serve Snap file(s) for testing [aliases: s]
25
- mm-snap watch Build Snap on change [aliases: w]
21
+ mm-snap build Build Snap from source [aliases: b]
22
+ mm-snap eval Attempt to evaluate Snap bundle in SES [aliases: e]
23
+ mm-snap init [directory] Initialize Snap package [aliases: i]
24
+ mm-snap manifest Validate the snap.manifest.json file [aliases: m]
25
+ mm-snap serve Locally serve Snap file(s) for testing [aliases: s]
26
+ mm-snap watch Build Snap on change [aliases: w]
26
27
 
27
28
  Options:
28
29
  --version Show version number [boolean]
29
- -c, --config Path to config file [string]
30
- --verboseErrors Display original errors [deprecated] [boolean]
31
- --suppressWarnings Whether to suppress warnings [deprecated] [boolean]
30
+ --verboseErrors Display original errors [boolean] [default: true]
31
+ --suppressWarnings Whether to suppress warnings[boolean] [default: false]
32
32
  -h, --help Show help [boolean]
33
33
 
34
34
  Examples:
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
35
+ mm-snap init Initialize a snap project in the
36
+ current directory
37
+ mm-snap init my-snap Initialize a snap project in the
38
+ 'my-snap' directory
39
+ mm-snap build -s src/index.js -d out Build 'src/index.js' as
40
+ './out/bundle.js'
41
+ mm-snap build -s src/index.js -d out -n Build 'src/index.js' as
42
+ snap.js './out/snap.js'
43
+ mm-snap serve -r out Serve files in './out' on port 8080
44
+ mm-snap serve -r out -p 9000 Serve files in './out' on port 9000
45
+ mm-snap watch -s src/index.js -d out Rebuild './out/bundle.js' on changes
46
+ to files in 'src/index.js' parent
47
+ and child directories
45
48
  ```
46
49
 
47
50
  ## MetaMask Snaps
48
51
 
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.
52
+ MetaMask Snaps enables trustlessly extending the functionality of MetaMask at runtime.
53
+ A Snap consist of two things: a JSON manifest and a JavaScript bundle.
54
+ At present, Snaps can be published as npm packages on the public npm registry, or hosted locally during development.
55
+ In the future, it will be possible to publish snaps on many different platforms, including arbitrary npm registries and IPFS.
55
56
 
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.
57
+ We recommend building your Snap using this tool.
58
+ 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.
59
+ Although Snaps currently execute in the browser, some browser APIs are not available to Snaps, and Snaps do not have DOM access.
60
60
 
61
61
  ### The Snap Manifest
62
62
 
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:
63
+ Your manifest must be named `snap.manifest.json` and located in the root directory of your npm package.
64
+ Here's an example manifest:
65
65
 
66
66
  ```json
67
67
  {
@@ -90,11 +90,9 @@ directory of your npm package. Here's an example manifest:
90
90
  }
91
91
  ```
92
92
 
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
+ 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.
95
94
 
96
- > **Note**: If your snap is not compatible with the publishing specification,
97
- > your snap may not work properly or install at all.
95
+ > **ATTN:** If your Snap is not compatible with the publishing specification, your Snap may not work properly or install at all.
98
96
 
99
97
  ### Assumed Project Structure
100
98
 
@@ -111,529 +109,56 @@ snap-project/
111
109
  ├─ ... (all other project files and folders)
112
110
  ```
113
111
 
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).
112
+ Source files other than `index.js` are located through its imports.
113
+ The defaults can be overwritten using the `snap.config.js` [config file](#configuration-file).
117
114
 
118
- ## Configuration
115
+ ### Configuration File
119
116
 
120
- The MetaMask Snaps CLI supports a configuration file. It can be either:
117
+ `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.
121
118
 
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
+ Example:
130
120
 
131
121
  ```javascript
132
122
  module.exports = {
133
- bundler: 'webpack', // default: 'browserify'
134
- input: 'src/index.js',
135
- output: {
136
- path: 'dist',
137
- },
138
- server: {
123
+ cliOptions: {
124
+ src: 'lib/index.js',
125
+ dist: 'out',
139
126
  port: 9000,
140
127
  },
141
128
  };
142
129
  ```
143
130
 
144
- #### TypeScript
131
+ 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.
145
132
 
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
+ Example:
148
134
 
149
- ```typescript
150
- import type { SnapConfig } from '@metamask/snaps-cli';
135
+ ```javascript
136
+ const brfs = require('brfs');
151
137
 
152
- const config: SnapConfig = {
153
- bundler: 'webpack', // default: 'browserify'
154
- input: 'src/index.js',
155
- output: {
156
- path: 'dist',
138
+ module.exports = {
139
+ cliOptions: {
140
+ /* ... */
157
141
  },
158
- server: {
159
- port: 9000,
142
+ bundlerCustomizer: (bundler) => {
143
+ bundler.transform(brfs);
160
144
  },
161
145
  };
162
-
163
- export default config;
164
146
  ```
165
147
 
166
148
  The configuration file should not be published.
167
149
 
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
- ```
150
+ ### Gotchas
151
+
152
+ - Commands
153
+ - `watch --src ... --dist ...` rebuilds on all changes in the parent directory
154
+ of `src` and its children except:
155
+ - `node_modules/`
156
+ - `test/`, `tests/`, `**/*.test.js`, and `**/*.test.ts`
157
+ - The specified `dist` directory
158
+ - Dotfiles
159
+ - `serve --root ... --port ...` serves the `root` directory on `localhost:port`
160
+ - By default, `root` serves the current working directory: `.`
161
+ - Arguments
162
+ - `src` must be a file path when specified
163
+ - `dist` and `root` must be directory paths when specified
164
+ - `transpilationMode` must be at least `localOnly` for TypeScript Snaps
@@ -0,0 +1,27 @@
1
+ import { Options, PositionalOptions } from 'yargs';
2
+ export declare type SnapsCliBuilders = {
3
+ readonly bundle: Readonly<Options>;
4
+ readonly dist: Readonly<Options>;
5
+ readonly eval: Readonly<Options>;
6
+ readonly manifest: Readonly<Options>;
7
+ readonly outfileName: Readonly<Options>;
8
+ readonly port: Readonly<Options>;
9
+ readonly root: Readonly<Options>;
10
+ readonly sourceMaps: Readonly<Options>;
11
+ readonly src: Readonly<Options>;
12
+ readonly stripComments: Readonly<Options>;
13
+ readonly suppressWarnings: Readonly<Options>;
14
+ readonly transpilationMode: Readonly<Options>;
15
+ readonly depsToTranspile: Readonly<Options>;
16
+ readonly verboseErrors: Readonly<Options>;
17
+ readonly writeManifest: Readonly<Options>;
18
+ readonly serve: Readonly<Options>;
19
+ readonly directory: Readonly<PositionalOptions>;
20
+ };
21
+ export declare enum TranspilationModes {
22
+ LocalAndDeps = "localAndDeps",
23
+ LocalOnly = "localOnly",
24
+ None = "none"
25
+ }
26
+ declare const builders: SnapsCliBuilders;
27
+ export default builders;