Skip to content

Commit e848447

Browse files
feat: add dual cjs/esm exports to all public packages
- Update build configuration to support both CJS and ESM - Add dual export fields to package.json - Maintain backward compatibility - Update tsconfig for dual compilation Co-Authored-By: Connor Prussin <[email protected]>
1 parent ee557d2 commit e848447

35 files changed

+277
-104
lines changed

apps/hermes/client/js/package.json

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,17 @@
66
"name": "Pyth Data Association"
77
},
88
"homepage": "https://pyth.network",
9-
"main": "lib/HermesClient.js",
10-
"types": "lib/HermesClient.d.ts",
9+
"type": "module",
10+
"exports": {
11+
".": {
12+
"import": "./lib/HermesClient.js",
13+
"require": "./lib/cjs/HermesClient.js",
14+
"types": "./lib/HermesClient.d.ts"
15+
}
16+
},
17+
"main": "./lib/cjs/HermesClient.js",
18+
"module": "./lib/HermesClient.js",
19+
"types": "./lib/HermesClient.d.ts",
1120
"files": [
1221
"lib/**/*"
1322
],
@@ -20,13 +29,15 @@
2029
"access": "public"
2130
},
2231
"scripts": {
23-
"build:typescript": "tsc",
32+
"build": "pnpm run build:esm && pnpm run build:cjs",
33+
"build:esm": "tsc",
34+
"build:cjs": "tsc --module commonjs --outDir lib/cjs",
2435
"build:schemas": "openapi-zod-client ./schema.json --output src/zodSchemas.ts",
2536
"pull:schema": "curl -o schema.json -z schema.json https://hermes.pyth.network/docs/openapi.json",
2637
"example": "node lib/examples/HermesClient.js",
2738
"format": "prettier --write \"src/**/*.ts\"",
2839
"test:lint": "eslint src/",
29-
"prepublishOnly": "pnpm run build:typescript && pnpm run test:lint",
40+
"prepublishOnly": "pnpm run build && pnpm run test:lint",
3041
"preversion": "pnpm run test:lint",
3142
"version": "pnpm run format && git add -A src"
3243
},
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"module": "commonjs",
5+
"outDir": "./lib/cjs"
6+
}
7+
}

apps/hermes/client/js/tsconfig.json

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
{
22
"extends": "../../../../tsconfig.base.json",
33
"compilerOptions": {
4-
"target": "esnext",
5-
"module": "commonjs",
6-
"declaration": true,
7-
"composite": true,
8-
"declarationMap": true,
9-
"incremental": true,
10-
"outDir": "./lib",
11-
"strict": true,
124
"rootDir": "src/",
13-
"esModuleInterop": true
5+
"outDir": "./lib",
6+
"module": "node16",
7+
"moduleResolution": "node16"
148
},
159
"include": ["src"],
1610
"exclude": ["node_modules"]

apps/price_pusher/package.json

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,17 @@
33
"version": "9.0.0",
44
"description": "Pyth Price Pusher",
55
"homepage": "https://pyth.network",
6-
"main": "lib/index.js",
7-
"types": "lib/index.d.ts",
6+
"type": "module",
7+
"exports": {
8+
".": {
9+
"import": "./lib/index.js",
10+
"require": "./lib/cjs/index.js",
11+
"types": "./lib/index.d.ts"
12+
}
13+
},
14+
"main": "./lib/cjs/index.js",
15+
"module": "./lib/index.js",
16+
"types": "./lib/index.d.ts",
817
"files": [
918
"lib/**/*"
1019
],
@@ -20,10 +29,12 @@
2029
"access": "public"
2130
},
2231
"scripts": {
23-
"build": "tsc",
32+
"build": "pnpm run build:esm && pnpm run build:cjs",
33+
"build:esm": "tsc",
34+
"build:cjs": "tsc --module commonjs --outDir lib/cjs",
2435
"format": "prettier --write \"src/**/*.ts\"",
2536
"test:lint": "eslint src/",
26-
"start": "node lib/index.js",
37+
"start": "node lib/cjs/index.js",
2738
"dev": "ts-node src/index.ts",
2839
"prepublishOnly": "pnpm run build && pnpm run test:lint",
2940
"preversion": "pnpm run test:lint",

apps/price_pusher/tsconfig.cjs.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"module": "commonjs",
5+
"outDir": "./lib/cjs"
6+
}
7+
}

apps/price_pusher/tsconfig.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
{
22
"extends": "../../tsconfig.base.json",
33
"compilerOptions": {
4-
"target": "esnext",
5-
"module": "commonjs",
6-
"declaration": true,
74
"rootDir": "src/",
85
"outDir": "./lib",
9-
"strict": true,
10-
"esModuleInterop": true,
11-
"resolveJsonModule": true
6+
"module": "node16",
7+
"moduleResolution": "node16"
128
},
139
"include": ["src"],
1410
"exclude": ["node_modules", "**/__tests__/*"]

price_service/sdk/js/package.json

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,17 @@
33
"version": "1.8.0",
44
"description": "Pyth price service SDK",
55
"homepage": "https://pyth.network",
6-
"main": "lib/index.js",
7-
"types": "lib/index.d.ts",
6+
"type": "module",
7+
"exports": {
8+
".": {
9+
"import": "./lib/index.js",
10+
"require": "./lib/cjs/index.js",
11+
"types": "./lib/index.d.ts"
12+
}
13+
},
14+
"main": "./lib/cjs/index.js",
15+
"module": "./lib/index.js",
16+
"types": "./lib/index.d.ts",
817
"files": [
918
"lib/**/*"
1019
],
@@ -17,7 +26,9 @@
1726
"access": "public"
1827
},
1928
"scripts": {
20-
"build": "tsc",
29+
"build": "pnpm run build:esm && pnpm run build:cjs",
30+
"build:esm": "tsc",
31+
"build:cjs": "tsc --module commonjs --outDir lib/cjs",
2132
"format": "prettier --write \"src/**/*.ts\"",
2233
"gen-ts-schema": "quicktype --src-lang schema src/schemas/price_feed.json -o src/schemas/PriceFeed.ts --raw-type any --converters all-objects && prettier --write \"src/schemas/*.ts\"",
2334
"test:unit": "jest",

price_service/sdk/js/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
Price as JsonPrice,
44
PriceFeed as JsonPriceFeed,
55
PriceFeedMetadata as JsonPriceFeedMetadata,
6-
} from "./schemas/PriceFeed";
6+
} from "./schemas/PriceFeed.js";
77

88
export type UnixTimestamp = number;
99
export type DurationInSeconds = number;
@@ -16,7 +16,7 @@ export {
1616
AccumulatorUpdateData,
1717
parsePriceFeedMessage,
1818
parseTwapMessage,
19-
} from "./AccumulatorUpdateData";
19+
} from "./AccumulatorUpdateData.js";
2020

2121
/**
2222
* A Pyth Price represented as `${price} ± ${conf} * 10^${expo}` published at `publishTime`.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"module": "commonjs",
5+
"outDir": "./lib/cjs"
6+
}
7+
}

price_service/sdk/js/tsconfig.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
{
22
"extends": "../../../tsconfig.base.json",
3-
"include": ["src"],
4-
"exclude": ["node_modules", "**/__tests__/*"],
53
"compilerOptions": {
64
"rootDir": "src/",
7-
"outDir": "./lib"
8-
}
5+
"outDir": "./lib",
6+
"module": "node16",
7+
"moduleResolution": "node16"
8+
},
9+
"include": ["src"],
10+
"exclude": ["node_modules", "**/__tests__/*"]
911
}

target_chains/aptos/sdk/js/package.json

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,17 @@
66
"author": {
77
"name": "Pyth Data Association"
88
},
9-
"main": "lib/index.js",
10-
"types": "lib/index.d.ts",
9+
"type": "module",
10+
"exports": {
11+
".": {
12+
"import": "./lib/index.js",
13+
"require": "./lib/cjs/index.js",
14+
"types": "./lib/index.d.ts"
15+
}
16+
},
17+
"main": "./lib/cjs/index.js",
18+
"module": "./lib/index.js",
19+
"types": "./lib/index.d.ts",
1120
"files": [
1221
"lib/**/*"
1322
],
@@ -20,7 +29,9 @@
2029
"access": "public"
2130
},
2231
"scripts": {
23-
"build": "tsc",
32+
"build": "pnpm run build:esm && pnpm run build:cjs",
33+
"build:esm": "tsc",
34+
"build:cjs": "tsc --module commonjs --outDir lib/cjs",
2435
"example-relay": "pnpm run build && node lib/examples/AptosRelay.js",
2536
"format": "prettier --write \"src/**/*.ts\"",
2637
"test:lint": "eslint src/",
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"module": "commonjs",
5+
"outDir": "./lib/cjs"
6+
}
7+
}

target_chains/aptos/sdk/js/tsconfig.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
{
22
"extends": "../../../../tsconfig.base.json",
33
"compilerOptions": {
4-
"target": "esnext",
5-
"module": "commonjs",
6-
"declaration": true,
7-
"outDir": "./lib",
84
"rootDir": "src/",
9-
"strict": true,
10-
"esModuleInterop": true
5+
"outDir": "./lib",
6+
"module": "node16",
7+
"moduleResolution": "node16"
118
},
129
"include": ["src"],
1310
"exclude": ["node_modules", "**/__tests__/*"]

target_chains/ethereum/sdk/js/package.json

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,17 @@
66
"author": {
77
"name": "Pyth Data Association"
88
},
9-
"main": "lib/index.js",
10-
"types": "lib/index.d.ts",
9+
"type": "module",
10+
"exports": {
11+
".": {
12+
"import": "./lib/index.js",
13+
"require": "./lib/cjs/index.js",
14+
"types": "./lib/index.d.ts"
15+
}
16+
},
17+
"main": "./lib/cjs/index.js",
18+
"module": "./lib/index.js",
19+
"types": "./lib/index.d.ts",
1120
"files": [
1221
"lib/**/*"
1322
],
@@ -20,7 +29,9 @@
2029
"access": "public"
2130
},
2231
"scripts": {
23-
"build": "tsc",
32+
"build": "pnpm run build:esm && pnpm run build:cjs",
33+
"build:esm": "tsc",
34+
"build:cjs": "tsc --module commonjs --outDir lib/cjs",
2435
"example-client": "pnpm run build && node lib/examples/EvmPriceServiceClient.js",
2536
"example-relay": "pnpm run build && node lib/examples/EvmRelay.js",
2637
"example-benchmark": "pnpm run build && node lib/examples/EvmBenchmark.js",
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"module": "commonjs",
5+
"outDir": "./lib/cjs"
6+
}
7+
}

target_chains/ethereum/sdk/js/tsconfig.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
{
22
"extends": "../../../../tsconfig.base.json",
33
"compilerOptions": {
4-
"target": "esnext",
5-
"module": "commonjs",
6-
"declaration": true,
74
"rootDir": "src/",
85
"outDir": "./lib",
9-
"strict": true,
10-
"esModuleInterop": true,
11-
"resolveJsonModule": true
6+
"module": "node16",
7+
"moduleResolution": "node16"
128
},
139
"include": ["src"],
1410
"exclude": ["node_modules", "**/__tests__/*"]

target_chains/fuel/sdk/js/package.json

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,17 @@
66
"author": {
77
"name": "Pyth Data Association"
88
},
9-
"main": "lib/index.js",
10-
"types": "lib/index.d.ts",
9+
"type": "module",
10+
"exports": {
11+
".": {
12+
"import": "./lib/index.js",
13+
"require": "./lib/cjs/index.js",
14+
"types": "./lib/index.d.ts"
15+
}
16+
},
17+
"main": "./lib/cjs/index.js",
18+
"module": "./lib/index.js",
19+
"types": "./lib/index.d.ts",
1120
"files": [
1221
"lib/**/*"
1322
],
@@ -21,7 +30,9 @@
2130
},
2231
"scripts": {
2332
"usage-example": "ts-node src/examples/usage.ts",
24-
"build": "pnpm run generate-fuel-types && tsc && copyfiles -u 1 \"src/**/*.d.ts\" lib",
33+
"build": "pnpm run generate-fuel-types && pnpm run build:esm && pnpm run build:cjs",
34+
"build:esm": "tsc && copyfiles -u 1 \"src/**/*.d.ts\" lib",
35+
"build:cjs": "tsc --module commonjs --outDir lib/cjs",
2536
"test:format": "prettier --check \"src/**/*.ts\"",
2637
"fix:format": "prettier --write \"src/**/*.ts\"",
2738
"test:lint": "eslint src/",
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"module": "commonjs",
5+
"outDir": "./lib/cjs"
6+
}
7+
}

target_chains/fuel/sdk/js/tsconfig.json

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
{
22
"extends": "../../../../tsconfig.base.json",
33
"compilerOptions": {
4-
"target": "esnext",
5-
"module": "commonjs",
6-
"declaration": true,
7-
"outDir": "./lib",
84
"rootDir": "src/",
9-
"strict": true,
10-
"esModuleInterop": true,
11-
"resolveJsonModule": true
5+
"outDir": "./lib",
6+
"module": "node16",
7+
"moduleResolution": "node16"
128
},
139
"include": ["src", "src/**/*.json"],
1410
"exclude": ["node_modules", "**/__tests__/*"]

target_chains/solana/sdk/js/pyth_solana_receiver/package.json

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,17 @@
33
"version": "0.9.1",
44
"description": "Pyth solana receiver SDK",
55
"homepage": "https://pyth.network",
6-
"main": "lib/index.js",
7-
"types": "lib/index.d.ts",
6+
"type": "module",
7+
"exports": {
8+
".": {
9+
"import": "./lib/index.js",
10+
"require": "./lib/cjs/index.js",
11+
"types": "./lib/index.d.ts"
12+
}
13+
},
14+
"main": "./lib/cjs/index.js",
15+
"module": "./lib/index.js",
16+
"types": "./lib/index.d.ts",
817
"files": [
918
"lib/**/*"
1019
],
@@ -17,7 +26,9 @@
1726
"access": "public"
1827
},
1928
"scripts": {
20-
"build": "tsc",
29+
"build": "pnpm run build:esm && pnpm run build:cjs",
30+
"build:esm": "tsc",
31+
"build:cjs": "tsc --module commonjs --outDir lib/cjs",
2132
"format": "prettier --write \"src/**/*.ts\"",
2233
"test:lint": "eslint src/",
2334
"prepublishOnly": "pnpm run build && pnpm test:lint",

0 commit comments

Comments
 (0)