Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tweak configs, await export and try async WASM compilation
Browse files Browse the repository at this point in the history
FrederikBolding committed Dec 9, 2024
1 parent 8cc5278 commit 4a4733c
Showing 32 changed files with 39 additions and 48 deletions.
2 changes: 1 addition & 1 deletion packages/examples/packages/bip32/snap.manifest.json
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "hRuh420QB8uksiS3rFwrvqNoQD5XTH/QyWkhFkmNBD8=",
"shasum": "dWCQ3BjoAmv1KlzbrNPRa4QlB3qSHQKL6ONaV0mo7b0=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
2 changes: 1 addition & 1 deletion packages/examples/packages/bip44/snap.manifest.json
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "kztNgPuBct9iJIGhWZs2i/yluGPJSQi0xl5+00opVGs=",
"shasum": "dqWYaxXKggEChwefUCTvipvNzQ+0KbaT6x8vRDW0miw=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "U1D6XbPDJ3m50P5jpjrEKh18nmCtNsAu0Th4sgqMqPk=",
"shasum": "2apoRqY/ywA9P7gcTYwLsbxYFp8Tb7aNmT2bADL/13o=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
2 changes: 1 addition & 1 deletion packages/examples/packages/cronjobs/snap.manifest.json
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "ZjF3VIQyyZMjs7bCHZHcBqkkM4mxQjAHhxURv3bNdIg=",
"shasum": "8bB9qcVDzKQyefr78Cm03aTbojKKg5jQ4nkzZUccKhs=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
2 changes: 1 addition & 1 deletion packages/examples/packages/dialogs/snap.manifest.json
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "Mo4tLj3FLGjTrODhiznPVbTmqLdghRqKWaAEhPUmBmg=",
"shasum": "uZhYG9+3b1yA/94e0QhCJycqrPA96cBQyP+2plF0SEg=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
2 changes: 1 addition & 1 deletion packages/examples/packages/errors/snap.manifest.json
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "yBkP0yx/0fYCe3r3hglrIJJAXuxTgMpCsR0HMJ/KV7o=",
"shasum": "nBAHoKcN5GNzCeKU2UdH+/8auyBBq6z3NxRbcTSuKj4=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "jb8yEH2CbYso7JvLwI2hxARfkiq1IXhGMJcD6xpGPrs=",
"shasum": "cFhK3nsekRxmXeas/P58bEzMVeLhbtp+ZeCDQ5LTtSs=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
2 changes: 1 addition & 1 deletion packages/examples/packages/ethers-js/snap.manifest.json
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "kgnGTfsOQs26Kb8oopMnEvXPmbOeDqy0BllLa9z5GCM=",
"shasum": "uVLwzYliwDATW6CiqATb1FyPgyagNs+3ini7QA+0okc=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
2 changes: 1 addition & 1 deletion packages/examples/packages/file-upload/snap.manifest.json
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "OeWGq3s0Anzwjj9wjWBtQQ+M2ArnYyo7iiJVb5I4NWg=",
"shasum": "14D89bvKXu2AM/k7XG9b7LhSxbf4mJq+8xdfpAAFXE8=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
2 changes: 1 addition & 1 deletion packages/examples/packages/get-entropy/snap.manifest.json
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "i70snr3mPw7knx20YaN64bYsJjEgaqNNDl01oFi4Bo4=",
"shasum": "1jPm8koZvt+Tme7DCtogqKfS+fR4SJnPU7N8r85ku1Y=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
2 changes: 1 addition & 1 deletion packages/examples/packages/get-file/snap.manifest.json
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "IHFTR7r/ZFrWGriDCjtG4cIh1TnQ/DOJ9/7XvzBnaXA=",
"shasum": "xJ6zVUIFqDUR04wPM54X1H64TBQnJ5TWD1wol4ggBz0=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
2 changes: 1 addition & 1 deletion packages/examples/packages/home-page/snap.manifest.json
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "emnlXHvrhsGBMi/y1IPhiQPX9ogHmjmOU/iujBu5GB8=",
"shasum": "NyUuomb1PK2tdiQmOZyT0C+vugl6CamwZ6iS86tREHE=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
2 changes: 1 addition & 1 deletion packages/examples/packages/images/snap.manifest.json
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "KJTZWGggYaU8C3LnOd9CodSJoIMtvzkNKC5bzfMPg4M=",
"shasum": "PWtPR8sJIxj/6B8eLRvGjndi5udmdlWu6eKP4QWFOXg=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "tjpxfy8rDCt+Qfl9RH+E+58FgwnkyN6WNHac2BzGH8A=",
"shasum": "il7JIqsKAL7HdA9TDvZ3uaZ2DmhrvG3/06VlWLZqY3I=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "HICk/M3ngw+6Vc+5PD1z97BZ0+hIIb0OhZMB1gNlA3g=",
"shasum": "McFa4RUs1FqKkxa/srAwgV/6zph9wvinW1vfD8u/OA8=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "g0lygIry0x1ULrACMgFTncUXfstO2l+7iM7/D65BXqY=",
"shasum": "QPxHqRPygXB1Z6M4XreZtw/im8wCEBJgEtLdkOtwob8=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
2 changes: 1 addition & 1 deletion packages/examples/packages/json-rpc/snap.manifest.json
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "fnBcv6jDxgrg7eGcfSt877oYlchyk3LOvWHXUarlMmM=",
"shasum": "mZmPwOndC6aSHcjT6+N6qNxtwBpXA88fE2+T7jg3/GA=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
2 changes: 1 addition & 1 deletion packages/examples/packages/jsx/snap.manifest.json
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "pwOggutOjvi9JIOQUsz3PtcWuIVeq88V8sM4H2Be+QE=",
"shasum": "s8bOADHqPUfTvQpQHBYauAnOLB9OUEVADsYyTUWJFMo=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "U+ry3tQOBH2gb+WQYNBYTqKst27YLCCNPNrL3mzwxY8=",
"shasum": "lFAmVlA2xtorYkfuEClJwiSdLKvEvVx8bWDb3FaKdi4=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
2 changes: 1 addition & 1 deletion packages/examples/packages/localization/snap.manifest.json
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "Riel+Ad0p0CyhwwLM52UgkSx6BORsIoK3N6g5f/3Epw=",
"shasum": "Z1wvLAfqLXOmsioIaOk0nUIvWydYKYL99EICJOMY1Cg=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
2 changes: 1 addition & 1 deletion packages/examples/packages/manage-state/snap.manifest.json
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "qPBUmh7sDOnakV5nawQSF5g4Z3Oq9SA0S7md02dV4NE=",
"shasum": "4F+GzRueJNZ90SaB6GnKyBFD2C3rGD3ZtEiHg+sEgcI=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
2 changes: 1 addition & 1 deletion packages/examples/packages/name-lookup/snap.manifest.json
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "xk7O5itVsuV3Dfldq3rI3WgggHa3z7HX7e17jzheE8w=",
"shasum": "pC2NRrOhYv4sUS7Vkx5As0A5F1rqcQwCWwnijZqCqSc=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "TTxdWj886/layHpYcL7oQMNqjur7dKuCGwQqoCwIZ+E=",
"shasum": "nRsZQCtNSsaFiu3rzF/ymnflq7ZQQwwm/KnQTBzwav4=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
2 changes: 1 addition & 1 deletion packages/examples/packages/preinstalled/snap.manifest.json
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "KbOfXRukEkbyCkPhl4rONcCB3Ih1YXLJK+2QV/WoKHE=",
"shasum": "adwoj6L+hZGsdmCh0Y/obHY00nAXHBoduUo9Gwtm+HE=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
2 changes: 1 addition & 1 deletion packages/examples/packages/send-flow/snap.manifest.json
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "0oqDk8ELSuPUKhZ1e9kqw42QXW+hNMUtYIgThYsN0hk=",
"shasum": "eiwEi6JZTZnPkriRaoiuFQX37mSHsdJEzO5MDZJGqOg=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "hlMIB9kls/72D0A77vdvIkZEbJNUDj3Py9PIxm7aWOM=",
"shasum": "W7760+wNYB7ikWVHQeEx5IRAt+Q07Cq4zaYwmfCEqr8=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "oKKYF+AERJAyRBABHRf4nsfQ6IrhKele+Fei+JXxGzA=",
"shasum": "FxEMWKtdMuijdmu4neAmXosp1zIiuvwzngv7U6t9eC4=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
2 changes: 1 addition & 1 deletion packages/examples/packages/wasm/snap.manifest.json
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "t4uK/pnTJODpftadTGKumNIEqmSCTP0zb87aMLMqFt8=",
"shasum": "n/JVqBQfO2/1ojbBN1WFNddejGlTvGduO9VgxYGYQQg=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
16 changes: 3 additions & 13 deletions packages/snaps-cli/src/webpack/config.ts
Original file line number Diff line number Diff line change
@@ -166,8 +166,8 @@ export async function getDefaultConfiguration(
*
* @see https://webpack.js.org/configuration/output/#outputlibrarytarget
*/
type: 'global',
name: 'exports',
type: 'assign',
name: 'module.exports',
},

/**
@@ -178,7 +178,7 @@ export async function getDefaultConfiguration(
*
* @see https://webpack.js.org/configuration/output/#outputchunkformat
*/
chunkFormat: 'module',
chunkFormat: 'commonjs',
},

/**
@@ -380,16 +380,6 @@ export async function getDefaultConfiguration(
],
},

/**
* The experiments configuration. This configures which Webpack
* experiments to enable/disable.
*
* @see https://webpack.js.org/configuration/experiments
*/
experiments: {
outputModule: true,
},

/**
* The performance configuration. This tells Webpack how to handle
* performance hints.
2 changes: 1 addition & 1 deletion packages/snaps-cli/src/webpack/loaders/wasm.ts
Original file line number Diff line number Diff line change
@@ -115,7 +115,7 @@ const loader: LoaderDefinitionFunction = async function loader(
}
const bytes = decode(b64);
const module = new WebAssembly.Module(bytes);
const module = await WebAssembly.compile(bytes);
const instance = new WebAssembly.Instance(module, {
${getModuleImports(imports)}
});
4 changes: 2 additions & 2 deletions packages/snaps-execution-environments/coverage.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"branches": 80.55,
"functions": 89.26,
"lines": 90.66,
"statements": 90.05
"lines": 90.67,
"statements": 90.06
}
Original file line number Diff line number Diff line change
@@ -418,8 +418,7 @@ export class BaseSnapExecutor {

await this.executeInSnapContext(snapId, async () => {
compartment.evaluate(sourceCode);
await snapModule.exports;
this.registerSnapExports(snapId, snapModule);
await this.registerSnapExports(snapId, snapModule);
});
} catch (error) {
this.removeSnap(snapId);
@@ -448,15 +447,17 @@ export class BaseSnapExecutor {
this.snapData.clear();
}

private registerSnapExports(snapId: string, snapModule: any) {
private async registerSnapExports(snapId: string, snapModule: any) {
const data = this.snapData.get(snapId);
// Somebody deleted the snap before we could register.
if (!data) {
return;
}

// If the module is async, we must await the exports.
const snapExports = await snapModule.exports;
data.exports = SNAP_EXPORT_NAMES.reduce((acc, exportName) => {
const snapExport = snapModule.exports[exportName];
const snapExport = snapExports[exportName];
const { validator } = SNAP_EXPORTS[exportName];
if (validator(snapExport)) {
return { ...acc, [exportName]: snapExport };

0 comments on commit 4a4733c

Please sign in to comment.