From 5a17b6befdf633c88dfd0457930190d5c130fec5 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Wed, 3 Aug 2022 02:02:40 -0400 Subject: [PATCH] *Remove all requires *Switch to commonjs target --- esbuild.config.js => build.js | 1 + package.json | 2 +- src/dht.ts | 3 ++- src/index.ts | 4 ++-- src/rpc.ts | 8 ++++---- src/rpc/dns.ts | 4 ++-- src/rpc/handshake.ts | 4 ++-- src/rpc/solana.ts | 2 +- src/util.ts | 2 +- 9 files changed, 16 insertions(+), 14 deletions(-) rename esbuild.config.js => build.js (99%) diff --git a/esbuild.config.js b/build.js similarity index 99% rename from esbuild.config.js rename to build.js index 79de58f..3c262f3 100644 --- a/esbuild.config.js +++ b/build.js @@ -1,4 +1,5 @@ const esbuild = require("esbuild"); + esbuild.buildSync({ entryPoints: ["build/index.js"], outdir: "node-dist", diff --git a/package.json b/package.json index b2ab6ca..af1de5c 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "scripts": { "compile": "tsc", "prebuild": "bash prebuild.sh", - "bundle": "node esbuild.config.js", + "bundle": "node build.js", "package": "pkg -c pkg.json node-dist/index.js -t linux --no-bytecode --public", "package-debug": "pkg -c pkg.json node-dist/index.js -b -t linux --no-bytecode --public", "build": "npm run compile && npm run prebuild && npm run bundle && npm run package", diff --git a/src/dht.ts b/src/dht.ts index f57734f..4804a42 100644 --- a/src/dht.ts +++ b/src/dht.ts @@ -1,7 +1,8 @@ //const require = createRequire(import.meta.url); //import { createRequire } from "module"; -const DHT = require("@hyperswarm/dht"); +// @ts-ignore +import DHT from "@hyperswarm/dht"; import { deriveMyskyRootKeypair, Ed25519Keypair, diff --git a/src/index.ts b/src/index.ts index abbddb1..294c284 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,7 @@ import { start as startRpc } from "./rpc.js"; import { start as startRelay } from "./relay.js"; import log from "loglevel"; -import config from "./config"; +import config from "./config.js"; log.setDefaultLevel(config.str("log-level")); @@ -13,5 +13,5 @@ async function boot() { boot(); process.on("uncaughtException", function (err) { - console.log("Caught exception: " + err); + console.log(`Caught exception: ${err.message} ${err.stack}`); }); diff --git a/src/rpc.ts b/src/rpc.ts index 582b617..112638d 100644 --- a/src/rpc.ts +++ b/src/rpc.ts @@ -9,13 +9,12 @@ import NodeCache from "node-cache"; import { get as getDHT } from "./dht.js"; import { rpcMethods } from "./rpc/index.js"; import { start as startDns } from "./dns.js"; -const { +import { Configuration, HttpRpcProvider, PocketAAT, Pocket, -} = require("@pokt-network/pocket-js/dist/index.js"); - +} from "@pokt-network/pocket-js/dist/index.js"; import { JSONRPCError, JSONRPCRequest, @@ -25,8 +24,9 @@ import { import config, { updateUsePocketGateway, usePocketGateway } from "./config.js"; import { ERR_NOT_READY, errorExit } from "./error.js"; import log from "loglevel"; +// @ts-ignore +import stringify from "json-stable-stringify"; -const stringify = require("json-stable-stringify"); const pendingRequests = new NodeCache(); const processedRequests = new NodeCache({ stdTTL: 60 * 60 * 12, diff --git a/src/rpc/dns.ts b/src/rpc/dns.ts index 0a59254..71687b9 100644 --- a/src/rpc/dns.ts +++ b/src/rpc/dns.ts @@ -3,8 +3,8 @@ import { isIp } from "../util.js"; import { RpcMethodList } from "./index.js"; - -const bns = require("bns"); +// @ts-ignore +import bns from "bns"; const { StubResolver, RecursiveResolver } = bns; const resolverOpt = { diff --git a/src/rpc/handshake.ts b/src/rpc/handshake.ts index 0ee01f3..9b5b879 100644 --- a/src/rpc/handshake.ts +++ b/src/rpc/handshake.ts @@ -8,8 +8,8 @@ import rand from "random-key"; import SPVNode from "hsd/lib/node/spvnode.js"; import config from "../config.js"; import { ERR_NOT_READY } from "../error.js"; - -const { NodeClient } = require("hs-client"); +// @ts-ignore +import { NodeClient } from "hs-client"; let hsdServer: SPVNode; diff --git a/src/rpc/solana.ts b/src/rpc/solana.ts index b438cb6..e5f6e9c 100644 --- a/src/rpc/solana.ts +++ b/src/rpc/solana.ts @@ -1,6 +1,6 @@ import { proxyRpcMethod } from "./common.js"; import { RpcMethodList } from "./index.js"; -import * as chainNetworks from "../networks.json"; +import chainNetworks from "../networks.json"; export default { getAccountInfo: proxyRpcMethod("getAccountInfo", [ diff --git a/src/util.ts b/src/util.ts index 45c8697..5436b32 100644 --- a/src/util.ts +++ b/src/util.ts @@ -1,4 +1,4 @@ -import * as chainNetworks from "./networks.json"; +import chainNetworks from "./networks.json"; type networks = { [net: string]: string };