@metamask/snaps-cli 0.35.0-flask.1 → 1.0.0-prerelease.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 (153) hide show
  1. package/CHANGELOG.md +3 -26
  2. package/README.md +6 -5
  3. package/dist/{esm/builders.js → builders.js} +29 -27
  4. package/dist/{cjs/builders.js.map → builders.js.map} +1 -1
  5. package/dist/cli.js +51 -0
  6. package/dist/cli.js.map +1 -0
  7. package/dist/cmds/build/buildHandler.js +37 -0
  8. package/dist/cmds/build/buildHandler.js.map +1 -0
  9. package/dist/cmds/build/bundle.js +80 -0
  10. package/dist/cmds/build/bundle.js.map +1 -0
  11. package/dist/{types/cmds/serve → cmds/build}/index.d.ts +2 -2
  12. package/dist/cmds/build/index.js +29 -0
  13. package/dist/cmds/build/index.js.map +1 -0
  14. package/dist/{esm/cmds → cmds}/build/utils.js +34 -22
  15. package/dist/cmds/build/utils.js.map +1 -0
  16. package/dist/cmds/eval/evalHandler.js +25 -0
  17. package/dist/cmds/eval/evalHandler.js.map +1 -0
  18. package/dist/{types/cmds/manifest → cmds/eval}/index.d.ts +2 -2
  19. package/dist/cmds/eval/index.js +15 -0
  20. package/dist/cmds/eval/index.js.map +1 -0
  21. package/dist/cmds/index.js +14 -0
  22. package/dist/cmds/index.js.map +1 -0
  23. package/dist/{types/cmds/build → cmds/init}/index.d.ts +2 -2
  24. package/dist/cmds/init/index.js +34 -0
  25. package/dist/cmds/init/index.js.map +1 -0
  26. package/dist/cmds/init/initHandler.d.ts +26 -0
  27. package/dist/cmds/init/initHandler.js +69 -0
  28. package/dist/cmds/init/initHandler.js.map +1 -0
  29. package/dist/cmds/init/initUtils.d.ts +39 -0
  30. package/dist/cmds/init/initUtils.js +122 -0
  31. package/dist/cmds/init/initUtils.js.map +1 -0
  32. package/dist/{types/cmds/eval → cmds/manifest}/index.d.ts +2 -2
  33. package/dist/cmds/manifest/index.js +24 -0
  34. package/dist/cmds/manifest/index.js.map +1 -0
  35. package/dist/cmds/manifest/manifestHandler.js +50 -0
  36. package/dist/cmds/manifest/manifestHandler.js.map +1 -0
  37. package/dist/cmds/serve/index.d.ts +9 -0
  38. package/dist/cmds/serve/index.js +15 -0
  39. package/dist/cmds/serve/index.js.map +1 -0
  40. package/dist/cmds/serve/serveHandler.js +59 -0
  41. package/dist/cmds/serve/serveHandler.js.map +1 -0
  42. package/dist/cmds/serve/serveUtils.js +39 -0
  43. package/dist/cmds/serve/serveUtils.js.map +1 -0
  44. package/dist/cmds/watch/index.d.ts +9 -0
  45. package/dist/cmds/watch/index.js +32 -0
  46. package/dist/cmds/watch/index.js.map +1 -0
  47. package/dist/cmds/watch/watchHandler.js +100 -0
  48. package/dist/cmds/watch/watchHandler.js.map +1 -0
  49. package/dist/main.js +15 -0
  50. package/dist/main.js.map +1 -0
  51. package/dist/utils/index.js +19 -0
  52. package/dist/utils/index.js.map +1 -0
  53. package/dist/{esm/utils → utils}/misc.js +50 -32
  54. package/dist/utils/misc.js.map +1 -0
  55. package/dist/{esm/utils → utils}/snap-config.js +39 -26
  56. package/dist/utils/snap-config.js.map +1 -0
  57. package/package.json +27 -65
  58. package/dist/cjs/builders.js +0 -149
  59. package/dist/cjs/cli.js +0 -35
  60. package/dist/cjs/cli.js.map +0 -1
  61. package/dist/cjs/cmds/build/buildHandler.js +0 -36
  62. package/dist/cjs/cmds/build/buildHandler.js.map +0 -1
  63. package/dist/cjs/cmds/build/bundle.js +0 -83
  64. package/dist/cjs/cmds/build/bundle.js.map +0 -1
  65. package/dist/cjs/cmds/build/index.js +0 -32
  66. package/dist/cjs/cmds/build/index.js.map +0 -1
  67. package/dist/cjs/cmds/build/utils.js +0 -79
  68. package/dist/cjs/cmds/build/utils.js.map +0 -1
  69. package/dist/cjs/cmds/eval/evalHandler.js +0 -24
  70. package/dist/cjs/cmds/eval/evalHandler.js.map +0 -1
  71. package/dist/cjs/cmds/eval/index.js +0 -31
  72. package/dist/cjs/cmds/eval/index.js.map +0 -1
  73. package/dist/cjs/cmds/index.js +0 -30
  74. package/dist/cjs/cmds/index.js.map +0 -1
  75. package/dist/cjs/cmds/manifest/index.js +0 -44
  76. package/dist/cjs/cmds/manifest/index.js.map +0 -1
  77. package/dist/cjs/cmds/manifest/manifestHandler.js +0 -46
  78. package/dist/cjs/cmds/manifest/manifestHandler.js.map +0 -1
  79. package/dist/cjs/cmds/serve/index.js +0 -31
  80. package/dist/cjs/cmds/serve/index.js.map +0 -1
  81. package/dist/cjs/cmds/serve/serveHandler.js +0 -62
  82. package/dist/cjs/cmds/serve/serveHandler.js.map +0 -1
  83. package/dist/cjs/cmds/serve/serveUtils.js +0 -37
  84. package/dist/cjs/cmds/serve/serveUtils.js.map +0 -1
  85. package/dist/cjs/cmds/watch/index.js +0 -32
  86. package/dist/cjs/cmds/watch/index.js.map +0 -1
  87. package/dist/cjs/cmds/watch/watchHandler.js +0 -91
  88. package/dist/cjs/cmds/watch/watchHandler.js.map +0 -1
  89. package/dist/cjs/index.js +0 -52
  90. package/dist/cjs/index.js.map +0 -1
  91. package/dist/cjs/main.js +0 -20
  92. package/dist/cjs/main.js.map +0 -1
  93. package/dist/cjs/utils/index.js +0 -21
  94. package/dist/cjs/utils/index.js.map +0 -1
  95. package/dist/cjs/utils/misc.js +0 -141
  96. package/dist/cjs/utils/misc.js.map +0 -1
  97. package/dist/cjs/utils/snap-config.js +0 -101
  98. package/dist/cjs/utils/snap-config.js.map +0 -1
  99. package/dist/esm/builders.js.map +0 -1
  100. package/dist/esm/cli.js +0 -26
  101. package/dist/esm/cli.js.map +0 -1
  102. package/dist/esm/cmds/build/buildHandler.js +0 -36
  103. package/dist/esm/cmds/build/buildHandler.js.map +0 -1
  104. package/dist/esm/cmds/build/bundle.js +0 -81
  105. package/dist/esm/cmds/build/bundle.js.map +0 -1
  106. package/dist/esm/cmds/build/index.js +0 -17
  107. package/dist/esm/cmds/build/index.js.map +0 -1
  108. package/dist/esm/cmds/build/utils.js.map +0 -1
  109. package/dist/esm/cmds/eval/evalHandler.js +0 -20
  110. package/dist/esm/cmds/eval/evalHandler.js.map +0 -1
  111. package/dist/esm/cmds/eval/index.js +0 -16
  112. package/dist/esm/cmds/eval/index.js.map +0 -1
  113. package/dist/esm/cmds/index.js +0 -15
  114. package/dist/esm/cmds/index.js.map +0 -1
  115. package/dist/esm/cmds/manifest/index.js +0 -29
  116. package/dist/esm/cmds/manifest/index.js.map +0 -1
  117. package/dist/esm/cmds/manifest/manifestHandler.js +0 -43
  118. package/dist/esm/cmds/manifest/manifestHandler.js.map +0 -1
  119. package/dist/esm/cmds/serve/index.js +0 -16
  120. package/dist/esm/cmds/serve/index.js.map +0 -1
  121. package/dist/esm/cmds/serve/serveHandler.js +0 -54
  122. package/dist/esm/cmds/serve/serveHandler.js.map +0 -1
  123. package/dist/esm/cmds/serve/serveUtils.js +0 -30
  124. package/dist/esm/cmds/serve/serveUtils.js.map +0 -1
  125. package/dist/esm/cmds/watch/index.js +0 -17
  126. package/dist/esm/cmds/watch/index.js.map +0 -1
  127. package/dist/esm/cmds/watch/watchHandler.js +0 -87
  128. package/dist/esm/cmds/watch/watchHandler.js.map +0 -1
  129. package/dist/esm/index.js +0 -3
  130. package/dist/esm/index.js.map +0 -1
  131. package/dist/esm/main.js +0 -11
  132. package/dist/esm/main.js.map +0 -1
  133. package/dist/esm/utils/index.js +0 -4
  134. package/dist/esm/utils/index.js.map +0 -1
  135. package/dist/esm/utils/misc.js.map +0 -1
  136. package/dist/esm/utils/snap-config.js.map +0 -1
  137. package/dist/types/cmds/watch/index.d.ts +0 -9
  138. package/dist/types/index.d.ts +0 -1
  139. /package/dist/{types/builders.d.ts → builders.d.ts} +0 -0
  140. /package/dist/{types/cli.d.ts → cli.d.ts} +0 -0
  141. /package/dist/{types/cmds → cmds}/build/buildHandler.d.ts +0 -0
  142. /package/dist/{types/cmds → cmds}/build/bundle.d.ts +0 -0
  143. /package/dist/{types/cmds → cmds}/build/utils.d.ts +0 -0
  144. /package/dist/{types/cmds → cmds}/eval/evalHandler.d.ts +0 -0
  145. /package/dist/{types/cmds → cmds}/index.d.ts +0 -0
  146. /package/dist/{types/cmds → cmds}/manifest/manifestHandler.d.ts +0 -0
  147. /package/dist/{types/cmds → cmds}/serve/serveHandler.d.ts +0 -0
  148. /package/dist/{types/cmds → cmds}/serve/serveUtils.d.ts +0 -0
  149. /package/dist/{types/cmds → cmds}/watch/watchHandler.d.ts +0 -0
  150. /package/dist/{types/main.d.ts → main.d.ts} +0 -0
  151. /package/dist/{types/utils → utils}/index.d.ts +0 -0
  152. /package/dist/{types/utils → utils}/misc.d.ts +0 -0
  153. /package/dist/{types/utils → utils}/snap-config.d.ts +0 -0
package/CHANGELOG.md CHANGED
@@ -6,29 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
- ## [0.35.0-flask.1]
10
- ### Changed
11
- - **BREAKING:** Build packages as both CJS and ESM ([#1519](https://github.com/MetaMask/snaps/pull/1519), ([#1532](https://github.com/MetaMask/snaps/pull/1532)))
12
- - This is breaking in the sense that imports to `dist/` will now require you to import either `dist/cjs` or `dist/esm`.
13
- - Add `sideEffects: false` ([#1486](https://github.com/MetaMask/snaps/pull/1486))
14
-
15
- ## [0.34.1-flask.1]
9
+ ## [1.0.0-prerelease.1]
16
10
  ### Changed
17
11
  - No changes this release.
18
12
 
19
- ## [0.34.0-flask.1]
20
- ### Removed
21
- - **BREAKING:** Remove `init` command ([#1268](https://github.com/MetaMask/snaps/pull/1268))
22
-
23
- ## [0.33.1-flask.1]
24
- ### Changed
25
- - No changes this release.
26
-
27
- ## [0.33.0-flask.1]
28
- ### Changed
29
- - Support ES2022 features ([#1373](https://github.com/MetaMask/snaps-monorepo/pull/1373))
30
- - Automatically watch `snap.config.js` and `snap.manifest.json` files ([#1358](https://github.com/MetaMask/snaps-monorepo/pull/1358))
31
-
32
13
  ## [0.32.2]
33
14
  ### Changed
34
15
  - No changes this release.
@@ -344,12 +325,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
344
325
  - Example snaps ([#72](https://github.com/MetaMask/snaps-monorepo/pull/72))
345
326
  - The examples now live in their own package, [`@metamask/snap-examples`](https://npmjs.com/package/@metamask/snap-examples).
346
327
 
347
- [Unreleased]: https://github.com/MetaMask/snaps/compare/v0.35.0-flask.1...HEAD
348
- [0.35.0-flask.1]: https://github.com/MetaMask/snaps/compare/v0.34.1-flask.1...v0.35.0-flask.1
349
- [0.34.1-flask.1]: https://github.com/MetaMask/snaps/compare/v0.34.0-flask.1...v0.34.1-flask.1
350
- [0.34.0-flask.1]: https://github.com/MetaMask/snaps/compare/v0.33.1-flask.1...v0.34.0-flask.1
351
- [0.33.1-flask.1]: https://github.com/MetaMask/snaps/compare/v0.33.0-flask.1...v0.33.1-flask.1
352
- [0.33.0-flask.1]: https://github.com/MetaMask/snaps/compare/v0.32.2...v0.33.0-flask.1
328
+ [Unreleased]: https://github.com/MetaMask/snaps/compare/v1.0.0-prerelease.1...HEAD
329
+ [1.0.0-prerelease.1]: https://github.com/MetaMask/snaps/compare/v0.32.2...v1.0.0-prerelease.1
353
330
  [0.32.2]: https://github.com/MetaMask/snaps/compare/v0.32.1...v0.32.2
354
331
  [0.32.1]: https://github.com/MetaMask/snaps/compare/v0.32.0...v0.32.1
355
332
  [0.32.0]: https://github.com/MetaMask/snaps/compare/v0.31.0...v0.32.0
package/README.md CHANGED
@@ -18,11 +18,12 @@ Install a dev dependency in your snap project or globally using `yarn` or `npm`:
18
18
  Usage: mm-snap <command> [options]
19
19
 
20
20
  Commands:
21
- mm-snap build Build Snap from source [aliases: b]
22
- mm-snap eval Attempt to evaluate Snap bundle in SES [aliases: e]
23
- mm-snap manifest Validate the snap.manifest.json file [aliases: m]
24
- mm-snap serve Locally serve Snap file(s) for testing [aliases: s]
25
- mm-snap watch Build Snap on change [aliases: w]
21
+ mm-snap build Build Snap from source [aliases: b]
22
+ mm-snap eval Attempt to evaluate Snap bundle in SES [aliases: e]
23
+ mm-snap init [directory] Initialize Snap package [aliases: i]
24
+ mm-snap manifest Validate the snap.manifest.json file [aliases: m]
25
+ mm-snap serve Locally serve Snap file(s) for testing [aliases: s]
26
+ mm-snap watch Build Snap on change [aliases: w]
26
27
 
27
28
  Options:
28
29
  --version Show version number [boolean]
@@ -1,9 +1,12 @@
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
11
  bundle: {
9
12
  alias: 'b',
@@ -11,7 +14,7 @@ const builders = {
11
14
  type: 'string',
12
15
  demandOption: true,
13
16
  normalize: true,
14
- default: 'dist/bundle.js'
17
+ default: 'dist/bundle.js',
15
18
  },
16
19
  dist: {
17
20
  alias: 'd',
@@ -19,21 +22,21 @@ const builders = {
19
22
  type: 'string',
20
23
  demandOption: true,
21
24
  normalize: true,
22
- default: 'dist'
25
+ default: 'dist',
23
26
  },
24
27
  eval: {
25
28
  alias: 'e',
26
29
  describe: 'Attempt to evaluate Snap bundle in SES',
27
30
  type: 'boolean',
28
31
  demandOption: false,
29
- default: true
32
+ default: true,
30
33
  },
31
34
  manifest: {
32
35
  alias: 'm',
33
36
  describe: 'Validate snap.manifest.json',
34
37
  type: 'boolean',
35
38
  demandOption: false,
36
- default: true
39
+ default: true,
37
40
  },
38
41
  port: {
39
42
  alias: 'p',
@@ -41,20 +44,20 @@ const builders = {
41
44
  type: 'number',
42
45
  demandOption: true,
43
46
  default: 8081,
44
- coerce: (arg)=>{
47
+ coerce: (arg) => {
45
48
  const port = Number.parseInt(String(arg), 10);
46
49
  if (Number.isNaN(port)) {
47
50
  throw new Error(`Invalid port: ${String(arg)}`);
48
51
  }
49
52
  return port;
50
- }
53
+ },
51
54
  },
52
55
  outfileName: {
53
56
  alias: 'n',
54
57
  describe: 'Output file name',
55
58
  type: 'string',
56
59
  demandOption: false,
57
- default: 'bundle.js'
60
+ default: 'bundle.js',
58
61
  },
59
62
  root: {
60
63
  alias: 'r',
@@ -62,13 +65,13 @@ const builders = {
62
65
  type: 'string',
63
66
  demandOption: true,
64
67
  normalize: true,
65
- default: '.'
68
+ default: '.',
66
69
  },
67
70
  sourceMaps: {
68
71
  describe: 'Whether builds include sourcemaps',
69
72
  type: 'boolean',
70
73
  demandOption: false,
71
- default: false
74
+ default: false,
72
75
  },
73
76
  src: {
74
77
  alias: 's',
@@ -76,56 +79,55 @@ const builders = {
76
79
  type: 'string',
77
80
  demandOption: true,
78
81
  normalize: true,
79
- default: 'src/index.js'
82
+ default: 'src/index.js',
80
83
  },
81
84
  stripComments: {
82
85
  alias: 'strip',
83
86
  describe: 'Whether to remove code comments from the build output',
84
87
  type: 'boolean',
85
88
  demandOption: false,
86
- default: true
89
+ default: true,
87
90
  },
88
91
  suppressWarnings: {
89
92
  type: 'boolean',
90
93
  describe: 'Whether to suppress warnings',
91
94
  demandOption: false,
92
- default: false
95
+ default: false,
93
96
  },
94
97
  transpilationMode: {
95
98
  type: 'string',
96
99
  describe: 'Whether to use Babel to transpile all source code (including dependencies), local source code only, or nothing.',
97
100
  demandOption: false,
98
101
  default: TranspilationModes.LocalOnly,
99
- choices: Object.values(TranspilationModes)
102
+ choices: Object.values(TranspilationModes),
100
103
  },
101
104
  depsToTranspile: {
102
105
  type: 'array',
103
106
  describe: 'Transpile only the listed dependencies.',
104
- demandOption: false
107
+ demandOption: false,
105
108
  },
106
109
  verboseErrors: {
107
110
  type: 'boolean',
108
111
  describe: 'Display original errors',
109
112
  demandOption: false,
110
- default: true
113
+ default: true,
111
114
  },
112
115
  writeManifest: {
113
116
  describe: 'Make necessary changes to the Snap manifest file',
114
117
  type: 'boolean',
115
118
  demandOption: false,
116
- default: true
119
+ default: true,
117
120
  },
118
121
  serve: {
119
122
  describe: 'Serve Snap file(s) locally for testing',
120
123
  type: 'boolean',
121
124
  demandOption: false,
122
- default: true
125
+ default: true,
123
126
  },
124
127
  directory: {
125
128
  describe: 'the directory to use',
126
- type: 'string'
127
- }
129
+ type: 'string',
130
+ },
128
131
  };
129
- export default builders;
130
-
132
+ exports.default = builders;
131
133
  //# sourceMappingURL=builders.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/builders.ts"],"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"],"names":["TranspilationModes","LocalAndDeps","LocalOnly","None","builders","bundle","alias","describe","type","demandOption","normalize","default","dist","eval","manifest","port","coerce","arg","Number","parseInt","String","isNaN","Error","outfileName","root","sourceMaps","src","stripComments","suppressWarnings","transpilationMode","choices","Object","values","depsToTranspile","verboseErrors","writeManifest","serve","directory"],"mappings":";;;;;;;;;;;;;;IAwKA,OAAwB;eAAxB;;;IAlJO;UAAKA,kBAAkB;IAAlBA,mBACVC,kBAAe;IADLD,mBAEVE,eAAY;IAFFF,mBAGVG,UAAO;GAHGH,uBAAAA;AAMZ,MAAMI,WAA6B;IACjCC,QAAQ;QACNC,OAAO;QACPC,UAAU;QACVC,MAAM;QACNC,cAAc;QACdC,WAAW;QACXC,SAAS;IACX;IAEAC,MAAM;QACJN,OAAO;QACPC,UAAU;QACVC,MAAM;QACNC,cAAc;QACdC,WAAW;QACXC,SAAS;IACX;IAEAE,MAAM;QACJP,OAAO;QACPC,UAAU;QACVC,MAAM;QACNC,cAAc;QACdE,SAAS;IACX;IAEAG,UAAU;QACRR,OAAO;QACPC,UAAU;QACVC,MAAM;QACNC,cAAc;QACdE,SAAS;IACX;IAEAI,MAAM;QACJT,OAAO;QACPC,UAAU;QACVC,MAAM;QACNC,cAAc;QACdE,SAAS;QACTK,QAAQ,CAACC;YACP,MAAMF,OAAOG,OAAOC,QAAQ,CAACC,OAAOH,MAAM;YAC1C,IAAIC,OAAOG,KAAK,CAACN,OAAO;gBACtB,MAAM,IAAIO,MAAM,CAAC,cAAc,EAAEF,OAAOH,KAAK,CAAC;YAChD;YACA,OAAOF;QACT;IACF;IAEAQ,aAAa;QACXjB,OAAO;QACPC,UAAU;QACVC,MAAM;QACNC,cAAc;QACdE,SAAS;IACX;IAEAa,MAAM;QACJlB,OAAO;QACPC,UAAU;QACVC,MAAM;QACNC,cAAc;QACdC,WAAW;QACXC,SAAS;IACX;IAEAc,YAAY;QACVlB,UAAU;QACVC,MAAM;QACNC,cAAc;QACdE,SAAS;IACX;IAEAe,KAAK;QACHpB,OAAO;QACPC,UAAU;QACVC,MAAM;QACNC,cAAc;QACdC,WAAW;QACXC,SAAS;IACX;IAEAgB,eAAe;QACbrB,OAAO;QACPC,UAAU;QACVC,MAAM;QACNC,cAAc;QACdE,SAAS;IACX;IAEAiB,kBAAkB;QAChBpB,MAAM;QACND,UAAU;QACVE,cAAc;QACdE,SAAS;IACX;IAEAkB,mBAAmB;QACjBrB,MAAM;QACND,UACE;QACFE,cAAc;QACdE,SAASX,mBAAmBE,SAAS;QACrC4B,SAASC,OAAOC,MAAM,CAAChC;IACzB;IAEAiC,iBAAiB;QACfzB,MAAM;QACND,UAAU;QACVE,cAAc;IAChB;IAEAyB,eAAe;QACb1B,MAAM;QACND,UAAU;QACVE,cAAc;QACdE,SAAS;IACX;IAEAwB,eAAe;QACb5B,UAAU;QACVC,MAAM;QACNC,cAAc;QACdE,SAAS;IACX;IAEAyB,OAAO;QACL7B,UAAU;QACVC,MAAM;QACNC,cAAc;QACdE,SAAS;IACX;IAEA0B,WAAW;QACT9B,UAAU;QACVC,MAAM;IACR;AACF;MAEA,WAAeJ"}
1
+ {"version":3,"file":"builders.js","sourceRoot":"","sources":["../src/builders.ts"],"names":[],"mappings":";;;AAsBA,IAAY,kBAIX;AAJD,WAAY,kBAAkB;IAC5B,mDAA6B,CAAA;IAC7B,6CAAuB,CAAA;IACvB,mCAAa,CAAA;AACf,CAAC,EAJW,kBAAkB,GAAlB,0BAAkB,KAAlB,0BAAkB,QAI7B;AAED,MAAM,QAAQ,GAAqB;IACjC,MAAM,EAAE;QACN,KAAK,EAAE,GAAG;QACV,QAAQ,EAAE,kBAAkB;QAC5B,IAAI,EAAE,QAAQ;QACd,YAAY,EAAE,IAAI;QAClB,SAAS,EAAE,IAAI;QACf,OAAO,EAAE,gBAAgB;KAC1B;IAED,IAAI,EAAE;QACJ,KAAK,EAAE,GAAG;QACV,QAAQ,EAAE,kBAAkB;QAC5B,IAAI,EAAE,QAAQ;QACd,YAAY,EAAE,I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\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"]}
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,CAA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,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,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,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,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ACJ,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
1
  import yargs from 'yargs';
2
2
  import { YargsArgs } from '../../types/yargs';
3
- declare const command: {
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"]}
@@ -1,7 +1,10 @@
1
- import { logInfo } from '@metamask/snaps-utils';
2
- import { promises as fs } from 'fs';
3
- import { TranspilationModes } from '../../builders';
4
- import { writeError } from '../../utils';
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");
5
8
  /**
6
9
  * Performs postprocessing on the bundle contents and writes them to disk.
7
10
  * Intended to be used in the callback passed to the Browserify `.bundle()`
@@ -15,62 +18,69 @@ import { writeError } from '../../utils';
15
18
  * @param options.dest - The destination file path.
16
19
  * @param options.resolve - A {@link Promise} resolution function, so that we
17
20
  * can use promises and `async`/`await` even though Browserify uses callbacks.
18
- */ export async function writeBundleFile({ bundleError, bundleBuffer, src, dest, resolve }) {
21
+ */
22
+ async function writeBundleFile({ bundleError, bundleBuffer, src, dest, resolve, }) {
19
23
  if (bundleError) {
20
- await writeError('Build error:', bundleError.message, bundleError);
24
+ await (0, utils_1.writeError)('Build error:', bundleError.message, bundleError);
21
25
  }
22
26
  try {
23
- await fs.writeFile(dest, bundleBuffer?.toString());
24
- logInfo(`Build success: '${src}' bundled as '${dest}'!`);
27
+ await fs_1.promises.writeFile(dest, bundleBuffer?.toString());
28
+ (0, snaps_utils_1.logInfo)(`Build success: '${src}' bundled as '${dest}'!`);
25
29
  resolve(true);
26
- } catch (error) {
27
- await writeError('Write error:', error.message, error, dest);
30
+ }
31
+ catch (error) {
32
+ await (0, utils_1.writeError)('Write error:', error.message, error, dest);
28
33
  }
29
34
  }
35
+ exports.writeBundleFile = writeBundleFile;
30
36
  /**
31
37
  * Processes dependencies and updates `argv` with an options object.
32
38
  *
33
39
  * @param argv - The Yargs arguments object.
34
40
  * @returns An object with options that can be passed to Babelify.
35
- */ export function processDependencies(argv) {
41
+ */
42
+ function processDependencies(argv) {
36
43
  const { depsToTranspile, transpilationMode } = argv;
37
44
  const babelifyOptions = {};
38
- if (transpilationMode === TranspilationModes.LocalAndDeps) {
45
+ if (transpilationMode === builders_1.TranspilationModes.LocalAndDeps) {
39
46
  const regexpStr = getDependencyRegExp(depsToTranspile);
40
47
  if (regexpStr !== null) {
41
- babelifyOptions.ignore = [
42
- regexpStr
43
- ];
48
+ babelifyOptions.ignore = [regexpStr];
44
49
  }
45
50
  }
46
51
  return babelifyOptions;
47
52
  }
53
+ exports.processDependencies = processDependencies;
48
54
  /**
49
55
  * Processes a string of space delimited dependencies into one RegExp string.
50
56
  *
51
57
  * @param dependencies - An array of dependencies to add to the RegExp.
52
58
  * @returns A RegExp object.
53
- */ export function getDependencyRegExp(dependencies) {
59
+ */
60
+ function getDependencyRegExp(dependencies) {
54
61
  let regexp = null;
55
62
  if (!dependencies || dependencies.includes('.') || !dependencies.length) {
56
63
  return regexp;
57
64
  }
58
65
  const paths = sanitizeDependencyPaths(dependencies);
59
66
  regexp = `/node_modules/(?!${paths.shift() ?? ''}`;
60
- paths.forEach((path)=>regexp += `|${path}`);
67
+ paths.forEach((path) => (regexp += `|${path}`));
61
68
  regexp += '/)';
62
69
  return RegExp(regexp, 'u');
63
70
  }
71
+ exports.getDependencyRegExp = getDependencyRegExp;
64
72
  /**
65
73
  * Helper function remove any leading and trailing slashes from dependency list.
66
74
  *
67
75
  * @param dependencies - An array of dependencies to sanitize.
68
76
  * @returns An array of sanitized paths.
69
- */ export function sanitizeDependencyPaths(dependencies) {
70
- return dependencies.map((dependency)=>{
77
+ */
78
+ function sanitizeDependencyPaths(dependencies) {
79
+ return dependencies.map((dependency) => {
71
80
  return dependency.replace(/^[/\\]+/u, '').replace(/[/\\]+$/u, '');
72
81
  });
73
82
  }
83
+ exports.sanitizeDependencyPaths = sanitizeDependencyPaths;
74
84
  /**
75
85
  * Check the Yargs argv object, to see if the provided options are valid. The
76
86
  * options are invalid if both `depsToTranspile` are provided, and
@@ -79,10 +89,12 @@ import { writeError } from '../../utils';
79
89
  * @param argv - The Yargs arguments object.
80
90
  * @throws If the `depsToTranspile` is set, and `transpilationMode` is not set
81
91
  * to `localAndDeps`.
82
- */ export function processInvalidTranspilation(argv) {
83
- if (argv.depsToTranspile && argv.transpilationMode !== TranspilationModes.LocalAndDeps) {
92
+ */
93
+ function processInvalidTranspilation(argv) {
94
+ if (argv.depsToTranspile &&
95
+ argv.transpilationMode !== builders_1.TranspilationModes.LocalAndDeps) {
84
96
  throw new Error('"depsToTranspile" can only be specified if "transpilationMode" is set to "localAndDeps" .');
85
97
  }
86
98
  }
87
-
99
+ exports.processInvalidTranspilation = processInvalidTranspilation;
88
100
  //# sourceMappingURL=utils.js.map