@metamask/snaps-cli 0.8.0 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/CHANGELOG.md +42 -1
  2. package/README.md +62 -20
  3. package/dist/builders.d.ts +16 -8
  4. package/dist/builders.js +66 -41
  5. package/dist/builders.js.map +1 -1
  6. package/dist/cli.js +3 -2
  7. package/dist/cli.js.map +1 -1
  8. package/dist/cmds/build/buildHandler.js +1 -1
  9. package/dist/cmds/build/buildHandler.js.map +1 -1
  10. package/dist/cmds/build/bundle.d.ts +9 -7
  11. package/dist/cmds/build/bundle.js +35 -31
  12. package/dist/cmds/build/bundle.js.map +1 -1
  13. package/dist/cmds/build/index.js +10 -4
  14. package/dist/cmds/build/index.js.map +1 -1
  15. package/dist/cmds/build/utils.d.ts +59 -0
  16. package/dist/cmds/build/utils.js +148 -0
  17. package/dist/cmds/build/utils.js.map +1 -0
  18. package/dist/cmds/init/initHandler.d.ts +2 -0
  19. package/dist/cmds/init/initHandler.js +6 -1
  20. package/dist/cmds/init/initHandler.js.map +1 -1
  21. package/dist/cmds/watch/index.js +11 -1
  22. package/dist/cmds/watch/index.js.map +1 -1
  23. package/dist/cmds/watch/watchHandler.js +32 -19
  24. package/dist/cmds/watch/watchHandler.js.map +1 -1
  25. package/dist/utils/misc.d.ts +10 -1
  26. package/dist/utils/misc.js +25 -4
  27. package/dist/utils/misc.js.map +1 -1
  28. package/dist/utils/snap-config.__GENERATED__.d.ts +2 -0
  29. package/dist/utils/snap-config.__GENERATED__.js +18 -0
  30. package/dist/utils/snap-config.__GENERATED__.js.map +1 -0
  31. package/dist/utils/snap-config.d.ts +8 -1
  32. package/dist/utils/snap-config.js +39 -32
  33. package/dist/utils/snap-config.js.map +1 -1
  34. package/package.json +11 -8
  35. package/dist/cmds/build/bundleUtils.d.ts +0 -42
  36. package/dist/cmds/build/bundleUtils.js +0 -95
  37. package/dist/cmds/build/bundleUtils.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -6,6 +6,44 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.10.1]
10
+ ### Fixed
11
+ - Comment stripping will no longer remove empty block comments in strings ([#276](https://github.com/MetaMask/snaps-skunkworks/pull/276))
12
+
13
+ ## [0.10.0]
14
+ ### Added
15
+ - **BREAKING:** Transform HTML comments by default ([#237](https://github.com/MetaMask/snaps-skunkworks/pull/237))
16
+ - The strings `<!--` and `-->` will be transformed into `< !--` and `-- >` respectively by default. If these strings appear as operands in an expression or in a string literal, this transform will change the behavior of your program. This behavior was added because these strings are rejected by SES. The behavior can be toggled using the `--transformHtmlComments` option.
17
+ - `--transpiledDeps` flag to `build` and `watch` commands ([#221](https://github.com/MetaMask/snaps-skunkworks/pull/221))
18
+ - This flag allows the user to specify which dependencies will be transpiled at build time if the `--transpilationMode` is `--localAndDeps`.
19
+ - Add CLI usage instructions to readme ([#228](https://github.com/MetaMask/snaps-skunkworks/pull/228))
20
+ - Build process customization ([#251](https://github.com/MetaMask/snaps-skunkworks/pull/251))
21
+ - Builds can now be customized by adding a `bundlerCustomizer` function to `snap.config.js`. See the README for details.
22
+
23
+ ### Changed
24
+ - **BREAKING:** Change Snap config file format ([#251](https://github.com/MetaMask/snaps-skunkworks/pull/251))
25
+ - The CLI now expects a file `snap.config.js` instead of `snap.config.json`, with a different structure. See the README for details.
26
+ - **BREAKING:** Strip comments in source code by default ([#243](https://github.com/MetaMask/snaps-skunkworks/pull/243))
27
+ - All comments will now be stripped from snap source code (including dependencies) by default.
28
+ - Enable `--verboseErrors` by default ([#249](https://github.com/MetaMask/snaps-skunkworks/pull/249))
29
+
30
+ ### Fixed
31
+ - Comment stripping bug ([#270](https://github.com/MetaMask/snaps-skunkworks/pull/270))
32
+ - Prior to this change, if the `--strip-comments` option was provided to `mm-snap build` and an empty block comment of the form `/**/` appeared anywhere in the source code (including dependencies), the remainder of the string after the empty block comment would be truncated. This was resolved by removing all instances of the string `/**/` from the raw bundle string.
33
+ - In an upcoming release, the string `/**/` will only be removed if it is in fact an empty block comment, and not if it e.g. appears in a string literal.
34
+ - `watch` command parity with `build` command ([#241](https://github.com/MetaMask/snaps-skunkworks/pull/241))
35
+ - The `build` command had received a number of options that were not made available to the `watch` command. They now have the same options.
36
+ - Update dead link in readme ([#240](https://github.com/MetaMask/snaps-skunkworks/pull/240))
37
+
38
+ ## [0.9.0]
39
+ ### Added
40
+ - Transpilation configuration ([#213](https://github.com/MetaMask/snaps-skunkworks/pull/213))
41
+ - `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.
42
+
43
+ ### Fixed
44
+ - `mm-snap build` command when CLI is installed globally ([#216](https://github.com/MetaMask/snaps-skunkworks/pull/216))
45
+ - Update installation command in readme ([#205](https://github.com/MetaMask/snaps-skunkworks/pull/205))
46
+
9
47
  ## [0.8.0]
10
48
  ### Changed
11
49
  - Update template snap created by `mm-snap init` ([#195](https://github.com/MetaMask/snaps-skunkworks/pull/195))
@@ -89,7 +127,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
89
127
  - Example snaps ([#72](https://github.com/MetaMask/snaps-skunkworks/pull/72))
90
128
  - The examples now live in their own package, [`@metamask/snap-examples`](https://npmjs.com/package/@metamask/snap-examples).
91
129
 
92
- [Unreleased]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.8.0...HEAD
130
+ [Unreleased]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.10.1...HEAD
131
+ [0.10.1]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.10.0...v0.10.1
132
+ [0.10.0]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.9.0...v0.10.0
133
+ [0.9.0]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.8.0...v0.9.0
93
134
  [0.8.0]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.7.0...v0.8.0
94
135
  [0.7.0]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.6.3...v0.7.0
95
136
  [0.6.3]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.6.2...v0.6.3
package/README.md CHANGED
@@ -7,14 +7,42 @@ 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
+ Install a dev dependency in your snap project or globally using `yarn` or `npm`:
11
11
 
12
- ## Basic Usage
12
+ - `npm install -g @metamask/snaps-cli`
13
+ - `yarn global add @metamask/snaps-cli`
13
14
 
14
- ```bash
15
- mkdir mySnap
16
- cd mySnap
17
- mm-snap init
15
+ ## Usage
16
+
17
+ ```text
18
+ Usage: mm-snap <command> [options]
19
+
20
+ Commands:
21
+ mm-snap build Build Snap from source [aliases: b]
22
+ mm-snap eval Attempt to evaluate Snap bundle in SES [aliases: e]
23
+ mm-snap init Initialize Snap package [aliases: i]
24
+ mm-snap manifest Validate the snap.manifest.json file [aliases: m]
25
+ mm-snap serve Locally serve Snap file(s) for testing [aliases: s]
26
+ mm-snap watch Build Snap on change [aliases: w]
27
+
28
+ Options:
29
+ --version Show version number [boolean]
30
+ --verboseErrors Display original errors [boolean] [default: true]
31
+ --suppressWarnings Whether to suppress warnings[boolean] [default: false]
32
+ -h, --help Show help [boolean]
33
+
34
+ Examples:
35
+ mm-snap init Initialize a snap project in the
36
+ current directory
37
+ mm-snap build -s src/index.js -d out Build 'src/index.js' as
38
+ './out/bundle.js'
39
+ mm-snap build -s src/index.js -d out -n Build 'src/index.js' as
40
+ snap.js './out/snap.js'
41
+ mm-snap serve -r out Serve files in './out' on port 8080
42
+ mm-snap serve -r out -p 9000 Serve files in './out' on port 9000
43
+ mm-snap watch -s src/index.js -d out Rebuild './out/bundle.js' on changes
44
+ to files in 'src/index.js' parent
45
+ and child directories
18
46
  ```
19
47
 
20
48
  ## MetaMask Snaps
@@ -60,7 +88,7 @@ Here's an example manifest:
60
88
  }
61
89
  ```
62
90
 
63
- Refer to [the Snaps publishing specification](https://github.com/MetaMask/specifications/blob/main/snaps/publishing.md) and the [manifest JSON schema](https://github.com/MetaMask/specifications/blob/main/snaps/schemas/snap-manifest.schema.json) for details.
91
+ Refer to [the Snaps publishing specification](https://github.com/MetaMask/specifications/blob/main/snaps/publishing.md) and the [manifest JSON schema](https://github.com/MetaMask/snaps-skunkworks/blob/main/packages/controllers/src/snaps/json-schemas/snap-manifest.schema.json) for details.
64
92
 
65
93
  > **ATTN:** If your Snap is not compatible with the publishing specification, your Snap may not work properly or install at all.
66
94
 
@@ -80,25 +108,39 @@ snap-project/
80
108
  ```
81
109
 
82
110
  Source files other than `index.js` are located through its imports.
83
- The defaults can be overwritten using the `snap.config.json` config file,
84
- [see below](#configuration-file).
111
+ The defaults can be overwritten using the `snap.config.json` [config file](#configuration-file).
85
112
 
86
- ## Usage
113
+ ### Configuration File
87
114
 
88
- Run `mm-snap --help` for usage instructions.
115
+ `snap.config.js` can be placed in the project root directory. It can override cli options - the property `cliOptions` should have string keys matching command arguments. Values become argument defaults, which can still be overriden on the command line.
89
116
 
90
- ### Configuration File
117
+ Example:
118
+
119
+ ```javascript
120
+ module.exports = {
121
+ cliOptions: {
122
+ src: 'lib/index.js',
123
+ dist: 'out',
124
+ port: 9000,
125
+ },
126
+ };
127
+ ```
128
+
129
+ Should you want to customize your build process, you can provide `bundlerCustomizer` property. It's a function that takes one argument - [browserify object](https://github.com/browserify/browserify#api-example) which we use internally to bundle the snap. You can transform it in any way you want, for example adding plugins.
91
130
 
92
- `snap.config.json` can be placed in the project root directory. It should have string keys matching command arguments.
93
- Values become argument defaults, which can still be overriden on the command line.
94
131
  Example:
95
132
 
96
- ```json
97
- {
98
- "src": "lib",
99
- "dist": "out",
100
- "port": 9000
101
- }
133
+ ```javascript
134
+ const brfs = require('brfs');
135
+
136
+ module.exports = {
137
+ cliOptions: {
138
+ /* ... */
139
+ },
140
+ bundlerCustomizer: (bundler) => {
141
+ bundler.transform(brfs);
142
+ },
143
+ };
102
144
  ```
103
145
 
104
146
  The configuration file should not be published.
@@ -1,18 +1,26 @@
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 transformHtmlComments: Readonly<Options>;
16
+ readonly depsToTranspile: Readonly<Options>;
17
+ readonly verboseErrors: Readonly<Options>;
18
+ readonly writeManifest: Readonly<Options>;
16
19
  };
20
+ export declare enum TranspilationModes {
21
+ localAndDeps = "localAndDeps",
22
+ localOnly = "localOnly",
23
+ none = "none"
24
+ }
17
25
  declare const builders: SnapsCliBuilders;
18
26
  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["localAndDeps"] = "localAndDeps";
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,57 +52,77 @@ 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',
59
87
  type: 'boolean',
60
88
  demandOption: false,
61
- default: false,
89
+ default: true,
62
90
  },
63
- outfileName: {
64
- alias: 'n',
65
- describe: 'Output file name',
66
- type: 'string',
91
+ suppressWarnings: {
92
+ type: 'boolean',
93
+ describe: 'Whether to suppress warnings',
67
94
  demandOption: false,
68
- default: 'bundle.js',
95
+ default: false,
69
96
  },
70
- manifest: {
71
- alias: 'm',
72
- describe: 'Validate snap.manifest.json',
73
- 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.',
74
100
  demandOption: false,
75
- default: true,
101
+ default: TranspilationModes.localOnly,
102
+ choices: Object.values(TranspilationModes),
76
103
  },
77
- writeManifest: {
78
- describe: 'Make necessary changes to the Snap manifest file',
104
+ transformHtmlComments: {
79
105
  type: 'boolean',
80
- demandOption: false,
106
+ describe: 'Whether to break up HTML comment tokens wherever they appear in your source code.',
107
+ demandOption: true,
81
108
  default: true,
82
109
  },
83
- eval: {
84
- alias: 'e',
85
- describe: 'Attempt to evaluate Snap bundle in SES',
86
- type: 'boolean',
110
+ depsToTranspile: {
111
+ type: 'array',
112
+ describe: 'Transpile only the listed dependencies.',
87
113
  demandOption: false,
88
- default: true,
89
114
  },
90
115
  verboseErrors: {
91
116
  type: 'boolean',
92
117
  describe: 'Display original errors',
93
118
  demandOption: false,
94
- default: false,
119
+ default: true,
95
120
  },
96
- suppressWarnings: {
121
+ writeManifest: {
122
+ describe: 'Make necessary changes to the Snap manifest file',
97
123
  type: 'boolean',
98
- describe: 'Suppress warnings',
99
124
  demandOption: false,
100
- default: false,
125
+ default: true,
101
126
  },
102
127
  };
103
128
  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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SAAS;QACf,YAAY,EAAE,KAAK;QACnB,OAAO,EAAE,KAAK;KACf;IAED,WAAW,EAAE;QACX,KAAK,EAAE,GAAG;QACV,QAAQ,EAAE,kBAAkB;QAC5B,IAAI,EAAE,QAAQ;QACd,YAAY,EAAE,KAAK;QACnB,OAAO,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":";;;AAqBA,IAAY,kBAIX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QACb,QAAQ,EAAE,yCAAyC;QACnD,YAAY,EAAE,KAAK;KACpB;IAED,aAAa,EAAE;QACb,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,yBAAyB;QACnC,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;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 transformHtmlComments: Readonly<Options>;\n readonly depsToTranspile: Readonly<Options>;\n readonly verboseErrors: Readonly<Options>;\n readonly writeManifest: Readonly<Options>;\n};\n\nexport enum TranspilationModes {\n localAndDeps = 'localAndDeps',\n localOnly = 'localOnly',\n none = 'none',\n}\n\nconst builders: SnapsCliBuilders = {\n bundle: {\n alias: 'b',\n describe: 'Snap bundle file',\n type: 'string',\n demandOption: true,\n normalize: true,\n default: 'dist/bundle.js',\n },\n\n dist: {\n alias: 'd',\n describe: 'Output directory',\n type: 'string',\n demandOption: true,\n normalize: true,\n default: 'dist',\n },\n\n eval: {\n alias: 'e',\n describe: 'Attempt to evaluate Snap bundle in SES',\n type: 'boolean',\n demandOption: false,\n default: true,\n },\n\n manifest: {\n alias: 'm',\n describe: 'Validate snap.manifest.json',\n type: 'boolean',\n demandOption: false,\n default: true,\n },\n\n port: {\n alias: 'p',\n describe: 'Local server port for testing',\n type: 'number',\n demandOption: true,\n default: 8081,\n coerce: (arg: unknown) => {\n const port = Number.parseInt(String(arg), 10);\n if (Number.isNaN(port)) {\n throw new Error(`Invalid port: ${arg}`);\n }\n return port;\n },\n },\n\n outfileName: {\n alias: 'n',\n describe: 'Output file name',\n type: 'string',\n demandOption: false,\n default: 'bundle.js',\n },\n\n root: {\n alias: 'r',\n describe: 'Server root directory',\n type: 'string',\n demandOption: true,\n normalize: true,\n default: '.',\n },\n\n sourceMaps: {\n describe: 'Whether builds include sourcemaps',\n type: 'boolean',\n demandOption: false,\n default: false,\n },\n\n src: {\n alias: 's',\n describe: 'Source file',\n type: 'string',\n demandOption: true,\n normalize: true,\n default: 'src/index.js',\n },\n\n stripComments: {\n alias: 'strip',\n describe: 'Whether to remove code comments from the build output',\n type: 'boolean',\n demandOption: false,\n default: true,\n },\n\n suppressWarnings: {\n type: 'boolean',\n describe: 'Whether to suppress warnings',\n demandOption: false,\n default: false,\n },\n\n transpilationMode: {\n type: 'string',\n describe:\n 'Whether to use Babel to transpile all source code (including dependencies), local source code only, or nothing.',\n demandOption: false,\n default: TranspilationModes.localOnly,\n choices: Object.values(TranspilationModes),\n },\n\n transformHtmlComments: {\n type: 'boolean',\n describe:\n 'Whether to break up HTML comment tokens wherever they appear in your source code.',\n demandOption: true,\n default: true,\n },\n\n depsToTranspile: {\n type: 'array',\n describe: 'Transpile only the listed dependencies.',\n demandOption: false,\n },\n\n verboseErrors: {\n type: 'boolean',\n describe: 'Display original errors',\n demandOption: false,\n default: true,\n },\n\n writeManifest: {\n describe: 'Make necessary changes to the Snap manifest file',\n type: 'boolean',\n demandOption: false,\n default: true,\n },\n};\n\nexport default builders;\n"]}
package/dist/cli.js CHANGED
@@ -11,8 +11,9 @@ function cli(argv, commands) {
11
11
  const rawArgv = argv.slice(2);
12
12
  // eslint-disable-next-line @typescript-eslint/no-unused-expressions
13
13
  yargs_1.default(rawArgv)
14
+ .scriptName('mm-snap')
14
15
  .usage('Usage: $0 <command> [options]')
15
- .example('$0 init', `\tInitialize Snap package from scratch`)
16
+ .example('$0 init', `\tInitialize a snap project in the current directory`)
16
17
  .example('$0 build -s src/index.js -d out', `\tBuild 'src/index.js' as './out/bundle.js'`)
17
18
  .example('$0 build -s src/index.js -d out -n snap.js', `\tBuild 'src/index.js' as './out/snap.js'`)
18
19
  .example('$0 serve -r out', `\tServe files in './out' on port 8080`)
@@ -26,7 +27,7 @@ function cli(argv, commands) {
26
27
  // yargs middleware functions receive the yargs instance as a second parameter.
27
28
  // ref: https://yargs.js.org/docs/#api-reference-middlewarecallbacks-applybeforevalidation
28
29
  .middleware(((yargsArgv, yargsInstance) => {
29
- utils_1.applyConfig(rawArgv, yargsArgv, yargsInstance);
30
+ utils_1.applyConfig(utils_1.loadConfig(), rawArgv, yargsArgv, yargsInstance);
30
31
  utils_1.setSnapGlobals(yargsArgv);
31
32
  utils_1.sanitizeInputs(yargsArgv);
32
33
  }), true)
package/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAyC;AAEzC,0DAAkC;AAClC,mCAAsE;AAEtE,SAAgB,GAAG,CAAC,IAAc,EAAE,QAAa;IAC/C,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC9B,oEAAoE;IACpE,eAAK,CAAC,OAAO,CAAC;SACX,KAAK,CAAC,+BAA+B,CAAC;SAEtC,OAAO,CAAC,SAAS,EAAE,wCAAwC,CAAC;SAC5D,OAAO,CACN,iCAAiC,EACjC,6CAA6C,CAC9C;SACA,OAAO,CACN,4CAA4C,EAC5C,2CAA2C,CAC5C;SACA,OAAO,CAAC,iBAAiB,EAAE,uCAAuC,CAAC;SACnE,OAAO,CAAC,yBAAyB,EAAE,uCAAuC,CAAC;SAC3E,OAAO,CACN,iCAAiC,EACjC,gGAAgG,CACjG;SAEA,OAAO,CAAC,QAAQ,CAAC;SAEjB,MAAM,CAAC,eAAe,EAAE,kBAAQ,CAAC,aAAa,CAAC;SAE/C,MAAM,CAAC,kBAAkB,EAAE,kBAAQ,CAAC,gBAAgB,CAAC;SAErD,MAAM,EAAE;QAET,gEAAgE;QAChE,+EAA+E;QAC/E,0FAA0F;SACzF,UAAU,CACT,CAAC,CAAC,SAAoB,EAAE,aAA+B,EAAE,EAAE;QACzD,mBAAW,CAAC,OAAO,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC;QAC/C,sBAAc,CAAC,SAAS,CAAC,CAAC;QAC1B,sBAAc,CAAC,SAAS,CAAC,CAAC;IAC5B,CAAC,CAAQ,EACT,IAAI,CACL;SAEA,IAAI,CAAC,CAAC,GAAW,EAAE,GAAU,EAAE,MAAM,EAAE,EAAE;QACxC,OAAO,CAAC,KAAK,CAAC,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC;QAClC,IAAI,CAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,KAAK,KAAI,MAAM,CAAC,KAAK,CAAC,aAAa,EAAE;YAC5C,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;SAC1B;QACD,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACvB,CAAC,CAAC;SAED,aAAa,CAAC,CAAC,EAAE,wCAAwC,CAAC;SAE1D,IAAI,EAAE;SACN,KAAK,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC;AAC7B,CAAC;AAtDD,kBAsDC","sourcesContent":["import yargs, { Arguments } from 'yargs';\nimport yargsType from 'yargs/yargs';\nimport builders from './builders';\nimport { applyConfig, sanitizeInputs, setSnapGlobals } from './utils';\n\nexport function cli(argv: string[], commands: any): void {\n const rawArgv = argv.slice(2);\n // eslint-disable-next-line @typescript-eslint/no-unused-expressions\n yargs(rawArgv)\n .usage('Usage: $0 <command> [options]')\n\n .example('$0 init', `\\tInitialize Snap package from scratch`)\n .example(\n '$0 build -s src/index.js -d out',\n `\\tBuild 'src/index.js' as './out/bundle.js'`,\n )\n .example(\n '$0 build -s src/index.js -d out -n snap.js',\n `\\tBuild 'src/index.js' as './out/snap.js'`,\n )\n .example('$0 serve -r out', `\\tServe files in './out' on port 8080`)\n .example('$0 serve -r out -p 9000', `\\tServe files in './out' on port 9000`)\n .example(\n '$0 watch -s src/index.js -d out',\n `\\tRebuild './out/bundle.js' on changes to files in 'src/index.js' parent and child directories`,\n )\n\n .command(commands)\n\n .option('verboseErrors', builders.verboseErrors)\n\n .option('suppressWarnings', builders.suppressWarnings)\n\n .strict()\n\n // Typecast: The @types/yargs type for .middleware is incorrect.\n // yargs middleware functions receive the yargs instance as a second parameter.\n // ref: https://yargs.js.org/docs/#api-reference-middlewarecallbacks-applybeforevalidation\n .middleware(\n ((yargsArgv: Arguments, yargsInstance: typeof yargsType) => {\n applyConfig(rawArgv, yargsArgv, yargsInstance);\n setSnapGlobals(yargsArgv);\n sanitizeInputs(yargsArgv);\n }) as any,\n true,\n )\n\n .fail((msg: string, err: Error, _yargs) => {\n console.error(msg || err.message);\n if (err?.stack && global.snaps.verboseErrors) {\n console.error(err.stack);\n }\n process.exitCode = 1;\n })\n\n .demandCommand(1, 'You must specify at least one command.')\n\n .help()\n .alias('help', 'h').argv;\n}\n"]}
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAyC;AAEzC,0DAAkC;AAClC,mCAKiB;AAEjB,SAAgB,GAAG,CAAC,IAAc,EAAE,QAAa;IAC/C,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC9B,oEAAoE;IACpE,eAAK,CAAC,OAAO,CAAC;SACX,UAAU,CAAC,SAAS,CAAC;SACrB,KAAK,CAAC,+BAA+B,CAAC;SAEtC,OAAO,CAAC,SAAS,EAAE,sDAAsD,CAAC;SAC1E,OAAO,CACN,iCAAiC,EACjC,6CAA6C,CAC9C;SACA,OAAO,CACN,4CAA4C,EAC5C,2CAA2C,CAC5C;SACA,OAAO,CAAC,iBAAiB,EAAE,uCAAuC,CAAC;SACnE,OAAO,CAAC,yBAAyB,EAAE,uCAAuC,CAAC;SAC3E,OAAO,CACN,iCAAiC,EACjC,gGAAgG,CACjG;SAEA,OAAO,CAAC,QAAQ,CAAC;SAEjB,MAAM,CAAC,eAAe,EAAE,kBAAQ,CAAC,aAAa,CAAC;SAE/C,MAAM,CAAC,kBAAkB,EAAE,kBAAQ,CAAC,gBAAgB,CAAC;SAErD,MAAM,EAAE;QAET,gEAAgE;QAChE,+EAA+E;QAC/E,0FAA0F;SACzF,UAAU,CACT,CAAC,CAAC,SAAoB,EAAE,aAA+B,EAAE,EAAE;QACzD,mBAAW,CAAC,kBAAU,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC;QAC7D,sBAAc,CAAC,SAAS,CAAC,CAAC;QAC1B,sBAAc,CAAC,SAAS,CAAC,CAAC;IAC5B,CAAC,CAAQ,EACT,IAAI,CACL;SAEA,IAAI,CAAC,CAAC,GAAW,EAAE,GAAU,EAAE,MAAM,EAAE,EAAE;QACxC,OAAO,CAAC,KAAK,CAAC,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC;QAClC,IAAI,CAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,KAAK,KAAI,MAAM,CAAC,KAAK,CAAC,aAAa,EAAE;YAC5C,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;SAC1B;QACD,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACvB,CAAC,CAAC;SAED,aAAa,CAAC,CAAC,EAAE,wCAAwC,CAAC;SAE1D,IAAI,EAAE;SACN,KAAK,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC;AAC7B,CAAC;AAvDD,kBAuDC","sourcesContent":["import yargs, { Arguments } from 'yargs';\nimport yargsType from 'yargs/yargs';\nimport builders from './builders';\nimport {\n applyConfig,\n loadConfig,\n sanitizeInputs,\n setSnapGlobals,\n} from './utils';\n\nexport function cli(argv: string[], commands: any): void {\n const rawArgv = argv.slice(2);\n // eslint-disable-next-line @typescript-eslint/no-unused-expressions\n yargs(rawArgv)\n .scriptName('mm-snap')\n .usage('Usage: $0 <command> [options]')\n\n .example('$0 init', `\\tInitialize a snap project in the current directory`)\n .example(\n '$0 build -s src/index.js -d out',\n `\\tBuild 'src/index.js' as './out/bundle.js'`,\n )\n .example(\n '$0 build -s src/index.js -d out -n snap.js',\n `\\tBuild 'src/index.js' as './out/snap.js'`,\n )\n .example('$0 serve -r out', `\\tServe files in './out' on port 8080`)\n .example('$0 serve -r out -p 9000', `\\tServe files in './out' on port 9000`)\n .example(\n '$0 watch -s src/index.js -d out',\n `\\tRebuild './out/bundle.js' on changes to files in 'src/index.js' parent and child directories`,\n )\n\n .command(commands)\n\n .option('verboseErrors', builders.verboseErrors)\n\n .option('suppressWarnings', builders.suppressWarnings)\n\n .strict()\n\n // Typecast: The @types/yargs type for .middleware is incorrect.\n // yargs middleware functions receive the yargs instance as a second parameter.\n // ref: https://yargs.js.org/docs/#api-reference-middlewarecallbacks-applybeforevalidation\n .middleware(\n ((yargsArgv: Arguments, yargsInstance: typeof yargsType) => {\n applyConfig(loadConfig(), rawArgv, yargsArgv, yargsInstance);\n setSnapGlobals(yargsArgv);\n sanitizeInputs(yargsArgv);\n }) as any,\n true,\n )\n\n .fail((msg: string, err: Error, _yargs) => {\n console.error(msg || err.message);\n if (err?.stack && global.snaps.verboseErrors) {\n console.error(err.stack);\n }\n process.exitCode = 1;\n })\n\n .demandCommand(1, 'You must specify at least one command.')\n\n .help()\n .alias('help', 'h').argv;\n}\n"]}
@@ -24,7 +24,7 @@ async function build(argv) {
24
24
  await utils_1.validateFilePath(src);
25
25
  await utils_1.validateDirPath(dist, true);
26
26
  const outfilePath = utils_1.getOutfilePath(dist, outfileName);
27
- const result = await bundle_1.bundle(src, outfilePath, argv);
27
+ const result = await bundle_1.bundle(src, outfilePath, argv, utils_1.loadConfig().bundlerCustomizer);
28
28
  if (result && argv.eval) {
29
29
  await evalHandler_1.snapEval(Object.assign(Object.assign({}, argv), { bundle: outfilePath }));
30
30
  }
@@ -1 +1 @@
1
- {"version":3,"file":"buildHandler.js","sourceRoot":"","sources":["../../../src/cmds/build/buildHandler.ts"],"names":[],"mappings":";;;AAAA,uCAKqB;AACrB,qDAA+C;AAC/C,iEAA8D;AAE9D,qCAAkC;AAElC;;;;;;;;;;GAUG;AACI,KAAK,UAAU,KAAK,CAAC,IAAe;IACzC,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC;IACxC,IAAI,WAAW,EAAE;QACf,2BAAmB,CAAC,WAAqB,CAAC,CAAC;KAC5C;IACD,MAAM,wBAAgB,CAAC,GAAG,CAAC,CAAC;IAC5B,MAAM,uBAAe,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAElC,MAAM,WAAW,GAAG,sBAAc,CAAC,IAAI,EAAE,WAAqB,CAAC,CAAC;IAChE,MAAM,MAAM,GAAG,MAAM,eAAM,CAAC,GAAG,EAAE,WAAW,EAAE,IAAI,CAAC,CAAC;IACpD,IAAI,MAAM,IAAI,IAAI,CAAC,IAAI,EAAE;QACvB,MAAM,sBAAQ,iCAAM,IAAI,KAAE,MAAM,EAAE,WAAW,IAAG,CAAC;KAClD;IAED,IAAI,IAAI,CAAC,QAAQ,EAAE;QACjB,MAAM,iCAAe,CAAC,IAAI,CAAC,CAAC;KAC7B;AACH,CAAC;AAjBD,sBAiBC","sourcesContent":["import {\n getOutfilePath,\n validateDirPath,\n validateFilePath,\n validateOutfileName,\n} from '../../utils';\nimport { snapEval } from '../eval/evalHandler';\nimport { manifestHandler } from '../manifest/manifestHandler';\nimport { YargsArgs } from '../../types/yargs';\nimport { bundle } from './bundle';\n\n/**\n * Builds all files in the given source directory to the given destination\n * directory.\n *\n * Creates destination directory if it doesn't exist.\n *\n * @param argv - argv from Yargs\n * @param argv.src - The source file path\n * @param argv.dist - The output directory path\n * @param argv.outfileName - The output file name\n */\nexport async function build(argv: YargsArgs): Promise<void> {\n const { src, dist, outfileName } = argv;\n if (outfileName) {\n validateOutfileName(outfileName as string);\n }\n await validateFilePath(src);\n await validateDirPath(dist, true);\n\n const outfilePath = getOutfilePath(dist, outfileName as string);\n const result = await bundle(src, outfilePath, argv);\n if (result && argv.eval) {\n await snapEval({ ...argv, bundle: outfilePath });\n }\n\n if (argv.manifest) {\n await manifestHandler(argv);\n }\n}\n"]}
1
+ {"version":3,"file":"buildHandler.js","sourceRoot":"","sources":["../../../src/cmds/build/buildHandler.ts"],"names":[],"mappings":";;;AACA,uCAMqB;AACrB,qDAA+C;AAC/C,iEAA8D;AAC9D,qCAAkC;AAElC;;;;;;;;;;GAUG;AACI,KAAK,UAAU,KAAK,CAAC,IAAe;IACzC,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC;IACxC,IAAI,WAAW,EAAE;QACf,2BAAmB,CAAC,WAAqB,CAAC,CAAC;KAC5C;IACD,MAAM,wBAAgB,CAAC,GAAG,CAAC,CAAC;IAC5B,MAAM,uBAAe,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAElC,MAAM,WAAW,GAAG,sBAAc,CAAC,IAAI,EAAE,WAAqB,CAAC,CAAC;IAChE,MAAM,MAAM,GAAG,MAAM,eAAM,CACzB,GAAG,EACH,WAAW,EACX,IAAI,EACJ,kBAAU,EAAE,CAAC,iBAAiB,CAC/B,CAAC;IACF,IAAI,MAAM,IAAI,IAAI,CAAC,IAAI,EAAE;QACvB,MAAM,sBAAQ,iCAAM,IAAI,KAAE,MAAM,EAAE,WAAW,IAAG,CAAC;KAClD;IAED,IAAI,IAAI,CAAC,QAAQ,EAAE;QACjB,MAAM,iCAAe,CAAC,IAAI,CAAC,CAAC;KAC7B;AACH,CAAC;AAtBD,sBAsBC","sourcesContent":["import { YargsArgs } from '../../types/yargs';\nimport {\n getOutfilePath,\n loadConfig,\n validateDirPath,\n validateFilePath,\n validateOutfileName,\n} from '../../utils';\nimport { snapEval } from '../eval/evalHandler';\nimport { manifestHandler } from '../manifest/manifestHandler';\nimport { bundle } from './bundle';\n\n/**\n * Builds all files in the given source directory to the given destination\n * directory.\n *\n * Creates destination directory if it doesn't exist.\n *\n * @param argv - argv from Yargs\n * @param argv.src - The source file path\n * @param argv.dist - The output directory path\n * @param argv.outfileName - The output file name\n */\nexport async function build(argv: YargsArgs): Promise<void> {\n const { src, dist, outfileName } = argv;\n if (outfileName) {\n validateOutfileName(outfileName as string);\n }\n await validateFilePath(src);\n await validateDirPath(dist, true);\n\n const outfilePath = getOutfilePath(dist, outfileName as string);\n const result = await bundle(\n src,\n outfilePath,\n argv,\n loadConfig().bundlerCustomizer,\n );\n if (result && argv.eval) {\n await snapEval({ ...argv, bundle: outfilePath });\n }\n\n if (argv.manifest) {\n await manifestHandler(argv);\n }\n}\n"]}
@@ -1,11 +1,13 @@
1
+ import { BrowserifyObject } from 'browserify';
1
2
  import { YargsArgs } from '../../types/yargs';
2
3
  /**
3
- * Builds a Snap bundle JSON file from its JavaScript source.
4
+ * Builds a Snap bundle JS file from its JavaScript source.
4
5
  *
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
6
+ * @param src - The source file path.
7
+ * @param dest - The destination file path.
8
+ * @param argv - arguments as an object generated by yargs.
9
+ * @param argv.sourceMaps - Whether to output sourcemaps.
10
+ * @param argv.stripComments - Whether to remove comments from code.
11
+ * @param argv.transpilationMode - The Babel transpilation mode.
10
12
  */
11
- export declare function bundle(src: string, dest: string, argv: YargsArgs): Promise<boolean>;
13
+ export declare function bundle(src: string, dest: string, argv: YargsArgs, bundlerTransform?: (bundler: BrowserifyObject) => void): Promise<boolean>;
@@ -5,44 +5,48 @@ 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 bundleUtils_1 = require("./bundleUtils");
8
+ const builders_1 = require("../../builders");
9
+ const utils_1 = require("./utils");
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
- * Builds a Snap bundle JSON file from its JavaScript source.
14
+ * Builds a Snap bundle JS 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
- function bundle(src, dest, argv) {
19
- const { sourceMaps: debug } = argv;
23
+ function bundle(src, dest, argv, bundlerTransform) {
24
+ const { sourceMaps: debug, transpilationMode } = argv;
25
+ const babelifyOptions = utils_1.processDependencies(argv);
20
26
  return new Promise((resolve, _reject) => {
21
- 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'), Object.assign({ global: transpilationMode === builders_1.TranspilationModes.localAndDeps, presets: [
30
+ [
31
+ require('@babel/preset-env'),
32
+ {
33
+ targets: {
34
+ browsers: ['chrome >= 66', 'firefox >= 68'],
35
+ },
30
36
  },
31
- },
32
- ],
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({
37
+ ],
38
+ ], plugins: [
39
+ require('@babel/plugin-transform-runtime'),
40
+ require('@babel/plugin-proposal-class-properties'),
41
+ require('@babel/plugin-proposal-object-rest-spread'),
42
+ require('@babel/plugin-proposal-optional-chaining'),
43
+ require('@babel/plugin-proposal-nullish-coalescing-operator'),
44
+ ] }, babelifyOptions));
45
+ }
46
+ bundlerTransform === null || bundlerTransform === void 0 ? void 0 : bundlerTransform(bundler);
47
+ bundler.bundle(async (bundleError, bundleBuffer) => await utils_1.writeBundleFile({
43
48
  bundleError,
44
49
  bundleBuffer,
45
- bundleStream,
46
50
  src,
47
51
  dest,
48
52
  resolve,
@@ -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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,IAAI;SACL,CAAC,CACL,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC;AAhDD,wBAgDC","sourcesContent":["import browserify, { BrowserifyObject } from 'browserify';\nimport { TranspilationModes } from '../../builders';\nimport { YargsArgs } from '../../types/yargs';\nimport { writeBundleFile, processDependencies } from './utils';\n\n// We need to statically import all Browserify transforms and all Babel presets\n// and plugins, and calling `require` is the sanest way to do that.\n/* eslint-disable @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires, node/global-require */\n\n/**\n * Builds a Snap bundle JS file from its JavaScript source.\n *\n * @param src - The source file path.\n * @param dest - The destination file path.\n * @param argv - arguments as an object generated by yargs.\n * @param argv.sourceMaps - Whether to output sourcemaps.\n * @param argv.stripComments - Whether to remove comments from code.\n * @param argv.transpilationMode - The Babel transpilation mode.\n */\nexport function bundle(\n src: string,\n dest: string,\n argv: YargsArgs,\n bundlerTransform?: (bundler: BrowserifyObject) => void,\n): Promise<boolean> {\n const { sourceMaps: debug, transpilationMode } = argv;\n const babelifyOptions = processDependencies(argv as any);\n return new Promise((resolve, _reject) => {\n const bundler = browserify(src, { debug });\n if (transpilationMode !== TranspilationModes.none) {\n bundler.transform(require('babelify'), {\n global: transpilationMode === TranspilationModes.localAndDeps,\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 ...(babelifyOptions as any),\n });\n }\n\n bundlerTransform?.(bundler);\n\n bundler.bundle(\n async (bundleError, bundleBuffer: Buffer) =>\n await writeBundleFile({\n bundleError,\n bundleBuffer,\n src,\n dest,\n resolve,\n argv,\n }),\n );\n });\n}\n"]}
@@ -4,20 +4,26 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  const builders_1 = __importDefault(require("../../builders"));
6
6
  const buildHandler_1 = require("./buildHandler");
7
+ const utils_1 = require("./utils");
7
8
  module.exports = {
8
9
  command: ['build', 'b'],
9
10
  desc: 'Build Snap from source',
10
11
  builder: (yarg) => {
11
12
  yarg
12
- .option('src', builders_1.default.src)
13
13
  .option('dist', builders_1.default.dist)
14
+ .option('eval', builders_1.default.eval)
15
+ .option('manifest', builders_1.default.manifest)
14
16
  .option('outfileName', builders_1.default.outfileName)
15
17
  .option('sourceMaps', builders_1.default.sourceMaps)
18
+ .option('src', builders_1.default.src)
16
19
  .option('stripComments', builders_1.default.stripComments)
17
- .option('eval', builders_1.default.eval)
18
- .option('manifest', builders_1.default.manifest)
20
+ .option('transpilationMode', builders_1.default.transpilationMode)
21
+ .option('depsToTranspile', builders_1.default.depsToTranspile)
22
+ .option('transformHtmlComments', builders_1.default.transformHtmlComments)
19
23
  .option('writeManifest', builders_1.default.writeManifest)
20
- .implies('writeManifest', 'manifest');
24
+ .implies('writeManifest', 'manifest')
25
+ .implies('depsToTranspile', 'transpilationMode')
26
+ .middleware((argv) => utils_1.processInvalidTranspilation(argv));
21
27
  },
22
28
  handler: (argv) => buildHandler_1.build(argv),
23
29
  };