@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
@@ -1,2 +1,6 @@
1
- export * from './misc';
2
- export * from './snap-config';
1
+ export * from './cli';
2
+ export * from './errors';
3
+ export * from './legacy';
4
+ export * from './logging';
5
+ export * from './path';
6
+ export * from './steps';
@@ -0,0 +1,27 @@
1
+ import type { LegacyOptions } from '../config';
2
+ /**
3
+ * Get the dependencies to transpile, as well as the regular input file.
4
+ *
5
+ * If `transpilationMode` is not set to `localAndDeps`, this will return an
6
+ * empty array.
7
+ *
8
+ * @param config - The config object.
9
+ * @returns An array with regular expressions of dependencies that should be
10
+ * transpiled.
11
+ */
12
+ export declare function processDependencies(config: LegacyOptions): RegExp[];
13
+ /**
14
+ * Processes a string of space delimited dependencies into one RegExp string.
15
+ *
16
+ * @param dependencies - An array of dependencies to add to the RegExp.
17
+ * @returns A RegExp object.
18
+ */
19
+ export declare function getDependencyRegExp(dependencies: string[]): RegExp | null;
20
+ /**
21
+ * Helper function to remove any leading and trailing slashes from dependency
22
+ * list.
23
+ *
24
+ * @param dependencies - An array of dependencies to sanitize.
25
+ * @returns An array of sanitized paths.
26
+ */
27
+ export declare function sanitizeDependencyPaths(dependencies: string[]): string[];
@@ -0,0 +1,22 @@
1
+ import type { Ora } from 'ora';
2
+ /**
3
+ * Log a warning message. The message is prefixed with "Warning:".
4
+ *
5
+ * @param message - The message to log.
6
+ * @param spinner - The spinner to clear.
7
+ */
8
+ export declare function warn(message: string, spinner?: Ora): void;
9
+ /**
10
+ * Log an info message.
11
+ *
12
+ * @param message - The message to log.
13
+ * @param spinner - The spinner to clear.
14
+ */
15
+ export declare function info(message: string, spinner?: Ora): void;
16
+ /**
17
+ * Log an error message. The message is prefixed with "Error:".
18
+ *
19
+ * @param message - The message to log.
20
+ * @param spinner - The spinner to clear.
21
+ */
22
+ export declare function error(message: string, spinner?: Ora): void;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Get the relative path from the current working directory to the given
3
+ * absolute path.
4
+ *
5
+ * @param absolutePath - The absolute path.
6
+ * @param cwd - The current working directory. Defaults to `process.cwd()`.
7
+ * @returns The relative path.
8
+ */
9
+ export declare function getRelativePath(absolutePath: string, cwd?: string): string;
@@ -0,0 +1,17 @@
1
+ import type { Ora } from 'ora';
2
+ export declare type Step<Context extends Record<string, unknown>> = {
3
+ name: string;
4
+ condition?: (context: Context) => boolean;
5
+ task: (context: Context & {
6
+ spinner: Ora;
7
+ }) => Promise<void>;
8
+ };
9
+ export declare type Steps<Context extends Record<string, unknown>> = Readonly<Step<Context>[]>;
10
+ /**
11
+ * Execute a list of steps in series. Each step receives the context object and
12
+ * a spinner instance.
13
+ *
14
+ * @param steps - The steps to execute.
15
+ * @param context - The context object that will be passed to each step.
16
+ */
17
+ export declare function executeSteps<Context extends Record<string, unknown>>(steps: Steps<Context>, context: Context): Promise<void>;
@@ -0,0 +1,29 @@
1
+ import type { Server } from 'http';
2
+ import type { ProcessedConfig, ProcessedWebpackConfig } from '../config';
3
+ import type { WebpackOptions } from './config';
4
+ /**
5
+ * Get a Webpack compiler for the given config.
6
+ *
7
+ * @param config - The config object.
8
+ * @param options - The Webpack options.
9
+ * @returns The Webpack compiler.
10
+ */
11
+ export declare function getCompiler(config: ProcessedWebpackConfig, options?: WebpackOptions): Promise<import("webpack").Compiler>;
12
+ /**
13
+ * Get a static server for development purposes.
14
+ *
15
+ * Note: We're intentionally not using `webpack-dev-server` here because it
16
+ * adds a lot of extra stuff to the output that we don't need, and it's
17
+ * difficult to customize.
18
+ *
19
+ * @param config - The config object.
20
+ * @returns An object with a `listen` method that returns a promise that
21
+ * resolves when the server is listening.
22
+ */
23
+ export declare function getServer(config: ProcessedConfig): {
24
+ listen: (port?: number) => Promise<{
25
+ port: number;
26
+ server: Server;
27
+ close: () => Promise<void>;
28
+ }>;
29
+ };
@@ -0,0 +1,37 @@
1
+ import type { Ora } from 'ora';
2
+ import type { Configuration } from 'webpack';
3
+ import type { ProcessedWebpackConfig } from '../config';
4
+ export declare type WebpackOptions = {
5
+ /**
6
+ * Whether to watch for changes.
7
+ */
8
+ watch?: boolean;
9
+ /**
10
+ * Whether to evaluate the bundle. If this is set, it will override the
11
+ * `evaluate` option in the config object.
12
+ */
13
+ evaluate?: boolean;
14
+ /**
15
+ * The spinner to use for logging.
16
+ */
17
+ spinner?: Ora;
18
+ };
19
+ /**
20
+ * Get the default Webpack configuration. This is the configuration that will
21
+ * be used if the user doesn't provide a custom Webpack configuration. The
22
+ * configuration is based on the snap config.
23
+ *
24
+ * The default configuration includes:
25
+ *
26
+ * - `SWC` to transpile TypeScript and JavaScript files.
27
+ * - `TerserPlugin` to minify the bundle.
28
+ * - `SnapsWebpackPlugin` to validate the bundle and update the manifest.
29
+ *
30
+ * It can be customized through the `customizeWebpackConfig` function in the
31
+ * snap config, but in most cases, you shouldn't need to do that.
32
+ *
33
+ * @param config - The processed snap Webpack config.
34
+ * @param options - The Webpack options.
35
+ * @returns The default Webpack configuration.
36
+ */
37
+ export declare function getDefaultConfiguration(config: ProcessedWebpackConfig, options?: WebpackOptions): Promise<Configuration>;
@@ -0,0 +1,3 @@
1
+ export * from './compiler';
2
+ export * from './config';
3
+ export * from './plugins';
@@ -0,0 +1,16 @@
1
+ import type { LoaderDefinitionFunction } from 'webpack';
2
+ import type { LegacyOptions } from '../../config';
3
+ /**
4
+ * A Browserify loader for Webpack. This exists for backwards compatibility with
5
+ * the legacy configuration format, in order to support the `bundlerCustomizer`
6
+ * function.
7
+ *
8
+ * When this loader is used, the input file will be processed by Browserify, and
9
+ * written to disk by Webpack. Most processing will be handled by Browserify, so
10
+ * there are no benefits like tree-shaking.
11
+ *
12
+ * @param content - The input file contents as a string.
13
+ * @param sourceMap - The source map of the input file.
14
+ */
15
+ declare const loader: LoaderDefinitionFunction<LegacyOptions>;
16
+ export default loader;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * A Webpack loader that inlines the WASM module as a `Uint8Array`. This makes
3
+ * it possible to import the WASM module directly, and use it with the
4
+ * `WebAssembly.instantiate` function.
5
+ *
6
+ * This is useful, because snaps are not allowed to import assets from outside
7
+ * of their package. This loader allows you to inline the WASM module as a
8
+ * `Uint8Array`, which can then be passed to `WebAssembly.instantiate`.
9
+ *
10
+ * @param source - The WASM module as a string.
11
+ * @returns A string that exports the WASM module as a `Uint8Array`.
12
+ * @example
13
+ * ```ts
14
+ * import wasm from './program.wasm';
15
+ *
16
+ * const { instance } = await WebAssembly.instantiate(wasm, {});
17
+ * // Do something with the WASM module...
18
+ * ```
19
+ */
20
+ export default function loader(source: unknown): string;
@@ -0,0 +1,147 @@
1
+ import type { Ora } from 'ora';
2
+ import type { Compiler, ResolvePluginInstance, Resolver, WebpackPluginInstance } from 'webpack';
3
+ export declare type SnapsStatsPluginOptions = {
4
+ /**
5
+ * Whether to log the verbose stats.
6
+ */
7
+ verbose?: boolean;
8
+ };
9
+ /**
10
+ * A plugin that logs the stats after compilation. This is useful for logging
11
+ * the number of files compiled, and the time taken to compile them.
12
+ */
13
+ export declare class SnapsStatsPlugin implements WebpackPluginInstance {
14
+ #private;
15
+ /**
16
+ * The options for the plugin.
17
+ */
18
+ readonly options: SnapsStatsPluginOptions;
19
+ constructor(options?: SnapsStatsPluginOptions, spinner?: Ora);
20
+ /**
21
+ * Apply the plugin to the Webpack compiler.
22
+ *
23
+ * @param compiler - The Webpack compiler.
24
+ */
25
+ apply(compiler: Compiler): void;
26
+ }
27
+ /**
28
+ * The options for the {@link SnapsWatchPlugin}.
29
+ */
30
+ export declare type SnapsWatchPluginOptions = {
31
+ /**
32
+ * The bundle path. This is the file that will be evaluated, if the `evaluate`
33
+ * option is set.
34
+ */
35
+ bundle?: string;
36
+ /**
37
+ * Whether to evaluate the bundle. This only applies if the `bundle` option is
38
+ * set.
39
+ */
40
+ evaluate?: boolean;
41
+ /**
42
+ * The extra files to watch.
43
+ */
44
+ files?: string[];
45
+ };
46
+ /**
47
+ * A plugin that adds extra files to watch. This is useful for watching files
48
+ * that are not imported by the entry point, such as the `snap.manifest.json`
49
+ * file.
50
+ */
51
+ export declare class SnapsWatchPlugin implements WebpackPluginInstance {
52
+ #private;
53
+ /**
54
+ * The options for the plugin.
55
+ */
56
+ readonly options: SnapsWatchPluginOptions;
57
+ constructor(options: SnapsWatchPluginOptions, spinner?: Ora);
58
+ /**
59
+ * Apply the plugin to the Webpack compiler.
60
+ *
61
+ * @param compiler - The Webpack compiler.
62
+ */
63
+ apply(compiler: Compiler): void;
64
+ }
65
+ /**
66
+ * The options for the {@link SnapsBuiltInResolver}.
67
+ */
68
+ export declare type SnapsBuiltInResolverOptions = {
69
+ /**
70
+ * The built-in modules to ignore.
71
+ */
72
+ ignore?: string[];
73
+ };
74
+ /**
75
+ * A plugin that logs a message when a built-in module is not resolved. The
76
+ * MetaMask Snaps CLI does not support built-in modules by default, and this
77
+ * plugin is used to warn the user when they try to import a built-in module,
78
+ * when no fallback is configured.
79
+ */
80
+ export declare class SnapsBuiltInResolver implements ResolvePluginInstance {
81
+ #private;
82
+ /**
83
+ * The built-in modules that have been imported, but not resolved.
84
+ */
85
+ readonly unresolvedModules: Set<string>;
86
+ /**
87
+ * The options for the plugin.
88
+ */
89
+ readonly options: SnapsBuiltInResolverOptions;
90
+ constructor(options?: SnapsBuiltInResolverOptions, spinner?: Ora);
91
+ /**
92
+ * Apply the plugin to the Webpack resolver.
93
+ *
94
+ * @param resolver - The Webpack resolver.
95
+ */
96
+ apply(resolver: Resolver): void;
97
+ }
98
+ /**
99
+ * The options for the {@link SnapsBundleWarningsPlugin}.
100
+ */
101
+ export declare type SnapsBundleWarningsPluginOptions = {
102
+ /**
103
+ * The {@link SnapsBuiltInResolver} instance to use for detecting built-in
104
+ * modules.
105
+ */
106
+ builtInResolver?: SnapsBuiltInResolver | false;
107
+ /**
108
+ * Whether to show warnings if built-in modules are used, but not provided by
109
+ * Webpack's `fallback` configuration.
110
+ */
111
+ builtIns?: boolean;
112
+ /**
113
+ * Whether to show warnings if the `Buffer` global is used, but not provided
114
+ * by Webpack's `DefinePlugin`.
115
+ */
116
+ buffer?: boolean;
117
+ };
118
+ /**
119
+ * A plugin that logs a message when:
120
+ *
121
+ * - A built-in module is not resolved. The MetaMask Snaps CLI does not support
122
+ * built-in modules by default, and this plugin is used to warn the user when
123
+ * they try to import a built-in module, when no fallback is configured.
124
+ * - A snap uses the `Buffer` global. The MetaMask Snaps CLI does not support
125
+ * the `Buffer` global by default, and this plugin is used to warn the user when
126
+ * they try to use the `Buffer` global.
127
+ *
128
+ * We use both a resolver and a plugin, because the resolver is used to detect
129
+ * when a built-in module is imported, and the plugin is used to log a single
130
+ * message when the compilation is complete. We can't do everything in a single
131
+ * plugin, because the resolver doesn't have access to the compilation, and the
132
+ * plugin doesn't have access to the resolver.
133
+ */
134
+ export declare class SnapsBundleWarningsPlugin implements WebpackPluginInstance {
135
+ #private;
136
+ /**
137
+ * The options for the plugin.
138
+ */
139
+ readonly options: SnapsBundleWarningsPluginOptions;
140
+ constructor(options?: SnapsBundleWarningsPluginOptions, spinner?: Ora);
141
+ /**
142
+ * Apply the plugin to the Webpack compiler.
143
+ *
144
+ * @param compiler - The Webpack compiler.
145
+ */
146
+ apply(compiler: Compiler): void;
147
+ }
@@ -0,0 +1,156 @@
1
+ /// <reference types="browserify" />
2
+ import type { Ora } from 'ora';
3
+ import type { Configuration } from 'webpack';
4
+ import type { ProcessedWebpackConfig } from '../config';
5
+ export declare const BROWSERSLIST_FILE: string;
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
+ */
22
+ export declare function getDefaultLoader({ legacy, sourceMap, }: ProcessedWebpackConfig): Promise<{
23
+ /**
24
+ * If the snap uses the legacy config, we use the custom `browserify`
25
+ * loader. This uses the legacy Browserify config to transpile the code.
26
+ * This is necessary for backwards compatibility with the
27
+ * `bundlerCustomizer` function.
28
+ */
29
+ loader: string;
30
+ /**
31
+ * The options for the `browserify` loader. These can be overridden in the
32
+ * snap config.
33
+ */
34
+ options: {
35
+ transpilationMode: import("../builders").TranspilationModes.LocalAndDeps;
36
+ depsToTranspile: string[];
37
+ writeManifest: boolean;
38
+ bundlerCustomizer?: ((bundler: import("browserify").BrowserifyObject) => void) | undefined;
39
+ } | {
40
+ transpilationMode: import("../builders").TranspilationModes.LocalOnly | import("../builders").TranspilationModes.None;
41
+ depsToTranspile: unknown[];
42
+ writeManifest: boolean;
43
+ bundlerCustomizer?: ((bundler: import("browserify").BrowserifyObject) => void) | undefined;
44
+ };
45
+ } | {
46
+ /**
47
+ * We use the `swc-loader` to transpile TypeScript and JavaScript files.
48
+ * This is a Webpack loader that uses the `SWC` compiler, which is a much
49
+ * faster alternative to Babel and TypeScript's own compiler.
50
+ */
51
+ loader: string;
52
+ /**
53
+ * The options for the `swc-loader`. These can be overridden in the
54
+ * `.swcrc` file.
55
+ *
56
+ * @see https://swc.rs/docs/configuration/swcrc
57
+ */
58
+ options: {
59
+ sync: boolean;
60
+ /**
61
+ * This tells SWC to generate source maps. We set it to the
62
+ * `sourceMap` value from the config object.
63
+ *
64
+ * This must be enabled if source maps are enabled in the config.
65
+ */
66
+ sourceMaps: boolean;
67
+ jsc: {
68
+ /**
69
+ * MetaMask targets ES2020, so we set the target to ES2020. This
70
+ * ensures that the code is transpiled to ES2020, and that the
71
+ * necessary polyfills are added.
72
+ *
73
+ * @see https://swc.rs/docs/configuration/compilation#jsctarget
74
+ */
75
+ target: string;
76
+ parser: {
77
+ /**
78
+ * This tells the parser to parse TypeScript files. If you
79
+ * don't need to support TypeScript, you can set this to
80
+ * `ecmascript` instead, but there's no harm in leaving it
81
+ * as `typescript`.
82
+ *
83
+ * @see https://swc.rs/docs/configuration/compilation#jscparser
84
+ */
85
+ syntax: string;
86
+ };
87
+ };
88
+ /**
89
+ * The module configuration. This tells SWC how to output the
90
+ * transpiled code.
91
+ *
92
+ * @see https://swc.rs/docs/configuration/modules
93
+ */
94
+ module: {
95
+ /**
96
+ * This tells SWC to output CommonJS modules. MetaMask Snaps
97
+ * doesn't support ES modules yet, so this is necessary.
98
+ *
99
+ * @see https://swc.rs/docs/configuration/modules#commonjs
100
+ */
101
+ type: string;
102
+ };
103
+ env: {
104
+ targets: string;
105
+ };
106
+ };
107
+ }>;
108
+ /**
109
+ * Get the Webpack devtool configuration based on the given snap config.
110
+ *
111
+ * - If `sourceMap` is `inline`, return `inline-source-map`.
112
+ * - If `sourceMap` is `true`, return `source-map`.
113
+ * - Otherwise, return `false`.
114
+ *
115
+ * @param sourceMap - The `sourceMap` value from the snap config.
116
+ * @returns The Webpack devtool configuration.
117
+ */
118
+ export declare function getDevTool(sourceMap: ProcessedWebpackConfig['sourceMap']): Configuration['devtool'];
119
+ /**
120
+ * Get a function that can be used as handler function for Webpack's
121
+ * `ProgressPlugin`.
122
+ *
123
+ * @param spinner - The spinner to update.
124
+ * @param spinnerText - The initial spinner text. This will be prepended to the
125
+ * percentage.
126
+ * @returns A function that can be used as handler function for Webpack's
127
+ * `ProgressPlugin`.
128
+ */
129
+ export declare function getProgressHandler(spinner?: Ora, spinnerText?: string): (percentage: number) => void;
130
+ /**
131
+ * Get the targets from the `.browserslistrc` file.
132
+ *
133
+ * @returns The browser targets as an array of strings.
134
+ */
135
+ export declare function getBrowserslistTargets(): Promise<string[]>;
136
+ /**
137
+ * Get a singular or plural string based on the given count. This is useful for
138
+ * generating messages like "1 error" or "2 errors". By default, the plural
139
+ * string is the singular string with an "s" appended to it.
140
+ *
141
+ * This assumes that the text is in English, and likely won't work for some
142
+ * other languages.
143
+ *
144
+ * @param count - The count.
145
+ * @param singular - The singular string.
146
+ * @param plural - The plural string.
147
+ * @returns The singular or plural string.
148
+ * @example
149
+ * ```typescript
150
+ * pluralize(1, 'error'); // => 'error'
151
+ * pluralize(2, 'error'); // => 'errors'
152
+ * pluralize(1, 'error', 'problem'); // => 'error'
153
+ * pluralize(2, 'error', 'problems'); // => 'problems'
154
+ * ```
155
+ */
156
+ export declare function pluralize(count: number, singular: string, plural?: string): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/snaps-cli",
3
- "version": "0.37.0-flask.1",
3
+ "version": "0.38.0-flask.1",
4
4
  "description": "A CLI for developing MetaMask Snaps.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -17,7 +17,8 @@
17
17
  "files": [
18
18
  "dist/cjs/**",
19
19
  "dist/esm/**",
20
- "dist/types/**"
20
+ "dist/types/**",
21
+ ".browserslistrc"
21
22
  ],
22
23
  "scripts": {
23
24
  "build": "yarn build:source && yarn build:types",
@@ -35,7 +36,7 @@
35
36
  "posttest": "jest-it-up",
36
37
  "test:watch": "yarn test --watch",
37
38
  "test:ci": "yarn test",
38
- "lint:changelog": "yarn auto-changelog validate",
39
+ "lint:changelog": "../../scripts/validate-changelog.sh @metamask/snaps-cli",
39
40
  "lint:eslint": "eslint . --cache --ext js,ts,jsx,tsx",
40
41
  "lint:misc": "prettier --no-error-on-unmatched-pattern --loglevel warn \"**/*.json\" \"**/*.md\" \"**/*.html\" \"!CHANGELOG.md\" --ignore-path ../../.gitignore",
41
42
  "lint": "yarn lint:eslint && yarn lint:misc --check && yarn lint:changelog",
@@ -53,16 +54,25 @@
53
54
  "@babel/plugin-transform-runtime": "^7.16.7",
54
55
  "@babel/preset-env": "^7.20.12",
55
56
  "@babel/preset-typescript": "^7.20.12",
56
- "@metamask/snaps-browserify-plugin": "^0.37.0-flask.1",
57
- "@metamask/snaps-utils": "^0.37.0-flask.1",
57
+ "@metamask/snaps-browserify-plugin": "^0.37.2-flask.1",
58
+ "@metamask/snaps-utils": "^0.37.2-flask.1",
59
+ "@metamask/snaps-webpack-plugin": "^0.37.2-flask.1",
58
60
  "@metamask/utils": "^6.0.1",
61
+ "@swc/core": "^1.3.66",
59
62
  "babelify": "^10.0.0",
60
63
  "browserify": "^17.0.0",
64
+ "chalk": "^4.1.2",
61
65
  "chokidar": "^3.5.2",
62
66
  "is-url": "^1.2.4",
67
+ "ora": "^5.4.1",
63
68
  "serve-handler": "^6.1.5",
64
69
  "ses": "^0.18.1",
65
70
  "superstruct": "^1.0.3",
71
+ "swc-loader": "^0.2.3",
72
+ "terser-webpack-plugin": "^5.3.9",
73
+ "webpack": "^5.88.0",
74
+ "webpack-dev-server": "^4.15.1",
75
+ "webpack-merge": "^5.9.0",
66
76
  "yargs": "^17.7.1",
67
77
  "yargs-parser": "^20.2.2"
68
78
  },
@@ -74,7 +84,6 @@
74
84
  "@metamask/eslint-config-nodejs": "^12.1.0",
75
85
  "@metamask/eslint-config-typescript": "^12.1.0",
76
86
  "@swc/cli": "^0.1.62",
77
- "@swc/core": "^1.3.66",
78
87
  "@swc/jest": "^0.2.26",
79
88
  "@types/browserify": "^12.0.37",
80
89
  "@types/is-url": "^1.2.28",
@@ -86,7 +95,6 @@
86
95
  "@typescript-eslint/eslint-plugin": "^5.42.1",
87
96
  "@typescript-eslint/parser": "^5.42.1",
88
97
  "babel-jest": "^29.5.0",
89
- "clet": "^1.0.1",
90
98
  "cross-fetch": "^3.1.5",
91
99
  "deepmerge": "^4.2.2",
92
100
  "eslint": "^8.27.0",
@@ -1,36 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "build", {
6
- enumerable: true,
7
- get: function() {
8
- return build;
9
- }
10
- });
11
- const _snapsutils = require("@metamask/snaps-utils");
12
- const _utils = require("../../utils");
13
- const _evalHandler = require("../eval/evalHandler");
14
- const _manifestHandler = require("../manifest/manifestHandler");
15
- const _bundle = require("./bundle");
16
- async function build(argv) {
17
- const { src, dist, outfileName } = argv;
18
- if (outfileName) {
19
- (0, _snapsutils.validateOutfileName)(outfileName);
20
- }
21
- await (0, _snapsutils.validateFilePath)(src);
22
- await (0, _snapsutils.validateDirPath)(dist, true);
23
- const outfilePath = (0, _snapsutils.getOutfilePath)(dist, outfileName);
24
- const result = await (0, _bundle.bundle)(src, outfilePath, argv, (0, _utils.loadConfig)().bundlerCustomizer);
25
- if (result && argv.eval) {
26
- await (0, _evalHandler.evalHandler)({
27
- ...argv,
28
- bundle: outfilePath
29
- });
30
- }
31
- if (argv.manifest) {
32
- await (0, _manifestHandler.manifestHandler)(argv);
33
- }
34
- }
35
-
36
- //# sourceMappingURL=buildHandler.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/cmds/build/buildHandler.ts"],"sourcesContent":["import {\n getOutfilePath,\n validateDirPath,\n validateFilePath,\n validateOutfileName,\n} from '@metamask/snaps-utils';\n\nimport type { YargsArgs } from '../../types/yargs';\nimport { loadConfig } from '../../utils';\nimport { evalHandler } from '../eval/evalHandler';\nimport { manifestHandler } from '../manifest/manifestHandler';\nimport { bundle } from './bundle';\n\n/**\n * Builds all files in the given source directory to the given destination\n * directory.\n *\n * Creates destination directory if it doesn't exist.\n *\n * @param argv - Argv from Yargs.\n * @param argv.src - The source file path.\n * @param argv.dist - The output directory path.\n * @param argv.outfileName - The output file name.\n */\nexport async function build(argv: YargsArgs): Promise<void> {\n const { src, dist, outfileName } = argv;\n if (outfileName) {\n validateOutfileName(outfileName);\n }\n await validateFilePath(src);\n await validateDirPath(dist, true);\n\n const outfilePath = getOutfilePath(dist, outfileName);\n const result = await bundle(\n src,\n outfilePath,\n argv,\n loadConfig().bundlerCustomizer,\n );\n if (result && argv.eval) {\n await evalHandler({ ...argv, bundle: outfilePath });\n }\n\n if (argv.manifest) {\n await manifestHandler(argv);\n }\n}\n"],"names":["build","argv","src","dist","outfileName","validateOutfileName","validateFilePath","validateDirPath","outfilePath","getOutfilePath","result","bundle","loadConfig","bundlerCustomizer","eval","evalHandler","manifest","manifestHandler"],"mappings":";;;;+BAwBsBA;;;eAAAA;;;4BAnBf;uBAGoB;6BACC;iCACI;wBACT;AAahB,eAAeA,MAAMC,IAAe;IACzC,MAAM,EAAEC,GAAG,EAAEC,IAAI,EAAEC,WAAW,EAAE,GAAGH;IACnC,IAAIG,aAAa;QACfC,IAAAA,+BAAmB,EAACD;IACtB;IACA,MAAME,IAAAA,4BAAgB,EAACJ;IACvB,MAAMK,IAAAA,2BAAe,EAACJ,MAAM;IAE5B,MAAMK,cAAcC,IAAAA,0BAAc,EAACN,MAAMC;IACzC,MAAMM,SAAS,MAAMC,IAAAA,cAAM,EACzBT,KACAM,aACAP,MACAW,IAAAA,iBAAU,IAAGC,iBAAiB;IAEhC,IAAIH,UAAUT,KAAKa,IAAI,EAAE;QACvB,MAAMC,IAAAA,wBAAW,EAAC;YAAE,GAAGd,IAAI;YAAEU,QAAQH;QAAY;IACnD;IAEA,IAAIP,KAAKe,QAAQ,EAAE;QACjB,MAAMC,IAAAA,gCAAe,EAAChB;IACxB;AACF"}