@metamask/snaps-rollup-plugin 0.24.1 → 0.25.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/dist/plugin.js CHANGED
@@ -3,9 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ const snaps_utils_1 = require("@metamask/snaps-utils");
6
7
  const fs_1 = require("fs");
7
8
  const path_1 = __importDefault(require("path"));
8
- const snaps_utils_1 = require("@metamask/snaps-utils");
9
9
  /**
10
10
  * Creates a Snaps Rollup plugin instance.
11
11
  *
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":";;;;;AAAA,2BAAoC;AACpC,gDAA6B;AAC7B,uDAK+B;AAY/B;;;;;;;;;;;;;GAaG;AACH,SAAwB,KAAK,CAAC,OAA0B;IACtD,MAAM,cAAc,mBAClB,IAAI,EAAE,IAAI,EACV,YAAY,EAAE,cAAS,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,oBAAoB,CAAC,EACjE,aAAa,EAAE,IAAI,IAChB,OAAO,CACX,CAAC;IAEF,OAAO;QACL,IAAI,EAAE,+BAA+B;QAErC,WAAW,CAAC,IAAY;YACtB,yEAAyE;YACzE,6DAA6D;YAC7D,MAAM,MAAM,GAAG,IAAA,+BAAiB,EAAC,IAAI,kCAChC,cAAc,KACjB,SAAS,EAAE,IAAI,IACf,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 { promises as fs } from 'fs';\nimport pathUtils from 'path';\nimport {\n checkManifest,\n evalBundle,\n postProcessBundle,\n PostProcessOptions,\n} from '@metamask/snaps-utils';\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',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Ac,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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/snaps-rollup-plugin",
3
- "version": "0.24.1",
3
+ "version": "0.25.0",
4
4
  "keywords": [
5
5
  "rollup",
6
6
  "rollup-plugin"
@@ -29,34 +29,36 @@
29
29
  "publish:package": "../../scripts/publish-package.sh"
30
30
  },
31
31
  "dependencies": {
32
- "@metamask/snaps-utils": "^0.24.1"
32
+ "@metamask/snaps-utils": "^0.25.0"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@lavamoat/allow-scripts": "^2.0.3",
36
- "@metamask/auto-changelog": "^2.6.0",
37
- "@metamask/eslint-config": "^9.0.0",
38
- "@metamask/eslint-config-jest": "^9.0.0",
39
- "@metamask/eslint-config-nodejs": "^9.0.0",
40
- "@metamask/eslint-config-typescript": "^9.0.1",
36
+ "@metamask/auto-changelog": "^3.1.0",
37
+ "@metamask/eslint-config": "^11.0.0",
38
+ "@metamask/eslint-config-jest": "^11.0.0",
39
+ "@metamask/eslint-config-nodejs": "^11.0.1",
40
+ "@metamask/eslint-config-typescript": "^11.0.0",
41
41
  "@rollup/plugin-virtual": "^2.1.0",
42
42
  "@types/jest": "^27.5.1",
43
+ "@typescript-eslint/eslint-plugin": "^5.42.1",
44
+ "@typescript-eslint/parser": "^5.42.1",
43
45
  "deepmerge": "^4.2.2",
44
- "eslint": "^7.30.0",
45
- "eslint-config-prettier": "^8.3.0",
46
- "eslint-plugin-import": "^2.23.4",
47
- "eslint-plugin-jest": "^24.4.0",
48
- "eslint-plugin-jsdoc": "^36.1.0",
46
+ "eslint": "^8.27.0",
47
+ "eslint-config-prettier": "^8.5.0",
48
+ "eslint-plugin-import": "^2.26.0",
49
+ "eslint-plugin-jest": "^27.1.5",
50
+ "eslint-plugin-jsdoc": "^39.6.2",
49
51
  "eslint-plugin-node": "^11.1.0",
50
- "eslint-plugin-prettier": "^3.4.0",
52
+ "eslint-plugin-prettier": "^4.2.1",
51
53
  "jest": "^29.0.2",
52
54
  "jest-it-up": "^2.0.0",
53
55
  "memfs": "^3.4.7",
54
- "prettier": "^2.3.2",
56
+ "prettier": "^2.7.1",
55
57
  "prettier-plugin-packagejson": "^2.2.11",
56
58
  "rimraf": "^3.0.2",
57
59
  "rollup": "^2.72.1",
58
60
  "ts-jest": "^29.0.0",
59
- "typescript": "^4.4.0"
61
+ "typescript": "~4.8.4"
60
62
  },
61
63
  "engines": {
62
64
  "node": ">=16.0.0"