@metamask/snaps-cli 6.6.1 → 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (235) hide show
  1. package/CHANGELOG.md +39 -1
  2. package/README.md +11 -244
  3. package/dist/builders.cjs +4 -98
  4. package/dist/builders.cjs.map +1 -1
  5. package/dist/builders.d.cts +28 -7
  6. package/dist/builders.d.cts.map +1 -1
  7. package/dist/builders.d.mts +28 -7
  8. package/dist/builders.d.mts.map +1 -1
  9. package/dist/builders.mjs +4 -97
  10. package/dist/builders.mjs.map +1 -1
  11. package/dist/cli.cjs +4 -9
  12. package/dist/cli.cjs.map +1 -1
  13. package/dist/cli.d.cts.map +1 -1
  14. package/dist/cli.d.mts.map +1 -1
  15. package/dist/cli.mjs +4 -16
  16. package/dist/cli.mjs.map +1 -1
  17. package/dist/commands/build/build.cjs +33 -7
  18. package/dist/commands/build/build.cjs.map +1 -1
  19. package/dist/commands/build/build.d.cts +2 -1
  20. package/dist/commands/build/build.d.cts.map +1 -1
  21. package/dist/commands/build/build.d.mts +2 -1
  22. package/dist/commands/build/build.d.mts.map +1 -1
  23. package/dist/commands/build/build.mjs +31 -5
  24. package/dist/commands/build/build.mjs.map +1 -1
  25. package/dist/commands/build/implementation.cjs +1 -1
  26. package/dist/commands/build/implementation.cjs.map +1 -1
  27. package/dist/commands/build/implementation.d.cts +3 -2
  28. package/dist/commands/build/implementation.d.cts.map +1 -1
  29. package/dist/commands/build/implementation.d.mts +3 -2
  30. package/dist/commands/build/implementation.d.mts.map +1 -1
  31. package/dist/commands/build/implementation.mjs +1 -1
  32. package/dist/commands/build/implementation.mjs.map +1 -1
  33. package/dist/commands/build/index.cjs +3 -14
  34. package/dist/commands/build/index.cjs.map +1 -1
  35. package/dist/commands/build/index.d.cts.map +1 -1
  36. package/dist/commands/build/index.d.mts.map +1 -1
  37. package/dist/commands/build/index.mjs +3 -14
  38. package/dist/commands/build/index.mjs.map +1 -1
  39. package/dist/commands/build/utils.cjs +25 -0
  40. package/dist/commands/build/utils.cjs.map +1 -0
  41. package/dist/commands/build/utils.d.cts +9 -0
  42. package/dist/commands/build/utils.d.cts.map +1 -0
  43. package/dist/commands/build/utils.d.mts +9 -0
  44. package/dist/commands/build/utils.d.mts.map +1 -0
  45. package/dist/commands/build/utils.mjs +21 -0
  46. package/dist/commands/build/utils.mjs.map +1 -0
  47. package/dist/commands/eval/__test__/webpack/bad/snap.config.cjs +0 -1
  48. package/dist/commands/eval/__test__/webpack/bad/snap.config.cjs.map +1 -1
  49. package/dist/commands/eval/__test__/webpack/bad/snap.config.d.cts.map +1 -1
  50. package/dist/commands/eval/__test__/webpack/bad/snap.config.d.mts.map +1 -1
  51. package/dist/commands/eval/__test__/webpack/bad/snap.config.mjs +0 -1
  52. package/dist/commands/eval/__test__/webpack/bad/snap.config.mjs.map +1 -1
  53. package/dist/commands/eval/__test__/webpack/good/snap.config.cjs +0 -1
  54. package/dist/commands/eval/__test__/webpack/good/snap.config.cjs.map +1 -1
  55. package/dist/commands/eval/__test__/webpack/good/snap.config.d.cts.map +1 -1
  56. package/dist/commands/eval/__test__/webpack/good/snap.config.d.mts.map +1 -1
  57. package/dist/commands/eval/__test__/webpack/good/snap.config.mjs +0 -1
  58. package/dist/commands/eval/__test__/webpack/good/snap.config.mjs.map +1 -1
  59. package/dist/commands/eval/__test__/webpack/snap.config.cjs +0 -1
  60. package/dist/commands/eval/__test__/webpack/snap.config.cjs.map +1 -1
  61. package/dist/commands/eval/__test__/webpack/snap.config.d.cts.map +1 -1
  62. package/dist/commands/eval/__test__/webpack/snap.config.d.mts.map +1 -1
  63. package/dist/commands/eval/__test__/webpack/snap.config.mjs +0 -1
  64. package/dist/commands/eval/__test__/webpack/snap.config.mjs.map +1 -1
  65. package/dist/commands/eval/eval.cjs +1 -1
  66. package/dist/commands/eval/eval.cjs.map +1 -1
  67. package/dist/commands/eval/eval.d.cts.map +1 -1
  68. package/dist/commands/eval/eval.d.mts.map +1 -1
  69. package/dist/commands/eval/eval.mjs +1 -1
  70. package/dist/commands/eval/eval.mjs.map +1 -1
  71. package/dist/commands/eval/index.cjs +1 -4
  72. package/dist/commands/eval/index.cjs.map +1 -1
  73. package/dist/commands/eval/index.d.cts.map +1 -1
  74. package/dist/commands/eval/index.d.mts.map +1 -1
  75. package/dist/commands/eval/index.mjs +1 -4
  76. package/dist/commands/eval/index.mjs.map +1 -1
  77. package/dist/commands/manifest/index.cjs +1 -4
  78. package/dist/commands/manifest/index.cjs.map +1 -1
  79. package/dist/commands/manifest/index.d.cts.map +1 -1
  80. package/dist/commands/manifest/index.d.mts.map +1 -1
  81. package/dist/commands/manifest/index.mjs +1 -4
  82. package/dist/commands/manifest/index.mjs.map +1 -1
  83. package/dist/commands/manifest/manifest.cjs +5 -6
  84. package/dist/commands/manifest/manifest.cjs.map +1 -1
  85. package/dist/commands/manifest/manifest.d.cts.map +1 -1
  86. package/dist/commands/manifest/manifest.d.mts.map +1 -1
  87. package/dist/commands/manifest/manifest.mjs +5 -6
  88. package/dist/commands/manifest/manifest.mjs.map +1 -1
  89. package/dist/commands/serve/index.cjs +2 -2
  90. package/dist/commands/serve/index.cjs.map +1 -1
  91. package/dist/commands/serve/index.d.cts.map +1 -1
  92. package/dist/commands/serve/index.d.mts.map +1 -1
  93. package/dist/commands/serve/index.mjs +2 -2
  94. package/dist/commands/serve/index.mjs.map +1 -1
  95. package/dist/commands/watch/implementation.cjs +2 -0
  96. package/dist/commands/watch/implementation.cjs.map +1 -1
  97. package/dist/commands/watch/implementation.d.cts +2 -2
  98. package/dist/commands/watch/implementation.d.cts.map +1 -1
  99. package/dist/commands/watch/implementation.d.mts +2 -2
  100. package/dist/commands/watch/implementation.d.mts.map +1 -1
  101. package/dist/commands/watch/implementation.mjs +2 -0
  102. package/dist/commands/watch/implementation.mjs.map +1 -1
  103. package/dist/commands/watch/index.cjs +2 -17
  104. package/dist/commands/watch/index.cjs.map +1 -1
  105. package/dist/commands/watch/index.d.cts.map +1 -1
  106. package/dist/commands/watch/index.d.mts.map +1 -1
  107. package/dist/commands/watch/index.mjs +2 -17
  108. package/dist/commands/watch/index.mjs.map +1 -1
  109. package/dist/commands/watch/watch.cjs +1 -1
  110. package/dist/commands/watch/watch.cjs.map +1 -1
  111. package/dist/commands/watch/watch.d.cts.map +1 -1
  112. package/dist/commands/watch/watch.d.mts.map +1 -1
  113. package/dist/commands/watch/watch.mjs +1 -1
  114. package/dist/commands/watch/watch.mjs.map +1 -1
  115. package/dist/config.cjs +11 -155
  116. package/dist/config.cjs.map +1 -1
  117. package/dist/config.d.cts +216 -314
  118. package/dist/config.d.cts.map +1 -1
  119. package/dist/config.d.mts +216 -314
  120. package/dist/config.d.mts.map +1 -1
  121. package/dist/config.mjs +13 -155
  122. package/dist/config.mjs.map +1 -1
  123. package/dist/main.cjs +0 -1
  124. package/dist/main.cjs.map +1 -1
  125. package/dist/main.mjs +0 -1
  126. package/dist/main.mjs.map +1 -1
  127. package/dist/utils/index.cjs +0 -1
  128. package/dist/utils/index.cjs.map +1 -1
  129. package/dist/utils/index.d.cts +0 -1
  130. package/dist/utils/index.d.cts.map +1 -1
  131. package/dist/utils/index.d.mts +0 -1
  132. package/dist/utils/index.d.mts.map +1 -1
  133. package/dist/utils/index.mjs +0 -1
  134. package/dist/utils/index.mjs.map +1 -1
  135. package/dist/utils/logging.cjs +16 -2
  136. package/dist/utils/logging.cjs.map +1 -1
  137. package/dist/utils/logging.d.cts +8 -1
  138. package/dist/utils/logging.d.cts.map +1 -1
  139. package/dist/utils/logging.d.mts +8 -1
  140. package/dist/utils/logging.d.mts.map +1 -1
  141. package/dist/utils/logging.mjs +15 -2
  142. package/dist/utils/logging.mjs.map +1 -1
  143. package/dist/utils/steps.cjs +11 -6
  144. package/dist/utils/steps.cjs.map +1 -1
  145. package/dist/utils/steps.d.cts +2 -2
  146. package/dist/utils/steps.d.cts.map +1 -1
  147. package/dist/utils/steps.d.mts +2 -2
  148. package/dist/utils/steps.d.mts.map +1 -1
  149. package/dist/utils/steps.mjs +11 -6
  150. package/dist/utils/steps.mjs.map +1 -1
  151. package/dist/webpack/compiler.cjs.map +1 -1
  152. package/dist/webpack/compiler.d.cts +2 -2
  153. package/dist/webpack/compiler.d.cts.map +1 -1
  154. package/dist/webpack/compiler.d.mts +2 -2
  155. package/dist/webpack/compiler.d.mts.map +1 -1
  156. package/dist/webpack/compiler.mjs.map +1 -1
  157. package/dist/webpack/config.cjs +8 -2
  158. package/dist/webpack/config.cjs.map +1 -1
  159. package/dist/webpack/config.d.cts +6 -2
  160. package/dist/webpack/config.d.cts.map +1 -1
  161. package/dist/webpack/config.d.mts +6 -2
  162. package/dist/webpack/config.d.mts.map +1 -1
  163. package/dist/webpack/config.mjs +8 -2
  164. package/dist/webpack/config.mjs.map +1 -1
  165. package/dist/webpack/loaders/function.cjs +7 -10
  166. package/dist/webpack/loaders/function.cjs.map +1 -1
  167. package/dist/webpack/loaders/function.d.cts +1 -0
  168. package/dist/webpack/loaders/function.d.cts.map +1 -1
  169. package/dist/webpack/loaders/function.d.mts +1 -0
  170. package/dist/webpack/loaders/function.d.mts.map +1 -1
  171. package/dist/webpack/loaders/function.mjs +6 -9
  172. package/dist/webpack/loaders/function.mjs.map +1 -1
  173. package/dist/webpack/loaders/index.cjs +1 -3
  174. package/dist/webpack/loaders/index.cjs.map +1 -1
  175. package/dist/webpack/loaders/index.d.cts +0 -1
  176. package/dist/webpack/loaders/index.d.cts.map +1 -1
  177. package/dist/webpack/loaders/index.d.mts +0 -1
  178. package/dist/webpack/loaders/index.d.mts.map +1 -1
  179. package/dist/webpack/loaders/index.mjs +0 -1
  180. package/dist/webpack/loaders/index.mjs.map +1 -1
  181. package/dist/webpack/loaders/wasm.cjs +0 -2
  182. package/dist/webpack/loaders/wasm.cjs.map +1 -1
  183. package/dist/webpack/loaders/wasm.d.cts.map +1 -1
  184. package/dist/webpack/loaders/wasm.d.mts.map +1 -1
  185. package/dist/webpack/loaders/wasm.mjs +0 -2
  186. package/dist/webpack/loaders/wasm.mjs.map +1 -1
  187. package/dist/webpack/plugins.cjs +15 -20
  188. package/dist/webpack/plugins.cjs.map +1 -1
  189. package/dist/webpack/plugins.d.cts +13 -3
  190. package/dist/webpack/plugins.d.cts.map +1 -1
  191. package/dist/webpack/plugins.d.mts +13 -3
  192. package/dist/webpack/plugins.d.mts.map +1 -1
  193. package/dist/webpack/plugins.mjs +4 -9
  194. package/dist/webpack/plugins.mjs.map +1 -1
  195. package/dist/webpack/utils.cjs +5 -21
  196. package/dist/webpack/utils.cjs.map +1 -1
  197. package/dist/webpack/utils.d.cts +6 -36
  198. package/dist/webpack/utils.d.cts.map +1 -1
  199. package/dist/webpack/utils.d.mts +6 -36
  200. package/dist/webpack/utils.d.mts.map +1 -1
  201. package/dist/webpack/utils.mjs +4 -18
  202. package/dist/webpack/utils.mjs.map +1 -1
  203. package/package.json +14 -38
  204. package/dist/commands/eval/__test__/browserify/bad/snap.config.cjs +0 -10
  205. package/dist/commands/eval/__test__/browserify/bad/snap.config.cjs.map +0 -1
  206. package/dist/commands/eval/__test__/browserify/bad/snap.config.d.cts +0 -4
  207. package/dist/commands/eval/__test__/browserify/bad/snap.config.d.cts.map +0 -1
  208. package/dist/commands/eval/__test__/browserify/bad/snap.config.d.mts +0 -4
  209. package/dist/commands/eval/__test__/browserify/bad/snap.config.d.mts.map +0 -1
  210. package/dist/commands/eval/__test__/browserify/bad/snap.config.mjs +0 -8
  211. package/dist/commands/eval/__test__/browserify/bad/snap.config.mjs.map +0 -1
  212. package/dist/commands/eval/__test__/browserify/good/snap.config.cjs +0 -10
  213. package/dist/commands/eval/__test__/browserify/good/snap.config.cjs.map +0 -1
  214. package/dist/commands/eval/__test__/browserify/good/snap.config.d.cts +0 -4
  215. package/dist/commands/eval/__test__/browserify/good/snap.config.d.cts.map +0 -1
  216. package/dist/commands/eval/__test__/browserify/good/snap.config.d.mts +0 -4
  217. package/dist/commands/eval/__test__/browserify/good/snap.config.d.mts.map +0 -1
  218. package/dist/commands/eval/__test__/browserify/good/snap.config.mjs +0 -8
  219. package/dist/commands/eval/__test__/browserify/good/snap.config.mjs.map +0 -1
  220. package/dist/utils/legacy.cjs +0 -53
  221. package/dist/utils/legacy.cjs.map +0 -1
  222. package/dist/utils/legacy.d.cts +0 -28
  223. package/dist/utils/legacy.d.cts.map +0 -1
  224. package/dist/utils/legacy.d.mts +0 -28
  225. package/dist/utils/legacy.d.mts.map +0 -1
  226. package/dist/utils/legacy.mjs +0 -47
  227. package/dist/utils/legacy.mjs.map +0 -1
  228. package/dist/webpack/loaders/browserify.cjs +0 -84
  229. package/dist/webpack/loaders/browserify.cjs.map +0 -1
  230. package/dist/webpack/loaders/browserify.d.cts +0 -18
  231. package/dist/webpack/loaders/browserify.d.cts.map +0 -1
  232. package/dist/webpack/loaders/browserify.d.mts +0 -18
  233. package/dist/webpack/loaders/browserify.d.mts.map +0 -1
  234. package/dist/webpack/loaders/browserify.mjs +0 -88
  235. package/dist/webpack/loaders/browserify.mjs.map +0 -1
@@ -22,19 +22,23 @@ async function executeSteps(steps, context) {
22
22
  });
23
23
  spinner.start();
24
24
  try {
25
- for (const step of steps) {
25
+ await steps.reduce(async (contextPromise, step) => {
26
+ const currentContext = await contextPromise;
26
27
  // If the step has a condition, and it returns false, we skip the step.
27
- if (step.condition && !step.condition(context)) {
28
- continue;
28
+ if (step.condition && !step.condition(currentContext)) {
29
+ return currentContext;
29
30
  }
30
31
  // Calling `start` here instead of setting `spinner.text` seems to work
31
32
  // better when the process doesn't have a TTY.
32
33
  spinner.start((0, chalk_1.dim)(step.name));
33
- await step.task({
34
- ...context,
34
+ const newContext = await step.task({
35
+ ...currentContext,
35
36
  spinner,
36
37
  });
37
- }
38
+ // If the task returns a new context, we use it. Otherwise, we keep the
39
+ // current context.
40
+ return newContext ?? currentContext;
41
+ }, Promise.resolve(context));
38
42
  // The spinner may have been stopped by a step, so we only succeed if it's
39
43
  // still spinning.
40
44
  if (spinner.isSpinning) {
@@ -44,6 +48,7 @@ async function executeSteps(steps, context) {
44
48
  catch (_error) {
45
49
  (0, logging_1.error)((0, errors_1.getErrorMessage)(_error), spinner);
46
50
  spinner.stop();
51
+ // eslint-disable-next-line require-atomic-updates
47
52
  process.exitCode = 1;
48
53
  }
49
54
  }
@@ -1 +1 @@
1
- {"version":3,"file":"steps.cjs","sourceRoot":"","sources":["../../src/utils/steps.ts"],"names":[],"mappings":";;;;;;AAAA,iCAA4B;AAE5B,uDAAgC;AAEhC,yCAA2C;AAC3C,2CAAkC;AAYlC;;;;;;GAMG;AACI,KAAK,UAAU,YAAY,CAChC,KAAqB,EACrB,OAAgB;IAEhB,MAAM,OAAO,GAAG,IAAA,aAAa,EAAC;QAC5B,6CAA6C;QAC7C,MAAM,EAAE,OAAO,CAAC,MAAM;KACvB,CAAC,CAAC;IAEH,OAAO,CAAC,KAAK,EAAE,CAAC;IAEhB,IAAI,CAAC;QACH,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,uEAAuE;YACvE,IAAI,IAAI,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC;gBAC/C,SAAS;YACX,CAAC;YAED,uEAAuE;YACvE,8CAA8C;YAC9C,OAAO,CAAC,KAAK,CAAC,IAAA,WAAG,EAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;YAE9B,MAAM,IAAI,CAAC,IAAI,CAAC;gBACd,GAAG,OAAO;gBACV,OAAO;aACR,CAAC,CAAC;QACL,CAAC;QAED,0EAA0E;QAC1E,kBAAkB;QAClB,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;YACvB,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAC3B,CAAC;IACH,CAAC;IAAC,OAAO,MAAM,EAAE,CAAC;QAChB,IAAA,eAAK,EAAC,IAAA,wBAAe,EAAC,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC;QACxC,OAAO,CAAC,IAAI,EAAE,CAAC;QACf,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACvB,CAAC;AACH,CAAC;AAtCD,oCAsCC","sourcesContent":["import { dim } from 'chalk';\nimport type { Ora } from 'ora';\nimport createSpinner from 'ora';\n\nimport { getErrorMessage } from './errors';\nimport { error } from './logging';\n\nexport type Step<Context extends Record<string, unknown>> = {\n name: string;\n condition?: (context: Context) => boolean;\n task: (context: Context & { spinner: Ora }) => Promise<void>;\n};\n\nexport type Steps<Context extends Record<string, unknown>> = Readonly<\n Step<Context>[]\n>;\n\n/**\n * Execute a list of steps in series. Each step receives the context object and\n * a spinner instance.\n *\n * @param steps - The steps to execute.\n * @param context - The context object that will be passed to each step.\n */\nexport async function executeSteps<Context extends Record<string, unknown>>(\n steps: Steps<Context>,\n context: Context,\n) {\n const spinner = createSpinner({\n // Ora writes to `process.stderr` by default.\n stream: process.stdout,\n });\n\n spinner.start();\n\n try {\n for (const step of steps) {\n // If the step has a condition, and it returns false, we skip the step.\n if (step.condition && !step.condition(context)) {\n continue;\n }\n\n // Calling `start` here instead of setting `spinner.text` seems to work\n // better when the process doesn't have a TTY.\n spinner.start(dim(step.name));\n\n await step.task({\n ...context,\n spinner,\n });\n }\n\n // The spinner may have been stopped by a step, so we only succeed if it's\n // still spinning.\n if (spinner.isSpinning) {\n spinner.succeed('Done!');\n }\n } catch (_error) {\n error(getErrorMessage(_error), spinner);\n spinner.stop();\n process.exitCode = 1;\n }\n}\n"]}
1
+ {"version":3,"file":"steps.cjs","sourceRoot":"","sources":["../../src/utils/steps.ts"],"names":[],"mappings":";;;;;;AAAA,iCAA4B;AAE5B,uDAAgC;AAEhC,yCAA2C;AAC3C,2CAAkC;AAWlC;;;;;;GAMG;AACI,KAAK,UAAU,YAAY,CAChC,KAAqB,EACrB,OAAgB;IAEhB,MAAM,OAAO,GAAG,IAAA,aAAa,EAAC;QAC5B,6CAA6C;QAC7C,MAAM,EAAE,OAAO,CAAC,MAAM;KACvB,CAAC,CAAC;IAEH,OAAO,CAAC,KAAK,EAAE,CAAC;IAEhB,IAAI,CAAC;QACH,MAAM,KAAK,CAAC,MAAM,CAAmB,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,EAAE;YAClE,MAAM,cAAc,GAAG,MAAM,cAAc,CAAC;YAE5C,uEAAuE;YACvE,IAAI,IAAI,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,EAAE,CAAC;gBACtD,OAAO,cAAc,CAAC;YACxB,CAAC;YAED,uEAAuE;YACvE,8CAA8C;YAC9C,OAAO,CAAC,KAAK,CAAC,IAAA,WAAG,EAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;YAE9B,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC;gBACjC,GAAG,cAAc;gBACjB,OAAO;aACR,CAAC,CAAC;YAEH,uEAAuE;YACvE,mBAAmB;YACnB,OAAO,UAAU,IAAI,cAAc,CAAC;QACtC,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;QAE7B,0EAA0E;QAC1E,kBAAkB;QAClB,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;YACvB,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAC3B,CAAC;IACH,CAAC;IAAC,OAAO,MAAM,EAAE,CAAC;QAChB,IAAA,eAAK,EAAC,IAAA,wBAAe,EAAC,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC;QACxC,OAAO,CAAC,IAAI,EAAE,CAAC;QAEf,kDAAkD;QAClD,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACvB,CAAC;AACH,CAAC;AA9CD,oCA8CC","sourcesContent":["import { dim } from 'chalk';\nimport type { Ora } from 'ora';\nimport createSpinner from 'ora';\n\nimport { getErrorMessage } from './errors';\nimport { error } from './logging';\n\nexport type Step<Context extends Record<string, unknown>> = {\n name: string;\n condition?: (context: Context) => boolean;\n task: (context: Context & { spinner: Ora }) => Promise<Context | void>;\n};\n\nexport type Steps<Context extends Record<string, unknown>> =\n readonly Step<Context>[];\n\n/**\n * Execute a list of steps in series. Each step receives the context object and\n * a spinner instance.\n *\n * @param steps - The steps to execute.\n * @param context - The context object that will be passed to each step.\n */\nexport async function executeSteps<Context extends Record<string, unknown>>(\n steps: Steps<Context>,\n context: Context,\n) {\n const spinner = createSpinner({\n // Ora writes to `process.stderr` by default.\n stream: process.stdout,\n });\n\n spinner.start();\n\n try {\n await steps.reduce<Promise<Context>>(async (contextPromise, step) => {\n const currentContext = await contextPromise;\n\n // If the step has a condition, and it returns false, we skip the step.\n if (step.condition && !step.condition(currentContext)) {\n return currentContext;\n }\n\n // Calling `start` here instead of setting `spinner.text` seems to work\n // better when the process doesn't have a TTY.\n spinner.start(dim(step.name));\n\n const newContext = await step.task({\n ...currentContext,\n spinner,\n });\n\n // If the task returns a new context, we use it. Otherwise, we keep the\n // current context.\n return newContext ?? currentContext;\n }, Promise.resolve(context));\n\n // The spinner may have been stopped by a step, so we only succeed if it's\n // still spinning.\n if (spinner.isSpinning) {\n spinner.succeed('Done!');\n }\n } catch (_error) {\n error(getErrorMessage(_error), spinner);\n spinner.stop();\n\n // eslint-disable-next-line require-atomic-updates\n process.exitCode = 1;\n }\n}\n"]}
@@ -4,9 +4,9 @@ export type Step<Context extends Record<string, unknown>> = {
4
4
  condition?: (context: Context) => boolean;
5
5
  task: (context: Context & {
6
6
  spinner: Ora;
7
- }) => Promise<void>;
7
+ }) => Promise<Context | void>;
8
8
  };
9
- export type Steps<Context extends Record<string, unknown>> = Readonly<Step<Context>[]>;
9
+ export type Steps<Context extends Record<string, unknown>> = readonly Step<Context>[];
10
10
  /**
11
11
  * Execute a list of steps in series. Each step receives the context object and
12
12
  * a spinner instance.
@@ -1 +1 @@
1
- {"version":3,"file":"steps.d.cts","sourceRoot":"","sources":["../../src/utils/steps.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,qBAAY;AAM/B,MAAM,MAAM,IAA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,CAAC,MAAM,EAAE,OAAO,CAAC,EACxE,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,EACrB,OAAO,EAAE,OAAO,iBA4CjB"}
@@ -4,9 +4,9 @@ export type Step<Context extends Record<string, unknown>> = {
4
4
  condition?: (context: Context) => boolean;
5
5
  task: (context: Context & {
6
6
  spinner: Ora;
7
- }) => Promise<void>;
7
+ }) => Promise<Context | void>;
8
8
  };
9
- export type Steps<Context extends Record<string, unknown>> = Readonly<Step<Context>[]>;
9
+ export type Steps<Context extends Record<string, unknown>> = readonly Step<Context>[];
10
10
  /**
11
11
  * Execute a list of steps in series. Each step receives the context object and
12
12
  * a spinner instance.
@@ -1 +1 @@
1
- {"version":3,"file":"steps.d.mts","sourceRoot":"","sources":["../../src/utils/steps.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,qBAAY;AAM/B,MAAM,MAAM,IAAI,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI;IAC1D,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC;IAC1C,IAAI,EAAE,CAAC,OAAO,EAAE,OAAO,GAAG;QAAE,OAAO,EAAE,GAAG,CAAA;KAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9D,CAAC;AAEF,MAAM,MAAM,KAAK,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,QAAQ,CACnE,IAAI,CAAC,OAAO,CAAC,EAAE,CAChB,CAAC;AAEF;;;;;;GAMG;AACH,wBAAsB,YAAY,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACxE,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,EACrB,OAAO,EAAE,OAAO,iBAoCjB"}
1
+ {"version":3,"file":"steps.d.mts","sourceRoot":"","sources":["../../src/utils/steps.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,qBAAY;AAM/B,MAAM,MAAM,IAAI,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI;IAC1D,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC;IAC1C,IAAI,EAAE,CAAC,OAAO,EAAE,OAAO,GAAG;QAAE,OAAO,EAAE,GAAG,CAAA;KAAE,KAAK,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC;CACxE,CAAC;AAEF,MAAM,MAAM,KAAK,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IACvD,SAAS,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;AAE3B;;;;;;GAMG;AACH,wBAAsB,YAAY,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACxE,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,EACrB,OAAO,EAAE,OAAO,iBA4CjB"}
@@ -24,19 +24,23 @@ export async function executeSteps(steps, context) {
24
24
  });
25
25
  spinner.start();
26
26
  try {
27
- for (const step of steps) {
27
+ await steps.reduce(async (contextPromise, step) => {
28
+ const currentContext = await contextPromise;
28
29
  // If the step has a condition, and it returns false, we skip the step.
29
- if (step.condition && !step.condition(context)) {
30
- continue;
30
+ if (step.condition && !step.condition(currentContext)) {
31
+ return currentContext;
31
32
  }
32
33
  // Calling `start` here instead of setting `spinner.text` seems to work
33
34
  // better when the process doesn't have a TTY.
34
35
  spinner.start(dim(step.name));
35
- await step.task({
36
- ...context,
36
+ const newContext = await step.task({
37
+ ...currentContext,
37
38
  spinner,
38
39
  });
39
- }
40
+ // If the task returns a new context, we use it. Otherwise, we keep the
41
+ // current context.
42
+ return newContext ?? currentContext;
43
+ }, Promise.resolve(context));
40
44
  // The spinner may have been stopped by a step, so we only succeed if it's
41
45
  // still spinning.
42
46
  if (spinner.isSpinning) {
@@ -46,6 +50,7 @@ export async function executeSteps(steps, context) {
46
50
  catch (_error) {
47
51
  error(getErrorMessage(_error), spinner);
48
52
  spinner.stop();
53
+ // eslint-disable-next-line require-atomic-updates
49
54
  process.exitCode = 1;
50
55
  }
51
56
  }
@@ -1 +1 @@
1
- {"version":3,"file":"steps.mjs","sourceRoot":"","sources":["../../src/utils/steps.ts"],"names":[],"mappings":";;;;;;;;AAEA,OAAO,cAAa,qBAAY;;AAEhC,OAAO,EAAE,eAAe,EAAE,qBAAiB;AAC3C,OAAO,EAAE,KAAK,EAAE,sBAAkB;AAYlC;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,KAAqB,EACrB,OAAgB;IAEhB,MAAM,OAAO,GAAG,aAAa,CAAC;QAC5B,6CAA6C;QAC7C,MAAM,EAAE,OAAO,CAAC,MAAM;KACvB,CAAC,CAAC;IAEH,OAAO,CAAC,KAAK,EAAE,CAAC;IAEhB,IAAI,CAAC;QACH,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,uEAAuE;YACvE,IAAI,IAAI,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC;gBAC/C,SAAS;YACX,CAAC;YAED,uEAAuE;YACvE,8CAA8C;YAC9C,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;YAE9B,MAAM,IAAI,CAAC,IAAI,CAAC;gBACd,GAAG,OAAO;gBACV,OAAO;aACR,CAAC,CAAC;QACL,CAAC;QAED,0EAA0E;QAC1E,kBAAkB;QAClB,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;YACvB,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAC3B,CAAC;IACH,CAAC;IAAC,OAAO,MAAM,EAAE,CAAC;QAChB,KAAK,CAAC,eAAe,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC;QACxC,OAAO,CAAC,IAAI,EAAE,CAAC;QACf,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACvB,CAAC;AACH,CAAC","sourcesContent":["import { dim } from 'chalk';\nimport type { Ora } from 'ora';\nimport createSpinner from 'ora';\n\nimport { getErrorMessage } from './errors';\nimport { error } from './logging';\n\nexport type Step<Context extends Record<string, unknown>> = {\n name: string;\n condition?: (context: Context) => boolean;\n task: (context: Context & { spinner: Ora }) => Promise<void>;\n};\n\nexport type Steps<Context extends Record<string, unknown>> = Readonly<\n Step<Context>[]\n>;\n\n/**\n * Execute a list of steps in series. Each step receives the context object and\n * a spinner instance.\n *\n * @param steps - The steps to execute.\n * @param context - The context object that will be passed to each step.\n */\nexport async function executeSteps<Context extends Record<string, unknown>>(\n steps: Steps<Context>,\n context: Context,\n) {\n const spinner = createSpinner({\n // Ora writes to `process.stderr` by default.\n stream: process.stdout,\n });\n\n spinner.start();\n\n try {\n for (const step of steps) {\n // If the step has a condition, and it returns false, we skip the step.\n if (step.condition && !step.condition(context)) {\n continue;\n }\n\n // Calling `start` here instead of setting `spinner.text` seems to work\n // better when the process doesn't have a TTY.\n spinner.start(dim(step.name));\n\n await step.task({\n ...context,\n spinner,\n });\n }\n\n // The spinner may have been stopped by a step, so we only succeed if it's\n // still spinning.\n if (spinner.isSpinning) {\n spinner.succeed('Done!');\n }\n } catch (_error) {\n error(getErrorMessage(_error), spinner);\n spinner.stop();\n process.exitCode = 1;\n }\n}\n"]}
1
+ {"version":3,"file":"steps.mjs","sourceRoot":"","sources":["../../src/utils/steps.ts"],"names":[],"mappings":";;;;;;;;AAEA,OAAO,cAAa,qBAAY;;AAEhC,OAAO,EAAE,eAAe,EAAE,qBAAiB;AAC3C,OAAO,EAAE,KAAK,EAAE,sBAAkB;AAWlC;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,KAAqB,EACrB,OAAgB;IAEhB,MAAM,OAAO,GAAG,aAAa,CAAC;QAC5B,6CAA6C;QAC7C,MAAM,EAAE,OAAO,CAAC,MAAM;KACvB,CAAC,CAAC;IAEH,OAAO,CAAC,KAAK,EAAE,CAAC;IAEhB,IAAI,CAAC;QACH,MAAM,KAAK,CAAC,MAAM,CAAmB,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,EAAE;YAClE,MAAM,cAAc,GAAG,MAAM,cAAc,CAAC;YAE5C,uEAAuE;YACvE,IAAI,IAAI,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,EAAE,CAAC;gBACtD,OAAO,cAAc,CAAC;YACxB,CAAC;YAED,uEAAuE;YACvE,8CAA8C;YAC9C,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;YAE9B,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC;gBACjC,GAAG,cAAc;gBACjB,OAAO;aACR,CAAC,CAAC;YAEH,uEAAuE;YACvE,mBAAmB;YACnB,OAAO,UAAU,IAAI,cAAc,CAAC;QACtC,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;QAE7B,0EAA0E;QAC1E,kBAAkB;QAClB,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;YACvB,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAC3B,CAAC;IACH,CAAC;IAAC,OAAO,MAAM,EAAE,CAAC;QAChB,KAAK,CAAC,eAAe,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC;QACxC,OAAO,CAAC,IAAI,EAAE,CAAC;QAEf,kDAAkD;QAClD,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACvB,CAAC;AACH,CAAC","sourcesContent":["import { dim } from 'chalk';\nimport type { Ora } from 'ora';\nimport createSpinner from 'ora';\n\nimport { getErrorMessage } from './errors';\nimport { error } from './logging';\n\nexport type Step<Context extends Record<string, unknown>> = {\n name: string;\n condition?: (context: Context) => boolean;\n task: (context: Context & { spinner: Ora }) => Promise<Context | void>;\n};\n\nexport type Steps<Context extends Record<string, unknown>> =\n readonly Step<Context>[];\n\n/**\n * Execute a list of steps in series. Each step receives the context object and\n * a spinner instance.\n *\n * @param steps - The steps to execute.\n * @param context - The context object that will be passed to each step.\n */\nexport async function executeSteps<Context extends Record<string, unknown>>(\n steps: Steps<Context>,\n context: Context,\n) {\n const spinner = createSpinner({\n // Ora writes to `process.stderr` by default.\n stream: process.stdout,\n });\n\n spinner.start();\n\n try {\n await steps.reduce<Promise<Context>>(async (contextPromise, step) => {\n const currentContext = await contextPromise;\n\n // If the step has a condition, and it returns false, we skip the step.\n if (step.condition && !step.condition(currentContext)) {\n return currentContext;\n }\n\n // Calling `start` here instead of setting `spinner.text` seems to work\n // better when the process doesn't have a TTY.\n spinner.start(dim(step.name));\n\n const newContext = await step.task({\n ...currentContext,\n spinner,\n });\n\n // If the task returns a new context, we use it. Otherwise, we keep the\n // current context.\n return newContext ?? currentContext;\n }, Promise.resolve(context));\n\n // The spinner may have been stopped by a step, so we only succeed if it's\n // still spinning.\n if (spinner.isSpinning) {\n spinner.succeed('Done!');\n }\n } catch (_error) {\n error(getErrorMessage(_error), spinner);\n spinner.stop();\n\n // eslint-disable-next-line require-atomic-updates\n process.exitCode = 1;\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"compiler.cjs","sourceRoot":"","sources":["../../src/webpack/compiler.ts"],"names":[],"mappings":";;;AAAA,qCAAkC;AAIlC,yCAAmD;AAEnD;;;;;;GAMG;AACI,KAAK,UAAU,WAAW,CAC/B,MAA8B,EAC9B,OAAwB;IAExB,MAAM,iBAAiB,GAAG,MAAM,IAAA,gCAAuB,EAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACzE,MAAM,aAAa,GACjB,MAAM,CAAC,sBAAsB,EAAE,CAAC,iBAAiB,CAAC,IAAI,iBAAiB,CAAC;IAE1E,OAAO,IAAA,iBAAO,EAAC,aAAa,CAAC,CAAC;AAChC,CAAC;AATD,kCASC","sourcesContent":["import { webpack } from 'webpack';\n\nimport type { ProcessedWebpackConfig } from '../config';\nimport type { WebpackOptions } from './config';\nimport { getDefaultConfiguration } from './config';\n\n/**\n * Get a Webpack compiler for the given config.\n *\n * @param config - The config object.\n * @param options - The Webpack options.\n * @returns The Webpack compiler.\n */\nexport async function getCompiler(\n config: ProcessedWebpackConfig,\n options?: WebpackOptions,\n) {\n const baseWebpackConfig = await getDefaultConfiguration(config, options);\n const webpackConfig =\n config.customizeWebpackConfig?.(baseWebpackConfig) ?? baseWebpackConfig;\n\n return webpack(webpackConfig);\n}\n"]}
1
+ {"version":3,"file":"compiler.cjs","sourceRoot":"","sources":["../../src/webpack/compiler.ts"],"names":[],"mappings":";;;AAAA,qCAAkC;AAGlC,yCAAmD;AAGnD;;;;;;GAMG;AACI,KAAK,UAAU,WAAW,CAC/B,MAAuB,EACvB,OAAwB;IAExB,MAAM,iBAAiB,GAAG,MAAM,IAAA,gCAAuB,EAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACzE,MAAM,aAAa,GACjB,MAAM,CAAC,sBAAsB,EAAE,CAAC,iBAAiB,CAAC,IAAI,iBAAiB,CAAC;IAE1E,OAAO,IAAA,iBAAO,EAAC,aAAa,CAAC,CAAC;AAChC,CAAC;AATD,kCASC","sourcesContent":["import { webpack } from 'webpack';\n\nimport type { WebpackOptions } from './config';\nimport { getDefaultConfiguration } from './config';\nimport type { ProcessedConfig } from '../config';\n\n/**\n * Get a Webpack compiler for the given config.\n *\n * @param config - The config object.\n * @param options - The Webpack options.\n * @returns The Webpack compiler.\n */\nexport async function getCompiler(\n config: ProcessedConfig,\n options?: WebpackOptions,\n) {\n const baseWebpackConfig = await getDefaultConfiguration(config, options);\n const webpackConfig =\n config.customizeWebpackConfig?.(baseWebpackConfig) ?? baseWebpackConfig;\n\n return webpack(webpackConfig);\n}\n"]}
@@ -1,5 +1,5 @@
1
- import type { ProcessedWebpackConfig } from "../config.cjs";
2
1
  import type { WebpackOptions } from "./config.cjs";
2
+ import type { ProcessedConfig } from "../config.cjs";
3
3
  /**
4
4
  * Get a Webpack compiler for the given config.
5
5
  *
@@ -7,5 +7,5 @@ import type { WebpackOptions } from "./config.cjs";
7
7
  * @param options - The Webpack options.
8
8
  * @returns The Webpack compiler.
9
9
  */
10
- export declare function getCompiler(config: ProcessedWebpackConfig, options?: WebpackOptions): Promise<import("webpack").Compiler>;
10
+ export declare function getCompiler(config: ProcessedConfig, options?: WebpackOptions): Promise<import("webpack").Compiler>;
11
11
  //# sourceMappingURL=compiler.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"compiler.d.cts","sourceRoot":"","sources":["../../src/webpack/compiler.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,sBAAsB,EAAE,sBAAkB;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,qBAAiB;AAG/C;;;;;;GAMG;AACH,wBAAsB,WAAW,CAC/B,MAAM,EAAE,sBAAsB,EAC9B,OAAO,CAAC,EAAE,cAAc,uCAOzB"}
1
+ {"version":3,"file":"compiler.d.cts","sourceRoot":"","sources":["../../src/webpack/compiler.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,qBAAiB;AAE/C,OAAO,KAAK,EAAE,eAAe,EAAE,sBAAkB;AAEjD;;;;;;GAMG;AACH,wBAAsB,WAAW,CAC/B,MAAM,EAAE,eAAe,EACvB,OAAO,CAAC,EAAE,cAAc,uCAOzB"}
@@ -1,5 +1,5 @@
1
- import type { ProcessedWebpackConfig } from "../config.mjs";
2
1
  import type { WebpackOptions } from "./config.mjs";
2
+ import type { ProcessedConfig } from "../config.mjs";
3
3
  /**
4
4
  * Get a Webpack compiler for the given config.
5
5
  *
@@ -7,5 +7,5 @@ import type { WebpackOptions } from "./config.mjs";
7
7
  * @param options - The Webpack options.
8
8
  * @returns The Webpack compiler.
9
9
  */
10
- export declare function getCompiler(config: ProcessedWebpackConfig, options?: WebpackOptions): Promise<import("webpack").Compiler>;
10
+ export declare function getCompiler(config: ProcessedConfig, options?: WebpackOptions): Promise<import("webpack").Compiler>;
11
11
  //# sourceMappingURL=compiler.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"compiler.d.mts","sourceRoot":"","sources":["../../src/webpack/compiler.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,sBAAsB,EAAE,sBAAkB;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,qBAAiB;AAG/C;;;;;;GAMG;AACH,wBAAsB,WAAW,CAC/B,MAAM,EAAE,sBAAsB,EAC9B,OAAO,CAAC,EAAE,cAAc,uCAOzB"}
1
+ {"version":3,"file":"compiler.d.mts","sourceRoot":"","sources":["../../src/webpack/compiler.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,qBAAiB;AAE/C,OAAO,KAAK,EAAE,eAAe,EAAE,sBAAkB;AAEjD;;;;;;GAMG;AACH,wBAAsB,WAAW,CAC/B,MAAM,EAAE,eAAe,EACvB,OAAO,CAAC,EAAE,cAAc,uCAOzB"}
@@ -1 +1 @@
1
- {"version":3,"file":"compiler.mjs","sourceRoot":"","sources":["../../src/webpack/compiler.ts"],"names":[],"mappings":";;AAIA,OAAO,EAAE,uBAAuB,EAAE,qBAAiB;AAEnD;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,MAA8B,EAC9B,OAAwB;IAExB,MAAM,iBAAiB,GAAG,MAAM,uBAAuB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACzE,MAAM,aAAa,GACjB,MAAM,CAAC,sBAAsB,EAAE,CAAC,iBAAiB,CAAC,IAAI,iBAAiB,CAAC;IAE1E,OAAO,OAAO,CAAC,aAAa,CAAC,CAAC;AAChC,CAAC","sourcesContent":["import { webpack } from 'webpack';\n\nimport type { ProcessedWebpackConfig } from '../config';\nimport type { WebpackOptions } from './config';\nimport { getDefaultConfiguration } from './config';\n\n/**\n * Get a Webpack compiler for the given config.\n *\n * @param config - The config object.\n * @param options - The Webpack options.\n * @returns The Webpack compiler.\n */\nexport async function getCompiler(\n config: ProcessedWebpackConfig,\n options?: WebpackOptions,\n) {\n const baseWebpackConfig = await getDefaultConfiguration(config, options);\n const webpackConfig =\n config.customizeWebpackConfig?.(baseWebpackConfig) ?? baseWebpackConfig;\n\n return webpack(webpackConfig);\n}\n"]}
1
+ {"version":3,"file":"compiler.mjs","sourceRoot":"","sources":["../../src/webpack/compiler.ts"],"names":[],"mappings":";;AAGA,OAAO,EAAE,uBAAuB,EAAE,qBAAiB;AAGnD;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,MAAuB,EACvB,OAAwB;IAExB,MAAM,iBAAiB,GAAG,MAAM,uBAAuB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACzE,MAAM,aAAa,GACjB,MAAM,CAAC,sBAAsB,EAAE,CAAC,iBAAiB,CAAC,IAAI,iBAAiB,CAAC;IAE1E,OAAO,OAAO,CAAC,aAAa,CAAC,CAAC;AAChC,CAAC","sourcesContent":["import { webpack } from 'webpack';\n\nimport type { WebpackOptions } from './config';\nimport { getDefaultConfiguration } from './config';\nimport type { ProcessedConfig } from '../config';\n\n/**\n * Get a Webpack compiler for the given config.\n *\n * @param config - The config object.\n * @param options - The Webpack options.\n * @returns The Webpack compiler.\n */\nexport async function getCompiler(\n config: ProcessedConfig,\n options?: WebpackOptions,\n) {\n const baseWebpackConfig = await getDefaultConfiguration(config, options);\n const webpackConfig =\n config.customizeWebpackConfig?.(baseWebpackConfig) ?? baseWebpackConfig;\n\n return webpack(webpackConfig);\n}\n"]}
@@ -9,6 +9,7 @@ const fork_ts_checker_webpack_plugin_1 = __importDefault(require("fork-ts-checke
9
9
  const path_1 = require("path");
10
10
  const terser_webpack_plugin_1 = __importDefault(require("terser-webpack-plugin"));
11
11
  const webpack_1 = require("webpack");
12
+ const webpack_bundle_analyzer_1 = require("webpack-bundle-analyzer");
12
13
  const loaders_1 = require("./loaders/index.cjs");
13
14
  const plugins_1 = require("./plugins.cjs");
14
15
  const utils_1 = require("./utils.cjs");
@@ -34,8 +35,7 @@ async function getDefaultConfiguration(config, options = {
34
35
  evaluate: config.evaluate,
35
36
  }) {
36
37
  const spinnerText = options.spinner?.text;
37
- const builtInResolver = config.stats.builtIns &&
38
- new plugins_1.SnapsBuiltInResolver(config.stats.builtIns, options.spinner);
38
+ const builtInResolver = config.stats.builtIns && new plugins_1.SnapsBuiltInResolver(config.stats.builtIns);
39
39
  return {
40
40
  /**
41
41
  * The target is set to `browserslist` so that Webpack will compile the
@@ -289,6 +289,12 @@ async function getDefaultConfiguration(config, options = {
289
289
  evaluate: options.evaluate,
290
290
  files: [config.manifest.path],
291
291
  }, options.spinner),
292
+ options.analyze &&
293
+ new webpack_bundle_analyzer_1.BundleAnalyzerPlugin({
294
+ analyzerPort: 0,
295
+ logLevel: 'silent',
296
+ openAnalyzer: false,
297
+ }),
292
298
  /**
293
299
  * The `ProviderPlugin` is a Webpack plugin that automatically load
294
300
  * modules instead of having to import or require them everywhere.
@@ -1 +1 @@
1
- {"version":3,"file":"config.cjs","sourceRoot":"","sources":["../../src/webpack/config.ts"],"names":[],"mappings":";;;;;;AAAA,0FAAgE;AAChE,oGAAwE;AAExE,+BAA+B;AAC/B,kFAAiD;AAEjD,qCAAsE;AAGtE,iDAAoD;AACpD,2CAKmB;AACnB,uCAQiB;AAoBjB;;;;;;;;;;;;;;;;;GAiBG;AACI,KAAK,UAAU,uBAAuB,CAC3C,MAA8B,EAC9B,UAA0B;IACxB,QAAQ,EAAE,MAAM,CAAC,QAAQ;CAC1B;IAED,MAAM,WAAW,GAAG,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC;IAC1C,MAAM,eAAe,GACnB,MAAM,CAAC,KAAK,CAAC,QAAQ;QACrB,IAAI,8BAAoB,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,OAAO,CA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I,+BAAY,CAAC;oBACf,QAAQ,EAAE,IAAI;iBACf,CAAC;aACH;SACF;QAED;;;;;WAKG;QACH,WAAW,EAAE;YACX;;;;;eAKG;YACH,KAAK,EAAE,KAAK;SACb;QAED;;;;;WAKG;QACH,qBAAqB,EAAE;YACrB;;;eAGG;YACH,KAAK,EAAE,MAAM;SACd;KACF,CAAC;AACJ,CAAC;AAvWD,0DAuWC","sourcesContent":["import SnapsWebpackPlugin from '@metamask/snaps-webpack-plugin';\nimport ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';\nimport type { Ora } from 'ora';\nimport { resolve } from 'path';\nimport TerserPlugin from 'terser-webpack-plugin';\nimport type { Configuration } from 'webpack';\nimport { DefinePlugin, ProgressPlugin, ProvidePlugin } from 'webpack';\n\nimport type { ProcessedWebpackConfig } from '../config';\nimport { getFunctionLoader, wasm } from './loaders';\nimport {\n SnapsBuiltInResolver,\n SnapsBundleWarningsPlugin,\n SnapsStatsPlugin,\n SnapsWatchPlugin,\n} from './plugins';\nimport {\n BROWSERSLIST_FILE,\n getDefaultLoader,\n getDevTool,\n getEnvironmentVariables,\n getFallbacks,\n getImageSVG,\n getProgressHandler,\n} from './utils';\n\nexport type WebpackOptions = {\n /**\n * Whether to watch for changes.\n */\n watch?: boolean;\n\n /**\n * Whether to evaluate the bundle. If this is set, it will override the\n * `evaluate` option in the config object.\n */\n evaluate?: boolean;\n\n /**\n * The spinner to use for logging.\n */\n spinner?: Ora;\n};\n\n/**\n * Get the default Webpack configuration. This is the configuration that will\n * be used if the user doesn't provide a custom Webpack configuration. The\n * configuration is based on the snap config.\n *\n * The default configuration includes:\n *\n * - `SWC` to transpile TypeScript and JavaScript files.\n * - `TerserPlugin` to minify the bundle.\n * - `SnapsWebpackPlugin` to validate the bundle and update the manifest.\n *\n * It can be customized through the `customizeWebpackConfig` function in the\n * snap config, but in most cases, you shouldn't need to do that.\n *\n * @param config - The processed snap Webpack config.\n * @param options - The Webpack options.\n * @returns The default Webpack configuration.\n */\nexport async function getDefaultConfiguration(\n config: ProcessedWebpackConfig,\n options: WebpackOptions = {\n evaluate: config.evaluate,\n },\n): Promise<Configuration> {\n const spinnerText = options.spinner?.text;\n const builtInResolver =\n config.stats.builtIns &&\n new SnapsBuiltInResolver(config.stats.builtIns, options.spinner);\n\n return {\n /**\n * The target is set to `browserslist` so that Webpack will compile the\n * bundle to support the browsers specified in the `.browserslistrc` file.\n * This Browserslist file contains the browsers that are supported by\n * MetaMask Snaps.\n *\n * @see https://webpack.js.org/configuration/target/\n */\n target: `browserslist:${BROWSERSLIST_FILE}`,\n\n /**\n * The mode is set to `production` by default, so that Webpack will minify\n * and optimize the bundle.\n *\n * @see https://webpack.js.org/configuration/mode/\n */\n mode: 'production',\n\n /**\n * The entry point is set to the `input` value from the config object.\n *\n * @see https://webpack.js.org/configuration/entry-context/\n */\n entry: config.input,\n\n /**\n * The devtool option controls how source maps are generated. We set it to\n * the `sourceMap` value from the config object.\n *\n * @see https://webpack.js.org/configuration/devtool/\n */\n devtool: getDevTool(config.sourceMap),\n\n /**\n * The stats option controls how much information is printed to the console\n * when Webpack is running. We set it to `none` so that we can control the\n * output ourselves.\n *\n * @see https://webpack.js.org/configuration/stats/\n */\n stats: 'none',\n\n /**\n * The output options.\n *\n * @see https://webpack.js.org/configuration/output/\n */\n output: {\n /**\n * This indicates whether Webpack should clear the output directory\n * before building. We set it to the `clean` value from the config\n * object.\n *\n * @see https://webpack.js.org/configuration/output/#outputclean\n */\n clean: config.output.clean,\n\n /**\n * The filename of the bundle. We set it to the `filename` value from\n * the config object.\n *\n * @see https://webpack.js.org/configuration/output/#outputfilename\n */\n filename: config.output.filename,\n\n /**\n * The path to the output directory. We set it to the `path` value from\n * the config object.\n *\n * @see https://webpack.js.org/configuration/output/#outputpath\n */\n path: config.output.path,\n\n /**\n * The public path of the bundle. We set it to `/` by default, so that\n * the bundle can be loaded from the root of the server.\n *\n * @see https://webpack.js.org/configuration/output/#outputpublicpath\n */\n publicPath: '/',\n\n /**\n * The library configuration. This tells Webpack how to export the\n * bundle.\n *\n * @see https://webpack.js.org/configuration/output/#outputlibrary\n */\n library: {\n /**\n * This tells Webpack to export the bundle via assignment to module.exports.\n * We do this to mimic CommonJS, but still allow for usage of async initialization logic\n * via top level await.\n *\n * CommonJS is currently the only supported format for MetaMask Snaps.\n *\n * @see https://webpack.js.org/configuration/output/#outputlibrarytarget\n */\n type: 'assign',\n name: 'module.exports',\n },\n\n /**\n * The chunk format. This tells Webpack how to export chunks. This is\n * required because we use browserslist to target browsers, but Snaps are\n * not fully compatible with browser APIs (such as `window` and\n * `document`).\n *\n * @see https://webpack.js.org/configuration/output/#outputchunkformat\n */\n chunkFormat: 'commonjs',\n },\n\n /**\n * The module configuration. This is where we tell Webpack how to handle\n * different types of files.\n *\n * @see https://webpack.js.org/configuration/module/\n */\n module: {\n rules: [\n {\n test: /\\.(js|jsx|mjs|cjs|ts|tsx)$/u,\n exclude: /node_modules/u,\n use: await getDefaultLoader(config),\n },\n\n /**\n * This allows importing modules that uses `.js` and not `.mjs` for the\n * ES build.\n *\n * @see https://webpack.js.org/configuration/module/#resolvefullyspecified\n */\n {\n test: /\\.m?js$/u,\n resolve: {\n fullySpecified: false,\n },\n },\n\n /**\n * This allows importing `.svg` files as a string.\n */\n config.features.images && {\n test: /\\.svg$/u,\n // `asset/source` returns the source as a UTF-8 string.\n type: 'asset/source',\n },\n\n /**\n * This allows importing `.png` files as a data URL.\n */\n config.features.images && {\n test: /\\.png$/u,\n type: 'asset/inline',\n generator: {\n dataUrl: getImageSVG.bind(null, 'image/png'),\n },\n },\n\n /**\n * This allows importing `.jpe?g` files as a data URL.\n */\n config.features.images && {\n test: /\\.jpe?g$/u,\n type: 'asset/inline',\n generator: {\n dataUrl: getImageSVG.bind(null, 'image/jpeg'),\n },\n },\n\n config.experimental.wasm && {\n test: /\\.wasm$/u,\n use: getFunctionLoader(wasm, {}),\n },\n ],\n },\n\n /**\n * The resolve configuration. This tells Webpack how to resolve imports.\n * We set it to resolve `.js` and `.ts` files.\n *\n * @see https://webpack.js.org/configuration/resolve/\n */\n resolve: {\n /**\n * The extensions to resolve. We set it to resolve `.(c|m)?jsx?` and\n * `.tsx?` files.\n */\n extensions: ['.js', '.jsx', '.mjs', '.cjs', '.ts', '.tsx'],\n\n /**\n * The fallback options. This tells Webpack how to handle imports that\n * aren't resolved. By default, we set Node.js built-ins to `false`, so\n * that they are ignored.\n */\n fallback: getFallbacks(config.polyfills),\n\n /**\n * The plugins to use. We use the {@link SnapsBuiltInResolver} to show\n * warnings about using Node.js built-ins, when no fallback is specified.\n */\n plugins: [builtInResolver],\n },\n\n /**\n * The plugins to use.\n *\n * @see https://webpack.js.org/configuration/plugins/\n */\n plugins: [\n /**\n * The `ForkTsCheckerWebpackPlugin` is a Webpack plugin that checks\n * Typescript type definitions, it does this in a separate process for speed.\n */\n config.typescript.enabled &&\n new ForkTsCheckerWebpackPlugin({\n typescript: {\n build: true,\n configFile: config.typescript.configFile,\n },\n }),\n\n /**\n * The `SnapsWebpackPlugin` is a Webpack plugin that checks and updates\n * the manifest file, and evaluates the bundle in SES. While not strictly\n * required, it's highly recommended to use this plugin.\n */\n new SnapsWebpackPlugin({\n manifestPath: config.manifest.path,\n writeManifest: config.manifest.update,\n eval: !options.watch && options.evaluate,\n }),\n\n /**\n * The `SnapsStatsPlugin` is a Webpack plugin that handles the stats\n * output. It's used to show the stats in the terminal, in a format that\n * is easy to read.\n */\n new SnapsStatsPlugin({ verbose: config.stats.verbose }, options.spinner),\n\n /**\n * The `DefinePlugin` is a Webpack plugin that adds static values to the\n * bundle. We use it to add the `NODE_DEBUG`, `NODE_ENV`, and `DEBUG`\n * environment variables, as well as any custom environment\n * variables (as `process.env`).\n */\n new DefinePlugin(getEnvironmentVariables(config.environment)),\n\n /**\n * The `ProgressPlugin` is a Webpack plugin that logs the progress of\n * the build. We set it to log the progress to the spinner.\n */\n new ProgressPlugin({\n handler: getProgressHandler(options.spinner, spinnerText),\n }),\n\n /**\n * The `SnapsBundleWarningPlugin` is a Webpack plugin that shows a\n * warning when the bundle is potentially incompatible with MetaMask\n * Snaps.\n */\n new SnapsBundleWarningsPlugin({\n builtInResolver,\n builtIns: Boolean(config.stats.builtIns),\n buffer: config.stats.buffer,\n }),\n\n /**\n * The `WatchPlugin` is a Webpack plugin that adds extra files to watch\n * for changes. This is useful for rebuilding the bundle when the\n * manifest file changes.\n */\n options.watch &&\n new SnapsWatchPlugin(\n {\n bundle: resolve(config.output.path, config.output.filename),\n evaluate: options.evaluate,\n files: [config.manifest.path],\n },\n options.spinner,\n ),\n\n /**\n * The `ProviderPlugin` is a Webpack plugin that automatically load\n * modules instead of having to import or require them everywhere.\n */\n (config.polyfills === true ||\n (config.polyfills !== false && config.polyfills.buffer)) &&\n new ProvidePlugin({\n Buffer: ['buffer', 'Buffer'],\n }),\n ].filter(Boolean),\n\n /**\n * The optimization configuration. This tells Webpack how to optimize the\n * bundle. Most of the time, you won't need to change this, as the default\n * options set by the `mode` option are sufficient.\n */\n optimization: {\n minimize: config.output.minimize,\n\n /**\n * We disable the nodeEnv optimization as we already add process.NODE_ENV\n * via the DefinePlugin in the section above this.\n */\n nodeEnv: false,\n\n /**\n * The minimizer to use. We set it to use the `TerserPlugin`.\n */\n minimizer: [\n new TerserPlugin({\n parallel: true,\n }),\n ],\n },\n\n /**\n * The performance configuration. This tells Webpack how to handle\n * performance hints.\n *\n * @see https://webpack.js.org/configuration/performance/\n */\n performance: {\n /**\n * The hints to show. We set it to `false`, so that we don't get\n * performance hints, as they are not relevant for Snaps.\n *\n * @see https://webpack.js.org/configuration/performance/#performancehints\n */\n hints: false,\n },\n\n /**\n * The infrastructure logging configuration. This tells Webpack how to\n * log messages.\n *\n * @see https://webpack.js.org/configuration/infrastructure-logging\n */\n infrastructureLogging: {\n /**\n * The level of logging to use. We set it to `none`, so that we can\n * control the output ourselves.\n */\n level: 'none',\n },\n };\n}\n"]}
1
+ {"version":3,"file":"config.cjs","sourceRoot":"","sources":["../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AC;iBAC9B,EACD,OAAO,CAAC,OAAO,CAChB;YAEH,OAAO,CAAC,OAAO;gBACb,IAAI,8CAAoB,CAAC;oBACvB,YAAY,EAAE,CAAC;oBACf,QAAQ,EAAE,QAAQ;oBAClB,YAAY,EAAE,KAAK;iBACpB,CAAC;YAEJ;;;eAGG;YACH,CAAC,MAAM,CAAC,SAAS,KAAK,IAAI;gBACxB,CAAC,MAAM,CAAC,SAAS,KAAK,KAAK,IAAI,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;gBACxD,IAAI,uBAAa,CAAC;oBAChB,MAAM,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC;iBAC7B,CAAC;SACL,CAAC,MAAM,CAAC,OAAO,CAAC;QAEjB;;;;WAIG;QACH,YAAY,EAAE;YACZ,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,QAAQ;YAEhC;;;eAGG;YACH,OAAO,EAAE,KAAK;YAEd;;eAEG;YACH,SAAS,EAAE;gBACT,IAAI,+BAAY,CAAC;oBACf,QAAQ,EAAE,IAAI;iBACf,CAAC;aACH;SACF;QAED;;;;;WAKG;QACH,WAAW,EAAE;YACX;;;;;eAKG;YACH,KAAK,EAAE,KAAK;SACb;QAED;;;;;WAKG;QACH,qBAAqB,EAAE;YACrB;;;eAGG;YACH,KAAK,EAAE,MAAM;SACd;KACF,CAAC;AACJ,CAAC;AA7WD,0DA6WC","sourcesContent":["import SnapsWebpackPlugin from '@metamask/snaps-webpack-plugin';\nimport ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';\nimport type { Ora } from 'ora';\nimport { resolve } from 'path';\nimport TerserPlugin from 'terser-webpack-plugin';\nimport type { Configuration } from 'webpack';\nimport { DefinePlugin, ProgressPlugin, ProvidePlugin } from 'webpack';\nimport { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';\n\nimport { getFunctionLoader, wasm } from './loaders';\nimport {\n SnapsBuiltInResolver,\n SnapsBundleWarningsPlugin,\n SnapsStatsPlugin,\n SnapsWatchPlugin,\n} from './plugins';\nimport {\n BROWSERSLIST_FILE,\n getDefaultLoader,\n getDevTool,\n getEnvironmentVariables,\n getFallbacks,\n getImageSVG,\n getProgressHandler,\n} from './utils';\nimport type { ProcessedConfig } from '../config';\n\nexport type WebpackOptions = {\n /**\n * Whether to analyze the bundle.\n */\n analyze?: boolean;\n\n /**\n * Whether to watch for changes.\n */\n watch?: boolean;\n\n /**\n * Whether to evaluate the bundle. If this is set, it will override the\n * `evaluate` option in the config object.\n */\n evaluate?: boolean;\n\n /**\n * The spinner to use for logging.\n */\n spinner?: Ora;\n};\n\n/**\n * Get the default Webpack configuration. This is the configuration that will\n * be used if the user doesn't provide a custom Webpack configuration. The\n * configuration is based on the snap config.\n *\n * The default configuration includes:\n *\n * - `SWC` to transpile TypeScript and JavaScript files.\n * - `TerserPlugin` to minify the bundle.\n * - `SnapsWebpackPlugin` to validate the bundle and update the manifest.\n *\n * It can be customized through the `customizeWebpackConfig` function in the\n * snap config, but in most cases, you shouldn't need to do that.\n *\n * @param config - The processed snap Webpack config.\n * @param options - The Webpack options.\n * @returns The default Webpack configuration.\n */\nexport async function getDefaultConfiguration(\n config: ProcessedConfig,\n options: WebpackOptions = {\n evaluate: config.evaluate,\n },\n): Promise<Configuration> {\n const spinnerText = options.spinner?.text;\n const builtInResolver =\n config.stats.builtIns && new SnapsBuiltInResolver(config.stats.builtIns);\n\n return {\n /**\n * The target is set to `browserslist` so that Webpack will compile the\n * bundle to support the browsers specified in the `.browserslistrc` file.\n * This Browserslist file contains the browsers that are supported by\n * MetaMask Snaps.\n *\n * @see https://webpack.js.org/configuration/target/\n */\n target: `browserslist:${BROWSERSLIST_FILE}`,\n\n /**\n * The mode is set to `production` by default, so that Webpack will minify\n * and optimize the bundle.\n *\n * @see https://webpack.js.org/configuration/mode/\n */\n mode: 'production',\n\n /**\n * The entry point is set to the `input` value from the config object.\n *\n * @see https://webpack.js.org/configuration/entry-context/\n */\n entry: config.input,\n\n /**\n * The devtool option controls how source maps are generated. We set it to\n * the `sourceMap` value from the config object.\n *\n * @see https://webpack.js.org/configuration/devtool/\n */\n devtool: getDevTool(config.sourceMap),\n\n /**\n * The stats option controls how much information is printed to the console\n * when Webpack is running. We set it to `none` so that we can control the\n * output ourselves.\n *\n * @see https://webpack.js.org/configuration/stats/\n */\n stats: 'none',\n\n /**\n * The output options.\n *\n * @see https://webpack.js.org/configuration/output/\n */\n output: {\n /**\n * This indicates whether Webpack should clear the output directory\n * before building. We set it to the `clean` value from the config\n * object.\n *\n * @see https://webpack.js.org/configuration/output/#outputclean\n */\n clean: config.output.clean,\n\n /**\n * The filename of the bundle. We set it to the `filename` value from\n * the config object.\n *\n * @see https://webpack.js.org/configuration/output/#outputfilename\n */\n filename: config.output.filename,\n\n /**\n * The path to the output directory. We set it to the `path` value from\n * the config object.\n *\n * @see https://webpack.js.org/configuration/output/#outputpath\n */\n path: config.output.path,\n\n /**\n * The public path of the bundle. We set it to `/` by default, so that\n * the bundle can be loaded from the root of the server.\n *\n * @see https://webpack.js.org/configuration/output/#outputpublicpath\n */\n publicPath: '/',\n\n /**\n * The library configuration. This tells Webpack how to export the\n * bundle.\n *\n * @see https://webpack.js.org/configuration/output/#outputlibrary\n */\n library: {\n /**\n * This tells Webpack to export the bundle via assignment to module.exports.\n * We do this to mimic CommonJS, but still allow for usage of async initialization logic\n * via top level await.\n *\n * CommonJS is currently the only supported format for MetaMask Snaps.\n *\n * @see https://webpack.js.org/configuration/output/#outputlibrarytarget\n */\n type: 'assign',\n name: 'module.exports',\n },\n\n /**\n * The chunk format. This tells Webpack how to export chunks. This is\n * required because we use browserslist to target browsers, but Snaps are\n * not fully compatible with browser APIs (such as `window` and\n * `document`).\n *\n * @see https://webpack.js.org/configuration/output/#outputchunkformat\n */\n chunkFormat: 'commonjs',\n },\n\n /**\n * The module configuration. This is where we tell Webpack how to handle\n * different types of files.\n *\n * @see https://webpack.js.org/configuration/module/\n */\n module: {\n rules: [\n {\n test: /\\.(js|jsx|mjs|cjs|ts|tsx)$/u,\n exclude: /node_modules/u,\n use: await getDefaultLoader(config),\n },\n\n /**\n * This allows importing modules that uses `.js` and not `.mjs` for the\n * ES build.\n *\n * @see https://webpack.js.org/configuration/module/#resolvefullyspecified\n */\n {\n test: /\\.m?js$/u,\n resolve: {\n fullySpecified: false,\n },\n },\n\n /**\n * This allows importing `.svg` files as a string.\n */\n config.features.images && {\n test: /\\.svg$/u,\n // `asset/source` returns the source as a UTF-8 string.\n type: 'asset/source',\n },\n\n /**\n * This allows importing `.png` files as a data URL.\n */\n config.features.images && {\n test: /\\.png$/u,\n type: 'asset/inline',\n generator: {\n dataUrl: getImageSVG.bind(null, 'image/png'),\n },\n },\n\n /**\n * This allows importing `.jpe?g` files as a data URL.\n */\n config.features.images && {\n test: /\\.jpe?g$/u,\n type: 'asset/inline',\n generator: {\n dataUrl: getImageSVG.bind(null, 'image/jpeg'),\n },\n },\n\n config.experimental.wasm && {\n test: /\\.wasm$/u,\n use: getFunctionLoader(wasm, {}),\n },\n ],\n },\n\n /**\n * The resolve configuration. This tells Webpack how to resolve imports.\n * We set it to resolve `.js` and `.ts` files.\n *\n * @see https://webpack.js.org/configuration/resolve/\n */\n resolve: {\n /**\n * The extensions to resolve. We set it to resolve `.(c|m)?jsx?` and\n * `.tsx?` files.\n */\n extensions: ['.js', '.jsx', '.mjs', '.cjs', '.ts', '.tsx'],\n\n /**\n * The fallback options. This tells Webpack how to handle imports that\n * aren't resolved. By default, we set Node.js built-ins to `false`, so\n * that they are ignored.\n */\n fallback: getFallbacks(config.polyfills),\n\n /**\n * The plugins to use. We use the {@link SnapsBuiltInResolver} to show\n * warnings about using Node.js built-ins, when no fallback is specified.\n */\n plugins: [builtInResolver],\n },\n\n /**\n * The plugins to use.\n *\n * @see https://webpack.js.org/configuration/plugins/\n */\n plugins: [\n /**\n * The `ForkTsCheckerWebpackPlugin` is a Webpack plugin that checks\n * Typescript type definitions, it does this in a separate process for speed.\n */\n config.typescript.enabled &&\n new ForkTsCheckerWebpackPlugin({\n typescript: {\n build: true,\n configFile: config.typescript.configFile,\n },\n }),\n\n /**\n * The `SnapsWebpackPlugin` is a Webpack plugin that checks and updates\n * the manifest file, and evaluates the bundle in SES. While not strictly\n * required, it's highly recommended to use this plugin.\n */\n new SnapsWebpackPlugin({\n manifestPath: config.manifest.path,\n writeManifest: config.manifest.update,\n eval: !options.watch && options.evaluate,\n }),\n\n /**\n * The `SnapsStatsPlugin` is a Webpack plugin that handles the stats\n * output. It's used to show the stats in the terminal, in a format that\n * is easy to read.\n */\n new SnapsStatsPlugin({ verbose: config.stats.verbose }, options.spinner),\n\n /**\n * The `DefinePlugin` is a Webpack plugin that adds static values to the\n * bundle. We use it to add the `NODE_DEBUG`, `NODE_ENV`, and `DEBUG`\n * environment variables, as well as any custom environment\n * variables (as `process.env`).\n */\n new DefinePlugin(getEnvironmentVariables(config.environment)),\n\n /**\n * The `ProgressPlugin` is a Webpack plugin that logs the progress of\n * the build. We set it to log the progress to the spinner.\n */\n new ProgressPlugin({\n handler: getProgressHandler(options.spinner, spinnerText),\n }),\n\n /**\n * The `SnapsBundleWarningPlugin` is a Webpack plugin that shows a\n * warning when the bundle is potentially incompatible with MetaMask\n * Snaps.\n */\n new SnapsBundleWarningsPlugin({\n builtInResolver,\n builtIns: Boolean(config.stats.builtIns),\n buffer: config.stats.buffer,\n }),\n\n /**\n * The `WatchPlugin` is a Webpack plugin that adds extra files to watch\n * for changes. This is useful for rebuilding the bundle when the\n * manifest file changes.\n */\n options.watch &&\n new SnapsWatchPlugin(\n {\n bundle: resolve(config.output.path, config.output.filename),\n evaluate: options.evaluate,\n files: [config.manifest.path],\n },\n options.spinner,\n ),\n\n options.analyze &&\n new BundleAnalyzerPlugin({\n analyzerPort: 0,\n logLevel: 'silent',\n openAnalyzer: false,\n }),\n\n /**\n * The `ProviderPlugin` is a Webpack plugin that automatically load\n * modules instead of having to import or require them everywhere.\n */\n (config.polyfills === true ||\n (config.polyfills !== false && config.polyfills.buffer)) &&\n new ProvidePlugin({\n Buffer: ['buffer', 'Buffer'],\n }),\n ].filter(Boolean),\n\n /**\n * The optimization configuration. This tells Webpack how to optimize the\n * bundle. Most of the time, you won't need to change this, as the default\n * options set by the `mode` option are sufficient.\n */\n optimization: {\n minimize: config.output.minimize,\n\n /**\n * We disable the nodeEnv optimization as we already add process.NODE_ENV\n * via the DefinePlugin in the section above this.\n */\n nodeEnv: false,\n\n /**\n * The minimizer to use. We set it to use the `TerserPlugin`.\n */\n minimizer: [\n new TerserPlugin({\n parallel: true,\n }),\n ],\n },\n\n /**\n * The performance configuration. This tells Webpack how to handle\n * performance hints.\n *\n * @see https://webpack.js.org/configuration/performance/\n */\n performance: {\n /**\n * The hints to show. We set it to `false`, so that we don't get\n * performance hints, as they are not relevant for Snaps.\n *\n * @see https://webpack.js.org/configuration/performance/#performancehints\n */\n hints: false,\n },\n\n /**\n * The infrastructure logging configuration. This tells Webpack how to\n * log messages.\n *\n * @see https://webpack.js.org/configuration/infrastructure-logging\n */\n infrastructureLogging: {\n /**\n * The level of logging to use. We set it to `none`, so that we can\n * control the output ourselves.\n */\n level: 'none',\n },\n };\n}\n"]}
@@ -1,7 +1,11 @@
1
1
  import type { Ora } from "ora/index.js";
2
2
  import type { Configuration } from "webpack";
3
- import type { ProcessedWebpackConfig } from "../config.cjs";
3
+ import type { ProcessedConfig } from "../config.cjs";
4
4
  export type WebpackOptions = {
5
+ /**
6
+ * Whether to analyze the bundle.
7
+ */
8
+ analyze?: boolean;
5
9
  /**
6
10
  * Whether to watch for changes.
7
11
  */
@@ -34,5 +38,5 @@ export type WebpackOptions = {
34
38
  * @param options - The Webpack options.
35
39
  * @returns The default Webpack configuration.
36
40
  */
37
- export declare function getDefaultConfiguration(config: ProcessedWebpackConfig, options?: WebpackOptions): Promise<Configuration>;
41
+ export declare function getDefaultConfiguration(config: ProcessedConfig, options?: WebpackOptions): Promise<Configuration>;
38
42
  //# sourceMappingURL=config.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.cts","sourceRoot":"","sources":["../../src/webpack/config.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,qBAAY;AAG/B,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB;AAG7C,OAAO,KAAK,EAAE,sBAAsB,EAAE,sBAAkB;AAkBxD,MAAM,MAAM,cAAc,GAAG;IAC3B;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;OAEG;IACH,OAAO,CAAC,EAAE,GAAG,CAAC;CACf,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,uBAAuB,CAC3C,MAAM,EAAE,sBAAsB,EAC9B,OAAO,GAAE,cAER,GACA,OAAO,CAAC,aAAa,CAAC,CAkWxB"}
1
+ {"version":3,"file":"config.d.cts","sourceRoot":"","sources":["../../src/webpack/config.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,qBAAY;AAG/B,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB;AAoB7C,OAAO,KAAK,EAAE,eAAe,EAAE,sBAAkB;AAEjD,MAAM,MAAM,cAAc,GAAG;IAC3B;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;OAEG;IACH,OAAO,CAAC,EAAE,GAAG,CAAC;CACf,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,uBAAuB,CAC3C,MAAM,EAAE,eAAe,EACvB,OAAO,GAAE,cAER,GACA,OAAO,CAAC,aAAa,CAAC,CAwWxB"}
@@ -1,7 +1,11 @@
1
1
  import type { Ora } from "ora/index.js";
2
2
  import type { Configuration } from "webpack";
3
- import type { ProcessedWebpackConfig } from "../config.mjs";
3
+ import type { ProcessedConfig } from "../config.mjs";
4
4
  export type WebpackOptions = {
5
+ /**
6
+ * Whether to analyze the bundle.
7
+ */
8
+ analyze?: boolean;
5
9
  /**
6
10
  * Whether to watch for changes.
7
11
  */
@@ -34,5 +38,5 @@ export type WebpackOptions = {
34
38
  * @param options - The Webpack options.
35
39
  * @returns The default Webpack configuration.
36
40
  */
37
- export declare function getDefaultConfiguration(config: ProcessedWebpackConfig, options?: WebpackOptions): Promise<Configuration>;
41
+ export declare function getDefaultConfiguration(config: ProcessedConfig, options?: WebpackOptions): Promise<Configuration>;
38
42
  //# sourceMappingURL=config.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.mts","sourceRoot":"","sources":["../../src/webpack/config.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,qBAAY;AAG/B,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB;AAG7C,OAAO,KAAK,EAAE,sBAAsB,EAAE,sBAAkB;AAkBxD,MAAM,MAAM,cAAc,GAAG;IAC3B;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;OAEG;IACH,OAAO,CAAC,EAAE,GAAG,CAAC;CACf,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,uBAAuB,CAC3C,MAAM,EAAE,sBAAsB,EAC9B,OAAO,GAAE,cAER,GACA,OAAO,CAAC,aAAa,CAAC,CAkWxB"}
1
+ {"version":3,"file":"config.d.mts","sourceRoot":"","sources":["../../src/webpack/config.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,qBAAY;AAG/B,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB;AAoB7C,OAAO,KAAK,EAAE,eAAe,EAAE,sBAAkB;AAEjD,MAAM,MAAM,cAAc,GAAG;IAC3B;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;OAEG;IACH,OAAO,CAAC,EAAE,GAAG,CAAC;CACf,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,uBAAuB,CAC3C,MAAM,EAAE,eAAe,EACvB,OAAO,GAAE,cAER,GACA,OAAO,CAAC,aAAa,CAAC,CAwWxB"}
@@ -12,6 +12,7 @@ import $TerserPlugin from "terser-webpack-plugin";
12
12
  const TerserPlugin = $importDefault($TerserPlugin);
13
13
  import $webpack from "webpack";
14
14
  const { DefinePlugin, ProgressPlugin, ProvidePlugin } = $webpack;
15
+ import { BundleAnalyzerPlugin } from "webpack-bundle-analyzer";
15
16
  import { getFunctionLoader, wasm } from "./loaders/index.mjs";
16
17
  import { SnapsBuiltInResolver, SnapsBundleWarningsPlugin, SnapsStatsPlugin, SnapsWatchPlugin } from "./plugins.mjs";
17
18
  import { BROWSERSLIST_FILE, getDefaultLoader, getDevTool, getEnvironmentVariables, getFallbacks, getImageSVG, getProgressHandler } from "./utils.mjs";
@@ -37,8 +38,7 @@ export async function getDefaultConfiguration(config, options = {
37
38
  evaluate: config.evaluate,
38
39
  }) {
39
40
  const spinnerText = options.spinner?.text;
40
- const builtInResolver = config.stats.builtIns &&
41
- new SnapsBuiltInResolver(config.stats.builtIns, options.spinner);
41
+ const builtInResolver = config.stats.builtIns && new SnapsBuiltInResolver(config.stats.builtIns);
42
42
  return {
43
43
  /**
44
44
  * The target is set to `browserslist` so that Webpack will compile the
@@ -292,6 +292,12 @@ export async function getDefaultConfiguration(config, options = {
292
292
  evaluate: options.evaluate,
293
293
  files: [config.manifest.path],
294
294
  }, options.spinner),
295
+ options.analyze &&
296
+ new BundleAnalyzerPlugin({
297
+ analyzerPort: 0,
298
+ logLevel: 'silent',
299
+ openAnalyzer: false,
300
+ }),
295
301
  /**
296
302
  * The `ProviderPlugin` is a Webpack plugin that automatically load
297
303
  * modules instead of having to import or require them everywhere.
@@ -1 +1 @@
1
- {"version":3,"file":"config.mjs","sourceRoot":"","sources":["../../src/webpack/config.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,kBAAkB,uCAAuC;AAChE,OAAO,2BAA0B,uCAAuC;;AAExE,OAAO,EAAE,OAAO,EAAE,aAAa;AAC/B,OAAO,aAAY,8BAA8B;;;;AAKjD,OAAO,EAAE,iBAAiB,EAAE,IAAI,EAAE,4BAAkB;AACpD,OAAO,EACL,oBAAoB,EACpB,yBAAyB,EACzB,gBAAgB,EAChB,gBAAgB,EACjB,sBAAkB;AACnB,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,UAAU,EACV,uBAAuB,EACvB,YAAY,EACZ,WAAW,EACX,kBAAkB,EACnB,oBAAgB;AAoBjB;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,MAA8B,EAC9B,UAA0B;IACxB,QAAQ,EAAE,MAAM,CAAC,QAAQ;CAC1B;IAED,MAAM,WAAW,GAAG,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC;IAC1C,MAAM,eAAe,GACnB,MAAM,CAAC,KAAK,CAAC,QAAQ;QACrB,IAAI,oBAAoB,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IAEnE,OAAO;QACL;;;;;;;WAOG;QACH,MAAM,EAAE,gBAAgB,iBAAiB,EAAE;QAE3C;;;;;WAKG;QACH,IAAI,EAAE,YAAY;QAElB;;;;WAIG;QACH,KAAK,EAAE,MAAM,CAAC,KAAK;QAEnB;;;;;WAKG;QACH,OAAO,EAAE,UAAU,CAAC,MAAM,CAAC,SAAS,CAAC;QAErC;;;;;;WAMG;QACH,KAAK,EAAE,MAAM;QAEb;;;;WAIG;QACH,MAAM,EAAE;YACN;;;;;;eAMG;YACH,KAAK,EAAE,M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K,CAAC,QAAQ,CAAC;gBACxC,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM;aAC5B,CAAC;YAEF;;;;eAIG;YACH,OAAO,CAAC,KAAK;gBACX,IAAI,gBAAgB,CAClB;oBACE,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC;oBAC3D,QAAQ,EAAE,OAAO,CAAC,QAAQ;oBAC1B,KAAK,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;iBAC9B,EACD,OAAO,CAAC,OAAO,CAChB;YAEH;;;eAGG;YACH,CAAC,MAAM,CAAC,SAAS,KAAK,IAAI;gBACxB,CAAC,MAAM,CAAC,SAAS,KAAK,KAAK,IAAI,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;gBACxD,IAAI,aAAa,CAAC;oBAChB,MAAM,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC;iBAC7B,CAAC;SACL,CAAC,MAAM,CAAC,OAAO,CAAC;QAEjB;;;;WAIG;QACH,YAAY,EAAE;YACZ,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,QAAQ;YAEhC;;;eAGG;YACH,OAAO,EAAE,KAAK;YAEd;;eAEG;YACH,SAAS,EAAE;gBACT,IAAI,YAAY,CAAC;oBACf,QAAQ,EAAE,IAAI;iBACf,CAAC;aACH;SACF;QAED;;;;;WAKG;QACH,WAAW,EAAE;YACX;;;;;eAKG;YACH,KAAK,EAAE,KAAK;SACb;QAED;;;;;WAKG;QACH,qBAAqB,EAAE;YACrB;;;eAGG;YACH,KAAK,EAAE,MAAM;SACd;KACF,CAAC;AACJ,CAAC","sourcesContent":["import SnapsWebpackPlugin from '@metamask/snaps-webpack-plugin';\nimport ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';\nimport type { Ora } from 'ora';\nimport { resolve } from 'path';\nimport TerserPlugin from 'terser-webpack-plugin';\nimport type { Configuration } from 'webpack';\nimport { DefinePlugin, ProgressPlugin, ProvidePlugin } from 'webpack';\n\nimport type { ProcessedWebpackConfig } from '../config';\nimport { getFunctionLoader, wasm } from './loaders';\nimport {\n SnapsBuiltInResolver,\n SnapsBundleWarningsPlugin,\n SnapsStatsPlugin,\n SnapsWatchPlugin,\n} from './plugins';\nimport {\n BROWSERSLIST_FILE,\n getDefaultLoader,\n getDevTool,\n getEnvironmentVariables,\n getFallbacks,\n getImageSVG,\n getProgressHandler,\n} from './utils';\n\nexport type WebpackOptions = {\n /**\n * Whether to watch for changes.\n */\n watch?: boolean;\n\n /**\n * Whether to evaluate the bundle. If this is set, it will override the\n * `evaluate` option in the config object.\n */\n evaluate?: boolean;\n\n /**\n * The spinner to use for logging.\n */\n spinner?: Ora;\n};\n\n/**\n * Get the default Webpack configuration. This is the configuration that will\n * be used if the user doesn't provide a custom Webpack configuration. The\n * configuration is based on the snap config.\n *\n * The default configuration includes:\n *\n * - `SWC` to transpile TypeScript and JavaScript files.\n * - `TerserPlugin` to minify the bundle.\n * - `SnapsWebpackPlugin` to validate the bundle and update the manifest.\n *\n * It can be customized through the `customizeWebpackConfig` function in the\n * snap config, but in most cases, you shouldn't need to do that.\n *\n * @param config - The processed snap Webpack config.\n * @param options - The Webpack options.\n * @returns The default Webpack configuration.\n */\nexport async function getDefaultConfiguration(\n config: ProcessedWebpackConfig,\n options: WebpackOptions = {\n evaluate: config.evaluate,\n },\n): Promise<Configuration> {\n const spinnerText = options.spinner?.text;\n const builtInResolver =\n config.stats.builtIns &&\n new SnapsBuiltInResolver(config.stats.builtIns, options.spinner);\n\n return {\n /**\n * The target is set to `browserslist` so that Webpack will compile the\n * bundle to support the browsers specified in the `.browserslistrc` file.\n * This Browserslist file contains the browsers that are supported by\n * MetaMask Snaps.\n *\n * @see https://webpack.js.org/configuration/target/\n */\n target: `browserslist:${BROWSERSLIST_FILE}`,\n\n /**\n * The mode is set to `production` by default, so that Webpack will minify\n * and optimize the bundle.\n *\n * @see https://webpack.js.org/configuration/mode/\n */\n mode: 'production',\n\n /**\n * The entry point is set to the `input` value from the config object.\n *\n * @see https://webpack.js.org/configuration/entry-context/\n */\n entry: config.input,\n\n /**\n * The devtool option controls how source maps are generated. We set it to\n * the `sourceMap` value from the config object.\n *\n * @see https://webpack.js.org/configuration/devtool/\n */\n devtool: getDevTool(config.sourceMap),\n\n /**\n * The stats option controls how much information is printed to the console\n * when Webpack is running. We set it to `none` so that we can control the\n * output ourselves.\n *\n * @see https://webpack.js.org/configuration/stats/\n */\n stats: 'none',\n\n /**\n * The output options.\n *\n * @see https://webpack.js.org/configuration/output/\n */\n output: {\n /**\n * This indicates whether Webpack should clear the output directory\n * before building. We set it to the `clean` value from the config\n * object.\n *\n * @see https://webpack.js.org/configuration/output/#outputclean\n */\n clean: config.output.clean,\n\n /**\n * The filename of the bundle. We set it to the `filename` value from\n * the config object.\n *\n * @see https://webpack.js.org/configuration/output/#outputfilename\n */\n filename: config.output.filename,\n\n /**\n * The path to the output directory. We set it to the `path` value from\n * the config object.\n *\n * @see https://webpack.js.org/configuration/output/#outputpath\n */\n path: config.output.path,\n\n /**\n * The public path of the bundle. We set it to `/` by default, so that\n * the bundle can be loaded from the root of the server.\n *\n * @see https://webpack.js.org/configuration/output/#outputpublicpath\n */\n publicPath: '/',\n\n /**\n * The library configuration. This tells Webpack how to export the\n * bundle.\n *\n * @see https://webpack.js.org/configuration/output/#outputlibrary\n */\n library: {\n /**\n * This tells Webpack to export the bundle via assignment to module.exports.\n * We do this to mimic CommonJS, but still allow for usage of async initialization logic\n * via top level await.\n *\n * CommonJS is currently the only supported format for MetaMask Snaps.\n *\n * @see https://webpack.js.org/configuration/output/#outputlibrarytarget\n */\n type: 'assign',\n name: 'module.exports',\n },\n\n /**\n * The chunk format. This tells Webpack how to export chunks. This is\n * required because we use browserslist to target browsers, but Snaps are\n * not fully compatible with browser APIs (such as `window` and\n * `document`).\n *\n * @see https://webpack.js.org/configuration/output/#outputchunkformat\n */\n chunkFormat: 'commonjs',\n },\n\n /**\n * The module configuration. This is where we tell Webpack how to handle\n * different types of files.\n *\n * @see https://webpack.js.org/configuration/module/\n */\n module: {\n rules: [\n {\n test: /\\.(js|jsx|mjs|cjs|ts|tsx)$/u,\n exclude: /node_modules/u,\n use: await getDefaultLoader(config),\n },\n\n /**\n * This allows importing modules that uses `.js` and not `.mjs` for the\n * ES build.\n *\n * @see https://webpack.js.org/configuration/module/#resolvefullyspecified\n */\n {\n test: /\\.m?js$/u,\n resolve: {\n fullySpecified: false,\n },\n },\n\n /**\n * This allows importing `.svg` files as a string.\n */\n config.features.images && {\n test: /\\.svg$/u,\n // `asset/source` returns the source as a UTF-8 string.\n type: 'asset/source',\n },\n\n /**\n * This allows importing `.png` files as a data URL.\n */\n config.features.images && {\n test: /\\.png$/u,\n type: 'asset/inline',\n generator: {\n dataUrl: getImageSVG.bind(null, 'image/png'),\n },\n },\n\n /**\n * This allows importing `.jpe?g` files as a data URL.\n */\n config.features.images && {\n test: /\\.jpe?g$/u,\n type: 'asset/inline',\n generator: {\n dataUrl: getImageSVG.bind(null, 'image/jpeg'),\n },\n },\n\n config.experimental.wasm && {\n test: /\\.wasm$/u,\n use: getFunctionLoader(wasm, {}),\n },\n ],\n },\n\n /**\n * The resolve configuration. This tells Webpack how to resolve imports.\n * We set it to resolve `.js` and `.ts` files.\n *\n * @see https://webpack.js.org/configuration/resolve/\n */\n resolve: {\n /**\n * The extensions to resolve. We set it to resolve `.(c|m)?jsx?` and\n * `.tsx?` files.\n */\n extensions: ['.js', '.jsx', '.mjs', '.cjs', '.ts', '.tsx'],\n\n /**\n * The fallback options. This tells Webpack how to handle imports that\n * aren't resolved. By default, we set Node.js built-ins to `false`, so\n * that they are ignored.\n */\n fallback: getFallbacks(config.polyfills),\n\n /**\n * The plugins to use. We use the {@link SnapsBuiltInResolver} to show\n * warnings about using Node.js built-ins, when no fallback is specified.\n */\n plugins: [builtInResolver],\n },\n\n /**\n * The plugins to use.\n *\n * @see https://webpack.js.org/configuration/plugins/\n */\n plugins: [\n /**\n * The `ForkTsCheckerWebpackPlugin` is a Webpack plugin that checks\n * Typescript type definitions, it does this in a separate process for speed.\n */\n config.typescript.enabled &&\n new ForkTsCheckerWebpackPlugin({\n typescript: {\n build: true,\n configFile: config.typescript.configFile,\n },\n }),\n\n /**\n * The `SnapsWebpackPlugin` is a Webpack plugin that checks and updates\n * the manifest file, and evaluates the bundle in SES. While not strictly\n * required, it's highly recommended to use this plugin.\n */\n new SnapsWebpackPlugin({\n manifestPath: config.manifest.path,\n writeManifest: config.manifest.update,\n eval: !options.watch && options.evaluate,\n }),\n\n /**\n * The `SnapsStatsPlugin` is a Webpack plugin that handles the stats\n * output. It's used to show the stats in the terminal, in a format that\n * is easy to read.\n */\n new SnapsStatsPlugin({ verbose: config.stats.verbose }, options.spinner),\n\n /**\n * The `DefinePlugin` is a Webpack plugin that adds static values to the\n * bundle. We use it to add the `NODE_DEBUG`, `NODE_ENV`, and `DEBUG`\n * environment variables, as well as any custom environment\n * variables (as `process.env`).\n */\n new DefinePlugin(getEnvironmentVariables(config.environment)),\n\n /**\n * The `ProgressPlugin` is a Webpack plugin that logs the progress of\n * the build. We set it to log the progress to the spinner.\n */\n new ProgressPlugin({\n handler: getProgressHandler(options.spinner, spinnerText),\n }),\n\n /**\n * The `SnapsBundleWarningPlugin` is a Webpack plugin that shows a\n * warning when the bundle is potentially incompatible with MetaMask\n * Snaps.\n */\n new SnapsBundleWarningsPlugin({\n builtInResolver,\n builtIns: Boolean(config.stats.builtIns),\n buffer: config.stats.buffer,\n }),\n\n /**\n * The `WatchPlugin` is a Webpack plugin that adds extra files to watch\n * for changes. This is useful for rebuilding the bundle when the\n * manifest file changes.\n */\n options.watch &&\n new SnapsWatchPlugin(\n {\n bundle: resolve(config.output.path, config.output.filename),\n evaluate: options.evaluate,\n files: [config.manifest.path],\n },\n options.spinner,\n ),\n\n /**\n * The `ProviderPlugin` is a Webpack plugin that automatically load\n * modules instead of having to import or require them everywhere.\n */\n (config.polyfills === true ||\n (config.polyfills !== false && config.polyfills.buffer)) &&\n new ProvidePlugin({\n Buffer: ['buffer', 'Buffer'],\n }),\n ].filter(Boolean),\n\n /**\n * The optimization configuration. This tells Webpack how to optimize the\n * bundle. Most of the time, you won't need to change this, as the default\n * options set by the `mode` option are sufficient.\n */\n optimization: {\n minimize: config.output.minimize,\n\n /**\n * We disable the nodeEnv optimization as we already add process.NODE_ENV\n * via the DefinePlugin in the section above this.\n */\n nodeEnv: false,\n\n /**\n * The minimizer to use. We set it to use the `TerserPlugin`.\n */\n minimizer: [\n new TerserPlugin({\n parallel: true,\n }),\n ],\n },\n\n /**\n * The performance configuration. This tells Webpack how to handle\n * performance hints.\n *\n * @see https://webpack.js.org/configuration/performance/\n */\n performance: {\n /**\n * The hints to show. We set it to `false`, so that we don't get\n * performance hints, as they are not relevant for Snaps.\n *\n * @see https://webpack.js.org/configuration/performance/#performancehints\n */\n hints: false,\n },\n\n /**\n * The infrastructure logging configuration. This tells Webpack how to\n * log messages.\n *\n * @see https://webpack.js.org/configuration/infrastructure-logging\n */\n infrastructureLogging: {\n /**\n * The level of logging to use. We set it to `none`, so that we can\n * control the output ourselves.\n */\n level: 'none',\n },\n };\n}\n"]}
1
+ {"version":3,"file":"config.mjs","sourceRoot":"","sources":["../../src/webpack/config.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,kBAAkB,uCAAuC;AAChE,OAAO,2BAA0B,uCAAuC;;AAExE,OAAO,EAAE,OAAO,EAAE,aAAa;AAC/B,OAAO,aAAY,8BAA8B;;;;AAGjD,OAAO,EAAE,oBAAoB,EAAE,gCAAgC;AAE/D,OAAO,EAAE,iBAAiB,EAAE,IAAI,EAAE,4BAAkB;AACpD,OAAO,EACL,oBAAoB,EACpB,yBAAyB,EACzB,gBAAgB,EAChB,gBAAgB,EACjB,sBAAkB;AACnB,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,UAAU,EACV,uBAAuB,EACvB,YAAY,E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;iBACpB,CAAC;YAEJ;;;eAGG;YACH,CAAC,MAAM,CAAC,SAAS,KAAK,IAAI;gBACxB,CAAC,MAAM,CAAC,SAAS,KAAK,KAAK,IAAI,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;gBACxD,IAAI,aAAa,CAAC;oBAChB,MAAM,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC;iBAC7B,CAAC;SACL,CAAC,MAAM,CAAC,OAAO,CAAC;QAEjB;;;;WAIG;QACH,YAAY,EAAE;YACZ,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,QAAQ;YAEhC;;;eAGG;YACH,OAAO,EAAE,KAAK;YAEd;;eAEG;YACH,SAAS,EAAE;gBACT,IAAI,YAAY,CAAC;oBACf,QAAQ,EAAE,IAAI;iBACf,CAAC;aACH;SACF;QAED;;;;;WAKG;QACH,WAAW,EAAE;YACX;;;;;eAKG;YACH,KAAK,EAAE,KAAK;SACb;QAED;;;;;WAKG;QACH,qBAAqB,EAAE;YACrB;;;eAGG;YACH,KAAK,EAAE,MAAM;SACd;KACF,CAAC;AACJ,CAAC","sourcesContent":["import SnapsWebpackPlugin from '@metamask/snaps-webpack-plugin';\nimport ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';\nimport type { Ora } from 'ora';\nimport { resolve } from 'path';\nimport TerserPlugin from 'terser-webpack-plugin';\nimport type { Configuration } from 'webpack';\nimport { DefinePlugin, ProgressPlugin, ProvidePlugin } from 'webpack';\nimport { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';\n\nimport { getFunctionLoader, wasm } from './loaders';\nimport {\n SnapsBuiltInResolver,\n SnapsBundleWarningsPlugin,\n SnapsStatsPlugin,\n SnapsWatchPlugin,\n} from './plugins';\nimport {\n BROWSERSLIST_FILE,\n getDefaultLoader,\n getDevTool,\n getEnvironmentVariables,\n getFallbacks,\n getImageSVG,\n getProgressHandler,\n} from './utils';\nimport type { ProcessedConfig } from '../config';\n\nexport type WebpackOptions = {\n /**\n * Whether to analyze the bundle.\n */\n analyze?: boolean;\n\n /**\n * Whether to watch for changes.\n */\n watch?: boolean;\n\n /**\n * Whether to evaluate the bundle. If this is set, it will override the\n * `evaluate` option in the config object.\n */\n evaluate?: boolean;\n\n /**\n * The spinner to use for logging.\n */\n spinner?: Ora;\n};\n\n/**\n * Get the default Webpack configuration. This is the configuration that will\n * be used if the user doesn't provide a custom Webpack configuration. The\n * configuration is based on the snap config.\n *\n * The default configuration includes:\n *\n * - `SWC` to transpile TypeScript and JavaScript files.\n * - `TerserPlugin` to minify the bundle.\n * - `SnapsWebpackPlugin` to validate the bundle and update the manifest.\n *\n * It can be customized through the `customizeWebpackConfig` function in the\n * snap config, but in most cases, you shouldn't need to do that.\n *\n * @param config - The processed snap Webpack config.\n * @param options - The Webpack options.\n * @returns The default Webpack configuration.\n */\nexport async function getDefaultConfiguration(\n config: ProcessedConfig,\n options: WebpackOptions = {\n evaluate: config.evaluate,\n },\n): Promise<Configuration> {\n const spinnerText = options.spinner?.text;\n const builtInResolver =\n config.stats.builtIns && new SnapsBuiltInResolver(config.stats.builtIns);\n\n return {\n /**\n * The target is set to `browserslist` so that Webpack will compile the\n * bundle to support the browsers specified in the `.browserslistrc` file.\n * This Browserslist file contains the browsers that are supported by\n * MetaMask Snaps.\n *\n * @see https://webpack.js.org/configuration/target/\n */\n target: `browserslist:${BROWSERSLIST_FILE}`,\n\n /**\n * The mode is set to `production` by default, so that Webpack will minify\n * and optimize the bundle.\n *\n * @see https://webpack.js.org/configuration/mode/\n */\n mode: 'production',\n\n /**\n * The entry point is set to the `input` value from the config object.\n *\n * @see https://webpack.js.org/configuration/entry-context/\n */\n entry: config.input,\n\n /**\n * The devtool option controls how source maps are generated. We set it to\n * the `sourceMap` value from the config object.\n *\n * @see https://webpack.js.org/configuration/devtool/\n */\n devtool: getDevTool(config.sourceMap),\n\n /**\n * The stats option controls how much information is printed to the console\n * when Webpack is running. We set it to `none` so that we can control the\n * output ourselves.\n *\n * @see https://webpack.js.org/configuration/stats/\n */\n stats: 'none',\n\n /**\n * The output options.\n *\n * @see https://webpack.js.org/configuration/output/\n */\n output: {\n /**\n * This indicates whether Webpack should clear the output directory\n * before building. We set it to the `clean` value from the config\n * object.\n *\n * @see https://webpack.js.org/configuration/output/#outputclean\n */\n clean: config.output.clean,\n\n /**\n * The filename of the bundle. We set it to the `filename` value from\n * the config object.\n *\n * @see https://webpack.js.org/configuration/output/#outputfilename\n */\n filename: config.output.filename,\n\n /**\n * The path to the output directory. We set it to the `path` value from\n * the config object.\n *\n * @see https://webpack.js.org/configuration/output/#outputpath\n */\n path: config.output.path,\n\n /**\n * The public path of the bundle. We set it to `/` by default, so that\n * the bundle can be loaded from the root of the server.\n *\n * @see https://webpack.js.org/configuration/output/#outputpublicpath\n */\n publicPath: '/',\n\n /**\n * The library configuration. This tells Webpack how to export the\n * bundle.\n *\n * @see https://webpack.js.org/configuration/output/#outputlibrary\n */\n library: {\n /**\n * This tells Webpack to export the bundle via assignment to module.exports.\n * We do this to mimic CommonJS, but still allow for usage of async initialization logic\n * via top level await.\n *\n * CommonJS is currently the only supported format for MetaMask Snaps.\n *\n * @see https://webpack.js.org/configuration/output/#outputlibrarytarget\n */\n type: 'assign',\n name: 'module.exports',\n },\n\n /**\n * The chunk format. This tells Webpack how to export chunks. This is\n * required because we use browserslist to target browsers, but Snaps are\n * not fully compatible with browser APIs (such as `window` and\n * `document`).\n *\n * @see https://webpack.js.org/configuration/output/#outputchunkformat\n */\n chunkFormat: 'commonjs',\n },\n\n /**\n * The module configuration. This is where we tell Webpack how to handle\n * different types of files.\n *\n * @see https://webpack.js.org/configuration/module/\n */\n module: {\n rules: [\n {\n test: /\\.(js|jsx|mjs|cjs|ts|tsx)$/u,\n exclude: /node_modules/u,\n use: await getDefaultLoader(config),\n },\n\n /**\n * This allows importing modules that uses `.js` and not `.mjs` for the\n * ES build.\n *\n * @see https://webpack.js.org/configuration/module/#resolvefullyspecified\n */\n {\n test: /\\.m?js$/u,\n resolve: {\n fullySpecified: false,\n },\n },\n\n /**\n * This allows importing `.svg` files as a string.\n */\n config.features.images && {\n test: /\\.svg$/u,\n // `asset/source` returns the source as a UTF-8 string.\n type: 'asset/source',\n },\n\n /**\n * This allows importing `.png` files as a data URL.\n */\n config.features.images && {\n test: /\\.png$/u,\n type: 'asset/inline',\n generator: {\n dataUrl: getImageSVG.bind(null, 'image/png'),\n },\n },\n\n /**\n * This allows importing `.jpe?g` files as a data URL.\n */\n config.features.images && {\n test: /\\.jpe?g$/u,\n type: 'asset/inline',\n generator: {\n dataUrl: getImageSVG.bind(null, 'image/jpeg'),\n },\n },\n\n config.experimental.wasm && {\n test: /\\.wasm$/u,\n use: getFunctionLoader(wasm, {}),\n },\n ],\n },\n\n /**\n * The resolve configuration. This tells Webpack how to resolve imports.\n * We set it to resolve `.js` and `.ts` files.\n *\n * @see https://webpack.js.org/configuration/resolve/\n */\n resolve: {\n /**\n * The extensions to resolve. We set it to resolve `.(c|m)?jsx?` and\n * `.tsx?` files.\n */\n extensions: ['.js', '.jsx', '.mjs', '.cjs', '.ts', '.tsx'],\n\n /**\n * The fallback options. This tells Webpack how to handle imports that\n * aren't resolved. By default, we set Node.js built-ins to `false`, so\n * that they are ignored.\n */\n fallback: getFallbacks(config.polyfills),\n\n /**\n * The plugins to use. We use the {@link SnapsBuiltInResolver} to show\n * warnings about using Node.js built-ins, when no fallback is specified.\n */\n plugins: [builtInResolver],\n },\n\n /**\n * The plugins to use.\n *\n * @see https://webpack.js.org/configuration/plugins/\n */\n plugins: [\n /**\n * The `ForkTsCheckerWebpackPlugin` is a Webpack plugin that checks\n * Typescript type definitions, it does this in a separate process for speed.\n */\n config.typescript.enabled &&\n new ForkTsCheckerWebpackPlugin({\n typescript: {\n build: true,\n configFile: config.typescript.configFile,\n },\n }),\n\n /**\n * The `SnapsWebpackPlugin` is a Webpack plugin that checks and updates\n * the manifest file, and evaluates the bundle in SES. While not strictly\n * required, it's highly recommended to use this plugin.\n */\n new SnapsWebpackPlugin({\n manifestPath: config.manifest.path,\n writeManifest: config.manifest.update,\n eval: !options.watch && options.evaluate,\n }),\n\n /**\n * The `SnapsStatsPlugin` is a Webpack plugin that handles the stats\n * output. It's used to show the stats in the terminal, in a format that\n * is easy to read.\n */\n new SnapsStatsPlugin({ verbose: config.stats.verbose }, options.spinner),\n\n /**\n * The `DefinePlugin` is a Webpack plugin that adds static values to the\n * bundle. We use it to add the `NODE_DEBUG`, `NODE_ENV`, and `DEBUG`\n * environment variables, as well as any custom environment\n * variables (as `process.env`).\n */\n new DefinePlugin(getEnvironmentVariables(config.environment)),\n\n /**\n * The `ProgressPlugin` is a Webpack plugin that logs the progress of\n * the build. We set it to log the progress to the spinner.\n */\n new ProgressPlugin({\n handler: getProgressHandler(options.spinner, spinnerText),\n }),\n\n /**\n * The `SnapsBundleWarningPlugin` is a Webpack plugin that shows a\n * warning when the bundle is potentially incompatible with MetaMask\n * Snaps.\n */\n new SnapsBundleWarningsPlugin({\n builtInResolver,\n builtIns: Boolean(config.stats.builtIns),\n buffer: config.stats.buffer,\n }),\n\n /**\n * The `WatchPlugin` is a Webpack plugin that adds extra files to watch\n * for changes. This is useful for rebuilding the bundle when the\n * manifest file changes.\n */\n options.watch &&\n new SnapsWatchPlugin(\n {\n bundle: resolve(config.output.path, config.output.filename),\n evaluate: options.evaluate,\n files: [config.manifest.path],\n },\n options.spinner,\n ),\n\n options.analyze &&\n new BundleAnalyzerPlugin({\n analyzerPort: 0,\n logLevel: 'silent',\n openAnalyzer: false,\n }),\n\n /**\n * The `ProviderPlugin` is a Webpack plugin that automatically load\n * modules instead of having to import or require them everywhere.\n */\n (config.polyfills === true ||\n (config.polyfills !== false && config.polyfills.buffer)) &&\n new ProvidePlugin({\n Buffer: ['buffer', 'Buffer'],\n }),\n ].filter(Boolean),\n\n /**\n * The optimization configuration. This tells Webpack how to optimize the\n * bundle. Most of the time, you won't need to change this, as the default\n * options set by the `mode` option are sufficient.\n */\n optimization: {\n minimize: config.output.minimize,\n\n /**\n * We disable the nodeEnv optimization as we already add process.NODE_ENV\n * via the DefinePlugin in the section above this.\n */\n nodeEnv: false,\n\n /**\n * The minimizer to use. We set it to use the `TerserPlugin`.\n */\n minimizer: [\n new TerserPlugin({\n parallel: true,\n }),\n ],\n },\n\n /**\n * The performance configuration. This tells Webpack how to handle\n * performance hints.\n *\n * @see https://webpack.js.org/configuration/performance/\n */\n performance: {\n /**\n * The hints to show. We set it to `false`, so that we don't get\n * performance hints, as they are not relevant for Snaps.\n *\n * @see https://webpack.js.org/configuration/performance/#performancehints\n */\n hints: false,\n },\n\n /**\n * The infrastructure logging configuration. This tells Webpack how to\n * log messages.\n *\n * @see https://webpack.js.org/configuration/infrastructure-logging\n */\n infrastructureLogging: {\n /**\n * The level of logging to use. We set it to `none`, so that we can\n * control the output ourselves.\n */\n level: 'none',\n },\n };\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getFunctionLoader = void 0;
3
+ exports.getFunctionLoader = exports.raw = void 0;
4
4
  /**
5
5
  * A loader that executes a function. See {@link getFunctionLoader} for more
6
6
  * information.
@@ -8,11 +8,17 @@ exports.getFunctionLoader = void 0;
8
8
  * @param content - The input file contents as a `Uint8Array`.
9
9
  * @returns The output of the function.
10
10
  */
11
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
12
+ // eslint-disable-next-line @typescript-eslint/promise-function-async
11
13
  const loader = function (content) {
12
14
  const { fn } = this.getOptions();
13
15
  return fn.bind(this)(content);
14
16
  };
15
17
  exports.default = loader;
18
+ // By setting `raw` to `true`, we are telling Webpack to provide the source as a
19
+ // `Uint8Array` instead of converting it to a string. This allows us to avoid
20
+ // having to convert the source back to a `Uint8Array` in the loader.
21
+ exports.raw = true;
16
22
  /**
17
23
  * Get a loader that executes the given function. This is useful for executing
18
24
  * loaders without needing to pass a file to Webpack.
@@ -33,13 +39,4 @@ function getFunctionLoader(fn, options) {
33
39
  };
34
40
  }
35
41
  exports.getFunctionLoader = getFunctionLoader;
36
- // When running as CJS, we need to export the loader as a default export, since
37
- // `tsup` exports it as `loader_default`.
38
- // istanbul ignore next 3
39
- // eslint-disable-next-line n/no-process-env
40
- if (typeof module !== 'undefined' && process?.env?.NODE_ENV !== 'test') {
41
- module.exports = loader;
42
- module.exports.getFunctionLoader = getFunctionLoader;
43
- module.exports.raw = true;
44
- }
45
42
  //# sourceMappingURL=function.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"function.cjs","sourceRoot":"","sources":["../../../src/webpack/loaders/function.ts"],"names":[],"mappings":";;;AAaA;;;;;;GAMG;AACH,MAAM,MAAM,GAAoD,UAC9D,OAAO;IAEP,MAAM,EAAE,EAAE,EAAE,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;IACjC,OAAO,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC;AAChC,CAAC,CAAC;AAEF,kBAAe,MAAM,CAAC;AAEtB;;;;;;;GAOG;AACH,SAAgB,iBAAiB,CAC/B,EAAqC,EACrC,OAAgB;IAEhB,OAAO;QACL,2EAA2E;QAC3E,sDAAsD;QACtD,MAAM,EAAE,UAAU;QAClB,OAAO,EAAE;YACP,EAAE;YACF,GAAG,OAAO;SACX;KACF,CAAC;AACJ,CAAC;AAbD,8CAaC;AAED,+EAA+E;AAC/E,yCAAyC;AACzC,yBAAyB;AACzB,4CAA4C;AAC5C,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,EAAE,GAAG,EAAE,QAAQ,KAAK,MAAM,EAAE,CAAC;IACvE,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,MAAM,CAAC,OAAO,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;IACrD,MAAM,CAAC,OAAO,CAAC,GAAG,GAAG,IAAI,CAAC;AAC5B,CAAC","sourcesContent":["import type { LoaderDefinitionFunction } from 'webpack';\n\n/**\n * Options for the function loader.\n */\nexport type FunctionLoaderOptions = {\n /**\n * The function to execute. This is bound to the loader context, so it can\n * access the loader options and other properties.\n */\n fn: LoaderDefinitionFunction;\n};\n\n/**\n * A loader that executes a function. See {@link getFunctionLoader} for more\n * information.\n *\n * @param content - The input file contents as a `Uint8Array`.\n * @returns The output of the function.\n */\nconst loader: LoaderDefinitionFunction<FunctionLoaderOptions> = function (\n content,\n) {\n const { fn } = this.getOptions();\n return fn.bind(this)(content);\n};\n\nexport default loader;\n\n/**\n * Get a loader that executes the given function. This is useful for executing\n * loaders without needing to pass a file to Webpack.\n *\n * @param fn - The function to execute.\n * @param options - The options to pass to the loader.\n * @returns The loader definition.\n */\nexport function getFunctionLoader<Options>(\n fn: LoaderDefinitionFunction<Options>,\n options: Options,\n) {\n return {\n // We use `__filename` as the loader, so Webpack will execute the loader in\n // this file, with the actual function in the options.\n loader: __filename,\n options: {\n fn,\n ...options,\n },\n };\n}\n\n// When running as CJS, we need to export the loader as a default export, since\n// `tsup` exports it as `loader_default`.\n// istanbul ignore next 3\n// eslint-disable-next-line n/no-process-env\nif (typeof module !== 'undefined' && process?.env?.NODE_ENV !== 'test') {\n module.exports = loader;\n module.exports.getFunctionLoader = getFunctionLoader;\n module.exports.raw = true;\n}\n"]}
1
+ {"version":3,"file":"function.cjs","sourceRoot":"","sources":["../../../src/webpack/loaders/function.ts"],"names":[],"mappings":";;;AAaA;;;;;;GAMG;AACH,gFAAgF;AAChF,qEAAqE;AACrE,MAAM,MAAM,GAAoD,UAC9D,OAAO;IAEP,MAAM,EAAE,EAAE,EAAE,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;IACjC,OAAO,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC;AAChC,CAAC,CAAC;AAEF,kBAAe,MAAM,CAAC;AAEtB,gFAAgF;AAChF,6EAA6E;AAC7E,qEAAqE;AACxD,QAAA,GAAG,GAAG,IAAI,CAAC;AAExB;;;;;;;GAOG;AACH,SAAgB,iBAAiB,CAC/B,EAAqC,EACrC,OAAgB;IAEhB,OAAO;QACL,2EAA2E;QAC3E,sDAAsD;QACtD,MAAM,EAAE,UAAU;QAClB,OAAO,EAAE;YACP,EAAE;YACF,GAAG,OAAO;SACX;KACF,CAAC;AACJ,CAAC;AAbD,8CAaC","sourcesContent":["import type { LoaderDefinitionFunction } from 'webpack';\n\n/**\n * Options for the function loader.\n */\nexport type FunctionLoaderOptions = {\n /**\n * The function to execute. This is bound to the loader context, so it can\n * access the loader options and other properties.\n */\n fn: LoaderDefinitionFunction;\n};\n\n/**\n * A loader that executes a function. See {@link getFunctionLoader} for more\n * information.\n *\n * @param content - The input file contents as a `Uint8Array`.\n * @returns The output of the function.\n */\n// TODO: Either fix this lint violation or explain why it's necessary to ignore.\n// eslint-disable-next-line @typescript-eslint/promise-function-async\nconst loader: LoaderDefinitionFunction<FunctionLoaderOptions> = function (\n content,\n) {\n const { fn } = this.getOptions();\n return fn.bind(this)(content);\n};\n\nexport default loader;\n\n// By setting `raw` to `true`, we are telling Webpack to provide the source as a\n// `Uint8Array` instead of converting it to a string. This allows us to avoid\n// having to convert the source back to a `Uint8Array` in the loader.\nexport const raw = true;\n\n/**\n * Get a loader that executes the given function. This is useful for executing\n * loaders without needing to pass a file to Webpack.\n *\n * @param fn - The function to execute.\n * @param options - The options to pass to the loader.\n * @returns The loader definition.\n */\nexport function getFunctionLoader<Options>(\n fn: LoaderDefinitionFunction<Options>,\n options: Options,\n) {\n return {\n // We use `__filename` as the loader, so Webpack will execute the loader in\n // this file, with the actual function in the options.\n loader: __filename,\n options: {\n fn,\n ...options,\n },\n };\n}\n"]}
@@ -18,6 +18,7 @@ export type FunctionLoaderOptions = {
18
18
  */
19
19
  declare const loader: LoaderDefinitionFunction<FunctionLoaderOptions>;
20
20
  export default loader;
21
+ export declare const raw = true;
21
22
  /**
22
23
  * Get a loader that executes the given function. This is useful for executing
23
24
  * loaders without needing to pass a file to Webpack.
@@ -1 +1 @@
1
- {"version":3,"file":"function.d.cts","sourceRoot":"","sources":["../../../src/webpack/loaders/function.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,gBAAgB;AAExD;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC;;;OAGG;IACH,EAAE,EAAE,wBAAwB,CAAC;CAC9B,CAAC;AAEF;;;;;;GAMG;AACH,QAAA,MAAM,MAAM,EAAE,wBAAwB,CAAC,qBAAqB,CAK3D,CAAC;AAEF,eAAe,MAAM,CAAC;AAEtB;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EACvC,EAAE,EAAE,wBAAwB,CAAC,OAAO,CAAC,EACrC,OAAO,EAAE,OAAO;;;;;EAWjB"}
1
+ {"version":3,"file":"function.d.cts","sourceRoot":"","sources":["../../../src/webpack/loaders/function.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,gBAAgB;AAExD;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC;;;OAGG;IACH,EAAE,EAAE,wBAAwB,CAAC;CAC9B,CAAC;AAEF;;;;;;GAMG;AAGH,QAAA,MAAM,MAAM,EAAE,wBAAwB,CAAC,qBAAqB,CAK3D,CAAC;AAEF,eAAe,MAAM,CAAC;AAKtB,eAAO,MAAM,GAAG,OAAO,CAAC;AAExB;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EACvC,EAAE,EAAE,wBAAwB,CAAC,OAAO,CAAC,EACrC,OAAO,EAAE,OAAO;;;;;EAWjB"}
@@ -18,6 +18,7 @@ export type FunctionLoaderOptions = {
18
18
  */
19
19
  declare const loader: LoaderDefinitionFunction<FunctionLoaderOptions>;
20
20
  export default loader;
21
+ export declare const raw = true;
21
22
  /**
22
23
  * Get a loader that executes the given function. This is useful for executing
23
24
  * loaders without needing to pass a file to Webpack.
@@ -1 +1 @@
1
- {"version":3,"file":"function.d.mts","sourceRoot":"","sources":["../../../src/webpack/loaders/function.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,gBAAgB;AAExD;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC;;;OAGG;IACH,EAAE,EAAE,wBAAwB,CAAC;CAC9B,CAAC;AAEF;;;;;;GAMG;AACH,QAAA,MAAM,MAAM,EAAE,wBAAwB,CAAC,qBAAqB,CAK3D,CAAC;AAEF,eAAe,MAAM,CAAC;AAEtB;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EACvC,EAAE,EAAE,wBAAwB,CAAC,OAAO,CAAC,EACrC,OAAO,EAAE,OAAO;;;;;EAWjB"}
1
+ {"version":3,"file":"function.d.mts","sourceRoot":"","sources":["../../../src/webpack/loaders/function.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,gBAAgB;AAExD;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC;;;OAGG;IACH,EAAE,EAAE,wBAAwB,CAAC;CAC9B,CAAC;AAEF;;;;;;GAMG;AAGH,QAAA,MAAM,MAAM,EAAE,wBAAwB,CAAC,qBAAqB,CAK3D,CAAC;AAEF,eAAe,MAAM,CAAC;AAKtB,eAAO,MAAM,GAAG,OAAO,CAAC;AAExB;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EACvC,EAAE,EAAE,wBAAwB,CAAC,OAAO,CAAC,EACrC,OAAO,EAAE,OAAO;;;;;EAWjB"}