@aptos-labs/aptos-cli 1.1.1 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/README.md +109 -0
  2. package/dist/aptos.js +7 -2
  3. package/dist/aptos.js.map +1 -1
  4. package/dist/tasks/install.js +110 -32
  5. package/dist/tasks/install.js.map +1 -1
  6. package/dist/tasks/run.js +13 -8
  7. package/dist/tasks/run.js.map +1 -1
  8. package/dist/tasks/update.js +56 -20
  9. package/dist/tasks/update.js.map +1 -1
  10. package/dist/utils/brewOperations.js +30 -4
  11. package/dist/utils/brewOperations.js.map +1 -1
  12. package/dist/utils/consts.js.map +1 -1
  13. package/dist/utils/execSyncShell.js +3 -2
  14. package/dist/utils/execSyncShell.js.map +1 -1
  15. package/dist/utils/executableIsAvailable.js +12 -0
  16. package/dist/utils/executableIsAvailable.js.map +1 -0
  17. package/dist/utils/getLocalBinPath.js +79 -23
  18. package/dist/utils/getLocalBinPath.js.map +1 -1
  19. package/dist/utils/getUserOs.js +78 -6
  20. package/dist/utils/getUserOs.js.map +1 -1
  21. package/dist/utils/ghOperations.js +104 -6
  22. package/dist/utils/ghOperations.js.map +1 -1
  23. package/dist/utils/parseCommandOptions.js +4 -4
  24. package/dist/utils/parseCommandOptions.js.map +1 -1
  25. package/dist/utils/windowsPackageManagers.js +103 -0
  26. package/dist/utils/windowsPackageManagers.js.map +1 -0
  27. package/package.json +35 -8
  28. package/bin/.gitkeep +0 -0
  29. package/bin/aptos.ts +0 -44
  30. package/bin/tasks/install.ts +0 -55
  31. package/bin/tasks/run.ts +0 -27
  32. package/bin/tasks/update.ts +0 -41
  33. package/bin/utils/aptosExecutableIsAvailable.ts +0 -14
  34. package/bin/utils/brewOperations.ts +0 -12
  35. package/bin/utils/consts.ts +0 -3
  36. package/bin/utils/execSyncShell.ts +0 -8
  37. package/bin/utils/getLocalBinPath.ts +0 -28
  38. package/bin/utils/getUserOs.ts +0 -18
  39. package/bin/utils/ghOperations.ts +0 -20
  40. package/bin/utils/handleHelpOptions.ts +0 -38
  41. package/bin/utils/parseCommandOptions.ts +0 -28
  42. package/bin/utils/versions.ts +0 -9
  43. package/dist/aptos.d.ts +0 -2
  44. package/dist/tasks/install.d.ts +0 -1
  45. package/dist/tasks/run.d.ts +0 -1
  46. package/dist/tasks/update.d.ts +0 -1
  47. package/dist/utils/aptosExecutableIsAvailable.d.ts +0 -1
  48. package/dist/utils/aptosExecutableIsAvailable.js +0 -11
  49. package/dist/utils/aptosExecutableIsAvailable.js.map +0 -1
  50. package/dist/utils/brewOperations.d.ts +0 -1
  51. package/dist/utils/consts.d.ts +0 -2
  52. package/dist/utils/execSyncShell.d.ts +0 -1
  53. package/dist/utils/getLocalBinPath.d.ts +0 -1
  54. package/dist/utils/getUserOs.d.ts +0 -1
  55. package/dist/utils/ghOperations.d.ts +0 -1
  56. package/dist/utils/handleHelpOptions.d.ts +0 -2
  57. package/dist/utils/handleHelpOptions.js +0 -16
  58. package/dist/utils/handleHelpOptions.js.map +0 -1
  59. package/dist/utils/parseCommandOptions.d.ts +0 -5
  60. package/dist/utils/versions.d.ts +0 -1
  61. package/dist/utils/versions.js +0 -6
  62. package/dist/utils/versions.js.map +0 -1
package/README.md CHANGED
@@ -42,6 +42,28 @@ If you already have the Aptos CLI binary installed on your system, you can speci
42
42
  npx aptos --binary-path /path/to/aptos <command>
43
43
  ```
44
44
 
45
+ ### Installing a Specific Version
46
+
47
+ You can install a specific version of the Aptos CLI by setting the `APTOS_CLI_VERSION` environment variable:
48
+
49
+ ```bash
50
+ # Install version 4.5.0
51
+ APTOS_CLI_VERSION=4.5.0 npx aptos --install
52
+
53
+ # Or with the v prefix
54
+ APTOS_CLI_VERSION=v4.5.0 npx aptos --install
55
+ ```
56
+
57
+ When `APTOS_CLI_VERSION` is set:
58
+ - The specified version is downloaded directly from GitHub releases (package managers are bypassed)
59
+ - The version is validated to ensure it exists before downloading
60
+ - This works for both `--install` and `--update` commands
61
+
62
+ This is useful for:
63
+ - Pinning to a known working version
64
+ - Testing against specific CLI versions
65
+ - Reproducible builds in CI/CD pipelines
66
+
45
67
  ## Updating the Aptos CLI
46
68
 
47
69
  To update the Aptos CLI, you can run the following command within your project environment:
@@ -73,3 +95,90 @@ To build the project:
73
95
  ```bash
74
96
  npm run build
75
97
  ```
98
+
99
+ ## Building Move Artifacts in CI/CD
100
+
101
+ The Aptos CLI can be used in CI/CD pipelines to build Move packages and generate deployment payloads. This is useful for automated deployments and multi-step workflows.
102
+
103
+ ### Example: Building Publish Payload
104
+
105
+ ```yaml
106
+ # In your GitHub Actions workflow
107
+
108
+ # Prerequisites: Set up Node.js first
109
+ - name: Setup Node.js
110
+ uses: actions/setup-node@v4
111
+ with:
112
+ node-version: "20"
113
+
114
+ - name: Install Aptos CLI npm package
115
+ run: npm install @aptos-labs/aptos-cli
116
+
117
+ - name: Install Aptos CLI
118
+ run: npx aptos --install
119
+
120
+ - name: Build Move package
121
+ working-directory: your-move-project
122
+ run: |
123
+ ~/.local/bin/aptos move compile \
124
+ --named-addresses your_module=0x1 \
125
+ --save-metadata
126
+
127
+ - name: Generate publish payload
128
+ working-directory: your-move-project
129
+ run: |
130
+ ~/.local/bin/aptos move build-publish-payload \
131
+ --named-addresses your_module=0x1 \
132
+ --json-output-file publish-payload.json \
133
+ --assume-yes
134
+
135
+ - name: Upload artifact for later steps
136
+ uses: actions/upload-artifact@v4
137
+ with:
138
+ name: move-artifacts
139
+ path: your-move-project/publish-payload.json
140
+ ```
141
+
142
+ ### Example: Building Upgrade Payload (Object Code Deployment)
143
+
144
+ For upgrading existing object-deployed contracts:
145
+
146
+ ```yaml
147
+ - name: Generate upgrade payload
148
+ working-directory: your-move-project
149
+ run: |
150
+ ~/.local/bin/aptos move build-upgrade-payload \
151
+ --named-addresses your_module=0x1 \
152
+ --object-address 0xYOUR_OBJECT_ADDRESS \
153
+ --json-output-file upgrade-payload.json \
154
+ --assume-yes
155
+ ```
156
+
157
+ ### Using Artifacts in Subsequent Jobs
158
+
159
+ ```yaml
160
+ jobs:
161
+ build:
162
+ runs-on: ubuntu-latest
163
+ steps:
164
+ # ... build steps above ...
165
+ - uses: actions/upload-artifact@v4
166
+ with:
167
+ name: move-artifacts
168
+ path: your-move-project/publish-payload.json
169
+
170
+ deploy:
171
+ needs: build
172
+ runs-on: ubuntu-latest
173
+ steps:
174
+ - uses: actions/download-artifact@v4
175
+ with:
176
+ name: move-artifacts
177
+
178
+ - name: Use the payload
179
+ run: |
180
+ # The payload JSON can be used for deployment
181
+ cat publish-payload.json
182
+ ```
183
+
184
+ See the [build-move-artifacts.yaml](.github/workflows/build-move-artifacts.yaml) workflow for a complete working example.
package/dist/aptos.js CHANGED
@@ -1,20 +1,25 @@
1
1
  #!/usr/bin/env node
2
2
  import { program } from "commander";
3
- import { parseCommandOptions } from "./utils/parseCommandOptions.js";
4
3
  import { runCLI } from "./tasks/run.js";
4
+ import { parseCommandOptions } from "./utils/parseCommandOptions.js";
5
5
  program
6
6
  .name("aptos")
7
7
  .helpOption(false)
8
8
  .option("-i, --install", "install the latest version of the CLI")
9
9
  .option("-u, --update", "update the CLI to the latest version")
10
10
  .option("-b, --binary-path <path>", "path to an existing Aptos CLI binary")
11
- .allowUnknownOption();
11
+ .option("-d, --direct-download", "skip package managers and download directly from GitHub")
12
+ .allowUnknownOption()
13
+ .allowExcessArguments(true);
12
14
  program.parse(process.argv);
13
15
  const main = async () => {
14
16
  const options = {
15
17
  install: program.opts().install,
16
18
  update: program.opts().update,
17
19
  binaryPath: program.opts().binaryPath,
20
+ directDownload: program.opts().directDownload ||
21
+ process.env.APTOS_DIRECT_DOWNLOAD === "1" ||
22
+ process.env.APTOS_DIRECT_DOWNLOAD === "true",
18
23
  };
19
24
  const unknownOptions = program.args;
20
25
  if (process.argv.includes("--help")) {
package/dist/aptos.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"aptos.js","sourceRoot":"","sources":["../bin/aptos.ts"],"names":[],"mappings":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AAE,MAAM,gCAAgC,CAAC;AAErE,OAAO;KACJ,IAAI,CAAC,OAAO,CAAC;KACb,UAAU,CAAC,KAAK,CAAC;KACjB,MAAM,CAAC,eAAe,EAAE,uCAAuC,CAAC;KAChE,MAAM,CAAC,cAAc,EAAE,sCAAsC,CAAC;KAC9D,MAAM,CAAC,0BAA0B,EAAE,sCAAsC,CAAC;KAC1E,MAAM,CACL,uBAAuB,EACvB,yDAAyD,CAC1D;KACA,kBAAkB,EAAE;KACpB,oBAAoB,CAAC,IAAI,CAAC,CAAC;AAE9B,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAE5B,MAAM,IAAI,GAAG,KAAK,IAAI,EAAE;IACtB,MAAM,OAAO,GAAG;QACd,OAAO,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC,OAAO;QAC/B,MAAM,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC,MAAM;QAC7B,UAAU,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC,UAAU;QACrC,cAAc,EACZ,OAAO,CAAC,IAAI,EAAE,CAAC,cAAc;YAC7B,OAAO,CAAC,GAAG,CAAC,qBAAqB,KAAK,GAAG;YACzC,OAAO,CAAC,GAAG,CAAC,qBAAqB,KAAK,MAAM;KAC/C,CAAC;IACF,MAAM,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAGpC,IAAI,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;QAEpC,OAAO,MAAM,CAAC,cAAc,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;IACpD,CAAC;IAED,MAAM,mBAAmB,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;AACrD,CAAC,CAAC;AAEF,IAAI,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC","sourcesContent":["#!/usr/bin/env node\n\n// Installation priorities by platform:\n//\n// macOS:\n// 1. Homebrew (if available) - builds for native CPU architecture\n// 2. Direct download from GitHub releases\n//\n// Windows:\n// 1. winget (if available)\n// 2. Chocolatey (if available)\n// 3. Direct download from GitHub releases\n//\n// Linux:\n// - Direct download from GitHub releases (with Ubuntu version detection)\n//\n// Use --direct-download or set APTOS_DIRECT_DOWNLOAD=1 to skip package managers.\n\nimport { program } from \"commander\";\nimport { runCLI } from \"./tasks/run.js\";\nimport { parseCommandOptions } from \"./utils/parseCommandOptions.js\";\n\nprogram\n .name(\"aptos\")\n .helpOption(false)\n .option(\"-i, --install\", \"install the latest version of the CLI\")\n .option(\"-u, --update\", \"update the CLI to the latest version\")\n .option(\"-b, --binary-path <path>\", \"path to an existing Aptos CLI binary\")\n .option(\n \"-d, --direct-download\",\n \"skip package managers and download directly from GitHub\",\n )\n .allowUnknownOption()\n .allowExcessArguments(true);\n\nprogram.parse(process.argv);\n\nconst main = async () => {\n const options = {\n install: program.opts().install,\n update: program.opts().update,\n binaryPath: program.opts().binaryPath,\n directDownload:\n program.opts().directDownload ||\n process.env.APTOS_DIRECT_DOWNLOAD === \"1\" ||\n process.env.APTOS_DIRECT_DOWNLOAD === \"true\",\n };\n const unknownOptions = program.args;\n\n // Manually check for `--help` and handle the CLI `--help`\n if (process.argv.includes(\"--help\")) {\n // Forward to the CLI\n return runCLI(unknownOptions, options.binaryPath);\n }\n\n await parseCommandOptions(options, unknownOptions);\n};\n\nmain().catch(console.error);\n"]}
@@ -1,42 +1,120 @@
1
- import { execSync } from "child_process";
2
- import { existsSync } from "fs";
1
+ import { execFileSync, execSync } from "node:child_process";
2
+ import { createHash } from "node:crypto";
3
+ import { chmodSync, createReadStream, existsSync, mkdirSync, renameSync, } from "node:fs";
4
+ import { tmpdir } from "node:os";
5
+ import { join } from "node:path";
6
+ import { installViaBrew, isBrewAvailable, isInstalledViaBrew, } from "../utils/brewOperations.js";
3
7
  import { GH_CLI_DOWNLOAD_URL, PNAME } from "../utils/consts.js";
4
- import { execSyncShell } from "../utils/execSyncShell.js";
5
- import { getCurrentOpenSSLVersion } from "../utils/versions.js";
6
- import { getOS } from "../utils/getUserOs.js";
7
- import { getLocalBinPath } from "../utils/getLocalBinPath.js";
8
- import { getLatestVersionGh } from "../utils/ghOperations.js";
9
- export const installCli = async () => {
10
- const path = getLocalBinPath();
11
- if (existsSync(path)) {
8
+ import { getBinDir, getLocalBinPath, invalidateBinPathCache, } from "../utils/getLocalBinPath.js";
9
+ import { getPlatformInfo, getTargetPlatform } from "../utils/getUserOs.js";
10
+ import { getAssetDigest, getCliVersion, hasUserSpecifiedVersion, } from "../utils/ghOperations.js";
11
+ import { installViaChoco, installViaWinget, isChocoAvailable, isInstalledViaChoco, isInstalledViaWinget, isWingetAvailable, } from "../utils/windowsPackageManagers.js";
12
+ const sha256File = (filePath) => {
13
+ return new Promise((resolve, reject) => {
14
+ const hash = createHash("sha256");
15
+ const stream = createReadStream(filePath);
16
+ stream.on("data", (chunk) => hash.update(chunk));
17
+ stream.on("end", () => resolve(hash.digest("hex")));
18
+ stream.on("error", reject);
19
+ });
20
+ };
21
+ const verifyChecksum = async (filePath, expectedDigest) => {
22
+ if (!expectedDigest) {
23
+ console.log("Checksum not available from GitHub API, skipping verification");
24
+ return;
25
+ }
26
+ const actual = await sha256File(filePath);
27
+ if (actual !== expectedDigest) {
28
+ throw new Error(`Checksum verification failed!\n` +
29
+ ` Expected: ${expectedDigest}\n` +
30
+ ` Actual: ${actual}\n` +
31
+ `The downloaded file may be corrupted or tampered with.`);
32
+ }
33
+ console.log("Checksum verified");
34
+ };
35
+ export const installCli = async (directDownload = false) => {
36
+ invalidateBinPathCache();
37
+ const { os } = getPlatformInfo();
38
+ const useDirectDownload = directDownload || hasUserSpecifiedVersion();
39
+ if (useDirectDownload && hasUserSpecifiedVersion()) {
40
+ console.log(`Using specified version from APTOS_CLI_VERSION: ${process.env.APTOS_CLI_VERSION}`);
41
+ }
42
+ if (!useDirectDownload) {
43
+ if (os === "macos" && isBrewAvailable()) {
44
+ if (isInstalledViaBrew()) {
45
+ console.log("Aptos CLI is already installed via Homebrew");
46
+ return;
47
+ }
48
+ installViaBrew();
49
+ return;
50
+ }
51
+ if (os === "windows") {
52
+ if (isWingetAvailable()) {
53
+ if (isInstalledViaWinget()) {
54
+ console.log("Aptos CLI is already installed via winget");
55
+ return;
56
+ }
57
+ installViaWinget();
58
+ return;
59
+ }
60
+ if (isChocoAvailable()) {
61
+ if (isInstalledViaChoco()) {
62
+ console.log("Aptos CLI is already installed via Chocolatey");
63
+ return;
64
+ }
65
+ installViaChoco();
66
+ return;
67
+ }
68
+ }
69
+ }
70
+ const binaryPath = getLocalBinPath();
71
+ if (existsSync(binaryPath)) {
12
72
  console.log("Aptos CLI is already installed");
13
73
  return;
14
74
  }
15
- const latestCLIVersion = await getLatestVersionGh();
16
- console.log(`Downloading aptos CLI version ${latestCLIVersion}`);
17
- const os = getOS();
18
- if (os === "Windows") {
19
- const url = `${GH_CLI_DOWNLOAD_URL}/${PNAME}-v${latestCLIVersion}/${PNAME}-${latestCLIVersion}-${os}-x86_64.zip`;
20
- execSync(`powershell -Command "if (!(Test-Path -Path 'C:\\tmp')) { New-Item -ItemType Directory -Path 'C:\\tmp' } ; Invoke-RestMethod -Uri ${url} -OutFile C:\\tmp\\aptos.zip; Expand-Archive -Path C:\\tmp\\aptos.zip -DestinationPath C:\\tmp -Force; Move-Item -Path C:\\tmp\\aptos.exe -Destination \"${path}\""`);
21
- }
22
- else if (os === "MacOS") {
23
- execSyncShell("brew install aptos", { encoding: "utf8" });
24
- }
25
- else {
26
- let osVersion = "x86_64";
27
- let opensSslVersion = "1.0.0";
28
- try {
29
- opensSslVersion = getCurrentOpenSSLVersion();
75
+ const binDir = getBinDir();
76
+ if (!existsSync(binDir)) {
77
+ mkdirSync(binDir, { recursive: true });
78
+ }
79
+ const targetPlatform = getTargetPlatform();
80
+ const version = await getCliVersion(targetPlatform);
81
+ console.log(`Downloading Aptos CLI version ${version} for ${targetPlatform}...`);
82
+ const assetName = `${PNAME}-${version}-${targetPlatform}.zip`;
83
+ const url = `${GH_CLI_DOWNLOAD_URL}/${PNAME}-v${version}/${assetName}`;
84
+ const expectedDigest = await getAssetDigest(version, assetName);
85
+ const tempDir = tmpdir();
86
+ const zipPath = join(tempDir, "aptos-cli.zip");
87
+ try {
88
+ if (os === "windows") {
89
+ execSync(`powershell -Command "Invoke-WebRequest -Uri '${url}' -OutFile '${zipPath}'"`, { stdio: "inherit" });
90
+ await verifyChecksum(zipPath, expectedDigest);
91
+ execSync(`powershell -Command "` +
92
+ `Expand-Archive -Path '${zipPath}' -DestinationPath '${binDir}' -Force; ` +
93
+ `Remove-Item -Path '${zipPath}' -Force"`, { stdio: "inherit" });
30
94
  }
31
- catch (error) {
32
- console.log("Could not determine OpenSSL version, assuming older version (1.x.x)");
95
+ else {
96
+ execFileSync("curl", ["-L", "-o", zipPath, url], { stdio: "inherit" });
97
+ await verifyChecksum(zipPath, expectedDigest);
98
+ execFileSync("unzip", ["-o", "-q", zipPath, "-d", tempDir], {
99
+ stdio: "inherit",
100
+ });
101
+ const extractedBinary = join(tempDir, "aptos");
102
+ renameSync(extractedBinary, binaryPath);
103
+ chmodSync(binaryPath, 0o755);
104
+ try {
105
+ execFileSync("rm", ["-f", zipPath], { stdio: "ignore" });
106
+ }
107
+ catch {
108
+ }
33
109
  }
34
- if (opensSslVersion.startsWith("3.")) {
35
- osVersion = "22.04-x86_64";
110
+ console.log(`Aptos CLI installed successfully to ${binaryPath}`);
111
+ if (os !== "windows") {
112
+ console.log(`\nMake sure ${binDir} is in your PATH. You can add it by running:`);
113
+ console.log(` export PATH="${binDir}:$PATH"`);
36
114
  }
37
- console.log(`Downloading CLI binary ${os}-${osVersion}`);
38
- const url = `${GH_CLI_DOWNLOAD_URL}/${PNAME}-v${latestCLIVersion}/${PNAME}-${latestCLIVersion}-${os}-${osVersion}.zip`;
39
- execSync(`curl -L -o /tmp/aptos.zip ${url}; unzip -o -q /tmp/aptos.zip -d /tmp; mv /tmp/aptos ${path};`);
115
+ }
116
+ catch (error) {
117
+ throw new Error(`Failed to install Aptos CLI: ${error instanceof Error ? error.message : String(error)}`);
40
118
  }
41
119
  };
42
120
  //# sourceMappingURL=install.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"install.js","sourceRoot":"","sources":["../../bin/tasks/install.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAEhC,OAAO,EAAE,mBAAmB,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAG9D,MAAM,CAAC,MAAM,UAAU,GAAG,KAAK,IAAI,EAAE;IACnC,MAAM,IAAI,GAAG,eAAe,EAAE,CAAC;IAC/B,IAAI,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QACrB,OAAO,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAC;QAC9C,OAAO;IACT,CAAC;IAED,MAAM,gBAAgB,GAAG,MAAM,kBAAkB,EAAE,CAAC;IACpD,OAAO,CAAC,GAAG,CAAC,iCAAiC,gBAAgB,EAAE,CAAC,CAAC;IACjE,MAAM,EAAE,GAAG,KAAK,EAAE,CAAC;IAEnB,IAAI,EAAE,KAAK,SAAS,EAAE,CAAC;QACrB,MAAM,GAAG,GAAG,GAAG,mBAAmB,IAAI,KAAK,KAAK,gBAAgB,IAAI,KAAK,IAAI,gBAAgB,IAAI,EAAE,aAAa,CAAC;QAEjH,QAAQ,CACN,oIAAoI,GAAG,4JAA4J,IAAI,KAAK,CAC7S,CAAC;IACJ,CAAC;SAAM,IAAI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,CAAC,CAAC","sourcesContent":["import { execFileSync, execSync } from \"node:child_process\";\nimport { createHash } from \"node:crypto\";\nimport {\n chmodSync,\n createReadStream,\n existsSync,\n mkdirSync,\n renameSync,\n} from \"node:fs\";\nimport { tmpdir } from \"node:os\";\nimport { join } from \"node:path\";\nimport {\n installViaBrew,\n isBrewAvailable,\n isInstalledViaBrew,\n} from \"../utils/brewOperations.js\";\nimport { GH_CLI_DOWNLOAD_URL, PNAME } from \"../utils/consts.js\";\nimport {\n getBinDir,\n getLocalBinPath,\n invalidateBinPathCache,\n} from \"../utils/getLocalBinPath.js\";\nimport { getPlatformInfo, getTargetPlatform } from \"../utils/getUserOs.js\";\nimport {\n getAssetDigest,\n getCliVersion,\n hasUserSpecifiedVersion,\n} from \"../utils/ghOperations.js\";\nimport {\n installViaChoco,\n installViaWinget,\n isChocoAvailable,\n isInstalledViaChoco,\n isInstalledViaWinget,\n isWingetAvailable,\n} from \"../utils/windowsPackageManagers.js\";\n\n/**\n * Compute the SHA256 hex digest of a file.\n */\nconst sha256File = (filePath: string): Promise<string> => {\n return new Promise((resolve, reject) => {\n const hash = createHash(\"sha256\");\n const stream = createReadStream(filePath);\n stream.on(\"data\", (chunk) => hash.update(chunk));\n stream.on(\"end\", () => resolve(hash.digest(\"hex\")));\n stream.on(\"error\", reject);\n });\n};\n\n/**\n * Verify a downloaded file against its expected SHA256 digest.\n * Warns on mismatch or if digest is unavailable; throws on mismatch.\n */\nconst verifyChecksum = async (\n filePath: string,\n expectedDigest: string | null,\n): Promise<void> => {\n if (!expectedDigest) {\n console.log(\n \"Checksum not available from GitHub API, skipping verification\",\n );\n return;\n }\n\n const actual = await sha256File(filePath);\n if (actual !== expectedDigest) {\n throw new Error(\n `Checksum verification failed!\\n` +\n ` Expected: ${expectedDigest}\\n` +\n ` Actual: ${actual}\\n` +\n `The downloaded file may be corrupted or tampered with.`,\n );\n }\n console.log(\"Checksum verified\");\n};\n\n/**\n * Install the Aptos CLI.\n *\n * Installation priority:\n *\n * macOS:\n * 1. Homebrew (if available)\n * 2. Direct download from GitHub releases\n *\n * Windows:\n * 1. winget (if available)\n * 2. Chocolatey (if available)\n * 3. Direct download from GitHub releases\n *\n * Linux:\n * - Direct download from GitHub releases\n *\n * Note: When APTOS_CLI_VERSION is set, package managers are skipped and the\n * specified version is downloaded directly from GitHub releases.\n *\n * @param directDownload - If true, skip package managers and download directly\n */\nexport const installCli = async (\n directDownload: boolean = false,\n): Promise<void> => {\n invalidateBinPathCache();\n const { os } = getPlatformInfo();\n\n // If a specific version is requested, force direct download\n // Package managers don't support installing specific versions\n const useDirectDownload = directDownload || hasUserSpecifiedVersion();\n\n if (useDirectDownload && hasUserSpecifiedVersion()) {\n console.log(\n `Using specified version from APTOS_CLI_VERSION: ${process.env.APTOS_CLI_VERSION}`,\n );\n }\n\n // Skip package managers if directDownload is set or specific version requested\n if (!useDirectDownload) {\n // On macOS, prefer Homebrew if available\n if (os === \"macos\" && isBrewAvailable()) {\n if (isInstalledViaBrew()) {\n console.log(\"Aptos CLI is already installed via Homebrew\");\n return;\n }\n installViaBrew();\n return;\n }\n\n // On Windows, prefer winget, then Chocolatey\n if (os === \"windows\") {\n if (isWingetAvailable()) {\n if (isInstalledViaWinget()) {\n console.log(\"Aptos CLI is already installed via winget\");\n return;\n }\n installViaWinget();\n return;\n }\n\n if (isChocoAvailable()) {\n if (isInstalledViaChoco()) {\n console.log(\"Aptos CLI is already installed via Chocolatey\");\n return;\n }\n installViaChoco();\n return;\n }\n }\n }\n\n // Direct download installation\n const binaryPath = getLocalBinPath();\n if (existsSync(binaryPath)) {\n console.log(\"Aptos CLI is already installed\");\n return;\n }\n\n // Ensure the bin directory exists\n const binDir = getBinDir();\n if (!existsSync(binDir)) {\n mkdirSync(binDir, { recursive: true });\n }\n\n // Get target platform first for version validation\n const targetPlatform = getTargetPlatform();\n\n // Get the version to install (user-specified or latest)\n const version = await getCliVersion(targetPlatform);\n\n console.log(\n `Downloading Aptos CLI version ${version} for ${targetPlatform}...`,\n );\n\n // Build download URL matching official release artifact naming\n const assetName = `${PNAME}-${version}-${targetPlatform}.zip`;\n const url = `${GH_CLI_DOWNLOAD_URL}/${PNAME}-v${version}/${assetName}`;\n\n // Fetch expected checksum from GitHub API (non-blocking)\n const expectedDigest = await getAssetDigest(version, assetName);\n\n const tempDir = tmpdir();\n const zipPath = join(tempDir, \"aptos-cli.zip\");\n\n try {\n if (os === \"windows\") {\n // Download\n execSync(\n `powershell -Command \"Invoke-WebRequest -Uri '${url}' -OutFile '${zipPath}'\"`,\n { stdio: \"inherit\" },\n );\n\n // Verify checksum before extraction\n await verifyChecksum(zipPath, expectedDigest);\n\n // Extract and clean up\n execSync(\n `powershell -Command \"` +\n `Expand-Archive -Path '${zipPath}' -DestinationPath '${binDir}' -Force; ` +\n `Remove-Item -Path '${zipPath}' -Force\"`,\n { stdio: \"inherit\" },\n );\n } else {\n // Download (argument array avoids shell injection)\n execFileSync(\"curl\", [\"-L\", \"-o\", zipPath, url], { stdio: \"inherit\" });\n\n // Verify checksum before extraction\n await verifyChecksum(zipPath, expectedDigest);\n\n // Extract\n execFileSync(\"unzip\", [\"-o\", \"-q\", zipPath, \"-d\", tempDir], {\n stdio: \"inherit\",\n });\n\n // Move binary to bin directory\n const extractedBinary = join(tempDir, \"aptos\");\n renameSync(extractedBinary, binaryPath);\n\n // Set executable permissions\n chmodSync(binaryPath, 0o755);\n\n // Clean up\n try {\n execFileSync(\"rm\", [\"-f\", zipPath], { stdio: \"ignore\" });\n } catch {\n // Ignore cleanup errors\n }\n }\n\n console.log(`Aptos CLI installed successfully to ${binaryPath}`);\n\n // Remind user about PATH if needed\n if (os !== \"windows\") {\n console.log(\n `\\nMake sure ${binDir} is in your PATH. You can add it by running:`,\n );\n console.log(` export PATH=\"${binDir}:$PATH\"`);\n }\n } catch (error) {\n throw new Error(\n `Failed to install Aptos CLI: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n};\n"]}
package/dist/tasks/run.js CHANGED
@@ -1,10 +1,10 @@
1
- import { spawn } from "child_process";
2
- import { existsSync } from "fs";
3
- import { getOS } from "../utils/getUserOs.js";
1
+ import { spawn } from "node:child_process";
2
+ import { existsSync } from "node:fs";
4
3
  import { getLocalBinPath } from "../utils/getLocalBinPath.js";
4
+ import { getPlatformInfo } from "../utils/getUserOs.js";
5
5
  export const runCLI = async (args = [], binaryPath) => {
6
- const path = binaryPath || getLocalBinPath();
7
- if (!existsSync(path)) {
6
+ const cliPath = binaryPath || getLocalBinPath();
7
+ if (!existsSync(cliPath)) {
8
8
  if (binaryPath) {
9
9
  console.error(`Error: Binary not found at specified path: ${binaryPath}`);
10
10
  process.exit(1);
@@ -12,10 +12,15 @@ export const runCLI = async (args = [], binaryPath) => {
12
12
  console.log("Aptos CLI not installed, run `npx aptos --install` to install");
13
13
  return;
14
14
  }
15
- const os = getOS();
16
- spawn(path, args, {
15
+ const { os } = getPlatformInfo();
16
+ const child = spawn(cliPath, args, {
17
17
  stdio: "inherit",
18
- shell: os === "Windows",
18
+ shell: os === "windows",
19
+ });
20
+ child.on("exit", (code) => {
21
+ if (code !== null && code !== 0) {
22
+ process.exit(code);
23
+ }
19
24
  });
20
25
  };
21
26
  //# sourceMappingURL=run.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"run.js","sourceRoot":"","sources":["../../bin/tasks/run.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAEhC,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAE9D,MAAM,CAAC,MAAM,MAAM,GAAG,KAAK,EAAE,OAAiB,EAAE,EAAE,UAAmB,EAAE,EAAE;IACvE,MAAM,IAAI,GAAG,UAAU,IAAI,eAAe,EAAE,CAAC;IAC7C,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC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;QAChB,KAAK,EAAE,EAAE,KAAK,SAAS;KACxB,CAAC,CAAC;IAGH,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;QACxB,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,CAAC,EAAE,CAAC;YAChC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACrB,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC","sourcesContent":["import { spawn } from \"node:child_process\";\nimport { existsSync } from \"node:fs\";\nimport { getLocalBinPath } from \"../utils/getLocalBinPath.js\";\nimport { getPlatformInfo } from \"../utils/getUserOs.js\";\n\n/**\n * Run the Aptos CLI with the provided arguments.\n * @param args - Arguments to pass to the CLI\n * @param binaryPath - Optional path to a custom binary\n */\nexport const runCLI = async (\n args: string[] = [],\n binaryPath?: string,\n): Promise<void> => {\n const cliPath = binaryPath || getLocalBinPath();\n\n if (!existsSync(cliPath)) {\n if (binaryPath) {\n console.error(`Error: Binary not found at specified path: ${binaryPath}`);\n process.exit(1);\n }\n console.log(\n \"Aptos CLI not installed, run `npx aptos --install` to install\",\n );\n return;\n }\n\n const { os } = getPlatformInfo();\n\n // Spawn a child process to run the real CLI executable with the forwarded arguments\n const child = spawn(cliPath, args, {\n stdio: \"inherit\", // Forward the stdio so output is visible\n shell: os === \"windows\", // Use shell on Windows for proper path handling\n });\n\n // Forward the exit code from the child process to the parent\n child.on(\"exit\", (code) => {\n if (code !== null && code !== 0) {\n process.exit(code);\n }\n });\n};\n"]}
@@ -1,33 +1,69 @@
1
- import { existsSync } from "fs";
2
- import { getLocalBinPath } from "../utils/getLocalBinPath.js";
3
- import { execSync } from "child_process";
4
- import { getOS } from "../utils/getUserOs.js";
5
- import { getLatestVersionGh } from "../utils/ghOperations.js";
1
+ import { existsSync, unlinkSync } from "node:fs";
2
+ import { isInstalledViaBrew, updateViaBrew } from "../utils/brewOperations.js";
6
3
  import { execSyncShell } from "../utils/execSyncShell.js";
4
+ import { getLocalBinPath, invalidateBinPathCache, } from "../utils/getLocalBinPath.js";
5
+ import { getTargetPlatform } from "../utils/getUserOs.js";
6
+ import { getCliVersion, hasUserSpecifiedVersion, } from "../utils/ghOperations.js";
7
+ import { isInstalledViaChoco, isInstalledViaWinget, updateViaChoco, updateViaWinget, } from "../utils/windowsPackageManagers.js";
7
8
  import { installCli } from "./install.js";
8
- export const updateCli = async () => {
9
- const path = getLocalBinPath();
10
- if (!existsSync(path)) {
9
+ export const updateCli = async (directDownload = false) => {
10
+ invalidateBinPathCache();
11
+ const binaryPath = getLocalBinPath();
12
+ if (!existsSync(binaryPath)) {
11
13
  console.log("Aptos CLI not installed, run `npx aptos --install` to install");
12
14
  return;
13
15
  }
14
- if (getOS() === "MacOS") {
15
- return execSync("brew upgrade aptos");
16
+ const useDirectDownload = directDownload || hasUserSpecifiedVersion();
17
+ if (useDirectDownload && hasUserSpecifiedVersion()) {
18
+ console.log(`Using specified version from APTOS_CLI_VERSION: ${process.env.APTOS_CLI_VERSION}`);
16
19
  }
17
- else {
18
- const latestVersion = await getLatestVersionGh();
19
- const currentVersion = execSyncShell(`${path} --version`, {
20
+ if (!useDirectDownload) {
21
+ if (isInstalledViaBrew()) {
22
+ updateViaBrew();
23
+ return;
24
+ }
25
+ if (isInstalledViaWinget()) {
26
+ updateViaWinget();
27
+ return;
28
+ }
29
+ if (isInstalledViaChoco()) {
30
+ updateViaChoco();
31
+ return;
32
+ }
33
+ }
34
+ const targetPlatform = getTargetPlatform();
35
+ const targetVersion = await getCliVersion(targetPlatform);
36
+ let currentVersion;
37
+ try {
38
+ const versionOutput = String(execSyncShell(`"${binaryPath}" --version`, {
20
39
  encoding: "utf8",
21
- })
22
- .trim()
23
- .split(" ")[1];
24
- if (currentVersion !== latestVersion) {
25
- console.log(`A newer version of the CLI is available: ${latestVersion}, installing...`);
26
- await installCli();
40
+ })).trim();
41
+ const match = versionOutput.match(/(\d+\.\d+\.\d+)/);
42
+ currentVersion = match?.[1] ?? "";
43
+ }
44
+ catch {
45
+ console.error("Warning: Could not determine current CLI version");
46
+ currentVersion = "";
47
+ }
48
+ if (currentVersion === targetVersion) {
49
+ if (hasUserSpecifiedVersion()) {
50
+ console.log(`CLI is already at the specified version (${currentVersion})`);
27
51
  }
28
52
  else {
29
- console.log(`CLI is up to date`);
53
+ console.log(`CLI is up to date (version ${currentVersion})`);
30
54
  }
55
+ return;
56
+ }
57
+ const updateDescription = hasUserSpecifiedVersion()
58
+ ? `Switching CLI from version ${currentVersion || "unknown"} to ${targetVersion}...`
59
+ : `Updating CLI from version ${currentVersion || "unknown"} to ${targetVersion}...`;
60
+ console.log(updateDescription);
61
+ try {
62
+ unlinkSync(binaryPath);
63
+ }
64
+ catch {
65
+ console.error(`Warning: Could not remove old binary at ${binaryPath}`);
31
66
  }
67
+ await installCli(useDirectDownload);
32
68
  };
33
69
  //# sourceMappingURL=update.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"update.js","sourceRoot":"","sources":["../../bin/tasks/update.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAEhC,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,IAAI,EAAE;IAClC,MAAM,IAAI,GAAG,eAAe,EAAE,CAAC;IAE/B,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QACtB,OAAO,CAAC,GAAG,CACT,+DAA+D,CAChE,CAAC;QACF,OAAO;IACT,CAAC;IAED,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AAE,CAAC;IACtB,CAAC;IAGD,IAAI,cAAc,KAAK,aAAa,EAAE,CAAC;QACrC,IAAI,uBAAuB,EAAE,EAAE,CAAC;YAC9B,OAAO,CAAC,GAAG,CACT,4CAA4C,cAAc,GAAG,CAC9D,CAAC;QACJ,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,GAAG,CAAC,8BAA8B,cAAc,GAAG,CAAC,CAAC;QAC/D,CAAC;QACD,OAAO;IACT,CAAC;IAED,MAAM,iBAAiB,GAAG,uBAAuB,EAAE;QACjD,CAAC,CAAC,8BAA8B,cAAc,IAAI,SAAS,OAAO,aAAa,KAAK;QACpF,CAAC,CAAC,6BAA6B,cAAc,IAAI,SAAS,OAAO,aAAa,KAAK,CAAC;IAEtF,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;IAG/B,IAAI,CAAC;QACH,UAAU,CAAC,UAAU,CAAC,CAAC;IACzB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,CAAC,KAAK,CAAC,2CAA2C,UAAU,EAAE,CAAC,CAAC;IACzE,CAAC;IAED,MAAM,UAAU,CAAC,iBAAiB,CAAC,CAAC;AACtC,CAAC,CAAC","sourcesContent":["import { existsSync, unlinkSync } from \"node:fs\";\nimport { isInstalledViaBrew, updateViaBrew } from \"../utils/brewOperations.js\";\nimport { execSyncShell } from \"../utils/execSyncShell.js\";\nimport {\n getLocalBinPath,\n invalidateBinPathCache,\n} from \"../utils/getLocalBinPath.js\";\nimport { getTargetPlatform } from \"../utils/getUserOs.js\";\nimport {\n getCliVersion,\n hasUserSpecifiedVersion,\n} from \"../utils/ghOperations.js\";\nimport {\n isInstalledViaChoco,\n isInstalledViaWinget,\n updateViaChoco,\n updateViaWinget,\n} from \"../utils/windowsPackageManagers.js\";\nimport { installCli } from \"./install.js\";\n\n/**\n * Update the Aptos CLI to the latest version (or a specific version if APTOS_CLI_VERSION is set).\n *\n * Update methods by installation type:\n * - Homebrew: `brew upgrade aptos`\n * - winget: `winget upgrade`\n * - Chocolatey: `choco upgrade`\n * - Direct download: Compare versions and reinstall if newer/different\n *\n * Note: When APTOS_CLI_VERSION is set, package managers are skipped and the\n * specified version is downloaded directly from GitHub releases.\n *\n * @param directDownload - If true, skip package manager updates and force direct download\n */\nexport const updateCli = async (\n directDownload: boolean = false,\n): Promise<void> => {\n invalidateBinPathCache();\n const binaryPath = getLocalBinPath();\n\n if (!existsSync(binaryPath)) {\n console.log(\n \"Aptos CLI not installed, run `npx aptos --install` to install\",\n );\n return;\n }\n\n // If a specific version is requested, force direct download\n const useDirectDownload = directDownload || hasUserSpecifiedVersion();\n\n if (useDirectDownload && hasUserSpecifiedVersion()) {\n console.log(\n `Using specified version from APTOS_CLI_VERSION: ${process.env.APTOS_CLI_VERSION}`,\n );\n }\n\n // Check for package manager installations (unless directDownload is set or specific version requested)\n if (!useDirectDownload) {\n // If installed via Homebrew, use brew upgrade\n if (isInstalledViaBrew()) {\n updateViaBrew();\n return;\n }\n\n // If installed via winget, use winget upgrade\n if (isInstalledViaWinget()) {\n updateViaWinget();\n return;\n }\n\n // If installed via Chocolatey, use choco upgrade\n if (isInstalledViaChoco()) {\n updateViaChoco();\n return;\n }\n }\n\n // Get target platform for version validation\n const targetPlatform = getTargetPlatform();\n\n // Get the target version (user-specified or latest)\n const targetVersion = await getCliVersion(targetPlatform);\n\n // Get the current version of the CLI\n let currentVersion: string;\n try {\n const versionOutput = String(\n execSyncShell(`\"${binaryPath}\" --version`, {\n encoding: \"utf8\",\n }),\n ).trim();\n // Extract semver from output (e.g. \"aptos 4.5.0\" or \"aptos-cli 4.5.0\")\n const match = versionOutput.match(/(\\d+\\.\\d+\\.\\d+)/);\n currentVersion = match?.[1] ?? \"\";\n } catch {\n console.error(\"Warning: Could not determine current CLI version\");\n currentVersion = \"\";\n }\n\n // Check if the installed version matches the target version\n if (currentVersion === targetVersion) {\n if (hasUserSpecifiedVersion()) {\n console.log(\n `CLI is already at the specified version (${currentVersion})`,\n );\n } else {\n console.log(`CLI is up to date (version ${currentVersion})`);\n }\n return;\n }\n\n const updateDescription = hasUserSpecifiedVersion()\n ? `Switching CLI from version ${currentVersion || \"unknown\"} to ${targetVersion}...`\n : `Updating CLI from version ${currentVersion || \"unknown\"} to ${targetVersion}...`;\n\n console.log(updateDescription);\n\n // Remove the old binary before installing the new one\n try {\n unlinkSync(binaryPath);\n } catch {\n console.error(`Warning: Could not remove old binary at ${binaryPath}`);\n }\n\n await installCli(useDirectDownload);\n};\n"]}
@@ -1,8 +1,34 @@
1
- import { execSyncShell } from "./execSyncShell.js";
1
+ import { execSync } from "node:child_process";
2
+ import { existsSync } from "node:fs";
3
+ import { executableIsAvailable } from "./executableIsAvailable.js";
4
+ export const isBrewAvailable = () => {
5
+ return executableIsAvailable("brew");
6
+ };
7
+ export const isInstalledViaBrew = () => {
8
+ if (!isBrewAvailable()) {
9
+ return false;
10
+ }
11
+ try {
12
+ const path = getCliPathBrew();
13
+ return existsSync(path);
14
+ }
15
+ catch {
16
+ return false;
17
+ }
18
+ };
2
19
  export const getCliPathBrew = () => {
3
- const directory = execSyncShell("brew --prefix aptos", { encoding: "utf8" })
4
- .toString()
5
- .trim();
20
+ const directory = execSync("brew --prefix aptos", {
21
+ encoding: "utf8",
22
+ stdio: ["pipe", "pipe", "pipe"],
23
+ }).trim();
6
24
  return `${directory}/bin/aptos`;
7
25
  };
26
+ export const installViaBrew = () => {
27
+ console.log("Installing Aptos CLI via Homebrew...");
28
+ execSync("brew install aptos", { stdio: "inherit" });
29
+ };
30
+ export const updateViaBrew = () => {
31
+ console.log("Updating Aptos CLI via Homebrew...");
32
+ execSync("brew upgrade aptos", { stdio: "inherit" });
33
+ };
8
34
  //# sourceMappingURL=brewOperations.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"brewOperations.js","sourceRoot":"","sources":["../../bin/utils/brewOperations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAMnD,MAAM,CAAC,MAAM,cAAc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;IACpD,QAAQ,CAAC,oBAAoB,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;AACvD,CAAC,CAAC;AAKF,MAAM,CAAC,MAAM,aAAa,GAAG,GAAS,EAAE;IACtC,OAAO,CAAC,GAAG,CAAC,oCAAoC,CAAC,CAAC;IAClD,QAAQ,CAAC,oBAAoB,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;AACvD,CAAC,CAAC","sourcesContent":["import { execSync } from \"node:child_process\";\nimport { existsSync } from \"node:fs\";\nimport { executableIsAvailable } from \"./executableIsAvailable.js\";\n\n/**\n * Check if Homebrew is available on the system.\n */\nexport const isBrewAvailable = (): boolean => {\n return executableIsAvailable(\"brew\");\n};\n\n/**\n * Check if the Aptos CLI was installed via Homebrew.\n */\nexport const isInstalledViaBrew = (): boolean => {\n if (!isBrewAvailable()) {\n return false;\n }\n try {\n const path = getCliPathBrew();\n return existsSync(path);\n } catch {\n return false;\n }\n};\n\n/**\n * Get the path to the Aptos CLI binary installed via Homebrew.\n * Based on the installation path of the aptos formula.\n */\nexport const getCliPathBrew = (): string => {\n const directory = execSync(\"brew --prefix aptos\", {\n encoding: \"utf8\",\n stdio: [\"pipe\", \"pipe\", \"pipe\"],\n }).trim();\n return `${directory}/bin/aptos`;\n};\n\n/**\n * Install the Aptos CLI via Homebrew.\n */\nexport const installViaBrew = (): void => {\n console.log(\"Installing Aptos CLI via Homebrew...\");\n execSync(\"brew install aptos\", { stdio: \"inherit\" });\n};\n\n/**\n * Update the Aptos CLI via Homebrew.\n */\nexport const updateViaBrew = (): void => {\n console.log(\"Updating Aptos CLI via Homebrew...\");\n execSync(\"brew upgrade aptos\", { stdio: \"inherit\" });\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"consts.js","sourceRoot":"","sources":["../../bin/utils/consts.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,KAAK,GAAG,WAAW,CAAC;AACjC,MAAM,CAAC,MAAM,mBAAmB,GAC9B,4DAA4D,CAAC"}
1
+ {"version":3,"file":"consts.js","sourceRoot":"","sources":["../../bin/utils/consts.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,KAAK,GAAG,WAAW,CAAC;AACjC,MAAM,CAAC,MAAM,mBAAmB,GAC9B,4DAA4D,CAAC","sourcesContent":["export const PNAME = \"aptos-cli\";\nexport const GH_CLI_DOWNLOAD_URL =\n \"https://github.com/aptos-labs/aptos-core/releases/download\";\n"]}
@@ -1,5 +1,6 @@
1
- import { execSync } from "child_process";
1
+ import { execSync } from "node:child_process";
2
2
  export const execSyncShell = (command, options) => {
3
- return execSync(command, { shell: true, ...options });
3
+ const shell = process.platform === "win32" ? "cmd.exe" : "/bin/sh";
4
+ return execSync(command, { ...options, shell });
4
5
  };
5
6
  //# sourceMappingURL=execSyncShell.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"execSyncShell.js","sourceRoot":"","sources":["../../bin/utils/execSyncShell.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAKzC,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE;IAChD,OAAO,QAAQ,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;AACxD,CAAC,CAAC"}
1
+ {"version":3,"file":"execSyncShell.js","sourceRoot":"","sources":["../../bin/utils/execSyncShell.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAQpE,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,OAAe,EACf,OAA8B,EACb,EAAE;IAGnB,MAAM,KAAK,GAAG,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC;IACnE,OAAO,QAAQ,CAAC,OAAO,EAAE,EAAE,GAAG,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;AAClD,CAAC,CAAC","sourcesContent":["import { type ExecSyncOptions, execSync } from \"node:child_process\";\n\ntype ExecSyncShellOptions = Omit<ExecSyncOptions, \"shell\">;\n\n/**\n * Wrapper around execSync that uses the shell.\n * This always executes with shell: true for cross-platform compatibility.\n */\nexport const execSyncShell = (\n command: string,\n options?: ExecSyncShellOptions,\n): Buffer | string => {\n // @types/node overloads type `shell` as only `string`, but Node.js\n // accepts `boolean` at runtime. Use the platform default shell path.\n const shell = process.platform === \"win32\" ? \"cmd.exe\" : \"/bin/sh\";\n return execSync(command, { ...options, shell });\n};\n"]}
@@ -0,0 +1,12 @@
1
+ import { execSync } from "node:child_process";
2
+ export const executableIsAvailable = (name) => {
3
+ try {
4
+ const command = process.platform === "win32" ? `where ${name}` : `which ${name}`;
5
+ execSync(command, { encoding: "utf8", stdio: "pipe" });
6
+ return true;
7
+ }
8
+ catch {
9
+ return false;
10
+ }
11
+ };
12
+ //# sourceMappingURL=executableIsAvailable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executableIsAvailable.js","sourceRoot":"","sources":["../../bin/utils/executableIsAvailable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAM9C,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,IAAY,EAAW,EAAE;IAC7D,IAAI,CAAC;QACH,MAAM,OAAO,GACX,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,CAAC,SAAS,IAAI,EAAE,CAAC;QACnE,QAAQ,CAAC,OAAO,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;QACvD,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC,CAAC","sourcesContent":["import { execSync } from \"node:child_process\";\n\n/**\n * Check if an executable is available on the system.\n * Uses `which` on Unix systems (macOS/Linux) and `where` on Windows.\n */\nexport const executableIsAvailable = (name: string): boolean => {\n try {\n const command =\n process.platform === \"win32\" ? `where ${name}` : `which ${name}`;\n execSync(command, { encoding: \"utf8\", stdio: \"pipe\" });\n return true;\n } catch {\n return false;\n }\n};\n"]}