@buda-ai/connector 0.1.18 → 0.1.20

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 (2) hide show
  1. package/dist/cli.js +87 -16
  2. package/package.json +2 -1
package/dist/cli.js CHANGED
@@ -517,7 +517,7 @@ import path2 from "path";
517
517
  // package.json
518
518
  var package_default = {
519
519
  name: "@buda-ai/connector",
520
- version: "0.1.18",
520
+ version: "0.1.20",
521
521
  private: false,
522
522
  type: "module",
523
523
  publishConfig: {
@@ -535,6 +535,7 @@ var package_default = {
535
535
  dev: "tsx src/cli.ts dev",
536
536
  daemon: "tsx src/cli.ts daemon",
537
537
  new: "tsx src/cli.ts new",
538
+ prepack: "tsup --silent",
538
539
  start: "node dist/cli.js daemon",
539
540
  build: "tsup",
540
541
  test: "vitest run",
@@ -2437,6 +2438,26 @@ var renameStagedRuntime = async (source, destination, options = {}) => {
2437
2438
  }
2438
2439
  };
2439
2440
  var exists = async (filePath) => access(filePath).then(() => true).catch(() => false);
2441
+ var resolveNpmInvocation = async (options = {}) => {
2442
+ const platform4 = options.platform ?? process.platform;
2443
+ if (platform4 !== "win32") return { argsPrefix: [], executable: "npm" };
2444
+ const nodeExecutable = options.nodeExecutable ?? process.execPath;
2445
+ const pathApi = options.pathApi ?? path6;
2446
+ const pathExists = options.pathExists ?? exists;
2447
+ const candidates = [
2448
+ options.npmExecPath ?? process.env.npm_execpath,
2449
+ pathApi.join(pathApi.dirname(nodeExecutable), "node_modules", "npm", "bin", "npm-cli.js")
2450
+ ];
2451
+ for (const candidate of candidates) {
2452
+ if (!candidate || pathApi.basename(candidate).toLowerCase() !== "npm-cli.js") continue;
2453
+ if (await pathExists(candidate)) {
2454
+ return { argsPrefix: [candidate], executable: nodeExecutable };
2455
+ }
2456
+ }
2457
+ throw new Error(
2458
+ `Unable to locate npm-cli.js for the stable Connector runtime installation (node=${JSON.stringify(nodeExecutable)}, npm_execpath=${JSON.stringify(options.npmExecPath ?? process.env.npm_execpath ?? "")})`
2459
+ );
2460
+ };
2440
2461
  var runtimeRoot = () => process.env.BUDA_CONNECTOR_RUNTIME_ROOT || path6.join(homedir3(), ".buda", "runtime");
2441
2462
  var runtimePlatformKey = `${process.platform}-${process.arch}-node${process.versions.modules}`;
2442
2463
  var versionDirectory = () => path6.join(runtimeRoot(), runtimePlatformKey, CONNECTOR_RUNTIME_VERSION);
@@ -2470,9 +2491,11 @@ var validateRuntime = async (runtime) => {
2470
2491
  };
2471
2492
  var installFromNpm = async (directory) => {
2472
2493
  await mkdir5(directory, { recursive: true, mode: 448 });
2494
+ const npm = await resolveNpmInvocation();
2473
2495
  await execFileAsync(
2474
- process.platform === "win32" ? "npm.cmd" : "npm",
2496
+ npm.executable,
2475
2497
  [
2498
+ ...npm.argsPrefix,
2476
2499
  "install",
2477
2500
  "--ignore-scripts=false",
2478
2501
  "--no-audit",
@@ -2604,6 +2627,57 @@ var compareVersions = (left, right) => {
2604
2627
  return 0;
2605
2628
  };
2606
2629
  var shouldReplaceDaemonVersion = (runningVersion, candidateVersion) => compareVersions(candidateVersion, runningVersion) > 0;
2630
+ var getErrorCode = (error) => typeof error === "object" && error !== null && "code" in error ? String(error.code) : "UNKNOWN";
2631
+ var waitForChildSpawn = (child) => new Promise((resolve, reject) => {
2632
+ const onError = (error) => {
2633
+ child.off("spawn", onSpawn);
2634
+ reject(error);
2635
+ };
2636
+ const onSpawn = () => {
2637
+ child.off("error", onError);
2638
+ resolve();
2639
+ };
2640
+ child.once("error", onError);
2641
+ child.once("spawn", onSpawn);
2642
+ });
2643
+ async function spawnDetachedDaemonProcess(command, args, options, dependencies = {}) {
2644
+ const platform4 = dependencies.platform ?? process.platform;
2645
+ const spawnProcess = dependencies.spawnProcess ?? ((file, fileArgs, spawnOptions) => spawn(file, fileArgs, spawnOptions));
2646
+ const strategies = platform4 === "win32" ? [
2647
+ { name: "detached-hidden", windowsHide: true },
2648
+ { name: "detached-unhidden", windowsHide: false }
2649
+ ] : [{ name: "detached-hidden", windowsHide: true }];
2650
+ const attempted = [];
2651
+ for (const [index, strategy] of strategies.entries()) {
2652
+ attempted.push(strategy.name);
2653
+ const child = spawnProcess(command, args, {
2654
+ detached: true,
2655
+ env: options.env,
2656
+ stdio: options.stdio,
2657
+ windowsHide: strategy.windowsHide
2658
+ });
2659
+ try {
2660
+ await waitForChildSpawn(child);
2661
+ child.unref();
2662
+ return strategy.name;
2663
+ } catch (error) {
2664
+ const code = getErrorCode(error);
2665
+ const shouldRetry = platform4 === "win32" && index === 0 && code === "EINVAL";
2666
+ if (shouldRetry) continue;
2667
+ const diagnostics = [
2668
+ `code=${code}`,
2669
+ `strategies=${attempted.join(",")}`,
2670
+ `platform=${platform4}`,
2671
+ `node=${dependencies.nodeVersion ?? process.version}`,
2672
+ `executable=${JSON.stringify(command)}`,
2673
+ `entrypoint=${JSON.stringify(args[0] ?? "")}`,
2674
+ `cwd=${JSON.stringify(dependencies.cwd ?? process.cwd())}`
2675
+ ].join(" ");
2676
+ throw new Error(`Connector daemon process creation failed: ${diagnostics}`, { cause: error });
2677
+ }
2678
+ }
2679
+ throw new Error("Connector daemon process creation failed without a spawn attempt");
2680
+ }
2607
2681
  var waitForDaemon = async (launchConfig, deadline) => {
2608
2682
  let lastConfig = null;
2609
2683
  while (Date.now() < deadline) {
@@ -2621,20 +2695,17 @@ var waitForDaemon = async (launchConfig, deadline) => {
2621
2695
  var spawnInternalDaemon = async (launchConfig, mode, preparedRuntime, options = {}) => {
2622
2696
  const runtime = preparedRuntime ?? await ensureStableConnectorRuntime();
2623
2697
  const debugDaemonStdio = process.env.BUDA_CONNECTOR_DEBUG_DAEMON_STDIO === "1";
2624
- const child = spawn(runtime.nodeExecutable, getRuntimeCommandArgs(runtime, mode, options), {
2625
- detached: true,
2626
- env: {
2627
- ...process.env,
2628
- BUDA_CONNECTOR_INTERNAL_LAUNCH_CONFIG: JSON.stringify(launchConfig ?? {})
2629
- },
2630
- stdio: debugDaemonStdio ? ["ignore", "inherit", "inherit"] : "ignore",
2631
- windowsHide: true
2632
- });
2633
- await new Promise((resolve, reject) => {
2634
- child.once("error", reject);
2635
- child.once("spawn", resolve);
2636
- });
2637
- child.unref();
2698
+ await spawnDetachedDaemonProcess(
2699
+ runtime.nodeExecutable,
2700
+ getRuntimeCommandArgs(runtime, mode, options),
2701
+ {
2702
+ env: {
2703
+ ...process.env,
2704
+ BUDA_CONNECTOR_INTERNAL_LAUNCH_CONFIG: JSON.stringify(launchConfig ?? {})
2705
+ },
2706
+ stdio: debugDaemonStdio ? ["ignore", "inherit", "inherit"] : "ignore"
2707
+ }
2708
+ );
2638
2709
  };
2639
2710
  var stopOlderIdleDaemon = async (config, status) => {
2640
2711
  if (!shouldReplaceDaemonVersion(status.version, CONNECTOR_RUNTIME_VERSION)) return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@buda-ai/connector",
3
- "version": "0.1.18",
3
+ "version": "0.1.20",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -18,6 +18,7 @@
18
18
  "dev": "tsx src/cli.ts dev",
19
19
  "daemon": "tsx src/cli.ts daemon",
20
20
  "new": "tsx src/cli.ts new",
21
+ "prepack": "tsup --silent",
21
22
  "start": "node dist/cli.js daemon",
22
23
  "build": "tsup",
23
24
  "test": "vitest run",