@get-bb/plugin-sdk 0.6.80 → 0.6.90

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.
@@ -45,8 +45,8 @@ var require_windows = __commonJS({
45
45
  "../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/windows.js"(exports, module) {
46
46
  module.exports = isexe;
47
47
  isexe.sync = sync;
48
- var fs = __require("fs");
49
- function checkPathExt(path, options) {
48
+ var fs2 = __require("fs");
49
+ function checkPathExt(path2, options) {
50
50
  var pathext = options.pathExt !== void 0 ? options.pathExt : process.env.PATHEXT;
51
51
  if (!pathext) {
52
52
  return true;
@@ -57,25 +57,25 @@ var require_windows = __commonJS({
57
57
  }
58
58
  for (var i = 0; i < pathext.length; i++) {
59
59
  var p = pathext[i].toLowerCase();
60
- if (p && path.substr(-p.length).toLowerCase() === p) {
60
+ if (p && path2.substr(-p.length).toLowerCase() === p) {
61
61
  return true;
62
62
  }
63
63
  }
64
64
  return false;
65
65
  }
66
- function checkStat(stat, path, options) {
66
+ function checkStat(stat, path2, options) {
67
67
  if (!stat.isSymbolicLink() && !stat.isFile()) {
68
68
  return false;
69
69
  }
70
- return checkPathExt(path, options);
70
+ return checkPathExt(path2, options);
71
71
  }
72
- function isexe(path, options, cb) {
73
- fs.stat(path, function(er, stat) {
74
- cb(er, er ? false : checkStat(stat, path, options));
72
+ function isexe(path2, options, cb) {
73
+ fs2.stat(path2, function(er, stat) {
74
+ cb(er, er ? false : checkStat(stat, path2, options));
75
75
  });
76
76
  }
77
- function sync(path, options) {
78
- return checkStat(fs.statSync(path), path, options);
77
+ function sync(path2, options) {
78
+ return checkStat(fs2.statSync(path2), path2, options);
79
79
  }
80
80
  }
81
81
  });
@@ -85,14 +85,14 @@ var require_mode = __commonJS({
85
85
  "../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/mode.js"(exports, module) {
86
86
  module.exports = isexe;
87
87
  isexe.sync = sync;
88
- var fs = __require("fs");
89
- function isexe(path, options, cb) {
90
- fs.stat(path, function(er, stat) {
88
+ var fs2 = __require("fs");
89
+ function isexe(path2, options, cb) {
90
+ fs2.stat(path2, function(er, stat) {
91
91
  cb(er, er ? false : checkStat(stat, options));
92
92
  });
93
93
  }
94
- function sync(path, options) {
95
- return checkStat(fs.statSync(path), options);
94
+ function sync(path2, options) {
95
+ return checkStat(fs2.statSync(path2), options);
96
96
  }
97
97
  function checkStat(stat, options) {
98
98
  return stat.isFile() && checkMode(stat, options);
@@ -116,7 +116,7 @@ var require_mode = __commonJS({
116
116
  // ../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/index.js
117
117
  var require_isexe = __commonJS({
118
118
  "../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/index.js"(exports, module) {
119
- var fs = __require("fs");
119
+ var fs2 = __require("fs");
120
120
  var core;
121
121
  if (process.platform === "win32" || global.TESTING_WINDOWS) {
122
122
  core = require_windows();
@@ -125,7 +125,7 @@ var require_isexe = __commonJS({
125
125
  }
126
126
  module.exports = isexe;
127
127
  isexe.sync = sync;
128
- function isexe(path, options, cb) {
128
+ function isexe(path2, options, cb) {
129
129
  if (typeof options === "function") {
130
130
  cb = options;
131
131
  options = {};
@@ -135,7 +135,7 @@ var require_isexe = __commonJS({
135
135
  throw new TypeError("callback not provided");
136
136
  }
137
137
  return new Promise(function(resolve2, reject) {
138
- isexe(path, options || {}, function(er, is) {
138
+ isexe(path2, options || {}, function(er, is) {
139
139
  if (er) {
140
140
  reject(er);
141
141
  } else {
@@ -144,7 +144,7 @@ var require_isexe = __commonJS({
144
144
  });
145
145
  });
146
146
  }
147
- core(path, options || {}, function(er, is) {
147
+ core(path2, options || {}, function(er, is) {
148
148
  if (er) {
149
149
  if (er.code === "EACCES" || options && options.ignoreErrors) {
150
150
  er = null;
@@ -154,9 +154,9 @@ var require_isexe = __commonJS({
154
154
  cb(er, is);
155
155
  });
156
156
  }
157
- function sync(path, options) {
157
+ function sync(path2, options) {
158
158
  try {
159
- return core.sync(path, options || {});
159
+ return core.sync(path2, options || {});
160
160
  } catch (er) {
161
161
  if (options && options.ignoreErrors || er.code === "EACCES") {
162
162
  return false;
@@ -171,22 +171,22 @@ var require_isexe = __commonJS({
171
171
  // ../../node_modules/.pnpm/which@2.0.2/node_modules/which/which.js
172
172
  var require_which = __commonJS({
173
173
  "../../node_modules/.pnpm/which@2.0.2/node_modules/which/which.js"(exports, module) {
174
- var isWindows = process.platform === "win32" || process.env.OSTYPE === "cygwin" || process.env.OSTYPE === "msys";
175
- var path = __require("path");
176
- var COLON = isWindows ? ";" : ":";
174
+ var isWindows2 = process.platform === "win32" || process.env.OSTYPE === "cygwin" || process.env.OSTYPE === "msys";
175
+ var path2 = __require("path");
176
+ var COLON = isWindows2 ? ";" : ":";
177
177
  var isexe = require_isexe();
178
178
  var getNotFoundError = (cmd) => Object.assign(new Error(`not found: ${cmd}`), { code: "ENOENT" });
179
179
  var getPathInfo = (cmd, opt) => {
180
180
  const colon = opt.colon || COLON;
181
- const pathEnv = cmd.match(/\//) || isWindows && cmd.match(/\\/) ? [""] : [
181
+ const pathEnv = cmd.match(/\//) || isWindows2 && cmd.match(/\\/) ? [""] : [
182
182
  // windows always checks the cwd first
183
- ...isWindows ? [process.cwd()] : [],
183
+ ...isWindows2 ? [process.cwd()] : [],
184
184
  ...(opt.path || process.env.PATH || /* istanbul ignore next: very unusual */
185
185
  "").split(colon)
186
186
  ];
187
- const pathExtExe = isWindows ? opt.pathExt || process.env.PATHEXT || ".EXE;.CMD;.BAT;.COM" : "";
188
- const pathExt = isWindows ? pathExtExe.split(colon) : [""];
189
- if (isWindows) {
187
+ const pathExtExe = isWindows2 ? opt.pathExt || process.env.PATHEXT || ".EXE;.CMD;.BAT;.COM" : "";
188
+ const pathExt = isWindows2 ? pathExtExe.split(colon) : [""];
189
+ if (isWindows2) {
190
190
  if (cmd.indexOf(".") !== -1 && pathExt[0] !== "")
191
191
  pathExt.unshift("");
192
192
  }
@@ -210,7 +210,7 @@ var require_which = __commonJS({
210
210
  return opt.all && found.length ? resolve2(found) : reject(getNotFoundError(cmd));
211
211
  const ppRaw = pathEnv[i];
212
212
  const pathPart = /^".*"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw;
213
- const pCmd = path.join(pathPart, cmd);
213
+ const pCmd = path2.join(pathPart, cmd);
214
214
  const p = !pathPart && /^\.[\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd : pCmd;
215
215
  resolve2(subStep(p, i, 0));
216
216
  });
@@ -237,7 +237,7 @@ var require_which = __commonJS({
237
237
  for (let i = 0; i < pathEnv.length; i++) {
238
238
  const ppRaw = pathEnv[i];
239
239
  const pathPart = /^".*"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw;
240
- const pCmd = path.join(pathPart, cmd);
240
+ const pCmd = path2.join(pathPart, cmd);
241
241
  const p = !pathPart && /^\.[\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd : pCmd;
242
242
  for (let j = 0; j < pathExt.length; j++) {
243
243
  const cur = p + pathExt[j];
@@ -285,7 +285,7 @@ var require_path_key = __commonJS({
285
285
  var require_resolveCommand = __commonJS({
286
286
  "../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/resolveCommand.js"(exports, module) {
287
287
  "use strict";
288
- var path = __require("path");
288
+ var path2 = __require("path");
289
289
  var which = require_which();
290
290
  var getPathKey = require_path_key();
291
291
  function resolveCommandAttempt(parsed, withoutPathExt) {
@@ -303,7 +303,7 @@ var require_resolveCommand = __commonJS({
303
303
  try {
304
304
  resolved = which.sync(parsed.command, {
305
305
  path: env[getPathKey({ env })],
306
- pathExt: withoutPathExt ? path.delimiter : void 0
306
+ pathExt: withoutPathExt ? path2.delimiter : void 0
307
307
  });
308
308
  } catch (e) {
309
309
  } finally {
@@ -312,7 +312,7 @@ var require_resolveCommand = __commonJS({
312
312
  }
313
313
  }
314
314
  if (resolved) {
315
- resolved = path.resolve(hasCustomCwd ? parsed.options.cwd : "", resolved);
315
+ resolved = path2.resolve(hasCustomCwd ? parsed.options.cwd : "", resolved);
316
316
  }
317
317
  return resolved;
318
318
  }
@@ -366,8 +366,8 @@ var require_shebang_command = __commonJS({
366
366
  if (!match) {
367
367
  return null;
368
368
  }
369
- const [path, argument] = match[0].replace(/#! ?/, "").split(" ");
370
- const binary = path.split("/").pop();
369
+ const [path2, argument] = match[0].replace(/#! ?/, "").split(" ");
370
+ const binary = path2.split("/").pop();
371
371
  if (binary === "env") {
372
372
  return argument;
373
373
  }
@@ -380,16 +380,16 @@ var require_shebang_command = __commonJS({
380
380
  var require_readShebang = __commonJS({
381
381
  "../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/readShebang.js"(exports, module) {
382
382
  "use strict";
383
- var fs = __require("fs");
383
+ var fs2 = __require("fs");
384
384
  var shebangCommand = require_shebang_command();
385
385
  function readShebang(command) {
386
386
  const size = 150;
387
387
  const buffer = Buffer.alloc(size);
388
388
  let fd;
389
389
  try {
390
- fd = fs.openSync(command, "r");
391
- fs.readSync(fd, buffer, 0, size, 0);
392
- fs.closeSync(fd);
390
+ fd = fs2.openSync(command, "r");
391
+ fs2.readSync(fd, buffer, 0, size, 0);
392
+ fs2.closeSync(fd);
393
393
  } catch (e) {
394
394
  }
395
395
  return shebangCommand(buffer.toString());
@@ -402,7 +402,7 @@ var require_readShebang = __commonJS({
402
402
  var require_parse = __commonJS({
403
403
  "../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/parse.js"(exports, module) {
404
404
  "use strict";
405
- var path = __require("path");
405
+ var path2 = __require("path");
406
406
  var resolveCommand = require_resolveCommand();
407
407
  var escape = require_escape();
408
408
  var readShebang = require_readShebang();
@@ -427,7 +427,7 @@ var require_parse = __commonJS({
427
427
  const needsShell = !isExecutableRegExp.test(commandFile);
428
428
  if (parsed.options.forceShell || needsShell) {
429
429
  const needsDoubleEscapeMetaChars = isCmdShimRegExp.test(commandFile);
430
- parsed.command = path.normalize(parsed.command);
430
+ parsed.command = path2.normalize(parsed.command);
431
431
  parsed.command = escape.command(parsed.command);
432
432
  parsed.args = parsed.args.map((arg) => escape.argument(arg, needsDoubleEscapeMetaChars));
433
433
  const shellCommand = [parsed.command].concat(parsed.args).join(" ");
@@ -437,7 +437,7 @@ var require_parse = __commonJS({
437
437
  }
438
438
  return parsed;
439
439
  }
440
- function parse(command, args, options) {
440
+ function parse2(command, args, options) {
441
441
  if (args && !Array.isArray(args)) {
442
442
  options = args;
443
443
  args = null;
@@ -456,7 +456,7 @@ var require_parse = __commonJS({
456
456
  };
457
457
  return options.shell ? parsed : parseNonShell(parsed);
458
458
  }
459
- module.exports = parse;
459
+ module.exports = parse2;
460
460
  }
461
461
  });
462
462
 
@@ -515,36 +515,509 @@ var require_cross_spawn = __commonJS({
515
515
  "../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/index.js"(exports, module) {
516
516
  "use strict";
517
517
  var cp = __require("child_process");
518
- var parse = require_parse();
518
+ var parse2 = require_parse();
519
519
  var enoent = require_enoent();
520
- function spawn(command, args, options) {
521
- const parsed = parse(command, args, options);
520
+ function spawn2(command, args, options) {
521
+ const parsed = parse2(command, args, options);
522
522
  const spawned = cp.spawn(parsed.command, parsed.args, parsed.options);
523
523
  enoent.hookChildProcess(spawned, parsed);
524
524
  return spawned;
525
525
  }
526
- function spawnSync(command, args, options) {
527
- const parsed = parse(command, args, options);
526
+ function spawnSync2(command, args, options) {
527
+ const parsed = parse2(command, args, options);
528
528
  const result = cp.spawnSync(parsed.command, parsed.args, parsed.options);
529
529
  result.error = result.error || enoent.verifyENOENTSync(result.status, parsed);
530
530
  return result;
531
531
  }
532
- module.exports = spawn;
533
- module.exports.spawn = spawn;
534
- module.exports.sync = spawnSync;
535
- module.exports._parse = parse;
532
+ module.exports = spawn2;
533
+ module.exports.spawn = spawn2;
534
+ module.exports.sync = spawnSync2;
535
+ module.exports._parse = parse2;
536
536
  module.exports._enoent = enoent;
537
537
  }
538
538
  });
539
539
 
540
540
  // ../provider-bridge-protocol/src/bridge-worker-entry.ts
541
541
  import { rmSync } from "node:fs";
542
- import { isAbsolute } from "node:path";
542
+ import { isAbsolute as isAbsolute2 } from "node:path";
543
543
  import { pathToFileURL } from "node:url";
544
544
 
545
- // ../process-utils/src/spawn.ts
545
+ // ../process-utils/src/host-process.ts
546
+ var import_parse = __toESM(require_parse(), 1);
546
547
  var import_cross_spawn = __toESM(require_cross_spawn(), 1);
547
548
 
549
+ // ../process-utils/src/host-toolchain.ts
550
+ import { spawn, spawnSync } from "node:child_process";
551
+ import {
552
+ accessSync,
553
+ constants,
554
+ existsSync,
555
+ readdirSync,
556
+ realpathSync,
557
+ statSync
558
+ } from "node:fs";
559
+ import { createRequire } from "node:module";
560
+ import { homedir } from "node:os";
561
+ import {
562
+ basename,
563
+ delimiter,
564
+ dirname,
565
+ extname,
566
+ isAbsolute,
567
+ join
568
+ } from "node:path";
569
+ import { fileURLToPath } from "node:url";
570
+
571
+ // ../../node_modules/.pnpm/which-command@0.1.0/node_modules/which-command/index.js
572
+ import fs from "node:fs";
573
+ import path from "node:path";
574
+ import process2 from "node:process";
575
+ var isWindows = process2.platform === "win32";
576
+ var separatorPattern = isWindows ? new RegExp("[\\/\\\\]", "v") : new RegExp("\\/", "v");
577
+ var defaultPathExt = ".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC";
578
+ function resolveOptions(command, options) {
579
+ if (typeof command !== "string" || command.length === 0) {
580
+ throw new TypeError("Expected a non-empty string.");
581
+ }
582
+ const {
583
+ cwd = process2.cwd(),
584
+ // On Windows, `process.env.PATH` can be undefined in some contexts (for example, worker threads), where it's only exposed as `Path`.
585
+ path: searchPath = process2.env.PATH ?? (isWindows ? process2.env.Path : void 0) ?? "",
586
+ // `||` (not `??`) so an empty `PATHEXT` falls back to the default instead of disabling all lookup on Windows.
587
+ pathExt = process2.env.PATHEXT || defaultPathExt
588
+ } = options;
589
+ return { cwd, searchPath, pathExt };
590
+ }
591
+ function windowsExtensions(command, pathExt) {
592
+ const extensions = pathExt.split(path.delimiter).filter(Boolean);
593
+ const commandExtension = path.extname(command).toLowerCase();
594
+ if (commandExtension !== "" && extensions.some((extension) => extension.toLowerCase() === commandExtension)) {
595
+ return ["", ...extensions];
596
+ }
597
+ return extensions;
598
+ }
599
+ function* candidatePaths(command, { cwd, searchPath, pathExt }) {
600
+ const extensions = isWindows ? windowsExtensions(command, pathExt) : [""];
601
+ if (separatorPattern.test(command)) {
602
+ const base = path.resolve(cwd, command);
603
+ for (const extension of extensions) {
604
+ yield base + extension;
605
+ }
606
+ return;
607
+ }
608
+ const directories = [
609
+ // Windows searches the current directory before `PATH`.
610
+ ...isWindows ? [cwd] : [],
611
+ ...searchPath.split(path.delimiter)
612
+ ];
613
+ for (const directory of directories) {
614
+ const unquoted = isWindows && directory.length > 1 && directory.startsWith('"') && directory.endsWith('"') ? directory.slice(1, -1) : directory;
615
+ if (unquoted === "") {
616
+ continue;
617
+ }
618
+ const base = path.resolve(cwd, unquoted, command);
619
+ for (const extension of extensions) {
620
+ yield base + extension;
621
+ }
622
+ }
623
+ }
624
+ function isExecutableSync(filePath) {
625
+ let stats;
626
+ try {
627
+ stats = fs.statSync(filePath);
628
+ } catch (error) {
629
+ return isWindows && error.code === "EACCES";
630
+ }
631
+ if (!stats.isFile()) {
632
+ return false;
633
+ }
634
+ if (isWindows) {
635
+ return true;
636
+ }
637
+ try {
638
+ fs.accessSync(filePath, fs.constants.X_OK);
639
+ return true;
640
+ } catch {
641
+ return false;
642
+ }
643
+ }
644
+ function whichCommandSync(command, options = {}) {
645
+ const resolved = resolveOptions(command, options);
646
+ for (const candidate of candidatePaths(command, resolved)) {
647
+ if (isExecutableSync(candidate)) {
648
+ return candidate;
649
+ }
650
+ }
651
+ return void 0;
652
+ }
653
+
654
+ // ../process-utils/src/host-toolchain.ts
655
+ var NETWORK_KEYS = [
656
+ "HTTP_PROXY",
657
+ "HTTPS_PROXY",
658
+ "NO_PROXY",
659
+ "http_proxy",
660
+ "https_proxy",
661
+ "no_proxy",
662
+ "NODE_EXTRA_CA_CERTS",
663
+ "SSL_CERT_FILE",
664
+ "SSL_CERT_DIR"
665
+ ];
666
+ var SHELL_START = "__BB_SHELL_ENV_START__";
667
+ var SHELL_END = "__BB_SHELL_ENV_END__";
668
+ var PROBE_TIMEOUT_MS = 3e3;
669
+ var PROBE_OUTPUT_MAX_CHARS = 1024 * 1024;
670
+ function executable(file) {
671
+ try {
672
+ accessSync(
673
+ file,
674
+ process.platform === "win32" ? constants.F_OK : constants.X_OK
675
+ );
676
+ return statSync(file).isFile();
677
+ } catch {
678
+ return false;
679
+ }
680
+ }
681
+ function envValue(env, key) {
682
+ if (process.platform !== "win32") return env[key];
683
+ return env[Object.keys(env).find(
684
+ (entry2) => entry2.toUpperCase() === key.toUpperCase()
685
+ ) ?? key];
686
+ }
687
+ function mergePath(...paths) {
688
+ const seen = /* @__PURE__ */ new Set();
689
+ return paths.flatMap((value) => (value ?? "").split(delimiter)).filter((entry2) => {
690
+ if (!entry2) return false;
691
+ const key = process.platform === "win32" ? entry2.replace(/[\\/]+$/u, "").toLowerCase() : entry2;
692
+ if (seen.has(key)) return false;
693
+ seen.add(key);
694
+ return true;
695
+ }).join(delimiter);
696
+ }
697
+ function onDiskName(file) {
698
+ if (process.platform !== "win32") return file;
699
+ try {
700
+ const name = basename(file).toLowerCase();
701
+ const entry2 = readdirSync(dirname(file)).find(
702
+ (candidate) => candidate.toLowerCase() === name
703
+ );
704
+ return entry2 === void 0 ? file : join(dirname(file), entry2);
705
+ } catch {
706
+ return file;
707
+ }
708
+ }
709
+ function runProbe(command, args, env) {
710
+ return new Promise((resolve2) => {
711
+ let stdout = "";
712
+ let settled = false;
713
+ let timer;
714
+ const finish = (status) => {
715
+ if (settled) return;
716
+ settled = true;
717
+ clearTimeout(timer);
718
+ resolve2({ status, stdout });
719
+ };
720
+ let child;
721
+ try {
722
+ child = spawn(command, args, {
723
+ cwd: homedir(),
724
+ env,
725
+ stdio: ["ignore", "pipe", "ignore"],
726
+ windowsHide: true
727
+ });
728
+ } catch {
729
+ finish(null);
730
+ return;
731
+ }
732
+ timer = setTimeout(() => {
733
+ child.kill("SIGKILL");
734
+ finish(null);
735
+ }, PROBE_TIMEOUT_MS);
736
+ child.stdout?.setEncoding("utf8");
737
+ child.stdout?.on("data", (chunk) => {
738
+ if (stdout.length < PROBE_OUTPUT_MAX_CHARS) stdout += chunk;
739
+ });
740
+ child.once("error", () => finish(null));
741
+ child.once("close", (code) => finish(code));
742
+ });
743
+ }
744
+ async function readShellEnvironment(env, retainPrevious) {
745
+ if (process.platform === "win32") {
746
+ const registry2 = join(
747
+ envValue(env, "SystemRoot") ?? "C:\\Windows",
748
+ "System32",
749
+ "reg.exe"
750
+ );
751
+ const values = { ...env };
752
+ const paths = [];
753
+ for (const key of [
754
+ "HKLM\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment",
755
+ "HKCU\\Environment"
756
+ ]) {
757
+ const result = await runProbe(registry2, ["query", key], env);
758
+ if (result.status !== 0) continue;
759
+ for (const match of result.stdout.matchAll(
760
+ /^ {4}(.+?) {4}REG_[A-Z_]+ {4}(.*)$/gmu
761
+ )) {
762
+ const name = match[1]?.trim();
763
+ if (!name) continue;
764
+ const value = (match[2] ?? "").trim();
765
+ if (name.toUpperCase() === "PATH") paths.push(value);
766
+ else {
767
+ const existing = Object.keys(values).find(
768
+ (key2) => key2.toUpperCase() === name.toUpperCase()
769
+ );
770
+ values[existing ?? name] = value;
771
+ }
772
+ }
773
+ }
774
+ const expand = (value) => {
775
+ for (let depth = 0; depth < 10; depth += 1) {
776
+ const expanded = value.replace(
777
+ /%([^%;\\/]+)%/gu,
778
+ (reference, variable) => envValue(values, variable) ?? reference
779
+ );
780
+ if (expanded === value) break;
781
+ value = expanded;
782
+ }
783
+ return value;
784
+ };
785
+ return paths.length === 0 ? null : { PATH: mergePath(...paths.map(expand), envValue(env, "PATH")) };
786
+ }
787
+ const shell = env.SHELL?.trim() || (process.platform === "darwin" ? "/bin/zsh" : "/bin/sh");
788
+ const command = `printf '%s\\n' ${SHELL_START}; /usr/bin/env; printf '%s\\n' ${SHELL_END}`;
789
+ const shellArgs = ["sh", "dash"].includes(basename(shell)) ? ["-lc"] : ["-ilc", "-lc"];
790
+ for (const arg of shellArgs) {
791
+ const result = await runProbe(shell, [arg, command], env);
792
+ if (result.status !== 0) {
793
+ if (retainPrevious) return null;
794
+ continue;
795
+ }
796
+ const start = result.stdout.indexOf(`${SHELL_START}
797
+ `);
798
+ const end = result.stdout.indexOf(`
799
+ ${SHELL_END}`, start);
800
+ if (start < 0 || end < 0) {
801
+ if (retainPrevious) return null;
802
+ continue;
803
+ }
804
+ const values = {};
805
+ for (const line of result.stdout.slice(start + SHELL_START.length + 1, end).split("\n")) {
806
+ const separator = line.indexOf("=");
807
+ const key = line.slice(0, separator);
808
+ if (key === "PATH" || NETWORK_KEYS.includes(key))
809
+ values[key] = line.slice(separator + 1);
810
+ }
811
+ if (values.PATH) return values;
812
+ }
813
+ return null;
814
+ }
815
+ var HostToolchain = class {
816
+ constructor(baseEnv = process.env, runtimePath = process.execPath) {
817
+ this.baseEnv = baseEnv;
818
+ this.runtimePath = runtimePath;
819
+ this.inheritedPath = envValue(baseEnv, "PATH");
820
+ this.nodePath = runtimePath;
821
+ }
822
+ baseEnv;
823
+ runtimePath;
824
+ shellEnv = {};
825
+ inheritedPath;
826
+ misses = /* @__PURE__ */ new Set();
827
+ nodePath;
828
+ refreshing = null;
829
+ refreshedAt = 0;
830
+ refresh() {
831
+ if (this.refreshing !== null) return this.refreshing;
832
+ this.misses.clear();
833
+ this.refreshedAt = Date.now();
834
+ const retainPrevious = this.shellEnv.PATH !== void 0;
835
+ this.refreshing = readShellEnvironment(this.baseEnv, retainPrevious).then((env) => {
836
+ if (env !== null) this.shellEnv = env;
837
+ }).finally(() => {
838
+ this.refreshing = null;
839
+ });
840
+ return this.refreshing;
841
+ }
842
+ invalidateFailure(errorOrCode) {
843
+ const code = typeof errorOrCode === "object" && errorOrCode !== null && "code" in errorOrCode ? errorOrCode.code : errorOrCode;
844
+ if (code === "ENOENT" || code === 127) void this.refresh();
845
+ }
846
+ searchPath(env) {
847
+ const inherited = envValue(env, "PATH");
848
+ const home = envValue(env, process.platform === "win32" ? "USERPROFILE" : "HOME") ?? homedir();
849
+ const fallbacks = [
850
+ join(home, ".local", "bin"),
851
+ join(home, ".local", "share", "mise", "shims"),
852
+ join(home, ".asdf", "shims"),
853
+ join(home, ".asdf", "bin"),
854
+ join(home, ".volta", "bin")
855
+ ];
856
+ if (process.platform === "darwin") fallbacks.push("/opt/homebrew/bin");
857
+ if (process.platform !== "win32")
858
+ fallbacks.push("/usr/local/bin", "/usr/bin", "/bin");
859
+ const [first, second] = inherited === void 0 || inherited === this.inheritedPath ? [this.shellEnv.PATH, inherited] : [inherited, this.shellEnv.PATH];
860
+ return mergePath(
861
+ first,
862
+ second,
863
+ executable(this.nodePath) && /^node(?:\.exe)?$/iu.test(basename(this.nodePath)) ? dirname(this.nodePath) : void 0,
864
+ ...fallbacks
865
+ );
866
+ }
867
+ environment(env = this.baseEnv) {
868
+ const path2 = this.searchPath(env);
869
+ const result = { ...env };
870
+ if (process.platform === "win32") {
871
+ for (const key of Object.keys(result))
872
+ if (key !== "PATH" && key.toUpperCase() === "PATH") delete result[key];
873
+ }
874
+ if (path2 !== "") result.PATH = path2;
875
+ const callerKeys = new Set(
876
+ Object.keys(env).filter((key) => env[key] !== void 0).map((key) => key.toUpperCase())
877
+ );
878
+ for (const key of NETWORK_KEYS)
879
+ if (!callerKeys.has(key.toUpperCase()) && this.shellEnv[key] !== void 0)
880
+ result[key] = this.shellEnv[key];
881
+ return result;
882
+ }
883
+ lookup(command, options) {
884
+ const env = this.environment(options.env);
885
+ const cwd = options.cwd instanceof URL ? fileURLToPath(options.cwd) : options.cwd ?? process.cwd();
886
+ if (command === "bb") {
887
+ for (const candidate of [
888
+ env.BB_CLI_LAUNCHER,
889
+ env.BB_CLI,
890
+ env.BB_CLI_DIR ? join(env.BB_CLI_DIR, "bb") : void 0
891
+ ]) {
892
+ if (candidate?.trim() && isAbsolute(candidate.trim()) && executable(candidate.trim()))
893
+ return candidate.trim();
894
+ }
895
+ }
896
+ const extension = extname(command);
897
+ const pathExt = envValue(env, "PATHEXT");
898
+ const path2 = envValue(env, "PATH") ?? "";
899
+ const lookupOptions = {
900
+ cwd,
901
+ path: path2,
902
+ pathExt: extension ? `${extension};${pathExt ?? ".EXE;.COM;.CMD;.BAT"}` : pathExt
903
+ };
904
+ const found = command === "bb" ? path2.split(delimiter).filter(isAbsolute).map(
905
+ (directory) => whichCommandSync(join(directory, command), lookupOptions)
906
+ ).find(Boolean) : whichCommandSync(command, lookupOptions);
907
+ return found ? onDiskName(found) : null;
908
+ }
909
+ resolve(command, options = {}) {
910
+ const found = this.lookup(command, options);
911
+ if (found !== null) return found;
912
+ const key = `${command}\0${String(options.cwd ?? "")}\0${envValue(options.env ?? this.baseEnv, "PATH") ?? ""}`;
913
+ const sinceRefresh = Date.now() - this.refreshedAt;
914
+ if (!(this.misses.has(key) && sinceRefresh < 3e4) && (this.misses.size === 0 || sinceRefresh >= 1e3))
915
+ void this.refresh();
916
+ this.misses.add(key);
917
+ return null;
918
+ }
919
+ node(options = {}) {
920
+ if (executable(this.nodePath)) return this.nodePath;
921
+ const stableHomebrew = this.runtimePath.replace(
922
+ /\/Cellar\/([^/]+)\/[^/]+\//u,
923
+ "/opt/$1/"
924
+ );
925
+ const candidates = [
926
+ stableHomebrew,
927
+ process.argv0,
928
+ this.lookup(process.platform === "win32" ? "node.exe" : "node", options)
929
+ ];
930
+ for (const candidate of candidates) {
931
+ if (!candidate || !isAbsolute(candidate) || !executable(candidate))
932
+ continue;
933
+ const probe = spawnSync(
934
+ candidate,
935
+ [
936
+ "-p",
937
+ "JSON.stringify({path:process.execPath,abi:process.versions.modules,electron:!!process.versions.electron})"
938
+ ],
939
+ {
940
+ env: this.environment(options.env),
941
+ cwd: options.cwd,
942
+ encoding: "utf8",
943
+ timeout: PROBE_TIMEOUT_MS,
944
+ killSignal: "SIGKILL",
945
+ windowsHide: true
946
+ }
947
+ );
948
+ if (probe.status !== 0) continue;
949
+ try {
950
+ const runtime = JSON.parse(probe.stdout.trim());
951
+ if (typeof runtime !== "object" || runtime === null || !("path" in runtime) || typeof runtime.path !== "string" || !("abi" in runtime) || runtime.abi !== process.versions.modules || !("electron" in runtime) || runtime.electron !== Boolean(process.versions.electron))
952
+ continue;
953
+ if (isAbsolute(runtime.path) && executable(runtime.path)) {
954
+ this.nodePath = runtime.path;
955
+ return runtime.path;
956
+ }
957
+ } catch {
958
+ }
959
+ }
960
+ throw Object.assign(
961
+ new Error(
962
+ "The Node runtime was removed and no replacement was found. Reinstall Node or restart bb with an available runtime."
963
+ ),
964
+ { code: "ENOENT" }
965
+ );
966
+ }
967
+ bundledNpmCli(command = "npm") {
968
+ const require2 = createRequire(import.meta.url);
969
+ return join(
970
+ dirname(require2.resolve("npm/package.json")),
971
+ "bin",
972
+ `${command}-cli.js`
973
+ );
974
+ }
975
+ npmCli(command = "npm", options = {}) {
976
+ const bin = `${command}-cli.js`;
977
+ const runtime = process.versions.electron ? null : this.node(options);
978
+ const candidates = [];
979
+ if (runtime !== null)
980
+ for (const cli of [
981
+ join(dirname(runtime), "..", "lib", "node_modules", "npm", "bin", bin),
982
+ join(dirname(runtime), "node_modules", "npm", "bin", bin)
983
+ ])
984
+ candidates.push({ node: runtime, cli });
985
+ const installed = this.resolve(command, options);
986
+ if (installed) {
987
+ try {
988
+ const cli = realpathSync(installed);
989
+ const npmRoot = dirname(dirname(cli));
990
+ const node = [
991
+ join(npmRoot, "..", "..", "..", "bin", "node"),
992
+ join(npmRoot, "..", "..", "node.exe"),
993
+ join(dirname(installed), "node")
994
+ ].find(executable);
995
+ if (basename(cli) === bin && node !== void 0)
996
+ candidates.push({ node: realpathSync(node), cli });
997
+ } catch {
998
+ }
999
+ }
1000
+ if (runtime !== null) {
1001
+ try {
1002
+ candidates.push({ node: runtime, cli: this.bundledNpmCli(command) });
1003
+ } catch {
1004
+ }
1005
+ }
1006
+ return candidates.find((candidate) => existsSync(candidate.cli)) ?? null;
1007
+ }
1008
+ command(command, args = [], options = {}) {
1009
+ const file = command === this.runtimePath ? this.node(options) : this.resolve(command, options) ?? command;
1010
+ const env = this.environment(options.env);
1011
+ if (/(?:^|[\\/])(?:npm|npx)-cli\.js$/u.test(args[0] ?? "")) {
1012
+ env.PATH = mergePath(dirname(file), env.PATH);
1013
+ }
1014
+ return { command: file, args: [...args], env };
1015
+ }
1016
+ };
1017
+ var toolchainKey = /* @__PURE__ */ Symbol.for("@bb/process-utils/host-toolchain");
1018
+ var shared = globalThis;
1019
+ var hostToolchain = shared[toolchainKey] ??= new HostToolchain();
1020
+
548
1021
  // ../process-utils/src/vcs-process-scheduler.ts
549
1022
  import { AsyncLocalStorage } from "node:async_hooks";
550
1023
  import { availableParallelism } from "node:os";
@@ -684,21 +1157,16 @@ var scheduler = registry.__bbVcsProcessScheduler ??= new VcsProcessScheduler();
684
1157
  // ../process-utils/src/plugin-process-paths.ts
685
1158
  import { mkdir, mkdtemp } from "node:fs/promises";
686
1159
  import { tmpdir } from "node:os";
687
- import { join } from "node:path";
1160
+ import { join as join2 } from "node:path";
688
1161
  function safePluginSegment(pluginId2) {
689
1162
  return encodeURIComponent(pluginId2);
690
1163
  }
691
1164
  async function createPluginProcessTempDir(args) {
692
1165
  return mkdtemp(
693
- join(tmpdir(), `${args.prefix}-${safePluginSegment(args.pluginId)}-`)
1166
+ join2(tmpdir(), `${args.prefix}-${safePluginSegment(args.pluginId)}-`)
694
1167
  );
695
1168
  }
696
1169
 
697
- // ../process-utils/src/process-info.ts
698
- import { execFile } from "node:child_process";
699
- import { promisify } from "node:util";
700
- var execFileAsync = promisify(execFile);
701
-
702
1170
  // ../provider-bridge-protocol/src/bridge-kit/bounded-line-reader.ts
703
1171
  import { StringDecoder } from "node:string_decoder";
704
1172
  var MAX_JSON_RPC_LINE_BYTES = 64 * 1024 * 1024;
@@ -752,7 +1220,7 @@ function readBoundedLines(args) {
752
1220
 
753
1221
  // ../provider-bridge-protocol/src/bridge-kit/bridge-recorder.ts
754
1222
  import { closeSync, mkdirSync, openSync, writeSync } from "node:fs";
755
- import { join as join2, resolve } from "node:path";
1223
+ import { join as join3, resolve } from "node:path";
756
1224
  import { StringDecoder as StringDecoder2 } from "node:string_decoder";
757
1225
  var PROVIDER_BRIDGE_RECORD_DIR_ENV = "BB_PROVIDER_BRIDGE_RECORD_DIR";
758
1226
  var BRIDGE_RECORDING_PROCESS_SCOPE = "_process";
@@ -832,10 +1300,10 @@ function createBridgeRecorder(args) {
832
1300
  if (existing !== void 0) {
833
1301
  return existing;
834
1302
  }
835
- const scopeDir = join2(dir, scope);
1303
+ const scopeDir = join3(dir, scope);
836
1304
  mkdirSync(scopeDir, { recursive: true });
837
1305
  const fd = openSync(
838
- join2(scopeDir, bridgeRecordingFileName(direction)),
1306
+ join3(scopeDir, bridgeRecordingFileName(direction)),
839
1307
  "a"
840
1308
  );
841
1309
  fds.set(key, fd);
@@ -985,7 +1453,7 @@ function fail(message) {
985
1453
  `);
986
1454
  process.exit(1);
987
1455
  }
988
- if (bridgeModulePath === void 0 || !isAbsolute(bridgeModulePath) || pluginId === void 0 || pluginId === "" || dataDir === void 0 || !isAbsolute(dataDir)) {
1456
+ if (bridgeModulePath === void 0 || !isAbsolute2(bridgeModulePath) || pluginId === void 0 || pluginId === "" || dataDir === void 0 || !isAbsolute2(dataDir)) {
989
1457
  fail(
990
1458
  "provider bridge bootstrap usage: <bridgeModulePath> <pluginId> <pluginDataDir> (absolute paths)"
991
1459
  );