Skip to content

Commit

Permalink
feat(swingset-vat): Thread module format through loadBasedir, swingse…
Browse files Browse the repository at this point in the history
…t config
  • Loading branch information
kriskowal committed Sep 10, 2021
1 parent f55982f commit b243889
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
32 changes: 24 additions & 8 deletions packages/SwingSet/src/initializeSwingset.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -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: {
Expand All @@ -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 });
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -284,7 +295,9 @@ export async function initializeSwingset(
}

const {
kernelBundles = await buildKernelBundles(),
kernelBundles = await buildKernelBundles({
bundleFormat: config.bundleFormat,
}),
verbose,
} = initializationOptions;

Expand Down Expand Up @@ -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);
Expand Down
11 changes: 9 additions & 2 deletions packages/SwingSet/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

// import '@agoric/marshal/src/types.js';

/**
* @typedef {'getExport' | 'nestedEvaluate' | 'endoZipBase64'} BundleFormat
*/

/**
* @typedef {CapData<string>} SwingSetCapData
*/
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit b243889

Please sign in to comment.