From b243889d2f5e7c3c279373943b593cf9773c6366 Mon Sep 17 00:00:00 2001 From: Kris Kowal Date: Mon, 16 Aug 2021 15:50:35 -0700 Subject: [PATCH] feat(swingset-vat): Thread module format through loadBasedir, swingset config --- packages/SwingSet/src/initializeSwingset.js | 32 ++++++++++++++----- packages/SwingSet/src/types.js | 11 +++++-- .../sharingService/test-sharing.js | 2 +- 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/packages/SwingSet/src/initializeSwingset.js b/packages/SwingSet/src/initializeSwingset.js index 83491bd8717..8f5e088a208 100644 --- a/packages/SwingSet/src/initializeSwingset.js +++ b/packages/SwingSet/src/initializeSwingset.js @@ -30,13 +30,23 @@ const allValues = async obj => /** * Build the source bundles for the kernel and xsnap vat worker. + * + * @param {Object} [options] + * @param {ModuleFormat} [options.bundleFormat] */ -export async function buildKernelBundles() { +export async function buildKernelBundles(options = {}) { // this takes 2.7s on my computer - const src = rel => bundleSource(new URL(rel, import.meta.url).pathname); + const { bundleFormat = undefined } = options; + + const src = rel => + bundleSource(new URL(rel, import.meta.url).pathname, { + format: bundleFormat, + }); const srcGE = rel => - bundleSource(new URL(rel, import.meta.url).pathname, 'getExport'); + bundleSource(new URL(rel, import.meta.url).pathname, { + format: 'getExport', + }); const bundles = await allValues({ kernel: src('./kernel/kernel.js'), @@ -71,7 +81,8 @@ function byName(a, b) { * * @param {string} basedir The directory to scan * @param {Object} [options] - * @param {boolean} [options.dev] whether to include devDependencies + * @param {boolean} [options.includeDevDependencies] whether to include devDependencies + * @param {ModuleFormat} [options.bundleFormat] the bundle format to use * @returns {SwingSetConfig} a swingset config object: { * bootstrap: "bootstrap", * vats: { @@ -89,7 +100,7 @@ function byName(a, b) { * Swingsets defined by scanning a directory in this manner define no devices. */ export function loadBasedir(basedir, options = {}) { - const { dev = false } = options; + const { includeDevDependencies = false, bundleFormat = undefined } = options; /** @type { SwingSetConfigDescriptor } */ const vats = {}; const subs = fs.readdirSync(basedir, { withFileTypes: true }); @@ -122,7 +133,7 @@ export function loadBasedir(basedir, options = {}) { // scanning thing is something we decide we want to have long term. bootstrapPath = undefined; } - const config = { vats, dev }; + const config = { vats, includeDevDependencies, format: bundleFormat }; if (bootstrapPath) { vats.bootstrap = { sourceSpec: bootstrapPath, @@ -284,7 +295,9 @@ export async function initializeSwingset( } const { - kernelBundles = await buildKernelBundles(), + kernelBundles = await buildKernelBundles({ + bundleFormat: config.bundleFormat, + }), verbose, } = initializationOptions; @@ -388,7 +401,10 @@ export async function initializeSwingset( if (desc.sourceSpec) { names.push(name); presumptiveBundles.push( - bundleSource(desc.sourceSpec, { dev: config.dev }), + bundleSource(desc.sourceSpec, { + dev: config.includeDevDependencies, + format: config.bundleFormat, + }), ); } else if (desc.bundleSpec) { names.push(name); diff --git a/packages/SwingSet/src/types.js b/packages/SwingSet/src/types.js index 24862413e52..01fd6938279 100644 --- a/packages/SwingSet/src/types.js +++ b/packages/SwingSet/src/types.js @@ -2,6 +2,10 @@ // import '@agoric/marshal/src/types.js'; +/** + * @typedef {'getExport' | 'nestedEvaluate' | 'endoZipBase64'} BundleFormat + */ + /** * @typedef {CapData} SwingSetCapData */ @@ -163,11 +167,14 @@ /** * @typedef {Object} SwingSetConfig a swingset config object * @property {string} [bootstrap] - * @property {boolean} [dev] indicates that `devDependencies` of the - * surrounding `package.json` should be accessible to bundles. + * @property {boolean} [includeDevDependencies] indicates that + * `devDependencies` of the surrounding `package.json` should be accessible to + * bundles. * @property { ManagerType } [defaultManagerType] * @property {SwingSetConfigDescriptor} [vats] * @property {SwingSetConfigDescriptor} [bundles] + * @property {BundleFormat} [bundleFormat] the bundle source / import bundle + * format. * @property {*} [devices] * * Swingsets defined by scanning a directory in this manner define no devices. diff --git a/packages/sharing-service/test/swingsetTests/sharingService/test-sharing.js b/packages/sharing-service/test/swingsetTests/sharingService/test-sharing.js index b2f65490eb4..891457439d4 100644 --- a/packages/sharing-service/test/swingsetTests/sharingService/test-sharing.js +++ b/packages/sharing-service/test/swingsetTests/sharingService/test-sharing.js @@ -10,7 +10,7 @@ const dirname = path.dirname(filename); async function main(basedir, argv) { const dir = path.resolve(`${dirname}/..`, basedir); - const config = await loadBasedir(dir, { dev: true }); + const config = await loadBasedir(dir, { includeDevDependencies: true }); config.defaultManagerType = 'xs-worker'; const controller = await buildVatController(config, argv); await controller.run();