@metamask/snaps-utils
Version:
A collection of utilities for MetaMask Snaps
42 lines • 1.8 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore - TypeScript complains about this being ESM in a CJS file, but
// `ses/lockdown` has a CommonJS entry point.
// eslint-disable-next-line import-x/no-unassigned-import
require("ses/lockdown");
const fs_1 = require("fs");
const handlers_1 = require("./handlers/index.cjs");
const mock_1 = require("./mock.cjs");
lockdown({
consoleTaming: 'unsafe',
errorTaming: 'unsafe',
mathTaming: 'unsafe',
dateTaming: 'unsafe',
overrideTaming: 'severe',
// We disable domain taming, because it does not work in certain cases when
// running tests. This is unlikely to be a problem in production, because
// Node.js domains are deprecated.
domainTaming: 'unsafe',
});
const snapFilePath = process.argv[2];
const snapModule = { exports: {} };
const compartment = new Compartment({
...(0, mock_1.generateMockEndowments)(),
module: snapModule,
exports: snapModule.exports,
});
// Mirror BaseSnapExecutor
compartment.globalThis.self = compartment.globalThis;
compartment.globalThis.global = compartment.globalThis;
compartment.globalThis.window = compartment.globalThis;
compartment.evaluate((0, fs_1.readFileSync)(snapFilePath, 'utf8'));
const invalidExports = Object.keys(snapModule.exports).filter((snapExport) => !handlers_1.SNAP_EXPORT_NAMES.includes(snapExport));
if (invalidExports.length > 0) {
// eslint-disable-next-line no-console
console.warn(`Invalid snap exports detected:\n${invalidExports.join('\n')}`);
}
// To ensure the worker exits we explicitly call exit here
// If we didn't the eval would wait for timers set during Compartment eval
process.exit(0);
//# sourceMappingURL=eval-worker.cjs.map