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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (256) hide show
  1. package/.browserslistrc +3 -0
  2. package/CHANGELOG.md +20 -426
  3. package/README.md +539 -63
  4. package/dist/cjs/builders.js +40 -41
  5. package/dist/cjs/builders.js.map +1 -1
  6. package/dist/cjs/cli.js +14 -14
  7. package/dist/cjs/cli.js.map +1 -1
  8. package/dist/cjs/commands/build/build.js +54 -0
  9. package/dist/cjs/commands/build/build.js.map +1 -0
  10. package/dist/cjs/commands/build/implementation.js +31 -0
  11. package/dist/cjs/commands/build/implementation.js.map +1 -0
  12. package/dist/cjs/{cmds → commands}/build/index.js +18 -5
  13. package/dist/cjs/commands/build/index.js.map +1 -0
  14. package/dist/cjs/commands/eval/eval.js +57 -0
  15. package/dist/cjs/commands/eval/eval.js.map +1 -0
  16. package/dist/cjs/commands/eval/implementation.js +27 -0
  17. package/dist/cjs/commands/eval/implementation.js.map +1 -0
  18. package/dist/cjs/commands/eval/index.js +50 -0
  19. package/dist/cjs/commands/eval/index.js.map +1 -0
  20. package/dist/cjs/commands/index.js.map +1 -0
  21. package/dist/cjs/commands/manifest/implementation.js +34 -0
  22. package/dist/cjs/commands/manifest/implementation.js.map +1 -0
  23. package/dist/cjs/commands/manifest/index.js +50 -0
  24. package/dist/cjs/commands/manifest/index.js.map +1 -0
  25. package/dist/cjs/commands/manifest/manifest.js +55 -0
  26. package/dist/cjs/commands/manifest/manifest.js.map +1 -0
  27. package/dist/cjs/{cmds → commands}/serve/index.js +4 -2
  28. package/dist/cjs/commands/serve/index.js.map +1 -0
  29. package/dist/cjs/commands/serve/serve.js +21 -0
  30. package/dist/cjs/commands/serve/serve.js.map +1 -0
  31. package/dist/cjs/commands/watch/implementation.js +35 -0
  32. package/dist/cjs/commands/watch/implementation.js.map +1 -0
  33. package/dist/cjs/{cmds → commands}/watch/index.js +19 -4
  34. package/dist/cjs/commands/watch/index.js.map +1 -0
  35. package/dist/cjs/commands/watch/watch.js +51 -0
  36. package/dist/cjs/commands/watch/watch.js.map +1 -0
  37. package/dist/cjs/config.js +290 -0
  38. package/dist/cjs/config.js.map +1 -0
  39. package/dist/cjs/errors.js +37 -0
  40. package/dist/cjs/errors.js.map +1 -0
  41. package/dist/cjs/index.js +28 -3
  42. package/dist/cjs/index.js.map +1 -1
  43. package/dist/cjs/main.js +6 -7
  44. package/dist/cjs/main.js.map +1 -1
  45. package/dist/cjs/utils/cli.js +61 -0
  46. package/dist/cjs/utils/cli.js.map +1 -0
  47. package/dist/cjs/utils/errors.js +42 -0
  48. package/dist/cjs/utils/errors.js.map +1 -0
  49. package/dist/cjs/utils/index.js +6 -2
  50. package/dist/cjs/utils/index.js.map +1 -1
  51. package/dist/cjs/utils/legacy.js +48 -0
  52. package/dist/cjs/utils/legacy.js.map +1 -0
  53. package/dist/cjs/utils/logging.js +46 -0
  54. package/dist/cjs/utils/logging.js.map +1 -0
  55. package/dist/cjs/utils/path.js +16 -0
  56. package/dist/cjs/utils/path.js.map +1 -0
  57. package/dist/cjs/utils/steps.js +52 -0
  58. package/dist/cjs/utils/steps.js.map +1 -0
  59. package/dist/cjs/webpack/compiler.js +96 -0
  60. package/dist/cjs/webpack/compiler.js.map +1 -0
  61. package/dist/cjs/webpack/config.js +234 -0
  62. package/dist/cjs/webpack/config.js.map +1 -0
  63. package/dist/cjs/webpack/index.js +22 -0
  64. package/dist/cjs/webpack/index.js.map +1 -0
  65. package/dist/cjs/webpack/loaders/browserify.js +97 -0
  66. package/dist/cjs/webpack/loaders/browserify.js.map +1 -0
  67. package/dist/cjs/webpack/loaders/wasm.js +36 -0
  68. package/dist/cjs/webpack/loaders/wasm.js.map +1 -0
  69. package/dist/cjs/webpack/plugins.js +340 -0
  70. package/dist/cjs/webpack/plugins.js.map +1 -0
  71. package/dist/cjs/webpack/utils.js +133 -0
  72. package/dist/cjs/webpack/utils.js.map +1 -0
  73. package/dist/esm/builders.js +40 -41
  74. package/dist/esm/builders.js.map +1 -1
  75. package/dist/esm/cli.js +15 -15
  76. package/dist/esm/cli.js.map +1 -1
  77. package/dist/esm/commands/build/build.js +51 -0
  78. package/dist/esm/commands/build/build.js.map +1 -0
  79. package/dist/esm/commands/build/implementation.js +27 -0
  80. package/dist/esm/commands/build/implementation.js.map +1 -0
  81. package/dist/esm/{cmds → commands}/build/index.js +5 -5
  82. package/dist/esm/commands/build/index.js.map +1 -0
  83. package/dist/esm/commands/eval/eval.js +54 -0
  84. package/dist/esm/commands/eval/eval.js.map +1 -0
  85. package/dist/esm/commands/eval/implementation.js +24 -0
  86. package/dist/esm/commands/eval/implementation.js.map +1 -0
  87. package/dist/esm/commands/eval/index.js +22 -0
  88. package/dist/esm/commands/eval/index.js.map +1 -0
  89. package/dist/esm/commands/index.js +15 -0
  90. package/dist/esm/commands/index.js.map +1 -0
  91. package/dist/esm/commands/manifest/implementation.js +33 -0
  92. package/dist/esm/commands/manifest/implementation.js.map +1 -0
  93. package/dist/esm/commands/manifest/index.js +22 -0
  94. package/dist/esm/commands/manifest/index.js.map +1 -0
  95. package/dist/esm/commands/manifest/manifest.js +52 -0
  96. package/dist/esm/commands/manifest/manifest.js.map +1 -0
  97. package/dist/esm/{cmds → commands}/serve/index.js +4 -2
  98. package/dist/esm/commands/serve/index.js.map +1 -0
  99. package/dist/esm/commands/serve/serve.js +17 -0
  100. package/dist/esm/commands/serve/serve.js.map +1 -0
  101. package/dist/esm/commands/watch/implementation.js +34 -0
  102. package/dist/esm/commands/watch/implementation.js.map +1 -0
  103. package/dist/esm/{cmds → commands}/watch/index.js +6 -4
  104. package/dist/esm/commands/watch/index.js.map +1 -0
  105. package/dist/esm/commands/watch/watch.js +50 -0
  106. package/dist/esm/commands/watch/watch.js.map +1 -0
  107. package/dist/esm/config.js +294 -0
  108. package/dist/esm/config.js.map +1 -0
  109. package/dist/esm/errors.js +30 -0
  110. package/dist/esm/errors.js.map +1 -0
  111. package/dist/esm/index.js +3 -0
  112. package/dist/esm/index.js.map +1 -1
  113. package/dist/esm/main.js +6 -7
  114. package/dist/esm/main.js.map +1 -1
  115. package/dist/esm/utils/cli.js +43 -0
  116. package/dist/esm/utils/cli.js.map +1 -0
  117. package/dist/esm/utils/errors.js +43 -0
  118. package/dist/esm/utils/errors.js.map +1 -0
  119. package/dist/esm/utils/index.js +6 -2
  120. package/dist/esm/utils/index.js.map +1 -1
  121. package/dist/esm/utils/legacy.js +47 -0
  122. package/dist/esm/utils/legacy.js.map +1 -0
  123. package/dist/esm/utils/logging.js +40 -0
  124. package/dist/esm/utils/logging.js.map +1 -0
  125. package/dist/esm/utils/path.js +13 -0
  126. package/dist/esm/utils/path.js.map +1 -0
  127. package/dist/esm/utils/steps.js +43 -0
  128. package/dist/esm/utils/steps.js.map +1 -0
  129. package/dist/esm/webpack/compiler.js +89 -0
  130. package/dist/esm/webpack/compiler.js.map +1 -0
  131. package/dist/esm/webpack/config.js +236 -0
  132. package/dist/esm/webpack/config.js.map +1 -0
  133. package/dist/esm/webpack/index.js +5 -0
  134. package/dist/esm/webpack/index.js.map +1 -0
  135. package/dist/esm/webpack/loaders/browserify.js +82 -0
  136. package/dist/esm/webpack/loaders/browserify.js.map +1 -0
  137. package/dist/esm/webpack/loaders/wasm.js +26 -0
  138. package/dist/esm/webpack/loaders/wasm.js.map +1 -0
  139. package/dist/esm/webpack/plugins.js +343 -0
  140. package/dist/esm/webpack/plugins.js.map +1 -0
  141. package/dist/esm/webpack/utils.js +160 -0
  142. package/dist/esm/webpack/utils.js.map +1 -0
  143. package/dist/types/__fixtures__/configs/cjs.d.ts +1 -0
  144. package/dist/types/__fixtures__/configs/esm.d.ts +3 -0
  145. package/dist/types/__fixtures__/configs/invalid.d.ts +3 -0
  146. package/dist/types/__fixtures__/configs/javascript/snap.config.d.ts +0 -0
  147. package/dist/types/__fixtures__/configs/typescript/snap.config.d.ts +3 -0
  148. package/dist/types/builders.d.ts +2 -21
  149. package/dist/types/cli.d.ts +1 -1
  150. package/dist/types/commands/build/build.d.ts +10 -0
  151. package/dist/types/commands/build/implementation.d.ts +10 -0
  152. package/dist/types/{cmds/eval → commands/build}/index.d.ts +1 -0
  153. package/dist/types/commands/eval/__test__/browserify/bad/snap.config.d.ts +3 -0
  154. package/dist/types/commands/eval/__test__/browserify/good/snap.config.d.ts +3 -0
  155. package/dist/types/commands/eval/__test__/webpack/bad/snap.config.d.ts +3 -0
  156. package/dist/types/commands/eval/__test__/webpack/good/snap.config.d.ts +3 -0
  157. package/dist/types/commands/eval/__test__/webpack/snap.config.d.ts +3 -0
  158. package/dist/types/commands/eval/eval.d.ts +14 -0
  159. package/dist/types/commands/eval/implementation.d.ts +9 -0
  160. package/dist/types/{cmds/serve → commands/eval}/index.d.ts +1 -0
  161. package/dist/types/commands/manifest/implementation.d.ts +12 -0
  162. package/dist/types/{cmds → commands}/manifest/index.d.ts +1 -0
  163. package/dist/types/commands/manifest/manifest.d.ts +14 -0
  164. package/dist/types/commands/serve/serve.d.ts +16 -0
  165. package/dist/types/commands/watch/implementation.d.ts +14 -0
  166. package/dist/types/commands/watch/index.d.ts +10 -0
  167. package/dist/types/commands/watch/watch.d.ts +19 -0
  168. package/dist/types/config.d.ts +626 -0
  169. package/dist/types/errors.d.ts +25 -0
  170. package/dist/types/index.d.ts +4 -0
  171. package/dist/types/utils/cli.d.ts +17 -0
  172. package/dist/types/utils/errors.d.ts +23 -0
  173. package/dist/types/utils/index.d.ts +6 -2
  174. package/dist/types/utils/legacy.d.ts +27 -0
  175. package/dist/types/utils/logging.d.ts +22 -0
  176. package/dist/types/utils/path.d.ts +9 -0
  177. package/dist/types/utils/steps.d.ts +17 -0
  178. package/dist/types/webpack/compiler.d.ts +29 -0
  179. package/dist/types/webpack/config.d.ts +37 -0
  180. package/dist/types/webpack/index.d.ts +3 -0
  181. package/dist/types/webpack/loaders/browserify.d.ts +16 -0
  182. package/dist/types/webpack/loaders/wasm.d.ts +20 -0
  183. package/dist/types/webpack/plugins.d.ts +147 -0
  184. package/dist/types/webpack/utils.d.ts +156 -0
  185. package/package.json +15 -7
  186. package/dist/cjs/cmds/build/buildHandler.js +0 -36
  187. package/dist/cjs/cmds/build/buildHandler.js.map +0 -1
  188. package/dist/cjs/cmds/build/bundle.js +0 -83
  189. package/dist/cjs/cmds/build/bundle.js.map +0 -1
  190. package/dist/cjs/cmds/build/index.js.map +0 -1
  191. package/dist/cjs/cmds/build/utils.js +0 -79
  192. package/dist/cjs/cmds/build/utils.js.map +0 -1
  193. package/dist/cjs/cmds/eval/evalHandler.js +0 -24
  194. package/dist/cjs/cmds/eval/evalHandler.js.map +0 -1
  195. package/dist/cjs/cmds/eval/index.js +0 -31
  196. package/dist/cjs/cmds/eval/index.js.map +0 -1
  197. package/dist/cjs/cmds/index.js.map +0 -1
  198. package/dist/cjs/cmds/manifest/index.js +0 -44
  199. package/dist/cjs/cmds/manifest/index.js.map +0 -1
  200. package/dist/cjs/cmds/manifest/manifestHandler.js +0 -47
  201. package/dist/cjs/cmds/manifest/manifestHandler.js.map +0 -1
  202. package/dist/cjs/cmds/serve/index.js.map +0 -1
  203. package/dist/cjs/cmds/serve/serveHandler.js +0 -62
  204. package/dist/cjs/cmds/serve/serveHandler.js.map +0 -1
  205. package/dist/cjs/cmds/serve/serveUtils.js +0 -37
  206. package/dist/cjs/cmds/serve/serveUtils.js.map +0 -1
  207. package/dist/cjs/cmds/watch/index.js.map +0 -1
  208. package/dist/cjs/cmds/watch/watchHandler.js +0 -91
  209. package/dist/cjs/cmds/watch/watchHandler.js.map +0 -1
  210. package/dist/cjs/utils/misc.js +0 -142
  211. package/dist/cjs/utils/misc.js.map +0 -1
  212. package/dist/cjs/utils/snap-config.js +0 -104
  213. package/dist/cjs/utils/snap-config.js.map +0 -1
  214. package/dist/esm/cmds/build/buildHandler.js +0 -36
  215. package/dist/esm/cmds/build/buildHandler.js.map +0 -1
  216. package/dist/esm/cmds/build/bundle.js +0 -81
  217. package/dist/esm/cmds/build/bundle.js.map +0 -1
  218. package/dist/esm/cmds/build/index.js.map +0 -1
  219. package/dist/esm/cmds/build/utils.js +0 -88
  220. package/dist/esm/cmds/build/utils.js.map +0 -1
  221. package/dist/esm/cmds/eval/evalHandler.js +0 -20
  222. package/dist/esm/cmds/eval/evalHandler.js.map +0 -1
  223. package/dist/esm/cmds/eval/index.js +0 -16
  224. package/dist/esm/cmds/eval/index.js.map +0 -1
  225. package/dist/esm/cmds/index.js +0 -15
  226. package/dist/esm/cmds/index.js.map +0 -1
  227. package/dist/esm/cmds/manifest/index.js +0 -29
  228. package/dist/esm/cmds/manifest/index.js.map +0 -1
  229. package/dist/esm/cmds/manifest/manifestHandler.js +0 -44
  230. package/dist/esm/cmds/manifest/manifestHandler.js.map +0 -1
  231. package/dist/esm/cmds/serve/index.js.map +0 -1
  232. package/dist/esm/cmds/serve/serveHandler.js +0 -54
  233. package/dist/esm/cmds/serve/serveHandler.js.map +0 -1
  234. package/dist/esm/cmds/serve/serveUtils.js +0 -30
  235. package/dist/esm/cmds/serve/serveUtils.js.map +0 -1
  236. package/dist/esm/cmds/watch/index.js.map +0 -1
  237. package/dist/esm/cmds/watch/watchHandler.js +0 -87
  238. package/dist/esm/cmds/watch/watchHandler.js.map +0 -1
  239. package/dist/esm/utils/misc.js +0 -139
  240. package/dist/esm/utils/misc.js.map +0 -1
  241. package/dist/esm/utils/snap-config.js +0 -107
  242. package/dist/esm/utils/snap-config.js.map +0 -1
  243. package/dist/types/cmds/build/buildHandler.d.ts +0 -13
  244. package/dist/types/cmds/build/bundle.d.ts +0 -15
  245. package/dist/types/cmds/build/utils.d.ts +0 -56
  246. package/dist/types/cmds/eval/evalHandler.d.ts +0 -9
  247. package/dist/types/cmds/manifest/manifestHandler.d.ts +0 -10
  248. package/dist/types/cmds/serve/serveHandler.d.ts +0 -10
  249. package/dist/types/cmds/serve/serveUtils.d.ts +0 -22
  250. package/dist/types/cmds/watch/index.d.ts +0 -9
  251. package/dist/types/cmds/watch/watchHandler.d.ts +0 -14
  252. package/dist/types/utils/misc.d.ts +0 -53
  253. package/dist/types/utils/snap-config.d.ts +0 -48
  254. /package/dist/cjs/{cmds → commands}/index.js +0 -0
  255. /package/dist/types/{cmds → commands}/index.d.ts +0 -0
  256. /package/dist/types/{cmds/build → commands/serve}/index.d.ts +0 -0
@@ -1,44 +0,0 @@
1
- import { checkManifest, logError, logWarning } from '@metamask/snaps-utils';
2
- const ERROR_PREFIX = 'Manifest Error: ';
3
- /**
4
- * Validates a snap.manifest.json file. Attempts to fix the manifest and write
5
- * the fixed version to disk if `writeManifest` is true. Throws if validation
6
- * fails.
7
- *
8
- * @param argv - The Yargs `argv` object.
9
- * @param argv.writeManifest - Whether to write the fixed manifest to disk.
10
- */ export async function manifestHandler({ writeManifest }) {
11
- try {
12
- const { warnings, errors } = await checkManifest(process.cwd(), Boolean(writeManifest));
13
- if (!writeManifest && errors.length > 0) {
14
- logError(`${ERROR_PREFIX}The manifest is invalid.`);
15
- errors.forEach(logManifestError);
16
- // eslint-disable-next-line n/no-process-exit
17
- process.exit(1);
18
- }
19
- if (warnings.length > 0) {
20
- logWarning('Manifest Warning: Validation of snap.manifest.json completed with warnings.');
21
- warnings.forEach(logManifestWarning);
22
- }
23
- } catch (error) {
24
- throw new Error(`${ERROR_PREFIX}${error}`);
25
- }
26
- }
27
- /**
28
- * Logs a manifest warning, if `suppressWarnings` is not enabled.
29
- *
30
- * @param message - The message to log.
31
- */ function logManifestWarning(message) {
32
- if (!global.snaps.suppressWarnings) {
33
- logWarning(`Manifest Warning: ${message}`);
34
- }
35
- }
36
- /**
37
- * Logs a manifest error.
38
- *
39
- * @param message - The message to log.
40
- */ function logManifestError(message) {
41
- logError(`${ERROR_PREFIX}${message}`);
42
- }
43
-
44
- //# sourceMappingURL=manifestHandler.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/cmds/manifest/manifestHandler.ts"],"sourcesContent":["import { checkManifest, logError, logWarning } from '@metamask/snaps-utils';\n\nimport type { YargsArgs } from '../../types/yargs';\n\nconst ERROR_PREFIX = 'Manifest Error: ';\n\n/**\n * Validates a snap.manifest.json file. Attempts to fix the manifest and write\n * the fixed version to disk if `writeManifest` is true. Throws if validation\n * fails.\n *\n * @param argv - The Yargs `argv` object.\n * @param argv.writeManifest - Whether to write the fixed manifest to disk.\n */\nexport async function manifestHandler({ writeManifest }: YargsArgs) {\n try {\n const { warnings, errors } = await checkManifest(\n process.cwd(),\n Boolean(writeManifest),\n );\n\n if (!writeManifest && errors.length > 0) {\n logError(`${ERROR_PREFIX}The manifest is invalid.`);\n errors.forEach(logManifestError);\n\n // eslint-disable-next-line n/no-process-exit\n process.exit(1);\n }\n\n if (warnings.length > 0) {\n logWarning(\n 'Manifest Warning: Validation of snap.manifest.json completed with warnings.',\n );\n warnings.forEach(logManifestWarning);\n }\n } catch (error) {\n throw new Error(`${ERROR_PREFIX}${error}`);\n }\n}\n\n/**\n * Logs a manifest warning, if `suppressWarnings` is not enabled.\n *\n * @param message - The message to log.\n */\nfunction logManifestWarning(message: string) {\n if (!global.snaps.suppressWarnings) {\n logWarning(`Manifest Warning: ${message}`);\n }\n}\n\n/**\n * Logs a manifest error.\n *\n * @param message - The message to log.\n */\nfunction logManifestError(message: string) {\n logError(`${ERROR_PREFIX}${message}`);\n}\n"],"names":["checkManifest","logError","logWarning","ERROR_PREFIX","manifestHandler","writeManifest","warnings","errors","process","cwd","Boolean","length","forEach","logManifestError","exit","logManifestWarning","error","Error","message","global","snaps","suppressWarnings"],"mappings":"AAAA,SAASA,aAAa,EAAEC,QAAQ,EAAEC,UAAU,QAAQ,wBAAwB;AAI5E,MAAMC,eAAe;AAErB;;;;;;;CAOC,GACD,OAAO,eAAeC,gBAAgB,EAAEC,aAAa,EAAa;IAChE,IAAI;QACF,MAAM,EAAEC,QAAQ,EAAEC,MAAM,EAAE,GAAG,MAAMP,cACjCQ,QAAQC,GAAG,IACXC,QAAQL;QAGV,IAAI,CAACA,iBAAiBE,OAAOI,MAAM,GAAG,GAAG;YACvCV,SAAS,CAAC,EAAEE,aAAa,wBAAwB,CAAC;YAClDI,OAAOK,OAAO,CAACC;YAEf,6CAA6C;YAC7CL,QAAQM,IAAI,CAAC;QACf;QAEA,IAAIR,SAASK,MAAM,GAAG,GAAG;YACvBT,WACE;YAEFI,SAASM,OAAO,CAACG;QACnB;IACF,EAAE,OAAOC,OAAO;QACd,MAAM,IAAIC,MAAM,CAAC,EAAEd,aAAa,EAAEa,MAAM,CAAC;IAC3C;AACF;AAEA;;;;CAIC,GACD,SAASD,mBAAmBG,OAAe;IACzC,IAAI,CAACC,OAAOC,KAAK,CAACC,gBAAgB,EAAE;QAClCnB,WAAW,CAAC,kBAAkB,EAAEgB,QAAQ,CAAC;IAC3C;AACF;AAEA;;;;CAIC,GACD,SAASL,iBAAiBK,OAAe;IACvCjB,SAAS,CAAC,EAAEE,aAAa,EAAEe,QAAQ,CAAC;AACtC"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/cmds/serve/index.ts"],"sourcesContent":["import type yargs from 'yargs';\n\nimport builders from '../../builders';\nimport type { YargsArgs } from '../../types/yargs';\nimport { serve } from './serveHandler';\n\nconst command = {\n command: ['serve', 's'],\n desc: 'Locally serve Snap file(s) for testing',\n builder: (yarg: yargs.Argv) => {\n yarg.option('root', builders.root).option('port', builders.port);\n },\n handler: async (argv: YargsArgs) => serve(argv),\n};\n\nexport default command;\n"],"names":["builders","serve","command","desc","builder","yarg","option","root","port","handler","argv"],"mappings":"AAEA,OAAOA,cAAc,iBAAiB;AAEtC,SAASC,KAAK,QAAQ,iBAAiB;AAEvC,MAAMC,UAAU;IACdA,SAAS;QAAC;QAAS;KAAI;IACvBC,MAAM;IACNC,SAAS,CAACC;QACRA,KAAKC,MAAM,CAAC,QAAQN,SAASO,IAAI,EAAED,MAAM,CAAC,QAAQN,SAASQ,IAAI;IACjE;IACAC,SAAS,OAAOC,OAAoBT,MAAMS;AAC5C;AAEA,eAAeR,QAAQ"}
@@ -1,54 +0,0 @@
1
- import { logInfo, validateDirPath } from '@metamask/snaps-utils';
2
- import http from 'http';
3
- import serveHandler from 'serve-handler';
4
- import { logRequest, logServerError, logServerListening } from './serveUtils';
5
- /**
6
- * Starts a local, static HTTP server on the given port with the given root
7
- * directory.
8
- *
9
- * @param argv - Arguments as an object generated by Yargs.
10
- * @param argv.root - The root directory path string.
11
- * @param argv.port - The server port.
12
- */ export async function serve(argv) {
13
- const { port, root: rootDir } = argv;
14
- await validateDirPath(rootDir, true);
15
- logInfo(`\nStarting server...`);
16
- const server = http.createServer((req, res)=>{
17
- serveHandler(req, res, {
18
- public: rootDir,
19
- headers: [
20
- {
21
- source: '**/*',
22
- headers: [
23
- {
24
- key: 'Cache-Control',
25
- value: 'no-cache'
26
- },
27
- {
28
- key: 'Access-Control-Allow-Origin',
29
- value: '*'
30
- }
31
- ]
32
- }
33
- ]
34
- })?.catch((error)=>{
35
- logServerError(error, argv.port);
36
- res.statusCode = 500;
37
- res.end();
38
- });
39
- });
40
- server.listen({
41
- port
42
- }, ()=>logServerListening(port));
43
- server.on('request', (request)=>logRequest(request));
44
- server.on('error', (error)=>{
45
- logServerError(error, argv.port);
46
- process.exitCode = 1;
47
- });
48
- server.on('close', ()=>{
49
- logInfo('Server closed');
50
- process.exitCode = 1;
51
- });
52
- }
53
-
54
- //# sourceMappingURL=serveHandler.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/cmds/serve/serveHandler.ts"],"sourcesContent":["import { logInfo, validateDirPath } from '@metamask/snaps-utils';\nimport http from 'http';\nimport serveHandler from 'serve-handler';\n\nimport type { YargsArgs } from '../../types/yargs';\nimport { logRequest, logServerError, logServerListening } from './serveUtils';\n\n/**\n * Starts a local, static HTTP server on the given port with the given root\n * directory.\n *\n * @param argv - Arguments as an object generated by Yargs.\n * @param argv.root - The root directory path string.\n * @param argv.port - The server port.\n */\nexport async function serve(argv: YargsArgs): Promise<void> {\n const { port, root: rootDir } = argv;\n\n await validateDirPath(rootDir as string, true);\n\n logInfo(`\\nStarting server...`);\n\n const server = http.createServer((req, res) => {\n serveHandler(req, res, {\n public: rootDir as string,\n headers: [\n {\n source: '**/*',\n headers: [\n {\n key: 'Cache-Control',\n value: 'no-cache',\n },\n {\n key: 'Access-Control-Allow-Origin',\n value: '*',\n },\n ],\n },\n ],\n })?.catch((error) => {\n logServerError(error, argv.port);\n res.statusCode = 500;\n res.end();\n });\n });\n\n server.listen({ port }, () => logServerListening(port));\n\n server.on('request', (request) => logRequest(request));\n\n server.on('error', (error) => {\n logServerError(error, argv.port);\n process.exitCode = 1;\n });\n\n server.on('close', () => {\n logInfo('Server closed');\n process.exitCode = 1;\n });\n}\n"],"names":["logInfo","validateDirPath","http","serveHandler","logRequest","logServerError","logServerListening","serve","argv","port","root","rootDir","server","createServer","req","res","public","headers","source","key","value","catch","error","statusCode","end","listen","on","request","process","exitCode"],"mappings":"AAAA,SAASA,OAAO,EAAEC,eAAe,QAAQ,wBAAwB;AACjE,OAAOC,UAAU,OAAO;AACxB,OAAOC,kBAAkB,gBAAgB;AAGzC,SAASC,UAAU,EAAEC,cAAc,EAAEC,kBAAkB,QAAQ,eAAe;AAE9E;;;;;;;CAOC,GACD,OAAO,eAAeC,MAAMC,IAAe;IACzC,MAAM,EAAEC,IAAI,EAAEC,MAAMC,OAAO,EAAE,GAAGH;IAEhC,MAAMP,gBAAgBU,SAAmB;IAEzCX,QAAQ,CAAC,oBAAoB,CAAC;IAE9B,MAAMY,SAASV,KAAKW,YAAY,CAAC,CAACC,KAAKC;QACrCZ,aAAaW,KAAKC,KAAK;YACrBC,QAAQL;YACRM,SAAS;gBACP;oBACEC,QAAQ;oBACRD,SAAS;wBACP;4BACEE,KAAK;4BACLC,OAAO;wBACT;wBACA;4BACED,KAAK;4BACLC,OAAO;wBACT;qBACD;gBACH;aACD;QACH,IAAIC,MAAM,CAACC;YACTjB,eAAeiB,OAAOd,KAAKC,IAAI;YAC/BM,IAAIQ,UAAU,GAAG;YACjBR,IAAIS,GAAG;QACT;IACF;IAEAZ,OAAOa,MAAM,CAAC;QAAEhB;IAAK,GAAG,IAAMH,mBAAmBG;IAEjDG,OAAOc,EAAE,CAAC,WAAW,CAACC,UAAYvB,WAAWuB;IAE7Cf,OAAOc,EAAE,CAAC,SAAS,CAACJ;QAClBjB,eAAeiB,OAAOd,KAAKC,IAAI;QAC/BmB,QAAQC,QAAQ,GAAG;IACrB;IAEAjB,OAAOc,EAAE,CAAC,SAAS;QACjB1B,QAAQ;QACR4B,QAAQC,QAAQ,GAAG;IACrB;AACF"}
@@ -1,30 +0,0 @@
1
- import { logError, logInfo } from '@metamask/snaps-utils';
2
- /**
3
- * Log a message with the URL and port of the server.
4
- *
5
- * @param port - The port that the server is running on.
6
- */ export function logServerListening(port) {
7
- logInfo(`Server listening on: http://localhost:${port}`);
8
- }
9
- /**
10
- * Log a message with the request URL.
11
- *
12
- * @param request - The request object.
13
- * @param request.url - The URL of the request.
14
- */ export function logRequest(request) {
15
- logInfo(`Handling incoming request for: ${request.url ?? 'unknown'}`);
16
- }
17
- /**
18
- * Log an error message.
19
- *
20
- * @param error - The error to log.
21
- * @param port - The port that the server is running on.
22
- */ export function logServerError(error, port) {
23
- if (error.code === 'EADDRINUSE') {
24
- logError(`Server error: Port ${port} already in use.`);
25
- } else {
26
- logError(`Server error: ${error.message}`);
27
- }
28
- }
29
-
30
- //# sourceMappingURL=serveUtils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/cmds/serve/serveUtils.ts"],"sourcesContent":["import { logError, logInfo } from '@metamask/snaps-utils';\n\n/**\n * Log a message with the URL and port of the server.\n *\n * @param port - The port that the server is running on.\n */\nexport function logServerListening(port: number) {\n logInfo(`Server listening on: http://localhost:${port}`);\n}\n\n/**\n * Log a message with the request URL.\n *\n * @param request - The request object.\n * @param request.url - The URL of the request.\n */\nexport function logRequest(request: { url?: string }) {\n logInfo(`Handling incoming request for: ${request.url ?? 'unknown'}`);\n}\n\n/**\n * Log an error message.\n *\n * @param error - The error to log.\n * @param port - The port that the server is running on.\n */\nexport function logServerError(error: Error, port: number) {\n if ((error as any).code === 'EADDRINUSE') {\n logError(`Server error: Port ${port} already in use.`);\n } else {\n logError(`Server error: ${error.message}`);\n }\n}\n"],"names":["logError","logInfo","logServerListening","port","logRequest","request","url","logServerError","error","code","message"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,OAAO,QAAQ,wBAAwB;AAE1D;;;;CAIC,GACD,OAAO,SAASC,mBAAmBC,IAAY;IAC7CF,QAAQ,CAAC,sCAAsC,EAAEE,KAAK,CAAC;AACzD;AAEA;;;;;CAKC,GACD,OAAO,SAASC,WAAWC,OAAyB;IAClDJ,QAAQ,CAAC,+BAA+B,EAAEI,QAAQC,GAAG,IAAI,UAAU,CAAC;AACtE;AAEA;;;;;CAKC,GACD,OAAO,SAASC,eAAeC,KAAY,EAAEL,IAAY;IACvD,IAAI,AAACK,MAAcC,IAAI,KAAK,cAAc;QACxCT,SAAS,CAAC,mBAAmB,EAAEG,KAAK,gBAAgB,CAAC;IACvD,OAAO;QACLH,SAAS,CAAC,cAAc,EAAEQ,MAAME,OAAO,CAAC,CAAC;IAC3C;AACF"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/cmds/watch/index.ts"],"sourcesContent":["import type yargs from 'yargs';\n\nimport builders from '../../builders';\nimport type { YargsArgs } from '../../types/yargs';\nimport { processInvalidTranspilation } from '../build/utils';\nimport { watch } from './watchHandler';\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 .middleware((argv) => processInvalidTranspilation(argv as any));\n },\n handler: async (argv: YargsArgs) => watch(argv),\n};\n\nexport default command;\n"],"names":["builders","processInvalidTranspilation","watch","command","desc","builder","yarg","option","src","eval","dist","outfileName","sourceMaps","stripComments","transpilationMode","depsToTranspile","manifest","writeManifest","serve","root","port","implies","middleware","argv","handler"],"mappings":"AAEA,OAAOA,cAAc,iBAAiB;AAEtC,SAASC,2BAA2B,QAAQ,iBAAiB;AAC7D,SAASC,KAAK,QAAQ,iBAAiB;AAEvC,MAAMC,UAAU;IACdA,SAAS;QAAC;QAAS;KAAI;IACvBC,MAAM;IACNC,SAAS,CAACC;QACRA,KACGC,MAAM,CAAC,OAAOP,SAASQ,GAAG,EAC1BD,MAAM,CAAC,QAAQP,SAASS,IAAI,EAC5BF,MAAM,CAAC,QAAQP,SAASU,IAAI,EAC5BH,MAAM,CAAC,eAAeP,SAASW,WAAW,EAC1CJ,MAAM,CAAC,cAAcP,SAASY,UAAU,EACxCL,MAAM,CAAC,iBAAiBP,SAASa,aAAa,EAC9CN,MAAM,CAAC,qBAAqBP,SAASc,iBAAiB,EACtDP,MAAM,CAAC,mBAAmBP,SAASe,eAAe,EAClDR,MAAM,CAAC,YAAYP,SAASgB,QAAQ,EACpCT,MAAM,CAAC,iBAAiBP,SAASiB,aAAa,EAC9CV,MAAM,CAAC,SAASP,SAASkB,KAAK,EAC9BX,MAAM,CAAC,QAAQP,SAASmB,IAAI,EAC5BZ,MAAM,CAAC,QAAQP,SAASoB,IAAI,EAC5BC,OAAO,CAAC,iBAAiB,YACzBA,OAAO,CAAC,mBAAmB,qBAC3BC,UAAU,CAAC,CAACC,OAAStB,4BAA4BsB;IACtD;IACAC,SAAS,OAAOD,OAAoBrB,MAAMqB;AAC5C;AAEA,eAAepB,QAAQ"}
@@ -1,87 +0,0 @@
1
- import { getOutfilePath, logError, logInfo, validateDirPath, validateFilePath, validateOutfileName, NpmSnapFileNames } from '@metamask/snaps-utils';
2
- import chokidar from 'chokidar';
3
- import pathUtils from 'path';
4
- import { CONFIG_FILE, loadConfig } from '../../utils';
5
- import { bundle } from '../build/bundle';
6
- import { evalHandler } from '../eval/evalHandler';
7
- import { manifestHandler } from '../manifest/manifestHandler';
8
- import { serve } from '../serve/serveHandler';
9
- /**
10
- * Watch a directory and its subdirectories for changes, and build when files
11
- * are added or changed.
12
- *
13
- * Ignores 'node_modules' and dotfiles.
14
- * Creates destination directory if it doesn't exist.
15
- *
16
- * @param argv - Arguments as an object generated by Yargs.
17
- * @param argv.src - The source file path.
18
- * @param argv.dist - The output directory path.
19
- * @param argv.'outfileName' - The output file name.
20
- */ export async function watch(argv) {
21
- const { dist, eval: shouldEval, manifest, outfileName, src, serve: shouldServe } = argv;
22
- if (outfileName) {
23
- validateOutfileName(outfileName);
24
- }
25
- await validateFilePath(src);
26
- await validateDirPath(dist, true);
27
- const srcDir = pathUtils.dirname(src);
28
- const watchDirs = [
29
- srcDir,
30
- NpmSnapFileNames.Manifest,
31
- CONFIG_FILE
32
- ];
33
- const outfilePath = getOutfilePath(dist, outfileName);
34
- const buildSnap = async (path, logMessage)=>{
35
- if (logMessage !== undefined) {
36
- logInfo(logMessage);
37
- }
38
- try {
39
- await bundle(src, outfilePath, argv, loadConfig().bundlerCustomizer);
40
- if (manifest) {
41
- await manifestHandler(argv);
42
- }
43
- if (shouldEval) {
44
- await evalHandler({
45
- ...argv,
46
- bundle: outfilePath
47
- });
48
- }
49
- } catch (error) {
50
- logError(`Error ${path === undefined ? 'during initial build' : `while processing "${path}"`}.`, error);
51
- }
52
- };
53
- chokidar.watch(watchDirs, {
54
- ignoreInitial: true,
55
- ignored: [
56
- '**/node_modules/**',
57
- `**/${dist}/**`,
58
- `**/test/**`,
59
- `**/tests/**`,
60
- `**/*.test.js`,
61
- `**/*.test.ts`,
62
- /* istanbul ignore next */ (str)=>str !== '.' && str.startsWith('.')
63
- ]
64
- }).on('ready', ()=>{
65
- buildSnap().then(()=>{
66
- if (shouldServe) {
67
- return serve(argv);
68
- }
69
- return undefined;
70
- }).catch((error)=>{
71
- logError('Error during initial build.', error);
72
- });
73
- }).on('add', (path)=>{
74
- buildSnap(path, `File added: ${path}`).catch((error)=>{
75
- logError(`Error while processing "${path}".`, error);
76
- });
77
- }).on('change', (path)=>{
78
- buildSnap(path, `File changed: ${path}`).catch((error)=>{
79
- logError(`Error while processing "${path}".`, error);
80
- });
81
- }).on('unlink', (path)=>logInfo(`File removed: ${path}`)).on('error', (error)=>{
82
- logError(`Watcher error: ${error.message}`, error);
83
- });
84
- logInfo(`Watching ${watchDirs.map((dir)=>`'${dir}'`).join(', ')} for changes...`);
85
- }
86
-
87
- //# sourceMappingURL=watchHandler.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/cmds/watch/watchHandler.ts"],"sourcesContent":["import {\n getOutfilePath,\n logError,\n logInfo,\n validateDirPath,\n validateFilePath,\n validateOutfileName,\n NpmSnapFileNames,\n} from '@metamask/snaps-utils';\nimport chokidar from 'chokidar';\nimport pathUtils from 'path';\n\nimport type { YargsArgs } from '../../types/yargs';\nimport { CONFIG_FILE, loadConfig } from '../../utils';\nimport { bundle } from '../build/bundle';\nimport { evalHandler } from '../eval/evalHandler';\nimport { manifestHandler } from '../manifest/manifestHandler';\nimport { serve } from '../serve/serveHandler';\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 argv - Arguments as an object generated by Yargs.\n * @param argv.src - The source file path.\n * @param argv.dist - The output directory path.\n * @param argv.'outfileName' - The output file name.\n */\nexport async function watch(argv: YargsArgs): Promise<void> {\n const {\n dist,\n eval: shouldEval,\n manifest,\n outfileName,\n src,\n serve: shouldServe,\n } = argv;\n if (outfileName) {\n validateOutfileName(outfileName);\n }\n await validateFilePath(src);\n await validateDirPath(dist, true);\n const srcDir = pathUtils.dirname(src);\n const watchDirs = [srcDir, NpmSnapFileNames.Manifest, CONFIG_FILE];\n const outfilePath = getOutfilePath(dist, outfileName);\n\n const buildSnap = async (path?: string, logMessage?: string) => {\n if (logMessage !== undefined) {\n logInfo(logMessage);\n }\n\n try {\n await bundle(src, outfilePath, argv, loadConfig().bundlerCustomizer);\n\n if (manifest) {\n await manifestHandler(argv);\n }\n\n if (shouldEval) {\n await evalHandler({ ...argv, bundle: outfilePath });\n }\n } catch (error) {\n logError(\n `Error ${\n path === undefined\n ? 'during initial build'\n : `while processing \"${path}\"`\n }.`,\n error,\n );\n }\n };\n\n chokidar\n .watch(watchDirs, {\n ignoreInitial: true,\n ignored: [\n '**/node_modules/**',\n `**/${dist}/**`,\n `**/test/**`,\n `**/tests/**`,\n `**/*.test.js`,\n `**/*.test.ts`,\n /* istanbul ignore next */\n (str: string) => str !== '.' && str.startsWith('.'),\n ],\n })\n\n .on('ready', () => {\n buildSnap()\n .then(() => {\n if (shouldServe) {\n return serve(argv);\n }\n\n return undefined;\n })\n .catch((error) => {\n logError('Error during initial build.', error);\n });\n })\n .on('add', (path) => {\n buildSnap(path, `File added: ${path}`).catch((error) => {\n logError(`Error while processing \"${path}\".`, error);\n });\n })\n .on('change', (path) => {\n buildSnap(path, `File changed: ${path}`).catch((error) => {\n logError(`Error while processing \"${path}\".`, error);\n });\n })\n .on('unlink', (path) => logInfo(`File removed: ${path}`))\n .on('error', (error: Error) => {\n logError(`Watcher error: ${error.message}`, error);\n });\n\n logInfo(\n `Watching ${watchDirs.map((dir) => `'${dir}'`).join(', ')} for changes...`,\n );\n}\n"],"names":["getOutfilePath","logError","logInfo","validateDirPath","validateFilePath","validateOutfileName","NpmSnapFileNames","chokidar","pathUtils","CONFIG_FILE","loadConfig","bundle","evalHandler","manifestHandler","serve","watch","argv","dist","eval","shouldEval","manifest","outfileName","src","shouldServe","srcDir","dirname","watchDirs","Manifest","outfilePath","buildSnap","path","logMessage","undefined","bundlerCustomizer","error","ignoreInitial","ignored","str","startsWith","on","then","catch","message","map","dir","join"],"mappings":"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"}
@@ -1,139 +0,0 @@
1
- import { logError as logErrorUtil } from '@metamask/snaps-utils';
2
- import { hasProperty } from '@metamask/utils';
3
- import { promises as filesystem } from 'fs';
4
- import path from 'path';
5
- export const permRequestKeys = [
6
- '@context',
7
- 'id',
8
- 'parentCapability',
9
- 'invoker',
10
- 'date',
11
- 'caveats',
12
- 'proof'
13
- ];
14
- export const CONFIG_FILE = 'snap.config.js';
15
- // CLI arguments whose values are file paths
16
- const pathArguments = new Set([
17
- 'src',
18
- 's',
19
- 'dist',
20
- 'd',
21
- 'bundle',
22
- 'b',
23
- 'root',
24
- 'r'
25
- ]);
26
- /**
27
- * Sets global variable snaps which tracks user settings:
28
- * watch mode activation, verbose errors messages, and whether to suppress
29
- * warnings.
30
- *
31
- * @param argv - Arguments as an object generated by `yargs`.
32
- */ export function setSnapGlobals(argv) {
33
- if ([
34
- 'w',
35
- 'watch'
36
- ].includes(argv._[0])) {
37
- global.snaps.isWatching = true;
38
- } else {
39
- global.snaps.isWatching = false;
40
- }
41
- if (hasProperty(argv, 'verboseErrors')) {
42
- global.snaps.verboseErrors = booleanStringToBoolean(argv.verboseErrors);
43
- }
44
- if (hasProperty(argv, 'suppressWarnings')) {
45
- global.snaps.suppressWarnings = booleanStringToBoolean(argv.suppressWarnings);
46
- }
47
- }
48
- /**
49
- * Attempts to convert a string to a boolean and throws if the value is invalid.
50
- *
51
- * @param value - The value to convert to a boolean.
52
- * @returns `true` if the value is the string `"true"`, `false` if it is the
53
- * string `"false"`, the value if it is already a boolean, or an error
54
- * otherwise.
55
- */ export function booleanStringToBoolean(value) {
56
- if (typeof value === 'boolean') {
57
- return value;
58
- } else if (value === 'true') {
59
- return true;
60
- } else if (value === 'false') {
61
- return false;
62
- }
63
- throw new Error(`Expected a boolean or the strings "true" or "false". Received: "${String(value)}"`);
64
- }
65
- /**
66
- * Sanitizes inputs. Currently normalizes "./" paths to ".".
67
- * Yargs handles other path normalization as specified in builders.
68
- *
69
- * @param argv - Arguments as an object generated by yargs.
70
- */ export function sanitizeInputs(argv) {
71
- Object.keys(argv).forEach((key)=>{
72
- if (typeof argv[key] === 'string') {
73
- // Node's path.normalize() does not do this
74
- if (argv[key] === './') {
75
- argv[key] = '.';
76
- }
77
- if (pathArguments.has(key)) {
78
- argv[key] = path.normalize(argv[key]);
79
- }
80
- }
81
- });
82
- }
83
- /**
84
- * Logs an error message to console. Logs original error if it exists and
85
- * the verboseErrors global is true.
86
- *
87
- * @param message - The error message.
88
- * @param error - The original error.
89
- */ export function logError(message, error) {
90
- if (message !== null) {
91
- logErrorUtil(message);
92
- }
93
- if (error && global.snaps.verboseErrors) {
94
- logErrorUtil(error);
95
- }
96
- if (message === null && (!error || error && !global.snaps.verboseErrors)) {
97
- logErrorUtil('Unknown error.');
98
- }
99
- }
100
- /**
101
- * Logs an error, attempts to unlink the destination file, and kills the
102
- * process.
103
- *
104
- * @param prefix - The message prefix.
105
- * @param message - The error message.
106
- * @param error - The original error.
107
- * @param destFilePath - The output file path.
108
- */ export async function writeError(prefix, message, error, destFilePath) {
109
- let processedPrefix = prefix;
110
- if (!prefix.endsWith(' ')) {
111
- processedPrefix += ' ';
112
- }
113
- logError(processedPrefix + message, error);
114
- try {
115
- if (destFilePath) {
116
- await filesystem.unlink(destFilePath);
117
- }
118
- } catch (unlinkError) {
119
- logError(`${processedPrefix}Failed to unlink mangled file.`, unlinkError);
120
- }
121
- // unless the watcher is active, exit
122
- if (!global.snaps.isWatching) {
123
- // TODO(ritave): Remove process exit and change into collapse of functions
124
- // https://github.com/MetaMask/snaps-monorepo/issues/81
125
- // eslint-disable-next-line n/no-process-exit
126
- process.exit(1);
127
- }
128
- }
129
- /**
130
- * Trims leading and trailing periods "." and forward slashes "/" from the
131
- * given path string.
132
- *
133
- * @param pathString - The path string to trim.
134
- * @returns The trimmed path string.
135
- */ export function trimPathString(pathString) {
136
- return pathString.replace(/^[./]+|[./]+$/gu, '');
137
- }
138
-
139
- //# sourceMappingURL=misc.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/utils/misc.ts"],"sourcesContent":["import { logError as logErrorUtil } from '@metamask/snaps-utils';\nimport { hasProperty } from '@metamask/utils';\nimport { promises as filesystem } from 'fs';\nimport path from 'path';\nimport type { Arguments } from 'yargs';\n\nexport const permRequestKeys = [\n '@context',\n 'id',\n 'parentCapability',\n 'invoker',\n 'date',\n 'caveats',\n 'proof',\n];\n\nexport const CONFIG_FILE = 'snap.config.js';\n\n// CLI arguments whose values are file paths\nconst pathArguments = new Set([\n 'src',\n 's',\n 'dist',\n 'd',\n 'bundle',\n 'b',\n 'root',\n 'r',\n]);\n\n/**\n * Sets global variable snaps which tracks user settings:\n * watch mode activation, verbose errors messages, and whether to suppress\n * warnings.\n *\n * @param argv - Arguments as an object generated by `yargs`.\n */\nexport function setSnapGlobals(argv: Arguments) {\n if (['w', 'watch'].includes(argv._[0] as string)) {\n global.snaps.isWatching = true;\n } else {\n global.snaps.isWatching = false;\n }\n\n if (hasProperty(argv, 'verboseErrors')) {\n global.snaps.verboseErrors = booleanStringToBoolean(argv.verboseErrors);\n }\n\n if (hasProperty(argv, 'suppressWarnings')) {\n global.snaps.suppressWarnings = booleanStringToBoolean(\n argv.suppressWarnings,\n );\n }\n}\n\n/**\n * Attempts to convert a string to a boolean and throws if the value is invalid.\n *\n * @param value - The value to convert to a boolean.\n * @returns `true` if the value is the string `\"true\"`, `false` if it is the\n * string `\"false\"`, the value if it is already a boolean, or an error\n * otherwise.\n */\nexport function booleanStringToBoolean(value: unknown): boolean {\n if (typeof value === 'boolean') {\n return value;\n } else if (value === 'true') {\n return true;\n } else if (value === 'false') {\n return false;\n }\n\n throw new Error(\n `Expected a boolean or the strings \"true\" or \"false\". Received: \"${String(\n value,\n )}\"`,\n );\n}\n\n/**\n * Sanitizes inputs. Currently normalizes \"./\" paths to \".\".\n * Yargs handles other path normalization as specified in builders.\n *\n * @param argv - Arguments as an object generated by yargs.\n */\nexport function sanitizeInputs(argv: Arguments) {\n Object.keys(argv).forEach((key) => {\n if (typeof argv[key] === 'string') {\n // Node's path.normalize() does not do this\n if (argv[key] === './') {\n argv[key] = '.';\n }\n\n if (pathArguments.has(key)) {\n argv[key] = path.normalize(argv[key] as string);\n }\n }\n });\n}\n\n/**\n * Logs an error message to console. Logs original error if it exists and\n * the verboseErrors global is true.\n *\n * @param message - The error message.\n * @param error - The original error.\n */\nexport function logError(message: string | null, error?: Error): void {\n if (message !== null) {\n logErrorUtil(message);\n }\n\n if (error && global.snaps.verboseErrors) {\n logErrorUtil(error);\n }\n\n if (message === null && (!error || (error && !global.snaps.verboseErrors))) {\n logErrorUtil('Unknown error.');\n }\n}\n\n/**\n * Logs an error, attempts to unlink the destination file, and kills the\n * process.\n *\n * @param prefix - The message prefix.\n * @param message - The error message.\n * @param error - The original error.\n * @param destFilePath - The output file path.\n */\nexport async function writeError(\n prefix: string,\n message: string,\n error: Error,\n destFilePath?: string,\n): Promise<void> {\n let processedPrefix = prefix;\n if (!prefix.endsWith(' ')) {\n processedPrefix += ' ';\n }\n\n logError(processedPrefix + message, error);\n try {\n if (destFilePath) {\n await filesystem.unlink(destFilePath);\n }\n } catch (unlinkError) {\n logError(`${processedPrefix}Failed to unlink mangled file.`, unlinkError);\n }\n\n // unless the watcher is active, exit\n if (!global.snaps.isWatching) {\n // TODO(ritave): Remove process exit and change into collapse of functions\n // https://github.com/MetaMask/snaps-monorepo/issues/81\n // eslint-disable-next-line n/no-process-exit\n process.exit(1);\n }\n}\n\n/**\n * Trims leading and trailing periods \".\" and forward slashes \"/\" from the\n * given path string.\n *\n * @param pathString - The path string to trim.\n * @returns The trimmed path string.\n */\nexport function trimPathString(pathString: string): string {\n return pathString.replace(/^[./]+|[./]+$/gu, '');\n}\n"],"names":["logError","logErrorUtil","hasProperty","promises","filesystem","path","permRequestKeys","CONFIG_FILE","pathArguments","Set","setSnapGlobals","argv","includes","_","global","snaps","isWatching","verboseErrors","booleanStringToBoolean","suppressWarnings","value","Error","String","sanitizeInputs","Object","keys","forEach","key","has","normalize","message","error","writeError","prefix","destFilePath","processedPrefix","endsWith","unlink","unlinkError","process","exit","trimPathString","pathString","replace"],"mappings":"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"}
@@ -1,107 +0,0 @@
1
- import { hasProperty } from '@metamask/utils';
2
- import path from 'path';
3
- import { object, optional, func, is } from 'superstruct';
4
- import yargsParse from 'yargs-parser';
5
- import builders from '../builders';
6
- import { CONFIG_FILE, logError } from './misc';
7
- export const SnapConfigStruct = object({
8
- cliOptions: optional(object()),
9
- bundlerCustomizer: optional(func())
10
- });
11
- /**
12
- * Check if the given value is a {@link SnapConfig} object. Note that this
13
- * function does not check the validity of the `bundleCustomizer` property, as
14
- * it is not possible to check the validity of a function in JavaScript.
15
- *
16
- * @param value - The value to check.
17
- * @returns `true` if the value is a valid {@link SnapConfig} object, `false`
18
- * otherwise.
19
- */ export function isSnapConfig(value) {
20
- return is(value, SnapConfigStruct);
21
- }
22
- let snapConfigCache;
23
- /**
24
- * Attempt to load the snap config file (`snap.config.js`). By default will use
25
- * the cached config, if it was loaded before, and `cached` is `true`. If the
26
- * config file is not found, or the config is invalid, this function will kill
27
- * the process.
28
- *
29
- * @param cached - Whether to use the cached config. Defaults to `true`.
30
- * @returns The snap config.
31
- */ export function loadConfig(cached = true) {
32
- if (snapConfigCache !== undefined && cached) {
33
- return snapConfigCache;
34
- }
35
- let config;
36
- try {
37
- // eslint-disable-next-line n/global-require, import/no-dynamic-require, @typescript-eslint/no-require-imports
38
- config = require(path.resolve(process.cwd(), CONFIG_FILE));
39
- } catch (error) {
40
- if (error.code === 'MODULE_NOT_FOUND') {
41
- snapConfigCache = {};
42
- return snapConfigCache;
43
- }
44
- logError(`Error during parsing of ${CONFIG_FILE}`, error);
45
- // eslint-disable-next-line n/no-process-exit
46
- return process.exit(1);
47
- }
48
- if (!isSnapConfig(config)) {
49
- logError(`Can't validate ${CONFIG_FILE}. Ensure it's a proper javascript file and abides with the structure of a snap configuration file`);
50
- // eslint-disable-next-line n/no-process-exit
51
- return process.exit(1);
52
- }
53
- snapConfigCache = config;
54
- return config;
55
- }
56
- // Note that the below function is necessary because yargs' .config() function
57
- // leaves much to be desired.
58
- //
59
- // In particular, it will set all properties included in the config file
60
- // regardless of the command, which fails during validation.
61
- /**
62
- * Attempts to read configuration options for package.json and the config file,
63
- * and apply them to argv if they weren't already set.
64
- *
65
- * Arguments are only set per the snap-cli config file if they were not specified
66
- * on the command line.
67
- *
68
- * @param snapConfig - The snap config.
69
- * @param processArgv - The command line arguments, i.e., `process.argv`.
70
- * @param yargsArgv - The processed `yargs` arguments.
71
- * @param yargsInstance - An instance of `yargs`.
72
- */ export function applyConfig(snapConfig, processArgv, yargsArgv, yargsInstance) {
73
- // Instances of yargs has a number of undocumented functions, including
74
- // getOptions. This function returns an object with properties "key" and
75
- // "alias", which specify the options associated with the current command and
76
- // their aliases, respectively.
77
- //
78
- // We leverage this to ensure that the config is only applied to args that are
79
- // valid for the current command, and that weren't specified by the user on
80
- // the command line.
81
- //
82
- // If we set args that aren't valid for the current command, yargs will error
83
- // during validation.
84
- const { alias: aliases, key: options } = yargsInstance.getOptions();
85
- const parsedProcessArgv = yargsParse(processArgv, {
86
- alias: aliases
87
- });
88
- delete parsedProcessArgv._; // irrelevant yargs parser artifact
89
- const commandOptions = new Set(Object.keys(options));
90
- const shouldSetArg = (key)=>{
91
- return commandOptions.has(key) && !hasProperty(parsedProcessArgv, key);
92
- };
93
- const config = snapConfig.cliOptions ?? {};
94
- for (const key of Object.keys(config)){
95
- if (hasProperty(builders, key)) {
96
- if (shouldSetArg(key)) {
97
- yargsArgv[key] = config[key];
98
- }
99
- } else {
100
- logError(`Error: Encountered unrecognized config property "options.${key}" in config file "${CONFIG_FILE}". Remove the property and try again.`);
101
- // eslint-disable-next-line n/no-process-exit
102
- process.exit(1);
103
- }
104
- }
105
- }
106
-
107
- //# sourceMappingURL=snap-config.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/utils/snap-config.ts"],"sourcesContent":["import { hasProperty } from '@metamask/utils';\nimport type browserify from 'browserify';\nimport path from 'path';\nimport type { Infer } from 'superstruct';\nimport { object, optional, func, is } from 'superstruct';\nimport type { Arguments } from 'yargs';\nimport yargsParse from 'yargs-parser';\nimport type yargs from 'yargs/yargs';\n\nimport builders from '../builders';\nimport { CONFIG_FILE, logError } from './misc';\n\nexport type BundleCustomizer = (bundler: browserify.BrowserifyObject) => void;\n\nexport const SnapConfigStruct = object({\n cliOptions: optional(object()),\n bundlerCustomizer: optional(func()),\n});\n\nexport type SnapConfig = Omit<\n Infer<typeof SnapConfigStruct>,\n 'bundlerCustomizer'\n> & {\n bundlerCustomizer?: BundleCustomizer;\n};\n\n/**\n * Check if the given value is a {@link SnapConfig} object. Note that this\n * function does not check the validity of the `bundleCustomizer` property, as\n * it is not possible to check the validity of a function in JavaScript.\n *\n * @param value - The value to check.\n * @returns `true` if the value is a valid {@link SnapConfig} object, `false`\n * otherwise.\n */\nexport function isSnapConfig(value: unknown): value is SnapConfig {\n return is(value, SnapConfigStruct);\n}\n\nlet snapConfigCache: SnapConfig | undefined;\n\n/**\n * Attempt to load the snap config file (`snap.config.js`). By default will use\n * the cached config, if it was loaded before, and `cached` is `true`. If the\n * config file is not found, or the config is invalid, this function will kill\n * the process.\n *\n * @param cached - Whether to use the cached config. Defaults to `true`.\n * @returns The snap config.\n */\nexport function loadConfig(cached = true): SnapConfig {\n if (snapConfigCache !== undefined && cached) {\n return snapConfigCache;\n }\n\n let config: any;\n try {\n // eslint-disable-next-line n/global-require, import/no-dynamic-require, @typescript-eslint/no-require-imports\n config = require(path.resolve(process.cwd(), CONFIG_FILE));\n } catch (error: any) {\n if (error.code === 'MODULE_NOT_FOUND') {\n snapConfigCache = {};\n return snapConfigCache;\n }\n logError(`Error during parsing of ${CONFIG_FILE}`, error);\n // eslint-disable-next-line n/no-process-exit\n return process.exit(1);\n }\n\n if (!isSnapConfig(config)) {\n logError(\n `Can't validate ${CONFIG_FILE}. Ensure it's a proper javascript file and abides with the structure of a snap configuration file`,\n );\n // eslint-disable-next-line n/no-process-exit\n return process.exit(1);\n }\n snapConfigCache = config;\n return config;\n}\n\n// Note that the below function is necessary because yargs' .config() function\n// leaves much to be desired.\n//\n// In particular, it will set all properties included in the config file\n// regardless of the command, which fails during validation.\n\n/**\n * Attempts to read configuration options for package.json and the config file,\n * and apply them to argv if they weren't already set.\n *\n * Arguments are only set per the snap-cli config file if they were not specified\n * on the command line.\n *\n * @param snapConfig - The snap config.\n * @param processArgv - The command line arguments, i.e., `process.argv`.\n * @param yargsArgv - The processed `yargs` arguments.\n * @param yargsInstance - An instance of `yargs`.\n */\nexport function applyConfig(\n snapConfig: SnapConfig,\n processArgv: string[],\n yargsArgv: Arguments,\n yargsInstance: typeof yargs,\n): void {\n // Instances of yargs has a number of undocumented functions, including\n // getOptions. This function returns an object with properties \"key\" and\n // \"alias\", which specify the options associated with the current command and\n // their aliases, respectively.\n //\n // We leverage this to ensure that the config is only applied to args that are\n // valid for the current command, and that weren't specified by the user on\n // the command line.\n //\n // If we set args that aren't valid for the current command, yargs will error\n // during validation.\n const { alias: aliases, key: options } = (\n yargsInstance as any\n ).getOptions() as {\n alias: Record<string, string[]>;\n key: Record<string, unknown>;\n };\n\n const parsedProcessArgv = yargsParse(processArgv, {\n alias: aliases,\n }) as Record<string, unknown>;\n delete parsedProcessArgv._; // irrelevant yargs parser artifact\n\n const commandOptions = new Set(Object.keys(options));\n\n const shouldSetArg = (key: string): boolean => {\n return commandOptions.has(key) && !hasProperty(parsedProcessArgv, key);\n };\n\n const config: Record<string, unknown> = snapConfig.cliOptions ?? {};\n for (const key of Object.keys(config)) {\n if (hasProperty(builders, key)) {\n if (shouldSetArg(key)) {\n yargsArgv[key] = config[key];\n }\n } else {\n logError(\n `Error: Encountered unrecognized config property \"options.${key}\" in config file \"${CONFIG_FILE}\". Remove the property and try again.`,\n );\n // eslint-disable-next-line n/no-process-exit\n process.exit(1);\n }\n }\n}\n"],"names":["hasProperty","path","object","optional","func","is","yargsParse","builders","CONFIG_FILE","logError","SnapConfigStruct","cliOptions","bundlerCustomizer","isSnapConfig","value","snapConfigCache","loadConfig","cached","undefined","config","require","resolve","process","cwd","error","code","exit","applyConfig","snapConfig","processArgv","yargsArgv","yargsInstance","alias","aliases","key","options","getOptions","parsedProcessArgv","_","commandOptions","Set","Object","keys","shouldSetArg","has"],"mappings":"AAAA,SAASA,WAAW,QAAQ,kBAAkB;AAE9C,OAAOC,UAAU,OAAO;AAExB,SAASC,MAAM,EAAEC,QAAQ,EAAEC,IAAI,EAAEC,EAAE,QAAQ,cAAc;AAEzD,OAAOC,gBAAgB,eAAe;AAGtC,OAAOC,cAAc,cAAc;AACnC,SAASC,WAAW,EAAEC,QAAQ,QAAQ,SAAS;AAI/C,OAAO,MAAMC,mBAAmBR,OAAO;IACrCS,YAAYR,SAASD;IACrBU,mBAAmBT,SAASC;AAC9B,GAAG;AASH;;;;;;;;CAQC,GACD,OAAO,SAASS,aAAaC,KAAc;IACzC,OAAOT,GAAGS,OAAOJ;AACnB;AAEA,IAAIK;AAEJ;;;;;;;;CAQC,GACD,OAAO,SAASC,WAAWC,SAAS,IAAI;IACtC,IAAIF,oBAAoBG,aAAaD,QAAQ;QAC3C,OAAOF;IACT;IAEA,IAAII;IACJ,IAAI;QACF,8GAA8G;QAC9GA,SAASC,QAAQnB,KAAKoB,OAAO,CAACC,QAAQC,GAAG,IAAIf;IAC/C,EAAE,OAAOgB,OAAY;QACnB,IAAIA,MAAMC,IAAI,KAAK,oBAAoB;YACrCV,kBAAkB,CAAC;YACnB,OAAOA;QACT;QACAN,SAAS,CAAC,wBAAwB,EAAED,YAAY,CAAC,EAAEgB;QACnD,6CAA6C;QAC7C,OAAOF,QAAQI,IAAI,CAAC;IACtB;IAEA,IAAI,CAACb,aAAaM,SAAS;QACzBV,SACE,CAAC,eAAe,EAAED,YAAY,iGAAiG,CAAC;QAElI,6CAA6C;QAC7C,OAAOc,QAAQI,IAAI,CAAC;IACtB;IACAX,kBAAkBI;IAClB,OAAOA;AACT;AAEA,8EAA8E;AAC9E,6BAA6B;AAC7B,EAAE;AACF,wEAAwE;AACxE,4DAA4D;AAE5D;;;;;;;;;;;CAWC,GACD,OAAO,SAASQ,YACdC,UAAsB,EACtBC,WAAqB,EACrBC,SAAoB,EACpBC,aAA2B;IAE3B,uEAAuE;IACvE,wEAAwE;IACxE,6EAA6E;IAC7E,+BAA+B;IAC/B,EAAE;IACF,8EAA8E;IAC9E,2EAA2E;IAC3E,oBAAoB;IACpB,EAAE;IACF,6EAA6E;IAC7E,qBAAqB;IACrB,MAAM,EAAEC,OAAOC,OAAO,EAAEC,KAAKC,OAAO,EAAE,GAAG,AACvCJ,cACAK,UAAU;IAKZ,MAAMC,oBAAoB/B,WAAWuB,aAAa;QAChDG,OAAOC;IACT;IACA,OAAOI,kBAAkBC,CAAC,EAAE,mCAAmC;IAE/D,MAAMC,iBAAiB,IAAIC,IAAIC,OAAOC,IAAI,CAACP;IAE3C,MAAMQ,eAAe,CAACT;QACpB,OAAOK,eAAeK,GAAG,CAACV,QAAQ,CAAClC,YAAYqC,mBAAmBH;IACpE;IAEA,MAAMf,SAAkCS,WAAWjB,UAAU,IAAI,CAAC;IAClE,KAAK,MAAMuB,OAAOO,OAAOC,IAAI,CAACvB,QAAS;QACrC,IAAInB,YAAYO,UAAU2B,MAAM;YAC9B,IAAIS,aAAaT,MAAM;gBACrBJ,SAAS,CAACI,IAAI,GAAGf,MAAM,CAACe,IAAI;YAC9B;QACF,OAAO;YACLzB,SACE,CAAC,yDAAyD,EAAEyB,IAAI,kBAAkB,EAAE1B,YAAY,qCAAqC,CAAC;YAExI,6CAA6C;YAC7Cc,QAAQI,IAAI,CAAC;QACf;IACF;AACF"}
@@ -1,13 +0,0 @@
1
- import type { YargsArgs } from '../../types/yargs';
2
- /**
3
- * Builds all files in the given source directory to the given destination
4
- * directory.
5
- *
6
- * Creates destination directory if it doesn't exist.
7
- *
8
- * @param argv - Argv from Yargs.
9
- * @param argv.src - The source file path.
10
- * @param argv.dist - The output directory path.
11
- * @param argv.outfileName - The output file name.
12
- */
13
- export declare function build(argv: YargsArgs): Promise<void>;
@@ -1,15 +0,0 @@
1
- import type { BrowserifyObject } from 'browserify';
2
- import type { YargsArgs } from '../../types/yargs';
3
- /**
4
- * Builds a Snap bundle JS file from its JavaScript source.
5
- *
6
- * @param src - The source file path.
7
- * @param dest - The destination file path.
8
- * @param argv - Arguments as an object generated by `yargs`.
9
- * @param argv.sourceMaps - Whether to output sourcemaps.
10
- * @param argv.stripComments - Whether to remove comments from code.
11
- * @param argv.transpilationMode - The Babel transpilation mode.
12
- * @param bundlerTransform - An optional function which can be used to transform
13
- * the Browserify instance, e.g., adding a custom transform or plugin.
14
- */
15
- export declare function bundle(src: string, dest: string, argv: YargsArgs, bundlerTransform?: (bundler: BrowserifyObject) => void): Promise<boolean>;
@@ -1,56 +0,0 @@
1
- /// <reference types="node" />
2
- import type { YargsArgs } from '../../types/yargs';
3
- declare type WriteBundleFileArgs = {
4
- bundleError: Error;
5
- bundleBuffer: Buffer;
6
- src: string;
7
- dest: string;
8
- resolve: (value: boolean) => void;
9
- };
10
- /**
11
- * Performs postprocessing on the bundle contents and writes them to disk.
12
- * Intended to be used in the callback passed to the Browserify `.bundle()`
13
- * call.
14
- *
15
- * @param options - Options bag.
16
- * @param options.bundleError - Any error received from Browserify.
17
- * @param options.bundleBuffer - The {@link Buffer} with the bundle contents
18
- * from Browserify.
19
- * @param options.src - The source file path.
20
- * @param options.dest - The destination file path.
21
- * @param options.resolve - A {@link Promise} resolution function, so that we
22
- * can use promises and `async`/`await` even though Browserify uses callbacks.
23
- */
24
- export declare function writeBundleFile({ bundleError, bundleBuffer, src, dest, resolve, }: WriteBundleFileArgs): Promise<void>;
25
- /**
26
- * Processes dependencies and updates `argv` with an options object.
27
- *
28
- * @param argv - The Yargs arguments object.
29
- * @returns An object with options that can be passed to Babelify.
30
- */
31
- export declare function processDependencies(argv: YargsArgs): Record<string, any>;
32
- /**
33
- * Processes a string of space delimited dependencies into one RegExp string.
34
- *
35
- * @param dependencies - An array of dependencies to add to the RegExp.
36
- * @returns A RegExp object.
37
- */
38
- export declare function getDependencyRegExp(dependencies: string[]): RegExp | null;
39
- /**
40
- * Helper function remove any leading and trailing slashes from dependency list.
41
- *
42
- * @param dependencies - An array of dependencies to sanitize.
43
- * @returns An array of sanitized paths.
44
- */
45
- export declare function sanitizeDependencyPaths(dependencies: string[]): string[];
46
- /**
47
- * Check the Yargs argv object, to see if the provided options are valid. The
48
- * options are invalid if both `depsToTranspile` are provided, and
49
- * `transpilationMode` is not set to `localAndDeps`.
50
- *
51
- * @param argv - The Yargs arguments object.
52
- * @throws If the `depsToTranspile` is set, and `transpilationMode` is not set
53
- * to `localAndDeps`.
54
- */
55
- export declare function processInvalidTranspilation(argv: YargsArgs): void;
56
- export {};