@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,83 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "bundle", {
6
- enumerable: true,
7
- get: function() {
8
- return bundle;
9
- }
10
- });
11
- const _snapsbrowserifyplugin = /*#__PURE__*/ _interop_require_default(require("@metamask/snaps-browserify-plugin"));
12
- const _browserify = /*#__PURE__*/ _interop_require_default(require("browserify"));
13
- const _builders = require("../../builders");
14
- const _utils = require("./utils");
15
- function _interop_require_default(obj) {
16
- return obj && obj.__esModule ? obj : {
17
- default: obj
18
- };
19
- }
20
- async function bundle(src, dest, argv, bundlerTransform) {
21
- const { sourceMaps: debug, transpilationMode } = argv;
22
- const babelifyOptions = (0, _utils.processDependencies)(argv);
23
- return new Promise((resolve, _reject)=>{
24
- const bundler = (0, _browserify.default)(src, {
25
- debug,
26
- extensions: [
27
- '.js',
28
- '.ts'
29
- ],
30
- // Standalone is required to properly support Snaps using module.exports
31
- standalone: '<snap>'
32
- });
33
- if (transpilationMode !== _builders.TranspilationModes.None) {
34
- bundler.transform(require('babelify'), {
35
- global: transpilationMode === _builders.TranspilationModes.LocalAndDeps,
36
- extensions: [
37
- '.js',
38
- '.ts'
39
- ],
40
- presets: [
41
- require('@babel/preset-typescript'),
42
- [
43
- require('@babel/preset-env'),
44
- {
45
- targets: {
46
- browsers: [
47
- 'chrome >= 90',
48
- 'firefox >= 91'
49
- ]
50
- }
51
- }
52
- ]
53
- ],
54
- plugins: [
55
- require('@babel/plugin-transform-runtime'),
56
- require('@babel/plugin-proposal-class-properties'),
57
- require('@babel/plugin-proposal-private-methods'),
58
- require('@babel/plugin-proposal-class-static-block'),
59
- require('@babel/plugin-proposal-private-property-in-object')
60
- ],
61
- parserOpts: {
62
- attachComment: !argv.stripComments
63
- },
64
- ...babelifyOptions
65
- });
66
- }
67
- bundlerTransform?.(bundler);
68
- bundler.plugin(_snapsbrowserifyplugin.default, {
69
- stripComments: argv.stripComments,
70
- manifestPath: undefined,
71
- eval: false
72
- });
73
- bundler.bundle(async (bundleError, bundleBuffer)=>await (0, _utils.writeBundleFile)({
74
- bundleError,
75
- bundleBuffer,
76
- src,
77
- dest,
78
- resolve
79
- }));
80
- });
81
- }
82
-
83
- //# sourceMappingURL=bundle.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/cmds/build/bundle.ts"],"sourcesContent":["import type { Options } from '@metamask/snaps-browserify-plugin';\nimport plugin from '@metamask/snaps-browserify-plugin';\nimport type { BrowserifyObject } from 'browserify';\nimport browserify from 'browserify';\n\nimport { TranspilationModes } from '../../builders';\nimport type { YargsArgs } from '../../types/yargs';\nimport { processDependencies, writeBundleFile } from './utils';\n\n// We need to statically import all Browserify transforms and all Babel presets\n// and plugins, and calling `require` is the sanest way to do that.\n/* eslint-disable @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires, n/global-require */\n\n/**\n * Builds a Snap bundle JS file from its JavaScript source.\n *\n * @param src - The source file path.\n * @param dest - The destination file path.\n * @param argv - Arguments as an object generated by `yargs`.\n * @param argv.sourceMaps - Whether to output sourcemaps.\n * @param argv.stripComments - Whether to remove comments from code.\n * @param argv.transpilationMode - The Babel transpilation mode.\n * @param bundlerTransform - An optional function which can be used to transform\n * the Browserify instance, e.g., adding a custom transform or plugin.\n */\nexport async function bundle(\n src: string,\n dest: string,\n argv: YargsArgs,\n bundlerTransform?: (bundler: BrowserifyObject) => void,\n): Promise<boolean> {\n const { sourceMaps: debug, transpilationMode } = argv;\n const babelifyOptions = processDependencies(argv as any);\n return new Promise((resolve, _reject) => {\n const bundler = browserify(src, {\n debug,\n extensions: ['.js', '.ts'],\n // Standalone is required to properly support Snaps using module.exports\n standalone: '<snap>',\n });\n\n if (transpilationMode !== TranspilationModes.None) {\n bundler.transform(require('babelify'), {\n global: transpilationMode === TranspilationModes.LocalAndDeps,\n extensions: ['.js', '.ts'],\n presets: [\n require('@babel/preset-typescript'),\n [\n require('@babel/preset-env'),\n {\n targets: {\n browsers: ['chrome >= 90', 'firefox >= 91'],\n },\n },\n ],\n ],\n plugins: [\n require('@babel/plugin-transform-runtime'),\n require('@babel/plugin-proposal-class-properties'),\n require('@babel/plugin-proposal-private-methods'),\n require('@babel/plugin-proposal-class-static-block'),\n require('@babel/plugin-proposal-private-property-in-object'),\n ],\n parserOpts: {\n attachComment: !argv.stripComments,\n },\n ...(babelifyOptions as any),\n });\n }\n\n bundlerTransform?.(bundler);\n\n bundler.plugin<Options>(plugin, {\n stripComments: argv.stripComments,\n manifestPath: undefined,\n eval: false,\n });\n\n bundler.bundle(\n async (bundleError, bundleBuffer: Buffer) =>\n await writeBundleFile({\n bundleError,\n bundleBuffer,\n src,\n dest,\n resolve,\n }),\n );\n });\n}\n"],"names":["bundle","src","dest","argv","bundlerTransform","sourceMaps","debug","transpilationMode","babelifyOptions","processDependencies","Promise","resolve","_reject","bundler","browserify","extensions","standalone","TranspilationModes","None","transform","require","global","LocalAndDeps","presets","targets","browsers","plugins","parserOpts","attachComment","stripComments","plugin","manifestPath","undefined","eval","bundleError","bundleBuffer","writeBundleFile"],"mappings":";;;;+BAyBsBA;;;eAAAA;;;8EAxBH;mEAEI;0BAEY;uBAEkB;;;;;;AAkB9C,eAAeA,OACpBC,GAAW,EACXC,IAAY,EACZC,IAAe,EACfC,gBAAsD;IAEtD,MAAM,EAAEC,YAAYC,KAAK,EAAEC,iBAAiB,EAAE,GAAGJ;IACjD,MAAMK,kBAAkBC,IAAAA,0BAAmB,EAACN;IAC5C,OAAO,IAAIO,QAAQ,CAACC,SAASC;QAC3B,MAAMC,UAAUC,IAAAA,mBAAU,EAACb,KAAK;YAC9BK;YACAS,YAAY;gBAAC;gBAAO;aAAM;YAC1B,wEAAwE;YACxEC,YAAY;QACd;QAEA,IAAIT,sBAAsBU,4BAAkB,CAACC,IAAI,EAAE;YACjDL,QAAQM,SAAS,CAACC,QAAQ,aAAa;gBACrCC,QAAQd,sBAAsBU,4BAAkB,CAACK,YAAY;gBAC7DP,YAAY;oBAAC;oBAAO;iBAAM;gBAC1BQ,SAAS;oBACPH,QAAQ;oBACR;wBACEA,QAAQ;wBACR;4BACEI,SAAS;gCACPC,UAAU;oCAAC;oCAAgB;iCAAgB;4BAC7C;wBACF;qBACD;iBACF;gBACDC,SAAS;oBACPN,QAAQ;oBACRA,QAAQ;oBACRA,QAAQ;oBACRA,QAAQ;oBACRA,QAAQ;iBACT;gBACDO,YAAY;oBACVC,eAAe,CAACzB,KAAK0B,aAAa;gBACpC;gBACA,GAAIrB,eAAe;YACrB;QACF;QAEAJ,mBAAmBS;QAEnBA,QAAQiB,MAAM,CAAUA,8BAAM,EAAE;YAC9BD,eAAe1B,KAAK0B,aAAa;YACjCE,cAAcC;YACdC,MAAM;QACR;QAEApB,QAAQb,MAAM,CACZ,OAAOkC,aAAaC,eAClB,MAAMC,IAAAA,sBAAe,EAAC;gBACpBF;gBACAC;gBACAlC;gBACAC;gBACAS;YACF;IAEN;AACF"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/cmds/build/index.ts"],"sourcesContent":["import type yargs from 'yargs';\n\nimport builders from '../../builders';\nimport type { YargsArgs } from '../../types/yargs';\nimport { build } from './buildHandler';\nimport { processInvalidTranspilation } from './utils';\n\nconst command = {\n command: ['build', 'b'],\n desc: 'Build Snap from source',\n builder: (yarg: yargs.Argv) => {\n yarg\n .option('dist', builders.dist)\n .option('eval', builders.eval)\n .option('manifest', builders.manifest)\n .option('outfileName', builders.outfileName)\n .option('sourceMaps', builders.sourceMaps)\n .option('src', builders.src)\n .option('stripComments', builders.stripComments)\n .option('transpilationMode', builders.transpilationMode)\n .option('depsToTranspile', builders.depsToTranspile)\n .option('writeManifest', builders.writeManifest)\n .implies('writeManifest', 'manifest')\n .implies('depsToTranspile', 'transpilationMode')\n .middleware((argv) => processInvalidTranspilation(argv as any));\n },\n handler: async (argv: YargsArgs) => build(argv),\n};\n\nexport default command;\n"],"names":["command","desc","builder","yarg","option","builders","dist","eval","manifest","outfileName","sourceMaps","src","stripComments","transpilationMode","depsToTranspile","writeManifest","implies","middleware","argv","processInvalidTranspilation","handler","build"],"mappings":";;;;+BA6BA;;;eAAA;;;iEA3BqB;8BAEC;uBACsB;;;;;;AAE5C,MAAMA,UAAU;IACdA,SAAS;QAAC;QAAS;KAAI;IACvBC,MAAM;IACNC,SAAS,CAACC;QACRA,KACGC,MAAM,CAAC,QAAQC,iBAAQ,CAACC,IAAI,EAC5BF,MAAM,CAAC,QAAQC,iBAAQ,CAACE,IAAI,EAC5BH,MAAM,CAAC,YAAYC,iBAAQ,CAACG,QAAQ,EACpCJ,MAAM,CAAC,eAAeC,iBAAQ,CAACI,WAAW,EAC1CL,MAAM,CAAC,cAAcC,iBAAQ,CAACK,UAAU,EACxCN,MAAM,CAAC,OAAOC,iBAAQ,CAACM,GAAG,EAC1BP,MAAM,CAAC,iBAAiBC,iBAAQ,CAACO,aAAa,EAC9CR,MAAM,CAAC,qBAAqBC,iBAAQ,CAACQ,iBAAiB,EACtDT,MAAM,CAAC,mBAAmBC,iBAAQ,CAACS,eAAe,EAClDV,MAAM,CAAC,iBAAiBC,iBAAQ,CAACU,aAAa,EAC9CC,OAAO,CAAC,iBAAiB,YACzBA,OAAO,CAAC,mBAAmB,qBAC3BC,UAAU,CAAC,CAACC,OAASC,IAAAA,kCAA2B,EAACD;IACtD;IACAE,SAAS,OAAOF,OAAoBG,IAAAA,mBAAK,EAACH;AAC5C;MAEA,WAAelB"}
@@ -1,79 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for(var name in all)Object.defineProperty(target, name, {
7
- enumerable: true,
8
- get: all[name]
9
- });
10
- }
11
- _export(exports, {
12
- writeBundleFile: function() {
13
- return writeBundleFile;
14
- },
15
- processDependencies: function() {
16
- return processDependencies;
17
- },
18
- getDependencyRegExp: function() {
19
- return getDependencyRegExp;
20
- },
21
- sanitizeDependencyPaths: function() {
22
- return sanitizeDependencyPaths;
23
- },
24
- processInvalidTranspilation: function() {
25
- return processInvalidTranspilation;
26
- }
27
- });
28
- const _snapsutils = require("@metamask/snaps-utils");
29
- const _fs = require("fs");
30
- const _builders = require("../../builders");
31
- const _utils = require("../../utils");
32
- async function writeBundleFile({ bundleError, bundleBuffer, src, dest, resolve }) {
33
- if (bundleError) {
34
- await (0, _utils.writeError)('Build error:', bundleError.message, bundleError);
35
- }
36
- try {
37
- await _fs.promises.writeFile(dest, bundleBuffer?.toString());
38
- (0, _snapsutils.logInfo)(`Build success: '${src}' bundled as '${dest}'!`);
39
- resolve(true);
40
- } catch (error) {
41
- await (0, _utils.writeError)('Write error:', error.message, error, dest);
42
- }
43
- }
44
- function processDependencies(argv) {
45
- const { depsToTranspile, transpilationMode } = argv;
46
- const babelifyOptions = {};
47
- if (transpilationMode === _builders.TranspilationModes.LocalAndDeps) {
48
- const regexpStr = getDependencyRegExp(depsToTranspile);
49
- if (regexpStr !== null) {
50
- babelifyOptions.ignore = [
51
- regexpStr
52
- ];
53
- }
54
- }
55
- return babelifyOptions;
56
- }
57
- function getDependencyRegExp(dependencies) {
58
- let regexp = null;
59
- if (!dependencies || dependencies.includes('.') || !dependencies.length) {
60
- return regexp;
61
- }
62
- const paths = sanitizeDependencyPaths(dependencies);
63
- regexp = `/node_modules/(?!${paths.shift() ?? ''}`;
64
- paths.forEach((path)=>regexp += `|${path}`);
65
- regexp += '/)';
66
- return RegExp(regexp, 'u');
67
- }
68
- function sanitizeDependencyPaths(dependencies) {
69
- return dependencies.map((dependency)=>{
70
- return dependency.replace(/^[/\\]+/u, '').replace(/[/\\]+$/u, '');
71
- });
72
- }
73
- function processInvalidTranspilation(argv) {
74
- if (argv.depsToTranspile && argv.transpilationMode !== _builders.TranspilationModes.LocalAndDeps) {
75
- throw new Error('"depsToTranspile" can only be specified if "transpilationMode" is set to "localAndDeps" .');
76
- }
77
- }
78
-
79
- //# sourceMappingURL=utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/cmds/build/utils.ts"],"sourcesContent":["import { logInfo } from '@metamask/snaps-utils';\nimport { promises as fs } from 'fs';\n\nimport { TranspilationModes } from '../../builders';\nimport type { YargsArgs } from '../../types/yargs';\nimport { writeError } from '../../utils';\n\ntype WriteBundleFileArgs = {\n bundleError: Error;\n bundleBuffer: Buffer;\n src: string;\n dest: string;\n resolve: (value: boolean) => void;\n};\n\n/**\n * Performs postprocessing on the bundle contents and writes them to disk.\n * Intended to be used in the callback passed to the Browserify `.bundle()`\n * call.\n *\n * @param options - Options bag.\n * @param options.bundleError - Any error received from Browserify.\n * @param options.bundleBuffer - The {@link Buffer} with the bundle contents\n * from Browserify.\n * @param options.src - The source file path.\n * @param options.dest - The destination file path.\n * @param options.resolve - A {@link Promise} resolution function, so that we\n * can use promises and `async`/`await` even though Browserify uses callbacks.\n */\nexport async function writeBundleFile({\n bundleError,\n bundleBuffer,\n src,\n dest,\n resolve,\n}: WriteBundleFileArgs) {\n if (bundleError) {\n await writeError('Build error:', bundleError.message, bundleError);\n }\n\n try {\n await fs.writeFile(dest, bundleBuffer?.toString());\n logInfo(`Build success: '${src}' bundled as '${dest}'!`);\n resolve(true);\n } catch (error) {\n await writeError('Write error:', error.message, error, dest);\n }\n}\n\n/**\n * Processes dependencies and updates `argv` with an options object.\n *\n * @param argv - The Yargs arguments object.\n * @returns An object with options that can be passed to Babelify.\n */\nexport function processDependencies(argv: YargsArgs) {\n const { depsToTranspile, transpilationMode } = argv;\n const babelifyOptions: Record<string, any> = {};\n if (transpilationMode === TranspilationModes.LocalAndDeps) {\n const regexpStr = getDependencyRegExp(depsToTranspile as string[]);\n if (regexpStr !== null) {\n babelifyOptions.ignore = [regexpStr];\n }\n }\n return babelifyOptions;\n}\n\n/**\n * Processes a string of space delimited dependencies into one RegExp string.\n *\n * @param dependencies - An array of dependencies to add to the RegExp.\n * @returns A RegExp object.\n */\nexport function getDependencyRegExp(dependencies: string[]): RegExp | null {\n let regexp: string | null = null;\n if (!dependencies || dependencies.includes('.') || !dependencies.length) {\n return regexp;\n }\n const paths: string[] = sanitizeDependencyPaths(dependencies);\n regexp = `/node_modules/(?!${paths.shift() ?? ''}`;\n paths.forEach((path) => (regexp += `|${path}`));\n regexp += '/)';\n return RegExp(regexp, 'u');\n}\n\n/**\n * Helper function remove any leading and trailing slashes from dependency list.\n *\n * @param dependencies - An array of dependencies to sanitize.\n * @returns An array of sanitized paths.\n */\nexport function sanitizeDependencyPaths(dependencies: string[]): string[] {\n return dependencies.map((dependency) => {\n return dependency.replace(/^[/\\\\]+/u, '').replace(/[/\\\\]+$/u, '');\n });\n}\n\n/**\n * Check the Yargs argv object, to see if the provided options are valid. The\n * options are invalid if both `depsToTranspile` are provided, and\n * `transpilationMode` is not set to `localAndDeps`.\n *\n * @param argv - The Yargs arguments object.\n * @throws If the `depsToTranspile` is set, and `transpilationMode` is not set\n * to `localAndDeps`.\n */\nexport function processInvalidTranspilation(argv: YargsArgs) {\n if (\n argv.depsToTranspile &&\n argv.transpilationMode !== TranspilationModes.LocalAndDeps\n ) {\n throw new Error(\n '\"depsToTranspile\" can only be specified if \"transpilationMode\" is set to \"localAndDeps\" .',\n );\n }\n}\n"],"names":["writeBundleFile","processDependencies","getDependencyRegExp","sanitizeDependencyPaths","processInvalidTranspilation","bundleError","bundleBuffer","src","dest","resolve","writeError","message","fs","writeFile","toString","logInfo","error","argv","depsToTranspile","transpilationMode","babelifyOptions","TranspilationModes","LocalAndDeps","regexpStr","ignore","dependencies","regexp","includes","length","paths","shift","forEach","path","RegExp","map","dependency","replace","Error"],"mappings":";;;;;;;;;;;IA6BsBA,eAAe;eAAfA;;IA0BNC,mBAAmB;eAAnBA;;IAkBAC,mBAAmB;eAAnBA;;IAkBAC,uBAAuB;eAAvBA;;IAeAC,2BAA2B;eAA3BA;;;4BA1GQ;oBACO;0BAEI;uBAER;AAwBpB,eAAeJ,gBAAgB,EACpCK,WAAW,EACXC,YAAY,EACZC,GAAG,EACHC,IAAI,EACJC,OAAO,EACa;IACpB,IAAIJ,aAAa;QACf,MAAMK,IAAAA,iBAAU,EAAC,gBAAgBL,YAAYM,OAAO,EAAEN;IACxD;IAEA,IAAI;QACF,MAAMO,YAAE,CAACC,SAAS,CAACL,MAAMF,cAAcQ;QACvCC,IAAAA,mBAAO,EAAC,CAAC,gBAAgB,EAAER,IAAI,cAAc,EAAEC,KAAK,EAAE,CAAC;QACvDC,QAAQ;IACV,EAAE,OAAOO,OAAO;QACd,MAAMN,IAAAA,iBAAU,EAAC,gBAAgBM,MAAML,OAAO,EAAEK,OAAOR;IACzD;AACF;AAQO,SAASP,oBAAoBgB,IAAe;IACjD,MAAM,EAAEC,eAAe,EAAEC,iBAAiB,EAAE,GAAGF;IAC/C,MAAMG,kBAAuC,CAAC;IAC9C,IAAID,sBAAsBE,4BAAkB,CAACC,YAAY,EAAE;QACzD,MAAMC,YAAYrB,oBAAoBgB;QACtC,IAAIK,cAAc,MAAM;YACtBH,gBAAgBI,MAAM,GAAG;gBAACD;aAAU;QACtC;IACF;IACA,OAAOH;AACT;AAQO,SAASlB,oBAAoBuB,YAAsB;IACxD,IAAIC,SAAwB;IAC5B,IAAI,CAACD,gBAAgBA,aAAaE,QAAQ,CAAC,QAAQ,CAACF,aAAaG,MAAM,EAAE;QACvE,OAAOF;IACT;IACA,MAAMG,QAAkB1B,wBAAwBsB;IAChDC,SAAS,CAAC,iBAAiB,EAAEG,MAAMC,KAAK,MAAM,GAAG,CAAC;IAClDD,MAAME,OAAO,CAAC,CAACC,OAAUN,UAAU,CAAC,CAAC,EAAEM,KAAK,CAAC;IAC7CN,UAAU;IACV,OAAOO,OAAOP,QAAQ;AACxB;AAQO,SAASvB,wBAAwBsB,YAAsB;IAC5D,OAAOA,aAAaS,GAAG,CAAC,CAACC;QACvB,OAAOA,WAAWC,OAAO,CAAC,YAAY,IAAIA,OAAO,CAAC,YAAY;IAChE;AACF;AAWO,SAAShC,4BAA4Ba,IAAe;IACzD,IACEA,KAAKC,eAAe,IACpBD,KAAKE,iBAAiB,KAAKE,4BAAkB,CAACC,YAAY,EAC1D;QACA,MAAM,IAAIe,MACR;IAEJ;AACF"}
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "evalHandler", {
6
- enumerable: true,
7
- get: function() {
8
- return evalHandler;
9
- }
10
- });
11
- const _snapsutils = require("@metamask/snaps-utils");
12
- const _utils = require("@metamask/utils");
13
- async function evalHandler(argv) {
14
- const { bundle: bundlePath } = argv;
15
- (0, _utils.assert)(typeof bundlePath === 'string');
16
- try {
17
- await (0, _snapsutils.evalBundle)(bundlePath);
18
- (0, _snapsutils.logInfo)(`Eval Success: evaluated '${bundlePath}' in SES!`);
19
- } catch (error) {
20
- throw new Error(`Snap evaluation error: ${error.message}`);
21
- }
22
- }
23
-
24
- //# sourceMappingURL=evalHandler.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/cmds/eval/evalHandler.ts"],"sourcesContent":["import { evalBundle, logInfo } from '@metamask/snaps-utils';\nimport { assert } from '@metamask/utils';\n\nimport type { YargsArgs } from '../../types/yargs';\n\n/**\n * Runs the snap in a worker, to ensure SES compatibility.\n *\n * @param argv - The Yargs arguments object.\n * @returns A promise that resolves once the eval has finished.\n * @throws If the eval failed.\n */\nexport async function evalHandler(argv: YargsArgs): Promise<void> {\n const { bundle: bundlePath } = argv;\n\n assert(typeof bundlePath === 'string');\n\n try {\n await evalBundle(bundlePath);\n logInfo(`Eval Success: evaluated '${bundlePath}' in SES!`);\n } catch (error) {\n throw new Error(`Snap evaluation error: ${error.message}`);\n }\n}\n"],"names":["evalHandler","argv","bundle","bundlePath","assert","evalBundle","logInfo","error","Error","message"],"mappings":";;;;+BAYsBA;;;eAAAA;;;4BAZc;uBACb;AAWhB,eAAeA,YAAYC,IAAe;IAC/C,MAAM,EAAEC,QAAQC,UAAU,EAAE,GAAGF;IAE/BG,IAAAA,aAAM,EAAC,OAAOD,eAAe;IAE7B,IAAI;QACF,MAAME,IAAAA,sBAAU,EAACF;QACjBG,IAAAA,mBAAO,EAAC,CAAC,yBAAyB,EAAEH,WAAW,SAAS,CAAC;IAC3D,EAAE,OAAOI,OAAO;QACd,MAAM,IAAIC,MAAM,CAAC,uBAAuB,EAAED,MAAME,OAAO,CAAC,CAAC;IAC3D;AACF"}
@@ -1,31 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "default", {
6
- enumerable: true,
7
- get: function() {
8
- return _default;
9
- }
10
- });
11
- const _builders = /*#__PURE__*/ _interop_require_default(require("../../builders"));
12
- const _evalHandler = require("./evalHandler");
13
- function _interop_require_default(obj) {
14
- return obj && obj.__esModule ? obj : {
15
- default: obj
16
- };
17
- }
18
- const command = {
19
- command: [
20
- 'eval',
21
- 'e'
22
- ],
23
- desc: 'Attempt to evaluate Snap bundle in SES',
24
- builder: (yarg)=>{
25
- yarg.option('bundle', _builders.default.bundle);
26
- },
27
- handler: async (argv)=>(0, _evalHandler.evalHandler)(argv)
28
- };
29
- const _default = command;
30
-
31
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/cmds/eval/index.ts"],"sourcesContent":["import type yargs from 'yargs';\n\nimport builders from '../../builders';\nimport type { YargsArgs } from '../../types/yargs';\nimport { evalHandler } from './evalHandler';\n\nconst command = {\n command: ['eval', 'e'],\n desc: 'Attempt to evaluate Snap bundle in SES',\n builder: (yarg: yargs.Argv) => {\n yarg.option('bundle', builders.bundle);\n },\n handler: async (argv: YargsArgs) => evalHandler(argv),\n};\n\nexport default command;\n"],"names":["command","desc","builder","yarg","option","builders","bundle","handler","argv","evalHandler"],"mappings":";;;;+BAeA;;;eAAA;;;iEAbqB;6BAEO;;;;;;AAE5B,MAAMA,UAAU;IACdA,SAAS;QAAC;QAAQ;KAAI;IACtBC,MAAM;IACNC,SAAS,CAACC;QACRA,KAAKC,MAAM,CAAC,UAAUC,iBAAQ,CAACC,MAAM;IACvC;IACAC,SAAS,OAAOC,OAAoBC,IAAAA,wBAAW,EAACD;AAClD;MAEA,WAAeR"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/cmds/index.ts"],"sourcesContent":["import build from './build';\nimport evaluate from './eval';\nimport manifest from './manifest';\nimport serve from './serve';\nimport watch from './watch';\n\nconst commands = [build, evaluate, manifest, serve, watch];\nexport default commands;\n"],"names":["commands","build","evaluate","manifest","serve","watch"],"mappings":";;;;+BAOA;;;eAAA;;;8DAPkB;6DACG;iEACA;8DACH;8DACA;;;;;;AAElB,MAAMA,WAAW;IAACC,cAAK;IAAEC,aAAQ;IAAEC,iBAAQ;IAAEC,cAAK;IAAEC,cAAK;CAAC;MAC1D,WAAeL"}
@@ -1,44 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "default", {
6
- enumerable: true,
7
- get: function() {
8
- return _default;
9
- }
10
- });
11
- const _builders = /*#__PURE__*/ _interop_require_default(require("../../builders"));
12
- const _utils = require("../../utils");
13
- const _manifestHandler = require("./manifestHandler");
14
- function _interop_require_default(obj) {
15
- return obj && obj.__esModule ? obj : {
16
- default: obj
17
- };
18
- }
19
- const command = {
20
- command: [
21
- 'manifest',
22
- 'm'
23
- ],
24
- desc: 'Validate the snap.manifest.json file',
25
- builder: (yarg)=>{
26
- yarg.option('writeManifest', {
27
- ..._builders.default.writeManifest,
28
- alias: [
29
- 'fix'
30
- ]
31
- });
32
- },
33
- handler: async (argv)=>{
34
- try {
35
- await (0, _manifestHandler.manifestHandler)(argv);
36
- } catch (error) {
37
- (0, _utils.logError)(error.message, error);
38
- throw error;
39
- }
40
- }
41
- };
42
- const _default = command;
43
-
44
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/cmds/manifest/index.ts"],"sourcesContent":["import type yargs from 'yargs';\n\nimport builders from '../../builders';\nimport type { YargsArgs } from '../../types/yargs';\nimport { logError } from '../../utils';\nimport { manifestHandler } from './manifestHandler';\n\nconst command = {\n command: ['manifest', 'm'],\n desc: 'Validate the snap.manifest.json file',\n builder: (yarg: yargs.Argv) => {\n yarg.option('writeManifest', { ...builders.writeManifest, alias: ['fix'] });\n },\n handler: async (argv: YargsArgs) => {\n try {\n await manifestHandler(argv);\n } catch (error) {\n logError(error.message, error);\n throw error;\n }\n },\n};\n\nexport default command;\n"],"names":["command","desc","builder","yarg","option","builders","writeManifest","alias","handler","argv","manifestHandler","error","logError","message"],"mappings":";;;;+BAuBA;;;eAAA;;;iEArBqB;uBAEI;iCACO;;;;;;AAEhC,MAAMA,UAAU;IACdA,SAAS;QAAC;QAAY;KAAI;IAC1BC,MAAM;IACNC,SAAS,CAACC;QACRA,KAAKC,MAAM,CAAC,iBAAiB;YAAE,GAAGC,iBAAQ,CAACC,aAAa;YAAEC,OAAO;gBAAC;aAAM;QAAC;IAC3E;IACAC,SAAS,OAAOC;QACd,IAAI;YACF,MAAMC,IAAAA,gCAAe,EAACD;QACxB,EAAE,OAAOE,OAAO;YACdC,IAAAA,eAAQ,EAACD,MAAME,OAAO,EAAEF;YACxB,MAAMA;QACR;IACF;AACF;MAEA,WAAeX"}
@@ -1,47 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "manifestHandler", {
6
- enumerable: true,
7
- get: function() {
8
- return manifestHandler;
9
- }
10
- });
11
- const _snapsutils = require("@metamask/snaps-utils");
12
- const ERROR_PREFIX = 'Manifest Error: ';
13
- async function manifestHandler({ writeManifest }) {
14
- try {
15
- const { warnings, errors } = await (0, _snapsutils.checkManifest)(process.cwd(), Boolean(writeManifest));
16
- if (!writeManifest && errors.length > 0) {
17
- (0, _snapsutils.logError)(`${ERROR_PREFIX}The manifest is invalid.`);
18
- errors.forEach(logManifestError);
19
- // eslint-disable-next-line n/no-process-exit
20
- process.exit(1);
21
- }
22
- if (warnings.length > 0) {
23
- (0, _snapsutils.logWarning)('Manifest Warning: Validation of snap.manifest.json completed with warnings.');
24
- warnings.forEach(logManifestWarning);
25
- }
26
- } catch (error) {
27
- throw new Error(`${ERROR_PREFIX}${error}`);
28
- }
29
- }
30
- /**
31
- * Logs a manifest warning, if `suppressWarnings` is not enabled.
32
- *
33
- * @param message - The message to log.
34
- */ function logManifestWarning(message) {
35
- if (!global.snaps.suppressWarnings) {
36
- (0, _snapsutils.logWarning)(`Manifest Warning: ${message}`);
37
- }
38
- }
39
- /**
40
- * Logs a manifest error.
41
- *
42
- * @param message - The message to log.
43
- */ function logManifestError(message) {
44
- (0, _snapsutils.logError)(`${ERROR_PREFIX}${message}`);
45
- }
46
-
47
- //# 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":["manifestHandler","ERROR_PREFIX","writeManifest","warnings","errors","checkManifest","process","cwd","Boolean","length","logError","forEach","logManifestError","exit","logWarning","logManifestWarning","error","Error","message","global","snaps","suppressWarnings"],"mappings":";;;;+BAcsBA;;;eAAAA;;;4BAd8B;AAIpD,MAAMC,eAAe;AAUd,eAAeD,gBAAgB,EAAEE,aAAa,EAAa;IAChE,IAAI;QACF,MAAM,EAAEC,QAAQ,EAAEC,MAAM,EAAE,GAAG,MAAMC,IAAAA,yBAAa,EAC9CC,QAAQC,GAAG,IACXC,QAAQN;QAGV,IAAI,CAACA,iBAAiBE,OAAOK,MAAM,GAAG,GAAG;YACvCC,IAAAA,oBAAQ,EAAC,CAAC,EAAET,aAAa,wBAAwB,CAAC;YAClDG,OAAOO,OAAO,CAACC;YAEf,6CAA6C;YAC7CN,QAAQO,IAAI,CAAC;QACf;QAEA,IAAIV,SAASM,MAAM,GAAG,GAAG;YACvBK,IAAAA,sBAAU,EACR;YAEFX,SAASQ,OAAO,CAACI;QACnB;IACF,EAAE,OAAOC,OAAO;QACd,MAAM,IAAIC,MAAM,CAAC,EAAEhB,aAAa,EAAEe,MAAM,CAAC;IAC3C;AACF;AAEA;;;;CAIC,GACD,SAASD,mBAAmBG,OAAe;IACzC,IAAI,CAACC,OAAOC,KAAK,CAACC,gBAAgB,EAAE;QAClCP,IAAAA,sBAAU,EAAC,CAAC,kBAAkB,EAAEI,QAAQ,CAAC;IAC3C;AACF;AAEA;;;;CAIC,GACD,SAASN,iBAAiBM,OAAe;IACvCR,IAAAA,oBAAQ,EAAC,CAAC,EAAET,aAAa,EAAEiB,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":["command","desc","builder","yarg","option","builders","root","port","handler","argv","serve"],"mappings":";;;;+BAeA;;;eAAA;;;iEAbqB;8BAEC;;;;;;AAEtB,MAAMA,UAAU;IACdA,SAAS;QAAC;QAAS;KAAI;IACvBC,MAAM;IACNC,SAAS,CAACC;QACRA,KAAKC,MAAM,CAAC,QAAQC,iBAAQ,CAACC,IAAI,EAAEF,MAAM,CAAC,QAAQC,iBAAQ,CAACE,IAAI;IACjE;IACAC,SAAS,OAAOC,OAAoBC,IAAAA,mBAAK,EAACD;AAC5C;MAEA,WAAeT"}
@@ -1,62 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "serve", {
6
- enumerable: true,
7
- get: function() {
8
- return serve;
9
- }
10
- });
11
- const _snapsutils = require("@metamask/snaps-utils");
12
- const _http = /*#__PURE__*/ _interop_require_default(require("http"));
13
- const _servehandler = /*#__PURE__*/ _interop_require_default(require("serve-handler"));
14
- const _serveUtils = require("./serveUtils");
15
- function _interop_require_default(obj) {
16
- return obj && obj.__esModule ? obj : {
17
- default: obj
18
- };
19
- }
20
- async function serve(argv) {
21
- const { port, root: rootDir } = argv;
22
- await (0, _snapsutils.validateDirPath)(rootDir, true);
23
- (0, _snapsutils.logInfo)(`\nStarting server...`);
24
- const server = _http.default.createServer((req, res)=>{
25
- (0, _servehandler.default)(req, res, {
26
- public: rootDir,
27
- headers: [
28
- {
29
- source: '**/*',
30
- headers: [
31
- {
32
- key: 'Cache-Control',
33
- value: 'no-cache'
34
- },
35
- {
36
- key: 'Access-Control-Allow-Origin',
37
- value: '*'
38
- }
39
- ]
40
- }
41
- ]
42
- })?.catch((error)=>{
43
- (0, _serveUtils.logServerError)(error, argv.port);
44
- res.statusCode = 500;
45
- res.end();
46
- });
47
- });
48
- server.listen({
49
- port
50
- }, ()=>(0, _serveUtils.logServerListening)(port));
51
- server.on('request', (request)=>(0, _serveUtils.logRequest)(request));
52
- server.on('error', (error)=>{
53
- (0, _serveUtils.logServerError)(error, argv.port);
54
- process.exitCode = 1;
55
- });
56
- server.on('close', ()=>{
57
- (0, _snapsutils.logInfo)('Server closed');
58
- process.exitCode = 1;
59
- });
60
- }
61
-
62
- //# 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":["serve","argv","port","root","rootDir","validateDirPath","logInfo","server","http","createServer","req","res","serveHandler","public","headers","source","key","value","catch","error","logServerError","statusCode","end","listen","logServerListening","on","request","logRequest","process","exitCode"],"mappings":";;;;+BAesBA;;;eAAAA;;;4BAfmB;6DACxB;qEACQ;4BAGsC;;;;;;AAUxD,eAAeA,MAAMC,IAAe;IACzC,MAAM,EAAEC,IAAI,EAAEC,MAAMC,OAAO,EAAE,GAAGH;IAEhC,MAAMI,IAAAA,2BAAe,EAACD,SAAmB;IAEzCE,IAAAA,mBAAO,EAAC,CAAC,oBAAoB,CAAC;IAE9B,MAAMC,SAASC,aAAI,CAACC,YAAY,CAAC,CAACC,KAAKC;QACrCC,IAAAA,qBAAY,EAACF,KAAKC,KAAK;YACrBE,QAAQT;YACRU,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;YACTC,IAAAA,0BAAc,EAACD,OAAOlB,KAAKC,IAAI;YAC/BS,IAAIU,UAAU,GAAG;YACjBV,IAAIW,GAAG;QACT;IACF;IAEAf,OAAOgB,MAAM,CAAC;QAAErB;IAAK,GAAG,IAAMsB,IAAAA,8BAAkB,EAACtB;IAEjDK,OAAOkB,EAAE,CAAC,WAAW,CAACC,UAAYC,IAAAA,sBAAU,EAACD;IAE7CnB,OAAOkB,EAAE,CAAC,SAAS,CAACN;QAClBC,IAAAA,0BAAc,EAACD,OAAOlB,KAAKC,IAAI;QAC/B0B,QAAQC,QAAQ,GAAG;IACrB;IAEAtB,OAAOkB,EAAE,CAAC,SAAS;QACjBnB,IAAAA,mBAAO,EAAC;QACRsB,QAAQC,QAAQ,GAAG;IACrB;AACF"}
@@ -1,37 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for(var name in all)Object.defineProperty(target, name, {
7
- enumerable: true,
8
- get: all[name]
9
- });
10
- }
11
- _export(exports, {
12
- logServerListening: function() {
13
- return logServerListening;
14
- },
15
- logRequest: function() {
16
- return logRequest;
17
- },
18
- logServerError: function() {
19
- return logServerError;
20
- }
21
- });
22
- const _snapsutils = require("@metamask/snaps-utils");
23
- function logServerListening(port) {
24
- (0, _snapsutils.logInfo)(`Server listening on: http://localhost:${port}`);
25
- }
26
- function logRequest(request) {
27
- (0, _snapsutils.logInfo)(`Handling incoming request for: ${request.url ?? 'unknown'}`);
28
- }
29
- function logServerError(error, port) {
30
- if (error.code === 'EADDRINUSE') {
31
- (0, _snapsutils.logError)(`Server error: Port ${port} already in use.`);
32
- } else {
33
- (0, _snapsutils.logError)(`Server error: ${error.message}`);
34
- }
35
- }
36
-
37
- //# 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":["logServerListening","logRequest","logServerError","port","logInfo","request","url","error","code","logError","message"],"mappings":";;;;;;;;;;;IAOgBA,kBAAkB;eAAlBA;;IAUAC,UAAU;eAAVA;;IAUAC,cAAc;eAAdA;;;4BA3BkB;AAO3B,SAASF,mBAAmBG,IAAY;IAC7CC,IAAAA,mBAAO,EAAC,CAAC,sCAAsC,EAAED,KAAK,CAAC;AACzD;AAQO,SAASF,WAAWI,OAAyB;IAClDD,IAAAA,mBAAO,EAAC,CAAC,+BAA+B,EAAEC,QAAQC,GAAG,IAAI,UAAU,CAAC;AACtE;AAQO,SAASJ,eAAeK,KAAY,EAAEJ,IAAY;IACvD,IAAI,AAACI,MAAcC,IAAI,KAAK,cAAc;QACxCC,IAAAA,oBAAQ,EAAC,CAAC,mBAAmB,EAAEN,KAAK,gBAAgB,CAAC;IACvD,OAAO;QACLM,IAAAA,oBAAQ,EAAC,CAAC,cAAc,EAAEF,MAAMG,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":["command","desc","builder","yarg","option","builders","src","eval","dist","outfileName","sourceMaps","stripComments","transpilationMode","depsToTranspile","manifest","writeManifest","serve","root","port","implies","middleware","argv","processInvalidTranspilation","handler","watch"],"mappings":";;;;+BAgCA;;;eAAA;;;iEA9BqB;uBAEuB;8BACtB;;;;;;AAEtB,MAAMA,UAAU;IACdA,SAAS;QAAC;QAAS;KAAI;IACvBC,MAAM;IACNC,SAAS,CAACC;QACRA,KACGC,MAAM,CAAC,OAAOC,iBAAQ,CAACC,GAAG,EAC1BF,MAAM,CAAC,QAAQC,iBAAQ,CAACE,IAAI,EAC5BH,MAAM,CAAC,QAAQC,iBAAQ,CAACG,IAAI,EAC5BJ,MAAM,CAAC,eAAeC,iBAAQ,CAACI,WAAW,EAC1CL,MAAM,CAAC,cAAcC,iBAAQ,CAACK,UAAU,EACxCN,MAAM,CAAC,iBAAiBC,iBAAQ,CAACM,aAAa,EAC9CP,MAAM,CAAC,qBAAqBC,iBAAQ,CAACO,iBAAiB,EACtDR,MAAM,CAAC,mBAAmBC,iBAAQ,CAACQ,eAAe,EAClDT,MAAM,CAAC,YAAYC,iBAAQ,CAACS,QAAQ,EACpCV,MAAM,CAAC,iBAAiBC,iBAAQ,CAACU,aAAa,EAC9CX,MAAM,CAAC,SAASC,iBAAQ,CAACW,KAAK,EAC9BZ,MAAM,CAAC,QAAQC,iBAAQ,CAACY,IAAI,EAC5Bb,MAAM,CAAC,QAAQC,iBAAQ,CAACa,IAAI,EAC5BC,OAAO,CAAC,iBAAiB,YACzBA,OAAO,CAAC,mBAAmB,qBAC3BC,UAAU,CAAC,CAACC,OAASC,IAAAA,kCAA2B,EAACD;IACtD;IACAE,SAAS,OAAOF,OAAoBG,IAAAA,mBAAK,EAACH;AAC5C;MAEA,WAAerB"}
@@ -1,91 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "watch", {
6
- enumerable: true,
7
- get: function() {
8
- return watch;
9
- }
10
- });
11
- const _snapsutils = require("@metamask/snaps-utils");
12
- const _chokidar = /*#__PURE__*/ _interop_require_default(require("chokidar"));
13
- const _path = /*#__PURE__*/ _interop_require_default(require("path"));
14
- const _utils = require("../../utils");
15
- const _bundle = require("../build/bundle");
16
- const _evalHandler = require("../eval/evalHandler");
17
- const _manifestHandler = require("../manifest/manifestHandler");
18
- const _serveHandler = require("../serve/serveHandler");
19
- function _interop_require_default(obj) {
20
- return obj && obj.__esModule ? obj : {
21
- default: obj
22
- };
23
- }
24
- async function watch(argv) {
25
- const { dist, eval: shouldEval, manifest, outfileName, src, serve: shouldServe } = argv;
26
- if (outfileName) {
27
- (0, _snapsutils.validateOutfileName)(outfileName);
28
- }
29
- await (0, _snapsutils.validateFilePath)(src);
30
- await (0, _snapsutils.validateDirPath)(dist, true);
31
- const srcDir = _path.default.dirname(src);
32
- const watchDirs = [
33
- srcDir,
34
- _snapsutils.NpmSnapFileNames.Manifest,
35
- _utils.CONFIG_FILE
36
- ];
37
- const outfilePath = (0, _snapsutils.getOutfilePath)(dist, outfileName);
38
- const buildSnap = async (path, logMessage)=>{
39
- if (logMessage !== undefined) {
40
- (0, _snapsutils.logInfo)(logMessage);
41
- }
42
- try {
43
- await (0, _bundle.bundle)(src, outfilePath, argv, (0, _utils.loadConfig)().bundlerCustomizer);
44
- if (manifest) {
45
- await (0, _manifestHandler.manifestHandler)(argv);
46
- }
47
- if (shouldEval) {
48
- await (0, _evalHandler.evalHandler)({
49
- ...argv,
50
- bundle: outfilePath
51
- });
52
- }
53
- } catch (error) {
54
- (0, _snapsutils.logError)(`Error ${path === undefined ? 'during initial build' : `while processing "${path}"`}.`, error);
55
- }
56
- };
57
- _chokidar.default.watch(watchDirs, {
58
- ignoreInitial: true,
59
- ignored: [
60
- '**/node_modules/**',
61
- `**/${dist}/**`,
62
- `**/test/**`,
63
- `**/tests/**`,
64
- `**/*.test.js`,
65
- `**/*.test.ts`,
66
- /* istanbul ignore next */ (str)=>str !== '.' && str.startsWith('.')
67
- ]
68
- }).on('ready', ()=>{
69
- buildSnap().then(()=>{
70
- if (shouldServe) {
71
- return (0, _serveHandler.serve)(argv);
72
- }
73
- return undefined;
74
- }).catch((error)=>{
75
- (0, _snapsutils.logError)('Error during initial build.', error);
76
- });
77
- }).on('add', (path)=>{
78
- buildSnap(path, `File added: ${path}`).catch((error)=>{
79
- (0, _snapsutils.logError)(`Error while processing "${path}".`, error);
80
- });
81
- }).on('change', (path)=>{
82
- buildSnap(path, `File changed: ${path}`).catch((error)=>{
83
- (0, _snapsutils.logError)(`Error while processing "${path}".`, error);
84
- });
85
- }).on('unlink', (path)=>(0, _snapsutils.logInfo)(`File removed: ${path}`)).on('error', (error)=>{
86
- (0, _snapsutils.logError)(`Watcher error: ${error.message}`, error);
87
- });
88
- (0, _snapsutils.logInfo)(`Watching ${watchDirs.map((dir)=>`'${dir}'`).join(', ')} for changes...`);
89
- }
90
-
91
- //# 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":["watch","argv","dist","eval","shouldEval","manifest","outfileName","src","serve","shouldServe","validateOutfileName","validateFilePath","validateDirPath","srcDir","pathUtils","dirname","watchDirs","NpmSnapFileNames","Manifest","CONFIG_FILE","outfilePath","getOutfilePath","buildSnap","path","logMessage","undefined","logInfo","bundle","loadConfig","bundlerCustomizer","manifestHandler","evalHandler","error","logError","chokidar","ignoreInitial","ignored","str","startsWith","on","then","catch","message","map","dir","join"],"mappings":";;;;+BA+BsBA;;;eAAAA;;;4BAvBf;iEACc;6DACC;uBAGkB;wBACjB;6BACK;iCACI;8BACV;;;;;;AAcf,eAAeA,MAAMC,IAAe;IACzC,MAAM,EACJC,IAAI,EACJC,MAAMC,UAAU,EAChBC,QAAQ,EACRC,WAAW,EACXC,GAAG,EACHC,OAAOC,WAAW,EACnB,GAAGR;IACJ,IAAIK,aAAa;QACfI,IAAAA,+BAAmB,EAACJ;IACtB;IACA,MAAMK,IAAAA,4BAAgB,EAACJ;IACvB,MAAMK,IAAAA,2BAAe,EAACV,MAAM;IAC5B,MAAMW,SAASC,aAAS,CAACC,OAAO,CAACR;IACjC,MAAMS,YAAY;QAACH;QAAQI,4BAAgB,CAACC,QAAQ;QAAEC,kBAAW;KAAC;IAClE,MAAMC,cAAcC,IAAAA,0BAAc,EAACnB,MAAMI;IAEzC,MAAMgB,YAAY,OAAOC,MAAeC;QACtC,IAAIA,eAAeC,WAAW;YAC5BC,IAAAA,mBAAO,EAACF;QACV;QAEA,IAAI;YACF,MAAMG,IAAAA,cAAM,EAACpB,KAAKa,aAAanB,MAAM2B,IAAAA,iBAAU,IAAGC,iBAAiB;YAEnE,IAAIxB,UAAU;gBACZ,MAAMyB,IAAAA,gCAAe,EAAC7B;YACxB;YAEA,IAAIG,YAAY;gBACd,MAAM2B,IAAAA,wBAAW,EAAC;oBAAE,GAAG9B,IAAI;oBAAE0B,QAAQP;gBAAY;YACnD;QACF,EAAE,OAAOY,OAAO;YACdC,IAAAA,oBAAQ,EACN,CAAC,MAAM,EACLV,SAASE,YACL,yBACA,CAAC,kBAAkB,EAAEF,KAAK,CAAC,CAAC,CACjC,CAAC,CAAC,EACHS;QAEJ;IACF;IAEAE,iBAAQ,CACLlC,KAAK,CAACgB,WAAW;QAChBmB,eAAe;QACfC,SAAS;YACP;YACA,CAAC,GAAG,EAAElC,KAAK,GAAG,CAAC;YACf,CAAC,UAAU,CAAC;YACZ,CAAC,WAAW,CAAC;YACb,CAAC,YAAY,CAAC;YACd,CAAC,YAAY,CAAC;YACd,wBAAwB,GACxB,CAACmC,MAAgBA,QAAQ,OAAOA,IAAIC,UAAU,CAAC;SAChD;IACH,GAECC,EAAE,CAAC,SAAS;QACXjB,YACGkB,IAAI,CAAC;YACJ,IAAI/B,aAAa;gBACf,OAAOD,IAAAA,mBAAK,EAACP;YACf;YAEA,OAAOwB;QACT,GACCgB,KAAK,CAAC,CAACT;YACNC,IAAAA,oBAAQ,EAAC,+BAA+BD;QAC1C;IACJ,GACCO,EAAE,CAAC,OAAO,CAAChB;QACVD,UAAUC,MAAM,CAAC,YAAY,EAAEA,KAAK,CAAC,EAAEkB,KAAK,CAAC,CAACT;YAC5CC,IAAAA,oBAAQ,EAAC,CAAC,wBAAwB,EAAEV,KAAK,EAAE,CAAC,EAAES;QAChD;IACF,GACCO,EAAE,CAAC,UAAU,CAAChB;QACbD,UAAUC,MAAM,CAAC,cAAc,EAAEA,KAAK,CAAC,EAAEkB,KAAK,CAAC,CAACT;YAC9CC,IAAAA,oBAAQ,EAAC,CAAC,wBAAwB,EAAEV,KAAK,EAAE,CAAC,EAAES;QAChD;IACF,GACCO,EAAE,CAAC,UAAU,CAAChB,OAASG,IAAAA,mBAAO,EAAC,CAAC,cAAc,EAAEH,KAAK,CAAC,GACtDgB,EAAE,CAAC,SAAS,CAACP;QACZC,IAAAA,oBAAQ,EAAC,CAAC,eAAe,EAAED,MAAMU,OAAO,CAAC,CAAC,EAAEV;IAC9C;IAEFN,IAAAA,mBAAO,EACL,CAAC,SAAS,EAAEV,UAAU2B,GAAG,CAAC,CAACC,MAAQ,CAAC,CAAC,EAAEA,IAAI,CAAC,CAAC,EAAEC,IAAI,CAAC,MAAM,eAAe,CAAC;AAE9E"}