@one2x/merouter 0.1.7-linux-arm64 → 0.1.7

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/bin.js ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env node
2
+ import path from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import { resolveBinaryPath, resolvePlatformOrThrow } from "./binary-resolver.js";
5
+ import { detectPackageManager, reinstallHint, } from "./package-manager.js";
6
+ import { runBinary } from "./spawn-child.js";
7
+ const shimDirname = path.dirname(fileURLToPath(import.meta.url));
8
+ const manager = detectPackageManager(shimDirname);
9
+ const platform = resolvePlatformOrThrow();
10
+ const binaryPath = resolveBinaryPath(platform, shimDirname, reinstallHint(manager));
11
+ await runBinary(binaryPath, process.argv.slice(2), manager);
@@ -0,0 +1,36 @@
1
+ import { existsSync } from "node:fs";
2
+ import { createRequire } from "node:module";
3
+ import path from "node:path";
4
+ import { detectPlatform, getBinaryName, getPlatformPackageName, } from "./utils/platforms.js";
5
+ const require = createRequire(import.meta.url);
6
+ export function resolvePlatformOrThrow() {
7
+ const platform = detectPlatform(process.platform, process.arch);
8
+ if (!platform) {
9
+ throw new Error(`Unsupported platform: ${process.platform} (${process.arch}).`);
10
+ }
11
+ return platform;
12
+ }
13
+ export function resolveBinaryPath(platform, shimDirname, reinstall) {
14
+ const binaryName = getBinaryName(platform.os);
15
+ const packageName = getPlatformPackageName(platform.key);
16
+ const localVendorRoot = path.join(shimDirname, "..", "vendor");
17
+ const localBinaryPath = path.join(localVendorRoot, platform.target, "merouter", binaryName);
18
+ let vendorRoot;
19
+ try {
20
+ const packageJsonPath = require.resolve(`${packageName}/package.json`);
21
+ vendorRoot = path.join(path.dirname(packageJsonPath), "vendor");
22
+ }
23
+ catch {
24
+ if (existsSync(localBinaryPath)) {
25
+ vendorRoot = localVendorRoot;
26
+ }
27
+ else {
28
+ throw new Error(`Missing optional dependency ${packageName}. Reinstall merouter: ${reinstall}`);
29
+ }
30
+ }
31
+ const binaryPath = path.join(vendorRoot, platform.target, "merouter", binaryName);
32
+ if (!existsSync(binaryPath)) {
33
+ throw new Error(`Binary not found at ${binaryPath}. Reinstall merouter: ${reinstall}`);
34
+ }
35
+ return binaryPath;
36
+ }
@@ -0,0 +1,17 @@
1
+ export function detectPackageManager(dirname) {
2
+ const userAgent = process.env.npm_config_user_agent ?? "";
3
+ if (/\bbun\//.test(userAgent))
4
+ return "bun";
5
+ if ((process.env.npm_execpath ?? "").includes("bun"))
6
+ return "bun";
7
+ if (dirname.includes(".bun/install/global") ||
8
+ dirname.includes(".bun\\install\\global")) {
9
+ return "bun";
10
+ }
11
+ return userAgent ? "npm" : null;
12
+ }
13
+ export function reinstallHint(manager) {
14
+ return manager === "bun"
15
+ ? "bun install -g @one2x/merouter@latest"
16
+ : "npm install -g @one2x/merouter@latest";
17
+ }
@@ -0,0 +1,48 @@
1
+ import { spawn } from "node:child_process";
2
+ const FORWARDED_SIGNALS = [
3
+ "SIGINT",
4
+ "SIGTERM",
5
+ "SIGHUP",
6
+ ];
7
+ export async function runBinary(binaryPath, argv, manager) {
8
+ const env = {
9
+ ...process.env,
10
+ [manager === "bun"
11
+ ? "MEROUTER_MANAGED_BY_BUN"
12
+ : "MEROUTER_MANAGED_BY_NPM"]: "1",
13
+ };
14
+ const child = spawn(binaryPath, argv, { stdio: "inherit", env });
15
+ child.on("error", (err) => {
16
+ console.error(err);
17
+ process.exit(1);
18
+ });
19
+ for (const sig of FORWARDED_SIGNALS) {
20
+ process.on(sig, () => {
21
+ if (!child.killed) {
22
+ try {
23
+ child.kill(sig);
24
+ }
25
+ catch {
26
+ /* child already exited */
27
+ }
28
+ }
29
+ });
30
+ }
31
+ const result = await new Promise((resolve) => {
32
+ child.on("exit", (code, signal) => {
33
+ if (signal) {
34
+ resolve({ type: "signal", signal });
35
+ }
36
+ else {
37
+ resolve({ type: "code", exitCode: code ?? 1 });
38
+ }
39
+ });
40
+ });
41
+ if (result.type === "signal") {
42
+ process.kill(process.pid, result.signal);
43
+ }
44
+ else {
45
+ process.exit(result.exitCode);
46
+ }
47
+ throw new Error("unreachable");
48
+ }
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Single source of truth for platform data used by both the runtime shim
3
+ * (src/bin.ts) and the publish-time stager (scripts/stage/main.ts).
4
+ *
5
+ * Add a new supported platform by appending to `PLATFORMS` — no other file
6
+ * in this package needs to change.
7
+ */
8
+ export const PLATFORMS = [
9
+ {
10
+ key: "linux-x64",
11
+ target: "x86_64-unknown-linux-gnu",
12
+ os: "linux",
13
+ cpu: "x64",
14
+ archive: "tar.gz",
15
+ },
16
+ {
17
+ key: "linux-arm64",
18
+ target: "aarch64-unknown-linux-gnu",
19
+ os: "linux",
20
+ cpu: "arm64",
21
+ archive: "tar.gz",
22
+ },
23
+ {
24
+ key: "darwin-x64",
25
+ target: "x86_64-apple-darwin",
26
+ os: "darwin",
27
+ cpu: "x64",
28
+ archive: "tar.gz",
29
+ },
30
+ {
31
+ key: "darwin-arm64",
32
+ target: "aarch64-apple-darwin",
33
+ os: "darwin",
34
+ cpu: "arm64",
35
+ archive: "tar.gz",
36
+ },
37
+ {
38
+ key: "win32-x64",
39
+ target: "x86_64-pc-windows-msvc",
40
+ os: "win32",
41
+ cpu: "x64",
42
+ archive: "zip",
43
+ },
44
+ ];
45
+ /** Base npm package name shared by the main shim and all platform artifacts. */
46
+ export const NPM_NAME = "@one2x/merouter";
47
+ /**
48
+ * Returns the executable filename for the given OS.
49
+ *
50
+ * Usage:
51
+ * getBinaryName("linux") // "merouter"
52
+ * getBinaryName("win32") // "merouter.exe"
53
+ */
54
+ export function getBinaryName(os) {
55
+ return os === "win32" ? "merouter.exe" : "merouter";
56
+ }
57
+ /**
58
+ * Returns the npm optionalDependency package key for a platform.
59
+ *
60
+ * The key MUST match the LHS of the `optionalDependencies` entries in
61
+ * packages/merouter/package.json — npm stores the aliased package under
62
+ * `node_modules/<key>/` regardless of the real underlying name/version.
63
+ *
64
+ * Usage:
65
+ * getPlatformPackageName("linux-x64") // "@one2x/merouter-linux-x64"
66
+ */
67
+ export function getPlatformPackageName(key) {
68
+ return `${NPM_NAME}-${key}`;
69
+ }
70
+ /**
71
+ * Detects the current host's platform from Node's `process.platform` and
72
+ * `process.arch`, returning null if the combination is unsupported.
73
+ */
74
+ export function detectPlatform(platform, arch) {
75
+ const nodeOs = platform === "linux" || platform === "android"
76
+ ? "linux"
77
+ : platform === "darwin"
78
+ ? "darwin"
79
+ : platform === "win32"
80
+ ? "win32"
81
+ : null;
82
+ if (!nodeOs)
83
+ return null;
84
+ const nodeCpu = arch === "x64" ? "x64" : arch === "arm64" ? "arm64" : null;
85
+ if (!nodeCpu)
86
+ return null;
87
+ return PLATFORMS.find((p) => p.os === nodeOs && p.cpu === nodeCpu) ?? null;
88
+ }
package/package.json CHANGED
@@ -1,16 +1,18 @@
1
1
  {
2
2
  "name": "@one2x/merouter",
3
- "version": "0.1.7-linux-arm64",
3
+ "version": "0.1.7",
4
+ "description": "Unified CLI for managing and routing across multiple AI model providers.",
4
5
  "license": "SEE LICENSE IN LICENSE",
5
- "description": "merouter CLI native binary for linux/arm64.",
6
- "os": [
7
- "linux"
8
- ],
9
- "cpu": [
10
- "arm64"
11
- ],
6
+ "type": "module",
7
+ "bin": {
8
+ "merouter": "bin/bin.js"
9
+ },
10
+ "engines": {
11
+ "node": ">=18"
12
+ },
12
13
  "files": [
13
- "vendor",
14
+ "bin",
15
+ "LICENSE",
14
16
  "README.md"
15
17
  ],
16
18
  "repository": {
@@ -20,5 +22,12 @@
20
22
  },
21
23
  "publishConfig": {
22
24
  "access": "public"
25
+ },
26
+ "optionalDependencies": {
27
+ "@one2x/merouter-linux-x64": "npm:@one2x/merouter@0.1.7-linux-x64",
28
+ "@one2x/merouter-linux-arm64": "npm:@one2x/merouter@0.1.7-linux-arm64",
29
+ "@one2x/merouter-darwin-x64": "npm:@one2x/merouter@0.1.7-darwin-x64",
30
+ "@one2x/merouter-darwin-arm64": "npm:@one2x/merouter@0.1.7-darwin-arm64",
31
+ "@one2x/merouter-win32-x64": "npm:@one2x/merouter@0.1.7-win32-x64"
23
32
  }
24
33
  }