From 0794387925e1770dbdd0658079bf5caa9d80dc0a Mon Sep 17 00:00:00 2001 From: eddie <66155195+just-toby@users.noreply.github.com> Date: Fri, 13 Dec 2024 11:21:09 -0500 Subject: [PATCH] feat(universal-router-sdk): separate esm / cjs builds --- sdks/universal-router-sdk/package.json | 22 +++++++++++++---- .../src/entities/actions/unwrapWETH.ts | 2 +- sdks/universal-router-sdk/src/index.ts | 24 +++++-------------- sdks/universal-router-sdk/tsconfig.base.json | 18 ++++++++++++++ sdks/universal-router-sdk/tsconfig.cjs.json | 7 ++++++ sdks/universal-router-sdk/tsconfig.esm.json | 7 ++++++ sdks/universal-router-sdk/tsconfig.json | 17 ------------- sdks/universal-router-sdk/tsconfig.types.json | 8 +++++++ yarn.lock | 1 - 9 files changed, 64 insertions(+), 42 deletions(-) create mode 100644 sdks/universal-router-sdk/tsconfig.base.json create mode 100644 sdks/universal-router-sdk/tsconfig.cjs.json create mode 100644 sdks/universal-router-sdk/tsconfig.esm.json delete mode 100644 sdks/universal-router-sdk/tsconfig.json create mode 100644 sdks/universal-router-sdk/tsconfig.types.json diff --git a/sdks/universal-router-sdk/package.json b/sdks/universal-router-sdk/package.json index b9370540a..8b7263f7e 100644 --- a/sdks/universal-router-sdk/package.json +++ b/sdks/universal-router-sdk/package.json @@ -7,8 +7,9 @@ "ethereum" ], "license": "MIT", - "main": "dist/index.js", - "typings": "dist/index.d.ts", + "main": "./dist/cjs/src/index.js", + "module": "./dist/esm/src/index.js", + "types": "./dist/types/src/index.d.ts", "files": [ "dist" ], @@ -16,7 +17,11 @@ "node": ">=14" }, "scripts": { - "build": "tsdx build", + "clean": "rm -rf dist", + "build": "yarn clean && yarn build:cjs && yarn build:esm && yarn build:types", + "build:cjs": "tsc -p tsconfig.cjs.json", + "build:esm": "tsc -p tsconfig.esm.json", + "build:types": "tsc -p tsconfig.types.json", "docs": "typedoc", "forge:fix": "forge fmt", "lint": "yarn prettier", @@ -53,7 +58,6 @@ "hardhat": "^2.22.15", "prettier": "^2.4.1", "ts-node": "^10.9.1", - "tsdx": "^0.14.1", "tslib": "^2.3.0", "typedoc": "^0.21.2", "typescript": "^4.3.3" @@ -99,5 +103,13 @@ }, "installConfig": { "hoistingLimits": "workspaces" - } + }, + "exports": { + ".": { + "types": "./dist/types/src/index.d.ts", + "import": "./dist/esm/src/index.js", + "require": "./dist/cjs/src/index.js" + } + }, + "sideEffects": false } diff --git a/sdks/universal-router-sdk/src/entities/actions/unwrapWETH.ts b/sdks/universal-router-sdk/src/entities/actions/unwrapWETH.ts index e0a03cbb4..bf3dde2f7 100644 --- a/sdks/universal-router-sdk/src/entities/actions/unwrapWETH.ts +++ b/sdks/universal-router-sdk/src/entities/actions/unwrapWETH.ts @@ -7,9 +7,9 @@ import { ROUTER_AS_RECIPIENT, WETH_ADDRESS } from '../../utils/constants' export class UnwrapWETH implements Command { readonly tradeType: RouterActionType = RouterActionType.UnwrapWETH - readonly permit2Data: Permit2Permit readonly wethAddress: string readonly amount: BigNumberish + readonly permit2Data?: Permit2Permit constructor(amount: BigNumberish, chainId: number, permit2?: Permit2Permit) { this.wethAddress = WETH_ADDRESS(chainId) diff --git a/sdks/universal-router-sdk/src/index.ts b/sdks/universal-router-sdk/src/index.ts index 3144a420f..566671ab9 100644 --- a/sdks/universal-router-sdk/src/index.ts +++ b/sdks/universal-router-sdk/src/index.ts @@ -1,15 +1,9 @@ -export { SwapRouter, MigrateV3ToV4Options } from './swapRouter' +export { SwapRouter } from './swapRouter' +export type { MigrateV3ToV4Options } from './swapRouter' export * from './entities' export * from './utils/routerTradeAdapter' -export { - RoutePlanner, - CommandType, - COMMAND_DEFINITION, - CommandDefinition, - Parser, - Subparser, - ParamType, -} from './utils/routerCommands' +export { RoutePlanner, CommandType, COMMAND_DEFINITION, Parser, Subparser } from './utils/routerCommands' +export type { CommandDefinition, ParamType } from './utils/routerCommands' export { UNIVERSAL_ROUTER_CREATION_BLOCK, UNIVERSAL_ROUTER_ADDRESS, @@ -17,11 +11,5 @@ export { WETH_ADDRESS, UniversalRouterVersion, } from './utils/constants' -export { - CommandParser, - GenericCommandParser, - UniversalRouterCommand, - UniversalRouterCall, - Param, - CommandsDefinition, -} from './utils/commandParser' +export { CommandParser, GenericCommandParser } from './utils/commandParser' +export type { UniversalRouterCommand, UniversalRouterCall, Param, CommandsDefinition } from './utils/commandParser' diff --git a/sdks/universal-router-sdk/tsconfig.base.json b/sdks/universal-router-sdk/tsconfig.base.json new file mode 100644 index 000000000..88aa2dd18 --- /dev/null +++ b/sdks/universal-router-sdk/tsconfig.base.json @@ -0,0 +1,18 @@ +{ + "include": ["src"], + "compilerOptions": { + "rootDir": ".", + "baseUrl": ".", + "target": "es6", + "module": "esnext", + "importHelpers": true, + "declaration": true, + "sourceMap": true, + "strict": true, + "moduleResolution": "node", + "resolveJsonModule": true, + "esModuleInterop": true, + "skipLibCheck": true, + "isolatedModules": true + } +} diff --git a/sdks/universal-router-sdk/tsconfig.cjs.json b/sdks/universal-router-sdk/tsconfig.cjs.json new file mode 100644 index 000000000..6dd12e73e --- /dev/null +++ b/sdks/universal-router-sdk/tsconfig.cjs.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.base.json", + "compilerOptions": { + "module": "commonjs", + "outDir": "dist/cjs" + } +} diff --git a/sdks/universal-router-sdk/tsconfig.esm.json b/sdks/universal-router-sdk/tsconfig.esm.json new file mode 100644 index 000000000..d714016a5 --- /dev/null +++ b/sdks/universal-router-sdk/tsconfig.esm.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.base.json", + "compilerOptions": { + "module": "esnext", + "outDir": "dist/esm" + } +} diff --git a/sdks/universal-router-sdk/tsconfig.json b/sdks/universal-router-sdk/tsconfig.json deleted file mode 100644 index 3e5889420..000000000 --- a/sdks/universal-router-sdk/tsconfig.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "compilerOptions": { - "target": "es2018", - "module": "esnext", - "moduleResolution": "node", - "strict": true, - "esModuleInterop": true, - "strictPropertyInitialization": false, - "resolveJsonModule": true, - "outDir": "dist", - "noUnusedLocals": true, - "noUnusedParameters": true, - "lib": ["esnext.string"], - "types": ["@types/mocha", "node"] - }, - "include": ["src", "test"] -} diff --git a/sdks/universal-router-sdk/tsconfig.types.json b/sdks/universal-router-sdk/tsconfig.types.json new file mode 100644 index 000000000..71c5d16ed --- /dev/null +++ b/sdks/universal-router-sdk/tsconfig.types.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig.base.json", + "compilerOptions": { + "declaration": true, + "emitDeclarationOnly": true, + "outDir": "dist/types" + } +} diff --git a/yarn.lock b/yarn.lock index 79df8ce97..1f63328fd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4663,7 +4663,6 @@ __metadata: hardhat: ^2.22.15 prettier: ^2.4.1 ts-node: ^10.9.1 - tsdx: ^0.14.1 tslib: ^2.3.0 typedoc: ^0.21.2 typescript: ^4.3.3