@metamask/snaps-cli 6.3.0 → 6.3.2

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 (636) hide show
  1. package/CHANGELOG.md +14 -1
  2. package/dist/__fixtures__/configs/cjs.cjs +9 -0
  3. package/dist/__fixtures__/configs/cjs.cjs.map +1 -0
  4. package/dist/__fixtures__/configs/cjs.d.cts +2 -0
  5. package/dist/__fixtures__/configs/cjs.d.cts.map +1 -0
  6. package/dist/__fixtures__/configs/cjs.d.mts +2 -0
  7. package/dist/__fixtures__/configs/cjs.d.mts.map +1 -0
  8. package/dist/__fixtures__/configs/cjs.mjs +8 -0
  9. package/dist/__fixtures__/configs/cjs.mjs.map +1 -0
  10. package/dist/__fixtures__/configs/esm.cjs +7 -0
  11. package/dist/__fixtures__/configs/esm.cjs.map +1 -0
  12. package/dist/__fixtures__/configs/esm.d.cts +4 -0
  13. package/dist/__fixtures__/configs/esm.d.cts.map +1 -0
  14. package/dist/__fixtures__/configs/esm.d.mts +4 -0
  15. package/dist/__fixtures__/configs/esm.d.mts.map +1 -0
  16. package/dist/__fixtures__/configs/esm.mjs +5 -0
  17. package/dist/__fixtures__/configs/esm.mjs.map +1 -0
  18. package/dist/__fixtures__/configs/invalid.cjs +8 -0
  19. package/dist/__fixtures__/configs/invalid.cjs.map +1 -0
  20. package/dist/__fixtures__/configs/invalid.d.cts +4 -0
  21. package/dist/__fixtures__/configs/invalid.d.cts.map +1 -0
  22. package/dist/__fixtures__/configs/invalid.d.mts +4 -0
  23. package/dist/__fixtures__/configs/invalid.d.mts.map +1 -0
  24. package/dist/__fixtures__/configs/invalid.mjs +6 -0
  25. package/dist/__fixtures__/configs/invalid.mjs.map +1 -0
  26. package/dist/__fixtures__/configs/javascript/snap.config.cjs +6 -0
  27. package/dist/__fixtures__/configs/javascript/snap.config.cjs.map +1 -0
  28. package/dist/__fixtures__/configs/javascript/snap.config.d.cts +2 -0
  29. package/dist/__fixtures__/configs/javascript/snap.config.d.cts.map +1 -0
  30. package/dist/__fixtures__/configs/javascript/snap.config.d.mts +2 -0
  31. package/dist/__fixtures__/configs/javascript/snap.config.d.mts.map +1 -0
  32. package/dist/__fixtures__/configs/javascript/snap.config.mjs +5 -0
  33. package/dist/__fixtures__/configs/javascript/snap.config.mjs.map +1 -0
  34. package/dist/__fixtures__/configs/typescript/snap.config.cjs +7 -0
  35. package/dist/__fixtures__/configs/typescript/snap.config.cjs.map +1 -0
  36. package/dist/__fixtures__/configs/typescript/snap.config.d.cts +4 -0
  37. package/dist/__fixtures__/configs/typescript/snap.config.d.cts.map +1 -0
  38. package/dist/__fixtures__/configs/typescript/snap.config.d.mts +4 -0
  39. package/dist/__fixtures__/configs/typescript/snap.config.d.mts.map +1 -0
  40. package/dist/__fixtures__/configs/typescript/snap.config.mjs +5 -0
  41. package/dist/__fixtures__/configs/typescript/snap.config.mjs.map +1 -0
  42. package/dist/builders.cjs +132 -0
  43. package/dist/builders.cjs.map +1 -0
  44. package/dist/{types/builders.d.ts → builders.d.cts} +2 -1
  45. package/dist/builders.d.cts.map +1 -0
  46. package/dist/builders.d.mts +9 -0
  47. package/dist/builders.d.mts.map +1 -0
  48. package/dist/builders.mjs +127 -8
  49. package/dist/builders.mjs.map +1 -1
  50. package/dist/cli.cjs +71 -0
  51. package/dist/cli.cjs.map +1 -0
  52. package/dist/{types/cli.d.ts → cli.d.cts} +1 -0
  53. package/dist/cli.d.cts.map +1 -0
  54. package/dist/cli.d.mts +16 -0
  55. package/dist/cli.d.mts.map +1 -0
  56. package/dist/cli.mjs +69 -20
  57. package/dist/cli.mjs.map +1 -1
  58. package/dist/commands/build/build.cjs +53 -0
  59. package/dist/commands/build/build.cjs.map +1 -0
  60. package/dist/{types/commands/build/build.d.ts → commands/build/build.d.cts} +3 -1
  61. package/dist/commands/build/build.d.cts.map +1 -0
  62. package/dist/commands/build/build.d.mts +12 -0
  63. package/dist/commands/build/build.d.mts.map +1 -0
  64. package/dist/commands/build/build.mjs +48 -28
  65. package/dist/commands/build/build.mjs.map +1 -1
  66. package/dist/commands/build/implementation.cjs +31 -0
  67. package/dist/commands/build/implementation.cjs.map +1 -0
  68. package/dist/{types/commands/build/implementation.d.ts → commands/build/implementation.d.cts} +3 -2
  69. package/dist/commands/build/implementation.d.cts.map +1 -0
  70. package/dist/commands/build/implementation.d.mts +11 -0
  71. package/dist/commands/build/implementation.d.mts.map +1 -0
  72. package/dist/commands/build/implementation.mjs +26 -27
  73. package/dist/commands/build/implementation.mjs.map +1 -1
  74. package/dist/commands/build/index.cjs +44 -0
  75. package/dist/commands/build/index.cjs.map +1 -0
  76. package/dist/{types/commands/eval/index.d.ts → commands/build/index.d.cts} +4 -3
  77. package/dist/commands/build/index.d.cts.map +1 -0
  78. package/dist/{types/commands/manifest/index.d.ts → commands/build/index.d.mts} +4 -3
  79. package/dist/commands/build/index.d.mts.map +1 -0
  80. package/dist/commands/build/index.mjs +23 -31
  81. package/dist/commands/build/index.mjs.map +1 -1
  82. package/dist/commands/eval/__test__/browserify/bad/snap.config.cjs +10 -0
  83. package/dist/commands/eval/__test__/browserify/bad/snap.config.cjs.map +1 -0
  84. package/dist/commands/eval/__test__/browserify/bad/snap.config.d.cts +4 -0
  85. package/dist/commands/eval/__test__/browserify/bad/snap.config.d.cts.map +1 -0
  86. package/dist/commands/eval/__test__/browserify/bad/snap.config.d.mts +4 -0
  87. package/dist/commands/eval/__test__/browserify/bad/snap.config.d.mts.map +1 -0
  88. package/dist/commands/eval/__test__/browserify/bad/snap.config.mjs +8 -0
  89. package/dist/commands/eval/__test__/browserify/bad/snap.config.mjs.map +1 -0
  90. package/dist/commands/eval/__test__/browserify/good/snap.config.cjs +10 -0
  91. package/dist/commands/eval/__test__/browserify/good/snap.config.cjs.map +1 -0
  92. package/dist/commands/eval/__test__/browserify/good/snap.config.d.cts +4 -0
  93. package/dist/commands/eval/__test__/browserify/good/snap.config.d.cts.map +1 -0
  94. package/dist/commands/eval/__test__/browserify/good/snap.config.d.mts +4 -0
  95. package/dist/commands/eval/__test__/browserify/good/snap.config.d.mts.map +1 -0
  96. package/dist/commands/eval/__test__/browserify/good/snap.config.mjs +8 -0
  97. package/dist/commands/eval/__test__/browserify/good/snap.config.mjs.map +1 -0
  98. package/dist/commands/eval/__test__/webpack/bad/snap.config.cjs +12 -0
  99. package/dist/commands/eval/__test__/webpack/bad/snap.config.cjs.map +1 -0
  100. package/dist/commands/eval/__test__/webpack/bad/snap.config.d.cts +4 -0
  101. package/dist/commands/eval/__test__/webpack/bad/snap.config.d.cts.map +1 -0
  102. package/dist/commands/eval/__test__/webpack/bad/snap.config.d.mts +4 -0
  103. package/dist/commands/eval/__test__/webpack/bad/snap.config.d.mts.map +1 -0
  104. package/dist/commands/eval/__test__/webpack/bad/snap.config.mjs +10 -0
  105. package/dist/commands/eval/__test__/webpack/bad/snap.config.mjs.map +1 -0
  106. package/dist/commands/eval/__test__/webpack/good/snap.config.cjs +12 -0
  107. package/dist/commands/eval/__test__/webpack/good/snap.config.cjs.map +1 -0
  108. package/dist/commands/eval/__test__/webpack/good/snap.config.d.cts +4 -0
  109. package/dist/commands/eval/__test__/webpack/good/snap.config.d.cts.map +1 -0
  110. package/dist/commands/eval/__test__/webpack/good/snap.config.d.mts +4 -0
  111. package/dist/commands/eval/__test__/webpack/good/snap.config.d.mts.map +1 -0
  112. package/dist/commands/eval/__test__/webpack/good/snap.config.mjs +10 -0
  113. package/dist/commands/eval/__test__/webpack/good/snap.config.mjs.map +1 -0
  114. package/dist/commands/eval/__test__/webpack/snap.config.cjs +8 -0
  115. package/dist/commands/eval/__test__/webpack/snap.config.cjs.map +1 -0
  116. package/dist/commands/eval/__test__/webpack/snap.config.d.cts +4 -0
  117. package/dist/commands/eval/__test__/webpack/snap.config.d.cts.map +1 -0
  118. package/dist/commands/eval/__test__/webpack/snap.config.d.mts +4 -0
  119. package/dist/commands/eval/__test__/webpack/snap.config.d.mts.map +1 -0
  120. package/dist/commands/eval/__test__/webpack/snap.config.mjs +6 -0
  121. package/dist/commands/eval/__test__/webpack/snap.config.mjs.map +1 -0
  122. package/dist/commands/eval/eval.cjs +57 -0
  123. package/dist/commands/eval/eval.cjs.map +1 -0
  124. package/dist/{types/commands/eval/eval.d.ts → commands/eval/eval.d.cts} +2 -1
  125. package/dist/commands/eval/eval.d.cts.map +1 -0
  126. package/dist/commands/eval/eval.d.mts +15 -0
  127. package/dist/commands/eval/eval.d.mts.map +1 -0
  128. package/dist/commands/eval/eval.mjs +52 -17
  129. package/dist/commands/eval/eval.mjs.map +1 -1
  130. package/dist/commands/eval/implementation.cjs +30 -0
  131. package/dist/commands/eval/implementation.cjs.map +1 -0
  132. package/dist/{types/commands/eval/implementation.d.ts → commands/eval/implementation.d.cts} +2 -0
  133. package/dist/commands/eval/implementation.d.cts.map +1 -0
  134. package/dist/commands/eval/implementation.d.mts +11 -0
  135. package/dist/commands/eval/implementation.d.mts.map +1 -0
  136. package/dist/commands/eval/implementation.mjs +26 -8
  137. package/dist/commands/eval/implementation.mjs.map +1 -1
  138. package/dist/commands/eval/index.cjs +35 -0
  139. package/dist/commands/eval/index.cjs.map +1 -0
  140. package/dist/commands/eval/index.d.cts +11 -0
  141. package/dist/commands/eval/index.d.cts.map +1 -0
  142. package/dist/commands/eval/index.d.mts +11 -0
  143. package/dist/commands/eval/index.d.mts.map +1 -0
  144. package/dist/commands/eval/index.mjs +14 -20
  145. package/dist/commands/eval/index.mjs.map +1 -1
  146. package/dist/commands/index.cjs +19 -0
  147. package/dist/commands/index.cjs.map +1 -0
  148. package/dist/{types/commands/index.d.ts → commands/index.d.cts} +1 -0
  149. package/dist/commands/index.d.cts.map +1 -0
  150. package/dist/commands/index.d.mts +9 -0
  151. package/dist/commands/index.d.mts.map +1 -0
  152. package/dist/commands/index.mjs +13 -38
  153. package/dist/commands/index.mjs.map +1 -1
  154. package/dist/commands/manifest/implementation.cjs +64 -0
  155. package/dist/commands/manifest/implementation.cjs.map +1 -0
  156. package/dist/{types/commands/manifest/implementation.d.ts → commands/manifest/implementation.d.cts} +3 -1
  157. package/dist/commands/manifest/implementation.d.cts.map +1 -0
  158. package/dist/commands/manifest/implementation.d.mts +14 -0
  159. package/dist/commands/manifest/implementation.d.mts.map +1 -0
  160. package/dist/commands/manifest/implementation.mjs +60 -16
  161. package/dist/commands/manifest/implementation.mjs.map +1 -1
  162. package/dist/commands/manifest/index.cjs +35 -0
  163. package/dist/commands/manifest/index.cjs.map +1 -0
  164. package/dist/commands/manifest/index.d.cts +11 -0
  165. package/dist/commands/manifest/index.d.cts.map +1 -0
  166. package/dist/commands/manifest/index.d.mts +11 -0
  167. package/dist/commands/manifest/index.d.mts.map +1 -0
  168. package/dist/commands/manifest/index.mjs +14 -20
  169. package/dist/commands/manifest/index.mjs.map +1 -1
  170. package/dist/commands/manifest/manifest.cjs +57 -0
  171. package/dist/commands/manifest/manifest.cjs.map +1 -0
  172. package/dist/{types/commands/manifest/manifest.d.ts → commands/manifest/manifest.d.cts} +2 -1
  173. package/dist/commands/manifest/manifest.d.cts.map +1 -0
  174. package/dist/commands/manifest/manifest.d.mts +15 -0
  175. package/dist/commands/manifest/manifest.d.mts.map +1 -0
  176. package/dist/commands/manifest/manifest.mjs +52 -17
  177. package/dist/commands/manifest/manifest.mjs.map +1 -1
  178. package/dist/commands/serve/index.cjs +19 -0
  179. package/dist/commands/serve/index.cjs.map +1 -0
  180. package/dist/{types/commands/serve/index.d.ts → commands/serve/index.d.cts} +3 -2
  181. package/dist/commands/serve/index.d.cts.map +1 -0
  182. package/dist/{types/commands/build/index.d.ts → commands/serve/index.d.mts} +3 -3
  183. package/dist/commands/serve/index.d.mts.map +1 -0
  184. package/dist/commands/serve/index.mjs +12 -27
  185. package/dist/commands/serve/index.mjs.map +1 -1
  186. package/dist/commands/serve/serve.cjs +21 -0
  187. package/dist/commands/serve/serve.cjs.map +1 -0
  188. package/dist/{types/commands/serve/serve.d.ts → commands/serve/serve.d.cts} +2 -1
  189. package/dist/commands/serve/serve.d.cts.map +1 -0
  190. package/dist/commands/serve/serve.d.mts +17 -0
  191. package/dist/commands/serve/serve.d.mts.map +1 -0
  192. package/dist/commands/serve/serve.mjs +16 -27
  193. package/dist/commands/serve/serve.mjs.map +1 -1
  194. package/dist/commands/watch/implementation.cjs +38 -0
  195. package/dist/{chunk-BAEGXYL7.mjs.map → commands/watch/implementation.cjs.map} +1 -1
  196. package/dist/{types/commands/watch/implementation.d.ts → commands/watch/implementation.d.cts} +4 -3
  197. package/dist/commands/watch/implementation.d.cts.map +1 -0
  198. package/dist/commands/watch/implementation.d.mts +15 -0
  199. package/dist/commands/watch/implementation.d.mts.map +1 -0
  200. package/dist/commands/watch/implementation.mjs +33 -27
  201. package/dist/commands/watch/implementation.mjs.map +1 -1
  202. package/dist/commands/watch/index.cjs +49 -0
  203. package/dist/commands/watch/index.cjs.map +1 -0
  204. package/dist/commands/watch/index.d.cts +11 -0
  205. package/dist/commands/watch/index.d.cts.map +1 -0
  206. package/dist/commands/watch/index.d.mts +11 -0
  207. package/dist/commands/watch/index.d.mts.map +1 -0
  208. package/dist/commands/watch/index.mjs +28 -31
  209. package/dist/commands/watch/index.mjs.map +1 -1
  210. package/dist/commands/watch/watch.cjs +49 -0
  211. package/dist/commands/watch/watch.cjs.map +1 -0
  212. package/dist/{types/commands/watch/watch.d.ts → commands/watch/watch.d.cts} +2 -1
  213. package/dist/commands/watch/watch.d.cts.map +1 -0
  214. package/dist/commands/watch/watch.d.mts +20 -0
  215. package/dist/commands/watch/watch.d.mts.map +1 -0
  216. package/dist/commands/watch/watch.mjs +44 -28
  217. package/dist/commands/watch/watch.mjs.map +1 -1
  218. package/dist/config.cjs +334 -0
  219. package/dist/config.cjs.map +1 -0
  220. package/dist/{types/config.d.ts → config.d.cts} +44 -43
  221. package/dist/config.d.cts.map +1 -0
  222. package/dist/config.d.mts +821 -0
  223. package/dist/config.d.mts.map +1 -0
  224. package/dist/config.mjs +322 -35
  225. package/dist/config.mjs.map +1 -1
  226. package/dist/errors.cjs +38 -0
  227. package/dist/errors.cjs.map +1 -0
  228. package/dist/{types/errors.d.ts → errors.d.cts} +1 -0
  229. package/dist/errors.d.cts.map +1 -0
  230. package/dist/errors.d.mts +26 -0
  231. package/dist/errors.d.mts.map +1 -0
  232. package/dist/errors.mjs +32 -11
  233. package/dist/errors.mjs.map +1 -1
  234. package/dist/index.cjs +39 -0
  235. package/dist/index.cjs.map +1 -0
  236. package/dist/index.d.cts +6 -0
  237. package/dist/index.d.cts.map +1 -0
  238. package/dist/index.d.mts +6 -0
  239. package/dist/index.d.mts.map +1 -0
  240. package/dist/index.mjs +4 -44
  241. package/dist/index.mjs.map +1 -1
  242. package/dist/main.cjs +24 -0
  243. package/dist/main.cjs.map +1 -0
  244. package/dist/main.d.cts +3 -0
  245. package/dist/main.d.cts.map +1 -0
  246. package/dist/main.d.mts +3 -0
  247. package/dist/main.d.mts.map +1 -0
  248. package/dist/main.mjs +15 -45
  249. package/dist/main.mjs.map +1 -1
  250. package/dist/structs.cjs +31 -0
  251. package/dist/structs.cjs.map +1 -0
  252. package/dist/{types/structs.d.ts → structs.d.cts} +1 -0
  253. package/dist/structs.d.cts.map +1 -0
  254. package/dist/structs.d.mts +21 -0
  255. package/dist/structs.d.mts.map +1 -0
  256. package/dist/structs.mjs +26 -7
  257. package/dist/structs.mjs.map +1 -1
  258. package/dist/utils/cli.cjs +52 -0
  259. package/dist/utils/cli.cjs.map +1 -0
  260. package/dist/{types/utils/cli.d.ts → utils/cli.d.cts} +1 -0
  261. package/dist/utils/cli.d.cts.map +1 -0
  262. package/dist/utils/cli.d.mts +18 -0
  263. package/dist/utils/cli.d.mts.map +1 -0
  264. package/dist/utils/cli.mjs +43 -13
  265. package/dist/utils/cli.mjs.map +1 -1
  266. package/dist/utils/errors.cjs +49 -0
  267. package/dist/utils/errors.cjs.map +1 -0
  268. package/dist/{types/utils/errors.d.ts → utils/errors.d.cts} +1 -0
  269. package/dist/utils/errors.d.cts.map +1 -0
  270. package/dist/utils/errors.d.mts +24 -0
  271. package/dist/utils/errors.d.mts.map +1 -0
  272. package/dist/utils/errors.mjs +43 -10
  273. package/dist/utils/errors.mjs.map +1 -1
  274. package/dist/utils/index.cjs +23 -0
  275. package/dist/utils/index.cjs.map +1 -0
  276. package/dist/utils/index.d.cts +7 -0
  277. package/dist/utils/index.d.cts.map +1 -0
  278. package/dist/utils/index.d.mts +7 -0
  279. package/dist/utils/index.d.mts.map +1 -0
  280. package/dist/utils/index.mjs +6 -46
  281. package/dist/utils/index.mjs.map +1 -1
  282. package/dist/utils/legacy.cjs +53 -0
  283. package/dist/utils/legacy.cjs.map +1 -0
  284. package/dist/{types/utils/legacy.d.ts → utils/legacy.d.cts} +2 -1
  285. package/dist/utils/legacy.d.cts.map +1 -0
  286. package/dist/utils/legacy.d.mts +28 -0
  287. package/dist/utils/legacy.d.mts.map +1 -0
  288. package/dist/utils/legacy.mjs +46 -12
  289. package/dist/utils/legacy.mjs.map +1 -1
  290. package/dist/utils/logging.cjs +48 -0
  291. package/dist/utils/logging.cjs.map +1 -0
  292. package/dist/{types/utils/logging.d.ts → utils/logging.d.cts} +2 -1
  293. package/dist/utils/logging.d.cts.map +1 -0
  294. package/dist/utils/logging.d.mts +23 -0
  295. package/dist/utils/logging.d.mts.map +1 -0
  296. package/dist/utils/logging.mjs +42 -11
  297. package/dist/utils/logging.mjs.map +1 -1
  298. package/dist/utils/path.cjs +17 -0
  299. package/dist/utils/path.cjs.map +1 -0
  300. package/dist/{types/utils/path.d.ts → utils/path.d.cts} +1 -0
  301. package/dist/utils/path.d.cts.map +1 -0
  302. package/dist/utils/path.d.mts +10 -0
  303. package/dist/utils/path.d.mts.map +1 -0
  304. package/dist/utils/path.mjs +12 -7
  305. package/dist/utils/path.mjs.map +1 -1
  306. package/dist/utils/steps.cjs +51 -0
  307. package/dist/utils/steps.cjs.map +1 -0
  308. package/dist/{types/utils/steps.d.ts → utils/steps.d.cts} +2 -1
  309. package/dist/utils/steps.d.cts.map +1 -0
  310. package/dist/utils/steps.d.mts +18 -0
  311. package/dist/utils/steps.d.mts.map +1 -0
  312. package/dist/utils/steps.mjs +51 -10
  313. package/dist/utils/steps.mjs.map +1 -1
  314. package/dist/webpack/compiler.cjs +19 -0
  315. package/dist/webpack/compiler.cjs.map +1 -0
  316. package/dist/{types/webpack/compiler.d.ts → webpack/compiler.d.cts} +3 -2
  317. package/dist/webpack/compiler.d.cts.map +1 -0
  318. package/dist/webpack/compiler.d.mts +11 -0
  319. package/dist/webpack/compiler.d.mts.map +1 -0
  320. package/dist/webpack/compiler.mjs +15 -24
  321. package/dist/webpack/compiler.mjs.map +1 -1
  322. package/dist/webpack/config.cjs +349 -0
  323. package/dist/webpack/config.cjs.map +1 -0
  324. package/dist/{types/webpack/config.d.ts → webpack/config.d.cts} +4 -3
  325. package/dist/webpack/config.d.cts.map +1 -0
  326. package/dist/webpack/config.d.mts +38 -0
  327. package/dist/webpack/config.d.mts.map +1 -0
  328. package/dist/webpack/config.mjs +349 -23
  329. package/dist/webpack/config.mjs.map +1 -1
  330. package/dist/webpack/index.cjs +21 -0
  331. package/dist/webpack/index.cjs.map +1 -0
  332. package/dist/webpack/index.d.cts +5 -0
  333. package/dist/webpack/index.d.cts.map +1 -0
  334. package/dist/webpack/index.d.mts +5 -0
  335. package/dist/webpack/index.d.mts.map +1 -0
  336. package/dist/webpack/index.mjs +4 -43
  337. package/dist/webpack/index.mjs.map +1 -1
  338. package/dist/webpack/loaders/browserify.cjs +84 -0
  339. package/dist/webpack/loaders/browserify.cjs.map +1 -0
  340. package/dist/{types/webpack/loaders/browserify.d.ts → webpack/loaders/browserify.d.cts} +4 -2
  341. package/dist/webpack/loaders/browserify.d.cts.map +1 -0
  342. package/dist/webpack/loaders/browserify.d.mts +18 -0
  343. package/dist/webpack/loaders/browserify.d.mts.map +1 -0
  344. package/dist/webpack/loaders/browserify.mjs +84 -17
  345. package/dist/webpack/loaders/browserify.mjs.map +1 -1
  346. package/dist/webpack/loaders/function.cjs +45 -0
  347. package/dist/webpack/loaders/function.cjs.map +1 -0
  348. package/dist/{types/webpack/loaders/function.d.ts → webpack/loaders/function.d.cts} +2 -1
  349. package/dist/webpack/loaders/function.d.cts.map +1 -0
  350. package/dist/webpack/loaders/function.d.mts +35 -0
  351. package/dist/webpack/loaders/function.d.mts.map +1 -0
  352. package/dist/webpack/loaders/function.mjs +39 -8
  353. package/dist/webpack/loaders/function.mjs.map +1 -1
  354. package/dist/webpack/loaders/index.cjs +26 -0
  355. package/dist/webpack/loaders/index.cjs.map +1 -0
  356. package/dist/webpack/loaders/index.d.cts +4 -0
  357. package/dist/webpack/loaders/index.d.cts.map +1 -0
  358. package/dist/webpack/loaders/index.d.mts +4 -0
  359. package/dist/webpack/loaders/index.d.mts.map +1 -0
  360. package/dist/webpack/loaders/index.mjs +3 -24
  361. package/dist/webpack/loaders/index.mjs.map +1 -1
  362. package/dist/webpack/loaders/wasm.cjs +103 -0
  363. package/dist/webpack/loaders/wasm.cjs.map +1 -0
  364. package/dist/{types/webpack/loaders/wasm.d.ts → webpack/loaders/wasm.d.cts} +2 -1
  365. package/dist/webpack/loaders/wasm.d.cts.map +1 -0
  366. package/dist/webpack/loaders/wasm.d.mts +43 -0
  367. package/dist/webpack/loaders/wasm.d.mts.map +1 -0
  368. package/dist/webpack/loaders/wasm.mjs +95 -14
  369. package/dist/webpack/loaders/wasm.mjs.map +1 -1
  370. package/dist/webpack/plugins.cjs +277 -0
  371. package/dist/webpack/plugins.cjs.map +1 -0
  372. package/dist/{types/webpack/plugins.d.ts → webpack/plugins.d.cts} +3 -2
  373. package/dist/webpack/plugins.d.cts.map +1 -0
  374. package/dist/webpack/plugins.d.mts +148 -0
  375. package/dist/webpack/plugins.d.mts.map +1 -0
  376. package/dist/webpack/plugins.mjs +270 -27
  377. package/dist/webpack/plugins.mjs.map +1 -1
  378. package/dist/webpack/server.cjs +144 -0
  379. package/dist/webpack/server.cjs.map +1 -0
  380. package/dist/{types/webpack/server.d.ts → webpack/server.d.cts} +5 -3
  381. package/dist/webpack/server.d.cts.map +1 -0
  382. package/dist/webpack/server.d.mts +32 -0
  383. package/dist/webpack/server.d.mts.map +1 -0
  384. package/dist/webpack/server.mjs +142 -9
  385. package/dist/webpack/server.mjs.map +1 -1
  386. package/dist/webpack/utils.cjs +359 -0
  387. package/dist/webpack/utils.cjs.map +1 -0
  388. package/dist/{types/webpack/utils.d.ts → webpack/utils.d.cts} +4 -3
  389. package/dist/webpack/utils.d.cts.map +1 -0
  390. package/dist/webpack/utils.d.mts +259 -0
  391. package/dist/webpack/utils.d.mts.map +1 -0
  392. package/dist/webpack/utils.mjs +350 -37
  393. package/dist/webpack/utils.mjs.map +1 -1
  394. package/package.json +22 -22
  395. package/dist/builders.js +0 -10
  396. package/dist/builders.js.map +0 -1
  397. package/dist/chunk-24QJ2ZUZ.mjs +0 -55
  398. package/dist/chunk-24QJ2ZUZ.mjs.map +0 -1
  399. package/dist/chunk-2P3D6FNV.mjs +0 -23
  400. package/dist/chunk-2P3D6FNV.mjs.map +0 -1
  401. package/dist/chunk-2ZBAKBVW.js +0 -28
  402. package/dist/chunk-2ZBAKBVW.js.map +0 -1
  403. package/dist/chunk-3WWFQLH4.mjs +0 -30
  404. package/dist/chunk-3WWFQLH4.mjs.map +0 -1
  405. package/dist/chunk-45LOTCC4.mjs +0 -1
  406. package/dist/chunk-45LOTCC4.mjs.map +0 -1
  407. package/dist/chunk-4A5QZUC7.mjs +0 -68
  408. package/dist/chunk-4A5QZUC7.mjs.map +0 -1
  409. package/dist/chunk-4JEJ7WKR.js +0 -61
  410. package/dist/chunk-4JEJ7WKR.js.map +0 -1
  411. package/dist/chunk-4QUVE3EK.js +0 -53
  412. package/dist/chunk-4QUVE3EK.js.map +0 -1
  413. package/dist/chunk-5IN3GGMV.js +0 -68
  414. package/dist/chunk-5IN3GGMV.js.map +0 -1
  415. package/dist/chunk-6ABGZTV7.mjs +0 -16
  416. package/dist/chunk-6ABGZTV7.mjs.map +0 -1
  417. package/dist/chunk-6EEZHGF5.js +0 -23
  418. package/dist/chunk-6EEZHGF5.js.map +0 -1
  419. package/dist/chunk-7H5FH7RY.js +0 -22
  420. package/dist/chunk-7H5FH7RY.js.map +0 -1
  421. package/dist/chunk-7RHK2YTB.mjs +0 -32
  422. package/dist/chunk-7RHK2YTB.mjs.map +0 -1
  423. package/dist/chunk-AQSQ7YYP.mjs +0 -24
  424. package/dist/chunk-AQSQ7YYP.mjs.map +0 -1
  425. package/dist/chunk-AZMQTZXZ.mjs +0 -28
  426. package/dist/chunk-AZMQTZXZ.mjs.map +0 -1
  427. package/dist/chunk-B3NNVTA6.js +0 -32
  428. package/dist/chunk-B3NNVTA6.js.map +0 -1
  429. package/dist/chunk-BAEGXYL7.mjs +0 -35
  430. package/dist/chunk-BALQOCUO.js +0 -22
  431. package/dist/chunk-BALQOCUO.js.map +0 -1
  432. package/dist/chunk-BYNQODL3.mjs +0 -23
  433. package/dist/chunk-BYNQODL3.mjs.map +0 -1
  434. package/dist/chunk-C44RRX3H.js +0 -18
  435. package/dist/chunk-C44RRX3H.js.map +0 -1
  436. package/dist/chunk-C46KEPAC.js +0 -37
  437. package/dist/chunk-C46KEPAC.js.map +0 -1
  438. package/dist/chunk-CB77QR32.js +0 -52
  439. package/dist/chunk-CB77QR32.js.map +0 -1
  440. package/dist/chunk-CZRGAFVI.mjs +0 -28
  441. package/dist/chunk-CZRGAFVI.mjs.map +0 -1
  442. package/dist/chunk-D2ZIM5W2.js +0 -370
  443. package/dist/chunk-D2ZIM5W2.js.map +0 -1
  444. package/dist/chunk-DBLADLQ4.js +0 -10
  445. package/dist/chunk-DBLADLQ4.js.map +0 -1
  446. package/dist/chunk-ERSRIVYH.mjs +0 -64
  447. package/dist/chunk-ERSRIVYH.mjs.map +0 -1
  448. package/dist/chunk-G62Q4YO5.js +0 -30
  449. package/dist/chunk-G62Q4YO5.js.map +0 -1
  450. package/dist/chunk-HAYK73YO.js +0 -23
  451. package/dist/chunk-HAYK73YO.js.map +0 -1
  452. package/dist/chunk-HLQEI6DV.js +0 -54
  453. package/dist/chunk-HLQEI6DV.js.map +0 -1
  454. package/dist/chunk-HLSCFGA7.mjs +0 -13
  455. package/dist/chunk-HLSCFGA7.mjs.map +0 -1
  456. package/dist/chunk-HOVEQTF3.mjs +0 -346
  457. package/dist/chunk-HOVEQTF3.mjs.map +0 -1
  458. package/dist/chunk-JAHNVVLT.mjs +0 -18
  459. package/dist/chunk-JAHNVVLT.mjs.map +0 -1
  460. package/dist/chunk-JCVSYVPD.mjs +0 -24
  461. package/dist/chunk-JCVSYVPD.mjs.map +0 -1
  462. package/dist/chunk-JL3URCHO.mjs +0 -53
  463. package/dist/chunk-JL3URCHO.mjs.map +0 -1
  464. package/dist/chunk-K26BOY6Z.mjs +0 -51
  465. package/dist/chunk-K26BOY6Z.mjs.map +0 -1
  466. package/dist/chunk-KLOPX6DO.js +0 -51
  467. package/dist/chunk-KLOPX6DO.js.map +0 -1
  468. package/dist/chunk-KWHAT6UJ.mjs +0 -22
  469. package/dist/chunk-KWHAT6UJ.mjs.map +0 -1
  470. package/dist/chunk-L72RLBV5.mjs +0 -37
  471. package/dist/chunk-L72RLBV5.mjs.map +0 -1
  472. package/dist/chunk-MECBOP7G.js +0 -35
  473. package/dist/chunk-MECBOP7G.js.map +0 -1
  474. package/dist/chunk-MR44GPM3.mjs +0 -135
  475. package/dist/chunk-MR44GPM3.mjs.map +0 -1
  476. package/dist/chunk-MR5TAGOG.mjs +0 -54
  477. package/dist/chunk-MR5TAGOG.mjs.map +0 -1
  478. package/dist/chunk-MUYXNION.js +0 -30
  479. package/dist/chunk-MUYXNION.js.map +0 -1
  480. package/dist/chunk-MXOKUCLH.js +0 -347
  481. package/dist/chunk-MXOKUCLH.js.map +0 -1
  482. package/dist/chunk-NGS23BTR.js +0 -13
  483. package/dist/chunk-NGS23BTR.js.map +0 -1
  484. package/dist/chunk-NOBUMOYX.mjs +0 -61
  485. package/dist/chunk-NOBUMOYX.mjs.map +0 -1
  486. package/dist/chunk-NR4OJOGX.mjs +0 -370
  487. package/dist/chunk-NR4OJOGX.mjs.map +0 -1
  488. package/dist/chunk-OIFTFHZ4.mjs +0 -30
  489. package/dist/chunk-OIFTFHZ4.mjs.map +0 -1
  490. package/dist/chunk-PDYQXXLP.js +0 -30
  491. package/dist/chunk-PDYQXXLP.js.map +0 -1
  492. package/dist/chunk-QAM2JJRA.mjs +0 -52
  493. package/dist/chunk-QAM2JJRA.mjs.map +0 -1
  494. package/dist/chunk-QHCKVO3P.js +0 -28
  495. package/dist/chunk-QHCKVO3P.js.map +0 -1
  496. package/dist/chunk-QMB2ZRWW.js +0 -16
  497. package/dist/chunk-QMB2ZRWW.js.map +0 -1
  498. package/dist/chunk-QMD3VO6R.mjs +0 -30
  499. package/dist/chunk-QMD3VO6R.mjs.map +0 -1
  500. package/dist/chunk-QRW2GKA3.mjs +0 -347
  501. package/dist/chunk-QRW2GKA3.mjs.map +0 -1
  502. package/dist/chunk-R77RJHC5.mjs +0 -44
  503. package/dist/chunk-R77RJHC5.mjs.map +0 -1
  504. package/dist/chunk-RANTKN66.js +0 -24
  505. package/dist/chunk-RANTKN66.js.map +0 -1
  506. package/dist/chunk-S7UP2YYF.js +0 -135
  507. package/dist/chunk-S7UP2YYF.js.map +0 -1
  508. package/dist/chunk-SQXMNT7M.js +0 -326
  509. package/dist/chunk-SQXMNT7M.js.map +0 -1
  510. package/dist/chunk-SYRWT2KT.mjs +0 -124
  511. package/dist/chunk-SYRWT2KT.mjs.map +0 -1
  512. package/dist/chunk-TDSL55B3.mjs +0 -10
  513. package/dist/chunk-TDSL55B3.mjs.map +0 -1
  514. package/dist/chunk-TJ2F3J6X.js +0 -31
  515. package/dist/chunk-TJ2F3J6X.js.map +0 -1
  516. package/dist/chunk-U4VFMIGO.js +0 -24
  517. package/dist/chunk-U4VFMIGO.js.map +0 -1
  518. package/dist/chunk-V6SYDSWM.mjs +0 -326
  519. package/dist/chunk-V6SYDSWM.mjs.map +0 -1
  520. package/dist/chunk-VXOV3ZCB.js +0 -1
  521. package/dist/chunk-VXOV3ZCB.js.map +0 -1
  522. package/dist/chunk-X3D3MHWF.js +0 -44
  523. package/dist/chunk-X3D3MHWF.js.map +0 -1
  524. package/dist/chunk-X7TESUC7.mjs +0 -22
  525. package/dist/chunk-X7TESUC7.mjs.map +0 -1
  526. package/dist/chunk-XGWLFH7Y.js +0 -41
  527. package/dist/chunk-XGWLFH7Y.js.map +0 -1
  528. package/dist/chunk-YCOC4VEP.js +0 -346
  529. package/dist/chunk-YCOC4VEP.js.map +0 -1
  530. package/dist/chunk-YCYGKEXF.mjs +0 -41
  531. package/dist/chunk-YCYGKEXF.mjs.map +0 -1
  532. package/dist/chunk-YGEAZQSC.js +0 -124
  533. package/dist/chunk-YGEAZQSC.js.map +0 -1
  534. package/dist/chunk-YQ2E7NEA.js +0 -64
  535. package/dist/chunk-YQ2E7NEA.js.map +0 -1
  536. package/dist/chunk-ZAW4ZWQX.mjs +0 -31
  537. package/dist/chunk-ZAW4ZWQX.mjs.map +0 -1
  538. package/dist/chunk-ZVUF6JDJ.js +0 -55
  539. package/dist/chunk-ZVUF6JDJ.js.map +0 -1
  540. package/dist/cli.js +0 -21
  541. package/dist/cli.js.map +0 -1
  542. package/dist/commands/build/build.js +0 -29
  543. package/dist/commands/build/build.js.map +0 -1
  544. package/dist/commands/build/implementation.js +0 -28
  545. package/dist/commands/build/implementation.js.map +0 -1
  546. package/dist/commands/build/index.js +0 -33
  547. package/dist/commands/build/index.js.map +0 -1
  548. package/dist/commands/eval/eval.js +0 -18
  549. package/dist/commands/eval/eval.js.map +0 -1
  550. package/dist/commands/eval/implementation.js +0 -9
  551. package/dist/commands/eval/implementation.js.map +0 -1
  552. package/dist/commands/eval/index.js +0 -22
  553. package/dist/commands/eval/index.js.map +0 -1
  554. package/dist/commands/index.js +0 -39
  555. package/dist/commands/index.js.map +0 -1
  556. package/dist/commands/manifest/implementation.js +0 -17
  557. package/dist/commands/manifest/implementation.js.map +0 -1
  558. package/dist/commands/manifest/index.js +0 -22
  559. package/dist/commands/manifest/index.js.map +0 -1
  560. package/dist/commands/manifest/manifest.js +0 -18
  561. package/dist/commands/manifest/manifest.js.map +0 -1
  562. package/dist/commands/serve/index.js +0 -29
  563. package/dist/commands/serve/index.js.map +0 -1
  564. package/dist/commands/serve/serve.js +0 -28
  565. package/dist/commands/serve/serve.js.map +0 -1
  566. package/dist/commands/watch/implementation.js +0 -28
  567. package/dist/commands/watch/implementation.js.map +0 -1
  568. package/dist/commands/watch/index.js +0 -33
  569. package/dist/commands/watch/index.js.map +0 -1
  570. package/dist/commands/watch/watch.js +0 -29
  571. package/dist/commands/watch/watch.js.map +0 -1
  572. package/dist/config.js +0 -36
  573. package/dist/config.js.map +0 -1
  574. package/dist/errors.js +0 -12
  575. package/dist/errors.js.map +0 -1
  576. package/dist/index.js +0 -45
  577. package/dist/index.js.map +0 -1
  578. package/dist/main.js +0 -49
  579. package/dist/main.js.map +0 -1
  580. package/dist/structs.js +0 -8
  581. package/dist/structs.js.map +0 -1
  582. package/dist/tsconfig.build.tsbuildinfo +0 -1
  583. package/dist/types/__fixtures__/configs/cjs.d.ts +0 -1
  584. package/dist/types/__fixtures__/configs/esm.d.ts +0 -3
  585. package/dist/types/__fixtures__/configs/invalid.d.ts +0 -3
  586. package/dist/types/__fixtures__/configs/javascript/snap.config.d.ts +0 -0
  587. package/dist/types/__fixtures__/configs/typescript/snap.config.d.ts +0 -3
  588. package/dist/types/commands/eval/__test__/browserify/bad/snap.config.d.ts +0 -3
  589. package/dist/types/commands/eval/__test__/browserify/good/snap.config.d.ts +0 -3
  590. package/dist/types/commands/eval/__test__/webpack/bad/snap.config.d.ts +0 -3
  591. package/dist/types/commands/eval/__test__/webpack/good/snap.config.d.ts +0 -3
  592. package/dist/types/commands/eval/__test__/webpack/snap.config.d.ts +0 -3
  593. package/dist/types/commands/watch/index.d.ts +0 -10
  594. package/dist/types/index.d.ts +0 -5
  595. package/dist/types/main.d.ts +0 -2
  596. package/dist/types/utils/index.d.ts +0 -6
  597. package/dist/types/webpack/index.d.ts +0 -4
  598. package/dist/types/webpack/loaders/index.d.ts +0 -3
  599. package/dist/types/yargs.d.js +0 -1
  600. package/dist/types/yargs.d.js.map +0 -1
  601. package/dist/types/yargs.d.mjs +0 -1
  602. package/dist/types/yargs.d.mjs.map +0 -1
  603. package/dist/utils/cli.js +0 -14
  604. package/dist/utils/cli.js.map +0 -1
  605. package/dist/utils/errors.js +0 -11
  606. package/dist/utils/errors.js.map +0 -1
  607. package/dist/utils/index.js +0 -47
  608. package/dist/utils/index.js.map +0 -1
  609. package/dist/utils/legacy.js +0 -13
  610. package/dist/utils/legacy.js.map +0 -1
  611. package/dist/utils/logging.js +0 -12
  612. package/dist/utils/logging.js.map +0 -1
  613. package/dist/utils/path.js +0 -8
  614. package/dist/utils/path.js.map +0 -1
  615. package/dist/utils/steps.js +0 -11
  616. package/dist/utils/steps.js.map +0 -1
  617. package/dist/webpack/compiler.js +0 -25
  618. package/dist/webpack/compiler.js.map +0 -1
  619. package/dist/webpack/config.js +0 -24
  620. package/dist/webpack/config.js.map +0 -1
  621. package/dist/webpack/index.js +0 -44
  622. package/dist/webpack/index.js.map +0 -1
  623. package/dist/webpack/loaders/browserify.js +0 -19
  624. package/dist/webpack/loaders/browserify.js.map +0 -1
  625. package/dist/webpack/loaders/function.js +0 -10
  626. package/dist/webpack/loaders/function.js.map +0 -1
  627. package/dist/webpack/loaders/index.js +0 -25
  628. package/dist/webpack/loaders/index.js.map +0 -1
  629. package/dist/webpack/loaders/wasm.js +0 -16
  630. package/dist/webpack/loaders/wasm.js.map +0 -1
  631. package/dist/webpack/plugins.js +0 -29
  632. package/dist/webpack/plugins.js.map +0 -1
  633. package/dist/webpack/server.js +0 -10
  634. package/dist/webpack/server.js.map +0 -1
  635. package/dist/webpack/utils.js +0 -39
  636. package/dist/webpack/utils.js.map +0 -1
@@ -1,10 +1,143 @@
1
- import {
2
- getAllowedPaths,
3
- getServer
4
- } from "../chunk-SYRWT2KT.mjs";
5
- import "../chunk-R77RJHC5.mjs";
6
- export {
7
- getAllowedPaths,
8
- getServer
9
- };
1
+ function $importDefault(module) {
2
+ if (module?.__esModule) {
3
+ return module.default;
4
+ }
5
+ return module;
6
+ }
7
+ import { logError, NpmSnapFileNames, readJsonFile } from "@metamask/snaps-utils/node";
8
+ import { createServer } from "http";
9
+ import { join, relative, resolve as resolvePath, sep, posix } from "path";
10
+ import $serveMiddleware from "serve-handler";
11
+ const serveMiddleware = $importDefault($serveMiddleware);
12
+ /**
13
+ * Get the relative path from one path to another.
14
+ *
15
+ * Note: This is a modified version of `path.relative` that uses Posix
16
+ * separators for URL-compatibility.
17
+ *
18
+ * @param from - The path to start from.
19
+ * @param to - The path to end at.
20
+ * @returns The relative path.
21
+ */
22
+ function getRelativePath(from, to) {
23
+ return relative(from, to).split(sep).join(posix.sep);
24
+ }
25
+ /**
26
+ * Get the allowed paths for the static server. This includes the output file,
27
+ * the manifest file, and any auxiliary/localization files.
28
+ *
29
+ * @param config - The config object.
30
+ * @param manifest - The Snap manifest object.
31
+ * @returns An array of allowed paths.
32
+ */
33
+ export function getAllowedPaths(config, manifest) {
34
+ const auxiliaryFiles = manifest.source.files?.map((file) => getRelativePath(config.server.root, resolvePath(config.server.root, file))) ?? [];
35
+ const localizationFiles = manifest.source.locales?.map((localization) => getRelativePath(config.server.root, resolvePath(config.server.root, localization))) ?? [];
36
+ const otherFiles = manifest.source.location.npm.iconPath
37
+ ? [
38
+ getRelativePath(config.server.root, resolvePath(config.server.root, manifest.source.location.npm.iconPath)),
39
+ ]
40
+ : [];
41
+ return [
42
+ getRelativePath(config.server.root, resolvePath(config.server.root, config.output.path, config.output.filename)),
43
+ getRelativePath(config.server.root, resolvePath(config.server.root, NpmSnapFileNames.Manifest)),
44
+ ...auxiliaryFiles,
45
+ ...localizationFiles,
46
+ ...otherFiles,
47
+ ];
48
+ }
49
+ /**
50
+ * Get a static server for development purposes.
51
+ *
52
+ * Note: We're intentionally not using `webpack-dev-server` here because it
53
+ * adds a lot of extra stuff to the output that we don't need, and it's
54
+ * difficult to customize.
55
+ *
56
+ * @param config - The config object.
57
+ * @returns An object with a `listen` method that returns a promise that
58
+ * resolves when the server is listening.
59
+ */
60
+ export function getServer(config) {
61
+ /**
62
+ * Get the response for a request. This is extracted into a function so that
63
+ * we can easily catch errors and send a 500 response.
64
+ *
65
+ * @param request - The request.
66
+ * @param response - The response.
67
+ * @returns A promise that resolves when the response is sent.
68
+ */
69
+ async function getResponse(request, response) {
70
+ const manifestPath = join(config.server.root, NpmSnapFileNames.Manifest);
71
+ const { result } = await readJsonFile(manifestPath);
72
+ const allowedPaths = getAllowedPaths(config, result);
73
+ const path = request.url?.slice(1);
74
+ const allowed = allowedPaths.some((allowedPath) => path === allowedPath);
75
+ if (!allowed) {
76
+ response.statusCode = 404;
77
+ response.end();
78
+ return;
79
+ }
80
+ await serveMiddleware(request, response, {
81
+ public: config.server.root,
82
+ directoryListing: false,
83
+ headers: [
84
+ {
85
+ source: '**/*',
86
+ headers: [
87
+ {
88
+ key: 'Cache-Control',
89
+ value: 'no-cache',
90
+ },
91
+ {
92
+ key: 'Access-Control-Allow-Origin',
93
+ value: '*',
94
+ },
95
+ ],
96
+ },
97
+ ],
98
+ });
99
+ }
100
+ const server = createServer((request, response) => {
101
+ getResponse(request, response).catch(
102
+ /* istanbul ignore next */
103
+ (error) => {
104
+ logError(error);
105
+ response.statusCode = 500;
106
+ response.end();
107
+ });
108
+ });
109
+ /**
110
+ * Start the server on the port specified in the config.
111
+ *
112
+ * @param port - The port to listen on.
113
+ * @returns A promise that resolves when the server is listening. The promise
114
+ * resolves to an object with the port and the server instance. Note that if
115
+ * the `config.server.port` is `0`, the OS will choose a random port for us,
116
+ * so we need to get the port from the server after it starts.
117
+ */
118
+ const listen = async (port = config.server.port) => {
119
+ return new Promise((resolve, reject) => {
120
+ try {
121
+ server.listen(port, () => {
122
+ const close = async () => {
123
+ await new Promise((resolveClose, rejectClose) => {
124
+ server.close((closeError) => {
125
+ if (closeError) {
126
+ return rejectClose(closeError);
127
+ }
128
+ return resolveClose();
129
+ });
130
+ });
131
+ };
132
+ const address = server.address();
133
+ resolve({ port: address.port, server, close });
134
+ });
135
+ }
136
+ catch (listenError) {
137
+ reject(listenError);
138
+ }
139
+ });
140
+ };
141
+ return { listen };
142
+ }
10
143
  //# sourceMappingURL=server.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
1
+ {"version":3,"file":"server.mjs","sourceRoot":"","sources":["../../src/webpack/server.ts"],"names":[],"mappings":";;;;;;AACA,OAAO,EACL,QAAQ,EACR,gBAAgB,EAChB,YAAY,EACb,mCAAmC;AAEpC,OAAO,EAAE,YAAY,EAAE,aAAa;AAEpC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,IAAI,WAAW,EAAE,GAAG,EAAE,KAAK,EAAE,aAAa;AAC1E,OAAO,gBAAe,sBAAsB;;AAI5C;;;;;;;;;GASG;AACH,SAAS,eAAe,CAAC,IAAY,EAAE,EAAU;IAC/C,OAAO,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;AACvD,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAC7B,MAAuB,EACvB,QAAsB;IAEtB,MAAM,cAAc,GAClB,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAClC,eAAe,CACb,MAAM,CAAC,MAAM,CAAC,IAAI,EAClB,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CACtC,CACF,IAAI,EAAE,CAAC;IAEV,MAAM,iBAAiB,GACrB,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,YAAY,EAAE,EAAE,CAC5C,eAAe,CACb,MAAM,CAAC,MAA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,MAAM,KAAK,GAAG,KAAK,IAAI,EAAE;wBACvB,MAAM,IAAI,OAAO,CAAO,CAAC,YAAY,EAAE,WAAW,EAAE,EAAE;4BACpD,MAAM,CAAC,KAAK,CAAC,CAAC,UAAU,EAAE,EAAE;gCAC1B,IAAI,UAAU,EAAE,CAAC;oCACf,OAAO,WAAW,CAAC,UAAU,CAAC,CAAC;gCACjC,CAAC;gCAED,OAAO,YAAY,EAAE,CAAC;4BACxB,CAAC,CAAC,CAAC;wBACL,CAAC,CAAC,CAAC;oBACL,CAAC,CAAC;oBAEF,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,EAAiB,CAAC;oBAChD,OAAO,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;gBACjD,CAAC,CAAC,CAAC;YACL,CAAC;YAAC,OAAO,WAAW,EAAE,CAAC;gBACrB,MAAM,CAAC,WAAW,CAAC,CAAC;YACtB,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;IAEF,OAAO,EAAE,MAAM,EAAE,CAAC;AACpB,CAAC","sourcesContent":["import type { SnapManifest } from '@metamask/snaps-utils';\nimport {\n logError,\n NpmSnapFileNames,\n readJsonFile,\n} from '@metamask/snaps-utils/node';\nimport type { IncomingMessage, Server, ServerResponse } from 'http';\nimport { createServer } from 'http';\nimport type { AddressInfo } from 'net';\nimport { join, relative, resolve as resolvePath, sep, posix } from 'path';\nimport serveMiddleware from 'serve-handler';\n\nimport type { ProcessedConfig } from '../config';\n\n/**\n * Get the relative path from one path to another.\n *\n * Note: This is a modified version of `path.relative` that uses Posix\n * separators for URL-compatibility.\n *\n * @param from - The path to start from.\n * @param to - The path to end at.\n * @returns The relative path.\n */\nfunction getRelativePath(from: string, to: string) {\n return relative(from, to).split(sep).join(posix.sep);\n}\n\n/**\n * Get the allowed paths for the static server. This includes the output file,\n * the manifest file, and any auxiliary/localization files.\n *\n * @param config - The config object.\n * @param manifest - The Snap manifest object.\n * @returns An array of allowed paths.\n */\nexport function getAllowedPaths(\n config: ProcessedConfig,\n manifest: SnapManifest,\n) {\n const auxiliaryFiles =\n manifest.source.files?.map((file) =>\n getRelativePath(\n config.server.root,\n resolvePath(config.server.root, file),\n ),\n ) ?? [];\n\n const localizationFiles =\n manifest.source.locales?.map((localization) =>\n getRelativePath(\n config.server.root,\n resolvePath(config.server.root, localization),\n ),\n ) ?? [];\n\n const otherFiles = manifest.source.location.npm.iconPath\n ? [\n getRelativePath(\n config.server.root,\n resolvePath(\n config.server.root,\n manifest.source.location.npm.iconPath,\n ),\n ),\n ]\n : [];\n\n return [\n getRelativePath(\n config.server.root,\n resolvePath(\n config.server.root,\n config.output.path,\n config.output.filename,\n ),\n ),\n getRelativePath(\n config.server.root,\n resolvePath(config.server.root, NpmSnapFileNames.Manifest),\n ),\n ...auxiliaryFiles,\n ...localizationFiles,\n ...otherFiles,\n ];\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 /**\n * Get the response for a request. This is extracted into a function so that\n * we can easily catch errors and send a 500 response.\n *\n * @param request - The request.\n * @param response - The response.\n * @returns A promise that resolves when the response is sent.\n */\n async function getResponse(\n request: IncomingMessage,\n response: ServerResponse,\n ) {\n const manifestPath = join(config.server.root, NpmSnapFileNames.Manifest);\n const { result } = await readJsonFile<SnapManifest>(manifestPath);\n const allowedPaths = getAllowedPaths(config, result);\n\n const path = request.url?.slice(1);\n const allowed = allowedPaths.some((allowedPath) => path === allowedPath);\n\n if (!allowed) {\n response.statusCode = 404;\n response.end();\n return;\n }\n\n await serveMiddleware(request, response, {\n public: config.server.root,\n directoryListing: false,\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 });\n }\n\n const server = createServer((request, response) => {\n getResponse(request, response).catch(\n /* istanbul ignore next */\n (error) => {\n logError(error);\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"]}
@@ -0,0 +1,359 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getImageSVG = exports.formatText = exports.getEnvironmentVariables = exports.getFallbacks = exports.pluralize = exports.getBrowserslistTargets = exports.getProgressHandler = exports.getDevTool = exports.getDefaultLoader = exports.WEBPACK_FALLBACKS = exports.BROWSERSLIST_FILE = void 0;
7
+ const utils_1 = require("@metamask/utils");
8
+ const chalk_1 = require("chalk");
9
+ const fs_1 = require("fs");
10
+ const module_1 = require("module");
11
+ const path_1 = require("path");
12
+ const strip_ansi_1 = __importDefault(require("strip-ansi/index.js"));
13
+ const loaders_1 = require("./loaders/index.cjs");
14
+ exports.BROWSERSLIST_FILE = (0, path_1.resolve)((0, path_1.dirname)(
15
+ // eslint-disable-next-line n/no-extraneous-require
16
+ require.resolve('@metamask/snaps-cli/package.json')), '.browserslistrc');
17
+ exports.WEBPACK_FALLBACKS = {
18
+ assert: require.resolve('assert/'),
19
+ buffer: require.resolve('buffer/'),
20
+ console: require.resolve('console-browserify'),
21
+ constants: require.resolve('constants-browserify'),
22
+ crypto: require.resolve('crypto-browserify'),
23
+ domain: require.resolve('domain-browser'),
24
+ events: require.resolve('events/'),
25
+ http: require.resolve('stream-http'),
26
+ https: require.resolve('https-browserify'),
27
+ os: require.resolve('os-browserify/browser'),
28
+ path: require.resolve('path-browserify'),
29
+ punycode: require.resolve('punycode/'),
30
+ process: require.resolve('process/browser'),
31
+ querystring: require.resolve('querystring-es3'),
32
+ stream: require.resolve('stream-browserify'),
33
+ /* eslint-disable @typescript-eslint/naming-convention */
34
+ _stream_duplex: require.resolve('readable-stream/lib/_stream_duplex'),
35
+ _stream_passthrough: require.resolve('readable-stream/lib/_stream_passthrough'),
36
+ _stream_readable: require.resolve('readable-stream/lib/_stream_readable'),
37
+ _stream_transform: require.resolve('readable-stream/lib/_stream_transform'),
38
+ _stream_writable: require.resolve('readable-stream/lib/_stream_writable'),
39
+ string_decoder: require.resolve('string_decoder/'),
40
+ /* eslint-enable @typescript-eslint/naming-convention */
41
+ sys: require.resolve('util/'),
42
+ timers: require.resolve('timers-browserify'),
43
+ tty: require.resolve('tty-browserify'),
44
+ url: require.resolve('url/'),
45
+ util: require.resolve('util/'),
46
+ vm: require.resolve('vm-browserify'),
47
+ zlib: require.resolve('browserify-zlib'),
48
+ };
49
+ /**
50
+ * Get the default loader for JavaScript and TypeScript files, based on the
51
+ * config object.
52
+ *
53
+ * - If the `legacy` option is set, we use the custom `browserify` loader. This
54
+ * uses the legacy Browserify config to transpile the code.
55
+ * - Otherwise, we use the `swc-loader`. This is a Webpack loader that uses the
56
+ * `SWC` compiler, which is a much faster alternative to Babel and TypeScript's
57
+ * own compiler.
58
+ *
59
+ * @param config - The processed snap Webpack config.
60
+ * @param config.legacy - The legacy config object, if any.
61
+ * @param config.sourceMap - Whether to generate source maps.
62
+ * @see https://swc.rs/docs/usage/swc-loader
63
+ * @returns The default loader.
64
+ */
65
+ async function getDefaultLoader({ legacy, sourceMap, }) {
66
+ if (legacy) {
67
+ /**
68
+ * If the snap uses the legacy config, we use the custom `browserify`
69
+ * loader. This uses the legacy Browserify config to transpile the code.
70
+ * This is necessary for backwards compatibility with the
71
+ * `bundlerCustomizer` function.
72
+ */
73
+ return (0, loaders_1.getFunctionLoader)(loaders_1.browserify, legacy);
74
+ }
75
+ const targets = await getBrowserslistTargets();
76
+ return {
77
+ /**
78
+ * We use the `swc-loader` to transpile TypeScript and JavaScript files.
79
+ * This is a Webpack loader that uses the `SWC` compiler, which is a much
80
+ * faster alternative to Babel and TypeScript's own compiler.
81
+ */
82
+ loader: require.resolve('swc-loader'),
83
+ /**
84
+ * The options for the `swc-loader`. These can be overridden in the
85
+ * `.swcrc` file.
86
+ *
87
+ * @see https://swc.rs/docs/configuration/swcrc
88
+ */
89
+ options: {
90
+ sync: false,
91
+ /**
92
+ * This tells SWC to generate source maps. We set it to the
93
+ * `sourceMap` value from the config object.
94
+ *
95
+ * This must be enabled if source maps are enabled in the config.
96
+ */
97
+ sourceMaps: Boolean(getDevTool(sourceMap)),
98
+ jsc: {
99
+ parser: {
100
+ /**
101
+ * This tells the parser to parse TypeScript files. If you
102
+ * don't need to support TypeScript, you can set this to
103
+ * `ecmascript` instead, but there's no harm in leaving it
104
+ * as `typescript`.
105
+ *
106
+ * @see https://swc.rs/docs/configuration/compilation#jscparser
107
+ */
108
+ syntax: 'typescript',
109
+ /**
110
+ * This tells the parser to transpile JSX.
111
+ *
112
+ * @see https://swc.rs/docs/configuration/compilation#jscparser
113
+ * @see https://swc.rs/docs/configuration/compilation#jscparserjsx
114
+ */
115
+ tsx: true,
116
+ },
117
+ transform: {
118
+ react: {
119
+ /**
120
+ * This tells SWC to use the JSX runtime, instead of the
121
+ * `createElement` function.
122
+ *
123
+ * @see https://swc.rs/docs/configuration/compilation#jsctransformreact
124
+ */
125
+ runtime: 'automatic',
126
+ /**
127
+ * This tells SWC to import the JSX runtime from the
128
+ * `@metamask/snaps-sdk` package, instead of the default React
129
+ * package.
130
+ *
131
+ * @see https://swc.rs/docs/configuration/compilation#jsctransformreact
132
+ */
133
+ importSource: '@metamask/snaps-sdk',
134
+ /**
135
+ * This tells SWC to use `Object.assign` and `Object.create` for
136
+ * JSX spread attributes, instead of the default behavior.
137
+ *
138
+ * @see https://swc.rs/docs/configuration/compilation#jsctransformreact
139
+ */
140
+ useBuiltins: true,
141
+ },
142
+ },
143
+ },
144
+ /**
145
+ * The module configuration. This tells SWC how to output the
146
+ * transpiled code.
147
+ *
148
+ * @see https://swc.rs/docs/configuration/modules
149
+ */
150
+ module: {
151
+ /**
152
+ * This tells SWC to output ES6 modules. This will allow Webpack to
153
+ * optimize the output code better. Snaps don't support ES6 however, so
154
+ * the output code will be transpiled to CommonJS by Webpack later in
155
+ * the build process.
156
+ *
157
+ * @see https://swc.rs/docs/configuration/modules#es6
158
+ */
159
+ type: 'es6',
160
+ },
161
+ env: {
162
+ targets: targets.join(', '),
163
+ },
164
+ },
165
+ };
166
+ }
167
+ exports.getDefaultLoader = getDefaultLoader;
168
+ /**
169
+ * Get the Webpack devtool configuration based on the given snap config.
170
+ *
171
+ * - If `sourceMap` is `inline`, return `inline-source-map`.
172
+ * - If `sourceMap` is `true`, return `source-map`.
173
+ * - Otherwise, return `false`.
174
+ *
175
+ * @param sourceMap - The `sourceMap` value from the snap config.
176
+ * @returns The Webpack devtool configuration.
177
+ */
178
+ function getDevTool(sourceMap) {
179
+ if (sourceMap === 'inline') {
180
+ return 'inline-source-map';
181
+ }
182
+ if (sourceMap === true) {
183
+ return 'source-map';
184
+ }
185
+ return false;
186
+ }
187
+ exports.getDevTool = getDevTool;
188
+ /**
189
+ * Get a function that can be used as handler function for Webpack's
190
+ * `ProgressPlugin`.
191
+ *
192
+ * @param spinner - The spinner to update.
193
+ * @param spinnerText - The initial spinner text. This will be prepended to the
194
+ * percentage.
195
+ * @returns A function that can be used as handler function for Webpack's
196
+ * `ProgressPlugin`.
197
+ */
198
+ // Note: This is extracted for testing purposes.
199
+ function getProgressHandler(spinner, spinnerText) {
200
+ return (percentage) => {
201
+ if (spinner && spinnerText) {
202
+ spinner.text = `${spinnerText} ${(0, chalk_1.dim)(`(${Math.round(percentage * 100)}%)`)}`;
203
+ }
204
+ };
205
+ }
206
+ exports.getProgressHandler = getProgressHandler;
207
+ /**
208
+ * Get the targets from the `.browserslistrc` file.
209
+ *
210
+ * @returns The browser targets as an array of strings.
211
+ */
212
+ async function getBrowserslistTargets() {
213
+ const contents = await fs_1.promises.readFile(exports.BROWSERSLIST_FILE, 'utf8');
214
+ return contents
215
+ .split('\n')
216
+ .map((line) => line.trim())
217
+ .filter((line) => line && !line.startsWith('#'));
218
+ }
219
+ exports.getBrowserslistTargets = getBrowserslistTargets;
220
+ /**
221
+ * Get a singular or plural string based on the given count. This is useful for
222
+ * generating messages like "1 error" or "2 errors". By default, the plural
223
+ * string is the singular string with an "s" appended to it.
224
+ *
225
+ * This assumes that the text is in English, and likely won't work for some
226
+ * other languages.
227
+ *
228
+ * @param count - The count.
229
+ * @param singular - The singular string.
230
+ * @param plural - The plural string.
231
+ * @returns The singular or plural string.
232
+ * @example
233
+ * ```typescript
234
+ * pluralize(1, 'error'); // => 'error'
235
+ * pluralize(2, 'error'); // => 'errors'
236
+ * pluralize(1, 'error', 'problem'); // => 'error'
237
+ * pluralize(2, 'error', 'problems'); // => 'problems'
238
+ * ```
239
+ */
240
+ function pluralize(count, singular, plural = `${singular}s`) {
241
+ return count === 1 ? singular : plural;
242
+ }
243
+ exports.pluralize = pluralize;
244
+ /**
245
+ * Get an object that can be used as fallback config for Webpack's
246
+ * `fallback` config.
247
+ *
248
+ * @param polyfills - The polyfill object from the snap config.
249
+ * @returns The webpack fallback config.
250
+ */
251
+ function getFallbacks(polyfills) {
252
+ if (polyfills === true) {
253
+ return Object.fromEntries(module_1.builtinModules.map((name) => [
254
+ name,
255
+ exports.WEBPACK_FALLBACKS[name] ?? false,
256
+ ]));
257
+ }
258
+ if (polyfills === false) {
259
+ return Object.fromEntries(module_1.builtinModules.map((name) => [name, false]));
260
+ }
261
+ return Object.fromEntries(module_1.builtinModules.map((name) => [
262
+ name,
263
+ polyfills[name]
264
+ ? exports.WEBPACK_FALLBACKS[name]
265
+ : false,
266
+ ]));
267
+ }
268
+ exports.getFallbacks = getFallbacks;
269
+ /**
270
+ * Get an object that can be used as environment variables for Webpack's
271
+ * `DefinePlugin`.
272
+ *
273
+ * @param environment - The environment object from the Snap config.
274
+ * @param defaults - The default environment variables.
275
+ * @returns The Webpack environment variables.
276
+ */
277
+ function getEnvironmentVariables(environment, defaults = {
278
+ NODE_DEBUG: 'false',
279
+ NODE_ENV: 'production',
280
+ DEBUG: 'false',
281
+ }) {
282
+ return Object.fromEntries(Object.entries({
283
+ ...defaults,
284
+ ...environment,
285
+ }).map(([key, value]) => [`process.env.${key}`, JSON.stringify(value)]));
286
+ }
287
+ exports.getEnvironmentVariables = getEnvironmentVariables;
288
+ /**
289
+ * Format the given line to fit within the terminal width.
290
+ *
291
+ * @param line - The line to format.
292
+ * @param indent - The indentation to use.
293
+ * @param initialIndent - The initial indentation to use, i.e., the indentation
294
+ * for the first line.
295
+ * @returns The formatted line.
296
+ */
297
+ function formatLine(line, indent, initialIndent) {
298
+ const terminalWidth = process.stdout.columns;
299
+ if (!terminalWidth) {
300
+ return `${' '.repeat(initialIndent)}${line}`;
301
+ }
302
+ return line.split(' ').reduce(({ formattedText, currentLineLength }, word, index) => {
303
+ // `chalk` adds ANSI escape codes to the text, which are not visible
304
+ // characters. We need to strip them to get the visible length of the
305
+ // text.
306
+ const visibleWord = (0, strip_ansi_1.default)(word);
307
+ // Determine if a space should be added before the word.
308
+ const spaceBeforeWord = index > 0 ? ' ' : '';
309
+ const wordLengthWithSpace = visibleWord.length + spaceBeforeWord.length;
310
+ // If the word would exceed the terminal width, start a new line.
311
+ if (currentLineLength + wordLengthWithSpace > terminalWidth) {
312
+ return {
313
+ formattedText: `${formattedText}\n${' '.repeat(indent)}${word}`,
314
+ currentLineLength: indent + visibleWord.length,
315
+ };
316
+ }
317
+ // Otherwise, add the word to the current line.
318
+ return {
319
+ formattedText: formattedText + spaceBeforeWord + word,
320
+ currentLineLength: currentLineLength + wordLengthWithSpace,
321
+ };
322
+ }, {
323
+ formattedText: ' '.repeat(initialIndent),
324
+ currentLineLength: initialIndent,
325
+ }).formattedText;
326
+ }
327
+ /**
328
+ * Format the given text to fit within the terminal width.
329
+ *
330
+ * @param text - The text to format.
331
+ * @param indent - The indentation to use.
332
+ * @param initialIndent - The initial indentation to use, i.e., the indentation
333
+ * for the first line.
334
+ * @returns The formatted text.
335
+ */
336
+ function formatText(text, indent, initialIndent = indent) {
337
+ const lines = text.split('\n');
338
+ // Apply formatting to each line separately and then join them.
339
+ return lines
340
+ .map((line, index) => {
341
+ const lineIndent = index === 0 ? initialIndent : indent;
342
+ return formatLine(line, indent, lineIndent);
343
+ })
344
+ .join('\n');
345
+ }
346
+ exports.formatText = formatText;
347
+ /**
348
+ * Get an SVG from the given bytes and mime type.
349
+ *
350
+ * @param mimeType - The mime type of the image.
351
+ * @param bytes - The image bytes.
352
+ * @returns The SVG.
353
+ */
354
+ function getImageSVG(mimeType, bytes) {
355
+ const dataUrl = `data:${mimeType};base64,${(0, utils_1.bytesToBase64)(bytes)}`;
356
+ return `<svg xmlns="http://www.w3.org/2000/svg"><image href="${dataUrl}" /></svg>`;
357
+ }
358
+ exports.getImageSVG = getImageSVG;
359
+ //# sourceMappingURL=utils.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../../src/webpack/utils.ts"],"names":[],"mappings":";;;;;;AAAA,2CAAgD;AAChD,iCAA4B;AAC5B,2BAAoC;AACpC,mCAAwC;AAExC,+BAAwC;AACxC,qEAAmC;AAInC,iDAA0D;AAE7C,QAAA,iBAAiB,GAAG,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a,EAAE,aAAa,GAAG,eAAe,GAAG,IAAI;YACrD,iBAAiB,EAAE,iBAAiB,GAAG,mBAAmB;SAC3D,CAAC;IACJ,CAAC,EACD;QACE,aAAa,EAAE,GAAG,CAAC,MAAM,CAAC,aAAa,CAAC;QACxC,iBAAiB,EAAE,aAAa;KACjC,CACF,CAAC,aAAa,CAAC;AAClB,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,UAAU,CACxB,IAAY,EACZ,MAAc,EACd,aAAa,GAAG,MAAM;IAEtB,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAE/B,+DAA+D;IAC/D,OAAO,KAAK;SACT,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;QACnB,MAAM,UAAU,GAAG,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,MAAM,CAAC;QACxD,OAAO,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;IAC9C,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC;AAdD,gCAcC;AAED;;;;;;GAMG;AACH,SAAgB,WAAW,CAAC,QAAgB,EAAE,KAAiB;IAC7D,MAAM,OAAO,GAAG,QAAQ,QAAQ,WAAW,IAAA,qBAAa,EAAC,KAAK,CAAC,EAAE,CAAC;IAClE,OAAO,wDAAwD,OAAO,YAAY,CAAC;AACrF,CAAC;AAHD,kCAGC","sourcesContent":["import { bytesToBase64 } from '@metamask/utils';\nimport { dim } from 'chalk';\nimport { promises as fs } from 'fs';\nimport { builtinModules } from 'module';\nimport type { Ora } from 'ora';\nimport { dirname, resolve } from 'path';\nimport stripAnsi from 'strip-ansi';\nimport type { Configuration } from 'webpack';\n\nimport type { ProcessedWebpackConfig } from '../config';\nimport { browserify, getFunctionLoader } from './loaders';\n\nexport const BROWSERSLIST_FILE = resolve(\n dirname(\n // eslint-disable-next-line n/no-extraneous-require\n require.resolve('@metamask/snaps-cli/package.json'),\n ),\n '.browserslistrc',\n);\n\nexport const WEBPACK_FALLBACKS = {\n assert: require.resolve('assert/'),\n buffer: require.resolve('buffer/'),\n console: require.resolve('console-browserify'),\n constants: require.resolve('constants-browserify'),\n crypto: require.resolve('crypto-browserify'),\n domain: require.resolve('domain-browser'),\n events: require.resolve('events/'),\n http: require.resolve('stream-http'),\n https: require.resolve('https-browserify'),\n os: require.resolve('os-browserify/browser'),\n path: require.resolve('path-browserify'),\n punycode: require.resolve('punycode/'),\n process: require.resolve('process/browser'),\n querystring: require.resolve('querystring-es3'),\n stream: require.resolve('stream-browserify'),\n /* eslint-disable @typescript-eslint/naming-convention */\n _stream_duplex: require.resolve('readable-stream/lib/_stream_duplex'),\n _stream_passthrough: require.resolve(\n 'readable-stream/lib/_stream_passthrough',\n ),\n _stream_readable: require.resolve('readable-stream/lib/_stream_readable'),\n _stream_transform: require.resolve('readable-stream/lib/_stream_transform'),\n _stream_writable: require.resolve('readable-stream/lib/_stream_writable'),\n string_decoder: require.resolve('string_decoder/'),\n /* eslint-enable @typescript-eslint/naming-convention */\n sys: require.resolve('util/'),\n timers: require.resolve('timers-browserify'),\n tty: require.resolve('tty-browserify'),\n url: require.resolve('url/'),\n util: require.resolve('util/'),\n vm: require.resolve('vm-browserify'),\n zlib: require.resolve('browserify-zlib'),\n};\n\n/**\n * Get the default loader for JavaScript and TypeScript files, based on the\n * config object.\n *\n * - If the `legacy` option is set, we use the custom `browserify` loader. This\n * uses the legacy Browserify config to transpile the code.\n * - Otherwise, we use the `swc-loader`. This is a Webpack loader that uses the\n * `SWC` compiler, which is a much faster alternative to Babel and TypeScript's\n * own compiler.\n *\n * @param config - The processed snap Webpack config.\n * @param config.legacy - The legacy config object, if any.\n * @param config.sourceMap - Whether to generate source maps.\n * @see https://swc.rs/docs/usage/swc-loader\n * @returns The default loader.\n */\nexport async function getDefaultLoader({\n legacy,\n sourceMap,\n}: ProcessedWebpackConfig) {\n if (legacy) {\n /**\n * If the snap uses the legacy config, we use the custom `browserify`\n * loader. This uses the legacy Browserify config to transpile the code.\n * This is necessary for backwards compatibility with the\n * `bundlerCustomizer` function.\n */\n return getFunctionLoader(browserify, legacy);\n }\n\n const targets = await getBrowserslistTargets();\n return {\n /**\n * We use the `swc-loader` to transpile TypeScript and JavaScript files.\n * This is a Webpack loader that uses the `SWC` compiler, which is a much\n * faster alternative to Babel and TypeScript's own compiler.\n */\n loader: require.resolve('swc-loader'),\n\n /**\n * The options for the `swc-loader`. These can be overridden in the\n * `.swcrc` file.\n *\n * @see https://swc.rs/docs/configuration/swcrc\n */\n options: {\n sync: false,\n\n /**\n * This tells SWC to generate source maps. We set it to the\n * `sourceMap` value from the config object.\n *\n * This must be enabled if source maps are enabled in the config.\n */\n sourceMaps: Boolean(getDevTool(sourceMap)),\n\n jsc: {\n parser: {\n /**\n * This tells the parser to parse TypeScript files. If you\n * don't need to support TypeScript, you can set this to\n * `ecmascript` instead, but there's no harm in leaving it\n * as `typescript`.\n *\n * @see https://swc.rs/docs/configuration/compilation#jscparser\n */\n syntax: 'typescript',\n\n /**\n * This tells the parser to transpile JSX.\n *\n * @see https://swc.rs/docs/configuration/compilation#jscparser\n * @see https://swc.rs/docs/configuration/compilation#jscparserjsx\n */\n tsx: true,\n },\n\n transform: {\n react: {\n /**\n * This tells SWC to use the JSX runtime, instead of the\n * `createElement` function.\n *\n * @see https://swc.rs/docs/configuration/compilation#jsctransformreact\n */\n runtime: 'automatic',\n\n /**\n * This tells SWC to import the JSX runtime from the\n * `@metamask/snaps-sdk` package, instead of the default React\n * package.\n *\n * @see https://swc.rs/docs/configuration/compilation#jsctransformreact\n */\n importSource: '@metamask/snaps-sdk',\n\n /**\n * This tells SWC to use `Object.assign` and `Object.create` for\n * JSX spread attributes, instead of the default behavior.\n *\n * @see https://swc.rs/docs/configuration/compilation#jsctransformreact\n */\n useBuiltins: true,\n },\n },\n },\n\n /**\n * The module configuration. This tells SWC how to output the\n * transpiled code.\n *\n * @see https://swc.rs/docs/configuration/modules\n */\n module: {\n /**\n * This tells SWC to output ES6 modules. This will allow Webpack to\n * optimize the output code better. Snaps don't support ES6 however, so\n * the output code will be transpiled to CommonJS by Webpack later in\n * the build process.\n *\n * @see https://swc.rs/docs/configuration/modules#es6\n */\n type: 'es6',\n },\n\n env: {\n targets: targets.join(', '),\n },\n },\n };\n}\n\n/**\n * Get the Webpack devtool configuration based on the given snap config.\n *\n * - If `sourceMap` is `inline`, return `inline-source-map`.\n * - If `sourceMap` is `true`, return `source-map`.\n * - Otherwise, return `false`.\n *\n * @param sourceMap - The `sourceMap` value from the snap config.\n * @returns The Webpack devtool configuration.\n */\nexport function getDevTool(\n sourceMap: ProcessedWebpackConfig['sourceMap'],\n): Configuration['devtool'] {\n if (sourceMap === 'inline') {\n return 'inline-source-map';\n }\n\n if (sourceMap === true) {\n return 'source-map';\n }\n\n return false;\n}\n\n/**\n * Get a function that can be used as handler function for Webpack's\n * `ProgressPlugin`.\n *\n * @param spinner - The spinner to update.\n * @param spinnerText - The initial spinner text. This will be prepended to the\n * percentage.\n * @returns A function that can be used as handler function for Webpack's\n * `ProgressPlugin`.\n */\n// Note: This is extracted for testing purposes.\nexport function getProgressHandler(spinner?: Ora, spinnerText?: string) {\n return (percentage: number) => {\n if (spinner && spinnerText) {\n spinner.text = `${spinnerText} ${dim(\n `(${Math.round(percentage * 100)}%)`,\n )}`;\n }\n };\n}\n\n/**\n * Get the targets from the `.browserslistrc` file.\n *\n * @returns The browser targets as an array of strings.\n */\nexport async function getBrowserslistTargets() {\n const contents = await fs.readFile(BROWSERSLIST_FILE, 'utf8');\n return contents\n .split('\\n')\n .map((line) => line.trim())\n .filter((line) => line && !line.startsWith('#'));\n}\n\n/**\n * Get a singular or plural string based on the given count. This is useful for\n * generating messages like \"1 error\" or \"2 errors\". By default, the plural\n * string is the singular string with an \"s\" appended to it.\n *\n * This assumes that the text is in English, and likely won't work for some\n * other languages.\n *\n * @param count - The count.\n * @param singular - The singular string.\n * @param plural - The plural string.\n * @returns The singular or plural string.\n * @example\n * ```typescript\n * pluralize(1, 'error'); // => 'error'\n * pluralize(2, 'error'); // => 'errors'\n * pluralize(1, 'error', 'problem'); // => 'error'\n * pluralize(2, 'error', 'problems'); // => 'problems'\n * ```\n */\nexport function pluralize(\n count: number,\n singular: string,\n plural = `${singular}s`,\n) {\n return count === 1 ? singular : plural;\n}\n\n/**\n * Get an object that can be used as fallback config for Webpack's\n * `fallback` config.\n *\n * @param polyfills - The polyfill object from the snap config.\n * @returns The webpack fallback config.\n */\nexport function getFallbacks(polyfills: ProcessedWebpackConfig['polyfills']): {\n [index: string]: string | false;\n} {\n if (polyfills === true) {\n return Object.fromEntries(\n builtinModules.map((name) => [\n name,\n WEBPACK_FALLBACKS[name as keyof typeof WEBPACK_FALLBACKS] ?? false,\n ]),\n );\n }\n\n if (polyfills === false) {\n return Object.fromEntries(builtinModules.map((name) => [name, false]));\n }\n\n return Object.fromEntries(\n builtinModules.map((name) => [\n name,\n polyfills[name as keyof ProcessedWebpackConfig['polyfills']]\n ? WEBPACK_FALLBACKS[name as keyof typeof WEBPACK_FALLBACKS]\n : false,\n ]),\n );\n}\n\n/**\n * Get an object that can be used as environment variables for Webpack's\n * `DefinePlugin`.\n *\n * @param environment - The environment object from the Snap config.\n * @param defaults - The default environment variables.\n * @returns The Webpack environment variables.\n */\nexport function getEnvironmentVariables(\n environment: Record<string, unknown>,\n defaults = {\n NODE_DEBUG: 'false',\n NODE_ENV: 'production',\n DEBUG: 'false',\n },\n) {\n return Object.fromEntries(\n Object.entries({\n ...defaults,\n ...environment,\n }).map(([key, value]) => [`process.env.${key}`, JSON.stringify(value)]),\n );\n}\n\n/**\n * Format the given line to fit within the terminal width.\n *\n * @param line - The line to format.\n * @param indent - The indentation to use.\n * @param initialIndent - The initial indentation to use, i.e., the indentation\n * for the first line.\n * @returns The formatted line.\n */\nfunction formatLine(line: string, indent: number, initialIndent: number) {\n const terminalWidth = process.stdout.columns;\n if (!terminalWidth) {\n return `${' '.repeat(initialIndent)}${line}`;\n }\n\n return line.split(' ').reduce(\n ({ formattedText, currentLineLength }, word, index) => {\n // `chalk` adds ANSI escape codes to the text, which are not visible\n // characters. We need to strip them to get the visible length of the\n // text.\n const visibleWord = stripAnsi(word);\n\n // Determine if a space should be added before the word.\n const spaceBeforeWord = index > 0 ? ' ' : '';\n const wordLengthWithSpace = visibleWord.length + spaceBeforeWord.length;\n\n // If the word would exceed the terminal width, start a new line.\n if (currentLineLength + wordLengthWithSpace > terminalWidth) {\n return {\n formattedText: `${formattedText}\\n${' '.repeat(indent)}${word}`,\n currentLineLength: indent + visibleWord.length,\n };\n }\n\n // Otherwise, add the word to the current line.\n return {\n formattedText: formattedText + spaceBeforeWord + word,\n currentLineLength: currentLineLength + wordLengthWithSpace,\n };\n },\n {\n formattedText: ' '.repeat(initialIndent),\n currentLineLength: initialIndent,\n },\n ).formattedText;\n}\n\n/**\n * Format the given text to fit within the terminal width.\n *\n * @param text - The text to format.\n * @param indent - The indentation to use.\n * @param initialIndent - The initial indentation to use, i.e., the indentation\n * for the first line.\n * @returns The formatted text.\n */\nexport function formatText(\n text: string,\n indent: number,\n initialIndent = indent,\n) {\n const lines = text.split('\\n');\n\n // Apply formatting to each line separately and then join them.\n return lines\n .map((line, index) => {\n const lineIndent = index === 0 ? initialIndent : indent;\n return formatLine(line, indent, lineIndent);\n })\n .join('\\n');\n}\n\n/**\n * Get an SVG from the given bytes and mime type.\n *\n * @param mimeType - The mime type of the image.\n * @param bytes - The image bytes.\n * @returns The SVG.\n */\nexport function getImageSVG(mimeType: string, bytes: Uint8Array) {\n const dataUrl = `data:${mimeType};base64,${bytesToBase64(bytes)}`;\n return `<svg xmlns=\"http://www.w3.org/2000/svg\"><image href=\"${dataUrl}\" /></svg>`;\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  /// <reference types="browserify" />
2
- import type { Ora } from 'ora';
3
- import type { Configuration } from 'webpack';
4
- import type { ProcessedWebpackConfig } from '../config';
2
+ import type { Ora } from "ora/index.js";
3
+ import type { Configuration } from "webpack";
4
+ import type { ProcessedWebpackConfig } from "../config.cjs";
5
5
  export declare const BROWSERSLIST_FILE: string;
6
6
  export declare const WEBPACK_FALLBACKS: {
7
7
  assert: string;
@@ -256,3 +256,4 @@ export declare function formatText(text: string, indent: number, initialIndent?:
256
256
  * @returns The SVG.
257
257
  */
258
258
  export declare function getImageSVG(mimeType: string, bytes: Uint8Array): string;
259
+ //# sourceMappingURL=utils.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.cts","sourceRoot":"","sources":["../../src/webpack/utils.ts"],"names":[],"mappings":";AAIA,OAAO,KAAK,EAAE,GAAG,EAAE,qBAAY;AAG/B,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB;AAE7C,OAAO,KAAK,EAAE,sBAAsB,EAAE,sBAAkB;AAGxD,eAAO,MAAM,iBAAiB,QAM7B,CAAC;AAEF,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiC7B,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,gBAAgB,CAAC,EACrC,MAAM,EACN,SAAS,GACV,EAAE,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;IAarB;;;;OAIG;;IAGH;;;;;OAKG;;;QAID;;;;;WAKG;;;;gBAKC;;;;;;;mBAOG;;gBAGH;;;;;mBAKG;;;;;oBAMD;;;;;uBAKG;;oBAGH;;;;;;uBAMG;;oBAGH;;;;;uBAKG;;;;;QAMT;;;;;WAKG;;YAED;;;;;;;eAOG;;;;;;;GASV;AAED;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CACxB,SAAS,EAAE,sBAAsB,CAAC,WAAW,CAAC,GAC7C,aAAa,CAAC,SAAS,CAAC,CAU1B;AAED;;;;;;;;;GASG;AAEH,wBAAgB,kBAAkB,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,WAAW,CAAC,EAAE,MAAM,gBAChD,M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