From 301c337c98fe48dbdf4feaceb4a17796173baac2 Mon Sep 17 00:00:00 2001 From: Kris Kowal Date: Fri, 13 Aug 2021 17:52:04 -0700 Subject: [PATCH] refactor: Convert RESM to NESM --- api/deploy.js | 4 ++-- api/package.json | 7 ++----- api/src/handler.js | 2 +- contract/deploy.js | 2 +- contract/package.json | 10 ++-------- contract/src/contract.js | 2 +- contract/test/test-contract.js | 12 +++++++----- package.json | 7 ------- ui/package.json | 4 +--- ui/public/lib/api-client.js | 4 ++-- ui/public/lib/constants.js | 2 +- ui/public/lib/wallet-client.js | 2 +- ui/public/src/connect.js | 6 +++--- ui/public/src/main.js | 6 +++--- 14 files changed, 27 insertions(+), 43 deletions(-) diff --git a/api/deploy.js b/api/deploy.js index ccb6c7f..29ed145 100644 --- a/api/deploy.js +++ b/api/deploy.js @@ -6,9 +6,9 @@ import fs from 'fs'; import { E } from '@agoric/eventual-send'; -import '@agoric/zoe/exported'; +import '@agoric/zoe/exported.js'; -import installationConstants from '../ui/public/conf/installationConstants'; +import installationConstants from '../ui/public/conf/installationConstants.js'; // deploy.js runs in an ephemeral Node.js outside of swingset. The // spawner runs within ag-solo, so is persistent. Once the deploy.js diff --git a/api/package.json b/api/package.json index e54895d..bbd2cae 100644 --- a/api/package.json +++ b/api/package.json @@ -3,9 +3,7 @@ "private": true, "version": "0.1.0", "description": "Agoric Dapp web server handler", - "parsers": { - "js": "mjs" - }, + "type": "module", "scripts": { "build": "exit 0", "test": "exit 0", @@ -28,8 +26,7 @@ }, "dependencies": { "@agoric/zoe": "*", - "@agoric/eventual-send": "*", - "esm": "^3.2.5" + "@agoric/eventual-send": "*" }, "eslintConfig": { "extends": [ diff --git a/api/src/handler.js b/api/src/handler.js index 62f67a6..bbbbb75 100644 --- a/api/src/handler.js +++ b/api/src/handler.js @@ -1,6 +1,6 @@ // @ts-check import { E } from '@agoric/eventual-send'; -import { makeWebSocketHandler } from './lib-http'; +import { makeWebSocketHandler } from './lib-http.js'; const spawnHandler = ( { creatorFacet, board, http, invitationIssuer }, diff --git a/contract/deploy.js b/contract/deploy.js index 8a266a6..929093f 100644 --- a/contract/deploy.js +++ b/contract/deploy.js @@ -1,7 +1,7 @@ // @ts-check import fs from 'fs'; -import '@agoric/zoe/exported'; +import '@agoric/zoe/exported.js'; import { E } from '@agoric/eventual-send'; // This script takes our contract code, installs it on Zoe, and makes diff --git a/contract/package.json b/contract/package.json index d733712..5ad94b3 100644 --- a/contract/package.json +++ b/contract/package.json @@ -3,9 +3,7 @@ "version": "0.1.0", "private": true, "description": "Contract for the Agoric Dapp", - "parsers": { - "js": "mjs" - }, + "type": "module", "scripts": { "build": "exit 0", "test": "ava --verbose", @@ -34,16 +32,12 @@ "@agoric/install-ses": "*", "@agoric/notifier": "*", "@agoric/store": "*", - "@agoric/zoe": "*", - "esm": "^3.2.5" + "@agoric/zoe": "*" }, "ava": { "files": [ "test/**/test-*.js" ], - "require": [ - "esm" - ], "timeout": "10m" }, "keywords": [], diff --git a/contract/src/contract.js b/contract/src/contract.js index 10367c6..3fb2964 100644 --- a/contract/src/contract.js +++ b/contract/src/contract.js @@ -1,5 +1,5 @@ // @ts-check -import '@agoric/zoe/exported'; +import '@agoric/zoe/exported.js'; import { AmountMath } from '@agoric/ertp'; /** diff --git a/contract/test/test-contract.js b/contract/test/test-contract.js index f2a7d47..ed789fa 100644 --- a/contract/test/test-contract.js +++ b/contract/test/test-contract.js @@ -1,17 +1,19 @@ // @ts-check -/* global __dirname */ - -import { test } from '@agoric/zoe/tools/prepare-test-env-ava'; +import { test } from '@agoric/zoe/tools/prepare-test-env-ava.js'; +import path from 'path'; import bundleSource from '@agoric/bundle-source'; import { E } from '@agoric/eventual-send'; -import { makeFakeVatAdmin } from '@agoric/zoe/tools/fakeVatAdmin'; +import { makeFakeVatAdmin } from '@agoric/zoe/tools/fakeVatAdmin.js'; import { makeZoe } from '@agoric/zoe'; import { AmountMath } from '@agoric/ertp'; -const contractPath = `${__dirname}/../src/contract`; +const filename = new URL(import.meta.url).pathname; +const dirname = path.dirname(filename); + +const contractPath = `${dirname}/../src/contract.js`; test('zoe - mint payments', async (t) => { const zoe = makeZoe(makeFakeVatAdmin().admin); diff --git a/package.json b/package.json index 5a83060..4ac5a33 100644 --- a/package.json +++ b/package.json @@ -3,10 +3,6 @@ "version": "0.0.1", "private": true, "useWorkspaces": true, - "main": "index.js", - "parsers": { - "js": "mjs" - }, "workspaces": [ "api", "contract", @@ -37,9 +33,6 @@ "agoric": "*", "eslint-plugin-eslint-comments": "^3.1.2" }, - "resolutions": { - "**/esm": "agoric-labs/esm#Agoric-built" - }, "prettier": { "trailingComma": "all", "singleQuote": true, diff --git a/ui/package.json b/ui/package.json index fd0c105..5920a2e 100644 --- a/ui/package.json +++ b/ui/package.json @@ -5,9 +5,7 @@ "author": "Agoric", "license": "Apache-2.0", "homepage": ".", - "parsers": { - "js": "mjs" - }, + "type": "module", "scripts": { "build": "parcel build public/index.html", "lint-check": "eslint '**/*.{js,jsx}'", diff --git a/ui/public/lib/api-client.js b/ui/public/lib/api-client.js index 6457932..2f8f266 100644 --- a/ui/public/lib/api-client.js +++ b/ui/public/lib/api-client.js @@ -1,9 +1,9 @@ // @ts-check /* globals window, WebSocket */ -import { registerSocket, closeSocket, getActiveSocket } from './socket'; +import { registerSocket, closeSocket, getActiveSocket } from './socket.js'; -import dappConstants from './constants'; +import dappConstants from './constants.js'; const { API_URL } = dappConstants; diff --git a/ui/public/lib/constants.js b/ui/public/lib/constants.js index 2f797ed..a6ab632 100644 --- a/ui/public/lib/constants.js +++ b/ui/public/lib/constants.js @@ -1,5 +1,5 @@ // Allow the runtime to override the defaults with __DAPP_CONSTANTS__ -import defaults from '../conf/defaults'; +import defaults from '../conf/defaults.js'; // eslint-disable-next-line no-underscore-dangle, no-undef export default globalThis.__DAPP_CONSTANTS__ || defaults; diff --git a/ui/public/lib/wallet-client.js b/ui/public/lib/wallet-client.js index 1def20d..34d0871 100644 --- a/ui/public/lib/wallet-client.js +++ b/ui/public/lib/wallet-client.js @@ -1,7 +1,7 @@ // @ts-check /* globals window document */ -import { registerSocket, getActiveSocket, closeSocket } from './socket'; +import { registerSocket, getActiveSocket, closeSocket } from './socket.js'; // Wallet bridge diff --git a/ui/public/src/connect.js b/ui/public/src/connect.js index ecde932..5763084 100644 --- a/ui/public/src/connect.js +++ b/ui/public/src/connect.js @@ -1,8 +1,8 @@ // @ts-check /* globals document */ -import { rpc } from '../lib/socket'; -import { activateSocket as startApi } from '../lib/api-client'; -import { activateSocket as startBridge } from '../lib/wallet-client'; +import { rpc } from '../lib/socket.js'; +import { activateSocket as startApi } from '../lib/api-client.js'; +import { activateSocket as startBridge } from '../lib/wallet-client.js'; const $messages = /** @type {HTMLDivElement} */ (document.getElementById( `messages`, diff --git a/ui/public/src/main.js b/ui/public/src/main.js index 4179053..0a6ad5c 100644 --- a/ui/public/src/main.js +++ b/ui/public/src/main.js @@ -1,8 +1,8 @@ // @ts-check /* globals document mdc */ -import 'regenerator-runtime/runtime'; -import dappConstants from '../lib/constants'; -import { connect } from './connect'; +import 'regenerator-runtime/runtime.js'; +import dappConstants from '../lib/constants.js'; +import { connect } from './connect.js'; const { INVITE_BRAND_BOARD_ID,