@metamask/snaps-cli 6.5.3 → 6.5.4
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 +8 -1
- package/dist/webpack/loaders/wasm.cjs +13 -3
- package/dist/webpack/loaders/wasm.cjs.map +1 -1
- package/dist/webpack/loaders/wasm.d.cts.map +1 -1
- package/dist/webpack/loaders/wasm.d.mts.map +1 -1
- package/dist/webpack/loaders/wasm.mjs +14 -4
- package/dist/webpack/loaders/wasm.mjs.map +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [6.5.4]
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
- Bundle and initialize WASM modules using Base64 encoding ([#2913](https://github.com/MetaMask/snaps/pull/2913))
|
|
15
|
+
|
|
10
16
|
## [6.5.3]
|
|
11
17
|
|
|
12
18
|
### Fixed
|
|
@@ -288,7 +294,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
288
294
|
- The version of the package no longer needs to match the version of all other
|
|
289
295
|
MetaMask Snaps packages.
|
|
290
296
|
|
|
291
|
-
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-cli@6.5.
|
|
297
|
+
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-cli@6.5.4...HEAD
|
|
298
|
+
[6.5.4]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-cli@6.5.3...@metamask/snaps-cli@6.5.4
|
|
292
299
|
[6.5.3]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-cli@6.5.2...@metamask/snaps-cli@6.5.3
|
|
293
300
|
[6.5.2]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-cli@6.5.1...@metamask/snaps-cli@6.5.2
|
|
294
301
|
[6.5.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-cli@6.5.0...@metamask/snaps-cli@6.5.1
|
|
@@ -66,8 +66,7 @@ exports.getExports = getExports;
|
|
|
66
66
|
// `this` to the loader context, and TypeScript can infer the type of `this`.
|
|
67
67
|
const loader = async function loader(source) {
|
|
68
68
|
(0, utils_1.assert)(source instanceof Uint8Array, 'Expected source to be a Uint8Array.');
|
|
69
|
-
const
|
|
70
|
-
const wasmModule = await WebAssembly.compile(bytes);
|
|
69
|
+
const wasmModule = await WebAssembly.compile(source);
|
|
71
70
|
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
72
71
|
const exports = WebAssembly.Module.exports(wasmModule);
|
|
73
72
|
const imports = WebAssembly.Module.imports(wasmModule).reduce((target, descriptor) => {
|
|
@@ -85,7 +84,18 @@ const loader = async function loader(source) {
|
|
|
85
84
|
return `
|
|
86
85
|
${getImports(imports)}
|
|
87
86
|
|
|
88
|
-
const
|
|
87
|
+
const b64 = ${JSON.stringify((0, utils_1.bytesToBase64)(source))};
|
|
88
|
+
|
|
89
|
+
function decode(encoded) {
|
|
90
|
+
const str = atob(encoded);
|
|
91
|
+
const bytes = new Uint8Array(str.length);
|
|
92
|
+
for (let i = 0; i < str.length; i++) {
|
|
93
|
+
bytes[i] = str.charCodeAt(i);
|
|
94
|
+
}
|
|
95
|
+
return bytes;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const bytes = decode(b64);
|
|
89
99
|
const module = new WebAssembly.Module(bytes);
|
|
90
100
|
const instance = new WebAssembly.Instance(module, {
|
|
91
101
|
${getModuleImports(imports)}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wasm.cjs","sourceRoot":"","sources":["../../../src/webpack/loaders/wasm.ts"],"names":[],"mappings":";AAAA,0CAA0C;;;AAE1C,
|
|
1
|
+
{"version":3,"file":"wasm.cjs","sourceRoot":"","sources":["../../../src/webpack/loaders/wasm.ts"],"names":[],"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ricted-globals */\n\nimport { assert, bytesToBase64 } from '@metamask/utils';\nimport { dirname, resolve } from 'path';\nimport type { LoaderDefinitionFunction } from 'webpack';\n\n/**\n * Get the imports code for the WASM module. This code imports each of the\n * imports from the WASM module.\n *\n * @param importMap - The import map for the WASM module.\n * @returns The imports code for the WASM module.\n */\nexport function getImports(importMap: Record<string, string[]>) {\n return Object.entries(importMap)\n .map(\n ([moduleName, exportNames]) =>\n `import { ${exportNames.join(', ')} } from ${JSON.stringify(\n moduleName,\n )};`,\n )\n .join('\\n');\n}\n\n/**\n * Get the imports code to use in `WebAssembly.Instance`. This code adds each of\n * the imports to the `imports` object.\n *\n * @param importMap - The import map for the WASM module.\n * @returns The imports code for the WASM module.\n */\nexport function getModuleImports(importMap: Record<string, string[]>) {\n return Object.entries(importMap)\n .map(\n ([moduleName, exportNames]) =>\n `${JSON.stringify(moduleName)}: { ${exportNames.join(', ')} },`,\n )\n .join('\\n');\n}\n\n/**\n * Get the exports code for the WASM module. This code exports each of the\n * exports from the WASM module as a variable. This function assumes that the\n * exports are available in a variable named `exports`.\n *\n * @param descriptors - The export descriptors from the WASM module.\n * @returns The exports code for the WASM module.\n */\nexport function getExports(descriptors: WebAssembly.ModuleExportDescriptor[]) {\n return descriptors\n .map((descriptor) => {\n if (descriptor.name === 'default') {\n return `export default exports[${JSON.stringify(descriptor.name)}];`;\n }\n\n return `export const ${descriptor.name} = exports[${JSON.stringify(\n descriptor.name,\n )}];`;\n })\n .join('\\n');\n}\n\n/**\n * A Webpack loader that synchronously loads the WASM module. This makes it\n * possible to import the WASM module directly.\n *\n * @param source - The WASM module as `Uint8Array`.\n * @returns The WASM module as a JavaScript string.\n * @example\n * ```ts\n * import * as wasm from './program.wasm';\n *\n * // Do something with the WASM module...\n * ```\n */\n// Note: This function needs to be defined like this, so that Webpack can bind\n// `this` to the loader context, and TypeScript can infer the type of `this`.\nconst loader: LoaderDefinitionFunction = async function loader(\n source: unknown,\n) {\n assert(source instanceof Uint8Array, 'Expected source to be a Uint8Array.');\n\n const wasmModule = await WebAssembly.compile(source);\n\n // eslint-disable-next-line @typescript-eslint/no-shadow\n const exports = WebAssembly.Module.exports(wasmModule);\n const imports = WebAssembly.Module.imports(wasmModule).reduce<\n Record<string, string[]>\n >((target, descriptor) => {\n target[descriptor.module] ??= [];\n target[descriptor.module].push(descriptor.name);\n\n return target;\n }, {});\n\n // Add the WASM import as a dependency so that Webpack will watch it for\n // changes.\n const path = dirname(this.resourcePath);\n for (const name of Object.keys(imports)) {\n this.addDependency(resolve(path, name));\n }\n\n return `\n ${getImports(imports)}\n\n const b64 = ${JSON.stringify(bytesToBase64(source))};\n\n function decode(encoded) {\n const str = atob(encoded);\n const bytes = new Uint8Array(str.length);\n for (let i = 0; i < str.length; i++) {\n bytes[i] = str.charCodeAt(i);\n }\n return bytes;\n }\n\n const bytes = decode(b64);\n const module = new WebAssembly.Module(bytes);\n const instance = new WebAssembly.Instance(module, {\n ${getModuleImports(imports)}\n });\n\n const exports = instance.exports;\n ${getExports(exports)}\n `;\n};\n\nexport default loader;\n\n// By setting `raw` to `true`, we are telling Webpack to provide the source as a\n// `Uint8Array` instead of converting it to a string. This allows us to avoid\n// having to convert the source back to a `Uint8Array` in the loader.\nexport const raw = true;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wasm.d.cts","sourceRoot":"","sources":["../../../src/webpack/loaders/wasm.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,wBAAwB,EAAE,gBAAgB;AAExD;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,UAS7D;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,UAOnE;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,WAAW,EAAE,WAAW,CAAC,sBAAsB,EAAE,UAY3E;AAED;;;;;;;;;;;;GAYG;AAGH,QAAA,MAAM,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"wasm.d.cts","sourceRoot":"","sources":["../../../src/webpack/loaders/wasm.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,wBAAwB,EAAE,gBAAgB;AAExD;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,UAS7D;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,UAOnE;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,WAAW,EAAE,WAAW,CAAC,sBAAsB,EAAE,UAY3E;AAED;;;;;;;;;;;;GAYG;AAGH,QAAA,MAAM,MAAM,EAAE,wBAgDb,CAAC;AAEF,eAAe,MAAM,CAAC;AAKtB,eAAO,MAAM,GAAG,OAAO,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wasm.d.mts","sourceRoot":"","sources":["../../../src/webpack/loaders/wasm.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,wBAAwB,EAAE,gBAAgB;AAExD;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,UAS7D;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,UAOnE;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,WAAW,EAAE,WAAW,CAAC,sBAAsB,EAAE,UAY3E;AAED;;;;;;;;;;;;GAYG;AAGH,QAAA,MAAM,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"wasm.d.mts","sourceRoot":"","sources":["../../../src/webpack/loaders/wasm.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,wBAAwB,EAAE,gBAAgB;AAExD;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,UAS7D;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,UAOnE;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,WAAW,EAAE,WAAW,CAAC,sBAAsB,EAAE,UAY3E;AAED;;;;;;;;;;;;GAYG;AAGH,QAAA,MAAM,MAAM,EAAE,wBAgDb,CAAC;AAEF,eAAe,MAAM,CAAC;AAKtB,eAAO,MAAM,GAAG,OAAO,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* eslint-disable no-restricted-globals */
|
|
2
|
-
import { assert } from "@metamask/utils";
|
|
2
|
+
import { assert, bytesToBase64 } from "@metamask/utils";
|
|
3
3
|
import { dirname, resolve } from "path";
|
|
4
4
|
/**
|
|
5
5
|
* Get the imports code for the WASM module. This code imports each of the
|
|
@@ -60,8 +60,7 @@ export function getExports(descriptors) {
|
|
|
60
60
|
// `this` to the loader context, and TypeScript can infer the type of `this`.
|
|
61
61
|
const loader = async function loader(source) {
|
|
62
62
|
assert(source instanceof Uint8Array, 'Expected source to be a Uint8Array.');
|
|
63
|
-
const
|
|
64
|
-
const wasmModule = await WebAssembly.compile(bytes);
|
|
63
|
+
const wasmModule = await WebAssembly.compile(source);
|
|
65
64
|
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
66
65
|
const exports = WebAssembly.Module.exports(wasmModule);
|
|
67
66
|
const imports = WebAssembly.Module.imports(wasmModule).reduce((target, descriptor) => {
|
|
@@ -79,7 +78,18 @@ const loader = async function loader(source) {
|
|
|
79
78
|
return `
|
|
80
79
|
${getImports(imports)}
|
|
81
80
|
|
|
82
|
-
const
|
|
81
|
+
const b64 = ${JSON.stringify(bytesToBase64(source))};
|
|
82
|
+
|
|
83
|
+
function decode(encoded) {
|
|
84
|
+
const str = atob(encoded);
|
|
85
|
+
const bytes = new Uint8Array(str.length);
|
|
86
|
+
for (let i = 0; i < str.length; i++) {
|
|
87
|
+
bytes[i] = str.charCodeAt(i);
|
|
88
|
+
}
|
|
89
|
+
return bytes;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const bytes = decode(b64);
|
|
83
93
|
const module = new WebAssembly.Module(bytes);
|
|
84
94
|
const instance = new WebAssembly.Instance(module, {
|
|
85
95
|
${getModuleImports(imports)}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wasm.mjs","sourceRoot":"","sources":["../../../src/webpack/loaders/wasm.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAE1C,OAAO,EAAE,MAAM,EAAE,wBAAwB;
|
|
1
|
+
{"version":3,"file":"wasm.mjs","sourceRoot":"","sources":["../../../src/webpack/loaders/wasm.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAE1C,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,wBAAwB;AACxD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,aAAa;AAGxC;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAC,SAAmC;IAC5D,OAAO,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC;SAC7B,GAAG,CACF,CAAC,CAAC,UAAU,EAAE,WAAW,CAAC,EAAE,EAAE,CAC5B,YAAY,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,IAAI,CAAC,SAAS,CACzD,UAAU,CACX,GAAG,CACP;SACA,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAC,SAAmC;IAClE,OAAO,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC;SAC7B,GAAG,CACF,CAAC,CAAC,UAAU,EAAE,WAAW,CAAC,EAAE,EAAE,CAC5B,GAAG,IAA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EAAE,CAAC,CAAC;IAEP,wEAAwE;IACxE,WAAW;IACX,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACxC,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QACxC,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;IAC1C,CAAC;IAED,OAAO;MACH,UAAU,CAAC,OAAO,CAAC;;kBAEP,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;;;;;;;;;;;;;;QAc/C,gBAAgB,CAAC,OAAO,CAAC;;;;MAI3B,UAAU,CAAC,OAAO,CAAC;GACtB,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,MAAM,CAAC;AAEtB,gFAAgF;AAChF,6EAA6E;AAC7E,qEAAqE;AACrE,MAAM,CAAC,MAAM,GAAG,GAAG,IAAI,CAAC","sourcesContent":["/* eslint-disable no-restricted-globals */\n\nimport { assert, bytesToBase64 } from '@metamask/utils';\nimport { dirname, resolve } from 'path';\nimport type { LoaderDefinitionFunction } from 'webpack';\n\n/**\n * Get the imports code for the WASM module. This code imports each of the\n * imports from the WASM module.\n *\n * @param importMap - The import map for the WASM module.\n * @returns The imports code for the WASM module.\n */\nexport function getImports(importMap: Record<string, string[]>) {\n return Object.entries(importMap)\n .map(\n ([moduleName, exportNames]) =>\n `import { ${exportNames.join(', ')} } from ${JSON.stringify(\n moduleName,\n )};`,\n )\n .join('\\n');\n}\n\n/**\n * Get the imports code to use in `WebAssembly.Instance`. This code adds each of\n * the imports to the `imports` object.\n *\n * @param importMap - The import map for the WASM module.\n * @returns The imports code for the WASM module.\n */\nexport function getModuleImports(importMap: Record<string, string[]>) {\n return Object.entries(importMap)\n .map(\n ([moduleName, exportNames]) =>\n `${JSON.stringify(moduleName)}: { ${exportNames.join(', ')} },`,\n )\n .join('\\n');\n}\n\n/**\n * Get the exports code for the WASM module. This code exports each of the\n * exports from the WASM module as a variable. This function assumes that the\n * exports are available in a variable named `exports`.\n *\n * @param descriptors - The export descriptors from the WASM module.\n * @returns The exports code for the WASM module.\n */\nexport function getExports(descriptors: WebAssembly.ModuleExportDescriptor[]) {\n return descriptors\n .map((descriptor) => {\n if (descriptor.name === 'default') {\n return `export default exports[${JSON.stringify(descriptor.name)}];`;\n }\n\n return `export const ${descriptor.name} = exports[${JSON.stringify(\n descriptor.name,\n )}];`;\n })\n .join('\\n');\n}\n\n/**\n * A Webpack loader that synchronously loads the WASM module. This makes it\n * possible to import the WASM module directly.\n *\n * @param source - The WASM module as `Uint8Array`.\n * @returns The WASM module as a JavaScript string.\n * @example\n * ```ts\n * import * as wasm from './program.wasm';\n *\n * // Do something with the WASM module...\n * ```\n */\n// Note: This function needs to be defined like this, so that Webpack can bind\n// `this` to the loader context, and TypeScript can infer the type of `this`.\nconst loader: LoaderDefinitionFunction = async function loader(\n source: unknown,\n) {\n assert(source instanceof Uint8Array, 'Expected source to be a Uint8Array.');\n\n const wasmModule = await WebAssembly.compile(source);\n\n // eslint-disable-next-line @typescript-eslint/no-shadow\n const exports = WebAssembly.Module.exports(wasmModule);\n const imports = WebAssembly.Module.imports(wasmModule).reduce<\n Record<string, string[]>\n >((target, descriptor) => {\n target[descriptor.module] ??= [];\n target[descriptor.module].push(descriptor.name);\n\n return target;\n }, {});\n\n // Add the WASM import as a dependency so that Webpack will watch it for\n // changes.\n const path = dirname(this.resourcePath);\n for (const name of Object.keys(imports)) {\n this.addDependency(resolve(path, name));\n }\n\n return `\n ${getImports(imports)}\n\n const b64 = ${JSON.stringify(bytesToBase64(source))};\n\n function decode(encoded) {\n const str = atob(encoded);\n const bytes = new Uint8Array(str.length);\n for (let i = 0; i < str.length; i++) {\n bytes[i] = str.charCodeAt(i);\n }\n return bytes;\n }\n\n const bytes = decode(b64);\n const module = new WebAssembly.Module(bytes);\n const instance = new WebAssembly.Instance(module, {\n ${getModuleImports(imports)}\n });\n\n const exports = instance.exports;\n ${getExports(exports)}\n `;\n};\n\nexport default loader;\n\n// By setting `raw` to `true`, we are telling Webpack to provide the source as a\n// `Uint8Array` instead of converting it to a string. This allows us to avoid\n// having to convert the source back to a `Uint8Array` in the loader.\nexport const raw = true;\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/snaps-cli",
|
|
3
|
-
"version": "6.5.
|
|
3
|
+
"version": "6.5.4",
|
|
4
4
|
"description": "A CLI for developing MetaMask Snaps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -72,8 +72,8 @@
|
|
|
72
72
|
"@babel/plugin-transform-runtime": "^7.13.2",
|
|
73
73
|
"@babel/preset-env": "^7.23.2",
|
|
74
74
|
"@babel/preset-typescript": "^7.23.2",
|
|
75
|
-
"@metamask/snaps-sdk": "^6.
|
|
76
|
-
"@metamask/snaps-utils": "^8.6.
|
|
75
|
+
"@metamask/snaps-sdk": "^6.13.0",
|
|
76
|
+
"@metamask/snaps-utils": "^8.6.1",
|
|
77
77
|
"@metamask/snaps-webpack-plugin": "^4.1.2",
|
|
78
78
|
"@metamask/superstruct": "^3.1.0",
|
|
79
79
|
"@metamask/utils": "^10.0.0",
|
|
@@ -123,7 +123,7 @@
|
|
|
123
123
|
"@metamask/eslint-config-nodejs": "^12.1.0",
|
|
124
124
|
"@metamask/eslint-config-typescript": "^12.1.0",
|
|
125
125
|
"@swc/jest": "^0.2.26",
|
|
126
|
-
"@ts-bridge/cli": "^0.6.
|
|
126
|
+
"@ts-bridge/cli": "^0.6.1",
|
|
127
127
|
"@types/browserify": "^12.0.37",
|
|
128
128
|
"@types/jest": "^27.5.1",
|
|
129
129
|
"@types/node": "18.14.2",
|