@metamask/snaps-cli 0.5.0 → 0.6.3
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 +29 -1
- package/README.md +65 -104
- package/dist/builders.d.ts +17 -2
- package/dist/builders.js +4 -6
- package/dist/builders.js.map +1 -1
- package/dist/cli.d.ts +0 -7
- package/dist/cli.js +3 -3
- 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/index.js +2 -3
- package/dist/cmds/build/index.js.map +1 -1
- package/dist/cmds/eval/eval-worker.js +4 -1
- package/dist/cmds/eval/eval-worker.js.map +1 -1
- package/dist/cmds/init/index.js +3 -2
- package/dist/cmds/init/index.js.map +1 -1
- package/dist/cmds/init/init-template.json +2 -2
- package/dist/cmds/init/initHandler.d.ts +6 -1
- package/dist/cmds/init/initHandler.js +50 -33
- package/dist/cmds/init/initHandler.js.map +1 -1
- package/dist/cmds/init/initUtils.d.ts +28 -11
- package/dist/cmds/init/initUtils.js +158 -91
- package/dist/cmds/init/initUtils.js.map +1 -1
- package/dist/cmds/manifest/index.js +3 -6
- package/dist/cmds/manifest/index.js.map +1 -1
- package/dist/cmds/manifest/manifestHandler.d.ts +15 -3
- package/dist/cmds/manifest/manifestHandler.js +180 -147
- package/dist/cmds/manifest/manifestHandler.js.map +1 -1
- package/dist/cmds/watch/watchHandler.js +2 -0
- package/dist/cmds/watch/watchHandler.js.map +1 -1
- package/dist/main.js.map +1 -1
- package/dist/tsconfig.json +3 -0
- package/dist/utils/fs.d.ts +10 -2
- package/dist/utils/fs.js +16 -3
- package/dist/utils/fs.js.map +1 -1
- package/dist/utils/misc.d.ts +4 -3
- package/dist/utils/misc.js +6 -4
- package/dist/utils/misc.js.map +1 -1
- package/dist/utils/snap-config.js +12 -17
- package/dist/utils/snap-config.js.map +1 -1
- package/dist/utils/validate-fs.d.ts +1 -1
- package/dist/utils/validate-fs.js +1 -1
- package/dist/utils/validate-fs.js.map +1 -1
- package/package.json +16 -7
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,30 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.6.3]
|
|
10
|
+
### Changed
|
|
11
|
+
- No changes this release.
|
|
12
|
+
|
|
13
|
+
## [0.6.2]
|
|
14
|
+
### Changed
|
|
15
|
+
- No changes this release.
|
|
16
|
+
|
|
17
|
+
## [0.6.1]
|
|
18
|
+
### Fixed
|
|
19
|
+
- `mm-snap init` Snap `snap_confirm` call ([#168](https://github.com/MetaMask/snaps-skunkworks/pull/168))
|
|
20
|
+
- The generated Snap was passing invalid parameters to the method.
|
|
21
|
+
|
|
22
|
+
## [0.6.0]
|
|
23
|
+
### Added
|
|
24
|
+
- Snap SVG icon support ([#163](https://github.com/MetaMask/snaps-skunkworks/pull/163))
|
|
25
|
+
|
|
26
|
+
### Changed
|
|
27
|
+
- **BREAKING:** Support the new Snaps publishing specification ([#140](https://github.com/MetaMask/snaps-skunkworks/pull/140), [#160](https://github.com/MetaMask/snaps-skunkworks/pull/160))
|
|
28
|
+
- This introduces several breaking changes to how Snaps are developed, hosted, and represented at runtime. See [the specification](https://github.com/MetaMask/specifications/blob/d4a5bf5d6990bb5b02a98bd3f95a24ffb28c701c/snaps/publishing.md) and the referenced pull requests for details.
|
|
29
|
+
- **BREAKING:** Rename Snap `name` property to `id` ([#147](https://github.com/MetaMask/snaps-skunkworks/pull/147))
|
|
30
|
+
- **BREAKING:** Update `ses` to version `^0.15.3` ([#159](https://github.com/MetaMask/snaps-skunkworks/pull/159))
|
|
31
|
+
- This will cause behavioral changes for code executed under SES, and may require modifications to code that previously executed without issues.
|
|
32
|
+
|
|
9
33
|
## [0.5.0]
|
|
10
34
|
### Changed
|
|
11
35
|
- **BREAKING:** Convert all TypeScript `interface` declarations to `type` equivalents ([#143](https://github.com/MetaMask/snaps-skunkworks/pull/143))
|
|
@@ -49,7 +73,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
49
73
|
- Example snaps ([#72](https://github.com/MetaMask/snaps-skunkworks/pull/72))
|
|
50
74
|
- The examples now live in their own package, [`@metamask/snap-examples`](https://npmjs.com/package/@metamask/snap-examples).
|
|
51
75
|
|
|
52
|
-
[Unreleased]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.
|
|
76
|
+
[Unreleased]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.6.3...HEAD
|
|
77
|
+
[0.6.3]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.6.2...v0.6.3
|
|
78
|
+
[0.6.2]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.6.1...v0.6.2
|
|
79
|
+
[0.6.1]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.6.0...v0.6.1
|
|
80
|
+
[0.6.0]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.5.0...v0.6.0
|
|
53
81
|
[0.5.0]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.4.0...v0.5.0
|
|
54
82
|
[0.4.0]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.3.1...v0.4.0
|
|
55
83
|
[0.3.1]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.3.0...v0.3.1
|
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ A CLI for developing MetaMask Snaps.
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
Use Node.js `12.11.0` or later.
|
|
8
|
-
We recommend [nvm](https://github.com/nvm-sh/nvm) for managing Node versions.
|
|
8
|
+
We recommend [nvm](https://github.com/nvm-sh/nvm) for managing Node.js versions.
|
|
9
9
|
|
|
10
10
|
- `yarn global add snaps-cli`
|
|
11
11
|
|
|
@@ -19,140 +19,101 @@ mm-snap init
|
|
|
19
19
|
|
|
20
20
|
## MetaMask Snaps
|
|
21
21
|
|
|
22
|
-
MetaMask Snaps
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
MetaMask Snaps enables trustlessly extending the functionality of MetaMask at runtime.
|
|
23
|
+
A Snap consist of two things: a JSON manifest and a JavaScript bundle.
|
|
24
|
+
At present, Snaps can be published as npm packages on the public npm registry, or hosted locally during development.
|
|
25
|
+
In the future, it will be possible to publish snaps on many different platforms, including arbitrary npm registries and IPFS.
|
|
25
26
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
We recommend building your Snap using this tool.
|
|
28
|
+
You can bundle your Snap using your own tools, but it must run in SES and only use the global APIs that MetaMask exposes at runtime.
|
|
29
|
+
Although Snaps currently execute in the browser, some browser APIs are not available to Snaps, and Snaps do not have DOM access.
|
|
30
|
+
|
|
31
|
+
### The Snap Manifest
|
|
31
32
|
|
|
32
|
-
|
|
33
|
+
Your manifest must be named `snap.manifest.json` and located in the root directory of your npm package.
|
|
34
|
+
Here's an example manifest:
|
|
33
35
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
36
|
+
```json
|
|
37
|
+
{
|
|
38
|
+
"version": "0.2.2",
|
|
39
|
+
"proposedName": "@metamask/example-snap",
|
|
40
|
+
"description": "An example snap.",
|
|
41
|
+
"repository": {
|
|
42
|
+
"type": "git",
|
|
43
|
+
"url": "https://github.com/MetaMask/example-snap.git"
|
|
44
|
+
},
|
|
45
|
+
"source": {
|
|
46
|
+
"shasum": "w3FltkDjKQZiPwM+AThnmypt0OFF7hj4ycg/kxxv+nU=",
|
|
47
|
+
"location": {
|
|
48
|
+
"npm": {
|
|
49
|
+
"filePath": "dist/bundle.js",
|
|
50
|
+
"iconPath": "images/icon.svg",
|
|
51
|
+
"packageName": "@metamask/example-snap",
|
|
52
|
+
"registry": "https://registry.npmjs.org/"
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"initialPermissions": {
|
|
57
|
+
"snap_confirm": {}
|
|
58
|
+
},
|
|
59
|
+
"manifestVersion": "0.1"
|
|
60
|
+
}
|
|
61
|
+
```
|
|
43
62
|
|
|
44
|
-
|
|
45
|
-
work properly or install at all.
|
|
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.
|
|
46
64
|
|
|
47
|
-
|
|
48
|
-
You can bundle your Snap using your own tools, but it must run in SES and only
|
|
49
|
-
use the global APIs that MetaMask exposes at runtime.
|
|
50
|
-
Although Snaps currently execute in the browser, some browser APIs are not available for snaps,
|
|
51
|
-
and Snaps do not have DOM access.
|
|
65
|
+
> **ATTN:** If your Snap is not compatible with the publishing specification, your Snap may not work properly or install at all.
|
|
52
66
|
|
|
53
67
|
### Assumed Project Structure
|
|
54
68
|
|
|
55
69
|
This tool has default arguments assuming the following project structure:
|
|
56
70
|
|
|
57
71
|
```text
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
72
|
+
snap-project/
|
|
73
|
+
├─ package.json
|
|
74
|
+
├─ src/
|
|
75
|
+
│ ├─ index.js
|
|
76
|
+
├─ snap.manifest.json
|
|
77
|
+
├─ dist/
|
|
78
|
+
│ ├─ bundle.js
|
|
79
|
+
├─ ... (all other project files and folders)
|
|
63
80
|
```
|
|
64
81
|
|
|
65
82
|
Source files other than `index.js` are located through its imports.
|
|
66
83
|
The defaults can be overwritten using the `snap.config.json` config file,
|
|
67
84
|
[see below](#configuration-file).
|
|
68
85
|
|
|
69
|
-
### Permissions
|
|
70
|
-
|
|
71
|
-
This module uses permissions as defined in [`rpc-cap`, MetaMask's JSON RPC
|
|
72
|
-
capabilities middleware](https://github.com/MetaMask/rpc-cap).
|
|
73
|
-
See examples in this repo for details.
|
|
74
|
-
|
|
75
86
|
## Usage
|
|
76
87
|
|
|
77
|
-
|
|
88
|
+
Run `mm-snap --help` for usage instructions.
|
|
78
89
|
|
|
79
|
-
|
|
90
|
+
### Configuration File
|
|
80
91
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
snap watch Build Snap on change [aliases: w]
|
|
92
|
-
|
|
93
|
-
Options (build):
|
|
94
|
-
--help, -h Show help [boolean]
|
|
95
|
-
--src, -s Source file
|
|
96
|
-
[string] [required] [default: "index.js"]
|
|
97
|
-
--dist, -d Output directory
|
|
98
|
-
[string] [required] [default: "dist/"]
|
|
99
|
-
--outfileName, -n Output file name
|
|
100
|
-
[string] [default: "bundle.js"]
|
|
101
|
-
--sourceMaps Whether building outputs sourcemaps
|
|
102
|
-
[boolean] [default: false]
|
|
103
|
-
--stripComments, --strip Whether to remove code comments from bundle
|
|
104
|
-
[boolean] [default: false]
|
|
105
|
-
--port, -p Local server port for testing
|
|
106
|
-
[number] [required] [default: 8081]
|
|
107
|
-
--eval, -e Attempt to evaluate Snap bundle in SES
|
|
108
|
-
[boolean] [default: true]
|
|
109
|
-
--manifest, -m Validate project package.json as a Snap
|
|
110
|
-
manifest [boolean] [default: true]
|
|
111
|
-
--populate Update Snap manifest properties of
|
|
112
|
-
package.json [boolean] [default: true]
|
|
113
|
-
--verboseErrors, -v, --verbose Display original errors
|
|
114
|
-
[boolean] [default: false]
|
|
115
|
-
--suppressWarnings, -w Suppress warnings [boolean] [default: false]
|
|
116
|
-
|
|
117
|
-
Examples:
|
|
118
|
-
snap init Initialize Snap package from
|
|
119
|
-
scratch
|
|
120
|
-
snap build -s index.js -d out Build 'Snap.js' as
|
|
121
|
-
'./out/bundle.js'
|
|
122
|
-
snap build -s index.js -d out -n Build 'Snap.js' as
|
|
123
|
-
Snap.js './out/Snap.js'
|
|
124
|
-
snap serve -r out Serve files in './out' on port 8080
|
|
125
|
-
snap serve -r out -p 9000 Serve files in './out' on port 9000
|
|
126
|
-
snap watch -s index.js -d out Rebuild './out/bundle.js' on changes
|
|
127
|
-
to files in 'index.js' parent and
|
|
128
|
-
child directories
|
|
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
|
+
Example:
|
|
95
|
+
|
|
96
|
+
```json
|
|
97
|
+
{
|
|
98
|
+
"src": "lib",
|
|
99
|
+
"dist": "out",
|
|
100
|
+
"port": 9000
|
|
101
|
+
}
|
|
129
102
|
```
|
|
130
103
|
|
|
131
|
-
|
|
104
|
+
The configuration file should not be published.
|
|
105
|
+
|
|
106
|
+
### Gotchas
|
|
132
107
|
|
|
133
108
|
- Commands
|
|
134
109
|
- `watch --src ... --dist ...` rebuilds on all changes in the parent directory
|
|
135
110
|
of `src` and its children except:
|
|
136
111
|
- `node_modules/`
|
|
137
|
-
- `test
|
|
112
|
+
- `test/`, `tests/`, `**/*.test.js`, and `**/*.test.ts`
|
|
138
113
|
- The specified `dist` directory
|
|
139
114
|
- Dotfiles
|
|
140
115
|
- `serve --root ... --port ...` serves the `root` directory on `localhost:port`
|
|
141
116
|
- By default, `root` serves the current working directory: `.`
|
|
142
117
|
- Arguments
|
|
143
|
-
- `src
|
|
118
|
+
- `src` must be a file path when specified
|
|
144
119
|
- `dist` and `root` must be directory paths when specified
|
|
145
|
-
|
|
146
|
-
### Configuration File
|
|
147
|
-
|
|
148
|
-
`snap.config.json` can be placed in the project root directory. It should have string keys matching
|
|
149
|
-
command arguments. Values become argument defaults, which can still be overriden on the command line.
|
|
150
|
-
Example:
|
|
151
|
-
|
|
152
|
-
```json
|
|
153
|
-
{
|
|
154
|
-
"src": "lib",
|
|
155
|
-
"dist": "out",
|
|
156
|
-
"port": 9000
|
|
157
|
-
}
|
|
158
|
-
```
|
package/dist/builders.d.ts
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
declare
|
|
1
|
+
import { Options } from 'yargs';
|
|
2
|
+
export declare type SnapsCliBuilders = {
|
|
3
|
+
readonly src: Readonly<Options>;
|
|
4
|
+
readonly dist: Readonly<Options>;
|
|
5
|
+
readonly bundle: Readonly<Options>;
|
|
6
|
+
readonly root: Readonly<Options>;
|
|
7
|
+
readonly port: Readonly<Options>;
|
|
8
|
+
readonly sourceMaps: Readonly<Options>;
|
|
9
|
+
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
|
+
readonly suppressWarnings: Readonly<Options>;
|
|
16
|
+
};
|
|
17
|
+
declare const builders: SnapsCliBuilders;
|
|
3
18
|
export default builders;
|
package/dist/builders.js
CHANGED
|
@@ -7,7 +7,7 @@ const builders = {
|
|
|
7
7
|
type: 'string',
|
|
8
8
|
demandOption: true,
|
|
9
9
|
normalize: true,
|
|
10
|
-
default: 'index.js',
|
|
10
|
+
default: 'src/index.js',
|
|
11
11
|
},
|
|
12
12
|
dist: {
|
|
13
13
|
alias: 'd',
|
|
@@ -69,13 +69,13 @@ const builders = {
|
|
|
69
69
|
},
|
|
70
70
|
manifest: {
|
|
71
71
|
alias: 'm',
|
|
72
|
-
describe: 'Validate
|
|
72
|
+
describe: 'Validate snap.manifest.json',
|
|
73
73
|
type: 'boolean',
|
|
74
74
|
demandOption: false,
|
|
75
75
|
default: true,
|
|
76
76
|
},
|
|
77
|
-
|
|
78
|
-
describe: '
|
|
77
|
+
writeManifest: {
|
|
78
|
+
describe: 'Make necessary changes to the Snap manifest file',
|
|
79
79
|
type: 'boolean',
|
|
80
80
|
demandOption: false,
|
|
81
81
|
default: true,
|
|
@@ -88,14 +88,12 @@ const builders = {
|
|
|
88
88
|
default: true,
|
|
89
89
|
},
|
|
90
90
|
verboseErrors: {
|
|
91
|
-
alias: 'v',
|
|
92
91
|
type: 'boolean',
|
|
93
92
|
describe: 'Display original errors',
|
|
94
93
|
demandOption: false,
|
|
95
94
|
default: false,
|
|
96
95
|
},
|
|
97
96
|
suppressWarnings: {
|
|
98
|
-
alias: 'sw',
|
|
99
97
|
type: 'boolean',
|
|
100
98
|
describe: 'Suppress warnings',
|
|
101
99
|
demandOption: false,
|
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":";;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,EAAE,IAAI;QAClB,SAAS,EAAE,IAAI;QACf,OAAO,EAAE,MAAM;KAChB;IAED,MAAM,EAAE;QACN,KAAK,EAAE,GAAG;QACV,QAAQ,EAAE,kBAAkB;QAC5B,IAAI,EAAE,QAAQ;QACd,YAAY,EAAE,IAAI;QAClB,SAAS,EAAE,IAAI;QACf,OAAO,EAAE,gBAAgB;KAC1B;IAED,IAAI,EAAE;QACJ,KAAK,EAAE,GAAG;QACV,QAAQ,EAAE,uBAAuB;QACjC,IAAI,EAAE,QAAQ;QACd,YAAY,EAAE,IAAI;QAClB,SAAS,EAAE,IAAI;QACf,OAAO,EAAE,GAAG;KACb;IAED,IAAI,EAAE;QACJ,KAAK,EAAE,GAAG;QACV,QAAQ,EAAE,+BAA+B;QACzC,IAAI,EAAE,QAAQ;QACd,YAAY,EAAE,IAAI;QAClB,OAAO,EAAE,IAAI;QACb,MAAM,EAAE,CAAC,GAAY,EAAE,EAAE;YACvB,MAAM,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC;YAC9C,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE;gBACtB,MAAM,IAAI,KAAK,CAAC,iBAAiB,GAAG,EAAE,CAAC,CAAC;aACzC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;KACF;IAED,UAAU,EAAE;QACV,QAAQ,EAAE,mCAAmC;QAC7C,IAAI,EAAE,SAAS;QACf,YAAY,EAAE,KAAK;QACnB,OAAO,EAAE,KAAK;KACf;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,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"]}
|
package/dist/cli.d.ts
CHANGED
package/dist/cli.js
CHANGED
|
@@ -13,11 +13,11 @@ function cli(argv, commands) {
|
|
|
13
13
|
yargs_1.default(rawArgv)
|
|
14
14
|
.usage('Usage: $0 <command> [options]')
|
|
15
15
|
.example('$0 init', `\tInitialize Snap package from scratch`)
|
|
16
|
-
.example('$0 build -s index.js -d out', `\tBuild 'index.js' as './out/bundle.js'`)
|
|
17
|
-
.example('$0 build -s index.js -d out -n snap.js', `\tBuild 'index.js' as './out/snap.js'`)
|
|
16
|
+
.example('$0 build -s src/index.js -d out', `\tBuild 'src/index.js' as './out/bundle.js'`)
|
|
17
|
+
.example('$0 build -s src/index.js -d out -n snap.js', `\tBuild 'src/index.js' as './out/snap.js'`)
|
|
18
18
|
.example('$0 serve -r out', `\tServe files in './out' on port 8080`)
|
|
19
19
|
.example('$0 serve -r out -p 9000', `\tServe files in './out' on port 9000`)
|
|
20
|
-
.example('$0 watch -s index.js -d out', `\tRebuild './out/bundle.js' on changes to files in 'index.js' parent and child directories`)
|
|
20
|
+
.example('$0 watch -s src/index.js -d out', `\tRebuild './out/bundle.js' on changes to files in 'src/index.js' parent and child directories`)
|
|
21
21
|
.command(commands)
|
|
22
22
|
.option('verboseErrors', builders_1.default.verboseErrors)
|
|
23
23
|
.option('suppressWarnings', builders_1.default.suppressWarnings)
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAyC;
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAyC;AAGzC,mCAAsE;AACtE,0DAAkC;AAElC,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,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,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';\n\nimport { applyConfig, sanitizeInputs, setSnapGlobals } from './utils';\nimport builders from './builders';\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.exit(1);\n })\n\n .demandCommand(1, 'You must specify at least one command.')\n\n .help()\n .alias('help', 'h').argv;\n}\n"]}
|
|
@@ -29,7 +29,7 @@ async function build(argv) {
|
|
|
29
29
|
await evalHandler_1.snapEval(Object.assign(Object.assign({}, argv), { bundle: outfilePath }));
|
|
30
30
|
}
|
|
31
31
|
if (argv.manifest) {
|
|
32
|
-
manifestHandler_1.
|
|
32
|
+
await manifestHandler_1.manifestHandler(argv);
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
exports.build = build;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildHandler.js","sourceRoot":"","sources":["../../../src/cmds/build/buildHandler.ts"],"names":[],"mappings":";;;AAAA,uCAKqB;AACrB,qDAA+C;AAC/C,
|
|
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"]}
|
package/dist/cmds/build/index.js
CHANGED
|
@@ -14,11 +14,10 @@ module.exports = {
|
|
|
14
14
|
.option('outfileName', builders_1.default.outfileName)
|
|
15
15
|
.option('sourceMaps', builders_1.default.sourceMaps)
|
|
16
16
|
.option('stripComments', builders_1.default.stripComments)
|
|
17
|
-
.option('port', builders_1.default.port)
|
|
18
17
|
.option('eval', builders_1.default.eval)
|
|
19
18
|
.option('manifest', builders_1.default.manifest)
|
|
20
|
-
.option('
|
|
21
|
-
.implies('
|
|
19
|
+
.option('writeManifest', builders_1.default.writeManifest)
|
|
20
|
+
.implies('writeManifest', 'manifest');
|
|
22
21
|
},
|
|
23
22
|
handler: (argv) => buildHandler_1.build(argv),
|
|
24
23
|
};
|
|
@@ -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,
|
|
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"]}
|
|
@@ -10,8 +10,11 @@ const crypto_1 = __importDefault(require("crypto"));
|
|
|
10
10
|
// eslint-disable-next-line import/no-unassigned-import
|
|
11
11
|
require("ses/lockdown");
|
|
12
12
|
lockdown({
|
|
13
|
-
|
|
13
|
+
consoleTaming: 'unsafe',
|
|
14
14
|
errorTaming: 'unsafe',
|
|
15
|
+
mathTaming: 'unsafe',
|
|
16
|
+
dateTaming: 'unsafe',
|
|
17
|
+
overrideTaming: 'severe',
|
|
15
18
|
});
|
|
16
19
|
if (worker_threads_1.parentPort !== null) {
|
|
17
20
|
worker_threads_1.parentPort.on('message', (message) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eval-worker.js","sourceRoot":"","sources":["../../../src/cmds/eval/eval-worker.ts"],"names":[],"mappings":";;;;;AAAA,mCAAsC;AACtC,mDAA4C;AAC5C,2BAAkC;AAClC,oDAA4B;AAE5B,uDAAuD;AACvD,wBAAsB;AAStB,QAAQ,CAAC;IACP,UAAU,EAAE,QAAQ;IACpB,
|
|
1
|
+
{"version":3,"file":"eval-worker.js","sourceRoot":"","sources":["../../../src/cmds/eval/eval-worker.ts"],"names":[],"mappings":";;;;;AAAA,mCAAsC;AACtC,mDAA4C;AAC5C,2BAAkC;AAClC,oDAA4B;AAE5B,uDAAuD;AACvD,wBAAsB;AAStB,QAAQ,CAAC;IACP,aAAa,EAAE,QAAQ;IACvB,WAAW,EAAE,QAAQ;IACrB,UAAU,EAAE,QAAQ;IACpB,UAAU,EAAE,QAAQ;IACpB,cAAc,EAAE,QAAQ;CACzB,CAAC,CAAC;AAEH,IAAI,2BAAU,KAAK,IAAI,EAAE;IACvB,2BAAU,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,OAAiC,EAAE,EAAE;QAC7D,MAAM,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;QAEjC,IAAI,WAAW,CAAC,iBAAiB,EAAE,CAAC,CAAC,QAAQ,CAC3C,iBAAY,CAAC,YAAY,EAAE,MAAM,CAAC,CACnC,CAAC;QACF,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,8BAA8B;IACzE,CAAC,CAAC,CAAC;CACJ;AAED,SAAS,mBAAmB;IAC1B,MAAM,YAAY,GAAG,IAAI,qBAAY,EAA+B,CAAC;IACrE,YAAY,CAAC,yBAAyB,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC;IACpD,YAAY,CAAC,OAAO,GAAG,KAAK,IAAI,EAAE,CAAC,IAAI,CAAC;IACxC,OAAO,YAAgC,CAAC;AAC1C,CAAC;AAED,SAAS,iBAAiB;IACxB,MAAM,UAAU,GAAG;QACjB,MAAM;QACN,MAAM;QACN,OAAO;QACP,MAAM,EAAN,gBAAM;QACN,IAAI;QACJ,KAAK,EAAE,GAAG,EAAE,CAAC,IAAI;QACjB,IAAI;QACJ,MAAM,EAAE,mBAAmB,EAAE;QAC7B,UAAU;QACV,YAAY,EAAE,GAAG,EAAE,CAAC,SAAS;QAC7B,SAAS,EAAE,GAAG,EAAE,CAAC,IAAI;QACrB,cAAc,EAAE,GAAG,EAAE,CAAC,IAAI;KAC3B,CAAC;IAEF,uCACK,UAAU,KACb,MAAM,EAAE,UAAU,IAClB;AACJ,CAAC","sourcesContent":["import { EventEmitter } from 'events';\nimport { parentPort } from 'worker_threads';\nimport { readFileSync } from 'fs';\nimport crypto from 'crypto';\n\n// eslint-disable-next-line import/no-unassigned-import\nimport 'ses/lockdown';\n\ndeclare let lockdown: any, Compartment: any;\n\ntype MockSnapProvider = EventEmitter & {\n registerRpcMessageHandler: () => any;\n request: () => Promise<any>;\n};\n\nlockdown({\n consoleTaming: 'unsafe',\n errorTaming: 'unsafe',\n mathTaming: 'unsafe',\n dateTaming: 'unsafe',\n overrideTaming: 'severe',\n});\n\nif (parentPort !== null) {\n parentPort.on('message', (message: { snapFilePath: string }) => {\n const { snapFilePath } = message;\n\n new Compartment(getMockEndowments()).evaluate(\n readFileSync(snapFilePath, 'utf8'),\n );\n setTimeout(() => process.exit(0), 1000); // Hack to ensure worker exits\n });\n}\n\nfunction getMockSnapProvider(): MockSnapProvider {\n const mockProvider = new EventEmitter() as Partial<MockSnapProvider>;\n mockProvider.registerRpcMessageHandler = () => true;\n mockProvider.request = async () => true;\n return mockProvider as MockSnapProvider;\n}\n\nfunction getMockEndowments() {\n const endowments = {\n BigInt,\n Buffer,\n console,\n crypto,\n Date,\n fetch: () => true,\n Math,\n wallet: getMockSnapProvider(),\n setTimeout,\n SubtleCrypto: () => undefined,\n WebSocket: () => true,\n XMLHttpRequest: () => true,\n };\n\n return {\n ...endowments,\n window: endowments,\n };\n}\n"]}
|
package/dist/cmds/init/index.js
CHANGED
|
@@ -9,6 +9,7 @@ async function init(argv) {
|
|
|
9
9
|
console.log();
|
|
10
10
|
const newArgs = await initHandler_1.initHandler(argv);
|
|
11
11
|
await buildHandler_1.build(Object.assign(Object.assign({}, newArgs), { manifest: false, eval: true }));
|
|
12
|
+
await initHandler_1.updateManifestShasum();
|
|
12
13
|
console.log('\nSnap project successfully initiated!');
|
|
13
14
|
}
|
|
14
15
|
module.exports = {
|
|
@@ -18,8 +19,8 @@ module.exports = {
|
|
|
18
19
|
yarg
|
|
19
20
|
.option('src', builders_1.default.src)
|
|
20
21
|
.option('dist', builders_1.default.dist)
|
|
21
|
-
.option('
|
|
22
|
-
.option('
|
|
22
|
+
.option('port', builders_1.default.port)
|
|
23
|
+
.option('outfileName', builders_1.default.outfileName);
|
|
23
24
|
},
|
|
24
25
|
handler: (argv) => init(argv),
|
|
25
26
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cmds/init/index.ts"],"names":[],"mappings":";;;;AACA,8DAAsC;AAEtC,wDAA8C;AAC9C,+
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cmds/init/index.ts"],"names":[],"mappings":";;;;AACA,8DAAsC;AAEtC,wDAA8C;AAC9C,+CAAkE;AAelE,KAAK,UAAU,IAAI,CAAC,IAAe;IACjC,OAAO,CAAC,GAAG,EAAE,CAAC;IACd,MAAM,OAAO,GAAG,MAAM,yBAAW,CAAC,IAAI,CAAC,CAAC;IAExC,MAAM,oBAAK,iCACN,OAAO,KACV,QAAQ,EAAE,KAAK,EACf,IAAI,EAAE,IAAI,IACV,CAAC;IAEH,MAAM,kCAAoB,EAAE,CAAC;IAE7B,OAAO,CAAC,GAAG,CAAC,wCAAwC,CAAC,CAAC;AACxD,CAAC;AA1BD,iBAAS;IACP,OAAO,EAAE,CAAC,MAAM,EAAE,GAAG,CAAC;IACtB,IAAI,EAAE,yBAAyB;IAC/B,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,MAAM,EAAE,kBAAQ,CAAC,IAAI,CAAC;aAC7B,MAAM,CAAC,aAAa,EAAE,kBAAQ,CAAC,WAAW,CAAC,CAAC;IACjD,CAAC;IACD,OAAO,EAAE,CAAC,IAAe,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC;CACzC,CAAC","sourcesContent":["import yargs from 'yargs';\nimport builders from '../../builders';\nimport { YargsArgs } from '../../types/yargs';\nimport { build } from '../build/buildHandler';\nimport { initHandler, updateManifestShasum } from './initHandler';\n\nexport = {\n command: ['init', 'i'],\n desc: 'Initialize Snap package',\n builder: (yarg: yargs.Argv) => {\n yarg\n .option('src', builders.src)\n .option('dist', builders.dist)\n .option('port', builders.port)\n .option('outfileName', builders.outfileName);\n },\n handler: (argv: YargsArgs) => init(argv),\n};\n\nasync function init(argv: YargsArgs): Promise<void> {\n console.log();\n const newArgs = await initHandler(argv);\n\n await build({\n ...newArgs,\n manifest: false,\n eval: true,\n });\n\n await updateManifestShasum();\n\n console.log('\\nSnap project successfully initiated!');\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
{
|
|
2
|
-
"html": "<!doctype html>\n
|
|
3
|
-
"
|
|
2
|
+
"html": "<!doctype html>\n<html>\n </head>\n <title>Hello, Snaps!</title>\n </head>\n\n <body>\n <h1>Hello, Snaps!</h1>\n <details>\n <summary>Instructions</summary>\n <ul>\n <li>First, click \"Connect\". Then, try out the other buttons!</li>\n <li>Please note that:</li>\n <ul>\n <li>\n The <code>snap.manifest.json</code> and <code>package.json</code> must be located in located in the server root directory..\n </li>\n <li>\n The Snap bundle must be hosted at the location specified by the <code>location</code> field of <code>snap.manifest.json</code>.\n </li>\n </ul>\n </ul>\n </details>\n <br/>\n\n <button class=\"connect\">Connect</button>\n <button class=\"sendHello\">Send Hello</button>\n </body>\n\n <script>\n\n // When developing locally, we identify Snaps like this\n const snapId = `local:${window.location.href}`;\n\n const connectButton = document.querySelector('button.connect')\n const sendButton = document.querySelector('button.sendHello')\n\n connectButton.addEventListener('click', connect)\n sendButton.addEventListener('click', send)\n\n // here we get permissions to interact with and install the snap\n async function connect () {\n await ethereum.request({\n method: 'wallet_enable',\n params: [{\n wallet_snap: { [snapId]: {} },\n }]\n })\n }\n\n // here we call the snap's \"hello\" method\n async function send () {\n try {\n const response = await ethereum.request({\n method: 'wallet_invokeSnap',\n params: [snapId, {\n method: 'hello'\n }]\n })\n } catch (err) {\n console.error(err)\n alert('Problem happened: ' + err.message || err)\n }\n }\n\n </script>\n</html>\n",
|
|
3
|
+
"source": "wallet.registerRpcMessageHandler(async (originString, requestObject) => {\n switch (requestObject.method) {\n case 'hello':\n return wallet.request({\n method: 'snap_confirm',\n params: [{ prompt: `Hello, ${originString}!` }],\n });\n default:\n throw new Error('Method not found.');\n }\n});\n"
|
|
4
4
|
}
|
|
@@ -6,7 +6,12 @@ export declare function initHandler(argv: YargsArgs): Promise<{
|
|
|
6
6
|
port: number;
|
|
7
7
|
dist: string;
|
|
8
8
|
src: string;
|
|
9
|
-
outfileName
|
|
9
|
+
outfileName: string;
|
|
10
10
|
_?: (string | number)[] | undefined;
|
|
11
11
|
$0?: string | undefined;
|
|
12
12
|
}>;
|
|
13
|
+
/**
|
|
14
|
+
* This updates the Snap shasum value of the manifest after building the Snap
|
|
15
|
+
* during the init command.
|
|
16
|
+
*/
|
|
17
|
+
export declare function updateManifestShasum(): Promise<void>;
|