Skip to content

Commit

Permalink
refactor(dapp-svelte-wallet): 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 b6e943b commit e83d614
Show file tree
Hide file tree
Showing 19 changed files with 78 additions and 62 deletions.
7 changes: 5 additions & 2 deletions packages/dapp-svelte-wallet/api/deploy.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
/* global __dirname */
// @ts-nocheck
// Agoric wallet deployment script.
// FIXME: This is just hacked together for the legacy wallet.

import { E } from '@agoric/eventual-send';
import { assert, details as X } from '@agoric/assert';
import path from 'path';

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

export default async function deployWallet(
homePromise,
Expand All @@ -26,7 +29,7 @@ export default async function deployWallet(
} = home;

// Bundle the wallet sources.
const bundle = await bundleSource(pathResolve(__dirname, './src/wallet.js'));
const bundle = await bundleSource(pathResolve(dirname, './src/wallet.js'));

// Install it on the local spawner.
const walletInstall = E(spawner).install(bundle);
Expand Down
2 changes: 1 addition & 1 deletion packages/dapp-svelte-wallet/api/exported.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import './src/types';
import './src/types.js';
1 change: 1 addition & 0 deletions packages/dapp-svelte-wallet/api/jsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",

"noEmit": true,
/*
Expand Down
6 changes: 2 additions & 4 deletions packages/dapp-svelte-wallet/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"private": true,
"version": "0.9.12",
"description": "Wallet web server handler",
"type": "module",
"scripts": {
"build": "exit 0",
"test": "ava",
Expand All @@ -28,7 +29,7 @@
"@agoric/promise-kit": "^0.2.21",
"@agoric/store": "^0.4.23",
"@agoric/zoe": "^0.17.6",
"esm": "agoric-labs/esm#Agoric-built"
"import-meta-resolve": "^1.1.1"
},
"eslintConfig": {
"extends": [
Expand All @@ -54,9 +55,6 @@
"files": [
"test/**/test-*.js"
],
"require": [
"esm"
],
"timeout": "2m"
}
}
4 changes: 2 additions & 2 deletions packages/dapp-svelte-wallet/api/src/issuerTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { E } from '@agoric/eventual-send';

import { makeWeakStore } from '@agoric/store';

import '../exported';
import './internal-types';
import '../exported.js';
import './internal-types.js';

/**
* IssuerTable
Expand Down
16 changes: 8 additions & 8 deletions packages/dapp-svelte-wallet/api/src/lib-wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ import {
} from '@agoric/notifier';
import { makePromiseKit } from '@agoric/promise-kit';

import { makeIssuerTable } from './issuerTable';
import { makeDehydrator } from './lib-dehydrate';
import { makeId, findOrMakeInvitation } from './findOrMakeInvitation';
import { bigintStringify } from './bigintStringify';
import { makeIssuerTable } from './issuerTable.js';
import { makeDehydrator } from './lib-dehydrate.js';
import { makeId, findOrMakeInvitation } from './findOrMakeInvitation.js';
import { bigintStringify } from './bigintStringify.js';

import '@agoric/store/exported';
import '@agoric/zoe/exported';
import '@agoric/store/exported.js';
import '@agoric/zoe/exported.js';

import './internal-types';
import './types';
import './internal-types.js';
import './types.js';

/**
* @template T
Expand Down
8 changes: 4 additions & 4 deletions packages/dapp-svelte-wallet/api/src/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import { E } from '@agoric/eventual-send';
import { makeNotifierKit, observeIteration } from '@agoric/notifier';
import { Far } from '@agoric/marshal';

import { makeWallet } from './lib-wallet';
import pubsub from './pubsub';
import { bigintStringify } from './bigintStringify';
import { makeWallet } from './lib-wallet.js';
import pubsub from './pubsub.js';
import { bigintStringify } from './bigintStringify.js';

import './internal-types';
import './internal-types.js';

export function buildRootObject(_vatPowers) {
let walletRoot;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { makeNotifierKit } from '@agoric/notifier';
import { Far } from '@agoric/marshal';

import '@agoric/zoe/exported';
import '@agoric/zoe/exported.js';

export const start = zcf => {
const { notifier, updater } = makeNotifierKit();
Expand Down
12 changes: 6 additions & 6 deletions packages/dapp-svelte-wallet/api/test/test-getPursesNotifier.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// @ts-check
import { test } from '@agoric/zoe/tools/prepare-test-env-ava';
import { test } from '@agoric/zoe/tools/prepare-test-env-ava.js';

import { makeIssuerKit } from '@agoric/ertp';
import { makeZoe } from '@agoric/zoe';
import fakeVatAdmin from '@agoric/zoe/tools/fakeVatAdmin';
import fakeVatAdmin from '@agoric/zoe/tools/fakeVatAdmin.js';
// eslint-disable-next-line import/no-extraneous-dependencies
import { makeBoard } from '@agoric/vats/src/lib-board';
import { makeBoard } from '@agoric/vats/src/lib-board.js';
// eslint-disable-next-line import/no-extraneous-dependencies
import { makeNameHubKit } from '@agoric/vats/src/nameHub';
import { makeNameHubKit } from '@agoric/vats/src/nameHub.js';
import { Far } from '@agoric/marshal';
import { makeWallet } from '../src/lib-wallet';
import { makeWallet } from '../src/lib-wallet.js';

import '../src/types';
import '../src/types.js';

function makeFakeMyAddressNameAdmin() {
const { nameAdmin: rawMyAddressNameAdmin } = makeNameHubKit();
Expand Down
4 changes: 2 additions & 2 deletions packages/dapp-svelte-wallet/api/test/test-lib-dehydrate.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { test } from '@agoric/zoe/tools/prepare-test-env-ava';
import { test } from '@agoric/zoe/tools/prepare-test-env-ava.js';

import { Far } from '@agoric/marshal';

import { makeDehydrator } from '../src/lib-dehydrate';
import { makeDehydrator } from '../src/lib-dehydrate.js';

test('makeDehydrator', async t => {
const { hydrate, dehydrate, makeMapping } = makeDehydrator();
Expand Down
33 changes: 21 additions & 12 deletions packages/dapp-svelte-wallet/api/test/test-lib-wallet.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
/* global require */
// @ts-check
import { test } from '@agoric/zoe/tools/prepare-test-env-ava';
import { test } from '@agoric/zoe/tools/prepare-test-env-ava.js';

// eslint-disable-next-line import/no-extraneous-dependencies
import bundleSource from '@agoric/bundle-source';
import { makeIssuerKit, AmountMath, AssetKind } from '@agoric/ertp';

import { makeZoe } from '@agoric/zoe';
import fakeVatAdmin from '@agoric/zoe/tools/fakeVatAdmin';
import fakeVatAdmin from '@agoric/zoe/tools/fakeVatAdmin.js';

import { assert } from '@agoric/assert';
import { E } from '@agoric/eventual-send';
// eslint-disable-next-line import/no-extraneous-dependencies
import { makeBoard } from '@agoric/vats/src/lib-board';
import { makeBoard } from '@agoric/vats/src/lib-board.js';
// eslint-disable-next-line import/no-extraneous-dependencies
import { makeNameHubKit } from '@agoric/vats/src/nameHub';
import { makeNameHubKit } from '@agoric/vats/src/nameHub.js';
import { Far } from '@agoric/marshal';
import { makeWallet } from '../src/lib-wallet';
import { resolve as importMetaResolve } from 'import-meta-resolve';
import { makeWallet } from '../src/lib-wallet.js';

import '../src/types';
import '../src/types.js';

const ZOE_INVITE_PURSE_PETNAME = 'Default Zoe invite purse';

Expand Down Expand Up @@ -49,9 +49,12 @@ async function setupTest() {
const board = makeBoard();

// Create AutomaticRefund instance
const automaticRefundContractRoot = require.resolve(
'@agoric/zoe/src/contracts/automaticRefund',
const automaticRefundContractUrl = await importMetaResolve(
'@agoric/zoe/src/contracts/automaticRefund.js',
import.meta.url,
);
const automaticRefundContractRoot = new URL(automaticRefundContractUrl)
.pathname;
const automaticRefundBundle = await bundleSource(automaticRefundContractRoot);
const installation = await zoe.install(automaticRefundBundle);
const issuerKeywordRecord = harden({ Contribution: moolaBundle.issuer });
Expand All @@ -62,9 +65,11 @@ async function setupTest() {
assert(invite);

// Create Autoswap instance
const autoswapContractRoot = require.resolve(
'@agoric/zoe/src/contracts/autoswap',
const autoswapContractUrl = await importMetaResolve(
'@agoric/zoe/src/contracts/autoswap.js',
import.meta.url,
);
const autoswapContractRoot = new URL(autoswapContractUrl).pathname;
const autoswapBundle = await bundleSource(autoswapContractRoot);
const autoswapInstallationHandle = await zoe.install(autoswapBundle);
const autoswapIssuerKeywordRecord = harden({
Expand Down Expand Up @@ -1192,7 +1197,11 @@ test('addOffer makeContinuingInvitation', async t => {
const board = makeBoard();

// Create ContinuingInvitationExample instance
const path = require.resolve('./continuingInvitationExample.js');
const url = await importMetaResolve(
'./continuingInvitationExample.js',
import.meta.url,
);
const path = new URL(url).pathname;
const bundle = await bundleSource(path);
const installation = await zoe.install(bundle);
const { creatorInvitation, instance } = await zoe.startInstance(installation);
Expand Down
7 changes: 3 additions & 4 deletions packages/dapp-svelte-wallet/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
{
"name": "@agoric/dapp-svelte-wallet",
"version": "0.10.11",
"parsers": {
"js": "mjs"
},
"type": "module",
"main": "index.js",
"license": "Apache-2.0",
"author": "Agoric",
Expand All @@ -26,7 +24,8 @@
"dependencies": {
"agoric": "^0.13.11",
"babel-eslint": "^10.0.3",
"eslint-plugin-eslint-comments": "^3.1.2"
"eslint-plugin-eslint-comments": "^3.1.2",
"import-meta-resolve": "^1.1.1"
},
"publishConfig": {
"access": "public"
Expand Down
2 changes: 1 addition & 1 deletion packages/dapp-svelte-wallet/ui/lib/helpers.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { dump } from '@agoric/vats/src/repl';
export { dump } from '@agoric/vats/src/repl.js';
1 change: 1 addition & 0 deletions packages/dapp-svelte-wallet/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.7.15",
"license": "Apache-2.0",
"author": "Agoric",
"type": "module",
"scripts": {
"build": "rollup -c",
"dev": "rollup -c -w",
Expand Down
3 changes: 2 additions & 1 deletion packages/dapp-svelte-wallet/ui/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import child_process from 'child_process';
import svelte from 'rollup-plugin-svelte';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
Expand All @@ -18,7 +19,7 @@ function serve() {
return {
writeBundle() {
if (server) return;
server = require('child_process').spawn('npm', ['run', 'start', '--', '--dev'], {
server = child_process.spawn('npm', ['run', 'start', '--', '--dev'], {
stdio: ['ignore', 'inherit', 'inherit'],
shell: true
});
Expand Down
20 changes: 12 additions & 8 deletions packages/dapp-svelte-wallet/ui/scripts/setupTypeScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@
rm -rf test-template template && git clone sveltejs/template test-template && node scripts/setupTypeScript.js test-template
*/

const fs = require("fs")
const path = require("path")
const { argv } = require("process")
import fs from 'fs';
import path from 'path';

const projectRoot = argv[2] || path.join(__dirname, "..")
const { argv } = process;

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

const projectRoot = argv[2] || path.join(dirname, "..")

// Add deps to pkg.json
const packageJSON = JSON.parse(fs.readFileSync(path.join(projectRoot, "package.json"), "utf8"))
Expand Down Expand Up @@ -99,15 +103,15 @@ if (!argv[2]) {
fs.unlinkSync(path.join(__filename))

// Check for Mac's DS_store file, and if it's the only one left remove it
const remainingFiles = fs.readdirSync(path.join(__dirname))
const remainingFiles = fs.readdirSync(path.join(dirname))
if (remainingFiles.length === 1 && remainingFiles[0] === '.DS_store') {
fs.unlinkSync(path.join(__dirname, '.DS_store'))
fs.unlinkSync(path.join(dirname, '.DS_store'))
}

// Check if the scripts folder is empty
if (fs.readdirSync(path.join(__dirname)).length === 0) {
if (fs.readdirSync(path.join(dirname)).length === 0) {
// Remove the scripts folder
fs.rmdirSync(path.join(__dirname))
fs.rmdirSync(path.join(dirname))
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/dapp-svelte-wallet/ui/src/install-ses-lockdown.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'ses';
import '@agoric/eventual-send/shim';
import '@agoric/eventual-send/shim.js';

lockdown();

Expand Down
2 changes: 1 addition & 1 deletion packages/dapp-svelte-wallet/ui/src/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import './install-ses-lockdown';
import './install-ses-lockdown.js';
import './tailwind.css';
import App from './App.svelte';

Expand Down
8 changes: 4 additions & 4 deletions packages/dapp-svelte-wallet/ui/src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { writable } from 'svelte/store';
import { E } from '@agoric/eventual-send';
import { observeNotifier } from '@agoric/notifier';

import { makeWebSocket } from './websocket';
import { makeCapTPConnection } from './captp';
import { makeWebSocket } from './websocket.js';
import { makeCapTPConnection } from './captp.js';

import '../../api/src/internal-types';
import '../../api/src/types';
import '../../api/src/internal-types.js';
import '../../api/src/types.js';

let accessTokenParams;
let hasAccessToken;
Expand Down

0 comments on commit e83d614

Please sign in to comment.