From 6ccbb426503994bd7f079deb0dda0849cd2dd0a4 Mon Sep 17 00:00:00 2001 From: Justin Poehnelt Date: Tue, 31 Mar 2026 11:47:43 -0600 Subject: [PATCH] fix: auto-install binary on run if missing (#654) * fix: auto-install binary on run if missing pnpm skips postinstall when the package is already cached/installed. This commit ensures run.js will auto-trigger install.js if the binary is missing, fixing the 'gws binary not found' error. * chore: add changeset for pnpm binary fix --------- Co-authored-by: jpoehnelt-bot --- .changeset/fix-pnpm-binary-install.md | 9 +++++++++ npm/run.js | 10 ++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 .changeset/fix-pnpm-binary-install.md diff --git a/.changeset/fix-pnpm-binary-install.md b/.changeset/fix-pnpm-binary-install.md new file mode 100644 index 0000000..fe0d0ed --- /dev/null +++ b/.changeset/fix-pnpm-binary-install.md @@ -0,0 +1,9 @@ +--- +"@googleworkspace/cli": patch +--- + +fix: auto-install binary on run if missing + +pnpm skips postinstall when the package is already up to date. +This ensures run.js will auto-trigger install.js if the +binary is missing, fixing the 'gws binary not found' error. diff --git a/npm/run.js b/npm/run.js index 67ff6fd..4d6e84d 100644 --- a/npm/run.js +++ b/npm/run.js @@ -12,9 +12,15 @@ const binPath = path.join(__dirname, "bin", platform.binary); if (!fs.existsSync(binPath)) { console.error( - `gws binary not found at ${binPath}\nRun "npm install -g @googleworkspace/cli" to install it.`, + `gws binary not found at ${binPath}\nAuto-installing...` ); - process.exit(1); + const install = spawnSync(process.execPath, [path.join(__dirname, "install.js")], { + cwd: __dirname, + stdio: "inherit", + }); + if (install.status !== 0) { + process.exit(install.status ?? 1); + } } const result = spawnSync(binPath, process.argv.slice(2), {