*Remove all requires

*Switch to commonjs target
This commit is contained in:
Derrick Hammer 2022-08-03 02:02:40 -04:00
parent 451f646fb2
commit 5a17b6befd
9 changed files with 16 additions and 14 deletions

View File

@ -1,4 +1,5 @@
const esbuild = require("esbuild"); const esbuild = require("esbuild");
esbuild.buildSync({ esbuild.buildSync({
entryPoints: ["build/index.js"], entryPoints: ["build/index.js"],
outdir: "node-dist", outdir: "node-dist",

View File

@ -11,7 +11,7 @@
"scripts": { "scripts": {
"compile": "tsc", "compile": "tsc",
"prebuild": "bash prebuild.sh", "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": "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", "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", "build": "npm run compile && npm run prebuild && npm run bundle && npm run package",

View File

@ -1,7 +1,8 @@
//const require = createRequire(import.meta.url); //const require = createRequire(import.meta.url);
//import { createRequire } from "module"; //import { createRequire } from "module";
const DHT = require("@hyperswarm/dht"); // @ts-ignore
import DHT from "@hyperswarm/dht";
import { import {
deriveMyskyRootKeypair, deriveMyskyRootKeypair,
Ed25519Keypair, Ed25519Keypair,

View File

@ -1,7 +1,7 @@
import { start as startRpc } from "./rpc.js"; import { start as startRpc } from "./rpc.js";
import { start as startRelay } from "./relay.js"; import { start as startRelay } from "./relay.js";
import log from "loglevel"; import log from "loglevel";
import config from "./config"; import config from "./config.js";
log.setDefaultLevel(config.str("log-level")); log.setDefaultLevel(config.str("log-level"));
@ -13,5 +13,5 @@ async function boot() {
boot(); boot();
process.on("uncaughtException", function (err) { process.on("uncaughtException", function (err) {
console.log("Caught exception: " + err); console.log(`Caught exception: ${err.message} ${err.stack}`);
}); });

View File

@ -9,13 +9,12 @@ import NodeCache from "node-cache";
import { get as getDHT } from "./dht.js"; import { get as getDHT } from "./dht.js";
import { rpcMethods } from "./rpc/index.js"; import { rpcMethods } from "./rpc/index.js";
import { start as startDns } from "./dns.js"; import { start as startDns } from "./dns.js";
const { import {
Configuration, Configuration,
HttpRpcProvider, HttpRpcProvider,
PocketAAT, PocketAAT,
Pocket, Pocket,
} = require("@pokt-network/pocket-js/dist/index.js"); } from "@pokt-network/pocket-js/dist/index.js";
import { import {
JSONRPCError, JSONRPCError,
JSONRPCRequest, JSONRPCRequest,
@ -25,8 +24,9 @@ import {
import config, { updateUsePocketGateway, usePocketGateway } from "./config.js"; import config, { updateUsePocketGateway, usePocketGateway } from "./config.js";
import { ERR_NOT_READY, errorExit } from "./error.js"; import { ERR_NOT_READY, errorExit } from "./error.js";
import log from "loglevel"; import log from "loglevel";
// @ts-ignore
import stringify from "json-stable-stringify";
const stringify = require("json-stable-stringify");
const pendingRequests = new NodeCache(); const pendingRequests = new NodeCache();
const processedRequests = new NodeCache({ const processedRequests = new NodeCache({
stdTTL: 60 * 60 * 12, stdTTL: 60 * 60 * 12,

View File

@ -3,8 +3,8 @@
import { isIp } from "../util.js"; import { isIp } from "../util.js";
import { RpcMethodList } from "./index.js"; import { RpcMethodList } from "./index.js";
// @ts-ignore
const bns = require("bns"); import bns from "bns";
const { StubResolver, RecursiveResolver } = bns; const { StubResolver, RecursiveResolver } = bns;
const resolverOpt = { const resolverOpt = {

View File

@ -8,8 +8,8 @@ import rand from "random-key";
import SPVNode from "hsd/lib/node/spvnode.js"; import SPVNode from "hsd/lib/node/spvnode.js";
import config from "../config.js"; import config from "../config.js";
import { ERR_NOT_READY } from "../error.js"; import { ERR_NOT_READY } from "../error.js";
// @ts-ignore
const { NodeClient } = require("hs-client"); import { NodeClient } from "hs-client";
let hsdServer: SPVNode; let hsdServer: SPVNode;

View File

@ -1,6 +1,6 @@
import { proxyRpcMethod } from "./common.js"; import { proxyRpcMethod } from "./common.js";
import { RpcMethodList } from "./index.js"; import { RpcMethodList } from "./index.js";
import * as chainNetworks from "../networks.json"; import chainNetworks from "../networks.json";
export default { export default {
getAccountInfo: proxyRpcMethod("getAccountInfo", [ getAccountInfo: proxyRpcMethod("getAccountInfo", [

View File

@ -1,4 +1,4 @@
import * as chainNetworks from "./networks.json"; import chainNetworks from "./networks.json";
type networks = { [net: string]: string }; type networks = { [net: string]: string };