@inferencesh/belt 1.9.6 → 1.9.8

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 (2) hide show
  1. package/install.js +47 -15
  2. package/package.json +1 -1
package/install.js CHANGED
@@ -3,11 +3,11 @@
3
3
  const https = require("https");
4
4
  const fs = require("fs");
5
5
  const path = require("path");
6
+ const os = require("os");
6
7
  const { execSync } = require("child_process");
7
8
  const crypto = require("crypto");
8
9
 
9
10
  const MANIFEST_URL = "https://dist.inference.sh/cli/manifest.json";
10
- const BIN_DIR = path.join(__dirname, "bin");
11
11
 
12
12
  const PLATFORM = { darwin: "darwin", linux: "linux", win32: "windows" }[
13
13
  process.platform
@@ -21,6 +21,17 @@ if (!PLATFORM || !ARCH) {
21
21
 
22
22
  const KEY = `${PLATFORM}-${ARCH}`;
23
23
 
24
+ function getInstallDir() {
25
+ // Same logic as the curl installer
26
+ if (process.platform === "win32") {
27
+ return path.join(os.homedir(), ".local", "bin");
28
+ }
29
+ if (process.getuid && process.getuid() === 0) {
30
+ return "/usr/local/bin";
31
+ }
32
+ return path.join(os.homedir(), ".local", "bin");
33
+ }
34
+
24
35
  function fetch(url) {
25
36
  return new Promise((resolve, reject) => {
26
37
  https
@@ -41,6 +52,7 @@ function fetch(url) {
41
52
  }
42
53
 
43
54
  async function main() {
55
+ const installDir = getInstallDir();
44
56
  console.log(`Downloading belt for ${PLATFORM}/${ARCH}...`);
45
57
 
46
58
  const manifest = JSON.parse(await fetch(MANIFEST_URL));
@@ -59,34 +71,54 @@ async function main() {
59
71
  process.exit(1);
60
72
  }
61
73
 
62
- fs.mkdirSync(BIN_DIR, { recursive: true });
63
-
64
- const archivePath = path.join(BIN_DIR, path.basename(build.url));
74
+ const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "belt-"));
75
+ const archivePath = path.join(tmpDir, path.basename(build.url));
65
76
  fs.writeFileSync(archivePath, archive);
66
77
 
67
78
  // Extract
68
79
  if (archivePath.endsWith(".zip")) {
69
- execSync(`unzip -o "${archivePath}" -d "${BIN_DIR}"`, { stdio: "pipe" });
80
+ execSync(`unzip -o "${archivePath}" -d "${tmpDir}"`, { stdio: "pipe" });
70
81
  } else {
71
- execSync(`tar -xzf "${archivePath}" -C "${BIN_DIR}"`, { stdio: "pipe" });
82
+ execSync(`tar -xzf "${archivePath}" -C "${tmpDir}"`, { stdio: "pipe" });
72
83
  }
73
84
 
74
- // Find the binary and rename to belt
85
+ // Find the extracted binary
75
86
  const ext = PLATFORM === "windows" ? ".exe" : "";
76
- const beltBin = path.join(BIN_DIR, `belt${ext}`);
77
- const files = fs.readdirSync(BIN_DIR).filter((f) => f.startsWith("inferencesh-cli"));
78
- if (files.length > 0) {
79
- fs.renameSync(path.join(BIN_DIR, files[0]), beltBin);
87
+ const files = fs.readdirSync(tmpDir).filter((f) => f.startsWith("inferencesh-cli"));
88
+ if (files.length === 0) {
89
+ console.error("Binary not found in archive");
90
+ process.exit(1);
80
91
  }
81
92
 
93
+ // Install to persistent location
94
+ fs.mkdirSync(installDir, { recursive: true });
95
+ const src = path.join(tmpDir, files[0]);
96
+ const dest = path.join(installDir, `belt${ext}`);
97
+
98
+ fs.copyFileSync(src, dest);
82
99
  if (PLATFORM !== "windows") {
83
- fs.chmodSync(beltBin, 0o755);
100
+ fs.chmodSync(dest, 0o755);
101
+ }
102
+
103
+ // Create symlinks (same as curl installer)
104
+ for (const alias of ["infsh", "inferencesh"]) {
105
+ const link = path.join(installDir, `${alias}${ext}`);
106
+ try { fs.unlinkSync(link); } catch {}
107
+ fs.symlinkSync(`belt${ext}`, link);
84
108
  }
85
109
 
86
- // Clean up archive
87
- fs.unlinkSync(archivePath);
110
+ // Clean up temp
111
+ fs.rmSync(tmpDir, { recursive: true });
112
+
113
+ // Also install into npm bin/ so run.js works for npm install -g
114
+ const npmBin = path.join(__dirname, "bin");
115
+ fs.mkdirSync(npmBin, { recursive: true });
116
+ fs.copyFileSync(dest, path.join(npmBin, `belt${ext}`));
117
+ if (PLATFORM !== "windows") {
118
+ fs.chmodSync(path.join(npmBin, `belt${ext}`), 0o755);
119
+ }
88
120
 
89
- console.log(`Installed belt ${manifest.version}`);
121
+ console.log(`Installed belt ${manifest.version} to ${installDir}`);
90
122
  }
91
123
 
92
124
  main().catch((err) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inferencesh/belt",
3
- "version": "1.9.6",
3
+ "version": "1.9.8",
4
4
  "description": "inference.sh CLI — run AI apps, manage skills, connect MCP servers",
5
5
  "homepage": "https://inference.sh",
6
6
  "repository": "https://github.com/inference-sh/cli",