Skip to content

Commit

Permalink
feat: add dual cjs/esm exports to all public packages
Browse files Browse the repository at this point in the history
- 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]>
  • Loading branch information
devin-ai-integration[bot] and cprussin committed Feb 13, 2025
1 parent ee557d2 commit e848447
Show file tree
Hide file tree
Showing 35 changed files with 277 additions and 104 deletions.
19 changes: 15 additions & 4 deletions apps/hermes/client/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,17 @@
"name": "Pyth Data Association"
},
"homepage": "https://pyth.network",
"main": "lib/HermesClient.js",
"types": "lib/HermesClient.d.ts",
"type": "module",
"exports": {
".": {
"import": "./lib/HermesClient.js",
"require": "./lib/cjs/HermesClient.js",
"types": "./lib/HermesClient.d.ts"
}
},
"main": "./lib/cjs/HermesClient.js",
"module": "./lib/HermesClient.js",
"types": "./lib/HermesClient.d.ts",
"files": [
"lib/**/*"
],
Expand All @@ -20,13 +29,15 @@
"access": "public"
},
"scripts": {
"build:typescript": "tsc",
"build": "pnpm run build:esm && pnpm run build:cjs",
"build:esm": "tsc",
"build:cjs": "tsc --module commonjs --outDir lib/cjs",
"build:schemas": "openapi-zod-client ./schema.json --output src/zodSchemas.ts",
"pull:schema": "curl -o schema.json -z schema.json https://hermes.pyth.network/docs/openapi.json",
"example": "node lib/examples/HermesClient.js",
"format": "prettier --write \"src/**/*.ts\"",
"test:lint": "eslint src/",
"prepublishOnly": "pnpm run build:typescript && pnpm run test:lint",
"prepublishOnly": "pnpm run build && pnpm run test:lint",
"preversion": "pnpm run test:lint",
"version": "pnpm run format && git add -A src"
},
Expand Down
7 changes: 7 additions & 0 deletions apps/hermes/client/js/tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "./lib/cjs"
}
}
12 changes: 3 additions & 9 deletions apps/hermes/client/js/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
{
"extends": "../../../../tsconfig.base.json",
"compilerOptions": {
"target": "esnext",
"module": "commonjs",
"declaration": true,
"composite": true,
"declarationMap": true,
"incremental": true,
"outDir": "./lib",
"strict": true,
"rootDir": "src/",
"esModuleInterop": true
"outDir": "./lib",
"module": "node16",
"moduleResolution": "node16"
},
"include": ["src"],
"exclude": ["node_modules"]
Expand Down
19 changes: 15 additions & 4 deletions apps/price_pusher/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,17 @@
"version": "9.0.0",
"description": "Pyth Price Pusher",
"homepage": "https://pyth.network",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"type": "module",
"exports": {
".": {
"import": "./lib/index.js",
"require": "./lib/cjs/index.js",
"types": "./lib/index.d.ts"
}
},
"main": "./lib/cjs/index.js",
"module": "./lib/index.js",
"types": "./lib/index.d.ts",
"files": [
"lib/**/*"
],
Expand All @@ -20,10 +29,12 @@
"access": "public"
},
"scripts": {
"build": "tsc",
"build": "pnpm run build:esm && pnpm run build:cjs",
"build:esm": "tsc",
"build:cjs": "tsc --module commonjs --outDir lib/cjs",
"format": "prettier --write \"src/**/*.ts\"",
"test:lint": "eslint src/",
"start": "node lib/index.js",
"start": "node lib/cjs/index.js",
"dev": "ts-node src/index.ts",
"prepublishOnly": "pnpm run build && pnpm run test:lint",
"preversion": "pnpm run test:lint",
Expand Down
7 changes: 7 additions & 0 deletions apps/price_pusher/tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "./lib/cjs"
}
}
8 changes: 2 additions & 6 deletions apps/price_pusher/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"target": "esnext",
"module": "commonjs",
"declaration": true,
"rootDir": "src/",
"outDir": "./lib",
"strict": true,
"esModuleInterop": true,
"resolveJsonModule": true
"module": "node16",
"moduleResolution": "node16"
},
"include": ["src"],
"exclude": ["node_modules", "**/__tests__/*"]
Expand Down
17 changes: 14 additions & 3 deletions price_service/sdk/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,17 @@
"version": "1.8.0",
"description": "Pyth price service SDK",
"homepage": "https://pyth.network",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"type": "module",
"exports": {
".": {
"import": "./lib/index.js",
"require": "./lib/cjs/index.js",
"types": "./lib/index.d.ts"
}
},
"main": "./lib/cjs/index.js",
"module": "./lib/index.js",
"types": "./lib/index.d.ts",
"files": [
"lib/**/*"
],
Expand All @@ -17,7 +26,9 @@
"access": "public"
},
"scripts": {
"build": "tsc",
"build": "pnpm run build:esm && pnpm run build:cjs",
"build:esm": "tsc",
"build:cjs": "tsc --module commonjs --outDir lib/cjs",
"format": "prettier --write \"src/**/*.ts\"",
"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\"",
"test:unit": "jest",
Expand Down
4 changes: 2 additions & 2 deletions price_service/sdk/js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
Price as JsonPrice,
PriceFeed as JsonPriceFeed,
PriceFeedMetadata as JsonPriceFeedMetadata,
} from "./schemas/PriceFeed";
} from "./schemas/PriceFeed.js";

export type UnixTimestamp = number;
export type DurationInSeconds = number;
Expand All @@ -16,7 +16,7 @@ export {
AccumulatorUpdateData,
parsePriceFeedMessage,
parseTwapMessage,
} from "./AccumulatorUpdateData";
} from "./AccumulatorUpdateData.js";

/**
* A Pyth Price represented as `${price} ± ${conf} * 10^${expo}` published at `publishTime`.
Expand Down
7 changes: 7 additions & 0 deletions price_service/sdk/js/tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "./lib/cjs"
}
}
10 changes: 6 additions & 4 deletions price_service/sdk/js/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"extends": "../../../tsconfig.base.json",
"include": ["src"],
"exclude": ["node_modules", "**/__tests__/*"],
"compilerOptions": {
"rootDir": "src/",
"outDir": "./lib"
}
"outDir": "./lib",
"module": "node16",
"moduleResolution": "node16"
},
"include": ["src"],
"exclude": ["node_modules", "**/__tests__/*"]
}
17 changes: 14 additions & 3 deletions target_chains/aptos/sdk/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,17 @@
"author": {
"name": "Pyth Data Association"
},
"main": "lib/index.js",
"types": "lib/index.d.ts",
"type": "module",
"exports": {
".": {
"import": "./lib/index.js",
"require": "./lib/cjs/index.js",
"types": "./lib/index.d.ts"
}
},
"main": "./lib/cjs/index.js",
"module": "./lib/index.js",
"types": "./lib/index.d.ts",
"files": [
"lib/**/*"
],
Expand All @@ -20,7 +29,9 @@
"access": "public"
},
"scripts": {
"build": "tsc",
"build": "pnpm run build:esm && pnpm run build:cjs",
"build:esm": "tsc",
"build:cjs": "tsc --module commonjs --outDir lib/cjs",
"example-relay": "pnpm run build && node lib/examples/AptosRelay.js",
"format": "prettier --write \"src/**/*.ts\"",
"test:lint": "eslint src/",
Expand Down
7 changes: 7 additions & 0 deletions target_chains/aptos/sdk/js/tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "./lib/cjs"
}
}
9 changes: 3 additions & 6 deletions target_chains/aptos/sdk/js/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
{
"extends": "../../../../tsconfig.base.json",
"compilerOptions": {
"target": "esnext",
"module": "commonjs",
"declaration": true,
"outDir": "./lib",
"rootDir": "src/",
"strict": true,
"esModuleInterop": true
"outDir": "./lib",
"module": "node16",
"moduleResolution": "node16"
},
"include": ["src"],
"exclude": ["node_modules", "**/__tests__/*"]
Expand Down
17 changes: 14 additions & 3 deletions target_chains/ethereum/sdk/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,17 @@
"author": {
"name": "Pyth Data Association"
},
"main": "lib/index.js",
"types": "lib/index.d.ts",
"type": "module",
"exports": {
".": {
"import": "./lib/index.js",
"require": "./lib/cjs/index.js",
"types": "./lib/index.d.ts"
}
},
"main": "./lib/cjs/index.js",
"module": "./lib/index.js",
"types": "./lib/index.d.ts",
"files": [
"lib/**/*"
],
Expand All @@ -20,7 +29,9 @@
"access": "public"
},
"scripts": {
"build": "tsc",
"build": "pnpm run build:esm && pnpm run build:cjs",
"build:esm": "tsc",
"build:cjs": "tsc --module commonjs --outDir lib/cjs",
"example-client": "pnpm run build && node lib/examples/EvmPriceServiceClient.js",
"example-relay": "pnpm run build && node lib/examples/EvmRelay.js",
"example-benchmark": "pnpm run build && node lib/examples/EvmBenchmark.js",
Expand Down
7 changes: 7 additions & 0 deletions target_chains/ethereum/sdk/js/tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "./lib/cjs"
}
}
8 changes: 2 additions & 6 deletions target_chains/ethereum/sdk/js/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
{
"extends": "../../../../tsconfig.base.json",
"compilerOptions": {
"target": "esnext",
"module": "commonjs",
"declaration": true,
"rootDir": "src/",
"outDir": "./lib",
"strict": true,
"esModuleInterop": true,
"resolveJsonModule": true
"module": "node16",
"moduleResolution": "node16"
},
"include": ["src"],
"exclude": ["node_modules", "**/__tests__/*"]
Expand Down
17 changes: 14 additions & 3 deletions target_chains/fuel/sdk/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,17 @@
"author": {
"name": "Pyth Data Association"
},
"main": "lib/index.js",
"types": "lib/index.d.ts",
"type": "module",
"exports": {
".": {
"import": "./lib/index.js",
"require": "./lib/cjs/index.js",
"types": "./lib/index.d.ts"
}
},
"main": "./lib/cjs/index.js",
"module": "./lib/index.js",
"types": "./lib/index.d.ts",
"files": [
"lib/**/*"
],
Expand All @@ -21,7 +30,9 @@
},
"scripts": {
"usage-example": "ts-node src/examples/usage.ts",
"build": "pnpm run generate-fuel-types && tsc && copyfiles -u 1 \"src/**/*.d.ts\" lib",
"build": "pnpm run generate-fuel-types && pnpm run build:esm && pnpm run build:cjs",
"build:esm": "tsc && copyfiles -u 1 \"src/**/*.d.ts\" lib",
"build:cjs": "tsc --module commonjs --outDir lib/cjs",
"test:format": "prettier --check \"src/**/*.ts\"",
"fix:format": "prettier --write \"src/**/*.ts\"",
"test:lint": "eslint src/",
Expand Down
7 changes: 7 additions & 0 deletions target_chains/fuel/sdk/js/tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "./lib/cjs"
}
}
10 changes: 3 additions & 7 deletions target_chains/fuel/sdk/js/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
{
"extends": "../../../../tsconfig.base.json",
"compilerOptions": {
"target": "esnext",
"module": "commonjs",
"declaration": true,
"outDir": "./lib",
"rootDir": "src/",
"strict": true,
"esModuleInterop": true,
"resolveJsonModule": true
"outDir": "./lib",
"module": "node16",
"moduleResolution": "node16"
},
"include": ["src", "src/**/*.json"],
"exclude": ["node_modules", "**/__tests__/*"]
Expand Down
17 changes: 14 additions & 3 deletions target_chains/solana/sdk/js/pyth_solana_receiver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,17 @@
"version": "0.9.1",
"description": "Pyth solana receiver SDK",
"homepage": "https://pyth.network",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"type": "module",
"exports": {
".": {
"import": "./lib/index.js",
"require": "./lib/cjs/index.js",
"types": "./lib/index.d.ts"
}
},
"main": "./lib/cjs/index.js",
"module": "./lib/index.js",
"types": "./lib/index.d.ts",
"files": [
"lib/**/*"
],
Expand All @@ -17,7 +26,9 @@
"access": "public"
},
"scripts": {
"build": "tsc",
"build": "pnpm run build:esm && pnpm run build:cjs",
"build:esm": "tsc",
"build:cjs": "tsc --module commonjs --outDir lib/cjs",
"format": "prettier --write \"src/**/*.ts\"",
"test:lint": "eslint src/",
"prepublishOnly": "pnpm run build && pnpm test:lint",
Expand Down
Loading

0 comments on commit e848447

Please sign in to comment.