From ec88bb61ef973ab28bc9d48df6a1907669e63a13 Mon Sep 17 00:00:00 2001 From: hanako mumei <81144685+2501babe@users.noreply.github.com> Date: Wed, 8 Nov 2023 07:04:05 -0800 Subject: [PATCH] single-pool-js: redo packaging --- single-pool/js/packages/classic/package.json | 22 ++++++++-------- single-pool/js/packages/classic/src/index.ts | 10 ++++---- .../js/packages/classic/src/instructions.ts | 2 +- .../js/packages/classic/src/transactions.ts | 2 +- single-pool/js/packages/classic/ts-fixup.sh | 1 + .../js/packages/classic/tsconfig-base.json | 1 + .../js/packages/classic/tsconfig-cjs.json | 1 + single-pool/js/packages/classic/tsconfig.json | 22 +--------------- single-pool/js/packages/modern/package.json | 24 +++++++++--------- .../js/packages/modern/src/addresses.ts | 4 +-- single-pool/js/packages/modern/src/index.ts | 8 +++--- .../js/packages/modern/src/instructions.ts | 6 ++--- .../js/packages/modern/src/transactions.ts | 6 ++--- single-pool/js/packages/modern/ts-fixup.sh | 1 + .../js/packages/modern/tsconfig-base.json | 1 + .../js/packages/modern/tsconfig-cjs.json | 1 + single-pool/js/packages/modern/tsconfig.json | 23 +---------------- single-pool/js/ts-fixup.sh | 11 ++++++++ single-pool/js/tsconfig-base.json | 25 +++++++++++++++++++ single-pool/js/tsconfig-cjs.json | 8 ++++++ single-pool/js/tsconfig.json | 8 ++++++ 21 files changed, 103 insertions(+), 84 deletions(-) create mode 120000 single-pool/js/packages/classic/ts-fixup.sh create mode 120000 single-pool/js/packages/classic/tsconfig-base.json create mode 120000 single-pool/js/packages/classic/tsconfig-cjs.json mode change 100644 => 120000 single-pool/js/packages/classic/tsconfig.json create mode 120000 single-pool/js/packages/modern/ts-fixup.sh create mode 120000 single-pool/js/packages/modern/tsconfig-base.json create mode 120000 single-pool/js/packages/modern/tsconfig-cjs.json mode change 100644 => 120000 single-pool/js/packages/modern/tsconfig.json create mode 100755 single-pool/js/ts-fixup.sh create mode 100644 single-pool/js/tsconfig-base.json create mode 100644 single-pool/js/tsconfig-cjs.json create mode 100644 single-pool/js/tsconfig.json diff --git a/single-pool/js/packages/classic/package.json b/single-pool/js/packages/classic/package.json index d02208e6829..4ea6921ceeb 100644 --- a/single-pool/js/packages/classic/package.json +++ b/single-pool/js/packages/classic/package.json @@ -1,20 +1,22 @@ { "name": "@solana/single-pool-classic", "version": "1.0.0", + "main": "dist/cjs/index.js", + "module": "dist/mjs/index.js", + "exports": { + ".": { + "import": "./dist/mjs/index.js", + "require": "./dist/cjs/index.js" + } + }, "scripts": { - "build": "pnpm tsc", + "build": "rm -fr dist/* && tsc -p tsconfig.json && tsc -p tsconfig-cjs.json && ./ts-fixup.sh", "lint": "eslint --max-warnings 0 .", "lint:fix": "eslint . --fix", - "test": "NODE_OPTIONS='--import=tsx' ava" - }, - "type": "module", - "main": "./dist/index.js", - "module": "./dist/index.js", - "exports": { - "require": "./dist/index.js", - "import": "./dist/index.js" + "test": "sed -i '1s/.*/{ \"type\": \"module\",/' package.json && NODE_OPTIONS='--loader=tsx' ava ; sed -i '1s/.*/{/' package.json" }, "devDependencies": { + "@types/node": "^20.9.0", "@ava/typescript": "^4.1.0", "@typescript-eslint/eslint-plugin": "^6.4.1", "ava": "^5.3.1", @@ -32,7 +34,7 @@ }, "ava": { "extensions": { - "ts": "commonjs" + "ts": "module" }, "nodeArguments": [ "--import=tsx" diff --git a/single-pool/js/packages/classic/src/index.ts b/single-pool/js/packages/classic/src/index.ts index 415bdcec605..63373aca905 100644 --- a/single-pool/js/packages/classic/src/index.ts +++ b/single-pool/js/packages/classic/src/index.ts @@ -1,12 +1,12 @@ import { Connection, PublicKey } from '@solana/web3.js'; import { getVoteAccountAddressForPool as getVoteModern } from '@solana/single-pool'; -import { rpc } from './internal'; +import { rpc } from './internal.js'; -export * from './mpl_metadata'; -export * from './addresses'; -export * from './instructions'; -export * from './transactions'; +export * from './mpl_metadata.js'; +export * from './addresses.js'; +export * from './instructions.js'; +export * from './transactions.js'; export async function getVoteAccountAddressForPool(connection: Connection, poolAddress: PublicKey) { const voteAccountModern = await getVoteModern(rpc(connection), poolAddress.toBase58()); diff --git a/single-pool/js/packages/classic/src/instructions.ts b/single-pool/js/packages/classic/src/instructions.ts index e783a8b5311..3bc44306875 100644 --- a/single-pool/js/packages/classic/src/instructions.ts +++ b/single-pool/js/packages/classic/src/instructions.ts @@ -1,7 +1,7 @@ import { PublicKey, TransactionInstruction } from '@solana/web3.js'; import { SinglePoolInstruction as PoolInstructionModern } from '@solana/single-pool'; -import { modernInstructionToLegacy } from './internal'; +import { modernInstructionToLegacy } from './internal.js'; export class SinglePoolInstruction { static async initializePool(voteAccount: PublicKey): Promise { diff --git a/single-pool/js/packages/classic/src/transactions.ts b/single-pool/js/packages/classic/src/transactions.ts index f422c8fa004..36e40545912 100644 --- a/single-pool/js/packages/classic/src/transactions.ts +++ b/single-pool/js/packages/classic/src/transactions.ts @@ -1,7 +1,7 @@ import { PublicKey, Connection } from '@solana/web3.js'; import { SinglePoolProgram as PoolProgramModern } from '@solana/single-pool'; -import { paramsToModern, modernTransactionToLegacy, rpc } from './internal'; +import { paramsToModern, modernTransactionToLegacy, rpc } from './internal.js'; interface DepositParams { connection: Connection; diff --git a/single-pool/js/packages/classic/ts-fixup.sh b/single-pool/js/packages/classic/ts-fixup.sh new file mode 120000 index 00000000000..2b79c262866 --- /dev/null +++ b/single-pool/js/packages/classic/ts-fixup.sh @@ -0,0 +1 @@ +../../ts-fixup.sh \ No newline at end of file diff --git a/single-pool/js/packages/classic/tsconfig-base.json b/single-pool/js/packages/classic/tsconfig-base.json new file mode 120000 index 00000000000..8cdeff689fc --- /dev/null +++ b/single-pool/js/packages/classic/tsconfig-base.json @@ -0,0 +1 @@ +../../tsconfig-base.json \ No newline at end of file diff --git a/single-pool/js/packages/classic/tsconfig-cjs.json b/single-pool/js/packages/classic/tsconfig-cjs.json new file mode 120000 index 00000000000..eb5b6778868 --- /dev/null +++ b/single-pool/js/packages/classic/tsconfig-cjs.json @@ -0,0 +1 @@ +../../tsconfig-cjs.json \ No newline at end of file diff --git a/single-pool/js/packages/classic/tsconfig.json b/single-pool/js/packages/classic/tsconfig.json deleted file mode 100644 index e2d884ce607..00000000000 --- a/single-pool/js/packages/classic/tsconfig.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "compilerOptions": { - "module": "esnext", - "target": "es2020", - "baseUrl": "./src", - "outDir": "dist", - "declaration": true, - "declarationDir": "dist", - "esModuleInterop": true, - "allowSyntheticDefaultImports": true, - "strict": true, - "forceConsistentCasingInFileNames": true, - "moduleResolution": "node", - "resolveJsonModule": true, - "isolatedModules": true, - "noFallthroughCasesInSwitch": true, - "noImplicitReturns": true, - "skipLibCheck": true // needed to avoid re-export errors from borsh - }, - "include": ["src/**/*.ts"] -} diff --git a/single-pool/js/packages/classic/tsconfig.json b/single-pool/js/packages/classic/tsconfig.json new file mode 120000 index 00000000000..fd0e4743dda --- /dev/null +++ b/single-pool/js/packages/classic/tsconfig.json @@ -0,0 +1 @@ +../../tsconfig.json \ No newline at end of file diff --git a/single-pool/js/packages/modern/package.json b/single-pool/js/packages/modern/package.json index 25df938007b..865a3cf4a34 100644 --- a/single-pool/js/packages/modern/package.json +++ b/single-pool/js/packages/modern/package.json @@ -1,27 +1,27 @@ { "name": "@solana/single-pool", "version": "1.0.0", + "main": "dist/cjs/index.js", + "module": "dist/mjs/index.js", + "exports": { + ".": { + "import": "./dist/mjs/index.js", + "require": "./dist/cjs/index.js" + } + }, "scripts": { - "build": "pnpm tsc", + "build": "rm -fr dist/* && tsc -p tsconfig.json && tsc -p tsconfig-cjs.json && ./ts-fixup.sh", "lint": "eslint --max-warnings 0 .", - "lint:fix": "eslint . --fix", - "test": "NODE_OPTIONS='--loader=tsx' ava" - }, - "type": "module", - "main": "./dist/index.js", - "module": "./dist/index.js", - "exports": { - "require": "./dist/index.js", - "import": "./dist/index.js" + "lint:fix": "eslint . --fix" }, "devDependencies": { + "@types/node": "^20.9.0", "@ava/typescript": "^4.1.0", "@typescript-eslint/eslint-plugin": "^6.4.1", "ava": "^5.3.1", "eslint": "^8.49.0", "eslint-config-prettier": "^9.0.0", "eslint-plugin-prettier": "^5.0.0", - "solana-bankrun": "^0.2.0", "ts-node": "^10.9.1", "tsx": "^3.12.7", "typescript": "^5.2.2" @@ -34,7 +34,7 @@ "ts": "module" }, "nodeArguments": [ - "--loader=tsx" + "--import=tsx" ] } } diff --git a/single-pool/js/packages/modern/src/addresses.ts b/single-pool/js/packages/modern/src/addresses.ts index 64ebd7ad6e3..7e8464e487f 100644 --- a/single-pool/js/packages/modern/src/addresses.ts +++ b/single-pool/js/packages/modern/src/addresses.ts @@ -6,8 +6,8 @@ import { createAddressWithSeed, } from '@solana/web3.js'; -import { MPL_METADATA_PROGRAM_ID } from './internal'; -import { STAKE_PROGRAM_ID } from './quarantine'; +import { MPL_METADATA_PROGRAM_ID } from './internal.js'; +import { STAKE_PROGRAM_ID } from './quarantine.js'; export const SINGLE_POOL_PROGRAM_ID = address('SVSPxpvHdN29nkVg9rPapPNDddN5DipNLRUFhyjFThE'); diff --git a/single-pool/js/packages/modern/src/index.ts b/single-pool/js/packages/modern/src/index.ts index f8697e33160..b26524a4f1b 100644 --- a/single-pool/js/packages/modern/src/index.ts +++ b/single-pool/js/packages/modern/src/index.ts @@ -1,10 +1,10 @@ import { getAddressCodec } from '@solana/web3.js'; -import { PoolAddress, VoteAccountAddress } from './addresses'; +import { PoolAddress, VoteAccountAddress } from './addresses.js'; -export * from './addresses'; -export * from './instructions'; -export * from './transactions'; +export * from './addresses.js'; +export * from './instructions.js'; +export * from './transactions.js'; export async function getVoteAccountAddressForPool( rpc: any, // XXX not exported: Rpc, diff --git a/single-pool/js/packages/modern/src/instructions.ts b/single-pool/js/packages/modern/src/instructions.ts index 3317355dbd2..a170f47764e 100644 --- a/single-pool/js/packages/modern/src/instructions.ts +++ b/single-pool/js/packages/modern/src/instructions.ts @@ -27,8 +27,8 @@ import { findPoolMintAuthorityAddress, findPoolStakeAuthorityAddress, SINGLE_POOL_PROGRAM_ID, -} from './addresses'; -import { MPL_METADATA_PROGRAM_ID } from './internal'; +} from './addresses.js'; +import { MPL_METADATA_PROGRAM_ID } from './internal.js'; import { SYSTEM_PROGRAM_ID, SYSVAR_RENT_ID, @@ -39,7 +39,7 @@ import { TOKEN_PROGRAM_ID, u32, u64, -} from './quarantine'; +} from './quarantine.js'; type InitializePoolInstruction = IInstruction & IInstructionWithAccounts< diff --git a/single-pool/js/packages/modern/src/transactions.ts b/single-pool/js/packages/modern/src/transactions.ts index 72b6255bf4d..03b2842b7c8 100644 --- a/single-pool/js/packages/modern/src/transactions.ts +++ b/single-pool/js/packages/modern/src/transactions.ts @@ -16,7 +16,7 @@ import { findPoolMintAuthorityAddress, findPoolStakeAuthorityAddress, SINGLE_POOL_PROGRAM_ID, -} from './addresses'; +} from './addresses.js'; import { initializePoolInstruction, reactivatePoolStakeInstruction, @@ -24,7 +24,7 @@ import { withdrawStakeInstruction, createTokenMetadataInstruction, updateTokenMetadataInstruction, -} from './instructions'; +} from './instructions.js'; import { STAKE_PROGRAM_ID, STAKE_ACCOUNT_SIZE, @@ -34,7 +34,7 @@ import { TokenInstruction, StakeAuthorizationType, getAssociatedTokenAddress, -} from './quarantine'; +} from './quarantine.js'; interface DepositParams { rpc: any; // XXX Rpc diff --git a/single-pool/js/packages/modern/ts-fixup.sh b/single-pool/js/packages/modern/ts-fixup.sh new file mode 120000 index 00000000000..2b79c262866 --- /dev/null +++ b/single-pool/js/packages/modern/ts-fixup.sh @@ -0,0 +1 @@ +../../ts-fixup.sh \ No newline at end of file diff --git a/single-pool/js/packages/modern/tsconfig-base.json b/single-pool/js/packages/modern/tsconfig-base.json new file mode 120000 index 00000000000..8cdeff689fc --- /dev/null +++ b/single-pool/js/packages/modern/tsconfig-base.json @@ -0,0 +1 @@ +../../tsconfig-base.json \ No newline at end of file diff --git a/single-pool/js/packages/modern/tsconfig-cjs.json b/single-pool/js/packages/modern/tsconfig-cjs.json new file mode 120000 index 00000000000..eb5b6778868 --- /dev/null +++ b/single-pool/js/packages/modern/tsconfig-cjs.json @@ -0,0 +1 @@ +../../tsconfig-cjs.json \ No newline at end of file diff --git a/single-pool/js/packages/modern/tsconfig.json b/single-pool/js/packages/modern/tsconfig.json deleted file mode 100644 index c3b7b616df8..00000000000 --- a/single-pool/js/packages/modern/tsconfig.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "compilerOptions": { - "module": "esnext", - "target": "es2020", - "baseUrl": "./src", - "outDir": "dist", - "declaration": true, - "declarationDir": "dist", - "esModuleInterop": true, - "allowSyntheticDefaultImports": true, - "strict": true, - "forceConsistentCasingInFileNames": true, - "moduleResolution": "node", - "resolveJsonModule": true, - "isolatedModules": true, - "noFallthroughCasesInSwitch": true, - "noImplicitReturns": true, - "lib": ["DOM"], - "skipLibCheck": true // needed to avoid re-export errors from borsh - }, - "include": ["src/**/*.ts"] -} diff --git a/single-pool/js/packages/modern/tsconfig.json b/single-pool/js/packages/modern/tsconfig.json new file mode 120000 index 00000000000..fd0e4743dda --- /dev/null +++ b/single-pool/js/packages/modern/tsconfig.json @@ -0,0 +1 @@ +../../tsconfig.json \ No newline at end of file diff --git a/single-pool/js/ts-fixup.sh b/single-pool/js/ts-fixup.sh new file mode 100755 index 00000000000..39177d08657 --- /dev/null +++ b/single-pool/js/ts-fixup.sh @@ -0,0 +1,11 @@ +cat >dist/cjs/package.json <dist/mjs/package.json <