@metamask/snaps-rollup-plugin 1.0.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -170
- package/dist/cjs/index.js +18 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/plugin.js +79 -0
- package/dist/cjs/plugin.js.map +1 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/{plugin.js → esm/plugin.js} +18 -21
- package/dist/esm/plugin.js.map +1 -0
- package/dist/{plugin.d.ts → types/plugin.d.ts} +2 -2
- package/package.json +35 -22
- package/dist/__fixtures__/source-map.js +0 -7
- package/dist/__fixtures__/source-map.js.map +0 -1
- package/dist/index.js +0 -9
- package/dist/index.js.map +0 -1
- package/dist/plugin.js.map +0 -1
- /package/dist/{__fixtures__ → types/__fixtures__}/source-map.d.ts +0 -0
- /package/dist/{index.d.ts → types/index.d.ts} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -6,178 +6,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
-
## [
|
|
9
|
+
## [2.0.0]
|
|
10
10
|
### Changed
|
|
11
|
-
-
|
|
11
|
+
- Initial stable release from main branch ([#1757](https://github.com/MetaMask/snaps/pull/1757))
|
|
12
12
|
|
|
13
|
-
## [
|
|
14
|
-
### Changed
|
|
15
|
-
- No changes this release.
|
|
16
|
-
|
|
17
|
-
## [1.0.0-prerelease.1]
|
|
18
|
-
### Changed
|
|
19
|
-
- No changes this release.
|
|
20
|
-
|
|
21
|
-
## [0.32.2]
|
|
22
|
-
### Changed
|
|
23
|
-
- No changes this release.
|
|
24
|
-
|
|
25
|
-
## [0.32.1]
|
|
26
|
-
### Changed
|
|
27
|
-
- No changes this release.
|
|
28
|
-
|
|
29
|
-
## [0.32.0]
|
|
30
|
-
### Changed
|
|
31
|
-
- No changes this release.
|
|
32
|
-
|
|
33
|
-
## [0.31.0]
|
|
34
|
-
### Changed
|
|
35
|
-
- **BREAKING:** Target `ES2020` ([#1247](https://github.com/MetaMask/snaps-monorepo/pull/1247))
|
|
36
|
-
|
|
37
|
-
## [0.30.0]
|
|
38
|
-
### Changed
|
|
39
|
-
- No changes this release.
|
|
40
|
-
|
|
41
|
-
## [0.29.0]
|
|
42
|
-
### Changed
|
|
43
|
-
- No changes this release.
|
|
44
|
-
|
|
45
|
-
## [0.28.0]
|
|
46
|
-
### Changed
|
|
47
|
-
- No changes this release.
|
|
48
|
-
|
|
49
|
-
## [0.27.1]
|
|
50
|
-
### Changed
|
|
51
|
-
- No changes this release.
|
|
52
|
-
|
|
53
|
-
## [0.27.0]
|
|
54
|
-
### Changed
|
|
55
|
-
- No changes this release.
|
|
56
|
-
|
|
57
|
-
## [0.26.2]
|
|
58
|
-
### Changed
|
|
59
|
-
- No changes this release.
|
|
60
|
-
|
|
61
|
-
## [0.26.1]
|
|
62
|
-
### Changed
|
|
63
|
-
- No changes this release.
|
|
64
|
-
|
|
65
|
-
## [0.26.0]
|
|
66
|
-
### Changed
|
|
67
|
-
- No changes this release.
|
|
68
|
-
|
|
69
|
-
## [0.25.0]
|
|
70
|
-
### Changed
|
|
71
|
-
- No changes this release.
|
|
72
|
-
|
|
73
|
-
## [0.24.1]
|
|
74
|
-
### Changed
|
|
75
|
-
- No changes this release.
|
|
76
|
-
|
|
77
|
-
## [0.24.0]
|
|
78
|
-
### Added
|
|
79
|
-
- Add compile-time warning when using `Math.random` ([#950](https://github.com/MetaMask/snaps-monorepo/pull/950))
|
|
80
|
-
|
|
81
|
-
### Changed
|
|
82
|
-
- **BREAKING:** Rename package to start with `snaps-` ([#937](https://github.com/MetaMask/snaps-monorepo/pull/937))
|
|
83
|
-
|
|
84
|
-
## [0.23.0]
|
|
85
|
-
### Changed
|
|
86
|
-
- No changes this release.
|
|
87
|
-
|
|
88
|
-
## [0.22.3]
|
|
89
|
-
### Changed
|
|
90
|
-
- No changes this release.
|
|
91
|
-
|
|
92
|
-
## [0.22.2]
|
|
93
|
-
### Changed
|
|
94
|
-
- No changes this release.
|
|
95
|
-
|
|
96
|
-
## [0.22.1]
|
|
97
|
-
### Changed
|
|
98
|
-
- No changes this release.
|
|
99
|
-
|
|
100
|
-
## [0.22.0]
|
|
101
|
-
### Changed
|
|
102
|
-
- No changes this release.
|
|
103
|
-
|
|
104
|
-
## [0.21.0]
|
|
105
|
-
### Added
|
|
106
|
-
- Run eval and fix manifest in bundler plugins ([#731](https://github.com/MetaMask/snaps-monorepo/pull/731))
|
|
107
|
-
|
|
108
|
-
## [0.20.0]
|
|
109
|
-
### Changed
|
|
110
|
-
- No changes this release.
|
|
111
|
-
|
|
112
|
-
## [0.19.1]
|
|
113
|
-
### Added
|
|
114
|
-
- Generate source maps from modified code ([#615](https://github.com/MetaMask/snaps-monorepo/pull/615))
|
|
115
|
-
|
|
116
|
-
## [0.19.0]
|
|
117
|
-
### Changed
|
|
118
|
-
- No changes this release.
|
|
119
|
-
|
|
120
|
-
## [0.18.1]
|
|
121
|
-
### Changed
|
|
122
|
-
- No changes this release.
|
|
123
|
-
|
|
124
|
-
## [0.18.0]
|
|
125
|
-
### Changed
|
|
126
|
-
- Reduce TypeScript compilation target to ES2017 ([#628](https://github.com/MetaMask/snaps-monorepo/pull/628))
|
|
127
|
-
|
|
128
|
-
## [0.17.0]
|
|
129
|
-
### Changed
|
|
130
|
-
- **BREAKING:** Bump minimum Node version to 16 ([#601](https://github.com/MetaMask/snaps-monorepo/pull/601))
|
|
131
|
-
|
|
132
|
-
## [0.16.0]
|
|
133
|
-
### Changed
|
|
134
|
-
- No changes this release.
|
|
135
|
-
|
|
136
|
-
## [0.15.0]
|
|
137
|
-
### Changed
|
|
138
|
-
- No changes this release.
|
|
139
|
-
|
|
140
|
-
## [0.14.0]
|
|
13
|
+
## [0.37.3-flask.1]
|
|
141
14
|
### Fixed
|
|
142
|
-
-
|
|
143
|
-
- Package contents were omitted from the previous version due to a build failure.
|
|
15
|
+
- Remove unused dependencies ([#1680](https://github.com/MetaMask/snaps/pull/1680))
|
|
144
16
|
|
|
145
|
-
## [0.
|
|
146
|
-
###
|
|
147
|
-
-
|
|
17
|
+
## [0.37.2-flask.1]
|
|
18
|
+
### Changed
|
|
19
|
+
- Release package independently ([#1600](https://github.com/MetaMask/snaps/pull/1600))
|
|
20
|
+
- The version of the package no longer needs to match the version of all other
|
|
21
|
+
MetaMask Snaps packages.
|
|
148
22
|
|
|
149
|
-
[Unreleased]: https://github.com/MetaMask/snaps/compare/
|
|
150
|
-
[
|
|
151
|
-
[
|
|
152
|
-
[
|
|
153
|
-
[0.32.2]: https://github.com/MetaMask/snaps/compare/v0.32.1...v0.32.2
|
|
154
|
-
[0.32.1]: https://github.com/MetaMask/snaps/compare/v0.32.0...v0.32.1
|
|
155
|
-
[0.32.0]: https://github.com/MetaMask/snaps/compare/v0.31.0...v0.32.0
|
|
156
|
-
[0.31.0]: https://github.com/MetaMask/snaps/compare/v0.30.0...v0.31.0
|
|
157
|
-
[0.30.0]: https://github.com/MetaMask/snaps/compare/v0.29.0...v0.30.0
|
|
158
|
-
[0.29.0]: https://github.com/MetaMask/snaps/compare/v0.28.0...v0.29.0
|
|
159
|
-
[0.28.0]: https://github.com/MetaMask/snaps/compare/v0.27.1...v0.28.0
|
|
160
|
-
[0.27.1]: https://github.com/MetaMask/snaps/compare/v0.27.0...v0.27.1
|
|
161
|
-
[0.27.0]: https://github.com/MetaMask/snaps/compare/v0.26.2...v0.27.0
|
|
162
|
-
[0.26.2]: https://github.com/MetaMask/snaps/compare/v0.26.1...v0.26.2
|
|
163
|
-
[0.26.1]: https://github.com/MetaMask/snaps/compare/v0.26.0...v0.26.1
|
|
164
|
-
[0.26.0]: https://github.com/MetaMask/snaps/compare/v0.25.0...v0.26.0
|
|
165
|
-
[0.25.0]: https://github.com/MetaMask/snaps/compare/v0.24.1...v0.25.0
|
|
166
|
-
[0.24.1]: https://github.com/MetaMask/snaps/compare/v0.24.0...v0.24.1
|
|
167
|
-
[0.24.0]: https://github.com/MetaMask/snaps/compare/v0.23.0...v0.24.0
|
|
168
|
-
[0.23.0]: https://github.com/MetaMask/snaps/compare/v0.22.3...v0.23.0
|
|
169
|
-
[0.22.3]: https://github.com/MetaMask/snaps/compare/v0.22.2...v0.22.3
|
|
170
|
-
[0.22.2]: https://github.com/MetaMask/snaps/compare/v0.22.1...v0.22.2
|
|
171
|
-
[0.22.1]: https://github.com/MetaMask/snaps/compare/v0.22.0...v0.22.1
|
|
172
|
-
[0.22.0]: https://github.com/MetaMask/snaps/compare/v0.21.0...v0.22.0
|
|
173
|
-
[0.21.0]: https://github.com/MetaMask/snaps/compare/v0.20.0...v0.21.0
|
|
174
|
-
[0.20.0]: https://github.com/MetaMask/snaps/compare/v0.19.1...v0.20.0
|
|
175
|
-
[0.19.1]: https://github.com/MetaMask/snaps/compare/v0.19.0...v0.19.1
|
|
176
|
-
[0.19.0]: https://github.com/MetaMask/snaps/compare/v0.18.1...v0.19.0
|
|
177
|
-
[0.18.1]: https://github.com/MetaMask/snaps/compare/v0.18.0...v0.18.1
|
|
178
|
-
[0.18.0]: https://github.com/MetaMask/snaps/compare/v0.17.0...v0.18.0
|
|
179
|
-
[0.17.0]: https://github.com/MetaMask/snaps/compare/v0.16.0...v0.17.0
|
|
180
|
-
[0.16.0]: https://github.com/MetaMask/snaps/compare/v0.15.0...v0.16.0
|
|
181
|
-
[0.15.0]: https://github.com/MetaMask/snaps/compare/v0.14.0...v0.15.0
|
|
182
|
-
[0.14.0]: https://github.com/MetaMask/snaps/compare/v0.13.0...v0.14.0
|
|
183
|
-
[0.13.0]: https://github.com/MetaMask/snaps/releases/tag/v0.13.0
|
|
23
|
+
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rollup-plugin@2.0.0...HEAD
|
|
24
|
+
[2.0.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rollup-plugin@0.37.3-flask.1...@metamask/snaps-rollup-plugin@2.0.0
|
|
25
|
+
[0.37.3-flask.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rollup-plugin@0.37.2-flask.1...@metamask/snaps-rollup-plugin@0.37.3-flask.1
|
|
26
|
+
[0.37.2-flask.1]: https://github.com/MetaMask/snaps/releases/tag/@metamask/snaps-rollup-plugin@0.37.2-flask.1
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return _plugin.default;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _plugin = /*#__PURE__*/ _interop_require_default(require("./plugin"));
|
|
12
|
+
function _interop_require_default(obj) {
|
|
13
|
+
return obj && obj.__esModule ? obj : {
|
|
14
|
+
default: obj
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export { default } from './plugin';\nexport type { Options } from './plugin';\n"],"names":["default"],"mappings":";;;;+BAASA;;;eAAAA,eAAO;;;+DAAQ"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, /**
|
|
6
|
+
* Creates a Snaps Rollup plugin instance.
|
|
7
|
+
*
|
|
8
|
+
* @param options - The plugin options.
|
|
9
|
+
* @param options.stripComments - Whether to strip comments. Defaults to `true`.
|
|
10
|
+
* @param options.eval - Whether to evaluate the bundle to test SES
|
|
11
|
+
* compatibility. Defaults to `true`.
|
|
12
|
+
* @param options.manifestPath - The path to the manifest file. If provided,
|
|
13
|
+
* the manifest will be validated. Defaults to
|
|
14
|
+
* `process.cwd() + '/snap.manifest.json'`.
|
|
15
|
+
* @param options.writeManifest - Whether to fix the manifest. Defaults to
|
|
16
|
+
* `true`.
|
|
17
|
+
* @returns The Rollup plugin object.
|
|
18
|
+
*/ "default", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function() {
|
|
21
|
+
return snaps;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
const _snapsutils = require("@metamask/snaps-utils");
|
|
25
|
+
const _fs = require("fs");
|
|
26
|
+
const _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
27
|
+
function _interop_require_default(obj) {
|
|
28
|
+
return obj && obj.__esModule ? obj : {
|
|
29
|
+
default: obj
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function snaps(options) {
|
|
33
|
+
const defaultOptions = {
|
|
34
|
+
eval: true,
|
|
35
|
+
manifestPath: _path.default.join(process.cwd(), 'snap.manifest.json'),
|
|
36
|
+
writeManifest: true,
|
|
37
|
+
...options
|
|
38
|
+
};
|
|
39
|
+
return {
|
|
40
|
+
name: '@metamask/snaps-rollup-plugin',
|
|
41
|
+
renderChunk (code) {
|
|
42
|
+
// Rollup internally merges the new source map with the old one, so there
|
|
43
|
+
// is no need to pass the current source map to the function.
|
|
44
|
+
const result = (0, _snapsutils.postProcessBundle)(code, {
|
|
45
|
+
...defaultOptions,
|
|
46
|
+
sourceMap: true
|
|
47
|
+
});
|
|
48
|
+
if (result.warnings.length > 0) {
|
|
49
|
+
this.warn(`Bundle Warning: Processing of the Snap bundle completed with warnings.\n${result.warnings.join('\n')}`);
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
code: result.code,
|
|
53
|
+
map: result.sourceMap
|
|
54
|
+
};
|
|
55
|
+
},
|
|
56
|
+
async writeBundle (output) {
|
|
57
|
+
if (!output.file) {
|
|
58
|
+
this.warn('No output file specified, skipping bundle validation.');
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (defaultOptions.eval) {
|
|
62
|
+
await (0, _snapsutils.evalBundle)(output.file).catch((error)=>{
|
|
63
|
+
this.error(error);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
if (defaultOptions.manifestPath) {
|
|
67
|
+
const { errors, warnings } = await (0, _snapsutils.checkManifest)(_path.default.dirname(defaultOptions.manifestPath), defaultOptions.writeManifest, await _fs.promises.readFile(output.file, 'utf8'));
|
|
68
|
+
if (!defaultOptions.writeManifest && errors.length > 0) {
|
|
69
|
+
this.error(`Manifest Error: The manifest is invalid.\n${errors.join('\n')}`);
|
|
70
|
+
}
|
|
71
|
+
if (warnings.length > 0) {
|
|
72
|
+
this.warn(`Manifest Warning: Validation of snap.manifest.json completed with warnings.\n${warnings.join('\n')}`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/plugin.ts"],"sourcesContent":["import type { PostProcessOptions } from '@metamask/snaps-utils';\nimport {\n checkManifest,\n evalBundle,\n postProcessBundle,\n} from '@metamask/snaps-utils';\nimport { promises as fs } from 'fs';\nimport pathUtils from 'path';\n// eslint-disable-next-line @typescript-eslint/no-shadow\nimport type { Plugin, SourceMapInput } from 'rollup';\n\ntype PluginOptions = {\n eval?: boolean;\n manifestPath?: string;\n writeManifest?: boolean;\n};\n\nexport type Options = PluginOptions &\n Omit<PostProcessOptions, 'sourceMap' | 'inputSourceMap'>;\n\n/**\n * Creates a Snaps Rollup plugin instance.\n *\n * @param options - The plugin options.\n * @param options.stripComments - Whether to strip comments. Defaults to `true`.\n * @param options.eval - Whether to evaluate the bundle to test SES\n * compatibility. Defaults to `true`.\n * @param options.manifestPath - The path to the manifest file. If provided,\n * the manifest will be validated. Defaults to\n * `process.cwd() + '/snap.manifest.json'`.\n * @param options.writeManifest - Whether to fix the manifest. Defaults to\n * `true`.\n * @returns The Rollup plugin object.\n */\nexport default function snaps(options?: Partial<Options>): Plugin {\n const defaultOptions = {\n eval: true,\n manifestPath: pathUtils.join(process.cwd(), 'snap.manifest.json'),\n writeManifest: true,\n ...options,\n };\n\n return {\n name: '@metamask/snaps-rollup-plugin',\n\n renderChunk(code: string): { code: string; map?: SourceMapInput } | null {\n // Rollup internally merges the new source map with the old one, so there\n // is no need to pass the current source map to the function.\n const result = postProcessBundle(code, {\n ...defaultOptions,\n sourceMap: true,\n });\n\n if (result.warnings.length > 0) {\n this.warn(\n `Bundle Warning: Processing of the Snap bundle completed with warnings.\\n${result.warnings.join(\n '\\n',\n )}`,\n );\n }\n\n return { code: result.code, map: result.sourceMap };\n },\n\n async writeBundle(output): Promise<void> {\n if (!output.file) {\n this.warn('No output file specified, skipping bundle validation.');\n return;\n }\n\n if (defaultOptions.eval) {\n await evalBundle(output.file).catch((error) => {\n this.error(error);\n });\n }\n\n if (defaultOptions.manifestPath) {\n const { errors, warnings } = await checkManifest(\n pathUtils.dirname(defaultOptions.manifestPath),\n defaultOptions.writeManifest,\n await fs.readFile(output.file, 'utf8'),\n );\n\n if (!defaultOptions.writeManifest && errors.length > 0) {\n this.error(\n `Manifest Error: The manifest is invalid.\\n${errors.join('\\n')}`,\n );\n }\n\n if (warnings.length > 0) {\n this.warn(\n `Manifest Warning: Validation of snap.manifest.json completed with warnings.\\n${warnings.join(\n '\\n',\n )}`,\n );\n }\n }\n },\n };\n}\n"],"names":["snaps","options","defaultOptions","eval","manifestPath","pathUtils","join","process","cwd","writeManifest","name","renderChunk","code","result","postProcessBundle","sourceMap","warnings","length","warn","map","writeBundle","output","file","evalBundle","catch","error","errors","checkManifest","dirname","fs","readFile"],"mappings":";;;;+BAoBA;;;;;;;;;;;;;CAaC,GACD;;;eAAwBA;;;4BA7BjB;oBACwB;6DACT;;;;;;AA2BP,SAASA,MAAMC,OAA0B;IACtD,MAAMC,iBAAiB;QACrBC,MAAM;QACNC,cAAcC,aAAS,CAACC,IAAI,CAACC,QAAQC,GAAG,IAAI;QAC5CC,eAAe;QACf,GAAGR,OAAO;IACZ;IAEA,OAAO;QACLS,MAAM;QAENC,aAAYC,IAAY;YACtB,yEAAyE;YACzE,6DAA6D;YAC7D,MAAMC,SAASC,IAAAA,6BAAiB,EAACF,MAAM;gBACrC,GAAGV,cAAc;gBACjBa,WAAW;YACb;YAEA,IAAIF,OAAOG,QAAQ,CAACC,MAAM,GAAG,GAAG;gBAC9B,IAAI,CAACC,IAAI,CACP,CAAC,wEAAwE,EAAEL,OAAOG,QAAQ,CAACV,IAAI,CAC7F,MACA,CAAC;YAEP;YAEA,OAAO;gBAAEM,MAAMC,OAAOD,IAAI;gBAAEO,KAAKN,OAAOE,SAAS;YAAC;QACpD;QAEA,MAAMK,aAAYC,MAAM;YACtB,IAAI,CAACA,OAAOC,IAAI,EAAE;gBAChB,IAAI,CAACJ,IAAI,CAAC;gBACV;YACF;YAEA,IAAIhB,eAAeC,IAAI,EAAE;gBACvB,MAAMoB,IAAAA,sBAAU,EAACF,OAAOC,IAAI,EAAEE,KAAK,CAAC,CAACC;oBACnC,IAAI,CAACA,KAAK,CAACA;gBACb;YACF;YAEA,IAAIvB,eAAeE,YAAY,EAAE;gBAC/B,MAAM,EAAEsB,MAAM,EAAEV,QAAQ,EAAE,GAAG,MAAMW,IAAAA,yBAAa,EAC9CtB,aAAS,CAACuB,OAAO,CAAC1B,eAAeE,YAAY,GAC7CF,eAAeO,aAAa,EAC5B,MAAMoB,YAAE,CAACC,QAAQ,CAACT,OAAOC,IAAI,EAAE;gBAGjC,IAAI,CAACpB,eAAeO,aAAa,IAAIiB,OAAOT,MAAM,GAAG,GAAG;oBACtD,IAAI,CAACQ,KAAK,CACR,CAAC,0CAA0C,EAAEC,OAAOpB,IAAI,CAAC,MAAM,CAAC;gBAEpE;gBAEA,IAAIU,SAASC,MAAM,GAAG,GAAG;oBACvB,IAAI,CAACC,IAAI,CACP,CAAC,6EAA6E,EAAEF,SAASV,IAAI,CAC3F,MACA,CAAC;gBAEP;YACF;QACF;IACF;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export { default } from './plugin';\nexport type { Options } from './plugin';\n"],"names":["default"],"mappings":"AAAA,SAASA,OAAO,QAAQ,WAAW"}
|
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const snaps_utils_1 = require("@metamask/snaps-utils");
|
|
7
|
-
const fs_1 = require("fs");
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
1
|
+
import { checkManifest, evalBundle, postProcessBundle } from '@metamask/snaps-utils';
|
|
2
|
+
import { promises as fs } from 'fs';
|
|
3
|
+
import pathUtils from 'path';
|
|
9
4
|
/**
|
|
10
5
|
* Creates a Snaps Rollup plugin instance.
|
|
11
6
|
*
|
|
@@ -19,40 +14,42 @@ const path_1 = __importDefault(require("path"));
|
|
|
19
14
|
* @param options.writeManifest - Whether to fix the manifest. Defaults to
|
|
20
15
|
* `true`.
|
|
21
16
|
* @returns The Rollup plugin object.
|
|
22
|
-
*/
|
|
23
|
-
function snaps(options) {
|
|
17
|
+
*/ export default function snaps(options) {
|
|
24
18
|
const defaultOptions = {
|
|
25
19
|
eval: true,
|
|
26
|
-
manifestPath:
|
|
20
|
+
manifestPath: pathUtils.join(process.cwd(), 'snap.manifest.json'),
|
|
27
21
|
writeManifest: true,
|
|
28
|
-
...options
|
|
22
|
+
...options
|
|
29
23
|
};
|
|
30
24
|
return {
|
|
31
25
|
name: '@metamask/snaps-rollup-plugin',
|
|
32
|
-
renderChunk(code) {
|
|
26
|
+
renderChunk (code) {
|
|
33
27
|
// Rollup internally merges the new source map with the old one, so there
|
|
34
28
|
// is no need to pass the current source map to the function.
|
|
35
|
-
const result =
|
|
29
|
+
const result = postProcessBundle(code, {
|
|
36
30
|
...defaultOptions,
|
|
37
|
-
sourceMap: true
|
|
31
|
+
sourceMap: true
|
|
38
32
|
});
|
|
39
33
|
if (result.warnings.length > 0) {
|
|
40
34
|
this.warn(`Bundle Warning: Processing of the Snap bundle completed with warnings.\n${result.warnings.join('\n')}`);
|
|
41
35
|
}
|
|
42
|
-
return {
|
|
36
|
+
return {
|
|
37
|
+
code: result.code,
|
|
38
|
+
map: result.sourceMap
|
|
39
|
+
};
|
|
43
40
|
},
|
|
44
|
-
async writeBundle(output) {
|
|
41
|
+
async writeBundle (output) {
|
|
45
42
|
if (!output.file) {
|
|
46
43
|
this.warn('No output file specified, skipping bundle validation.');
|
|
47
44
|
return;
|
|
48
45
|
}
|
|
49
46
|
if (defaultOptions.eval) {
|
|
50
|
-
await
|
|
47
|
+
await evalBundle(output.file).catch((error)=>{
|
|
51
48
|
this.error(error);
|
|
52
49
|
});
|
|
53
50
|
}
|
|
54
51
|
if (defaultOptions.manifestPath) {
|
|
55
|
-
const { errors, warnings } = await
|
|
52
|
+
const { errors, warnings } = await checkManifest(pathUtils.dirname(defaultOptions.manifestPath), defaultOptions.writeManifest, await fs.readFile(output.file, 'utf8'));
|
|
56
53
|
if (!defaultOptions.writeManifest && errors.length > 0) {
|
|
57
54
|
this.error(`Manifest Error: The manifest is invalid.\n${errors.join('\n')}`);
|
|
58
55
|
}
|
|
@@ -60,8 +57,8 @@ function snaps(options) {
|
|
|
60
57
|
this.warn(`Manifest Warning: Validation of snap.manifest.json completed with warnings.\n${warnings.join('\n')}`);
|
|
61
58
|
}
|
|
62
59
|
}
|
|
63
|
-
}
|
|
60
|
+
}
|
|
64
61
|
};
|
|
65
62
|
}
|
|
66
|
-
|
|
63
|
+
|
|
67
64
|
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/plugin.ts"],"sourcesContent":["import type { PostProcessOptions } from '@metamask/snaps-utils';\nimport {\n checkManifest,\n evalBundle,\n postProcessBundle,\n} from '@metamask/snaps-utils';\nimport { promises as fs } from 'fs';\nimport pathUtils from 'path';\n// eslint-disable-next-line @typescript-eslint/no-shadow\nimport type { Plugin, SourceMapInput } from 'rollup';\n\ntype PluginOptions = {\n eval?: boolean;\n manifestPath?: string;\n writeManifest?: boolean;\n};\n\nexport type Options = PluginOptions &\n Omit<PostProcessOptions, 'sourceMap' | 'inputSourceMap'>;\n\n/**\n * Creates a Snaps Rollup plugin instance.\n *\n * @param options - The plugin options.\n * @param options.stripComments - Whether to strip comments. Defaults to `true`.\n * @param options.eval - Whether to evaluate the bundle to test SES\n * compatibility. Defaults to `true`.\n * @param options.manifestPath - The path to the manifest file. If provided,\n * the manifest will be validated. Defaults to\n * `process.cwd() + '/snap.manifest.json'`.\n * @param options.writeManifest - Whether to fix the manifest. Defaults to\n * `true`.\n * @returns The Rollup plugin object.\n */\nexport default function snaps(options?: Partial<Options>): Plugin {\n const defaultOptions = {\n eval: true,\n manifestPath: pathUtils.join(process.cwd(), 'snap.manifest.json'),\n writeManifest: true,\n ...options,\n };\n\n return {\n name: '@metamask/snaps-rollup-plugin',\n\n renderChunk(code: string): { code: string; map?: SourceMapInput } | null {\n // Rollup internally merges the new source map with the old one, so there\n // is no need to pass the current source map to the function.\n const result = postProcessBundle(code, {\n ...defaultOptions,\n sourceMap: true,\n });\n\n if (result.warnings.length > 0) {\n this.warn(\n `Bundle Warning: Processing of the Snap bundle completed with warnings.\\n${result.warnings.join(\n '\\n',\n )}`,\n );\n }\n\n return { code: result.code, map: result.sourceMap };\n },\n\n async writeBundle(output): Promise<void> {\n if (!output.file) {\n this.warn('No output file specified, skipping bundle validation.');\n return;\n }\n\n if (defaultOptions.eval) {\n await evalBundle(output.file).catch((error) => {\n this.error(error);\n });\n }\n\n if (defaultOptions.manifestPath) {\n const { errors, warnings } = await checkManifest(\n pathUtils.dirname(defaultOptions.manifestPath),\n defaultOptions.writeManifest,\n await fs.readFile(output.file, 'utf8'),\n );\n\n if (!defaultOptions.writeManifest && errors.length > 0) {\n this.error(\n `Manifest Error: The manifest is invalid.\\n${errors.join('\\n')}`,\n );\n }\n\n if (warnings.length > 0) {\n this.warn(\n `Manifest Warning: Validation of snap.manifest.json completed with warnings.\\n${warnings.join(\n '\\n',\n )}`,\n );\n }\n }\n },\n };\n}\n"],"names":["checkManifest","evalBundle","postProcessBundle","promises","fs","pathUtils","snaps","options","defaultOptions","eval","manifestPath","join","process","cwd","writeManifest","name","renderChunk","code","result","sourceMap","warnings","length","warn","map","writeBundle","output","file","catch","error","errors","dirname","readFile"],"mappings":"AACA,SACEA,aAAa,EACbC,UAAU,EACVC,iBAAiB,QACZ,wBAAwB;AAC/B,SAASC,YAAYC,EAAE,QAAQ,KAAK;AACpC,OAAOC,eAAe,OAAO;AAa7B;;;;;;;;;;;;;CAaC,GACD,eAAe,SAASC,MAAMC,OAA0B;IACtD,MAAMC,iBAAiB;QACrBC,MAAM;QACNC,cAAcL,UAAUM,IAAI,CAACC,QAAQC,GAAG,IAAI;QAC5CC,eAAe;QACf,GAAGP,OAAO;IACZ;IAEA,OAAO;QACLQ,MAAM;QAENC,aAAYC,IAAY;YACtB,yEAAyE;YACzE,6DAA6D;YAC7D,MAAMC,SAAShB,kBAAkBe,MAAM;gBACrC,GAAGT,cAAc;gBACjBW,WAAW;YACb;YAEA,IAAID,OAAOE,QAAQ,CAACC,MAAM,GAAG,GAAG;gBAC9B,IAAI,CAACC,IAAI,CACP,CAAC,wEAAwE,EAAEJ,OAAOE,QAAQ,CAACT,IAAI,CAC7F,MACA,CAAC;YAEP;YAEA,OAAO;gBAAEM,MAAMC,OAAOD,IAAI;gBAAEM,KAAKL,OAAOC,SAAS;YAAC;QACpD;QAEA,MAAMK,aAAYC,MAAM;YACtB,IAAI,CAACA,OAAOC,IAAI,EAAE;gBAChB,IAAI,CAACJ,IAAI,CAAC;gBACV;YACF;YAEA,IAAId,eAAeC,IAAI,EAAE;gBACvB,MAAMR,WAAWwB,OAAOC,IAAI,EAAEC,KAAK,CAAC,CAACC;oBACnC,IAAI,CAACA,KAAK,CAACA;gBACb;YACF;YAEA,IAAIpB,eAAeE,YAAY,EAAE;gBAC/B,MAAM,EAAEmB,MAAM,EAAET,QAAQ,EAAE,GAAG,MAAMpB,cACjCK,UAAUyB,OAAO,CAACtB,eAAeE,YAAY,GAC7CF,eAAeM,aAAa,EAC5B,MAAMV,GAAG2B,QAAQ,CAACN,OAAOC,IAAI,EAAE;gBAGjC,IAAI,CAAClB,eAAeM,aAAa,IAAIe,OAAOR,MAAM,GAAG,GAAG;oBACtD,IAAI,CAACO,KAAK,CACR,CAAC,0CAA0C,EAAEC,OAAOlB,IAAI,CAAC,MAAM,CAAC;gBAEpE;gBAEA,IAAIS,SAASC,MAAM,GAAG,GAAG;oBACvB,IAAI,CAACC,IAAI,CACP,CAAC,6EAA6E,EAAEF,SAAST,IAAI,CAC3F,MACA,CAAC;gBAEP;YACF;QACF;IACF;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { PostProcessOptions } from '@metamask/snaps-utils';
|
|
2
|
-
import { Plugin } from 'rollup';
|
|
1
|
+
import type { PostProcessOptions } from '@metamask/snaps-utils';
|
|
2
|
+
import type { Plugin } from 'rollup';
|
|
3
3
|
declare type PluginOptions = {
|
|
4
4
|
eval?: boolean;
|
|
5
5
|
manifestPath?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/snaps-rollup-plugin",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"rollup",
|
|
6
6
|
"rollup-plugin"
|
|
@@ -9,57 +9,70 @@
|
|
|
9
9
|
"type": "git",
|
|
10
10
|
"url": "https://github.com/MetaMask/snaps.git"
|
|
11
11
|
},
|
|
12
|
-
"
|
|
12
|
+
"sideEffects": false,
|
|
13
|
+
"main": "./dist/cjs/index.js",
|
|
14
|
+
"module": "./dist/esm/index.js",
|
|
15
|
+
"types": "./dist/types/index.d.ts",
|
|
13
16
|
"files": [
|
|
14
|
-
"dist/"
|
|
17
|
+
"dist/cjs/**",
|
|
18
|
+
"dist/esm/**",
|
|
19
|
+
"dist/types/**"
|
|
15
20
|
],
|
|
16
21
|
"scripts": {
|
|
17
22
|
"test": "jest && yarn posttest",
|
|
18
23
|
"posttest": "jest-it-up",
|
|
19
24
|
"test:ci": "yarn test",
|
|
20
|
-
"lint:eslint": "eslint . --cache --ext js,ts",
|
|
21
|
-
"lint:misc": "prettier
|
|
22
|
-
"lint": "yarn lint:eslint && yarn lint:misc --check",
|
|
25
|
+
"lint:eslint": "eslint . --cache --ext js,ts,jsx,tsx",
|
|
26
|
+
"lint:misc": "prettier --no-error-on-unmatched-pattern --loglevel warn \"**/*.json\" \"**/*.md\" \"**/*.html\" \"!CHANGELOG.md\" --ignore-path ../../.gitignore",
|
|
27
|
+
"lint": "yarn lint:eslint && yarn lint:misc --check && yarn lint:changelog && yarn lint:dependencies",
|
|
23
28
|
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write",
|
|
24
|
-
"lint:changelog": "
|
|
25
|
-
"build
|
|
26
|
-
"build": "yarn build:
|
|
29
|
+
"lint:changelog": "../../scripts/validate-changelog.sh @metamask/snaps-rollup-plugin",
|
|
30
|
+
"build": "yarn build:source && yarn build:types",
|
|
31
|
+
"build:source": "yarn build:esm && yarn build:cjs",
|
|
32
|
+
"build:types": "tsc --project tsconfig.build.json",
|
|
33
|
+
"build:esm": "swc src --out-dir dist/esm --config-file ../../.swcrc.build.json --config module.type=es6",
|
|
34
|
+
"build:cjs": "swc src --out-dir dist/cjs --config-file ../../.swcrc.build.json --config module.type=commonjs",
|
|
27
35
|
"build:clean": "yarn clean && yarn build",
|
|
28
|
-
"clean": "rimraf '*.tsbuildinfo' 'dist
|
|
36
|
+
"clean": "rimraf '*.tsbuildinfo' 'dist'",
|
|
29
37
|
"prepare-manifest:preview": "../../scripts/prepare-preview-manifest.sh",
|
|
30
38
|
"publish:preview": "yarn npm publish --tag preview",
|
|
31
|
-
"
|
|
39
|
+
"lint:ci": "yarn lint",
|
|
40
|
+
"lint:dependencies": "depcheck"
|
|
32
41
|
},
|
|
33
42
|
"dependencies": {
|
|
34
|
-
"@metamask/snaps-utils": "^
|
|
43
|
+
"@metamask/snaps-utils": "^2.0.0"
|
|
35
44
|
},
|
|
36
45
|
"devDependencies": {
|
|
37
|
-
"@lavamoat/allow-scripts": "^2.
|
|
46
|
+
"@lavamoat/allow-scripts": "^2.3.1",
|
|
38
47
|
"@metamask/auto-changelog": "^3.1.0",
|
|
39
|
-
"@metamask/eslint-config": "^
|
|
40
|
-
"@metamask/eslint-config-jest": "^
|
|
41
|
-
"@metamask/eslint-config-nodejs": "^
|
|
42
|
-
"@metamask/eslint-config-typescript": "^
|
|
48
|
+
"@metamask/eslint-config": "^12.1.0",
|
|
49
|
+
"@metamask/eslint-config-jest": "^12.1.0",
|
|
50
|
+
"@metamask/eslint-config-nodejs": "^12.1.0",
|
|
51
|
+
"@metamask/eslint-config-typescript": "^12.1.0",
|
|
43
52
|
"@rollup/plugin-virtual": "^2.1.0",
|
|
53
|
+
"@swc/cli": "^0.1.62",
|
|
54
|
+
"@swc/core": "1.3.78",
|
|
55
|
+
"@swc/jest": "^0.2.26",
|
|
44
56
|
"@types/jest": "^27.5.1",
|
|
45
57
|
"@typescript-eslint/eslint-plugin": "^5.42.1",
|
|
46
58
|
"@typescript-eslint/parser": "^5.42.1",
|
|
47
59
|
"deepmerge": "^4.2.2",
|
|
60
|
+
"depcheck": "^1.4.5",
|
|
48
61
|
"eslint": "^8.27.0",
|
|
49
62
|
"eslint-config-prettier": "^8.5.0",
|
|
50
63
|
"eslint-plugin-import": "^2.26.0",
|
|
51
64
|
"eslint-plugin-jest": "^27.1.5",
|
|
52
65
|
"eslint-plugin-jsdoc": "^39.6.2",
|
|
53
|
-
"eslint-plugin-
|
|
66
|
+
"eslint-plugin-n": "^15.7.0",
|
|
54
67
|
"eslint-plugin-prettier": "^4.2.1",
|
|
68
|
+
"eslint-plugin-promise": "^6.1.1",
|
|
55
69
|
"jest": "^29.0.2",
|
|
56
70
|
"jest-it-up": "^2.0.0",
|
|
57
|
-
"memfs": "^3.4.
|
|
71
|
+
"memfs": "^3.4.13",
|
|
58
72
|
"prettier": "^2.7.1",
|
|
59
73
|
"prettier-plugin-packagejson": "^2.2.11",
|
|
60
|
-
"rimraf": "^
|
|
61
|
-
"rollup": "^2.
|
|
62
|
-
"ts-jest": "^29.0.0",
|
|
74
|
+
"rimraf": "^4.1.2",
|
|
75
|
+
"rollup": "^2.73.0",
|
|
63
76
|
"typescript": "~4.8.4"
|
|
64
77
|
},
|
|
65
78
|
"engines": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"source-map.js","sourceRoot":"","sources":["../../src/__fixtures__/source-map.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAE5D,8CAA8C;AAC9C,MAAM,GAAG,GAAG,KAAK,CAAC;AAClB,sCAAsC;AACtC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC","sourcesContent":["// This file is only used for testing source map generation.\n\n// eslint-disable-next-line import/unambiguous\nconst foo = 'bar';\n// eslint-disable-next-line no-console\nconsole.log(foo);\n"]}
|
package/dist/index.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var plugin_1 = require("./plugin");
|
|
8
|
-
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(plugin_1).default; } });
|
|
9
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,mCAAmC;AAA1B,kHAAA,OAAO,OAAA","sourcesContent":["export { default } from './plugin';\nexport type { Options } from './plugin';\n"]}
|
package/dist/plugin.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":";;;;;AAAA,uDAK+B;AAC/B,2BAAoC;AACpC,gDAA6B;AAa7B;;;;;;;;;;;;;GAaG;AACH,SAAwB,KAAK,CAAC,OAA0B;IACtD,MAAM,cAAc,GAAG;QACrB,IAAI,EAAE,IAAI;QACV,YAAY,EAAE,cAAS,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,oBAAoB,CAAC;QACjE,aAAa,EAAE,IAAI;QACnB,GAAG,OAAO;KACX,CAAC;IAEF,OAAO;QACL,IAAI,EAAE,+BAA+B;QAErC,WAAW,CAAC,IAAY;YACtB,yEAAyE;YACzE,6DAA6D;YAC7D,MAAM,MAAM,GAAG,IAAA,+BAAiB,EAAC,IAAI,EAAE;gBACrC,GAAG,cAAc;gBACjB,SAAS,EAAE,IAAI;aAChB,CAAC,CAAC;YAEH,IAAI,MAAM,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE;gBAC9B,IAAI,CAAC,IAAI,CACP,2EAA2E,MAAM,CAAC,QAAQ,CAAC,IAAI,CAC7F,IAAI,CACL,EAAE,CACJ,CAAC;aACH;YAED,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,MAAM,CAAC,SAAS,EAAE,CAAC;QACtD,CAAC;QAED,KAAK,CAAC,WAAW,CAAC,MAAM;YACtB,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE;gBAChB,IAAI,CAAC,IAAI,CAAC,uDAAuD,CAAC,CAAC;gBACnE,OAAO;aACR;YAED,IAAI,cAAc,CAAC,IAAI,EAAE;gBACvB,MAAM,IAAA,wBAAU,EAAC,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;oBAC5C,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;gBACpB,CAAC,CAAC,CAAC;aACJ;YAED,IAAI,cAAc,CAAC,YAAY,EAAE;gBAC/B,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,IAAA,2BAAa,EAC9C,cAAS,CAAC,OAAO,CAAC,cAAc,CAAC,YAAY,CAAC,EAC9C,cAAc,CAAC,aAAa,EAC5B,MAAM,aAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CACvC,CAAC;gBAEF,IAAI,CAAC,cAAc,CAAC,aAAa,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;oBACtD,IAAI,CAAC,KAAK,CACR,6CAA6C,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CACjE,CAAC;iBACH;gBAED,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE;oBACvB,IAAI,CAAC,IAAI,CACP,gFAAgF,QAAQ,CAAC,IAAI,CAC3F,IAAI,CACL,EAAE,CACJ,CAAC;iBACH;aACF;QACH,CAAC;KACF,CAAC;AACJ,CAAC;AAjED,wBAiEC","sourcesContent":["import {\n checkManifest,\n evalBundle,\n postProcessBundle,\n PostProcessOptions,\n} from '@metamask/snaps-utils';\nimport { promises as fs } from 'fs';\nimport pathUtils from 'path';\n// eslint-disable-next-line @typescript-eslint/no-shadow\nimport { Plugin, SourceMapInput } from 'rollup';\n\ntype PluginOptions = {\n eval?: boolean;\n manifestPath?: string;\n writeManifest?: boolean;\n};\n\nexport type Options = PluginOptions &\n Omit<PostProcessOptions, 'sourceMap' | 'inputSourceMap'>;\n\n/**\n * Creates a Snaps Rollup plugin instance.\n *\n * @param options - The plugin options.\n * @param options.stripComments - Whether to strip comments. Defaults to `true`.\n * @param options.eval - Whether to evaluate the bundle to test SES\n * compatibility. Defaults to `true`.\n * @param options.manifestPath - The path to the manifest file. If provided,\n * the manifest will be validated. Defaults to\n * `process.cwd() + '/snap.manifest.json'`.\n * @param options.writeManifest - Whether to fix the manifest. Defaults to\n * `true`.\n * @returns The Rollup plugin object.\n */\nexport default function snaps(options?: Partial<Options>): Plugin {\n const defaultOptions = {\n eval: true,\n manifestPath: pathUtils.join(process.cwd(), 'snap.manifest.json'),\n writeManifest: true,\n ...options,\n };\n\n return {\n name: '@metamask/snaps-rollup-plugin',\n\n renderChunk(code: string): { code: string; map?: SourceMapInput } | null {\n // Rollup internally merges the new source map with the old one, so there\n // is no need to pass the current source map to the function.\n const result = postProcessBundle(code, {\n ...defaultOptions,\n sourceMap: true,\n });\n\n if (result.warnings.length > 0) {\n this.warn(\n `Bundle Warning: Processing of the Snap bundle completed with warnings.\\n${result.warnings.join(\n '\\n',\n )}`,\n );\n }\n\n return { code: result.code, map: result.sourceMap };\n },\n\n async writeBundle(output): Promise<void> {\n if (!output.file) {\n this.warn('No output file specified, skipping bundle validation.');\n return;\n }\n\n if (defaultOptions.eval) {\n await evalBundle(output.file).catch((error) => {\n this.error(error);\n });\n }\n\n if (defaultOptions.manifestPath) {\n const { errors, warnings } = await checkManifest(\n pathUtils.dirname(defaultOptions.manifestPath),\n defaultOptions.writeManifest,\n await fs.readFile(output.file, 'utf8'),\n );\n\n if (!defaultOptions.writeManifest && errors.length > 0) {\n this.error(\n `Manifest Error: The manifest is invalid.\\n${errors.join('\\n')}`,\n );\n }\n\n if (warnings.length > 0) {\n this.warn(\n `Manifest Warning: Validation of snap.manifest.json completed with warnings.\\n${warnings.join(\n '\\n',\n )}`,\n );\n }\n }\n },\n };\n}\n"]}
|
|
File without changes
|
|
File without changes
|