@metamask/snaps-cli 6.7.0 → 7.1.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 (255) hide show
  1. package/CHANGELOG.md +45 -1
  2. package/README.md +12 -244
  3. package/dist/builders.cjs +5 -97
  4. package/dist/builders.cjs.map +1 -1
  5. package/dist/builders.d.cts +5 -94
  6. package/dist/builders.d.cts.map +1 -1
  7. package/dist/builders.d.mts +5 -94
  8. package/dist/builders.d.mts.map +1 -1
  9. package/dist/builders.mjs +5 -96
  10. package/dist/builders.mjs.map +1 -1
  11. package/dist/cli.cjs +4 -9
  12. package/dist/cli.cjs.map +1 -1
  13. package/dist/cli.d.cts.map +1 -1
  14. package/dist/cli.d.mts.map +1 -1
  15. package/dist/cli.mjs +4 -16
  16. package/dist/cli.mjs.map +1 -1
  17. package/dist/commands/build/build.cjs +15 -11
  18. package/dist/commands/build/build.cjs.map +1 -1
  19. package/dist/commands/build/build.d.cts +8 -0
  20. package/dist/commands/build/build.d.cts.map +1 -1
  21. package/dist/commands/build/build.d.mts +8 -0
  22. package/dist/commands/build/build.d.mts.map +1 -1
  23. package/dist/commands/build/build.mjs +9 -5
  24. package/dist/commands/build/build.mjs.map +1 -1
  25. package/dist/commands/build/implementation.cjs.map +1 -1
  26. package/dist/commands/build/implementation.d.cts +2 -2
  27. package/dist/commands/build/implementation.d.cts.map +1 -1
  28. package/dist/commands/build/implementation.d.mts +2 -2
  29. package/dist/commands/build/implementation.d.mts.map +1 -1
  30. package/dist/commands/build/implementation.mjs.map +1 -1
  31. package/dist/commands/build/index.cjs +5 -14
  32. package/dist/commands/build/index.cjs.map +1 -1
  33. package/dist/commands/build/index.d.cts +1 -0
  34. package/dist/commands/build/index.d.cts.map +1 -1
  35. package/dist/commands/build/index.d.mts +1 -0
  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/eval/__test__/webpack/bad/snap.config.cjs +0 -1
  40. package/dist/commands/eval/__test__/webpack/bad/snap.config.cjs.map +1 -1
  41. package/dist/commands/eval/__test__/webpack/bad/snap.config.d.cts.map +1 -1
  42. package/dist/commands/eval/__test__/webpack/bad/snap.config.d.mts.map +1 -1
  43. package/dist/commands/eval/__test__/webpack/bad/snap.config.mjs +0 -1
  44. package/dist/commands/eval/__test__/webpack/bad/snap.config.mjs.map +1 -1
  45. package/dist/commands/eval/__test__/webpack/good/snap.config.cjs +0 -1
  46. package/dist/commands/eval/__test__/webpack/good/snap.config.cjs.map +1 -1
  47. package/dist/commands/eval/__test__/webpack/good/snap.config.d.cts.map +1 -1
  48. package/dist/commands/eval/__test__/webpack/good/snap.config.d.mts.map +1 -1
  49. package/dist/commands/eval/__test__/webpack/good/snap.config.mjs +0 -1
  50. package/dist/commands/eval/__test__/webpack/good/snap.config.mjs.map +1 -1
  51. package/dist/commands/eval/__test__/webpack/snap.config.cjs +0 -1
  52. package/dist/commands/eval/__test__/webpack/snap.config.cjs.map +1 -1
  53. package/dist/commands/eval/__test__/webpack/snap.config.d.cts.map +1 -1
  54. package/dist/commands/eval/__test__/webpack/snap.config.d.mts.map +1 -1
  55. package/dist/commands/eval/__test__/webpack/snap.config.mjs +0 -1
  56. package/dist/commands/eval/__test__/webpack/snap.config.mjs.map +1 -1
  57. package/dist/commands/eval/eval.cjs +1 -1
  58. package/dist/commands/eval/eval.cjs.map +1 -1
  59. package/dist/commands/eval/eval.d.cts.map +1 -1
  60. package/dist/commands/eval/eval.d.mts.map +1 -1
  61. package/dist/commands/eval/eval.mjs +1 -1
  62. package/dist/commands/eval/eval.mjs.map +1 -1
  63. package/dist/commands/eval/index.cjs +1 -4
  64. package/dist/commands/eval/index.cjs.map +1 -1
  65. package/dist/commands/eval/index.d.cts.map +1 -1
  66. package/dist/commands/eval/index.d.mts.map +1 -1
  67. package/dist/commands/eval/index.mjs +1 -4
  68. package/dist/commands/eval/index.mjs.map +1 -1
  69. package/dist/commands/index.cjs +2 -0
  70. package/dist/commands/index.cjs.map +1 -1
  71. package/dist/commands/index.d.cts.map +1 -1
  72. package/dist/commands/index.d.mts.map +1 -1
  73. package/dist/commands/index.mjs +2 -0
  74. package/dist/commands/index.mjs.map +1 -1
  75. package/dist/commands/manifest/index.cjs +1 -4
  76. package/dist/commands/manifest/index.cjs.map +1 -1
  77. package/dist/commands/manifest/index.d.cts.map +1 -1
  78. package/dist/commands/manifest/index.d.mts.map +1 -1
  79. package/dist/commands/manifest/index.mjs +1 -4
  80. package/dist/commands/manifest/index.mjs.map +1 -1
  81. package/dist/commands/manifest/manifest.cjs +5 -6
  82. package/dist/commands/manifest/manifest.cjs.map +1 -1
  83. package/dist/commands/manifest/manifest.d.cts.map +1 -1
  84. package/dist/commands/manifest/manifest.d.mts.map +1 -1
  85. package/dist/commands/manifest/manifest.mjs +5 -6
  86. package/dist/commands/manifest/manifest.mjs.map +1 -1
  87. package/dist/commands/sandbox/index.cjs +17 -0
  88. package/dist/commands/sandbox/index.cjs.map +1 -0
  89. package/dist/commands/sandbox/index.d.cts +10 -0
  90. package/dist/commands/sandbox/index.d.cts.map +1 -0
  91. package/dist/commands/sandbox/index.d.mts +10 -0
  92. package/dist/commands/sandbox/index.d.mts.map +1 -0
  93. package/dist/commands/sandbox/index.mjs +12 -0
  94. package/dist/commands/sandbox/index.mjs.map +1 -0
  95. package/dist/commands/sandbox/sandbox.cjs +33 -0
  96. package/dist/commands/sandbox/sandbox.cjs.map +1 -0
  97. package/dist/commands/sandbox/sandbox.d.cts +14 -0
  98. package/dist/commands/sandbox/sandbox.d.cts.map +1 -0
  99. package/dist/commands/sandbox/sandbox.d.mts +14 -0
  100. package/dist/commands/sandbox/sandbox.d.mts.map +1 -0
  101. package/dist/commands/sandbox/sandbox.mjs +29 -0
  102. package/dist/commands/sandbox/sandbox.mjs.map +1 -0
  103. package/dist/commands/sandbox/server.cjs +27 -0
  104. package/dist/commands/sandbox/server.cjs.map +1 -0
  105. package/dist/commands/sandbox/server.d.cts +14 -0
  106. package/dist/commands/sandbox/server.d.cts.map +1 -0
  107. package/dist/commands/sandbox/server.d.mts +14 -0
  108. package/dist/commands/sandbox/server.d.mts.map +1 -0
  109. package/dist/commands/sandbox/server.mjs +25 -0
  110. package/dist/commands/sandbox/server.mjs.map +1 -0
  111. package/dist/commands/serve/index.cjs +2 -2
  112. package/dist/commands/serve/index.cjs.map +1 -1
  113. package/dist/commands/serve/index.d.cts.map +1 -1
  114. package/dist/commands/serve/index.d.mts.map +1 -1
  115. package/dist/commands/serve/index.mjs +2 -2
  116. package/dist/commands/serve/index.mjs.map +1 -1
  117. package/dist/commands/watch/implementation.cjs +2 -0
  118. package/dist/commands/watch/implementation.cjs.map +1 -1
  119. package/dist/commands/watch/implementation.d.cts +2 -2
  120. package/dist/commands/watch/implementation.d.cts.map +1 -1
  121. package/dist/commands/watch/implementation.d.mts +2 -2
  122. package/dist/commands/watch/implementation.d.mts.map +1 -1
  123. package/dist/commands/watch/implementation.mjs +2 -0
  124. package/dist/commands/watch/implementation.mjs.map +1 -1
  125. package/dist/commands/watch/index.cjs +2 -17
  126. package/dist/commands/watch/index.cjs.map +1 -1
  127. package/dist/commands/watch/index.d.cts.map +1 -1
  128. package/dist/commands/watch/index.d.mts.map +1 -1
  129. package/dist/commands/watch/index.mjs +2 -17
  130. package/dist/commands/watch/index.mjs.map +1 -1
  131. package/dist/commands/watch/watch.cjs +1 -1
  132. package/dist/commands/watch/watch.cjs.map +1 -1
  133. package/dist/commands/watch/watch.d.cts.map +1 -1
  134. package/dist/commands/watch/watch.d.mts.map +1 -1
  135. package/dist/commands/watch/watch.mjs +1 -1
  136. package/dist/commands/watch/watch.mjs.map +1 -1
  137. package/dist/config.cjs +11 -155
  138. package/dist/config.cjs.map +1 -1
  139. package/dist/config.d.cts +216 -314
  140. package/dist/config.d.cts.map +1 -1
  141. package/dist/config.d.mts +216 -314
  142. package/dist/config.d.mts.map +1 -1
  143. package/dist/config.mjs +13 -155
  144. package/dist/config.mjs.map +1 -1
  145. package/dist/main.cjs +0 -1
  146. package/dist/main.cjs.map +1 -1
  147. package/dist/main.mjs +0 -1
  148. package/dist/main.mjs.map +1 -1
  149. package/dist/utils/index.cjs +0 -1
  150. package/dist/utils/index.cjs.map +1 -1
  151. package/dist/utils/index.d.cts +0 -1
  152. package/dist/utils/index.d.cts.map +1 -1
  153. package/dist/utils/index.d.mts +0 -1
  154. package/dist/utils/index.d.mts.map +1 -1
  155. package/dist/utils/index.mjs +0 -1
  156. package/dist/utils/index.mjs.map +1 -1
  157. package/dist/utils/steps.cjs.map +1 -1
  158. package/dist/utils/steps.d.cts +1 -1
  159. package/dist/utils/steps.d.cts.map +1 -1
  160. package/dist/utils/steps.d.mts +1 -1
  161. package/dist/utils/steps.d.mts.map +1 -1
  162. package/dist/utils/steps.mjs.map +1 -1
  163. package/dist/webpack/compiler.cjs.map +1 -1
  164. package/dist/webpack/compiler.d.cts +2 -2
  165. package/dist/webpack/compiler.d.cts.map +1 -1
  166. package/dist/webpack/compiler.d.mts +2 -2
  167. package/dist/webpack/compiler.d.mts.map +1 -1
  168. package/dist/webpack/compiler.mjs.map +1 -1
  169. package/dist/webpack/config.cjs +1 -2
  170. package/dist/webpack/config.cjs.map +1 -1
  171. package/dist/webpack/config.d.cts +2 -2
  172. package/dist/webpack/config.d.cts.map +1 -1
  173. package/dist/webpack/config.d.mts +2 -2
  174. package/dist/webpack/config.d.mts.map +1 -1
  175. package/dist/webpack/config.mjs +1 -2
  176. package/dist/webpack/config.mjs.map +1 -1
  177. package/dist/webpack/loaders/function.cjs +7 -10
  178. package/dist/webpack/loaders/function.cjs.map +1 -1
  179. package/dist/webpack/loaders/function.d.cts +1 -0
  180. package/dist/webpack/loaders/function.d.cts.map +1 -1
  181. package/dist/webpack/loaders/function.d.mts +1 -0
  182. package/dist/webpack/loaders/function.d.mts.map +1 -1
  183. package/dist/webpack/loaders/function.mjs +6 -9
  184. package/dist/webpack/loaders/function.mjs.map +1 -1
  185. package/dist/webpack/loaders/index.cjs +1 -3
  186. package/dist/webpack/loaders/index.cjs.map +1 -1
  187. package/dist/webpack/loaders/index.d.cts +0 -1
  188. package/dist/webpack/loaders/index.d.cts.map +1 -1
  189. package/dist/webpack/loaders/index.d.mts +0 -1
  190. package/dist/webpack/loaders/index.d.mts.map +1 -1
  191. package/dist/webpack/loaders/index.mjs +0 -1
  192. package/dist/webpack/loaders/index.mjs.map +1 -1
  193. package/dist/webpack/loaders/wasm.cjs +0 -2
  194. package/dist/webpack/loaders/wasm.cjs.map +1 -1
  195. package/dist/webpack/loaders/wasm.d.cts.map +1 -1
  196. package/dist/webpack/loaders/wasm.d.mts.map +1 -1
  197. package/dist/webpack/loaders/wasm.mjs +0 -2
  198. package/dist/webpack/loaders/wasm.mjs.map +1 -1
  199. package/dist/webpack/plugins.cjs +15 -20
  200. package/dist/webpack/plugins.cjs.map +1 -1
  201. package/dist/webpack/plugins.d.cts +13 -3
  202. package/dist/webpack/plugins.d.cts.map +1 -1
  203. package/dist/webpack/plugins.d.mts +13 -3
  204. package/dist/webpack/plugins.d.mts.map +1 -1
  205. package/dist/webpack/plugins.mjs +4 -9
  206. package/dist/webpack/plugins.mjs.map +1 -1
  207. package/dist/webpack/server.cjs +83 -72
  208. package/dist/webpack/server.cjs.map +1 -1
  209. package/dist/webpack/server.d.cts +6 -1
  210. package/dist/webpack/server.d.cts.map +1 -1
  211. package/dist/webpack/server.d.mts +6 -1
  212. package/dist/webpack/server.d.mts.map +1 -1
  213. package/dist/webpack/server.mjs +63 -72
  214. package/dist/webpack/server.mjs.map +1 -1
  215. package/dist/webpack/utils.cjs +5 -21
  216. package/dist/webpack/utils.cjs.map +1 -1
  217. package/dist/webpack/utils.d.cts +6 -36
  218. package/dist/webpack/utils.d.cts.map +1 -1
  219. package/dist/webpack/utils.d.mts +6 -36
  220. package/dist/webpack/utils.d.mts.map +1 -1
  221. package/dist/webpack/utils.mjs +4 -18
  222. package/dist/webpack/utils.mjs.map +1 -1
  223. package/package.json +16 -40
  224. package/dist/commands/eval/__test__/browserify/bad/snap.config.cjs +0 -10
  225. package/dist/commands/eval/__test__/browserify/bad/snap.config.cjs.map +0 -1
  226. package/dist/commands/eval/__test__/browserify/bad/snap.config.d.cts +0 -4
  227. package/dist/commands/eval/__test__/browserify/bad/snap.config.d.cts.map +0 -1
  228. package/dist/commands/eval/__test__/browserify/bad/snap.config.d.mts +0 -4
  229. package/dist/commands/eval/__test__/browserify/bad/snap.config.d.mts.map +0 -1
  230. package/dist/commands/eval/__test__/browserify/bad/snap.config.mjs +0 -8
  231. package/dist/commands/eval/__test__/browserify/bad/snap.config.mjs.map +0 -1
  232. package/dist/commands/eval/__test__/browserify/good/snap.config.cjs +0 -10
  233. package/dist/commands/eval/__test__/browserify/good/snap.config.cjs.map +0 -1
  234. package/dist/commands/eval/__test__/browserify/good/snap.config.d.cts +0 -4
  235. package/dist/commands/eval/__test__/browserify/good/snap.config.d.cts.map +0 -1
  236. package/dist/commands/eval/__test__/browserify/good/snap.config.d.mts +0 -4
  237. package/dist/commands/eval/__test__/browserify/good/snap.config.d.mts.map +0 -1
  238. package/dist/commands/eval/__test__/browserify/good/snap.config.mjs +0 -8
  239. package/dist/commands/eval/__test__/browserify/good/snap.config.mjs.map +0 -1
  240. package/dist/utils/legacy.cjs +0 -53
  241. package/dist/utils/legacy.cjs.map +0 -1
  242. package/dist/utils/legacy.d.cts +0 -28
  243. package/dist/utils/legacy.d.cts.map +0 -1
  244. package/dist/utils/legacy.d.mts +0 -28
  245. package/dist/utils/legacy.d.mts.map +0 -1
  246. package/dist/utils/legacy.mjs +0 -47
  247. package/dist/utils/legacy.mjs.map +0 -1
  248. package/dist/webpack/loaders/browserify.cjs +0 -84
  249. package/dist/webpack/loaders/browserify.cjs.map +0 -1
  250. package/dist/webpack/loaders/browserify.d.cts +0 -18
  251. package/dist/webpack/loaders/browserify.d.cts.map +0 -1
  252. package/dist/webpack/loaders/browserify.d.mts +0 -18
  253. package/dist/webpack/loaders/browserify.d.mts.map +0 -1
  254. package/dist/webpack/loaders/browserify.mjs +0 -88
  255. package/dist/webpack/loaders/browserify.mjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"implementation.mjs","sourceRoot":"","sources":["../../../src/commands/watch/implementation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,aAAa;AAKhC,OAAO,EAAE,WAAW,EAAE,gCAAsB;AAE5C;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,KAAK,CACzB,MAA8B,EAC9B,OAAwB;IAExB,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,MAAM,EAAE;QACzC,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,KAAK,EAAE,IAAI;QACX,OAAO,EAAE,OAAO,EAAE,OAAO;KAC1B,CAAC,CAAC;IAEH,OAAO,IAAI,OAAO,CAAW,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC/C,QAAQ,CAAC,KAAK,CACZ;YACE,OAAO,EAAE;gBACP,sBAAsB;gBACtB,MAAM,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO;aAC1C;SACF,EACD,CAAC,UAAU,EAAE,EAAE;YACb,IAAI,UAAU,EAAE,CAAC;gBACf,MAAM,CAAC,UAAU,CAAC,CAAC;gBACnB,OAAO;YACT,CAAC;YAED,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QAC7B,CAAC,CACF,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { basename } from 'path';\nimport type { Watching } from 'webpack';\n\nimport type { ProcessedWebpackConfig } from '../../config';\nimport type { WebpackOptions } from '../../webpack';\nimport { getCompiler } from '../../webpack';\n\n/**\n * Build the snap bundle and watch for changes. This uses Webpack to build the\n * bundle.\n *\n * @param config - The config object.\n * @param options - The Webpack options.\n * @returns A promise that resolves when the bundle is built for the first time.\n * The promise resolves with a Webpack watching instance that can be used to\n * close the watcher.\n */\nexport async function watch(\n config: ProcessedWebpackConfig,\n options?: WebpackOptions,\n) {\n const compiler = await getCompiler(config, {\n evaluate: config.evaluate,\n watch: true,\n spinner: options?.spinner,\n });\n\n return new Promise<Watching>((resolve, reject) => {\n compiler.watch(\n {\n ignored: [\n '**/node_modules/**/*',\n `**/${basename(config.output.path)}/**/*`,\n ],\n },\n (watchError) => {\n if (watchError) {\n reject(watchError);\n return;\n }\n\n resolve(compiler.watching);\n },\n );\n });\n}\n"]}
1
+ {"version":3,"file":"implementation.mjs","sourceRoot":"","sources":["../../../src/commands/watch/implementation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,wBAAwB;AACzC,OAAO,EAAE,QAAQ,EAAE,aAAa;AAKhC,OAAO,EAAE,WAAW,EAAE,gCAAsB;AAE5C;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,KAAK,CAAC,MAAuB,EAAE,OAAwB;IAC3E,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,MAAM,EAAE;QACzC,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,KAAK,EAAE,IAAI;QACX,OAAO,EAAE,OAAO,EAAE,OAAO;KAC1B,CAAC,CAAC;IAEH,OAAO,IAAI,OAAO,CAAW,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC/C,QAAQ,CAAC,KAAK,CACZ;YACE,OAAO,EAAE;gBACP,sBAAsB;gBACtB,MAAM,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO;aAC1C;SACF,EACD,CAAC,UAAU,EAAE,EAAE;YACb,IAAI,UAAU,EAAE,CAAC;gBACf,MAAM,CAAC,UAAU,CAAC,CAAC;gBACnB,OAAO;YACT,CAAC;YAED,MAAM,CAAC,QAAQ,CAAC,QAAQ,EAAE,yCAAyC,CAAC,CAAC;YACrE,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QAC7B,CAAC,CACF,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { assert } from '@metamask/utils';\nimport { basename } from 'path';\nimport type { Watching } from 'webpack';\n\nimport type { ProcessedConfig } from '../../config';\nimport type { WebpackOptions } from '../../webpack';\nimport { getCompiler } from '../../webpack';\n\n/**\n * Build the snap bundle and watch for changes. This uses Webpack to build the\n * bundle.\n *\n * @param config - The config object.\n * @param options - The Webpack options.\n * @returns A promise that resolves when the bundle is built for the first time.\n * The promise resolves with a Webpack watching instance that can be used to\n * close the watcher.\n */\nexport async function watch(config: ProcessedConfig, options?: WebpackOptions) {\n const compiler = await getCompiler(config, {\n evaluate: config.evaluate,\n watch: true,\n spinner: options?.spinner,\n });\n\n return new Promise<Watching>((resolve, reject) => {\n compiler.watch(\n {\n ignored: [\n '**/node_modules/**/*',\n `**/${basename(config.output.path)}/**/*`,\n ],\n },\n (watchError) => {\n if (watchError) {\n reject(watchError);\n return;\n }\n\n assert(compiler.watching, 'Expected `compiler.watching` to be set.');\n resolve(compiler.watching);\n },\n );\n });\n}\n"]}
@@ -17,28 +17,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- const builders_1 = __importDefault(require("../../builders.cjs"));
21
20
  const watch_1 = require("./watch.cjs");
21
+ const builders_1 = __importDefault(require("../../builders.cjs"));
22
22
  const command = {
23
23
  command: ['watch', 'w'],
24
24
  desc: 'Build Snap on change',
25
25
  builder: (yarg) => {
26
- yarg
27
- .option('src', builders_1.default.src)
28
- .option('eval', builders_1.default.eval)
29
- .option('dist', builders_1.default.dist)
30
- .option('outfileName', builders_1.default.outfileName)
31
- .option('sourceMaps', builders_1.default.sourceMaps)
32
- .option('stripComments', builders_1.default.stripComments)
33
- .option('transpilationMode', builders_1.default.transpilationMode)
34
- .option('depsToTranspile', builders_1.default.depsToTranspile)
35
- .option('manifest', builders_1.default.manifest)
36
- .option('writeManifest', builders_1.default.writeManifest)
37
- .option('serve', builders_1.default.serve)
38
- .option('root', builders_1.default.root)
39
- .option('port', builders_1.default.port)
40
- .implies('writeManifest', 'manifest')
41
- .implies('depsToTranspile', 'transpilationMode');
26
+ yarg.option('port', builders_1.default.port);
42
27
  },
43
28
  handler: async (argv) => (0, watch_1.watchHandler)(argv.context.config, {
44
29
  port: argv.port,
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../src/commands/watch/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAEA,kEAAsC;AAEtC,uCAAuC;AAEvC,MAAM,OAAO,GAAG;IACd,OAAO,EAAE,CAAC,OAAO,EAAE,GAAG,CAAC;IACvB,IAAI,EAAE,sBAAsB;IAC5B,OAAO,EAAE,CAAC,IAAgB,EAAE,EAAE;QAC5B,IAAI;aACD,MAAM,CAAC,KAAK,EAAE,kBAAQ,CAAC,GAAG,CAAC;aAC3B,MAAM,CAAC,MAAM,EAAE,kBAAQ,CAAC,IAAI,CAAC;aAC7B,MAAM,CAAC,MAAM,EAAE,kBAAQ,CAAC,IAAI,CAAC;aAC7B,MAAM,CAAC,aAAa,EAAE,kBAAQ,CAAC,WAAW,CAAC;aAC3C,MAAM,CAAC,YAAY,EAAE,kBAAQ,CAAC,UAAU,CAAC;aACzC,MAAM,CAAC,eAAe,EAAE,kBAAQ,CAAC,aAAa,CAAC;aAC/C,MAAM,CAAC,mBAAmB,EAAE,kBAAQ,CAAC,iBAAiB,CAAC;aACvD,MAAM,CAAC,iBAAiB,EAAE,kBAAQ,CAAC,eAAe,CAAC;aACnD,MAAM,CAAC,UAAU,EAAE,kBAAQ,CAAC,QAAQ,CAAC;aACrC,MAAM,CAAC,eAAe,EAAE,kBAAQ,CAAC,aAAa,CAAC;aAC/C,MAAM,CAAC,OAAO,EAAE,kBAAQ,CAAC,KAAK,CAAC;aAC/B,MAAM,CAAC,MAAM,EAAE,kBAAQ,CAAC,IAAI,CAAC;aAC7B,MAAM,CAAC,MAAM,EAAE,kBAAQ,CAAC,IAAI,CAAC;aAC7B,OAAO,CAAC,eAAe,EAAE,UAAU,CAAC;aACpC,OAAO,CAAC,iBAAiB,EAAE,mBAAmB,CAAC,CAAC;IACrD,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,IAAe,EAAE,EAAE,CACjC,IAAA,oBAAY,EAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;QAChC,IAAI,EAAE,IAAI,CAAC,IAAI;KAChB,CAAC;CACL,CAAC;AAEF,uDAAiC;AACjC,kBAAe,OAAO,CAAC","sourcesContent":["import type yargs from 'yargs';\n\nimport builders from '../../builders';\nimport type { YargsArgs } from '../../types/yargs';\nimport { watchHandler } from './watch';\n\nconst command = {\n command: ['watch', 'w'],\n desc: 'Build Snap on change',\n builder: (yarg: yargs.Argv) => {\n yarg\n .option('src', builders.src)\n .option('eval', builders.eval)\n .option('dist', builders.dist)\n .option('outfileName', builders.outfileName)\n .option('sourceMaps', builders.sourceMaps)\n .option('stripComments', builders.stripComments)\n .option('transpilationMode', builders.transpilationMode)\n .option('depsToTranspile', builders.depsToTranspile)\n .option('manifest', builders.manifest)\n .option('writeManifest', builders.writeManifest)\n .option('serve', builders.serve)\n .option('root', builders.root)\n .option('port', builders.port)\n .implies('writeManifest', 'manifest')\n .implies('depsToTranspile', 'transpilationMode');\n },\n handler: async (argv: YargsArgs) =>\n watchHandler(argv.context.config, {\n port: argv.port,\n }),\n};\n\nexport * from './implementation';\nexport default command;\n"]}
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../src/commands/watch/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAEA,uCAAuC;AACvC,kEAAsC;AAGtC,MAAM,OAAO,GAAG;IACd,OAAO,EAAE,CAAC,OAAO,EAAE,GAAG,CAAC;IACvB,IAAI,EAAE,sBAAsB;IAC5B,OAAO,EAAE,CAAC,IAAgB,EAAE,EAAE;QAC5B,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,kBAAQ,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,IAAe,EAAE,EAAE,CACjC,IAAA,oBAAY,EAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;QAChC,IAAI,EAAE,IAAI,CAAC,IAAI;KAChB,CAAC;CACL,CAAC;AAEF,uDAAiC;AACjC,kBAAe,OAAO,CAAC","sourcesContent":["import type yargs from 'yargs';\n\nimport { watchHandler } from './watch';\nimport builders from '../../builders';\nimport type { YargsArgs } from '../../types/yargs';\n\nconst command = {\n command: ['watch', 'w'],\n desc: 'Build Snap on change',\n builder: (yarg: yargs.Argv) => {\n yarg.option('port', builders.port);\n },\n handler: async (argv: YargsArgs) =>\n watchHandler(argv.context.config, {\n port: argv.port,\n }),\n};\n\nexport * from './implementation';\nexport default command;\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/commands/watch/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,cAAc;AAG/B,OAAO,KAAK,EAAE,SAAS,EAAE,gCAA0B;AAGnD,QAAA,MAAM,OAAO;;;oBAGK,MAAM,IAAI;oBAkBJ,SAAS;CAIhC,CAAC;AAEF,qCAAiC;AACjC,eAAe,OAAO,CAAC"}
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/commands/watch/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,cAAc;AAI/B,OAAO,KAAK,EAAE,SAAS,EAAE,gCAA0B;AAEnD,QAAA,MAAM,OAAO;;;oBAGK,MAAM,IAAI;oBAGJ,SAAS;CAIhC,CAAC;AAEF,qCAAiC;AACjC,eAAe,OAAO,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/commands/watch/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,cAAc;AAG/B,OAAO,KAAK,EAAE,SAAS,EAAE,gCAA0B;AAGnD,QAAA,MAAM,OAAO;;;oBAGK,MAAM,IAAI;oBAkBJ,SAAS;CAIhC,CAAC;AAEF,qCAAiC;AACjC,eAAe,OAAO,CAAC"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/commands/watch/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,cAAc;AAI/B,OAAO,KAAK,EAAE,SAAS,EAAE,gCAA0B;AAEnD,QAAA,MAAM,OAAO;;;oBAGK,MAAM,IAAI;oBAGJ,SAAS;CAIhC,CAAC;AAEF,qCAAiC;AACjC,eAAe,OAAO,CAAC"}
@@ -1,25 +1,10 @@
1
- import builders from "../../builders.mjs";
2
1
  import { watchHandler } from "./watch.mjs";
2
+ import builders from "../../builders.mjs";
3
3
  const command = {
4
4
  command: ['watch', 'w'],
5
5
  desc: 'Build Snap on change',
6
6
  builder: (yarg) => {
7
- yarg
8
- .option('src', builders.src)
9
- .option('eval', builders.eval)
10
- .option('dist', builders.dist)
11
- .option('outfileName', builders.outfileName)
12
- .option('sourceMaps', builders.sourceMaps)
13
- .option('stripComments', builders.stripComments)
14
- .option('transpilationMode', builders.transpilationMode)
15
- .option('depsToTranspile', builders.depsToTranspile)
16
- .option('manifest', builders.manifest)
17
- .option('writeManifest', builders.writeManifest)
18
- .option('serve', builders.serve)
19
- .option('root', builders.root)
20
- .option('port', builders.port)
21
- .implies('writeManifest', 'manifest')
22
- .implies('depsToTranspile', 'transpilationMode');
7
+ yarg.option('port', builders.port);
23
8
  },
24
9
  handler: async (argv) => watchHandler(argv.context.config, {
25
10
  port: argv.port,
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../src/commands/watch/index.ts"],"names":[],"mappings":"AAEA,OAAO,QAAQ,2BAAuB;AAEtC,OAAO,EAAE,YAAY,EAAE,oBAAgB;AAEvC,MAAM,OAAO,GAAG;IACd,OAAO,EAAE,CAAC,OAAO,EAAE,GAAG,CAAC;IACvB,IAAI,EAAE,sBAAsB;IAC5B,OAAO,EAAE,CAAC,IAAgB,EAAE,EAAE;QAC5B,IAAI;aACD,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,CAAC;aAC3B,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC;aAC7B,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC;aAC7B,MAAM,CAAC,aAAa,EAAE,QAAQ,CAAC,WAAW,CAAC;aAC3C,MAAM,CAAC,YAAY,EAAE,QAAQ,CAAC,UAAU,CAAC;aACzC,MAAM,CAAC,eAAe,EAAE,QAAQ,CAAC,aAAa,CAAC;aAC/C,MAAM,CAAC,mBAAmB,EAAE,QAAQ,CAAC,iBAAiB,CAAC;aACvD,MAAM,CAAC,iBAAiB,EAAE,QAAQ,CAAC,eAAe,CAAC;aACnD,MAAM,CAAC,UAAU,EAAE,QAAQ,CAAC,QAAQ,CAAC;aACrC,MAAM,CAAC,eAAe,EAAE,QAAQ,CAAC,aAAa,CAAC;aAC/C,MAAM,CAAC,OAAO,EAAE,QAAQ,CAAC,KAAK,CAAC;aAC/B,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC;aAC7B,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC;aAC7B,OAAO,CAAC,eAAe,EAAE,UAAU,CAAC;aACpC,OAAO,CAAC,iBAAiB,EAAE,mBAAmB,CAAC,CAAC;IACrD,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,IAAe,EAAE,EAAE,CACjC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;QAChC,IAAI,EAAE,IAAI,CAAC,IAAI;KAChB,CAAC;CACL,CAAC;AAEF,qCAAiC;AACjC,eAAe,OAAO,CAAC","sourcesContent":["import type yargs from 'yargs';\n\nimport builders from '../../builders';\nimport type { YargsArgs } from '../../types/yargs';\nimport { watchHandler } from './watch';\n\nconst command = {\n command: ['watch', 'w'],\n desc: 'Build Snap on change',\n builder: (yarg: yargs.Argv) => {\n yarg\n .option('src', builders.src)\n .option('eval', builders.eval)\n .option('dist', builders.dist)\n .option('outfileName', builders.outfileName)\n .option('sourceMaps', builders.sourceMaps)\n .option('stripComments', builders.stripComments)\n .option('transpilationMode', builders.transpilationMode)\n .option('depsToTranspile', builders.depsToTranspile)\n .option('manifest', builders.manifest)\n .option('writeManifest', builders.writeManifest)\n .option('serve', builders.serve)\n .option('root', builders.root)\n .option('port', builders.port)\n .implies('writeManifest', 'manifest')\n .implies('depsToTranspile', 'transpilationMode');\n },\n handler: async (argv: YargsArgs) =>\n watchHandler(argv.context.config, {\n port: argv.port,\n }),\n};\n\nexport * from './implementation';\nexport default command;\n"]}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../src/commands/watch/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,oBAAgB;AACvC,OAAO,QAAQ,2BAAuB;AAGtC,MAAM,OAAO,GAAG;IACd,OAAO,EAAE,CAAC,OAAO,EAAE,GAAG,CAAC;IACvB,IAAI,EAAE,sBAAsB;IAC5B,OAAO,EAAE,CAAC,IAAgB,EAAE,EAAE;QAC5B,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,IAAe,EAAE,EAAE,CACjC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;QAChC,IAAI,EAAE,IAAI,CAAC,IAAI;KAChB,CAAC;CACL,CAAC;AAEF,qCAAiC;AACjC,eAAe,OAAO,CAAC","sourcesContent":["import type yargs from 'yargs';\n\nimport { watchHandler } from './watch';\nimport builders from '../../builders';\nimport type { YargsArgs } from '../../types/yargs';\n\nconst command = {\n command: ['watch', 'w'],\n desc: 'Build Snap on change',\n builder: (yarg: yargs.Argv) => {\n yarg.option('port', builders.port);\n },\n handler: async (argv: YargsArgs) =>\n watchHandler(argv.context.config, {\n port: argv.port,\n }),\n};\n\nexport * from './implementation';\nexport default command;\n"]}
@@ -2,10 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.watchHandler = void 0;
4
4
  const node_1 = require("@metamask/snaps-utils/node");
5
+ const implementation_1 = require("./implementation.cjs");
5
6
  const errors_1 = require("../../errors.cjs");
6
7
  const utils_1 = require("../../utils/index.cjs");
7
8
  const webpack_1 = require("../../webpack/index.cjs");
8
- const implementation_1 = require("./implementation.cjs");
9
9
  const steps = [
10
10
  {
11
11
  name: 'Checking the input file.',
@@ -1 +1 @@
1
- {"version":3,"file":"watch.cjs","sourceRoot":"","sources":["../../../src/commands/watch/watch.ts"],"names":[],"mappings":";;;AAAA,qDAAoD;AAGpD,6CAA4C;AAE5C,iDAAiD;AACjD,qDAA0C;AAC1C,yDAAyC;AAczC,MAAM,KAAK,GAAwB;IACjC;QACE,IAAI,EAAE,0BAA0B;QAChC,IAAI,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;YACzB,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC;YAEzB,IAAI,CAAC,CAAC,MAAM,IAAA,aAAM,EAAC,KAAK,CAAC,CAAC,EAAE,CAAC;gBAC3B,MAAM,IAAI,qBAAY,CACpB,0BAA0B,KAAK,qEAAqE,CACrG,CAAC;YACJ,CAAC;QACH,CAAC;KACF;IACD;QACE,IAAI,EAAE,kCAAkC;QACxC,SAAS,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO;QAChD,IAAI,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE;YAC3C,MAAM,MAAM,GAAG,IAAA,mBAAS,EAAC,MAAM,CAAC,CAAC;YACjC,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YAEzE,IAAA,YAAI,EAAC,+CAA+C,IAAI,GAAG,EAAE,OAAO,CAAC,CAAC;QACxE,CAAC;KACF;IACD;QACE,IAAI,EAAE,2BAA2B;QACjC,IAAI,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE;YAClC,MAAM,IAAA,sBAAK,EAAC,MAAM,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;QACnC,CAAC;KACF;CACF,CAAC;AAEF;;;;;;;;;GASG;AACI,KAAK,UAAU,YAAY,CAChC,MAAuB,EACvB,OAAqB;IAErB,MAAM,IAAA,oBAAY,EAAC,KAAK,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;AACjD,CAAC;AALD,oCAKC","sourcesContent":["import { isFile } from '@metamask/snaps-utils/node';\n\nimport type { ProcessedConfig, ProcessedWebpackConfig } from '../../config';\nimport { CommandError } from '../../errors';\nimport type { Steps } from '../../utils';\nimport { executeSteps, info } from '../../utils';\nimport { getServer } from '../../webpack';\nimport { watch } from './implementation';\n\ntype WatchOptions = {\n /**\n * The port to listen on.\n */\n port?: number;\n};\n\ntype WatchContext = {\n config: ProcessedWebpackConfig;\n options: WatchOptions;\n};\n\nconst steps: Steps<WatchContext> = [\n {\n name: 'Checking the input file.',\n task: async ({ config }) => {\n const { input } = config;\n\n if (!(await isFile(input))) {\n throw new CommandError(\n `Input file not found: \"${input}\". Make sure that the \"input\" field in your snap config is correct.`,\n );\n }\n },\n },\n {\n name: 'Starting the development server.',\n condition: ({ config }) => config.server.enabled,\n task: async ({ config, options, spinner }) => {\n const server = getServer(config);\n const { port } = await server.listen(options.port ?? config.server.port);\n\n info(`The server is listening on http://localhost:${port}.`, spinner);\n },\n },\n {\n name: 'Building the snap bundle.',\n task: async ({ config, spinner }) => {\n await watch(config, { spinner });\n },\n },\n];\n\n/**\n * Watch a directory and its subdirectories for changes, and build when files\n * are added or changed.\n *\n * Ignores 'node_modules' and dotfiles.\n * Creates destination directory if it doesn't exist.\n *\n * @param config - The config object.\n * @param options - The options object.\n */\nexport async function watchHandler(\n config: ProcessedConfig,\n options: WatchOptions,\n): Promise<void> {\n await executeSteps(steps, { config, options });\n}\n"]}
1
+ {"version":3,"file":"watch.cjs","sourceRoot":"","sources":["../../../src/commands/watch/watch.ts"],"names":[],"mappings":";;;AAAA,qDAAoD;AAEpD,yDAAyC;AAEzC,6CAA4C;AAE5C,iDAAiD;AACjD,qDAA0C;AAc1C,MAAM,KAAK,GAAwB;IACjC;QACE,IAAI,EAAE,0BAA0B;QAChC,IAAI,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;YACzB,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC;YAEzB,IAAI,CAAC,CAAC,MAAM,IAAA,aAAM,EAAC,KAAK,CAAC,CAAC,EAAE,CAAC;gBAC3B,MAAM,IAAI,qBAAY,CACpB,0BAA0B,KAAK,qEAAqE,CACrG,CAAC;YACJ,CAAC;QACH,CAAC;KACF;IACD;QACE,IAAI,EAAE,kCAAkC;QACxC,SAAS,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO;QAChD,IAAI,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE;YAC3C,MAAM,MAAM,GAAG,IAAA,mBAAS,EAAC,MAAM,CAAC,CAAC;YACjC,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YAEzE,IAAA,YAAI,EAAC,+CAA+C,IAAI,GAAG,EAAE,OAAO,CAAC,CAAC;QACxE,CAAC;KACF;IACD;QACE,IAAI,EAAE,2BAA2B;QACjC,IAAI,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE;YAClC,MAAM,IAAA,sBAAK,EAAC,MAAM,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;QACnC,CAAC;KACF;CACF,CAAC;AAEF;;;;;;;;;GASG;AACI,KAAK,UAAU,YAAY,CAChC,MAAuB,EACvB,OAAqB;IAErB,MAAM,IAAA,oBAAY,EAAC,KAAK,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;AACjD,CAAC;AALD,oCAKC","sourcesContent":["import { isFile } from '@metamask/snaps-utils/node';\n\nimport { watch } from './implementation';\nimport type { ProcessedConfig } from '../../config';\nimport { CommandError } from '../../errors';\nimport type { Steps } from '../../utils';\nimport { executeSteps, info } from '../../utils';\nimport { getServer } from '../../webpack';\n\ntype WatchOptions = {\n /**\n * The port to listen on.\n */\n port?: number;\n};\n\ntype WatchContext = {\n config: ProcessedConfig;\n options: WatchOptions;\n};\n\nconst steps: Steps<WatchContext> = [\n {\n name: 'Checking the input file.',\n task: async ({ config }) => {\n const { input } = config;\n\n if (!(await isFile(input))) {\n throw new CommandError(\n `Input file not found: \"${input}\". Make sure that the \"input\" field in your snap config is correct.`,\n );\n }\n },\n },\n {\n name: 'Starting the development server.',\n condition: ({ config }) => config.server.enabled,\n task: async ({ config, options, spinner }) => {\n const server = getServer(config);\n const { port } = await server.listen(options.port ?? config.server.port);\n\n info(`The server is listening on http://localhost:${port}.`, spinner);\n },\n },\n {\n name: 'Building the snap bundle.',\n task: async ({ config, spinner }) => {\n await watch(config, { spinner });\n },\n },\n];\n\n/**\n * Watch a directory and its subdirectories for changes, and build when files\n * are added or changed.\n *\n * Ignores 'node_modules' and dotfiles.\n * Creates destination directory if it doesn't exist.\n *\n * @param config - The config object.\n * @param options - The options object.\n */\nexport async function watchHandler(\n config: ProcessedConfig,\n options: WatchOptions,\n): Promise<void> {\n await executeSteps(steps, { config, options });\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"watch.d.cts","sourceRoot":"","sources":["../../../src/commands/watch/watch.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAA0B,yBAAqB;AAO5E,KAAK,YAAY,GAAG;IAClB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAsCF;;;;;;;;;GASG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,eAAe,EACvB,OAAO,EAAE,YAAY,GACpB,OAAO,CAAC,IAAI,CAAC,CAEf"}
1
+ {"version":3,"file":"watch.d.cts","sourceRoot":"","sources":["../../../src/commands/watch/watch.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,yBAAqB;AAMpD,KAAK,YAAY,GAAG;IAClB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAsCF;;;;;;;;;GASG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,eAAe,EACvB,OAAO,EAAE,YAAY,GACpB,OAAO,CAAC,IAAI,CAAC,CAEf"}
@@ -1 +1 @@
1
- {"version":3,"file":"watch.d.mts","sourceRoot":"","sources":["../../../src/commands/watch/watch.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAA0B,yBAAqB;AAO5E,KAAK,YAAY,GAAG;IAClB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAsCF;;;;;;;;;GASG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,eAAe,EACvB,OAAO,EAAE,YAAY,GACpB,OAAO,CAAC,IAAI,CAAC,CAEf"}
1
+ {"version":3,"file":"watch.d.mts","sourceRoot":"","sources":["../../../src/commands/watch/watch.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,yBAAqB;AAMpD,KAAK,YAAY,GAAG;IAClB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAsCF;;;;;;;;;GASG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,eAAe,EACvB,OAAO,EAAE,YAAY,GACpB,OAAO,CAAC,IAAI,CAAC,CAEf"}
@@ -1,8 +1,8 @@
1
1
  import { isFile } from "@metamask/snaps-utils/node";
2
+ import { watch } from "./implementation.mjs";
2
3
  import { CommandError } from "../../errors.mjs";
3
4
  import { executeSteps, info } from "../../utils/index.mjs";
4
5
  import { getServer } from "../../webpack/index.mjs";
5
- import { watch } from "./implementation.mjs";
6
6
  const steps = [
7
7
  {
8
8
  name: 'Checking the input file.',
@@ -1 +1 @@
1
- {"version":3,"file":"watch.mjs","sourceRoot":"","sources":["../../../src/commands/watch/watch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,mCAAmC;AAGpD,OAAO,EAAE,YAAY,EAAE,yBAAqB;AAE5C,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,8BAAoB;AACjD,OAAO,EAAE,SAAS,EAAE,gCAAsB;AAC1C,OAAO,EAAE,KAAK,EAAE,6BAAyB;AAczC,MAAM,KAAK,GAAwB;IACjC;QACE,IAAI,EAAE,0BAA0B;QAChC,IAAI,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;YACzB,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC;YAEzB,IAAI,CAAC,CAAC,MAAM,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;gBAC3B,MAAM,IAAI,YAAY,CACpB,0BAA0B,KAAK,qEAAqE,CACrG,CAAC;YACJ,CAAC;QACH,CAAC;KACF;IACD;QACE,IAAI,EAAE,kCAAkC;QACxC,SAAS,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO;QAChD,IAAI,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE;YAC3C,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;YACjC,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YAEzE,IAAI,CAAC,+CAA+C,IAAI,GAAG,EAAE,OAAO,CAAC,CAAC;QACxE,CAAC;KACF;IACD;QACE,IAAI,EAAE,2BAA2B;QACjC,IAAI,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE;YAClC,MAAM,KAAK,CAAC,MAAM,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;QACnC,CAAC;KACF;CACF,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,MAAuB,EACvB,OAAqB;IAErB,MAAM,YAAY,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;AACjD,CAAC","sourcesContent":["import { isFile } from '@metamask/snaps-utils/node';\n\nimport type { ProcessedConfig, ProcessedWebpackConfig } from '../../config';\nimport { CommandError } from '../../errors';\nimport type { Steps } from '../../utils';\nimport { executeSteps, info } from '../../utils';\nimport { getServer } from '../../webpack';\nimport { watch } from './implementation';\n\ntype WatchOptions = {\n /**\n * The port to listen on.\n */\n port?: number;\n};\n\ntype WatchContext = {\n config: ProcessedWebpackConfig;\n options: WatchOptions;\n};\n\nconst steps: Steps<WatchContext> = [\n {\n name: 'Checking the input file.',\n task: async ({ config }) => {\n const { input } = config;\n\n if (!(await isFile(input))) {\n throw new CommandError(\n `Input file not found: \"${input}\". Make sure that the \"input\" field in your snap config is correct.`,\n );\n }\n },\n },\n {\n name: 'Starting the development server.',\n condition: ({ config }) => config.server.enabled,\n task: async ({ config, options, spinner }) => {\n const server = getServer(config);\n const { port } = await server.listen(options.port ?? config.server.port);\n\n info(`The server is listening on http://localhost:${port}.`, spinner);\n },\n },\n {\n name: 'Building the snap bundle.',\n task: async ({ config, spinner }) => {\n await watch(config, { spinner });\n },\n },\n];\n\n/**\n * Watch a directory and its subdirectories for changes, and build when files\n * are added or changed.\n *\n * Ignores 'node_modules' and dotfiles.\n * Creates destination directory if it doesn't exist.\n *\n * @param config - The config object.\n * @param options - The options object.\n */\nexport async function watchHandler(\n config: ProcessedConfig,\n options: WatchOptions,\n): Promise<void> {\n await executeSteps(steps, { config, options });\n}\n"]}
1
+ {"version":3,"file":"watch.mjs","sourceRoot":"","sources":["../../../src/commands/watch/watch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,mCAAmC;AAEpD,OAAO,EAAE,KAAK,EAAE,6BAAyB;AAEzC,OAAO,EAAE,YAAY,EAAE,yBAAqB;AAE5C,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,8BAAoB;AACjD,OAAO,EAAE,SAAS,EAAE,gCAAsB;AAc1C,MAAM,KAAK,GAAwB;IACjC;QACE,IAAI,EAAE,0BAA0B;QAChC,IAAI,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;YACzB,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC;YAEzB,IAAI,CAAC,CAAC,MAAM,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;gBAC3B,MAAM,IAAI,YAAY,CACpB,0BAA0B,KAAK,qEAAqE,CACrG,CAAC;YACJ,CAAC;QACH,CAAC;KACF;IACD;QACE,IAAI,EAAE,kCAAkC;QACxC,SAAS,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO;QAChD,IAAI,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE;YAC3C,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;YACjC,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YAEzE,IAAI,CAAC,+CAA+C,IAAI,GAAG,EAAE,OAAO,CAAC,CAAC;QACxE,CAAC;KACF;IACD;QACE,IAAI,EAAE,2BAA2B;QACjC,IAAI,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE;YAClC,MAAM,KAAK,CAAC,MAAM,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;QACnC,CAAC;KACF;CACF,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,MAAuB,EACvB,OAAqB;IAErB,MAAM,YAAY,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;AACjD,CAAC","sourcesContent":["import { isFile } from '@metamask/snaps-utils/node';\n\nimport { watch } from './implementation';\nimport type { ProcessedConfig } from '../../config';\nimport { CommandError } from '../../errors';\nimport type { Steps } from '../../utils';\nimport { executeSteps, info } from '../../utils';\nimport { getServer } from '../../webpack';\n\ntype WatchOptions = {\n /**\n * The port to listen on.\n */\n port?: number;\n};\n\ntype WatchContext = {\n config: ProcessedConfig;\n options: WatchOptions;\n};\n\nconst steps: Steps<WatchContext> = [\n {\n name: 'Checking the input file.',\n task: async ({ config }) => {\n const { input } = config;\n\n if (!(await isFile(input))) {\n throw new CommandError(\n `Input file not found: \"${input}\". Make sure that the \"input\" field in your snap config is correct.`,\n );\n }\n },\n },\n {\n name: 'Starting the development server.',\n condition: ({ config }) => config.server.enabled,\n task: async ({ config, options, spinner }) => {\n const server = getServer(config);\n const { port } = await server.listen(options.port ?? config.server.port);\n\n info(`The server is listening on http://localhost:${port}.`, spinner);\n },\n },\n {\n name: 'Building the snap bundle.',\n task: async ({ config, spinner }) => {\n await watch(config, { spinner });\n },\n },\n];\n\n/**\n * Watch a directory and its subdirectories for changes, and build when files\n * are added or changed.\n *\n * Ignores 'node_modules' and dotfiles.\n * Creates destination directory if it doesn't exist.\n *\n * @param config - The config object.\n * @param options - The options object.\n */\nexport async function watchHandler(\n config: ProcessedConfig,\n options: WatchOptions,\n): Promise<void> {\n await executeSteps(steps, { config, options });\n}\n"]}
package/dist/config.cjs CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getWebpackConfig = exports.mergeLegacyOptions = exports.getConfigByArgv = exports.resolveConfig = exports.loadConfig = exports.getConfig = exports.LegacyOptionsStruct = exports.SnapsConfigStruct = exports.SnapsWebpackConfigStruct = exports.SnapsBrowserifyConfigStruct = void 0;
6
+ exports.getConfigByArgv = exports.resolveConfig = exports.loadConfig = exports.getConfig = exports.SnapsConfigStruct = void 0;
7
7
  const snaps_sdk_1 = require("@metamask/snaps-sdk");
8
8
  const node_1 = require("@metamask/snaps-utils/node");
9
9
  const superstruct_1 = require("@metamask/superstruct");
@@ -13,7 +13,6 @@ const chalk_1 = require("chalk");
13
13
  const promises_1 = require("fs/promises");
14
14
  const module_1 = __importDefault(require("module"));
15
15
  const path_1 = require("path");
16
- const builders_1 = require("./builders.cjs");
17
16
  const errors_1 = require("./errors.cjs");
18
17
  const structs_1 = require("./structs.cjs");
19
18
  const utils_2 = require("./utils/index.cjs");
@@ -21,35 +20,8 @@ const CONFIG_FILES = [utils_2.CONFIG_FILE, utils_2.TS_CONFIG_FILE];
21
20
  // This struct is essentially the same as the `func` struct, but it's defined
22
21
  // separately so that we include the function type in the inferred TypeScript
23
22
  // type definitions.
24
- const SnapsBrowserifyBundlerCustomizerFunctionStruct = (0, superstruct_1.define)('function', (0, superstruct_1.func)().validator);
25
- exports.SnapsBrowserifyConfigStruct = (0, superstruct_1.object)({
26
- bundler: (0, snaps_sdk_1.literal)('browserify'),
27
- cliOptions: (0, superstruct_1.defaulted)((0, superstruct_1.object)({
28
- bundle: (0, superstruct_1.optional)((0, structs_1.file)()),
29
- dist: (0, superstruct_1.defaulted)((0, structs_1.file)(), 'dist'),
30
- eval: (0, superstruct_1.defaulted)((0, superstruct_1.boolean)(), true),
31
- manifest: (0, superstruct_1.defaulted)((0, superstruct_1.boolean)(), true),
32
- port: (0, superstruct_1.defaulted)((0, superstruct_1.number)(), 8081),
33
- outfileName: (0, superstruct_1.defaulted)((0, superstruct_1.string)(), 'bundle.js'),
34
- root: (0, superstruct_1.defaulted)((0, structs_1.file)(), process.cwd()),
35
- sourceMaps: (0, superstruct_1.defaulted)((0, superstruct_1.boolean)(), false),
36
- src: (0, superstruct_1.defaulted)((0, structs_1.file)(), 'src/index.js'),
37
- stripComments: (0, superstruct_1.defaulted)((0, superstruct_1.boolean)(), true),
38
- suppressWarnings: (0, superstruct_1.defaulted)((0, superstruct_1.boolean)(), false),
39
- transpilationMode: (0, superstruct_1.defaulted)((0, snaps_sdk_1.union)([(0, snaps_sdk_1.literal)('localAndDeps'), (0, snaps_sdk_1.literal)('localOnly'), (0, snaps_sdk_1.literal)('none')]), 'localOnly'),
40
- depsToTranspile: (0, superstruct_1.defaulted)((0, superstruct_1.array)((0, superstruct_1.string)()), []),
41
- verboseErrors: (0, superstruct_1.defaulted)((0, superstruct_1.boolean)(), true),
42
- writeManifest: (0, superstruct_1.defaulted)((0, superstruct_1.boolean)(), true),
43
- serve: (0, superstruct_1.defaulted)((0, superstruct_1.boolean)(), true),
44
- }), {}),
45
- bundlerCustomizer: (0, superstruct_1.optional)(SnapsBrowserifyBundlerCustomizerFunctionStruct),
46
- });
47
- // This struct is essentially the same as the `func` struct, but it's defined
48
- // separately so that we include the function type in the inferred TypeScript
49
- // type definitions.
50
23
  const SnapsWebpackCustomizeWebpackConfigFunctionStruct = (0, superstruct_1.define)('function', (0, superstruct_1.func)().validator);
51
- exports.SnapsWebpackConfigStruct = (0, superstruct_1.object)({
52
- bundler: (0, superstruct_1.defaulted)((0, snaps_sdk_1.literal)('webpack'), 'webpack'),
24
+ exports.SnapsConfigStruct = (0, superstruct_1.object)({
53
25
  input: (0, superstruct_1.defaulted)((0, structs_1.file)(), (0, path_1.resolve)(process.cwd(), 'src/index.js')),
54
26
  sourceMap: (0, superstruct_1.defaulted)((0, snaps_sdk_1.union)([(0, superstruct_1.boolean)(), (0, snaps_sdk_1.literal)('inline')]), false),
55
27
  evaluate: (0, superstruct_1.defaulted)((0, superstruct_1.boolean)(), true),
@@ -124,43 +96,17 @@ exports.SnapsWebpackConfigStruct = (0, superstruct_1.object)({
124
96
  wasm: (0, superstruct_1.defaulted)((0, superstruct_1.boolean)(), false),
125
97
  }), {}),
126
98
  });
127
- exports.SnapsConfigStruct = (0, superstruct_1.type)({
128
- bundler: (0, superstruct_1.defaulted)((0, snaps_sdk_1.union)([(0, snaps_sdk_1.literal)('browserify'), (0, snaps_sdk_1.literal)('webpack')]), 'webpack'),
129
- });
130
- exports.LegacyOptionsStruct = (0, snaps_sdk_1.union)([
131
- (0, node_1.named)('object with `transpilationMode` set to `localAndDeps` and `depsToTranspile` set to an array of strings', (0, superstruct_1.type)({
132
- depsToTranspile: (0, superstruct_1.array)((0, superstruct_1.string)()),
133
- transpilationMode: (0, snaps_sdk_1.literal)(builders_1.TranspilationModes.LocalAndDeps),
134
- writeManifest: (0, superstruct_1.boolean)(),
135
- bundlerCustomizer: (0, superstruct_1.optional)(SnapsBrowserifyBundlerCustomizerFunctionStruct),
136
- })),
137
- (0, node_1.named)('object without `depsToTranspile`', (0, superstruct_1.type)({
138
- depsToTranspile: (0, node_1.named)('empty array', (0, superstruct_1.empty)((0, superstruct_1.array)())),
139
- transpilationMode: (0, snaps_sdk_1.union)([
140
- (0, snaps_sdk_1.literal)(builders_1.TranspilationModes.LocalOnly),
141
- (0, snaps_sdk_1.literal)(builders_1.TranspilationModes.None),
142
- ]),
143
- writeManifest: (0, superstruct_1.boolean)(),
144
- bundlerCustomizer: (0, superstruct_1.optional)(SnapsBrowserifyBundlerCustomizerFunctionStruct),
145
- })),
146
- ]);
147
99
  /**
148
100
  * Get a validated snap config. This validates the config and adds default
149
101
  * values for any missing properties.
150
102
  *
151
103
  * @param config - The config to validate.
152
- * @param argv - The CLI arguments.
153
104
  * @returns The validated config.
154
105
  */
155
- function getConfig(config, argv) {
106
+ function getConfig(config) {
156
107
  const prefix = 'The snap config file is invalid';
157
108
  const suffix = (0, chalk_1.dim)('Refer to the documentation for more information: https://docs.metamask.io/snaps/reference/cli/options/');
158
- const { bundler } = (0, node_1.createFromStruct)(config, exports.SnapsConfigStruct, prefix, suffix);
159
- if (bundler === 'browserify') {
160
- const legacyConfig = (0, node_1.createFromStruct)(config, exports.SnapsBrowserifyConfigStruct, prefix, suffix);
161
- return getWebpackConfig(mergeLegacyOptions(argv, legacyConfig));
162
- }
163
- return (0, node_1.createFromStruct)(config, exports.SnapsWebpackConfigStruct, prefix, suffix);
109
+ return (0, node_1.createFromStruct)(config, exports.SnapsConfigStruct, prefix, suffix);
164
110
  }
165
111
  exports.getConfig = getConfig;
166
112
  /**
@@ -171,12 +117,11 @@ exports.getConfig = getConfig;
171
117
  * `module.exports` or `export default`.
172
118
  *
173
119
  * @param path - The full path to the config file.
174
- * @param argv - The CLI arguments.
175
120
  * @returns The validated config.
176
121
  * @throws If the config file is invalid, or if the config file does not have a
177
122
  * default export.
178
123
  */
179
- async function loadConfig(path, argv) {
124
+ async function loadConfig(path) {
180
125
  try {
181
126
  const contents = await (0, promises_1.readFile)(path, 'utf8');
182
127
  const source = await (0, core_1.transform)(contents, {
@@ -196,9 +141,9 @@ async function loadConfig(path, argv) {
196
141
  // @ts-expect-error - This function is not typed.
197
142
  config._compile(source.code, path);
198
143
  if (!(0, utils_1.hasProperty)(config.exports, 'default')) {
199
- return getConfig(config.exports, argv);
144
+ return getConfig(config.exports);
200
145
  }
201
- return getConfig(config.exports.default, argv);
146
+ return getConfig(config.exports.default);
202
147
  }
203
148
  catch (error) {
204
149
  if (error instanceof node_1.SnapsStructError) {
@@ -214,15 +159,14 @@ exports.loadConfig = loadConfig;
214
159
  *
215
160
  * @param path - The path to resolve the snap config from. Defaults to the
216
161
  * current working directory.
217
- * @param argv - The CLI arguments.
218
162
  * @returns The resolved and validated snap config.
219
163
  * @throws If a snap config could not be found.
220
164
  */
221
- async function resolveConfig(path, argv) {
165
+ async function resolveConfig(path) {
222
166
  for (const configFile of CONFIG_FILES) {
223
167
  const filePath = (0, path_1.resolve)(path, configFile);
224
168
  if (await (0, node_1.isFile)(filePath)) {
225
- return await loadConfig(filePath, argv);
169
+ return await loadConfig(filePath);
226
170
  }
227
171
  }
228
172
  throw new errors_1.ConfigError(`Could not find a "snap.config.js" or "snap.config.ts" file in the current or specified directory ("${path}").`);
@@ -242,97 +186,9 @@ async function getConfigByArgv(argv, cwd = process.cwd()) {
242
186
  if (!(await (0, node_1.isFile)(argv.config))) {
243
187
  throw new errors_1.ConfigError(`Could not find a config file at "${argv.config}". Make sure that the path is correct.`);
244
188
  }
245
- return await loadConfig(argv.config, argv);
189
+ return await loadConfig(argv.config);
246
190
  }
247
- return await resolveConfig(cwd, argv);
191
+ return await resolveConfig(cwd);
248
192
  }
249
193
  exports.getConfigByArgv = getConfigByArgv;
250
- /**
251
- * Merge legacy CLI options into the config. This is used to support the legacy
252
- * config format, where options can be specified both in the config file and
253
- * through CLI flags.
254
- *
255
- * @param argv - The CLI arguments.
256
- * @param config - The config to merge the CLI options into.
257
- * @returns The config with the CLI options merged in.
258
- * @deprecated This function is only used to support the legacy config format.
259
- */
260
- function mergeLegacyOptions(argv, config) {
261
- const cliOptions = Object.keys(config.cliOptions).reduce((accumulator, key) => {
262
- if (argv[key] !== undefined) {
263
- return {
264
- ...accumulator,
265
- [key]: argv[key],
266
- };
267
- }
268
- return accumulator;
269
- }, config.cliOptions);
270
- return {
271
- ...config,
272
- cliOptions,
273
- };
274
- }
275
- exports.mergeLegacyOptions = mergeLegacyOptions;
276
- /**
277
- * Get a Webpack config from a legacy browserify config. This is used to
278
- * support the legacy config format, and convert it to the new format.
279
- *
280
- * @param legacyConfig - The legacy browserify config.
281
- * @returns The Webpack config.
282
- */
283
- function getWebpackConfig(legacyConfig) {
284
- const defaultConfig = (0, superstruct_1.create)({ bundler: 'webpack' }, exports.SnapsWebpackConfigStruct);
285
- // The legacy config has two options for specifying the output path and
286
- // filename: `bundle`, and `dist` + `outfileName`. If `bundle` is specified,
287
- // we use that as the output path and filename. Otherwise, we use `dist` and
288
- // `outfileName`.
289
- const path = legacyConfig.cliOptions.bundle
290
- ? (0, path_1.dirname)(legacyConfig.cliOptions.bundle)
291
- : legacyConfig.cliOptions.dist;
292
- const filename = legacyConfig.cliOptions.bundle
293
- ? (0, path_1.basename)(legacyConfig.cliOptions.bundle)
294
- : legacyConfig.cliOptions.outfileName;
295
- return {
296
- ...defaultConfig,
297
- input: legacyConfig.cliOptions.src,
298
- evaluate: legacyConfig.cliOptions.eval,
299
- sourceMap: legacyConfig.cliOptions.sourceMaps,
300
- output: {
301
- path,
302
- filename,
303
- // The legacy config has an option to remove comments from the bundle, but
304
- // the terser plugin does this by default, so we only enable the terser if
305
- // the legacy config has `stripComments` set to `true`. This is not a
306
- // perfect solution, but it's the best we can do without breaking the
307
- // legacy config.
308
- minimize: legacyConfig.cliOptions.stripComments,
309
- // The legacy config does not have a `clean` option, so we default to
310
- // `false` here.
311
- clean: false,
312
- },
313
- manifest: {
314
- // The legacy config does not have a `manifest` option, so we default to
315
- // `process.cwd()/snap.manifest.json`.
316
- path: (0, path_1.resolve)(process.cwd(), 'snap.manifest.json'),
317
- update: legacyConfig.cliOptions.writeManifest,
318
- },
319
- server: {
320
- enabled: legacyConfig.cliOptions.serve,
321
- port: legacyConfig.cliOptions.port,
322
- root: legacyConfig.cliOptions.root,
323
- },
324
- stats: {
325
- verbose: false,
326
- // These plugins are designed to be used with the modern config format, so
327
- // we disable them for the legacy config format.
328
- builtIns: false,
329
- buffer: false,
330
- },
331
- legacy: (0, node_1.createFromStruct)({
332
- ...legacyConfig.cliOptions,
333
- bundlerCustomizer: legacyConfig.bundlerCustomizer,
334
- }, exports.LegacyOptionsStruct, 'Invalid Browserify CLI options'),
335
- };
336
- }
337
- exports.getWebpackConfig = getWebpackConfig;
338
194
  //# sourceMappingURL=config.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.cjs","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;;;;;AAAA,mDAAqD;AACrD,qDAMoC;AACpC,uDAe+B;AAE/B,2CAA8C;AAC9C,oCAAsC;AAEtC,iCAA4B;AAC5B,0CAAuC;AACvC,oDAA4B;AAC5B,+BAAkD;AAGlD,6CAAgD;AAChD,yCAAuC;AACvC,2CAAiC;AAEjC,6CAAsD;AAEtD,MAAM,YAAY,GAAG,CAAC,mBAAW,EAAE,sBAAc,CAAC,CAAC;AAqenD,6EAA6E;AAC7E,6EAA6E;AAC7E,oBAAoB;AACpB,MAAM,8CAA8C,GAClD,IAAA,oBAAM,EACJ,UAAU,EACV,IAAA,kBAAI,GAAE,CAAC,SAAS,CACjB,CAAC;AAES,QAAA,2BAA2B,GAAG,IAAA,oBAAM,EAAC;IAChD,OAAO,EAAE,IAAA,mBAAO,EAAC,YAAY,CAAC;IAC9B,UAAU,EAAE,IAAA,uBAAS,EACnB,IAAA,oBAAM,EAAC;QACL,MAAM,EAAE,IAAA,sBAAQ,EAAC,IAAA,cAAI,GAAE,CAAC;QACxB,IAAI,EAAE,IAAA,uBAAS,EAAC,IAAA,cAAI,GAAE,EAAE,MAAM,CAAC;QAC/B,IAAI,EAAE,IAAA,uBAAS,EAAC,IAAA,qBAAO,GAAE,EAAE,IAAI,CAAC;QAChC,QAAQ,EAAE,IAAA,uBAAS,EAAC,IAAA,qBAAO,GAAE,EAAE,IAAI,CAAC;QACpC,IAAI,EAAE,IAAA,uBAAS,EAAC,IAAA,oBAAM,GAAE,EAAE,IAAI,CAAC;QAC/B,WAAW,EAAE,IAAA,uBAAS,EAAC,IAAA,oBAAM,GAAE,EAAE,WAAW,CAAC;QAC7C,IAAI,EAAE,IAAA,uBAAS,EAAC,IAAA,cAAI,GAAE,EA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U,CAAC,IAAI;QACtC,SAAS,EAAE,YAAY,CAAC,UAAU,CAAC,UAAU;QAC7C,MAAM,EAAE;YACN,IAAI;YACJ,QAAQ;YAER,0EAA0E;YAC1E,0EAA0E;YAC1E,qEAAqE;YACrE,qEAAqE;YACrE,iBAAiB;YACjB,QAAQ,EAAE,YAAY,CAAC,UAAU,CAAC,aAAa;YAE/C,qEAAqE;YACrE,gBAAgB;YAChB,KAAK,EAAE,KAAK;SACb;QACD,QAAQ,EAAE;YACR,wEAAwE;YACxE,sCAAsC;YACtC,IAAI,EAAE,IAAA,cAAO,EAAC,OAAO,CAAC,GAAG,EAAE,EAAE,oBAAoB,CAAC;YAClD,MAAM,EAAE,YAAY,CAAC,UAAU,CAAC,aAAa;SAC9C;QACD,MAAM,EAAE;YACN,OAAO,EAAE,YAAY,CAAC,UAAU,CAAC,KAAK;YACtC,IAAI,EAAE,YAAY,CAAC,UAAU,CAAC,IAAI;YAClC,IAAI,EAAE,YAAY,CAAC,UAAU,CAAC,IAAI;SACnC;QACD,KAAK,EAAE;YACL,OAAO,EAAE,KAAK;YAEd,0EAA0E;YAC1E,gDAAgD;YAChD,QAAQ,EAAE,KAAK;YACf,MAAM,EAAE,KAAK;SACd;QACD,MAAM,EAAE,IAAA,uBAAgB,EACtB;YACE,GAAG,YAAY,CAAC,UAAU;YAC1B,iBAAiB,EAAE,YAAY,CAAC,iBAAiB;SAClD,EACD,2BAAmB,EACnB,gCAAgC,CACjC;KACF,CAAC;AACJ,CAAC;AApED,4CAoEC","sourcesContent":["import { literal, union } from '@metamask/snaps-sdk';\nimport {\n createFromStruct,\n indent,\n isFile,\n SnapsStructError,\n named,\n} from '@metamask/snaps-utils/node';\nimport {\n array,\n boolean,\n create,\n defaulted,\n define,\n func,\n number,\n object,\n optional,\n record,\n string,\n type,\n unknown,\n empty,\n} from '@metamask/superstruct';\nimport type { Infer } from '@metamask/superstruct';\nimport { hasProperty } from '@metamask/utils';\nimport { transform } from '@swc/core';\nimport type { BrowserifyObject } from 'browserify';\nimport { dim } from 'chalk';\nimport { readFile } from 'fs/promises';\nimport Module from 'module';\nimport { basename, dirname, resolve } from 'path';\nimport type { Configuration as WebpackConfiguration } from 'webpack';\n\nimport { TranspilationModes } from './builders';\nimport { ConfigError } from './errors';\nimport { file } from './structs';\nimport type { YargsArgs } from './types/yargs';\nimport { CONFIG_FILE, TS_CONFIG_FILE } from './utils';\n\nconst CONFIG_FILES = [CONFIG_FILE, TS_CONFIG_FILE];\n\n/**\n * The configuration for the Snaps CLI, stored as `snap.config.js` or\n * `snap.config.ts` in the root of the project.\n *\n * @deprecated The Browserify bundler is deprecated and will be removed in a\n * future release. Use the Webpack bundler instead.\n */\nexport type SnapBrowserifyConfig = {\n /**\n * The bundler to use to build the snap. For backwards compatibility, if not\n * specified, Browserify will be used. However, the Browserify bundler is\n * deprecated and will be removed in a future release, so it's recommended to\n * use the Webpack bundler instead.\n */\n bundler: 'browserify';\n\n /**\n * The options for the Snaps CLI. These are merged with the options passed to\n * the CLI, with the CLI options taking precedence.\n *\n * @deprecated The Browserify bundler is deprecated and will be removed in a\n * future release. Use the Webpack bundler instead.\n */\n cliOptions?: {\n /**\n * The path to the snap bundle file.\n *\n * @default 'dist/bundle.js'\n */\n bundle?: string;\n\n /**\n * The directory to output the snap to. This is only used if `bundle` is\n * not specified.\n *\n * @default 'dist'\n */\n dist?: string;\n\n /**\n * Whether to attempt to evaluate the snap in SES. This can catch some errors\n * that would otherwise only be caught at runtime.\n *\n * @default true\n */\n eval?: boolean;\n\n /**\n * Whether to validate the snap manifest.\n *\n * @default true\n */\n manifest?: boolean;\n\n /**\n * The name of the bundle file. This is only used if `bundle` is not\n * specified.\n *\n * @default 'bundle.js'\n */\n outfileName?: string;\n\n /**\n * The port to run the server on.\n *\n * @default 8081\n */\n port?: number;\n\n /**\n * The root directory to serve the snap from.\n *\n * @default `process.cwd()`\n */\n root?: string;\n\n /**\n * Whether to generate source maps for the snap bundle.\n *\n * @default false\n */\n sourceMaps?: boolean;\n\n /**\n * The path to the snap entry point.\n *\n * @default 'src/index.js'\n */\n src?: string;\n\n /**\n * Whether to remove comments from the bundle.\n *\n * @default true\n */\n stripComments?: boolean;\n\n /**\n * Whether to suppress warnings.\n *\n * @default false\n */\n suppressWarnings?: boolean;\n\n /**\n * The transpilation mode to use, which determines which files are\n * transpiled.\n *\n * - `'localAndDeps'`: Transpile the snap entry point and all dependencies.\n * - `'localOnly'`: Transpile only the snap entry point.\n * - `'none'`: Don't transpile any files.\n *\n * @default 'localOnly'\n */\n transpilationMode?: 'localAndDeps' | 'localOnly' | 'none';\n\n /**\n * The dependencies to transpile when `transpilationMode` is set to\n * `'localAndDeps'`. If not specified, all dependencies will be transpiled.\n */\n depsToTranspile?: string[];\n\n /**\n * Whether to show original errors.\n *\n * @default true\n */\n verboseErrors?: boolean;\n\n /**\n * Whether to write the updated manifest to disk.\n *\n * @default true\n */\n writeManifest?: boolean;\n\n /**\n * Whether to serve the snap locally.\n *\n * @default true\n */\n serve?: boolean;\n };\n\n /**\n * A function that can be used to customize the Browserify instance used to\n * build the snap.\n *\n * @param bundler - The Browserify instance.\n * @deprecated The Browserify bundler is deprecated and will be removed in a\n * future release. Use the Webpack bundler instead.\n */\n bundlerCustomizer?: (bundler: BrowserifyObject) => void;\n};\n\n/**\n * The configuration for the Snaps CLI, stored as `snap.config.js` or\n * `snap.config.ts` in the root of the project.\n */\nexport type SnapWebpackConfig = {\n /**\n * The bundler to use to build the snap. For backwards compatibility, if not\n * specified, Browserify will be used. However, the Browserify bundler is\n * deprecated and will be removed in a future release, so it's recommended to\n * use the Webpack bundler instead.\n */\n bundler?: 'webpack';\n\n /**\n * The path to the snap entry point. This should be a JavaScript or TypeScript\n * file.\n */\n input: string;\n\n /**\n * Whether to generate source maps for the snap. If `true`, source maps will\n * be generated as separate files. If `'inline'`, source maps will be\n * inlined in the generated JavaScript bundle.\n *\n * @default true\n */\n sourceMap?: boolean | 'inline';\n\n /**\n * Whether to attempt to evaluate the snap in SES. This can catch some errors\n * that would otherwise only be caught at runtime.\n *\n * @default true\n */\n evaluate?: boolean;\n\n output?: {\n /**\n * The path to the directory where the snap will be built. This directory\n * will be created if it doesn't exist.\n *\n * If the path is relative, it will be resolved relative to the current\n * working directory.\n *\n * @default 'dist'\n */\n path?: string;\n\n /**\n * The name of the JavaScript bundle file.\n *\n * @default 'bundle.js'\n */\n filename?: string;\n\n /**\n * Whether to clean the output directory before building the snap. If\n * `true`, the output directory will be deleted and recreated. Otherwise,\n * the output directory will be left as-is.\n *\n * @default false\n */\n clean?: boolean;\n\n /**\n * Whether to minimize the snap bundle. If `true`, the bundle will be\n * minified. Otherwise, the bundle will be left as-is.\n *\n * @default true\n */\n minimize?: boolean;\n };\n\n manifest?: {\n /**\n * The path to the snap manifest file. If the path is relative, it will be\n * resolved relative to the current working directory.\n *\n * @default 'snap.manifest.json'\n */\n path?: string;\n\n /**\n * Whether to automatically update the manifest. If `true`, the manifest\n * will be updated with the latest shasum of the snap bundle, and some\n * common fields will be updated if they are missing or incorrect. If\n * `false`, the manifest will be left as-is.\n *\n * @default true\n */\n update?: boolean;\n };\n\n server?: {\n /**\n * Whether to enable the local server. If `true`, the snap will be served\n * from a local server, when running the `watch` command. If `false`, the\n * snap will not be served.\n *\n * @default true\n */\n enabled?: boolean;\n\n /**\n * The root directory to serve the snap from. If the path is relative, it\n * will be resolved relative to the current working directory.\n *\n * @default `process.cwd()`\n */\n root?: string;\n\n /**\n * The port to run the server on.\n *\n * @default 8081\n */\n port?: number;\n };\n\n /**\n * The environment variables to set when building the snap. These will be\n * available in the snap as `process.env`. In addition to these environment\n * variables, the following environment variables will always be set:\n *\n * - `NODE_DEBUG`: `false`\n * - `NODE_ENV`: `'production'`\n * - `DEBUG`: `false`\n *\n * Any environment variables specified here will override these defaults. You\n * can also override any variables here by setting them in your shell when\n * running the CLI.\n */\n environment?: Record<string, unknown>;\n\n /**\n * Options that control the logging output of the CLI.\n */\n stats?: {\n /**\n * Whether to enable verbose logging.\n *\n * @default false\n */\n verbose?: boolean;\n\n /**\n * Whether to log warnings about unresolved built-in modules. If `false`,\n * warnings will not be logged.\n */\n builtIns?:\n | {\n /**\n * The built-in modules to ignore when resolving modules. If a module\n * is ignored, no warning will be logged if it is not resolved.\n */\n ignore?: string[];\n }\n | false;\n\n /**\n * Whether to log warnings about the use of the `Buffer` global. If `false`,\n * warnings will not be logged. If `true`, the CLI will warn if the `Buffer`\n * global is used, but not provided by Webpack's `DefinePlugin`.\n */\n buffer?: boolean;\n };\n\n /**\n * Whether to provide polyfills for node builtins. If `true`, all the available\n * polyfills will be provided. If `false` no polyfills will be provided. If a\n * configuration object is passed only the polyfills set to `true` will be provided.\n *\n * @default false\n * @example\n * ```ts\n * polyfills: true\n *\n * // or\n *\n * polyfills: {\n * assert: true,\n * buffer: true\n * }\n * ```\n */\n polyfills?:\n | boolean\n | {\n assert?: boolean;\n buffer?: boolean;\n console?: boolean;\n constants?: boolean;\n crypto?: boolean;\n domain?: boolean;\n events?: boolean;\n http?: boolean;\n https?: boolean;\n os?: boolean;\n path?: boolean;\n punycode?: boolean;\n process?: boolean;\n querystring?: boolean;\n stream?: boolean;\n /* eslint-disable @typescript-eslint/naming-convention */\n _stream_duplex?: boolean;\n _stream_passthrough?: boolean;\n _stream_readable?: boolean;\n _stream_transform?: boolean;\n _stream_writable?: boolean;\n string_decoder?: boolean;\n /* eslint-enable @typescript-eslint/naming-convention */\n sys?: boolean;\n timers?: boolean;\n tty?: boolean;\n url?: boolean;\n util?: boolean;\n vm?: boolean;\n zlib?: boolean;\n };\n\n /**\n * Support for TypeScript type-checking feature.\n *\n * @example\n * {\n * enabled: true;\n * configFile: './path/to/tsconfig.json'\n * }\n */\n typescript?: {\n /**\n * Whether to enable TypeScript type-checking feature.\n *\n * @default false\n */\n enabled?: boolean;\n /**\n * Path to tsconfig.json file for the Snap.\n *\n * @default 'tsconfig.json'\n */\n configFile?: string;\n };\n\n /**\n * Optional features to enable in the CLI.\n *\n * @example\n * {\n * features: {\n * images: true,\n * }\n * }\n */\n features?: {\n /**\n * Whether to enable support for images. If `true`, the Webpack\n * configuration will be modified to support images. If `false`, the\n * Webpack configuration will not be modified.\n *\n * @default true\n */\n images?: boolean;\n };\n\n /**\n * A function to customize the Webpack configuration used to build the snap.\n * This function will be called with the default Webpack configuration, and\n * should return the modified configuration. If not specified, the default\n * configuration will be used.\n *\n * It's recommended to use the `webpack-merge` package to merge the default\n * configuration with your customizations. The merge function is exported as\n * `merge` from the `@metamask/snaps-cli` package.\n *\n * @example\n * ```ts\n * import type { SnapsConfig } from '@metamask/snaps-cli';\n * import { merge } from '@metamask/snaps-cli';\n *\n * const config: SnapsConfig = {\n * bundler: 'webpack',\n * entry: 'src/index.ts',\n * customizeWebpackConfig: (config) => merge(config, {\n * module: {\n * rules: [\n * {\n * test: /\\.wasm$/,\n * type: 'assets/resource',\n * },\n * ],\n * },\n * }),\n * };\n *\n * export default config;\n * ```\n */\n customizeWebpackConfig?: (\n config: WebpackConfiguration,\n ) => WebpackConfiguration;\n\n /**\n * Experimental features that can be enabled. These features are not\n * guaranteed to be stable, and may be removed or changed in a future release.\n */\n experimental?: {\n /**\n * Whether to enable WebAssembly support. If `true`, the Webpack\n * configuration will be modified to support WebAssembly. If `false`, the\n * Webpack configuration will not be modified.\n *\n * @default false\n */\n wasm?: boolean;\n };\n};\n\n/**\n * The configuration for the Snaps CLI, stored as `snap.config.js` or\n * `snap.config.ts` in the root of the project.\n */\nexport type SnapConfig = SnapBrowserifyConfig | SnapWebpackConfig;\n\ntype SnapsBrowserifyBundlerCustomizerFunction = (\n bundler: BrowserifyObject,\n) => void;\n\n// This struct is essentially the same as the `func` struct, but it's defined\n// separately so that we include the function type in the inferred TypeScript\n// type definitions.\nconst SnapsBrowserifyBundlerCustomizerFunctionStruct =\n define<SnapsBrowserifyBundlerCustomizerFunction>(\n 'function',\n func().validator,\n );\n\nexport const SnapsBrowserifyConfigStruct = object({\n bundler: literal('browserify'),\n cliOptions: defaulted(\n object({\n bundle: optional(file()),\n dist: defaulted(file(), 'dist'),\n eval: defaulted(boolean(), true),\n manifest: defaulted(boolean(), true),\n port: defaulted(number(), 8081),\n outfileName: defaulted(string(), 'bundle.js'),\n root: defaulted(file(), process.cwd()),\n sourceMaps: defaulted(boolean(), false),\n src: defaulted(file(), 'src/index.js'),\n stripComments: defaulted(boolean(), true),\n suppressWarnings: defaulted(boolean(), false),\n transpilationMode: defaulted(\n union([literal('localAndDeps'), literal('localOnly'), literal('none')]),\n 'localOnly',\n ),\n depsToTranspile: defaulted(array(string()), []),\n verboseErrors: defaulted(boolean(), true),\n writeManifest: defaulted(boolean(), true),\n serve: defaulted(boolean(), true),\n }),\n {},\n ),\n bundlerCustomizer: optional(SnapsBrowserifyBundlerCustomizerFunctionStruct),\n});\n\ntype SnapsWebpackCustomizeWebpackConfigFunction = (\n config: WebpackConfiguration,\n) => WebpackConfiguration;\n\n// This struct is essentially the same as the `func` struct, but it's defined\n// separately so that we include the function type in the inferred TypeScript\n// type definitions.\nconst SnapsWebpackCustomizeWebpackConfigFunctionStruct =\n define<SnapsWebpackCustomizeWebpackConfigFunction>(\n 'function',\n func().validator,\n );\n\nexport const SnapsWebpackConfigStruct = object({\n bundler: defaulted(literal('webpack'), 'webpack'),\n input: defaulted(file(), resolve(process.cwd(), 'src/index.js')),\n sourceMap: defaulted(union([boolean(), literal('inline')]), false),\n evaluate: defaulted(boolean(), true),\n\n output: defaulted(\n object({\n path: defaulted(file(), resolve(process.cwd(), 'dist')),\n filename: defaulted(string(), 'bundle.js'),\n clean: defaulted(boolean(), false),\n minimize: defaulted(boolean(), true),\n }),\n {},\n ),\n\n manifest: defaulted(\n object({\n path: defaulted(file(), resolve(process.cwd(), 'snap.manifest.json')),\n update: defaulted(boolean(), true),\n }),\n {},\n ),\n\n server: defaulted(\n object({\n enabled: defaulted(boolean(), true),\n root: defaulted(file(), process.cwd()),\n port: defaulted(number(), 8081),\n }),\n {},\n ),\n\n environment: defaulted(record(string(), unknown()), {}),\n\n stats: defaulted(\n object({\n verbose: defaulted(boolean(), false),\n builtIns: defaulted(\n union([\n object({ ignore: defaulted(array(string()), []) }),\n literal(false),\n ]),\n {},\n ),\n buffer: defaulted(boolean(), true),\n }),\n {},\n ),\n\n polyfills: defaulted(\n union([\n boolean(),\n object({\n assert: defaulted(boolean(), false),\n buffer: defaulted(boolean(), false),\n console: defaulted(boolean(), false),\n constants: defaulted(boolean(), false),\n crypto: defaulted(boolean(), false),\n domain: defaulted(boolean(), false),\n events: defaulted(boolean(), false),\n http: defaulted(boolean(), false),\n https: defaulted(boolean(), false),\n os: defaulted(boolean(), false),\n path: defaulted(boolean(), false),\n punycode: defaulted(boolean(), false),\n process: defaulted(boolean(), false),\n querystring: defaulted(boolean(), false),\n stream: defaulted(boolean(), false),\n /* eslint-disable @typescript-eslint/naming-convention */\n _stream_duplex: defaulted(boolean(), false),\n _stream_passthrough: defaulted(boolean(), false),\n _stream_readable: defaulted(boolean(), false),\n _stream_transform: defaulted(boolean(), false),\n _stream_writable: defaulted(boolean(), false),\n string_decoder: defaulted(boolean(), false),\n /* eslint-enable @typescript-eslint/naming-convention */\n sys: defaulted(boolean(), false),\n timers: defaulted(boolean(), false),\n tty: defaulted(boolean(), false),\n url: defaulted(boolean(), false),\n util: defaulted(boolean(), false),\n vm: defaulted(boolean(), false),\n zlib: defaulted(boolean(), false),\n }),\n ]),\n false,\n ),\n\n typescript: defaulted(\n object({\n enabled: defaulted(boolean(), false),\n configFile: defaulted(file(), 'tsconfig.json'),\n }),\n {},\n ),\n\n features: defaulted(\n object({\n images: defaulted(boolean(), true),\n }),\n {},\n ),\n\n customizeWebpackConfig: optional(\n SnapsWebpackCustomizeWebpackConfigFunctionStruct,\n ),\n\n experimental: defaulted(\n object({\n wasm: defaulted(boolean(), false),\n }),\n {},\n ),\n});\n\nexport const SnapsConfigStruct = type({\n bundler: defaulted(\n union([literal('browserify'), literal('webpack')]),\n 'webpack',\n ),\n});\n\nexport const LegacyOptionsStruct = union([\n named(\n 'object with `transpilationMode` set to `localAndDeps` and `depsToTranspile` set to an array of strings',\n type({\n depsToTranspile: array(string()),\n transpilationMode: literal(TranspilationModes.LocalAndDeps),\n writeManifest: boolean(),\n bundlerCustomizer: optional(\n SnapsBrowserifyBundlerCustomizerFunctionStruct,\n ),\n }),\n ),\n named(\n 'object without `depsToTranspile`',\n type({\n depsToTranspile: named('empty array', empty(array())),\n transpilationMode: union([\n literal(TranspilationModes.LocalOnly),\n literal(TranspilationModes.None),\n ]),\n writeManifest: boolean(),\n bundlerCustomizer: optional(\n SnapsBrowserifyBundlerCustomizerFunctionStruct,\n ),\n }),\n ),\n]);\n\nexport type LegacyOptions = Infer<typeof LegacyOptionsStruct>;\n\nexport type ProcessedBrowserifyConfig = Infer<\n typeof SnapsBrowserifyConfigStruct\n>;\n\nexport type ProcessedWebpackConfig = Infer<typeof SnapsWebpackConfigStruct> & {\n /**\n * The legacy Browserify config, if the bundler is Browserify. This is used\n * to support the legacy config format.\n */\n legacy?: LegacyOptions;\n};\n\nexport type ProcessedConfig = ProcessedWebpackConfig;\n\n/**\n * Get a validated snap config. This validates the config and adds default\n * values for any missing properties.\n *\n * @param config - The config to validate.\n * @param argv - The CLI arguments.\n * @returns The validated config.\n */\nexport function getConfig(config: unknown, argv: YargsArgs): ProcessedConfig {\n const prefix = 'The snap config file is invalid';\n const suffix = dim(\n 'Refer to the documentation for more information: https://docs.metamask.io/snaps/reference/cli/options/',\n );\n\n const { bundler } = createFromStruct(\n config,\n SnapsConfigStruct,\n prefix,\n suffix,\n );\n\n if (bundler === 'browserify') {\n const legacyConfig = createFromStruct(\n config,\n SnapsBrowserifyConfigStruct,\n prefix,\n suffix,\n );\n\n return getWebpackConfig(mergeLegacyOptions(argv, legacyConfig));\n }\n\n return createFromStruct(config, SnapsWebpackConfigStruct, prefix, suffix);\n}\n\n/**\n * Load a snap config from a file. This supports both JavaScript and TypeScript\n * config files, in the CommonJS module format and the ES module format.\n *\n * This assumes that the config file exports a default object, either through\n * `module.exports` or `export default`.\n *\n * @param path - The full path to the config file.\n * @param argv - The CLI arguments.\n * @returns The validated config.\n * @throws If the config file is invalid, or if the config file does not have a\n * default export.\n */\nexport async function loadConfig(path: string, argv: YargsArgs) {\n try {\n const contents = await readFile(path, 'utf8');\n const source = await transform(contents, {\n swcrc: false,\n jsc: {\n parser: {\n syntax: 'typescript',\n },\n },\n module: {\n type: 'commonjs',\n },\n });\n\n const config = new Module(path);\n\n // @ts-expect-error - This function is not typed.\n config.paths = Module._nodeModulePaths(dirname(path));\n\n // @ts-expect-error - This function is not typed.\n config._compile(source.code, path);\n\n if (!hasProperty(config.exports, 'default')) {\n return getConfig(config.exports, argv);\n }\n\n return getConfig(config.exports.default, argv);\n } catch (error) {\n if (error instanceof SnapsStructError) {\n throw new ConfigError(error.message);\n }\n\n throw new ConfigError(\n `Unable to load snap config file at \"${path}\".\\n\\n${indent(\n error.message,\n )}`,\n );\n }\n}\n\n/**\n * Resolve a snap config. This function will look for a `snap.config.js` or\n * `snap.config.ts` file in the current or specified directory.\n *\n * @param path - The path to resolve the snap config from. Defaults to the\n * current working directory.\n * @param argv - The CLI arguments.\n * @returns The resolved and validated snap config.\n * @throws If a snap config could not be found.\n */\nexport async function resolveConfig(path: string, argv: YargsArgs) {\n for (const configFile of CONFIG_FILES) {\n const filePath = resolve(path, configFile);\n if (await isFile(filePath)) {\n return await loadConfig(filePath, argv);\n }\n }\n\n throw new ConfigError(\n `Could not find a \"snap.config.js\" or \"snap.config.ts\" file in the current or specified directory (\"${path}\").`,\n );\n}\n\n/**\n * Get a snap config from the CLI arguments. This will either load the config\n * from the specified config file, or resolve the config from the current\n * working directory.\n *\n * @param argv - The CLI arguments.\n * @param cwd - The current working directory. Defaults to `process.cwd()`.\n * @returns The resolved and validated snap config.\n */\nexport async function getConfigByArgv(\n argv: YargsArgs,\n cwd: string = process.cwd(),\n) {\n if (argv.config) {\n if (!(await isFile(argv.config))) {\n throw new ConfigError(\n `Could not find a config file at \"${argv.config}\". Make sure that the path is correct.`,\n );\n }\n\n return await loadConfig(argv.config, argv);\n }\n\n return await resolveConfig(cwd, argv);\n}\n\n/**\n * Merge legacy CLI options into the config. This is used to support the legacy\n * config format, where options can be specified both in the config file and\n * through CLI flags.\n *\n * @param argv - The CLI arguments.\n * @param config - The config to merge the CLI options into.\n * @returns The config with the CLI options merged in.\n * @deprecated This function is only used to support the legacy config format.\n */\nexport function mergeLegacyOptions(\n argv: YargsArgs,\n config: ProcessedBrowserifyConfig,\n) {\n const cliOptions = Object.keys(config.cliOptions).reduce<\n ProcessedBrowserifyConfig['cliOptions']\n >((accumulator, key) => {\n if (argv[key] !== undefined) {\n return {\n ...accumulator,\n [key]: argv[key],\n };\n }\n\n return accumulator;\n }, config.cliOptions);\n\n return {\n ...config,\n cliOptions,\n };\n}\n\n/**\n * Get a Webpack config from a legacy browserify config. This is used to\n * support the legacy config format, and convert it to the new format.\n *\n * @param legacyConfig - The legacy browserify config.\n * @returns The Webpack config.\n */\nexport function getWebpackConfig(\n legacyConfig: ProcessedBrowserifyConfig,\n): ProcessedWebpackConfig {\n const defaultConfig = create(\n { bundler: 'webpack' },\n SnapsWebpackConfigStruct,\n );\n\n // The legacy config has two options for specifying the output path and\n // filename: `bundle`, and `dist` + `outfileName`. If `bundle` is specified,\n // we use that as the output path and filename. Otherwise, we use `dist` and\n // `outfileName`.\n const path = legacyConfig.cliOptions.bundle\n ? dirname(legacyConfig.cliOptions.bundle)\n : legacyConfig.cliOptions.dist;\n\n const filename = legacyConfig.cliOptions.bundle\n ? basename(legacyConfig.cliOptions.bundle)\n : legacyConfig.cliOptions.outfileName;\n\n return {\n ...defaultConfig,\n input: legacyConfig.cliOptions.src,\n evaluate: legacyConfig.cliOptions.eval,\n sourceMap: legacyConfig.cliOptions.sourceMaps,\n output: {\n path,\n filename,\n\n // The legacy config has an option to remove comments from the bundle, but\n // the terser plugin does this by default, so we only enable the terser if\n // the legacy config has `stripComments` set to `true`. This is not a\n // perfect solution, but it's the best we can do without breaking the\n // legacy config.\n minimize: legacyConfig.cliOptions.stripComments,\n\n // The legacy config does not have a `clean` option, so we default to\n // `false` here.\n clean: false,\n },\n manifest: {\n // The legacy config does not have a `manifest` option, so we default to\n // `process.cwd()/snap.manifest.json`.\n path: resolve(process.cwd(), 'snap.manifest.json'),\n update: legacyConfig.cliOptions.writeManifest,\n },\n server: {\n enabled: legacyConfig.cliOptions.serve,\n port: legacyConfig.cliOptions.port,\n root: legacyConfig.cliOptions.root,\n },\n stats: {\n verbose: false,\n\n // These plugins are designed to be used with the modern config format, so\n // we disable them for the legacy config format.\n builtIns: false,\n buffer: false,\n },\n legacy: createFromStruct(\n {\n ...legacyConfig.cliOptions,\n bundlerCustomizer: legacyConfig.bundlerCustomizer,\n },\n LegacyOptionsStruct,\n 'Invalid Browserify CLI options',\n ),\n };\n}\n"]}
1
+ {"version":3,"file":"config.cjs","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;;;;;AAAA,mDAAqD;AACrD,qDAKoC;AACpC,uDAY+B;AAE/B,2CAA8C;AAC9C,oCAAsC;AACtC,iCAA4B;AAC5B,0CAAuC;AACvC,oDAA4B;AAC5B,+BAAwC;AAGxC,yCAAuC;AACvC,2CAAiC;AAEjC,6CAAsD;AAEtD,MAAM,YAAY,GAAG,CAAC,mBAAW,EAAE,sBAAc,CAAC,CAAC;AA4TnD,6EAA6E;AAC7E,6EAA6E;AAC7E,oBAAoB;AACpB,MAAM,gDAAgD,GACpD,IAAA,oBAAM,EACJ,UAAU,EACV,IAAA,kBAAI,GAAE,CAAC,SAAS,CACjB,CAAC;AAES,QAAA,iBAAiB,GAAG,IAAA,oBAAM,EAAC;IACtC,KAAK,EAAE,IAAA,uBAAS,EAAC,IAAA,cAAI,GAAE,EAAE,IAAA,cAAO,EAAC,OAAO,CAAC,GAAG,EAAE,EAAE,cAAc,CAAC,CAAC;IAChE,SAAS,EAAE,IAAA,uBAAS,EAAC,IAAA,iBAAK,EAAC,CAAC,IAAA,qBAA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GAQG;AACI,KAAK,UAAU,aAAa,CAAC,IAAY;IAC9C,KAAK,MAAM,UAAU,IAAI,YAAY,EAAE,CAAC;QACtC,MAAM,QAAQ,GAAG,IAAA,cAAO,EAAC,IAAI,EAAE,UAAU,CAAC,CAAC;QAC3C,IAAI,MAAM,IAAA,aAAM,EAAC,QAAQ,CAAC,EAAE,CAAC;YAC3B,OAAO,MAAM,UAAU,CAAC,QAAQ,CAAC,CAAC;QACpC,CAAC;IACH,CAAC;IAED,MAAM,IAAI,oBAAW,CACnB,sGAAsG,IAAI,KAAK,CAChH,CAAC;AACJ,CAAC;AAXD,sCAWC;AAED;;;;;;;;GAQG;AACI,KAAK,UAAU,eAAe,CACnC,IAAe,EACf,MAAc,OAAO,CAAC,GAAG,EAAE;IAE3B,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;QAChB,IAAI,CAAC,CAAC,MAAM,IAAA,aAAM,EAAC,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC;YACjC,MAAM,IAAI,oBAAW,CACnB,oCAAoC,IAAI,CAAC,MAAM,wCAAwC,CACxF,CAAC;QACJ,CAAC;QAED,OAAO,MAAM,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACvC,CAAC;IAED,OAAO,MAAM,aAAa,CAAC,GAAG,CAAC,CAAC;AAClC,CAAC;AAfD,0CAeC","sourcesContent":["import { literal, union } from '@metamask/snaps-sdk';\nimport {\n createFromStruct,\n indent,\n isFile,\n SnapsStructError,\n} from '@metamask/snaps-utils/node';\nimport {\n array,\n boolean,\n defaulted,\n define,\n func,\n number,\n object,\n optional,\n record,\n string,\n unknown,\n} from '@metamask/superstruct';\nimport type { Infer } from '@metamask/superstruct';\nimport { hasProperty } from '@metamask/utils';\nimport { transform } from '@swc/core';\nimport { dim } from 'chalk';\nimport { readFile } from 'fs/promises';\nimport Module from 'module';\nimport { dirname, resolve } from 'path';\nimport type { Configuration as WebpackConfiguration } from 'webpack';\n\nimport { ConfigError } from './errors';\nimport { file } from './structs';\nimport type { YargsArgs } from './types/yargs';\nimport { CONFIG_FILE, TS_CONFIG_FILE } from './utils';\n\nconst CONFIG_FILES = [CONFIG_FILE, TS_CONFIG_FILE];\n\n/**\n * The configuration for the Snaps CLI, stored as `snap.config.js` or\n * `snap.config.ts` in the root of the project.\n */\nexport type SnapConfig = {\n /**\n * The path to the snap entry point. This should be a JavaScript or TypeScript\n * file.\n */\n input: string;\n\n /**\n * Whether to generate source maps for the snap. If `true`, source maps will\n * be generated as separate files. If `'inline'`, source maps will be\n * inlined in the generated JavaScript bundle.\n *\n * @default true\n */\n sourceMap?: boolean | 'inline';\n\n /**\n * Whether to attempt to evaluate the snap in SES. This can catch some errors\n * that would otherwise only be caught at runtime.\n *\n * @default true\n */\n evaluate?: boolean;\n\n output?: {\n /**\n * The path to the directory where the snap will be built. This directory\n * will be created if it doesn't exist.\n *\n * If the path is relative, it will be resolved relative to the current\n * working directory.\n *\n * @default 'dist'\n */\n path?: string;\n\n /**\n * The name of the JavaScript bundle file.\n *\n * @default 'bundle.js'\n */\n filename?: string;\n\n /**\n * Whether to clean the output directory before building the snap. If\n * `true`, the output directory will be deleted and recreated. Otherwise,\n * the output directory will be left as-is.\n *\n * @default false\n */\n clean?: boolean;\n\n /**\n * Whether to minimize the snap bundle. If `true`, the bundle will be\n * minified. Otherwise, the bundle will be left as-is.\n *\n * @default true\n */\n minimize?: boolean;\n };\n\n manifest?: {\n /**\n * The path to the snap manifest file. If the path is relative, it will be\n * resolved relative to the current working directory.\n *\n * @default 'snap.manifest.json'\n */\n path?: string;\n\n /**\n * Whether to automatically update the manifest. If `true`, the manifest\n * will be updated with the latest shasum of the snap bundle, and some\n * common fields will be updated if they are missing or incorrect. If\n * `false`, the manifest will be left as-is.\n *\n * @default true\n */\n update?: boolean;\n };\n\n server?: {\n /**\n * Whether to enable the local server. If `true`, the snap will be served\n * from a local server, when running the `watch` command. If `false`, the\n * snap will not be served.\n *\n * @default true\n */\n enabled?: boolean;\n\n /**\n * The root directory to serve the snap from. If the path is relative, it\n * will be resolved relative to the current working directory.\n *\n * @default `process.cwd()`\n */\n root?: string;\n\n /**\n * The port to run the server on.\n *\n * @default 8081\n */\n port?: number;\n };\n\n /**\n * The environment variables to set when building the snap. These will be\n * available in the snap as `process.env`. In addition to these environment\n * variables, the following environment variables will always be set:\n *\n * - `NODE_DEBUG`: `false`\n * - `NODE_ENV`: `'production'`\n * - `DEBUG`: `false`\n *\n * Any environment variables specified here will override these defaults. You\n * can also override any variables here by setting them in your shell when\n * running the CLI.\n */\n environment?: Record<string, unknown>;\n\n /**\n * Options that control the logging output of the CLI.\n */\n stats?: {\n /**\n * Whether to enable verbose logging.\n *\n * @default false\n */\n verbose?: boolean;\n\n /**\n * Whether to log warnings about unresolved built-in modules. If `false`,\n * warnings will not be logged.\n */\n builtIns?:\n | {\n /**\n * The built-in modules to ignore when resolving modules. If a module\n * is ignored, no warning will be logged if it is not resolved.\n */\n ignore?: string[];\n }\n | false;\n\n /**\n * Whether to log warnings about the use of the `Buffer` global. If `false`,\n * warnings will not be logged. If `true`, the CLI will warn if the `Buffer`\n * global is used, but not provided by Webpack's `DefinePlugin`.\n */\n buffer?: boolean;\n };\n\n /**\n * Whether to provide polyfills for node builtins. If `true`, all the available\n * polyfills will be provided. If `false` no polyfills will be provided. If a\n * configuration object is passed only the polyfills set to `true` will be provided.\n *\n * @default false\n * @example\n * ```ts\n * polyfills: true\n *\n * // or\n *\n * polyfills: {\n * assert: true,\n * buffer: true\n * }\n * ```\n */\n polyfills?:\n | boolean\n | {\n assert?: boolean;\n buffer?: boolean;\n console?: boolean;\n constants?: boolean;\n crypto?: boolean;\n domain?: boolean;\n events?: boolean;\n http?: boolean;\n https?: boolean;\n os?: boolean;\n path?: boolean;\n punycode?: boolean;\n process?: boolean;\n querystring?: boolean;\n stream?: boolean;\n /* eslint-disable @typescript-eslint/naming-convention */\n _stream_duplex?: boolean;\n _stream_passthrough?: boolean;\n _stream_readable?: boolean;\n _stream_transform?: boolean;\n _stream_writable?: boolean;\n string_decoder?: boolean;\n /* eslint-enable @typescript-eslint/naming-convention */\n sys?: boolean;\n timers?: boolean;\n tty?: boolean;\n url?: boolean;\n util?: boolean;\n vm?: boolean;\n zlib?: boolean;\n };\n\n /**\n * Support for TypeScript type-checking feature.\n *\n * @example\n * {\n * enabled: true;\n * configFile: './path/to/tsconfig.json'\n * }\n */\n typescript?: {\n /**\n * Whether to enable TypeScript type-checking feature.\n *\n * @default false\n */\n enabled?: boolean;\n /**\n * Path to tsconfig.json file for the Snap.\n *\n * @default 'tsconfig.json'\n */\n configFile?: string;\n };\n\n /**\n * Optional features to enable in the CLI.\n *\n * @example\n * {\n * features: {\n * images: true,\n * }\n * }\n */\n features?: {\n /**\n * Whether to enable support for images. If `true`, the Webpack\n * configuration will be modified to support images. If `false`, the\n * Webpack configuration will not be modified.\n *\n * @default true\n */\n images?: boolean;\n };\n\n /**\n * A function to customize the Webpack configuration used to build the snap.\n * This function will be called with the default Webpack configuration, and\n * should return the modified configuration. If not specified, the default\n * configuration will be used.\n *\n * It's recommended to use the `webpack-merge` package to merge the default\n * configuration with your customizations. The merge function is exported as\n * `merge` from the `@metamask/snaps-cli` package.\n *\n * @example\n * ```ts\n * import type { SnapsConfig } from '@metamask/snaps-cli';\n * import { merge } from '@metamask/snaps-cli';\n *\n * const config: SnapsConfig = {\n * bundler: 'webpack',\n * entry: 'src/index.ts',\n * customizeWebpackConfig: (config) => merge(config, {\n * module: {\n * rules: [\n * {\n * test: /\\.wasm$/,\n * type: 'assets/resource',\n * },\n * ],\n * },\n * }),\n * };\n *\n * export default config;\n * ```\n */\n customizeWebpackConfig?: (\n config: WebpackConfiguration,\n ) => WebpackConfiguration;\n\n /**\n * Experimental features that can be enabled. These features are not\n * guaranteed to be stable, and may be removed or changed in a future release.\n */\n experimental?: {\n /**\n * Whether to enable WebAssembly support. If `true`, the Webpack\n * configuration will be modified to support WebAssembly. If `false`, the\n * Webpack configuration will not be modified.\n *\n * @default false\n */\n wasm?: boolean;\n };\n};\n\ntype SnapsWebpackCustomizeWebpackConfigFunction = (\n config: WebpackConfiguration,\n) => WebpackConfiguration;\n\n// This struct is essentially the same as the `func` struct, but it's defined\n// separately so that we include the function type in the inferred TypeScript\n// type definitions.\nconst SnapsWebpackCustomizeWebpackConfigFunctionStruct =\n define<SnapsWebpackCustomizeWebpackConfigFunction>(\n 'function',\n func().validator,\n );\n\nexport const SnapsConfigStruct = object({\n input: defaulted(file(), resolve(process.cwd(), 'src/index.js')),\n sourceMap: defaulted(union([boolean(), literal('inline')]), false),\n evaluate: defaulted(boolean(), true),\n\n output: defaulted(\n object({\n path: defaulted(file(), resolve(process.cwd(), 'dist')),\n filename: defaulted(string(), 'bundle.js'),\n clean: defaulted(boolean(), false),\n minimize: defaulted(boolean(), true),\n }),\n {},\n ),\n\n manifest: defaulted(\n object({\n path: defaulted(file(), resolve(process.cwd(), 'snap.manifest.json')),\n update: defaulted(boolean(), true),\n }),\n {},\n ),\n\n server: defaulted(\n object({\n enabled: defaulted(boolean(), true),\n root: defaulted(file(), process.cwd()),\n port: defaulted(number(), 8081),\n }),\n {},\n ),\n\n environment: defaulted(record(string(), unknown()), {}),\n\n stats: defaulted(\n object({\n verbose: defaulted(boolean(), false),\n builtIns: defaulted(\n union([\n object({ ignore: defaulted(array(string()), []) }),\n literal(false),\n ]),\n {},\n ),\n buffer: defaulted(boolean(), true),\n }),\n {},\n ),\n\n polyfills: defaulted(\n union([\n boolean(),\n object({\n assert: defaulted(boolean(), false),\n buffer: defaulted(boolean(), false),\n console: defaulted(boolean(), false),\n constants: defaulted(boolean(), false),\n crypto: defaulted(boolean(), false),\n domain: defaulted(boolean(), false),\n events: defaulted(boolean(), false),\n http: defaulted(boolean(), false),\n https: defaulted(boolean(), false),\n os: defaulted(boolean(), false),\n path: defaulted(boolean(), false),\n punycode: defaulted(boolean(), false),\n process: defaulted(boolean(), false),\n querystring: defaulted(boolean(), false),\n stream: defaulted(boolean(), false),\n /* eslint-disable @typescript-eslint/naming-convention */\n _stream_duplex: defaulted(boolean(), false),\n _stream_passthrough: defaulted(boolean(), false),\n _stream_readable: defaulted(boolean(), false),\n _stream_transform: defaulted(boolean(), false),\n _stream_writable: defaulted(boolean(), false),\n string_decoder: defaulted(boolean(), false),\n /* eslint-enable @typescript-eslint/naming-convention */\n sys: defaulted(boolean(), false),\n timers: defaulted(boolean(), false),\n tty: defaulted(boolean(), false),\n url: defaulted(boolean(), false),\n util: defaulted(boolean(), false),\n vm: defaulted(boolean(), false),\n zlib: defaulted(boolean(), false),\n }),\n ]),\n false,\n ),\n\n typescript: defaulted(\n object({\n enabled: defaulted(boolean(), false),\n configFile: defaulted(file(), 'tsconfig.json'),\n }),\n {},\n ),\n\n features: defaulted(\n object({\n images: defaulted(boolean(), true),\n }),\n {},\n ),\n\n customizeWebpackConfig: optional(\n SnapsWebpackCustomizeWebpackConfigFunctionStruct,\n ),\n\n experimental: defaulted(\n object({\n wasm: defaulted(boolean(), false),\n }),\n {},\n ),\n});\n\nexport type ProcessedConfig = Infer<typeof SnapsConfigStruct>;\n\n/**\n * Get a validated snap config. This validates the config and adds default\n * values for any missing properties.\n *\n * @param config - The config to validate.\n * @returns The validated config.\n */\nexport function getConfig(config: unknown): ProcessedConfig {\n const prefix = 'The snap config file is invalid';\n const suffix = dim(\n 'Refer to the documentation for more information: https://docs.metamask.io/snaps/reference/cli/options/',\n );\n\n return createFromStruct(config, SnapsConfigStruct, prefix, suffix);\n}\n\n/**\n * Load a snap config from a file. This supports both JavaScript and TypeScript\n * config files, in the CommonJS module format and the ES module format.\n *\n * This assumes that the config file exports a default object, either through\n * `module.exports` or `export default`.\n *\n * @param path - The full path to the config file.\n * @returns The validated config.\n * @throws If the config file is invalid, or if the config file does not have a\n * default export.\n */\nexport async function loadConfig(path: string) {\n try {\n const contents = await readFile(path, 'utf8');\n const source = await transform(contents, {\n swcrc: false,\n jsc: {\n parser: {\n syntax: 'typescript',\n },\n },\n module: {\n type: 'commonjs',\n },\n });\n\n const config = new Module(path);\n\n // @ts-expect-error - This function is not typed.\n config.paths = Module._nodeModulePaths(dirname(path));\n\n // @ts-expect-error - This function is not typed.\n config._compile(source.code, path);\n\n if (!hasProperty(config.exports, 'default')) {\n return getConfig(config.exports);\n }\n\n return getConfig(config.exports.default);\n } catch (error) {\n if (error instanceof SnapsStructError) {\n throw new ConfigError(error.message);\n }\n\n throw new ConfigError(\n `Unable to load snap config file at \"${path}\".\\n\\n${indent(\n error.message,\n )}`,\n );\n }\n}\n\n/**\n * Resolve a snap config. This function will look for a `snap.config.js` or\n * `snap.config.ts` file in the current or specified directory.\n *\n * @param path - The path to resolve the snap config from. Defaults to the\n * current working directory.\n * @returns The resolved and validated snap config.\n * @throws If a snap config could not be found.\n */\nexport async function resolveConfig(path: string) {\n for (const configFile of CONFIG_FILES) {\n const filePath = resolve(path, configFile);\n if (await isFile(filePath)) {\n return await loadConfig(filePath);\n }\n }\n\n throw new ConfigError(\n `Could not find a \"snap.config.js\" or \"snap.config.ts\" file in the current or specified directory (\"${path}\").`,\n );\n}\n\n/**\n * Get a snap config from the CLI arguments. This will either load the config\n * from the specified config file, or resolve the config from the current\n * working directory.\n *\n * @param argv - The CLI arguments.\n * @param cwd - The current working directory. Defaults to `process.cwd()`.\n * @returns The resolved and validated snap config.\n */\nexport async function getConfigByArgv(\n argv: YargsArgs,\n cwd: string = process.cwd(),\n) {\n if (argv.config) {\n if (!(await isFile(argv.config))) {\n throw new ConfigError(\n `Could not find a config file at \"${argv.config}\". Make sure that the path is correct.`,\n );\n }\n\n return await loadConfig(argv.config);\n }\n\n return await resolveConfig(cwd);\n}\n"]}