Skip to content

Commit

Permalink
fix: built export fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Keyrxng committed Jul 17, 2024
1 parent 8ed1230 commit 2a6103a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 21 deletions.
13 changes: 0 additions & 13 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
export default async function getRPCHandler() {
let modulePath;
if (typeof window !== "undefined") {
modulePath = "./esm/index.js";
} else {
modulePath = "./cjs/index.js";
}

const { RPCHandler } = await import(modulePath);

return RPCHandler;
}

import {
NetworkId,
NetworkName,
Expand Down
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,17 @@
"format": "run-s format:lint format:prettier format:cspell",
"format:lint": "eslint --fix .",
"format:prettier": "prettier --write .",
"format:cspell": "tsx .github/cspell.ts",
"format:cspell": "npx tsx .github/cspell.ts",
"knip": "knip",
"knip-ci": "knip --no-exit-code --reporter json",
"prepare": "husky install",
"build:types": "tsc --emitDeclarationOnly --declaration --outDir dist",
"build:index": "tsx build/esbuild-build.ts",
"build": "run-s clean build:index build:types clean:types",
"build": "run-s clean build:index build:types",
"postinstall": "git submodule update --init --recursive",
"test:anvil": "npx tsx ./tests/anvil.ts",
"test": "jest --runInBand",
"clean": "rm -rf dist",
"clean:types": "rm -rf dist/dynamic.d.ts"
"clean": "rm -rf dist"
},
"keywords": [
"typescript",
Expand Down
5 changes: 2 additions & 3 deletions tests/script-test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import getRPCHandler, { HandlerConstructorConfig, RPCHandler, networkIds, networkCurrencies, networkExplorers, networkNames } from "../dist/";
import { HandlerConstructorConfig, RPCHandler, networkIds, networkCurrencies, networkExplorers, networkNames } from "../dist/";

/**
* A test script to ensure that the module can be imported and used correctly
Expand All @@ -8,7 +8,6 @@ import getRPCHandler, { HandlerConstructorConfig, RPCHandler, networkIds, networ
(async () => {
// a hook that loads the correct module based on the environment
// not required but a good to have if main/module entry is causing issues
const RPCHandler = await getRPCHandler();

const config: HandlerConstructorConfig = {
networkId: "100",
Expand All @@ -28,7 +27,7 @@ import getRPCHandler, { HandlerConstructorConfig, RPCHandler, networkIds, networ
},
};

const handler: RPCHandler = new RPCHandler(config);
const handler = new RPCHandler(config);

await handler.getFastestRpcProvider();

Expand Down
10 changes: 9 additions & 1 deletion types/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,16 @@ export type NetworkRPCs = typeof networkRpcs;
export type NetworkCurrencies = typeof networkCurrencies;
export type NetworkExplorers = typeof networkExplorers;

/**
* Without this NetworkName builds as `any` because `keyof typeof EXTRA_RPCS`
* extends symbol which cannot be used to index an object
*/
type NetworkIds<T extends PropertyKey = keyof typeof EXTRA_RPCS> = {
[K in T]: K extends string ? K : never;
}[T];

// filtered NetworkId union
export type NetworkId = keyof typeof EXTRA_RPCS | "31337" | "1337";
export type NetworkId = NetworkIds | "31337" | "1337";

// unfiltered Record<NetworkId, NetworkName>
type ChainsUnfiltered = {
Expand Down

0 comments on commit 2a6103a

Please sign in to comment.