@getmonoceros/workbench 1.38.8 → 1.38.9

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/bin.js CHANGED
@@ -9005,7 +9005,7 @@ var CLI_VERSION;
9005
9005
  var init_version = __esm({
9006
9006
  "src/version.ts"() {
9007
9007
  "use strict";
9008
- CLI_VERSION = true ? "1.38.8" : "dev";
9008
+ CLI_VERSION = true ? "1.38.9" : "dev";
9009
9009
  }
9010
9010
  });
9011
9011
 
@@ -12623,15 +12623,65 @@ var init_caddy = __esm({
12623
12623
  }
12624
12624
  });
12625
12625
 
12626
- // src/share/run.ts
12626
+ // src/devcontainer/wsl-networking.ts
12627
+ import { spawn as spawn14 } from "child_process";
12627
12628
  import os4 from "os";
12628
- import { spawn as spawn14, spawnSync as spawnSync2 } from "child_process";
12629
+ function capture(cmd, args) {
12630
+ return new Promise((resolve) => {
12631
+ let stdout = "";
12632
+ const child = spawn14(cmd, args, {
12633
+ stdio: ["ignore", "pipe", "ignore"]
12634
+ });
12635
+ child.stdout.on("data", (c) => stdout += c.toString());
12636
+ child.on("error", () => resolve({ stdout: "", code: -1 }));
12637
+ child.on("exit", (code) => resolve({ stdout, code: code ?? -1 }));
12638
+ });
12639
+ }
12640
+ async function windowsLanIpv4() {
12641
+ if (!isWsl()) return null;
12642
+ const psScript = "(Get-NetIPConfiguration | Where-Object { $_.IPv4DefaultGateway -ne $null -and $_.NetAdapter.Status -eq 'Up' } | Select-Object -First 1 -ExpandProperty IPv4Address).IPAddress";
12643
+ const r = await capture("powershell.exe", [
12644
+ "-NoProfile",
12645
+ "-NonInteractive",
12646
+ "-Command",
12647
+ psScript
12648
+ ]);
12649
+ const ip = r.stdout.replace(/\r/g, "").trim().split(/\s+/)[0] ?? "";
12650
+ return IPV4_RE3.test(ip) ? ip : null;
12651
+ }
12652
+ function localInterfacesInclude(ip) {
12653
+ for (const list of Object.values(os4.networkInterfaces())) {
12654
+ for (const addr of list ?? []) {
12655
+ if (addr.family === "IPv4" && addr.address === ip) return true;
12656
+ }
12657
+ }
12658
+ return false;
12659
+ }
12660
+ async function wslLanTarget() {
12661
+ const lanIp = await windowsLanIpv4();
12662
+ return {
12663
+ lanIp,
12664
+ mirrored: lanIp !== null && localInterfacesInclude(lanIp)
12665
+ };
12666
+ }
12667
+ var IPV4_RE3;
12668
+ var init_wsl_networking = __esm({
12669
+ "src/devcontainer/wsl-networking.ts"() {
12670
+ "use strict";
12671
+ init_ssh_attach();
12672
+ IPV4_RE3 = /^(\d{1,3}\.){3}\d{1,3}$/;
12673
+ }
12674
+ });
12675
+
12676
+ // src/share/run.ts
12677
+ import os5 from "os";
12678
+ import { spawn as spawn15, spawnSync as spawnSync2 } from "child_process";
12629
12679
  import { consola as consola35 } from "consola";
12630
12680
  import { promises as fs22 } from "fs";
12631
12681
  import path34 from "path";
12632
12682
  function realHostAddresses() {
12633
12683
  let ip;
12634
- for (const list of Object.values(os4.networkInterfaces())) {
12684
+ for (const list of Object.values(os5.networkInterfaces())) {
12635
12685
  for (const addr of list ?? []) {
12636
12686
  if (addr.family === "IPv4" && !addr.internal) {
12637
12687
  ip = addr.address;
@@ -12650,19 +12700,19 @@ function mdnsHostName() {
12650
12700
  const name = res.status === 0 ? res.stdout.trim() : "";
12651
12701
  if (name) return `${name}.local`;
12652
12702
  }
12653
- const hn = os4.hostname();
12703
+ const hn = os5.hostname();
12654
12704
  return hn.endsWith(".local") ? hn : `${hn}.local`;
12655
12705
  }
12656
12706
  async function defaultEnsureImage(image, log) {
12657
12707
  const present = await new Promise((resolve) => {
12658
- const c = spawn14("docker", ["image", "inspect", image], { stdio: "ignore" });
12708
+ const c = spawn15("docker", ["image", "inspect", image], { stdio: "ignore" });
12659
12709
  c.on("error", () => resolve(false));
12660
12710
  c.on("exit", (code) => resolve(code === 0));
12661
12711
  });
12662
12712
  if (present) return;
12663
12713
  log.info(dim(`Pulling ${image} (first run, one-time)\u2026`));
12664
12714
  await new Promise((resolve, reject) => {
12665
- const c = spawn14("docker", ["pull", "-q", image], {
12715
+ const c = spawn15("docker", ["pull", "-q", image], {
12666
12716
  stdio: ["ignore", "ignore", "pipe"]
12667
12717
  });
12668
12718
  let err = "";
@@ -12715,7 +12765,14 @@ async function runShare(opts) {
12715
12765
  for (const port of ports) {
12716
12766
  await preflight({ port, address: SHARE_ADDRESS });
12717
12767
  }
12718
- const { ip, mdnsName } = (opts.hostAddresses ?? realHostAddresses)();
12768
+ const { ip: rawIp, mdnsName } = (opts.hostAddresses ?? realHostAddresses)();
12769
+ let ip = rawIp;
12770
+ let wslNatUnreachable = false;
12771
+ if (isWsl()) {
12772
+ const t = await wslLanTarget();
12773
+ if (t.lanIp) ip = t.lanIp;
12774
+ wslNatUnreachable = t.lanIp !== null && !t.mirrored;
12775
+ }
12719
12776
  const sans = [mdnsName, ip, "localhost", "127.0.0.1"].filter(
12720
12777
  (s) => typeof s === "string" && s.length > 0
12721
12778
  );
@@ -12762,6 +12819,17 @@ async function runShare(opts) {
12762
12819
  ` First device? Trust the local CA once so HTTPS is warning-free: ${caPath}`
12763
12820
  )
12764
12821
  );
12822
+ if (wslNatUnreachable) {
12823
+ const warn = log.warn ?? log.info;
12824
+ warn(
12825
+ "WSL is in NAT mode, so the URL above is not reachable from other devices yet."
12826
+ );
12827
+ warn("Enable mirrored networking once, then re-run this command:");
12828
+ warn(" 1. add to %USERPROFILE%\\.wslconfig:");
12829
+ warn(" [wsl2]");
12830
+ warn(" networkingMode=mirrored");
12831
+ warn(" 2. run wsl --shutdown in PowerShell (closes your WSL sessions)");
12832
+ }
12765
12833
  const dockerSpawn = opts.dockerSpawn ?? defaultDockerSpawn;
12766
12834
  const handles = [
12767
12835
  dockerSpawn(
@@ -12801,6 +12869,7 @@ var init_run4 = __esm({
12801
12869
  init_caddy();
12802
12870
  init_paths();
12803
12871
  init_ssh_attach();
12872
+ init_wsl_networking();
12804
12873
  init_format();
12805
12874
  SHARE_ADDRESS = "0.0.0.0";
12806
12875
  }