@kvell007/embed-labs-local-bridge 0.1.0-alpha.75 → 0.1.0-alpha.77

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/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  #!/usr/bin/env node
2
- export { startServer } from "./server.js";
2
+ export declare function resolveBridgeBinary(): string;
3
+ export declare function startBridgeProcess(args?: string[]): Promise<number>;
package/dist/index.js CHANGED
@@ -1,10 +1,136 @@
1
1
  #!/usr/bin/env node
2
- import { realpathSync } from "node:fs";
2
+ import { spawn } from "node:child_process";
3
+ import { accessSync, constants, realpathSync } from "node:fs";
4
+ import { createRequire } from "node:module";
5
+ import { dirname, join, resolve } from "node:path";
6
+ import { arch, platform } from "node:os";
3
7
  import { fileURLToPath } from "node:url";
4
- import { startServer } from "./server.js";
5
- export { startServer } from "./server.js";
8
+ const require = createRequire(import.meta.url);
9
+ const TARGETS = {
10
+ "darwin-arm64": {
11
+ packageName: "@embed-labs/local-bridge-darwin-arm64",
12
+ artifactDir: "darwin-arm64",
13
+ binaryName: "embed-local-bridge"
14
+ },
15
+ "linux-x64": {
16
+ packageName: "@embed-labs/local-bridge-linux-x64",
17
+ artifactDir: "linux-x64",
18
+ binaryName: "embed-local-bridge"
19
+ },
20
+ "linux-arm64": {
21
+ packageName: "@embed-labs/local-bridge-linux-arm64",
22
+ artifactDir: "linux-arm64",
23
+ binaryName: "embed-local-bridge"
24
+ },
25
+ "win32-x64": {
26
+ packageName: "@embed-labs/local-bridge-win32-x64",
27
+ artifactDir: "win32-x64",
28
+ binaryName: "embed-local-bridge.exe"
29
+ },
30
+ "win32-arm64": {
31
+ packageName: "@embed-labs/local-bridge-win32-arm64",
32
+ artifactDir: "win32-arm64",
33
+ binaryName: "embed-local-bridge.exe"
34
+ }
35
+ };
36
+ export function resolveBridgeBinary() {
37
+ const explicit = process.env.EMBED_LOCAL_BRIDGE_BINARY?.trim();
38
+ if (explicit) {
39
+ return assertExecutable(explicit, `EMBED_LOCAL_BRIDGE_BINARY points to a non-executable file: ${explicit}`);
40
+ }
41
+ const targetKey = `${platform()}-${arch()}`;
42
+ const target = TARGETS[targetKey];
43
+ if (!target) {
44
+ throw new Error(`Embed Labs Local Bridge does not provide a native binary for ${targetKey}. Supported targets: ${Object.keys(TARGETS).join(", ")}.`);
45
+ }
46
+ const packagedBinary = resolvePackagedBinary(target);
47
+ if (packagedBinary) {
48
+ return packagedBinary;
49
+ }
50
+ const repoBinary = resolveRepoArtifactBinary(target);
51
+ if (repoBinary) {
52
+ return repoBinary;
53
+ }
54
+ throw new Error([
55
+ `Embed Labs Local Bridge native package is missing for ${targetKey}.`,
56
+ `Expected optional dependency ${target.packageName}.`,
57
+ "Reinstall without omitting optional dependencies:",
58
+ " npm install",
59
+ "or install the CLI package again without --omit=optional.",
60
+ "For source-tree development, run npm run build:bridge-go first."
61
+ ].join("\n"));
62
+ }
63
+ export function startBridgeProcess(args = process.argv.slice(2)) {
64
+ const binary = resolveBridgeBinary();
65
+ const child = spawn(binary, args, {
66
+ stdio: "inherit",
67
+ env: process.env
68
+ });
69
+ const forwardSignal = (signal) => {
70
+ if (!child.killed) {
71
+ child.kill(signal);
72
+ }
73
+ };
74
+ process.once("SIGINT", forwardSignal);
75
+ process.once("SIGTERM", forwardSignal);
76
+ return new Promise((resolve) => {
77
+ child.on("error", (error) => {
78
+ console.error(error instanceof Error ? error.message : String(error));
79
+ resolve(1);
80
+ });
81
+ child.on("close", (code, signal) => {
82
+ process.off("SIGINT", forwardSignal);
83
+ process.off("SIGTERM", forwardSignal);
84
+ if (signal) {
85
+ resolve(signal === "SIGINT" || signal === "SIGTERM" ? 0 : 1);
86
+ }
87
+ else {
88
+ resolve(code ?? 0);
89
+ }
90
+ });
91
+ });
92
+ }
6
93
  if (isDirectRun()) {
7
- startServer();
94
+ startBridgeProcess().then((code) => {
95
+ process.exitCode = code;
96
+ });
97
+ }
98
+ function resolvePackagedBinary(target) {
99
+ try {
100
+ const packageJson = require.resolve(`${target.packageName}/package.json`);
101
+ return assertExecutable(join(dirname(packageJson), "bin", target.binaryName), "");
102
+ }
103
+ catch {
104
+ return undefined;
105
+ }
106
+ }
107
+ function resolveRepoArtifactBinary(target) {
108
+ const here = dirname(fileURLToPath(import.meta.url));
109
+ const candidates = [
110
+ resolve(here, "../../../artifacts/local-bridge-bin", target.artifactDir, target.binaryName),
111
+ resolve(here, "../../artifacts/local-bridge-bin", target.artifactDir, target.binaryName)
112
+ ];
113
+ for (const candidate of candidates) {
114
+ try {
115
+ return assertExecutable(candidate, "");
116
+ }
117
+ catch {
118
+ // Keep searching fallback candidates.
119
+ }
120
+ }
121
+ return undefined;
122
+ }
123
+ function assertExecutable(path, message) {
124
+ try {
125
+ accessSync(path, constants.X_OK);
126
+ }
127
+ catch (error) {
128
+ if (message) {
129
+ throw new Error(message);
130
+ }
131
+ throw error;
132
+ }
133
+ return path;
8
134
  }
9
135
  function isDirectRun() {
10
136
  if (!process.argv[1]) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kvell007/embed-labs-local-bridge",
3
- "version": "0.1.0-alpha.75",
3
+ "version": "0.1.0-alpha.77",
4
4
  "description": "Local hardware bridge service for Embed Labs Cloud. Experimental npm publish.",
5
5
  "private": false,
6
6
  "type": "module",
@@ -18,11 +18,11 @@
18
18
  "embed-local-bridge": "dist/index.js"
19
19
  },
20
20
  "optionalDependencies": {
21
- "@embed-labs/local-bridge-darwin-arm64": "npm:@kvell007/embed-labs-local-bridge-darwin-arm64@0.1.0-alpha.75",
22
- "@embed-labs/local-bridge-linux-arm64": "npm:@kvell007/embed-labs-local-bridge-linux-arm64@0.1.0-alpha.75",
23
- "@embed-labs/local-bridge-linux-x64": "npm:@kvell007/embed-labs-local-bridge-linux-x64@0.1.0-alpha.75",
24
- "@embed-labs/local-bridge-win32-arm64": "npm:@kvell007/embed-labs-local-bridge-win32-arm64@0.1.0-alpha.75",
25
- "@embed-labs/local-bridge-win32-x64": "npm:@kvell007/embed-labs-local-bridge-win32-x64@0.1.0-alpha.75"
21
+ "@embed-labs/local-bridge-darwin-arm64": "npm:@kvell007/embed-labs-local-bridge-darwin-arm64@0.1.0-alpha.77",
22
+ "@embed-labs/local-bridge-linux-arm64": "npm:@kvell007/embed-labs-local-bridge-linux-arm64@0.1.0-alpha.77",
23
+ "@embed-labs/local-bridge-linux-x64": "npm:@kvell007/embed-labs-local-bridge-linux-x64@0.1.0-alpha.77",
24
+ "@embed-labs/local-bridge-win32-arm64": "npm:@kvell007/embed-labs-local-bridge-win32-arm64@0.1.0-alpha.77",
25
+ "@embed-labs/local-bridge-win32-x64": "npm:@kvell007/embed-labs-local-bridge-win32-x64@0.1.0-alpha.77"
26
26
  },
27
27
  "publishConfig": {
28
28
  "access": "public",