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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (253) hide show
  1. package/CHANGELOG.md +377 -19
  2. package/README.md +67 -542
  3. package/dist/builders.d.ts +27 -0
  4. package/dist/{esm/builders.js → builders.js} +51 -48
  5. package/dist/builders.js.map +1 -0
  6. package/dist/{types/cli.d.ts → cli.d.ts} +1 -1
  7. package/dist/cli.js +51 -0
  8. package/dist/cli.js.map +1 -0
  9. package/dist/cmds/build/buildHandler.d.ts +13 -0
  10. package/dist/cmds/build/buildHandler.js +37 -0
  11. package/dist/cmds/build/buildHandler.js.map +1 -0
  12. package/dist/cmds/build/bundle.d.ts +15 -0
  13. package/dist/cmds/build/bundle.js +80 -0
  14. package/dist/cmds/build/bundle.js.map +1 -0
  15. package/dist/{types/commands/serve → cmds/build}/index.d.ts +4 -4
  16. package/dist/cmds/build/index.js +29 -0
  17. package/dist/cmds/build/index.js.map +1 -0
  18. package/dist/cmds/build/utils.d.ts +56 -0
  19. package/dist/cmds/build/utils.js +100 -0
  20. package/dist/cmds/build/utils.js.map +1 -0
  21. package/dist/cmds/eval/evalHandler.d.ts +9 -0
  22. package/dist/cmds/eval/evalHandler.js +25 -0
  23. package/dist/cmds/eval/evalHandler.js.map +1 -0
  24. package/dist/cmds/eval/index.d.ts +9 -0
  25. package/dist/cmds/eval/index.js +15 -0
  26. package/dist/cmds/eval/index.js.map +1 -0
  27. package/dist/cmds/index.js +14 -0
  28. package/dist/cmds/index.js.map +1 -0
  29. package/dist/cmds/init/index.d.ts +9 -0
  30. package/dist/cmds/init/index.js +34 -0
  31. package/dist/cmds/init/index.js.map +1 -0
  32. package/dist/cmds/init/initHandler.d.ts +26 -0
  33. package/dist/cmds/init/initHandler.js +69 -0
  34. package/dist/cmds/init/initHandler.js.map +1 -0
  35. package/dist/cmds/init/initUtils.d.ts +39 -0
  36. package/dist/cmds/init/initUtils.js +122 -0
  37. package/dist/cmds/init/initUtils.js.map +1 -0
  38. package/dist/cmds/manifest/index.d.ts +9 -0
  39. package/dist/cmds/manifest/index.js +24 -0
  40. package/dist/cmds/manifest/index.js.map +1 -0
  41. package/dist/cmds/manifest/manifestHandler.d.ts +10 -0
  42. package/dist/cmds/manifest/manifestHandler.js +50 -0
  43. package/dist/cmds/manifest/manifestHandler.js.map +1 -0
  44. package/dist/cmds/serve/index.d.ts +9 -0
  45. package/dist/cmds/serve/index.js +15 -0
  46. package/dist/cmds/serve/index.js.map +1 -0
  47. package/dist/cmds/serve/serveHandler.d.ts +10 -0
  48. package/dist/cmds/serve/serveHandler.js +59 -0
  49. package/dist/cmds/serve/serveHandler.js.map +1 -0
  50. package/dist/cmds/serve/serveUtils.d.ts +22 -0
  51. package/dist/cmds/serve/serveUtils.js +39 -0
  52. package/dist/cmds/serve/serveUtils.js.map +1 -0
  53. package/dist/cmds/watch/index.d.ts +9 -0
  54. package/dist/cmds/watch/index.js +32 -0
  55. package/dist/cmds/watch/index.js.map +1 -0
  56. package/dist/cmds/watch/watchHandler.d.ts +14 -0
  57. package/dist/cmds/watch/watchHandler.js +100 -0
  58. package/dist/cmds/watch/watchHandler.js.map +1 -0
  59. package/dist/main.js +15 -0
  60. package/dist/main.js.map +1 -0
  61. package/dist/utils/index.d.ts +2 -0
  62. package/dist/utils/index.js +19 -0
  63. package/dist/utils/index.js.map +1 -0
  64. package/dist/utils/misc.d.ts +53 -0
  65. package/dist/utils/misc.js +156 -0
  66. package/dist/utils/misc.js.map +1 -0
  67. package/dist/utils/snap-config.d.ts +48 -0
  68. package/dist/utils/snap-config.js +117 -0
  69. package/dist/utils/snap-config.js.map +1 -0
  70. package/package.json +35 -54
  71. package/.browserslistrc +0 -3
  72. package/dist/cjs/builders.js +0 -148
  73. package/dist/cjs/builders.js.map +0 -1
  74. package/dist/cjs/cli.js +0 -35
  75. package/dist/cjs/cli.js.map +0 -1
  76. package/dist/cjs/commands/build/build.js +0 -54
  77. package/dist/cjs/commands/build/build.js.map +0 -1
  78. package/dist/cjs/commands/build/implementation.js +0 -31
  79. package/dist/cjs/commands/build/implementation.js.map +0 -1
  80. package/dist/cjs/commands/build/index.js +0 -45
  81. package/dist/cjs/commands/build/index.js.map +0 -1
  82. package/dist/cjs/commands/eval/eval.js +0 -57
  83. package/dist/cjs/commands/eval/eval.js.map +0 -1
  84. package/dist/cjs/commands/eval/implementation.js +0 -27
  85. package/dist/cjs/commands/eval/implementation.js.map +0 -1
  86. package/dist/cjs/commands/eval/index.js +0 -50
  87. package/dist/cjs/commands/eval/index.js.map +0 -1
  88. package/dist/cjs/commands/index.js +0 -30
  89. package/dist/cjs/commands/index.js.map +0 -1
  90. package/dist/cjs/commands/manifest/implementation.js +0 -34
  91. package/dist/cjs/commands/manifest/implementation.js.map +0 -1
  92. package/dist/cjs/commands/manifest/index.js +0 -50
  93. package/dist/cjs/commands/manifest/index.js.map +0 -1
  94. package/dist/cjs/commands/manifest/manifest.js +0 -55
  95. package/dist/cjs/commands/manifest/manifest.js.map +0 -1
  96. package/dist/cjs/commands/serve/index.js +0 -33
  97. package/dist/cjs/commands/serve/index.js.map +0 -1
  98. package/dist/cjs/commands/serve/serve.js +0 -21
  99. package/dist/cjs/commands/serve/serve.js.map +0 -1
  100. package/dist/cjs/commands/watch/implementation.js +0 -35
  101. package/dist/cjs/commands/watch/implementation.js.map +0 -1
  102. package/dist/cjs/commands/watch/index.js +0 -47
  103. package/dist/cjs/commands/watch/index.js.map +0 -1
  104. package/dist/cjs/commands/watch/watch.js +0 -51
  105. package/dist/cjs/commands/watch/watch.js.map +0 -1
  106. package/dist/cjs/config.js +0 -290
  107. package/dist/cjs/config.js.map +0 -1
  108. package/dist/cjs/errors.js +0 -37
  109. package/dist/cjs/errors.js.map +0 -1
  110. package/dist/cjs/index.js +0 -77
  111. package/dist/cjs/index.js.map +0 -1
  112. package/dist/cjs/main.js +0 -19
  113. package/dist/cjs/main.js.map +0 -1
  114. package/dist/cjs/utils/cli.js +0 -61
  115. package/dist/cjs/utils/cli.js.map +0 -1
  116. package/dist/cjs/utils/errors.js +0 -42
  117. package/dist/cjs/utils/errors.js.map +0 -1
  118. package/dist/cjs/utils/index.js +0 -25
  119. package/dist/cjs/utils/index.js.map +0 -1
  120. package/dist/cjs/utils/legacy.js +0 -48
  121. package/dist/cjs/utils/legacy.js.map +0 -1
  122. package/dist/cjs/utils/logging.js +0 -46
  123. package/dist/cjs/utils/logging.js.map +0 -1
  124. package/dist/cjs/utils/path.js +0 -16
  125. package/dist/cjs/utils/path.js.map +0 -1
  126. package/dist/cjs/utils/steps.js +0 -52
  127. package/dist/cjs/utils/steps.js.map +0 -1
  128. package/dist/cjs/webpack/compiler.js +0 -96
  129. package/dist/cjs/webpack/compiler.js.map +0 -1
  130. package/dist/cjs/webpack/config.js +0 -234
  131. package/dist/cjs/webpack/config.js.map +0 -1
  132. package/dist/cjs/webpack/index.js +0 -22
  133. package/dist/cjs/webpack/index.js.map +0 -1
  134. package/dist/cjs/webpack/loaders/browserify.js +0 -97
  135. package/dist/cjs/webpack/loaders/browserify.js.map +0 -1
  136. package/dist/cjs/webpack/loaders/wasm.js +0 -36
  137. package/dist/cjs/webpack/loaders/wasm.js.map +0 -1
  138. package/dist/cjs/webpack/plugins.js +0 -340
  139. package/dist/cjs/webpack/plugins.js.map +0 -1
  140. package/dist/cjs/webpack/utils.js +0 -133
  141. package/dist/cjs/webpack/utils.js.map +0 -1
  142. package/dist/esm/builders.js.map +0 -1
  143. package/dist/esm/cli.js +0 -26
  144. package/dist/esm/cli.js.map +0 -1
  145. package/dist/esm/commands/build/build.js +0 -51
  146. package/dist/esm/commands/build/build.js.map +0 -1
  147. package/dist/esm/commands/build/implementation.js +0 -27
  148. package/dist/esm/commands/build/implementation.js.map +0 -1
  149. package/dist/esm/commands/build/index.js +0 -17
  150. package/dist/esm/commands/build/index.js.map +0 -1
  151. package/dist/esm/commands/eval/eval.js +0 -54
  152. package/dist/esm/commands/eval/eval.js.map +0 -1
  153. package/dist/esm/commands/eval/implementation.js +0 -24
  154. package/dist/esm/commands/eval/implementation.js.map +0 -1
  155. package/dist/esm/commands/eval/index.js +0 -22
  156. package/dist/esm/commands/eval/index.js.map +0 -1
  157. package/dist/esm/commands/index.js +0 -15
  158. package/dist/esm/commands/index.js.map +0 -1
  159. package/dist/esm/commands/manifest/implementation.js +0 -33
  160. package/dist/esm/commands/manifest/implementation.js.map +0 -1
  161. package/dist/esm/commands/manifest/index.js +0 -22
  162. package/dist/esm/commands/manifest/index.js.map +0 -1
  163. package/dist/esm/commands/manifest/manifest.js +0 -52
  164. package/dist/esm/commands/manifest/manifest.js.map +0 -1
  165. package/dist/esm/commands/serve/index.js +0 -18
  166. package/dist/esm/commands/serve/index.js.map +0 -1
  167. package/dist/esm/commands/serve/serve.js +0 -17
  168. package/dist/esm/commands/serve/serve.js.map +0 -1
  169. package/dist/esm/commands/watch/implementation.js +0 -34
  170. package/dist/esm/commands/watch/implementation.js.map +0 -1
  171. package/dist/esm/commands/watch/index.js +0 -19
  172. package/dist/esm/commands/watch/index.js.map +0 -1
  173. package/dist/esm/commands/watch/watch.js +0 -50
  174. package/dist/esm/commands/watch/watch.js.map +0 -1
  175. package/dist/esm/config.js +0 -294
  176. package/dist/esm/config.js.map +0 -1
  177. package/dist/esm/errors.js +0 -30
  178. package/dist/esm/errors.js.map +0 -1
  179. package/dist/esm/index.js +0 -6
  180. package/dist/esm/index.js.map +0 -1
  181. package/dist/esm/main.js +0 -10
  182. package/dist/esm/main.js.map +0 -1
  183. package/dist/esm/utils/cli.js +0 -43
  184. package/dist/esm/utils/cli.js.map +0 -1
  185. package/dist/esm/utils/errors.js +0 -43
  186. package/dist/esm/utils/errors.js.map +0 -1
  187. package/dist/esm/utils/index.js +0 -8
  188. package/dist/esm/utils/index.js.map +0 -1
  189. package/dist/esm/utils/legacy.js +0 -47
  190. package/dist/esm/utils/legacy.js.map +0 -1
  191. package/dist/esm/utils/logging.js +0 -40
  192. package/dist/esm/utils/logging.js.map +0 -1
  193. package/dist/esm/utils/path.js +0 -13
  194. package/dist/esm/utils/path.js.map +0 -1
  195. package/dist/esm/utils/steps.js +0 -43
  196. package/dist/esm/utils/steps.js.map +0 -1
  197. package/dist/esm/webpack/compiler.js +0 -89
  198. package/dist/esm/webpack/compiler.js.map +0 -1
  199. package/dist/esm/webpack/config.js +0 -236
  200. package/dist/esm/webpack/config.js.map +0 -1
  201. package/dist/esm/webpack/index.js +0 -5
  202. package/dist/esm/webpack/index.js.map +0 -1
  203. package/dist/esm/webpack/loaders/browserify.js +0 -82
  204. package/dist/esm/webpack/loaders/browserify.js.map +0 -1
  205. package/dist/esm/webpack/loaders/wasm.js +0 -26
  206. package/dist/esm/webpack/loaders/wasm.js.map +0 -1
  207. package/dist/esm/webpack/plugins.js +0 -343
  208. package/dist/esm/webpack/plugins.js.map +0 -1
  209. package/dist/esm/webpack/utils.js +0 -160
  210. package/dist/esm/webpack/utils.js.map +0 -1
  211. package/dist/types/__fixtures__/configs/cjs.d.ts +0 -1
  212. package/dist/types/__fixtures__/configs/esm.d.ts +0 -3
  213. package/dist/types/__fixtures__/configs/invalid.d.ts +0 -3
  214. package/dist/types/__fixtures__/configs/javascript/snap.config.d.ts +0 -0
  215. package/dist/types/__fixtures__/configs/typescript/snap.config.d.ts +0 -3
  216. package/dist/types/builders.d.ts +0 -8
  217. package/dist/types/commands/build/build.d.ts +0 -10
  218. package/dist/types/commands/build/implementation.d.ts +0 -10
  219. package/dist/types/commands/build/index.d.ts +0 -10
  220. package/dist/types/commands/eval/__test__/browserify/bad/snap.config.d.ts +0 -3
  221. package/dist/types/commands/eval/__test__/browserify/good/snap.config.d.ts +0 -3
  222. package/dist/types/commands/eval/__test__/webpack/bad/snap.config.d.ts +0 -3
  223. package/dist/types/commands/eval/__test__/webpack/good/snap.config.d.ts +0 -3
  224. package/dist/types/commands/eval/__test__/webpack/snap.config.d.ts +0 -3
  225. package/dist/types/commands/eval/eval.d.ts +0 -14
  226. package/dist/types/commands/eval/implementation.d.ts +0 -9
  227. package/dist/types/commands/eval/index.d.ts +0 -10
  228. package/dist/types/commands/manifest/implementation.d.ts +0 -12
  229. package/dist/types/commands/manifest/index.d.ts +0 -10
  230. package/dist/types/commands/manifest/manifest.d.ts +0 -14
  231. package/dist/types/commands/serve/serve.d.ts +0 -16
  232. package/dist/types/commands/watch/implementation.d.ts +0 -14
  233. package/dist/types/commands/watch/index.d.ts +0 -10
  234. package/dist/types/commands/watch/watch.d.ts +0 -19
  235. package/dist/types/config.d.ts +0 -626
  236. package/dist/types/errors.d.ts +0 -25
  237. package/dist/types/index.d.ts +0 -5
  238. package/dist/types/utils/cli.d.ts +0 -17
  239. package/dist/types/utils/errors.d.ts +0 -23
  240. package/dist/types/utils/index.d.ts +0 -6
  241. package/dist/types/utils/legacy.d.ts +0 -27
  242. package/dist/types/utils/logging.d.ts +0 -22
  243. package/dist/types/utils/path.d.ts +0 -9
  244. package/dist/types/utils/steps.d.ts +0 -17
  245. package/dist/types/webpack/compiler.d.ts +0 -29
  246. package/dist/types/webpack/config.d.ts +0 -37
  247. package/dist/types/webpack/index.d.ts +0 -3
  248. package/dist/types/webpack/loaders/browserify.d.ts +0 -16
  249. package/dist/types/webpack/loaders/wasm.d.ts +0 -20
  250. package/dist/types/webpack/plugins.d.ts +0 -147
  251. package/dist/types/webpack/utils.d.ts +0 -156
  252. /package/dist/{types/commands → cmds}/index.d.ts +0 -0
  253. /package/dist/{types/main.d.ts → main.d.ts} +0 -0
@@ -1,130 +1,133 @@
1
- export var TranspilationModes;
2
- (function(TranspilationModes) {
3
- TranspilationModes["LocalAndDeps"] = 'localAndDeps';
4
- TranspilationModes["LocalOnly"] = 'localOnly';
5
- TranspilationModes["None"] = 'none';
6
- })(TranspilationModes || (TranspilationModes = {}));
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TranspilationModes = void 0;
4
+ var TranspilationModes;
5
+ (function (TranspilationModes) {
6
+ TranspilationModes["LocalAndDeps"] = "localAndDeps";
7
+ TranspilationModes["LocalOnly"] = "localOnly";
8
+ TranspilationModes["None"] = "none";
9
+ })(TranspilationModes = exports.TranspilationModes || (exports.TranspilationModes = {}));
7
10
  const builders = {
8
- // eslint-disable-next-line @typescript-eslint/naming-convention
9
- config: {
10
- alias: 'c',
11
- describe: 'Path to config file',
12
- type: 'string',
13
- normalize: true
14
- },
15
- fix: {
16
- describe: 'Attempt to fix snap.manifest.json',
17
- type: 'boolean'
18
- },
19
- input: {
20
- alias: 'i',
21
- describe: 'Snap bundle file to evaluate',
22
- type: 'string',
23
- normalize: true
24
- },
25
- // Deprecated Browserify options.
26
11
  bundle: {
27
12
  alias: 'b',
28
13
  describe: 'Snap bundle file',
29
14
  type: 'string',
15
+ demandOption: true,
30
16
  normalize: true,
31
- deprecated: 'Use --input instead.'
17
+ default: 'dist/bundle.js',
32
18
  },
33
19
  dist: {
34
20
  alias: 'd',
35
21
  describe: 'Output directory',
36
22
  type: 'string',
23
+ demandOption: true,
37
24
  normalize: true,
38
- deprecated: true
25
+ default: 'dist',
39
26
  },
40
27
  eval: {
41
28
  alias: 'e',
42
29
  describe: 'Attempt to evaluate Snap bundle in SES',
43
30
  type: 'boolean',
44
- deprecated: true
31
+ demandOption: false,
32
+ default: true,
45
33
  },
46
34
  manifest: {
47
35
  alias: 'm',
48
36
  describe: 'Validate snap.manifest.json',
49
37
  type: 'boolean',
50
- deprecated: true
38
+ demandOption: false,
39
+ default: true,
51
40
  },
52
41
  port: {
53
42
  alias: 'p',
54
43
  describe: 'Local server port for testing',
55
44
  type: 'number',
56
- coerce: (arg)=>{
45
+ demandOption: true,
46
+ default: 8081,
47
+ coerce: (arg) => {
57
48
  const port = Number.parseInt(String(arg), 10);
58
49
  if (Number.isNaN(port)) {
59
- throw new Error(`Invalid port: "${String(arg)}".`);
50
+ throw new Error(`Invalid port: ${String(arg)}`);
60
51
  }
61
52
  return port;
62
53
  },
63
- deprecated: true
64
54
  },
65
55
  outfileName: {
66
56
  alias: 'n',
67
57
  describe: 'Output file name',
68
58
  type: 'string',
69
- deprecated: true
59
+ demandOption: false,
60
+ default: 'bundle.js',
70
61
  },
71
62
  root: {
72
63
  alias: 'r',
73
64
  describe: 'Server root directory',
74
65
  type: 'string',
66
+ demandOption: true,
75
67
  normalize: true,
76
- deprecated: true
68
+ default: '.',
77
69
  },
78
70
  sourceMaps: {
79
71
  describe: 'Whether builds include sourcemaps',
80
72
  type: 'boolean',
81
- deprecated: true
73
+ demandOption: false,
74
+ default: false,
82
75
  },
83
76
  src: {
84
77
  alias: 's',
85
78
  describe: 'Source file',
86
79
  type: 'string',
80
+ demandOption: true,
87
81
  normalize: true,
88
- deprecated: true
82
+ default: 'src/index.js',
89
83
  },
90
84
  stripComments: {
91
85
  alias: 'strip',
92
86
  describe: 'Whether to remove code comments from the build output',
93
87
  type: 'boolean',
94
- deprecated: true
88
+ demandOption: false,
89
+ default: true,
95
90
  },
96
91
  suppressWarnings: {
97
92
  type: 'boolean',
98
93
  describe: 'Whether to suppress warnings',
99
- deprecated: true
94
+ demandOption: false,
95
+ default: false,
100
96
  },
101
97
  transpilationMode: {
102
98
  type: 'string',
103
- describe: 'Whether to use Babel to transpile all source code (including dependencies), local source code only, or nothing',
99
+ describe: 'Whether to use Babel to transpile all source code (including dependencies), local source code only, or nothing.',
100
+ demandOption: false,
101
+ default: TranspilationModes.LocalOnly,
104
102
  choices: Object.values(TranspilationModes),
105
- deprecated: true
106
103
  },
107
104
  depsToTranspile: {
108
105
  type: 'array',
109
106
  describe: 'Transpile only the listed dependencies.',
110
- deprecated: true
107
+ demandOption: false,
111
108
  },
112
109
  verboseErrors: {
113
110
  type: 'boolean',
114
111
  describe: 'Display original errors',
115
- deprecated: true
112
+ demandOption: false,
113
+ default: true,
116
114
  },
117
115
  writeManifest: {
118
- describe: 'Make necessary changes to the snap manifest file',
116
+ describe: 'Make necessary changes to the Snap manifest file',
119
117
  type: 'boolean',
120
- deprecated: true
118
+ demandOption: false,
119
+ default: true,
121
120
  },
122
121
  serve: {
123
- describe: 'Serve snap file(s) locally for testing',
122
+ describe: 'Serve Snap file(s) locally for testing',
124
123
  type: 'boolean',
125
- deprecated: true
126
- }
124
+ demandOption: false,
125
+ default: true,
126
+ },
127
+ directory: {
128
+ describe: 'the directory to use',
129
+ type: 'string',
130
+ },
127
131
  };
128
- export default builders;
129
-
132
+ exports.default = builders;
130
133
  //# sourceMappingURL=builders.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"builders.js","sourceRoot":"","sources":["../src/builders.ts"],"names":[],"mappings":"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","sourcesContent":["import { Options, PositionalOptions } from 'yargs';\n\nexport type SnapsCliBuilders = {\n readonly bundle: Readonly<Options>;\n readonly dist: Readonly<Options>;\n readonly eval: Readonly<Options>;\n readonly manifest: Readonly<Options>;\n readonly outfileName: Readonly<Options>;\n readonly port: Readonly<Options>;\n readonly root: Readonly<Options>;\n readonly sourceMaps: Readonly<Options>;\n readonly src: Readonly<Options>;\n readonly stripComments: Readonly<Options>;\n readonly suppressWarnings: Readonly<Options>;\n readonly transpilationMode: Readonly<Options>;\n readonly depsToTranspile: Readonly<Options>;\n readonly verboseErrors: Readonly<Options>;\n readonly writeManifest: Readonly<Options>;\n readonly serve: Readonly<Options>;\n readonly directory: Readonly<PositionalOptions>;\n};\n\nexport enum TranspilationModes {\n LocalAndDeps = 'localAndDeps',\n LocalOnly = 'localOnly',\n None = 'none',\n}\n\nconst builders: SnapsCliBuilders = {\n bundle: {\n alias: 'b',\n describe: 'Snap bundle file',\n type: 'string',\n demandOption: true,\n normalize: true,\n default: 'dist/bundle.js',\n },\n\n dist: {\n alias: 'd',\n describe: 'Output directory',\n type: 'string',\n demandOption: true,\n normalize: true,\n default: 'dist',\n },\n\n eval: {\n alias: 'e',\n describe: 'Attempt to evaluate Snap bundle in SES',\n type: 'boolean',\n demandOption: false,\n default: true,\n },\n\n manifest: {\n alias: 'm',\n describe: 'Validate snap.manifest.json',\n type: 'boolean',\n demandOption: false,\n default: true,\n },\n\n port: {\n alias: 'p',\n describe: 'Local server port for testing',\n type: 'number',\n demandOption: true,\n default: 8081,\n coerce: (arg: unknown) => {\n const port = Number.parseInt(String(arg), 10);\n if (Number.isNaN(port)) {\n throw new Error(`Invalid port: ${String(arg)}`);\n }\n return port;\n },\n },\n\n outfileName: {\n alias: 'n',\n describe: 'Output file name',\n type: 'string',\n demandOption: false,\n default: 'bundle.js',\n },\n\n root: {\n alias: 'r',\n describe: 'Server root directory',\n type: 'string',\n demandOption: true,\n normalize: true,\n default: '.',\n },\n\n sourceMaps: {\n describe: 'Whether builds include sourcemaps',\n type: 'boolean',\n demandOption: false,\n default: false,\n },\n\n src: {\n alias: 's',\n describe: 'Source file',\n type: 'string',\n demandOption: true,\n normalize: true,\n default: 'src/index.js',\n },\n\n stripComments: {\n alias: 'strip',\n describe: 'Whether to remove code comments from the build output',\n type: 'boolean',\n demandOption: false,\n default: true,\n },\n\n suppressWarnings: {\n type: 'boolean',\n describe: 'Whether to suppress warnings',\n demandOption: false,\n default: false,\n },\n\n transpilationMode: {\n type: 'string',\n describe:\n 'Whether to use Babel to transpile all source code (including dependencies), local source code only, or nothing.',\n demandOption: false,\n default: TranspilationModes.LocalOnly,\n choices: Object.values(TranspilationModes),\n },\n\n depsToTranspile: {\n type: 'array',\n describe: 'Transpile only the listed dependencies.',\n demandOption: false,\n },\n\n verboseErrors: {\n type: 'boolean',\n describe: 'Display original errors',\n demandOption: false,\n default: true,\n },\n\n writeManifest: {\n describe: 'Make necessary changes to the Snap manifest file',\n type: 'boolean',\n demandOption: false,\n default: true,\n },\n\n serve: {\n describe: 'Serve Snap file(s) locally for testing',\n type: 'boolean',\n demandOption: false,\n default: true,\n },\n\n directory: {\n describe: 'the directory to use',\n type: 'string',\n },\n};\n\nexport default builders;\n"]}
@@ -5,4 +5,4 @@
5
5
  * @param argv - The raw command line arguments, i.e., `process.argv`.
6
6
  * @param commands - The list of commands to use.
7
7
  */
8
- export declare function cli(argv: string[], commands: any): Promise<void>;
8
+ export declare function cli(argv: string[], commands: any): void;
package/dist/cli.js ADDED
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.cli = void 0;
7
+ const yargs_1 = __importDefault(require("yargs"));
8
+ const builders_1 = __importDefault(require("./builders"));
9
+ const utils_1 = require("./utils");
10
+ /**
11
+ * The main CLI entry point function. This processes the command line args, and
12
+ * runs the appropriate function.
13
+ *
14
+ * @param argv - The raw command line arguments, i.e., `process.argv`.
15
+ * @param commands - The list of commands to use.
16
+ */
17
+ function cli(argv, commands) {
18
+ const rawArgv = argv.slice(2);
19
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
20
+ (0, yargs_1.default)(rawArgv)
21
+ .scriptName('mm-snap')
22
+ .usage('Usage: $0 <command> [options]')
23
+ .example('$0 init', `\tInitialize a snap project in the current directory`)
24
+ .example('$0 init my-snap', `\tInitialize a snap project in the 'my-snap' directory`)
25
+ .example('$0 build -s src/index.js -d out', `\tBuild 'src/index.js' as './out/bundle.js'`)
26
+ .example('$0 build -s src/index.js -d out -n snap.js', `\tBuild 'src/index.js' as './out/snap.js'`)
27
+ .example('$0 serve -r out', `\tServe files in './out' on port 8080`)
28
+ .example('$0 serve -r out -p 9000', `\tServe files in './out' on port 9000`)
29
+ .example('$0 watch -s src/index.js -d out', `\tRebuild './out/bundle.js' on changes to files in 'src/index.js' parent and child directories`)
30
+ .command(commands)
31
+ .option('verboseErrors', builders_1.default.verboseErrors)
32
+ .option('suppressWarnings', builders_1.default.suppressWarnings)
33
+ .strict()
34
+ // Typecast: The @types/yargs type for .middleware is incorrect.
35
+ // yargs middleware functions receive the yargs instance as a second parameter.
36
+ // ref: https://yargs.js.org/docs/#api-reference-middlewarecallbacks-applybeforevalidation
37
+ .middleware(((yargsArgv, yargsInstance) => {
38
+ (0, utils_1.applyConfig)((0, utils_1.loadConfig)(), rawArgv, yargsArgv, yargsInstance);
39
+ (0, utils_1.setSnapGlobals)(yargsArgv);
40
+ (0, utils_1.sanitizeInputs)(yargsArgv);
41
+ }), true)
42
+ .fail((message, error, _yargs) => {
43
+ (0, utils_1.logError)(message, error);
44
+ process.exitCode = 1;
45
+ })
46
+ .demandCommand(1, 'You must specify at least one command.')
47
+ .help()
48
+ .alias('help', 'h').argv;
49
+ }
50
+ exports.cli = cli;
51
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAyC;AAGzC,0DAAkC;AAClC,mCAMiB;AAEjB;;;;;;GAMG;AACH,SAAgB,GAAG,CAAC,IAAc,EAAE,QAAa;IAC/C,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC9B,oEAAoE;IACpE,IAAA,eAAK,EAAC,OAAO,CAAC;SACX,UAAU,CAAC,SAAS,CAAC;SACrB,KAAK,CAAC,+BAA+B,CAAC;SAEtC,OAAO,CAAC,SAAS,EAAE,sDAAsD,CAAC;SAC1E,OAAO,CACN,iBAAiB,EACjB,wDAAwD,CACzD;SACA,OAAO,CACN,iCAAiC,EACjC,6CAA6C,CAC9C;SACA,OAAO,CACN,4CAA4C,EAC5C,2CAA2C,CAC5C;SACA,OAAO,CAAC,iBAAiB,EAAE,uCAAuC,CAAC;SACnE,OAAO,CAAC,yBAAyB,EAAE,uCAAuC,CAAC;SAC3E,OAAO,CACN,iCAAiC,EACjC,gGAAgG,CACjG;SAEA,OAAO,CAAC,QAAQ,CAAC;SAEjB,MAAM,CAAC,eAAe,EAAE,kBAAQ,CAAC,aAAa,CAAC;SAE/C,MAAM,CAAC,kBAAkB,EAAE,kBAAQ,CAAC,gBAAgB,CAAC;SAErD,MAAM,EAAE;QAET,gEAAgE;QAChE,+EAA+E;QAC/E,0FAA0F;SACzF,UAAU,CACT,CAAC,CAAC,SAAoB,EAAE,aAA+B,EAAE,EAAE;QACzD,IAAA,mBAAW,EAAC,IAAA,kBAAU,GAAE,EAAE,OAAO,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC;QAC7D,IAAA,sBAAc,EAAC,SAAS,CAAC,CAAC;QAC1B,IAAA,sBAAc,EAAC,SAAS,CAAC,CAAC;IAC5B,CAAC,CAAQ,EACT,IAAI,CACL;SAEA,IAAI,CAAC,CAAC,OAAe,EAAE,KAAY,EAAE,MAAM,EAAE,EAAE;QAC9C,IAAA,gBAAQ,EAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QACzB,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACvB,CAAC,CAAC;SAED,aAAa,CAAC,CAAC,EAAE,wCAAwC,CAAC;SAE1D,IAAI,EAAE;SACN,KAAK,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC;AAC7B,CAAC;AAxDD,kBAwDC","sourcesContent":["import yargs, { Arguments } from 'yargs';\nimport yargsType from 'yargs/yargs';\n\nimport builders from './builders';\nimport {\n applyConfig,\n loadConfig,\n sanitizeInputs,\n setSnapGlobals,\n logError,\n} from './utils';\n\n/**\n * The main CLI entry point function. This processes the command line args, and\n * runs the appropriate function.\n *\n * @param argv - The raw command line arguments, i.e., `process.argv`.\n * @param commands - The list of commands to use.\n */\nexport function cli(argv: string[], commands: any): void {\n const rawArgv = argv.slice(2);\n // eslint-disable-next-line @typescript-eslint/no-unused-expressions\n yargs(rawArgv)\n .scriptName('mm-snap')\n .usage('Usage: $0 <command> [options]')\n\n .example('$0 init', `\\tInitialize a snap project in the current directory`)\n .example(\n '$0 init my-snap',\n `\\tInitialize a snap project in the 'my-snap' directory`,\n )\n .example(\n '$0 build -s src/index.js -d out',\n `\\tBuild 'src/index.js' as './out/bundle.js'`,\n )\n .example(\n '$0 build -s src/index.js -d out -n snap.js',\n `\\tBuild 'src/index.js' as './out/snap.js'`,\n )\n .example('$0 serve -r out', `\\tServe files in './out' on port 8080`)\n .example('$0 serve -r out -p 9000', `\\tServe files in './out' on port 9000`)\n .example(\n '$0 watch -s src/index.js -d out',\n `\\tRebuild './out/bundle.js' on changes to files in 'src/index.js' parent and child directories`,\n )\n\n .command(commands)\n\n .option('verboseErrors', builders.verboseErrors)\n\n .option('suppressWarnings', builders.suppressWarnings)\n\n .strict()\n\n // Typecast: The @types/yargs type for .middleware is incorrect.\n // yargs middleware functions receive the yargs instance as a second parameter.\n // ref: https://yargs.js.org/docs/#api-reference-middlewarecallbacks-applybeforevalidation\n .middleware(\n ((yargsArgv: Arguments, yargsInstance: typeof yargsType) => {\n applyConfig(loadConfig(), rawArgv, yargsArgv, yargsInstance);\n setSnapGlobals(yargsArgv);\n sanitizeInputs(yargsArgv);\n }) as any,\n true,\n )\n\n .fail((message: string, error: Error, _yargs) => {\n logError(message, error);\n process.exitCode = 1;\n })\n\n .demandCommand(1, 'You must specify at least one command.')\n\n .help()\n .alias('help', 'h').argv;\n}\n"]}
@@ -0,0 +1,13 @@
1
+ import { 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>;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.build = void 0;
4
+ const snaps_utils_1 = require("@metamask/snaps-utils");
5
+ const utils_1 = require("../../utils");
6
+ const evalHandler_1 = require("../eval/evalHandler");
7
+ const manifestHandler_1 = require("../manifest/manifestHandler");
8
+ const bundle_1 = require("./bundle");
9
+ /**
10
+ * Builds all files in the given source directory to the given destination
11
+ * directory.
12
+ *
13
+ * Creates destination directory if it doesn't exist.
14
+ *
15
+ * @param argv - Argv from Yargs.
16
+ * @param argv.src - The source file path.
17
+ * @param argv.dist - The output directory path.
18
+ * @param argv.outfileName - The output file name.
19
+ */
20
+ async function build(argv) {
21
+ const { src, dist, outfileName } = argv;
22
+ if (outfileName) {
23
+ (0, snaps_utils_1.validateOutfileName)(outfileName);
24
+ }
25
+ await (0, snaps_utils_1.validateFilePath)(src);
26
+ await (0, snaps_utils_1.validateDirPath)(dist, true);
27
+ const outfilePath = (0, snaps_utils_1.getOutfilePath)(dist, outfileName);
28
+ const result = await (0, bundle_1.bundle)(src, outfilePath, argv, (0, utils_1.loadConfig)().bundlerCustomizer);
29
+ if (result && argv.eval) {
30
+ await (0, evalHandler_1.evalHandler)({ ...argv, bundle: outfilePath });
31
+ }
32
+ if (argv.manifest) {
33
+ await (0, manifestHandler_1.manifestHandler)(argv);
34
+ }
35
+ }
36
+ exports.build = build;
37
+ //# sourceMappingURL=buildHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildHandler.js","sourceRoot":"","sources":["../../../src/cmds/build/buildHandler.ts"],"names":[],"mappings":";;;AAAA,uDAK+B;AAG/B,uCAAyC;AACzC,qDAAkD;AAClD,iEAA8D;AAC9D,qCAAkC;AAElC;;;;;;;;;;GAUG;AACI,KAAK,UAAU,KAAK,CAAC,IAAe;IACzC,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC;IACxC,IAAI,WAAW,EAAE;QACf,IAAA,iCAAmB,EAAC,WAAW,CAAC,CAAC;KAClC;IACD,MAAM,IAAA,8BAAgB,EAAC,GAAG,CAAC,CAAC;IAC5B,MAAM,IAAA,6BAAe,EAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAElC,MAAM,WAAW,GAAG,IAAA,4BAAc,EAAC,IAAI,EAAE,WAAW,CAAC,CAAC;IACtD,MAAM,MAAM,GAAG,MAAM,IAAA,eAAM,EACzB,GAAG,EACH,WAAW,EACX,IAAI,EACJ,IAAA,kBAAU,GAAE,CAAC,iBAAiB,CAC/B,CAAC;IACF,IAAI,MAAM,IAAI,IAAI,CAAC,IAAI,EAAE;QACvB,MAAM,IAAA,yBAAW,EAAC,EAAE,GAAG,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC,CAAC;KACrD;IAED,IAAI,IAAI,CAAC,QAAQ,EAAE;QACjB,MAAM,IAAA,iCAAe,EAAC,IAAI,CAAC,CAAC;KAC7B;AACH,CAAC;AAtBD,sBAsBC","sourcesContent":["import {\n getOutfilePath,\n validateDirPath,\n validateFilePath,\n validateOutfileName,\n} from '@metamask/snaps-utils';\n\nimport { YargsArgs } from '../../types/yargs';\nimport { loadConfig } from '../../utils';\nimport { evalHandler } from '../eval/evalHandler';\nimport { manifestHandler } from '../manifest/manifestHandler';\nimport { bundle } from './bundle';\n\n/**\n * Builds all files in the given source directory to the given destination\n * directory.\n *\n * Creates destination directory if it doesn't exist.\n *\n * @param argv - Argv from 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 build(argv: YargsArgs): Promise<void> {\n const { src, dist, outfileName } = argv;\n if (outfileName) {\n validateOutfileName(outfileName);\n }\n await validateFilePath(src);\n await validateDirPath(dist, true);\n\n const outfilePath = getOutfilePath(dist, outfileName);\n const result = await bundle(\n src,\n outfilePath,\n argv,\n loadConfig().bundlerCustomizer,\n );\n if (result && argv.eval) {\n await evalHandler({ ...argv, bundle: outfilePath });\n }\n\n if (argv.manifest) {\n await manifestHandler(argv);\n }\n}\n"]}
@@ -0,0 +1,15 @@
1
+ import { BrowserifyObject } from 'browserify';
2
+ import { 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>;
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.bundle = void 0;
7
+ const snaps_browserify_plugin_1 = __importDefault(require("@metamask/snaps-browserify-plugin"));
8
+ const browserify_1 = __importDefault(require("browserify"));
9
+ const builders_1 = require("../../builders");
10
+ const utils_1 = require("./utils");
11
+ // We need to statically import all Browserify transforms and all Babel presets
12
+ // and plugins, and calling `require` is the sanest way to do that.
13
+ /* eslint-disable @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires, node/global-require */
14
+ /**
15
+ * Builds a Snap bundle JS file from its JavaScript source.
16
+ *
17
+ * @param src - The source file path.
18
+ * @param dest - The destination file path.
19
+ * @param argv - Arguments as an object generated by `yargs`.
20
+ * @param argv.sourceMaps - Whether to output sourcemaps.
21
+ * @param argv.stripComments - Whether to remove comments from code.
22
+ * @param argv.transpilationMode - The Babel transpilation mode.
23
+ * @param bundlerTransform - An optional function which can be used to transform
24
+ * the Browserify instance, e.g., adding a custom transform or plugin.
25
+ */
26
+ async function bundle(src, dest, argv, bundlerTransform) {
27
+ const { sourceMaps: debug, transpilationMode } = argv;
28
+ const babelifyOptions = (0, utils_1.processDependencies)(argv);
29
+ return new Promise((resolve, _reject) => {
30
+ const bundler = (0, browserify_1.default)(src, {
31
+ debug,
32
+ extensions: ['.js', '.ts'],
33
+ // Standalone is required to properly support Snaps using module.exports
34
+ standalone: '<snap>',
35
+ });
36
+ if (transpilationMode !== builders_1.TranspilationModes.None) {
37
+ bundler.transform(require('babelify'), {
38
+ global: transpilationMode === builders_1.TranspilationModes.LocalAndDeps,
39
+ extensions: ['.js', '.ts'],
40
+ presets: [
41
+ require('@babel/preset-typescript'),
42
+ [
43
+ require('@babel/preset-env'),
44
+ {
45
+ targets: {
46
+ browsers: ['chrome >= 66', 'firefox >= 68'],
47
+ },
48
+ },
49
+ ],
50
+ ],
51
+ plugins: [
52
+ require('@babel/plugin-transform-runtime'),
53
+ require('@babel/plugin-proposal-class-properties'),
54
+ require('@babel/plugin-proposal-object-rest-spread'),
55
+ require('@babel/plugin-proposal-optional-chaining'),
56
+ require('@babel/plugin-proposal-nullish-coalescing-operator'),
57
+ ],
58
+ parserOpts: {
59
+ attachComment: !argv.stripComments,
60
+ },
61
+ ...babelifyOptions,
62
+ });
63
+ }
64
+ bundlerTransform?.(bundler);
65
+ bundler.plugin(snaps_browserify_plugin_1.default, {
66
+ stripComments: argv.stripComments,
67
+ manifestPath: undefined,
68
+ eval: false,
69
+ });
70
+ bundler.bundle(async (bundleError, bundleBuffer) => await (0, utils_1.writeBundleFile)({
71
+ bundleError,
72
+ bundleBuffer,
73
+ src,
74
+ dest,
75
+ resolve,
76
+ }));
77
+ });
78
+ }
79
+ exports.bundle = bundle;
80
+ //# sourceMappingURL=bundle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bundle.js","sourceRoot":"","sources":["../../../src/cmds/build/bundle.ts"],"names":[],"mappings":";;;;;;AAAA,gGAAoE;AACpE,4DAA0D;AAE1D,6CAAoD;AAEpD,mCAA+D;AAE/D,+EAA+E;AAC/E,mEAAmE;AACnE,mHAAmH;AAEnH;;;;;;;;;;;GAWG;AACI,KAAK,UAAU,MAAM,CAC1B,GAAW,EACX,IAAY,EACZ,IAAe,EACf,gBAAsD;IAEtD,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,iBAAiB,EAAE,GAAG,IAAI,CAAC;IACtD,MAAM,eAAe,GAAG,IAAA,2BAAmB,EAAC,IAAW,CAAC,CAAC;IACzD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE;QACtC,MAAM,OAAO,GAAG,IAAA,oBAAU,EAAC,GAAG,EAAE;YAC9B,KAAK;YACL,UAAU,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC;YAC1B,wEAAwE;YACxE,UAAU,EAAE,QAAQ;SACrB,CAAC,CAAC;QAEH,IAAI,iBAAiB,KAAK,6BAAkB,CAAC,IAAI,EAAE;YACjD,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE;gBACrC,MAAM,EAAE,iBAAiB,KAAK,6BAAkB,CAAC,YAAY;gBAC7D,UAAU,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC;gBAC1B,OAAO,EAAE;oBACP,OAAO,CAAC,0BAA0B,CAAC;oBACnC;wBACE,OAAO,CAAC,mBAAmB,CAAC;wBAC5B;4BACE,OAAO,EAAE;gCACP,QAAQ,EAAE,CAAC,cAAc,EAAE,eAAe,CAAC;6BAC5C;yBACF;qBACF;iBACF;gBACD,OAAO,EAAE;oBACP,OAAO,CAAC,iCAAiC,CAAC;oBAC1C,OAAO,CAAC,yCAAyC,CAAC;oBAClD,OAAO,CAAC,2CAA2C,CAAC;oBACpD,OAAO,CAAC,0CAA0C,CAAC;oBACnD,OAAO,CAAC,oDAAoD,CAAC;iBAC9D;gBACD,UAAU,EAAE;oBACV,aAAa,EAAE,CAAC,IAAI,CAAC,aAAa;iBACnC;gBACD,GAAI,eAAuB;aAC5B,CAAC,CAAC;SACJ;QAED,gBAAgB,EAAE,CAAC,OAAO,CAAC,CAAC;QAE5B,OAAO,CAAC,MAAM,CAAU,iCAAM,EAAE;YAC9B,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,YAAY,EAAE,SAAS;YACvB,IAAI,EAAE,KAAK;SACZ,CAAC,CAAC;QAEH,OAAO,CAAC,MAAM,CACZ,KAAK,EAAE,WAAW,EAAE,YAAoB,EAAE,EAAE,CAC1C,MAAM,IAAA,uBAAe,EAAC;YACpB,WAAW;YACX,YAAY;YACZ,GAAG;YACH,IAAI;YACJ,OAAO;SACR,CAAC,CACL,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC;AAhED,wBAgEC","sourcesContent":["import plugin, { Options } from '@metamask/snaps-browserify-plugin';\nimport browserify, { BrowserifyObject } from 'browserify';\n\nimport { TranspilationModes } from '../../builders';\nimport { 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, node/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 >= 66', 'firefox >= 68'],\n },\n },\n ],\n ],\n plugins: [\n require('@babel/plugin-transform-runtime'),\n require('@babel/plugin-proposal-class-properties'),\n require('@babel/plugin-proposal-object-rest-spread'),\n require('@babel/plugin-proposal-optional-chaining'),\n require('@babel/plugin-proposal-nullish-coalescing-operator'),\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"]}
@@ -1,9 +1,9 @@
1
- import type yargs from 'yargs';
2
- import type { YargsArgs } from '../../types/yargs';
3
- declare const command: {
1
+ import yargs from 'yargs';
2
+ import { YargsArgs } from '../../types/yargs';
3
+ declare const _default: {
4
4
  command: string[];
5
5
  desc: string;
6
6
  builder: (yarg: yargs.Argv) => void;
7
7
  handler: (argv: YargsArgs) => Promise<void>;
8
8
  };
9
- export default command;
9
+ export = _default;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ const builders_1 = __importDefault(require("../../builders"));
6
+ const buildHandler_1 = require("./buildHandler");
7
+ const utils_1 = require("./utils");
8
+ module.exports = {
9
+ command: ['build', 'b'],
10
+ desc: 'Build Snap from source',
11
+ builder: (yarg) => {
12
+ yarg
13
+ .option('dist', builders_1.default.dist)
14
+ .option('eval', builders_1.default.eval)
15
+ .option('manifest', builders_1.default.manifest)
16
+ .option('outfileName', builders_1.default.outfileName)
17
+ .option('sourceMaps', builders_1.default.sourceMaps)
18
+ .option('src', builders_1.default.src)
19
+ .option('stripComments', builders_1.default.stripComments)
20
+ .option('transpilationMode', builders_1.default.transpilationMode)
21
+ .option('depsToTranspile', builders_1.default.depsToTranspile)
22
+ .option('writeManifest', builders_1.default.writeManifest)
23
+ .implies('writeManifest', 'manifest')
24
+ .implies('depsToTranspile', 'transpilationMode')
25
+ .middleware((argv) => (0, utils_1.processInvalidTranspilation)(argv));
26
+ },
27
+ handler: async (argv) => (0, buildHandler_1.build)(argv),
28
+ };
29
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cmds/build/index.ts"],"names":[],"mappings":";;;;AAEA,8DAAsC;AAEtC,iDAAuC;AACvC,mCAAsD;AAEtD,iBAAS;IACP,OAAO,EAAE,CAAC,OAAO,EAAE,GAAG,CAAC;IACvB,IAAI,EAAE,wBAAwB;IAC9B,OAAO,EAAE,CAAC,IAAgB,EAAE,EAAE;QAC5B,IAAI;aACD,MAAM,CAAC,MAAM,EAAE,kBAAQ,CAAC,IAAI,CAAC;aAC7B,MAAM,CAAC,MAAM,EAAE,kBAAQ,CAAC,IAAI,CAAC;aAC7B,MAAM,CAAC,UAAU,EAAE,kBAAQ,CAAC,QAAQ,CAAC;aACrC,MAAM,CAAC,aAAa,EAAE,kBAAQ,CAAC,WAAW,CAAC;aAC3C,MAAM,CAAC,YAAY,EAAE,kBAAQ,CAAC,UAAU,CAAC;aACzC,MAAM,CAAC,KAAK,EAAE,kBAAQ,CAAC,GAAG,CAAC;aAC3B,MAAM,CAAC,eAAe,EAAE,kBAAQ,CAAC,aAAa,CAAC;aAC/C,MAAM,CAAC,mBAAmB,EAAE,kBAAQ,CAAC,iBAAiB,CAAC;aACvD,MAAM,CAAC,iBAAiB,EAAE,kBAAQ,CAAC,eAAe,CAAC;aACnD,MAAM,CAAC,eAAe,EAAE,kBAAQ,CAAC,aAAa,CAAC;aAC/C,OAAO,CAAC,eAAe,EAAE,UAAU,CAAC;aACpC,OAAO,CAAC,iBAAiB,EAAE,mBAAmB,CAAC;aAC/C,UAAU,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAA,mCAA2B,EAAC,IAAW,CAAC,CAAC,CAAC;IACpE,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,IAAe,EAAE,EAAE,CAAC,IAAA,oBAAK,EAAC,IAAI,CAAC;CAChD,CAAC","sourcesContent":["import yargs from 'yargs';\n\nimport builders from '../../builders';\nimport { YargsArgs } from '../../types/yargs';\nimport { build } from './buildHandler';\nimport { processInvalidTranspilation } from './utils';\n\nexport = {\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"]}
@@ -0,0 +1,56 @@
1
+ /// <reference types="node" />
2
+ import { 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 {};
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.processInvalidTranspilation = exports.sanitizeDependencyPaths = exports.getDependencyRegExp = exports.processDependencies = exports.writeBundleFile = void 0;
4
+ const snaps_utils_1 = require("@metamask/snaps-utils");
5
+ const fs_1 = require("fs");
6
+ const builders_1 = require("../../builders");
7
+ const utils_1 = require("../../utils");
8
+ /**
9
+ * Performs postprocessing on the bundle contents and writes them to disk.
10
+ * Intended to be used in the callback passed to the Browserify `.bundle()`
11
+ * call.
12
+ *
13
+ * @param options - Options bag.
14
+ * @param options.bundleError - Any error received from Browserify.
15
+ * @param options.bundleBuffer - The {@link Buffer} with the bundle contents
16
+ * from Browserify.
17
+ * @param options.src - The source file path.
18
+ * @param options.dest - The destination file path.
19
+ * @param options.resolve - A {@link Promise} resolution function, so that we
20
+ * can use promises and `async`/`await` even though Browserify uses callbacks.
21
+ */
22
+ async function writeBundleFile({ bundleError, bundleBuffer, src, dest, resolve, }) {
23
+ if (bundleError) {
24
+ await (0, utils_1.writeError)('Build error:', bundleError.message, bundleError);
25
+ }
26
+ try {
27
+ await fs_1.promises.writeFile(dest, bundleBuffer?.toString());
28
+ (0, snaps_utils_1.logInfo)(`Build success: '${src}' bundled as '${dest}'!`);
29
+ resolve(true);
30
+ }
31
+ catch (error) {
32
+ await (0, utils_1.writeError)('Write error:', error.message, error, dest);
33
+ }
34
+ }
35
+ exports.writeBundleFile = writeBundleFile;
36
+ /**
37
+ * Processes dependencies and updates `argv` with an options object.
38
+ *
39
+ * @param argv - The Yargs arguments object.
40
+ * @returns An object with options that can be passed to Babelify.
41
+ */
42
+ function processDependencies(argv) {
43
+ const { depsToTranspile, transpilationMode } = argv;
44
+ const babelifyOptions = {};
45
+ if (transpilationMode === builders_1.TranspilationModes.LocalAndDeps) {
46
+ const regexpStr = getDependencyRegExp(depsToTranspile);
47
+ if (regexpStr !== null) {
48
+ babelifyOptions.ignore = [regexpStr];
49
+ }
50
+ }
51
+ return babelifyOptions;
52
+ }
53
+ exports.processDependencies = processDependencies;
54
+ /**
55
+ * Processes a string of space delimited dependencies into one RegExp string.
56
+ *
57
+ * @param dependencies - An array of dependencies to add to the RegExp.
58
+ * @returns A RegExp object.
59
+ */
60
+ function getDependencyRegExp(dependencies) {
61
+ let regexp = null;
62
+ if (!dependencies || dependencies.includes('.') || !dependencies.length) {
63
+ return regexp;
64
+ }
65
+ const paths = sanitizeDependencyPaths(dependencies);
66
+ regexp = `/node_modules/(?!${paths.shift() ?? ''}`;
67
+ paths.forEach((path) => (regexp += `|${path}`));
68
+ regexp += '/)';
69
+ return RegExp(regexp, 'u');
70
+ }
71
+ exports.getDependencyRegExp = getDependencyRegExp;
72
+ /**
73
+ * Helper function remove any leading and trailing slashes from dependency list.
74
+ *
75
+ * @param dependencies - An array of dependencies to sanitize.
76
+ * @returns An array of sanitized paths.
77
+ */
78
+ function sanitizeDependencyPaths(dependencies) {
79
+ return dependencies.map((dependency) => {
80
+ return dependency.replace(/^[/\\]+/u, '').replace(/[/\\]+$/u, '');
81
+ });
82
+ }
83
+ exports.sanitizeDependencyPaths = sanitizeDependencyPaths;
84
+ /**
85
+ * Check the Yargs argv object, to see if the provided options are valid. The
86
+ * options are invalid if both `depsToTranspile` are provided, and
87
+ * `transpilationMode` is not set to `localAndDeps`.
88
+ *
89
+ * @param argv - The Yargs arguments object.
90
+ * @throws If the `depsToTranspile` is set, and `transpilationMode` is not set
91
+ * to `localAndDeps`.
92
+ */
93
+ function processInvalidTranspilation(argv) {
94
+ if (argv.depsToTranspile &&
95
+ argv.transpilationMode !== builders_1.TranspilationModes.LocalAndDeps) {
96
+ throw new Error('"depsToTranspile" can only be specified if "transpilationMode" is set to "localAndDeps" .');
97
+ }
98
+ }
99
+ exports.processInvalidTranspilation = processInvalidTranspilation;
100
+ //# sourceMappingURL=utils.js.map