Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(spawner): Converts RESM to NESM #3643

Merged
merged 2 commits into from
Aug 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/spawner/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ source retrieval, issuers, invitations, or seats). These callers now do
something like:

```js
const bundle = await bundleSource(pathResolve(__dirname, './src/wallet.js'));
const bundlePath = new URL('src/wallet.js', import.meta.url).pathname;
const bundle = await bundleSource(bundlePath);
const walletInstall = E(spawner).install(bundle);
const walletVat = await E(walletInstall).spawn(args);
```
Expand Down
14 changes: 5 additions & 9 deletions packages/spawner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@
"name": "@agoric/spawner",
"version": "0.4.23",
"description": "Wrapper for JavaScript map",
"parsers": {
"js": "mjs"
},
"main": "src/contractHost.js",
"type": "module",
"main": "./src/contractHost.js",
"engines": {
"node": ">=11.0"
},
"scripts": {
"build": "yarn build-bundle-spawn",
"build-bundle-spawn": "node -r esm scripts/build-bundle-spawn.js",
"build-bundle-spawn": "node scripts/build-bundle-spawn.js",
"test": "ava",
"test:c8": "c8 $C8_OPTIONS ava --config=ava-nesm.config.js",
"test:xs": "exit 0",
"lint-check": "yarn lint",
"lint-fix": "eslint --fix '**/*.js'",
Expand Down Expand Up @@ -43,7 +42,7 @@
"@agoric/install-ses": "^0.5.21",
"@agoric/swingset-vat": "^0.19.0",
"ava": "^3.12.1",
"esm": "agoric-labs/esm#Agoric-built"
"c8": "^7.7.2"
},
"files": [
"src/",
Expand All @@ -68,9 +67,6 @@
"files": [
"test/**/test-*.js"
],
"require": [
"esm"
],
"timeout": "2m"
}
}
12 changes: 7 additions & 5 deletions packages/spawner/scripts/build-bundle-spawn.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
/* global __dirname */

// eslint-disable-next-line import/no-extraneous-dependencies
import 'ses';
import fs from 'fs';
import path from 'path';
import process from 'process';
import bundleSource from '@agoric/bundle-source';

const filename = new URL(import.meta.url).pathname;
const dirname = path.dirname(filename);

async function writeSourceBundle(contractFilename, outputPath) {
await bundleSource(contractFilename).then(bundle => {
fs.mkdirSync(`${__dirname}/../bundles`, { recursive: true });
fs.mkdirSync(`${dirname}/../bundles`, { recursive: true });
fs.writeFileSync(outputPath, `export default ${JSON.stringify(bundle)};`);
});
}

async function main() {
const contractFilename = `${__dirname}/../src/vat-spawned.js`;
const outputPath = `${__dirname}/../bundles/bundle-spawn.js`;
const contractFilename = `${dirname}/../src/vat-spawned.js`;
const outputPath = `${dirname}/../bundles/bundle-spawn.js`;
await writeSourceBundle(contractFilename, outputPath);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* global __dirname */
// eslint-disable-next-line import/order
import { test } from '@agoric/swingset-vat/tools/prepare-test-env-ava.js';
// eslint-disable-next-line import/order
Expand All @@ -10,15 +9,18 @@ import {
loadBasedir,
} from '@agoric/swingset-vat';

const filename = new URL(import.meta.url).pathname;
const dirname = path.dirname(filename);

test.before(async t => {
const kernelBundles = await buildKernelBundles();
const trivialFn = path.resolve(__dirname, 'trivial.js');
const trivialFn = path.resolve(dirname, 'trivial.js');
const trivialBundle = await bundleSource(trivialFn);
t.context.data = { kernelBundles, trivialBundle };
});

async function main(t, mode) {
const config = await loadBasedir(__dirname);
const config = await loadBasedir(dirname);
config.defaultManagerType = 'xs-worker';
const { kernelBundles, trivialBundle } = t.context.data;
const argv = [mode, trivialBundle];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (C) 2018 Agoric, under Apache License 2.0
import { Far } from '@agoric/marshal';
import { makeSpawner } from '../../../src/contractHost';
import { makeSpawner } from '../../../src/contractHost.js';

function buildRootObject() {
return Far('root', {
Expand Down