From 77246d2a6606749f61e43da523c7bc2e4cd368c7 Mon Sep 17 00:00:00 2001 From: dhiyaan Date: Tue, 1 Sep 2026 20:03:20 -0400 Subject: [PATCH] Resolve the plugin root from sim-host.mjs, not by counting ../ from the bundle MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit defaultDeps() was handed new URL("../../", import.meta.url), which is the plugin root when evaluated from src/sim/wire.ts but, from the bundled dist/server.js, is the directory *containing* the install. For a git install that is ~/.bb/plugins/cache/git/github.com//bb-plugin-xcode/, which has no node_modules, so require.resolve("serve-sim/middleware") fails and `bb xcode sim doctor` reports serve-sim as not installed on a machine where it is — with a STOP that blocks Live. resolveSimHostPath already searches both layouts for sim-host.mjs, which sits at the plugin root, so the root is simply its directory. Hoisted that lookup above the preflight wiring and reused it. --- src/sim/wire.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/sim/wire.ts b/src/sim/wire.ts index db85a7b..67d80af 100644 --- a/src/sim/wire.ts +++ b/src/sim/wire.ts @@ -16,7 +16,7 @@ * `safely`, and every fire-and-forget through `detach`. */ import type { BbPluginApi } from "@get-bb/plugin-sdk"; -import { isAbsolute, join, relative, resolve, sep } from "node:path"; +import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path"; import { tmpdir } from "node:os"; import { rpcContract } from "./contract.js"; @@ -167,9 +167,15 @@ export async function installSimulators(bb: BbPluginApi, host: SimulatorHost): P // Probed on first use, not at load: the probes cost a few seconds of child // processes and nothing needs them until someone opens the doctor. Memoized // on the in-flight promise so two panels mounting together share one sweep. - // Two above `src/sim/`, so this is the plugin root either way — bundled at - // `dist/server.js` or evaluated from source. - const preflightDeps = defaultDeps(new URL("../../", import.meta.url).pathname); + // + // The plugin root is wherever `sim-host.mjs` lives: `resolveSimHostPath` + // already knows both layouts. Counting `../` from `import.meta.url` does not + // — two above `src/sim/wire.ts` is the root, but two above `dist/server.js` + // is the directory *containing* a git install, where there is no + // `node_modules`, and the doctor then reports serve-sim as not installed on + // a machine where it is. + const simHost = resolveSimHostPath(import.meta.url); + const preflightDeps = defaultDeps(dirname(simHost.path)); let preflight: Promise | null = null; const getPreflight = (): Promise => { preflight ??= runPreflight(preflightDeps); @@ -203,7 +209,6 @@ export async function installSimulators(bb: BbPluginApi, host: SimulatorHost): P // --------------------------------------------------------------------------- const driver = new DeviceDriver(); - const simHost = resolveSimHostPath(import.meta.url); log("info", `capture host at ${simHost.path}`); const live = new LiveService({ driver,