@metamask/snaps-cli 1.0.2 → 2.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/.browserslistrc +3 -0
  2. package/CHANGELOG.md +32 -377
  3. package/README.md +548 -69
  4. package/dist/cjs/builders.js +148 -0
  5. package/dist/cjs/builders.js.map +1 -0
  6. package/dist/cjs/cli.js +35 -0
  7. package/dist/cjs/cli.js.map +1 -0
  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/commands/build/index.js +45 -0
  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 +30 -0
  21. package/dist/cjs/commands/index.js.map +1 -0
  22. package/dist/cjs/commands/manifest/implementation.js +34 -0
  23. package/dist/cjs/commands/manifest/implementation.js.map +1 -0
  24. package/dist/cjs/commands/manifest/index.js +50 -0
  25. package/dist/cjs/commands/manifest/index.js.map +1 -0
  26. package/dist/cjs/commands/manifest/manifest.js +55 -0
  27. package/dist/cjs/commands/manifest/manifest.js.map +1 -0
  28. package/dist/cjs/commands/serve/index.js +33 -0
  29. package/dist/cjs/commands/serve/index.js.map +1 -0
  30. package/dist/cjs/commands/serve/serve.js +21 -0
  31. package/dist/cjs/commands/serve/serve.js.map +1 -0
  32. package/dist/cjs/commands/watch/implementation.js +35 -0
  33. package/dist/cjs/commands/watch/implementation.js.map +1 -0
  34. package/dist/cjs/commands/watch/index.js +47 -0
  35. package/dist/cjs/commands/watch/index.js.map +1 -0
  36. package/dist/cjs/commands/watch/watch.js +51 -0
  37. package/dist/cjs/commands/watch/watch.js.map +1 -0
  38. package/dist/cjs/config.js +323 -0
  39. package/dist/cjs/config.js.map +1 -0
  40. package/dist/cjs/errors.js +37 -0
  41. package/dist/cjs/errors.js.map +1 -0
  42. package/dist/cjs/index.js +77 -0
  43. package/dist/cjs/index.js.map +1 -0
  44. package/dist/cjs/main.js +19 -0
  45. package/dist/cjs/main.js.map +1 -0
  46. package/dist/cjs/utils/cli.js +61 -0
  47. package/dist/cjs/utils/cli.js.map +1 -0
  48. package/dist/cjs/utils/errors.js +42 -0
  49. package/dist/cjs/utils/errors.js.map +1 -0
  50. package/dist/cjs/utils/index.js +25 -0
  51. package/dist/cjs/utils/index.js.map +1 -0
  52. package/dist/cjs/utils/legacy.js +48 -0
  53. package/dist/cjs/utils/legacy.js.map +1 -0
  54. package/dist/cjs/utils/logging.js +46 -0
  55. package/dist/cjs/utils/logging.js.map +1 -0
  56. package/dist/cjs/utils/path.js +16 -0
  57. package/dist/cjs/utils/path.js.map +1 -0
  58. package/dist/cjs/utils/steps.js +52 -0
  59. package/dist/cjs/utils/steps.js.map +1 -0
  60. package/dist/cjs/webpack/compiler.js +96 -0
  61. package/dist/cjs/webpack/compiler.js.map +1 -0
  62. package/dist/cjs/webpack/config.js +239 -0
  63. package/dist/cjs/webpack/config.js.map +1 -0
  64. package/dist/cjs/webpack/index.js +22 -0
  65. package/dist/cjs/webpack/index.js.map +1 -0
  66. package/dist/cjs/webpack/loaders/browserify.js +97 -0
  67. package/dist/cjs/webpack/loaders/browserify.js.map +1 -0
  68. package/dist/cjs/webpack/loaders/wasm.js +36 -0
  69. package/dist/cjs/webpack/loaders/wasm.js.map +1 -0
  70. package/dist/cjs/webpack/plugins.js +340 -0
  71. package/dist/cjs/webpack/plugins.js.map +1 -0
  72. package/dist/cjs/webpack/utils.js +181 -0
  73. package/dist/cjs/webpack/utils.js.map +1 -0
  74. package/dist/{builders.js → esm/builders.js} +48 -51
  75. package/dist/esm/builders.js.map +1 -0
  76. package/dist/esm/cli.js +26 -0
  77. package/dist/esm/cli.js.map +1 -0
  78. package/dist/esm/commands/build/build.js +51 -0
  79. package/dist/esm/commands/build/build.js.map +1 -0
  80. package/dist/esm/commands/build/implementation.js +27 -0
  81. package/dist/esm/commands/build/implementation.js.map +1 -0
  82. package/dist/esm/commands/build/index.js +17 -0
  83. package/dist/esm/commands/build/index.js.map +1 -0
  84. package/dist/esm/commands/eval/eval.js +54 -0
  85. package/dist/esm/commands/eval/eval.js.map +1 -0
  86. package/dist/esm/commands/eval/implementation.js +24 -0
  87. package/dist/esm/commands/eval/implementation.js.map +1 -0
  88. package/dist/esm/commands/eval/index.js +22 -0
  89. package/dist/esm/commands/eval/index.js.map +1 -0
  90. package/dist/esm/commands/index.js +15 -0
  91. package/dist/esm/commands/index.js.map +1 -0
  92. package/dist/esm/commands/manifest/implementation.js +33 -0
  93. package/dist/esm/commands/manifest/implementation.js.map +1 -0
  94. package/dist/esm/commands/manifest/index.js +22 -0
  95. package/dist/esm/commands/manifest/index.js.map +1 -0
  96. package/dist/esm/commands/manifest/manifest.js +52 -0
  97. package/dist/esm/commands/manifest/manifest.js.map +1 -0
  98. package/dist/esm/commands/serve/index.js +18 -0
  99. package/dist/esm/commands/serve/index.js.map +1 -0
  100. package/dist/esm/commands/serve/serve.js +17 -0
  101. package/dist/esm/commands/serve/serve.js.map +1 -0
  102. package/dist/esm/commands/watch/implementation.js +34 -0
  103. package/dist/esm/commands/watch/implementation.js.map +1 -0
  104. package/dist/esm/commands/watch/index.js +19 -0
  105. package/dist/esm/commands/watch/index.js.map +1 -0
  106. package/dist/esm/commands/watch/watch.js +50 -0
  107. package/dist/esm/commands/watch/watch.js.map +1 -0
  108. package/dist/esm/config.js +327 -0
  109. package/dist/esm/config.js.map +1 -0
  110. package/dist/esm/errors.js +30 -0
  111. package/dist/esm/errors.js.map +1 -0
  112. package/dist/esm/index.js +6 -0
  113. package/dist/esm/index.js.map +1 -0
  114. package/dist/esm/main.js +10 -0
  115. package/dist/esm/main.js.map +1 -0
  116. package/dist/esm/utils/cli.js +43 -0
  117. package/dist/esm/utils/cli.js.map +1 -0
  118. package/dist/esm/utils/errors.js +43 -0
  119. package/dist/esm/utils/errors.js.map +1 -0
  120. package/dist/esm/utils/index.js +8 -0
  121. package/dist/esm/utils/index.js.map +1 -0
  122. package/dist/esm/utils/legacy.js +47 -0
  123. package/dist/esm/utils/legacy.js.map +1 -0
  124. package/dist/esm/utils/logging.js +40 -0
  125. package/dist/esm/utils/logging.js.map +1 -0
  126. package/dist/esm/utils/path.js +13 -0
  127. package/dist/esm/utils/path.js.map +1 -0
  128. package/dist/esm/utils/steps.js +43 -0
  129. package/dist/esm/utils/steps.js.map +1 -0
  130. package/dist/esm/webpack/compiler.js +89 -0
  131. package/dist/esm/webpack/compiler.js.map +1 -0
  132. package/dist/esm/webpack/config.js +241 -0
  133. package/dist/esm/webpack/config.js.map +1 -0
  134. package/dist/esm/webpack/index.js +5 -0
  135. package/dist/esm/webpack/index.js.map +1 -0
  136. package/dist/esm/webpack/loaders/browserify.js +82 -0
  137. package/dist/esm/webpack/loaders/browserify.js.map +1 -0
  138. package/dist/esm/webpack/loaders/wasm.js +26 -0
  139. package/dist/esm/webpack/loaders/wasm.js.map +1 -0
  140. package/dist/esm/webpack/plugins.js +343 -0
  141. package/dist/esm/webpack/plugins.js.map +1 -0
  142. package/dist/esm/webpack/utils.js +208 -0
  143. package/dist/esm/webpack/utils.js.map +1 -0
  144. package/dist/types/__fixtures__/configs/cjs.d.ts +1 -0
  145. package/dist/types/__fixtures__/configs/esm.d.ts +3 -0
  146. package/dist/types/__fixtures__/configs/invalid.d.ts +3 -0
  147. package/dist/types/__fixtures__/configs/javascript/snap.config.d.ts +0 -0
  148. package/dist/types/__fixtures__/configs/typescript/snap.config.d.ts +3 -0
  149. package/dist/types/builders.d.ts +8 -0
  150. package/dist/{cli.d.ts → types/cli.d.ts} +1 -1
  151. package/dist/types/commands/build/build.d.ts +10 -0
  152. package/dist/types/commands/build/implementation.d.ts +10 -0
  153. package/dist/types/commands/build/index.d.ts +10 -0
  154. package/dist/types/commands/eval/__test__/browserify/bad/snap.config.d.ts +3 -0
  155. package/dist/types/commands/eval/__test__/browserify/good/snap.config.d.ts +3 -0
  156. package/dist/types/commands/eval/__test__/webpack/bad/snap.config.d.ts +3 -0
  157. package/dist/types/commands/eval/__test__/webpack/good/snap.config.d.ts +3 -0
  158. package/dist/types/commands/eval/__test__/webpack/snap.config.d.ts +3 -0
  159. package/dist/types/commands/eval/eval.d.ts +14 -0
  160. package/dist/types/commands/eval/implementation.d.ts +9 -0
  161. package/dist/types/commands/eval/index.d.ts +10 -0
  162. package/dist/types/commands/manifest/implementation.d.ts +12 -0
  163. package/dist/types/commands/manifest/index.d.ts +10 -0
  164. package/dist/types/commands/manifest/manifest.d.ts +14 -0
  165. package/dist/{cmds/build → types/commands/serve}/index.d.ts +4 -4
  166. package/dist/types/commands/serve/serve.d.ts +16 -0
  167. package/dist/types/commands/watch/implementation.d.ts +14 -0
  168. package/dist/types/commands/watch/index.d.ts +10 -0
  169. package/dist/types/commands/watch/watch.d.ts +19 -0
  170. package/dist/types/config.d.ts +792 -0
  171. package/dist/types/errors.d.ts +25 -0
  172. package/dist/types/index.d.ts +5 -0
  173. package/dist/types/utils/cli.d.ts +17 -0
  174. package/dist/types/utils/errors.d.ts +23 -0
  175. package/dist/types/utils/index.d.ts +6 -0
  176. package/dist/types/utils/legacy.d.ts +27 -0
  177. package/dist/types/utils/logging.d.ts +22 -0
  178. package/dist/types/utils/path.d.ts +9 -0
  179. package/dist/types/utils/steps.d.ts +17 -0
  180. package/dist/types/webpack/compiler.d.ts +29 -0
  181. package/dist/types/webpack/config.d.ts +37 -0
  182. package/dist/types/webpack/index.d.ts +3 -0
  183. package/dist/types/webpack/loaders/browserify.d.ts +16 -0
  184. package/dist/types/webpack/loaders/wasm.d.ts +20 -0
  185. package/dist/types/webpack/plugins.d.ts +147 -0
  186. package/dist/types/webpack/utils.d.ts +188 -0
  187. package/package.json +83 -43
  188. package/dist/builders.d.ts +0 -27
  189. package/dist/builders.js.map +0 -1
  190. package/dist/cli.js +0 -51
  191. package/dist/cli.js.map +0 -1
  192. package/dist/cmds/build/buildHandler.d.ts +0 -13
  193. package/dist/cmds/build/buildHandler.js +0 -37
  194. package/dist/cmds/build/buildHandler.js.map +0 -1
  195. package/dist/cmds/build/bundle.d.ts +0 -15
  196. package/dist/cmds/build/bundle.js +0 -80
  197. package/dist/cmds/build/bundle.js.map +0 -1
  198. package/dist/cmds/build/index.js +0 -29
  199. package/dist/cmds/build/index.js.map +0 -1
  200. package/dist/cmds/build/utils.d.ts +0 -56
  201. package/dist/cmds/build/utils.js +0 -100
  202. package/dist/cmds/build/utils.js.map +0 -1
  203. package/dist/cmds/eval/evalHandler.d.ts +0 -9
  204. package/dist/cmds/eval/evalHandler.js +0 -25
  205. package/dist/cmds/eval/evalHandler.js.map +0 -1
  206. package/dist/cmds/eval/index.d.ts +0 -9
  207. package/dist/cmds/eval/index.js +0 -15
  208. package/dist/cmds/eval/index.js.map +0 -1
  209. package/dist/cmds/index.js +0 -14
  210. package/dist/cmds/index.js.map +0 -1
  211. package/dist/cmds/init/index.d.ts +0 -9
  212. package/dist/cmds/init/index.js +0 -34
  213. package/dist/cmds/init/index.js.map +0 -1
  214. package/dist/cmds/init/initHandler.d.ts +0 -26
  215. package/dist/cmds/init/initHandler.js +0 -69
  216. package/dist/cmds/init/initHandler.js.map +0 -1
  217. package/dist/cmds/init/initUtils.d.ts +0 -39
  218. package/dist/cmds/init/initUtils.js +0 -122
  219. package/dist/cmds/init/initUtils.js.map +0 -1
  220. package/dist/cmds/manifest/index.d.ts +0 -9
  221. package/dist/cmds/manifest/index.js +0 -24
  222. package/dist/cmds/manifest/index.js.map +0 -1
  223. package/dist/cmds/manifest/manifestHandler.d.ts +0 -10
  224. package/dist/cmds/manifest/manifestHandler.js +0 -50
  225. package/dist/cmds/manifest/manifestHandler.js.map +0 -1
  226. package/dist/cmds/serve/index.d.ts +0 -9
  227. package/dist/cmds/serve/index.js +0 -15
  228. package/dist/cmds/serve/index.js.map +0 -1
  229. package/dist/cmds/serve/serveHandler.d.ts +0 -10
  230. package/dist/cmds/serve/serveHandler.js +0 -59
  231. package/dist/cmds/serve/serveHandler.js.map +0 -1
  232. package/dist/cmds/serve/serveUtils.d.ts +0 -22
  233. package/dist/cmds/serve/serveUtils.js +0 -39
  234. package/dist/cmds/serve/serveUtils.js.map +0 -1
  235. package/dist/cmds/watch/index.d.ts +0 -9
  236. package/dist/cmds/watch/index.js +0 -32
  237. package/dist/cmds/watch/index.js.map +0 -1
  238. package/dist/cmds/watch/watchHandler.d.ts +0 -14
  239. package/dist/cmds/watch/watchHandler.js +0 -100
  240. package/dist/cmds/watch/watchHandler.js.map +0 -1
  241. package/dist/main.js +0 -15
  242. package/dist/main.js.map +0 -1
  243. package/dist/utils/index.d.ts +0 -2
  244. package/dist/utils/index.js +0 -19
  245. package/dist/utils/index.js.map +0 -1
  246. package/dist/utils/misc.d.ts +0 -53
  247. package/dist/utils/misc.js +0 -156
  248. package/dist/utils/misc.js.map +0 -1
  249. package/dist/utils/snap-config.d.ts +0 -48
  250. package/dist/utils/snap-config.js +0 -117
  251. package/dist/utils/snap-config.js.map +0 -1
  252. /package/dist/{cmds → types/commands}/index.d.ts +0 -0
  253. /package/dist/{main.d.ts → types/main.d.ts} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/webpack/config.ts"],"sourcesContent":["import SnapsWebpackPlugin from '@metamask/snaps-webpack-plugin';\nimport type { Ora } from 'ora';\nimport { resolve } from 'path';\nimport TerserPlugin from 'terser-webpack-plugin';\nimport type { Configuration } from 'webpack';\nimport { EnvironmentPlugin, ProgressPlugin, ProvidePlugin } from 'webpack';\n\nimport type { ProcessedWebpackConfig } from '../config';\nimport {\n SnapsBuiltInResolver,\n SnapsBundleWarningsPlugin,\n SnapsStatsPlugin,\n SnapsWatchPlugin,\n} from './plugins';\nimport {\n BROWSERSLIST_FILE,\n getDefaultLoader,\n getDevTool,\n getFallbacks,\n getProgressHandler,\n} from './utils';\n\nexport type WebpackOptions = {\n /**\n * Whether to watch for changes.\n */\n watch?: boolean;\n\n /**\n * Whether to evaluate the bundle. If this is set, it will override the\n * `evaluate` option in the config object.\n */\n evaluate?: boolean;\n\n /**\n * The spinner to use for logging.\n */\n spinner?: Ora;\n};\n\n/**\n * Get the default Webpack configuration. This is the configuration that will\n * be used if the user doesn't provide a custom Webpack configuration. The\n * configuration is based on the snap config.\n *\n * The default configuration includes:\n *\n * - `SWC` to transpile TypeScript and JavaScript files.\n * - `TerserPlugin` to minify the bundle.\n * - `SnapsWebpackPlugin` to validate the bundle and update the manifest.\n *\n * It can be customized through the `customizeWebpackConfig` function in the\n * snap config, but in most cases, you shouldn't need to do that.\n *\n * @param config - The processed snap Webpack config.\n * @param options - The Webpack options.\n * @returns The default Webpack configuration.\n */\nexport async function getDefaultConfiguration(\n config: ProcessedWebpackConfig,\n options: WebpackOptions = {\n evaluate: config.evaluate,\n },\n): Promise<Configuration> {\n const spinnerText = options.spinner?.text;\n const builtInResolver =\n config.stats.builtIns &&\n new SnapsBuiltInResolver(config.stats.builtIns, options.spinner);\n\n return {\n /**\n * The target is set to `browserslist` so that Webpack will compile the\n * bundle to support the browsers specified in the `.browserslistrc` file.\n * This Browserslist file contains the browsers that are supported by\n * MetaMask Snaps.\n *\n * @see https://webpack.js.org/configuration/target/\n */\n target: `browserslist:${BROWSERSLIST_FILE}`,\n\n /**\n * The mode is set to `production` by default, so that Webpack will minify\n * and optimize the bundle.\n *\n * @see https://webpack.js.org/configuration/mode/\n */\n mode: 'production',\n\n /**\n * The entry point is set to the `input` value from the config object.\n *\n * @see https://webpack.js.org/configuration/entry-context/\n */\n entry: config.input,\n\n /**\n * The devtool option controls how source maps are generated. We set it to\n * the `sourceMap` value from the config object.\n *\n * @see https://webpack.js.org/configuration/devtool/\n */\n devtool: getDevTool(config.sourceMap),\n\n /**\n * The stats option controls how much information is printed to the console\n * when Webpack is running. We set it to `none` so that we can control the\n * output ourselves.\n *\n * @see https://webpack.js.org/configuration/stats/\n */\n stats: 'none',\n\n /**\n * The output options.\n *\n * @see https://webpack.js.org/configuration/output/\n */\n output: {\n /**\n * This indicates whether Webpack should clear the output directory\n * before building. We set it to the `clean` value from the config\n * object.\n *\n * @see https://webpack.js.org/configuration/output/#outputclean\n */\n clean: config.output.clean,\n\n /**\n * The filename of the bundle. We set it to the `filename` value from\n * the config object.\n *\n * @see https://webpack.js.org/configuration/output/#outputfilename\n */\n filename: config.output.filename,\n\n /**\n * The path to the output directory. We set it to the `path` value from\n * the config object.\n *\n * @see https://webpack.js.org/configuration/output/#outputpath\n */\n path: config.output.path,\n\n /**\n * The public path of the bundle. We set it to `/` by default, so that\n * the bundle can be loaded from the root of the server.\n *\n * @see https://webpack.js.org/configuration/output/#outputpublicpath\n */\n publicPath: '/',\n\n /**\n * The library configuration. This tells Webpack how to export the\n * bundle.\n *\n * @see https://webpack.js.org/configuration/output/#outputlibrary\n */\n library: {\n /**\n * This tells Webpack to export the bundle as a CommonJS module. This\n * is necessary for MetaMask Snaps.\n *\n * @see https://webpack.js.org/configuration/output/#outputlibrarytarget\n */\n type: 'commonjs',\n },\n },\n\n /**\n * The module configuration. This is where we tell Webpack how to handle\n * different types of files.\n *\n * @see https://webpack.js.org/configuration/module/\n */\n module: {\n rules: [\n {\n test: /\\.[tj]sx?$/u,\n exclude: /node_modules/u,\n use: await getDefaultLoader(config),\n },\n\n config.experimental.wasm && {\n test: /\\.wasm$/u,\n use: {\n loader: resolve(__dirname, 'loaders', 'wasm'),\n },\n },\n ],\n },\n\n /**\n * The resolve configuration. This tells Webpack how to resolve imports.\n * We set it to resolve `.js` and `.ts` files.\n *\n * @see https://webpack.js.org/configuration/resolve/\n */\n resolve: {\n /**\n * The extensions to resolve. We set it to resolve `.js` and `.ts`\n * files.\n */\n extensions: ['.js', '.ts'],\n\n /**\n * The fallback options. This tells Webpack how to handle imports that\n * aren't resolved. By default, we set Node.js built-ins to `false`, so\n * that they are ignored.\n */\n fallback: getFallbacks(config.polyfills),\n\n /**\n * The plugins to use. We use the {@link SnapsBuiltInResolver} to show\n * warnings about using Node.js built-ins, when no fallback is specified.\n */\n plugins: [builtInResolver],\n },\n\n /**\n * The plugins to use.\n *\n * @see https://webpack.js.org/configuration/plugins/\n */\n plugins: [\n /**\n * The `SnapsWebpackPlugin` is a Webpack plugin that checks and updates\n * the manifest file, and evaluates the bundle in SES. While not strictly\n * required, it's highly recommended to use this plugin.\n */\n new SnapsWebpackPlugin({\n manifestPath: config.manifest.path,\n writeManifest: config.manifest.update,\n eval: !options.watch && options.evaluate,\n }),\n\n /**\n * The `SnapsStatsPlugin` is a Webpack plugin that handles the stats\n * output. It's used to show the stats in the terminal, in a format that\n * is easy to read.\n */\n new SnapsStatsPlugin({ verbose: config.stats.verbose }, options.spinner),\n\n /**\n * The `EnvironmentPlugin` is a Webpack plugin that adds environment\n * variables to the bundle. We use it to add the `NODE_ENV` and `DEBUG`\n * environment variables.\n */\n new EnvironmentPlugin(config.environment),\n\n /**\n * The `ProgressPlugin` is a Webpack plugin that logs the progress of\n * the build. We set it to log the progress to the spinner.\n */\n new ProgressPlugin({\n handler: getProgressHandler(options.spinner, spinnerText),\n }),\n\n /**\n * The `SnapsBundleWarningPlugin` is a Webpack plugin that shows a\n * warning when the bundle is potentially incompatible with MetaMask\n * Snaps.\n */\n new SnapsBundleWarningsPlugin(\n {\n builtInResolver,\n builtIns: Boolean(config.stats.builtIns),\n buffer: config.stats.buffer,\n },\n options.spinner,\n ),\n\n /**\n * The `WatchPlugin` is a Webpack plugin that adds extra files to watch\n * for changes. This is useful for rebuilding the bundle when the\n * manifest file changes.\n */\n options.watch &&\n new SnapsWatchPlugin(\n {\n bundle: resolve(config.output.path, config.output.filename),\n evaluate: options.evaluate,\n files: [config.manifest.path],\n },\n options.spinner,\n ),\n\n /**\n * The `ProviderPlugin` is a Webpack plugin that automatically load\n * modules instead of having to import or require them everywhere.\n */\n (config.polyfills === true ||\n (config.polyfills !== false && config.polyfills.buffer)) &&\n new ProvidePlugin({\n Buffer: ['buffer', 'Buffer'],\n }),\n ].filter(Boolean),\n\n /**\n * The optimization configuration. This tells Webpack how to optimize the\n * bundle. Most of the time, you won't need to change this, as the default\n * options set by the `mode` option are sufficient.\n */\n optimization: {\n minimize: config.output.minimize,\n\n /**\n * The minimizer to use. We set it to use the `TerserPlugin`.\n */\n minimizer: [\n new TerserPlugin({\n parallel: true,\n }),\n ],\n },\n\n /**\n * The infrastructure logging configuration. This tells Webpack how to\n * log messages.\n *\n * @see https://webpack.js.org/configuration/infrastructure-logging\n */\n infrastructureLogging: {\n /**\n * The level of logging to use. We set it to `none`, so that we can\n * control the output ourselves.\n */\n level: 'none',\n },\n };\n}\n"],"names":["SnapsWebpackPlugin","resolve","TerserPlugin","EnvironmentPlugin","ProgressPlugin","ProvidePlugin","SnapsBuiltInResolver","SnapsBundleWarningsPlugin","SnapsStatsPlugin","SnapsWatchPlugin","BROWSERSLIST_FILE","getDefaultLoader","getDevTool","getFallbacks","getProgressHandler","getDefaultConfiguration","config","options","evaluate","spinnerText","spinner","text","builtInResolver","stats","builtIns","target","mode","entry","input","devtool","sourceMap","output","clean","filename","path","publicPath","library","type","module","rules","test","exclude","use","experimental","wasm","loader","__dirname","extensions","fallback","polyfills","plugins","manifestPath","manifest","writeManifest","update","eval","watch","verbose","environment","handler","Boolean","buffer","bundle","files","Buffer","filter","optimization","minimize","minimizer","parallel","infrastructureLogging","level"],"mappings":"AAAA,OAAOA,wBAAwB,iCAAiC;AAEhE,SAASC,OAAO,QAAQ,OAAO;AAC/B,OAAOC,kBAAkB,wBAAwB;AAEjD,SAASC,iBAAiB,EAAEC,cAAc,EAAEC,aAAa,QAAQ,UAAU;AAG3E,SACEC,oBAAoB,EACpBC,yBAAyB,EACzBC,gBAAgB,EA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;;;;KAIC,GACDM,cAAc;YACZC,UAAUnD,OAAOe,MAAM,CAACoC,QAAQ;YAEhC;;OAEC,GACDC,WAAW;gBACT,IAAIlE,aAAa;oBACfmE,UAAU;gBACZ;aACD;QACH;QAEA;;;;;KAKC,GACDC,uBAAuB;YACrB;;;OAGC,GACDC,OAAO;QACT;IACF;AACF"}
@@ -0,0 +1,5 @@
1
+ export * from './compiler';
2
+ export * from './config';
3
+ export * from './plugins';
4
+
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/webpack/index.ts"],"sourcesContent":["export * from './compiler';\nexport * from './config';\nexport * from './plugins';\n"],"names":[],"mappings":"AAAA,cAAc,aAAa;AAC3B,cAAc,WAAW;AACzB,cAAc,YAAY"}
@@ -0,0 +1,82 @@
1
+ import browserify from 'browserify';
2
+ import { Readable } from 'stream';
3
+ import { TranspilationModes } from '../../builders';
4
+ import { processDependencies } from '../../utils';
5
+ import { getBrowserslistTargets } from '../utils';
6
+ /**
7
+ * A Browserify loader for Webpack. This exists for backwards compatibility with
8
+ * the legacy configuration format, in order to support the `bundlerCustomizer`
9
+ * function.
10
+ *
11
+ * When this loader is used, the input file will be processed by Browserify, and
12
+ * written to disk by Webpack. Most processing will be handled by Browserify, so
13
+ * there are no benefits like tree-shaking.
14
+ *
15
+ * @param content - The input file contents as a string.
16
+ * @param sourceMap - The source map of the input file.
17
+ */ const loader = async function(content, sourceMap) {
18
+ const config = this.getOptions();
19
+ const { transpilationMode } = config;
20
+ const bundler = browserify({
21
+ extensions: [
22
+ '.js',
23
+ '.ts'
24
+ ],
25
+ debug: Boolean(sourceMap),
26
+ standalone: '<snap>'
27
+ });
28
+ if (transpilationMode !== TranspilationModes.None) {
29
+ const babelifyOptions = processDependencies(config);
30
+ // We need to statically import all Browserify transforms, and all Babel
31
+ // presets and plugins, and calling `require` is the sanest way to do that.
32
+ /* eslint-disable @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires, n/global-require */ bundler.transform(require('babelify'), {
33
+ global: transpilationMode === TranspilationModes.LocalAndDeps,
34
+ extensions: [
35
+ '.js',
36
+ '.ts'
37
+ ],
38
+ presets: [
39
+ require('@babel/preset-typescript'),
40
+ [
41
+ require('@babel/preset-env'),
42
+ {
43
+ targets: {
44
+ browsers: await getBrowserslistTargets()
45
+ }
46
+ }
47
+ ]
48
+ ],
49
+ plugins: [
50
+ require('@babel/plugin-transform-runtime'),
51
+ require('@babel/plugin-proposal-class-properties'),
52
+ require('@babel/plugin-proposal-private-methods'),
53
+ require('@babel/plugin-proposal-class-static-block'),
54
+ require('@babel/plugin-proposal-private-property-in-object')
55
+ ],
56
+ ...babelifyOptions
57
+ });
58
+ /* eslint-enable @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires, n/global-require */ }
59
+ config.bundlerCustomizer?.(bundler);
60
+ // Browserify doesn't accept a string as an entry point, so we need to convert
61
+ // it to a stream.
62
+ const stream = new Readable();
63
+ stream.push(content);
64
+ stream.push(null);
65
+ bundler.add(stream, {
66
+ file: this.resourcePath
67
+ });
68
+ return new Promise((resolve, reject)=>{
69
+ bundler.bundle((bundleError, buffer)=>{
70
+ if (bundleError) {
71
+ reject(bundleError);
72
+ return;
73
+ }
74
+ // Browserify inlines the source map, so we just pass the output buffer back
75
+ // to Webpack.
76
+ resolve(buffer);
77
+ });
78
+ });
79
+ };
80
+ export default loader;
81
+
82
+ //# sourceMappingURL=browserify.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/webpack/loaders/browserify.ts"],"sourcesContent":["import browserify from 'browserify';\nimport { Readable } from 'stream';\nimport type { LoaderDefinitionFunction } from 'webpack';\n\nimport { TranspilationModes } from '../../builders';\nimport type { LegacyOptions } from '../../config';\nimport { processDependencies } from '../../utils';\nimport { getBrowserslistTargets } from '../utils';\n\n/**\n * A Browserify loader for Webpack. This exists for backwards compatibility with\n * the legacy configuration format, in order to support the `bundlerCustomizer`\n * function.\n *\n * When this loader is used, the input file will be processed by Browserify, and\n * written to disk by Webpack. Most processing will be handled by Browserify, so\n * there are no benefits like tree-shaking.\n *\n * @param content - The input file contents as a string.\n * @param sourceMap - The source map of the input file.\n */\nconst loader: LoaderDefinitionFunction<LegacyOptions> = async function (\n content,\n sourceMap,\n) {\n const config = this.getOptions();\n\n const { transpilationMode } = config;\n\n const bundler = browserify({\n extensions: ['.js', '.ts'],\n debug: Boolean(sourceMap),\n standalone: '<snap>',\n });\n\n if (transpilationMode !== TranspilationModes.None) {\n const babelifyOptions = processDependencies(config);\n\n // We need to statically import all Browserify transforms, and all Babel\n // presets and plugins, and calling `require` is the sanest way to do that.\n /* eslint-disable @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires, n/global-require */\n bundler.transform(require('babelify'), {\n global: transpilationMode === TranspilationModes.LocalAndDeps,\n extensions: ['.js', '.ts'],\n presets: [\n require('@babel/preset-typescript'),\n [\n require('@babel/preset-env'),\n {\n targets: {\n browsers: await getBrowserslistTargets(),\n },\n },\n ],\n ],\n plugins: [\n require('@babel/plugin-transform-runtime'),\n require('@babel/plugin-proposal-class-properties'),\n require('@babel/plugin-proposal-private-methods'),\n require('@babel/plugin-proposal-class-static-block'),\n require('@babel/plugin-proposal-private-property-in-object'),\n ],\n ...(babelifyOptions as any),\n });\n /* eslint-enable @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires, n/global-require */\n }\n\n config.bundlerCustomizer?.(bundler);\n\n // Browserify doesn't accept a string as an entry point, so we need to convert\n // it to a stream.\n const stream = new Readable();\n stream.push(content);\n stream.push(null);\n\n bundler.add(stream, {\n file: this.resourcePath,\n });\n\n return new Promise<Buffer>((resolve, reject) => {\n bundler.bundle((bundleError, buffer: Buffer) => {\n if (bundleError) {\n reject(bundleError);\n return;\n }\n\n // Browserify inlines the source map, so we just pass the output buffer back\n // to Webpack.\n resolve(buffer);\n });\n });\n};\n\nexport default loader;\n"],"names":["browserify","Readable","TranspilationModes","processDependencies","getBrowserslistTargets","loader","content","sourceMap","config","getOptions","transpilationMode","bundler","extensions","debug","Boolean","standalone","None","babelifyOptions","transform","require","global","LocalAndDeps","presets","targets","browsers","plugins","bundlerCustomizer","stream","push","add","file","resourcePath","Promise","resolve","reject","bundle","bundleError","buffer"],"mappings":"AAAA,OAAOA,gBAAgB,aAAa;AACpC,SAASC,QAAQ,QAAQ,SAAS;AAGlC,SAASC,kBAAkB,QAAQ,iBAAiB;AAEpD,SAASC,mBAAmB,QAAQ,cAAc;AAClD,SAASC,sBAAsB,QAAQ,WAAW;AAElD;;;;;;;;;;;CAWC,GACD,MAAMC,SAAkD,eACtDC,OAAO,EACPC,SAAS;IAET,MAAMC,SAAS,IAAI,CAACC,UAAU;IAE9B,MAAM,EAAEC,iBAAiB,EAAE,GAAGF;IAE9B,MAAMG,UAAUX,WAAW;QACzBY,YAAY;YAAC;YAAO;SAAM;QAC1BC,OAAOC,QAAQP;QACfQ,YAAY;IACd;IAEA,IAAIL,sBAAsBR,mBAAmBc,IAAI,EAAE;QACjD,MAAMC,kBAAkBd,oBAAoBK;QAE5C,wEAAwE;QACxE,2EAA2E;QAC3E,8GAA8G,GAC9GG,QAAQO,SAAS,CAACC,QAAQ,aAAa;YACrCC,QAAQV,sBAAsBR,mBAAmBmB,YAAY;YAC7DT,YAAY;gBAAC;gBAAO;aAAM;YAC1BU,SAAS;gBACPH,QAAQ;gBACR;oBACEA,QAAQ;oBACR;wBACEI,SAAS;4BACPC,UAAU,MAAMpB;wBAClB;oBACF;iBACD;aACF;YACDqB,SAAS;gBACPN,QAAQ;gBACRA,QAAQ;gBACRA,QAAQ;gBACRA,QAAQ;gBACRA,QAAQ;aACT;YACD,GAAIF,eAAe;QACrB;IACA,6GAA6G,GAC/G;IAEAT,OAAOkB,iBAAiB,GAAGf;IAE3B,8EAA8E;IAC9E,kBAAkB;IAClB,MAAMgB,SAAS,IAAI1B;IACnB0B,OAAOC,IAAI,CAACtB;IACZqB,OAAOC,IAAI,CAAC;IAEZjB,QAAQkB,GAAG,CAACF,QAAQ;QAClBG,MAAM,IAAI,CAACC,YAAY;IACzB;IAEA,OAAO,IAAIC,QAAgB,CAACC,SAASC;QACnCvB,QAAQwB,MAAM,CAAC,CAACC,aAAaC;YAC3B,IAAID,aAAa;gBACfF,OAAOE;gBACP;YACF;YAEA,4EAA4E;YAC5E,cAAc;YACdH,QAAQI;QACV;IACF;AACF;AAEA,eAAehC,OAAO"}
@@ -0,0 +1,26 @@
1
+ import { assert, stringToBytes } from '@metamask/utils';
2
+ /**
3
+ * A Webpack loader that inlines the WASM module as a `Uint8Array`. This makes
4
+ * it possible to import the WASM module directly, and use it with the
5
+ * `WebAssembly.instantiate` function.
6
+ *
7
+ * This is useful, because snaps are not allowed to import assets from outside
8
+ * of their package. This loader allows you to inline the WASM module as a
9
+ * `Uint8Array`, which can then be passed to `WebAssembly.instantiate`.
10
+ *
11
+ * @param source - The WASM module as a string.
12
+ * @returns A string that exports the WASM module as a `Uint8Array`.
13
+ * @example
14
+ * ```ts
15
+ * import wasm from './program.wasm';
16
+ *
17
+ * const { instance } = await WebAssembly.instantiate(wasm, {});
18
+ * // Do something with the WASM module...
19
+ * ```
20
+ */ export default function loader(source) {
21
+ assert(typeof source === 'string', 'Expected source to be a string.');
22
+ const bytes = stringToBytes(source);
23
+ return `export default new Uint8Array(${JSON.stringify(Array.from(bytes))});`;
24
+ }
25
+
26
+ //# sourceMappingURL=wasm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/webpack/loaders/wasm.ts"],"sourcesContent":["import { assert, stringToBytes } from '@metamask/utils';\n\n/**\n * A Webpack loader that inlines the WASM module as a `Uint8Array`. This makes\n * it possible to import the WASM module directly, and use it with the\n * `WebAssembly.instantiate` function.\n *\n * This is useful, because snaps are not allowed to import assets from outside\n * of their package. This loader allows you to inline the WASM module as a\n * `Uint8Array`, which can then be passed to `WebAssembly.instantiate`.\n *\n * @param source - The WASM module as a string.\n * @returns A string that exports the WASM module as a `Uint8Array`.\n * @example\n * ```ts\n * import wasm from './program.wasm';\n *\n * const { instance } = await WebAssembly.instantiate(wasm, {});\n * // Do something with the WASM module...\n * ```\n */\nexport default function loader(source: unknown) {\n assert(typeof source === 'string', 'Expected source to be a string.');\n\n const bytes = stringToBytes(source);\n return `export default new Uint8Array(${JSON.stringify(Array.from(bytes))});`;\n}\n"],"names":["assert","stringToBytes","loader","source","bytes","JSON","stringify","Array","from"],"mappings":"AAAA,SAASA,MAAM,EAAEC,aAAa,QAAQ,kBAAkB;AAExD;;;;;;;;;;;;;;;;;;CAkBC,GACD,eAAe,SAASC,OAAOC,MAAe;IAC5CH,OAAO,OAAOG,WAAW,UAAU;IAEnC,MAAMC,QAAQH,cAAcE;IAC5B,OAAO,CAAC,8BAA8B,EAAEE,KAAKC,SAAS,CAACC,MAAMC,IAAI,CAACJ,QAAQ,EAAE,CAAC;AAC/E"}
@@ -0,0 +1,343 @@
1
+ function _check_private_redeclaration(obj, privateCollection) {
2
+ if (privateCollection.has(obj)) {
3
+ throw new TypeError("Cannot initialize the same private elements twice on an object");
4
+ }
5
+ }
6
+ function _class_apply_descriptor_get(receiver, descriptor) {
7
+ if (descriptor.get) {
8
+ return descriptor.get.call(receiver);
9
+ }
10
+ return descriptor.value;
11
+ }
12
+ function _class_apply_descriptor_set(receiver, descriptor, value) {
13
+ if (descriptor.set) {
14
+ descriptor.set.call(receiver, value);
15
+ } else {
16
+ if (!descriptor.writable) {
17
+ throw new TypeError("attempted to set read only private field");
18
+ }
19
+ descriptor.value = value;
20
+ }
21
+ }
22
+ function _class_extract_field_descriptor(receiver, privateMap, action) {
23
+ if (!privateMap.has(receiver)) {
24
+ throw new TypeError("attempted to " + action + " private field on non-instance");
25
+ }
26
+ return privateMap.get(receiver);
27
+ }
28
+ function _class_private_field_get(receiver, privateMap) {
29
+ var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
30
+ return _class_apply_descriptor_get(receiver, descriptor);
31
+ }
32
+ function _class_private_field_init(obj, privateMap, value) {
33
+ _check_private_redeclaration(obj, privateMap);
34
+ privateMap.set(obj, value);
35
+ }
36
+ function _class_private_field_set(receiver, privateMap, value) {
37
+ var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
38
+ _class_apply_descriptor_set(receiver, descriptor, value);
39
+ return value;
40
+ }
41
+ function _class_private_method_get(receiver, privateSet, fn) {
42
+ if (!privateSet.has(receiver)) {
43
+ throw new TypeError("attempted to get private field on non-instance");
44
+ }
45
+ return fn;
46
+ }
47
+ function _class_private_method_init(obj, privateSet) {
48
+ _check_private_redeclaration(obj, privateSet);
49
+ privateSet.add(obj);
50
+ }
51
+ function _define_property(obj, key, value) {
52
+ if (key in obj) {
53
+ Object.defineProperty(obj, key, {
54
+ value: value,
55
+ enumerable: true,
56
+ configurable: true,
57
+ writable: true
58
+ });
59
+ } else {
60
+ obj[key] = value;
61
+ }
62
+ return obj;
63
+ }
64
+ import { indent } from '@metamask/snaps-utils';
65
+ import { assert, hasProperty, isObject } from '@metamask/utils';
66
+ import { dim, red, yellow } from 'chalk';
67
+ import { isBuiltin } from 'module';
68
+ import { evaluate } from '../commands/eval';
69
+ import { error, getErrorMessage, info, warn } from '../utils';
70
+ import { pluralize } from './utils';
71
+ var _spinner = /*#__PURE__*/ new WeakMap(), /**
72
+ * Get the error message for the given stats error.
73
+ *
74
+ * @param statsError - The stats error.
75
+ * @returns The error message.
76
+ */ _getStatsErrorMessage = /*#__PURE__*/ new WeakSet();
77
+ /**
78
+ * A plugin that logs the stats after compilation. This is useful for logging
79
+ * the number of files compiled, and the time taken to compile them.
80
+ */ export class SnapsStatsPlugin {
81
+ /**
82
+ * Apply the plugin to the Webpack compiler.
83
+ *
84
+ * @param compiler - The Webpack compiler.
85
+ */ apply(compiler) {
86
+ compiler.hooks.afterDone.tap(this.constructor.name, (stats)=>{
87
+ if (!stats) {
88
+ return;
89
+ }
90
+ const { modules, time, errors } = stats.toJson();
91
+ assert(modules, 'Modules must be defined in stats.');
92
+ assert(time, 'Time must be defined in stats.');
93
+ if (errors?.length) {
94
+ const formattedErrors = errors.map(_class_private_method_get(this, _getStatsErrorMessage, getStatsErrorMessage).bind(this)).join('\n\n');
95
+ error(`Compiled ${modules.length} ${pluralize(modules.length, 'file')} in ${time}ms with ${errors.length} ${pluralize(errors.length, 'error')}.\n\n${formattedErrors}\n`, _class_private_field_get(this, _spinner));
96
+ _class_private_field_get(this, _spinner)?.stop();
97
+ process.exitCode = 1;
98
+ return;
99
+ }
100
+ info(`Compiled ${modules.length} ${pluralize(modules.length, 'file')} in ${time}ms.`, _class_private_field_get(this, _spinner));
101
+ if (compiler.watchMode) {
102
+ // The spinner may be restarted by the watch plugin, outside of the
103
+ // `executeSteps` flow, so we stop it here just in case.
104
+ _class_private_field_get(this, _spinner)?.succeed('Done!');
105
+ }
106
+ });
107
+ }
108
+ constructor(options = {
109
+ verbose: false
110
+ }, spinner){
111
+ _class_private_method_init(this, _getStatsErrorMessage);
112
+ /**
113
+ * The options for the plugin.
114
+ */ _define_property(this, "options", void 0);
115
+ /**
116
+ * The spinner to use for logging.
117
+ */ _class_private_field_init(this, _spinner, {
118
+ writable: true,
119
+ value: void 0
120
+ });
121
+ this.options = options;
122
+ _class_private_field_set(this, _spinner, spinner);
123
+ }
124
+ }
125
+ function getStatsErrorMessage(statsError) {
126
+ const baseMessage = this.options.verbose ? getErrorMessage(statsError) : statsError.message;
127
+ const [first, ...rest] = baseMessage.split('\n');
128
+ return [
129
+ indent(red(`• ${first}`), 2),
130
+ ...rest.map((message)=>indent(red(message), 4)),
131
+ statsError.details && indent(dim(statsError.details), 4)
132
+ ].filter(Boolean).join('\n');
133
+ }
134
+ var _spinner1 = /*#__PURE__*/ new WeakMap(), _safeEvaluate = /*#__PURE__*/ new WeakSet();
135
+ /**
136
+ * A plugin that adds extra files to watch. This is useful for watching files
137
+ * that are not imported by the entry point, such as the `snap.manifest.json`
138
+ * file.
139
+ */ export class SnapsWatchPlugin {
140
+ /**
141
+ * Apply the plugin to the Webpack compiler.
142
+ *
143
+ * @param compiler - The Webpack compiler.
144
+ */ apply(compiler) {
145
+ compiler.hooks.invalid.tap(this.constructor.name, (file)=>{
146
+ _class_private_field_get(this, _spinner1)?.start();
147
+ info(`Changes detected in ${yellow(file)}, recompiling.`, _class_private_field_get(this, _spinner1));
148
+ });
149
+ compiler.hooks.afterEmit.tapPromise(this.constructor.name, async ({ fileDependencies })=>{
150
+ this.options.files?.forEach(fileDependencies.add.bind(fileDependencies));
151
+ if (this.options.bundle && this.options.evaluate) {
152
+ await _class_private_method_get(this, _safeEvaluate, safeEvaluate).call(this, this.options.bundle);
153
+ }
154
+ });
155
+ }
156
+ constructor(options, spinner){
157
+ /**
158
+ * Safely evaluate the bundle at the given path. If an error occurs, it will
159
+ * be logged to the console, rather than throwing an error.
160
+ *
161
+ * This function should never throw an error.
162
+ *
163
+ * @param bundlePath - The path to the bundle.
164
+ */ _class_private_method_init(this, _safeEvaluate);
165
+ /**
166
+ * The options for the plugin.
167
+ */ _define_property(this, "options", void 0);
168
+ /**
169
+ * The spinner to use for logging.
170
+ */ _class_private_field_init(this, _spinner1, {
171
+ writable: true,
172
+ value: void 0
173
+ });
174
+ this.options = options;
175
+ _class_private_field_set(this, _spinner1, spinner);
176
+ }
177
+ }
178
+ async function safeEvaluate(bundlePath) {
179
+ try {
180
+ await evaluate(bundlePath);
181
+ info(`Snap bundle evaluated successfully.`, _class_private_field_get(this, _spinner1));
182
+ } catch (evaluateError) {
183
+ error(evaluateError.message, _class_private_field_get(this, _spinner1));
184
+ }
185
+ }
186
+ var _source = /*#__PURE__*/ new WeakMap(), _spinner2 = /*#__PURE__*/ new WeakMap();
187
+ /**
188
+ * A plugin that logs a message when a built-in module is not resolved. The
189
+ * MetaMask Snaps CLI does not support built-in modules by default, and this
190
+ * plugin is used to warn the user when they try to import a built-in module,
191
+ * when no fallback is configured.
192
+ */ export class SnapsBuiltInResolver {
193
+ /**
194
+ * Apply the plugin to the Webpack resolver.
195
+ *
196
+ * @param resolver - The Webpack resolver.
197
+ */ apply(resolver) {
198
+ resolver.getHook(_class_private_field_get(this, _source)).tapAsync(this.constructor.name, ({ module: isModule, request }, _, callback)=>{
199
+ if (!isModule || !request) {
200
+ return callback();
201
+ }
202
+ const baseRequest = request.split('/')[0];
203
+ if (isBuiltin(baseRequest) && !this.options.ignore?.includes(baseRequest)) {
204
+ const fallback = resolver.options.fallback.find(({ name })=>name === baseRequest);
205
+ if (fallback && !fallback.alias) {
206
+ this.unresolvedModules.add(baseRequest);
207
+ }
208
+ }
209
+ return callback();
210
+ });
211
+ }
212
+ constructor(options = {
213
+ ignore: []
214
+ }, spinner){
215
+ /**
216
+ * The built-in modules that have been imported, but not resolved.
217
+ */ _define_property(this, "unresolvedModules", new Set());
218
+ /**
219
+ * The name of the resolver hook to tap into.
220
+ */ _class_private_field_init(this, _source, {
221
+ writable: true,
222
+ value: 'described-resolve'
223
+ });
224
+ /**
225
+ * The options for the plugin.
226
+ */ _define_property(this, "options", void 0);
227
+ /**
228
+ * The spinner to use for logging.
229
+ */ _class_private_field_init(this, _spinner2, {
230
+ writable: true,
231
+ value: void 0
232
+ });
233
+ this.options = options;
234
+ _class_private_field_set(this, _spinner2, spinner);
235
+ }
236
+ }
237
+ var _spinner3 = /*#__PURE__*/ new WeakMap(), /**
238
+ * Check if a built-in module is used, but not provided by Webpack's
239
+ * `fallback` configuration.
240
+ *
241
+ * @param compiler - The Webpack compiler.
242
+ */ _checkBuiltIns = /*#__PURE__*/ new WeakSet(), /**
243
+ * Check if the given instance is a `ProvidePlugin`. This is not guaranteed to
244
+ * be accurate, but it's good enough for our purposes. If we were to use
245
+ * `instanceof` instead, it might not work if multiple versions of Webpack are
246
+ * installed.
247
+ *
248
+ * @param instance - The instance to check.
249
+ * @returns Whether the instance is a `ProvidePlugin`, i.e., whether it's an
250
+ * object with the name `ProvidePlugin` and a `definitions` property.
251
+ */ _isProvidePlugin = /*#__PURE__*/ new WeakSet(), /**
252
+ * Check if the `Buffer` global is used, but not provided by Webpack's
253
+ * `DefinePlugin`.
254
+ *
255
+ * @param compiler - The Webpack compiler.
256
+ */ _checkBuffer = /*#__PURE__*/ new WeakSet();
257
+ /**
258
+ * A plugin that logs a message when:
259
+ *
260
+ * - A built-in module is not resolved. The MetaMask Snaps CLI does not support
261
+ * built-in modules by default, and this plugin is used to warn the user when
262
+ * they try to import a built-in module, when no fallback is configured.
263
+ * - A snap uses the `Buffer` global. The MetaMask Snaps CLI does not support
264
+ * the `Buffer` global by default, and this plugin is used to warn the user when
265
+ * they try to use the `Buffer` global.
266
+ *
267
+ * We use both a resolver and a plugin, because the resolver is used to detect
268
+ * when a built-in module is imported, and the plugin is used to log a single
269
+ * message when the compilation is complete. We can't do everything in a single
270
+ * plugin, because the resolver doesn't have access to the compilation, and the
271
+ * plugin doesn't have access to the resolver.
272
+ */ export class SnapsBundleWarningsPlugin {
273
+ /**
274
+ * Apply the plugin to the Webpack compiler.
275
+ *
276
+ * @param compiler - The Webpack compiler.
277
+ */ apply(compiler) {
278
+ if (this.options.builtIns) {
279
+ _class_private_method_get(this, _checkBuiltIns, checkBuiltIns).call(this, compiler);
280
+ }
281
+ if (this.options.buffer) {
282
+ _class_private_method_get(this, _checkBuffer, checkBuffer).call(this, compiler);
283
+ }
284
+ }
285
+ constructor(options = {
286
+ buffer: true,
287
+ builtIns: true
288
+ }, spinner){
289
+ _class_private_method_init(this, _checkBuiltIns);
290
+ _class_private_method_init(this, _isProvidePlugin);
291
+ _class_private_method_init(this, _checkBuffer);
292
+ /**
293
+ * The spinner to use for logging.
294
+ */ _class_private_field_init(this, _spinner3, {
295
+ writable: true,
296
+ value: void 0
297
+ });
298
+ /**
299
+ * The options for the plugin.
300
+ */ _define_property(this, "options", void 0);
301
+ this.options = options;
302
+ _class_private_field_set(this, _spinner3, spinner);
303
+ }
304
+ }
305
+ function checkBuiltIns(compiler) {
306
+ compiler.hooks.afterCompile.tap(this.constructor.name, ()=>{
307
+ if (!this.options.builtInResolver) {
308
+ return;
309
+ }
310
+ const { unresolvedModules } = this.options.builtInResolver;
311
+ if (unresolvedModules.size === 0) {
312
+ return;
313
+ }
314
+ const formattedModules = new Array(...unresolvedModules).map((name)=>indent(`• ${name}`, 2)).join('\n');
315
+ warn(`The snap attempted to use one or more Node.js builtins, but no browser fallback has been provided.\n` + `The MetaMask Snaps CLI does not support Node.js builtins by default. If you want to use this module, you must set ${yellow(`polyfills`)} to ${yellow(`true`)} or an object with the builtins to polyfill as the key and ${yellow(`true`)} as the value.\n` + `To disable this warning, set ${yellow('`stats.builtIns`')} to ${yellow('`false`')} in your snap config file, or add the module to the ${yellow('`stats.builtIns.ignore`')} array.\n\n${formattedModules}\n`, _class_private_field_get(this, _spinner3));
316
+ });
317
+ }
318
+ function isProvidePlugin(instance) {
319
+ return isObject(instance) && instance.constructor.name === 'ProvidePlugin' && hasProperty(instance, 'definitions');
320
+ }
321
+ function checkBuffer(compiler) {
322
+ const plugin = compiler.options.plugins?.find((instance)=>_class_private_method_get(this, _isProvidePlugin, isProvidePlugin).call(this, instance));
323
+ // If the `ProvidePlugin` is configured to provide `Buffer`, then we don't
324
+ // need to warn the user.
325
+ if (plugin) {
326
+ const { definitions } = plugin;
327
+ if (definitions.Buffer) {
328
+ return;
329
+ }
330
+ }
331
+ compiler.hooks.compilation.tap(this.constructor.name, (compilation)=>{
332
+ compilation.hooks.afterProcessAssets.tap(this.constructor.name, (assets)=>{
333
+ // Check if assets use `Buffer`.
334
+ const bufferAssets = Object.entries(assets).filter(([name])=>name.endsWith('.js')).filter(([, asset])=>asset.source().includes('Buffer'));
335
+ if (bufferAssets.length === 0) {
336
+ return;
337
+ }
338
+ warn(`The snap attempted to use the Node.js Buffer global, which is not supported in the MetaMask Snaps CLI by default.\n` + `To use the Buffer global, you must polyfill Buffer by setting ${yellow(`buffer`)} to ${yellow(`true`)} in the ${yellow(`polyfills`)} config object in your snap config.\n` + `To disable this warning, set ${yellow('`stats.buffer`')} to ${yellow('`false`')} in your snap config file.`, _class_private_field_get(this, _spinner3));
339
+ });
340
+ });
341
+ }
342
+
343
+ //# sourceMappingURL=plugins.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/webpack/plugins.ts"],"sourcesContent":["import { indent } from '@metamask/snaps-utils';\nimport { assert, hasProperty, isObject } from '@metamask/utils';\nimport { dim, red, yellow } from 'chalk';\nimport { isBuiltin } from 'module';\nimport type { Ora } from 'ora';\nimport type {\n Compiler,\n ProvidePlugin,\n ResolvePluginInstance,\n Resolver,\n StatsError,\n WebpackPluginInstance,\n} from 'webpack';\n\nimport { evaluate } from '../commands/eval';\nimport { error, getErrorMessage, info, warn } from '../utils';\nimport { pluralize } from './utils';\n\nexport type SnapsStatsPluginOptions = {\n /**\n * Whether to log the verbose stats.\n */\n verbose?: boolean;\n};\n\n/**\n * A plugin that logs the stats after compilation. This is useful for logging\n * the number of files compiled, and the time taken to compile them.\n */\nexport class SnapsStatsPlugin implements WebpackPluginInstance {\n /**\n * The options for the plugin.\n */\n readonly options: SnapsStatsPluginOptions;\n\n /**\n * The spinner to use for logging.\n */\n readonly #spinner?: Ora;\n\n constructor(\n options: SnapsStatsPluginOptions = {\n verbose: false,\n },\n spinner?: Ora,\n ) {\n this.options = options;\n this.#spinner = spinner;\n }\n\n /**\n * Apply the plugin to the Webpack compiler.\n *\n * @param compiler - The Webpack compiler.\n */\n apply(compiler: Compiler) {\n compiler.hooks.afterDone.tap(this.constructor.name, (stats) => {\n if (!stats) {\n return;\n }\n\n const { modules, time, errors } = stats.toJson();\n\n assert(modules, 'Modules must be defined in stats.');\n assert(time, 'Time must be defined in stats.');\n\n if (errors?.length) {\n const formattedErrors = errors\n .map(this.#getStatsErrorMessage.bind(this))\n .join('\\n\\n');\n\n error(\n `Compiled ${modules.length} ${pluralize(\n modules.length,\n 'file',\n )} in ${time}ms with ${errors.length} ${pluralize(\n errors.length,\n 'error',\n )}.\\n\\n${formattedErrors}\\n`,\n this.#spinner,\n );\n\n this.#spinner?.stop();\n\n process.exitCode = 1;\n return;\n }\n\n info(\n `Compiled ${modules.length} ${pluralize(\n modules.length,\n 'file',\n )} in ${time}ms.`,\n this.#spinner,\n );\n\n if (compiler.watchMode) {\n // The spinner may be restarted by the watch plugin, outside of the\n // `executeSteps` flow, so we stop it here just in case.\n this.#spinner?.succeed('Done!');\n }\n });\n }\n\n /**\n * Get the error message for the given stats error.\n *\n * @param statsError - The stats error.\n * @returns The error message.\n */\n #getStatsErrorMessage(statsError: StatsError) {\n const baseMessage = this.options.verbose\n ? getErrorMessage(statsError)\n : statsError.message;\n\n const [first, ...rest] = baseMessage.split('\\n');\n\n return [\n indent(red(`• ${first}`), 2),\n ...rest.map((message) => indent(red(message), 4)),\n statsError.details && indent(dim(statsError.details), 4),\n ]\n .filter(Boolean)\n .join('\\n');\n }\n}\n\n/**\n * The options for the {@link SnapsWatchPlugin}.\n */\nexport type SnapsWatchPluginOptions = {\n /**\n * The bundle path. This is the file that will be evaluated, if the `evaluate`\n * option is set.\n */\n bundle?: string;\n\n /**\n * Whether to evaluate the bundle. This only applies if the `bundle` option is\n * set.\n */\n evaluate?: boolean;\n\n /**\n * The extra files to watch.\n */\n files?: string[];\n};\n\n/**\n * A plugin that adds extra files to watch. This is useful for watching files\n * that are not imported by the entry point, such as the `snap.manifest.json`\n * file.\n */\nexport class SnapsWatchPlugin implements WebpackPluginInstance {\n /**\n * The options for the plugin.\n */\n readonly options: SnapsWatchPluginOptions;\n\n /**\n * The spinner to use for logging.\n */\n readonly #spinner?: Ora;\n\n constructor(options: SnapsWatchPluginOptions, spinner?: Ora) {\n this.options = options;\n this.#spinner = spinner;\n }\n\n /**\n * Apply the plugin to the Webpack compiler.\n *\n * @param compiler - The Webpack compiler.\n */\n apply(compiler: Compiler) {\n compiler.hooks.invalid.tap(this.constructor.name, (file) => {\n this.#spinner?.start();\n info(`Changes detected in ${yellow(file)}, recompiling.`, this.#spinner);\n });\n\n compiler.hooks.afterEmit.tapPromise(\n this.constructor.name,\n async ({ fileDependencies }) => {\n this.options.files?.forEach(\n fileDependencies.add.bind(fileDependencies),\n );\n\n if (this.options.bundle && this.options.evaluate) {\n await this.#safeEvaluate(this.options.bundle);\n }\n },\n );\n }\n\n /**\n * Safely evaluate the bundle at the given path. If an error occurs, it will\n * be logged to the console, rather than throwing an error.\n *\n * This function should never throw an error.\n *\n * @param bundlePath - The path to the bundle.\n */\n async #safeEvaluate(bundlePath: string) {\n try {\n await evaluate(bundlePath);\n info(`Snap bundle evaluated successfully.`, this.#spinner);\n } catch (evaluateError) {\n error(evaluateError.message, this.#spinner);\n }\n }\n}\n\n/**\n * The options for the {@link SnapsBuiltInResolver}.\n */\nexport type SnapsBuiltInResolverOptions = {\n /**\n * The built-in modules to ignore.\n */\n ignore?: string[];\n};\n\n/**\n * A plugin that logs a message when a built-in module is not resolved. The\n * MetaMask Snaps CLI does not support built-in modules by default, and this\n * plugin is used to warn the user when they try to import a built-in module,\n * when no fallback is configured.\n */\nexport class SnapsBuiltInResolver implements ResolvePluginInstance {\n /**\n * The built-in modules that have been imported, but not resolved.\n */\n readonly unresolvedModules = new Set<string>();\n\n /**\n * The name of the resolver hook to tap into.\n */\n readonly #source = 'described-resolve';\n\n /**\n * The options for the plugin.\n */\n readonly options: SnapsBuiltInResolverOptions;\n\n /**\n * The spinner to use for logging.\n */\n readonly #spinner?: Ora;\n\n constructor(\n options: SnapsBuiltInResolverOptions = {\n ignore: [],\n },\n spinner?: Ora,\n ) {\n this.options = options;\n this.#spinner = spinner;\n }\n\n /**\n * Apply the plugin to the Webpack resolver.\n *\n * @param resolver - The Webpack resolver.\n */\n apply(resolver: Resolver) {\n resolver\n .getHook(this.#source)\n .tapAsync(\n this.constructor.name,\n ({ module: isModule, request }, _, callback) => {\n if (!isModule || !request) {\n return callback();\n }\n\n const baseRequest = request.split('/')[0];\n if (\n isBuiltin(baseRequest) &&\n !this.options.ignore?.includes(baseRequest)\n ) {\n const fallback = resolver.options.fallback.find(\n ({ name }) => name === baseRequest,\n );\n\n if (fallback && !fallback.alias) {\n this.unresolvedModules.add(baseRequest);\n }\n }\n\n return callback();\n },\n );\n }\n}\n\n/**\n * The options for the {@link SnapsBundleWarningsPlugin}.\n */\nexport type SnapsBundleWarningsPluginOptions = {\n /**\n * The {@link SnapsBuiltInResolver} instance to use for detecting built-in\n * modules.\n */\n builtInResolver?: SnapsBuiltInResolver | false;\n\n /**\n * Whether to show warnings if built-in modules are used, but not provided by\n * Webpack's `fallback` configuration.\n */\n builtIns?: boolean;\n\n /**\n * Whether to show warnings if the `Buffer` global is used, but not provided\n * by Webpack's `DefinePlugin`.\n */\n buffer?: boolean;\n};\n\n/**\n * A plugin that logs a message when:\n *\n * - A built-in module is not resolved. The MetaMask Snaps CLI does not support\n * built-in modules by default, and this plugin is used to warn the user when\n * they try to import a built-in module, when no fallback is configured.\n * - A snap uses the `Buffer` global. The MetaMask Snaps CLI does not support\n * the `Buffer` global by default, and this plugin is used to warn the user when\n * they try to use the `Buffer` global.\n *\n * We use both a resolver and a plugin, because the resolver is used to detect\n * when a built-in module is imported, and the plugin is used to log a single\n * message when the compilation is complete. We can't do everything in a single\n * plugin, because the resolver doesn't have access to the compilation, and the\n * plugin doesn't have access to the resolver.\n */\n\nexport class SnapsBundleWarningsPlugin implements WebpackPluginInstance {\n /**\n * The spinner to use for logging.\n */\n readonly #spinner?: Ora;\n\n /**\n * The options for the plugin.\n */\n readonly options: SnapsBundleWarningsPluginOptions;\n\n constructor(\n options: SnapsBundleWarningsPluginOptions = {\n buffer: true,\n builtIns: true,\n },\n spinner?: Ora,\n ) {\n this.options = options;\n this.#spinner = spinner;\n }\n\n /**\n * Apply the plugin to the Webpack compiler.\n *\n * @param compiler - The Webpack compiler.\n */\n apply(compiler: Compiler) {\n if (this.options.builtIns) {\n this.#checkBuiltIns(compiler);\n }\n\n if (this.options.buffer) {\n this.#checkBuffer(compiler);\n }\n }\n\n /**\n * Check if a built-in module is used, but not provided by Webpack's\n * `fallback` configuration.\n *\n * @param compiler - The Webpack compiler.\n */\n #checkBuiltIns(compiler: Compiler) {\n compiler.hooks.afterCompile.tap(this.constructor.name, () => {\n if (!this.options.builtInResolver) {\n return;\n }\n\n const { unresolvedModules } = this.options.builtInResolver;\n if (unresolvedModules.size === 0) {\n return;\n }\n\n const formattedModules = new Array(...unresolvedModules)\n .map((name) => indent(`• ${name}`, 2))\n .join('\\n');\n\n warn(\n `The snap attempted to use one or more Node.js builtins, but no browser fallback has been provided.\\n` +\n `The MetaMask Snaps CLI does not support Node.js builtins by default. If you want to use this module, you must set ${yellow(\n `polyfills`,\n )} to ${yellow(\n `true`,\n )} or an object with the builtins to polyfill as the key and ${yellow(\n `true`,\n )} as the value.\\n` +\n `To disable this warning, set ${yellow(\n '`stats.builtIns`',\n )} to ${yellow(\n '`false`',\n )} in your snap config file, or add the module to the ${yellow(\n '`stats.builtIns.ignore`',\n )} array.\\n\\n${formattedModules}\\n`,\n this.#spinner,\n );\n });\n }\n\n /**\n * Check if the given instance is a `ProvidePlugin`. This is not guaranteed to\n * be accurate, but it's good enough for our purposes. If we were to use\n * `instanceof` instead, it might not work if multiple versions of Webpack are\n * installed.\n *\n * @param instance - The instance to check.\n * @returns Whether the instance is a `ProvidePlugin`, i.e., whether it's an\n * object with the name `ProvidePlugin` and a `definitions` property.\n */\n #isProvidePlugin(instance: unknown): instance is ProvidePlugin {\n return (\n isObject(instance) &&\n instance.constructor.name === 'ProvidePlugin' &&\n hasProperty(instance, 'definitions')\n );\n }\n\n /**\n * Check if the `Buffer` global is used, but not provided by Webpack's\n * `DefinePlugin`.\n *\n * @param compiler - The Webpack compiler.\n */\n #checkBuffer(compiler: Compiler) {\n const plugin = compiler.options.plugins?.find((instance) =>\n this.#isProvidePlugin(instance),\n ) as ProvidePlugin | undefined;\n\n // If the `ProvidePlugin` is configured to provide `Buffer`, then we don't\n // need to warn the user.\n if (plugin) {\n const { definitions } = plugin;\n if (definitions.Buffer) {\n return;\n }\n }\n\n compiler.hooks.compilation.tap(this.constructor.name, (compilation) => {\n compilation.hooks.afterProcessAssets.tap(\n this.constructor.name,\n (assets) => {\n // Check if assets use `Buffer`.\n const bufferAssets = Object.entries(assets)\n .filter(([name]) => name.endsWith('.js'))\n .filter(([, asset]) => asset.source().includes('Buffer'));\n\n if (bufferAssets.length === 0) {\n return;\n }\n\n warn(\n `The snap attempted to use the Node.js Buffer global, which is not supported in the MetaMask Snaps CLI by default.\\n` +\n `To use the Buffer global, you must polyfill Buffer by setting ${yellow(\n `buffer`,\n )} to ${yellow(`true`)} in the ${yellow(\n `polyfills`,\n )} config object in your snap config.\\n` +\n `To disable this warning, set ${yellow(\n '`stats.buffer`',\n )} to ${yellow('`false`')} in your snap config file.`,\n this.#spinner,\n );\n },\n );\n });\n }\n}\n"],"names":["indent","assert","hasProperty","isObject","dim","red","yellow","isBuiltin","evaluate","error","getErrorMessage","info","warn","pluralize","SnapsStatsPlugin","apply","compiler","hooks","afterDone","tap","constructor","name","stats","modules","time","errors","toJson","length","formattedErrors","map","getStatsErrorMessage","bind","join","spinner","stop","process","exitCode","watchMode","succeed","options","verbose","statsError","baseMessage","message","first","rest","split","details","filter","Boolean","SnapsWatchPlugin","invalid","file","start","afterEmit","tapPromise","fileDependencies","files","forEach","add","bundle","safeEvaluate","bundlePath","evaluateError","SnapsBuiltInResolver","resolver","getHook","source","tapAsync","module","isModule","request","_","callback","baseRequest","ignore","includes","fallback","find","alias","unresolvedModules","Set","SnapsBundleWarningsPlugin","builtIns","checkBuiltIns","buffer","checkBuffer","afterCompile","builtInResolver","size","formattedModules","Array","instance","plugin","plugins","isProvidePlugin","definitions","Buffer","compilation","afterProcessAssets","assets","bufferAssets","Object","entries","endsWith","asset"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAASA,MAAM,QAAQ,wBAAwB;AAC/C,SAASC,MAAM,EAAEC,WAAW,EAAEC,QAAQ,QAAQ,kBAAkB;AAChE,SAASC,GAAG,EAAEC,GAAG,EAAEC,MAAM,QAAQ,QAAQ;AAC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