@anona-labs/anona-compute 0.1.0 → 0.1.2

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 (3) hide show
  1. package/bin/anona-compute +30 -11
  2. package/package.json +11 -16
  3. package/install.js +0 -107
package/bin/anona-compute CHANGED
@@ -1,22 +1,41 @@
1
1
  #!/usr/bin/env node
2
- // Shim: execs the real anona-compute binary that install.js downloaded next to this file.
2
+ // Shim: resolves and execs the real anona-compute binary from whichever
3
+ // platform-specific optionalDependency npm installed for this machine.
3
4
  "use strict";
4
5
 
5
- const path = require("node:path");
6
6
  const { spawnSync } = require("node:child_process");
7
7
 
8
- const exeName = process.platform === "win32" ? "anona-compute.exe" : "anona-compute-bin";
9
- const target = path.join(__dirname, exeName);
8
+ const PLATFORM_PACKAGES = {
9
+ "linux-x64": "@anona-labs/anona-compute-linux-x64",
10
+ "linux-arm64": "@anona-labs/anona-compute-linux-arm64",
11
+ "darwin-x64": "@anona-labs/anona-compute-darwin-x64",
12
+ "darwin-arm64": "@anona-labs/anona-compute-darwin-arm64",
13
+ "win32-x64": "@anona-labs/anona-compute-win32-x64",
14
+ "win32-arm64": "@anona-labs/anona-compute-win32-arm64",
15
+ };
16
+
17
+ const key = `${process.platform}-${process.arch}`;
18
+ const pkgName = PLATFORM_PACKAGES[key];
19
+ if (!pkgName) {
20
+ console.error(`@anona-labs/anona-compute: unsupported platform ${key}`);
21
+ process.exit(1);
22
+ }
23
+
24
+ const binName = process.platform === "win32" ? "anona-compute.exe" : "anona-compute";
25
+ let target;
26
+ try {
27
+ target = require.resolve(`${pkgName}/bin/${binName}`);
28
+ } catch {
29
+ console.error(
30
+ `@anona-labs/anona-compute: optional dependency ${pkgName} is missing; ` +
31
+ "reinstall with npm install -g @anona-labs/anona-compute."
32
+ );
33
+ process.exit(1);
34
+ }
10
35
 
11
36
  const result = spawnSync(target, process.argv.slice(2), { stdio: "inherit" });
12
37
  if (result.error) {
13
- if (result.error.code === "ENOENT") {
14
- console.error(
15
- "anona-compute binary not found; reinstall the package (npm install -g @anonalabs/anona-compute)."
16
- );
17
- } else {
18
- console.error(result.error.message);
19
- }
38
+ console.error(result.error.message);
20
39
  process.exit(1);
21
40
  }
22
41
  process.exit(result.status === null ? 1 : result.status);
package/package.json CHANGED
@@ -1,30 +1,25 @@
1
1
  {
2
2
  "name": "@anona-labs/anona-compute",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Anona Compute CLI and MCP server",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
8
- "url": "https://github.com/anonalabs/Anona-Compute.git",
8
+ "url": "git+https://github.com/anonalabs/Anona-Compute.git",
9
9
  "directory": "npm/anona-compute"
10
10
  },
11
11
  "bin": {
12
12
  "anona-compute": "bin/anona-compute"
13
13
  },
14
14
  "files": [
15
- "bin/anona-compute",
16
- "install.js"
15
+ "bin/anona-compute"
17
16
  ],
18
- "scripts": {
19
- "postinstall": "node install.js"
20
- },
21
- "os": [
22
- "darwin",
23
- "linux",
24
- "win32"
25
- ],
26
- "cpu": [
27
- "x64",
28
- "arm64"
29
- ]
17
+ "optionalDependencies": {
18
+ "@anona-labs/anona-compute-linux-x64": "0.1.2",
19
+ "@anona-labs/anona-compute-linux-arm64": "0.1.2",
20
+ "@anona-labs/anona-compute-darwin-x64": "0.1.2",
21
+ "@anona-labs/anona-compute-darwin-arm64": "0.1.2",
22
+ "@anona-labs/anona-compute-win32-x64": "0.1.2",
23
+ "@anona-labs/anona-compute-win32-arm64": "0.1.2"
24
+ }
30
25
  }
package/install.js DELETED
@@ -1,107 +0,0 @@
1
- // postinstall: downloads the anona-compute release binary matching this
2
- // package's version and this machine's OS/arch from GitHub Releases,
3
- // verifies it against the release's checksums.txt, and drops it next to
4
- // bin/anona-compute (the JS shim that execs it).
5
- "use strict";
6
-
7
- const fs = require("node:fs");
8
- const os = require("node:os");
9
- const path = require("node:path");
10
- const https = require("node:https");
11
- const crypto = require("node:crypto");
12
- const { spawnSync } = require("node:child_process");
13
-
14
- const pkg = require("./package.json");
15
-
16
- const PLATFORMS = { linux: "linux", darwin: "darwin", win32: "windows" };
17
- const ARCHES = { x64: "amd64", arm64: "arm64" };
18
-
19
- function fail(message) {
20
- console.error(`@anonalabs/anona-compute: ${message}`);
21
- process.exit(1);
22
- }
23
-
24
- function download(url, destPath, redirectsLeft = 5) {
25
- return new Promise((resolve, reject) => {
26
- const file = fs.createWriteStream(destPath);
27
- https
28
- .get(url, { headers: { "User-Agent": "anona-compute-npm-installer" } }, (res) => {
29
- if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
30
- file.close();
31
- fs.unlinkSync(destPath);
32
- if (redirectsLeft <= 0) return reject(new Error("too many redirects"));
33
- return resolve(download(res.headers.location, destPath, redirectsLeft - 1));
34
- }
35
- if (res.statusCode !== 200) {
36
- file.close();
37
- return reject(new Error(`GET ${url} -> ${res.statusCode}`));
38
- }
39
- res.pipe(file);
40
- file.on("finish", () => file.close(resolve));
41
- })
42
- .on("error", reject);
43
- });
44
- }
45
-
46
- async function fetchText(url) {
47
- const tmp = path.join(os.tmpdir(), `anona-compute-${crypto.randomUUID()}.txt`);
48
- await download(url, tmp);
49
- const text = fs.readFileSync(tmp, "utf8");
50
- fs.unlinkSync(tmp);
51
- return text;
52
- }
53
-
54
- function sha256File(filePath) {
55
- const hash = crypto.createHash("sha256");
56
- hash.update(fs.readFileSync(filePath));
57
- return hash.digest("hex");
58
- }
59
-
60
- async function main() {
61
- const goos = PLATFORMS[process.platform];
62
- const goarch = ARCHES[process.arch];
63
- if (!goos || !goarch) {
64
- fail(`unsupported platform ${process.platform}/${process.arch}`);
65
- }
66
-
67
- const version = pkg.version;
68
- const base = `https://github.com/anonalabs/Anona-Compute/releases/download/v${version}`;
69
- const ext = goos === "windows" ? "zip" : "tar.gz";
70
- const archiveName = `anona-compute_${version}_${goos}_${goarch}.${ext}`;
71
- const archiveUrl = `${base}/${archiveName}`;
72
- const binDir = path.join(__dirname, "bin");
73
- const archivePath = path.join(os.tmpdir(), `${archiveName}-${crypto.randomUUID()}`);
74
-
75
- console.log(`@anonalabs/anona-compute: downloading ${archiveName}`);
76
- await download(archiveUrl, archivePath);
77
-
78
- const checksums = await fetchText(`${base}/checksums.txt`);
79
- const line = checksums.split("\n").find((l) => l.endsWith(archiveName));
80
- if (!line) fail(`checksums.txt has no entry for ${archiveName}`);
81
- const expected = line.split(/\s+/)[0];
82
- const actual = sha256File(archivePath);
83
- if (expected !== actual) {
84
- fs.unlinkSync(archivePath);
85
- fail(`checksum mismatch for ${archiveName}: expected ${expected}, got ${actual}`);
86
- }
87
-
88
- const finalName = goos === "windows" ? "anona-compute.exe" : "anona-compute-bin";
89
- if (goos === "windows") {
90
- const result = spawnSync("powershell.exe", [
91
- "-NoProfile",
92
- "-Command",
93
- `Expand-Archive -LiteralPath '${archivePath}' -DestinationPath '${binDir}' -Force`,
94
- ]);
95
- if (result.status !== 0) fail(`Expand-Archive failed: ${result.stderr}`);
96
- } else {
97
- const result = spawnSync("tar", ["-xzf", archivePath, "-C", binDir, "anona-compute"]);
98
- if (result.status !== 0) fail(`tar extraction failed: ${result.stderr}`);
99
- fs.renameSync(path.join(binDir, "anona-compute"), path.join(binDir, finalName));
100
- }
101
-
102
- fs.unlinkSync(archivePath);
103
- fs.chmodSync(path.join(binDir, finalName), 0o755);
104
- console.log(`@anonalabs/anona-compute: installed ${finalName}`);
105
- }
106
-
107
- main().catch((err) => fail(err.message));