@metamask/snaps-utils 0.37.0-flask.1 → 0.37.2-flask.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.
- package/CHANGELOG.md +6 -281
- package/dist/cjs/enum.js +2 -2
- package/dist/cjs/enum.js.map +1 -1
- package/dist/cjs/eval.js +54 -6
- package/dist/cjs/eval.js.map +1 -1
- package/dist/cjs/index.browser.js +2 -0
- package/dist/cjs/index.browser.js.map +1 -1
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/manifest/manifest.js +4 -4
- package/dist/cjs/manifest/manifest.js.map +1 -1
- package/dist/cjs/strings.js +21 -0
- package/dist/cjs/strings.js.map +1 -0
- package/dist/cjs/structs.js +163 -0
- package/dist/cjs/structs.js.map +1 -0
- package/dist/esm/enum.js +1 -1
- package/dist/esm/enum.js.map +1 -1
- package/dist/esm/eval.js +43 -3
- package/dist/esm/eval.js.map +1 -1
- package/dist/esm/index.browser.js +2 -0
- package/dist/esm/index.browser.js.map +1 -1
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/manifest/manifest.js +5 -4
- package/dist/esm/manifest/manifest.js.map +1 -1
- package/dist/esm/strings.js +11 -0
- package/dist/esm/strings.js.map +1 -0
- package/dist/esm/structs.js +230 -0
- package/dist/esm/structs.js.map +1 -0
- package/dist/types/enum.d.ts +1 -1
- package/dist/types/eval.d.ts +9 -1
- package/dist/types/index.browser.d.ts +2 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/manifest/manifest.d.ts +3 -1
- package/dist/types/strings.d.ts +8 -0
- package/dist/types/structs.d.ts +158 -0
- package/package.json +4 -3
package/CHANGELOG.md
CHANGED
|
@@ -6,286 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
-
## [0.37.
|
|
9
|
+
## [0.37.2-flask.1]
|
|
10
10
|
### Changed
|
|
11
|
-
-
|
|
11
|
+
- Release package independently ([#1600](https://github.com/MetaMask/snaps/pull/1600))
|
|
12
|
+
- The version of the package no longer needs to match the version of all other
|
|
13
|
+
MetaMask Snaps packages.
|
|
12
14
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
- No changes this release.
|
|
16
|
-
|
|
17
|
-
## [0.36.0-flask.1]
|
|
18
|
-
### Changed
|
|
19
|
-
- No changes this release.
|
|
20
|
-
|
|
21
|
-
## [0.35.2-flask.1]
|
|
22
|
-
### Fixed
|
|
23
|
-
- Fix type issue introduced by [#1532](https://github.com/MetaMask/snaps/pull/1532) ([#1541](https://github.com/MetaMask/snaps/pull/1541))
|
|
24
|
-
|
|
25
|
-
## [0.35.1-flask.1]
|
|
26
|
-
### Changed
|
|
27
|
-
- No changes this release.
|
|
28
|
-
|
|
29
|
-
## [0.35.0-flask.1]
|
|
30
|
-
### Added
|
|
31
|
-
- Add `snap_manageAccounts` RPC method ([#1290](https://github.com/MetaMask/snaps/pull/1290))
|
|
32
|
-
|
|
33
|
-
### Changed
|
|
34
|
-
- **BREAKING:** Build packages as both CJS and ESM ([#1519](https://github.com/MetaMask/snaps/pull/1519), ([#1532](https://github.com/MetaMask/snaps/pull/1532)))
|
|
35
|
-
- This is breaking in the sense that imports to `dist/` will now require you to import either `dist/cjs` or `dist/esm`.
|
|
36
|
-
- **BREAKING:** Disallow deriving Ethereum keys ([#1217](https://github.com/MetaMask/snaps/pull/1217))
|
|
37
|
-
- Coin type `60` is now blocked for derivation.
|
|
38
|
-
- Add `sideEffects: false` ([#1486](https://github.com/MetaMask/snaps/pull/1486))
|
|
39
|
-
|
|
40
|
-
### Removed
|
|
41
|
-
- **BREAKING:** Remove utility functions used for multichain/keyring effort ([#1527](https://github.com/MetaMask/snaps/pull/1527))
|
|
42
|
-
|
|
43
|
-
### Fixed
|
|
44
|
-
- Improve JSON parsing safety ([#1499](https://github.com/MetaMask/snaps/pull/1499))
|
|
45
|
-
- Fix false positives when post processing code with HTML comment tokens ([#1522](https://github.com/MetaMask/snaps/pull/1522))
|
|
46
|
-
- Fix BIP-32 path validation ([#1506](https://github.com/MetaMask/snaps/pull/1506))
|
|
47
|
-
|
|
48
|
-
## [0.34.1-flask.1]
|
|
49
|
-
### Changed
|
|
50
|
-
- No changes this release.
|
|
51
|
-
|
|
52
|
-
## [0.34.0-flask.1]
|
|
53
|
-
### Changed
|
|
54
|
-
- Add SVG validation ([#1401](https://github.com/MetaMask/snaps/pull/1401))
|
|
55
|
-
- Make handler types generic, allowing them to be changed ([#1409](https://github.com/MetaMask/snaps/pull/1409))
|
|
56
|
-
- Allow use of `$schema` in manifest files ([#1389](https://github.com/MetaMask/snaps/pull/1389))
|
|
57
|
-
|
|
58
|
-
## [0.33.1-flask.1]
|
|
59
|
-
### Changed
|
|
60
|
-
- No changes this release.
|
|
61
|
-
|
|
62
|
-
## [0.33.0-flask.1]
|
|
63
|
-
### Changed
|
|
64
|
-
- **BREAKING:** Added `snapIds` caveat mapper ([#1360](https://github.com/MetaMask/snaps-monorepo/pull/1360))
|
|
65
|
-
- Snap dependencies must be specified in a simplified manner. See the PR for an example.
|
|
66
|
-
- Add subject type restrictions to snap-specific permissions ([#1366](https://github.com/MetaMask/snaps-monorepo/pull/1366))
|
|
67
|
-
- Add Web Worker support for snap execution ([#1320](https://github.com/MetaMask/snaps-monorepo/pull/1320))
|
|
68
|
-
|
|
69
|
-
### Fixed
|
|
70
|
-
- Add `WebAssembly` to eval mock ([#1359](https://github.com/MetaMask/snaps-monorepo/pull/1359))
|
|
71
|
-
|
|
72
|
-
## [0.32.2]
|
|
73
|
-
### Changed
|
|
74
|
-
- No changes this release.
|
|
75
|
-
|
|
76
|
-
## [0.32.1]
|
|
77
|
-
### Changed
|
|
78
|
-
- No changes this release.
|
|
79
|
-
|
|
80
|
-
## [0.32.0]
|
|
81
|
-
### Changed
|
|
82
|
-
- Use side effects to install snaps via `wallet_snap` permission ([#1301](https://github.com/MetaMask/snaps-monorepo/pull/1301))
|
|
83
|
-
|
|
84
|
-
## [0.31.0]
|
|
85
|
-
### Changed
|
|
86
|
-
- **BREAKING:** Target `ES2020` ([#1247](https://github.com/MetaMask/snaps-monorepo/pull/1247))
|
|
87
|
-
- Improve validation and sanitizing of snap IDs ([#1237](https://github.com/MetaMask/snaps-monorepo/pull/1237))
|
|
88
|
-
|
|
89
|
-
## [0.30.0]
|
|
90
|
-
### Changed
|
|
91
|
-
- Properly sandbox iframe and inline SES in execution bundles ([#1193](https://github.com/MetaMask/snaps-monorepo/pull/1193))
|
|
92
|
-
|
|
93
|
-
## [0.29.0]
|
|
94
|
-
### Changed
|
|
95
|
-
- Skip writing manifest if identical ([#1171](https://github.com/MetaMask/snaps-monorepo/pull/1171))
|
|
96
|
-
- This fixes a bug on Windows where the CLI could get stuck in a loop
|
|
97
|
-
|
|
98
|
-
### Removed
|
|
99
|
-
- **BREAKING:** Remove `SnapsGlobalObject` type ([#1014](https://github.com/MetaMask/snaps-monorepo/pull/1014))
|
|
100
|
-
|
|
101
|
-
## [0.28.0]
|
|
102
|
-
### Added
|
|
103
|
-
- **BREAKING:** Add support for snap registries ([#1090](https://github.com/MetaMask/snaps-monorepo/pull/1090))
|
|
104
|
-
- This removes the `checkBlockList` constructor argument in favor of `registry`
|
|
105
|
-
- A registry implementation can be passed here, defaulting to a hosted JSON file
|
|
106
|
-
- Requiring a snap to be on the allowlist can be toggled with the feature flag `requireAllowlist`
|
|
107
|
-
- Add experimental offscreen execution environment ([#1082](https://github.com/MetaMask/snaps-monorepo/pull/1082))
|
|
108
|
-
|
|
109
|
-
### Changed
|
|
110
|
-
- **BREAKING:** Bump `key-tree` to 6.2.0 and use `Uint8Array` for secret recovery phrases ([#1137](https://github.com/MetaMask/snaps-monorepo/pull/1137))
|
|
111
|
-
|
|
112
|
-
### Removed
|
|
113
|
-
- **BREAKING:** Remove `WebSocket` endowment ([#1122](https://github.com/MetaMask/snaps-monorepo/pull/1122))
|
|
114
|
-
|
|
115
|
-
### Fixed
|
|
116
|
-
- Fix missing cronjob export ([#1134](https://github.com/MetaMask/snaps-monorepo/pull/1134))
|
|
117
|
-
|
|
118
|
-
## [0.27.1]
|
|
119
|
-
### Changed
|
|
120
|
-
- No changes this release.
|
|
121
|
-
|
|
122
|
-
## [0.27.0]
|
|
123
|
-
### Changed
|
|
124
|
-
- **BREAKING:** Use SIP-6 algorithm for state encryption ([#1055](https://github.com/MetaMask/snaps-monorepo/pull/1055))
|
|
125
|
-
- This breaks all existing snaps that use `snap_manageState`
|
|
126
|
-
- **BREAKING:** Use custom UI in transaction insights ([#1047](https://github.com/MetaMask/snaps-monorepo/pull/1047))
|
|
127
|
-
- **BREAKING:** Move all internal types from `snaps-types` to `snaps-utils` ([#1060](https://github.com/MetaMask/snaps-monorepo/pull/1060))
|
|
128
|
-
|
|
129
|
-
## [0.26.2]
|
|
130
|
-
### Changed
|
|
131
|
-
- No changes this release.
|
|
132
|
-
|
|
133
|
-
## [0.26.1]
|
|
134
|
-
### Fixed
|
|
135
|
-
- Fix some paths being wrongly normalized ([#1053](https://github.com/MetaMask/snaps-monorepo/pull/1053))
|
|
136
|
-
- Fix utils browser export ([#1049](https://github.com/MetaMask/snaps-monorepo/pull/1049))
|
|
137
|
-
|
|
138
|
-
## [0.26.0]
|
|
139
|
-
### Fixed
|
|
140
|
-
- Fix post processing issue with `object.eval` ([#1040](https://github.com/MetaMask/snaps-monorepo/pull/1040))
|
|
141
|
-
|
|
142
|
-
## [0.25.0]
|
|
143
|
-
### Added
|
|
144
|
-
- **BREAKING:** Add JSON-RPC handler permission ([#905](https://github.com/MetaMask/snaps-monorepo/pull/905))
|
|
145
|
-
- Snaps are now required to request `endowment:rpc` to receive RPC requests.
|
|
146
|
-
|
|
147
|
-
## [0.24.1]
|
|
148
|
-
### Fixed
|
|
149
|
-
- Fix `snap_getBip32PublicKey` manifest validation ([#970](https://github.com/MetaMask/snaps-monorepo/pull/970))
|
|
150
|
-
|
|
151
|
-
## [0.24.0]
|
|
152
|
-
### Added
|
|
153
|
-
- Add transaction insight caveat for accessing transaction origin ([#902](https://github.com/MetaMask/snaps-monorepo/pull/902))
|
|
154
|
-
- Add `snap_getEntropy` JSON-RPC method ([#940](https://github.com/MetaMask/snaps-monorepo/pull/940))
|
|
155
|
-
- Add permission validation to `snap.manifest.json` ([#910](https://github.com/MetaMask/snaps-monorepo/pull/910))
|
|
156
|
-
- Add compile-time warning when using `Math.random` ([#950](https://github.com/MetaMask/snaps-monorepo/pull/950))
|
|
157
|
-
|
|
158
|
-
### Changed
|
|
159
|
-
- **BREAKING:** Rename package to start with `snaps-` ([#937](https://github.com/MetaMask/snaps-monorepo/pull/937))
|
|
160
|
-
- **BREAKING:** Remove `wallet` global in favor of `snap` and `ethereum` ([#939](https://github.com/MetaMask/snaps-monorepo/pull/939), [#964](https://github.com/MetaMask/snaps-monorepo/pull/964))
|
|
161
|
-
|
|
162
|
-
## [0.23.0]
|
|
163
|
-
### Added
|
|
164
|
-
- Add snap cronjobs ([#651](https://github.com/MetaMask/snaps-monorepo/pull/651))
|
|
165
|
-
|
|
166
|
-
### Changed
|
|
167
|
-
- **BREAKING:** Replace Buffer with Typed Arrays ([#878](https://github.com/MetaMask/snaps-monorepo/pull/878))
|
|
168
|
-
- Improve keyring endowment error messaging ([#884](https://github.com/MetaMask/snaps-monorepo/pull/884))
|
|
169
|
-
- Replace JSON schema validation with structs ([#862](https://github.com/MetaMask/snaps-monorepo/pull/862))
|
|
170
|
-
|
|
171
|
-
### Removed
|
|
172
|
-
- **BREAKING:** Stop including source code in SnapController state ([#861](https://github.com/MetaMask/snaps-monorepo/pull/861))
|
|
173
|
-
|
|
174
|
-
## [0.22.3]
|
|
175
|
-
### Fixed
|
|
176
|
-
- Make @babel/types a regular dependency ([#852](https://github.com/MetaMask/snaps-monorepo/pull/852))
|
|
177
|
-
|
|
178
|
-
## [0.22.2]
|
|
179
|
-
### Changed
|
|
180
|
-
- No changes this release.
|
|
181
|
-
|
|
182
|
-
## [0.22.1]
|
|
183
|
-
### Fixed
|
|
184
|
-
- Add browser entry point for `snap-utils` ([#820](https://github.com/MetaMask/snaps-monorepo/pull/820))
|
|
185
|
-
|
|
186
|
-
## [0.22.0]
|
|
187
|
-
### Added
|
|
188
|
-
- Add functionality required for Snap Keyring support ([#700](https://github.com/MetaMask/snaps-monorepo/pull/700), [#777](https://github.com/MetaMask/snaps-monorepo/pull/777))
|
|
189
|
-
|
|
190
|
-
## [0.21.0]
|
|
191
|
-
### Changed
|
|
192
|
-
- Run eval and fix manifest in bundler plugins ([#731](https://github.com/MetaMask/snaps-monorepo/pull/731))
|
|
193
|
-
|
|
194
|
-
## [0.20.0]
|
|
195
|
-
### Added
|
|
196
|
-
- **BREAKING:** Add Transaction Insight API ([#642](https://github.com/MetaMask/snaps-monorepo/pull/642))
|
|
197
|
-
- Add internal types from `@metamask/snaps-types` ([#695](https://github.com/MetaMask/snaps-monorepo/pull/695))
|
|
198
|
-
|
|
199
|
-
### Changed
|
|
200
|
-
- **BREAKING:** Simplify manifest format for permission caveats ([#705](https://github.com/MetaMask/snaps-monorepo/pull/705))
|
|
201
|
-
- Reduce TypeScript compilation target for `snap-controllers` ([#708](https://github.com/MetaMask/snaps-monorepo/pull/708))
|
|
202
|
-
|
|
203
|
-
## [0.19.1]
|
|
204
|
-
### Added
|
|
205
|
-
- Generate source maps from modified code ([#615](https://github.com/MetaMask/snaps-monorepo/pull/615))
|
|
206
|
-
|
|
207
|
-
## [0.19.0]
|
|
208
|
-
### Changed
|
|
209
|
-
- Move eval functionality to utils package ([#666](https://github.com/MetaMask/snaps-monorepo/pull/666))
|
|
210
|
-
- Move manifest handling functionality to utils ([#652](https://github.com/MetaMask/snaps-monorepo/pull/652))
|
|
211
|
-
- Move JSON schemas and controller utils to utils package ([#623](https://github.com/MetaMask/snaps-monorepo/pull/623))
|
|
212
|
-
|
|
213
|
-
### Fixed
|
|
214
|
-
- Fixed missing AbortSignal in default endowments ([#682](https://github.com/MetaMask/snaps-monorepo/pull/682))
|
|
215
|
-
|
|
216
|
-
## [0.18.1]
|
|
217
|
-
### Changed
|
|
218
|
-
- No changes this release.
|
|
219
|
-
|
|
220
|
-
## [0.18.0]
|
|
221
|
-
### Changed
|
|
222
|
-
- Reduce TypeScript compilation target to ES2017 ([#628](https://github.com/MetaMask/snaps-monorepo/pull/628))
|
|
223
|
-
|
|
224
|
-
## [0.17.0]
|
|
225
|
-
### Changed
|
|
226
|
-
- **BREAKING:** Bump minimum Node version to 16 ([#601](https://github.com/MetaMask/snaps-monorepo/pull/601))
|
|
227
|
-
|
|
228
|
-
## [0.16.0]
|
|
229
|
-
### Changed
|
|
230
|
-
- No changes this release.
|
|
231
|
-
|
|
232
|
-
## [0.15.0]
|
|
233
|
-
### Fixed
|
|
234
|
-
- Fix an issue where comment stripping would break for large files ([#468](https://github.com/MetaMask/snaps-monorepo/pull/468))
|
|
235
|
-
|
|
236
|
-
## [0.14.0]
|
|
237
|
-
### Changed
|
|
238
|
-
- **BREAKING:** Increase TypeScript compilation target to ES2020 ([#449](https://github.com/MetaMask/snaps-monorepo/pull/449))
|
|
239
|
-
- This should not be breaking for consumers on any non-deprecated browser or Node.js version.
|
|
240
|
-
|
|
241
|
-
## [0.13.0]
|
|
242
|
-
### Changed
|
|
243
|
-
- No changes this release.
|
|
244
|
-
|
|
245
|
-
## [0.12.0]
|
|
246
|
-
### Added
|
|
247
|
-
- Initial release ([#410](https://github.com/MetaMask/snaps-monorepo/pull/410), [#421](https://github.com/MetaMask/snaps-monorepo/pull/421))
|
|
248
|
-
|
|
249
|
-
[Unreleased]: https://github.com/MetaMask/snaps/compare/v0.37.0-flask.1...HEAD
|
|
250
|
-
[0.37.0-flask.1]: https://github.com/MetaMask/snaps/compare/v0.36.1-flask.1...v0.37.0-flask.1
|
|
251
|
-
[0.36.1-flask.1]: https://github.com/MetaMask/snaps/compare/v0.36.0-flask.1...v0.36.1-flask.1
|
|
252
|
-
[0.36.0-flask.1]: https://github.com/MetaMask/snaps/compare/v0.35.2-flask.1...v0.36.0-flask.1
|
|
253
|
-
[0.35.2-flask.1]: https://github.com/MetaMask/snaps/compare/v0.35.1-flask.1...v0.35.2-flask.1
|
|
254
|
-
[0.35.1-flask.1]: https://github.com/MetaMask/snaps/compare/v0.35.0-flask.1...v0.35.1-flask.1
|
|
255
|
-
[0.35.0-flask.1]: https://github.com/MetaMask/snaps/compare/v0.34.1-flask.1...v0.35.0-flask.1
|
|
256
|
-
[0.34.1-flask.1]: https://github.com/MetaMask/snaps/compare/v0.34.0-flask.1...v0.34.1-flask.1
|
|
257
|
-
[0.34.0-flask.1]: https://github.com/MetaMask/snaps/compare/v0.33.1-flask.1...v0.34.0-flask.1
|
|
258
|
-
[0.33.1-flask.1]: https://github.com/MetaMask/snaps/compare/v0.33.0-flask.1...v0.33.1-flask.1
|
|
259
|
-
[0.33.0-flask.1]: https://github.com/MetaMask/snaps/compare/v0.32.2...v0.33.0-flask.1
|
|
260
|
-
[0.32.2]: https://github.com/MetaMask/snaps/compare/v0.32.1...v0.32.2
|
|
261
|
-
[0.32.1]: https://github.com/MetaMask/snaps/compare/v0.32.0...v0.32.1
|
|
262
|
-
[0.32.0]: https://github.com/MetaMask/snaps/compare/v0.31.0...v0.32.0
|
|
263
|
-
[0.31.0]: https://github.com/MetaMask/snaps/compare/v0.30.0...v0.31.0
|
|
264
|
-
[0.30.0]: https://github.com/MetaMask/snaps/compare/v0.29.0...v0.30.0
|
|
265
|
-
[0.29.0]: https://github.com/MetaMask/snaps/compare/v0.28.0...v0.29.0
|
|
266
|
-
[0.28.0]: https://github.com/MetaMask/snaps/compare/v0.27.1...v0.28.0
|
|
267
|
-
[0.27.1]: https://github.com/MetaMask/snaps/compare/v0.27.0...v0.27.1
|
|
268
|
-
[0.27.0]: https://github.com/MetaMask/snaps/compare/v0.26.2...v0.27.0
|
|
269
|
-
[0.26.2]: https://github.com/MetaMask/snaps/compare/v0.26.1...v0.26.2
|
|
270
|
-
[0.26.1]: https://github.com/MetaMask/snaps/compare/v0.26.0...v0.26.1
|
|
271
|
-
[0.26.0]: https://github.com/MetaMask/snaps/compare/v0.25.0...v0.26.0
|
|
272
|
-
[0.25.0]: https://github.com/MetaMask/snaps/compare/v0.24.1...v0.25.0
|
|
273
|
-
[0.24.1]: https://github.com/MetaMask/snaps/compare/v0.24.0...v0.24.1
|
|
274
|
-
[0.24.0]: https://github.com/MetaMask/snaps/compare/v0.23.0...v0.24.0
|
|
275
|
-
[0.23.0]: https://github.com/MetaMask/snaps/compare/v0.22.3...v0.23.0
|
|
276
|
-
[0.22.3]: https://github.com/MetaMask/snaps/compare/v0.22.2...v0.22.3
|
|
277
|
-
[0.22.2]: https://github.com/MetaMask/snaps/compare/v0.22.1...v0.22.2
|
|
278
|
-
[0.22.1]: https://github.com/MetaMask/snaps/compare/v0.22.0...v0.22.1
|
|
279
|
-
[0.22.0]: https://github.com/MetaMask/snaps/compare/v0.21.0...v0.22.0
|
|
280
|
-
[0.21.0]: https://github.com/MetaMask/snaps/compare/v0.20.0...v0.21.0
|
|
281
|
-
[0.20.0]: https://github.com/MetaMask/snaps/compare/v0.19.1...v0.20.0
|
|
282
|
-
[0.19.1]: https://github.com/MetaMask/snaps/compare/v0.19.0...v0.19.1
|
|
283
|
-
[0.19.0]: https://github.com/MetaMask/snaps/compare/v0.18.1...v0.19.0
|
|
284
|
-
[0.18.1]: https://github.com/MetaMask/snaps/compare/v0.18.0...v0.18.1
|
|
285
|
-
[0.18.0]: https://github.com/MetaMask/snaps/compare/v0.17.0...v0.18.0
|
|
286
|
-
[0.17.0]: https://github.com/MetaMask/snaps/compare/v0.16.0...v0.17.0
|
|
287
|
-
[0.16.0]: https://github.com/MetaMask/snaps/compare/v0.15.0...v0.16.0
|
|
288
|
-
[0.15.0]: https://github.com/MetaMask/snaps/compare/v0.14.0...v0.15.0
|
|
289
|
-
[0.14.0]: https://github.com/MetaMask/snaps/compare/v0.13.0...v0.14.0
|
|
290
|
-
[0.13.0]: https://github.com/MetaMask/snaps/compare/v0.12.0...v0.13.0
|
|
291
|
-
[0.12.0]: https://github.com/MetaMask/snaps/releases/tag/v0.12.0
|
|
15
|
+
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@0.37.2-flask.1...HEAD
|
|
16
|
+
[0.37.2-flask.1]: https://github.com/MetaMask/snaps/releases/tag/@metamask/snaps-utils@0.37.2-flask.1
|
package/dist/cjs/enum.js
CHANGED
|
@@ -8,9 +8,9 @@ Object.defineProperty(exports, "enumValue", {
|
|
|
8
8
|
return enumValue;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
const
|
|
11
|
+
const _structs = require("./structs");
|
|
12
12
|
function enumValue(constant) {
|
|
13
|
-
return (0,
|
|
13
|
+
return (0, _structs.literal)(constant);
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
//# sourceMappingURL=enum.js.map
|
package/dist/cjs/enum.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/enum.ts"],"sourcesContent":["import type { Struct } from 'superstruct';\nimport { literal } from '
|
|
1
|
+
{"version":3,"sources":["../../src/enum.ts"],"sourcesContent":["import type { Struct } from 'superstruct';\n\nimport { literal } from './structs';\n\n/**\n * Get the enum values as union type. This allows using both the enum string\n * values and the enum itself as values.\n *\n * Note: This only works for string enums.\n *\n * @example\n * ```typescript\n * enum Foo {\n * Bar = 'bar',\n * Baz = 'baz',\n * }\n *\n * type FooValue = EnumToUnion<Foo>;\n * // FooValue is 'bar' | 'baz'\n *\n * const foo: FooValue = Foo.Bar; // Works\n * const foo: FooValue = 'bar'; // Also works\n * ```\n */\nexport type EnumToUnion<Type extends string> = `${Type}`;\n\n/**\n * Superstruct struct for validating an enum value. This allows using both the\n * enum string values and the enum itself as values.\n *\n * @param constant - The enum to validate against.\n * @returns The superstruct struct.\n */\nexport function enumValue<Type extends string>(\n constant: Type,\n): Struct<EnumToUnion<Type>, null> {\n return literal(constant as EnumToUnion<Type>);\n}\n"],"names":["enumValue","constant","literal"],"mappings":";;;;+BAiCgBA;;;eAAAA;;;yBA/BQ;AA+BjB,SAASA,UACdC,QAAc;IAEd,OAAOC,IAAAA,gBAAO,EAACD;AACjB"}
|
package/dist/cjs/eval.js
CHANGED
|
@@ -2,26 +2,74 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
SnapEvalError: function() {
|
|
13
|
+
return SnapEvalError;
|
|
14
|
+
},
|
|
15
|
+
evalBundle: function() {
|
|
8
16
|
return evalBundle;
|
|
9
17
|
}
|
|
10
18
|
});
|
|
19
|
+
const _utils = require("@metamask/utils");
|
|
11
20
|
const _child_process = require("child_process");
|
|
12
21
|
const _path = require("path");
|
|
13
22
|
const _fs = require("./fs");
|
|
23
|
+
function _define_property(obj, key, value) {
|
|
24
|
+
if (key in obj) {
|
|
25
|
+
Object.defineProperty(obj, key, {
|
|
26
|
+
value: value,
|
|
27
|
+
enumerable: true,
|
|
28
|
+
configurable: true,
|
|
29
|
+
writable: true
|
|
30
|
+
});
|
|
31
|
+
} else {
|
|
32
|
+
obj[key] = value;
|
|
33
|
+
}
|
|
34
|
+
return obj;
|
|
35
|
+
}
|
|
36
|
+
class SnapEvalError extends Error {
|
|
37
|
+
constructor(message, output){
|
|
38
|
+
super(message);
|
|
39
|
+
_define_property(this, "output", void 0);
|
|
40
|
+
this.name = 'SnapEvalError';
|
|
41
|
+
this.output = output;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
14
44
|
async function evalBundle(bundlePath) {
|
|
15
45
|
await (0, _fs.validateFilePath)(bundlePath);
|
|
16
46
|
return new Promise((resolve, reject)=>{
|
|
17
47
|
const worker = (0, _child_process.fork)((0, _path.join)(__dirname, 'eval-worker.js'), [
|
|
18
48
|
bundlePath
|
|
19
|
-
]
|
|
49
|
+
], {
|
|
50
|
+
// To avoid printing the output of the worker to the console, we set
|
|
51
|
+
// `stdio` to `pipe` and handle the output ourselves.
|
|
52
|
+
stdio: 'pipe'
|
|
53
|
+
});
|
|
54
|
+
let stdout = '';
|
|
55
|
+
let stderr = '';
|
|
56
|
+
(0, _utils.assert)(worker.stdout, '`stdout` should be defined.');
|
|
57
|
+
(0, _utils.assert)(worker.stderr, '`stderr` should be defined.');
|
|
58
|
+
worker.stdout.on('data', (data)=>{
|
|
59
|
+
stdout += data.toString();
|
|
60
|
+
});
|
|
61
|
+
worker.stderr.on('data', (data)=>{
|
|
62
|
+
stderr += data.toString();
|
|
63
|
+
});
|
|
20
64
|
worker.on('exit', (exitCode)=>{
|
|
65
|
+
const output = {
|
|
66
|
+
stdout,
|
|
67
|
+
stderr
|
|
68
|
+
};
|
|
21
69
|
if (exitCode === 0) {
|
|
22
|
-
return resolve(
|
|
70
|
+
return resolve(output);
|
|
23
71
|
}
|
|
24
|
-
return reject(new
|
|
72
|
+
return reject(new SnapEvalError(`Process exited with non-zero exit code: ${exitCode}.`, output));
|
|
25
73
|
});
|
|
26
74
|
});
|
|
27
75
|
}
|
package/dist/cjs/eval.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/eval.ts"],"sourcesContent":["import { fork } from 'child_process';\nimport { join } from 'path';\n\nimport { validateFilePath } from './fs';\n\n/**\n * Spawn a new process to run the provided bundle in.\n *\n * @param bundlePath - The path to the bundle to run.\n * @returns `null` if the worker ran successfully.\n * @throws If the worker failed to run successfully.\n */\nexport async function evalBundle(bundlePath: string): Promise<
|
|
1
|
+
{"version":3,"sources":["../../src/eval.ts"],"sourcesContent":["import { assert } from '@metamask/utils';\nimport { fork } from 'child_process';\nimport { join } from 'path';\n\nimport { validateFilePath } from './fs';\n\nexport type EvalOutput = {\n stdout: string;\n stderr: string;\n};\n\nexport class SnapEvalError extends Error {\n readonly output: EvalOutput;\n\n constructor(message: string, output: EvalOutput) {\n super(message);\n\n this.name = 'SnapEvalError';\n this.output = output;\n }\n}\n\n/**\n * Spawn a new process to run the provided bundle in.\n *\n * @param bundlePath - The path to the bundle to run.\n * @returns `null` if the worker ran successfully.\n * @throws If the worker failed to run successfully.\n */\nexport async function evalBundle(bundlePath: string): Promise<EvalOutput> {\n await validateFilePath(bundlePath);\n\n return new Promise((resolve, reject) => {\n const worker = fork(join(__dirname, 'eval-worker.js'), [bundlePath], {\n // To avoid printing the output of the worker to the console, we set\n // `stdio` to `pipe` and handle the output ourselves.\n stdio: 'pipe',\n });\n\n let stdout = '';\n let stderr = '';\n\n assert(worker.stdout, '`stdout` should be defined.');\n assert(worker.stderr, '`stderr` should be defined.');\n\n worker.stdout.on('data', (data: Buffer) => {\n stdout += data.toString();\n });\n\n worker.stderr.on('data', (data: Buffer) => {\n stderr += data.toString();\n });\n\n worker.on('exit', (exitCode: number) => {\n const output = {\n stdout,\n stderr,\n };\n\n if (exitCode === 0) {\n return resolve(output);\n }\n\n return reject(\n new SnapEvalError(\n `Process exited with non-zero exit code: ${exitCode}.`,\n output,\n ),\n );\n });\n });\n}\n"],"names":["SnapEvalError","evalBundle","Error","constructor","message","output","name","bundlePath","validateFilePath","Promise","resolve","reject","worker","fork","join","__dirname","stdio","stdout","stderr","assert","on","data","toString","exitCode"],"mappings":";;;;;;;;;;;IAWaA,aAAa;eAAbA;;IAkBSC,UAAU;eAAVA;;;uBA7BC;+BACF;sBACA;oBAEY;;;;;;;;;;;;;;AAO1B,MAAMD,sBAAsBE;IAGjCC,YAAYC,OAAe,EAAEC,MAAkB,CAAE;QAC/C,KAAK,CAACD;QAHR,uBAASC,UAAT,KAAA;QAKE,IAAI,CAACC,IAAI,GAAG;QACZ,IAAI,CAACD,MAAM,GAAGA;IAChB;AACF;AASO,eAAeJ,WAAWM,UAAkB;IACjD,MAAMC,IAAAA,oBAAgB,EAACD;IAEvB,OAAO,IAAIE,QAAQ,CAACC,SAASC;QAC3B,MAAMC,SAASC,IAAAA,mBAAI,EAACC,IAAAA,UAAI,EAACC,WAAW,mBAAmB;YAACR;SAAW,EAAE;YACnE,oEAAoE;YACpE,qDAAqD;YACrDS,OAAO;QACT;QAEA,IAAIC,SAAS;QACb,IAAIC,SAAS;QAEbC,IAAAA,aAAM,EAACP,OAAOK,MAAM,EAAE;QACtBE,IAAAA,aAAM,EAACP,OAAOM,MAAM,EAAE;QAEtBN,OAAOK,MAAM,CAACG,EAAE,CAAC,QAAQ,CAACC;YACxBJ,UAAUI,KAAKC,QAAQ;QACzB;QAEAV,OAAOM,MAAM,CAACE,EAAE,CAAC,QAAQ,CAACC;YACxBH,UAAUG,KAAKC,QAAQ;QACzB;QAEAV,OAAOQ,EAAE,CAAC,QAAQ,CAACG;YACjB,MAAMlB,SAAS;gBACbY;gBACAC;YACF;YAEA,IAAIK,aAAa,GAAG;gBAClB,OAAOb,QAAQL;YACjB;YAEA,OAAOM,OACL,IAAIX,cACF,CAAC,wCAAwC,EAAEuB,SAAS,CAAC,CAAC,EACtDlB;QAGN;IACF;AACF"}
|
|
@@ -19,6 +19,8 @@ _export_star(require("./manifest/index.browser"), exports);
|
|
|
19
19
|
_export_star(require("./namespace"), exports);
|
|
20
20
|
_export_star(require("./path"), exports);
|
|
21
21
|
_export_star(require("./snaps"), exports);
|
|
22
|
+
_export_star(require("./strings"), exports);
|
|
23
|
+
_export_star(require("./structs"), exports);
|
|
22
24
|
_export_star(require("./types"), exports);
|
|
23
25
|
_export_star(require("./validation"), exports);
|
|
24
26
|
_export_star(require("./versions"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.browser.ts"],"sourcesContent":["export * from './array';\nexport * from './caveats';\nexport * from './checksum';\nexport * from './cronjob';\nexport * from './deep-clone';\nexport * from './default-endowments';\nexport * from './entropy';\nexport * from './enum';\nexport * from './handlers';\nexport * from './iframe';\nexport * from './json';\nexport * from './json-rpc';\nexport * from './logging';\nexport * from './manifest/index.browser';\nexport * from './namespace';\nexport * from './path';\nexport * from './snaps';\nexport * from './types';\nexport * from './validation';\nexport * from './versions';\nexport * from './virtual-file/index.browser';\n"],"names":[],"mappings":";;;;qBAAc;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA"}
|
|
1
|
+
{"version":3,"sources":["../../src/index.browser.ts"],"sourcesContent":["export * from './array';\nexport * from './caveats';\nexport * from './checksum';\nexport * from './cronjob';\nexport * from './deep-clone';\nexport * from './default-endowments';\nexport * from './entropy';\nexport * from './enum';\nexport * from './handlers';\nexport * from './iframe';\nexport * from './json';\nexport * from './json-rpc';\nexport * from './logging';\nexport * from './manifest/index.browser';\nexport * from './namespace';\nexport * from './path';\nexport * from './snaps';\nexport * from './strings';\nexport * from './structs';\nexport * from './types';\nexport * from './validation';\nexport * from './versions';\nexport * from './virtual-file/index.browser';\n"],"names":[],"mappings":";;;;qBAAc;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA"}
|
package/dist/cjs/index.js
CHANGED
|
@@ -24,6 +24,8 @@ _export_star(require("./npm"), exports);
|
|
|
24
24
|
_export_star(require("./path"), exports);
|
|
25
25
|
_export_star(require("./post-process"), exports);
|
|
26
26
|
_export_star(require("./snaps"), exports);
|
|
27
|
+
_export_star(require("./strings"), exports);
|
|
28
|
+
_export_star(require("./structs"), exports);
|
|
27
29
|
_export_star(require("./types"), exports);
|
|
28
30
|
_export_star(require("./validation"), exports);
|
|
29
31
|
_export_star(require("./versions"), exports);
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './array';\nexport * from './caveats';\nexport * from './cronjob';\nexport * from './checksum';\nexport * from './deep-clone';\nexport * from './default-endowments';\nexport * from './entropy';\nexport * from './enum';\nexport * from './eval';\nexport * from './fs';\nexport * from './handlers';\nexport * from './iframe';\nexport * from './json';\nexport * from './json-rpc';\nexport * from './logging';\nexport * from './manifest';\nexport * from './mock';\nexport * from './namespace';\nexport * from './npm';\nexport * from './path';\nexport * from './post-process';\nexport * from './snaps';\nexport * from './types';\nexport * from './validation';\nexport * from './versions';\nexport * from './virtual-file';\n"],"names":[],"mappings":";;;;qBAAc;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA"}
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './array';\nexport * from './caveats';\nexport * from './cronjob';\nexport * from './checksum';\nexport * from './deep-clone';\nexport * from './default-endowments';\nexport * from './entropy';\nexport * from './enum';\nexport * from './eval';\nexport * from './fs';\nexport * from './handlers';\nexport * from './iframe';\nexport * from './json';\nexport * from './json-rpc';\nexport * from './logging';\nexport * from './manifest';\nexport * from './mock';\nexport * from './namespace';\nexport * from './npm';\nexport * from './path';\nexport * from './post-process';\nexport * from './snaps';\nexport * from './strings';\nexport * from './structs';\nexport * from './types';\nexport * from './validation';\nexport * from './versions';\nexport * from './virtual-file';\n"],"names":[],"mappings":";;;;qBAAc;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA"}
|
|
@@ -53,7 +53,7 @@ const MANIFEST_SORT_ORDER = {
|
|
|
53
53
|
initialPermissions: 7,
|
|
54
54
|
manifestVersion: 8
|
|
55
55
|
};
|
|
56
|
-
async function checkManifest(basePath, writeManifest = true, sourceCode) {
|
|
56
|
+
async function checkManifest(basePath, writeManifest = true, sourceCode, writeFileFn = _fs.promises.writeFile) {
|
|
57
57
|
const warnings = [];
|
|
58
58
|
const errors = [];
|
|
59
59
|
let updated = false;
|
|
@@ -124,7 +124,7 @@ async function checkManifest(basePath, writeManifest = true, sourceCode) {
|
|
|
124
124
|
try {
|
|
125
125
|
const newManifest = `${JSON.stringify(getWritableManifest(validatedManifest), null, 2)}\n`;
|
|
126
126
|
if (updated || newManifest !== manifestFile.value) {
|
|
127
|
-
await
|
|
127
|
+
await writeFileFn(_path.default.join(basePath, _types.NpmSnapFileNames.Manifest), newManifest);
|
|
128
128
|
}
|
|
129
129
|
} catch (error) {
|
|
130
130
|
// Note: This error isn't pushed to the errors array, because it's not an
|
|
@@ -181,7 +181,7 @@ async function getSnapSourceCode(basePath, manifest, sourceCode) {
|
|
|
181
181
|
const virtualFile = await (0, _virtualfile.readVirtualFile)(_path.default.join(basePath, sourceFilePath), 'utf8');
|
|
182
182
|
return virtualFile;
|
|
183
183
|
} catch (error) {
|
|
184
|
-
throw new Error(`Failed to read
|
|
184
|
+
throw new Error(`Failed to read snap bundle file: ${error.message}`);
|
|
185
185
|
}
|
|
186
186
|
}
|
|
187
187
|
async function getSnapIcon(basePath, manifest) {
|
|
@@ -196,7 +196,7 @@ async function getSnapIcon(basePath, manifest) {
|
|
|
196
196
|
const virtualFile = await (0, _virtualfile.readVirtualFile)(_path.default.join(basePath, iconPath), 'utf8');
|
|
197
197
|
return virtualFile;
|
|
198
198
|
} catch (error) {
|
|
199
|
-
throw new Error(`Failed to read
|
|
199
|
+
throw new Error(`Failed to read snap icon file: ${error.message}`);
|
|
200
200
|
}
|
|
201
201
|
}
|
|
202
202
|
function getWritableManifest(manifest) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/manifest/manifest.ts"],"sourcesContent":["import type { Json } from '@metamask/utils';\nimport { assertExhaustive, assert, isPlainObject } from '@metamask/utils';\nimport deepEqual from 'fast-deep-equal';\nimport { promises as fs } from 'fs';\nimport pathUtils from 'path';\n\nimport { deepClone } from '../deep-clone';\nimport { readJsonFile } from '../fs';\nimport { validateNpmSnap } from '../npm';\nimport {\n getSnapChecksum,\n ProgrammaticallyFixableSnapError,\n validateSnapShasum,\n} from '../snaps';\nimport type { SnapFiles, UnvalidatedSnapFiles } from '../types';\nimport { NpmSnapFileNames, SnapValidationFailureReason } from '../types';\nimport { readVirtualFile, VirtualFile } from '../virtual-file';\nimport type { SnapManifest } from './validation';\n\nconst MANIFEST_SORT_ORDER: Record<keyof SnapManifest, number> = {\n $schema: 1,\n version: 2,\n description: 3,\n proposedName: 4,\n repository: 5,\n source: 6,\n initialPermissions: 7,\n manifestVersion: 8,\n};\n\n/**\n * The result from the `checkManifest` function.\n *\n * @property manifest - The fixed manifest object.\n * @property updated - Whether the manifest was updated.\n * @property warnings - An array of warnings that were encountered during\n * processing of the manifest files. These warnings are not logged to the\n * console automatically, so depending on the environment the function is called\n * in, a different method for logging can be used.\n * @property errors - An array of errors that were encountered during\n * processing of the manifest files. These errors are not logged to the\n * console automatically, so depending on the environment the function is called\n * in, a different method for logging can be used.\n */\nexport type CheckManifestResult = {\n manifest: SnapManifest;\n updated?: boolean;\n warnings: string[];\n errors: string[];\n};\n\n/**\n * Validates a snap.manifest.json file. Attempts to fix the manifest and write\n * the fixed version to disk if `writeManifest` is true. Throws if validation\n * fails.\n *\n * @param basePath - The path to the folder with the manifest files.\n * @param writeManifest - Whether to write the fixed manifest to disk.\n * @param sourceCode - The source code of the Snap.\n * @returns Whether the manifest was updated, and an array of warnings that\n * were encountered during processing of the manifest files.\n */\nexport async function checkManifest(\n basePath: string,\n writeManifest = true,\n sourceCode?: string,\n): Promise<CheckManifestResult> {\n const warnings: string[] = [];\n const errors: string[] = [];\n\n let updated = false;\n\n const manifestPath = pathUtils.join(basePath, NpmSnapFileNames.Manifest);\n const manifestFile = await readJsonFile(manifestPath);\n const unvalidatedManifest = manifestFile.result;\n\n const packageFile = await readJsonFile(\n pathUtils.join(basePath, NpmSnapFileNames.PackageJson),\n );\n\n const snapFiles: UnvalidatedSnapFiles = {\n manifest: manifestFile,\n packageJson: packageFile,\n sourceCode: await getSnapSourceCode(\n basePath,\n unvalidatedManifest,\n sourceCode,\n ),\n svgIcon: await getSnapIcon(basePath, unvalidatedManifest),\n };\n\n let manifest: VirtualFile<SnapManifest> | undefined;\n try {\n ({ manifest } = validateNpmSnap(snapFiles));\n } catch (error) {\n if (error instanceof ProgrammaticallyFixableSnapError) {\n errors.push(error.message);\n\n // If we get here, the files at least have the correct shape.\n const partiallyValidatedFiles = snapFiles as SnapFiles;\n\n let isInvalid = true;\n let currentError = error;\n const maxAttempts = Object.keys(SnapValidationFailureReason).length;\n\n // Attempt to fix all fixable validation failure reasons. All such reasons\n // are enumerated by the `SnapValidationFailureReason` enum, so we only\n // attempt to fix the manifest the same amount of times as there are\n // reasons in the enum.\n for (let attempts = 1; isInvalid && attempts <= maxAttempts; attempts++) {\n manifest = fixManifest(\n manifest\n ? { ...partiallyValidatedFiles, manifest }\n : partiallyValidatedFiles,\n currentError,\n );\n\n try {\n validateNpmSnapManifest({ ...partiallyValidatedFiles, manifest });\n\n isInvalid = false;\n } catch (nextValidationError) {\n currentError = nextValidationError;\n /* istanbul ignore next: this should be impossible */\n if (\n !(\n nextValidationError instanceof ProgrammaticallyFixableSnapError\n ) ||\n (attempts === maxAttempts && !isInvalid)\n ) {\n throw new Error(\n `Internal error: Failed to fix manifest. This is a bug, please report it. Reason:\\n${error.message}`,\n );\n }\n\n errors.push(currentError.message);\n }\n }\n\n updated = true;\n } else {\n throw error;\n }\n }\n\n // TypeScript assumes `manifest` can still be undefined, that is not the case.\n // But we assert to keep TypeScript happy.\n assert(manifest);\n\n const validatedManifest = manifest.result;\n\n // Check presence of recommended keys\n const recommendedFields = ['repository'] as const;\n\n const missingRecommendedFields = recommendedFields.filter(\n (key) => !validatedManifest[key],\n );\n\n if (missingRecommendedFields.length > 0) {\n warnings.push(\n `Missing recommended package.json properties:\\n${missingRecommendedFields.reduce(\n (allMissing, currentField) => {\n return `${allMissing}\\t${currentField}\\n`;\n },\n '',\n )}`,\n );\n }\n\n if (writeManifest) {\n try {\n const newManifest = `${JSON.stringify(\n getWritableManifest(validatedManifest),\n null,\n 2,\n )}\\n`;\n\n if (updated || newManifest !== manifestFile.value) {\n await fs.writeFile(\n pathUtils.join(basePath, NpmSnapFileNames.Manifest),\n newManifest,\n );\n }\n } catch (error) {\n // Note: This error isn't pushed to the errors array, because it's not an\n // error in the manifest itself.\n throw new Error(`Failed to update snap.manifest.json: ${error.message}`);\n }\n }\n\n return { manifest: validatedManifest, updated, warnings, errors };\n}\n\n/**\n * Given the relevant Snap files (manifest, `package.json`, and bundle) and a\n * Snap manifest validation error, fixes the fault in the manifest that caused\n * the error.\n *\n * @param snapFiles - The contents of all Snap files.\n * @param error - The {@link ProgrammaticallyFixableSnapError} that was thrown.\n * @returns A copy of the manifest file where the cause of the error is fixed.\n */\nexport function fixManifest(\n snapFiles: SnapFiles,\n error: ProgrammaticallyFixableSnapError,\n): VirtualFile<SnapManifest> {\n const { manifest, packageJson } = snapFiles;\n const clonedFile = manifest.clone();\n const manifestCopy = clonedFile.result;\n\n switch (error.reason) {\n case SnapValidationFailureReason.NameMismatch:\n manifestCopy.source.location.npm.packageName = packageJson.result.name;\n break;\n\n case SnapValidationFailureReason.VersionMismatch:\n manifestCopy.version = packageJson.result.version;\n break;\n\n case SnapValidationFailureReason.RepositoryMismatch:\n manifestCopy.repository = packageJson.result.repository\n ? deepClone(packageJson.result.repository)\n : undefined;\n break;\n\n case SnapValidationFailureReason.ShasumMismatch:\n manifestCopy.source.shasum = getSnapChecksum(snapFiles);\n break;\n\n /* istanbul ignore next */\n default:\n assertExhaustive(error.reason);\n }\n\n clonedFile.result = manifestCopy;\n clonedFile.value = JSON.stringify(manifestCopy);\n return clonedFile;\n}\n\n/**\n * Given an unvalidated Snap manifest, attempts to extract the location of the\n * bundle source file location and read the file.\n *\n * @param basePath - The path to the folder with the manifest files.\n * @param manifest - The unvalidated Snap manifest file contents.\n * @param sourceCode - Override source code for plugins.\n * @returns The contents of the bundle file, if any.\n */\nexport async function getSnapSourceCode(\n basePath: string,\n manifest: Json,\n sourceCode?: string,\n): Promise<VirtualFile | undefined> {\n if (!isPlainObject(manifest)) {\n return undefined;\n }\n\n const sourceFilePath = (manifest as Partial<SnapManifest>).source?.location\n ?.npm?.filePath;\n\n if (!sourceFilePath) {\n return undefined;\n }\n\n if (sourceCode) {\n return new VirtualFile({\n path: pathUtils.join(basePath, sourceFilePath),\n value: sourceCode,\n });\n }\n\n try {\n const virtualFile = await readVirtualFile(\n pathUtils.join(basePath, sourceFilePath),\n 'utf8',\n );\n return virtualFile;\n } catch (error) {\n throw new Error(`Failed to read Snap bundle file: ${error.message}`);\n }\n}\n\n/**\n * Given an unvalidated Snap manifest, attempts to extract the location of the\n * icon and read the file.\n *\n * @param basePath - The path to the folder with the manifest files.\n * @param manifest - The unvalidated Snap manifest file contents.\n * @returns The contents of the icon, if any.\n */\nexport async function getSnapIcon(\n basePath: string,\n manifest: Json,\n): Promise<VirtualFile | undefined> {\n if (!isPlainObject(manifest)) {\n return undefined;\n }\n\n const iconPath = (manifest as Partial<SnapManifest>).source?.location?.npm\n ?.iconPath;\n\n if (!iconPath) {\n return undefined;\n }\n\n try {\n const virtualFile = await readVirtualFile(\n pathUtils.join(basePath, iconPath),\n 'utf8',\n );\n return virtualFile;\n } catch (error) {\n throw new Error(`Failed to read Snap icon file: ${error.message}`);\n }\n}\n\n/**\n * Sorts the given manifest in our preferred sort order and removes the\n * `repository` field if it is falsy (it may be `null`).\n *\n * @param manifest - The manifest to sort and modify.\n * @returns The disk-ready manifest.\n */\nexport function getWritableManifest(manifest: SnapManifest): SnapManifest {\n const { repository, ...remaining } = manifest;\n\n const keys = Object.keys(\n repository ? { ...remaining, repository } : remaining,\n ) as (keyof SnapManifest)[];\n\n const writableManifest = keys\n .sort((a, b) => MANIFEST_SORT_ORDER[a] - MANIFEST_SORT_ORDER[b])\n .reduce<Partial<SnapManifest>>(\n (result, key) => ({\n ...result,\n [key]: manifest[key],\n }),\n {},\n );\n\n return writableManifest as SnapManifest;\n}\n\n/**\n * Validates the fields of an npm Snap manifest that has already passed JSON\n * Schema validation.\n *\n * @param snapFiles - The relevant snap files to validate.\n * @param snapFiles.manifest - The npm Snap manifest to validate.\n * @param snapFiles.packageJson - The npm Snap's `package.json`.\n * @param snapFiles.sourceCode - The Snap's source code.\n * @param snapFiles.svgIcon - The Snap's optional icon.\n */\nexport function validateNpmSnapManifest({\n manifest,\n packageJson,\n sourceCode,\n svgIcon,\n}: SnapFiles) {\n const packageJsonName = packageJson.result.name;\n const packageJsonVersion = packageJson.result.version;\n const packageJsonRepository = packageJson.result.repository;\n\n const manifestPackageName = manifest.result.source.location.npm.packageName;\n const manifestPackageVersion = manifest.result.version;\n const manifestRepository = manifest.result.repository;\n\n if (packageJsonName !== manifestPackageName) {\n throw new ProgrammaticallyFixableSnapError(\n `\"${NpmSnapFileNames.Manifest}\" npm package name (\"${manifestPackageName}\") does not match the \"${NpmSnapFileNames.PackageJson}\" \"name\" field (\"${packageJsonName}\").`,\n SnapValidationFailureReason.NameMismatch,\n );\n }\n\n if (packageJsonVersion !== manifestPackageVersion) {\n throw new ProgrammaticallyFixableSnapError(\n `\"${NpmSnapFileNames.Manifest}\" npm package version (\"${manifestPackageVersion}\") does not match the \"${NpmSnapFileNames.PackageJson}\" \"version\" field (\"${packageJsonVersion}\").`,\n SnapValidationFailureReason.VersionMismatch,\n );\n }\n\n if (\n // The repository may be `undefined` in package.json but can only be defined\n // or `null` in the Snap manifest due to TS@<4.4 issues.\n (packageJsonRepository || manifestRepository) &&\n !deepEqual(packageJsonRepository, manifestRepository)\n ) {\n throw new ProgrammaticallyFixableSnapError(\n `\"${NpmSnapFileNames.Manifest}\" \"repository\" field does not match the \"${NpmSnapFileNames.PackageJson}\" \"repository\" field.`,\n SnapValidationFailureReason.RepositoryMismatch,\n );\n }\n\n validateSnapShasum(\n { manifest, sourceCode, svgIcon },\n `\"${NpmSnapFileNames.Manifest}\" \"shasum\" field does not match computed shasum.`,\n );\n}\n"],"names":["checkManifest","fixManifest","getSnapSourceCode","getSnapIcon","getWritableManifest","validateNpmSnapManifest","MANIFEST_SORT_ORDER","$schema","version","description","proposedName","repository","source","initialPermissions","manifestVersion","basePath","writeManifest","sourceCode","warnings","errors","updated","manifestPath","pathUtils","join","NpmSnapFileNames","Manifest","manifestFile","readJsonFile","unvalidatedManifest","result","packageFile","PackageJson","snapFiles","manifest","packageJson","svgIcon","validateNpmSnap","error","ProgrammaticallyFixableSnapError","push","message","partiallyValidatedFiles","isInvalid","currentError","maxAttempts","Object","keys","SnapValidationFailureReason","length","attempts","nextValidationError","Error","assert","validatedManifest","recommendedFields","missingRecommendedFields","filter","key","reduce","allMissing","currentField","newManifest","JSON","stringify","value","fs","writeFile","clonedFile","clone","manifestCopy","reason","NameMismatch","location","npm","packageName","name","VersionMismatch","RepositoryMismatch","deepClone","undefined","ShasumMismatch","shasum","getSnapChecksum","assertExhaustive","isPlainObject","sourceFilePath","filePath","VirtualFile","path","virtualFile","readVirtualFile","iconPath","remaining","writableManifest","sort","a","b","packageJsonName","packageJsonVersion","packageJsonRepository","manifestPackageName","manifestPackageVersion","manifestRepository","deepEqual","validateSnapShasum"],"mappings":";;;;;;;;;;;IA8DsBA,aAAa;eAAbA;;IA4INC,WAAW;eAAXA;;IA8CMC,iBAAiB;eAAjBA;;IA0CAC,WAAW;eAAXA;;IAiCNC,mBAAmB;eAAnBA;;IA8BAC,uBAAuB;eAAvBA;;;uBAhWwC;sEAClC;oBACS;6DACT;2BAEI;qBACG;qBACG;uBAKzB;uBAEuD;6BACjB;;;;;;AAG7C,MAAMC,sBAA0D;IAC9DC,SAAS;IACTC,SAAS;IACT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vE;QAAUhB;QAAYkB;IAAQ,GAChC,CAAC,CAAC,EAAEX,uBAAgB,CAACC,QAAQ,CAAC,gDAAgD,CAAC;AAEnF"}
|
|
1
|
+
{"version":3,"sources":["../../../src/manifest/manifest.ts"],"sourcesContent":["import type { Json } from '@metamask/utils';\nimport { assertExhaustive, assert, isPlainObject } from '@metamask/utils';\nimport deepEqual from 'fast-deep-equal';\nimport { promises as fs } from 'fs';\nimport pathUtils from 'path';\n\nimport { deepClone } from '../deep-clone';\nimport { readJsonFile } from '../fs';\nimport { validateNpmSnap } from '../npm';\nimport {\n getSnapChecksum,\n ProgrammaticallyFixableSnapError,\n validateSnapShasum,\n} from '../snaps';\nimport type { SnapFiles, UnvalidatedSnapFiles } from '../types';\nimport { NpmSnapFileNames, SnapValidationFailureReason } from '../types';\nimport { readVirtualFile, VirtualFile } from '../virtual-file';\nimport type { SnapManifest } from './validation';\n\nconst MANIFEST_SORT_ORDER: Record<keyof SnapManifest, number> = {\n $schema: 1,\n version: 2,\n description: 3,\n proposedName: 4,\n repository: 5,\n source: 6,\n initialPermissions: 7,\n manifestVersion: 8,\n};\n\n/**\n * The result from the `checkManifest` function.\n *\n * @property manifest - The fixed manifest object.\n * @property updated - Whether the manifest was updated.\n * @property warnings - An array of warnings that were encountered during\n * processing of the manifest files. These warnings are not logged to the\n * console automatically, so depending on the environment the function is called\n * in, a different method for logging can be used.\n * @property errors - An array of errors that were encountered during\n * processing of the manifest files. These errors are not logged to the\n * console automatically, so depending on the environment the function is called\n * in, a different method for logging can be used.\n */\nexport type CheckManifestResult = {\n manifest: SnapManifest;\n updated?: boolean;\n warnings: string[];\n errors: string[];\n};\n\nexport type WriteFileFunction = (path: string, data: string) => Promise<void>;\n\n/**\n * Validates a snap.manifest.json file. Attempts to fix the manifest and write\n * the fixed version to disk if `writeManifest` is true. Throws if validation\n * fails.\n *\n * @param basePath - The path to the folder with the manifest files.\n * @param writeManifest - Whether to write the fixed manifest to disk.\n * @param sourceCode - The source code of the Snap.\n * @param writeFileFn - The function to use to write the manifest to disk.\n * @returns Whether the manifest was updated, and an array of warnings that\n * were encountered during processing of the manifest files.\n */\nexport async function checkManifest(\n basePath: string,\n writeManifest = true,\n sourceCode?: string,\n writeFileFn: WriteFileFunction = fs.writeFile,\n): Promise<CheckManifestResult> {\n const warnings: string[] = [];\n const errors: string[] = [];\n\n let updated = false;\n\n const manifestPath = pathUtils.join(basePath, NpmSnapFileNames.Manifest);\n const manifestFile = await readJsonFile(manifestPath);\n const unvalidatedManifest = manifestFile.result;\n\n const packageFile = await readJsonFile(\n pathUtils.join(basePath, NpmSnapFileNames.PackageJson),\n );\n\n const snapFiles: UnvalidatedSnapFiles = {\n manifest: manifestFile,\n packageJson: packageFile,\n sourceCode: await getSnapSourceCode(\n basePath,\n unvalidatedManifest,\n sourceCode,\n ),\n svgIcon: await getSnapIcon(basePath, unvalidatedManifest),\n };\n\n let manifest: VirtualFile<SnapManifest> | undefined;\n try {\n ({ manifest } = validateNpmSnap(snapFiles));\n } catch (error) {\n if (error instanceof ProgrammaticallyFixableSnapError) {\n errors.push(error.message);\n\n // If we get here, the files at least have the correct shape.\n const partiallyValidatedFiles = snapFiles as SnapFiles;\n\n let isInvalid = true;\n let currentError = error;\n const maxAttempts = Object.keys(SnapValidationFailureReason).length;\n\n // Attempt to fix all fixable validation failure reasons. All such reasons\n // are enumerated by the `SnapValidationFailureReason` enum, so we only\n // attempt to fix the manifest the same amount of times as there are\n // reasons in the enum.\n for (let attempts = 1; isInvalid && attempts <= maxAttempts; attempts++) {\n manifest = fixManifest(\n manifest\n ? { ...partiallyValidatedFiles, manifest }\n : partiallyValidatedFiles,\n currentError,\n );\n\n try {\n validateNpmSnapManifest({ ...partiallyValidatedFiles, manifest });\n\n isInvalid = false;\n } catch (nextValidationError) {\n currentError = nextValidationError;\n /* istanbul ignore next: this should be impossible */\n if (\n !(\n nextValidationError instanceof ProgrammaticallyFixableSnapError\n ) ||\n (attempts === maxAttempts && !isInvalid)\n ) {\n throw new Error(\n `Internal error: Failed to fix manifest. This is a bug, please report it. Reason:\\n${error.message}`,\n );\n }\n\n errors.push(currentError.message);\n }\n }\n\n updated = true;\n } else {\n throw error;\n }\n }\n\n // TypeScript assumes `manifest` can still be undefined, that is not the case.\n // But we assert to keep TypeScript happy.\n assert(manifest);\n\n const validatedManifest = manifest.result;\n\n // Check presence of recommended keys\n const recommendedFields = ['repository'] as const;\n\n const missingRecommendedFields = recommendedFields.filter(\n (key) => !validatedManifest[key],\n );\n\n if (missingRecommendedFields.length > 0) {\n warnings.push(\n `Missing recommended package.json properties:\\n${missingRecommendedFields.reduce(\n (allMissing, currentField) => {\n return `${allMissing}\\t${currentField}\\n`;\n },\n '',\n )}`,\n );\n }\n\n if (writeManifest) {\n try {\n const newManifest = `${JSON.stringify(\n getWritableManifest(validatedManifest),\n null,\n 2,\n )}\\n`;\n\n if (updated || newManifest !== manifestFile.value) {\n await writeFileFn(\n pathUtils.join(basePath, NpmSnapFileNames.Manifest),\n newManifest,\n );\n }\n } catch (error) {\n // Note: This error isn't pushed to the errors array, because it's not an\n // error in the manifest itself.\n throw new Error(`Failed to update snap.manifest.json: ${error.message}`);\n }\n }\n\n return { manifest: validatedManifest, updated, warnings, errors };\n}\n\n/**\n * Given the relevant Snap files (manifest, `package.json`, and bundle) and a\n * Snap manifest validation error, fixes the fault in the manifest that caused\n * the error.\n *\n * @param snapFiles - The contents of all Snap files.\n * @param error - The {@link ProgrammaticallyFixableSnapError} that was thrown.\n * @returns A copy of the manifest file where the cause of the error is fixed.\n */\nexport function fixManifest(\n snapFiles: SnapFiles,\n error: ProgrammaticallyFixableSnapError,\n): VirtualFile<SnapManifest> {\n const { manifest, packageJson } = snapFiles;\n const clonedFile = manifest.clone();\n const manifestCopy = clonedFile.result;\n\n switch (error.reason) {\n case SnapValidationFailureReason.NameMismatch:\n manifestCopy.source.location.npm.packageName = packageJson.result.name;\n break;\n\n case SnapValidationFailureReason.VersionMismatch:\n manifestCopy.version = packageJson.result.version;\n break;\n\n case SnapValidationFailureReason.RepositoryMismatch:\n manifestCopy.repository = packageJson.result.repository\n ? deepClone(packageJson.result.repository)\n : undefined;\n break;\n\n case SnapValidationFailureReason.ShasumMismatch:\n manifestCopy.source.shasum = getSnapChecksum(snapFiles);\n break;\n\n /* istanbul ignore next */\n default:\n assertExhaustive(error.reason);\n }\n\n clonedFile.result = manifestCopy;\n clonedFile.value = JSON.stringify(manifestCopy);\n return clonedFile;\n}\n\n/**\n * Given an unvalidated Snap manifest, attempts to extract the location of the\n * bundle source file location and read the file.\n *\n * @param basePath - The path to the folder with the manifest files.\n * @param manifest - The unvalidated Snap manifest file contents.\n * @param sourceCode - Override source code for plugins.\n * @returns The contents of the bundle file, if any.\n */\nexport async function getSnapSourceCode(\n basePath: string,\n manifest: Json,\n sourceCode?: string,\n): Promise<VirtualFile | undefined> {\n if (!isPlainObject(manifest)) {\n return undefined;\n }\n\n const sourceFilePath = (manifest as Partial<SnapManifest>).source?.location\n ?.npm?.filePath;\n\n if (!sourceFilePath) {\n return undefined;\n }\n\n if (sourceCode) {\n return new VirtualFile({\n path: pathUtils.join(basePath, sourceFilePath),\n value: sourceCode,\n });\n }\n\n try {\n const virtualFile = await readVirtualFile(\n pathUtils.join(basePath, sourceFilePath),\n 'utf8',\n );\n return virtualFile;\n } catch (error) {\n throw new Error(`Failed to read snap bundle file: ${error.message}`);\n }\n}\n\n/**\n * Given an unvalidated Snap manifest, attempts to extract the location of the\n * icon and read the file.\n *\n * @param basePath - The path to the folder with the manifest files.\n * @param manifest - The unvalidated Snap manifest file contents.\n * @returns The contents of the icon, if any.\n */\nexport async function getSnapIcon(\n basePath: string,\n manifest: Json,\n): Promise<VirtualFile | undefined> {\n if (!isPlainObject(manifest)) {\n return undefined;\n }\n\n const iconPath = (manifest as Partial<SnapManifest>).source?.location?.npm\n ?.iconPath;\n\n if (!iconPath) {\n return undefined;\n }\n\n try {\n const virtualFile = await readVirtualFile(\n pathUtils.join(basePath, iconPath),\n 'utf8',\n );\n return virtualFile;\n } catch (error) {\n throw new Error(`Failed to read snap icon file: ${error.message}`);\n }\n}\n\n/**\n * Sorts the given manifest in our preferred sort order and removes the\n * `repository` field if it is falsy (it may be `null`).\n *\n * @param manifest - The manifest to sort and modify.\n * @returns The disk-ready manifest.\n */\nexport function getWritableManifest(manifest: SnapManifest): SnapManifest {\n const { repository, ...remaining } = manifest;\n\n const keys = Object.keys(\n repository ? { ...remaining, repository } : remaining,\n ) as (keyof SnapManifest)[];\n\n const writableManifest = keys\n .sort((a, b) => MANIFEST_SORT_ORDER[a] - MANIFEST_SORT_ORDER[b])\n .reduce<Partial<SnapManifest>>(\n (result, key) => ({\n ...result,\n [key]: manifest[key],\n }),\n {},\n );\n\n return writableManifest as SnapManifest;\n}\n\n/**\n * Validates the fields of an npm Snap manifest that has already passed JSON\n * Schema validation.\n *\n * @param snapFiles - The relevant snap files to validate.\n * @param snapFiles.manifest - The npm Snap manifest to validate.\n * @param snapFiles.packageJson - The npm Snap's `package.json`.\n * @param snapFiles.sourceCode - The Snap's source code.\n * @param snapFiles.svgIcon - The Snap's optional icon.\n */\nexport function validateNpmSnapManifest({\n manifest,\n packageJson,\n sourceCode,\n svgIcon,\n}: SnapFiles) {\n const packageJsonName = packageJson.result.name;\n const packageJsonVersion = packageJson.result.version;\n const packageJsonRepository = packageJson.result.repository;\n\n const manifestPackageName = manifest.result.source.location.npm.packageName;\n const manifestPackageVersion = manifest.result.version;\n const manifestRepository = manifest.result.repository;\n\n if (packageJsonName !== manifestPackageName) {\n throw new ProgrammaticallyFixableSnapError(\n `\"${NpmSnapFileNames.Manifest}\" npm package name (\"${manifestPackageName}\") does not match the \"${NpmSnapFileNames.PackageJson}\" \"name\" field (\"${packageJsonName}\").`,\n SnapValidationFailureReason.NameMismatch,\n );\n }\n\n if (packageJsonVersion !== manifestPackageVersion) {\n throw new ProgrammaticallyFixableSnapError(\n `\"${NpmSnapFileNames.Manifest}\" npm package version (\"${manifestPackageVersion}\") does not match the \"${NpmSnapFileNames.PackageJson}\" \"version\" field (\"${packageJsonVersion}\").`,\n SnapValidationFailureReason.VersionMismatch,\n );\n }\n\n if (\n // The repository may be `undefined` in package.json but can only be defined\n // or `null` in the Snap manifest due to TS@<4.4 issues.\n (packageJsonRepository || manifestRepository) &&\n !deepEqual(packageJsonRepository, manifestRepository)\n ) {\n throw new ProgrammaticallyFixableSnapError(\n `\"${NpmSnapFileNames.Manifest}\" \"repository\" field does not match the \"${NpmSnapFileNames.PackageJson}\" \"repository\" field.`,\n SnapValidationFailureReason.RepositoryMismatch,\n );\n }\n\n validateSnapShasum(\n { manifest, sourceCode, svgIcon },\n `\"${NpmSnapFileNames.Manifest}\" \"shasum\" field does not match computed shasum.`,\n );\n}\n"],"names":["checkManifest","fixManifest","getSnapSourceCode","getSnapIcon","getWritableManifest","validateNpmSnapManifest","MANIFEST_SORT_ORDER","$schema","version","description","proposedName","repository","source","initialPermissions","manifestVersion","basePath","writeManifest","sourceCode","writeFileFn","fs","writeFile","warnings","errors","updated","manifestPath","pathUtils","join","NpmSnapFileNames","Manifest","manifestFile","readJsonFile","unvalidatedManifest","result","packageFile","PackageJson","snapFiles","manifest","packageJson","svgIcon","validateNpmSnap","error","ProgrammaticallyFixableSnapError","push","message","partiallyValidatedFiles","isInvalid","currentError","maxAttempts","Object","keys","SnapValidationFailureReason","length","attempts","nextValidationError","Error","assert","validatedManifest","recommendedFields","missingRecommendedFields","filter","key","reduce","allMissing","currentField","newManifest","JSON","stringify","value","clonedFile","clone","manifestCopy","reason","NameMismatch","location","npm","packageName","name","VersionMismatch","RepositoryMismatch","deepClone","undefined","ShasumMismatch","shasum","getSnapChecksum","assertExhaustive","isPlainObject","sourceFilePath","filePath","VirtualFile","path","virtualFile","readVirtualFile","iconPath","remaining","writableManifest","sort","a","b","packageJsonName","packageJsonVersion","packageJsonRepository","manifestPackageName","manifestPackageVersion","manifestRepository","deepEqual","validateSnapShasum"],"mappings":";;;;;;;;;;;IAiEsBA,aAAa;eAAbA;;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,kBAAiB,KAC3C,CAACC,IAAAA,sBAAS,EAACJ,uBAAuBG,qBAClC;QACA,MAAM,IAAI9D,uCAAgC,CACxC,CAAC,CAAC,EAAEd,uBAAgB,CAACC,QAAQ,CAAC,yCAAyC,EAAED,uBAAgB,CAACO,WAAW,CAAC,qBAAqB,CAAC,EAC5HgB,kCAA2B,CAAC4B,kBAAkB;IAElD;IAEA2B,IAAAA,yBAAkB,EAChB;QAAErE;QAAUnB;QAAYqB;IAAQ,GAChC,CAAC,CAAC,EAAEX,uBAAgB,CAACC,QAAQ,CAAC,gDAAgD,CAAC;AAEnF"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Indent a message by adding a number of spaces to the beginning of each line.
|
|
3
|
+
*
|
|
4
|
+
* @param message - The message to indent.
|
|
5
|
+
* @param spaces - The number of spaces to indent by. Defaults to 2.
|
|
6
|
+
* @returns The indented message.
|
|
7
|
+
*/ "use strict";
|
|
8
|
+
Object.defineProperty(exports, "__esModule", {
|
|
9
|
+
value: true
|
|
10
|
+
});
|
|
11
|
+
Object.defineProperty(exports, "indent", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function() {
|
|
14
|
+
return indent;
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
function indent(message, spaces = 2) {
|
|
18
|
+
return message.replace(/^/gmu, ' '.repeat(spaces));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=strings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/strings.ts"],"sourcesContent":["/**\n * Indent a message by adding a number of spaces to the beginning of each line.\n *\n * @param message - The message to indent.\n * @param spaces - The number of spaces to indent by. Defaults to 2.\n * @returns The indented message.\n */\nexport function indent(message: string, spaces = 2) {\n return message.replace(/^/gmu, ' '.repeat(spaces));\n}\n"],"names":["indent","message","spaces","replace","repeat"],"mappings":"AAAA;;;;;;CAMC;;;;+BACeA;;;eAAAA;;;AAAT,SAASA,OAAOC,OAAe,EAAEC,SAAS,CAAC;IAChD,OAAOD,QAAQE,OAAO,CAAC,QAAQ,IAAIC,MAAM,CAACF;AAC5C"}
|