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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (256) hide show
  1. package/.browserslistrc +3 -0
  2. package/CHANGELOG.md +19 -425
  3. package/README.md +539 -63
  4. package/dist/cjs/builders.js +40 -41
  5. package/dist/cjs/builders.js.map +1 -1
  6. package/dist/cjs/cli.js +14 -14
  7. package/dist/cjs/cli.js.map +1 -1
  8. package/dist/cjs/commands/build/build.js +54 -0
  9. package/dist/cjs/commands/build/build.js.map +1 -0
  10. package/dist/cjs/commands/build/implementation.js +31 -0
  11. package/dist/cjs/commands/build/implementation.js.map +1 -0
  12. package/dist/cjs/{cmds → commands}/build/index.js +18 -5
  13. package/dist/cjs/commands/build/index.js.map +1 -0
  14. package/dist/cjs/commands/eval/eval.js +57 -0
  15. package/dist/cjs/commands/eval/eval.js.map +1 -0
  16. package/dist/cjs/commands/eval/implementation.js +27 -0
  17. package/dist/cjs/commands/eval/implementation.js.map +1 -0
  18. package/dist/cjs/commands/eval/index.js +50 -0
  19. package/dist/cjs/commands/eval/index.js.map +1 -0
  20. package/dist/cjs/commands/index.js.map +1 -0
  21. package/dist/cjs/commands/manifest/implementation.js +34 -0
  22. package/dist/cjs/commands/manifest/implementation.js.map +1 -0
  23. package/dist/cjs/commands/manifest/index.js +50 -0
  24. package/dist/cjs/commands/manifest/index.js.map +1 -0
  25. package/dist/cjs/commands/manifest/manifest.js +55 -0
  26. package/dist/cjs/commands/manifest/manifest.js.map +1 -0
  27. package/dist/cjs/{cmds → commands}/serve/index.js +4 -2
  28. package/dist/cjs/commands/serve/index.js.map +1 -0
  29. package/dist/cjs/commands/serve/serve.js +21 -0
  30. package/dist/cjs/commands/serve/serve.js.map +1 -0
  31. package/dist/cjs/commands/watch/implementation.js +35 -0
  32. package/dist/cjs/commands/watch/implementation.js.map +1 -0
  33. package/dist/cjs/{cmds → commands}/watch/index.js +19 -4
  34. package/dist/cjs/commands/watch/index.js.map +1 -0
  35. package/dist/cjs/commands/watch/watch.js +51 -0
  36. package/dist/cjs/commands/watch/watch.js.map +1 -0
  37. package/dist/cjs/config.js +290 -0
  38. package/dist/cjs/config.js.map +1 -0
  39. package/dist/cjs/errors.js +37 -0
  40. package/dist/cjs/errors.js.map +1 -0
  41. package/dist/cjs/index.js +28 -3
  42. package/dist/cjs/index.js.map +1 -1
  43. package/dist/cjs/main.js +6 -7
  44. package/dist/cjs/main.js.map +1 -1
  45. package/dist/cjs/utils/cli.js +61 -0
  46. package/dist/cjs/utils/cli.js.map +1 -0
  47. package/dist/cjs/utils/errors.js +42 -0
  48. package/dist/cjs/utils/errors.js.map +1 -0
  49. package/dist/cjs/utils/index.js +6 -2
  50. package/dist/cjs/utils/index.js.map +1 -1
  51. package/dist/cjs/utils/legacy.js +48 -0
  52. package/dist/cjs/utils/legacy.js.map +1 -0
  53. package/dist/cjs/utils/logging.js +46 -0
  54. package/dist/cjs/utils/logging.js.map +1 -0
  55. package/dist/cjs/utils/path.js +16 -0
  56. package/dist/cjs/utils/path.js.map +1 -0
  57. package/dist/cjs/utils/steps.js +52 -0
  58. package/dist/cjs/utils/steps.js.map +1 -0
  59. package/dist/cjs/webpack/compiler.js +96 -0
  60. package/dist/cjs/webpack/compiler.js.map +1 -0
  61. package/dist/cjs/webpack/config.js +234 -0
  62. package/dist/cjs/webpack/config.js.map +1 -0
  63. package/dist/cjs/webpack/index.js +22 -0
  64. package/dist/cjs/webpack/index.js.map +1 -0
  65. package/dist/cjs/webpack/loaders/browserify.js +97 -0
  66. package/dist/cjs/webpack/loaders/browserify.js.map +1 -0
  67. package/dist/cjs/webpack/loaders/wasm.js +36 -0
  68. package/dist/cjs/webpack/loaders/wasm.js.map +1 -0
  69. package/dist/cjs/webpack/plugins.js +340 -0
  70. package/dist/cjs/webpack/plugins.js.map +1 -0
  71. package/dist/cjs/webpack/utils.js +133 -0
  72. package/dist/cjs/webpack/utils.js.map +1 -0
  73. package/dist/esm/builders.js +40 -41
  74. package/dist/esm/builders.js.map +1 -1
  75. package/dist/esm/cli.js +15 -15
  76. package/dist/esm/cli.js.map +1 -1
  77. package/dist/esm/commands/build/build.js +51 -0
  78. package/dist/esm/commands/build/build.js.map +1 -0
  79. package/dist/esm/commands/build/implementation.js +27 -0
  80. package/dist/esm/commands/build/implementation.js.map +1 -0
  81. package/dist/esm/{cmds → commands}/build/index.js +5 -5
  82. package/dist/esm/commands/build/index.js.map +1 -0
  83. package/dist/esm/commands/eval/eval.js +54 -0
  84. package/dist/esm/commands/eval/eval.js.map +1 -0
  85. package/dist/esm/commands/eval/implementation.js +24 -0
  86. package/dist/esm/commands/eval/implementation.js.map +1 -0
  87. package/dist/esm/commands/eval/index.js +22 -0
  88. package/dist/esm/commands/eval/index.js.map +1 -0
  89. package/dist/esm/commands/index.js +15 -0
  90. package/dist/esm/commands/index.js.map +1 -0
  91. package/dist/esm/commands/manifest/implementation.js +33 -0
  92. package/dist/esm/commands/manifest/implementation.js.map +1 -0
  93. package/dist/esm/commands/manifest/index.js +22 -0
  94. package/dist/esm/commands/manifest/index.js.map +1 -0
  95. package/dist/esm/commands/manifest/manifest.js +52 -0
  96. package/dist/esm/commands/manifest/manifest.js.map +1 -0
  97. package/dist/esm/{cmds → commands}/serve/index.js +4 -2
  98. package/dist/esm/commands/serve/index.js.map +1 -0
  99. package/dist/esm/commands/serve/serve.js +17 -0
  100. package/dist/esm/commands/serve/serve.js.map +1 -0
  101. package/dist/esm/commands/watch/implementation.js +34 -0
  102. package/dist/esm/commands/watch/implementation.js.map +1 -0
  103. package/dist/esm/{cmds → commands}/watch/index.js +6 -4
  104. package/dist/esm/commands/watch/index.js.map +1 -0
  105. package/dist/esm/commands/watch/watch.js +50 -0
  106. package/dist/esm/commands/watch/watch.js.map +1 -0
  107. package/dist/esm/config.js +294 -0
  108. package/dist/esm/config.js.map +1 -0
  109. package/dist/esm/errors.js +30 -0
  110. package/dist/esm/errors.js.map +1 -0
  111. package/dist/esm/index.js +3 -0
  112. package/dist/esm/index.js.map +1 -1
  113. package/dist/esm/main.js +6 -7
  114. package/dist/esm/main.js.map +1 -1
  115. package/dist/esm/utils/cli.js +43 -0
  116. package/dist/esm/utils/cli.js.map +1 -0
  117. package/dist/esm/utils/errors.js +43 -0
  118. package/dist/esm/utils/errors.js.map +1 -0
  119. package/dist/esm/utils/index.js +6 -2
  120. package/dist/esm/utils/index.js.map +1 -1
  121. package/dist/esm/utils/legacy.js +47 -0
  122. package/dist/esm/utils/legacy.js.map +1 -0
  123. package/dist/esm/utils/logging.js +40 -0
  124. package/dist/esm/utils/logging.js.map +1 -0
  125. package/dist/esm/utils/path.js +13 -0
  126. package/dist/esm/utils/path.js.map +1 -0
  127. package/dist/esm/utils/steps.js +43 -0
  128. package/dist/esm/utils/steps.js.map +1 -0
  129. package/dist/esm/webpack/compiler.js +89 -0
  130. package/dist/esm/webpack/compiler.js.map +1 -0
  131. package/dist/esm/webpack/config.js +236 -0
  132. package/dist/esm/webpack/config.js.map +1 -0
  133. package/dist/esm/webpack/index.js +5 -0
  134. package/dist/esm/webpack/index.js.map +1 -0
  135. package/dist/esm/webpack/loaders/browserify.js +82 -0
  136. package/dist/esm/webpack/loaders/browserify.js.map +1 -0
  137. package/dist/esm/webpack/loaders/wasm.js +26 -0
  138. package/dist/esm/webpack/loaders/wasm.js.map +1 -0
  139. package/dist/esm/webpack/plugins.js +343 -0
  140. package/dist/esm/webpack/plugins.js.map +1 -0
  141. package/dist/esm/webpack/utils.js +160 -0
  142. package/dist/esm/webpack/utils.js.map +1 -0
  143. package/dist/types/__fixtures__/configs/cjs.d.ts +1 -0
  144. package/dist/types/__fixtures__/configs/esm.d.ts +3 -0
  145. package/dist/types/__fixtures__/configs/invalid.d.ts +3 -0
  146. package/dist/types/__fixtures__/configs/javascript/snap.config.d.ts +0 -0
  147. package/dist/types/__fixtures__/configs/typescript/snap.config.d.ts +3 -0
  148. package/dist/types/builders.d.ts +2 -21
  149. package/dist/types/cli.d.ts +1 -1
  150. package/dist/types/commands/build/build.d.ts +10 -0
  151. package/dist/types/commands/build/implementation.d.ts +10 -0
  152. package/dist/types/{cmds/eval → commands/build}/index.d.ts +1 -0
  153. package/dist/types/commands/eval/__test__/browserify/bad/snap.config.d.ts +3 -0
  154. package/dist/types/commands/eval/__test__/browserify/good/snap.config.d.ts +3 -0
  155. package/dist/types/commands/eval/__test__/webpack/bad/snap.config.d.ts +3 -0
  156. package/dist/types/commands/eval/__test__/webpack/good/snap.config.d.ts +3 -0
  157. package/dist/types/commands/eval/__test__/webpack/snap.config.d.ts +3 -0
  158. package/dist/types/commands/eval/eval.d.ts +14 -0
  159. package/dist/types/commands/eval/implementation.d.ts +9 -0
  160. package/dist/types/{cmds/serve → commands/eval}/index.d.ts +1 -0
  161. package/dist/types/commands/manifest/implementation.d.ts +12 -0
  162. package/dist/types/{cmds → commands}/manifest/index.d.ts +1 -0
  163. package/dist/types/commands/manifest/manifest.d.ts +14 -0
  164. package/dist/types/commands/serve/serve.d.ts +16 -0
  165. package/dist/types/commands/watch/implementation.d.ts +14 -0
  166. package/dist/types/commands/watch/index.d.ts +10 -0
  167. package/dist/types/commands/watch/watch.d.ts +19 -0
  168. package/dist/types/config.d.ts +626 -0
  169. package/dist/types/errors.d.ts +25 -0
  170. package/dist/types/index.d.ts +4 -0
  171. package/dist/types/utils/cli.d.ts +17 -0
  172. package/dist/types/utils/errors.d.ts +23 -0
  173. package/dist/types/utils/index.d.ts +6 -2
  174. package/dist/types/utils/legacy.d.ts +27 -0
  175. package/dist/types/utils/logging.d.ts +22 -0
  176. package/dist/types/utils/path.d.ts +9 -0
  177. package/dist/types/utils/steps.d.ts +17 -0
  178. package/dist/types/webpack/compiler.d.ts +29 -0
  179. package/dist/types/webpack/config.d.ts +37 -0
  180. package/dist/types/webpack/index.d.ts +3 -0
  181. package/dist/types/webpack/loaders/browserify.d.ts +16 -0
  182. package/dist/types/webpack/loaders/wasm.d.ts +20 -0
  183. package/dist/types/webpack/plugins.d.ts +147 -0
  184. package/dist/types/webpack/utils.d.ts +156 -0
  185. package/package.json +15 -7
  186. package/dist/cjs/cmds/build/buildHandler.js +0 -36
  187. package/dist/cjs/cmds/build/buildHandler.js.map +0 -1
  188. package/dist/cjs/cmds/build/bundle.js +0 -83
  189. package/dist/cjs/cmds/build/bundle.js.map +0 -1
  190. package/dist/cjs/cmds/build/index.js.map +0 -1
  191. package/dist/cjs/cmds/build/utils.js +0 -79
  192. package/dist/cjs/cmds/build/utils.js.map +0 -1
  193. package/dist/cjs/cmds/eval/evalHandler.js +0 -24
  194. package/dist/cjs/cmds/eval/evalHandler.js.map +0 -1
  195. package/dist/cjs/cmds/eval/index.js +0 -31
  196. package/dist/cjs/cmds/eval/index.js.map +0 -1
  197. package/dist/cjs/cmds/index.js.map +0 -1
  198. package/dist/cjs/cmds/manifest/index.js +0 -44
  199. package/dist/cjs/cmds/manifest/index.js.map +0 -1
  200. package/dist/cjs/cmds/manifest/manifestHandler.js +0 -47
  201. package/dist/cjs/cmds/manifest/manifestHandler.js.map +0 -1
  202. package/dist/cjs/cmds/serve/index.js.map +0 -1
  203. package/dist/cjs/cmds/serve/serveHandler.js +0 -62
  204. package/dist/cjs/cmds/serve/serveHandler.js.map +0 -1
  205. package/dist/cjs/cmds/serve/serveUtils.js +0 -37
  206. package/dist/cjs/cmds/serve/serveUtils.js.map +0 -1
  207. package/dist/cjs/cmds/watch/index.js.map +0 -1
  208. package/dist/cjs/cmds/watch/watchHandler.js +0 -91
  209. package/dist/cjs/cmds/watch/watchHandler.js.map +0 -1
  210. package/dist/cjs/utils/misc.js +0 -142
  211. package/dist/cjs/utils/misc.js.map +0 -1
  212. package/dist/cjs/utils/snap-config.js +0 -104
  213. package/dist/cjs/utils/snap-config.js.map +0 -1
  214. package/dist/esm/cmds/build/buildHandler.js +0 -36
  215. package/dist/esm/cmds/build/buildHandler.js.map +0 -1
  216. package/dist/esm/cmds/build/bundle.js +0 -81
  217. package/dist/esm/cmds/build/bundle.js.map +0 -1
  218. package/dist/esm/cmds/build/index.js.map +0 -1
  219. package/dist/esm/cmds/build/utils.js +0 -88
  220. package/dist/esm/cmds/build/utils.js.map +0 -1
  221. package/dist/esm/cmds/eval/evalHandler.js +0 -20
  222. package/dist/esm/cmds/eval/evalHandler.js.map +0 -1
  223. package/dist/esm/cmds/eval/index.js +0 -16
  224. package/dist/esm/cmds/eval/index.js.map +0 -1
  225. package/dist/esm/cmds/index.js +0 -15
  226. package/dist/esm/cmds/index.js.map +0 -1
  227. package/dist/esm/cmds/manifest/index.js +0 -29
  228. package/dist/esm/cmds/manifest/index.js.map +0 -1
  229. package/dist/esm/cmds/manifest/manifestHandler.js +0 -44
  230. package/dist/esm/cmds/manifest/manifestHandler.js.map +0 -1
  231. package/dist/esm/cmds/serve/index.js.map +0 -1
  232. package/dist/esm/cmds/serve/serveHandler.js +0 -54
  233. package/dist/esm/cmds/serve/serveHandler.js.map +0 -1
  234. package/dist/esm/cmds/serve/serveUtils.js +0 -30
  235. package/dist/esm/cmds/serve/serveUtils.js.map +0 -1
  236. package/dist/esm/cmds/watch/index.js.map +0 -1
  237. package/dist/esm/cmds/watch/watchHandler.js +0 -87
  238. package/dist/esm/cmds/watch/watchHandler.js.map +0 -1
  239. package/dist/esm/utils/misc.js +0 -139
  240. package/dist/esm/utils/misc.js.map +0 -1
  241. package/dist/esm/utils/snap-config.js +0 -107
  242. package/dist/esm/utils/snap-config.js.map +0 -1
  243. package/dist/types/cmds/build/buildHandler.d.ts +0 -13
  244. package/dist/types/cmds/build/bundle.d.ts +0 -15
  245. package/dist/types/cmds/build/utils.d.ts +0 -56
  246. package/dist/types/cmds/eval/evalHandler.d.ts +0 -9
  247. package/dist/types/cmds/manifest/manifestHandler.d.ts +0 -10
  248. package/dist/types/cmds/serve/serveHandler.d.ts +0 -10
  249. package/dist/types/cmds/serve/serveUtils.d.ts +0 -22
  250. package/dist/types/cmds/watch/index.d.ts +0 -9
  251. package/dist/types/cmds/watch/watchHandler.d.ts +0 -14
  252. package/dist/types/utils/misc.d.ts +0 -53
  253. package/dist/types/utils/snap-config.d.ts +0 -48
  254. /package/dist/cjs/{cmds → commands}/index.js +0 -0
  255. /package/dist/types/{cmds → commands}/index.d.ts +0 -0
  256. /package/dist/types/{cmds/build → commands/serve}/index.d.ts +0 -0
@@ -0,0 +1,343 @@
1
+ function _check_private_redeclaration(obj, privateCollection) {
2
+ if (privateCollection.has(obj)) {
3
+ throw new TypeError("Cannot initialize the same private elements twice on an object");
4
+ }
5
+ }
6
+ function _class_apply_descriptor_get(receiver, descriptor) {
7
+ if (descriptor.get) {
8
+ return descriptor.get.call(receiver);
9
+ }
10
+ return descriptor.value;
11
+ }
12
+ function _class_apply_descriptor_set(receiver, descriptor, value) {
13
+ if (descriptor.set) {
14
+ descriptor.set.call(receiver, value);
15
+ } else {
16
+ if (!descriptor.writable) {
17
+ throw new TypeError("attempted to set read only private field");
18
+ }
19
+ descriptor.value = value;
20
+ }
21
+ }
22
+ function _class_extract_field_descriptor(receiver, privateMap, action) {
23
+ if (!privateMap.has(receiver)) {
24
+ throw new TypeError("attempted to " + action + " private field on non-instance");
25
+ }
26
+ return privateMap.get(receiver);
27
+ }
28
+ function _class_private_field_get(receiver, privateMap) {
29
+ var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
30
+ return _class_apply_descriptor_get(receiver, descriptor);
31
+ }
32
+ function _class_private_field_init(obj, privateMap, value) {
33
+ _check_private_redeclaration(obj, privateMap);
34
+ privateMap.set(obj, value);
35
+ }
36
+ function _class_private_field_set(receiver, privateMap, value) {
37
+ var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
38
+ _class_apply_descriptor_set(receiver, descriptor, value);
39
+ return value;
40
+ }
41
+ function _class_private_method_get(receiver, privateSet, fn) {
42
+ if (!privateSet.has(receiver)) {
43
+ throw new TypeError("attempted to get private field on non-instance");
44
+ }
45
+ return fn;
46
+ }
47
+ function _class_private_method_init(obj, privateSet) {
48
+ _check_private_redeclaration(obj, privateSet);
49
+ privateSet.add(obj);
50
+ }
51
+ function _define_property(obj, key, value) {
52
+ if (key in obj) {
53
+ Object.defineProperty(obj, key, {
54
+ value: value,
55
+ enumerable: true,
56
+ configurable: true,
57
+ writable: true
58
+ });
59
+ } else {
60
+ obj[key] = value;
61
+ }
62
+ return obj;
63
+ }
64
+ import { indent } from '@metamask/snaps-utils';
65
+ import { assert, hasProperty, isObject } from '@metamask/utils';
66
+ import { dim, red, yellow } from 'chalk';
67
+ import { isBuiltin } from 'module';
68
+ import { evaluate } from '../commands/eval';
69
+ import { error, getErrorMessage, info, warn } from '../utils';
70
+ import { pluralize } from './utils';
71
+ var _spinner = /*#__PURE__*/ new WeakMap(), /**
72
+ * Get the error message for the given stats error.
73
+ *
74
+ * @param statsError - The stats error.
75
+ * @returns The error message.
76
+ */ _getStatsErrorMessage = /*#__PURE__*/ new WeakSet();
77
+ /**
78
+ * A plugin that logs the stats after compilation. This is useful for logging
79
+ * the number of files compiled, and the time taken to compile them.
80
+ */ export class SnapsStatsPlugin {
81
+ /**
82
+ * Apply the plugin to the Webpack compiler.
83
+ *
84
+ * @param compiler - The Webpack compiler.
85
+ */ apply(compiler) {
86
+ compiler.hooks.afterDone.tap(this.constructor.name, (stats)=>{
87
+ if (!stats) {
88
+ return;
89
+ }
90
+ const { modules, time, errors } = stats.toJson();
91
+ assert(modules, 'Modules must be defined in stats.');
92
+ assert(time, 'Time must be defined in stats.');
93
+ if (errors?.length) {
94
+ const formattedErrors = errors.map(_class_private_method_get(this, _getStatsErrorMessage, getStatsErrorMessage).bind(this)).join('\n\n');
95
+ error(`Compiled ${modules.length} ${pluralize(modules.length, 'file')} in ${time}ms with ${errors.length} ${pluralize(errors.length, 'error')}.\n\n${formattedErrors}\n`, _class_private_field_get(this, _spinner));
96
+ _class_private_field_get(this, _spinner)?.stop();
97
+ process.exitCode = 1;
98
+ return;
99
+ }
100
+ info(`Compiled ${modules.length} ${pluralize(modules.length, 'file')} in ${time}ms.`, _class_private_field_get(this, _spinner));
101
+ if (compiler.watchMode) {
102
+ // The spinner may be restarted by the watch plugin, outside of the
103
+ // `executeSteps` flow, so we stop it here just in case.
104
+ _class_private_field_get(this, _spinner)?.succeed('Done!');
105
+ }
106
+ });
107
+ }
108
+ constructor(options = {
109
+ verbose: false
110
+ }, spinner){
111
+ _class_private_method_init(this, _getStatsErrorMessage);
112
+ /**
113
+ * The options for the plugin.
114
+ */ _define_property(this, "options", void 0);
115
+ /**
116
+ * The spinner to use for logging.
117
+ */ _class_private_field_init(this, _spinner, {
118
+ writable: true,
119
+ value: void 0
120
+ });
121
+ this.options = options;
122
+ _class_private_field_set(this, _spinner, spinner);
123
+ }
124
+ }
125
+ function getStatsErrorMessage(statsError) {
126
+ const baseMessage = this.options.verbose ? getErrorMessage(statsError) : statsError.message;
127
+ const [first, ...rest] = baseMessage.split('\n');
128
+ return [
129
+ indent(red(`• ${first}`), 2),
130
+ ...rest.map((message)=>indent(red(message), 4)),
131
+ statsError.details && indent(dim(statsError.details), 4)
132
+ ].filter(Boolean).join('\n');
133
+ }
134
+ var _spinner1 = /*#__PURE__*/ new WeakMap(), _safeEvaluate = /*#__PURE__*/ new WeakSet();
135
+ /**
136
+ * A plugin that adds extra files to watch. This is useful for watching files
137
+ * that are not imported by the entry point, such as the `snap.manifest.json`
138
+ * file.
139
+ */ export class SnapsWatchPlugin {
140
+ /**
141
+ * Apply the plugin to the Webpack compiler.
142
+ *
143
+ * @param compiler - The Webpack compiler.
144
+ */ apply(compiler) {
145
+ compiler.hooks.invalid.tap(this.constructor.name, (file)=>{
146
+ _class_private_field_get(this, _spinner1)?.start();
147
+ info(`Changes detected in ${yellow(file)}, recompiling.`, _class_private_field_get(this, _spinner1));
148
+ });
149
+ compiler.hooks.afterEmit.tapPromise(this.constructor.name, async ({ fileDependencies })=>{
150
+ this.options.files?.forEach(fileDependencies.add.bind(fileDependencies));
151
+ if (this.options.bundle && this.options.evaluate) {
152
+ await _class_private_method_get(this, _safeEvaluate, safeEvaluate).call(this, this.options.bundle);
153
+ }
154
+ });
155
+ }
156
+ constructor(options, spinner){
157
+ /**
158
+ * Safely evaluate the bundle at the given path. If an error occurs, it will
159
+ * be logged to the console, rather than throwing an error.
160
+ *
161
+ * This function should never throw an error.
162
+ *
163
+ * @param bundlePath - The path to the bundle.
164
+ */ _class_private_method_init(this, _safeEvaluate);
165
+ /**
166
+ * The options for the plugin.
167
+ */ _define_property(this, "options", void 0);
168
+ /**
169
+ * The spinner to use for logging.
170
+ */ _class_private_field_init(this, _spinner1, {
171
+ writable: true,
172
+ value: void 0
173
+ });
174
+ this.options = options;
175
+ _class_private_field_set(this, _spinner1, spinner);
176
+ }
177
+ }
178
+ async function safeEvaluate(bundlePath) {
179
+ try {
180
+ await evaluate(bundlePath);
181
+ info(`Snap bundle evaluated successfully.`, _class_private_field_get(this, _spinner1));
182
+ } catch (evaluateError) {
183
+ error(evaluateError.message, _class_private_field_get(this, _spinner1));
184
+ }
185
+ }
186
+ var _source = /*#__PURE__*/ new WeakMap(), _spinner2 = /*#__PURE__*/ new WeakMap();
187
+ /**
188
+ * A plugin that logs a message when a built-in module is not resolved. The
189
+ * MetaMask Snaps CLI does not support built-in modules by default, and this
190
+ * plugin is used to warn the user when they try to import a built-in module,
191
+ * when no fallback is configured.
192
+ */ export class SnapsBuiltInResolver {
193
+ /**
194
+ * Apply the plugin to the Webpack resolver.
195
+ *
196
+ * @param resolver - The Webpack resolver.
197
+ */ apply(resolver) {
198
+ resolver.getHook(_class_private_field_get(this, _source)).tapAsync(this.constructor.name, ({ module: isModule, request }, _, callback)=>{
199
+ if (!isModule || !request) {
200
+ return callback();
201
+ }
202
+ const baseRequest = request.split('/')[0];
203
+ if (isBuiltin(baseRequest) && !this.options.ignore?.includes(baseRequest)) {
204
+ const fallback = resolver.options.fallback.find(({ name })=>name === baseRequest);
205
+ if (fallback && !fallback.alias) {
206
+ this.unresolvedModules.add(baseRequest);
207
+ }
208
+ }
209
+ return callback();
210
+ });
211
+ }
212
+ constructor(options = {
213
+ ignore: []
214
+ }, spinner){
215
+ /**
216
+ * The built-in modules that have been imported, but not resolved.
217
+ */ _define_property(this, "unresolvedModules", new Set());
218
+ /**
219
+ * The name of the resolver hook to tap into.
220
+ */ _class_private_field_init(this, _source, {
221
+ writable: true,
222
+ value: 'described-resolve'
223
+ });
224
+ /**
225
+ * The options for the plugin.
226
+ */ _define_property(this, "options", void 0);
227
+ /**
228
+ * The spinner to use for logging.
229
+ */ _class_private_field_init(this, _spinner2, {
230
+ writable: true,
231
+ value: void 0
232
+ });
233
+ this.options = options;
234
+ _class_private_field_set(this, _spinner2, spinner);
235
+ }
236
+ }
237
+ var _spinner3 = /*#__PURE__*/ new WeakMap(), /**
238
+ * Check if a built-in module is used, but not provided by Webpack's
239
+ * `fallback` configuration.
240
+ *
241
+ * @param compiler - The Webpack compiler.
242
+ */ _checkBuiltIns = /*#__PURE__*/ new WeakSet(), /**
243
+ * Check if the given instance is a `ProvidePlugin`. This is not guaranteed to
244
+ * be accurate, but it's good enough for our purposes. If we were to use
245
+ * `instanceof` instead, it might not work if multiple versions of Webpack are
246
+ * installed.
247
+ *
248
+ * @param instance - The instance to check.
249
+ * @returns Whether the instance is a `ProvidePlugin`, i.e., whether it's an
250
+ * object with the name `ProvidePlugin` and a `definitions` property.
251
+ */ _isProvidePlugin = /*#__PURE__*/ new WeakSet(), /**
252
+ * Check if the `Buffer` global is used, but not provided by Webpack's
253
+ * `DefinePlugin`.
254
+ *
255
+ * @param compiler - The Webpack compiler.
256
+ */ _checkBuffer = /*#__PURE__*/ new WeakSet();
257
+ /**
258
+ * A plugin that logs a message when:
259
+ *
260
+ * - A built-in module is not resolved. The MetaMask Snaps CLI does not support
261
+ * built-in modules by default, and this plugin is used to warn the user when
262
+ * they try to import a built-in module, when no fallback is configured.
263
+ * - A snap uses the `Buffer` global. The MetaMask Snaps CLI does not support
264
+ * the `Buffer` global by default, and this plugin is used to warn the user when
265
+ * they try to use the `Buffer` global.
266
+ *
267
+ * We use both a resolver and a plugin, because the resolver is used to detect
268
+ * when a built-in module is imported, and the plugin is used to log a single
269
+ * message when the compilation is complete. We can't do everything in a single
270
+ * plugin, because the resolver doesn't have access to the compilation, and the
271
+ * plugin doesn't have access to the resolver.
272
+ */ export class SnapsBundleWarningsPlugin {
273
+ /**
274
+ * Apply the plugin to the Webpack compiler.
275
+ *
276
+ * @param compiler - The Webpack compiler.
277
+ */ apply(compiler) {
278
+ if (this.options.builtIns) {
279
+ _class_private_method_get(this, _checkBuiltIns, checkBuiltIns).call(this, compiler);
280
+ }
281
+ if (this.options.buffer) {
282
+ _class_private_method_get(this, _checkBuffer, checkBuffer).call(this, compiler);
283
+ }
284
+ }
285
+ constructor(options = {
286
+ buffer: true,
287
+ builtIns: true
288
+ }, spinner){
289
+ _class_private_method_init(this, _checkBuiltIns);
290
+ _class_private_method_init(this, _isProvidePlugin);
291
+ _class_private_method_init(this, _checkBuffer);
292
+ /**
293
+ * The spinner to use for logging.
294
+ */ _class_private_field_init(this, _spinner3, {
295
+ writable: true,
296
+ value: void 0
297
+ });
298
+ /**
299
+ * The options for the plugin.
300
+ */ _define_property(this, "options", void 0);
301
+ this.options = options;
302
+ _class_private_field_set(this, _spinner3, spinner);
303
+ }
304
+ }
305
+ function checkBuiltIns(compiler) {
306
+ compiler.hooks.afterCompile.tap(this.constructor.name, ()=>{
307
+ if (!this.options.builtInResolver) {
308
+ return;
309
+ }
310
+ const { unresolvedModules } = this.options.builtInResolver;
311
+ if (unresolvedModules.size === 0) {
312
+ return;
313
+ }
314
+ const formattedModules = new Array(...unresolvedModules).map((name)=>indent(`• ${name}`, 2)).join('\n');
315
+ warn(`The snap attempted to use one or more Node.js builtins, but no browser fallback has been provided.\n` + `The MetaMask Snaps CLI does not support Node.js builtins by default. If you want to use this module, you must provide a fallback: https://webpack.js.org/configuration/resolve/#resolvefallback.\n` + `To disable this warning, set ${yellow('`stats.builtIns`')} to ${yellow('`false`')} in your snap config file, or add the module to the ${yellow('`stats.builtIns.ignore`')} array.\n\n${formattedModules}\n`, _class_private_field_get(this, _spinner3));
316
+ });
317
+ }
318
+ function isProvidePlugin(instance) {
319
+ return isObject(instance) && instance.constructor.name === 'ProvidePlugin' && hasProperty(instance, 'definitions');
320
+ }
321
+ function checkBuffer(compiler) {
322
+ const plugin = compiler.options.plugins?.find((instance)=>_class_private_method_get(this, _isProvidePlugin, isProvidePlugin).call(this, instance));
323
+ // If the `ProvidePlugin` is configured to provide `Buffer`, then we don't
324
+ // need to warn the user.
325
+ if (plugin) {
326
+ const { definitions } = plugin;
327
+ if (definitions.Buffer) {
328
+ return;
329
+ }
330
+ }
331
+ compiler.hooks.compilation.tap(this.constructor.name, (compilation)=>{
332
+ compilation.hooks.afterProcessAssets.tap(this.constructor.name, (assets)=>{
333
+ // Check if assets use `Buffer`.
334
+ const bufferAssets = Object.entries(assets).filter(([name])=>name.endsWith('.js')).filter(([, asset])=>asset.source().includes('Buffer'));
335
+ if (bufferAssets.length === 0) {
336
+ return;
337
+ }
338
+ warn(`The snap attempted to use the Node.js Buffer global, which is not supported by the MetaMask Snaps CLI.\n` + `To use the Buffer global, you must use the ${yellow('`ProvidePlugin`')} to inject it: https://webpack.js.org/plugins/provide-plugin/.\n` + `To disable this warning, set ${yellow('`stats.buffer`')} to ${yellow('`false`')} in your snap config file.`, _class_private_field_get(this, _spinner3));
339
+ });
340
+ });
341
+ }
342
+
343
+ //# sourceMappingURL=plugins.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/webpack/plugins.ts"],"sourcesContent":["import { indent } from '@metamask/snaps-utils';\nimport { assert, hasProperty, isObject } from '@metamask/utils';\nimport { dim, red, yellow } from 'chalk';\nimport { isBuiltin } from 'module';\nimport type { Ora } from 'ora';\nimport type {\n Compiler,\n ProvidePlugin,\n ResolvePluginInstance,\n Resolver,\n StatsError,\n WebpackPluginInstance,\n} from 'webpack';\n\nimport { evaluate } from '../commands/eval';\nimport { error, getErrorMessage, info, warn } from '../utils';\nimport { pluralize } from './utils';\n\nexport type SnapsStatsPluginOptions = {\n /**\n * Whether to log the verbose stats.\n */\n verbose?: boolean;\n};\n\n/**\n * A plugin that logs the stats after compilation. This is useful for logging\n * the number of files compiled, and the time taken to compile them.\n */\nexport class SnapsStatsPlugin implements WebpackPluginInstance {\n /**\n * The options for the plugin.\n */\n readonly options: SnapsStatsPluginOptions;\n\n /**\n * The spinner to use for logging.\n */\n readonly #spinner?: Ora;\n\n constructor(\n options: SnapsStatsPluginOptions = {\n verbose: false,\n },\n spinner?: Ora,\n ) {\n this.options = options;\n this.#spinner = spinner;\n }\n\n /**\n * Apply the plugin to the Webpack compiler.\n *\n * @param compiler - The Webpack compiler.\n */\n apply(compiler: Compiler) {\n compiler.hooks.afterDone.tap(this.constructor.name, (stats) => {\n if (!stats) {\n return;\n }\n\n const { modules, time, errors } = stats.toJson();\n\n assert(modules, 'Modules must be defined in stats.');\n assert(time, 'Time must be defined in stats.');\n\n if (errors?.length) {\n const formattedErrors = errors\n .map(this.#getStatsErrorMessage.bind(this))\n .join('\\n\\n');\n\n error(\n `Compiled ${modules.length} ${pluralize(\n modules.length,\n 'file',\n )} in ${time}ms with ${errors.length} ${pluralize(\n errors.length,\n 'error',\n )}.\\n\\n${formattedErrors}\\n`,\n this.#spinner,\n );\n\n this.#spinner?.stop();\n\n process.exitCode = 1;\n return;\n }\n\n info(\n `Compiled ${modules.length} ${pluralize(\n modules.length,\n 'file',\n )} in ${time}ms.`,\n this.#spinner,\n );\n\n if (compiler.watchMode) {\n // The spinner may be restarted by the watch plugin, outside of the\n // `executeSteps` flow, so we stop it here just in case.\n this.#spinner?.succeed('Done!');\n }\n });\n }\n\n /**\n * Get the error message for the given stats error.\n *\n * @param statsError - The stats error.\n * @returns The error message.\n */\n #getStatsErrorMessage(statsError: StatsError) {\n const baseMessage = this.options.verbose\n ? getErrorMessage(statsError)\n : statsError.message;\n\n const [first, ...rest] = baseMessage.split('\\n');\n\n return [\n indent(red(`• ${first}`), 2),\n ...rest.map((message) => indent(red(message), 4)),\n statsError.details && indent(dim(statsError.details), 4),\n ]\n .filter(Boolean)\n .join('\\n');\n }\n}\n\n/**\n * The options for the {@link SnapsWatchPlugin}.\n */\nexport type SnapsWatchPluginOptions = {\n /**\n * The bundle path. This is the file that will be evaluated, if the `evaluate`\n * option is set.\n */\n bundle?: string;\n\n /**\n * Whether to evaluate the bundle. This only applies if the `bundle` option is\n * set.\n */\n evaluate?: boolean;\n\n /**\n * The extra files to watch.\n */\n files?: string[];\n};\n\n/**\n * A plugin that adds extra files to watch. This is useful for watching files\n * that are not imported by the entry point, such as the `snap.manifest.json`\n * file.\n */\nexport class SnapsWatchPlugin implements WebpackPluginInstance {\n /**\n * The options for the plugin.\n */\n readonly options: SnapsWatchPluginOptions;\n\n /**\n * The spinner to use for logging.\n */\n readonly #spinner?: Ora;\n\n constructor(options: SnapsWatchPluginOptions, spinner?: Ora) {\n this.options = options;\n this.#spinner = spinner;\n }\n\n /**\n * Apply the plugin to the Webpack compiler.\n *\n * @param compiler - The Webpack compiler.\n */\n apply(compiler: Compiler) {\n compiler.hooks.invalid.tap(this.constructor.name, (file) => {\n this.#spinner?.start();\n info(`Changes detected in ${yellow(file)}, recompiling.`, this.#spinner);\n });\n\n compiler.hooks.afterEmit.tapPromise(\n this.constructor.name,\n async ({ fileDependencies }) => {\n this.options.files?.forEach(\n fileDependencies.add.bind(fileDependencies),\n );\n\n if (this.options.bundle && this.options.evaluate) {\n await this.#safeEvaluate(this.options.bundle);\n }\n },\n );\n }\n\n /**\n * Safely evaluate the bundle at the given path. If an error occurs, it will\n * be logged to the console, rather than throwing an error.\n *\n * This function should never throw an error.\n *\n * @param bundlePath - The path to the bundle.\n */\n async #safeEvaluate(bundlePath: string) {\n try {\n await evaluate(bundlePath);\n info(`Snap bundle evaluated successfully.`, this.#spinner);\n } catch (evaluateError) {\n error(evaluateError.message, this.#spinner);\n }\n }\n}\n\n/**\n * The options for the {@link SnapsBuiltInResolver}.\n */\nexport type SnapsBuiltInResolverOptions = {\n /**\n * The built-in modules to ignore.\n */\n ignore?: string[];\n};\n\n/**\n * A plugin that logs a message when a built-in module is not resolved. The\n * MetaMask Snaps CLI does not support built-in modules by default, and this\n * plugin is used to warn the user when they try to import a built-in module,\n * when no fallback is configured.\n */\nexport class SnapsBuiltInResolver implements ResolvePluginInstance {\n /**\n * The built-in modules that have been imported, but not resolved.\n */\n readonly unresolvedModules = new Set<string>();\n\n /**\n * The name of the resolver hook to tap into.\n */\n readonly #source = 'described-resolve';\n\n /**\n * The options for the plugin.\n */\n readonly options: SnapsBuiltInResolverOptions;\n\n /**\n * The spinner to use for logging.\n */\n readonly #spinner?: Ora;\n\n constructor(\n options: SnapsBuiltInResolverOptions = {\n ignore: [],\n },\n spinner?: Ora,\n ) {\n this.options = options;\n this.#spinner = spinner;\n }\n\n /**\n * Apply the plugin to the Webpack resolver.\n *\n * @param resolver - The Webpack resolver.\n */\n apply(resolver: Resolver) {\n resolver\n .getHook(this.#source)\n .tapAsync(\n this.constructor.name,\n ({ module: isModule, request }, _, callback) => {\n if (!isModule || !request) {\n return callback();\n }\n\n const baseRequest = request.split('/')[0];\n if (\n isBuiltin(baseRequest) &&\n !this.options.ignore?.includes(baseRequest)\n ) {\n const fallback = resolver.options.fallback.find(\n ({ name }) => name === baseRequest,\n );\n\n if (fallback && !fallback.alias) {\n this.unresolvedModules.add(baseRequest);\n }\n }\n\n return callback();\n },\n );\n }\n}\n\n/**\n * The options for the {@link SnapsBundleWarningsPlugin}.\n */\nexport type SnapsBundleWarningsPluginOptions = {\n /**\n * The {@link SnapsBuiltInResolver} instance to use for detecting built-in\n * modules.\n */\n builtInResolver?: SnapsBuiltInResolver | false;\n\n /**\n * Whether to show warnings if built-in modules are used, but not provided by\n * Webpack's `fallback` configuration.\n */\n builtIns?: boolean;\n\n /**\n * Whether to show warnings if the `Buffer` global is used, but not provided\n * by Webpack's `DefinePlugin`.\n */\n buffer?: boolean;\n};\n\n/**\n * A plugin that logs a message when:\n *\n * - A built-in module is not resolved. The MetaMask Snaps CLI does not support\n * built-in modules by default, and this plugin is used to warn the user when\n * they try to import a built-in module, when no fallback is configured.\n * - A snap uses the `Buffer` global. The MetaMask Snaps CLI does not support\n * the `Buffer` global by default, and this plugin is used to warn the user when\n * they try to use the `Buffer` global.\n *\n * We use both a resolver and a plugin, because the resolver is used to detect\n * when a built-in module is imported, and the plugin is used to log a single\n * message when the compilation is complete. We can't do everything in a single\n * plugin, because the resolver doesn't have access to the compilation, and the\n * plugin doesn't have access to the resolver.\n */\n\nexport class SnapsBundleWarningsPlugin implements WebpackPluginInstance {\n /**\n * The spinner to use for logging.\n */\n readonly #spinner?: Ora;\n\n /**\n * The options for the plugin.\n */\n readonly options: SnapsBundleWarningsPluginOptions;\n\n constructor(\n options: SnapsBundleWarningsPluginOptions = {\n buffer: true,\n builtIns: true,\n },\n spinner?: Ora,\n ) {\n this.options = options;\n this.#spinner = spinner;\n }\n\n /**\n * Apply the plugin to the Webpack compiler.\n *\n * @param compiler - The Webpack compiler.\n */\n apply(compiler: Compiler) {\n if (this.options.builtIns) {\n this.#checkBuiltIns(compiler);\n }\n\n if (this.options.buffer) {\n this.#checkBuffer(compiler);\n }\n }\n\n /**\n * Check if a built-in module is used, but not provided by Webpack's\n * `fallback` configuration.\n *\n * @param compiler - The Webpack compiler.\n */\n #checkBuiltIns(compiler: Compiler) {\n compiler.hooks.afterCompile.tap(this.constructor.name, () => {\n if (!this.options.builtInResolver) {\n return;\n }\n\n const { unresolvedModules } = this.options.builtInResolver;\n if (unresolvedModules.size === 0) {\n return;\n }\n\n const formattedModules = new Array(...unresolvedModules)\n .map((name) => indent(`• ${name}`, 2))\n .join('\\n');\n\n warn(\n `The snap attempted to use one or more Node.js builtins, but no browser fallback has been provided.\\n` +\n `The MetaMask Snaps CLI does not support Node.js builtins by default. If you want to use this module, you must provide a fallback: https://webpack.js.org/configuration/resolve/#resolvefallback.\\n` +\n `To disable this warning, set ${yellow(\n '`stats.builtIns`',\n )} to ${yellow(\n '`false`',\n )} in your snap config file, or add the module to the ${yellow(\n '`stats.builtIns.ignore`',\n )} array.\\n\\n${formattedModules}\\n`,\n this.#spinner,\n );\n });\n }\n\n /**\n * Check if the given instance is a `ProvidePlugin`. This is not guaranteed to\n * be accurate, but it's good enough for our purposes. If we were to use\n * `instanceof` instead, it might not work if multiple versions of Webpack are\n * installed.\n *\n * @param instance - The instance to check.\n * @returns Whether the instance is a `ProvidePlugin`, i.e., whether it's an\n * object with the name `ProvidePlugin` and a `definitions` property.\n */\n #isProvidePlugin(instance: unknown): instance is ProvidePlugin {\n return (\n isObject(instance) &&\n instance.constructor.name === 'ProvidePlugin' &&\n hasProperty(instance, 'definitions')\n );\n }\n\n /**\n * Check if the `Buffer` global is used, but not provided by Webpack's\n * `DefinePlugin`.\n *\n * @param compiler - The Webpack compiler.\n */\n #checkBuffer(compiler: Compiler) {\n const plugin = compiler.options.plugins?.find((instance) =>\n this.#isProvidePlugin(instance),\n ) as ProvidePlugin | undefined;\n\n // If the `ProvidePlugin` is configured to provide `Buffer`, then we don't\n // need to warn the user.\n if (plugin) {\n const { definitions } = plugin;\n if (definitions.Buffer) {\n return;\n }\n }\n\n compiler.hooks.compilation.tap(this.constructor.name, (compilation) => {\n compilation.hooks.afterProcessAssets.tap(\n this.constructor.name,\n (assets) => {\n // Check if assets use `Buffer`.\n const bufferAssets = Object.entries(assets)\n .filter(([name]) => name.endsWith('.js'))\n .filter(([, asset]) => asset.source().includes('Buffer'));\n\n if (bufferAssets.length === 0) {\n return;\n }\n\n warn(\n `The snap attempted to use the Node.js Buffer global, which is not supported by the MetaMask Snaps CLI.\\n` +\n `To use the Buffer global, you must use the ${yellow(\n '`ProvidePlugin`',\n )} to inject it: https://webpack.js.org/plugins/provide-plugin/.\\n` +\n `To disable this warning, set ${yellow(\n '`stats.buffer`',\n )} to ${yellow('`false`')} in your snap config file.`,\n this.#spinner,\n );\n },\n );\n });\n }\n}\n"],"names":["indent","assert","hasProperty","isObject","dim","red","yellow","isBuiltin","evaluate","error","getErrorMessage","info","warn","pluralize","SnapsStatsPlugin","apply","compiler","hooks","afterDone","tap","constructor","name","stats","modules","time","errors","toJson","length","formattedErrors","map","getStatsErrorMessage","bind","join","spinner","stop","process","exitCode","watchMode","succeed","options","verbose","statsError","baseMessage","message","first","rest","split","details","filter","Boolean","SnapsWatchPlugin","invalid","file","start","afterEmit","tapPromise","fileDependencies","files","forEach","add","bundle","safeEvaluate","bundlePath","evaluateError","SnapsBuiltInResolver","resolver","getHook","source","tapAsync","module","isModule","request","_","callback","baseRequest","ignore","includes","fallback","find","alias","unresolvedModules","Set","SnapsBundleWarningsPlugin","builtIns","checkBuiltIns","buffer","checkBuffer","afterCompile","builtInResolver","size","formattedModules","Array","instance","plugin","plugins","isProvidePlugin","definitions","Buffer","compilation","afterProcessAssets","assets","bufferAssets","Object","entries","endsWith","asset"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAASA,MAAM,QAAQ,wBAAwB;AAC/C,SAASC,MAAM,EAAEC,WAAW,EAAEC,QAAQ,QAAQ,kBAAkB;AAChE,SAASC,GAAG,EAAEC,GAAG,EAAEC,MAAM,QAAQ,QAAQ;AACzC,SAASC,SAAS,QAAQ,SAAS;AAWnC,SAASC,QAAQ,QAAQ,mBAAmB;AAC5C,SAASC,KAAK,EAAEC,eAAe,EAAEC,IAAI,EAAEC,IAAI,QAAQ,WAAW;AAC9D,SAASC,SAAS,QAAQ,UAAU;IAsBzB,wCAkET;;;;;GAKC,GACD;AArFF;;;CAGC,GACD,OAAO,MAAMC;IAqBX;;;;GAIC,GACDC,MAAMC,QAAkB,EAAE;QACxBA,SAASC,KAAK,CAACC,SAAS,CAACC,GAAG,CAAC,IAAI,CAACC,WAAW,CAACC,IAAI,EAAE,CAACC;YACnD,IAAI,CAACA,OAAO;gBACV;YACF;YAEA,MAAM,EAAEC,OAAO,EAAEC,IAAI,EAAEC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A,SAAA,gBAAiB2D,QAAiB;IAChC,OACEzF,SAASyF,aACTA,SAASxE,WAAW,CAACC,IAAI,KAAK,mBAC9BnB,YAAY0F,UAAU;AAE1B;AAQA,SAAA,YAAa5E,QAAkB;IAC7B,MAAM6E,SAAS7E,SAASuB,OAAO,CAACuD,OAAO,EAAEhB,KAAK,CAACc,WAC7C,0BAAA,IAAI,EAAEG,kBAAAA,sBAAN,IAAI,EAAkBH;IAGxB,0EAA0E;IAC1E,yBAAyB;IACzB,IAAIC,QAAQ;QACV,MAAM,EAAEG,WAAW,EAAE,GAAGH;QACxB,IAAIG,YAAYC,MAAM,EAAE;YACtB;QACF;IACF;IAEAjF,SAASC,KAAK,CAACiF,WAAW,CAAC/E,GAAG,CAAC,IAAI,CAACC,WAAW,CAACC,IAAI,EAAE,CAAC6E;QACrDA,YAAYjF,KAAK,CAACkF,kBAAkB,CAAChF,GAAG,CACtC,IAAI,CAACC,WAAW,CAACC,IAAI,EACrB,CAAC+E;YACC,gCAAgC;YAChC,MAAMC,eAAeC,OAAOC,OAAO,CAACH,QACjCpD,MAAM,CAAC,CAAC,CAAC3B,KAAK,GAAKA,KAAKmF,QAAQ,CAAC,QACjCxD,MAAM,CAAC,CAAC,GAAGyD,MAAM,GAAKA,MAAMtC,MAAM,GAAGS,QAAQ,CAAC;YAEjD,IAAIyB,aAAa1E,MAAM,KAAK,GAAG;gBAC7B;YACF;YAEAf,KACE,CAAC,wGAAwG,CAAC,GACxG,CAAC,2CAA2C,EAAEN,OAC5C,mBACA,gEAAgE,CAAC,GACnE,CAAC,6BAA6B,EAAEA,OAC9B,kBACA,IAAI,EAAEA,OAAO,WAAW,0BAA0B,CAAC,2BACvD,IAAI,EAAE2B;QAEV;IAEJ;AACF"}
@@ -0,0 +1,160 @@
1
+ import { dim } from 'chalk';
2
+ import { promises as fs } from 'fs';
3
+ import { dirname, resolve } from 'path';
4
+ export const BROWSERSLIST_FILE = resolve(dirname(// eslint-disable-next-line n/no-extraneous-require
5
+ require.resolve('@metamask/snaps-cli/package.json')), '.browserslistrc');
6
+ /**
7
+ * Get the default loader for JavaScript and TypeScript files, based on the
8
+ * config object.
9
+ *
10
+ * - If the `legacy` option is set, we use the custom `browserify` loader. This
11
+ * uses the legacy Browserify config to transpile the code.
12
+ * - Otherwise, we use the `swc-loader`. This is a Webpack loader that uses the
13
+ * `SWC` compiler, which is a much faster alternative to Babel and TypeScript's
14
+ * own compiler.
15
+ *
16
+ * @param config - The processed snap Webpack config.
17
+ * @param config.legacy - The legacy config object, if any.
18
+ * @param config.sourceMap - Whether to generate source maps.
19
+ * @see https://swc.rs/docs/usage/swc-loader
20
+ * @returns The default loader.
21
+ */ export async function getDefaultLoader({ legacy, sourceMap }) {
22
+ if (legacy) {
23
+ return {
24
+ /**
25
+ * If the snap uses the legacy config, we use the custom `browserify`
26
+ * loader. This uses the legacy Browserify config to transpile the code.
27
+ * This is necessary for backwards compatibility with the
28
+ * `bundlerCustomizer` function.
29
+ */ loader: resolve(__dirname, 'loaders', 'browserify'),
30
+ /**
31
+ * The options for the `browserify` loader. These can be overridden in the
32
+ * snap config.
33
+ */ options: legacy
34
+ };
35
+ }
36
+ const targets = await getBrowserslistTargets();
37
+ return {
38
+ /**
39
+ * We use the `swc-loader` to transpile TypeScript and JavaScript files.
40
+ * This is a Webpack loader that uses the `SWC` compiler, which is a much
41
+ * faster alternative to Babel and TypeScript's own compiler.
42
+ */ loader: 'swc-loader',
43
+ /**
44
+ * The options for the `swc-loader`. These can be overridden in the
45
+ * `.swcrc` file.
46
+ *
47
+ * @see https://swc.rs/docs/configuration/swcrc
48
+ */ options: {
49
+ sync: false,
50
+ /**
51
+ * This tells SWC to generate source maps. We set it to the
52
+ * `sourceMap` value from the config object.
53
+ *
54
+ * This must be enabled if source maps are enabled in the config.
55
+ */ sourceMaps: Boolean(getDevTool(sourceMap)),
56
+ jsc: {
57
+ /**
58
+ * MetaMask targets ES2020, so we set the target to ES2020. This
59
+ * ensures that the code is transpiled to ES2020, and that the
60
+ * necessary polyfills are added.
61
+ *
62
+ * @see https://swc.rs/docs/configuration/compilation#jsctarget
63
+ */ target: 'es2020',
64
+ parser: {
65
+ /**
66
+ * This tells the parser to parse TypeScript files. If you
67
+ * don't need to support TypeScript, you can set this to
68
+ * `ecmascript` instead, but there's no harm in leaving it
69
+ * as `typescript`.
70
+ *
71
+ * @see https://swc.rs/docs/configuration/compilation#jscparser
72
+ */ syntax: 'typescript'
73
+ }
74
+ },
75
+ /**
76
+ * The module configuration. This tells SWC how to output the
77
+ * transpiled code.
78
+ *
79
+ * @see https://swc.rs/docs/configuration/modules
80
+ */ module: {
81
+ /**
82
+ * This tells SWC to output CommonJS modules. MetaMask Snaps
83
+ * doesn't support ES modules yet, so this is necessary.
84
+ *
85
+ * @see https://swc.rs/docs/configuration/modules#commonjs
86
+ */ type: 'commonjs'
87
+ },
88
+ env: {
89
+ targets: targets.join(', ')
90
+ }
91
+ }
92
+ };
93
+ }
94
+ /**
95
+ * Get the Webpack devtool configuration based on the given snap config.
96
+ *
97
+ * - If `sourceMap` is `inline`, return `inline-source-map`.
98
+ * - If `sourceMap` is `true`, return `source-map`.
99
+ * - Otherwise, return `false`.
100
+ *
101
+ * @param sourceMap - The `sourceMap` value from the snap config.
102
+ * @returns The Webpack devtool configuration.
103
+ */ export function getDevTool(sourceMap) {
104
+ if (sourceMap === 'inline') {
105
+ return 'inline-source-map';
106
+ }
107
+ if (sourceMap === true) {
108
+ return 'source-map';
109
+ }
110
+ return false;
111
+ }
112
+ /**
113
+ * Get a function that can be used as handler function for Webpack's
114
+ * `ProgressPlugin`.
115
+ *
116
+ * @param spinner - The spinner to update.
117
+ * @param spinnerText - The initial spinner text. This will be prepended to the
118
+ * percentage.
119
+ * @returns A function that can be used as handler function for Webpack's
120
+ * `ProgressPlugin`.
121
+ */ // Note: This is extracted for testing purposes.
122
+ export function getProgressHandler(spinner, spinnerText) {
123
+ return (percentage)=>{
124
+ if (spinner && spinnerText) {
125
+ spinner.text = `${spinnerText} ${dim(`(${Math.round(percentage * 100)}%)`)}`;
126
+ }
127
+ };
128
+ }
129
+ /**
130
+ * Get the targets from the `.browserslistrc` file.
131
+ *
132
+ * @returns The browser targets as an array of strings.
133
+ */ export async function getBrowserslistTargets() {
134
+ const contents = await fs.readFile(BROWSERSLIST_FILE, 'utf8');
135
+ return contents.split('\n').map((line)=>line.trim()).filter((line)=>line && !line.startsWith('#'));
136
+ }
137
+ /**
138
+ * Get a singular or plural string based on the given count. This is useful for
139
+ * generating messages like "1 error" or "2 errors". By default, the plural
140
+ * string is the singular string with an "s" appended to it.
141
+ *
142
+ * This assumes that the text is in English, and likely won't work for some
143
+ * other languages.
144
+ *
145
+ * @param count - The count.
146
+ * @param singular - The singular string.
147
+ * @param plural - The plural string.
148
+ * @returns The singular or plural string.
149
+ * @example
150
+ * ```typescript
151
+ * pluralize(1, 'error'); // => 'error'
152
+ * pluralize(2, 'error'); // => 'errors'
153
+ * pluralize(1, 'error', 'problem'); // => 'error'
154
+ * pluralize(2, 'error', 'problems'); // => 'problems'
155
+ * ```
156
+ */ export function pluralize(count, singular, plural = `${singular}s`) {
157
+ return count === 1 ? singular : plural;
158
+ }
159
+
160
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/webpack/utils.ts"],"sourcesContent":["import { dim } from 'chalk';\nimport { promises as fs } from 'fs';\nimport type { Ora } from 'ora';\nimport { dirname, resolve } from 'path';\nimport type { Configuration } from 'webpack';\n\nimport type { ProcessedWebpackConfig } from '../config';\n\nexport const BROWSERSLIST_FILE = resolve(\n dirname(\n // eslint-disable-next-line n/no-extraneous-require\n require.resolve('@metamask/snaps-cli/package.json'),\n ),\n '.browserslistrc',\n);\n\n/**\n * Get the default loader for JavaScript and TypeScript files, based on the\n * config object.\n *\n * - If the `legacy` option is set, we use the custom `browserify` loader. This\n * uses the legacy Browserify config to transpile the code.\n * - Otherwise, we use the `swc-loader`. This is a Webpack loader that uses the\n * `SWC` compiler, which is a much faster alternative to Babel and TypeScript's\n * own compiler.\n *\n * @param config - The processed snap Webpack config.\n * @param config.legacy - The legacy config object, if any.\n * @param config.sourceMap - Whether to generate source maps.\n * @see https://swc.rs/docs/usage/swc-loader\n * @returns The default loader.\n */\nexport async function getDefaultLoader({\n legacy,\n sourceMap,\n}: ProcessedWebpackConfig) {\n if (legacy) {\n return {\n /**\n * If the snap uses the legacy config, we use the custom `browserify`\n * loader. This uses the legacy Browserify config to transpile the code.\n * This is necessary for backwards compatibility with the\n * `bundlerCustomizer` function.\n */\n loader: resolve(__dirname, 'loaders', 'browserify'),\n\n /**\n * The options for the `browserify` loader. These can be overridden in the\n * snap config.\n */\n options: legacy,\n };\n }\n\n const targets = await getBrowserslistTargets();\n return {\n /**\n * We use the `swc-loader` to transpile TypeScript and JavaScript files.\n * This is a Webpack loader that uses the `SWC` compiler, which is a much\n * faster alternative to Babel and TypeScript's own compiler.\n */\n loader: 'swc-loader',\n\n /**\n * The options for the `swc-loader`. These can be overridden in the\n * `.swcrc` file.\n *\n * @see https://swc.rs/docs/configuration/swcrc\n */\n options: {\n sync: false,\n\n /**\n * This tells SWC to generate source maps. We set it to the\n * `sourceMap` value from the config object.\n *\n * This must be enabled if source maps are enabled in the config.\n */\n sourceMaps: Boolean(getDevTool(sourceMap)),\n\n jsc: {\n /**\n * MetaMask targets ES2020, so we set the target to ES2020. This\n * ensures that the code is transpiled to ES2020, and that the\n * necessary polyfills are added.\n *\n * @see https://swc.rs/docs/configuration/compilation#jsctarget\n */\n target: 'es2020',\n\n parser: {\n /**\n * This tells the parser to parse TypeScript files. If you\n * don't need to support TypeScript, you can set this to\n * `ecmascript` instead, but there's no harm in leaving it\n * as `typescript`.\n *\n * @see https://swc.rs/docs/configuration/compilation#jscparser\n */\n syntax: 'typescript',\n },\n },\n\n /**\n * The module configuration. This tells SWC how to output the\n * transpiled code.\n *\n * @see https://swc.rs/docs/configuration/modules\n */\n module: {\n /**\n * This tells SWC to output CommonJS modules. MetaMask Snaps\n * doesn't support ES modules yet, so this is necessary.\n *\n * @see https://swc.rs/docs/configuration/modules#commonjs\n */\n type: 'commonjs',\n },\n\n env: {\n targets: targets.join(', '),\n },\n },\n };\n}\n\n/**\n * Get the Webpack devtool configuration based on the given snap config.\n *\n * - If `sourceMap` is `inline`, return `inline-source-map`.\n * - If `sourceMap` is `true`, return `source-map`.\n * - Otherwise, return `false`.\n *\n * @param sourceMap - The `sourceMap` value from the snap config.\n * @returns The Webpack devtool configuration.\n */\nexport function getDevTool(\n sourceMap: ProcessedWebpackConfig['sourceMap'],\n): Configuration['devtool'] {\n if (sourceMap === 'inline') {\n return 'inline-source-map';\n }\n\n if (sourceMap === true) {\n return 'source-map';\n }\n\n return false;\n}\n\n/**\n * Get a function that can be used as handler function for Webpack's\n * `ProgressPlugin`.\n *\n * @param spinner - The spinner to update.\n * @param spinnerText - The initial spinner text. This will be prepended to the\n * percentage.\n * @returns A function that can be used as handler function for Webpack's\n * `ProgressPlugin`.\n */\n// Note: This is extracted for testing purposes.\nexport function getProgressHandler(spinner?: Ora, spinnerText?: string) {\n return (percentage: number) => {\n if (spinner && spinnerText) {\n spinner.text = `${spinnerText} ${dim(\n `(${Math.round(percentage * 100)}%)`,\n )}`;\n }\n };\n}\n\n/**\n * Get the targets from the `.browserslistrc` file.\n *\n * @returns The browser targets as an array of strings.\n */\nexport async function getBrowserslistTargets() {\n const contents = await fs.readFile(BROWSERSLIST_FILE, 'utf8');\n return contents\n .split('\\n')\n .map((line) => line.trim())\n .filter((line) => line && !line.startsWith('#'));\n}\n\n/**\n * Get a singular or plural string based on the given count. This is useful for\n * generating messages like \"1 error\" or \"2 errors\". By default, the plural\n * string is the singular string with an \"s\" appended to it.\n *\n * This assumes that the text is in English, and likely won't work for some\n * other languages.\n *\n * @param count - The count.\n * @param singular - The singular string.\n * @param plural - The plural string.\n * @returns The singular or plural string.\n * @example\n * ```typescript\n * pluralize(1, 'error'); // => 'error'\n * pluralize(2, 'error'); // => 'errors'\n * pluralize(1, 'error', 'problem'); // => 'error'\n * pluralize(2, 'error', 'problems'); // => 'problems'\n * ```\n */\nexport function pluralize(\n count: number,\n singular: string,\n plural = `${singular}s`,\n) {\n return count === 1 ? singular : plural;\n}\n"],"names":["dim","promises","fs","dirname","resolve","BROWSERSLIST_FILE","require","getDefaultLoader","legacy","sourceMap","loader","__dirname","options","targets","getBrowserslistTargets","sync","sourceMaps","Boolean","getDevTool","jsc","target","parser","syntax","module","type","env","join","getProgressHandler","spinner","spinnerText","percentage","text","Math","round","contents","readFile","split","map","line","trim","filter","startsWith","pluralize","count","singular","plural"],"mappings":"AAAA,SAASA,GAAG,QAAQ,QAAQ;AAC5B,SAASC,YAAYC,EAAE,QAAQ,KAAK;AAEpC,SAASC,OAAO,EAAEC,OAAO,QAAQ,OAAO;AAKxC,OAAO,MAAMC,oBAAoBD,QAC/BD,QACE,mDAAmD;AACnDG,QAAQF,OAAO,CAAC,sCAElB,mBACA;AAEF;;;;;;;;;;;;;;;CAeC,GACD,OAAO,eAAeG,iBAAiB,EACrCC,MAAM,EACNC,SAAS,EACc;IACvB,IAAID,QAAQ;QACV,OAAO;YACL;;;;;OAKC,GACDE,QAAQN,QAAQO,WAAW,WAAW;YAEtC;;;OAGC,GACDC,SAASJ;QACX;IACF;IAEA,MAAMK,UAAU,MAAMC;IACtB,OAAO;QACL;;;;KAIC,GACDJ,QAAQ;QAER;;;;;KAKC,GACDE,SAAS;YACPG,MAAM;YAEN;;;;;OAKC,GACDC,YAAYC,QAAQC,WAAWT;YAE/BU,KAAK;gBACH;;;;;;SAMC,GACDC,QAAQ;gBAERC,QAAQ;oBACN;;;;;;;WAOC,GACDC,QAAQ;gBACV;YACF;YAEA;;;;;OAKC,GACDC,QAAQ;gBACN;;;;;SAKC,GACDC,MAAM;YACR;YAEAC,KAAK;gBACHZ,SAASA,QAAQa,IAAI,CAAC;YACxB;QACF;IACF;AACF;AAEA;;;;;;;;;CASC,GACD,OAAO,SAASR,WACdT,SAA8C;IAE9C,IAAIA,cAAc,UAAU;QAC1B,OAAO;IACT;IAEA,IAAIA,cAAc,MAAM;QACtB,OAAO;IACT;IAEA,OAAO;AACT;AAEA;;;;;;;;;CASC,GACD,gDAAgD;AAChD,OAAO,SAASkB,mBAAmBC,OAAa,EAAEC,WAAoB;IACpE,OAAO,CAACC;QACN,IAAIF,WAAWC,aAAa;YAC1BD,QAAQG,IAAI,GAAG,CAAC,EAAEF,YAAY,CAAC,EAAE7B,IAC/B,CAAC,CAAC,EAAEgC,KAAKC,KAAK,CAACH,aAAa,KAAK,EAAE,CAAC,EACpC,CAAC;QACL;IACF;AACF;AAEA;;;;CAIC,GACD,OAAO,eAAehB;IACpB,MAAMoB,WAAW,MAAMhC,GAAGiC,QAAQ,CAAC9B,mBAAmB;IACtD,OAAO6B,SACJE,KAAK,CAAC,MACNC,GAAG,CAAC,CAACC,OAASA,KAAKC,IAAI,IACvBC,MAAM,CAAC,CAACF,OAASA,QAAQ,CAACA,KAAKG,UAAU,CAAC;AAC/C;AAEA;;;;;;;;;;;;;;;;;;;CAmBC,GACD,OAAO,SAASC,UACdC,KAAa,EACbC,QAAgB,EAChBC,SAAS,CAAC,EAAED,SAAS,CAAC,CAAC;IAEvB,OAAOD,UAAU,IAAIC,WAAWC;AAClC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { SnapConfig } from '../../config';
2
+ declare const config: SnapConfig;
3
+ export default config;
@@ -0,0 +1,3 @@
1
+ import type { SnapConfig } from '../../config';
2
+ declare const config: SnapConfig;
3
+ export default config;
@@ -0,0 +1,3 @@
1
+ import type { SnapConfig } from '../../../config';
2
+ declare const config: SnapConfig;
3
+ export default config;
@@ -1,27 +1,8 @@
1
- import type { Options, PositionalOptions } from 'yargs';
2
- export declare type SnapsCliBuilders = {
3
- readonly bundle: Readonly<Options>;
4
- readonly dist: Readonly<Options>;
5
- readonly eval: Readonly<Options>;
6
- readonly manifest: Readonly<Options>;
7
- readonly outfileName: Readonly<Options>;
8
- readonly port: Readonly<Options>;
9
- readonly root: Readonly<Options>;
10
- readonly sourceMaps: Readonly<Options>;
11
- readonly src: Readonly<Options>;
12
- readonly stripComments: Readonly<Options>;
13
- readonly suppressWarnings: Readonly<Options>;
14
- readonly transpilationMode: Readonly<Options>;
15
- readonly depsToTranspile: Readonly<Options>;
16
- readonly verboseErrors: Readonly<Options>;
17
- readonly writeManifest: Readonly<Options>;
18
- readonly serve: Readonly<Options>;
19
- readonly directory: Readonly<PositionalOptions>;
20
- };
1
+ import type { Options } from 'yargs';
21
2
  export declare enum TranspilationModes {
22
3
  LocalAndDeps = "localAndDeps",
23
4
  LocalOnly = "localOnly",
24
5
  None = "none"
25
6
  }
26
- declare const builders: SnapsCliBuilders;
7
+ declare const builders: Record<string, Readonly<Options>>;
27
8
  export default builders;
@@ -5,4 +5,4 @@
5
5
  * @param argv - The raw command line arguments, i.e., `process.argv`.
6
6
  * @param commands - The list of commands to use.
7
7
  */
8
- export declare function cli(argv: string[], commands: any): void;
8
+ export declare function cli(argv: string[], commands: any): Promise<void>;
@@ -0,0 +1,10 @@
1
+ import type { ProcessedConfig } from '../../config';
2
+ /**
3
+ * Build all files in the given source directory to the given destination
4
+ * directory.
5
+ *
6
+ * This creates the destination directory if it doesn't exist.
7
+ *
8
+ * @param config - The config object.
9
+ */
10
+ export declare function buildHandler(config: ProcessedConfig): Promise<void>;
@@ -0,0 +1,10 @@
1
+ import type { ProcessedWebpackConfig } from '../../config';
2
+ import type { WebpackOptions } from '../../webpack';
3
+ /**
4
+ * Build the snap bundle. This uses Webpack to build the bundle.
5
+ *
6
+ * @param config - The config object.
7
+ * @param options - The Webpack options.
8
+ * @returns A promise that resolves when the bundle is built.
9
+ */
10
+ export declare function build(config: ProcessedWebpackConfig, options?: WebpackOptions): Promise<void>;
@@ -6,4 +6,5 @@ declare const command: {
6
6
  builder: (yarg: yargs.Argv) => void;
7
7
  handler: (argv: YargsArgs) => Promise<void>;
8
8
  };
9
+ export * from './implementation';
9
10
  export default command;