@metamask/snaps-rollup-plugin 1.0.2 → 3.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 CHANGED
@@ -6,183 +6,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
- ## [1.0.2]
9
+ ## [3.0.0]
10
10
  ### Changed
11
- - No changes this release.
11
+ - **BREAKING:** Bump minimum Node.js version to `^18.16.0` ([#1741](https://github.com/MetaMask/snaps/pull/1741))
12
12
 
13
- ## [1.0.1]
13
+ ## [2.0.0]
14
14
  ### Changed
15
- - No changes this release.
15
+ - Initial stable release from main branch ([#1757](https://github.com/MetaMask/snaps/pull/1757))
16
16
 
17
- ## [1.0.0]
18
- ### Changed
19
- - No changes this release.
20
-
21
- ## [1.0.0-prerelease.1]
22
- ### Changed
23
- - No changes this release.
24
-
25
- ## [0.32.2]
26
- ### Changed
27
- - No changes this release.
28
-
29
- ## [0.32.1]
30
- ### Changed
31
- - No changes this release.
32
-
33
- ## [0.32.0]
34
- ### Changed
35
- - No changes this release.
36
-
37
- ## [0.31.0]
38
- ### Changed
39
- - **BREAKING:** Target `ES2020` ([#1247](https://github.com/MetaMask/snaps-monorepo/pull/1247))
40
-
41
- ## [0.30.0]
42
- ### Changed
43
- - No changes this release.
44
-
45
- ## [0.29.0]
46
- ### Changed
47
- - No changes this release.
48
-
49
- ## [0.28.0]
50
- ### Changed
51
- - No changes this release.
52
-
53
- ## [0.27.1]
54
- ### Changed
55
- - No changes this release.
56
-
57
- ## [0.27.0]
58
- ### Changed
59
- - No changes this release.
60
-
61
- ## [0.26.2]
62
- ### Changed
63
- - No changes this release.
64
-
65
- ## [0.26.1]
66
- ### Changed
67
- - No changes this release.
68
-
69
- ## [0.26.0]
70
- ### Changed
71
- - No changes this release.
72
-
73
- ## [0.25.0]
74
- ### Changed
75
- - No changes this release.
76
-
77
- ## [0.24.1]
78
- ### Changed
79
- - No changes this release.
80
-
81
- ## [0.24.0]
82
- ### Added
83
- - Add compile-time warning when using `Math.random` ([#950](https://github.com/MetaMask/snaps-monorepo/pull/950))
84
-
85
- ### Changed
86
- - **BREAKING:** Rename package to start with `snaps-` ([#937](https://github.com/MetaMask/snaps-monorepo/pull/937))
87
-
88
- ## [0.23.0]
89
- ### Changed
90
- - No changes this release.
91
-
92
- ## [0.22.3]
93
- ### Changed
94
- - No changes this release.
95
-
96
- ## [0.22.2]
97
- ### Changed
98
- - No changes this release.
99
-
100
- ## [0.22.1]
101
- ### Changed
102
- - No changes this release.
103
-
104
- ## [0.22.0]
105
- ### Changed
106
- - No changes this release.
107
-
108
- ## [0.21.0]
109
- ### Added
110
- - Run eval and fix manifest in bundler plugins ([#731](https://github.com/MetaMask/snaps-monorepo/pull/731))
111
-
112
- ## [0.20.0]
113
- ### Changed
114
- - No changes this release.
115
-
116
- ## [0.19.1]
117
- ### Added
118
- - Generate source maps from modified code ([#615](https://github.com/MetaMask/snaps-monorepo/pull/615))
119
-
120
- ## [0.19.0]
121
- ### Changed
122
- - No changes this release.
123
-
124
- ## [0.18.1]
125
- ### Changed
126
- - No changes this release.
127
-
128
- ## [0.18.0]
129
- ### Changed
130
- - Reduce TypeScript compilation target to ES2017 ([#628](https://github.com/MetaMask/snaps-monorepo/pull/628))
131
-
132
- ## [0.17.0]
133
- ### Changed
134
- - **BREAKING:** Bump minimum Node version to 16 ([#601](https://github.com/MetaMask/snaps-monorepo/pull/601))
135
-
136
- ## [0.16.0]
137
- ### Changed
138
- - No changes this release.
139
-
140
- ## [0.15.0]
141
- ### Changed
142
- - No changes this release.
143
-
144
- ## [0.14.0]
17
+ ## [0.37.3-flask.1]
145
18
  ### Fixed
146
- - Actually publish package contents ([#449](https://github.com/MetaMask/snaps-monorepo/pull/449))
147
- - Package contents were omitted from the previous version due to a build failure.
19
+ - Remove unused dependencies ([#1680](https://github.com/MetaMask/snaps/pull/1680))
148
20
 
149
- ## [0.13.0]
150
- ### Added
151
- - Initial release ([#431](https://github.com/MetaMask/snaps-monorepo/pull/431))
21
+ ## [0.37.2-flask.1]
22
+ ### Changed
23
+ - Release package independently ([#1600](https://github.com/MetaMask/snaps/pull/1600))
24
+ - The version of the package no longer needs to match the version of all other
25
+ MetaMask Snaps packages.
152
26
 
153
- [Unreleased]: https://github.com/MetaMask/snaps/compare/v1.0.2...HEAD
154
- [1.0.2]: https://github.com/MetaMask/snaps/compare/v1.0.1...v1.0.2
155
- [1.0.1]: https://github.com/MetaMask/snaps/compare/v1.0.0...v1.0.1
156
- [1.0.0]: https://github.com/MetaMask/snaps/compare/v1.0.0-prerelease.1...v1.0.0
157
- [1.0.0-prerelease.1]: https://github.com/MetaMask/snaps/compare/v0.32.2...v1.0.0-prerelease.1
158
- [0.32.2]: https://github.com/MetaMask/snaps/compare/v0.32.1...v0.32.2
159
- [0.32.1]: https://github.com/MetaMask/snaps/compare/v0.32.0...v0.32.1
160
- [0.32.0]: https://github.com/MetaMask/snaps/compare/v0.31.0...v0.32.0
161
- [0.31.0]: https://github.com/MetaMask/snaps/compare/v0.30.0...v0.31.0
162
- [0.30.0]: https://github.com/MetaMask/snaps/compare/v0.29.0...v0.30.0
163
- [0.29.0]: https://github.com/MetaMask/snaps/compare/v0.28.0...v0.29.0
164
- [0.28.0]: https://github.com/MetaMask/snaps/compare/v0.27.1...v0.28.0
165
- [0.27.1]: https://github.com/MetaMask/snaps/compare/v0.27.0...v0.27.1
166
- [0.27.0]: https://github.com/MetaMask/snaps/compare/v0.26.2...v0.27.0
167
- [0.26.2]: https://github.com/MetaMask/snaps/compare/v0.26.1...v0.26.2
168
- [0.26.1]: https://github.com/MetaMask/snaps/compare/v0.26.0...v0.26.1
169
- [0.26.0]: https://github.com/MetaMask/snaps/compare/v0.25.0...v0.26.0
170
- [0.25.0]: https://github.com/MetaMask/snaps/compare/v0.24.1...v0.25.0
171
- [0.24.1]: https://github.com/MetaMask/snaps/compare/v0.24.0...v0.24.1
172
- [0.24.0]: https://github.com/MetaMask/snaps/compare/v0.23.0...v0.24.0
173
- [0.23.0]: https://github.com/MetaMask/snaps/compare/v0.22.3...v0.23.0
174
- [0.22.3]: https://github.com/MetaMask/snaps/compare/v0.22.2...v0.22.3
175
- [0.22.2]: https://github.com/MetaMask/snaps/compare/v0.22.1...v0.22.2
176
- [0.22.1]: https://github.com/MetaMask/snaps/compare/v0.22.0...v0.22.1
177
- [0.22.0]: https://github.com/MetaMask/snaps/compare/v0.21.0...v0.22.0
178
- [0.21.0]: https://github.com/MetaMask/snaps/compare/v0.20.0...v0.21.0
179
- [0.20.0]: https://github.com/MetaMask/snaps/compare/v0.19.1...v0.20.0
180
- [0.19.1]: https://github.com/MetaMask/snaps/compare/v0.19.0...v0.19.1
181
- [0.19.0]: https://github.com/MetaMask/snaps/compare/v0.18.1...v0.19.0
182
- [0.18.1]: https://github.com/MetaMask/snaps/compare/v0.18.0...v0.18.1
183
- [0.18.0]: https://github.com/MetaMask/snaps/compare/v0.17.0...v0.18.0
184
- [0.17.0]: https://github.com/MetaMask/snaps/compare/v0.16.0...v0.17.0
185
- [0.16.0]: https://github.com/MetaMask/snaps/compare/v0.15.0...v0.16.0
186
- [0.15.0]: https://github.com/MetaMask/snaps/compare/v0.14.0...v0.15.0
187
- [0.14.0]: https://github.com/MetaMask/snaps/compare/v0.13.0...v0.14.0
188
- [0.13.0]: https://github.com/MetaMask/snaps/releases/tag/v0.13.0
27
+ [Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rollup-plugin@3.0.0...HEAD
28
+ [3.0.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rollup-plugin@2.0.0...@metamask/snaps-rollup-plugin@3.0.0
29
+ [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
30
+ [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
31
+ [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,3 @@
1
+ export { default } from './plugin';
2
+
3
+ //# 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":"AAAA,SAASA,OAAO,QAAQ,WAAW"}
@@ -1,11 +1,6 @@
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
- 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: path_1.default.join(process.cwd(), 'snap.manifest.json'),
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 = (0, snaps_utils_1.postProcessBundle)(code, {
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 { code: result.code, map: result.sourceMap };
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 (0, snaps_utils_1.evalBundle)(output.file).catch((error) => {
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 (0, snaps_utils_1.checkManifest)(path_1.default.dirname(defaultOptions.manifestPath), defaultOptions.writeManifest, await fs_1.promises.readFile(output.file, 'utf8'));
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
- exports.default = snaps;
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": "1.0.2",
3
+ "version": "3.0.0",
4
4
  "keywords": [
5
5
  "rollup",
6
6
  "rollup-plugin"
@@ -9,61 +9,74 @@
9
9
  "type": "git",
10
10
  "url": "https://github.com/MetaMask/snaps.git"
11
11
  },
12
- "main": "dist/index.js",
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 '**/*.json' '**/*.md' '!CHANGELOG.md' --ignore-path ../../.gitignore",
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": "yarn auto-changelog validate",
25
- "build:tsc": "tsc --project tsconfig.build.json",
26
- "build": "yarn build:tsc",
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
- "publish:package": "../../scripts/publish-package.sh"
39
+ "lint:ci": "yarn lint",
40
+ "lint:dependencies": "depcheck"
32
41
  },
33
42
  "dependencies": {
34
- "@metamask/snaps-utils": "^1.0.2"
43
+ "@metamask/snaps-utils": "^3.0.0"
35
44
  },
36
45
  "devDependencies": {
37
- "@lavamoat/allow-scripts": "^2.0.3",
38
- "@metamask/auto-changelog": "^3.1.0",
39
- "@metamask/eslint-config": "^11.0.0",
40
- "@metamask/eslint-config-jest": "^11.0.0",
41
- "@metamask/eslint-config-nodejs": "^11.0.1",
42
- "@metamask/eslint-config-typescript": "^11.0.0",
46
+ "@lavamoat/allow-scripts": "^2.5.1",
47
+ "@metamask/auto-changelog": "^3.3.0",
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-node": "^11.1.0",
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.7",
71
+ "memfs": "^3.4.13",
58
72
  "prettier": "^2.7.1",
59
73
  "prettier-plugin-packagejson": "^2.2.11",
60
- "rimraf": "^3.0.2",
61
- "rollup": "^2.72.1",
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": {
66
- "node": ">=16.0.0"
79
+ "node": "^18.16 || >=20"
67
80
  },
68
81
  "publishConfig": {
69
82
  "access": "public",
@@ -1,7 +0,0 @@
1
- "use strict";
2
- // This file is only used for testing source map generation.
3
- // eslint-disable-next-line import/unambiguous
4
- const foo = 'bar';
5
- // eslint-disable-next-line no-console
6
- console.log(foo);
7
- //# sourceMappingURL=source-map.js.map
@@ -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"]}
@@ -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