瀏覽代碼

fix(@pythnetwork/aptos-cli): fixed build

benduran 3 周之前
父節點
當前提交
76d65ed014

+ 37 - 2
target_chains/aptos/cli/package.json

@@ -3,7 +3,7 @@
   "version": "1.0.0",
   "description": "Utilities for managing the Pyth Target Chain contract on Aptos",
   "private": true,
-  "main": "index.js",
+  "main": "./dist/cjs/index.js",
   "scripts": {
     "cli": "ts-node src/cli.ts",
     "build": "ts-duality",
@@ -34,5 +34,40 @@
     "pnpm": ">=10.19.0"
   },
   "packageManager": "pnpm@10.19.0",
-  "type": "module"
+  "type": "module",
+  "exports": {
+    "./cli": {
+      "require": {
+        "default": "./dist/cjs/cli.js",
+        "types": "./dist/cjs/cli.d.ts"
+      },
+      "import": {
+        "default": "./dist/esm/cli.js",
+        "types": "./dist/esm/cli.d.ts"
+      }
+    },
+    "./commands/aptos": {
+      "require": {
+        "default": "./dist/cjs/commands/aptos.js",
+        "types": "./dist/cjs/commands/aptos.d.ts"
+      },
+      "import": {
+        "default": "./dist/esm/commands/aptos.js",
+        "types": "./dist/esm/commands/aptos.d.ts"
+      }
+    },
+    ".": {
+      "require": {
+        "default": "./dist/cjs/index.js",
+        "types": "./dist/cjs/index.d.ts"
+      },
+      "import": {
+        "default": "./dist/esm/index.js",
+        "types": "./dist/esm/index.d.ts"
+      }
+    },
+    "./package.json": "./package.json"
+  },
+  "module": "./dist/esm/index.js",
+  "types": "./dist/cjs/index.d.ts"
 }

+ 5 - 3
target_chains/aptos/cli/src/cli.ts

@@ -1,7 +1,9 @@
 #!/usr/bin/env node
 
-import yargs from "yargs";
+import createCLI from "yargs";
 import { hideBin } from "yargs/helpers";
-import { builder } from "./commands/aptos";
+import { builder } from "./commands/aptos.js";
 
-builder(yargs(hideBin(process.argv))).argv;
+const yargs = createCLI(hideBin(process.argv));
+
+builder(yargs).argv;

+ 6 - 14
target_chains/aptos/cli/src/commands/aptos.ts

@@ -1,15 +1,14 @@
-import { Argv } from "yargs";
+import type { Argv } from "yargs";
 import { spawnSync } from "child_process";
 import { AptosAccount, AptosClient, BCS, TxnBuilderTypes } from "aptos";
 import fs from "fs";
 import sha3 from "js-sha3";
-import { ethers } from "ethers";
-import { DefaultStore } from "@pythnetwork/contract-manager/node/store";
 import { AptosChain } from "@pythnetwork/contract-manager/core/chains";
 import { getDefaultDeploymentConfig } from "@pythnetwork/contract-manager/core/base";
+import { DefaultStore } from "@pythnetwork/contract-manager/node/utils/store";
 
 const NETWORK_CHOICES = Object.entries(DefaultStore.chains)
-  .filter(([chain, config]) => {
+  .filter(([_, config]) => {
     return config instanceof AptosChain;
   })
   .map(([chain, _]) => {
@@ -181,7 +180,7 @@ export const builder: (args: Argv<any>) => Argv<any> = (yargs) =>
         const guardian_addresses_serializer = new BCS.Serializer();
         guardian_addresses_serializer.serializeU32AsUleb128(1);
         guardian_addresses_serializer.serializeBytes(
-          Buffer.from(guardian_address, "hex"),
+          Buffer.from(guardian_address!, "hex"),
         );
 
         const args = [
@@ -351,7 +350,8 @@ export const builder: (args: Argv<any>) => Argv<any> = (yargs) =>
         const addr2 = argv["addr-2"];
         const url = `${endpoint}/accounts/${addr1}/resource/0x1::code::PackageRegistry`;
         const response = await (await fetch(url)).json();
-        for (const module of response.data.packages[0].modules) {
+        // @ts-expect-error - TODO: Please improve typings on the .json() response here
+        for (const module of response?.data?.packages[0]?.modules ?? []) {
           const moduleName = module.name;
           const addr1Module = `${endpoint}/accounts/${addr1}/module/${moduleName}`;
           const addr2Module = `${endpoint}/accounts/${addr2}/module/${moduleName}`;
@@ -513,11 +513,3 @@ function createDeployDerivedTransaction(
     ),
   );
 }
-
-function hex(x: string): string {
-  return ethers.utils.hexlify(x, { allowMissingPrefix: true });
-}
-
-function evm_address(x: string): string {
-  return hex(x).substring(2).padStart(64, "0");
-}

+ 1 - 0
target_chains/aptos/cli/src/index.ts

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

+ 2 - 1
target_chains/aptos/cli/tsconfig.build.json

@@ -3,7 +3,8 @@
   "compilerOptions": {
     "noEmit": false,
     "incremental": false,
-    "declaration": true
+    "declaration": true,
+    "isolatedModules": false
   },
   "exclude": [
     "node_modules",