Skip to content

Commit

Permalink
refactor(solo): Convert RESM to NESM
Browse files Browse the repository at this point in the history
Refs #527
  • Loading branch information
kriskowal committed Aug 11, 2021
1 parent da0d7a2 commit 55fe336
Show file tree
Hide file tree
Showing 14 changed files with 60 additions and 59 deletions.
2 changes: 0 additions & 2 deletions packages/solo/bin/ag-solo

This file was deleted.

1 change: 1 addition & 0 deletions packages/solo/bin/ag-solo
11 changes: 3 additions & 8 deletions packages/solo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
"name": "@agoric/solo",
"version": "0.2.12",
"description": "Agoric's Solo vat runner",
"parsers": {
"js": "mjs"
},
"type": "module",
"bin": {
"ag-solo": "src/entrypoint.cjs"
"ag-solo": "src/entrypoint.js"
},
"main": "src/main.js",
"repository": "https://github.com/Agoric/agoric-sdk",
Expand Down Expand Up @@ -46,8 +44,8 @@
"@agoric/xsnap": "^0.6.10",
"anylogger": "^0.21.0",
"deterministic-json": "^1.0.5",
"esm": "agoric-labs/esm#Agoric-built",
"express": "^4.17.1",
"import-meta-resolve": "^1.1.1",
"minimist": "^1.2.0",
"morgan": "^1.9.1",
"node-fetch": "^2.6.0",
Expand Down Expand Up @@ -79,9 +77,6 @@
"files": [
"test/**/test-*.js"
],
"require": [
"esm"
],
"timeout": "20m"
}
}
2 changes: 1 addition & 1 deletion packages/solo/src/add-chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import path from 'path';
import fs from 'fs';

import { assert, details as X } from '@agoric/assert';
import setGCIIngress from './set-gci-ingress';
import setGCIIngress from './set-gci-ingress.js';

const DEFAULT_CHAIN_CONFIG = 'https://testnet.agoric.com/network-config';

Expand Down
2 changes: 1 addition & 1 deletion packages/solo/src/chain-cosmos-sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { assert, details as X } from '@agoric/assert';
import {
DEFAULT_BATCH_TIMEOUT_MS,
makeBatchedDeliver,
} from '@agoric/vats/src/batched-deliver';
} from '@agoric/vats/src/batched-deliver.js';

const console = anylogger('chain-cosmos-sdk');

Expand Down
3 changes: 0 additions & 3 deletions packages/solo/src/entrypoint.cjs

This file was deleted.

12 changes: 7 additions & 5 deletions packages/solo/src/init-basedir.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global __dirname Buffer process */
/* global Buffer process */
import fs from 'fs';
import path from 'path';
import { execFileSync } from 'child_process';
Expand All @@ -10,6 +10,9 @@ const log = anylogger('ag-solo:init');

const DEFAULT_WALLET = '@agoric/dapp-svelte-wallet';

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

export default function initBasedir(
basedir,
webport,
Expand All @@ -27,7 +30,6 @@ export default function initBasedir(
options.wallet = wallet;
options.defaultManagerType = defaultManagerType;

const here = __dirname;
// We either need a basedir with an initialised key, or no basedir.
assert(
fs.existsSync(path.join(basedir, 'ag-cosmos-helper-address')) ||
Expand All @@ -50,11 +52,11 @@ export default function initBasedir(

// Save our version codes.
const pj = 'package.json';
fs.copyFileSync(path.join(here, '..', pj), path.join(dstHtmldir, pj));
fs.copyFileSync(path.join(dirname, '..', pj), path.join(dstHtmldir, pj));
const gr = 'git-revision.txt';
try {
fs.copyFileSync(
path.join(here, '../public', gr),
path.join(dirname, '../public', gr),
path.join(dstHtmldir, gr),
);
} catch (e) {
Expand Down Expand Up @@ -118,7 +120,7 @@ export default function initBasedir(

// this marker file is how we recognize ag-solo basedirs
fs.copyFileSync(
path.join(here, '..', 'solo-README-to-install.md'),
path.join(dirname, '..', 'solo-README-to-install.md'),
path.join(basedir, 'solo-README.md'),
);

Expand Down
17 changes: 9 additions & 8 deletions packages/solo/src/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* global __dirname */
import fs from 'fs';
import path from 'path';
import parseArgs from 'minimist';
Expand All @@ -9,12 +8,12 @@ import { assert } from '@agoric/assert';
import anylogger from 'anylogger';

// Start a network service
import addChain from './add-chain';
import initBasedir from './init-basedir';
import resetState from './reset-state';
import setGCIIngress from './set-gci-ingress';
import setFakeChain from './set-fake-chain';
import start from './start';
import addChain from './add-chain.js';
import initBasedir from './init-basedir.js';
import resetState from './reset-state.js';
import setGCIIngress from './set-gci-ingress.js';
import setFakeChain from './set-fake-chain.js';
import start from './start.js';

const log = anylogger('ag-solo');

Expand Down Expand Up @@ -142,7 +141,9 @@ start
}
case 'calc-gci':
case 'calc-rpcport': {
const cp = spawnSync(`${__dirname}/../../${argv[0]}.js`, argv.slice(1), {
const filename = new URL(import.meta.url).pathname;
const dirname = path.dirname(filename);
const cp = spawnSync(`${dirname}/../../${argv[0]}.js`, argv.slice(1), {
stdio: 'inherit',
});
return cp.status;
Expand Down
23 changes: 14 additions & 9 deletions packages/solo/src/start.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/* global __dirname require process setTimeout */
/* global process setTimeout */
import fs from 'fs';
import path from 'path';
import temp from 'temp';
import { fork } from 'child_process';
import { promisify } from 'util';
import { resolve as importMetaResolve } from 'import-meta-resolve';
// import { createHash } from 'crypto';

import anylogger from 'anylogger';
Expand All @@ -24,13 +25,13 @@ import {
buildTimer,
} from '@agoric/swingset-vat';
import { openLMDBSwingStore } from '@agoric/swing-store-lmdb';
import { connectToFakeChain } from '@agoric/cosmic-swingset/src/sim-chain';
import { makeWithQueue } from '@agoric/vats/src/queue';
import { connectToFakeChain } from '@agoric/cosmic-swingset/src/sim-chain.js';
import { makeWithQueue } from '@agoric/vats/src/queue.js';

import { deliver, addDeliveryTarget } from './outbound';
import { makeHTTPListener } from './web';
import { deliver, addDeliveryTarget } from './outbound.js';
import { makeHTTPListener } from './web.js';

import { connectToChain } from './chain-cosmos-sdk';
import { connectToChain } from './chain-cosmos-sdk.js';

const log = anylogger('start');

Expand Down Expand Up @@ -112,7 +113,7 @@ async function buildSwingset(
const plugin = buildPlugin(pluginDir, importPlugin, queueThunkForKernel);

const config = await loadSwingsetConfigFile(
`${__dirname}/../solo-config.json`,
new URL('../solo-config.json', import.meta.url).pathname,
);
config.devices = {
mailbox: {
Expand Down Expand Up @@ -326,7 +327,9 @@ export default async function start(basedir, argv) {
await unlink('html/wallet').catch(_ => {});

// Symlink the wallet.
const pjs = require.resolve(`${wallet}/package.json`);
const pjs = new URL(
await importMetaResolve(`${wallet}/package.json`, import.meta.url),
).pathname;
const {
'agoric-wallet': {
htmlBasedir = 'ui/build',
Expand Down Expand Up @@ -407,7 +410,9 @@ export default async function start(basedir, argv) {
.map(dep => path.resolve(agWallet, dep))
.join(' ');

const agoricCli = require.resolve('agoric/bin/agoric');
const agoricCli = new URL(
await importMetaResolve('agoric/bin/agoric', import.meta.url),
).pathname;

// Use the same verbosity as our caller did for us.
let verbosity;
Expand Down
4 changes: 2 additions & 2 deletions packages/solo/src/vat-http.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { makeNotifierKit } from '@agoric/notifier';
import { E } from '@agoric/eventual-send';
import { Far } from '@agoric/marshal';
import { assert, details as X } from '@agoric/assert';
import { getReplHandler } from '@agoric/vats/src/repl';
import { getCapTPHandler } from './captp';
import { getReplHandler } from '@agoric/vats/src/repl.js';
import { getCapTPHandler } from './captp.js';

// This vat contains the HTTP request handler.
export function buildRootObject(vatPowers) {
Expand Down
2 changes: 1 addition & 1 deletion packages/solo/src/vat-uploads.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Far } from '@agoric/marshal';
import makeScratchPad from './scratch';
import makeScratchPad from './scratch.js';

// This vat contains the private upload scratch pad.

Expand Down
10 changes: 3 additions & 7 deletions packages/solo/src/web.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
/* global __dirname require setTimeout clearTimeout setInterval clearInterval */
/* global setTimeout clearTimeout setInterval clearInterval */
// Start a network service
import path from 'path';
import http from 'http';
import { createConnection } from 'net';
import express from 'express';
import WebSocket from 'ws';
import anylogger from 'anylogger';
import morgan from 'morgan';

import { getAccessToken } from '@agoric/access-token';

// We need to CommonJS require morgan or else it warns, until:
// https://github.com/expressjs/morgan/issues/190
// is fixed.
const morgan = require('morgan');

const log = anylogger('web');

const channels = new Map();
Expand Down Expand Up @@ -89,7 +85,7 @@ export async function makeHTTPListener(basedir, port, host, rawInboundCommand) {
const htmldir = path.join(basedir, 'html');
log(`Serving static files from ${htmldir}`);
app.use(express.static(htmldir));
app.use(express.static(`${__dirname}/../public`));
app.use(express.static(new URL('../public', import.meta.url).pathname));

// The rules for validation:
//
Expand Down
4 changes: 2 additions & 2 deletions packages/solo/test/captp-fixture.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global __dirname process setTimeout */
/* global process setTimeout */
import { spawn } from 'child_process';
import WebSocket from 'ws';
import { makeCapTP, E } from '@agoric/captp';
Expand All @@ -18,7 +18,7 @@ export async function makeFixture(PORT, noisy = false) {
: ['ignore', 'pipe', 'pipe'];
const cp = spawn('./startsolo.sh', {
env: { ...process.env, PORT },
cwd: __dirname,
cwd: new URL('./', import.meta.url).pathname,
stdio,
detached: true,
});
Expand Down
19 changes: 12 additions & 7 deletions packages/solo/test/test-home.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global require process */
/* global process */

// `test.after.always` does not yet seem compatible with ses-ava
// See https://github.com/endojs/endo/issues/647
Expand All @@ -7,15 +7,16 @@
// TODO Remove babel-standalone preinitialization
// https://github.com/endojs/endo/issues/768
import '@agoric/babel-standalone';
import '@agoric/swingset-vat/tools/prepare-test-env';
import '@agoric/swingset-vat/tools/prepare-test-env.js';
// eslint-disable-next-line import/no-extraneous-dependencies
import test from 'ava';

import bundleSource from '@agoric/bundle-source';
import { Far } from '@agoric/marshal';
import { CENTRAL_ISSUER_NAME } from '@agoric/vats/src/issuers';
import { resolve as importMetaResolve } from 'import-meta-resolve';
import { CENTRAL_ISSUER_NAME } from '@agoric/vats/src/issuers.js';

import { makeFixture, E } from './captp-fixture';
import { makeFixture, E } from './captp-fixture.js';

const SOLO_PORT = 7999;

Expand Down Expand Up @@ -60,9 +61,13 @@ test.serial('home.wallet - receive zoe invite', async t => {
const { wallet, zoe, board } = E.get(home);

// Setup contract in order to get an invite to use in tests
const contractRoot = require.resolve(
'@agoric/zoe/src/contracts/automaticRefund',
);
const contractRoot = new URL(
await importMetaResolve(
'@agoric/zoe/src/contracts/automaticRefund.js',
import.meta.url,
),
).pathname;
t.log({ contractRoot });
const bundle = await bundleSource(contractRoot);
const installationHandle = await E(zoe).install(bundle);
const { creatorInvitation: invite } = await E(zoe).startInstance(
Expand Down
7 changes: 4 additions & 3 deletions packages/solo/test/test-xsnap-store.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* global require */
import '@agoric/install-ses';

import fs from 'fs';
Expand All @@ -9,18 +8,20 @@ import tmp from 'tmp';
import test from 'ava';
import { xsnap } from '@agoric/xsnap';
import { makeSnapStore } from '@agoric/swing-store-lmdb';
import { resolve as importMetaResolve } from 'import-meta-resolve';

const { freeze } = Object;

const ld = (() => {
/** @param { string } ref */
// WARNING: ambient
const resolve = ref => require.resolve(ref);
const resolve = async ref =>
new URL(await importMetaResolve(ref, import.meta.url)).pathname;
const readFile = fs.promises.readFile;
return freeze({
resolve,
/** @param { string } ref */
asset: async ref => readFile(resolve(ref), 'utf-8'),
asset: async ref => readFile(await resolve(ref), 'utf-8'),
});
})();

Expand Down

0 comments on commit 55fe336

Please sign in to comment.