From 3700f33804eab9eda0fab020fa00e7275b12f588 Mon Sep 17 00:00:00 2001 From: Richard <18597956+Rihyx@users.noreply.github.com> Date: Mon, 25 Nov 2024 10:49:01 +0100 Subject: [PATCH] Add export check (#397) * --wip-- [skip ci] * fix getSourceData * finish removing unused exports * change pipeline * remove unexisting type * put broken type back --- .github/workflows/{build.yml => lint.yml} | 3 + package.json | 2 + .../src/getTransferData/getMoonChainData.ts | 2 +- .../mrl/src/getTransferData/getSourceData.ts | 16 ++--- .../src/getTransferData/getTransferData.ts | 2 +- .../getTransferData/getTransferData.utils.ts | 8 +-- packages/mrl/src/index.ts | 1 + .../src/getTransferData/getTransferData.ts | 2 +- .../polkadot/PolkadotService.interfaces.ts | 7 -- packages/types/src/chain/Chain.utils.ts | 2 +- pnpm-lock.yaml | 67 +++++++++++++++++++ 11 files changed, 88 insertions(+), 24 deletions(-) rename .github/workflows/{build.yml => lint.yml} (90%) delete mode 100644 packages/sdk/src/services/polkadot/PolkadotService.interfaces.ts diff --git a/.github/workflows/build.yml b/.github/workflows/lint.yml similarity index 90% rename from .github/workflows/build.yml rename to .github/workflows/lint.yml index ba7425ea..ba19e695 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/lint.yml @@ -37,3 +37,6 @@ jobs: if: always() id: spell-check run: pnpm run spell + + - name: 🚪 Run Check Exports + run: npm run lint:exports diff --git a/package.json b/package.json index 5eb08845..c07d10d6 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "link": "turbo run link", "lint": "pnpm biome check .", "lint:fix": "pnpm biome check --write .", + "lint:exports": "ts-unused-exports tsconfig.json --excludePathsFromReport='vitest.workspace.ts;tsup.config.ts;build;examples;vitest.config;src/index.ts' --exitWithCount", "typecheck": "turbo run typecheck", "spell": "cspell --quiet -c cspell.config.cjs 'packages/**/src/**'", "test": "turbo run test", @@ -59,6 +60,7 @@ "glob": "^11.0.0", "lefthook": "^1.7.15", "syncpack": "^13.0.0", + "ts-unused-exports": "^10.1.0", "tsup": "^8.3.0", "turbo": "^2.1.3", "typescript": "^5.6.3", diff --git a/packages/mrl/src/getTransferData/getMoonChainData.ts b/packages/mrl/src/getTransferData/getMoonChainData.ts index 98c47eb1..010248ce 100644 --- a/packages/mrl/src/getTransferData/getMoonChainData.ts +++ b/packages/mrl/src/getTransferData/getMoonChainData.ts @@ -7,7 +7,7 @@ import type { MoonChainTransferData, } from '../mrl.interfaces'; -export interface GetMoonChainDataParams { +interface GetMoonChainDataParams { destinationData: DestinationTransferData; route: MrlAssetRoute; sourceAddress: string; diff --git a/packages/mrl/src/getTransferData/getSourceData.ts b/packages/mrl/src/getTransferData/getSourceData.ts index 0b732ef9..baeae161 100644 --- a/packages/mrl/src/getTransferData/getSourceData.ts +++ b/packages/mrl/src/getTransferData/getSourceData.ts @@ -29,7 +29,7 @@ import { getMrlBuilderParams, } from './getTransferData.utils'; -export interface GetSourceDataParams { +interface GetSourceDataParams { route: MrlAssetRoute; destinationAddress: string; destinationFee: AssetAmount; @@ -142,7 +142,7 @@ export async function getSourceData({ }; } -export interface GetFeeParams { +interface GetFeeParams { balance: AssetAmount; chain: AnyChain; destinationFee: AssetAmount; @@ -152,18 +152,18 @@ export interface GetFeeParams { transfer: ContractConfig | ExtrinsicConfig | WormholeConfig; } -export interface GetRelayFeeParams extends BuildTransferParams { +interface GetRelayFeeParams extends BuildTransferParams { chain: AnyChain; transfer: ContractConfig | ExtrinsicConfig | WormholeConfig; } -export interface GetWormholeFeeParams { +interface GetWormholeFeeParams { asset: AssetAmount; chain: AnyChain; config: ContractConfig | ExtrinsicConfig | WormholeConfig; } -export async function getFee({ +async function getFee({ balance, feeBalance, chain, @@ -200,7 +200,7 @@ export async function getFee({ }); } -export async function getRelayerFee({ +async function getRelayerFee({ asset, chain, destinationAddress, @@ -250,14 +250,14 @@ async function getWormholeFee({ return; } -export interface GetMoonChainFeeBalanceParams { +interface GetMoonChainFeeBalanceParams { balance: AssetAmount; feeBalance: AssetAmount; route: MrlAssetRoute; sourceAddress: string; } -export async function getMoonChainFeeBalance({ +async function getMoonChainFeeBalance({ balance, feeBalance, route, diff --git a/packages/mrl/src/getTransferData/getTransferData.ts b/packages/mrl/src/getTransferData/getTransferData.ts index 07050069..088a2935 100644 --- a/packages/mrl/src/getTransferData/getTransferData.ts +++ b/packages/mrl/src/getTransferData/getTransferData.ts @@ -28,7 +28,7 @@ import { getMrlMin, } from './getTransferData.utils'; -export interface GetTransferDataParams { +interface GetTransferDataParams { route: MrlAssetRoute; sourceAddress: string; destinationAddress: string; diff --git a/packages/mrl/src/getTransferData/getTransferData.utils.ts b/packages/mrl/src/getTransferData/getTransferData.utils.ts index a1716291..d9223a44 100644 --- a/packages/mrl/src/getTransferData/getTransferData.utils.ts +++ b/packages/mrl/src/getTransferData/getTransferData.utils.ts @@ -42,7 +42,7 @@ const MOON_CHAIN_AUTOMATIC_GAS_ESTIMATION = { [moonbaseAlpha.key]: 1470417n, }; -export interface DataParams { +interface DataParams { destinationData: DestinationChainTransferData; moonChainData: MoonChainTransferData; sourceData: SourceTransferData; @@ -168,7 +168,7 @@ export async function getMrlBuilderParams({ }; } -export async function getTransact(params: MrlBuilderParams): Promise { +async function getTransact(params: MrlBuilderParams): Promise { const { sourceAddress, source, moonChain } = params; const polkadot = await PolkadotService.create(moonChain); const moonGasLimit = await getMoonGasLimit(params); @@ -199,9 +199,7 @@ export async function getTransact(params: MrlBuilderParams): Promise { }; } -export async function getMoonGasLimit( - params: MrlBuilderParams, -): Promise { +async function getMoonGasLimit(params: MrlBuilderParams): Promise { const { asset, isAutomatic, moonChain, source, sourceAddress } = params; if (!EvmParachain.isAnyParachain(source)) { diff --git a/packages/mrl/src/index.ts b/packages/mrl/src/index.ts index a5b48e19..d4eb4a1e 100644 --- a/packages/mrl/src/index.ts +++ b/packages/mrl/src/index.ts @@ -1 +1,2 @@ export * from './mrl'; +export * from './mrl.interfaces'; diff --git a/packages/sdk/src/getTransferData/getTransferData.ts b/packages/sdk/src/getTransferData/getTransferData.ts index dce15565..00e07e9f 100644 --- a/packages/sdk/src/getTransferData/getTransferData.ts +++ b/packages/sdk/src/getTransferData/getTransferData.ts @@ -17,7 +17,7 @@ import { validateSovereignAccountBalances, } from './getTransferData.utils'; -export interface GetTransferDataParams { +interface GetTransferDataParams { route: AssetRoute; sourceAddress: string; destinationAddress: string; diff --git a/packages/sdk/src/services/polkadot/PolkadotService.interfaces.ts b/packages/sdk/src/services/polkadot/PolkadotService.interfaces.ts deleted file mode 100644 index f41b18d0..00000000 --- a/packages/sdk/src/services/polkadot/PolkadotService.interfaces.ts +++ /dev/null @@ -1,7 +0,0 @@ -import type { Bytes, Option, Struct, u8 } from '@polkadot/types'; - -export interface AssetMetadata extends Struct { - readonly name: Bytes; - readonly symbol: Bytes; - readonly decimals: u8 | Option; -} diff --git a/packages/types/src/chain/Chain.utils.ts b/packages/types/src/chain/Chain.utils.ts index d285aab3..f2d3d1b5 100644 --- a/packages/types/src/chain/Chain.utils.ts +++ b/packages/types/src/chain/Chain.utils.ts @@ -1,7 +1,7 @@ import { type Chain, defineChain } from 'viem'; import type { ChainAsset } from '../asset'; -export interface GetViemChainParams { +interface GetViemChainParams { id: number; name: string; nativeAsset: ChainAsset; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 454ebc7b..c3d54f40 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -69,6 +69,9 @@ importers: syncpack: specifier: ^13.0.0 version: 13.0.0(typescript@5.6.3) + ts-unused-exports: + specifier: ^10.1.0 + version: 10.1.0(typescript@5.6.3) tsup: specifier: ^8.3.0 version: 8.3.5(postcss@8.4.45)(typescript@5.6.3)(yaml@2.5.1) @@ -2091,6 +2094,9 @@ packages: '@types/estree@1.0.6': resolution: {integrity: sha512-AYnb1nQyY49te+VRAVgmzfcgjYS91mY5P0TKUDCLEM+gNnA+3T6rWITXRLYCpahpqSQbN5cE+gHpnPyXjHWxcw==} + '@types/json5@0.0.29': + resolution: {integrity: sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==} + '@types/node-fetch@2.6.11': resolution: {integrity: sha512-24xFj9R5+rfQJLRyM56qh+wnVSYhyXC2tkoBndtY0U+vubqNsYXGjufB2nn8Q6gt0LrARwL6UBtMCSVCwl4B1g==} @@ -2318,6 +2324,7 @@ packages: bun@1.1.33: resolution: {integrity: sha512-pNcxhsh87TURsaXwwLnOggb1HWdSDgOOjupTuXINmQUZeZ4UzLeVK8h8trzIVA0ECijDex94AkAQ5/JG4r5gkg==} + cpu: [arm64, x64] os: [darwin, linux, win32] hasBin: true @@ -2357,6 +2364,10 @@ packages: resolution: {integrity: sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==} engines: {node: '>=4'} + chalk@4.1.2: + resolution: {integrity: sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==} + engines: {node: '>=10'} + chalk@5.3.0: resolution: {integrity: sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w==} engines: {node: ^12.17.0 || ^14.13 || >=16.0.0} @@ -2796,6 +2807,10 @@ packages: resolution: {integrity: sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==} engines: {node: '>=4'} + has-flag@4.0.0: + resolution: {integrity: sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==} + engines: {node: '>=8'} + has-own-prop@2.0.0: resolution: {integrity: sha512-Pq0h+hvsVm6dDEa8x82GnLSYHOzNDt7f0ddFa3FqcQlgzEiptPqL+XrOJNavjOzSYiYWIrgeVYYgGlLmnxwilQ==} engines: {node: '>=8'} @@ -2935,6 +2950,10 @@ packages: json-stringify-safe@5.0.1: resolution: {integrity: sha512-ZClg6AaYvamvYEE82d3Iyd3vSSIjQ+odgjaTzRuO3s7toCdFKczob2i0zCh7JE8kWn17yvAWhUVxvqGwUalsRA==} + json5@1.0.2: + resolution: {integrity: sha512-g1MWMLBiz8FKi1e4w0UyVL3w+iJceWAFBAaBnnGKOpNa5f8TLktkbre1+s6oICydWAm+HRUGTmI+//xv2hvXYA==} + hasBin: true + jsonc-parser@3.3.1: resolution: {integrity: sha512-HUgH65KyejrUFPvHFPbqOY0rsFip3Bo5wb4ngvdi1EpCYWUQDC5V+Y7mZws+DLkr4M//zQJoanu1SP+87Dv1oQ==} @@ -3093,6 +3112,9 @@ packages: resolution: {integrity: sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==} engines: {node: '>=16 || 14 >=14.17'} + minimist@1.2.8: + resolution: {integrity: sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==} + minipass@7.1.2: resolution: {integrity: sha512-qOOzS1cBTWYF4BH8fVePDBOO9iptMnGUEZwNc/cMWnTV2nVLZ7VoNWEPHkYczZA0pdoA7dl6e7FL659nX9S2aw==} engines: {node: '>=16 || 14 >=14.17'} @@ -3564,6 +3586,10 @@ packages: resolution: {integrity: sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==} engines: {node: '>=4'} + supports-color@7.2.0: + resolution: {integrity: sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==} + engines: {node: '>=8'} + syncpack@13.0.0: resolution: {integrity: sha512-0PIoEWMP2+YkllkcZXw8N9d2sFqpmr8ULBdvms3gc1vG5tnccEMqc6flxHYnF/N+NTTcUnf0J+4xAD5hwH6XGQ==} engines: {node: '>=18.18.0'} @@ -3633,6 +3659,15 @@ packages: ts-toolbelt@9.6.0: resolution: {integrity: sha512-nsZd8ZeNUzukXPlJmTBwUAuABDe/9qtVDelJeT/qW0ow3ZS3BsQJtNkan1802aM9Uf68/Y8ljw86Hu0h5IUW3w==} + ts-unused-exports@10.1.0: + resolution: {integrity: sha512-QA11Dpwkm5Apfe9s/UkFzHEpbiBxKy0VQ72YRAoqq9VgNbxvvIOcS5Kgm1MCitOec9YU6nf51DEWnmL6jkP2Yg==} + hasBin: true + peerDependencies: + typescript: '>=3.8.3' + + tsconfig-paths@3.15.0: + resolution: {integrity: sha512-2Ac2RgzDe/cn48GvOe3M+o82pEFewD3UPbyoUHHdKasHwJKjds4fLXWf/Ux5kATBKN20oaFGu+jbElp1pos0mg==} + tslib@1.14.1: resolution: {integrity: sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==} @@ -6311,6 +6346,8 @@ snapshots: '@types/estree@1.0.6': {} + '@types/json5@0.0.29': {} + '@types/node-fetch@2.6.11': dependencies: '@types/node': 22.5.4 @@ -6606,6 +6643,11 @@ snapshots: escape-string-regexp: 1.0.5 supports-color: 5.5.0 + chalk@4.1.2: + dependencies: + ansi-styles: 4.3.0 + supports-color: 7.2.0 + chalk@5.3.0: {} chardet@0.7.0: {} @@ -7138,6 +7180,8 @@ snapshots: has-flag@3.0.0: {} + has-flag@4.0.0: {} + has-own-prop@2.0.0: {} hash-base@3.1.0: @@ -7253,6 +7297,10 @@ snapshots: json-stringify-safe@5.0.1: {} + json5@1.0.2: + dependencies: + minimist: 1.2.8 + jsonc-parser@3.3.1: {} jsonfile@4.0.0: @@ -7387,6 +7435,8 @@ snapshots: dependencies: brace-expansion: 2.0.1 + minimist@1.2.8: {} + minipass@7.1.2: {} mock-socket@9.3.1: {} @@ -7860,6 +7910,10 @@ snapshots: dependencies: has-flag: 3.0.0 + supports-color@7.2.0: + dependencies: + has-flag: 4.0.0 + syncpack@13.0.0(typescript@5.6.3): dependencies: '@effect/schema': 0.71.1(effect@3.6.5) @@ -7932,6 +7986,19 @@ snapshots: ts-toolbelt@9.6.0: {} + ts-unused-exports@10.1.0(typescript@5.6.3): + dependencies: + chalk: 4.1.2 + tsconfig-paths: 3.15.0 + typescript: 5.6.3 + + tsconfig-paths@3.15.0: + dependencies: + '@types/json5': 0.0.29 + json5: 1.0.2 + minimist: 1.2.8 + strip-bom: 3.0.0 + tslib@1.14.1: {} tslib@2.4.0: {}