From 37a6202afdddf7db26ca27478a78c3ed8b3ecde3 Mon Sep 17 00:00:00 2001 From: "zaid.arain" Date: Thu, 5 Dec 2024 15:56:46 +1100 Subject: [PATCH] clean up and fix sdk bundling --- packages/blockchain-data/sdk/package.json | 2 +- packages/checkout/sdk/package.json | 2 +- packages/checkout/widgets-lib/package.json | 2 +- packages/config/package.json | 2 +- packages/internal/bridge/sdk/package.json | 2 +- packages/internal/cryptofiat/package.json | 2 +- packages/internal/dex/sdk/package.json | 2 +- .../internal/generated-clients/package.json | 2 +- packages/internal/toolkit/package.json | 2 +- packages/minting-backend/sdk/package.json | 2 +- packages/orderbook/package.json | 2 +- packages/passport/sdk/package.json | 2 +- packages/webhook/sdk/package.json | 2 +- packages/x-client/package.json | 2 +- packages/x-provider/package.json | 2 +- sdk/package.json | 3 +- sdk/tsup.config.js | 36 ++++++------------- 17 files changed, 27 insertions(+), 42 deletions(-) diff --git a/packages/blockchain-data/sdk/package.json b/packages/blockchain-data/sdk/package.json index a629141328..e1108a78b2 100644 --- a/packages/blockchain-data/sdk/package.json +++ b/packages/blockchain-data/sdk/package.json @@ -45,7 +45,7 @@ "scripts": { "build": "pnpm transpile && pnpm typegen", "transpile": "tsup src/index.ts --config ../../../tsup.config.js", - "typegen": "tsc --customConditions default --emitDeclarationOnly --outDir dist/types", + "typegen": "tsc --customConditions default --emitDeclarationOnly --outDir dist/types", "lint": "eslint ./src --ext .ts,.jsx,.tsx --max-warnings=0", "test": "jest", "test:watch": "jest --watch", diff --git a/packages/checkout/sdk/package.json b/packages/checkout/sdk/package.json index c039de96e2..89ccb8de17 100644 --- a/packages/checkout/sdk/package.json +++ b/packages/checkout/sdk/package.json @@ -65,7 +65,7 @@ "scripts": { "build": "pnpm transpile && pnpm typegen", "transpile": "tsup src/index.ts --config ./tsup.config.js", - "typegen": "tsc --customConditions default --emitDeclarationOnly --outDir dist/types", + "typegen": "tsc --customConditions default --emitDeclarationOnly --outDir dist/types", "build:dev": "CHECKOUT_DEV_MODE=true pnpm build", "docs": "typedoc --plugin typedoc-plugin-markdown --skipErrorChecking --disableSources --out docs src/index.ts", "lint": "eslint ./src --ext .ts,.jsx,.tsx --max-warnings=0", diff --git a/packages/checkout/widgets-lib/package.json b/packages/checkout/widgets-lib/package.json index f73c25210f..1446031087 100644 --- a/packages/checkout/widgets-lib/package.json +++ b/packages/checkout/widgets-lib/package.json @@ -98,7 +98,7 @@ "scripts": { "build": "pnpm transpile && pnpm typegen", "transpile": "tsup src/index.ts --config ./tsup.config.js", - "typegen": "tsc --customConditions default --emitDeclarationOnly --outDir dist/types", + "typegen": "tsc --customConditions default --emitDeclarationOnly --outDir dist/types", "build:local": "pnpm build && mkdir -p ../widgets-sample-app/public/lib/js && cp dist/*.js ../widgets-sample-app/public/lib/js/", "lint": "eslint ./src --ext .ts,.jsx,.tsx --max-warnings=0", "lint:fix": "eslint ./src --ext .ts,.jsx,.tsx --max-warnings=0 --fix", diff --git a/packages/config/package.json b/packages/config/package.json index 787a1ef4c3..a30122b399 100644 --- a/packages/config/package.json +++ b/packages/config/package.json @@ -51,7 +51,7 @@ "scripts": { "build": "pnpm transpile && pnpm typegen", "transpile": "tsup src/index.ts --config ../../tsup.config.js", - "typegen": "tsc --customConditions default --emitDeclarationOnly --outDir dist/types", + "typegen": "tsc --customConditions default --emitDeclarationOnly --outDir dist/types", "lint": "eslint ./src --ext .ts,.jsx,.tsx --max-warnings=0", "test": "jest", "test:watch": "jest --watch", diff --git a/packages/internal/bridge/sdk/package.json b/packages/internal/bridge/sdk/package.json index fe833c2409..9c2b32e6bc 100644 --- a/packages/internal/bridge/sdk/package.json +++ b/packages/internal/bridge/sdk/package.json @@ -56,7 +56,7 @@ "scripts": { "build": "pnpm transpile && pnpm typegen", "transpile": "tsup src/index.ts --config ../../../../tsup.config.js", - "typegen": "tsc --customConditions default --emitDeclarationOnly --outDir dist/types", + "typegen": "tsc --customConditions default --emitDeclarationOnly --outDir dist/types", "lint": "eslint ./src --ext .ts --max-warnings=0", "lint:fix": "cd ../../../../ && pnpm wsrun -p @imtbl/bridge-sdk -c lint --fix", "test": "jest test -- --silent=false", diff --git a/packages/internal/cryptofiat/package.json b/packages/internal/cryptofiat/package.json index 4248e53c57..a5bb33e4bb 100644 --- a/packages/internal/cryptofiat/package.json +++ b/packages/internal/cryptofiat/package.json @@ -55,7 +55,7 @@ "scripts": { "build": "pnpm transpile && pnpm typegen", "transpile": "tsup src/index.ts --config ../../../tsup.config.js", - "typegen": "tsc --customConditions default --emitDeclarationOnly --outDir dist/types", + "typegen": "tsc --customConditions default --emitDeclarationOnly --outDir dist/types", "lint": "eslint ./src --ext .ts,.jsx,.tsx --max-warnings=0 --fix", "test": "jest", "test:watch": "jest --watch", diff --git a/packages/internal/dex/sdk/package.json b/packages/internal/dex/sdk/package.json index 6697dc217d..363272fe15 100644 --- a/packages/internal/dex/sdk/package.json +++ b/packages/internal/dex/sdk/package.json @@ -63,7 +63,7 @@ "scripts": { "build": "pnpm transpile && pnpm typegen", "transpile": "tsup src/index.ts --config ../../../../tsup.config.js", - "typegen": "tsc --customConditions default --emitDeclarationOnly --outDir dist/types", + "typegen": "tsc --customConditions default --emitDeclarationOnly --outDir dist/types", "generate-types": "typechain --target ethers-v5 --out-dir ./src/contracts/types ./src/contracts/ABIs/*.json", "lint": "eslint ./src --ext .ts --max-warnings=0", "lint:fix": "cd ../../../.. && pnpm wsrun -p @imtbl/dex-sdk -c lint --fix", diff --git a/packages/internal/generated-clients/package.json b/packages/internal/generated-clients/package.json index f4b8b1ef0a..50dba0b667 100644 --- a/packages/internal/generated-clients/package.json +++ b/packages/internal/generated-clients/package.json @@ -46,7 +46,7 @@ "scripts": { "build": "pnpm transpile && pnpm typegen", "transpile": "tsup src/index.ts --config ../../../tsup.config.js", - "typegen": "tsc --customConditions default --emitDeclarationOnly --outDir dist/types", + "typegen": "tsc --customConditions default --emitDeclarationOnly --outDir dist/types", "test": "jest", "test:watch": "jest --watch", "typecheck": "tsc --customConditions default --noEmit --jsx preserve", diff --git a/packages/internal/toolkit/package.json b/packages/internal/toolkit/package.json index d2ef925b01..36fac7e9ba 100644 --- a/packages/internal/toolkit/package.json +++ b/packages/internal/toolkit/package.json @@ -66,7 +66,7 @@ "scripts": { "build": "pnpm transpile && pnpm typegen", "transpile": "tsup src/index.ts --config ../../../tsup.config.js", - "typegen": "tsc --customConditions default --emitDeclarationOnly --outDir dist/types", + "typegen": "tsc --customConditions default --emitDeclarationOnly --outDir dist/types", "lint": "eslint ./src --ext .ts,.jsx,.tsx --max-warnings=0", "test": "jest", "test:watch": "jest --watch", diff --git a/packages/minting-backend/sdk/package.json b/packages/minting-backend/sdk/package.json index bae928e872..dbaf217e5f 100644 --- a/packages/minting-backend/sdk/package.json +++ b/packages/minting-backend/sdk/package.json @@ -53,7 +53,7 @@ "scripts": { "build": "pnpm transpile && pnpm typegen", "transpile": "tsup src/index.ts --config ./tsup.config.js", - "typegen": "tsc --customConditions default --emitDeclarationOnly --outDir dist/types", + "typegen": "tsc --customConditions default --emitDeclarationOnly --outDir dist/types", "lint": "eslint ./src --ext .ts,.jsx,.tsx --max-warnings=0", "test": "jest --passWithNoTests", "test:watch": "jest --watch", diff --git a/packages/orderbook/package.json b/packages/orderbook/package.json index 3233db71ea..4011d1961c 100644 --- a/packages/orderbook/package.json +++ b/packages/orderbook/package.json @@ -55,7 +55,7 @@ "scripts": { "build": "pnpm transpile && pnpm typegen", "transpile": "tsup src/index.ts --config ../../tsup.config.js", - "typegen": "tsc --customConditions default --emitDeclarationOnly --outDir dist/types", + "typegen": "tsc --customConditions default --emitDeclarationOnly --outDir dist/types", "generate-types": "typechain --target=ethers-v5 --out-dir=src/typechain/types 'abi/*.json'", "lint": "eslint ./src --ext .ts,.jsx,.tsx --max-warnings=0", "lint:fix": "eslint ./src --ext .ts,.jsx,.tsx --max-warnings=0 --fix", diff --git a/packages/passport/sdk/package.json b/packages/passport/sdk/package.json index 66285b31e9..9c441d349d 100644 --- a/packages/passport/sdk/package.json +++ b/packages/passport/sdk/package.json @@ -79,7 +79,7 @@ "scripts": { "build": "pnpm transpile && pnpm typegen", "transpile": "tsup src/index.ts --config ../../../tsup.config.js", - "typegen": "tsc --customConditions default --emitDeclarationOnly --outDir dist/types", + "typegen": "tsc --customConditions default --emitDeclarationOnly --outDir dist/types", "lint": "eslint ./src --ext .ts,.jsx,.tsx --max-warnings=0", "test": "jest", "test:watch": "jest --watch", diff --git a/packages/webhook/sdk/package.json b/packages/webhook/sdk/package.json index ca14cc69c7..ae15e9ca2f 100644 --- a/packages/webhook/sdk/package.json +++ b/packages/webhook/sdk/package.json @@ -43,7 +43,7 @@ "scripts": { "build": "pnpm transpile && pnpm typegen", "transpile": "tsup src/index.ts --config ./tsup.config.js", - "typegen": "tsc --customConditions default --emitDeclarationOnly --outDir dist/types", + "typegen": "tsc --customConditions default --emitDeclarationOnly --outDir dist/types", "lint": "eslint ./src --ext .ts,.jsx,.tsx --max-warnings=0", "test": "jest --passWithNoTests", "test:watch": "jest --watch", diff --git a/packages/x-client/package.json b/packages/x-client/package.json index 3170c70a8d..5f4aa977db 100644 --- a/packages/x-client/package.json +++ b/packages/x-client/package.json @@ -63,7 +63,7 @@ "scripts": { "build": "pnpm transpile && pnpm typegen", "transpile": "tsup src/index.ts --config ../../tsup.config.js", - "typegen": "tsc --customConditions default --emitDeclarationOnly --outDir dist/types", + "typegen": "tsc --customConditions default --emitDeclarationOnly --outDir dist/types", "lint": "eslint ./src --ext .ts,.jsx,.tsx --max-warnings=0", "test": "jest", "test:watch": "jest --watch", diff --git a/packages/x-provider/package.json b/packages/x-provider/package.json index 98ea2e3d18..361254c574 100644 --- a/packages/x-provider/package.json +++ b/packages/x-provider/package.json @@ -68,7 +68,7 @@ "scripts": { "build": "pnpm transpile && pnpm typegen", "transpile": "tsup src/index.ts --config ../../tsup.config.js", - "typegen": "tsc --customConditions default --emitDeclarationOnly --outDir dist/types", + "typegen": "tsc --customConditions default --emitDeclarationOnly --outDir dist/types", "lint": "eslint ./src --ext .ts,.jsx,.tsx --max-warnings=0", "test": "jest", "test:watch": "jest --watch", diff --git a/sdk/package.json b/sdk/package.json index ceeb8adf5b..f6b3238699 100644 --- a/sdk/package.json +++ b/sdk/package.json @@ -155,11 +155,12 @@ "license": "Apache-2.0", "main": "./dist/index.cjs", "module": "./dist/index.js", + "browser": "./dist/index.browser.js", "repository": "immutable/ts-immutable-sdk.git", "scripts": { "build": "pnpm transpile && pnpm typegen", "transpile": "tsup --config ./tsup.config.js", - "typegen": "tsc --customConditions default --emitDeclarationOnly", + "typegen": "tsc --customConditions default --emitDeclarationOnly", "lint": "eslint ./src --ext .ts,.jsx,.tsx --max-warnings=0", "typecheck": "tsc --customConditions default --noEmit --jsx preserve" }, diff --git a/sdk/tsup.config.js b/sdk/tsup.config.js index d30847239a..888a3ab2e8 100644 --- a/sdk/tsup.config.js +++ b/sdk/tsup.config.js @@ -18,43 +18,27 @@ export default defineConfig((options) => { } return [ - // Node Bundle for CommonJS and ESM + // Node & Browser Bundle for ESM { - entry: ['src', '!src/index.browser.ts'], + entry: ['src'], outDir: 'dist', - platform: 'node', - format: ['esm', 'cjs'], + format: 'esm', target: 'es2022', bundle: false, + treeshake: true, minify: false, - esbuildPlugins: [ - replace({ - '__SDK_VERSION__': pkg.version, - }) - ] }, - // Browser Bundle for ESM + // Node Bundle for CJS { - entry: ['src/index.browser.ts'], + entry: ['src', '!src/index.browser.ts'], outDir: 'dist', - platform: 'browser', - format: 'esm', + platform: 'node', + format: 'cjs', target: 'es2022', - bundle: false, + bundle: true, + treeshake: true, minify: false, - esbuildPlugins: [ - nodeModulesPolyfillPlugin({ - globals: { - Buffer: true, - process: true, - }, - modules: ['crypto', 'buffer', 'process', 'http'] - }), - replace({ - '__SDK_VERSION__': pkg.version, - }) - ] }, // Browser Bundle for CDN