@metamask/snaps-webpack-plugin 3.1.1 → 3.2.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 +10 -1
- package/dist/cjs/plugin.js +3 -2
- package/dist/cjs/plugin.js.map +1 -1
- package/dist/esm/plugin.js +3 -2
- package/dist/esm/plugin.js.map +1 -1
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [3.2.0]
|
|
10
|
+
### Added
|
|
11
|
+
- Add a manifest warning when no icon is found and when icon is not square ([#2185](https://github.com/MetaMask/snaps/pull/2185))
|
|
12
|
+
|
|
13
|
+
### Changed
|
|
14
|
+
- Update warning messages ([#2186](https://github.com/MetaMask/snaps/pull/2186))
|
|
15
|
+
- Bump several MetaMask dependencies ([#2054](https://github.com/MetaMask/snaps/pull/2054), [#2100](https://github.com/MetaMask/snaps/pull/2100), [#2105](https://github.com/MetaMask/snaps/pull/2105), [#2173](https://github.com/MetaMask/snaps/pull/2173))
|
|
16
|
+
|
|
9
17
|
## [3.1.1]
|
|
10
18
|
### Changed
|
|
11
19
|
- Bump several MetaMask dependencies ([#1964](https://github.com/MetaMask/snaps/pull/1964))
|
|
@@ -46,7 +54,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
46
54
|
- The version of the package no longer needs to match the version of all other
|
|
47
55
|
MetaMask Snaps packages.
|
|
48
56
|
|
|
49
|
-
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-webpack-plugin@3.
|
|
57
|
+
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-webpack-plugin@3.2.0...HEAD
|
|
58
|
+
[3.2.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-webpack-plugin@3.1.1...@metamask/snaps-webpack-plugin@3.2.0
|
|
50
59
|
[3.1.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-webpack-plugin@3.1.0...@metamask/snaps-webpack-plugin@3.1.1
|
|
51
60
|
[3.1.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-webpack-plugin@3.0.1...@metamask/snaps-webpack-plugin@3.1.0
|
|
52
61
|
[3.0.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-webpack-plugin@3.0.0...@metamask/snaps-webpack-plugin@3.0.1
|
package/dist/cjs/plugin.js
CHANGED
|
@@ -59,7 +59,8 @@ class SnapsWebpackPlugin {
|
|
|
59
59
|
inputSourceMap: devtool ? sourceMap : undefined
|
|
60
60
|
});
|
|
61
61
|
if (processed.warnings.length > 0) {
|
|
62
|
-
|
|
62
|
+
const webpackErrors = processed.warnings.map((warning)=>new _webpack.WebpackError(warning));
|
|
63
|
+
compilation.warnings.push(...webpackErrors);
|
|
63
64
|
}
|
|
64
65
|
const replacement = processed.sourceMap ? new _webpacksources.SourceMapSource(processed.code, assetName, processed.sourceMap, source, sourceMap) : new _webpacksources.RawSource(processed.code);
|
|
65
66
|
// For some reason the type of `RawSource` is not compatible with
|
|
@@ -89,7 +90,7 @@ class SnapsWebpackPlugin {
|
|
|
89
90
|
throw new Error(`Manifest Error: The manifest is invalid.\n${errors.join('\n')}`);
|
|
90
91
|
}
|
|
91
92
|
if (warnings.length > 0) {
|
|
92
|
-
compilation.warnings.push(new _webpack.WebpackError(
|
|
93
|
+
compilation.warnings.push(...warnings.map((warning)=>new _webpack.WebpackError(warning)));
|
|
93
94
|
}
|
|
94
95
|
}
|
|
95
96
|
});
|
package/dist/cjs/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/plugin.ts"],"sourcesContent":["import { getErrorMessage } from '@metamask/snaps-sdk';\nimport type { PostProcessOptions, SourceMap } from '@metamask/snaps-utils';\nimport {\n checkManifest,\n evalBundle,\n postProcessBundle,\n useTemporaryFile,\n} from '@metamask/snaps-utils';\nimport { assert } from '@metamask/utils';\nimport pathUtils from 'path';\nimport { promisify } from 'util';\nimport type { Compiler } from 'webpack';\nimport { Compilation, WebpackError } from 'webpack';\nimport { RawSource, SourceMapSource } from 'webpack-sources';\n\nconst PLUGIN_NAME = 'SnapsWebpackPlugin';\n\ntype PluginOptions = {\n eval?: boolean;\n manifestPath?: string;\n writeManifest?: boolean;\n};\n\nexport type Options = PluginOptions &\n Omit<PostProcessOptions, 'sourceMap' | 'inputSourceMap'>;\n\nexport default class SnapsWebpackPlugin {\n public readonly options: Partial<Options>;\n\n /**\n * Construct an instance of the plugin.\n *\n * @param options - The post-process options.\n * @param options.stripComments - Whether to strip comments. Defaults to\n * `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.\n * Defaults to `true`.\n */\n constructor(options?: Partial<Options>) {\n this.options = {\n eval: true,\n manifestPath: pathUtils.join(process.cwd(), 'snap.manifest.json'),\n writeManifest: true,\n ...options,\n };\n }\n\n /**\n * Apply the plugin to the Webpack compiler. Hooks into the `processAssets`\n * stage to process the bundle.\n *\n * @param compiler - The Webpack compiler.\n */\n apply(compiler: Compiler) {\n const { devtool } = compiler.options;\n\n compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {\n compilation.hooks.processAssets.tap(\n {\n name: PLUGIN_NAME,\n stage: Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_COMPATIBILITY,\n additionalAssets: true,\n },\n (assets) => {\n Object.keys(assets)\n .filter((assetName) => assetName.endsWith('.js'))\n .forEach((assetName) => {\n const asset = assets[assetName];\n const source = asset.source() as string;\n const sourceMap = asset.map();\n\n try {\n const processed = postProcessBundle(source, {\n ...this.options,\n sourceMap: Boolean(devtool),\n inputSourceMap: devtool\n ? (sourceMap as SourceMap)\n : undefined,\n });\n\n if (processed.warnings.length > 0) {\n
|
|
1
|
+
{"version":3,"sources":["../../src/plugin.ts"],"sourcesContent":["import { getErrorMessage } from '@metamask/snaps-sdk';\nimport type { PostProcessOptions, SourceMap } from '@metamask/snaps-utils';\nimport {\n checkManifest,\n evalBundle,\n postProcessBundle,\n useTemporaryFile,\n} from '@metamask/snaps-utils';\nimport { assert } from '@metamask/utils';\nimport pathUtils from 'path';\nimport { promisify } from 'util';\nimport type { Compiler } from 'webpack';\nimport { Compilation, WebpackError } from 'webpack';\nimport { RawSource, SourceMapSource } from 'webpack-sources';\n\nconst PLUGIN_NAME = 'SnapsWebpackPlugin';\n\ntype PluginOptions = {\n eval?: boolean;\n manifestPath?: string;\n writeManifest?: boolean;\n};\n\nexport type Options = PluginOptions &\n Omit<PostProcessOptions, 'sourceMap' | 'inputSourceMap'>;\n\nexport default class SnapsWebpackPlugin {\n public readonly options: Partial<Options>;\n\n /**\n * Construct an instance of the plugin.\n *\n * @param options - The post-process options.\n * @param options.stripComments - Whether to strip comments. Defaults to\n * `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.\n * Defaults to `true`.\n */\n constructor(options?: Partial<Options>) {\n this.options = {\n eval: true,\n manifestPath: pathUtils.join(process.cwd(), 'snap.manifest.json'),\n writeManifest: true,\n ...options,\n };\n }\n\n /**\n * Apply the plugin to the Webpack compiler. Hooks into the `processAssets`\n * stage to process the bundle.\n *\n * @param compiler - The Webpack compiler.\n */\n apply(compiler: Compiler) {\n const { devtool } = compiler.options;\n\n compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {\n compilation.hooks.processAssets.tap(\n {\n name: PLUGIN_NAME,\n stage: Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_COMPATIBILITY,\n additionalAssets: true,\n },\n (assets) => {\n Object.keys(assets)\n .filter((assetName) => assetName.endsWith('.js'))\n .forEach((assetName) => {\n const asset = assets[assetName];\n const source = asset.source() as string;\n const sourceMap = asset.map();\n\n try {\n const processed = postProcessBundle(source, {\n ...this.options,\n sourceMap: Boolean(devtool),\n inputSourceMap: devtool\n ? (sourceMap as SourceMap)\n : undefined,\n });\n\n if (processed.warnings.length > 0) {\n const webpackErrors = processed.warnings.map(\n (warning) => new WebpackError(warning),\n );\n\n compilation.warnings.push(...webpackErrors);\n }\n\n const replacement = processed.sourceMap\n ? new SourceMapSource(\n processed.code,\n assetName,\n processed.sourceMap,\n source,\n sourceMap as SourceMap,\n )\n : new RawSource(processed.code);\n\n // For some reason the type of `RawSource` is not compatible with\n // Webpack's own `Source`, but works fine when casting it to `any`.\n compilation.updateAsset(assetName, replacement as any);\n } catch (error) {\n compilation.errors.push(\n new WebpackError(getErrorMessage(error)),\n );\n }\n });\n },\n );\n });\n\n compiler.hooks.afterEmit.tapPromise(PLUGIN_NAME, async (compilation) => {\n const file = compilation\n .getAssets()\n .find((asset) => asset.name.endsWith('.js'));\n\n assert(file);\n\n assert(compilation.outputOptions.path);\n const outputPath = compilation.outputOptions.path;\n\n const filePath = pathUtils.join(outputPath, file.name);\n\n const bundleFile = await promisify(\n compiler.outputFileSystem.readFile.bind(compiler.outputFileSystem),\n )(filePath);\n assert(bundleFile);\n\n const bundleContent = bundleFile.toString();\n\n if (this.options.eval) {\n await useTemporaryFile('snaps-bundle.js', bundleContent, (path) =>\n evalBundle(path),\n );\n }\n\n if (this.options.manifestPath) {\n const { errors, warnings } = await checkManifest(\n pathUtils.dirname(this.options.manifestPath),\n this.options.writeManifest,\n bundleContent,\n promisify(\n compiler.outputFileSystem.writeFile.bind(compiler.outputFileSystem),\n ),\n );\n\n if (!this.options.writeManifest && errors.length > 0) {\n throw new Error(\n `Manifest Error: The manifest is invalid.\\n${errors.join('\\n')}`,\n );\n }\n\n if (warnings.length > 0) {\n compilation.warnings.push(\n ...warnings.map((warning) => new WebpackError(warning)),\n );\n }\n }\n });\n }\n}\n"],"names":["SnapsWebpackPlugin","PLUGIN_NAME","apply","compiler","devtool","options","hooks","compilation","tap","processAssets","name","stage","Compilation","PROCESS_ASSETS_STAGE_OPTIMIZE_COMPATIBILITY","additionalAssets","assets","Object","keys","filter","assetName","endsWith","forEach","asset","source","sourceMap","map","processed","postProcessBundle","Boolean","inputSourceMap","undefined","warnings","length","webpackErrors","warning","WebpackError","push","replacement","SourceMapSource","code","RawSource","updateAsset","error","errors","getErrorMessage","afterEmit","tapPromise","file","getAssets","find","assert","outputOptions","path","outputPath","filePath","pathUtils","join","bundleFile","promisify","outputFileSystem","readFile","bind","bundleContent","toString","eval","useTemporaryFile","evalBundle","manifestPath","checkManifest","dirname","writeManifest","writeFile","Error","constructor","process","cwd"],"mappings":";;;;;;;eA0BqBA;;;0BA1BW;4BAOzB;uBACgB;6DACD;sBACI;yBAEgB;gCACC;;;;;;;;;;;;;;;;;;;AAE3C,MAAMC,cAAc;AAWL,MAAMD;IA0BnB;;;;;GAKC,GACDE,MAAMC,QAAkB,EAAE;QACxB,MAAM,EAAEC,OAAO,EAAE,GAAGD,SAASE,OAAO;QAEpCF,SAASG,KAAK,CAACC,WAAW,CAACC,GAAG,CAACP,aAAa,CAACM;YAC3CA,YAAYD,KAAK,CAACG,aAAa,CAACD,GAAG,CACjC;gBACEE,MAAMT;gBACNU,OAAOC,oBAAW,CAACC,2CAA2C;gBAC9DC,kBAAkB;YACpB,GACA,CAACC;gBACCC,OAAOC,IAAI,CAACF,QACTG,MAAM,CAAC,CAACC,YAAcA,UAAUC,QAAQ,CAAC,QACzCC,OAAO,CAAC,CAACF;oBACR,MAAMG,QAAQP,MAAM,CAACI,UAAU;oBAC/B,MAAMI,SAASD,MAAMC,MAAM;oBAC3B,MAAMC,YAAYF,MAAMG,GAAG;oBAE3B,IAAI;wBACF,MAAMC,YAAYC,IAAAA,6BAAiB,EAACJ,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,IAAI,CAAC1D,OAAO,CAAC2D,IAAI,EAAE;gBACrB,MAAMC,IAAAA,4BAAgB,EAAC,mBAAmBH,eAAe,CAACV,OACxDc,IAAAA,sBAAU,EAACd;YAEf;YAEA,IAAI,IAAI,CAAC/C,OAAO,CAAC8D,YAAY,EAAE;gBAC7B,MAAM,EAAExB,MAAM,EAAEZ,QAAQ,EAAE,GAAG,MAAMqC,IAAAA,yBAAa,EAC9Cb,aAAS,CAACc,OAAO,CAAC,IAAI,CAAChE,OAAO,CAAC8D,YAAY,GAC3C,IAAI,CAAC9D,OAAO,CAACiE,aAAa,EAC1BR,eACAJ,IAAAA,eAAS,EACPvD,SAASwD,gBAAgB,CAACY,SAAS,CAACV,IAAI,CAAC1D,SAASwD,gBAAgB;gBAItE,IAAI,CAAC,IAAI,CAACtD,OAAO,CAACiE,aAAa,IAAI3B,OAAOX,MAAM,GAAG,GAAG;oBACpD,MAAM,IAAIwC,MACR,CAAC,0CAA0C,EAAE7B,OAAOa,IAAI,CAAC,MAAM,CAAC;gBAEpE;gBAEA,IAAIzB,SAASC,MAAM,GAAG,GAAG;oBACvBzB,YAAYwB,QAAQ,CAACK,IAAI,IACpBL,SAASN,GAAG,CAAC,CAACS,UAAY,IAAIC,qBAAY,CAACD;gBAElD;YACF;QACF;IACF;IAvIA;;;;;;;;;;;;;GAaC,GACDuC,YAAYpE,OAA0B,CAAE;QAhBxC,uBAAgBA,WAAhB,KAAA;QAiBE,IAAI,CAACA,OAAO,GAAG;YACb2D,MAAM;YACNG,cAAcZ,aAAS,CAACC,IAAI,CAACkB,QAAQC,GAAG,IAAI;YAC5CL,eAAe;YACf,GAAGjE,OAAO;QACZ;IACF;AAmHF"}
|
package/dist/esm/plugin.js
CHANGED
|
@@ -44,7 +44,8 @@ class SnapsWebpackPlugin {
|
|
|
44
44
|
inputSourceMap: devtool ? sourceMap : undefined
|
|
45
45
|
});
|
|
46
46
|
if (processed.warnings.length > 0) {
|
|
47
|
-
|
|
47
|
+
const webpackErrors = processed.warnings.map((warning)=>new WebpackError(warning));
|
|
48
|
+
compilation.warnings.push(...webpackErrors);
|
|
48
49
|
}
|
|
49
50
|
const replacement = processed.sourceMap ? new SourceMapSource(processed.code, assetName, processed.sourceMap, source, sourceMap) : new RawSource(processed.code);
|
|
50
51
|
// For some reason the type of `RawSource` is not compatible with
|
|
@@ -74,7 +75,7 @@ class SnapsWebpackPlugin {
|
|
|
74
75
|
throw new Error(`Manifest Error: The manifest is invalid.\n${errors.join('\n')}`);
|
|
75
76
|
}
|
|
76
77
|
if (warnings.length > 0) {
|
|
77
|
-
compilation.warnings.push(new WebpackError(
|
|
78
|
+
compilation.warnings.push(...warnings.map((warning)=>new WebpackError(warning)));
|
|
78
79
|
}
|
|
79
80
|
}
|
|
80
81
|
});
|
package/dist/esm/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/plugin.ts"],"sourcesContent":["import { getErrorMessage } from '@metamask/snaps-sdk';\nimport type { PostProcessOptions, SourceMap } from '@metamask/snaps-utils';\nimport {\n checkManifest,\n evalBundle,\n postProcessBundle,\n useTemporaryFile,\n} from '@metamask/snaps-utils';\nimport { assert } from '@metamask/utils';\nimport pathUtils from 'path';\nimport { promisify } from 'util';\nimport type { Compiler } from 'webpack';\nimport { Compilation, WebpackError } from 'webpack';\nimport { RawSource, SourceMapSource } from 'webpack-sources';\n\nconst PLUGIN_NAME = 'SnapsWebpackPlugin';\n\ntype PluginOptions = {\n eval?: boolean;\n manifestPath?: string;\n writeManifest?: boolean;\n};\n\nexport type Options = PluginOptions &\n Omit<PostProcessOptions, 'sourceMap' | 'inputSourceMap'>;\n\nexport default class SnapsWebpackPlugin {\n public readonly options: Partial<Options>;\n\n /**\n * Construct an instance of the plugin.\n *\n * @param options - The post-process options.\n * @param options.stripComments - Whether to strip comments. Defaults to\n * `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.\n * Defaults to `true`.\n */\n constructor(options?: Partial<Options>) {\n this.options = {\n eval: true,\n manifestPath: pathUtils.join(process.cwd(), 'snap.manifest.json'),\n writeManifest: true,\n ...options,\n };\n }\n\n /**\n * Apply the plugin to the Webpack compiler. Hooks into the `processAssets`\n * stage to process the bundle.\n *\n * @param compiler - The Webpack compiler.\n */\n apply(compiler: Compiler) {\n const { devtool } = compiler.options;\n\n compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {\n compilation.hooks.processAssets.tap(\n {\n name: PLUGIN_NAME,\n stage: Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_COMPATIBILITY,\n additionalAssets: true,\n },\n (assets) => {\n Object.keys(assets)\n .filter((assetName) => assetName.endsWith('.js'))\n .forEach((assetName) => {\n const asset = assets[assetName];\n const source = asset.source() as string;\n const sourceMap = asset.map();\n\n try {\n const processed = postProcessBundle(source, {\n ...this.options,\n sourceMap: Boolean(devtool),\n inputSourceMap: devtool\n ? (sourceMap as SourceMap)\n : undefined,\n });\n\n if (processed.warnings.length > 0) {\n
|
|
1
|
+
{"version":3,"sources":["../../src/plugin.ts"],"sourcesContent":["import { getErrorMessage } from '@metamask/snaps-sdk';\nimport type { PostProcessOptions, SourceMap } from '@metamask/snaps-utils';\nimport {\n checkManifest,\n evalBundle,\n postProcessBundle,\n useTemporaryFile,\n} from '@metamask/snaps-utils';\nimport { assert } from '@metamask/utils';\nimport pathUtils from 'path';\nimport { promisify } from 'util';\nimport type { Compiler } from 'webpack';\nimport { Compilation, WebpackError } from 'webpack';\nimport { RawSource, SourceMapSource } from 'webpack-sources';\n\nconst PLUGIN_NAME = 'SnapsWebpackPlugin';\n\ntype PluginOptions = {\n eval?: boolean;\n manifestPath?: string;\n writeManifest?: boolean;\n};\n\nexport type Options = PluginOptions &\n Omit<PostProcessOptions, 'sourceMap' | 'inputSourceMap'>;\n\nexport default class SnapsWebpackPlugin {\n public readonly options: Partial<Options>;\n\n /**\n * Construct an instance of the plugin.\n *\n * @param options - The post-process options.\n * @param options.stripComments - Whether to strip comments. Defaults to\n * `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.\n * Defaults to `true`.\n */\n constructor(options?: Partial<Options>) {\n this.options = {\n eval: true,\n manifestPath: pathUtils.join(process.cwd(), 'snap.manifest.json'),\n writeManifest: true,\n ...options,\n };\n }\n\n /**\n * Apply the plugin to the Webpack compiler. Hooks into the `processAssets`\n * stage to process the bundle.\n *\n * @param compiler - The Webpack compiler.\n */\n apply(compiler: Compiler) {\n const { devtool } = compiler.options;\n\n compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {\n compilation.hooks.processAssets.tap(\n {\n name: PLUGIN_NAME,\n stage: Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_COMPATIBILITY,\n additionalAssets: true,\n },\n (assets) => {\n Object.keys(assets)\n .filter((assetName) => assetName.endsWith('.js'))\n .forEach((assetName) => {\n const asset = assets[assetName];\n const source = asset.source() as string;\n const sourceMap = asset.map();\n\n try {\n const processed = postProcessBundle(source, {\n ...this.options,\n sourceMap: Boolean(devtool),\n inputSourceMap: devtool\n ? (sourceMap as SourceMap)\n : undefined,\n });\n\n if (processed.warnings.length > 0) {\n const webpackErrors = processed.warnings.map(\n (warning) => new WebpackError(warning),\n );\n\n compilation.warnings.push(...webpackErrors);\n }\n\n const replacement = processed.sourceMap\n ? new SourceMapSource(\n processed.code,\n assetName,\n processed.sourceMap,\n source,\n sourceMap as SourceMap,\n )\n : new RawSource(processed.code);\n\n // For some reason the type of `RawSource` is not compatible with\n // Webpack's own `Source`, but works fine when casting it to `any`.\n compilation.updateAsset(assetName, replacement as any);\n } catch (error) {\n compilation.errors.push(\n new WebpackError(getErrorMessage(error)),\n );\n }\n });\n },\n );\n });\n\n compiler.hooks.afterEmit.tapPromise(PLUGIN_NAME, async (compilation) => {\n const file = compilation\n .getAssets()\n .find((asset) => asset.name.endsWith('.js'));\n\n assert(file);\n\n assert(compilation.outputOptions.path);\n const outputPath = compilation.outputOptions.path;\n\n const filePath = pathUtils.join(outputPath, file.name);\n\n const bundleFile = await promisify(\n compiler.outputFileSystem.readFile.bind(compiler.outputFileSystem),\n )(filePath);\n assert(bundleFile);\n\n const bundleContent = bundleFile.toString();\n\n if (this.options.eval) {\n await useTemporaryFile('snaps-bundle.js', bundleContent, (path) =>\n evalBundle(path),\n );\n }\n\n if (this.options.manifestPath) {\n const { errors, warnings } = await checkManifest(\n pathUtils.dirname(this.options.manifestPath),\n this.options.writeManifest,\n bundleContent,\n promisify(\n compiler.outputFileSystem.writeFile.bind(compiler.outputFileSystem),\n ),\n );\n\n if (!this.options.writeManifest && errors.length > 0) {\n throw new Error(\n `Manifest Error: The manifest is invalid.\\n${errors.join('\\n')}`,\n );\n }\n\n if (warnings.length > 0) {\n compilation.warnings.push(\n ...warnings.map((warning) => new WebpackError(warning)),\n );\n }\n }\n });\n }\n}\n"],"names":["getErrorMessage","checkManifest","evalBundle","postProcessBundle","useTemporaryFile","assert","pathUtils","promisify","Compilation","WebpackError","RawSource","SourceMapSource","PLUGIN_NAME","SnapsWebpackPlugin","apply","compiler","devtool","options","hooks","compilation","tap","processAssets","name","stage","PROCESS_ASSETS_STAGE_OPTIMIZE_COMPATIBILITY","additionalAssets","assets","Object","keys","filter","assetName","endsWith","forEach","asset","source","sourceMap","map","processed","Boolean","inputSourceMap","undefined","warnings","length","webpackErrors","warning","push","replacement","code","updateAsset","error","errors","afterEmit","tapPromise","file","getAssets","find","outputOptions","path","outputPath","filePath","join","bundleFile","outputFileSystem","readFile","bind","bundleContent","toString","eval","manifestPath","dirname","writeManifest","writeFile","Error","constructor","process","cwd"],"mappings":";;;;;;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C,IAAI,CAAC7C,OAAO,CAACqD,aAAa,IAAIpB,OAAOR,MAAM,GAAG,GAAG;oBACpD,MAAM,IAAI8B,MACR,CAAC,0CAA0C,EAAEtB,OAAOU,IAAI,CAAC,MAAM,CAAC;gBAEpE;gBAEA,IAAInB,SAASC,MAAM,GAAG,GAAG;oBACvBvB,YAAYsB,QAAQ,CAACI,IAAI,IACpBJ,SAASL,GAAG,CAAC,CAACQ,UAAY,IAAInC,aAAamC;gBAElD;YACF;QACF;IACF;IAvIA;;;;;;;;;;;;;GAaC,GACD6B,YAAYxD,OAA0B,CAAE;QAhBxC,uBAAgBA,WAAhB,KAAA;QAiBE,IAAI,CAACA,OAAO,GAAG;YACbkD,MAAM;YACNC,cAAc9D,UAAUsD,IAAI,CAACc,QAAQC,GAAG,IAAI;YAC5CL,eAAe;YACf,GAAGrD,OAAO;QACZ;IACF;AAmHF;AA3IA,SAAqBJ,gCA2IpB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/snaps-webpack-plugin",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"webpack",
|
|
6
6
|
"plugin"
|
|
@@ -39,14 +39,14 @@
|
|
|
39
39
|
"lint:dependencies": "depcheck"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@metamask/snaps-sdk": "^1.
|
|
43
|
-
"@metamask/snaps-utils": "^
|
|
44
|
-
"@metamask/utils": "^8.
|
|
42
|
+
"@metamask/snaps-sdk": "^2.1.0",
|
|
43
|
+
"@metamask/snaps-utils": "^6.1.0",
|
|
44
|
+
"@metamask/utils": "^8.3.0",
|
|
45
45
|
"webpack-sources": "^3.2.3"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@lavamoat/allow-scripts": "^
|
|
49
|
-
"@metamask/auto-changelog": "^3.4.
|
|
48
|
+
"@lavamoat/allow-scripts": "^3.0.2",
|
|
49
|
+
"@metamask/auto-changelog": "^3.4.4",
|
|
50
50
|
"@metamask/eslint-config": "^12.1.0",
|
|
51
51
|
"@metamask/eslint-config-jest": "^12.1.0",
|
|
52
52
|
"@metamask/eslint-config-nodejs": "^12.1.0",
|