浏览代码

Refactor reexports (#143)

* feat: add reexport generator

* refactor: system exports

* feat: add imports e2e

* ci: canary publish

* chore: changeset
Nick Frostbutter 5 月之前
父节点
当前提交
0be650e92c

+ 5 - 0
.changeset/warm-ears-report.md

@@ -0,0 +1,5 @@
+---
+"gill": patch
+---
+
+refactor system program reexports

+ 57 - 0
.github/workflows/publish-canary-releases.yml

@@ -0,0 +1,57 @@
+name: Publish Canary Releases
+
+on:
+  workflow_dispatch:
+    branches:
+      - main
+  push:
+    branches:
+      - main
+
+permissions:
+  contents: read
+
+env:
+  # Among other things, opts out of Turborepo telemetry
+  # See https://consoledonottrack.com/
+  DO_NOT_TRACK: '1'
+  # Some tasks slow down considerably on GitHub Actions runners when concurrency is high
+  TURBO_CONCURRENCY: 1
+  # Enables Turborepo Remote Caching.
+  TURBO_REMOTE_CACHE_SIGNATURE_KEY: ${{ secrets.TURBO_REMOTE_CACHE_SIGNATURE_KEY }}
+  TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
+  TURBO_TEAM: ${{ vars.TURBO_TEAM }}
+
+jobs:
+  build-and-publish-snapshots-to-npm:
+    permissions:
+      pull-requests: write
+    runs-on: ubuntu-latest
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v4
+
+      - name: Install Dependencies
+        uses: ./.github/workflows/actions/install-dependencies
+
+      - name: Run Build Step (force)
+        run: pnpm turbo build --force=true
+
+      - name: Configure NPM token
+        run: |
+          pnpm config set '//registry.npmjs.org/:_authToken' "${NPM_TOKEN}"
+        env:
+          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
+
+      - name: Publish Canary Releases
+        run: |
+          find packages/* -maxdepth 0 -type d -print0 | \
+            xargs -t0 -n 1 -I {} \
+              sh -c 'cd {} && pnpm pkg delete devDependencies'
+          pnpm changeset version --snapshot canary
+          pnpm turbo publish-packages --concurrency=${TURBO_CONCURRENCY:-1}
+        env:
+          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
+          PUBLISH_TAG: canary

+ 51 - 0
e2e/imports/.gitignore

@@ -0,0 +1,51 @@
+# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
+
+# dependencies
+/node_modules
+/.cache
+/.pnp
+.pnp.js
+
+# testing
+/coverage
+
+# next.js
+/.next/
+/out/
+
+# production
+/build
+/dist
+/bin
+
+# misc
+.DS_Store
+*.pem
+
+# debug
+npm-debug.log*
+yarn-debug.log*
+yarn-error.log*
+
+# local env files
+.env
+!.env.example
+
+# vercel
+.vercel
+
+# contentlayer
+.contentlayer
+
+# typescript
+*.tsbuildinfo
+next-env.d.ts
+
+# sitemaps / robots
+public/sitemap*
+public/robot*
+
+test-ledger
+temp
+
+.cache

+ 11 - 0
e2e/imports/.prettierrc

@@ -0,0 +1,11 @@
+{
+  "tabWidth": 2,
+  "useTabs": false,
+  "singleQuote": false,
+  "bracketSpacing": true,
+  "semi": true,
+  "trailingComma": "all",
+  "proseWrap": "always",
+  "arrowParens": "always",
+  "printWidth": 80
+}

+ 19 - 0
e2e/imports/package.json

@@ -0,0 +1,19 @@
+{
+  "name": "gill-e2e",
+  "license": "MIT",
+  "private": true,
+  "version": "0.1.0",
+  "scripts": {
+    "test:unit:node": "TERM_OVERRIDE=\"${TURBO_HASH:+dumb}\" TERM=${TERM_OVERRIDE:-$TERM} pnpm start:tsx && pnpm start:node",
+    "start:tsx": "pnpm tsx ./src/imports.ts",
+    "start:node": "node ./src/imports.js",
+    "start:tsc": "tsc ./src/imports.ts --outFile ./src/imports-tsc.js && node ./src/imports-tsc.js"
+  },
+  "dependencies": {
+    "gill": "workspace:*"
+  },
+  "devDependencies": {
+    "tsx": "^4.19.4",
+    "typescript": "^5.8.3"
+  }
+}

+ 69 - 0
e2e/imports/src/imports.js

@@ -0,0 +1,69 @@
+/**
+ * Import and log one of each type of symbol from the reexported or generated program clients
+ */
+
+/**
+ * SPL System program client
+ */
+import { SYSTEM_PROGRAM_ADDRESS } from "gill/programs";
+console.log(SYSTEM_PROGRAM_ADDRESS);
+
+import { getTransferSolInstruction } from "gill/programs";
+console.log(getTransferSolInstruction);
+
+/**
+ * SPL Address Lookup Table program client
+ */
+import { ADDRESS_LOOKUP_TABLE_PROGRAM_ADDRESS } from "gill/programs";
+console.log(ADDRESS_LOOKUP_TABLE_PROGRAM_ADDRESS);
+
+import { getAddressLookupTableDecoder } from "gill/programs";
+console.log(getAddressLookupTableDecoder);
+
+/**
+ * SPL Compute Budget program client
+ */
+import { COMPUTE_BUDGET_PROGRAM_ADDRESS } from "gill/programs";
+console.log(COMPUTE_BUDGET_PROGRAM_ADDRESS);
+
+import { getSetComputeUnitLimitInstruction } from "gill/programs";
+console.log(getSetComputeUnitLimitInstruction);
+
+// !this is a custom symbol that gill provides
+import { isSetComputeLimitInstruction } from "gill/programs";
+console.log(isSetComputeLimitInstruction);
+
+/**
+ * !SPL Memo program is generated and vendored in
+ */
+import { MEMO_PROGRAM_ADDRESS } from "gill/programs";
+console.log(MEMO_PROGRAM_ADDRESS);
+
+import { getAddMemoInstruction } from "gill/programs";
+console.log(getAddMemoInstruction);
+
+/**
+ * ! Metaplex's Token Metadata client is generated and vendored in
+ */
+import { TOKEN_METADATA_PROGRAM_ADDRESS } from "gill/programs";
+console.log(TOKEN_METADATA_PROGRAM_ADDRESS);
+
+import { getMetadataCodec } from "gill/programs";
+console.log(getMetadataCodec);
+
+/**
+ * SPL Token 2022 program client
+ */
+import { TOKEN_2022_PROGRAM_ADDRESS } from "gill/programs/token";
+console.log(TOKEN_2022_PROGRAM_ADDRESS);
+
+import { getMintToInstruction } from "gill/programs/token";
+console.log(getMintToInstruction);
+
+// !this is a custom symbol that gill provides
+import { getAssociatedTokenAccountAddress } from "gill/programs/token";
+console.log(getAssociatedTokenAccountAddress);
+
+// !this is a custom symbol that gill provides
+import { TOKEN_PROGRAM_ADDRESS } from "gill/programs/token";
+console.log(TOKEN_PROGRAM_ADDRESS);

+ 69 - 0
e2e/imports/src/imports.ts

@@ -0,0 +1,69 @@
+/**
+ * Import and log one of each type of symbol from the reexported or generated program clients
+ */
+
+/**
+ * SPL System program client
+ */
+import { SYSTEM_PROGRAM_ADDRESS } from "gill/programs";
+console.log(SYSTEM_PROGRAM_ADDRESS);
+
+import { getTransferSolInstruction } from "gill/programs";
+console.log(getTransferSolInstruction);
+
+/**
+ * SPL Address Lookup Table program client
+ */
+import { ADDRESS_LOOKUP_TABLE_PROGRAM_ADDRESS } from "gill/programs";
+console.log(ADDRESS_LOOKUP_TABLE_PROGRAM_ADDRESS);
+
+import { getAddressLookupTableDecoder } from "gill/programs";
+console.log(getAddressLookupTableDecoder);
+
+/**
+ * SPL Compute Budget program client
+ */
+import { COMPUTE_BUDGET_PROGRAM_ADDRESS } from "gill/programs";
+console.log(COMPUTE_BUDGET_PROGRAM_ADDRESS);
+
+import { getSetComputeUnitLimitInstruction } from "gill/programs";
+console.log(getSetComputeUnitLimitInstruction);
+
+// !this is a custom symbol that gill provides
+import { isSetComputeLimitInstruction } from "gill/programs";
+console.log(isSetComputeLimitInstruction);
+
+/**
+ * !SPL Memo program is generated and vendored in
+ */
+import { MEMO_PROGRAM_ADDRESS } from "gill/programs";
+console.log(MEMO_PROGRAM_ADDRESS);
+
+import { getAddMemoInstruction } from "gill/programs";
+console.log(getAddMemoInstruction);
+
+/**
+ * ! Metaplex's Token Metadata client is generated and vendored in
+ */
+import { TOKEN_METADATA_PROGRAM_ADDRESS } from "gill/programs";
+console.log(TOKEN_METADATA_PROGRAM_ADDRESS);
+
+import { getMetadataCodec } from "gill/programs";
+console.log(getMetadataCodec);
+
+/**
+ * SPL Token 2022 program client
+ */
+import { TOKEN_2022_PROGRAM_ADDRESS } from "gill/programs/token";
+console.log(TOKEN_2022_PROGRAM_ADDRESS);
+
+import { getMintToInstruction } from "gill/programs/token";
+console.log(getMintToInstruction);
+
+// !this is a custom symbol that gill provides
+import { getAssociatedTokenAccountAddress } from "gill/programs/token";
+console.log(getAssociatedTokenAccountAddress);
+
+// !this is a custom symbol that gill provides
+import { TOKEN_PROGRAM_ADDRESS } from "gill/programs/token";
+console.log(TOKEN_PROGRAM_ADDRESS);

+ 10 - 0
e2e/imports/tsconfig.json

@@ -0,0 +1,10 @@
+{
+  "compilerOptions": {
+    "target": "es2022",
+    "module": "NodeNext",
+    "esModuleInterop": true,
+    "forceConsistentCasingInFileNames": true,
+    "strict": true,
+    "skipLibCheck": true
+  }
+}

+ 48 - 0
packages/gill/generate-reexports.ts

@@ -0,0 +1,48 @@
+#!/usr/bin/env node
+import fs from "fs";
+
+type ReexportSettings = {
+  package: string;
+  outputFile: string;
+};
+
+const packages: ReexportSettings[] = [
+  {
+    package: "@solana-program/system",
+    outputFile: "./src/programs/system/reexports.ts",
+  },
+  //   {
+  //     package: "@solana-program/address-lookup-table",
+  //     outputFile: "./src/programs/address-lookup-table/reexports.ts",
+  //   },
+  //   {
+  //     package: "@solana-program/compute-budget",
+  //     outputFile: "./src/programs/compute-budget/reexports.ts",
+  //   },
+];
+
+async function generateExports() {
+  for (const pkg of packages) {
+    let exports = "";
+    try {
+      // Import the package to get its exports
+      const module = await import(pkg.package);
+      const exportNames = Object.keys(module).filter((key) => key !== "default");
+
+      if (exportNames.length > 0) {
+        exports += `// Re-exports from ${pkg.package}\n`;
+        exports += `export {\n`;
+        exports += exportNames.map((name) => `  ${name},`).join("\n");
+        exports += `\n} from "${pkg.package}";\n\n`;
+      }
+
+      // Write to output file
+      fs.writeFileSync(pkg.outputFile, exports);
+      console.log(`✓ Generated exports for ${pkg.package}: ${exportNames.length} exports`);
+    } catch (error) {
+      console.error(`✗ Failed to process ${pkg.package}:`, error.message);
+    }
+  }
+}
+
+generateExports().catch(console.error);

+ 2 - 0
packages/gill/package.json

@@ -6,11 +6,13 @@
   "scripts": {
     "clean": "rimraf dist build node_modules .turbo .docs",
     "clean:docs": "rimraf ../../docs/content/api/gill*",
+    "generate-reexports": "npx esrun ./generate-reexports.ts",
     "compile:docs-core": "typedoc --options typedoc.core.json",
     "compile:docs-node": "typedoc --options typedoc.node.json",
     "compile:docs-programs": "typedoc --options typedoc.programs.json",
     "compile:docs": "pnpm compile:docs-core && pnpm compile:docs-node && pnpm compile:docs-programs && pnpm move:docs",
     "move:docs": "pnpm clean:docs && cp -rf ./.docs/* ../../docs/content/api/",
+    "prebuild": "rimraf dist",
     "compile:js": "tsup --config ./tsup.config.package.ts",
     "compile:typedefs": "tsc -p ./tsconfig.declarations.json",
     "prepublishOnly": "pnpm pkg delete devDependencies",

+ 1 - 1
packages/gill/src/programs/index.ts

@@ -2,7 +2,7 @@
  * Re-export the most common program clients compatible with this library
  */
 
-export * from "@solana-program/system";
+export * from "./system";
 
 export * from "@solana-program/address-lookup-table";
 export * from "@solana-program/compute-budget";

+ 1 - 0
packages/gill/src/programs/system/index.ts

@@ -0,0 +1 @@
+export * from "./reexports";

+ 127 - 0
packages/gill/src/programs/system/reexports.ts

@@ -0,0 +1,127 @@
+// Re-exports from @solana-program/system
+export {
+  ADVANCE_NONCE_ACCOUNT_DISCRIMINATOR,
+  ALLOCATE_DISCRIMINATOR,
+  ALLOCATE_WITH_SEED_DISCRIMINATOR,
+  ASSIGN_DISCRIMINATOR,
+  ASSIGN_WITH_SEED_DISCRIMINATOR,
+  AUTHORIZE_NONCE_ACCOUNT_DISCRIMINATOR,
+  CREATE_ACCOUNT_DISCRIMINATOR,
+  CREATE_ACCOUNT_WITH_SEED_DISCRIMINATOR,
+  INITIALIZE_NONCE_ACCOUNT_DISCRIMINATOR,
+  NonceState,
+  NonceVersion,
+  SYSTEM_ERROR__ACCOUNT_ALREADY_IN_USE,
+  SYSTEM_ERROR__ADDRESS_WITH_SEED_MISMATCH,
+  SYSTEM_ERROR__INVALID_ACCOUNT_DATA_LENGTH,
+  SYSTEM_ERROR__INVALID_PROGRAM_ID,
+  SYSTEM_ERROR__MAX_SEED_LENGTH_EXCEEDED,
+  SYSTEM_ERROR__NONCE_BLOCKHASH_NOT_EXPIRED,
+  SYSTEM_ERROR__NONCE_NO_RECENT_BLOCKHASHES,
+  SYSTEM_ERROR__NONCE_UNEXPECTED_BLOCKHASH_VALUE,
+  SYSTEM_ERROR__RESULT_WITH_NEGATIVE_LAMPORTS,
+  SYSTEM_PROGRAM_ADDRESS,
+  SystemAccount,
+  SystemInstruction,
+  TRANSFER_SOL_DISCRIMINATOR,
+  TRANSFER_SOL_WITH_SEED_DISCRIMINATOR,
+  UPGRADE_NONCE_ACCOUNT_DISCRIMINATOR,
+  WITHDRAW_NONCE_ACCOUNT_DISCRIMINATOR,
+  decodeNonce,
+  fetchAllMaybeNonce,
+  fetchAllNonce,
+  fetchMaybeNonce,
+  fetchNonce,
+  getAdvanceNonceAccountDiscriminatorBytes,
+  getAdvanceNonceAccountInstruction,
+  getAdvanceNonceAccountInstructionDataCodec,
+  getAdvanceNonceAccountInstructionDataDecoder,
+  getAdvanceNonceAccountInstructionDataEncoder,
+  getAllocateDiscriminatorBytes,
+  getAllocateInstruction,
+  getAllocateInstructionDataCodec,
+  getAllocateInstructionDataDecoder,
+  getAllocateInstructionDataEncoder,
+  getAllocateWithSeedDiscriminatorBytes,
+  getAllocateWithSeedInstruction,
+  getAllocateWithSeedInstructionDataCodec,
+  getAllocateWithSeedInstructionDataDecoder,
+  getAllocateWithSeedInstructionDataEncoder,
+  getAssignDiscriminatorBytes,
+  getAssignInstruction,
+  getAssignInstructionDataCodec,
+  getAssignInstructionDataDecoder,
+  getAssignInstructionDataEncoder,
+  getAssignWithSeedDiscriminatorBytes,
+  getAssignWithSeedInstruction,
+  getAssignWithSeedInstructionDataCodec,
+  getAssignWithSeedInstructionDataDecoder,
+  getAssignWithSeedInstructionDataEncoder,
+  getAuthorizeNonceAccountDiscriminatorBytes,
+  getAuthorizeNonceAccountInstruction,
+  getAuthorizeNonceAccountInstructionDataCodec,
+  getAuthorizeNonceAccountInstructionDataDecoder,
+  getAuthorizeNonceAccountInstructionDataEncoder,
+  getCreateAccountDiscriminatorBytes,
+  getCreateAccountInstruction,
+  getCreateAccountInstructionDataCodec,
+  getCreateAccountInstructionDataDecoder,
+  getCreateAccountInstructionDataEncoder,
+  getCreateAccountWithSeedDiscriminatorBytes,
+  getCreateAccountWithSeedInstruction,
+  getCreateAccountWithSeedInstructionDataCodec,
+  getCreateAccountWithSeedInstructionDataDecoder,
+  getCreateAccountWithSeedInstructionDataEncoder,
+  getInitializeNonceAccountDiscriminatorBytes,
+  getInitializeNonceAccountInstruction,
+  getInitializeNonceAccountInstructionDataCodec,
+  getInitializeNonceAccountInstructionDataDecoder,
+  getInitializeNonceAccountInstructionDataEncoder,
+  getNonceCodec,
+  getNonceDecoder,
+  getNonceEncoder,
+  getNonceSize,
+  getNonceStateCodec,
+  getNonceStateDecoder,
+  getNonceStateEncoder,
+  getNonceVersionCodec,
+  getNonceVersionDecoder,
+  getNonceVersionEncoder,
+  getSystemErrorMessage,
+  getTransferSolDiscriminatorBytes,
+  getTransferSolInstruction,
+  getTransferSolInstructionDataCodec,
+  getTransferSolInstructionDataDecoder,
+  getTransferSolInstructionDataEncoder,
+  getTransferSolWithSeedDiscriminatorBytes,
+  getTransferSolWithSeedInstruction,
+  getTransferSolWithSeedInstructionDataCodec,
+  getTransferSolWithSeedInstructionDataDecoder,
+  getTransferSolWithSeedInstructionDataEncoder,
+  getUpgradeNonceAccountDiscriminatorBytes,
+  getUpgradeNonceAccountInstruction,
+  getUpgradeNonceAccountInstructionDataCodec,
+  getUpgradeNonceAccountInstructionDataDecoder,
+  getUpgradeNonceAccountInstructionDataEncoder,
+  getWithdrawNonceAccountDiscriminatorBytes,
+  getWithdrawNonceAccountInstruction,
+  getWithdrawNonceAccountInstructionDataCodec,
+  getWithdrawNonceAccountInstructionDataDecoder,
+  getWithdrawNonceAccountInstructionDataEncoder,
+  identifySystemInstruction,
+  isSystemError,
+  parseAdvanceNonceAccountInstruction,
+  parseAllocateInstruction,
+  parseAllocateWithSeedInstruction,
+  parseAssignInstruction,
+  parseAssignWithSeedInstruction,
+  parseAuthorizeNonceAccountInstruction,
+  parseCreateAccountInstruction,
+  parseCreateAccountWithSeedInstruction,
+  parseInitializeNonceAccountInstruction,
+  parseTransferSolInstruction,
+  parseTransferSolWithSeedInstruction,
+  parseUpgradeNonceAccountInstruction,
+  parseWithdrawNonceAccountInstruction,
+} from "@solana-program/system";
+

文件差异内容过多而无法显示
+ 255 - 248
pnpm-lock.yaml


+ 1 - 0
pnpm-workspace.yaml

@@ -1,5 +1,6 @@
 packages:
   - "examples/*"
   - "scripts"
+  - "e2e/*"
   - "packages/*"
   - "!docs"

部分文件因为文件数量过多而无法显示