@kvell007/embed-labs-cli 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.js CHANGED
@@ -7,7 +7,6 @@ import { createRequire } from "node:module";
7
7
  import { homedir, tmpdir } from "node:os";
8
8
  import { basename, delimiter, dirname, join, resolve } from "node:path";
9
9
  import { fileURLToPath } from "node:url";
10
- import { startServer } from "@embed-labs/local-bridge";
11
10
  import { composeBootLogoPackage } from "./image-compose.js";
12
11
  import { buildTaishanPiQtSmoke, compileTaishanPiSingleFile, currentLocalToolchain, installLocalToolchain, latestLocalToolchain, validateLocalToolchain } from "./local-toolchain.js";
13
12
  import { fail, ok } from "@embed-labs/protocol";
@@ -147,11 +146,20 @@ async function main(argv) {
147
146
  return output(parsed, await bridgePost("/v1/board/taishanpi/deploy", request), renderBoardDeployResult);
148
147
  }
149
148
  if (area === "bridge" && action === "start") {
150
- startServer({
151
- host: stringFlag(parsed, "host"),
152
- port: numberFlag(parsed, "port")
149
+ const launcher = await resolveBridgeLauncher();
150
+ const args = [
151
+ ...launcher.args,
152
+ ...(stringFlag(parsed, "host") ? ["--host", stringFlag(parsed, "host")] : []),
153
+ ...(numberFlag(parsed, "port") ? ["--port", String(numberFlag(parsed, "port"))] : [])
154
+ ];
155
+ const child = spawn(launcher.command, args, {
156
+ cwd: process.cwd(),
157
+ env: process.env,
158
+ stdio: "inherit"
159
+ });
160
+ return await new Promise((resolveExit) => {
161
+ child.on("close", (code) => resolveExit(code ?? 0));
153
162
  });
154
- return await waitForever();
155
163
  }
156
164
  if (area === "bridge" && action === "status") {
157
165
  return output(parsed, await bridgeGet("/healthz"), renderBridgeStatus);
@@ -1559,7 +1567,7 @@ async function installOpenCodePlugin(parsed, context) {
1559
1567
  }
1560
1568
  await mkdir(join(targetRoot, "plugins"), { recursive: true });
1561
1569
  const packagePath = await prepareOpenCodePackageForInstall(targetRoot, source.data.packagePath);
1562
- const npmResult = await runLocalProcess("npm", [
1570
+ const npmResult = await runLocalProcess(await resolveNpmExecutable(), [
1563
1571
  "install",
1564
1572
  "--prefix",
1565
1573
  targetRoot,
@@ -1641,7 +1649,7 @@ async function resolveOpenCodePluginSource(context) {
1641
1649
  remediation: "Run from the Embed-Labs-Cloud repo root or pass --release-dir pointing to a plugin release directory."
1642
1650
  });
1643
1651
  }
1644
- const packed = await runLocalProcess("npm", ["pack", packagePath, "--pack-destination", context.tempDir, "--json"]);
1652
+ const packed = await runLocalProcess(await resolveNpmExecutable(), ["pack", packagePath, "--pack-destination", context.tempDir, "--json"]);
1645
1653
  if (packed.code !== 0) {
1646
1654
  return fail("opencode_plugin_pack_failed", "npm pack failed while preparing the OpenCode plugin source package.", {
1647
1655
  details: {
@@ -1972,6 +1980,55 @@ async function resolveExecutableOnPath(name) {
1972
1980
  }
1973
1981
  return undefined;
1974
1982
  }
1983
+ async function resolveNpmExecutable() {
1984
+ const candidate = process.platform === "win32" ? "npm.cmd" : "npm";
1985
+ return await resolveExecutableOnPath(candidate) ?? candidate;
1986
+ }
1987
+ async function resolveBridgeLauncher() {
1988
+ const explicitBinary = process.env.EMBED_LOCAL_BRIDGE_BINARY?.trim();
1989
+ if (explicitBinary) {
1990
+ try {
1991
+ await access(explicitBinary, constants.X_OK);
1992
+ return { command: explicitBinary, args: [] };
1993
+ }
1994
+ catch {
1995
+ // Fall through so the package launcher can print its clearer repair message.
1996
+ }
1997
+ }
1998
+ const pathBinary = await resolveExecutableOnPath(process.platform === "win32" ? "embed-local-bridge.cmd" : "embed-local-bridge");
1999
+ if (pathBinary) {
2000
+ return { command: pathBinary, args: [] };
2001
+ }
2002
+ const packageLauncher = await resolveBridgePackageLauncher();
2003
+ if (packageLauncher) {
2004
+ return { command: process.execPath, args: [packageLauncher] };
2005
+ }
2006
+ return {
2007
+ command: process.execPath,
2008
+ args: [resolve(SOURCE_CHECKOUT_ROOT, "packages", "local-bridge", "dist", "index.js")]
2009
+ };
2010
+ }
2011
+ async function resolveBridgePackageLauncher() {
2012
+ const candidates = [];
2013
+ try {
2014
+ const packageJson = require.resolve("@embed-labs/local-bridge/package.json");
2015
+ candidates.push(join(dirname(packageJson), "dist", "index.js"));
2016
+ }
2017
+ catch {
2018
+ // Source checkout fallback below.
2019
+ }
2020
+ candidates.push(resolve(SOURCE_CHECKOUT_ROOT, "packages", "local-bridge", "dist", "index.js"));
2021
+ for (const candidate of candidates) {
2022
+ try {
2023
+ await access(candidate, constants.R_OK);
2024
+ return candidate;
2025
+ }
2026
+ catch {
2027
+ // Keep looking.
2028
+ }
2029
+ }
2030
+ return undefined;
2031
+ }
1975
2032
  function defaultOpenCodeRoot() {
1976
2033
  return join(process.cwd(), ".opencode");
1977
2034
  }