Skip to content

Commit 4bf4428

Browse files
authored
Packaging: Provide true ESM modules and fallback CJS (#408)
1 parent da48521 commit 4bf4428

File tree

372 files changed

+3295
-2238
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

372 files changed

+3295
-2238
lines changed

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ Getting started is simple, just import Wormhole and the [Platform](#platforms) m
4040
<!--EXAMPLE_IMPORTS-->
4141
```ts
4242
import { wormhole } from "@wormhole-foundation/sdk";
43-
import { algorand } from "@wormhole-foundation/sdk/algorand";
44-
import { cosmwasm } from "@wormhole-foundation/sdk/cosmwasm";
45-
import { evm } from "@wormhole-foundation/sdk/evm";
46-
import { solana } from "@wormhole-foundation/sdk/solana";
47-
import { sui } from "@wormhole-foundation/sdk/sui";
43+
import algorand from "@wormhole-foundation/sdk/algorand";
44+
import cosmwasm from "@wormhole-foundation/sdk/cosmwasm";
45+
import evm from "@wormhole-foundation/sdk/evm";
46+
import solana from "@wormhole-foundation/sdk/solana";
47+
import sui from "@wormhole-foundation/sdk/sui";
4848
```
4949
See example [here](https://github.com/wormhole-foundation/connect-sdk/blob/main/examples/src/index.ts#L2)
5050
<!--EXAMPLE_IMPORTS-->

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.5.0-beta.10
1+
0.5.0-alpha.8

connect/__tests__/index.test.ts

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import * as publicRpcMock from "./mocks/publicrpc"; // Should be first
1+
import * as publicRpcMock from "./mocks/publicrpc.js"; // Should be first
22

33
import { describe, expect, test } from "@jest/globals";
44
import { Platform, platform } from "@wormhole-foundation/sdk-base";
55
import { ChainContext, PlatformContext, RpcConnection } from "@wormhole-foundation/sdk-definitions";
6-
76
import { mocks, utils } from "@wormhole-foundation/sdk-definitions/testing";
8-
import { Wormhole, networkPlatformConfigs } from "../src";
7+
8+
import { Wormhole, networkPlatformConfigs } from "./../src/index.js";
99

1010
const network: "Testnet" = "Testnet";
1111
type TNet = typeof network;
@@ -40,7 +40,6 @@ describe("Wormhole Tests", () => {
4040
});
4141
expect(vaa).toBeDefined();
4242
});
43-
4443
test("returns undefined when vaa bytes not found", async function () {
4544
publicRpcMock.givenSignedVaaNotFound();
4645
const vaa = await wh.getVaaBytes(
@@ -49,7 +48,6 @@ describe("Wormhole Tests", () => {
4948
);
5049
expect(vaa).toBeNull();
5150
});
52-
5351
test("returns after first try fails", async function () {
5452
publicRpcMock.givenSignedVaaRequestWorksAfterRetry();
5553
const vaa = await wh.getVaaBytes({
@@ -70,8 +68,8 @@ describe("Platform Tests", () => {
7068
});
7169

7270
let rpc: RpcConnection<Platform>;
73-
test("Gets RPC", () => {
74-
rpc = p.getRpc("Ethereum");
71+
test("Gets RPC", async () => {
72+
rpc = await p.getRpc("Ethereum");
7573
expect(rpc).toBeTruthy();
7674
});
7775
});
@@ -84,8 +82,8 @@ describe("Chain Tests", () => {
8482
});
8583

8684
let rpc: RpcConnection<Platform>;
87-
test("Gets RPC", () => {
88-
rpc = c.getRpc();
85+
test("Gets RPC", async () => {
86+
rpc = await c.getRpc();
8987
expect(rpc).toBeTruthy();
9088
});
9189
});

connect/__tests__/route.test.ts

+5-18
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,22 @@
11
import { describe } from "@jest/globals";
22
import { platform } from "@wormhole-foundation/sdk-base";
3-
import { utils, mocks } from "@wormhole-foundation/sdk-definitions/testing";
4-
import { Wormhole, networkPlatformConfigs } from "../src";
5-
import { RouteTransferRequest } from "../src/routes";
3+
import { mocks } from "@wormhole-foundation/sdk-definitions/testing";
4+
import { Wormhole, networkPlatformConfigs } from "./../src/index.js";
65

76
const network: "Testnet" = "Testnet";
87
type TNet = typeof network;
98
const allPlatformCtrs = platform.platforms.map((p) =>
109
mocks.mockPlatformFactory(p, networkPlatformConfigs(network, p)),
1110
);
1211

13-
async function createRequest(wh: Wormhole<TNet>): Promise<RouteTransferRequest<TNet>> {
14-
const fromChain = wh.getChain("Solana");
15-
const toChain = wh.getChain("Ethereum");
16-
17-
const req = {
18-
from: utils.makeUniversalChainAddress("Solana"),
19-
to: utils.makeUniversalChainAddress("Ethereum"),
20-
source: utils.makeUniversalChainAddress("Solana"),
21-
destination: utils.makeUniversalChainAddress("Ethereum"),
22-
};
23-
return RouteTransferRequest.create(wh, req, fromChain, toChain);
24-
}
25-
2612
describe("Wormhole Tests", () => {
2713
let wh: Wormhole<TNet>;
28-
beforeEach(() => {
14+
beforeEach(function () {
2915
wh = new Wormhole(network, allPlatformCtrs);
3016
});
3117

32-
test("nothing", () => {
18+
test("nothing", function () {
19+
console.log(wh.network);
3320
expect(1).toBe(1);
3421
});
3522
// test("Creates route resolver", async () => {

connect/jest.config.ts

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
import type { JestConfigWithTsJest } from "ts-jest";
22

33
const jestConfig: JestConfigWithTsJest = {
4-
preset: "ts-jest",
54
verbose: true,
6-
modulePathIgnorePatterns: ["mocks"],
5+
preset: "ts-jest",
6+
moduleNameMapper: {
7+
"^(\\.{1,2}/.*)\\.js$": "$1",
8+
},
79
transform: {
8-
"^.+\\.tsx?$": [
9-
"ts-jest",
10-
{
11-
isolatedModules: true,
12-
},
13-
],
10+
"^.+\\.tsx?$": ["ts-jest", { tsconfig: "tsconfig.esm.json" }],
1411
},
1512
};
1613

connect/package.json

+21-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@wormhole-foundation/sdk-connect",
3-
"version": "0.5.0-beta.10",
3+
"version": "0.5.0-alpha.8",
44
"repository": {
55
"type": "git",
66
"url": "git+https://github.com/wormhole-foundation/connect-sdk.git"
@@ -18,9 +18,21 @@
1818
"module": "./dist/esm/index.js",
1919
"author": "",
2020
"description": "The core package for the Connect SDK, used in conjunction with 1 or more of the chain packages",
21+
"exports": {
22+
".": {
23+
"import": {
24+
"types": "./dist/esm/index.d.ts",
25+
"default": "./dist/esm/index.js"
26+
},
27+
"require": {
28+
"default": "./dist/cjs/index.js",
29+
"types": "./dist/cjs/index.d.ts"
30+
}
31+
}
32+
},
2133
"files": [
22-
"dist/cjs",
23-
"dist/esm"
34+
"dist/esm",
35+
"dist/cjs"
2436
],
2537
"keywords": [
2638
"wormhole",
@@ -33,9 +45,9 @@
3345
},
3446
"sideEffects": false,
3547
"scripts": {
36-
"build:cjs": "tsc -p ./tsconfig.cjs.json",
48+
"build:cjs": "tsc -p ./tsconfig.cjs.json && echo '{\"type\":\"commonjs\"}' > dist/cjs/package.json",
3749
"build:esm": "tsc -p ./tsconfig.esm.json",
38-
"build": "npm run build:cjs && npm run build:esm",
50+
"build": "npm run build:esm && npm run build:cjs",
3951
"rebuild": "npm run clean && npm run build",
4052
"clean": "rm -rf ./dist && rm -rf ./.turbo",
4153
"lint": "npm run prettier && eslint --fix ./src --ext .ts",
@@ -46,7 +58,8 @@
4658
},
4759
"dependencies": {
4860
"axios": "^1.4.0",
49-
"@wormhole-foundation/sdk-base": "0.5.0-beta.10",
50-
"@wormhole-foundation/sdk-definitions": "0.5.0-beta.10"
51-
}
61+
"@wormhole-foundation/sdk-base": "0.5.0-alpha.8",
62+
"@wormhole-foundation/sdk-definitions": "0.5.0-alpha.8"
63+
},
64+
"type": "module"
5265
}

connect/src/circle-api.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import axios from "axios";
2-
import { retry } from "./tasks";
2+
import { retry } from "./tasks.js";
33

44
// Note: mostly ripped off from https://github.com/circlefin/cctp-sample-app/blob/master/src/services/attestationService.ts
55
export const CIRCLE_RETRY_INTERVAL = 2000;

connect/src/index.ts

+13-12
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
export * from "./wormhole";
2-
export * from "./config";
3-
export * from "./common";
4-
export * from "./types";
1+
export * from "./wormhole.js";
2+
export * from "./config.js";
3+
export * from "./common.js";
4+
export * from "./types.js";
55

6-
export * from "./protocols/wormholeTransfer";
7-
export * from "./protocols/tokenTransfer";
8-
export * from "./protocols/cctpTransfer";
9-
export * from "./protocols/gatewayTransfer";
6+
export * from "./protocols/wormholeTransfer.js";
7+
export * from "./protocols/tokenTransfer.js";
8+
export * from "./protocols/cctpTransfer.js";
9+
export * from "./protocols/gatewayTransfer.js";
1010

11-
export * as tasks from "./tasks";
12-
export * as circleApi from "./circle-api";
13-
export * as api from "./whscan-api";
11+
export * as tasks from "./tasks.js";
12+
export * as circleApi from "./circle-api.js";
13+
export * as api from "./whscan-api.js";
1414

15-
export * as routes from "./routes";
15+
export * as routes from "./routes/index.js";
1616

1717
// Re-export from core packages
1818
export * from "@wormhole-foundation/sdk-base";
1919
export * from "@wormhole-foundation/sdk-definitions";
20+
export * as testing from "@wormhole-foundation/sdk-definitions/testing";

connect/src/protocols/cctpTransfer.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import {
2222
isWormholeMessageId,
2323
} from "@wormhole-foundation/sdk-definitions";
2424

25-
import { signSendWait } from "../common";
26-
import { DEFAULT_TASK_TIMEOUT } from "../config";
25+
import { signSendWait } from "../common.js";
26+
import { DEFAULT_TASK_TIMEOUT } from "../config.js";
2727
import type {
2828
AttestationReceipt,
2929
AttestedTransferReceipt,
@@ -32,10 +32,10 @@ import type {
3232
SourceInitiatedTransferReceipt,
3333
TransferQuote,
3434
TransferReceipt,
35-
} from "../types";
36-
import { TransferState, isAttested, isSourceFinalized, isSourceInitiated } from "../types";
37-
import { Wormhole } from "../wormhole";
38-
import type { WormholeTransfer } from "./wormholeTransfer";
35+
} from "../types.js";
36+
import { TransferState, isAttested, isSourceFinalized, isSourceInitiated } from "../types.js";
37+
import { Wormhole } from "../wormhole.js";
38+
import type { WormholeTransfer } from "./wormholeTransfer.js";
3939

4040
type CircleTransferProtocol = "CircleBridge" | "AutomaticCircleBridge";
4141

connect/src/protocols/gatewayTransfer.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ import {
2727
toGatewayMsg,
2828
toNative,
2929
} from "@wormhole-foundation/sdk-definitions";
30-
import { signSendWait } from "../common";
31-
import { fetchIbcXfer, isTokenBridgeVaaRedeemed, retry } from "../tasks";
32-
import { TransferState } from "../types";
33-
import { Wormhole } from "../wormhole";
34-
import type { WormholeTransfer } from "./wormholeTransfer";
30+
import { signSendWait } from "../common.js";
31+
import { fetchIbcXfer, isTokenBridgeVaaRedeemed, retry } from "../tasks.js";
32+
import { TransferState } from "../types.js";
33+
import { Wormhole } from "../wormhole.js";
34+
import type { WormholeTransfer } from "./wormholeTransfer.js";
3535

3636
type GatewayContext<N extends Network> = ChainContext<N, typeof GatewayTransfer.chain>;
3737

connect/src/protocols/tokenTransfer.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ import {
2525
toUniversal,
2626
universalAddress,
2727
} from "@wormhole-foundation/sdk-definitions";
28-
import { signSendWait } from "../common";
29-
import { DEFAULT_TASK_TIMEOUT } from "../config";
28+
import { signSendWait } from "../common.js";
29+
import { DEFAULT_TASK_TIMEOUT } from "../config.js";
3030
import type {
3131
AttestationReceipt,
3232
AttestedTransferReceipt,
@@ -35,11 +35,11 @@ import type {
3535
SourceInitiatedTransferReceipt,
3636
TransferQuote,
3737
TransferReceipt,
38-
} from "../types";
39-
import { TransferState, isAttested, isSourceFinalized, isSourceInitiated } from "../types";
40-
import { getGovernedTokens, getGovernorLimits } from "../whscan-api";
41-
import { Wormhole } from "../wormhole";
42-
import type { WormholeTransfer } from "./wormholeTransfer";
38+
} from "../types.js";
39+
import { TransferState, isAttested, isSourceFinalized, isSourceInitiated } from "../types.js";
40+
import { getGovernedTokens, getGovernorLimits } from "../whscan-api.js";
41+
import { Wormhole } from "../wormhole.js";
42+
import type { WormholeTransfer } from "./wormholeTransfer.js";
4343

4444
export type TokenTransferProtocol = "TokenBridge" | "AutomaticTokenBridge";
4545
export type TokenTransferVAA = TokenBridge.TransferVAA | AutomaticTokenBridge.VAA;

connect/src/protocols/wormholeTransfer.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@ import type {
99
TokenTransferDetails,
1010
TxHash,
1111
} from "@wormhole-foundation/sdk-definitions";
12-
import type { AttestationReceipt, TransferQuote, TransferReceipt, TransferState } from "../types";
13-
import type { Wormhole } from "../wormhole";
12+
import type {
13+
AttestationReceipt,
14+
TransferQuote,
15+
TransferReceipt,
16+
TransferState,
17+
} from "../types.js";
18+
import type { Wormhole } from "../wormhole.js";
1419

1520
export type TransferRequest<PN extends ProtocolName = ProtocolName> = PN extends
1621
| "TokenBridge"

connect/src/routes/cctp/automatic.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@ import type {
77
TokenId,
88
} from "@wormhole-foundation/sdk-definitions";
99
import { nativeTokenId } from "@wormhole-foundation/sdk-definitions";
10-
import type { CircleAttestationReceipt } from "../../protocols/cctpTransfer";
11-
import { CircleTransfer } from "../../protocols/cctpTransfer";
12-
import { TransferState } from "../../types";
13-
import type { StaticRouteMethods } from "../route";
14-
import { AutomaticRoute } from "../route";
10+
import type { CircleAttestationReceipt } from "../../protocols/cctpTransfer.js";
11+
import { CircleTransfer } from "../../protocols/cctpTransfer.js";
12+
import { TransferState } from "../../types.js";
13+
import type { StaticRouteMethods } from "../route.js";
14+
import { AutomaticRoute } from "../route.js";
1515
import type {
1616
Quote,
1717
QuoteResult,
1818
Receipt,
1919
TransferParams,
2020
ValidatedTransferParams,
2121
ValidationResult,
22-
} from "../types";
23-
import { Wormhole } from "../../wormhole";
22+
} from "../types.js";
23+
import { Wormhole } from "../../wormhole.js";
2424

2525
export namespace AutomaticCCTPRoute {
2626
export type Options = {

connect/src/routes/cctp/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export * from "./manual";
2-
export * from "./automatic";
1+
export * from "./manual.js";
2+
export * from "./automatic.js";

connect/src/routes/cctp/manual.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@ import type {
88
TransactionId,
99
} from "@wormhole-foundation/sdk-definitions";
1010
import { CircleBridge } from "@wormhole-foundation/sdk-definitions";
11-
import { signSendWait } from "../../common";
12-
import type { CircleAttestationReceipt } from "../../protocols/cctpTransfer";
13-
import { CircleTransfer } from "../../protocols/cctpTransfer";
14-
import type { TransferReceipt } from "../../types";
15-
import { TransferState, isAttested } from "../../types";
16-
import type { StaticRouteMethods } from "../route";
17-
import { ManualRoute } from "../route";
11+
import { signSendWait } from "../../common.js";
12+
import type { CircleAttestationReceipt } from "../../protocols/cctpTransfer.js";
13+
import { CircleTransfer } from "../../protocols/cctpTransfer.js";
14+
import type { TransferReceipt } from "../../types.js";
15+
import { TransferState, isAttested } from "../../types.js";
16+
import type { StaticRouteMethods } from "../route.js";
17+
import { ManualRoute } from "../route.js";
1818
import type {
1919
Quote,
2020
QuoteResult,
2121
TransferParams,
2222
ValidatedTransferParams,
2323
ValidationResult,
24-
} from "../types";
25-
import { Wormhole } from "../../wormhole";
24+
} from "../types.js";
25+
import { Wormhole } from "../../wormhole.js";
2626

2727
export namespace CCTPRoute {
2828
export type Options = {

connect/src/routes/common.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import type { Network } from "@wormhole-foundation/sdk-base";
22
import type { Signer } from "@wormhole-foundation/sdk-definitions";
3-
import type { Receipt } from "./types";
4-
import type { Route } from "./route";
5-
import { isManual } from "./route";
6-
import { TransferState, isAttested, isCompleted } from "../types";
3+
import type { Receipt } from "./types.js";
4+
import type { Route } from "./route.js";
5+
import { isManual } from "./route.js";
6+
import { TransferState, isAttested, isCompleted } from "../types.js";
77

88
/**
99
* track the transfer until the destination is initiated

0 commit comments

Comments
 (0)