@sys9/chord-cli 0.1.10-linux-x64 → 0.1.10

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.
package/bin/chord ADDED
@@ -0,0 +1,95 @@
1
+ #!/usr/bin/env node
2
+
3
+ "use strict";
4
+
5
+ const { spawn } = require("node:child_process");
6
+ const { existsSync } = require("node:fs");
7
+ const path = require("node:path");
8
+
9
+ const packageJSON = require("../package.json");
10
+ const {
11
+ resolvePackagedBinaryPath,
12
+ resolvePlatformPackageName,
13
+ } = require("../lib/platform");
14
+
15
+ function detectPackageManager() {
16
+ const userAgent = process.env.npm_config_user_agent || "";
17
+ if (/\bbun\//.test(userAgent)) {
18
+ return "bun";
19
+ }
20
+
21
+ const execPath = process.env.npm_execpath || "";
22
+ if (execPath.includes("bun")) {
23
+ return "bun";
24
+ }
25
+
26
+ if (
27
+ __dirname.includes(".bun/install/global") ||
28
+ __dirname.includes(".bun\\install\\global")
29
+ ) {
30
+ return "bun";
31
+ }
32
+
33
+ return userAgent ? "npm" : null;
34
+ }
35
+
36
+ function resolveBinaryPath() {
37
+ const platformPackage = resolvePlatformPackageName(packageJSON.name);
38
+ try {
39
+ const packageJSONPath = require.resolve(platformPackage + "/package.json");
40
+ return {
41
+ binaryPath: resolvePackagedBinaryPath(path.dirname(packageJSONPath)),
42
+ platformPackage,
43
+ };
44
+ } catch {
45
+ return {
46
+ binaryPath: resolvePackagedBinaryPath(path.join(__dirname, "..")),
47
+ platformPackage,
48
+ };
49
+ }
50
+ }
51
+
52
+ const { binaryPath, platformPackage } = resolveBinaryPath();
53
+ if (!existsSync(binaryPath)) {
54
+ const packageManager = detectPackageManager();
55
+ const updateCommand =
56
+ packageManager === "bun"
57
+ ? "bun add -g @sys9/chord-cli@latest"
58
+ : "npm install -g @sys9/chord-cli@latest";
59
+ throw new Error(
60
+ "Missing optional dependency " + platformPackage + ". Reinstall chord: " + updateCommand,
61
+ );
62
+ }
63
+
64
+ const child = spawn(binaryPath, process.argv.slice(2), {
65
+ stdio: "inherit",
66
+ env: process.env,
67
+ });
68
+
69
+ child.on("error", (error) => {
70
+ console.error(error);
71
+ process.exit(1);
72
+ });
73
+
74
+ const forwardSignal = (signal) => {
75
+ if (child.killed) {
76
+ return;
77
+ }
78
+ try {
79
+ child.kill(signal);
80
+ } catch {
81
+ // Ignore failures while the child is already exiting.
82
+ }
83
+ };
84
+
85
+ ["SIGINT", "SIGTERM", "SIGHUP"].forEach((signal) => {
86
+ process.on(signal, () => forwardSignal(signal));
87
+ });
88
+
89
+ child.on("exit", (code, signal) => {
90
+ if (signal) {
91
+ process.kill(process.pid, signal);
92
+ return;
93
+ }
94
+ process.exit(code ?? 1);
95
+ });
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+
3
+ const path = require("node:path");
4
+
5
+ const SUPPORTED_TARGETS = [
6
+ {
7
+ slug: "linux-x64",
8
+ os: "linux",
9
+ cpu: "x64",
10
+ vendorDir: "linux_amd64",
11
+ targetTriple: "x86_64-unknown-linux-musl",
12
+ },
13
+ {
14
+ slug: "linux-arm64",
15
+ os: "linux",
16
+ cpu: "arm64",
17
+ vendorDir: "linux_arm64",
18
+ targetTriple: "aarch64-unknown-linux-musl",
19
+ },
20
+ {
21
+ slug: "darwin-x64",
22
+ os: "darwin",
23
+ cpu: "x64",
24
+ vendorDir: "darwin_amd64",
25
+ targetTriple: "x86_64-apple-darwin",
26
+ },
27
+ {
28
+ slug: "darwin-arm64",
29
+ os: "darwin",
30
+ cpu: "arm64",
31
+ vendorDir: "darwin_arm64",
32
+ targetTriple: "aarch64-apple-darwin",
33
+ }
34
+ ];
35
+
36
+ function resolveSupportedTarget(platform = process.platform, arch = process.arch) {
37
+ for (const target of SUPPORTED_TARGETS) {
38
+ if (target.os === platform && target.cpu === arch) {
39
+ return target;
40
+ }
41
+ }
42
+ throw new Error("unsupported platform: " + platform + " (" + arch + ")");
43
+ }
44
+
45
+ function resolvePackagedBinaryPath(rootDir, platform = process.platform, arch = process.arch) {
46
+ const target = resolveSupportedTarget(platform, arch);
47
+ return path.join(rootDir, "vendor", target.vendorDir, "chord");
48
+ }
49
+
50
+ function resolvePlatformPackageName(rootPackageName, platform = process.platform, arch = process.arch) {
51
+ const target = resolveSupportedTarget(platform, arch);
52
+ return rootPackageName + "-" + target.slug;
53
+ }
54
+
55
+ module.exports = {
56
+ SUPPORTED_TARGETS,
57
+ resolvePackagedBinaryPath,
58
+ resolvePlatformPackageName,
59
+ resolveSupportedTarget,
60
+ };
package/package.json CHANGED
@@ -1,22 +1,30 @@
1
1
  {
2
2
  "name": "@sys9/chord-cli",
3
- "version": "0.1.10-linux-x64",
3
+ "version": "0.1.10",
4
4
  "description": "Chord CLI package used by @sys9/cli",
5
5
  "license": "UNLICENSED",
6
- "os": [
7
- "linux"
8
- ],
9
- "cpu": [
10
- "x64"
11
- ],
12
- "files": [
13
- "vendor"
14
- ],
15
6
  "repository": {
16
7
  "type": "git",
17
8
  "url": "git+https://github.com/sys9-ai/chord.git"
18
9
  },
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "bin": {
14
+ "chord": "bin/chord"
15
+ },
16
+ "files": [
17
+ "README.md",
18
+ "bin",
19
+ "lib"
20
+ ],
19
21
  "engines": {
20
22
  "node": ">=16"
23
+ },
24
+ "optionalDependencies": {
25
+ "@sys9/chord-cli-linux-x64": "npm:@sys9/chord-cli@0.1.10-linux-x64",
26
+ "@sys9/chord-cli-linux-arm64": "npm:@sys9/chord-cli@0.1.10-linux-arm64",
27
+ "@sys9/chord-cli-darwin-x64": "npm:@sys9/chord-cli@0.1.10-darwin-x64",
28
+ "@sys9/chord-cli-darwin-arm64": "npm:@sys9/chord-cli@0.1.10-darwin-arm64"
21
29
  }
22
30
  }
Binary file