@metamask/snaps-cli 0.37.1-flask.1 → 0.38.0-flask.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (256) hide show
  1. package/.browserslistrc +3 -0
  2. package/CHANGELOG.md +20 -431
  3. package/README.md +539 -63
  4. package/dist/cjs/builders.js +40 -41
  5. package/dist/cjs/builders.js.map +1 -1
  6. package/dist/cjs/cli.js +14 -14
  7. package/dist/cjs/cli.js.map +1 -1
  8. package/dist/cjs/commands/build/build.js +54 -0
  9. package/dist/cjs/commands/build/build.js.map +1 -0
  10. package/dist/cjs/commands/build/implementation.js +31 -0
  11. package/dist/cjs/commands/build/implementation.js.map +1 -0
  12. package/dist/cjs/{cmds → commands}/build/index.js +18 -5
  13. package/dist/cjs/commands/build/index.js.map +1 -0
  14. package/dist/cjs/commands/eval/eval.js +57 -0
  15. package/dist/cjs/commands/eval/eval.js.map +1 -0
  16. package/dist/cjs/commands/eval/implementation.js +27 -0
  17. package/dist/cjs/commands/eval/implementation.js.map +1 -0
  18. package/dist/cjs/commands/eval/index.js +50 -0
  19. package/dist/cjs/commands/eval/index.js.map +1 -0
  20. package/dist/cjs/commands/index.js.map +1 -0
  21. package/dist/cjs/commands/manifest/implementation.js +34 -0
  22. package/dist/cjs/commands/manifest/implementation.js.map +1 -0
  23. package/dist/cjs/commands/manifest/index.js +50 -0
  24. package/dist/cjs/commands/manifest/index.js.map +1 -0
  25. package/dist/cjs/commands/manifest/manifest.js +55 -0
  26. package/dist/cjs/commands/manifest/manifest.js.map +1 -0
  27. package/dist/cjs/{cmds → commands}/serve/index.js +4 -2
  28. package/dist/cjs/commands/serve/index.js.map +1 -0
  29. package/dist/cjs/commands/serve/serve.js +21 -0
  30. package/dist/cjs/commands/serve/serve.js.map +1 -0
  31. package/dist/cjs/commands/watch/implementation.js +35 -0
  32. package/dist/cjs/commands/watch/implementation.js.map +1 -0
  33. package/dist/cjs/{cmds → commands}/watch/index.js +19 -4
  34. package/dist/cjs/commands/watch/index.js.map +1 -0
  35. package/dist/cjs/commands/watch/watch.js +51 -0
  36. package/dist/cjs/commands/watch/watch.js.map +1 -0
  37. package/dist/cjs/config.js +290 -0
  38. package/dist/cjs/config.js.map +1 -0
  39. package/dist/cjs/errors.js +37 -0
  40. package/dist/cjs/errors.js.map +1 -0
  41. package/dist/cjs/index.js +28 -3
  42. package/dist/cjs/index.js.map +1 -1
  43. package/dist/cjs/main.js +6 -7
  44. package/dist/cjs/main.js.map +1 -1
  45. package/dist/cjs/utils/cli.js +61 -0
  46. package/dist/cjs/utils/cli.js.map +1 -0
  47. package/dist/cjs/utils/errors.js +42 -0
  48. package/dist/cjs/utils/errors.js.map +1 -0
  49. package/dist/cjs/utils/index.js +6 -2
  50. package/dist/cjs/utils/index.js.map +1 -1
  51. package/dist/cjs/utils/legacy.js +48 -0
  52. package/dist/cjs/utils/legacy.js.map +1 -0
  53. package/dist/cjs/utils/logging.js +46 -0
  54. package/dist/cjs/utils/logging.js.map +1 -0
  55. package/dist/cjs/utils/path.js +16 -0
  56. package/dist/cjs/utils/path.js.map +1 -0
  57. package/dist/cjs/utils/steps.js +52 -0
  58. package/dist/cjs/utils/steps.js.map +1 -0
  59. package/dist/cjs/webpack/compiler.js +96 -0
  60. package/dist/cjs/webpack/compiler.js.map +1 -0
  61. package/dist/cjs/webpack/config.js +234 -0
  62. package/dist/cjs/webpack/config.js.map +1 -0
  63. package/dist/cjs/webpack/index.js +22 -0
  64. package/dist/cjs/webpack/index.js.map +1 -0
  65. package/dist/cjs/webpack/loaders/browserify.js +97 -0
  66. package/dist/cjs/webpack/loaders/browserify.js.map +1 -0
  67. package/dist/cjs/webpack/loaders/wasm.js +36 -0
  68. package/dist/cjs/webpack/loaders/wasm.js.map +1 -0
  69. package/dist/cjs/webpack/plugins.js +340 -0
  70. package/dist/cjs/webpack/plugins.js.map +1 -0
  71. package/dist/cjs/webpack/utils.js +133 -0
  72. package/dist/cjs/webpack/utils.js.map +1 -0
  73. package/dist/esm/builders.js +40 -41
  74. package/dist/esm/builders.js.map +1 -1
  75. package/dist/esm/cli.js +15 -15
  76. package/dist/esm/cli.js.map +1 -1
  77. package/dist/esm/commands/build/build.js +51 -0
  78. package/dist/esm/commands/build/build.js.map +1 -0
  79. package/dist/esm/commands/build/implementation.js +27 -0
  80. package/dist/esm/commands/build/implementation.js.map +1 -0
  81. package/dist/esm/{cmds → commands}/build/index.js +5 -5
  82. package/dist/esm/commands/build/index.js.map +1 -0
  83. package/dist/esm/commands/eval/eval.js +54 -0
  84. package/dist/esm/commands/eval/eval.js.map +1 -0
  85. package/dist/esm/commands/eval/implementation.js +24 -0
  86. package/dist/esm/commands/eval/implementation.js.map +1 -0
  87. package/dist/esm/commands/eval/index.js +22 -0
  88. package/dist/esm/commands/eval/index.js.map +1 -0
  89. package/dist/esm/commands/index.js +15 -0
  90. package/dist/esm/commands/index.js.map +1 -0
  91. package/dist/esm/commands/manifest/implementation.js +33 -0
  92. package/dist/esm/commands/manifest/implementation.js.map +1 -0
  93. package/dist/esm/commands/manifest/index.js +22 -0
  94. package/dist/esm/commands/manifest/index.js.map +1 -0
  95. package/dist/esm/commands/manifest/manifest.js +52 -0
  96. package/dist/esm/commands/manifest/manifest.js.map +1 -0
  97. package/dist/esm/{cmds → commands}/serve/index.js +4 -2
  98. package/dist/esm/commands/serve/index.js.map +1 -0
  99. package/dist/esm/commands/serve/serve.js +17 -0
  100. package/dist/esm/commands/serve/serve.js.map +1 -0
  101. package/dist/esm/commands/watch/implementation.js +34 -0
  102. package/dist/esm/commands/watch/implementation.js.map +1 -0
  103. package/dist/esm/{cmds → commands}/watch/index.js +6 -4
  104. package/dist/esm/commands/watch/index.js.map +1 -0
  105. package/dist/esm/commands/watch/watch.js +50 -0
  106. package/dist/esm/commands/watch/watch.js.map +1 -0
  107. package/dist/esm/config.js +294 -0
  108. package/dist/esm/config.js.map +1 -0
  109. package/dist/esm/errors.js +30 -0
  110. package/dist/esm/errors.js.map +1 -0
  111. package/dist/esm/index.js +3 -0
  112. package/dist/esm/index.js.map +1 -1
  113. package/dist/esm/main.js +6 -7
  114. package/dist/esm/main.js.map +1 -1
  115. package/dist/esm/utils/cli.js +43 -0
  116. package/dist/esm/utils/cli.js.map +1 -0
  117. package/dist/esm/utils/errors.js +43 -0
  118. package/dist/esm/utils/errors.js.map +1 -0
  119. package/dist/esm/utils/index.js +6 -2
  120. package/dist/esm/utils/index.js.map +1 -1
  121. package/dist/esm/utils/legacy.js +47 -0
  122. package/dist/esm/utils/legacy.js.map +1 -0
  123. package/dist/esm/utils/logging.js +40 -0
  124. package/dist/esm/utils/logging.js.map +1 -0
  125. package/dist/esm/utils/path.js +13 -0
  126. package/dist/esm/utils/path.js.map +1 -0
  127. package/dist/esm/utils/steps.js +43 -0
  128. package/dist/esm/utils/steps.js.map +1 -0
  129. package/dist/esm/webpack/compiler.js +89 -0
  130. package/dist/esm/webpack/compiler.js.map +1 -0
  131. package/dist/esm/webpack/config.js +236 -0
  132. package/dist/esm/webpack/config.js.map +1 -0
  133. package/dist/esm/webpack/index.js +5 -0
  134. package/dist/esm/webpack/index.js.map +1 -0
  135. package/dist/esm/webpack/loaders/browserify.js +82 -0
  136. package/dist/esm/webpack/loaders/browserify.js.map +1 -0
  137. package/dist/esm/webpack/loaders/wasm.js +26 -0
  138. package/dist/esm/webpack/loaders/wasm.js.map +1 -0
  139. package/dist/esm/webpack/plugins.js +343 -0
  140. package/dist/esm/webpack/plugins.js.map +1 -0
  141. package/dist/esm/webpack/utils.js +160 -0
  142. package/dist/esm/webpack/utils.js.map +1 -0
  143. package/dist/types/__fixtures__/configs/cjs.d.ts +1 -0
  144. package/dist/types/__fixtures__/configs/esm.d.ts +3 -0
  145. package/dist/types/__fixtures__/configs/invalid.d.ts +3 -0
  146. package/dist/types/__fixtures__/configs/javascript/snap.config.d.ts +0 -0
  147. package/dist/types/__fixtures__/configs/typescript/snap.config.d.ts +3 -0
  148. package/dist/types/builders.d.ts +2 -21
  149. package/dist/types/cli.d.ts +1 -1
  150. package/dist/types/commands/build/build.d.ts +10 -0
  151. package/dist/types/commands/build/implementation.d.ts +10 -0
  152. package/dist/types/{cmds/eval → commands/build}/index.d.ts +1 -0
  153. package/dist/types/commands/eval/__test__/browserify/bad/snap.config.d.ts +3 -0
  154. package/dist/types/commands/eval/__test__/browserify/good/snap.config.d.ts +3 -0
  155. package/dist/types/commands/eval/__test__/webpack/bad/snap.config.d.ts +3 -0
  156. package/dist/types/commands/eval/__test__/webpack/good/snap.config.d.ts +3 -0
  157. package/dist/types/commands/eval/__test__/webpack/snap.config.d.ts +3 -0
  158. package/dist/types/commands/eval/eval.d.ts +14 -0
  159. package/dist/types/commands/eval/implementation.d.ts +9 -0
  160. package/dist/types/{cmds/serve → commands/eval}/index.d.ts +1 -0
  161. package/dist/types/commands/manifest/implementation.d.ts +12 -0
  162. package/dist/types/{cmds → commands}/manifest/index.d.ts +1 -0
  163. package/dist/types/commands/manifest/manifest.d.ts +14 -0
  164. package/dist/types/commands/serve/serve.d.ts +16 -0
  165. package/dist/types/commands/watch/implementation.d.ts +14 -0
  166. package/dist/types/commands/watch/index.d.ts +10 -0
  167. package/dist/types/commands/watch/watch.d.ts +19 -0
  168. package/dist/types/config.d.ts +626 -0
  169. package/dist/types/errors.d.ts +25 -0
  170. package/dist/types/index.d.ts +4 -0
  171. package/dist/types/utils/cli.d.ts +17 -0
  172. package/dist/types/utils/errors.d.ts +23 -0
  173. package/dist/types/utils/index.d.ts +6 -2
  174. package/dist/types/utils/legacy.d.ts +27 -0
  175. package/dist/types/utils/logging.d.ts +22 -0
  176. package/dist/types/utils/path.d.ts +9 -0
  177. package/dist/types/utils/steps.d.ts +17 -0
  178. package/dist/types/webpack/compiler.d.ts +29 -0
  179. package/dist/types/webpack/config.d.ts +37 -0
  180. package/dist/types/webpack/index.d.ts +3 -0
  181. package/dist/types/webpack/loaders/browserify.d.ts +16 -0
  182. package/dist/types/webpack/loaders/wasm.d.ts +20 -0
  183. package/dist/types/webpack/plugins.d.ts +147 -0
  184. package/dist/types/webpack/utils.d.ts +156 -0
  185. package/package.json +15 -7
  186. package/dist/cjs/cmds/build/buildHandler.js +0 -36
  187. package/dist/cjs/cmds/build/buildHandler.js.map +0 -1
  188. package/dist/cjs/cmds/build/bundle.js +0 -83
  189. package/dist/cjs/cmds/build/bundle.js.map +0 -1
  190. package/dist/cjs/cmds/build/index.js.map +0 -1
  191. package/dist/cjs/cmds/build/utils.js +0 -79
  192. package/dist/cjs/cmds/build/utils.js.map +0 -1
  193. package/dist/cjs/cmds/eval/evalHandler.js +0 -24
  194. package/dist/cjs/cmds/eval/evalHandler.js.map +0 -1
  195. package/dist/cjs/cmds/eval/index.js +0 -31
  196. package/dist/cjs/cmds/eval/index.js.map +0 -1
  197. package/dist/cjs/cmds/index.js.map +0 -1
  198. package/dist/cjs/cmds/manifest/index.js +0 -44
  199. package/dist/cjs/cmds/manifest/index.js.map +0 -1
  200. package/dist/cjs/cmds/manifest/manifestHandler.js +0 -47
  201. package/dist/cjs/cmds/manifest/manifestHandler.js.map +0 -1
  202. package/dist/cjs/cmds/serve/index.js.map +0 -1
  203. package/dist/cjs/cmds/serve/serveHandler.js +0 -62
  204. package/dist/cjs/cmds/serve/serveHandler.js.map +0 -1
  205. package/dist/cjs/cmds/serve/serveUtils.js +0 -37
  206. package/dist/cjs/cmds/serve/serveUtils.js.map +0 -1
  207. package/dist/cjs/cmds/watch/index.js.map +0 -1
  208. package/dist/cjs/cmds/watch/watchHandler.js +0 -91
  209. package/dist/cjs/cmds/watch/watchHandler.js.map +0 -1
  210. package/dist/cjs/utils/misc.js +0 -142
  211. package/dist/cjs/utils/misc.js.map +0 -1
  212. package/dist/cjs/utils/snap-config.js +0 -104
  213. package/dist/cjs/utils/snap-config.js.map +0 -1
  214. package/dist/esm/cmds/build/buildHandler.js +0 -36
  215. package/dist/esm/cmds/build/buildHandler.js.map +0 -1
  216. package/dist/esm/cmds/build/bundle.js +0 -81
  217. package/dist/esm/cmds/build/bundle.js.map +0 -1
  218. package/dist/esm/cmds/build/index.js.map +0 -1
  219. package/dist/esm/cmds/build/utils.js +0 -88
  220. package/dist/esm/cmds/build/utils.js.map +0 -1
  221. package/dist/esm/cmds/eval/evalHandler.js +0 -20
  222. package/dist/esm/cmds/eval/evalHandler.js.map +0 -1
  223. package/dist/esm/cmds/eval/index.js +0 -16
  224. package/dist/esm/cmds/eval/index.js.map +0 -1
  225. package/dist/esm/cmds/index.js +0 -15
  226. package/dist/esm/cmds/index.js.map +0 -1
  227. package/dist/esm/cmds/manifest/index.js +0 -29
  228. package/dist/esm/cmds/manifest/index.js.map +0 -1
  229. package/dist/esm/cmds/manifest/manifestHandler.js +0 -44
  230. package/dist/esm/cmds/manifest/manifestHandler.js.map +0 -1
  231. package/dist/esm/cmds/serve/index.js.map +0 -1
  232. package/dist/esm/cmds/serve/serveHandler.js +0 -54
  233. package/dist/esm/cmds/serve/serveHandler.js.map +0 -1
  234. package/dist/esm/cmds/serve/serveUtils.js +0 -30
  235. package/dist/esm/cmds/serve/serveUtils.js.map +0 -1
  236. package/dist/esm/cmds/watch/index.js.map +0 -1
  237. package/dist/esm/cmds/watch/watchHandler.js +0 -87
  238. package/dist/esm/cmds/watch/watchHandler.js.map +0 -1
  239. package/dist/esm/utils/misc.js +0 -139
  240. package/dist/esm/utils/misc.js.map +0 -1
  241. package/dist/esm/utils/snap-config.js +0 -107
  242. package/dist/esm/utils/snap-config.js.map +0 -1
  243. package/dist/types/cmds/build/buildHandler.d.ts +0 -13
  244. package/dist/types/cmds/build/bundle.d.ts +0 -15
  245. package/dist/types/cmds/build/utils.d.ts +0 -56
  246. package/dist/types/cmds/eval/evalHandler.d.ts +0 -9
  247. package/dist/types/cmds/manifest/manifestHandler.d.ts +0 -10
  248. package/dist/types/cmds/serve/serveHandler.d.ts +0 -10
  249. package/dist/types/cmds/serve/serveUtils.d.ts +0 -22
  250. package/dist/types/cmds/watch/index.d.ts +0 -9
  251. package/dist/types/cmds/watch/watchHandler.d.ts +0 -14
  252. package/dist/types/utils/misc.d.ts +0 -53
  253. package/dist/types/utils/snap-config.d.ts +0 -48
  254. /package/dist/cjs/{cmds → commands}/index.js +0 -0
  255. /package/dist/types/{cmds → commands}/index.d.ts +0 -0
  256. /package/dist/types/{cmds/build → commands/serve}/index.d.ts +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/webpack/compiler.ts"],"sourcesContent":["import type { Server } from 'http';\nimport { createServer } from 'http';\nimport type { AddressInfo } from 'net';\nimport serveMiddleware from 'serve-handler';\nimport { webpack } from 'webpack';\n\nimport type { ProcessedConfig, 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\n/**\n * Get a static server for development purposes.\n *\n * Note: We're intentionally not using `webpack-dev-server` here because it\n * adds a lot of extra stuff to the output that we don't need, and it's\n * difficult to customize.\n *\n * @param config - The config object.\n * @returns An object with a `listen` method that returns a promise that\n * resolves when the server is listening.\n */\nexport function getServer(config: ProcessedConfig) {\n const server = createServer((request, response) => {\n serveMiddleware(request, response, {\n public: config.server.root,\n headers: [\n {\n source: '**/*',\n headers: [\n {\n key: 'Cache-Control',\n value: 'no-cache',\n },\n {\n key: 'Access-Control-Allow-Origin',\n value: '*',\n },\n ],\n },\n ],\n })?.catch(\n /* istanbul ignore next */ () => {\n response.statusCode = 500;\n response.end();\n },\n );\n });\n\n /**\n * Start the server on the port specified in the config.\n *\n * @param port - The port to listen on.\n * @returns A promise that resolves when the server is listening. The promise\n * resolves to an object with the port and the server instance. Note that if\n * the `config.server.port` is `0`, the OS will choose a random port for us,\n * so we need to get the port from the server after it starts.\n */\n const listen = async (port = config.server.port) => {\n return new Promise<{\n port: number;\n server: Server;\n close: () => Promise<void>;\n }>((resolve, reject) => {\n try {\n server.listen(port, () => {\n const close = async () => {\n await new Promise<void>((resolveClose, rejectClose) => {\n server.close((closeError) => {\n if (closeError) {\n return rejectClose(closeError);\n }\n\n return resolveClose();\n });\n });\n };\n\n const address = server.address() as AddressInfo;\n resolve({ port: address.port, server, close });\n });\n } catch (listenError) {\n reject(listenError);\n }\n });\n };\n\n return { listen };\n}\n"],"names":["getCompiler","getServer","config","options","baseWebpackConfig","getDefaultConfiguration","webpackConfig","customizeWebpackConfig","webpack","server","createServer","request","response","serveMiddleware","public","root","headers","source","key","value","catch","statusCode","end","listen","port","Promise","resolve","reject","close","resolveClose","rejectClose","closeError","address","listenError"],"mappings":";;;;;;;;;;;IAiBsBA,WAAW;eAAXA;;IAsBNC,SAAS;eAATA;;;sBAtCa;qEAED;yBACJ;wBAIgB;;;;;;AASjC,eAAeD,YACpBE,MAA8B,EAC9BC,OAAwB;IAExB,MAAMC,oBAAoB,MAAMC,IAAAA,+BAAuB,EAACH,QAAQC;IAChE,MAAMG,gBACJJ,OAAOK,sBAAsB,GAAGH,sBAAsBA;IAExD,OAAOI,IAAAA,gBAAO,EAACF;AACjB;AAaO,SAASL,UAAUC,MAAuB;IAC/C,MAAMO,SAASC,IAAAA,kBAAY,EAAC,CAACC,SAASC;QACpCC,IAAAA,qBAAe,EAACF,SAASC,UAAU;YACjCE,QAAQZ,OAAOO,MAAM,CAACM,IAAI;YAC1BC,SAAS;gBACP;oBACEC,QAAQ;oBACRD,SAAS;wBACP;4BACEE,KAAK;4BACLC,OAAO;wBACT;wBACA;4BACED,KAAK;4BACLC,OAAO;wBACT;qBACD;gBACH;aACD;QACH,IAAIC,MACF,wBAAwB,GAAG;YACzBR,SAASS,UAAU,GAAG;YACtBT,SAASU,GAAG;QACd;IAEJ;IAEA;;;;;;;;GAQC,GACD,MAAMC,SAAS,OAAOC,OAAOtB,OAAOO,MAAM,CAACe,IAAI;QAC7C,OAAO,IAAIC,QAIR,CAACC,SAASC;YACX,IAAI;gBACFlB,OAAOc,MAAM,CAACC,MAAM;oBAClB,MAAMI,QAAQ;wBACZ,MAAM,IAAIH,QAAc,CAACI,cAAcC;4BACrCrB,OAAOmB,KAAK,CAAC,CAACG;gCACZ,IAAIA,YAAY;oCACd,OAAOD,YAAYC;gCACrB;gCAEA,OAAOF;4BACT;wBACF;oBACF;oBAEA,MAAMG,UAAUvB,OAAOuB,OAAO;oBAC9BN,QAAQ;wBAAEF,MAAMQ,QAAQR,IAAI;wBAAEf;wBAAQmB;oBAAM;gBAC9C;YACF,EAAE,OAAOK,aAAa;gBACpBN,OAAOM;YACT;QACF;IACF;IAEA,OAAO;QAAEV;IAAO;AAClB"}
@@ -0,0 +1,234 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "getDefaultConfiguration", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return getDefaultConfiguration;
9
+ }
10
+ });
11
+ const _snapswebpackplugin = /*#__PURE__*/ _interop_require_default(require("@metamask/snaps-webpack-plugin"));
12
+ const _module = require("module");
13
+ const _path = require("path");
14
+ const _terserwebpackplugin = /*#__PURE__*/ _interop_require_default(require("terser-webpack-plugin"));
15
+ const _webpack = require("webpack");
16
+ const _plugins = require("./plugins");
17
+ const _utils = require("./utils");
18
+ function _interop_require_default(obj) {
19
+ return obj && obj.__esModule ? obj : {
20
+ default: obj
21
+ };
22
+ }
23
+ async function getDefaultConfiguration(config, options = {
24
+ evaluate: config.evaluate
25
+ }) {
26
+ const spinnerText = options.spinner?.text;
27
+ const builtInResolver = config.stats.builtIns && new _plugins.SnapsBuiltInResolver(config.stats.builtIns, options.spinner);
28
+ return {
29
+ /**
30
+ * The target is set to `browserslist` so that Webpack will compile the
31
+ * bundle to support the browsers specified in the `.browserslistrc` file.
32
+ * This Browserslist file contains the browsers that are supported by
33
+ * MetaMask Snaps.
34
+ *
35
+ * @see https://webpack.js.org/configuration/target/
36
+ */ target: `browserslist:${_utils.BROWSERSLIST_FILE}`,
37
+ /**
38
+ * The mode is set to `production` by default, so that Webpack will minify
39
+ * and optimize the bundle.
40
+ *
41
+ * @see https://webpack.js.org/configuration/mode/
42
+ */ mode: 'production',
43
+ /**
44
+ * The entry point is set to the `input` value from the config object.
45
+ *
46
+ * @see https://webpack.js.org/configuration/entry-context/
47
+ */ entry: config.input,
48
+ /**
49
+ * The devtool option controls how source maps are generated. We set it to
50
+ * the `sourceMap` value from the config object.
51
+ *
52
+ * @see https://webpack.js.org/configuration/devtool/
53
+ */ devtool: (0, _utils.getDevTool)(config.sourceMap),
54
+ /**
55
+ * The stats option controls how much information is printed to the console
56
+ * when Webpack is running. We set it to `none` so that we can control the
57
+ * output ourselves.
58
+ *
59
+ * @see https://webpack.js.org/configuration/stats/
60
+ */ stats: 'none',
61
+ /**
62
+ * The output options.
63
+ *
64
+ * @see https://webpack.js.org/configuration/output/
65
+ */ output: {
66
+ /**
67
+ * This indicates whether Webpack should clear the output directory
68
+ * before building. We set it to the `clean` value from the config
69
+ * object.
70
+ *
71
+ * @see https://webpack.js.org/configuration/output/#outputclean
72
+ */ clean: config.output.clean,
73
+ /**
74
+ * The filename of the bundle. We set it to the `filename` value from
75
+ * the config object.
76
+ *
77
+ * @see https://webpack.js.org/configuration/output/#outputfilename
78
+ */ filename: config.output.filename,
79
+ /**
80
+ * The path to the output directory. We set it to the `path` value from
81
+ * the config object.
82
+ *
83
+ * @see https://webpack.js.org/configuration/output/#outputpath
84
+ */ path: config.output.path,
85
+ /**
86
+ * The public path of the bundle. We set it to `/` by default, so that
87
+ * the bundle can be loaded from the root of the server.
88
+ *
89
+ * @see https://webpack.js.org/configuration/output/#outputpublicpath
90
+ */ publicPath: '/',
91
+ /**
92
+ * The library configuration. This tells Webpack how to export the
93
+ * bundle.
94
+ *
95
+ * @see https://webpack.js.org/configuration/output/#outputlibrary
96
+ */ library: {
97
+ /**
98
+ * This tells Webpack to export the bundle as a CommonJS module. This
99
+ * is necessary for MetaMask Snaps.
100
+ *
101
+ * @see https://webpack.js.org/configuration/output/#outputlibrarytarget
102
+ */ type: 'commonjs'
103
+ }
104
+ },
105
+ /**
106
+ * The module configuration. This is where we tell Webpack how to handle
107
+ * different types of files.
108
+ *
109
+ * @see https://webpack.js.org/configuration/module/
110
+ */ module: {
111
+ rules: [
112
+ {
113
+ test: /\.[tj]sx?$/u,
114
+ exclude: /node_modules/u,
115
+ use: await (0, _utils.getDefaultLoader)(config)
116
+ },
117
+ config.experimental.wasm && {
118
+ test: /\.wasm$/u,
119
+ use: {
120
+ loader: (0, _path.resolve)(__dirname, 'loaders', 'wasm')
121
+ }
122
+ }
123
+ ]
124
+ },
125
+ /**
126
+ * The resolve configuration. This tells Webpack how to resolve imports.
127
+ * We set it to resolve `.js` and `.ts` files.
128
+ *
129
+ * @see https://webpack.js.org/configuration/resolve/
130
+ */ resolve: {
131
+ /**
132
+ * The extensions to resolve. We set it to resolve `.js` and `.ts`
133
+ * files.
134
+ */ extensions: [
135
+ '.js',
136
+ '.ts'
137
+ ],
138
+ /**
139
+ * The fallback options. This tells Webpack how to handle imports that
140
+ * aren't resolved. By default, we set Node.js built-ins to `false`, so
141
+ * that they are ignored.
142
+ */ fallback: Object.fromEntries(_module.builtinModules.map((name)=>[
143
+ name,
144
+ false
145
+ ])),
146
+ /**
147
+ * The plugins to use. We use the {@link SnapsBuiltInResolver} to show
148
+ * warnings about using Node.js built-ins, when no fallback is specified.
149
+ */ plugins: [
150
+ builtInResolver
151
+ ]
152
+ },
153
+ /**
154
+ * The plugins to use.
155
+ *
156
+ * @see https://webpack.js.org/configuration/plugins/
157
+ */ plugins: [
158
+ /**
159
+ * The `SnapsWebpackPlugin` is a Webpack plugin that checks and updates
160
+ * the manifest file, and evaluates the bundle in SES. While not strictly
161
+ * required, it's highly recommended to use this plugin.
162
+ */ new _snapswebpackplugin.default({
163
+ manifestPath: config.manifest.path,
164
+ writeManifest: config.manifest.update,
165
+ eval: !options.watch && options.evaluate
166
+ }),
167
+ /**
168
+ * The `SnapsStatsPlugin` is a Webpack plugin that handles the stats
169
+ * output. It's used to show the stats in the terminal, in a format that
170
+ * is easy to read.
171
+ */ new _plugins.SnapsStatsPlugin({
172
+ verbose: config.stats.verbose
173
+ }, options.spinner),
174
+ /**
175
+ * The `EnvironmentPlugin` is a Webpack plugin that adds environment
176
+ * variables to the bundle. We use it to add the `NODE_ENV` and `DEBUG`
177
+ * environment variables.
178
+ */ new _webpack.EnvironmentPlugin(config.environment),
179
+ /**
180
+ * The `ProgressPlugin` is a Webpack plugin that logs the progress of
181
+ * the build. We set it to log the progress to the spinner.
182
+ */ new _webpack.ProgressPlugin({
183
+ handler: (0, _utils.getProgressHandler)(options.spinner, spinnerText)
184
+ }),
185
+ /**
186
+ * The `SnapsBundleWarningPlugin` is a Webpack plugin that shows a
187
+ * warning when the bundle is potentially incompatible with MetaMask
188
+ * Snaps.
189
+ */ new _plugins.SnapsBundleWarningsPlugin({
190
+ builtInResolver,
191
+ builtIns: Boolean(config.stats.builtIns),
192
+ buffer: config.stats.buffer
193
+ }, options.spinner),
194
+ /**
195
+ * The `WatchPlugin` is a Webpack plugin that adds extra files to watch
196
+ * for changes. This is useful for rebuilding the bundle when the
197
+ * manifest file changes.
198
+ */ options.watch && new _plugins.SnapsWatchPlugin({
199
+ bundle: (0, _path.resolve)(config.output.path, config.output.filename),
200
+ evaluate: options.evaluate,
201
+ files: [
202
+ config.manifest.path
203
+ ]
204
+ }, options.spinner)
205
+ ].filter(Boolean),
206
+ /**
207
+ * The optimization configuration. This tells Webpack how to optimize the
208
+ * bundle. Most of the time, you won't need to change this, as the default
209
+ * options set by the `mode` option are sufficient.
210
+ */ optimization: {
211
+ minimize: config.output.minimize,
212
+ /**
213
+ * The minimizer to use. We set it to use the `TerserPlugin`.
214
+ */ minimizer: [
215
+ new _terserwebpackplugin.default({
216
+ parallel: true
217
+ })
218
+ ]
219
+ },
220
+ /**
221
+ * The infrastructure logging configuration. This tells Webpack how to
222
+ * log messages.
223
+ *
224
+ * @see https://webpack.js.org/configuration/infrastructure-logging
225
+ */ infrastructureLogging: {
226
+ /**
227
+ * The level of logging to use. We set it to `none`, so that we can
228
+ * control the output ourselves.
229
+ */ level: 'none'
230
+ }
231
+ };
232
+ }
233
+
234
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/webpack/config.ts"],"sourcesContent":["import SnapsWebpackPlugin from '@metamask/snaps-webpack-plugin';\nimport { builtinModules } from 'module';\nimport type { Ora } from 'ora';\nimport { resolve } from 'path';\nimport TerserPlugin from 'terser-webpack-plugin';\nimport type { Configuration } from 'webpack';\nimport { EnvironmentPlugin, ProgressPlugin } from 'webpack';\n\nimport type { ProcessedWebpackConfig } from '../config';\nimport {\n SnapsBuiltInResolver,\n SnapsBundleWarningsPlugin,\n SnapsStatsPlugin,\n SnapsWatchPlugin,\n} from './plugins';\nimport {\n BROWSERSLIST_FILE,\n getDefaultLoader,\n getDevTool,\n getProgressHandler,\n} from './utils';\n\nexport type WebpackOptions = {\n /**\n * Whether to watch for changes.\n */\n watch?: boolean;\n\n /**\n * Whether to evaluate the bundle. If this is set, it will override the\n * `evaluate` option in the config object.\n */\n evaluate?: boolean;\n\n /**\n * The spinner to use for logging.\n */\n spinner?: Ora;\n};\n\n/**\n * Get the default Webpack configuration. This is the configuration that will\n * be used if the user doesn't provide a custom Webpack configuration. The\n * configuration is based on the snap config.\n *\n * The default configuration includes:\n *\n * - `SWC` to transpile TypeScript and JavaScript files.\n * - `TerserPlugin` to minify the bundle.\n * - `SnapsWebpackPlugin` to validate the bundle and update the manifest.\n *\n * It can be customized through the `customizeWebpackConfig` function in the\n * snap config, but in most cases, you shouldn't need to do that.\n *\n * @param config - The processed snap Webpack config.\n * @param options - The Webpack options.\n * @returns The default Webpack configuration.\n */\nexport async function getDefaultConfiguration(\n config: ProcessedWebpackConfig,\n options: WebpackOptions = {\n evaluate: config.evaluate,\n },\n): Promise<Configuration> {\n const spinnerText = options.spinner?.text;\n const builtInResolver =\n config.stats.builtIns &&\n new SnapsBuiltInResolver(config.stats.builtIns, options.spinner);\n\n return {\n /**\n * The target is set to `browserslist` so that Webpack will compile the\n * bundle to support the browsers specified in the `.browserslistrc` file.\n * This Browserslist file contains the browsers that are supported by\n * MetaMask Snaps.\n *\n * @see https://webpack.js.org/configuration/target/\n */\n target: `browserslist:${BROWSERSLIST_FILE}`,\n\n /**\n * The mode is set to `production` by default, so that Webpack will minify\n * and optimize the bundle.\n *\n * @see https://webpack.js.org/configuration/mode/\n */\n mode: 'production',\n\n /**\n * The entry point is set to the `input` value from the config object.\n *\n * @see https://webpack.js.org/configuration/entry-context/\n */\n entry: config.input,\n\n /**\n * The devtool option controls how source maps are generated. We set it to\n * the `sourceMap` value from the config object.\n *\n * @see https://webpack.js.org/configuration/devtool/\n */\n devtool: getDevTool(config.sourceMap),\n\n /**\n * The stats option controls how much information is printed to the console\n * when Webpack is running. We set it to `none` so that we can control the\n * output ourselves.\n *\n * @see https://webpack.js.org/configuration/stats/\n */\n stats: 'none',\n\n /**\n * The output options.\n *\n * @see https://webpack.js.org/configuration/output/\n */\n output: {\n /**\n * This indicates whether Webpack should clear the output directory\n * before building. We set it to the `clean` value from the config\n * object.\n *\n * @see https://webpack.js.org/configuration/output/#outputclean\n */\n clean: config.output.clean,\n\n /**\n * The filename of the bundle. We set it to the `filename` value from\n * the config object.\n *\n * @see https://webpack.js.org/configuration/output/#outputfilename\n */\n filename: config.output.filename,\n\n /**\n * The path to the output directory. We set it to the `path` value from\n * the config object.\n *\n * @see https://webpack.js.org/configuration/output/#outputpath\n */\n path: config.output.path,\n\n /**\n * The public path of the bundle. We set it to `/` by default, so that\n * the bundle can be loaded from the root of the server.\n *\n * @see https://webpack.js.org/configuration/output/#outputpublicpath\n */\n publicPath: '/',\n\n /**\n * The library configuration. This tells Webpack how to export the\n * bundle.\n *\n * @see https://webpack.js.org/configuration/output/#outputlibrary\n */\n library: {\n /**\n * This tells Webpack to export the bundle as a CommonJS module. This\n * is necessary for MetaMask Snaps.\n *\n * @see https://webpack.js.org/configuration/output/#outputlibrarytarget\n */\n type: 'commonjs',\n },\n },\n\n /**\n * The module configuration. This is where we tell Webpack how to handle\n * different types of files.\n *\n * @see https://webpack.js.org/configuration/module/\n */\n module: {\n rules: [\n {\n test: /\\.[tj]sx?$/u,\n exclude: /node_modules/u,\n use: await getDefaultLoader(config),\n },\n\n config.experimental.wasm && {\n test: /\\.wasm$/u,\n use: {\n loader: resolve(__dirname, 'loaders', 'wasm'),\n },\n },\n ],\n },\n\n /**\n * The resolve configuration. This tells Webpack how to resolve imports.\n * We set it to resolve `.js` and `.ts` files.\n *\n * @see https://webpack.js.org/configuration/resolve/\n */\n resolve: {\n /**\n * The extensions to resolve. We set it to resolve `.js` and `.ts`\n * files.\n */\n extensions: ['.js', '.ts'],\n\n /**\n * The fallback options. This tells Webpack how to handle imports that\n * aren't resolved. By default, we set Node.js built-ins to `false`, so\n * that they are ignored.\n */\n fallback: Object.fromEntries(builtinModules.map((name) => [name, false])),\n\n /**\n * The plugins to use. We use the {@link SnapsBuiltInResolver} to show\n * warnings about using Node.js built-ins, when no fallback is specified.\n */\n plugins: [builtInResolver],\n },\n\n /**\n * The plugins to use.\n *\n * @see https://webpack.js.org/configuration/plugins/\n */\n plugins: [\n /**\n * The `SnapsWebpackPlugin` is a Webpack plugin that checks and updates\n * the manifest file, and evaluates the bundle in SES. While not strictly\n * required, it's highly recommended to use this plugin.\n */\n new SnapsWebpackPlugin({\n manifestPath: config.manifest.path,\n writeManifest: config.manifest.update,\n eval: !options.watch && options.evaluate,\n }),\n\n /**\n * The `SnapsStatsPlugin` is a Webpack plugin that handles the stats\n * output. It's used to show the stats in the terminal, in a format that\n * is easy to read.\n */\n new SnapsStatsPlugin({ verbose: config.stats.verbose }, options.spinner),\n\n /**\n * The `EnvironmentPlugin` is a Webpack plugin that adds environment\n * variables to the bundle. We use it to add the `NODE_ENV` and `DEBUG`\n * environment variables.\n */\n new EnvironmentPlugin(config.environment),\n\n /**\n * The `ProgressPlugin` is a Webpack plugin that logs the progress of\n * the build. We set it to log the progress to the spinner.\n */\n new ProgressPlugin({\n handler: getProgressHandler(options.spinner, spinnerText),\n }),\n\n /**\n * The `SnapsBundleWarningPlugin` is a Webpack plugin that shows a\n * warning when the bundle is potentially incompatible with MetaMask\n * Snaps.\n */\n new SnapsBundleWarningsPlugin(\n {\n builtInResolver,\n builtIns: Boolean(config.stats.builtIns),\n buffer: config.stats.buffer,\n },\n options.spinner,\n ),\n\n /**\n * The `WatchPlugin` is a Webpack plugin that adds extra files to watch\n * for changes. This is useful for rebuilding the bundle when the\n * manifest file changes.\n */\n options.watch &&\n new SnapsWatchPlugin(\n {\n bundle: resolve(config.output.path, config.output.filename),\n evaluate: options.evaluate,\n files: [config.manifest.path],\n },\n options.spinner,\n ),\n ].filter(Boolean),\n\n /**\n * The optimization configuration. This tells Webpack how to optimize the\n * bundle. Most of the time, you won't need to change this, as the default\n * options set by the `mode` option are sufficient.\n */\n optimization: {\n minimize: config.output.minimize,\n\n /**\n * The minimizer to use. We set it to use the `TerserPlugin`.\n */\n minimizer: [\n new TerserPlugin({\n parallel: true,\n }),\n ],\n },\n\n /**\n * The infrastructure logging configuration. This tells Webpack how to\n * log messages.\n *\n * @see https://webpack.js.org/configuration/infrastructure-logging\n */\n infrastructureLogging: {\n /**\n * The level of logging to use. We set it to `none`, so that we can\n * control the output ourselves.\n */\n level: 'none',\n },\n };\n}\n"],"names":["getDefaultConfiguration","config","options","evaluate","spinnerText","spinner","text","builtInResolver","stats","builtIns","SnapsBuiltInResolver","target","BROWSERSLIST_FILE","mode","entry","input","devtool","getDevTool","sourceMap","output","clean","filename","path","publicPath","library","type","module","rules","test","exclude","use","getDefaultLoader","experimental","wasm","loader","resolve","__dirname","extensions","fallback","Object","fromEntries","builtinModules","map","name","plugins","SnapsWebpackPlugin","manifestPath","manifest","writeManifest","update","eval","watch","SnapsStatsPlugin","verbose","EnvironmentPlugin","environment","ProgressPlugin","handler","getProgressHandler","SnapsBundleWarningsPlugin","Boolean","buffer","SnapsWatchPlugin","bundle","files","filter","optimization","minimize","minimizer","TerserPlugin","parallel","infrastructureLogging","level"],"mappings":"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"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ _export_star(require("./compiler"), exports);
6
+ _export_star(require("./config"), exports);
7
+ _export_star(require("./plugins"), exports);
8
+ function _export_star(from, to) {
9
+ Object.keys(from).forEach(function(k) {
10
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
11
+ Object.defineProperty(to, k, {
12
+ enumerable: true,
13
+ get: function() {
14
+ return from[k];
15
+ }
16
+ });
17
+ }
18
+ });
19
+ return from;
20
+ }
21
+
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/webpack/index.ts"],"sourcesContent":["export * from './compiler';\nexport * from './config';\nexport * from './plugins';\n"],"names":[],"mappings":";;;;qBAAc;qBACA;qBACA"}
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return _default;
9
+ }
10
+ });
11
+ const _browserify = /*#__PURE__*/ _interop_require_default(require("browserify"));
12
+ const _stream = require("stream");
13
+ const _builders = require("../../builders");
14
+ const _utils = require("../../utils");
15
+ const _utils1 = require("../utils");
16
+ function _interop_require_default(obj) {
17
+ return obj && obj.__esModule ? obj : {
18
+ default: obj
19
+ };
20
+ }
21
+ /**
22
+ * A Browserify loader for Webpack. This exists for backwards compatibility with
23
+ * the legacy configuration format, in order to support the `bundlerCustomizer`
24
+ * function.
25
+ *
26
+ * When this loader is used, the input file will be processed by Browserify, and
27
+ * written to disk by Webpack. Most processing will be handled by Browserify, so
28
+ * there are no benefits like tree-shaking.
29
+ *
30
+ * @param content - The input file contents as a string.
31
+ * @param sourceMap - The source map of the input file.
32
+ */ const loader = async function(content, sourceMap) {
33
+ const config = this.getOptions();
34
+ const { transpilationMode } = config;
35
+ const bundler = (0, _browserify.default)({
36
+ extensions: [
37
+ '.js',
38
+ '.ts'
39
+ ],
40
+ debug: Boolean(sourceMap),
41
+ standalone: '<snap>'
42
+ });
43
+ if (transpilationMode !== _builders.TranspilationModes.None) {
44
+ const babelifyOptions = (0, _utils.processDependencies)(config);
45
+ // We need to statically import all Browserify transforms, and all Babel
46
+ // presets and plugins, and calling `require` is the sanest way to do that.
47
+ /* eslint-disable @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires, n/global-require */ bundler.transform(require('babelify'), {
48
+ global: transpilationMode === _builders.TranspilationModes.LocalAndDeps,
49
+ extensions: [
50
+ '.js',
51
+ '.ts'
52
+ ],
53
+ presets: [
54
+ require('@babel/preset-typescript'),
55
+ [
56
+ require('@babel/preset-env'),
57
+ {
58
+ targets: {
59
+ browsers: await (0, _utils1.getBrowserslistTargets)()
60
+ }
61
+ }
62
+ ]
63
+ ],
64
+ plugins: [
65
+ require('@babel/plugin-transform-runtime'),
66
+ require('@babel/plugin-proposal-class-properties'),
67
+ require('@babel/plugin-proposal-private-methods'),
68
+ require('@babel/plugin-proposal-class-static-block'),
69
+ require('@babel/plugin-proposal-private-property-in-object')
70
+ ],
71
+ ...babelifyOptions
72
+ });
73
+ /* eslint-enable @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires, n/global-require */ }
74
+ config.bundlerCustomizer?.(bundler);
75
+ // Browserify doesn't accept a string as an entry point, so we need to convert
76
+ // it to a stream.
77
+ const stream = new _stream.Readable();
78
+ stream.push(content);
79
+ stream.push(null);
80
+ bundler.add(stream, {
81
+ file: this.resourcePath
82
+ });
83
+ return new Promise((resolve, reject)=>{
84
+ bundler.bundle((bundleError, buffer)=>{
85
+ if (bundleError) {
86
+ reject(bundleError);
87
+ return;
88
+ }
89
+ // Browserify inlines the source map, so we just pass the output buffer back
90
+ // to Webpack.
91
+ resolve(buffer);
92
+ });
93
+ });
94
+ };
95
+ const _default = loader;
96
+
97
+ //# sourceMappingURL=browserify.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/webpack/loaders/browserify.ts"],"sourcesContent":["import browserify from 'browserify';\nimport { Readable } from 'stream';\nimport type { LoaderDefinitionFunction } from 'webpack';\n\nimport { TranspilationModes } from '../../builders';\nimport type { LegacyOptions } from '../../config';\nimport { processDependencies } from '../../utils';\nimport { getBrowserslistTargets } from '../utils';\n\n/**\n * A Browserify loader for Webpack. This exists for backwards compatibility with\n * the legacy configuration format, in order to support the `bundlerCustomizer`\n * function.\n *\n * When this loader is used, the input file will be processed by Browserify, and\n * written to disk by Webpack. Most processing will be handled by Browserify, so\n * there are no benefits like tree-shaking.\n *\n * @param content - The input file contents as a string.\n * @param sourceMap - The source map of the input file.\n */\nconst loader: LoaderDefinitionFunction<LegacyOptions> = async function (\n content,\n sourceMap,\n) {\n const config = this.getOptions();\n\n const { transpilationMode } = config;\n\n const bundler = browserify({\n extensions: ['.js', '.ts'],\n debug: Boolean(sourceMap),\n standalone: '<snap>',\n });\n\n if (transpilationMode !== TranspilationModes.None) {\n const babelifyOptions = processDependencies(config);\n\n // We need to statically import all Browserify transforms, and all Babel\n // presets and plugins, and calling `require` is the sanest way to do that.\n /* eslint-disable @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires, n/global-require */\n bundler.transform(require('babelify'), {\n global: transpilationMode === TranspilationModes.LocalAndDeps,\n extensions: ['.js', '.ts'],\n presets: [\n require('@babel/preset-typescript'),\n [\n require('@babel/preset-env'),\n {\n targets: {\n browsers: await getBrowserslistTargets(),\n },\n },\n ],\n ],\n plugins: [\n require('@babel/plugin-transform-runtime'),\n require('@babel/plugin-proposal-class-properties'),\n require('@babel/plugin-proposal-private-methods'),\n require('@babel/plugin-proposal-class-static-block'),\n require('@babel/plugin-proposal-private-property-in-object'),\n ],\n ...(babelifyOptions as any),\n });\n /* eslint-enable @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires, n/global-require */\n }\n\n config.bundlerCustomizer?.(bundler);\n\n // Browserify doesn't accept a string as an entry point, so we need to convert\n // it to a stream.\n const stream = new Readable();\n stream.push(content);\n stream.push(null);\n\n bundler.add(stream, {\n file: this.resourcePath,\n });\n\n return new Promise<Buffer>((resolve, reject) => {\n bundler.bundle((bundleError, buffer: Buffer) => {\n if (bundleError) {\n reject(bundleError);\n return;\n }\n\n // Browserify inlines the source map, so we just pass the output buffer back\n // to Webpack.\n resolve(buffer);\n });\n });\n};\n\nexport default loader;\n"],"names":["loader","content","sourceMap","config","getOptions","transpilationMode","bundler","browserify","extensions","debug","Boolean","standalone","TranspilationModes","None","babelifyOptions","processDependencies","transform","require","global","LocalAndDeps","presets","targets","browsers","getBrowserslistTargets","plugins","bundlerCustomizer","stream","Readable","push","add","file","resourcePath","Promise","resolve","reject","bundle","bundleError","buffer"],"mappings":";;;;+BA6FA;;;eAAA;;;mEA7FuB;wBACE;0BAGU;uBAEC;wBACG;;;;;;AAEvC;;;;;;;;;;;CAWC,GACD,MAAMA,SAAkD,eACtDC,OAAO,EACPC,SAAS;IAET,MAAMC,SAAS,IAAI,CAACC,UAAU;IAE9B,MAAM,EAAEC,iBAAiB,EAAE,GAAGF;IAE9B,MAAMG,UAAUC,IAAAA,mBAAU,EAAC;QACzBC,YAAY;YAAC;YAAO;SAAM;QAC1BC,OAAOC,QAAQR;QACfS,YAAY;IACd;IAEA,IAAIN,sBAAsBO,4BAAkB,CAACC,IAAI,EAAE;QACjD,MAAMC,kBAAkBC,IAAAA,0BAAmB,EAACZ;QAE5C,wEAAwE;QACxE,2EAA2E;QAC3E,8GAA8G,GAC9GG,QAAQU,SAAS,CAACC,QAAQ,aAAa;YACrCC,QAAQb,sBAAsBO,4BAAkB,CAACO,YAAY;YAC7DX,YAAY;gBAAC;gBAAO;aAAM;YAC1BY,SAAS;gBACPH,QAAQ;gBACR;oBACEA,QAAQ;oBACR;wBACEI,SAAS;4BACPC,UAAU,MAAMC,IAAAA,8BAAsB;wBACxC;oBACF;iBACD;aACF;YACDC,SAAS;gBACPP,QAAQ;gBACRA,QAAQ;gBACRA,QAAQ;gBACRA,QAAQ;gBACRA,QAAQ;aACT;YACD,GAAIH,eAAe;QACrB;IACA,6GAA6G,GAC/G;IAEAX,OAAOsB,iBAAiB,GAAGnB;IAE3B,8EAA8E;IAC9E,kBAAkB;IAClB,MAAMoB,SAAS,IAAIC,gBAAQ;IAC3BD,OAAOE,IAAI,CAAC3B;IACZyB,OAAOE,IAAI,CAAC;IAEZtB,QAAQuB,GAAG,CAACH,QAAQ;QAClBI,MAAM,IAAI,CAACC,YAAY;IACzB;IAEA,OAAO,IAAIC,QAAgB,CAACC,SAASC;QACnC5B,QAAQ6B,MAAM,CAAC,CAACC,aAAaC;YAC3B,IAAID,aAAa;gBACfF,OAAOE;gBACP;YACF;YAEA,4EAA4E;YAC5E,cAAc;YACdH,QAAQI;QACV;IACF;AACF;MAEA,WAAerC"}
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, /**
6
+ * A Webpack loader that inlines the WASM module as a `Uint8Array`. This makes
7
+ * it possible to import the WASM module directly, and use it with the
8
+ * `WebAssembly.instantiate` function.
9
+ *
10
+ * This is useful, because snaps are not allowed to import assets from outside
11
+ * of their package. This loader allows you to inline the WASM module as a
12
+ * `Uint8Array`, which can then be passed to `WebAssembly.instantiate`.
13
+ *
14
+ * @param source - The WASM module as a string.
15
+ * @returns A string that exports the WASM module as a `Uint8Array`.
16
+ * @example
17
+ * ```ts
18
+ * import wasm from './program.wasm';
19
+ *
20
+ * const { instance } = await WebAssembly.instantiate(wasm, {});
21
+ * // Do something with the WASM module...
22
+ * ```
23
+ */ "default", {
24
+ enumerable: true,
25
+ get: function() {
26
+ return loader;
27
+ }
28
+ });
29
+ const _utils = require("@metamask/utils");
30
+ function loader(source) {
31
+ (0, _utils.assert)(typeof source === 'string', 'Expected source to be a string.');
32
+ const bytes = (0, _utils.stringToBytes)(source);
33
+ return `export default new Uint8Array(${JSON.stringify(Array.from(bytes))});`;
34
+ }
35
+
36
+ //# sourceMappingURL=wasm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/webpack/loaders/wasm.ts"],"sourcesContent":["import { assert, stringToBytes } from '@metamask/utils';\n\n/**\n * A Webpack loader that inlines the WASM module as a `Uint8Array`. This makes\n * it possible to import the WASM module directly, and use it with the\n * `WebAssembly.instantiate` function.\n *\n * This is useful, because snaps are not allowed to import assets from outside\n * of their package. This loader allows you to inline the WASM module as a\n * `Uint8Array`, which can then be passed to `WebAssembly.instantiate`.\n *\n * @param source - The WASM module as a string.\n * @returns A string that exports the WASM module as a `Uint8Array`.\n * @example\n * ```ts\n * import wasm from './program.wasm';\n *\n * const { instance } = await WebAssembly.instantiate(wasm, {});\n * // Do something with the WASM module...\n * ```\n */\nexport default function loader(source: unknown) {\n assert(typeof source === 'string', 'Expected source to be a string.');\n\n const bytes = stringToBytes(source);\n return `export default new Uint8Array(${JSON.stringify(Array.from(bytes))});`;\n}\n"],"names":["loader","source","assert","bytes","stringToBytes","JSON","stringify","Array","from"],"mappings":";;;;+BAEA;;;;;;;;;;;;;;;;;;CAkBC,GACD;;;eAAwBA;;;uBArBc;AAqBvB,SAASA,OAAOC,MAAe;IAC5CC,IAAAA,aAAM,EAAC,OAAOD,WAAW,UAAU;IAEnC,MAAME,QAAQC,IAAAA,oBAAa,EAACH;IAC5B,OAAO,CAAC,8BAA8B,EAAEI,KAAKC,SAAS,CAACC,MAAMC,IAAI,CAACL,QAAQ,EAAE,CAAC;AAC/E"}