@metamask/snaps-cli 0.8.0 → 0.9.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.
package/CHANGELOG.md CHANGED
@@ -6,6 +6,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.9.0]
10
+ ### Added
11
+ - Transpilation configuration ([#213](https://github.com/MetaMask/snaps-skunkworks/pull/213))
12
+ - `mm-snap build` now takes a `--transpilationMode` argument which determines what will be transpiled by Babel during building: all source code (including dependencies), local source code only, or nothing.
13
+
14
+ ### Fixed
15
+ - `mm-snap build` command when CLI is installed globally ([#216](https://github.com/MetaMask/snaps-skunkworks/pull/216))
16
+ - Update installation command in readme ([#205](https://github.com/MetaMask/snaps-skunkworks/pull/205))
17
+
9
18
  ## [0.8.0]
10
19
  ### Changed
11
20
  - Update template snap created by `mm-snap init` ([#195](https://github.com/MetaMask/snaps-skunkworks/pull/195))
@@ -89,7 +98,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
89
98
  - Example snaps ([#72](https://github.com/MetaMask/snaps-skunkworks/pull/72))
90
99
  - The examples now live in their own package, [`@metamask/snap-examples`](https://npmjs.com/package/@metamask/snap-examples).
91
100
 
92
- [Unreleased]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.8.0...HEAD
101
+ [Unreleased]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.9.0...HEAD
102
+ [0.9.0]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.8.0...v0.9.0
93
103
  [0.8.0]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.7.0...v0.8.0
94
104
  [0.7.0]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.6.3...v0.7.0
95
105
  [0.6.3]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.6.2...v0.6.3
package/README.md CHANGED
@@ -7,7 +7,7 @@ A CLI for developing MetaMask Snaps.
7
7
  Use Node.js `12.11.0` or later.
8
8
  We recommend [nvm](https://github.com/nvm-sh/nvm) for managing Node.js versions.
9
9
 
10
- - `yarn global add snaps-cli`
10
+ - `yarn global add @metamask/snaps-cli`
11
11
 
12
12
  ## Basic Usage
13
13
 
@@ -1,18 +1,24 @@
1
1
  import { Options } from 'yargs';
2
2
  export declare type SnapsCliBuilders = {
3
- readonly src: Readonly<Options>;
4
- readonly dist: Readonly<Options>;
5
3
  readonly bundle: Readonly<Options>;
6
- readonly root: Readonly<Options>;
4
+ readonly dist: Readonly<Options>;
5
+ readonly eval: Readonly<Options>;
6
+ readonly manifest: Readonly<Options>;
7
+ readonly outfileName: Readonly<Options>;
7
8
  readonly port: Readonly<Options>;
9
+ readonly root: Readonly<Options>;
8
10
  readonly sourceMaps: Readonly<Options>;
11
+ readonly src: Readonly<Options>;
9
12
  readonly stripComments: Readonly<Options>;
10
- readonly outfileName: Readonly<Options>;
11
- readonly manifest: Readonly<Options>;
12
- readonly writeManifest: Readonly<Options>;
13
- readonly eval: Readonly<Options>;
14
- readonly verboseErrors: Readonly<Options>;
15
13
  readonly suppressWarnings: Readonly<Options>;
14
+ readonly transpilationMode: Readonly<Options>;
15
+ readonly verboseErrors: Readonly<Options>;
16
+ readonly writeManifest: Readonly<Options>;
16
17
  };
18
+ export declare enum TranspilationModes {
19
+ all = "all",
20
+ localOnly = "localOnly",
21
+ none = "none"
22
+ }
17
23
  declare const builders: SnapsCliBuilders;
18
24
  export default builders;
package/dist/builders.js CHANGED
@@ -1,13 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TranspilationModes = void 0;
4
+ var TranspilationModes;
5
+ (function (TranspilationModes) {
6
+ TranspilationModes["all"] = "all";
7
+ TranspilationModes["localOnly"] = "localOnly";
8
+ TranspilationModes["none"] = "none";
9
+ })(TranspilationModes = exports.TranspilationModes || (exports.TranspilationModes = {}));
3
10
  const builders = {
4
- src: {
5
- alias: 's',
6
- describe: 'Source file',
11
+ bundle: {
12
+ alias: 'b',
13
+ describe: 'Snap bundle file',
7
14
  type: 'string',
8
15
  demandOption: true,
9
16
  normalize: true,
10
- default: 'src/index.js',
17
+ default: 'dist/bundle.js',
11
18
  },
12
19
  dist: {
13
20
  alias: 'd',
@@ -17,21 +24,19 @@ const builders = {
17
24
  normalize: true,
18
25
  default: 'dist',
19
26
  },
20
- bundle: {
21
- alias: 'b',
22
- describe: 'Snap bundle file',
23
- type: 'string',
24
- demandOption: true,
25
- normalize: true,
26
- default: 'dist/bundle.js',
27
+ eval: {
28
+ alias: 'e',
29
+ describe: 'Attempt to evaluate Snap bundle in SES',
30
+ type: 'boolean',
31
+ demandOption: false,
32
+ default: true,
27
33
  },
28
- root: {
29
- alias: 'r',
30
- describe: 'Server root directory',
31
- type: 'string',
32
- demandOption: true,
33
- normalize: true,
34
- default: '.',
34
+ manifest: {
35
+ alias: 'm',
36
+ describe: 'Validate snap.manifest.json',
37
+ type: 'boolean',
38
+ demandOption: false,
39
+ default: true,
35
40
  },
36
41
  port: {
37
42
  alias: 'p',
@@ -47,12 +52,35 @@ const builders = {
47
52
  return port;
48
53
  },
49
54
  },
55
+ outfileName: {
56
+ alias: 'n',
57
+ describe: 'Output file name',
58
+ type: 'string',
59
+ demandOption: false,
60
+ default: 'bundle.js',
61
+ },
62
+ root: {
63
+ alias: 'r',
64
+ describe: 'Server root directory',
65
+ type: 'string',
66
+ demandOption: true,
67
+ normalize: true,
68
+ default: '.',
69
+ },
50
70
  sourceMaps: {
51
71
  describe: 'Whether builds include sourcemaps',
52
72
  type: 'boolean',
53
73
  demandOption: false,
54
74
  default: false,
55
75
  },
76
+ src: {
77
+ alias: 's',
78
+ describe: 'Source file',
79
+ type: 'string',
80
+ demandOption: true,
81
+ normalize: true,
82
+ default: 'src/index.js',
83
+ },
56
84
  stripComments: {
57
85
  alias: 'strip',
58
86
  describe: 'Whether to remove code comments from the build output',
@@ -60,32 +88,18 @@ const builders = {
60
88
  demandOption: false,
61
89
  default: false,
62
90
  },
63
- outfileName: {
64
- alias: 'n',
65
- describe: 'Output file name',
66
- type: 'string',
67
- demandOption: false,
68
- default: 'bundle.js',
69
- },
70
- manifest: {
71
- alias: 'm',
72
- describe: 'Validate snap.manifest.json',
73
- type: 'boolean',
74
- demandOption: false,
75
- default: true,
76
- },
77
- writeManifest: {
78
- describe: 'Make necessary changes to the Snap manifest file',
91
+ suppressWarnings: {
79
92
  type: 'boolean',
93
+ describe: 'Whether to suppress warnings',
80
94
  demandOption: false,
81
- default: true,
95
+ default: false,
82
96
  },
83
- eval: {
84
- alias: 'e',
85
- describe: 'Attempt to evaluate Snap bundle in SES',
86
- type: 'boolean',
97
+ transpilationMode: {
98
+ type: 'string',
99
+ describe: 'Whether to use Babel to transpile all source code (including dependencies), local source code only, or nothing.',
87
100
  demandOption: false,
88
- default: true,
101
+ default: TranspilationModes.all,
102
+ choices: Object.values(TranspilationModes),
89
103
  },
90
104
  verboseErrors: {
91
105
  type: 'boolean',
@@ -93,11 +107,11 @@ const builders = {
93
107
  demandOption: false,
94
108
  default: false,
95
109
  },
96
- suppressWarnings: {
110
+ writeManifest: {
111
+ describe: 'Make necessary changes to the Snap manifest file',
97
112
  type: 'boolean',
98
- describe: 'Suppress warnings',
99
113
  demandOption: false,
100
- default: false,
114
+ default: true,
101
115
  },
102
116
  };
103
117
  exports.default = builders;
@@ -1 +1 @@
1
- {"version":3,"file":"builders.js","sourceRoot":"","sources":["../src/builders.ts"],"names":[],"mappings":";;AAkBA,MAAM,QAAQ,GAAqB;IACjC,GAAG,EAAE;QACH,KAAK,EAAE,GAAG;QACV,QAAQ,EAAE,aAAa;QACvB,IAAI,EAAE,QAAQ;QACd,YAAY,EAAE,IAAI;QAClB,SAAS,EAAE,IAAI;QACf,OAAO,EAAE,cAAc;KACxB;IAED,IAAI,EAAE;QACJ,KAAK,EAAE,GAAG;QACV,QAAQ,EAAE,kBAAkB;QAC5B,IAAI,EAAE,QAAQ;QACd,YAAY,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AO,EAAE,WAAW;KACrB;IAED,QAAQ,EAAE;QACR,KAAK,EAAE,GAAG;QACV,QAAQ,EAAE,6BAA6B;QACvC,IAAI,EAAE,SAAS;QACf,YAAY,EAAE,KAAK;QACnB,OAAO,EAAE,IAAI;KACd;IAED,aAAa,EAAE;QACb,QAAQ,EAAE,kDAAkD;QAC5D,IAAI,EAAE,SAAS;QACf,YAAY,EAAE,KAAK;QACnB,OAAO,EAAE,IAAI;KACd;IAED,IAAI,EAAE;QACJ,KAAK,EAAE,GAAG;QACV,QAAQ,EAAE,wCAAwC;QAClD,IAAI,EAAE,SAAS;QACf,YAAY,EAAE,KAAK;QACnB,OAAO,EAAE,IAAI;KACd;IAED,aAAa,EAAE;QACb,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,yBAAyB;QACnC,YAAY,EAAE,KAAK;QACnB,OAAO,EAAE,KAAK;KACf;IAED,gBAAgB,EAAE;QAChB,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,mBAAmB;QAC7B,YAAY,EAAE,KAAK;QACnB,OAAO,EAAE,KAAK;KACf;CACF,CAAC;AAEF,kBAAe,QAAQ,CAAC","sourcesContent":["import { Options } from 'yargs';\n\nexport type SnapsCliBuilders = {\n readonly src: Readonly<Options>;\n readonly dist: Readonly<Options>;\n readonly bundle: Readonly<Options>;\n readonly root: Readonly<Options>;\n readonly port: Readonly<Options>;\n readonly sourceMaps: Readonly<Options>;\n readonly stripComments: Readonly<Options>;\n readonly outfileName: Readonly<Options>;\n readonly manifest: Readonly<Options>;\n readonly writeManifest: Readonly<Options>;\n readonly eval: Readonly<Options>;\n readonly verboseErrors: Readonly<Options>;\n readonly suppressWarnings: Readonly<Options>;\n};\n\nconst builders: SnapsCliBuilders = {\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 dist: {\n alias: 'd',\n describe: 'Output directory',\n type: 'string',\n demandOption: true,\n normalize: true,\n default: 'dist',\n },\n\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 root: {\n alias: 'r',\n describe: 'Server root directory',\n type: 'string',\n demandOption: true,\n normalize: true,\n default: '.',\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: ${arg}`);\n }\n return port;\n },\n },\n\n sourceMaps: {\n describe: 'Whether builds include sourcemaps',\n type: 'boolean',\n demandOption: false,\n default: false,\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: false,\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 manifest: {\n alias: 'm',\n describe: 'Validate snap.manifest.json',\n type: 'boolean',\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 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 verboseErrors: {\n type: 'boolean',\n describe: 'Display original errors',\n demandOption: false,\n default: false,\n },\n\n suppressWarnings: {\n type: 'boolean',\n describe: 'Suppress warnings',\n demandOption: false,\n default: false,\n },\n};\n\nexport default builders;\n"]}
1
+ {"version":3,"file":"builders.js","sourceRoot":"","sources":["../src/builders.ts"],"names":[],"mappings":";;;AAmBA,IAAY,kBAIX;AAJD,WAAY,kBAAkB;IAC5B,iCAAW,CAAA;IACX,6CAAuB,CAAA;IACvB,mCAAa,CAAA;AACf,CAAC,EAJW,kBAAkB,GAAlB,0BAAkB,KAAlB,0BAAkB,QAI7B;AAED,MAAM,QAAQ,GAAqB;IACjC,MAAM,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,EAAE,GAAG;QACV,QAAQ,EAAE,uBAAuB;QACjC,IAAI,EAAE,QAAQ;QACd,YAAY,EAAE,IAAI;QAClB,SAAS,EAAE,IAAI;QACf,OAAO,EAAE,GAAG;KACb;IAED,UAAU,EAAE;QACV,QAAQ,EAAE,mCAAmC;QAC7C,IAAI,EAAE,SAAS;QACf,YAAY,EAAE,KAAK;QACnB,OAAO,EAAE,KAAK;KACf;IAED,GAAG,EAAE;QACH,KAAK,EAAE,GAAG;QACV,QAAQ,EAAE,aAAa;QACvB,IAAI,EAAE,QAAQ;QACd,YAAY,EAAE,IAAI;QAClB,SAAS,EAAE,IAAI;QACf,OAAO,EAAE,cAAc;KACxB;IAED,aAAa,EAAE;QACb,KAAK,EAAE,OAAO;QACd,QAAQ,EAAE,uDAAuD;QACjE,IAAI,EAAE,SAAS;QACf,YAAY,EAAE,KAAK;QACnB,OAAO,EAAE,KAAK;KACf;IAED,gBAAgB,EAAE;QAChB,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,8BAA8B;QACxC,YAAY,EAAE,KAAK;QACnB,OAAO,EAAE,KAAK;KACf;IAED,iBAAiB,EAAE;QACjB,IAAI,EAAE,QAAQ;QACd,QAAQ,EACN,iHAAiH;QACnH,YAAY,EAAE,KAAK;QACnB,OAAO,EAAE,kBAAkB,CAAC,GAAG;QAC/B,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC;KAC3C;IAED,aAAa,EAAE;QACb,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,yBAAyB;QACnC,YAAY,EAAE,KAAK;QACnB,OAAO,EAAE,KAAK;KACf;IAED,aAAa,EAAE;QACb,QAAQ,EAAE,kDAAkD;QAC5D,IAAI,EAAE,SAAS;QACf,YAAY,EAAE,KAAK;QACnB,OAAO,EAAE,IAAI;KACd;CACF,CAAC;AAEF,kBAAe,QAAQ,CAAC","sourcesContent":["import { Options } 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 verboseErrors: Readonly<Options>;\n readonly writeManifest: Readonly<Options>;\n};\n\nexport enum TranspilationModes {\n all = 'all',\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: ${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: false,\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.all,\n choices: Object.values(TranspilationModes),\n },\n\n verboseErrors: {\n type: 'boolean',\n describe: 'Display original errors',\n demandOption: false,\n default: false,\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\nexport default builders;\n"]}
@@ -2,10 +2,11 @@ import { YargsArgs } from '../../types/yargs';
2
2
  /**
3
3
  * Builds a Snap bundle JSON file from its JavaScript source.
4
4
  *
5
- * @param src - The source file path
6
- * @param dest - The destination file path
7
- * @param argv - arguments as an object generated by yargs
8
- * @param argv.sourceMaps - Whether to output sourcemaps
9
- * @param argv.stripComments - Whether to remove comments from code
5
+ * @param src - The source file path.
6
+ * @param dest - The destination file path.
7
+ * @param argv - arguments as an object generated by yargs.
8
+ * @param argv.sourceMaps - Whether to output sourcemaps.
9
+ * @param argv.stripComments - Whether to remove comments from code.
10
+ * @param argv.transpilationMode - The Babel transpilation mode.
10
11
  */
11
12
  export declare function bundle(src: string, dest: string, argv: YargsArgs): Promise<boolean>;
@@ -5,41 +5,49 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.bundle = void 0;
7
7
  const browserify_1 = __importDefault(require("browserify"));
8
+ const builders_1 = require("../../builders");
8
9
  const bundleUtils_1 = require("./bundleUtils");
10
+ // We need to statically import all Browserify transforms and all Babel presets
11
+ // and plugins, and calling `require` is the sanest way to do that.
12
+ /* eslint-disable @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires, node/global-require */
9
13
  /**
10
14
  * Builds a Snap bundle JSON file from its JavaScript source.
11
15
  *
12
- * @param src - The source file path
13
- * @param dest - The destination file path
14
- * @param argv - arguments as an object generated by yargs
15
- * @param argv.sourceMaps - Whether to output sourcemaps
16
- * @param argv.stripComments - Whether to remove comments from code
16
+ * @param src - The source file path.
17
+ * @param dest - The destination file path.
18
+ * @param argv - arguments as an object generated by yargs.
19
+ * @param argv.sourceMaps - Whether to output sourcemaps.
20
+ * @param argv.stripComments - Whether to remove comments from code.
21
+ * @param argv.transpilationMode - The Babel transpilation mode.
17
22
  */
18
23
  function bundle(src, dest, argv) {
19
- const { sourceMaps: debug } = argv;
24
+ const { sourceMaps: debug, transpilationMode } = argv;
20
25
  return new Promise((resolve, _reject) => {
21
26
  const bundleStream = bundleUtils_1.createBundleStream(dest);
22
- browserify_1.default(src, { debug })
23
- .transform('babelify', {
24
- presets: [
25
- [
26
- '@babel/preset-env',
27
- {
28
- targets: {
29
- browsers: ['chrome >= 66', 'firefox >= 68'],
27
+ const bundler = browserify_1.default(src, { debug });
28
+ if (transpilationMode !== builders_1.TranspilationModes.none) {
29
+ bundler.transform(require('babelify'), {
30
+ global: transpilationMode === builders_1.TranspilationModes.all,
31
+ presets: [
32
+ [
33
+ require('@babel/preset-env'),
34
+ {
35
+ targets: {
36
+ browsers: ['chrome >= 66', 'firefox >= 68'],
37
+ },
30
38
  },
31
- },
39
+ ],
32
40
  ],
33
- ],
34
- plugins: [
35
- '@babel/plugin-transform-runtime',
36
- '@babel/plugin-proposal-class-properties',
37
- '@babel/plugin-proposal-object-rest-spread',
38
- '@babel/plugin-proposal-optional-chaining',
39
- '@babel/plugin-proposal-nullish-coalescing-operator',
40
- ],
41
- })
42
- .bundle(async (bundleError, bundleBuffer) => await bundleUtils_1.closeBundleStream({
41
+ plugins: [
42
+ require('@babel/plugin-transform-runtime'),
43
+ require('@babel/plugin-proposal-class-properties'),
44
+ require('@babel/plugin-proposal-object-rest-spread'),
45
+ require('@babel/plugin-proposal-optional-chaining'),
46
+ require('@babel/plugin-proposal-nullish-coalescing-operator'),
47
+ ],
48
+ });
49
+ }
50
+ bundler.bundle(async (bundleError, bundleBuffer) => await bundleUtils_1.closeBundleStream({
43
51
  bundleError,
44
52
  bundleBuffer,
45
53
  bundleStream,
@@ -1 +1 @@
1
- {"version":3,"file":"bundle.js","sourceRoot":"","sources":["../../../src/cmds/build/bundle.ts"],"names":[],"mappings":";;;;;;AAAA,4DAAoC;AAEpC,+CAAsE;AAEtE;;;;;;;;GAQG;AACH,SAAgB,MAAM,CACpB,GAAW,EACX,IAAY,EACZ,IAAe;IAEf,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;IAEnC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE;QACtC,MAAM,YAAY,GAAG,gCAAkB,CAAC,IAAI,CAAC,CAAC;QAC9C,oBAAU,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,CAAC;aACvB,SAAS,CAAC,UAAU,EAAE;YACrB,OAAO,EAAE;gBACP;oBACE,mBAAmB;oBACnB;wBACE,OAAO,EAAE;4BACP,QAAQ,EAAE,CAAC,cAAc,EAAE,eAAe,CAAC;yBAC5C;qBACF;iBACF;aACF;YACD,OAAO,EAAE;gBACP,iCAAiC;gBACjC,yCAAyC;gBACzC,2CAA2C;gBAC3C,0CAA0C;gBAC1C,oDAAoD;aACrD;SACF,CAAC;aACD,MAAM,CACL,KAAK,EAAE,WAAW,EAAE,YAAoB,EAAE,EAAE,CAC1C,MAAM,+BAAiB,CAAC;YACtB,WAAW;YACX,YAAY;YACZ,YAAY;YACZ,GAAG;YACH,IAAI;YACJ,OAAO;YACP,IAAI;SACL,CAAC,CACL,CAAC;IACN,CAAC,CAAC,CAAC;AACL,CAAC;AA1CD,wBA0CC","sourcesContent":["import browserify from 'browserify';\nimport { YargsArgs } from '../../types/yargs';\nimport { createBundleStream, closeBundleStream } from './bundleUtils';\n\n/**\n * Builds a Snap bundle JSON 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 */\nexport function bundle(\n src: string,\n dest: string,\n argv: YargsArgs,\n): Promise<boolean> {\n const { sourceMaps: debug } = argv;\n\n return new Promise((resolve, _reject) => {\n const bundleStream = createBundleStream(dest);\n browserify(src, { debug })\n .transform('babelify', {\n presets: [\n [\n '@babel/preset-env',\n {\n targets: {\n browsers: ['chrome >= 66', 'firefox >= 68'],\n },\n },\n ],\n ],\n plugins: [\n '@babel/plugin-transform-runtime',\n '@babel/plugin-proposal-class-properties',\n '@babel/plugin-proposal-object-rest-spread',\n '@babel/plugin-proposal-optional-chaining',\n '@babel/plugin-proposal-nullish-coalescing-operator',\n ],\n })\n .bundle(\n async (bundleError, bundleBuffer: Buffer) =>\n await closeBundleStream({\n bundleError,\n bundleBuffer,\n bundleStream,\n src,\n dest,\n resolve,\n argv,\n }),\n );\n });\n}\n"]}
1
+ {"version":3,"file":"bundle.js","sourceRoot":"","sources":["../../../src/cmds/build/bundle.ts"],"names":[],"mappings":";;;;;;AAAA,4DAAoC;AAEpC,6CAAoD;AACpD,+CAAsE;AAEtE,+EAA+E;AAC/E,mEAAmE;AACnE,mHAAmH;AAEnH;;;;;;;;;GASG;AACH,SAAgB,MAAM,CACpB,GAAW,EACX,IAAY,EACZ,IAAe;IAEf,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,iBAAiB,EAAE,GAAG,IAAI,CAAC;IAEtD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE;QACtC,MAAM,YAAY,GAAG,gCAAkB,CAAC,IAAI,CAAC,CAAC;QAC9C,MAAM,OAAO,GAAG,oBAAU,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QAE3C,IAAI,iBAAiB,KAAK,6BAAkB,CAAC,IAAI,EAAE;YACjD,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE;gBACrC,MAAM,EAAE,iBAAiB,KAAK,6BAAkB,CAAC,GAAG;gBACpD,OAAO,EAAE;oBACP;wBACE,OAAO,CAAC,mBAAmB,CAAC;wBAC5B;4BACE,OAAO,EAAE;gCACP,QAAQ,EAAE,CAAC,cAAc,EAAE,eAAe,CAAC;6BAC5C;yBACF;qBACF;iBACF;gBACD,OAAO,EAAE;oBACP,OAAO,CAAC,iCAAiC,CAAC;oBAC1C,OAAO,CAAC,yCAAyC,CAAC;oBAClD,OAAO,CAAC,2CAA2C,CAAC;oBACpD,OAAO,CAAC,0CAA0C,CAAC;oBACnD,OAAO,CAAC,oDAAoD,CAAC;iBAC9D;aACF,CAAC,CAAC;SACJ;QAED,OAAO,CAAC,MAAM,CACZ,KAAK,EAAE,WAAW,EAAE,YAAoB,EAAE,EAAE,CAC1C,MAAM,+BAAiB,CAAC;YACtB,WAAW;YACX,YAAY;YACZ,YAAY;YACZ,GAAG;YACH,IAAI;YACJ,OAAO;YACP,IAAI;SACL,CAAC,CACL,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC;AA/CD,wBA+CC","sourcesContent":["import browserify from 'browserify';\nimport { YargsArgs } from '../../types/yargs';\nimport { TranspilationModes } from '../../builders';\nimport { createBundleStream, closeBundleStream } from './bundleUtils';\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 JSON 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 */\nexport function bundle(\n src: string,\n dest: string,\n argv: YargsArgs,\n): Promise<boolean> {\n const { sourceMaps: debug, transpilationMode } = argv;\n\n return new Promise((resolve, _reject) => {\n const bundleStream = createBundleStream(dest);\n const bundler = browserify(src, { debug });\n\n if (transpilationMode !== TranspilationModes.none) {\n bundler.transform(require('babelify'), {\n global: transpilationMode === TranspilationModes.all,\n presets: [\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 });\n }\n\n bundler.bundle(\n async (bundleError, bundleBuffer: Buffer) =>\n await closeBundleStream({\n bundleError,\n bundleBuffer,\n bundleStream,\n src,\n dest,\n resolve,\n argv,\n }),\n );\n });\n}\n"]}
@@ -9,13 +9,14 @@ module.exports = {
9
9
  desc: 'Build Snap from source',
10
10
  builder: (yarg) => {
11
11
  yarg
12
- .option('src', builders_1.default.src)
13
12
  .option('dist', builders_1.default.dist)
13
+ .option('eval', builders_1.default.eval)
14
+ .option('manifest', builders_1.default.manifest)
14
15
  .option('outfileName', builders_1.default.outfileName)
15
16
  .option('sourceMaps', builders_1.default.sourceMaps)
17
+ .option('src', builders_1.default.src)
16
18
  .option('stripComments', builders_1.default.stripComments)
17
- .option('eval', builders_1.default.eval)
18
- .option('manifest', builders_1.default.manifest)
19
+ .option('transpilationMode', builders_1.default.transpilationMode)
19
20
  .option('writeManifest', builders_1.default.writeManifest)
20
21
  .implies('writeManifest', 'manifest');
21
22
  },
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cmds/build/index.ts"],"names":[],"mappings":";;;;AACA,8DAAsC;AAEtC,iDAAuC;AAEvC,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,KAAK,EAAE,kBAAQ,CAAC,GAAG,CAAC;aAC3B,MAAM,CAAC,MAAM,EAAE,kBAAQ,CAAC,IAAI,CAAC;aAC7B,MAAM,CAAC,aAAa,EAAE,kBAAQ,CAAC,WAAW,CAAC;aAC3C,MAAM,CAAC,YAAY,EAAE,kBAAQ,CAAC,UAAU,CAAC;aACzC,MAAM,CAAC,eAAe,EAAE,kBAAQ,CAAC,aAAa,CAAC;aAC/C,MAAM,CAAC,MAAM,EAAE,kBAAQ,CAAC,IAAI,CAAC;aAC7B,MAAM,CAAC,UAAU,EAAE,kBAAQ,CAAC,QAAQ,CAAC;aACrC,MAAM,CAAC,eAAe,EAAE,kBAAQ,CAAC,aAAa,CAAC;aAC/C,OAAO,CAAC,eAAe,EAAE,UAAU,CAAC,CAAC;IAC1C,CAAC;IACD,OAAO,EAAE,CAAC,IAAe,EAAE,EAAE,CAAC,oBAAK,CAAC,IAAI,CAAC;CAC1C,CAAC","sourcesContent":["import yargs from 'yargs';\nimport builders from '../../builders';\nimport { YargsArgs } from '../../types/yargs';\nimport { build } from './buildHandler';\n\nexport = {\n command: ['build', 'b'],\n desc: 'Build Snap from source',\n builder: (yarg: yargs.Argv) => {\n yarg\n .option('src', builders.src)\n .option('dist', builders.dist)\n .option('outfileName', builders.outfileName)\n .option('sourceMaps', builders.sourceMaps)\n .option('stripComments', builders.stripComments)\n .option('eval', builders.eval)\n .option('manifest', builders.manifest)\n .option('writeManifest', builders.writeManifest)\n .implies('writeManifest', 'manifest');\n },\n handler: (argv: YargsArgs) => build(argv),\n};\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cmds/build/index.ts"],"names":[],"mappings":";;;;AACA,8DAAsC;AAEtC,iDAAuC;AAEvC,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,eAAe,EAAE,kBAAQ,CAAC,aAAa,CAAC;aAC/C,OAAO,CAAC,eAAe,EAAE,UAAU,CAAC,CAAC;IAC1C,CAAC;IACD,OAAO,EAAE,CAAC,IAAe,EAAE,EAAE,CAAC,oBAAK,CAAC,IAAI,CAAC;CAC1C,CAAC","sourcesContent":["import yargs from 'yargs';\nimport builders from '../../builders';\nimport { YargsArgs } from '../../types/yargs';\nimport { build } from './buildHandler';\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('writeManifest', builders.writeManifest)\n .implies('writeManifest', 'manifest');\n },\n handler: (argv: YargsArgs) => build(argv),\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/snaps-cli",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "A CLI for developing MetaMask Snaps.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -43,7 +43,7 @@
43
43
  "@babel/plugin-proposal-optional-chaining": "^7.16.7",
44
44
  "@babel/plugin-transform-runtime": "^7.16.7",
45
45
  "@babel/preset-env": "^7.16.7",
46
- "@metamask/snap-controllers": "^0.8.0",
46
+ "@metamask/snap-controllers": "^0.9.0",
47
47
  "@nodefactory/strip-comments": "^1.0.2",
48
48
  "babelify": "^10.0.0",
49
49
  "browserify": "^17.0.0",