From c23f909468acc1468d93068ea7a576b199046a85 Mon Sep 17 00:00:00 2001 From: matthew-pilot Date: Thu, 28 May 2026 11:02:01 +0000 Subject: [PATCH] fix: probe sub-package bin/ in runtime seeder (PILOT-209) pkgBinDir() previously only looked in the main package's bin// directory for native binaries. Because bin/ is .gitignored and excluded from the files array, published packages never contain it. The optional platform sub-packages (e.g. pilotprotocol-darwin-arm64) ship binaries in their own bin/ directories, but the runtime never checked there. Add a fallback: when the main package bin// is absent, resolve node_modules/pilotprotocol-/bin/ from the optional dependency. Also tightened the existence check: the sub-package fallback only resolves when pilotctl (BIN_NAMES[0]) actually exists there. --- src/runtime.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/runtime.ts b/src/runtime.ts index 15c24c2..f0a0535 100644 --- a/src/runtime.ts +++ b/src/runtime.ts @@ -88,7 +88,16 @@ function pkgBinDir(): string { // resorting to vi.spyOn on a live binding. Honored only when set. const override = process.env['PILOT_PKG_BIN_DIR']; if (override) return override; - return join(pkgBinRoot(), platformDirName()); + const root = pkgBinRoot(); + const dir = platformDirName(); + const mainPath = join(root, dir); + if (existsSync(mainPath)) return mainPath; + // Fallback: optional platform sub-package installed by npm via + // optionalDependencies (e.g. pilotprotocol-darwin-arm64). These ship + // native Go binaries in their own bin/ directory. + const subPkgPath = resolve(root, '..', 'node_modules', `pilotprotocol-${dir}`, 'bin'); + if (existsSync(subPkgPath) && existsSync(join(subPkgPath, BIN_NAMES[0]))) return subPkgPath; + return mainPath; } function runtimeRoot(): string {