@metamask/snaps-cli 6.0.2 → 6.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/CHANGELOG.md +21 -1
  2. package/dist/{chunk-WYDHPUWV.mjs → chunk-76IQAFYR.mjs} +2 -2
  3. package/dist/{chunk-X7VYAL2L.mjs → chunk-7P7JW53B.mjs} +8 -3
  4. package/dist/chunk-7P7JW53B.mjs.map +1 -0
  5. package/dist/{chunk-BVPYLBE5.js → chunk-AKAP22EL.js} +8 -3
  6. package/dist/chunk-AKAP22EL.js.map +1 -0
  7. package/dist/{chunk-K5QMGTQL.mjs → chunk-AO724LXX.mjs} +2 -2
  8. package/dist/{chunk-XUYXKO4F.js → chunk-BFX2RH3M.js} +43 -14
  9. package/dist/chunk-BFX2RH3M.js.map +1 -0
  10. package/dist/{chunk-7NQQGJZJ.mjs → chunk-BVPROOGE.mjs} +2 -2
  11. package/dist/{chunk-SVYNCWMH.js → chunk-C2OMV3H5.js} +3 -3
  12. package/dist/{chunk-JI3B665Z.js → chunk-CQZ2AXMG.js} +3 -3
  13. package/dist/{chunk-CIYE263O.js → chunk-EHJPVBQU.js} +5 -5
  14. package/dist/{chunk-HQBA5RU6.mjs → chunk-FQ3HKVHQ.mjs} +2 -2
  15. package/dist/{chunk-OKDY7C7S.js → chunk-HNWSVD35.js} +10 -10
  16. package/dist/{chunk-OPE2PGM6.mjs → chunk-IO6WNNPF.mjs} +2 -2
  17. package/dist/{chunk-5KQNAW4C.mjs → chunk-JBSWMUCQ.mjs} +2 -2
  18. package/dist/{chunk-MDHJ5HLM.js → chunk-JEMJNDZO.js} +8 -2
  19. package/dist/chunk-JEMJNDZO.js.map +1 -0
  20. package/dist/{chunk-26C34AS7.mjs → chunk-OGGTU5W6.mjs} +7 -1
  21. package/dist/chunk-OGGTU5W6.mjs.map +1 -0
  22. package/dist/{chunk-KUSHMQXD.js → chunk-QXP34HW3.js} +8 -17
  23. package/dist/chunk-QXP34HW3.js.map +1 -0
  24. package/dist/{chunk-CGJKCIHP.js → chunk-RJ6IKKA2.js} +3 -3
  25. package/dist/{chunk-EDEA4QTA.js → chunk-RM5FN3N5.js} +3 -3
  26. package/dist/{chunk-T7NEPTM5.mjs → chunk-SM2JEXE6.mjs} +2 -2
  27. package/dist/{chunk-XZJLYKES.mjs → chunk-SUSC466E.mjs} +7 -16
  28. package/dist/chunk-SUSC466E.mjs.map +1 -0
  29. package/dist/{chunk-GKRRE4WN.mjs → chunk-T4CLBV7F.mjs} +3 -3
  30. package/dist/{chunk-YQVCFM6L.js → chunk-V4UPOVEH.js} +3 -3
  31. package/dist/{chunk-YWCNJELN.mjs → chunk-VIQIUSXW.mjs} +33 -4
  32. package/dist/chunk-VIQIUSXW.mjs.map +1 -0
  33. package/dist/{chunk-WO7DMSQU.mjs → chunk-WUC7DUXN.mjs} +2 -2
  34. package/dist/{chunk-5CLEKHXE.js → chunk-XQGKSVFJ.js} +3 -3
  35. package/dist/{chunk-R6NBQKVH.js → chunk-ZOC4OHGM.js} +3 -3
  36. package/dist/cli.js +3 -3
  37. package/dist/cli.mjs +2 -2
  38. package/dist/commands/build/build.js +7 -7
  39. package/dist/commands/build/build.mjs +6 -6
  40. package/dist/commands/build/implementation.js +6 -6
  41. package/dist/commands/build/implementation.mjs +5 -5
  42. package/dist/commands/build/index.js +8 -8
  43. package/dist/commands/build/index.mjs +7 -7
  44. package/dist/commands/index.js +12 -12
  45. package/dist/commands/index.mjs +11 -11
  46. package/dist/commands/serve/index.js +4 -4
  47. package/dist/commands/serve/index.mjs +4 -4
  48. package/dist/commands/serve/serve.js +4 -4
  49. package/dist/commands/serve/serve.mjs +4 -4
  50. package/dist/commands/watch/implementation.js +6 -6
  51. package/dist/commands/watch/implementation.mjs +5 -5
  52. package/dist/commands/watch/index.js +8 -8
  53. package/dist/commands/watch/index.mjs +7 -7
  54. package/dist/commands/watch/watch.js +7 -7
  55. package/dist/commands/watch/watch.mjs +6 -6
  56. package/dist/config.js +2 -2
  57. package/dist/config.mjs +1 -1
  58. package/dist/index.js +7 -5
  59. package/dist/index.js.map +1 -1
  60. package/dist/index.mjs +7 -5
  61. package/dist/index.mjs.map +1 -1
  62. package/dist/main.js +14 -14
  63. package/dist/main.mjs +13 -13
  64. package/dist/tsconfig.build.tsbuildinfo +1 -1
  65. package/dist/types/config.d.ts +28 -0
  66. package/dist/types/index.d.ts +1 -1
  67. package/dist/types/webpack/utils.d.ts +8 -0
  68. package/dist/webpack/compiler.js +5 -5
  69. package/dist/webpack/compiler.mjs +4 -4
  70. package/dist/webpack/config.js +4 -4
  71. package/dist/webpack/config.mjs +3 -3
  72. package/dist/webpack/index.js +5 -5
  73. package/dist/webpack/index.mjs +4 -4
  74. package/dist/webpack/loaders/browserify.js +2 -2
  75. package/dist/webpack/loaders/browserify.mjs +1 -1
  76. package/dist/webpack/loaders/index.js +2 -2
  77. package/dist/webpack/loaders/index.mjs +1 -1
  78. package/dist/webpack/plugins.js +3 -3
  79. package/dist/webpack/plugins.mjs +2 -2
  80. package/dist/webpack/utils.js +4 -2
  81. package/dist/webpack/utils.mjs +3 -1
  82. package/package.json +4 -4
  83. package/dist/chunk-26C34AS7.mjs.map +0 -1
  84. package/dist/chunk-BVPYLBE5.js.map +0 -1
  85. package/dist/chunk-KUSHMQXD.js.map +0 -1
  86. package/dist/chunk-MDHJ5HLM.js.map +0 -1
  87. package/dist/chunk-X7VYAL2L.mjs.map +0 -1
  88. package/dist/chunk-XUYXKO4F.js.map +0 -1
  89. package/dist/chunk-XZJLYKES.mjs.map +0 -1
  90. package/dist/chunk-YWCNJELN.mjs.map +0 -1
  91. /package/dist/{chunk-WYDHPUWV.mjs.map → chunk-76IQAFYR.mjs.map} +0 -0
  92. /package/dist/{chunk-K5QMGTQL.mjs.map → chunk-AO724LXX.mjs.map} +0 -0
  93. /package/dist/{chunk-7NQQGJZJ.mjs.map → chunk-BVPROOGE.mjs.map} +0 -0
  94. /package/dist/{chunk-SVYNCWMH.js.map → chunk-C2OMV3H5.js.map} +0 -0
  95. /package/dist/{chunk-JI3B665Z.js.map → chunk-CQZ2AXMG.js.map} +0 -0
  96. /package/dist/{chunk-CIYE263O.js.map → chunk-EHJPVBQU.js.map} +0 -0
  97. /package/dist/{chunk-HQBA5RU6.mjs.map → chunk-FQ3HKVHQ.mjs.map} +0 -0
  98. /package/dist/{chunk-OKDY7C7S.js.map → chunk-HNWSVD35.js.map} +0 -0
  99. /package/dist/{chunk-OPE2PGM6.mjs.map → chunk-IO6WNNPF.mjs.map} +0 -0
  100. /package/dist/{chunk-5KQNAW4C.mjs.map → chunk-JBSWMUCQ.mjs.map} +0 -0
  101. /package/dist/{chunk-CGJKCIHP.js.map → chunk-RJ6IKKA2.js.map} +0 -0
  102. /package/dist/{chunk-EDEA4QTA.js.map → chunk-RM5FN3N5.js.map} +0 -0
  103. /package/dist/{chunk-T7NEPTM5.mjs.map → chunk-SM2JEXE6.mjs.map} +0 -0
  104. /package/dist/{chunk-GKRRE4WN.mjs.map → chunk-T4CLBV7F.mjs.map} +0 -0
  105. /package/dist/{chunk-YQVCFM6L.js.map → chunk-V4UPOVEH.js.map} +0 -0
  106. /package/dist/{chunk-WO7DMSQU.mjs.map → chunk-WUC7DUXN.mjs.map} +0 -0
  107. /package/dist/{chunk-5CLEKHXE.js.map → chunk-XQGKSVFJ.js.map} +0 -0
  108. /package/dist/{chunk-R6NBQKVH.js.map → chunk-ZOC4OHGM.js.map} +0 -0
@@ -336,6 +336,26 @@ export declare type SnapWebpackConfig = {
336
336
  vm?: boolean;
337
337
  zlib?: boolean;
338
338
  };
339
+ /**
340
+ * Optional features to enable in the CLI.
341
+ *
342
+ * @example
343
+ * {
344
+ * features: {
345
+ * images: true,
346
+ * }
347
+ * }
348
+ */
349
+ features?: {
350
+ /**
351
+ * Whether to enable support for images. If `true`, the Webpack
352
+ * configuration will be modified to support images. If `false`, the
353
+ * Webpack configuration will not be modified.
354
+ *
355
+ * @default true
356
+ */
357
+ images?: boolean;
358
+ };
339
359
  /**
340
360
  * A function to customize the Webpack configuration used to build the snap.
341
361
  * This function will be called with the default Webpack configuration, and
@@ -510,6 +530,9 @@ export declare const SnapsWebpackConfigStruct: import("superstruct").Struct<{
510
530
  util: boolean;
511
531
  vm: boolean;
512
532
  };
533
+ features: {
534
+ images: boolean;
535
+ };
513
536
  experimental: {
514
537
  wasm: boolean;
515
538
  };
@@ -652,6 +675,11 @@ export declare const SnapsWebpackConfigStruct: import("superstruct").Struct<{
652
675
  vm: import("superstruct").Struct<boolean, null>;
653
676
  zlib: import("superstruct").Struct<boolean, null>;
654
677
  }>]>;
678
+ features: import("superstruct").Struct<{
679
+ images: boolean;
680
+ }, {
681
+ images: import("superstruct").Struct<boolean, null>;
682
+ }>;
655
683
  customizeWebpackConfig: import("superstruct").Struct<SnapsWebpackCustomizeWebpackConfigFunction | undefined, null>;
656
684
  experimental: import("superstruct").Struct<{
657
685
  wasm: boolean;
@@ -2,4 +2,4 @@ export * as utils from './utils';
2
2
  export type { SnapConfig } from './config';
3
3
  export { getDefaultConfiguration, SnapsStatsPlugin, SnapsWatchPlugin, SnapsBuiltInResolver, SnapsBundleWarningsPlugin, } from './webpack';
4
4
  export type { SnapsStatsPluginOptions, SnapsWatchPluginOptions, SnapsBuiltInResolverOptions, SnapsBundleWarningsPluginOptions, } from './webpack';
5
- export { merge } from 'webpack-merge';
5
+ export { merge, mergeWithCustomize, mergeWithRules } from 'webpack-merge';
@@ -215,3 +215,11 @@ export declare function getEnvironmentVariables(environment: Record<string, unkn
215
215
  * @returns The formatted text.
216
216
  */
217
217
  export declare function formatText(text: string, indent: number, initialIndent?: number): string;
218
+ /**
219
+ * Get an SVG from the given bytes and mime type.
220
+ *
221
+ * @param mimeType - The mime type of the image.
222
+ * @param bytes - The image bytes.
223
+ * @returns The SVG.
224
+ */
225
+ export declare function getImageSVG(mimeType: string, bytes: Uint8Array): string;
@@ -1,12 +1,12 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkR6NBQKVHjs = require('../chunk-R6NBQKVH.js');
4
- require('../chunk-XUYXKO4F.js');
5
- require('../chunk-OKDY7C7S.js');
3
+ var _chunkZOC4OHGMjs = require('../chunk-ZOC4OHGM.js');
4
+ require('../chunk-BFX2RH3M.js');
5
+ require('../chunk-HNWSVD35.js');
6
6
  require('../chunk-6EEZHGF5.js');
7
7
  require('../chunk-KLOPX6DO.js');
8
8
  require('../chunk-MUYXNION.js');
9
- require('../chunk-MDHJ5HLM.js');
9
+ require('../chunk-JEMJNDZO.js');
10
10
  require('../chunk-QHCKVO3P.js');
11
11
  require('../chunk-YQ2E7NEA.js');
12
12
  require('../chunk-4QUVE3EK.js');
@@ -21,5 +21,5 @@ require('../chunk-BALQOCUO.js');
21
21
  require('../chunk-X3D3MHWF.js');
22
22
 
23
23
 
24
- exports.getCompiler = _chunkR6NBQKVHjs.getCompiler;
24
+ exports.getCompiler = _chunkZOC4OHGMjs.getCompiler;
25
25
  //# sourceMappingURL=compiler.js.map
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  getCompiler
3
- } from "../chunk-WO7DMSQU.mjs";
4
- import "../chunk-YWCNJELN.mjs";
5
- import "../chunk-5KQNAW4C.mjs";
3
+ } from "../chunk-WUC7DUXN.mjs";
4
+ import "../chunk-VIQIUSXW.mjs";
5
+ import "../chunk-JBSWMUCQ.mjs";
6
6
  import "../chunk-BYNQODL3.mjs";
7
7
  import "../chunk-K26BOY6Z.mjs";
8
8
  import "../chunk-3WWFQLH4.mjs";
9
- import "../chunk-26C34AS7.mjs";
9
+ import "../chunk-OGGTU5W6.mjs";
10
10
  import "../chunk-AZMQTZXZ.mjs";
11
11
  import "../chunk-ERSRIVYH.mjs";
12
12
  import "../chunk-JL3URCHO.mjs";
@@ -1,11 +1,11 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkXUYXKO4Fjs = require('../chunk-XUYXKO4F.js');
4
- require('../chunk-OKDY7C7S.js');
3
+ var _chunkBFX2RH3Mjs = require('../chunk-BFX2RH3M.js');
4
+ require('../chunk-HNWSVD35.js');
5
5
  require('../chunk-6EEZHGF5.js');
6
6
  require('../chunk-KLOPX6DO.js');
7
7
  require('../chunk-MUYXNION.js');
8
- require('../chunk-MDHJ5HLM.js');
8
+ require('../chunk-JEMJNDZO.js');
9
9
  require('../chunk-QHCKVO3P.js');
10
10
  require('../chunk-YQ2E7NEA.js');
11
11
  require('../chunk-4QUVE3EK.js');
@@ -20,5 +20,5 @@ require('../chunk-BALQOCUO.js');
20
20
  require('../chunk-X3D3MHWF.js');
21
21
 
22
22
 
23
- exports.getDefaultConfiguration = _chunkXUYXKO4Fjs.getDefaultConfiguration;
23
+ exports.getDefaultConfiguration = _chunkBFX2RH3Mjs.getDefaultConfiguration;
24
24
  //# sourceMappingURL=config.js.map
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  getDefaultConfiguration
3
- } from "../chunk-YWCNJELN.mjs";
4
- import "../chunk-5KQNAW4C.mjs";
3
+ } from "../chunk-VIQIUSXW.mjs";
4
+ import "../chunk-JBSWMUCQ.mjs";
5
5
  import "../chunk-BYNQODL3.mjs";
6
6
  import "../chunk-K26BOY6Z.mjs";
7
7
  import "../chunk-3WWFQLH4.mjs";
8
- import "../chunk-26C34AS7.mjs";
8
+ import "../chunk-OGGTU5W6.mjs";
9
9
  import "../chunk-AZMQTZXZ.mjs";
10
10
  import "../chunk-ERSRIVYH.mjs";
11
11
  import "../chunk-JL3URCHO.mjs";
@@ -1,16 +1,16 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});require('../chunk-VXOV3ZCB.js');
2
2
 
3
3
 
4
- var _chunkR6NBQKVHjs = require('../chunk-R6NBQKVH.js');
4
+ var _chunkZOC4OHGMjs = require('../chunk-ZOC4OHGM.js');
5
5
 
6
6
 
7
- var _chunkXUYXKO4Fjs = require('../chunk-XUYXKO4F.js');
7
+ var _chunkBFX2RH3Mjs = require('../chunk-BFX2RH3M.js');
8
8
 
9
9
 
10
10
 
11
11
 
12
12
 
13
- var _chunkOKDY7C7Sjs = require('../chunk-OKDY7C7S.js');
13
+ var _chunkHNWSVD35js = require('../chunk-HNWSVD35.js');
14
14
  require('../chunk-6EEZHGF5.js');
15
15
  require('../chunk-KLOPX6DO.js');
16
16
  require('../chunk-MUYXNION.js');
@@ -18,7 +18,7 @@ require('../chunk-MUYXNION.js');
18
18
 
19
19
 
20
20
  var _chunkYGEAZQSCjs = require('../chunk-YGEAZQSC.js');
21
- require('../chunk-MDHJ5HLM.js');
21
+ require('../chunk-JEMJNDZO.js');
22
22
  require('../chunk-QHCKVO3P.js');
23
23
  require('../chunk-YQ2E7NEA.js');
24
24
  require('../chunk-4QUVE3EK.js');
@@ -40,5 +40,5 @@ require('../chunk-X3D3MHWF.js');
40
40
 
41
41
 
42
42
 
43
- exports.SnapsBuiltInResolver = _chunkOKDY7C7Sjs.SnapsBuiltInResolver; exports.SnapsBundleWarningsPlugin = _chunkOKDY7C7Sjs.SnapsBundleWarningsPlugin; exports.SnapsStatsPlugin = _chunkOKDY7C7Sjs.SnapsStatsPlugin; exports.SnapsWatchPlugin = _chunkOKDY7C7Sjs.SnapsWatchPlugin; exports.getAllowedPaths = _chunkYGEAZQSCjs.getAllowedPaths; exports.getCompiler = _chunkR6NBQKVHjs.getCompiler; exports.getDefaultConfiguration = _chunkXUYXKO4Fjs.getDefaultConfiguration; exports.getServer = _chunkYGEAZQSCjs.getServer;
43
+ exports.SnapsBuiltInResolver = _chunkHNWSVD35js.SnapsBuiltInResolver; exports.SnapsBundleWarningsPlugin = _chunkHNWSVD35js.SnapsBundleWarningsPlugin; exports.SnapsStatsPlugin = _chunkHNWSVD35js.SnapsStatsPlugin; exports.SnapsWatchPlugin = _chunkHNWSVD35js.SnapsWatchPlugin; exports.getAllowedPaths = _chunkYGEAZQSCjs.getAllowedPaths; exports.getCompiler = _chunkZOC4OHGMjs.getCompiler; exports.getDefaultConfiguration = _chunkBFX2RH3Mjs.getDefaultConfiguration; exports.getServer = _chunkYGEAZQSCjs.getServer;
44
44
  //# sourceMappingURL=index.js.map
@@ -1,16 +1,16 @@
1
1
  import "../chunk-45LOTCC4.mjs";
2
2
  import {
3
3
  getCompiler
4
- } from "../chunk-WO7DMSQU.mjs";
4
+ } from "../chunk-WUC7DUXN.mjs";
5
5
  import {
6
6
  getDefaultConfiguration
7
- } from "../chunk-YWCNJELN.mjs";
7
+ } from "../chunk-VIQIUSXW.mjs";
8
8
  import {
9
9
  SnapsBuiltInResolver,
10
10
  SnapsBundleWarningsPlugin,
11
11
  SnapsStatsPlugin,
12
12
  SnapsWatchPlugin
13
- } from "../chunk-5KQNAW4C.mjs";
13
+ } from "../chunk-JBSWMUCQ.mjs";
14
14
  import "../chunk-BYNQODL3.mjs";
15
15
  import "../chunk-K26BOY6Z.mjs";
16
16
  import "../chunk-3WWFQLH4.mjs";
@@ -18,7 +18,7 @@ import {
18
18
  getAllowedPaths,
19
19
  getServer
20
20
  } from "../chunk-SYRWT2KT.mjs";
21
- import "../chunk-26C34AS7.mjs";
21
+ import "../chunk-OGGTU5W6.mjs";
22
22
  import "../chunk-AZMQTZXZ.mjs";
23
23
  import "../chunk-ERSRIVYH.mjs";
24
24
  import "../chunk-JL3URCHO.mjs";
@@ -1,6 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkMDHJ5HLMjs = require('../../chunk-MDHJ5HLM.js');
3
+ var _chunkJEMJNDZOjs = require('../../chunk-JEMJNDZO.js');
4
4
  require('../../chunk-QHCKVO3P.js');
5
5
  require('../../chunk-YQ2E7NEA.js');
6
6
  require('../../chunk-4QUVE3EK.js');
@@ -15,5 +15,5 @@ require('../../chunk-BALQOCUO.js');
15
15
  require('../../chunk-X3D3MHWF.js');
16
16
 
17
17
 
18
- exports.default = _chunkMDHJ5HLMjs.browserify_default;
18
+ exports.default = _chunkJEMJNDZOjs.browserify_default;
19
19
  //# sourceMappingURL=browserify.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  browserify_default
3
- } from "../../chunk-26C34AS7.mjs";
3
+ } from "../../chunk-OGGTU5W6.mjs";
4
4
  import "../../chunk-AZMQTZXZ.mjs";
5
5
  import "../../chunk-ERSRIVYH.mjs";
6
6
  import "../../chunk-JL3URCHO.mjs";
@@ -1,6 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkMDHJ5HLMjs = require('../../chunk-MDHJ5HLM.js');
3
+ var _chunkJEMJNDZOjs = require('../../chunk-JEMJNDZO.js');
4
4
 
5
5
 
6
6
  var _chunkQHCKVO3Pjs = require('../../chunk-QHCKVO3P.js');
@@ -21,5 +21,5 @@ require('../../chunk-X3D3MHWF.js');
21
21
 
22
22
 
23
23
 
24
- exports.browserify = _chunkMDHJ5HLMjs.browserify_default; exports.getFunctionLoader = _chunkQHCKVO3Pjs.getFunctionLoader; exports.wasm = _chunkYQ2E7NEAjs.wasm_default;
24
+ exports.browserify = _chunkJEMJNDZOjs.browserify_default; exports.getFunctionLoader = _chunkQHCKVO3Pjs.getFunctionLoader; exports.wasm = _chunkYQ2E7NEAjs.wasm_default;
25
25
  //# sourceMappingURL=index.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  browserify_default
3
- } from "../../chunk-26C34AS7.mjs";
3
+ } from "../../chunk-OGGTU5W6.mjs";
4
4
  import {
5
5
  getFunctionLoader
6
6
  } from "../../chunk-AZMQTZXZ.mjs";
@@ -3,11 +3,11 @@
3
3
 
4
4
 
5
5
 
6
- var _chunkOKDY7C7Sjs = require('../chunk-OKDY7C7S.js');
6
+ var _chunkHNWSVD35js = require('../chunk-HNWSVD35.js');
7
7
  require('../chunk-6EEZHGF5.js');
8
8
  require('../chunk-KLOPX6DO.js');
9
9
  require('../chunk-MUYXNION.js');
10
- require('../chunk-MDHJ5HLM.js');
10
+ require('../chunk-JEMJNDZO.js');
11
11
  require('../chunk-QHCKVO3P.js');
12
12
  require('../chunk-YQ2E7NEA.js');
13
13
  require('../chunk-4QUVE3EK.js');
@@ -25,5 +25,5 @@ require('../chunk-X3D3MHWF.js');
25
25
 
26
26
 
27
27
 
28
- exports.SnapsBuiltInResolver = _chunkOKDY7C7Sjs.SnapsBuiltInResolver; exports.SnapsBundleWarningsPlugin = _chunkOKDY7C7Sjs.SnapsBundleWarningsPlugin; exports.SnapsStatsPlugin = _chunkOKDY7C7Sjs.SnapsStatsPlugin; exports.SnapsWatchPlugin = _chunkOKDY7C7Sjs.SnapsWatchPlugin;
28
+ exports.SnapsBuiltInResolver = _chunkHNWSVD35js.SnapsBuiltInResolver; exports.SnapsBundleWarningsPlugin = _chunkHNWSVD35js.SnapsBundleWarningsPlugin; exports.SnapsStatsPlugin = _chunkHNWSVD35js.SnapsStatsPlugin; exports.SnapsWatchPlugin = _chunkHNWSVD35js.SnapsWatchPlugin;
29
29
  //# sourceMappingURL=plugins.js.map
@@ -3,11 +3,11 @@ import {
3
3
  SnapsBundleWarningsPlugin,
4
4
  SnapsStatsPlugin,
5
5
  SnapsWatchPlugin
6
- } from "../chunk-5KQNAW4C.mjs";
6
+ } from "../chunk-JBSWMUCQ.mjs";
7
7
  import "../chunk-BYNQODL3.mjs";
8
8
  import "../chunk-K26BOY6Z.mjs";
9
9
  import "../chunk-3WWFQLH4.mjs";
10
- import "../chunk-26C34AS7.mjs";
10
+ import "../chunk-OGGTU5W6.mjs";
11
11
  import "../chunk-AZMQTZXZ.mjs";
12
12
  import "../chunk-ERSRIVYH.mjs";
13
13
  import "../chunk-JL3URCHO.mjs";
@@ -9,7 +9,8 @@
9
9
 
10
10
 
11
11
 
12
- var _chunkMDHJ5HLMjs = require('../chunk-MDHJ5HLM.js');
12
+
13
+ var _chunkJEMJNDZOjs = require('../chunk-JEMJNDZO.js');
13
14
  require('../chunk-QHCKVO3P.js');
14
15
  require('../chunk-YQ2E7NEA.js');
15
16
  require('../chunk-4QUVE3EK.js');
@@ -33,5 +34,6 @@ require('../chunk-X3D3MHWF.js');
33
34
 
34
35
 
35
36
 
36
- exports.BROWSERSLIST_FILE = _chunkMDHJ5HLMjs.BROWSERSLIST_FILE; exports.WEBPACK_FALLBACKS = _chunkMDHJ5HLMjs.WEBPACK_FALLBACKS; exports.formatText = _chunkMDHJ5HLMjs.formatText; exports.getBrowserslistTargets = _chunkMDHJ5HLMjs.getBrowserslistTargets; exports.getDefaultLoader = _chunkMDHJ5HLMjs.getDefaultLoader; exports.getDevTool = _chunkMDHJ5HLMjs.getDevTool; exports.getEnvironmentVariables = _chunkMDHJ5HLMjs.getEnvironmentVariables; exports.getFallbacks = _chunkMDHJ5HLMjs.getFallbacks; exports.getProgressHandler = _chunkMDHJ5HLMjs.getProgressHandler; exports.pluralize = _chunkMDHJ5HLMjs.pluralize;
37
+
38
+ exports.BROWSERSLIST_FILE = _chunkJEMJNDZOjs.BROWSERSLIST_FILE; exports.WEBPACK_FALLBACKS = _chunkJEMJNDZOjs.WEBPACK_FALLBACKS; exports.formatText = _chunkJEMJNDZOjs.formatText; exports.getBrowserslistTargets = _chunkJEMJNDZOjs.getBrowserslistTargets; exports.getDefaultLoader = _chunkJEMJNDZOjs.getDefaultLoader; exports.getDevTool = _chunkJEMJNDZOjs.getDevTool; exports.getEnvironmentVariables = _chunkJEMJNDZOjs.getEnvironmentVariables; exports.getFallbacks = _chunkJEMJNDZOjs.getFallbacks; exports.getImageSVG = _chunkJEMJNDZOjs.getImageSVG; exports.getProgressHandler = _chunkJEMJNDZOjs.getProgressHandler; exports.pluralize = _chunkJEMJNDZOjs.pluralize;
37
39
  //# sourceMappingURL=utils.js.map
@@ -7,9 +7,10 @@ import {
7
7
  getDevTool,
8
8
  getEnvironmentVariables,
9
9
  getFallbacks,
10
+ getImageSVG,
10
11
  getProgressHandler,
11
12
  pluralize
12
- } from "../chunk-26C34AS7.mjs";
13
+ } from "../chunk-OGGTU5W6.mjs";
13
14
  import "../chunk-AZMQTZXZ.mjs";
14
15
  import "../chunk-ERSRIVYH.mjs";
15
16
  import "../chunk-JL3URCHO.mjs";
@@ -31,6 +32,7 @@ export {
31
32
  getDevTool,
32
33
  getEnvironmentVariables,
33
34
  getFallbacks,
35
+ getImageSVG,
34
36
  getProgressHandler,
35
37
  pluralize
36
38
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/snaps-cli",
3
- "version": "6.0.2",
3
+ "version": "6.1.0",
4
4
  "description": "A CLI for developing MetaMask Snaps.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -57,8 +57,8 @@
57
57
  "@babel/plugin-transform-runtime": "^7.13.2",
58
58
  "@babel/preset-env": "^7.23.2",
59
59
  "@babel/preset-typescript": "^7.23.2",
60
- "@metamask/snaps-sdk": "^3.0.1",
61
- "@metamask/snaps-utils": "^7.0.1",
60
+ "@metamask/snaps-sdk": "^3.2.0",
61
+ "@metamask/snaps-utils": "^7.0.4",
62
62
  "@metamask/snaps-webpack-plugin": "^4.0.1",
63
63
  "@metamask/utils": "^8.3.0",
64
64
  "@swc/core": "1.3.78",
@@ -100,7 +100,7 @@
100
100
  "yargs": "^17.7.1"
101
101
  },
102
102
  "devDependencies": {
103
- "@lavamoat/allow-scripts": "^3.0.2",
103
+ "@lavamoat/allow-scripts": "^3.0.3",
104
104
  "@metamask/auto-changelog": "^3.4.4",
105
105
  "@metamask/eslint-config": "^12.1.0",
106
106
  "@metamask/eslint-config-jest": "^12.1.0",
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/webpack/utils.ts","../src/webpack/loaders/browserify.ts"],"sourcesContent":["import { dim } from 'chalk';\nimport { promises as fs } from 'fs';\nimport { builtinModules } from 'module';\nimport type { Ora } from 'ora';\nimport { dirname, resolve } from 'path';\nimport stripAnsi from 'strip-ansi';\nimport type { Configuration } from 'webpack';\n\nimport type { ProcessedWebpackConfig } from '../config';\nimport { browserify, getFunctionLoader } from './loaders';\n\nexport const BROWSERSLIST_FILE = resolve(\n dirname(\n // eslint-disable-next-line n/no-extraneous-require\n require.resolve('@metamask/snaps-cli/package.json'),\n ),\n '.browserslistrc',\n);\n\nexport const WEBPACK_FALLBACKS = {\n assert: require.resolve('assert/'),\n buffer: require.resolve('buffer/'),\n console: require.resolve('console-browserify'),\n constants: require.resolve('constants-browserify'),\n crypto: require.resolve('crypto-browserify'),\n domain: require.resolve('domain-browser'),\n events: require.resolve('events/'),\n http: require.resolve('stream-http'),\n https: require.resolve('https-browserify'),\n os: require.resolve('os-browserify/browser'),\n path: require.resolve('path-browserify'),\n punycode: require.resolve('punycode/'),\n process: require.resolve('process/browser'),\n querystring: require.resolve('querystring-es3'),\n stream: require.resolve('stream-browserify'),\n /* eslint-disable @typescript-eslint/naming-convention */\n _stream_duplex: require.resolve('readable-stream/lib/_stream_duplex'),\n _stream_passthrough: require.resolve(\n 'readable-stream/lib/_stream_passthrough',\n ),\n _stream_readable: require.resolve('readable-stream/lib/_stream_readable'),\n _stream_transform: require.resolve('readable-stream/lib/_stream_transform'),\n _stream_writable: require.resolve('readable-stream/lib/_stream_writable'),\n string_decoder: require.resolve('string_decoder/'),\n /* eslint-enable @typescript-eslint/naming-convention */\n sys: require.resolve('util/'),\n timers: require.resolve('timers-browserify'),\n tty: require.resolve('tty-browserify'),\n url: require.resolve('url/'),\n util: require.resolve('util/'),\n vm: require.resolve('vm-browserify'),\n zlib: require.resolve('browserify-zlib'),\n};\n\n/**\n * Get the default loader for JavaScript and TypeScript files, based on the\n * config object.\n *\n * - If the `legacy` option is set, we use the custom `browserify` loader. This\n * uses the legacy Browserify config to transpile the code.\n * - Otherwise, we use the `swc-loader`. This is a Webpack loader that uses the\n * `SWC` compiler, which is a much faster alternative to Babel and TypeScript's\n * own compiler.\n *\n * @param config - The processed snap Webpack config.\n * @param config.legacy - The legacy config object, if any.\n * @param config.sourceMap - Whether to generate source maps.\n * @see https://swc.rs/docs/usage/swc-loader\n * @returns The default loader.\n */\nexport async function getDefaultLoader({\n legacy,\n sourceMap,\n}: ProcessedWebpackConfig) {\n if (legacy) {\n /**\n * If the snap uses the legacy config, we use the custom `browserify`\n * loader. This uses the legacy Browserify config to transpile the code.\n * This is necessary for backwards compatibility with the\n * `bundlerCustomizer` function.\n */\n return getFunctionLoader(browserify, legacy);\n }\n\n const targets = await getBrowserslistTargets();\n return {\n /**\n * We use the `swc-loader` to transpile TypeScript and JavaScript files.\n * This is a Webpack loader that uses the `SWC` compiler, which is a much\n * faster alternative to Babel and TypeScript's own compiler.\n */\n loader: require.resolve('swc-loader'),\n\n /**\n * The options for the `swc-loader`. These can be overridden in the\n * `.swcrc` file.\n *\n * @see https://swc.rs/docs/configuration/swcrc\n */\n options: {\n sync: false,\n\n /**\n * This tells SWC to generate source maps. We set it to the\n * `sourceMap` value from the config object.\n *\n * This must be enabled if source maps are enabled in the config.\n */\n sourceMaps: Boolean(getDevTool(sourceMap)),\n\n jsc: {\n parser: {\n /**\n * This tells the parser to parse TypeScript files. If you\n * don't need to support TypeScript, you can set this to\n * `ecmascript` instead, but there's no harm in leaving it\n * as `typescript`.\n *\n * @see https://swc.rs/docs/configuration/compilation#jscparser\n */\n syntax: 'typescript',\n },\n },\n\n /**\n * The module configuration. This tells SWC how to output the\n * transpiled code.\n *\n * @see https://swc.rs/docs/configuration/modules\n */\n module: {\n /**\n * This tells SWC to output ES6 modules. This will allow Webpack to\n * optimize the output code better. Snaps don't support ES6 however, so\n * the output code will be transpiled to CommonJS by Webpack later in\n * the build process.\n *\n * @see https://swc.rs/docs/configuration/modules#es6\n */\n type: 'es6',\n },\n\n env: {\n targets: targets.join(', '),\n },\n },\n };\n}\n\n/**\n * Get the Webpack devtool configuration based on the given snap config.\n *\n * - If `sourceMap` is `inline`, return `inline-source-map`.\n * - If `sourceMap` is `true`, return `source-map`.\n * - Otherwise, return `false`.\n *\n * @param sourceMap - The `sourceMap` value from the snap config.\n * @returns The Webpack devtool configuration.\n */\nexport function getDevTool(\n sourceMap: ProcessedWebpackConfig['sourceMap'],\n): Configuration['devtool'] {\n if (sourceMap === 'inline') {\n return 'inline-source-map';\n }\n\n if (sourceMap === true) {\n return 'source-map';\n }\n\n return false;\n}\n\n/**\n * Get a function that can be used as handler function for Webpack's\n * `ProgressPlugin`.\n *\n * @param spinner - The spinner to update.\n * @param spinnerText - The initial spinner text. This will be prepended to the\n * percentage.\n * @returns A function that can be used as handler function for Webpack's\n * `ProgressPlugin`.\n */\n// Note: This is extracted for testing purposes.\nexport function getProgressHandler(spinner?: Ora, spinnerText?: string) {\n return (percentage: number) => {\n if (spinner && spinnerText) {\n spinner.text = `${spinnerText} ${dim(\n `(${Math.round(percentage * 100)}%)`,\n )}`;\n }\n };\n}\n\n/**\n * Get the targets from the `.browserslistrc` file.\n *\n * @returns The browser targets as an array of strings.\n */\nexport async function getBrowserslistTargets() {\n const contents = await fs.readFile(BROWSERSLIST_FILE, 'utf8');\n return contents\n .split('\\n')\n .map((line) => line.trim())\n .filter((line) => line && !line.startsWith('#'));\n}\n\n/**\n * Get a singular or plural string based on the given count. This is useful for\n * generating messages like \"1 error\" or \"2 errors\". By default, the plural\n * string is the singular string with an \"s\" appended to it.\n *\n * This assumes that the text is in English, and likely won't work for some\n * other languages.\n *\n * @param count - The count.\n * @param singular - The singular string.\n * @param plural - The plural string.\n * @returns The singular or plural string.\n * @example\n * ```typescript\n * pluralize(1, 'error'); // => 'error'\n * pluralize(2, 'error'); // => 'errors'\n * pluralize(1, 'error', 'problem'); // => 'error'\n * pluralize(2, 'error', 'problems'); // => 'problems'\n * ```\n */\nexport function pluralize(\n count: number,\n singular: string,\n plural = `${singular}s`,\n) {\n return count === 1 ? singular : plural;\n}\n\n/**\n * Get an object that can be used as fallback config for Webpack's\n * `fallback` config.\n *\n * @param polyfills - The polyfill object from the snap config.\n * @returns The webpack fallback config.\n */\nexport function getFallbacks(polyfills: ProcessedWebpackConfig['polyfills']): {\n [index: string]: string | false;\n} {\n if (polyfills === true) {\n return Object.fromEntries(\n builtinModules.map((name) => [\n name,\n WEBPACK_FALLBACKS[name as keyof typeof WEBPACK_FALLBACKS] ?? false,\n ]),\n );\n }\n\n if (polyfills === false) {\n return Object.fromEntries(builtinModules.map((name) => [name, false]));\n }\n\n return Object.fromEntries(\n builtinModules.map((name) => [\n name,\n polyfills[name as keyof ProcessedWebpackConfig['polyfills']]\n ? WEBPACK_FALLBACKS[name as keyof typeof WEBPACK_FALLBACKS]\n : false,\n ]),\n );\n}\n\n/**\n * Get an object that can be used as environment variables for Webpack's\n * `DefinePlugin`.\n *\n * @param environment - The environment object from the Snap config.\n * @param defaults - The default environment variables.\n * @returns The Webpack environment variables.\n */\nexport function getEnvironmentVariables(\n environment: Record<string, unknown>,\n defaults = {\n NODE_DEBUG: 'false',\n NODE_ENV: 'production',\n DEBUG: 'false',\n },\n) {\n return Object.fromEntries(\n Object.entries({\n ...defaults,\n ...environment,\n }).map(([key, value]) => [`process.env.${key}`, JSON.stringify(value)]),\n );\n}\n\n/**\n * Format the given line to fit within the terminal width.\n *\n * @param line - The line to format.\n * @param indent - The indentation to use.\n * @param initialIndent - The initial indentation to use, i.e., the indentation\n * for the first line.\n * @returns The formatted line.\n */\nfunction formatLine(line: string, indent: number, initialIndent: number) {\n const terminalWidth = process.stdout.columns;\n if (!terminalWidth) {\n return `${' '.repeat(initialIndent)}${line}`;\n }\n\n return line.split(' ').reduce(\n ({ formattedText, currentLineLength }, word, index) => {\n // `chalk` adds ANSI escape codes to the text, which are not visible\n // characters. We need to strip them to get the visible length of the\n // text.\n const visibleWord = stripAnsi(word);\n\n // Determine if a space should be added before the word.\n const spaceBeforeWord = index > 0 ? ' ' : '';\n const wordLengthWithSpace = visibleWord.length + spaceBeforeWord.length;\n\n // If the word would exceed the terminal width, start a new line.\n if (currentLineLength + wordLengthWithSpace > terminalWidth) {\n return {\n formattedText: `${formattedText}\\n${' '.repeat(indent)}${word}`,\n currentLineLength: indent + visibleWord.length,\n };\n }\n\n // Otherwise, add the word to the current line.\n return {\n formattedText: formattedText + spaceBeforeWord + word,\n currentLineLength: currentLineLength + wordLengthWithSpace,\n };\n },\n {\n formattedText: ' '.repeat(initialIndent),\n currentLineLength: initialIndent,\n },\n ).formattedText;\n}\n\n/**\n * Format the given text to fit within the terminal width.\n *\n * @param text - The text to format.\n * @param indent - The indentation to use.\n * @param initialIndent - The initial indentation to use, i.e., the indentation\n * for the first line.\n * @returns The formatted text.\n */\nexport function formatText(\n text: string,\n indent: number,\n initialIndent = indent,\n) {\n const lines = text.split('\\n');\n\n // Apply formatting to each line separately and then join them.\n return lines\n .map((line, index) => {\n const lineIndent = index === 0 ? initialIndent : indent;\n return formatLine(line, indent, lineIndent);\n })\n .join('\\n');\n}\n","import browserify from 'browserify';\nimport { Readable } from 'readable-stream';\nimport type { LoaderDefinitionFunction } from 'webpack';\n\nimport { TranspilationModes } from '../../builders';\nimport type { LegacyOptions } from '../../config';\nimport { processDependencies } from '../../utils';\nimport { getBrowserslistTargets } from '../utils';\n\n/**\n * A Browserify loader for Webpack. This exists for backwards compatibility with\n * the legacy configuration format, in order to support the `bundlerCustomizer`\n * function.\n *\n * When this loader is used, the input file will be processed by Browserify, and\n * written to disk by Webpack. Most processing will be handled by Browserify, so\n * there are no benefits like tree-shaking.\n *\n * @param content - The input file contents as a string.\n * @param sourceMap - The source map of the input file.\n */\nconst loader: LoaderDefinitionFunction<LegacyOptions> = async function (\n content,\n sourceMap,\n) {\n const config = this.getOptions();\n\n const { transpilationMode } = config;\n\n const bundler = browserify({\n extensions: ['.js', '.ts'],\n debug: Boolean(sourceMap),\n standalone: '<snap>',\n });\n\n if (transpilationMode !== TranspilationModes.None) {\n const babelifyOptions = processDependencies(config);\n\n // We need to statically import all Browserify transforms, and all Babel\n // presets and plugins, and calling `require` is the sanest way to do that.\n /* eslint-disable @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires, n/global-require */\n 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: await getBrowserslistTargets(),\n },\n },\n ],\n ],\n plugins: [\n require('@babel/plugin-transform-runtime'),\n require('@babel/plugin-transform-class-properties'),\n require('@babel/plugin-transform-private-methods'),\n require('@babel/plugin-transform-class-static-block'),\n require('@babel/plugin-transform-private-property-in-object'),\n ],\n ...(babelifyOptions as any),\n });\n /* eslint-enable @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires, n/global-require */\n }\n\n config.bundlerCustomizer?.(bundler);\n\n // Browserify doesn't accept a string as an entry point, so we need to convert\n // it to a stream.\n const stream = new Readable();\n stream.push(content);\n stream.push(null);\n\n bundler.add(stream, {\n file: this.resourcePath,\n });\n\n return new Promise<Buffer>((resolve, reject) => {\n bundler.bundle((bundleError, buffer: Buffer) => {\n if (bundleError) {\n reject(bundleError);\n return;\n }\n\n // Browserify inlines the source map, so we just pass the output buffer back\n // to Webpack.\n resolve(buffer);\n });\n });\n};\n\nexport default loader;\n"],"mappings":";;;;;;;;;;;AAAA,SAAS,WAAW;AACpB,SAAS,YAAY,UAAU;AAC/B,SAAS,sBAAsB;AAE/B,SAAS,SAAS,eAAe;AACjC,OAAO,eAAe;;;ACLtB,OAAO,gBAAgB;AACvB,SAAS,gBAAgB;AAoBzB,IAAM,SAAkD,eACtD,SACA,WACA;AACA,QAAM,SAAS,KAAK,WAAW;AAE/B,QAAM,EAAE,kBAAkB,IAAI;AAE9B,QAAM,UAAU,WAAW;AAAA,IACzB,YAAY,CAAC,OAAO,KAAK;AAAA,IACzB,OAAO,QAAQ,SAAS;AAAA,IACxB,YAAY;AAAA,EACd,CAAC;AAED,MAAI,yCAA+C;AACjD,UAAM,kBAAkB,oBAAoB,MAAM;AAKlD,YAAQ,UAAU,UAAQ,UAAU,GAAG;AAAA,MACrC,QAAQ;AAAA,MACR,YAAY,CAAC,OAAO,KAAK;AAAA,MACzB,SAAS;AAAA,QACP,UAAQ,0BAA0B;AAAA,QAClC;AAAA,UACE,UAAQ,mBAAmB;AAA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AAA,QACH,CAAC,GAAG,GAAG,KAAK,GAAG;AAAA,MACjB;AAAA,IACF;AAEA,WAAO;AAAA,EACT,GAAG,OAAO,UAAU;AAEpB,SAAO;AAAA,IACL,GAAG;AAAA,IACH;AAAA,EACF;AACF;AASO,SAAS,iBACd,cACwB;AACxB,QAAM,gBAAgB;AAAA,IACpB,EAAE,SAAS,UAAU;AAAA,IACrB;AAAA,EACF;AAMA,QAAM,OAAO,aAAa,WAAW,SACjC,QAAQ,aAAa,WAAW,MAAM,IACtC,aAAa,WAAW;AAE5B,QAAM,WAAW,aAAa,WAAW,SACrC,SAAS,aAAa,WAAW,MAAM,IACvC,aAAa,WAAW;AAE5B,SAAO;AAAA,IACL,GAAG;AAAA,IACH,OAAO,aAAa,WAAW;AAAA,IAC/B,UAAU,aAAa,WAAW;AAAA,IAClC,WAAW,aAAa,WAAW;AAAA,IACnC,QAAQ;AAAA,MACN;AAAA,MACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAOA,UAAU,aAAa,WAAW;AAAA;AAAA;AAAA,MAIlC,OAAO;AAAA,IACT;AAAA,IACA,UAAU;AAAA;AAAA;AAAA,MAGR,MAAM,QAAQ,QAAQ,IAAI,GAAG,oBAAoB;AAAA,MACjD,QAAQ,aAAa,WAAW;AAAA,IAClC;AAAA,IACA,QAAQ;AAAA,MACN,SAAS,aAAa,WAAW;AAAA,MACjC,MAAM,aAAa,WAAW;AAAA,MAC9B,MAAM,aAAa,WAAW;AAAA,IAChC;AAAA,IACA,OAAO;AAAA,MACL,SAAS;AAAA;AAAA;AAAA,MAIT,UAAU;AAAA,MACV,QAAQ;AAAA,IACV;AAAA,IACA,QAAQ;AAAA,MACN;AAAA,QACE,GAAG,aAAa;AAAA,QAChB,mBAAmB,aAAa;AAAA,MAClC;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF","sourcesContent":["import { literal, union } from '@metamask/snaps-sdk';\nimport {\n createFromStruct,\n indent,\n isFile,\n SnapsStructError,\n named,\n} from '@metamask/snaps-utils/node';\nimport { hasProperty } from '@metamask/utils';\nimport { transform } from '@swc/core';\nimport type { BrowserifyObject } from 'browserify';\nimport { dim } from 'chalk';\nimport { readFile } from 'fs/promises';\nimport Module from 'module';\nimport { basename, dirname, resolve } from 'path';\nimport type { Infer } from 'superstruct';\nimport {\n array,\n boolean,\n create,\n defaulted,\n define,\n func,\n number,\n object,\n optional,\n record,\n string,\n type,\n unknown,\n empty,\n} from 'superstruct';\nimport type { Configuration as WebpackConfiguration } from 'webpack';\n\nimport { TranspilationModes } from './builders';\nimport { ConfigError } from './errors';\nimport { file } from './structs';\nimport type { YargsArgs } from './types/yargs';\nimport { CONFIG_FILE, TS_CONFIG_FILE } from './utils';\n\nconst CONFIG_FILES = [CONFIG_FILE, TS_CONFIG_FILE];\n\n/**\n * The configuration for the Snaps CLI, stored as `snap.config.js` or\n * `snap.config.ts` in the root of the project.\n *\n * @deprecated The Browserify bundler is deprecated and will be removed in a\n * future release. Use the Webpack bundler instead.\n */\nexport type SnapBrowserifyConfig = {\n /**\n * The bundler to use to build the snap. For backwards compatibility, if not\n * specified, Browserify will be used. However, the Browserify bundler is\n * deprecated and will be removed in a future release, so it's recommended to\n * use the Webpack bundler instead.\n */\n bundler: 'browserify';\n\n /**\n * The options for the Snaps CLI. These are merged with the options passed to\n * the CLI, with the CLI options taking precedence.\n *\n * @deprecated The Browserify bundler is deprecated and will be removed in a\n * future release. Use the Webpack bundler instead.\n */\n cliOptions?: {\n /**\n * The path to the snap bundle file.\n *\n * @default 'dist/bundle.js'\n */\n bundle?: string;\n\n /**\n * The directory to output the snap to. This is only used if `bundle` is\n * not specified.\n *\n * @default 'dist'\n */\n dist?: string;\n\n /**\n * Whether to attempt to evaluate the snap in SES. This can catch some errors\n * that would otherwise only be caught at runtime.\n *\n * @default true\n */\n eval?: boolean;\n\n /**\n * Whether to validate the snap manifest.\n *\n * @default true\n */\n manifest?: boolean;\n\n /**\n * The name of the bundle file. This is only used if `bundle` is not\n * specified.\n *\n * @default 'bundle.js'\n */\n outfileName?: string;\n\n /**\n * The port to run the server on.\n *\n * @default 8081\n */\n port?: number;\n\n /**\n * The root directory to serve the snap from.\n *\n * @default `process.cwd()`\n */\n root?: string;\n\n /**\n * Whether to generate source maps for the snap bundle.\n *\n * @default false\n */\n sourceMaps?: boolean;\n\n /**\n * The path to the snap entry point.\n *\n * @default 'src/index.js'\n */\n src?: string;\n\n /**\n * Whether to remove comments from the bundle.\n *\n * @default true\n */\n stripComments?: boolean;\n\n /**\n * Whether to suppress warnings.\n *\n * @default false\n */\n suppressWarnings?: boolean;\n\n /**\n * The transpilation mode to use, which determines which files are\n * transpiled.\n *\n * - `'localAndDeps'`: Transpile the snap entry point and all dependencies.\n * - `'localOnly'`: Transpile only the snap entry point.\n * - `'none'`: Don't transpile any files.\n *\n * @default 'localOnly'\n */\n transpilationMode?: 'localAndDeps' | 'localOnly' | 'none';\n\n /**\n * The dependencies to transpile when `transpilationMode` is set to\n * `'localAndDeps'`. If not specified, all dependencies will be transpiled.\n */\n depsToTranspile?: string[];\n\n /**\n * Whether to show original errors.\n *\n * @default true\n */\n verboseErrors?: boolean;\n\n /**\n * Whether to write the updated manifest to disk.\n *\n * @default true\n */\n writeManifest?: boolean;\n\n /**\n * Whether to serve the snap locally.\n *\n * @default true\n */\n serve?: boolean;\n };\n\n /**\n * A function that can be used to customize the Browserify instance used to\n * build the snap.\n *\n * @param bundler - The Browserify instance.\n * @deprecated The Browserify bundler is deprecated and will be removed in a\n * future release. Use the Webpack bundler instead.\n */\n bundlerCustomizer?: (bundler: BrowserifyObject) => void;\n};\n\n/**\n * The configuration for the Snaps CLI, stored as `snap.config.js` or\n * `snap.config.ts` in the root of the project.\n */\nexport type SnapWebpackConfig = {\n /**\n * The bundler to use to build the snap. For backwards compatibility, if not\n * specified, Browserify will be used. However, the Browserify bundler is\n * deprecated and will be removed in a future release, so it's recommended to\n * use the Webpack bundler instead.\n */\n bundler?: 'webpack';\n\n /**\n * The path to the snap entry point. This should be a JavaScript or TypeScript\n * file.\n */\n input: string;\n\n /**\n * Whether to generate source maps for the snap. If `true`, source maps will\n * be generated as separate files. If `'inline'`, source maps will be\n * inlined in the generated JavaScript bundle.\n *\n * @default true\n */\n sourceMap?: boolean | 'inline';\n\n /**\n * Whether to attempt to evaluate the snap in SES. This can catch some errors\n * that would otherwise only be caught at runtime.\n *\n * @default true\n */\n evaluate?: boolean;\n\n output?: {\n /**\n * The path to the directory where the snap will be built. This directory\n * will be created if it doesn't exist.\n *\n * If the path is relative, it will be resolved relative to the current\n * working directory.\n *\n * @default 'dist'\n */\n path?: string;\n\n /**\n * The name of the JavaScript bundle file.\n *\n * @default 'bundle.js'\n */\n filename?: string;\n\n /**\n * Whether to clean the output directory before building the snap. If\n * `true`, the output directory will be deleted and recreated. Otherwise,\n * the output directory will be left as-is.\n *\n * @default false\n */\n clean?: boolean;\n\n /**\n * Whether to minimize the snap bundle. If `true`, the bundle will be\n * minified. Otherwise, the bundle will be left as-is.\n *\n * @default true\n */\n minimize?: boolean;\n };\n\n manifest?: {\n /**\n * The path to the snap manifest file. If the path is relative, it will be\n * resolved relative to the current working directory.\n *\n * @default 'snap.manifest.json'\n */\n path?: string;\n\n /**\n * Whether to automatically update the manifest. If `true`, the manifest\n * will be updated with the latest shasum of the snap bundle, and some\n * common fields will be updated if they are missing or incorrect. If\n * `false`, the manifest will be left as-is.\n *\n * @default true\n */\n update?: boolean;\n };\n\n server?: {\n /**\n * Whether to enable the local server. If `true`, the snap will be served\n * from a local server, when running the `watch` command. If `false`, the\n * snap will not be served.\n *\n * @default true\n */\n enabled?: boolean;\n\n /**\n * The root directory to serve the snap from. If the path is relative, it\n * will be resolved relative to the current working directory.\n *\n * @default `process.cwd()`\n */\n root?: string;\n\n /**\n * The port to run the server on.\n *\n * @default 8081\n */\n port?: number;\n };\n\n /**\n * The environment variables to set when building the snap. These will be\n * available in the snap as `process.env`. In addition to these environment\n * variables, the following environment variables will always be set:\n *\n * - `NODE_DEBUG`: `false`\n * - `NODE_ENV`: `'production'`\n * - `DEBUG`: `false`\n *\n * Any environment variables specified here will override these defaults. You\n * can also override any variables here by setting them in your shell when\n * running the CLI.\n */\n environment?: Record<string, unknown>;\n\n /**\n * Options that control the logging output of the CLI.\n */\n stats?: {\n /**\n * Whether to enable verbose logging.\n *\n * @default false\n */\n verbose?: boolean;\n\n /**\n * Whether to log warnings about unresolved built-in modules. If `false`,\n * warnings will not be logged.\n */\n builtIns?:\n | {\n /**\n * The built-in modules to ignore when resolving modules. If a module\n * is ignored, no warning will be logged if it is not resolved.\n */\n ignore?: string[];\n }\n | false;\n\n /**\n * Whether to log warnings about the use of the `Buffer` global. If `false`,\n * warnings will not be logged. If `true`, the CLI will warn if the `Buffer`\n * global is used, but not provided by Webpack's `DefinePlugin`.\n */\n buffer?: boolean;\n };\n\n /**\n * Whether to provide polyfills for node builtins. If `true`, all the available\n * polyfills will be provided. If `false` no polyfills will be provided. If a\n * configuration object is passed only the polyfills set to `true` will be provided.\n *\n * @default false\n * @example\n * ```ts\n * polyfills: true\n *\n * // or\n *\n * polyfills: {\n * assert: true,\n * buffer: true\n * }\n * ```\n */\n polyfills?:\n | boolean\n | {\n assert?: boolean;\n buffer?: boolean;\n console?: boolean;\n constants?: boolean;\n crypto?: boolean;\n domain?: boolean;\n events?: boolean;\n http?: boolean;\n https?: boolean;\n os?: boolean;\n path?: boolean;\n punycode?: boolean;\n process?: boolean;\n querystring?: boolean;\n stream?: boolean;\n /* eslint-disable @typescript-eslint/naming-convention */\n _stream_duplex?: boolean;\n _stream_passthrough?: boolean;\n _stream_readable?: boolean;\n _stream_transform?: boolean;\n _stream_writable?: boolean;\n string_decoder?: boolean;\n /* eslint-enable @typescript-eslint/naming-convention */\n sys?: boolean;\n timers?: boolean;\n tty?: boolean;\n url?: boolean;\n util?: boolean;\n vm?: boolean;\n zlib?: boolean;\n };\n\n /**\n * A function to customize the Webpack configuration used to build the snap.\n * This function will be called with the default Webpack configuration, and\n * should return the modified configuration. If not specified, the default\n * configuration will be used.\n *\n * It's recommended to use the `webpack-merge` package to merge the default\n * configuration with your customizations. The merge function is exported as\n * `merge` from the `@metamask/snaps-cli` package.\n *\n * @example\n * ```ts\n * import type { SnapsConfig } from '@metamask/snaps-cli';\n * import { merge } from '@metamask/snaps-cli';\n *\n * const config: SnapsConfig = {\n * bundler: 'webpack',\n * entry: 'src/index.ts',\n * customizeWebpackConfig: (config) => merge(config, {\n * module: {\n * rules: [\n * {\n * test: /\\.wasm$/,\n * type: 'assets/resource',\n * },\n * ],\n * },\n * }),\n * };\n *\n * export default config;\n * ```\n */\n customizeWebpackConfig?: (\n config: WebpackConfiguration,\n ) => WebpackConfiguration;\n\n /**\n * Experimental features that can be enabled. These features are not\n * guaranteed to be stable, and may be removed or changed in a future release.\n */\n experimental?: {\n /**\n * Whether to enable WebAssembly support. If `true`, the Webpack\n * configuration will be modified to support WebAssembly. If `false`, the\n * Webpack configuration will not be modified.\n *\n * @default false\n */\n wasm?: boolean;\n };\n};\n\n/**\n * The configuration for the Snaps CLI, stored as `snap.config.js` or\n * `snap.config.ts` in the root of the project.\n */\nexport type SnapConfig = SnapBrowserifyConfig | SnapWebpackConfig;\n\ntype SnapsBrowserifyBundlerCustomizerFunction = (\n bundler: BrowserifyObject,\n) => void;\n\n// This struct is essentially the same as the `func` struct, but it's defined\n// separately so that we include the function type in the inferred TypeScript\n// type definitions.\nconst SnapsBrowserifyBundlerCustomizerFunctionStruct =\n define<SnapsBrowserifyBundlerCustomizerFunction>(\n 'function',\n func().validator,\n );\n\nexport const SnapsBrowserifyConfigStruct = object({\n bundler: literal('browserify'),\n cliOptions: defaulted(\n object({\n bundle: optional(file()),\n dist: defaulted(file(), 'dist'),\n eval: defaulted(boolean(), true),\n manifest: defaulted(boolean(), true),\n port: defaulted(number(), 8081),\n outfileName: defaulted(string(), 'bundle.js'),\n root: defaulted(file(), process.cwd()),\n sourceMaps: defaulted(boolean(), false),\n src: defaulted(file(), 'src/index.js'),\n stripComments: defaulted(boolean(), true),\n suppressWarnings: defaulted(boolean(), false),\n transpilationMode: defaulted(\n union([literal('localAndDeps'), literal('localOnly'), literal('none')]),\n 'localOnly',\n ),\n depsToTranspile: defaulted(array(string()), []),\n verboseErrors: defaulted(boolean(), true),\n writeManifest: defaulted(boolean(), true),\n serve: defaulted(boolean(), true),\n }),\n {},\n ),\n bundlerCustomizer: optional(SnapsBrowserifyBundlerCustomizerFunctionStruct),\n});\n\ntype SnapsWebpackCustomizeWebpackConfigFunction = (\n config: WebpackConfiguration,\n) => WebpackConfiguration;\n\n// This struct is essentially the same as the `func` struct, but it's defined\n// separately so that we include the function type in the inferred TypeScript\n// type definitions.\nconst SnapsWebpackCustomizeWebpackConfigFunctionStruct =\n define<SnapsWebpackCustomizeWebpackConfigFunction>(\n 'function',\n func().validator,\n );\n\nexport const SnapsWebpackConfigStruct = object({\n bundler: defaulted(literal('webpack'), 'webpack'),\n input: defaulted(file(), resolve(process.cwd(), 'src/index.js')),\n sourceMap: defaulted(union([boolean(), literal('inline')]), false),\n evaluate: defaulted(boolean(), true),\n\n output: defaulted(\n object({\n path: defaulted(file(), resolve(process.cwd(), 'dist')),\n filename: defaulted(string(), 'bundle.js'),\n clean: defaulted(boolean(), false),\n minimize: defaulted(boolean(), true),\n }),\n {},\n ),\n\n manifest: defaulted(\n object({\n path: defaulted(file(), resolve(process.cwd(), 'snap.manifest.json')),\n update: defaulted(boolean(), true),\n }),\n {},\n ),\n\n server: defaulted(\n object({\n enabled: defaulted(boolean(), true),\n root: defaulted(file(), process.cwd()),\n port: defaulted(number(), 8081),\n }),\n {},\n ),\n\n environment: defaulted(record(string(), unknown()), {}),\n\n stats: defaulted(\n object({\n verbose: defaulted(boolean(), false),\n builtIns: defaulted(\n union([\n object({ ignore: defaulted(array(string()), []) }),\n literal(false),\n ]),\n {},\n ),\n buffer: defaulted(boolean(), true),\n }),\n {},\n ),\n\n polyfills: defaulted(\n union([\n boolean(),\n object({\n assert: defaulted(boolean(), false),\n buffer: defaulted(boolean(), false),\n console: defaulted(boolean(), false),\n constants: defaulted(boolean(), false),\n crypto: defaulted(boolean(), false),\n domain: defaulted(boolean(), false),\n events: defaulted(boolean(), false),\n http: defaulted(boolean(), false),\n https: defaulted(boolean(), false),\n os: defaulted(boolean(), false),\n path: defaulted(boolean(), false),\n punycode: defaulted(boolean(), false),\n process: defaulted(boolean(), false),\n querystring: defaulted(boolean(), false),\n stream: defaulted(boolean(), false),\n /* eslint-disable @typescript-eslint/naming-convention */\n _stream_duplex: defaulted(boolean(), false),\n _stream_passthrough: defaulted(boolean(), false),\n _stream_readable: defaulted(boolean(), false),\n _stream_transform: defaulted(boolean(), false),\n _stream_writable: defaulted(boolean(), false),\n string_decoder: defaulted(boolean(), false),\n /* eslint-enable @typescript-eslint/naming-convention */\n sys: defaulted(boolean(), false),\n timers: defaulted(boolean(), false),\n tty: defaulted(boolean(), false),\n url: defaulted(boolean(), false),\n util: defaulted(boolean(), false),\n vm: defaulted(boolean(), false),\n zlib: defaulted(boolean(), false),\n }),\n ]),\n false,\n ),\n\n customizeWebpackConfig: optional(\n SnapsWebpackCustomizeWebpackConfigFunctionStruct,\n ),\n\n experimental: defaulted(\n object({\n wasm: defaulted(boolean(), false),\n }),\n {},\n ),\n});\n\nexport const SnapsConfigStruct = type({\n bundler: defaulted(\n union([literal('browserify'), literal('webpack')]),\n 'webpack',\n ),\n});\n\nexport const LegacyOptionsStruct = union([\n named(\n 'object with `transpilationMode` set to `localAndDeps` and `depsToTranspile` set to an array of strings',\n type({\n depsToTranspile: array(string()),\n transpilationMode: literal(TranspilationModes.LocalAndDeps),\n writeManifest: boolean(),\n bundlerCustomizer: optional(\n SnapsBrowserifyBundlerCustomizerFunctionStruct,\n ),\n }),\n ),\n named(\n 'object without `depsToTranspile`',\n type({\n depsToTranspile: named('empty array', empty(array())),\n transpilationMode: union([\n literal(TranspilationModes.LocalOnly),\n literal(TranspilationModes.None),\n ]),\n writeManifest: boolean(),\n bundlerCustomizer: optional(\n SnapsBrowserifyBundlerCustomizerFunctionStruct,\n ),\n }),\n ),\n]);\n\nexport type LegacyOptions = Infer<typeof LegacyOptionsStruct>;\n\nexport type ProcessedBrowserifyConfig = Infer<\n typeof SnapsBrowserifyConfigStruct\n>;\n\nexport type ProcessedWebpackConfig = Infer<typeof SnapsWebpackConfigStruct> & {\n /**\n * The legacy Browserify config, if the bundler is Browserify. This is used\n * to support the legacy config format.\n */\n legacy?: LegacyOptions;\n};\n\nexport type ProcessedConfig = ProcessedWebpackConfig;\n\n/**\n * Get a validated snap config. This validates the config and adds default\n * values for any missing properties.\n *\n * @param config - The config to validate.\n * @param argv - The CLI arguments.\n * @returns The validated config.\n */\nexport function getConfig(config: unknown, argv: YargsArgs): ProcessedConfig {\n const prefix = 'The snap config file is invalid';\n const suffix = dim(\n // TODO: Link to `docs.metamask.io` once the docs are published.\n 'Refer to the documentation for more information: https://github.com/MetaMask/snaps/tree/main/packages/snaps-cli/',\n );\n\n const { bundler } = createFromStruct(\n config,\n SnapsConfigStruct,\n prefix,\n suffix,\n );\n\n if (bundler === 'browserify') {\n const legacyConfig = createFromStruct(\n config,\n SnapsBrowserifyConfigStruct,\n prefix,\n suffix,\n );\n\n return getWebpackConfig(mergeLegacyOptions(argv, legacyConfig));\n }\n\n return createFromStruct(config, SnapsWebpackConfigStruct, prefix, suffix);\n}\n\n/**\n * Load a snap config from a file. This supports both JavaScript and TypeScript\n * config files, in the CommonJS module format and the ES module format.\n *\n * This assumes that the config file exports a default object, either through\n * `module.exports` or `export default`.\n *\n * @param path - The full path to the config file.\n * @param argv - The CLI arguments.\n * @returns The validated config.\n * @throws If the config file is invalid, or if the config file does not have a\n * default export.\n */\nexport async function loadConfig(path: string, argv: YargsArgs) {\n try {\n const contents = await readFile(path, 'utf8');\n const source = await transform(contents, {\n swcrc: false,\n jsc: {\n parser: {\n syntax: 'typescript',\n },\n },\n module: {\n type: 'commonjs',\n },\n });\n\n const config = new Module(path);\n\n // @ts-expect-error - This function is not typed.\n config.paths = Module._nodeModulePaths(dirname(path));\n\n // @ts-expect-error - This function is not typed.\n config._compile(source.code, path);\n\n if (!hasProperty(config.exports, 'default')) {\n return getConfig(config.exports, argv);\n }\n\n return getConfig(config.exports.default, argv);\n } catch (error) {\n if (error instanceof SnapsStructError) {\n throw new ConfigError(error.message);\n }\n\n throw new ConfigError(\n `Unable to load snap config file at \"${path}\".\\n\\n${indent(\n error.message,\n )}`,\n );\n }\n}\n\n/**\n * Resolve a snap config. This function will look for a `snap.config.js` or\n * `snap.config.ts` file in the current or specified directory.\n *\n * @param path - The path to resolve the snap config from. Defaults to the\n * current working directory.\n * @param argv - The CLI arguments.\n * @returns The resolved and validated snap config.\n * @throws If a snap config could not be found.\n */\nexport async function resolveConfig(path: string, argv: YargsArgs) {\n for (const configFile of CONFIG_FILES) {\n const filePath = resolve(path, configFile);\n if (await isFile(filePath)) {\n return await loadConfig(filePath, argv);\n }\n }\n\n throw new ConfigError(\n `Could not find a \"snap.config.js\" or \"snap.config.ts\" file in the current or specified directory (\"${path}\").`,\n );\n}\n\n/**\n * Get a snap config from the CLI arguments. This will either load the config\n * from the specified config file, or resolve the config from the current\n * working directory.\n *\n * @param argv - The CLI arguments.\n * @param cwd - The current working directory. Defaults to `process.cwd()`.\n * @returns The resolved and validated snap config.\n */\nexport async function getConfigByArgv(\n argv: YargsArgs,\n cwd: string = process.cwd(),\n) {\n if (argv.config) {\n if (!(await isFile(argv.config))) {\n throw new ConfigError(\n `Could not find a config file at \"${argv.config}\". Make sure that the path is correct.`,\n );\n }\n\n return await loadConfig(argv.config, argv);\n }\n\n return await resolveConfig(cwd, argv);\n}\n\n/**\n * Merge legacy CLI options into the config. This is used to support the legacy\n * config format, where options can be specified both in the config file and\n * through CLI flags.\n *\n * @param argv - The CLI arguments.\n * @param config - The config to merge the CLI options into.\n * @returns The config with the CLI options merged in.\n * @deprecated This function is only used to support the legacy config format.\n */\nexport function mergeLegacyOptions(\n argv: YargsArgs,\n config: ProcessedBrowserifyConfig,\n) {\n const cliOptions = Object.keys(config.cliOptions).reduce<\n ProcessedBrowserifyConfig['cliOptions']\n >((accumulator, key) => {\n if (argv[key] !== undefined) {\n return {\n ...accumulator,\n [key]: argv[key],\n };\n }\n\n return accumulator;\n }, config.cliOptions);\n\n return {\n ...config,\n cliOptions,\n };\n}\n\n/**\n * Get a Webpack config from a legacy browserify config. This is used to\n * support the legacy config format, and convert it to the new format.\n *\n * @param legacyConfig - The legacy browserify config.\n * @returns The Webpack config.\n */\nexport function getWebpackConfig(\n legacyConfig: ProcessedBrowserifyConfig,\n): ProcessedWebpackConfig {\n const defaultConfig = create(\n { bundler: 'webpack' },\n SnapsWebpackConfigStruct,\n );\n\n // The legacy config has two options for specifying the output path and\n // filename: `bundle`, and `dist` + `outfileName`. If `bundle` is specified,\n // we use that as the output path and filename. Otherwise, we use `dist` and\n // `outfileName`.\n const path = legacyConfig.cliOptions.bundle\n ? dirname(legacyConfig.cliOptions.bundle)\n : legacyConfig.cliOptions.dist;\n\n const filename = legacyConfig.cliOptions.bundle\n ? basename(legacyConfig.cliOptions.bundle)\n : legacyConfig.cliOptions.outfileName;\n\n return {\n ...defaultConfig,\n input: legacyConfig.cliOptions.src,\n evaluate: legacyConfig.cliOptions.eval,\n sourceMap: legacyConfig.cliOptions.sourceMaps,\n output: {\n path,\n filename,\n\n // The legacy config has an option to remove comments from the bundle, but\n // the terser plugin does this by default, so we only enable the terser if\n // the legacy config has `stripComments` set to `true`. This is not a\n // perfect solution, but it's the best we can do without breaking the\n // legacy config.\n minimize: legacyConfig.cliOptions.stripComments,\n\n // The legacy config does not have a `clean` option, so we default to\n // `false` here.\n clean: false,\n },\n manifest: {\n // The legacy config does not have a `manifest` option, so we default to\n // `process.cwd()/snap.manifest.json`.\n path: resolve(process.cwd(), 'snap.manifest.json'),\n update: legacyConfig.cliOptions.writeManifest,\n },\n server: {\n enabled: legacyConfig.cliOptions.serve,\n port: legacyConfig.cliOptions.port,\n root: legacyConfig.cliOptions.root,\n },\n stats: {\n verbose: false,\n\n // These plugins are designed to be used with the modern config format, so\n // we disable them for the legacy config format.\n builtIns: false,\n buffer: false,\n },\n legacy: createFromStruct(\n {\n ...legacyConfig.cliOptions,\n bundlerCustomizer: legacyConfig.bundlerCustomizer,\n },\n LegacyOptionsStruct,\n 'Invalid Browserify CLI options',\n ),\n };\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,OAAO,YAAY;AACnB,OAAO,WAAW;AAClB,SAAS,eAAe;AAMxB,IAAM,0BAA0B;AAChC,IAAM,0BAA0B;AAQzB,SAAS,iBACd,cAAsB,QAAQ,QAAQ,MAAM,CAAC,GAC7C;AACA,QAAM,eAAe,OAAO,MAAM,WAAW;AAC7C,QAAM,UAAU,gBAAgB,WAAW,sCAAsC,uBAAuB;AAExG,MAAI,eAAe,IAAI;AACrB,UAAM,OAAO;AAEb,YAAQ,KAAK,CAAC;AAAA,EAChB;AAIA,MAAI,iBAAiB,MAAM,OAAO,GAAG,aAAa,uBAAuB,GAAG;AAC1E,UAAM,OAAO;AAEb,YAAQ,KAAK,CAAC;AAAA,EAChB;AAEA,MAAI,iBAAiB,MAAM,OAAO,GAAG,aAAa,uBAAuB,GAAG;AAC1E;AAAA,MACE,gBAAgB,WAAW,sCAAsC,uBAAuB;AAAA,IAC1F;AAEA,YAAQ,KAAK,CAAC;AAAA,EAChB;AACF;AASA,eAAsB,IAAI,MAAgB,UAAe;AACvD,mBAAiB;AAEjB,QAAM,MAAM,QAAQ,IAAI,CAAC,EACtB,WAAW,SAAS,EACpB,MAAM,+BAA+B,EAErC,QAAQ,YAAY,8CAA8C,EAClE;AAAA,IACC;AAAA,IACA;AAAA,EACF,EACC,QAAQ,qBAAqB,6CAA6C,EAC1E;AAAA,IACC;AAAA,IACA;AAAA,EACF,EACC,QAAQ,wBAAwB,oCAAoC,EAEpE,QAAQ,QAAQ,EAEhB,OAAO,UAAU,iBAAS,MAAM,EAChC,OAAO,iBAAiB,iBAAS,aAAa,EAC9C,OAAO,oBAAoB,iBAAS,gBAAgB,EAEpD,OAAO,EAEP,WAAW,OAAO,SAAc;AAE/B,SAAK,UAAU;AAAA,MACb,QAAQ,MAAM,gBAAgB,IAAI;AAAA,IACpC;AAEA,mBAAe,IAAI;AAAA,EACrB,GAAG,KAAK,EAEP,cAAc,GAAG,wCAAwC,EAEzD,KAAK,CAAC,SAAS,YAAY;AAC1B,UAAM,qBAAqB,SAAS,OAAO,CAAC;AAE5C,YAAQ,KAAK,CAAC;AAAA,EAChB,CAAC,EAEA,KAAK,EACL,MAAM,QAAQ,GAAG,EACjB,WAAW;AAChB","sourcesContent":["import semver from 'semver';\nimport yargs from 'yargs';\nimport { hideBin } from 'yargs/helpers';\n\nimport builders from './builders';\nimport { getConfigByArgv } from './config';\nimport { error, getYargsErrorMessage, sanitizeInputs } from './utils';\n\nconst MINIMUM_NODE_16_VERSION = '16.17.0';\nconst MINIMUM_NODE_18_VERSION = '18.6.0';\n\n/**\n * Check the Node version. If the Node version is less than the minimum required\n * version, this logs an error and exits the process.\n *\n * @param nodeVersion - The Node version to check.\n */\nexport function checkNodeVersion(\n nodeVersion: string = process.version.slice(1),\n) {\n const majorVersion = semver.major(nodeVersion);\n const message = `Node version ${nodeVersion} is not supported. Please use Node ${MINIMUM_NODE_16_VERSION} or later.`;\n\n if (majorVersion < 16) {\n error(message);\n // eslint-disable-next-line n/no-process-exit\n process.exit(1);\n }\n\n // Node 16 and 18 have a different minimum version requirement, so we need to\n // check for both.\n if (majorVersion === 16 && semver.lt(nodeVersion, MINIMUM_NODE_16_VERSION)) {\n error(message);\n // eslint-disable-next-line n/no-process-exit\n process.exit(1);\n }\n\n if (majorVersion === 18 && semver.lt(nodeVersion, MINIMUM_NODE_18_VERSION)) {\n error(\n `Node version ${nodeVersion} is not supported. Please use Node ${MINIMUM_NODE_18_VERSION} or later.`,\n );\n // eslint-disable-next-line n/no-process-exit\n process.exit(1);\n }\n}\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 async function cli(argv: string[], commands: any) {\n checkNodeVersion();\n\n await yargs(hideBin(argv))\n .scriptName('mm-snap')\n .usage('Usage: $0 <command> [options]')\n\n .example('$0 build', `Build './src/index.js' as './dist/bundle.js'`)\n .example(\n '$0 build --config ./snap.config.build.ts',\n `Build './src/index.js' as './dist/bundle.js' using the config in './snap.config.build.ts'`,\n )\n .example('$0 manifest --fix', `Check the snap manifest, and fix any errors`)\n .example(\n '$0 watch --port 8000',\n `The snap input file for changes, and serve it on port 8000`,\n )\n .example('$0 serve --port 8000', `Serve the snap bundle on port 8000`)\n\n .command(commands)\n\n .option('config', builders.config)\n .option('verboseErrors', builders.verboseErrors)\n .option('suppressWarnings', builders.suppressWarnings)\n\n .strict()\n\n .middleware(async (args: any) => {\n // eslint-disable-next-line require-atomic-updates\n args.context = {\n config: await getConfigByArgv(args),\n };\n\n sanitizeInputs(args);\n }, false)\n\n .demandCommand(1, 'You must specify at least one command.')\n\n .fail((message, failure) => {\n error(getYargsErrorMessage(message, failure));\n // eslint-disable-next-line n/no-process-exit\n process.exit(1);\n })\n\n .help()\n .alias('help', 'h')\n .parseAsync();\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/webpack/utils.ts","../src/webpack/loaders/browserify.ts"],"names":["resolve"],"mappings":";;;;;;;;;;;AAAA,SAAS,WAAW;AACpB,SAAS,YAAY,UAAU;AAC/B,SAAS,sBAAsB;AAE/B,SAAS,SAAS,eAAe;AACjC,OAAO,eAAe;;;ACLtB,OAAO,gBAAgB;AACvB,SAAS,gBAAgB;AAoBzB,IAAM,SAAkD,eACtD,SACA,WACA;AACA,QAAM,SAAS,KAAK,WAAW;AAE/B,QAAM,EAAE,kBAAkB,IAAI;AAE9B,QAAM,UAAU,WAAW;AAAA,IACzB,YAAY,CA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,aAAa;AAAA,EAAK,IAAI,OAAO,MAAM,CAAC,GAAG,IAAI;AAAA,UAC7D,mBAAmB,SAAS,YAAY;AAAA,QAC1C;AAAA,MACF;AAGA,aAAO;AAAA,QACL,eAAe,gBAAgB,kBAAkB;AAAA,QACjD,mBAAmB,oBAAoB;AAAA,MACzC;AAAA,IACF;AAAA,IACA;AAAA,MACE,eAAe,IAAI,OAAO,aAAa;AAAA,MACvC,mBAAmB;AAAA,IACrB;AAAA,EACF,EAAE;AACJ;AAWO,SAAS,WACd,MACA,QACA,gBAAgB,QAChB;AACA,QAAM,QAAQ,KAAK,MAAM,IAAI;AAG7B,SAAO,MACJ,IAAI,CAAC,MAAM,UAAU;AACpB,UAAM,aAAa,UAAU,IAAI,gBAAgB;AACjD,WAAO,WAAW,MAAM,QAAQ,UAAU;AAAA,EAC5C,CAAC,EACA,KAAK,IAAI;AACd","sourcesContent":["import { dim } from 'chalk';\nimport { promises as fs } from 'fs';\nimport { builtinModules } from 'module';\nimport type { Ora } from 'ora';\nimport { dirname, resolve } from 'path';\nimport stripAnsi from 'strip-ansi';\nimport type { Configuration } from 'webpack';\n\nimport type { ProcessedWebpackConfig } from '../config';\nimport { browserify, getFunctionLoader } from './loaders';\n\nexport const BROWSERSLIST_FILE = resolve(\n dirname(\n // eslint-disable-next-line n/no-extraneous-require\n require.resolve('@metamask/snaps-cli/package.json'),\n ),\n '.browserslistrc',\n);\n\nexport const WEBPACK_FALLBACKS = {\n assert: require.resolve('assert/'),\n buffer: require.resolve('buffer/'),\n console: require.resolve('console-browserify'),\n constants: require.resolve('constants-browserify'),\n crypto: require.resolve('crypto-browserify'),\n domain: require.resolve('domain-browser'),\n events: require.resolve('events/'),\n http: require.resolve('stream-http'),\n https: require.resolve('https-browserify'),\n os: require.resolve('os-browserify/browser'),\n path: require.resolve('path-browserify'),\n punycode: require.resolve('punycode/'),\n process: require.resolve('process/browser'),\n querystring: require.resolve('querystring-es3'),\n stream: require.resolve('stream-browserify'),\n /* eslint-disable @typescript-eslint/naming-convention */\n _stream_duplex: require.resolve('readable-stream/lib/_stream_duplex'),\n _stream_passthrough: require.resolve(\n 'readable-stream/lib/_stream_passthrough',\n ),\n _stream_readable: require.resolve('readable-stream/lib/_stream_readable'),\n _stream_transform: require.resolve('readable-stream/lib/_stream_transform'),\n _stream_writable: require.resolve('readable-stream/lib/_stream_writable'),\n string_decoder: require.resolve('string_decoder/'),\n /* eslint-enable @typescript-eslint/naming-convention */\n sys: require.resolve('util/'),\n timers: require.resolve('timers-browserify'),\n tty: require.resolve('tty-browserify'),\n url: require.resolve('url/'),\n util: require.resolve('util/'),\n vm: require.resolve('vm-browserify'),\n zlib: require.resolve('browserify-zlib'),\n};\n\n/**\n * Get the default loader for JavaScript and TypeScript files, based on the\n * config object.\n *\n * - If the `legacy` option is set, we use the custom `browserify` loader. This\n * uses the legacy Browserify config to transpile the code.\n * - Otherwise, we use the `swc-loader`. This is a Webpack loader that uses the\n * `SWC` compiler, which is a much faster alternative to Babel and TypeScript's\n * own compiler.\n *\n * @param config - The processed snap Webpack config.\n * @param config.legacy - The legacy config object, if any.\n * @param config.sourceMap - Whether to generate source maps.\n * @see https://swc.rs/docs/usage/swc-loader\n * @returns The default loader.\n */\nexport async function getDefaultLoader({\n legacy,\n sourceMap,\n}: ProcessedWebpackConfig) {\n if (legacy) {\n /**\n * If the snap uses the legacy config, we use the custom `browserify`\n * loader. This uses the legacy Browserify config to transpile the code.\n * This is necessary for backwards compatibility with the\n * `bundlerCustomizer` function.\n */\n return getFunctionLoader(browserify, legacy);\n }\n\n const targets = await getBrowserslistTargets();\n return {\n /**\n * We use the `swc-loader` to transpile TypeScript and JavaScript files.\n * This is a Webpack loader that uses the `SWC` compiler, which is a much\n * faster alternative to Babel and TypeScript's own compiler.\n */\n loader: require.resolve('swc-loader'),\n\n /**\n * The options for the `swc-loader`. These can be overridden in the\n * `.swcrc` file.\n *\n * @see https://swc.rs/docs/configuration/swcrc\n */\n options: {\n sync: false,\n\n /**\n * This tells SWC to generate source maps. We set it to the\n * `sourceMap` value from the config object.\n *\n * This must be enabled if source maps are enabled in the config.\n */\n sourceMaps: Boolean(getDevTool(sourceMap)),\n\n jsc: {\n parser: {\n /**\n * This tells the parser to parse TypeScript files. If you\n * don't need to support TypeScript, you can set this to\n * `ecmascript` instead, but there's no harm in leaving it\n * as `typescript`.\n *\n * @see https://swc.rs/docs/configuration/compilation#jscparser\n */\n syntax: 'typescript',\n },\n },\n\n /**\n * The module configuration. This tells SWC how to output the\n * transpiled code.\n *\n * @see https://swc.rs/docs/configuration/modules\n */\n module: {\n /**\n * This tells SWC to output ES6 modules. This will allow Webpack to\n * optimize the output code better. Snaps don't support ES6 however, so\n * the output code will be transpiled to CommonJS by Webpack later in\n * the build process.\n *\n * @see https://swc.rs/docs/configuration/modules#es6\n */\n type: 'es6',\n },\n\n env: {\n targets: targets.join(', '),\n },\n },\n };\n}\n\n/**\n * Get the Webpack devtool configuration based on the given snap config.\n *\n * - If `sourceMap` is `inline`, return `inline-source-map`.\n * - If `sourceMap` is `true`, return `source-map`.\n * - Otherwise, return `false`.\n *\n * @param sourceMap - The `sourceMap` value from the snap config.\n * @returns The Webpack devtool configuration.\n */\nexport function getDevTool(\n sourceMap: ProcessedWebpackConfig['sourceMap'],\n): Configuration['devtool'] {\n if (sourceMap === 'inline') {\n return 'inline-source-map';\n }\n\n if (sourceMap === true) {\n return 'source-map';\n }\n\n return false;\n}\n\n/**\n * Get a function that can be used as handler function for Webpack's\n * `ProgressPlugin`.\n *\n * @param spinner - The spinner to update.\n * @param spinnerText - The initial spinner text. This will be prepended to the\n * percentage.\n * @returns A function that can be used as handler function for Webpack's\n * `ProgressPlugin`.\n */\n// Note: This is extracted for testing purposes.\nexport function getProgressHandler(spinner?: Ora, spinnerText?: string) {\n return (percentage: number) => {\n if (spinner && spinnerText) {\n spinner.text = `${spinnerText} ${dim(\n `(${Math.round(percentage * 100)}%)`,\n )}`;\n }\n };\n}\n\n/**\n * Get the targets from the `.browserslistrc` file.\n *\n * @returns The browser targets as an array of strings.\n */\nexport async function getBrowserslistTargets() {\n const contents = await fs.readFile(BROWSERSLIST_FILE, 'utf8');\n return contents\n .split('\\n')\n .map((line) => line.trim())\n .filter((line) => line && !line.startsWith('#'));\n}\n\n/**\n * Get a singular or plural string based on the given count. This is useful for\n * generating messages like \"1 error\" or \"2 errors\". By default, the plural\n * string is the singular string with an \"s\" appended to it.\n *\n * This assumes that the text is in English, and likely won't work for some\n * other languages.\n *\n * @param count - The count.\n * @param singular - The singular string.\n * @param plural - The plural string.\n * @returns The singular or plural string.\n * @example\n * ```typescript\n * pluralize(1, 'error'); // => 'error'\n * pluralize(2, 'error'); // => 'errors'\n * pluralize(1, 'error', 'problem'); // => 'error'\n * pluralize(2, 'error', 'problems'); // => 'problems'\n * ```\n */\nexport function pluralize(\n count: number,\n singular: string,\n plural = `${singular}s`,\n) {\n return count === 1 ? singular : plural;\n}\n\n/**\n * Get an object that can be used as fallback config for Webpack's\n * `fallback` config.\n *\n * @param polyfills - The polyfill object from the snap config.\n * @returns The webpack fallback config.\n */\nexport function getFallbacks(polyfills: ProcessedWebpackConfig['polyfills']): {\n [index: string]: string | false;\n} {\n if (polyfills === true) {\n return Object.fromEntries(\n builtinModules.map((name) => [\n name,\n WEBPACK_FALLBACKS[name as keyof typeof WEBPACK_FALLBACKS] ?? false,\n ]),\n );\n }\n\n if (polyfills === false) {\n return Object.fromEntries(builtinModules.map((name) => [name, false]));\n }\n\n return Object.fromEntries(\n builtinModules.map((name) => [\n name,\n polyfills[name as keyof ProcessedWebpackConfig['polyfills']]\n ? WEBPACK_FALLBACKS[name as keyof typeof WEBPACK_FALLBACKS]\n : false,\n ]),\n );\n}\n\n/**\n * Get an object that can be used as environment variables for Webpack's\n * `DefinePlugin`.\n *\n * @param environment - The environment object from the Snap config.\n * @param defaults - The default environment variables.\n * @returns The Webpack environment variables.\n */\nexport function getEnvironmentVariables(\n environment: Record<string, unknown>,\n defaults = {\n NODE_DEBUG: 'false',\n NODE_ENV: 'production',\n DEBUG: 'false',\n },\n) {\n return Object.fromEntries(\n Object.entries({\n ...defaults,\n ...environment,\n }).map(([key, value]) => [`process.env.${key}`, JSON.stringify(value)]),\n );\n}\n\n/**\n * Format the given line to fit within the terminal width.\n *\n * @param line - The line to format.\n * @param indent - The indentation to use.\n * @param initialIndent - The initial indentation to use, i.e., the indentation\n * for the first line.\n * @returns The formatted line.\n */\nfunction formatLine(line: string, indent: number, initialIndent: number) {\n const terminalWidth = process.stdout.columns;\n if (!terminalWidth) {\n return `${' '.repeat(initialIndent)}${line}`;\n }\n\n return line.split(' ').reduce(\n ({ formattedText, currentLineLength }, word, index) => {\n // `chalk` adds ANSI escape codes to the text, which are not visible\n // characters. We need to strip them to get the visible length of the\n // text.\n const visibleWord = stripAnsi(word);\n\n // Determine if a space should be added before the word.\n const spaceBeforeWord = index > 0 ? ' ' : '';\n const wordLengthWithSpace = visibleWord.length + spaceBeforeWord.length;\n\n // If the word would exceed the terminal width, start a new line.\n if (currentLineLength + wordLengthWithSpace > terminalWidth) {\n return {\n formattedText: `${formattedText}\\n${' '.repeat(indent)}${word}`,\n currentLineLength: indent + visibleWord.length,\n };\n }\n\n // Otherwise, add the word to the current line.\n return {\n formattedText: formattedText + spaceBeforeWord + word,\n currentLineLength: currentLineLength + wordLengthWithSpace,\n };\n },\n {\n formattedText: ' '.repeat(initialIndent),\n currentLineLength: initialIndent,\n },\n ).formattedText;\n}\n\n/**\n * Format the given text to fit within the terminal width.\n *\n * @param text - The text to format.\n * @param indent - The indentation to use.\n * @param initialIndent - The initial indentation to use, i.e., the indentation\n * for the first line.\n * @returns The formatted text.\n */\nexport function formatText(\n text: string,\n indent: number,\n initialIndent = indent,\n) {\n const lines = text.split('\\n');\n\n // Apply formatting to each line separately and then join them.\n return lines\n .map((line, index) => {\n const lineIndent = index === 0 ? initialIndent : indent;\n return formatLine(line, indent, lineIndent);\n })\n .join('\\n');\n}\n","import browserify from 'browserify';\nimport { Readable } from 'readable-stream';\nimport type { LoaderDefinitionFunction } from 'webpack';\n\nimport { TranspilationModes } from '../../builders';\nimport type { LegacyOptions } from '../../config';\nimport { processDependencies } from '../../utils';\nimport { getBrowserslistTargets } from '../utils';\n\n/**\n * A Browserify loader for Webpack. This exists for backwards compatibility with\n * the legacy configuration format, in order to support the `bundlerCustomizer`\n * function.\n *\n * When this loader is used, the input file will be processed by Browserify, and\n * written to disk by Webpack. Most processing will be handled by Browserify, so\n * there are no benefits like tree-shaking.\n *\n * @param content - The input file contents as a string.\n * @param sourceMap - The source map of the input file.\n */\nconst loader: LoaderDefinitionFunction<LegacyOptions> = async function (\n content,\n sourceMap,\n) {\n const config = this.getOptions();\n\n const { transpilationMode } = config;\n\n const bundler = browserify({\n extensions: ['.js', '.ts'],\n debug: Boolean(sourceMap),\n standalone: '<snap>',\n });\n\n if (transpilationMode !== TranspilationModes.None) {\n const babelifyOptions = processDependencies(config);\n\n // We need to statically import all Browserify transforms, and all Babel\n // presets and plugins, and calling `require` is the sanest way to do that.\n /* eslint-disable @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires, n/global-require */\n 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: await getBrowserslistTargets(),\n },\n },\n ],\n ],\n plugins: [\n require('@babel/plugin-transform-runtime'),\n require('@babel/plugin-transform-class-properties'),\n require('@babel/plugin-transform-private-methods'),\n require('@babel/plugin-transform-class-static-block'),\n require('@babel/plugin-transform-private-property-in-object'),\n ],\n ...(babelifyOptions as any),\n });\n /* eslint-enable @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires, n/global-require */\n }\n\n config.bundlerCustomizer?.(bundler);\n\n // Browserify doesn't accept a string as an entry point, so we need to convert\n // it to a stream.\n const stream = new Readable();\n stream.push(content);\n stream.push(null);\n\n bundler.add(stream, {\n file: this.resourcePath,\n });\n\n return new Promise<Buffer>((resolve, reject) => {\n bundler.bundle((bundleError, buffer: Buffer) => {\n if (bundleError) {\n reject(bundleError);\n return;\n }\n\n // Browserify inlines the source map, so we just pass the output buffer back\n // to Webpack.\n resolve(buffer);\n });\n });\n};\n\nexport default loader;\n"]}