@metamask/snaps-cli 6.7.0 → 7.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 (213) hide show
  1. package/CHANGELOG.md +32 -1
  2. package/README.md +11 -244
  3. package/dist/builders.cjs +0 -97
  4. package/dist/builders.cjs.map +1 -1
  5. package/dist/builders.d.cts +0 -94
  6. package/dist/builders.d.cts.map +1 -1
  7. package/dist/builders.d.mts +0 -94
  8. package/dist/builders.d.mts.map +1 -1
  9. package/dist/builders.mjs +0 -96
  10. package/dist/builders.mjs.map +1 -1
  11. package/dist/cli.cjs +4 -9
  12. package/dist/cli.cjs.map +1 -1
  13. package/dist/cli.d.cts.map +1 -1
  14. package/dist/cli.d.mts.map +1 -1
  15. package/dist/cli.mjs +4 -16
  16. package/dist/cli.mjs.map +1 -1
  17. package/dist/commands/build/build.cjs +7 -7
  18. package/dist/commands/build/build.cjs.map +1 -1
  19. package/dist/commands/build/build.d.cts.map +1 -1
  20. package/dist/commands/build/build.d.mts.map +1 -1
  21. package/dist/commands/build/build.mjs +2 -2
  22. package/dist/commands/build/build.mjs.map +1 -1
  23. package/dist/commands/build/implementation.cjs.map +1 -1
  24. package/dist/commands/build/implementation.d.cts +2 -2
  25. package/dist/commands/build/implementation.d.cts.map +1 -1
  26. package/dist/commands/build/implementation.d.mts +2 -2
  27. package/dist/commands/build/implementation.d.mts.map +1 -1
  28. package/dist/commands/build/implementation.mjs.map +1 -1
  29. package/dist/commands/build/index.cjs +2 -14
  30. package/dist/commands/build/index.cjs.map +1 -1
  31. package/dist/commands/build/index.d.cts.map +1 -1
  32. package/dist/commands/build/index.d.mts.map +1 -1
  33. package/dist/commands/build/index.mjs +2 -14
  34. package/dist/commands/build/index.mjs.map +1 -1
  35. package/dist/commands/eval/__test__/webpack/bad/snap.config.cjs +0 -1
  36. package/dist/commands/eval/__test__/webpack/bad/snap.config.cjs.map +1 -1
  37. package/dist/commands/eval/__test__/webpack/bad/snap.config.d.cts.map +1 -1
  38. package/dist/commands/eval/__test__/webpack/bad/snap.config.d.mts.map +1 -1
  39. package/dist/commands/eval/__test__/webpack/bad/snap.config.mjs +0 -1
  40. package/dist/commands/eval/__test__/webpack/bad/snap.config.mjs.map +1 -1
  41. package/dist/commands/eval/__test__/webpack/good/snap.config.cjs +0 -1
  42. package/dist/commands/eval/__test__/webpack/good/snap.config.cjs.map +1 -1
  43. package/dist/commands/eval/__test__/webpack/good/snap.config.d.cts.map +1 -1
  44. package/dist/commands/eval/__test__/webpack/good/snap.config.d.mts.map +1 -1
  45. package/dist/commands/eval/__test__/webpack/good/snap.config.mjs +0 -1
  46. package/dist/commands/eval/__test__/webpack/good/snap.config.mjs.map +1 -1
  47. package/dist/commands/eval/__test__/webpack/snap.config.cjs +0 -1
  48. package/dist/commands/eval/__test__/webpack/snap.config.cjs.map +1 -1
  49. package/dist/commands/eval/__test__/webpack/snap.config.d.cts.map +1 -1
  50. package/dist/commands/eval/__test__/webpack/snap.config.d.mts.map +1 -1
  51. package/dist/commands/eval/__test__/webpack/snap.config.mjs +0 -1
  52. package/dist/commands/eval/__test__/webpack/snap.config.mjs.map +1 -1
  53. package/dist/commands/eval/eval.cjs +1 -1
  54. package/dist/commands/eval/eval.cjs.map +1 -1
  55. package/dist/commands/eval/eval.d.cts.map +1 -1
  56. package/dist/commands/eval/eval.d.mts.map +1 -1
  57. package/dist/commands/eval/eval.mjs +1 -1
  58. package/dist/commands/eval/eval.mjs.map +1 -1
  59. package/dist/commands/eval/index.cjs +1 -4
  60. package/dist/commands/eval/index.cjs.map +1 -1
  61. package/dist/commands/eval/index.d.cts.map +1 -1
  62. package/dist/commands/eval/index.d.mts.map +1 -1
  63. package/dist/commands/eval/index.mjs +1 -4
  64. package/dist/commands/eval/index.mjs.map +1 -1
  65. package/dist/commands/manifest/index.cjs +1 -4
  66. package/dist/commands/manifest/index.cjs.map +1 -1
  67. package/dist/commands/manifest/index.d.cts.map +1 -1
  68. package/dist/commands/manifest/index.d.mts.map +1 -1
  69. package/dist/commands/manifest/index.mjs +1 -4
  70. package/dist/commands/manifest/index.mjs.map +1 -1
  71. package/dist/commands/manifest/manifest.cjs +5 -6
  72. package/dist/commands/manifest/manifest.cjs.map +1 -1
  73. package/dist/commands/manifest/manifest.d.cts.map +1 -1
  74. package/dist/commands/manifest/manifest.d.mts.map +1 -1
  75. package/dist/commands/manifest/manifest.mjs +5 -6
  76. package/dist/commands/manifest/manifest.mjs.map +1 -1
  77. package/dist/commands/serve/index.cjs +2 -2
  78. package/dist/commands/serve/index.cjs.map +1 -1
  79. package/dist/commands/serve/index.d.cts.map +1 -1
  80. package/dist/commands/serve/index.d.mts.map +1 -1
  81. package/dist/commands/serve/index.mjs +2 -2
  82. package/dist/commands/serve/index.mjs.map +1 -1
  83. package/dist/commands/watch/implementation.cjs +2 -0
  84. package/dist/commands/watch/implementation.cjs.map +1 -1
  85. package/dist/commands/watch/implementation.d.cts +2 -2
  86. package/dist/commands/watch/implementation.d.cts.map +1 -1
  87. package/dist/commands/watch/implementation.d.mts +2 -2
  88. package/dist/commands/watch/implementation.d.mts.map +1 -1
  89. package/dist/commands/watch/implementation.mjs +2 -0
  90. package/dist/commands/watch/implementation.mjs.map +1 -1
  91. package/dist/commands/watch/index.cjs +2 -17
  92. package/dist/commands/watch/index.cjs.map +1 -1
  93. package/dist/commands/watch/index.d.cts.map +1 -1
  94. package/dist/commands/watch/index.d.mts.map +1 -1
  95. package/dist/commands/watch/index.mjs +2 -17
  96. package/dist/commands/watch/index.mjs.map +1 -1
  97. package/dist/commands/watch/watch.cjs +1 -1
  98. package/dist/commands/watch/watch.cjs.map +1 -1
  99. package/dist/commands/watch/watch.d.cts.map +1 -1
  100. package/dist/commands/watch/watch.d.mts.map +1 -1
  101. package/dist/commands/watch/watch.mjs +1 -1
  102. package/dist/commands/watch/watch.mjs.map +1 -1
  103. package/dist/config.cjs +11 -155
  104. package/dist/config.cjs.map +1 -1
  105. package/dist/config.d.cts +216 -314
  106. package/dist/config.d.cts.map +1 -1
  107. package/dist/config.d.mts +216 -314
  108. package/dist/config.d.mts.map +1 -1
  109. package/dist/config.mjs +13 -155
  110. package/dist/config.mjs.map +1 -1
  111. package/dist/main.cjs +0 -1
  112. package/dist/main.cjs.map +1 -1
  113. package/dist/main.mjs +0 -1
  114. package/dist/main.mjs.map +1 -1
  115. package/dist/utils/index.cjs +0 -1
  116. package/dist/utils/index.cjs.map +1 -1
  117. package/dist/utils/index.d.cts +0 -1
  118. package/dist/utils/index.d.cts.map +1 -1
  119. package/dist/utils/index.d.mts +0 -1
  120. package/dist/utils/index.d.mts.map +1 -1
  121. package/dist/utils/index.mjs +0 -1
  122. package/dist/utils/index.mjs.map +1 -1
  123. package/dist/utils/steps.cjs.map +1 -1
  124. package/dist/utils/steps.d.cts +1 -1
  125. package/dist/utils/steps.d.cts.map +1 -1
  126. package/dist/utils/steps.d.mts +1 -1
  127. package/dist/utils/steps.d.mts.map +1 -1
  128. package/dist/utils/steps.mjs.map +1 -1
  129. package/dist/webpack/compiler.cjs.map +1 -1
  130. package/dist/webpack/compiler.d.cts +2 -2
  131. package/dist/webpack/compiler.d.cts.map +1 -1
  132. package/dist/webpack/compiler.d.mts +2 -2
  133. package/dist/webpack/compiler.d.mts.map +1 -1
  134. package/dist/webpack/compiler.mjs.map +1 -1
  135. package/dist/webpack/config.cjs +1 -2
  136. package/dist/webpack/config.cjs.map +1 -1
  137. package/dist/webpack/config.d.cts +2 -2
  138. package/dist/webpack/config.d.cts.map +1 -1
  139. package/dist/webpack/config.d.mts +2 -2
  140. package/dist/webpack/config.d.mts.map +1 -1
  141. package/dist/webpack/config.mjs +1 -2
  142. package/dist/webpack/config.mjs.map +1 -1
  143. package/dist/webpack/loaders/function.cjs +7 -10
  144. package/dist/webpack/loaders/function.cjs.map +1 -1
  145. package/dist/webpack/loaders/function.d.cts +1 -0
  146. package/dist/webpack/loaders/function.d.cts.map +1 -1
  147. package/dist/webpack/loaders/function.d.mts +1 -0
  148. package/dist/webpack/loaders/function.d.mts.map +1 -1
  149. package/dist/webpack/loaders/function.mjs +6 -9
  150. package/dist/webpack/loaders/function.mjs.map +1 -1
  151. package/dist/webpack/loaders/index.cjs +1 -3
  152. package/dist/webpack/loaders/index.cjs.map +1 -1
  153. package/dist/webpack/loaders/index.d.cts +0 -1
  154. package/dist/webpack/loaders/index.d.cts.map +1 -1
  155. package/dist/webpack/loaders/index.d.mts +0 -1
  156. package/dist/webpack/loaders/index.d.mts.map +1 -1
  157. package/dist/webpack/loaders/index.mjs +0 -1
  158. package/dist/webpack/loaders/index.mjs.map +1 -1
  159. package/dist/webpack/loaders/wasm.cjs +0 -2
  160. package/dist/webpack/loaders/wasm.cjs.map +1 -1
  161. package/dist/webpack/loaders/wasm.d.cts.map +1 -1
  162. package/dist/webpack/loaders/wasm.d.mts.map +1 -1
  163. package/dist/webpack/loaders/wasm.mjs +0 -2
  164. package/dist/webpack/loaders/wasm.mjs.map +1 -1
  165. package/dist/webpack/plugins.cjs +15 -20
  166. package/dist/webpack/plugins.cjs.map +1 -1
  167. package/dist/webpack/plugins.d.cts +13 -3
  168. package/dist/webpack/plugins.d.cts.map +1 -1
  169. package/dist/webpack/plugins.d.mts +13 -3
  170. package/dist/webpack/plugins.d.mts.map +1 -1
  171. package/dist/webpack/plugins.mjs +4 -9
  172. package/dist/webpack/plugins.mjs.map +1 -1
  173. package/dist/webpack/utils.cjs +5 -21
  174. package/dist/webpack/utils.cjs.map +1 -1
  175. package/dist/webpack/utils.d.cts +6 -36
  176. package/dist/webpack/utils.d.cts.map +1 -1
  177. package/dist/webpack/utils.d.mts +6 -36
  178. package/dist/webpack/utils.d.mts.map +1 -1
  179. package/dist/webpack/utils.mjs +4 -18
  180. package/dist/webpack/utils.mjs.map +1 -1
  181. package/package.json +13 -38
  182. package/dist/commands/eval/__test__/browserify/bad/snap.config.cjs +0 -10
  183. package/dist/commands/eval/__test__/browserify/bad/snap.config.cjs.map +0 -1
  184. package/dist/commands/eval/__test__/browserify/bad/snap.config.d.cts +0 -4
  185. package/dist/commands/eval/__test__/browserify/bad/snap.config.d.cts.map +0 -1
  186. package/dist/commands/eval/__test__/browserify/bad/snap.config.d.mts +0 -4
  187. package/dist/commands/eval/__test__/browserify/bad/snap.config.d.mts.map +0 -1
  188. package/dist/commands/eval/__test__/browserify/bad/snap.config.mjs +0 -8
  189. package/dist/commands/eval/__test__/browserify/bad/snap.config.mjs.map +0 -1
  190. package/dist/commands/eval/__test__/browserify/good/snap.config.cjs +0 -10
  191. package/dist/commands/eval/__test__/browserify/good/snap.config.cjs.map +0 -1
  192. package/dist/commands/eval/__test__/browserify/good/snap.config.d.cts +0 -4
  193. package/dist/commands/eval/__test__/browserify/good/snap.config.d.cts.map +0 -1
  194. package/dist/commands/eval/__test__/browserify/good/snap.config.d.mts +0 -4
  195. package/dist/commands/eval/__test__/browserify/good/snap.config.d.mts.map +0 -1
  196. package/dist/commands/eval/__test__/browserify/good/snap.config.mjs +0 -8
  197. package/dist/commands/eval/__test__/browserify/good/snap.config.mjs.map +0 -1
  198. package/dist/utils/legacy.cjs +0 -53
  199. package/dist/utils/legacy.cjs.map +0 -1
  200. package/dist/utils/legacy.d.cts +0 -28
  201. package/dist/utils/legacy.d.cts.map +0 -1
  202. package/dist/utils/legacy.d.mts +0 -28
  203. package/dist/utils/legacy.d.mts.map +0 -1
  204. package/dist/utils/legacy.mjs +0 -47
  205. package/dist/utils/legacy.mjs.map +0 -1
  206. package/dist/webpack/loaders/browserify.cjs +0 -84
  207. package/dist/webpack/loaders/browserify.cjs.map +0 -1
  208. package/dist/webpack/loaders/browserify.d.cts +0 -18
  209. package/dist/webpack/loaders/browserify.d.cts.map +0 -1
  210. package/dist/webpack/loaders/browserify.d.mts +0 -18
  211. package/dist/webpack/loaders/browserify.d.mts.map +0 -1
  212. package/dist/webpack/loaders/browserify.mjs +0 -88
  213. package/dist/webpack/loaders/browserify.mjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"compiler.mjs","sourceRoot":"","sources":["../../src/webpack/compiler.ts"],"names":[],"mappings":";;AAIA,OAAO,EAAE,uBAAuB,EAAE,qBAAiB;AAEnD;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,MAA8B,EAC9B,OAAwB;IAExB,MAAM,iBAAiB,GAAG,MAAM,uBAAuB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACzE,MAAM,aAAa,GACjB,MAAM,CAAC,sBAAsB,EAAE,CAAC,iBAAiB,CAAC,IAAI,iBAAiB,CAAC;IAE1E,OAAO,OAAO,CAAC,aAAa,CAAC,CAAC;AAChC,CAAC","sourcesContent":["import { webpack } from 'webpack';\n\nimport type { ProcessedWebpackConfig } from '../config';\nimport type { WebpackOptions } from './config';\nimport { getDefaultConfiguration } from './config';\n\n/**\n * Get a Webpack compiler for the given config.\n *\n * @param config - The config object.\n * @param options - The Webpack options.\n * @returns The Webpack compiler.\n */\nexport async function getCompiler(\n config: ProcessedWebpackConfig,\n options?: WebpackOptions,\n) {\n const baseWebpackConfig = await getDefaultConfiguration(config, options);\n const webpackConfig =\n config.customizeWebpackConfig?.(baseWebpackConfig) ?? baseWebpackConfig;\n\n return webpack(webpackConfig);\n}\n"]}
1
+ {"version":3,"file":"compiler.mjs","sourceRoot":"","sources":["../../src/webpack/compiler.ts"],"names":[],"mappings":";;AAGA,OAAO,EAAE,uBAAuB,EAAE,qBAAiB;AAGnD;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,MAAuB,EACvB,OAAwB;IAExB,MAAM,iBAAiB,GAAG,MAAM,uBAAuB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACzE,MAAM,aAAa,GACjB,MAAM,CAAC,sBAAsB,EAAE,CAAC,iBAAiB,CAAC,IAAI,iBAAiB,CAAC;IAE1E,OAAO,OAAO,CAAC,aAAa,CAAC,CAAC;AAChC,CAAC","sourcesContent":["import { webpack } from 'webpack';\n\nimport type { WebpackOptions } from './config';\nimport { getDefaultConfiguration } from './config';\nimport type { ProcessedConfig } from '../config';\n\n/**\n * Get a Webpack compiler for the given config.\n *\n * @param config - The config object.\n * @param options - The Webpack options.\n * @returns The Webpack compiler.\n */\nexport async function getCompiler(\n config: ProcessedConfig,\n options?: WebpackOptions,\n) {\n const baseWebpackConfig = await getDefaultConfiguration(config, options);\n const webpackConfig =\n config.customizeWebpackConfig?.(baseWebpackConfig) ?? baseWebpackConfig;\n\n return webpack(webpackConfig);\n}\n"]}
@@ -35,8 +35,7 @@ async function getDefaultConfiguration(config, options = {
35
35
  evaluate: config.evaluate,
36
36
  }) {
37
37
  const spinnerText = options.spinner?.text;
38
- const builtInResolver = config.stats.builtIns &&
39
- new plugins_1.SnapsBuiltInResolver(config.stats.builtIns, options.spinner);
38
+ const builtInResolver = config.stats.builtIns && new plugins_1.SnapsBuiltInResolver(config.stats.builtIns);
40
39
  return {
41
40
  /**
42
41
  * The target is set to `browserslist` so that Webpack will compile the
@@ -1 +1 @@
1
- {"version":3,"file":"config.cjs","sourceRoot":"","sources":["../../src/webpack/config.ts"],"names":[],"mappings":";;;;;;AAAA,0FAAgE;AAChE,oGAAwE;AAExE,+BAA+B;AAC/B,kFAAiD;AAEjD,qCAAsE;AACtE,qEAA+D;AAG/D,iDAAoD;AACpD,2CAKmB;AACnB,uCAQiB;AAyBjB;;;;;;;;;;;;;;;;;GAiBG;AACI,KAAK,UAAU,uBAAuB,CAC3C,MAA8B,EAC9B,UAA0B;IACxB,QAAQ,EAAE,MAAM,CAAC,QAAQ;CAC1B;IAED,MAAM,WAAW,GAAG,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC;IAC1C,MAAM,eAAe,GACnB,MAAM,CAAC,KAAK,CAAC,QAAQ;QACrB,IAAI,8BAAoB,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IAEnE,OAAO;QACL;;;;;;;WAOG;QACH,MAAM,EAAE,gBAAgB,yBAAiB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eAGG;YACH,OAAO,EAAE,KAAK;YAEd;;eAEG;YACH,SAAS,EAAE;gBACT,IAAI,+BAAY,CAAC;oBACf,QAAQ,EAAE,IAAI;iBACf,CAAC;aACH;SACF;QAED;;;;;WAKG;QACH,WAAW,EAAE;YACX;;;;;eAKG;YACH,KAAK,EAAE,KAAK;SACb;QAED;;;;;WAKG;QACH,qBAAqB,EAAE;YACrB;;;eAGG;YACH,KAAK,EAAE,MAAM;SACd;KACF,CAAC;AACJ,CAAC;AA9WD,0DA8WC","sourcesContent":["import SnapsWebpackPlugin from '@metamask/snaps-webpack-plugin';\nimport ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';\nimport type { Ora } from 'ora';\nimport { resolve } from 'path';\nimport TerserPlugin from 'terser-webpack-plugin';\nimport type { Configuration } from 'webpack';\nimport { DefinePlugin, ProgressPlugin, ProvidePlugin } from 'webpack';\nimport { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';\n\nimport type { ProcessedWebpackConfig } from '../config';\nimport { getFunctionLoader, wasm } from './loaders';\nimport {\n SnapsBuiltInResolver,\n SnapsBundleWarningsPlugin,\n SnapsStatsPlugin,\n SnapsWatchPlugin,\n} from './plugins';\nimport {\n BROWSERSLIST_FILE,\n getDefaultLoader,\n getDevTool,\n getEnvironmentVariables,\n getFallbacks,\n getImageSVG,\n getProgressHandler,\n} from './utils';\n\nexport type WebpackOptions = {\n /**\n * Whether to analyze the bundle.\n */\n analyze?: boolean;\n\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 via assignment to module.exports.\n * We do this to mimic CommonJS, but still allow for usage of async initialization logic\n * via top level await.\n *\n * CommonJS is currently the only supported format for MetaMask Snaps.\n *\n * @see https://webpack.js.org/configuration/output/#outputlibrarytarget\n */\n type: 'assign',\n name: 'module.exports',\n },\n\n /**\n * The chunk format. This tells Webpack how to export chunks. This is\n * required because we use browserslist to target browsers, but Snaps are\n * not fully compatible with browser APIs (such as `window` and\n * `document`).\n *\n * @see https://webpack.js.org/configuration/output/#outputchunkformat\n */\n chunkFormat: 'commonjs',\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: /\\.(js|jsx|mjs|cjs|ts|tsx)$/u,\n exclude: /node_modules/u,\n use: await getDefaultLoader(config),\n },\n\n /**\n * This allows importing modules that uses `.js` and not `.mjs` for the\n * ES build.\n *\n * @see https://webpack.js.org/configuration/module/#resolvefullyspecified\n */\n {\n test: /\\.m?js$/u,\n resolve: {\n fullySpecified: false,\n },\n },\n\n /**\n * This allows importing `.svg` files as a string.\n */\n config.features.images && {\n test: /\\.svg$/u,\n // `asset/source` returns the source as a UTF-8 string.\n type: 'asset/source',\n },\n\n /**\n * This allows importing `.png` files as a data URL.\n */\n config.features.images && {\n test: /\\.png$/u,\n type: 'asset/inline',\n generator: {\n dataUrl: getImageSVG.bind(null, 'image/png'),\n },\n },\n\n /**\n * This allows importing `.jpe?g` files as a data URL.\n */\n config.features.images && {\n test: /\\.jpe?g$/u,\n type: 'asset/inline',\n generator: {\n dataUrl: getImageSVG.bind(null, 'image/jpeg'),\n },\n },\n\n config.experimental.wasm && {\n test: /\\.wasm$/u,\n use: getFunctionLoader(wasm, {}),\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 `.(c|m)?jsx?` and\n * `.tsx?` files.\n */\n extensions: ['.js', '.jsx', '.mjs', '.cjs', '.ts', '.tsx'],\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 `ForkTsCheckerWebpackPlugin` is a Webpack plugin that checks\n * Typescript type definitions, it does this in a separate process for speed.\n */\n config.typescript.enabled &&\n new ForkTsCheckerWebpackPlugin({\n typescript: {\n build: true,\n configFile: config.typescript.configFile,\n },\n }),\n\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 `DefinePlugin` is a Webpack plugin that adds static values to the\n * bundle. We use it to add the `NODE_DEBUG`, `NODE_ENV`, and `DEBUG`\n * environment variables, as well as any custom environment\n * variables (as `process.env`).\n */\n new DefinePlugin(getEnvironmentVariables(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 builtInResolver,\n builtIns: Boolean(config.stats.builtIns),\n buffer: config.stats.buffer,\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 options.analyze &&\n new BundleAnalyzerPlugin({\n analyzerPort: 0,\n logLevel: 'silent',\n openAnalyzer: false,\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 * We disable the nodeEnv optimization as we already add process.NODE_ENV\n * via the DefinePlugin in the section above this.\n */\n nodeEnv: false,\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 performance configuration. This tells Webpack how to handle\n * performance hints.\n *\n * @see https://webpack.js.org/configuration/performance/\n */\n performance: {\n /**\n * The hints to show. We set it to `false`, so that we don't get\n * performance hints, as they are not relevant for Snaps.\n *\n * @see https://webpack.js.org/configuration/performance/#performancehints\n */\n hints: false,\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"]}
1
+ {"version":3,"file":"config.cjs","sourceRoot":"","sources":["../../src/webpack/config.ts"],"names":[],"mappings":";;;;;;AAAA,0FAAgE;AAChE,oGAAwE;AAExE,+BAA+B;AAC/B,kFAAiD;AAEjD,qCAAsE;AACtE,qEAA+D;AAE/D,iDAAoD;AACpD,2CAKmB;AACnB,uCAQiB;AA0BjB;;;;;;;;;;;;;;;;;GAiBG;AACI,KAAK,UAAU,uBAAuB,CAC3C,MAAuB,EACvB,UAA0B;IACxB,QAAQ,EAAE,MAAM,CAAC,QAAQ;CAC1B;IAED,MAAM,WAAW,GAAG,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC;IAC1C,MAAM,eAAe,GACnB,MAAM,CAAC,KAAK,CAAC,QAAQ,IAAI,IAAI,8BAAoB,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAE3E,OAAO;QACL;;;;;;;WAOG;QACH,MAAM,EAAE,gBAAgB,yBAAiB,EAAE;QAE3C;;;;;WAKG;QACH,IAAI,EAAE,YAAY;QAElB;;;;WAIG;QACH,KAAK,EAAE,MAAM,CAAC,KAAK;QAEnB;;;;;WAKG;QACH,OAAO,EAAE,IAAA,kBAAU,EAAC,MAAM,CAAC,SAAS,CAAC;QAErC;;;;;;WAMG;QACH,KAAK,EAAE,MAAM;QAEb;;;;WAIG;QACH,MAAM,EAAE;YACN;;;;;;eAMG;YACH,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK;YAE1B;;;;;eAKG;YACH,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,QAAQ;YAEhC;;;;;eAKG;YACH,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI;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ACX,IAAI,0BAAgB,CAClB;oBACE,MAAM,EAAE,IAAA,cAAO,EAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC;oBAC3D,QAAQ,EAAE,OAAO,CAAC,QAAQ;oBAC1B,KAAK,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;iBAC9B,EACD,OAAO,CAAC,OAAO,CAChB;YAEH,OAAO,CAAC,OAAO;gBACb,IAAI,8CAAoB,CAAC;oBACvB,YAAY,EAAE,CAAC;oBACf,QAAQ,EAAE,QAAQ;oBAClB,YAAY,EAAE,KAAK;iBACpB,CAAC;YAEJ;;;eAGG;YACH,CAAC,MAAM,CAAC,SAAS,KAAK,IAAI;gBACxB,CAAC,MAAM,CAAC,SAAS,KAAK,KAAK,IAAI,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;gBACxD,IAAI,uBAAa,CAAC;oBAChB,MAAM,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC;iBAC7B,CAAC;SACL,CAAC,MAAM,CAAC,OAAO,CAAC;QAEjB;;;;WAIG;QACH,YAAY,EAAE;YACZ,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,QAAQ;YAEhC;;;eAGG;YACH,OAAO,EAAE,KAAK;YAEd;;eAEG;YACH,SAAS,EAAE;gBACT,IAAI,+BAAY,CAAC;oBACf,QAAQ,EAAE,IAAI;iBACf,CAAC;aACH;SACF;QAED;;;;;WAKG;QACH,WAAW,EAAE;YACX;;;;;eAKG;YACH,KAAK,EAAE,KAAK;SACb;QAED;;;;;WAKG;QACH,qBAAqB,EAAE;YACrB;;;eAGG;YACH,KAAK,EAAE,MAAM;SACd;KACF,CAAC;AACJ,CAAC;AA7WD,0DA6WC","sourcesContent":["import SnapsWebpackPlugin from '@metamask/snaps-webpack-plugin';\nimport ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';\nimport type { Ora } from 'ora';\nimport { resolve } from 'path';\nimport TerserPlugin from 'terser-webpack-plugin';\nimport type { Configuration } from 'webpack';\nimport { DefinePlugin, ProgressPlugin, ProvidePlugin } from 'webpack';\nimport { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';\n\nimport { getFunctionLoader, wasm } from './loaders';\nimport {\n SnapsBuiltInResolver,\n SnapsBundleWarningsPlugin,\n SnapsStatsPlugin,\n SnapsWatchPlugin,\n} from './plugins';\nimport {\n BROWSERSLIST_FILE,\n getDefaultLoader,\n getDevTool,\n getEnvironmentVariables,\n getFallbacks,\n getImageSVG,\n getProgressHandler,\n} from './utils';\nimport type { ProcessedConfig } from '../config';\n\nexport type WebpackOptions = {\n /**\n * Whether to analyze the bundle.\n */\n analyze?: boolean;\n\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: ProcessedConfig,\n options: WebpackOptions = {\n evaluate: config.evaluate,\n },\n): Promise<Configuration> {\n const spinnerText = options.spinner?.text;\n const builtInResolver =\n config.stats.builtIns && new SnapsBuiltInResolver(config.stats.builtIns);\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 via assignment to module.exports.\n * We do this to mimic CommonJS, but still allow for usage of async initialization logic\n * via top level await.\n *\n * CommonJS is currently the only supported format for MetaMask Snaps.\n *\n * @see https://webpack.js.org/configuration/output/#outputlibrarytarget\n */\n type: 'assign',\n name: 'module.exports',\n },\n\n /**\n * The chunk format. This tells Webpack how to export chunks. This is\n * required because we use browserslist to target browsers, but Snaps are\n * not fully compatible with browser APIs (such as `window` and\n * `document`).\n *\n * @see https://webpack.js.org/configuration/output/#outputchunkformat\n */\n chunkFormat: 'commonjs',\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: /\\.(js|jsx|mjs|cjs|ts|tsx)$/u,\n exclude: /node_modules/u,\n use: await getDefaultLoader(config),\n },\n\n /**\n * This allows importing modules that uses `.js` and not `.mjs` for the\n * ES build.\n *\n * @see https://webpack.js.org/configuration/module/#resolvefullyspecified\n */\n {\n test: /\\.m?js$/u,\n resolve: {\n fullySpecified: false,\n },\n },\n\n /**\n * This allows importing `.svg` files as a string.\n */\n config.features.images && {\n test: /\\.svg$/u,\n // `asset/source` returns the source as a UTF-8 string.\n type: 'asset/source',\n },\n\n /**\n * This allows importing `.png` files as a data URL.\n */\n config.features.images && {\n test: /\\.png$/u,\n type: 'asset/inline',\n generator: {\n dataUrl: getImageSVG.bind(null, 'image/png'),\n },\n },\n\n /**\n * This allows importing `.jpe?g` files as a data URL.\n */\n config.features.images && {\n test: /\\.jpe?g$/u,\n type: 'asset/inline',\n generator: {\n dataUrl: getImageSVG.bind(null, 'image/jpeg'),\n },\n },\n\n config.experimental.wasm && {\n test: /\\.wasm$/u,\n use: getFunctionLoader(wasm, {}),\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 `.(c|m)?jsx?` and\n * `.tsx?` files.\n */\n extensions: ['.js', '.jsx', '.mjs', '.cjs', '.ts', '.tsx'],\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 `ForkTsCheckerWebpackPlugin` is a Webpack plugin that checks\n * Typescript type definitions, it does this in a separate process for speed.\n */\n config.typescript.enabled &&\n new ForkTsCheckerWebpackPlugin({\n typescript: {\n build: true,\n configFile: config.typescript.configFile,\n },\n }),\n\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 `DefinePlugin` is a Webpack plugin that adds static values to the\n * bundle. We use it to add the `NODE_DEBUG`, `NODE_ENV`, and `DEBUG`\n * environment variables, as well as any custom environment\n * variables (as `process.env`).\n */\n new DefinePlugin(getEnvironmentVariables(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 builtInResolver,\n builtIns: Boolean(config.stats.builtIns),\n buffer: config.stats.buffer,\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 options.analyze &&\n new BundleAnalyzerPlugin({\n analyzerPort: 0,\n logLevel: 'silent',\n openAnalyzer: false,\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 * We disable the nodeEnv optimization as we already add process.NODE_ENV\n * via the DefinePlugin in the section above this.\n */\n nodeEnv: false,\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 performance configuration. This tells Webpack how to handle\n * performance hints.\n *\n * @see https://webpack.js.org/configuration/performance/\n */\n performance: {\n /**\n * The hints to show. We set it to `false`, so that we don't get\n * performance hints, as they are not relevant for Snaps.\n *\n * @see https://webpack.js.org/configuration/performance/#performancehints\n */\n hints: false,\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"]}
@@ -1,6 +1,6 @@
1
1
  import type { Ora } from "ora/index.js";
2
2
  import type { Configuration } from "webpack";
3
- import type { ProcessedWebpackConfig } from "../config.cjs";
3
+ import type { ProcessedConfig } from "../config.cjs";
4
4
  export type WebpackOptions = {
5
5
  /**
6
6
  * Whether to analyze the bundle.
@@ -38,5 +38,5 @@ export type WebpackOptions = {
38
38
  * @param options - The Webpack options.
39
39
  * @returns The default Webpack configuration.
40
40
  */
41
- export declare function getDefaultConfiguration(config: ProcessedWebpackConfig, options?: WebpackOptions): Promise<Configuration>;
41
+ export declare function getDefaultConfiguration(config: ProcessedConfig, options?: WebpackOptions): Promise<Configuration>;
42
42
  //# sourceMappingURL=config.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.cts","sourceRoot":"","sources":["../../src/webpack/config.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,qBAAY;AAG/B,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB;AAI7C,OAAO,KAAK,EAAE,sBAAsB,EAAE,sBAAkB;AAkBxD,MAAM,MAAM,cAAc,GAAG;IAC3B;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;OAEG;IACH,OAAO,CAAC,EAAE,GAAG,CAAC;CACf,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,uBAAuB,CAC3C,MAAM,EAAE,sBAAsB,EAC9B,OAAO,GAAE,cAER,GACA,OAAO,CAAC,aAAa,CAAC,CAyWxB"}
1
+ {"version":3,"file":"config.d.cts","sourceRoot":"","sources":["../../src/webpack/config.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,qBAAY;AAG/B,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB;AAoB7C,OAAO,KAAK,EAAE,eAAe,EAAE,sBAAkB;AAEjD,MAAM,MAAM,cAAc,GAAG;IAC3B;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;OAEG;IACH,OAAO,CAAC,EAAE,GAAG,CAAC;CACf,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,uBAAuB,CAC3C,MAAM,EAAE,eAAe,EACvB,OAAO,GAAE,cAER,GACA,OAAO,CAAC,aAAa,CAAC,CAwWxB"}
@@ -1,6 +1,6 @@
1
1
  import type { Ora } from "ora/index.js";
2
2
  import type { Configuration } from "webpack";
3
- import type { ProcessedWebpackConfig } from "../config.mjs";
3
+ import type { ProcessedConfig } from "../config.mjs";
4
4
  export type WebpackOptions = {
5
5
  /**
6
6
  * Whether to analyze the bundle.
@@ -38,5 +38,5 @@ export type WebpackOptions = {
38
38
  * @param options - The Webpack options.
39
39
  * @returns The default Webpack configuration.
40
40
  */
41
- export declare function getDefaultConfiguration(config: ProcessedWebpackConfig, options?: WebpackOptions): Promise<Configuration>;
41
+ export declare function getDefaultConfiguration(config: ProcessedConfig, options?: WebpackOptions): Promise<Configuration>;
42
42
  //# sourceMappingURL=config.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.mts","sourceRoot":"","sources":["../../src/webpack/config.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,qBAAY;AAG/B,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB;AAI7C,OAAO,KAAK,EAAE,sBAAsB,EAAE,sBAAkB;AAkBxD,MAAM,MAAM,cAAc,GAAG;IAC3B;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;OAEG;IACH,OAAO,CAAC,EAAE,GAAG,CAAC;CACf,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,uBAAuB,CAC3C,MAAM,EAAE,sBAAsB,EAC9B,OAAO,GAAE,cAER,GACA,OAAO,CAAC,aAAa,CAAC,CAyWxB"}
1
+ {"version":3,"file":"config.d.mts","sourceRoot":"","sources":["../../src/webpack/config.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,qBAAY;AAG/B,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB;AAoB7C,OAAO,KAAK,EAAE,eAAe,EAAE,sBAAkB;AAEjD,MAAM,MAAM,cAAc,GAAG;IAC3B;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;OAEG;IACH,OAAO,CAAC,EAAE,GAAG,CAAC;CACf,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,uBAAuB,CAC3C,MAAM,EAAE,eAAe,EACvB,OAAO,GAAE,cAER,GACA,OAAO,CAAC,aAAa,CAAC,CAwWxB"}
@@ -38,8 +38,7 @@ export async function getDefaultConfiguration(config, options = {
38
38
  evaluate: config.evaluate,
39
39
  }) {
40
40
  const spinnerText = options.spinner?.text;
41
- const builtInResolver = config.stats.builtIns &&
42
- new SnapsBuiltInResolver(config.stats.builtIns, options.spinner);
41
+ const builtInResolver = config.stats.builtIns && new SnapsBuiltInResolver(config.stats.builtIns);
43
42
  return {
44
43
  /**
45
44
  * The target is set to `browserslist` so that Webpack will compile the
@@ -1 +1 @@
1
- {"version":3,"file":"config.mjs","sourceRoot":"","sources":["../../src/webpack/config.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,kBAAkB,uCAAuC;AAChE,OAAO,2BAA0B,uCAAuC;;AAExE,OAAO,EAAE,OAAO,EAAE,aAAa;AAC/B,OAAO,aAAY,8BAA8B;;;;AAGjD,OAAO,EAAE,oBAAoB,EAAE,gCAAgC;AAG/D,OAAO,EAAE,iBAAiB,EAAE,IAAI,EAAE,4BAAkB;AACpD,OAAO,EACL,oBAAoB,EACpB,yBAAyB,EACzB,gBAAgB,EAChB,gBAAgB,EACjB,sBAAkB;AACnB,OAAO,EACL,iBAAiB,E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;oBACvB,YAAY,EAAE,CAAC;oBACf,QAAQ,EAAE,QAAQ;oBAClB,YAAY,EAAE,KAAK;iBACpB,CAAC;YAEJ;;;eAGG;YACH,CAAC,MAAM,CAAC,SAAS,KAAK,IAAI;gBACxB,CAAC,MAAM,CAAC,SAAS,KAAK,KAAK,IAAI,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;gBACxD,IAAI,aAAa,CAAC;oBAChB,MAAM,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC;iBAC7B,CAAC;SACL,CAAC,MAAM,CAAC,OAAO,CAAC;QAEjB;;;;WAIG;QACH,YAAY,EAAE;YACZ,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,QAAQ;YAEhC;;;eAGG;YACH,OAAO,EAAE,KAAK;YAEd;;eAEG;YACH,SAAS,EAAE;gBACT,IAAI,YAAY,CAAC;oBACf,QAAQ,EAAE,IAAI;iBACf,CAAC;aACH;SACF;QAED;;;;;WAKG;QACH,WAAW,EAAE;YACX;;;;;eAKG;YACH,KAAK,EAAE,KAAK;SACb;QAED;;;;;WAKG;QACH,qBAAqB,EAAE;YACrB;;;eAGG;YACH,KAAK,EAAE,MAAM;SACd;KACF,CAAC;AACJ,CAAC","sourcesContent":["import SnapsWebpackPlugin from '@metamask/snaps-webpack-plugin';\nimport ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';\nimport type { Ora } from 'ora';\nimport { resolve } from 'path';\nimport TerserPlugin from 'terser-webpack-plugin';\nimport type { Configuration } from 'webpack';\nimport { DefinePlugin, ProgressPlugin, ProvidePlugin } from 'webpack';\nimport { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';\n\nimport type { ProcessedWebpackConfig } from '../config';\nimport { getFunctionLoader, wasm } from './loaders';\nimport {\n SnapsBuiltInResolver,\n SnapsBundleWarningsPlugin,\n SnapsStatsPlugin,\n SnapsWatchPlugin,\n} from './plugins';\nimport {\n BROWSERSLIST_FILE,\n getDefaultLoader,\n getDevTool,\n getEnvironmentVariables,\n getFallbacks,\n getImageSVG,\n getProgressHandler,\n} from './utils';\n\nexport type WebpackOptions = {\n /**\n * Whether to analyze the bundle.\n */\n analyze?: boolean;\n\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 via assignment to module.exports.\n * We do this to mimic CommonJS, but still allow for usage of async initialization logic\n * via top level await.\n *\n * CommonJS is currently the only supported format for MetaMask Snaps.\n *\n * @see https://webpack.js.org/configuration/output/#outputlibrarytarget\n */\n type: 'assign',\n name: 'module.exports',\n },\n\n /**\n * The chunk format. This tells Webpack how to export chunks. This is\n * required because we use browserslist to target browsers, but Snaps are\n * not fully compatible with browser APIs (such as `window` and\n * `document`).\n *\n * @see https://webpack.js.org/configuration/output/#outputchunkformat\n */\n chunkFormat: 'commonjs',\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: /\\.(js|jsx|mjs|cjs|ts|tsx)$/u,\n exclude: /node_modules/u,\n use: await getDefaultLoader(config),\n },\n\n /**\n * This allows importing modules that uses `.js` and not `.mjs` for the\n * ES build.\n *\n * @see https://webpack.js.org/configuration/module/#resolvefullyspecified\n */\n {\n test: /\\.m?js$/u,\n resolve: {\n fullySpecified: false,\n },\n },\n\n /**\n * This allows importing `.svg` files as a string.\n */\n config.features.images && {\n test: /\\.svg$/u,\n // `asset/source` returns the source as a UTF-8 string.\n type: 'asset/source',\n },\n\n /**\n * This allows importing `.png` files as a data URL.\n */\n config.features.images && {\n test: /\\.png$/u,\n type: 'asset/inline',\n generator: {\n dataUrl: getImageSVG.bind(null, 'image/png'),\n },\n },\n\n /**\n * This allows importing `.jpe?g` files as a data URL.\n */\n config.features.images && {\n test: /\\.jpe?g$/u,\n type: 'asset/inline',\n generator: {\n dataUrl: getImageSVG.bind(null, 'image/jpeg'),\n },\n },\n\n config.experimental.wasm && {\n test: /\\.wasm$/u,\n use: getFunctionLoader(wasm, {}),\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 `.(c|m)?jsx?` and\n * `.tsx?` files.\n */\n extensions: ['.js', '.jsx', '.mjs', '.cjs', '.ts', '.tsx'],\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 `ForkTsCheckerWebpackPlugin` is a Webpack plugin that checks\n * Typescript type definitions, it does this in a separate process for speed.\n */\n config.typescript.enabled &&\n new ForkTsCheckerWebpackPlugin({\n typescript: {\n build: true,\n configFile: config.typescript.configFile,\n },\n }),\n\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 `DefinePlugin` is a Webpack plugin that adds static values to the\n * bundle. We use it to add the `NODE_DEBUG`, `NODE_ENV`, and `DEBUG`\n * environment variables, as well as any custom environment\n * variables (as `process.env`).\n */\n new DefinePlugin(getEnvironmentVariables(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 builtInResolver,\n builtIns: Boolean(config.stats.builtIns),\n buffer: config.stats.buffer,\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 options.analyze &&\n new BundleAnalyzerPlugin({\n analyzerPort: 0,\n logLevel: 'silent',\n openAnalyzer: false,\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 * We disable the nodeEnv optimization as we already add process.NODE_ENV\n * via the DefinePlugin in the section above this.\n */\n nodeEnv: false,\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 performance configuration. This tells Webpack how to handle\n * performance hints.\n *\n * @see https://webpack.js.org/configuration/performance/\n */\n performance: {\n /**\n * The hints to show. We set it to `false`, so that we don't get\n * performance hints, as they are not relevant for Snaps.\n *\n * @see https://webpack.js.org/configuration/performance/#performancehints\n */\n hints: false,\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"]}
1
+ {"version":3,"file":"config.mjs","sourceRoot":"","sources":["../../src/webpack/config.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,kBAAkB,uCAAuC;AAChE,OAAO,2BAA0B,uCAAuC;;AAExE,OAAO,EAAE,OAAO,EAAE,aAAa;AAC/B,OAAO,aAAY,8BAA8B;;;;AAGjD,OAAO,EAAE,oBAAoB,EAAE,gCAAgC;AAE/D,OAAO,EAAE,iBAAiB,EAAE,IAAI,EAAE,4BAAkB;AACpD,OAAO,EACL,oBAAoB,EACpB,yBAAyB,EACzB,gBAAgB,EAChB,gBAAgB,EACjB,sBAAkB;AACnB,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,UAAU,EACV,uBAAuB,EACvB,YAAY,EACZ,WAAW,EACX,kBAAkB,EACnB,oBAAgB;AA0BjB;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,MAAuB,EACvB,UAA0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S,CAAC,MAAM,CAAC,CAAC;gBACxD,IAAI,aAAa,CAAC;oBAChB,MAAM,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC;iBAC7B,CAAC;SACL,CAAC,MAAM,CAAC,OAAO,CAAC;QAEjB;;;;WAIG;QACH,YAAY,EAAE;YACZ,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,QAAQ;YAEhC;;;eAGG;YACH,OAAO,EAAE,KAAK;YAEd;;eAEG;YACH,SAAS,EAAE;gBACT,IAAI,YAAY,CAAC;oBACf,QAAQ,EAAE,IAAI;iBACf,CAAC;aACH;SACF;QAED;;;;;WAKG;QACH,WAAW,EAAE;YACX;;;;;eAKG;YACH,KAAK,EAAE,KAAK;SACb;QAED;;;;;WAKG;QACH,qBAAqB,EAAE;YACrB;;;eAGG;YACH,KAAK,EAAE,MAAM;SACd;KACF,CAAC;AACJ,CAAC","sourcesContent":["import SnapsWebpackPlugin from '@metamask/snaps-webpack-plugin';\nimport ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';\nimport type { Ora } from 'ora';\nimport { resolve } from 'path';\nimport TerserPlugin from 'terser-webpack-plugin';\nimport type { Configuration } from 'webpack';\nimport { DefinePlugin, ProgressPlugin, ProvidePlugin } from 'webpack';\nimport { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';\n\nimport { getFunctionLoader, wasm } from './loaders';\nimport {\n SnapsBuiltInResolver,\n SnapsBundleWarningsPlugin,\n SnapsStatsPlugin,\n SnapsWatchPlugin,\n} from './plugins';\nimport {\n BROWSERSLIST_FILE,\n getDefaultLoader,\n getDevTool,\n getEnvironmentVariables,\n getFallbacks,\n getImageSVG,\n getProgressHandler,\n} from './utils';\nimport type { ProcessedConfig } from '../config';\n\nexport type WebpackOptions = {\n /**\n * Whether to analyze the bundle.\n */\n analyze?: boolean;\n\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: ProcessedConfig,\n options: WebpackOptions = {\n evaluate: config.evaluate,\n },\n): Promise<Configuration> {\n const spinnerText = options.spinner?.text;\n const builtInResolver =\n config.stats.builtIns && new SnapsBuiltInResolver(config.stats.builtIns);\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 via assignment to module.exports.\n * We do this to mimic CommonJS, but still allow for usage of async initialization logic\n * via top level await.\n *\n * CommonJS is currently the only supported format for MetaMask Snaps.\n *\n * @see https://webpack.js.org/configuration/output/#outputlibrarytarget\n */\n type: 'assign',\n name: 'module.exports',\n },\n\n /**\n * The chunk format. This tells Webpack how to export chunks. This is\n * required because we use browserslist to target browsers, but Snaps are\n * not fully compatible with browser APIs (such as `window` and\n * `document`).\n *\n * @see https://webpack.js.org/configuration/output/#outputchunkformat\n */\n chunkFormat: 'commonjs',\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: /\\.(js|jsx|mjs|cjs|ts|tsx)$/u,\n exclude: /node_modules/u,\n use: await getDefaultLoader(config),\n },\n\n /**\n * This allows importing modules that uses `.js` and not `.mjs` for the\n * ES build.\n *\n * @see https://webpack.js.org/configuration/module/#resolvefullyspecified\n */\n {\n test: /\\.m?js$/u,\n resolve: {\n fullySpecified: false,\n },\n },\n\n /**\n * This allows importing `.svg` files as a string.\n */\n config.features.images && {\n test: /\\.svg$/u,\n // `asset/source` returns the source as a UTF-8 string.\n type: 'asset/source',\n },\n\n /**\n * This allows importing `.png` files as a data URL.\n */\n config.features.images && {\n test: /\\.png$/u,\n type: 'asset/inline',\n generator: {\n dataUrl: getImageSVG.bind(null, 'image/png'),\n },\n },\n\n /**\n * This allows importing `.jpe?g` files as a data URL.\n */\n config.features.images && {\n test: /\\.jpe?g$/u,\n type: 'asset/inline',\n generator: {\n dataUrl: getImageSVG.bind(null, 'image/jpeg'),\n },\n },\n\n config.experimental.wasm && {\n test: /\\.wasm$/u,\n use: getFunctionLoader(wasm, {}),\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 `.(c|m)?jsx?` and\n * `.tsx?` files.\n */\n extensions: ['.js', '.jsx', '.mjs', '.cjs', '.ts', '.tsx'],\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 `ForkTsCheckerWebpackPlugin` is a Webpack plugin that checks\n * Typescript type definitions, it does this in a separate process for speed.\n */\n config.typescript.enabled &&\n new ForkTsCheckerWebpackPlugin({\n typescript: {\n build: true,\n configFile: config.typescript.configFile,\n },\n }),\n\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 `DefinePlugin` is a Webpack plugin that adds static values to the\n * bundle. We use it to add the `NODE_DEBUG`, `NODE_ENV`, and `DEBUG`\n * environment variables, as well as any custom environment\n * variables (as `process.env`).\n */\n new DefinePlugin(getEnvironmentVariables(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 builtInResolver,\n builtIns: Boolean(config.stats.builtIns),\n buffer: config.stats.buffer,\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 options.analyze &&\n new BundleAnalyzerPlugin({\n analyzerPort: 0,\n logLevel: 'silent',\n openAnalyzer: false,\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 * We disable the nodeEnv optimization as we already add process.NODE_ENV\n * via the DefinePlugin in the section above this.\n */\n nodeEnv: false,\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 performance configuration. This tells Webpack how to handle\n * performance hints.\n *\n * @see https://webpack.js.org/configuration/performance/\n */\n performance: {\n /**\n * The hints to show. We set it to `false`, so that we don't get\n * performance hints, as they are not relevant for Snaps.\n *\n * @see https://webpack.js.org/configuration/performance/#performancehints\n */\n hints: false,\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"]}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getFunctionLoader = void 0;
3
+ exports.getFunctionLoader = exports.raw = void 0;
4
4
  /**
5
5
  * A loader that executes a function. See {@link getFunctionLoader} for more
6
6
  * information.
@@ -8,11 +8,17 @@ exports.getFunctionLoader = void 0;
8
8
  * @param content - The input file contents as a `Uint8Array`.
9
9
  * @returns The output of the function.
10
10
  */
11
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
12
+ // eslint-disable-next-line @typescript-eslint/promise-function-async
11
13
  const loader = function (content) {
12
14
  const { fn } = this.getOptions();
13
15
  return fn.bind(this)(content);
14
16
  };
15
17
  exports.default = loader;
18
+ // By setting `raw` to `true`, we are telling Webpack to provide the source as a
19
+ // `Uint8Array` instead of converting it to a string. This allows us to avoid
20
+ // having to convert the source back to a `Uint8Array` in the loader.
21
+ exports.raw = true;
16
22
  /**
17
23
  * Get a loader that executes the given function. This is useful for executing
18
24
  * loaders without needing to pass a file to Webpack.
@@ -33,13 +39,4 @@ function getFunctionLoader(fn, options) {
33
39
  };
34
40
  }
35
41
  exports.getFunctionLoader = getFunctionLoader;
36
- // When running as CJS, we need to export the loader as a default export, since
37
- // `tsup` exports it as `loader_default`.
38
- // istanbul ignore next 3
39
- // eslint-disable-next-line n/no-process-env
40
- if (typeof module !== 'undefined' && process?.env?.NODE_ENV !== 'test') {
41
- module.exports = loader;
42
- module.exports.getFunctionLoader = getFunctionLoader;
43
- module.exports.raw = true;
44
- }
45
42
  //# sourceMappingURL=function.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"function.cjs","sourceRoot":"","sources":["../../../src/webpack/loaders/function.ts"],"names":[],"mappings":";;;AAaA;;;;;;GAMG;AACH,MAAM,MAAM,GAAoD,UAC9D,OAAO;IAEP,MAAM,EAAE,EAAE,EAAE,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;IACjC,OAAO,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC;AAChC,CAAC,CAAC;AAEF,kBAAe,MAAM,CAAC;AAEtB;;;;;;;GAOG;AACH,SAAgB,iBAAiB,CAC/B,EAAqC,EACrC,OAAgB;IAEhB,OAAO;QACL,2EAA2E;QAC3E,sDAAsD;QACtD,MAAM,EAAE,UAAU;QAClB,OAAO,EAAE;YACP,EAAE;YACF,GAAG,OAAO;SACX;KACF,CAAC;AACJ,CAAC;AAbD,8CAaC;AAED,+EAA+E;AAC/E,yCAAyC;AACzC,yBAAyB;AACzB,4CAA4C;AAC5C,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,EAAE,GAAG,EAAE,QAAQ,KAAK,MAAM,EAAE,CAAC;IACvE,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,MAAM,CAAC,OAAO,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;IACrD,MAAM,CAAC,OAAO,CAAC,GAAG,GAAG,IAAI,CAAC;AAC5B,CAAC","sourcesContent":["import type { LoaderDefinitionFunction } from 'webpack';\n\n/**\n * Options for the function loader.\n */\nexport type FunctionLoaderOptions = {\n /**\n * The function to execute. This is bound to the loader context, so it can\n * access the loader options and other properties.\n */\n fn: LoaderDefinitionFunction;\n};\n\n/**\n * A loader that executes a function. See {@link getFunctionLoader} for more\n * information.\n *\n * @param content - The input file contents as a `Uint8Array`.\n * @returns The output of the function.\n */\nconst loader: LoaderDefinitionFunction<FunctionLoaderOptions> = function (\n content,\n) {\n const { fn } = this.getOptions();\n return fn.bind(this)(content);\n};\n\nexport default loader;\n\n/**\n * Get a loader that executes the given function. This is useful for executing\n * loaders without needing to pass a file to Webpack.\n *\n * @param fn - The function to execute.\n * @param options - The options to pass to the loader.\n * @returns The loader definition.\n */\nexport function getFunctionLoader<Options>(\n fn: LoaderDefinitionFunction<Options>,\n options: Options,\n) {\n return {\n // We use `__filename` as the loader, so Webpack will execute the loader in\n // this file, with the actual function in the options.\n loader: __filename,\n options: {\n fn,\n ...options,\n },\n };\n}\n\n// When running as CJS, we need to export the loader as a default export, since\n// `tsup` exports it as `loader_default`.\n// istanbul ignore next 3\n// eslint-disable-next-line n/no-process-env\nif (typeof module !== 'undefined' && process?.env?.NODE_ENV !== 'test') {\n module.exports = loader;\n module.exports.getFunctionLoader = getFunctionLoader;\n module.exports.raw = true;\n}\n"]}
1
+ {"version":3,"file":"function.cjs","sourceRoot":"","sources":["../../../src/webpack/loaders/function.ts"],"names":[],"mappings":";;;AAaA;;;;;;GAMG;AACH,gFAAgF;AAChF,qEAAqE;AACrE,MAAM,MAAM,GAAoD,UAC9D,OAAO;IAEP,MAAM,EAAE,EAAE,EAAE,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;IACjC,OAAO,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC;AAChC,CAAC,CAAC;AAEF,kBAAe,MAAM,CAAC;AAEtB,gFAAgF;AAChF,6EAA6E;AAC7E,qEAAqE;AACxD,QAAA,GAAG,GAAG,IAAI,CAAC;AAExB;;;;;;;GAOG;AACH,SAAgB,iBAAiB,CAC/B,EAAqC,EACrC,OAAgB;IAEhB,OAAO;QACL,2EAA2E;QAC3E,sDAAsD;QACtD,MAAM,EAAE,UAAU;QAClB,OAAO,EAAE;YACP,EAAE;YACF,GAAG,OAAO;SACX;KACF,CAAC;AACJ,CAAC;AAbD,8CAaC","sourcesContent":["import type { LoaderDefinitionFunction } from 'webpack';\n\n/**\n * Options for the function loader.\n */\nexport type FunctionLoaderOptions = {\n /**\n * The function to execute. This is bound to the loader context, so it can\n * access the loader options and other properties.\n */\n fn: LoaderDefinitionFunction;\n};\n\n/**\n * A loader that executes a function. See {@link getFunctionLoader} for more\n * information.\n *\n * @param content - The input file contents as a `Uint8Array`.\n * @returns The output of the function.\n */\n// TODO: Either fix this lint violation or explain why it's necessary to ignore.\n// eslint-disable-next-line @typescript-eslint/promise-function-async\nconst loader: LoaderDefinitionFunction<FunctionLoaderOptions> = function (\n content,\n) {\n const { fn } = this.getOptions();\n return fn.bind(this)(content);\n};\n\nexport default loader;\n\n// By setting `raw` to `true`, we are telling Webpack to provide the source as a\n// `Uint8Array` instead of converting it to a string. This allows us to avoid\n// having to convert the source back to a `Uint8Array` in the loader.\nexport const raw = true;\n\n/**\n * Get a loader that executes the given function. This is useful for executing\n * loaders without needing to pass a file to Webpack.\n *\n * @param fn - The function to execute.\n * @param options - The options to pass to the loader.\n * @returns The loader definition.\n */\nexport function getFunctionLoader<Options>(\n fn: LoaderDefinitionFunction<Options>,\n options: Options,\n) {\n return {\n // We use `__filename` as the loader, so Webpack will execute the loader in\n // this file, with the actual function in the options.\n loader: __filename,\n options: {\n fn,\n ...options,\n },\n };\n}\n"]}
@@ -18,6 +18,7 @@ export type FunctionLoaderOptions = {
18
18
  */
19
19
  declare const loader: LoaderDefinitionFunction<FunctionLoaderOptions>;
20
20
  export default loader;
21
+ export declare const raw = true;
21
22
  /**
22
23
  * Get a loader that executes the given function. This is useful for executing
23
24
  * loaders without needing to pass a file to Webpack.
@@ -1 +1 @@
1
- {"version":3,"file":"function.d.cts","sourceRoot":"","sources":["../../../src/webpack/loaders/function.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,gBAAgB;AAExD;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC;;;OAGG;IACH,EAAE,EAAE,wBAAwB,CAAC;CAC9B,CAAC;AAEF;;;;;;GAMG;AACH,QAAA,MAAM,MAAM,EAAE,wBAAwB,CAAC,qBAAqB,CAK3D,CAAC;AAEF,eAAe,MAAM,CAAC;AAEtB;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EACvC,EAAE,EAAE,wBAAwB,CAAC,OAAO,CAAC,EACrC,OAAO,EAAE,OAAO;;;;;EAWjB"}
1
+ {"version":3,"file":"function.d.cts","sourceRoot":"","sources":["../../../src/webpack/loaders/function.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,gBAAgB;AAExD;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC;;;OAGG;IACH,EAAE,EAAE,wBAAwB,CAAC;CAC9B,CAAC;AAEF;;;;;;GAMG;AAGH,QAAA,MAAM,MAAM,EAAE,wBAAwB,CAAC,qBAAqB,CAK3D,CAAC;AAEF,eAAe,MAAM,CAAC;AAKtB,eAAO,MAAM,GAAG,OAAO,CAAC;AAExB;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EACvC,EAAE,EAAE,wBAAwB,CAAC,OAAO,CAAC,EACrC,OAAO,EAAE,OAAO;;;;;EAWjB"}
@@ -18,6 +18,7 @@ export type FunctionLoaderOptions = {
18
18
  */
19
19
  declare const loader: LoaderDefinitionFunction<FunctionLoaderOptions>;
20
20
  export default loader;
21
+ export declare const raw = true;
21
22
  /**
22
23
  * Get a loader that executes the given function. This is useful for executing
23
24
  * loaders without needing to pass a file to Webpack.
@@ -1 +1 @@
1
- {"version":3,"file":"function.d.mts","sourceRoot":"","sources":["../../../src/webpack/loaders/function.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,gBAAgB;AAExD;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC;;;OAGG;IACH,EAAE,EAAE,wBAAwB,CAAC;CAC9B,CAAC;AAEF;;;;;;GAMG;AACH,QAAA,MAAM,MAAM,EAAE,wBAAwB,CAAC,qBAAqB,CAK3D,CAAC;AAEF,eAAe,MAAM,CAAC;AAEtB;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EACvC,EAAE,EAAE,wBAAwB,CAAC,OAAO,CAAC,EACrC,OAAO,EAAE,OAAO;;;;;EAWjB"}
1
+ {"version":3,"file":"function.d.mts","sourceRoot":"","sources":["../../../src/webpack/loaders/function.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,gBAAgB;AAExD;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC;;;OAGG;IACH,EAAE,EAAE,wBAAwB,CAAC;CAC9B,CAAC;AAEF;;;;;;GAMG;AAGH,QAAA,MAAM,MAAM,EAAE,wBAAwB,CAAC,qBAAqB,CAK3D,CAAC;AAEF,eAAe,MAAM,CAAC;AAKtB,eAAO,MAAM,GAAG,OAAO,CAAC;AAExB;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EACvC,EAAE,EAAE,wBAAwB,CAAC,OAAO,CAAC,EACrC,OAAO,EAAE,OAAO;;;;;EAWjB"}
@@ -9,11 +9,17 @@ function $__filename(fileUrl) {
9
9
  * @param content - The input file contents as a `Uint8Array`.
10
10
  * @returns The output of the function.
11
11
  */
12
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
13
+ // eslint-disable-next-line @typescript-eslint/promise-function-async
12
14
  const loader = function (content) {
13
15
  const { fn } = this.getOptions();
14
16
  return fn.bind(this)(content);
15
17
  };
16
18
  export default loader;
19
+ // By setting `raw` to `true`, we are telling Webpack to provide the source as a
20
+ // `Uint8Array` instead of converting it to a string. This allows us to avoid
21
+ // having to convert the source back to a `Uint8Array` in the loader.
22
+ export const raw = true;
17
23
  /**
18
24
  * Get a loader that executes the given function. This is useful for executing
19
25
  * loaders without needing to pass a file to Webpack.
@@ -33,13 +39,4 @@ export function getFunctionLoader(fn, options) {
33
39
  },
34
40
  };
35
41
  }
36
- // When running as CJS, we need to export the loader as a default export, since
37
- // `tsup` exports it as `loader_default`.
38
- // istanbul ignore next 3
39
- // eslint-disable-next-line n/no-process-env
40
- if (typeof module !== 'undefined' && process?.env?.NODE_ENV !== 'test') {
41
- module.exports = loader;
42
- module.exports.getFunctionLoader = getFunctionLoader;
43
- module.exports.raw = true;
44
- }
45
42
  //# sourceMappingURL=function.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"function.mjs","sourceRoot":"","sources":["../../../src/webpack/loaders/function.ts"],"names":[],"mappings":";;;;AAaA;;;;;;GAMG;AACH,MAAM,MAAM,GAAoD,UAC9D,OAAO;IAEP,MAAM,EAAE,EAAE,EAAE,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;IACjC,OAAO,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC;AAChC,CAAC,CAAC;AAEF,eAAe,MAAM,CAAC;AAEtB;;;;;;;GAOG;AACH,MAAM,UAAU,iBAAiB,CAC/B,EAAqC,EACrC,OAAgB;IAEhB,OAAO;QACL,2EAA2E;QAC3E,sDAAsD;QACtD,MAAM,8BAAY;QAClB,OAAO,EAAE;YACP,EAAE;YACF,GAAG,OAAO;SACX;KACF,CAAC;AACJ,CAAC;AAED,+EAA+E;AAC/E,yCAAyC;AACzC,yBAAyB;AACzB,4CAA4C;AAC5C,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,EAAE,GAAG,EAAE,QAAQ,KAAK,MAAM,EAAE,CAAC;IACvE,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,MAAM,CAAC,OAAO,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;IACrD,MAAM,CAAC,OAAO,CAAC,GAAG,GAAG,IAAI,CAAC;AAC5B,CAAC","sourcesContent":["import type { LoaderDefinitionFunction } from 'webpack';\n\n/**\n * Options for the function loader.\n */\nexport type FunctionLoaderOptions = {\n /**\n * The function to execute. This is bound to the loader context, so it can\n * access the loader options and other properties.\n */\n fn: LoaderDefinitionFunction;\n};\n\n/**\n * A loader that executes a function. See {@link getFunctionLoader} for more\n * information.\n *\n * @param content - The input file contents as a `Uint8Array`.\n * @returns The output of the function.\n */\nconst loader: LoaderDefinitionFunction<FunctionLoaderOptions> = function (\n content,\n) {\n const { fn } = this.getOptions();\n return fn.bind(this)(content);\n};\n\nexport default loader;\n\n/**\n * Get a loader that executes the given function. This is useful for executing\n * loaders without needing to pass a file to Webpack.\n *\n * @param fn - The function to execute.\n * @param options - The options to pass to the loader.\n * @returns The loader definition.\n */\nexport function getFunctionLoader<Options>(\n fn: LoaderDefinitionFunction<Options>,\n options: Options,\n) {\n return {\n // We use `__filename` as the loader, so Webpack will execute the loader in\n // this file, with the actual function in the options.\n loader: __filename,\n options: {\n fn,\n ...options,\n },\n };\n}\n\n// When running as CJS, we need to export the loader as a default export, since\n// `tsup` exports it as `loader_default`.\n// istanbul ignore next 3\n// eslint-disable-next-line n/no-process-env\nif (typeof module !== 'undefined' && process?.env?.NODE_ENV !== 'test') {\n module.exports = loader;\n module.exports.getFunctionLoader = getFunctionLoader;\n module.exports.raw = true;\n}\n"]}
1
+ {"version":3,"file":"function.mjs","sourceRoot":"","sources":["../../../src/webpack/loaders/function.ts"],"names":[],"mappings":";;;;AAaA;;;;;;GAMG;AACH,gFAAgF;AAChF,qEAAqE;AACrE,MAAM,MAAM,GAAoD,UAC9D,OAAO;IAEP,MAAM,EAAE,EAAE,EAAE,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;IACjC,OAAO,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC;AAChC,CAAC,CAAC;AAEF,eAAe,MAAM,CAAC;AAEtB,gFAAgF;AAChF,6EAA6E;AAC7E,qEAAqE;AACrE,MAAM,CAAC,MAAM,GAAG,GAAG,IAAI,CAAC;AAExB;;;;;;;GAOG;AACH,MAAM,UAAU,iBAAiB,CAC/B,EAAqC,EACrC,OAAgB;IAEhB,OAAO;QACL,2EAA2E;QAC3E,sDAAsD;QACtD,MAAM,8BAAY;QAClB,OAAO,EAAE;YACP,EAAE;YACF,GAAG,OAAO;SACX;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { LoaderDefinitionFunction } from 'webpack';\n\n/**\n * Options for the function loader.\n */\nexport type FunctionLoaderOptions = {\n /**\n * The function to execute. This is bound to the loader context, so it can\n * access the loader options and other properties.\n */\n fn: LoaderDefinitionFunction;\n};\n\n/**\n * A loader that executes a function. See {@link getFunctionLoader} for more\n * information.\n *\n * @param content - The input file contents as a `Uint8Array`.\n * @returns The output of the function.\n */\n// TODO: Either fix this lint violation or explain why it's necessary to ignore.\n// eslint-disable-next-line @typescript-eslint/promise-function-async\nconst loader: LoaderDefinitionFunction<FunctionLoaderOptions> = function (\n content,\n) {\n const { fn } = this.getOptions();\n return fn.bind(this)(content);\n};\n\nexport default loader;\n\n// By setting `raw` to `true`, we are telling Webpack to provide the source as a\n// `Uint8Array` instead of converting it to a string. This allows us to avoid\n// having to convert the source back to a `Uint8Array` in the loader.\nexport const raw = true;\n\n/**\n * Get a loader that executes the given function. This is useful for executing\n * loaders without needing to pass a file to Webpack.\n *\n * @param fn - The function to execute.\n * @param options - The options to pass to the loader.\n * @returns The loader definition.\n */\nexport function getFunctionLoader<Options>(\n fn: LoaderDefinitionFunction<Options>,\n options: Options,\n) {\n return {\n // We use `__filename` as the loader, so Webpack will execute the loader in\n // this file, with the actual function in the options.\n loader: __filename,\n options: {\n fn,\n ...options,\n },\n };\n}\n"]}
@@ -17,10 +17,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.wasm = exports.browserify = void 0;
20
+ exports.wasm = void 0;
21
21
  __exportStar(require("./function.cjs"), exports);
22
- var browserify_1 = require("./browserify.cjs");
23
- Object.defineProperty(exports, "browserify", { enumerable: true, get: function () { return __importDefault(browserify_1).default; } });
24
22
  var wasm_1 = require("./wasm.cjs");
25
23
  Object.defineProperty(exports, "wasm", { enumerable: true, get: function () { return __importDefault(wasm_1).default; } });
26
24
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../src/webpack/loaders/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,iDAA2B;AAC3B,+CAAqD;AAA5C,yHAAA,OAAO,OAAc;AAC9B,mCAAyC;AAAhC,6GAAA,OAAO,OAAQ","sourcesContent":["export * from './function';\nexport { default as browserify } from './browserify';\nexport { default as wasm } from './wasm';\n"]}
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../src/webpack/loaders/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,iDAA2B;AAC3B,mCAAyC;AAAhC,6GAAA,OAAO,OAAQ","sourcesContent":["export * from './function';\nexport { default as wasm } from './wasm';\n"]}
@@ -1,4 +1,3 @@
1
1
  export * from "./function.cjs";
2
- export { default as browserify } from "./browserify.cjs";
3
2
  export { default as wasm } from "./wasm.cjs";
4
3
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/webpack/loaders/index.ts"],"names":[],"mappings":"AAAA,+BAA2B;AAC3B,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,yBAAqB;AACrD,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,mBAAe"}
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/webpack/loaders/index.ts"],"names":[],"mappings":"AAAA,+BAA2B;AAC3B,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,mBAAe"}
@@ -1,4 +1,3 @@
1
1
  export * from "./function.mjs";
2
- export { default as browserify } from "./browserify.mjs";
3
2
  export { default as wasm } from "./wasm.mjs";
4
3
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/webpack/loaders/index.ts"],"names":[],"mappings":"AAAA,+BAA2B;AAC3B,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,yBAAqB;AACrD,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,mBAAe"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/webpack/loaders/index.ts"],"names":[],"mappings":"AAAA,+BAA2B;AAC3B,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,mBAAe"}
@@ -1,4 +1,3 @@
1
1
  export * from "./function.mjs";
2
- export { default as browserify } from "./browserify.mjs";
3
2
  export { default as wasm } from "./wasm.mjs";
4
3
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../src/webpack/loaders/index.ts"],"names":[],"mappings":"AAAA,+BAA2B;AAC3B,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,yBAAqB;AACrD,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,mBAAe","sourcesContent":["export * from './function';\nexport { default as browserify } from './browserify';\nexport { default as wasm } from './wasm';\n"]}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../src/webpack/loaders/index.ts"],"names":[],"mappings":"AAAA,+BAA2B;AAC3B,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,mBAAe","sourcesContent":["export * from './function';\nexport { default as wasm } from './wasm';\n"]}
@@ -1,5 +1,4 @@
1
1
  "use strict";
2
- /* eslint-disable no-restricted-globals */
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  exports.raw = exports.getExports = exports.getModuleImports = exports.getImports = void 0;
5
4
  const utils_1 = require("@metamask/utils");
@@ -67,7 +66,6 @@ exports.getExports = getExports;
67
66
  const loader = async function loader(source) {
68
67
  (0, utils_1.assert)(source instanceof Uint8Array, 'Expected source to be a Uint8Array.');
69
68
  const wasmModule = await WebAssembly.compile(source);
70
- // eslint-disable-next-line @typescript-eslint/no-shadow
71
69
  const exports = WebAssembly.Module.exports(wasmModule);
72
70
  const imports = WebAssembly.Module.imports(wasmModule).reduce((target, descriptor) => {
73
71
  var _a;
@@ -1 +1 @@
1
- {"version":3,"file":"wasm.cjs","sourceRoot":"","sources":["../../../src/webpack/loaders/wasm.ts"],"names":[],"mappings":";AAAA,0CAA0C;;;AAE1C,2CAAwD;AACxD,+BAAwC;AAGxC;;;;;;GAMG;AACH,SAAgB,UAAU,CAAC,SAAmC;IAC5D,OAAO,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC;SAC7B,GAAG,CACF,CAAC,CAAC,UAAU,EAAE,WAAW,CAAC,EAAE,EAAE,CAC5B,YAAY,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,IAAI,CAAC,SAAS,CACzD,UAAU,CACX,GAAG,CACP;SACA,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC;AATD,gCASC;AAED;;;;;;GAMG;AACH,SAAgB,gBAAgB,CAAC,SAAmC;IAClE,OAAO,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC;SAC7B,GAAG,CACF,CAAC,CAAC,UAAU,EAAE,WAAW,CAAC,EAAE,EAAE,CAC5B,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,OAAO,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAClE;SACA,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC;AAPD,4CAOC;AAED;;;;;;;GAOG;AACH,SAAgB,UAAU,CAAC,WAAiD;IAC1E,OAAO,WAAW;SACf,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE;QAClB,IAAI,UAAU,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;YAClC,OAAO,0BAA0B,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC;QAC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AA,qBAAa,EAAC,MAAM,CAAC,CAAC;;;;;;;;;;;;;QAa/C,gBAAgB,CAAC,OAAO,CAAC;;;;MAI3B,UAAU,CAAC,OAAO,CAAC;GACtB,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,MAAM,CAAC;AAEtB,gFAAgF;AAChF,6EAA6E;AAC7E,qEAAqE;AACxD,QAAA,GAAG,GAAG,IAAI,CAAC","sourcesContent":["/* eslint-disable no-restricted-globals */\n\nimport { assert, bytesToBase64 } from '@metamask/utils';\nimport { dirname, resolve } from 'path';\nimport type { LoaderDefinitionFunction } from 'webpack';\n\n/**\n * Get the imports code for the WASM module. This code imports each of the\n * imports from the WASM module.\n *\n * @param importMap - The import map for the WASM module.\n * @returns The imports code for the WASM module.\n */\nexport function getImports(importMap: Record<string, string[]>) {\n return Object.entries(importMap)\n .map(\n ([moduleName, exportNames]) =>\n `import { ${exportNames.join(', ')} } from ${JSON.stringify(\n moduleName,\n )};`,\n )\n .join('\\n');\n}\n\n/**\n * Get the imports code to use in `WebAssembly.Instance`. This code adds each of\n * the imports to the `imports` object.\n *\n * @param importMap - The import map for the WASM module.\n * @returns The imports code for the WASM module.\n */\nexport function getModuleImports(importMap: Record<string, string[]>) {\n return Object.entries(importMap)\n .map(\n ([moduleName, exportNames]) =>\n `${JSON.stringify(moduleName)}: { ${exportNames.join(', ')} },`,\n )\n .join('\\n');\n}\n\n/**\n * Get the exports code for the WASM module. This code exports each of the\n * exports from the WASM module as a variable. This function assumes that the\n * exports are available in a variable named `exports`.\n *\n * @param descriptors - The export descriptors from the WASM module.\n * @returns The exports code for the WASM module.\n */\nexport function getExports(descriptors: WebAssembly.ModuleExportDescriptor[]) {\n return descriptors\n .map((descriptor) => {\n if (descriptor.name === 'default') {\n return `export default exports[${JSON.stringify(descriptor.name)}];`;\n }\n\n return `export const ${descriptor.name} = exports[${JSON.stringify(\n descriptor.name,\n )}];`;\n })\n .join('\\n');\n}\n\n/**\n * A Webpack loader that synchronously loads the WASM module. This makes it\n * possible to import the WASM module directly.\n *\n * @param source - The WASM module as `Uint8Array`.\n * @returns The WASM module as a JavaScript string.\n * @example\n * ```ts\n * import * as wasm from './program.wasm';\n *\n * // Do something with the WASM module...\n * ```\n */\n// Note: This function needs to be defined like this, so that Webpack can bind\n// `this` to the loader context, and TypeScript can infer the type of `this`.\nconst loader: LoaderDefinitionFunction = async function loader(\n source: unknown,\n) {\n assert(source instanceof Uint8Array, 'Expected source to be a Uint8Array.');\n\n const wasmModule = await WebAssembly.compile(source);\n\n // eslint-disable-next-line @typescript-eslint/no-shadow\n const exports = WebAssembly.Module.exports(wasmModule);\n const imports = WebAssembly.Module.imports(wasmModule).reduce<\n Record<string, string[]>\n >((target, descriptor) => {\n target[descriptor.module] ??= [];\n target[descriptor.module].push(descriptor.name);\n\n return target;\n }, {});\n\n // Add the WASM import as a dependency so that Webpack will watch it for\n // changes.\n const path = dirname(this.resourcePath);\n for (const name of Object.keys(imports)) {\n this.addDependency(resolve(path, name));\n }\n\n return `\n ${getImports(imports)}\n\n const b64 = ${JSON.stringify(bytesToBase64(source))};\n\n function decode(encoded) {\n const str = atob(encoded);\n const bytes = new Uint8Array(str.length);\n for (let i = 0; i < str.length; i++) {\n bytes[i] = str.charCodeAt(i);\n }\n return bytes;\n }\n\n const bytes = decode(b64);\n const { instance } = await WebAssembly.instantiate(bytes, {\n ${getModuleImports(imports)}\n });\n\n const exports = instance.exports;\n ${getExports(exports)}\n `;\n};\n\nexport default loader;\n\n// By setting `raw` to `true`, we are telling Webpack to provide the source as a\n// `Uint8Array` instead of converting it to a string. This allows us to avoid\n// having to convert the source back to a `Uint8Array` in the loader.\nexport const raw = true;\n"]}
1
+ {"version":3,"file":"wasm.cjs","sourceRoot":"","sources":["../../../src/webpack/loaders/wasm.ts"],"names":[],"mappings":";;;AAAA,2CAAwD;AACxD,+BAAwC;AAGxC;;;;;;GAMG;AACH,SAAgB,UAAU,CAAC,SAAmC;IAC5D,OAAO,MAAM,CAAC,OAAO,CA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O,CAAC,MAAM,CAAC,CAAC;IAErD,MAAM,OAAO,GAAG,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IACvD,MAAM,OAAO,GAAG,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,MAAM,CAE3D,CAAC,MAAM,EAAE,UAAU,EAAE,EAAE;;QACvB,MAAM,MAAC,UAAU,CAAC,MAAM,MAAxB,MAAM,OAAwB,EAAE,EAAC;QACjC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QAEhD,OAAO,MAAM,CAAC;IAChB,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,wEAAwE;IACxE,WAAW;IACX,MAAM,IAAI,GAAG,IAAA,cAAO,EAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACxC,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QACxC,IAAI,CAAC,aAAa,CAAC,IAAA,cAAO,EAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;IAC1C,CAAC;IAED,OAAO;MACH,UAAU,CAAC,OAAO,CAAC;;kBAEP,IAAI,CAAC,SAAS,CAAC,IAAA,qBAAa,EAAC,MAAM,CAAC,CAAC;;;;;;;;;;;;;QAa/C,gBAAgB,CAAC,OAAO,CAAC;;;;MAI3B,UAAU,CAAC,OAAO,CAAC;GACtB,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,MAAM,CAAC;AAEtB,gFAAgF;AAChF,6EAA6E;AAC7E,qEAAqE;AACxD,QAAA,GAAG,GAAG,IAAI,CAAC","sourcesContent":["import { assert, bytesToBase64 } from '@metamask/utils';\nimport { dirname, resolve } from 'path';\nimport type { LoaderDefinitionFunction } from 'webpack';\n\n/**\n * Get the imports code for the WASM module. This code imports each of the\n * imports from the WASM module.\n *\n * @param importMap - The import map for the WASM module.\n * @returns The imports code for the WASM module.\n */\nexport function getImports(importMap: Record<string, string[]>) {\n return Object.entries(importMap)\n .map(\n ([moduleName, exportNames]) =>\n `import { ${exportNames.join(', ')} } from ${JSON.stringify(\n moduleName,\n )};`,\n )\n .join('\\n');\n}\n\n/**\n * Get the imports code to use in `WebAssembly.Instance`. This code adds each of\n * the imports to the `imports` object.\n *\n * @param importMap - The import map for the WASM module.\n * @returns The imports code for the WASM module.\n */\nexport function getModuleImports(importMap: Record<string, string[]>) {\n return Object.entries(importMap)\n .map(\n ([moduleName, exportNames]) =>\n `${JSON.stringify(moduleName)}: { ${exportNames.join(', ')} },`,\n )\n .join('\\n');\n}\n\n/**\n * Get the exports code for the WASM module. This code exports each of the\n * exports from the WASM module as a variable. This function assumes that the\n * exports are available in a variable named `exports`.\n *\n * @param descriptors - The export descriptors from the WASM module.\n * @returns The exports code for the WASM module.\n */\nexport function getExports(descriptors: WebAssembly.ModuleExportDescriptor[]) {\n return descriptors\n .map((descriptor) => {\n if (descriptor.name === 'default') {\n return `export default exports[${JSON.stringify(descriptor.name)}];`;\n }\n\n return `export const ${descriptor.name} = exports[${JSON.stringify(\n descriptor.name,\n )}];`;\n })\n .join('\\n');\n}\n\n/**\n * A Webpack loader that synchronously loads the WASM module. This makes it\n * possible to import the WASM module directly.\n *\n * @param source - The WASM module as `Uint8Array`.\n * @returns The WASM module as a JavaScript string.\n * @example\n * ```ts\n * import * as wasm from './program.wasm';\n *\n * // Do something with the WASM module...\n * ```\n */\n// Note: This function needs to be defined like this, so that Webpack can bind\n// `this` to the loader context, and TypeScript can infer the type of `this`.\nconst loader: LoaderDefinitionFunction = async function loader(\n source: unknown,\n) {\n assert(source instanceof Uint8Array, 'Expected source to be a Uint8Array.');\n\n const wasmModule = await WebAssembly.compile(source);\n\n const exports = WebAssembly.Module.exports(wasmModule);\n const imports = WebAssembly.Module.imports(wasmModule).reduce<\n Record<string, string[]>\n >((target, descriptor) => {\n target[descriptor.module] ??= [];\n target[descriptor.module].push(descriptor.name);\n\n return target;\n }, {});\n\n // Add the WASM import as a dependency so that Webpack will watch it for\n // changes.\n const path = dirname(this.resourcePath);\n for (const name of Object.keys(imports)) {\n this.addDependency(resolve(path, name));\n }\n\n return `\n ${getImports(imports)}\n\n const b64 = ${JSON.stringify(bytesToBase64(source))};\n\n function decode(encoded) {\n const str = atob(encoded);\n const bytes = new Uint8Array(str.length);\n for (let i = 0; i < str.length; i++) {\n bytes[i] = str.charCodeAt(i);\n }\n return bytes;\n }\n\n const bytes = decode(b64);\n const { instance } = await WebAssembly.instantiate(bytes, {\n ${getModuleImports(imports)}\n });\n\n const exports = instance.exports;\n ${getExports(exports)}\n `;\n};\n\nexport default loader;\n\n// By setting `raw` to `true`, we are telling Webpack to provide the source as a\n// `Uint8Array` instead of converting it to a string. This allows us to avoid\n// having to convert the source back to a `Uint8Array` in the loader.\nexport const raw = true;\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"wasm.d.cts","sourceRoot":"","sources":["../../../src/webpack/loaders/wasm.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,wBAAwB,EAAE,gBAAgB;AAExD;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,UAS7D;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,UAOnE;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,WAAW,EAAE,WAAW,CAAC,sBAAsB,EAAE,UAY3E;AAED;;;;;;;;;;;;GAYG;AAGH,QAAA,MAAM,MAAM,EAAE,wBA+Cb,CAAC;AAEF,eAAe,MAAM,CAAC;AAKtB,eAAO,MAAM,GAAG,OAAO,CAAC"}
1
+ {"version":3,"file":"wasm.d.cts","sourceRoot":"","sources":["../../../src/webpack/loaders/wasm.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,wBAAwB,EAAE,gBAAgB;AAExD;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,UAS7D;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,UAOnE;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,WAAW,EAAE,WAAW,CAAC,sBAAsB,EAAE,UAY3E;AAED;;;;;;;;;;;;GAYG;AAGH,QAAA,MAAM,MAAM,EAAE,wBA8Cb,CAAC;AAEF,eAAe,MAAM,CAAC;AAKtB,eAAO,MAAM,GAAG,OAAO,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"wasm.d.mts","sourceRoot":"","sources":["../../../src/webpack/loaders/wasm.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,wBAAwB,EAAE,gBAAgB;AAExD;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,UAS7D;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,UAOnE;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,WAAW,EAAE,WAAW,CAAC,sBAAsB,EAAE,UAY3E;AAED;;;;;;;;;;;;GAYG;AAGH,QAAA,MAAM,MAAM,EAAE,wBA+Cb,CAAC;AAEF,eAAe,MAAM,CAAC;AAKtB,eAAO,MAAM,GAAG,OAAO,CAAC"}
1
+ {"version":3,"file":"wasm.d.mts","sourceRoot":"","sources":["../../../src/webpack/loaders/wasm.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,wBAAwB,EAAE,gBAAgB;AAExD;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,UAS7D;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,UAOnE;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,WAAW,EAAE,WAAW,CAAC,sBAAsB,EAAE,UAY3E;AAED;;;;;;;;;;;;GAYG;AAGH,QAAA,MAAM,MAAM,EAAE,wBA8Cb,CAAC;AAEF,eAAe,MAAM,CAAC;AAKtB,eAAO,MAAM,GAAG,OAAO,CAAC"}
@@ -1,4 +1,3 @@
1
- /* eslint-disable no-restricted-globals */
2
1
  import { assert, bytesToBase64 } from "@metamask/utils";
3
2
  import { dirname, resolve } from "path";
4
3
  /**
@@ -61,7 +60,6 @@ export function getExports(descriptors) {
61
60
  const loader = async function loader(source) {
62
61
  assert(source instanceof Uint8Array, 'Expected source to be a Uint8Array.');
63
62
  const wasmModule = await WebAssembly.compile(source);
64
- // eslint-disable-next-line @typescript-eslint/no-shadow
65
63
  const exports = WebAssembly.Module.exports(wasmModule);
66
64
  const imports = WebAssembly.Module.imports(wasmModule).reduce((target, descriptor) => {
67
65
  var _a;
@@ -1 +1 @@
1
- {"version":3,"file":"wasm.mjs","sourceRoot":"","sources":["../../../src/webpack/loaders/wasm.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAE1C,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,wBAAwB;AACxD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,aAAa;AAGxC;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAC,SAAmC;IAC5D,OAAO,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC;SAC7B,GAAG,CACF,CAAC,CAAC,UAAU,EAAE,WAAW,CAAC,EAAE,EAAE,CAC5B,YAAY,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,IAAI,CAAC,SAAS,CACzD,UAAU,CACX,GAAG,CACP;SACA,IAAI,CAAC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U,EAAE,EAAE;;QACvB,MAAM,MAAC,UAAU,CAAC,MAAM,MAAxB,MAAM,OAAwB,EAAE,EAAC;QACjC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QAEhD,OAAO,MAAM,CAAC;IAChB,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,wEAAwE;IACxE,WAAW;IACX,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACxC,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QACxC,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;IAC1C,CAAC;IAED,OAAO;MACH,UAAU,CAAC,OAAO,CAAC;;kBAEP,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;;;;;;;;;;;;;QAa/C,gBAAgB,CAAC,OAAO,CAAC;;;;MAI3B,UAAU,CAAC,OAAO,CAAC;GACtB,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,MAAM,CAAC;AAEtB,gFAAgF;AAChF,6EAA6E;AAC7E,qEAAqE;AACrE,MAAM,CAAC,MAAM,GAAG,GAAG,IAAI,CAAC","sourcesContent":["/* eslint-disable no-restricted-globals */\n\nimport { assert, bytesToBase64 } from '@metamask/utils';\nimport { dirname, resolve } from 'path';\nimport type { LoaderDefinitionFunction } from 'webpack';\n\n/**\n * Get the imports code for the WASM module. This code imports each of the\n * imports from the WASM module.\n *\n * @param importMap - The import map for the WASM module.\n * @returns The imports code for the WASM module.\n */\nexport function getImports(importMap: Record<string, string[]>) {\n return Object.entries(importMap)\n .map(\n ([moduleName, exportNames]) =>\n `import { ${exportNames.join(', ')} } from ${JSON.stringify(\n moduleName,\n )};`,\n )\n .join('\\n');\n}\n\n/**\n * Get the imports code to use in `WebAssembly.Instance`. This code adds each of\n * the imports to the `imports` object.\n *\n * @param importMap - The import map for the WASM module.\n * @returns The imports code for the WASM module.\n */\nexport function getModuleImports(importMap: Record<string, string[]>) {\n return Object.entries(importMap)\n .map(\n ([moduleName, exportNames]) =>\n `${JSON.stringify(moduleName)}: { ${exportNames.join(', ')} },`,\n )\n .join('\\n');\n}\n\n/**\n * Get the exports code for the WASM module. This code exports each of the\n * exports from the WASM module as a variable. This function assumes that the\n * exports are available in a variable named `exports`.\n *\n * @param descriptors - The export descriptors from the WASM module.\n * @returns The exports code for the WASM module.\n */\nexport function getExports(descriptors: WebAssembly.ModuleExportDescriptor[]) {\n return descriptors\n .map((descriptor) => {\n if (descriptor.name === 'default') {\n return `export default exports[${JSON.stringify(descriptor.name)}];`;\n }\n\n return `export const ${descriptor.name} = exports[${JSON.stringify(\n descriptor.name,\n )}];`;\n })\n .join('\\n');\n}\n\n/**\n * A Webpack loader that synchronously loads the WASM module. This makes it\n * possible to import the WASM module directly.\n *\n * @param source - The WASM module as `Uint8Array`.\n * @returns The WASM module as a JavaScript string.\n * @example\n * ```ts\n * import * as wasm from './program.wasm';\n *\n * // Do something with the WASM module...\n * ```\n */\n// Note: This function needs to be defined like this, so that Webpack can bind\n// `this` to the loader context, and TypeScript can infer the type of `this`.\nconst loader: LoaderDefinitionFunction = async function loader(\n source: unknown,\n) {\n assert(source instanceof Uint8Array, 'Expected source to be a Uint8Array.');\n\n const wasmModule = await WebAssembly.compile(source);\n\n // eslint-disable-next-line @typescript-eslint/no-shadow\n const exports = WebAssembly.Module.exports(wasmModule);\n const imports = WebAssembly.Module.imports(wasmModule).reduce<\n Record<string, string[]>\n >((target, descriptor) => {\n target[descriptor.module] ??= [];\n target[descriptor.module].push(descriptor.name);\n\n return target;\n }, {});\n\n // Add the WASM import as a dependency so that Webpack will watch it for\n // changes.\n const path = dirname(this.resourcePath);\n for (const name of Object.keys(imports)) {\n this.addDependency(resolve(path, name));\n }\n\n return `\n ${getImports(imports)}\n\n const b64 = ${JSON.stringify(bytesToBase64(source))};\n\n function decode(encoded) {\n const str = atob(encoded);\n const bytes = new Uint8Array(str.length);\n for (let i = 0; i < str.length; i++) {\n bytes[i] = str.charCodeAt(i);\n }\n return bytes;\n }\n\n const bytes = decode(b64);\n const { instance } = await WebAssembly.instantiate(bytes, {\n ${getModuleImports(imports)}\n });\n\n const exports = instance.exports;\n ${getExports(exports)}\n `;\n};\n\nexport default loader;\n\n// By setting `raw` to `true`, we are telling Webpack to provide the source as a\n// `Uint8Array` instead of converting it to a string. This allows us to avoid\n// having to convert the source back to a `Uint8Array` in the loader.\nexport const raw = true;\n"]}
1
+ {"version":3,"file":"wasm.mjs","sourceRoot":"","sources":["../../../src/webpack/loaders/wasm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,wBAAwB;AACxD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,aAAa;AAGxC;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAC,SAAmC;IAC5D,OAAO,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC;SAC7B,GAAG,CACF,CAAC,CAAC,UAAU,EAAE,WAAW,CAAC,EAAE,EAAE,CAC5B,YAAY,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,IAAI,CAAC,SAAS,CACzD,UAAU,CACX,GAAG,CACP;SACA,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAC,SAAmC;IAClE,OAAO,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC;SAC7B,GAAG,CACF,CAAC,CAAC,UAAU,EAAE,WAAW,CAAC,EAAE,EAAE,CAC5B,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,OAAO,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAClE;SACA,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,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AAC;QACxC,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;IAC1C,CAAC;IAED,OAAO;MACH,UAAU,CAAC,OAAO,CAAC;;kBAEP,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;;;;;;;;;;;;;QAa/C,gBAAgB,CAAC,OAAO,CAAC;;;;MAI3B,UAAU,CAAC,OAAO,CAAC;GACtB,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,MAAM,CAAC;AAEtB,gFAAgF;AAChF,6EAA6E;AAC7E,qEAAqE;AACrE,MAAM,CAAC,MAAM,GAAG,GAAG,IAAI,CAAC","sourcesContent":["import { assert, bytesToBase64 } from '@metamask/utils';\nimport { dirname, resolve } from 'path';\nimport type { LoaderDefinitionFunction } from 'webpack';\n\n/**\n * Get the imports code for the WASM module. This code imports each of the\n * imports from the WASM module.\n *\n * @param importMap - The import map for the WASM module.\n * @returns The imports code for the WASM module.\n */\nexport function getImports(importMap: Record<string, string[]>) {\n return Object.entries(importMap)\n .map(\n ([moduleName, exportNames]) =>\n `import { ${exportNames.join(', ')} } from ${JSON.stringify(\n moduleName,\n )};`,\n )\n .join('\\n');\n}\n\n/**\n * Get the imports code to use in `WebAssembly.Instance`. This code adds each of\n * the imports to the `imports` object.\n *\n * @param importMap - The import map for the WASM module.\n * @returns The imports code for the WASM module.\n */\nexport function getModuleImports(importMap: Record<string, string[]>) {\n return Object.entries(importMap)\n .map(\n ([moduleName, exportNames]) =>\n `${JSON.stringify(moduleName)}: { ${exportNames.join(', ')} },`,\n )\n .join('\\n');\n}\n\n/**\n * Get the exports code for the WASM module. This code exports each of the\n * exports from the WASM module as a variable. This function assumes that the\n * exports are available in a variable named `exports`.\n *\n * @param descriptors - The export descriptors from the WASM module.\n * @returns The exports code for the WASM module.\n */\nexport function getExports(descriptors: WebAssembly.ModuleExportDescriptor[]) {\n return descriptors\n .map((descriptor) => {\n if (descriptor.name === 'default') {\n return `export default exports[${JSON.stringify(descriptor.name)}];`;\n }\n\n return `export const ${descriptor.name} = exports[${JSON.stringify(\n descriptor.name,\n )}];`;\n })\n .join('\\n');\n}\n\n/**\n * A Webpack loader that synchronously loads the WASM module. This makes it\n * possible to import the WASM module directly.\n *\n * @param source - The WASM module as `Uint8Array`.\n * @returns The WASM module as a JavaScript string.\n * @example\n * ```ts\n * import * as wasm from './program.wasm';\n *\n * // Do something with the WASM module...\n * ```\n */\n// Note: This function needs to be defined like this, so that Webpack can bind\n// `this` to the loader context, and TypeScript can infer the type of `this`.\nconst loader: LoaderDefinitionFunction = async function loader(\n source: unknown,\n) {\n assert(source instanceof Uint8Array, 'Expected source to be a Uint8Array.');\n\n const wasmModule = await WebAssembly.compile(source);\n\n const exports = WebAssembly.Module.exports(wasmModule);\n const imports = WebAssembly.Module.imports(wasmModule).reduce<\n Record<string, string[]>\n >((target, descriptor) => {\n target[descriptor.module] ??= [];\n target[descriptor.module].push(descriptor.name);\n\n return target;\n }, {});\n\n // Add the WASM import as a dependency so that Webpack will watch it for\n // changes.\n const path = dirname(this.resourcePath);\n for (const name of Object.keys(imports)) {\n this.addDependency(resolve(path, name));\n }\n\n return `\n ${getImports(imports)}\n\n const b64 = ${JSON.stringify(bytesToBase64(source))};\n\n function decode(encoded) {\n const str = atob(encoded);\n const bytes = new Uint8Array(str.length);\n for (let i = 0; i < str.length; i++) {\n bytes[i] = str.charCodeAt(i);\n }\n return bytes;\n }\n\n const bytes = decode(b64);\n const { instance } = await WebAssembly.instantiate(bytes, {\n ${getModuleImports(imports)}\n });\n\n const exports = instance.exports;\n ${getExports(exports)}\n `;\n};\n\nexport default loader;\n\n// By setting `raw` to `true`, we are telling Webpack to provide the source as a\n// `Uint8Array` instead of converting it to a string. This allows us to avoid\n// having to convert the source back to a `Uint8Array` in the loader.\nexport const raw = true;\n"]}