@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
@@ -1,160 +0,0 @@
1
- import { dim } from 'chalk';
2
- import { promises as fs } from 'fs';
3
- import { dirname, resolve } from 'path';
4
- export const BROWSERSLIST_FILE = resolve(dirname(// eslint-disable-next-line n/no-extraneous-require
5
- require.resolve('@metamask/snaps-cli/package.json')), '.browserslistrc');
6
- /**
7
- * Get the default loader for JavaScript and TypeScript files, based on the
8
- * config object.
9
- *
10
- * - If the `legacy` option is set, we use the custom `browserify` loader. This
11
- * uses the legacy Browserify config to transpile the code.
12
- * - Otherwise, we use the `swc-loader`. This is a Webpack loader that uses the
13
- * `SWC` compiler, which is a much faster alternative to Babel and TypeScript's
14
- * own compiler.
15
- *
16
- * @param config - The processed snap Webpack config.
17
- * @param config.legacy - The legacy config object, if any.
18
- * @param config.sourceMap - Whether to generate source maps.
19
- * @see https://swc.rs/docs/usage/swc-loader
20
- * @returns The default loader.
21
- */ export async function getDefaultLoader({ legacy, sourceMap }) {
22
- if (legacy) {
23
- return {
24
- /**
25
- * If the snap uses the legacy config, we use the custom `browserify`
26
- * loader. This uses the legacy Browserify config to transpile the code.
27
- * This is necessary for backwards compatibility with the
28
- * `bundlerCustomizer` function.
29
- */ loader: resolve(__dirname, 'loaders', 'browserify'),
30
- /**
31
- * The options for the `browserify` loader. These can be overridden in the
32
- * snap config.
33
- */ options: legacy
34
- };
35
- }
36
- const targets = await getBrowserslistTargets();
37
- return {
38
- /**
39
- * We use the `swc-loader` to transpile TypeScript and JavaScript files.
40
- * This is a Webpack loader that uses the `SWC` compiler, which is a much
41
- * faster alternative to Babel and TypeScript's own compiler.
42
- */ loader: 'swc-loader',
43
- /**
44
- * The options for the `swc-loader`. These can be overridden in the
45
- * `.swcrc` file.
46
- *
47
- * @see https://swc.rs/docs/configuration/swcrc
48
- */ options: {
49
- sync: false,
50
- /**
51
- * This tells SWC to generate source maps. We set it to the
52
- * `sourceMap` value from the config object.
53
- *
54
- * This must be enabled if source maps are enabled in the config.
55
- */ sourceMaps: Boolean(getDevTool(sourceMap)),
56
- jsc: {
57
- /**
58
- * MetaMask targets ES2020, so we set the target to ES2020. This
59
- * ensures that the code is transpiled to ES2020, and that the
60
- * necessary polyfills are added.
61
- *
62
- * @see https://swc.rs/docs/configuration/compilation#jsctarget
63
- */ target: 'es2020',
64
- parser: {
65
- /**
66
- * This tells the parser to parse TypeScript files. If you
67
- * don't need to support TypeScript, you can set this to
68
- * `ecmascript` instead, but there's no harm in leaving it
69
- * as `typescript`.
70
- *
71
- * @see https://swc.rs/docs/configuration/compilation#jscparser
72
- */ syntax: 'typescript'
73
- }
74
- },
75
- /**
76
- * The module configuration. This tells SWC how to output the
77
- * transpiled code.
78
- *
79
- * @see https://swc.rs/docs/configuration/modules
80
- */ module: {
81
- /**
82
- * This tells SWC to output CommonJS modules. MetaMask Snaps
83
- * doesn't support ES modules yet, so this is necessary.
84
- *
85
- * @see https://swc.rs/docs/configuration/modules#commonjs
86
- */ type: 'commonjs'
87
- },
88
- env: {
89
- targets: targets.join(', ')
90
- }
91
- }
92
- };
93
- }
94
- /**
95
- * Get the Webpack devtool configuration based on the given snap config.
96
- *
97
- * - If `sourceMap` is `inline`, return `inline-source-map`.
98
- * - If `sourceMap` is `true`, return `source-map`.
99
- * - Otherwise, return `false`.
100
- *
101
- * @param sourceMap - The `sourceMap` value from the snap config.
102
- * @returns The Webpack devtool configuration.
103
- */ export function getDevTool(sourceMap) {
104
- if (sourceMap === 'inline') {
105
- return 'inline-source-map';
106
- }
107
- if (sourceMap === true) {
108
- return 'source-map';
109
- }
110
- return false;
111
- }
112
- /**
113
- * Get a function that can be used as handler function for Webpack's
114
- * `ProgressPlugin`.
115
- *
116
- * @param spinner - The spinner to update.
117
- * @param spinnerText - The initial spinner text. This will be prepended to the
118
- * percentage.
119
- * @returns A function that can be used as handler function for Webpack's
120
- * `ProgressPlugin`.
121
- */ // Note: This is extracted for testing purposes.
122
- export function getProgressHandler(spinner, spinnerText) {
123
- return (percentage)=>{
124
- if (spinner && spinnerText) {
125
- spinner.text = `${spinnerText} ${dim(`(${Math.round(percentage * 100)}%)`)}`;
126
- }
127
- };
128
- }
129
- /**
130
- * Get the targets from the `.browserslistrc` file.
131
- *
132
- * @returns The browser targets as an array of strings.
133
- */ export async function getBrowserslistTargets() {
134
- const contents = await fs.readFile(BROWSERSLIST_FILE, 'utf8');
135
- return contents.split('\n').map((line)=>line.trim()).filter((line)=>line && !line.startsWith('#'));
136
- }
137
- /**
138
- * Get a singular or plural string based on the given count. This is useful for
139
- * generating messages like "1 error" or "2 errors". By default, the plural
140
- * string is the singular string with an "s" appended to it.
141
- *
142
- * This assumes that the text is in English, and likely won't work for some
143
- * other languages.
144
- *
145
- * @param count - The count.
146
- * @param singular - The singular string.
147
- * @param plural - The plural string.
148
- * @returns The singular or plural string.
149
- * @example
150
- * ```typescript
151
- * pluralize(1, 'error'); // => 'error'
152
- * pluralize(2, 'error'); // => 'errors'
153
- * pluralize(1, 'error', 'problem'); // => 'error'
154
- * pluralize(2, 'error', 'problems'); // => 'problems'
155
- * ```
156
- */ export function pluralize(count, singular, plural = `${singular}s`) {
157
- return count === 1 ? singular : plural;
158
- }
159
-
160
- //# sourceMappingURL=utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/webpack/utils.ts"],"sourcesContent":["import { dim } from 'chalk';\nimport { promises as fs } from 'fs';\nimport type { Ora } from 'ora';\nimport { dirname, resolve } from 'path';\nimport type { Configuration } from 'webpack';\n\nimport type { ProcessedWebpackConfig } from '../config';\n\nexport const BROWSERSLIST_FILE = resolve(\n dirname(\n // eslint-disable-next-line n/no-extraneous-require\n require.resolve('@metamask/snaps-cli/package.json'),\n ),\n '.browserslistrc',\n);\n\n/**\n * Get the default loader for JavaScript and TypeScript files, based on the\n * config object.\n *\n * - If the `legacy` option is set, we use the custom `browserify` loader. This\n * uses the legacy Browserify config to transpile the code.\n * - Otherwise, we use the `swc-loader`. This is a Webpack loader that uses the\n * `SWC` compiler, which is a much faster alternative to Babel and TypeScript's\n * own compiler.\n *\n * @param config - The processed snap Webpack config.\n * @param config.legacy - The legacy config object, if any.\n * @param config.sourceMap - Whether to generate source maps.\n * @see https://swc.rs/docs/usage/swc-loader\n * @returns The default loader.\n */\nexport async function getDefaultLoader({\n legacy,\n sourceMap,\n}: ProcessedWebpackConfig) {\n if (legacy) {\n return {\n /**\n * If the snap uses the legacy config, we use the custom `browserify`\n * loader. This uses the legacy Browserify config to transpile the code.\n * This is necessary for backwards compatibility with the\n * `bundlerCustomizer` function.\n */\n loader: resolve(__dirname, 'loaders', 'browserify'),\n\n /**\n * The options for the `browserify` loader. These can be overridden in the\n * snap config.\n */\n options: legacy,\n };\n }\n\n const targets = await getBrowserslistTargets();\n return {\n /**\n * We use the `swc-loader` to transpile TypeScript and JavaScript files.\n * This is a Webpack loader that uses the `SWC` compiler, which is a much\n * faster alternative to Babel and TypeScript's own compiler.\n */\n loader: 'swc-loader',\n\n /**\n * The options for the `swc-loader`. These can be overridden in the\n * `.swcrc` file.\n *\n * @see https://swc.rs/docs/configuration/swcrc\n */\n options: {\n sync: false,\n\n /**\n * This tells SWC to generate source maps. We set it to the\n * `sourceMap` value from the config object.\n *\n * This must be enabled if source maps are enabled in the config.\n */\n sourceMaps: Boolean(getDevTool(sourceMap)),\n\n jsc: {\n /**\n * MetaMask targets ES2020, so we set the target to ES2020. This\n * ensures that the code is transpiled to ES2020, and that the\n * necessary polyfills are added.\n *\n * @see https://swc.rs/docs/configuration/compilation#jsctarget\n */\n target: 'es2020',\n\n parser: {\n /**\n * This tells the parser to parse TypeScript files. If you\n * don't need to support TypeScript, you can set this to\n * `ecmascript` instead, but there's no harm in leaving it\n * as `typescript`.\n *\n * @see https://swc.rs/docs/configuration/compilation#jscparser\n */\n syntax: 'typescript',\n },\n },\n\n /**\n * The module configuration. This tells SWC how to output the\n * transpiled code.\n *\n * @see https://swc.rs/docs/configuration/modules\n */\n module: {\n /**\n * This tells SWC to output CommonJS modules. MetaMask Snaps\n * doesn't support ES modules yet, so this is necessary.\n *\n * @see https://swc.rs/docs/configuration/modules#commonjs\n */\n type: 'commonjs',\n },\n\n env: {\n targets: targets.join(', '),\n },\n },\n };\n}\n\n/**\n * Get the Webpack devtool configuration based on the given snap config.\n *\n * - If `sourceMap` is `inline`, return `inline-source-map`.\n * - If `sourceMap` is `true`, return `source-map`.\n * - Otherwise, return `false`.\n *\n * @param sourceMap - The `sourceMap` value from the snap config.\n * @returns The Webpack devtool configuration.\n */\nexport function getDevTool(\n sourceMap: ProcessedWebpackConfig['sourceMap'],\n): Configuration['devtool'] {\n if (sourceMap === 'inline') {\n return 'inline-source-map';\n }\n\n if (sourceMap === true) {\n return 'source-map';\n }\n\n return false;\n}\n\n/**\n * Get a function that can be used as handler function for Webpack's\n * `ProgressPlugin`.\n *\n * @param spinner - The spinner to update.\n * @param spinnerText - The initial spinner text. This will be prepended to the\n * percentage.\n * @returns A function that can be used as handler function for Webpack's\n * `ProgressPlugin`.\n */\n// Note: This is extracted for testing purposes.\nexport function getProgressHandler(spinner?: Ora, spinnerText?: string) {\n return (percentage: number) => {\n if (spinner && spinnerText) {\n spinner.text = `${spinnerText} ${dim(\n `(${Math.round(percentage * 100)}%)`,\n )}`;\n }\n };\n}\n\n/**\n * Get the targets from the `.browserslistrc` file.\n *\n * @returns The browser targets as an array of strings.\n */\nexport async function getBrowserslistTargets() {\n const contents = await fs.readFile(BROWSERSLIST_FILE, 'utf8');\n return contents\n .split('\\n')\n .map((line) => line.trim())\n .filter((line) => line && !line.startsWith('#'));\n}\n\n/**\n * Get a singular or plural string based on the given count. This is useful for\n * generating messages like \"1 error\" or \"2 errors\". By default, the plural\n * string is the singular string with an \"s\" appended to it.\n *\n * This assumes that the text is in English, and likely won't work for some\n * other languages.\n *\n * @param count - The count.\n * @param singular - The singular string.\n * @param plural - The plural string.\n * @returns The singular or plural string.\n * @example\n * ```typescript\n * pluralize(1, 'error'); // => 'error'\n * pluralize(2, 'error'); // => 'errors'\n * pluralize(1, 'error', 'problem'); // => 'error'\n * pluralize(2, 'error', 'problems'); // => 'problems'\n * ```\n */\nexport function pluralize(\n count: number,\n singular: string,\n plural = `${singular}s`,\n) {\n return count === 1 ? singular : plural;\n}\n"],"names":["dim","promises","fs","dirname","resolve","BROWSERSLIST_FILE","require","getDefaultLoader","legacy","sourceMap","loader","__dirname","options","targets","getBrowserslistTargets","sync","sourceMaps","Boolean","getDevTool","jsc","target","parser","syntax","module","type","env","join","getProgressHandler","spinner","spinnerText","percentage","text","Math","round","contents","readFile","split","map","line","trim","filter","startsWith","pluralize","count","singular","plural"],"mappings":"AAAA,SAASA,GAAG,QAAQ,QAAQ;AAC5B,SAASC,YAAYC,EAAE,QAAQ,KAAK;AAEpC,SAASC,OAAO,EAAEC,OAAO,QAAQ,OAAO;AAKxC,OAAO,MAAMC,oBAAoBD,QAC/BD,QACE,mDAAmD;AACnDG,QAAQF,OAAO,CAAC,sCAElB,mBACA;AAEF;;;;;;;;;;;;;;;CAeC,GACD,OAAO,eAAeG,iBAAiB,EACrCC,MAAM,EACNC,SAAS,EACc;IACvB,IAAID,QAAQ;QACV,OAAO;YACL;;;;;OAKC,GACDE,QAAQN,QAAQO,WAAW,WAAW;YAEtC;;;OAGC,GACDC,SAASJ;QACX;IACF;IAEA,MAAMK,UAAU,MAAMC;IACtB,OAAO;QACL;;;;KAIC,GACDJ,QAAQ;QAER;;;;;KAKC,GACDE,SAAS;YACPG,MAAM;YAEN;;;;;OAKC,GACDC,YAAYC,QAAQC,WAAWT;YAE/BU,KAAK;gBACH;;;;;;SAMC,GACDC,QAAQ;gBAERC,QAAQ;oBACN;;;;;;;WAOC,GACDC,QAAQ;gBACV;YACF;YAEA;;;;;OAKC,GACDC,QAAQ;gBACN;;;;;SAKC,GACDC,MAAM;YACR;YAEAC,KAAK;gBACHZ,SAASA,QAAQa,IAAI,CAAC;YACxB;QACF;IACF;AACF;AAEA;;;;;;;;;CASC,GACD,OAAO,SAASR,WACdT,SAA8C;IAE9C,IAAIA,cAAc,UAAU;QAC1B,OAAO;IACT;IAEA,IAAIA,cAAc,MAAM;QACtB,OAAO;IACT;IAEA,OAAO;AACT;AAEA;;;;;;;;;CASC,GACD,gDAAgD;AAChD,OAAO,SAASkB,mBAAmBC,OAAa,EAAEC,WAAoB;IACpE,OAAO,CAACC;QACN,IAAIF,WAAWC,aAAa;YAC1BD,QAAQG,IAAI,GAAG,CAAC,EAAEF,YAAY,CAAC,EAAE7B,IAC/B,CAAC,CAAC,EAAEgC,KAAKC,KAAK,CAACH,aAAa,KAAK,EAAE,CAAC,EACpC,CAAC;QACL;IACF;AACF;AAEA;;;;CAIC,GACD,OAAO,eAAehB;IACpB,MAAMoB,WAAW,MAAMhC,GAAGiC,QAAQ,CAAC9B,mBAAmB;IACtD,OAAO6B,SACJE,KAAK,CAAC,MACNC,GAAG,CAAC,CAACC,OAASA,KAAKC,IAAI,IACvBC,MAAM,CAAC,CAACF,OAASA,QAAQ,CAACA,KAAKG,UAAU,CAAC;AAC/C;AAEA;;;;;;;;;;;;;;;;;;;CAmBC,GACD,OAAO,SAASC,UACdC,KAAa,EACbC,QAAgB,EAChBC,SAAS,CAAC,EAAED,SAAS,CAAC,CAAC;IAEvB,OAAOD,UAAU,IAAIC,WAAWC;AAClC"}
@@ -1 +0,0 @@
1
- export {};
@@ -1,3 +0,0 @@
1
- import type { SnapConfig } from '../../config';
2
- declare const config: SnapConfig;
3
- export default config;
@@ -1,3 +0,0 @@
1
- import type { SnapConfig } from '../../config';
2
- declare const config: SnapConfig;
3
- export default config;
@@ -1,3 +0,0 @@
1
- import type { SnapConfig } from '../../../config';
2
- declare const config: SnapConfig;
3
- export default config;
@@ -1,8 +0,0 @@
1
- import type { Options } from 'yargs';
2
- export declare enum TranspilationModes {
3
- LocalAndDeps = "localAndDeps",
4
- LocalOnly = "localOnly",
5
- None = "none"
6
- }
7
- declare const builders: Record<string, Readonly<Options>>;
8
- export default builders;
@@ -1,10 +0,0 @@
1
- import type { ProcessedConfig } from '../../config';
2
- /**
3
- * Build all files in the given source directory to the given destination
4
- * directory.
5
- *
6
- * This creates the destination directory if it doesn't exist.
7
- *
8
- * @param config - The config object.
9
- */
10
- export declare function buildHandler(config: ProcessedConfig): Promise<void>;
@@ -1,10 +0,0 @@
1
- import type { ProcessedWebpackConfig } from '../../config';
2
- import type { WebpackOptions } from '../../webpack';
3
- /**
4
- * Build the snap bundle. This uses Webpack to build the bundle.
5
- *
6
- * @param config - The config object.
7
- * @param options - The Webpack options.
8
- * @returns A promise that resolves when the bundle is built.
9
- */
10
- export declare function build(config: ProcessedWebpackConfig, options?: WebpackOptions): Promise<void>;
@@ -1,10 +0,0 @@
1
- import type yargs from 'yargs';
2
- import type { YargsArgs } from '../../types/yargs';
3
- declare const command: {
4
- command: string[];
5
- desc: string;
6
- builder: (yarg: yargs.Argv) => void;
7
- handler: (argv: YargsArgs) => Promise<void>;
8
- };
9
- export * from './implementation';
10
- export default command;
@@ -1,3 +0,0 @@
1
- import type { SnapConfig } from '../../../../../config';
2
- declare const config: SnapConfig;
3
- export default config;
@@ -1,3 +0,0 @@
1
- import type { SnapConfig } from '../../../../../config';
2
- declare const config: SnapConfig;
3
- export default config;
@@ -1,3 +0,0 @@
1
- import type { SnapConfig } from '../../../../../config';
2
- declare const config: SnapConfig;
3
- export default config;
@@ -1,3 +0,0 @@
1
- import type { SnapConfig } from '../../../../../config';
2
- declare const config: SnapConfig;
3
- export default config;
@@ -1,3 +0,0 @@
1
- import type { SnapConfig } from '../../../../config';
2
- declare const config: SnapConfig;
3
- export default config;
@@ -1,14 +0,0 @@
1
- import type { ProcessedConfig } from '../../config';
2
- export declare type EvalOptions = {
3
- input?: string;
4
- };
5
- export declare type EvalContext = Required<EvalOptions>;
6
- /**
7
- * Runs the snap in a worker, to ensure SES compatibility.
8
- *
9
- * @param config - The processed config object.
10
- * @param options - The eval options.
11
- * @returns A promise that resolves once the eval has finished.
12
- * @throws If the eval failed.
13
- */
14
- export declare function evaluateHandler(config: ProcessedConfig, options?: EvalOptions): Promise<void>;
@@ -1,9 +0,0 @@
1
- /**
2
- * Evaluate the given bundle in the SES environment. This is a wrapper around
3
- * {@link evalBundle} that throws a {@link CommandError} if the bundle cannot be
4
- * evaluated.
5
- *
6
- * @param path - The path to the bundle.
7
- * @throws If the bundle cannot be evaluated.
8
- */
9
- export declare function evaluate(path: string): Promise<import("@metamask/snaps-utils").EvalOutput>;
@@ -1,10 +0,0 @@
1
- import type yargs from 'yargs';
2
- import type { YargsArgs } from '../../types/yargs';
3
- declare const command: {
4
- command: string[];
5
- desc: string;
6
- builder: (yarg: yargs.Argv) => void;
7
- handler: (argv: YargsArgs) => Promise<void>;
8
- };
9
- export * from './implementation';
10
- export default command;
@@ -1,12 +0,0 @@
1
- import type { Ora } from 'ora';
2
- /**
3
- * Check the snap manifest file at the given path. If `write` is `true`, the
4
- * manifest will be written to disk if it is invalid. If `write` is `false`,
5
- * the manifest will not be written to disk, and the function will log any
6
- * errors and warnings to the console.
7
- *
8
- * @param path - The path to the manifest file.
9
- * @param write - Whether to write the manifest to disk if it is invalid.
10
- * @param spinner - An optional spinner to use for logging.
11
- */
12
- export declare function manifest(path: string, write: boolean, spinner?: Ora): Promise<boolean>;
@@ -1,10 +0,0 @@
1
- import type yargs from 'yargs';
2
- import type { YargsArgs } from '../../types/yargs';
3
- declare const command: {
4
- command: string[];
5
- desc: string;
6
- builder: (yarg: yargs.Argv) => void;
7
- handler: (argv: YargsArgs) => Promise<void>;
8
- };
9
- export * from './implementation';
10
- export default command;
@@ -1,14 +0,0 @@
1
- import type { ProcessedConfig } from '../../config';
2
- declare type ManifestOptions = {
3
- fix?: boolean;
4
- };
5
- /**
6
- * Validates a snap.manifest.json file. Attempts to fix the manifest and write
7
- * the fixed version to disk if `writeManifest` is true. Throws if validation
8
- * fails.
9
- *
10
- * @param config - The config object.
11
- * @param options - The options object.
12
- */
13
- export declare function manifestHandler(config: ProcessedConfig, options: ManifestOptions): Promise<void>;
14
- export {};
@@ -1,16 +0,0 @@
1
- import type { ProcessedConfig } from '../../config';
2
- declare type ServeOptions = {
3
- /**
4
- * The port to listen on.
5
- */
6
- port: number;
7
- };
8
- /**
9
- * Starts a local, static HTTP server on the given port with the given root
10
- * directory.
11
- *
12
- * @param config - The config object.
13
- * @param options - The options object.
14
- */
15
- export declare function serveHandler(config: ProcessedConfig, options: ServeOptions): Promise<void>;
16
- export {};
@@ -1,14 +0,0 @@
1
- import type { Watching } from 'webpack';
2
- import type { ProcessedWebpackConfig } from '../../config';
3
- import type { WebpackOptions } from '../../webpack';
4
- /**
5
- * Build the snap bundle and watch for changes. This uses Webpack to build the
6
- * bundle.
7
- *
8
- * @param config - The config object.
9
- * @param options - The Webpack options.
10
- * @returns A promise that resolves when the bundle is built for the first time.
11
- * The promise resolves with a Webpack watching instance that can be used to
12
- * close the watcher.
13
- */
14
- export declare function watch(config: ProcessedWebpackConfig, options?: WebpackOptions): Promise<Watching>;
@@ -1,10 +0,0 @@
1
- import type yargs from 'yargs';
2
- import type { YargsArgs } from '../../types/yargs';
3
- declare const command: {
4
- command: string[];
5
- desc: string;
6
- builder: (yarg: yargs.Argv) => void;
7
- handler: (argv: YargsArgs) => Promise<void>;
8
- };
9
- export * from './implementation';
10
- export default command;
@@ -1,19 +0,0 @@
1
- import type { ProcessedConfig } from '../../config';
2
- declare type WatchOptions = {
3
- /**
4
- * The port to listen on.
5
- */
6
- port?: number;
7
- };
8
- /**
9
- * Watch a directory and its subdirectories for changes, and build when files
10
- * are added or changed.
11
- *
12
- * Ignores 'node_modules' and dotfiles.
13
- * Creates destination directory if it doesn't exist.
14
- *
15
- * @param config - The config object.
16
- * @param options - The options object.
17
- */
18
- export declare function watchHandler(config: ProcessedConfig, options: WatchOptions): Promise<void>;
19
- export {};