@metamask/snaps-cli 0.9.0 → 0.10.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 +27 -1
- package/README.md +61 -19
- package/dist/builders.d.ts +3 -1
- package/dist/builders.js +15 -4
- package/dist/builders.js.map +1 -1
- package/dist/cli.js +3 -2
- package/dist/cli.js.map +1 -1
- package/dist/cmds/build/buildHandler.js +1 -1
- package/dist/cmds/build/buildHandler.js.map +1 -1
- package/dist/cmds/build/bundle.d.ts +3 -2
- package/dist/cmds/build/bundle.js +9 -13
- package/dist/cmds/build/bundle.js.map +1 -1
- package/dist/cmds/build/index.js +6 -1
- package/dist/cmds/build/index.js.map +1 -1
- package/dist/cmds/build/utils.d.ts +59 -0
- package/dist/cmds/build/utils.js +152 -0
- package/dist/cmds/build/utils.js.map +1 -0
- package/dist/cmds/init/initHandler.d.ts +2 -0
- package/dist/cmds/init/initHandler.js +6 -1
- package/dist/cmds/init/initHandler.js.map +1 -1
- package/dist/cmds/watch/index.js +11 -1
- package/dist/cmds/watch/index.js.map +1 -1
- package/dist/cmds/watch/watchHandler.js +32 -19
- package/dist/cmds/watch/watchHandler.js.map +1 -1
- package/dist/utils/misc.d.ts +10 -1
- package/dist/utils/misc.js +25 -4
- package/dist/utils/misc.js.map +1 -1
- package/dist/utils/snap-config.__GENERATED__.d.ts +2 -0
- package/dist/utils/snap-config.__GENERATED__.js +18 -0
- package/dist/utils/snap-config.__GENERATED__.js.map +1 -0
- package/dist/utils/snap-config.d.ts +8 -1
- package/dist/utils/snap-config.js +39 -32
- package/dist/utils/snap-config.js.map +1 -1
- package/package.json +10 -7
- package/dist/cmds/build/bundleUtils.d.ts +0 -42
- package/dist/cmds/build/bundleUtils.js +0 -95
- package/dist/cmds/build/bundleUtils.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,31 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.10.0]
|
|
10
|
+
### Added
|
|
11
|
+
- **BREAKING:** Transform HTML comments by default ([#237](https://github.com/MetaMask/snaps-skunkworks/pull/237))
|
|
12
|
+
- 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.
|
|
13
|
+
- `--transpiledDeps` flag to `build` and `watch` commands ([#221](https://github.com/MetaMask/snaps-skunkworks/pull/221))
|
|
14
|
+
- This flag allows the user to specify which dependencies will be transpiled at build time if the `--transpilationMode` is `--localAndDeps`.
|
|
15
|
+
- Add CLI usage instructions to readme ([#228](https://github.com/MetaMask/snaps-skunkworks/pull/228))
|
|
16
|
+
- Build process customization ([#251](https://github.com/MetaMask/snaps-skunkworks/pull/251))
|
|
17
|
+
- Builds can now be customized by adding a `bundlerCustomizer` function to `snap.config.js`. See the README for details.
|
|
18
|
+
|
|
19
|
+
### Changed
|
|
20
|
+
- **BREAKING:** Change Snap config file format ([#251](https://github.com/MetaMask/snaps-skunkworks/pull/251))
|
|
21
|
+
- The CLI now expects a file `snap.config.js` instead of `snap.config.json`, with a different structure. See the README for details.
|
|
22
|
+
- **BREAKING:** Strip comments in source code by default ([#243](https://github.com/MetaMask/snaps-skunkworks/pull/243))
|
|
23
|
+
- All comments will now be stripped from snap source code (including dependencies) by default.
|
|
24
|
+
- Enable `--verboseErrors` by default ([#249](https://github.com/MetaMask/snaps-skunkworks/pull/249))
|
|
25
|
+
|
|
26
|
+
### Fixed
|
|
27
|
+
- Comment stripping bug ([#270](https://github.com/MetaMask/snaps-skunkworks/pull/270))
|
|
28
|
+
- 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.
|
|
29
|
+
- 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.
|
|
30
|
+
- `watch` command parity with `build` command ([#241](https://github.com/MetaMask/snaps-skunkworks/pull/241))
|
|
31
|
+
- The `build` command had received a number of options that were not made available to the `watch` command. They now have the same options.
|
|
32
|
+
- Update dead link in readme ([#240](https://github.com/MetaMask/snaps-skunkworks/pull/240))
|
|
33
|
+
|
|
9
34
|
## [0.9.0]
|
|
10
35
|
### Added
|
|
11
36
|
- Transpilation configuration ([#213](https://github.com/MetaMask/snaps-skunkworks/pull/213))
|
|
@@ -98,7 +123,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
98
123
|
- Example snaps ([#72](https://github.com/MetaMask/snaps-skunkworks/pull/72))
|
|
99
124
|
- The examples now live in their own package, [`@metamask/snap-examples`](https://npmjs.com/package/@metamask/snap-examples).
|
|
100
125
|
|
|
101
|
-
[Unreleased]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.
|
|
126
|
+
[Unreleased]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.10.0...HEAD
|
|
127
|
+
[0.10.0]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.9.0...v0.10.0
|
|
102
128
|
[0.9.0]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.8.0...v0.9.0
|
|
103
129
|
[0.8.0]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.7.0...v0.8.0
|
|
104
130
|
[0.7.0]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.6.3...v0.7.0
|
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
|
+
Install a dev dependency in your snap project or globally using `yarn` or `npm`:
|
|
11
|
+
|
|
12
|
+
- `npm install -g @metamask/snaps-cli`
|
|
10
13
|
- `yarn global add @metamask/snaps-cli`
|
|
11
14
|
|
|
12
|
-
##
|
|
15
|
+
## Usage
|
|
13
16
|
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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/
|
|
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
|
-
|
|
113
|
+
### Configuration File
|
|
87
114
|
|
|
88
|
-
|
|
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
|
-
|
|
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
|
-
```
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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.
|
package/dist/builders.d.ts
CHANGED
|
@@ -12,11 +12,13 @@ export declare type SnapsCliBuilders = {
|
|
|
12
12
|
readonly stripComments: Readonly<Options>;
|
|
13
13
|
readonly suppressWarnings: Readonly<Options>;
|
|
14
14
|
readonly transpilationMode: Readonly<Options>;
|
|
15
|
+
readonly transformHtmlComments: Readonly<Options>;
|
|
16
|
+
readonly depsToTranspile: Readonly<Options>;
|
|
15
17
|
readonly verboseErrors: Readonly<Options>;
|
|
16
18
|
readonly writeManifest: Readonly<Options>;
|
|
17
19
|
};
|
|
18
20
|
export declare enum TranspilationModes {
|
|
19
|
-
|
|
21
|
+
localAndDeps = "localAndDeps",
|
|
20
22
|
localOnly = "localOnly",
|
|
21
23
|
none = "none"
|
|
22
24
|
}
|
package/dist/builders.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.TranspilationModes = void 0;
|
|
4
4
|
var TranspilationModes;
|
|
5
5
|
(function (TranspilationModes) {
|
|
6
|
-
TranspilationModes["
|
|
6
|
+
TranspilationModes["localAndDeps"] = "localAndDeps";
|
|
7
7
|
TranspilationModes["localOnly"] = "localOnly";
|
|
8
8
|
TranspilationModes["none"] = "none";
|
|
9
9
|
})(TranspilationModes = exports.TranspilationModes || (exports.TranspilationModes = {}));
|
|
@@ -86,7 +86,7 @@ const builders = {
|
|
|
86
86
|
describe: 'Whether to remove code comments from the build output',
|
|
87
87
|
type: 'boolean',
|
|
88
88
|
demandOption: false,
|
|
89
|
-
default:
|
|
89
|
+
default: true,
|
|
90
90
|
},
|
|
91
91
|
suppressWarnings: {
|
|
92
92
|
type: 'boolean',
|
|
@@ -98,14 +98,25 @@ const builders = {
|
|
|
98
98
|
type: 'string',
|
|
99
99
|
describe: 'Whether to use Babel to transpile all source code (including dependencies), local source code only, or nothing.',
|
|
100
100
|
demandOption: false,
|
|
101
|
-
default: TranspilationModes.
|
|
101
|
+
default: TranspilationModes.localOnly,
|
|
102
102
|
choices: Object.values(TranspilationModes),
|
|
103
103
|
},
|
|
104
|
+
transformHtmlComments: {
|
|
105
|
+
type: 'boolean',
|
|
106
|
+
describe: 'Whether to break up HTML comment tokens wherever they appear in your source code.',
|
|
107
|
+
demandOption: true,
|
|
108
|
+
default: true,
|
|
109
|
+
},
|
|
110
|
+
depsToTranspile: {
|
|
111
|
+
type: 'array',
|
|
112
|
+
describe: 'Transpile only the listed dependencies.',
|
|
113
|
+
demandOption: false,
|
|
114
|
+
},
|
|
104
115
|
verboseErrors: {
|
|
105
116
|
type: 'boolean',
|
|
106
117
|
describe: 'Display original errors',
|
|
107
118
|
demandOption: false,
|
|
108
|
-
default:
|
|
119
|
+
default: true,
|
|
109
120
|
},
|
|
110
121
|
writeManifest: {
|
|
111
122
|
describe: 'Make necessary changes to the Snap manifest file',
|
package/dist/builders.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builders.js","sourceRoot":"","sources":["../src/builders.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"builders.js","sourceRoot":"","sources":["../src/builders.ts"],"names":[],"mappings":"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","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
|
|
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,
|
|
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":";;;
|
|
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,6 +1,7 @@
|
|
|
1
|
+
import { BrowserifyObject } from 'browserify';
|
|
1
2
|
import { YargsArgs } from '../../types/yargs';
|
|
2
3
|
/**
|
|
3
|
-
* Builds a Snap bundle
|
|
4
|
+
* Builds a Snap bundle JS file from its JavaScript source.
|
|
4
5
|
*
|
|
5
6
|
* @param src - The source file path.
|
|
6
7
|
* @param dest - The destination file path.
|
|
@@ -9,4 +10,4 @@ import { YargsArgs } from '../../types/yargs';
|
|
|
9
10
|
* @param argv.stripComments - Whether to remove comments from code.
|
|
10
11
|
* @param argv.transpilationMode - The Babel transpilation mode.
|
|
11
12
|
*/
|
|
12
|
-
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>;
|
|
@@ -6,12 +6,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.bundle = void 0;
|
|
7
7
|
const browserify_1 = __importDefault(require("browserify"));
|
|
8
8
|
const builders_1 = require("../../builders");
|
|
9
|
-
const
|
|
9
|
+
const utils_1 = require("./utils");
|
|
10
10
|
// We need to statically import all Browserify transforms and all Babel presets
|
|
11
11
|
// and plugins, and calling `require` is the sanest way to do that.
|
|
12
12
|
/* eslint-disable @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires, node/global-require */
|
|
13
13
|
/**
|
|
14
|
-
* Builds a Snap bundle
|
|
14
|
+
* Builds a Snap bundle JS file from its JavaScript source.
|
|
15
15
|
*
|
|
16
16
|
* @param src - The source file path.
|
|
17
17
|
* @param dest - The destination file path.
|
|
@@ -20,15 +20,13 @@ const bundleUtils_1 = require("./bundleUtils");
|
|
|
20
20
|
* @param argv.stripComments - Whether to remove comments from code.
|
|
21
21
|
* @param argv.transpilationMode - The Babel transpilation mode.
|
|
22
22
|
*/
|
|
23
|
-
function bundle(src, dest, argv) {
|
|
23
|
+
function bundle(src, dest, argv, bundlerTransform) {
|
|
24
24
|
const { sourceMaps: debug, transpilationMode } = argv;
|
|
25
|
+
const babelifyOptions = utils_1.processDependencies(argv);
|
|
25
26
|
return new Promise((resolve, _reject) => {
|
|
26
|
-
const bundleStream = bundleUtils_1.createBundleStream(dest);
|
|
27
27
|
const bundler = browserify_1.default(src, { debug });
|
|
28
28
|
if (transpilationMode !== builders_1.TranspilationModes.none) {
|
|
29
|
-
bundler.transform(require('babelify'), {
|
|
30
|
-
global: transpilationMode === builders_1.TranspilationModes.all,
|
|
31
|
-
presets: [
|
|
29
|
+
bundler.transform(require('babelify'), Object.assign({ global: transpilationMode === builders_1.TranspilationModes.localAndDeps, presets: [
|
|
32
30
|
[
|
|
33
31
|
require('@babel/preset-env'),
|
|
34
32
|
{
|
|
@@ -37,20 +35,18 @@ function bundle(src, dest, argv) {
|
|
|
37
35
|
},
|
|
38
36
|
},
|
|
39
37
|
],
|
|
40
|
-
],
|
|
41
|
-
plugins: [
|
|
38
|
+
], plugins: [
|
|
42
39
|
require('@babel/plugin-transform-runtime'),
|
|
43
40
|
require('@babel/plugin-proposal-class-properties'),
|
|
44
41
|
require('@babel/plugin-proposal-object-rest-spread'),
|
|
45
42
|
require('@babel/plugin-proposal-optional-chaining'),
|
|
46
43
|
require('@babel/plugin-proposal-nullish-coalescing-operator'),
|
|
47
|
-
],
|
|
48
|
-
});
|
|
44
|
+
] }, babelifyOptions));
|
|
49
45
|
}
|
|
50
|
-
|
|
46
|
+
bundlerTransform === null || bundlerTransform === void 0 ? void 0 : bundlerTransform(bundler);
|
|
47
|
+
bundler.bundle(async (bundleError, bundleBuffer) => await utils_1.writeBundleFile({
|
|
51
48
|
bundleError,
|
|
52
49
|
bundleBuffer,
|
|
53
|
-
bundleStream,
|
|
54
50
|
src,
|
|
55
51
|
dest,
|
|
56
52
|
resolve,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bundle.js","sourceRoot":"","sources":["../../../src/cmds/build/bundle.ts"],"names":[],"mappings":";;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"bundle.js","sourceRoot":"","sources":["../../../src/cmds/build/bundle.ts"],"names":[],"mappings":";;;;;;AAAA,4DAA0D;AAC1D,6CAAoD;AAEpD,mCAA+D;AAE/D,+EAA+E;AAC/E,mEAAmE;AACnE,mHAAmH;AAEnH;;;;;;;;;GASG;AACH,SAAgB,MAAM,CACpB,GAAW,EACX,IAAY,EACZ,IAAe,EACf,gBAAsD;IAEtD,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,iBAAiB,EAAE,GAAG,IAAI,CAAC;IACtD,MAAM,eAAe,GAAG,2BAAmB,CAAC,IAAW,CAAC,CAAC;IACzD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE;QACtC,MAAM,OAAO,GAAG,oBAAU,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QAC3C,IAAI,iBAAiB,KAAK,6BAAkB,CAAC,IAAI,EAAE;YACjD,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,kBACnC,MAAM,EAAE,iBAAiB,KAAK,6BAAkB,CAAC,YAAY,EAC7D,OAAO,EAAE;oBACP;wBACE,OAAO,CAAC,mBAAmB,CAAC;wBAC5B;4BACE,OAAO,EAAE;gCACP,QAAQ,EAAE,CAAC,cAAc,EAAE,eAAe,CAAC;6BAC5C;yBACF;qBACF;iBACF,EACD,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,IACG,eAAuB,EAC3B,CAAC;SACJ;QAED,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAG,OAAO,CAAC,CAAC;QAE5B,OAAO,CAAC,MAAM,CACZ,KAAK,EAAE,WAAW,EAAE,YAAoB,EAAE,EAAE,CAC1C,MAAM,uBAAe,CAAC;YACpB,WAAW;YACX,YAAY;YACZ,GAAG;YACH,IAAI;YACJ,OAAO;YACP,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"]}
|
package/dist/cmds/build/index.js
CHANGED
|
@@ -4,6 +4,7 @@ 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',
|
|
@@ -17,8 +18,12 @@ module.exports = {
|
|
|
17
18
|
.option('src', builders_1.default.src)
|
|
18
19
|
.option('stripComments', builders_1.default.stripComments)
|
|
19
20
|
.option('transpilationMode', builders_1.default.transpilationMode)
|
|
21
|
+
.option('depsToTranspile', builders_1.default.depsToTranspile)
|
|
22
|
+
.option('transformHtmlComments', builders_1.default.transformHtmlComments)
|
|
20
23
|
.option('writeManifest', builders_1.default.writeManifest)
|
|
21
|
-
.implies('writeManifest', 'manifest')
|
|
24
|
+
.implies('writeManifest', 'manifest')
|
|
25
|
+
.implies('depsToTranspile', 'transpilationMode')
|
|
26
|
+
.middleware((argv) => utils_1.processInvalidTranspilation(argv));
|
|
22
27
|
},
|
|
23
28
|
handler: (argv) => buildHandler_1.build(argv),
|
|
24
29
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cmds/build/index.ts"],"names":[],"mappings":";;;;AACA,8DAAsC;AAEtC,iDAAuC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cmds/build/index.ts"],"names":[],"mappings":";;;;AACA,8DAAsC;AAEtC,iDAAuC;AACvC,mCAAsD;AAEtD,iBAAS;IACP,OAAO,EAAE,CAAC,OAAO,EAAE,GAAG,CAAC;IACvB,IAAI,EAAE,wBAAwB;IAC9B,OAAO,EAAE,CAAC,IAAgB,EAAE,EAAE;QAC5B,IAAI;aACD,MAAM,CAAC,MAAM,EAAE,kBAAQ,CAAC,IAAI,CAAC;aAC7B,MAAM,CAAC,MAAM,EAAE,kBAAQ,CAAC,IAAI,CAAC;aAC7B,MAAM,CAAC,UAAU,EAAE,kBAAQ,CAAC,QAAQ,CAAC;aACrC,MAAM,CAAC,aAAa,EAAE,kBAAQ,CAAC,WAAW,CAAC;aAC3C,MAAM,CAAC,YAAY,EAAE,kBAAQ,CAAC,UAAU,CAAC;aACzC,MAAM,CAAC,KAAK,EAAE,kBAAQ,CAAC,GAAG,CAAC;aAC3B,MAAM,CAAC,eAAe,EAAE,kBAAQ,CAAC,aAAa,CAAC;aAC/C,MAAM,CAAC,mBAAmB,EAAE,kBAAQ,CAAC,iBAAiB,CAAC;aACvD,MAAM,CAAC,iBAAiB,EAAE,kBAAQ,CAAC,eAAe,CAAC;aACnD,MAAM,CAAC,uBAAuB,EAAE,kBAAQ,CAAC,qBAAqB,CAAC;aAC/D,MAAM,CAAC,eAAe,EAAE,kBAAQ,CAAC,aAAa,CAAC;aAC/C,OAAO,CAAC,eAAe,EAAE,UAAU,CAAC;aACpC,OAAO,CAAC,iBAAiB,EAAE,mBAAmB,CAAC;aAC/C,UAAU,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,mCAA2B,CAAC,IAAW,CAAC,CAAC,CAAC;IACpE,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';\nimport { processInvalidTranspilation } from './utils';\n\nexport = {\n command: ['build', 'b'],\n desc: 'Build Snap from source',\n builder: (yarg: yargs.Argv) => {\n yarg\n .option('dist', builders.dist)\n .option('eval', builders.eval)\n .option('manifest', builders.manifest)\n .option('outfileName', builders.outfileName)\n .option('sourceMaps', builders.sourceMaps)\n .option('src', builders.src)\n .option('stripComments', builders.stripComments)\n .option('transpilationMode', builders.transpilationMode)\n .option('depsToTranspile', builders.depsToTranspile)\n .option('transformHtmlComments', builders.transformHtmlComments)\n .option('writeManifest', builders.writeManifest)\n .implies('writeManifest', 'manifest')\n .implies('depsToTranspile', 'transpilationMode')\n .middleware((argv) => processInvalidTranspilation(argv as any));\n },\n handler: (argv: YargsArgs) => build(argv),\n};\n"]}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Option, YargsArgs } from '../../types/yargs';
|
|
3
|
+
declare type WriteBundleFileArgs = {
|
|
4
|
+
bundleError: Error;
|
|
5
|
+
bundleBuffer: Buffer;
|
|
6
|
+
src: string;
|
|
7
|
+
dest: string;
|
|
8
|
+
resolve: (value: boolean) => void;
|
|
9
|
+
argv: YargsArgs;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Performs postprocessing on the bundle contents and writes them to disk.
|
|
13
|
+
* Intended to be used in the callback passed to the Browserify `.bundle()`
|
|
14
|
+
* call.
|
|
15
|
+
*
|
|
16
|
+
* @param options - Options bag.
|
|
17
|
+
* @param options.bundleError - Any error received from Browserify.
|
|
18
|
+
* @param options.bundleBuffer - The {@link Buffer} with the bundle contents
|
|
19
|
+
* from Browserify.
|
|
20
|
+
* @param options.src - The source file path.
|
|
21
|
+
* @param options.dest - The destination file path.
|
|
22
|
+
* @param options.resolve - A {@link Promise} resolution function, so that we
|
|
23
|
+
* can use promises and `async`/`await` even though Browserify uses callbacks.
|
|
24
|
+
* @param options.argv - The Yargs `argv` object.
|
|
25
|
+
*/
|
|
26
|
+
export declare function writeBundleFile({ bundleError, bundleBuffer, src, dest, resolve, argv, }: WriteBundleFileArgs): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Postprocesses a JavaScript bundle string such that it can be evaluated in SES.
|
|
29
|
+
* Currently:
|
|
30
|
+
* - converts certain dot notation to string notation (for indexing)
|
|
31
|
+
* - makes all direct calls to eval indirect
|
|
32
|
+
* - wraps original bundle in anonymous function
|
|
33
|
+
* - handles certain Babel-related edge cases
|
|
34
|
+
*
|
|
35
|
+
* @param bundleString - The bundle string
|
|
36
|
+
* @param options - post process options
|
|
37
|
+
* @param options.stripComments
|
|
38
|
+
* @returns - The postprocessed bundle string
|
|
39
|
+
*/
|
|
40
|
+
export declare function postProcess(bundleString: string | null, options?: Partial<Option>): string | null;
|
|
41
|
+
/**
|
|
42
|
+
* Processes dependencies and updates argv with an options object
|
|
43
|
+
* @param argv
|
|
44
|
+
*/
|
|
45
|
+
export declare function processDependencies(argv: YargsArgs): Record<string, any>;
|
|
46
|
+
/**
|
|
47
|
+
* Processes a string of space delimited dependencies into one regex string
|
|
48
|
+
* @param dependencies
|
|
49
|
+
* @returns a regexp string
|
|
50
|
+
*/
|
|
51
|
+
export declare function getDependencyRegExp(dependencies: string[]): RegExp | null;
|
|
52
|
+
/**
|
|
53
|
+
* Helper function remove any leading and trailing slashes from dependency list
|
|
54
|
+
* @param dependencies
|
|
55
|
+
* @returns an array of sanitized paths
|
|
56
|
+
*/
|
|
57
|
+
export declare function sanitizeDependencyPaths(dependencies: string[]): string[];
|
|
58
|
+
export declare function processInvalidTranspilation(argv: YargsArgs): void;
|
|
59
|
+
export {};
|