fix(install): verify gsd-sdk resolves on PATH after npm install

`npm install -g` can succeed while the binary lands in a prefix that
isn't on the current shell's PATH (common with Homebrew, nvm, or an
unconfigured npm prefix). Re-probe via `which gsd-sdk` (or `where` on
Windows) after install; if it doesn't resolve, downgrade the success
message to a warning with a shell-restart hint.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jeremy McSpadden
2026-04-17 16:09:19 -05:00
parent 08b1d8377d
commit 819af761a0

View File

@@ -6659,12 +6659,30 @@ function installSdkIfNeeded() {
console.log(`\n ${cyan}Installing GSD SDK (@gsd-build/sdk)…${reset}`);
const npmCmd = process.platform === 'win32' ? 'npm.cmd' : 'npm';
const result = spawnSync(npmCmd, ['install', '-g', '@gsd-build/sdk'], { stdio: 'inherit' });
if (result.status === 0) {
console.log(` ${green}✓${reset} Installed @gsd-build/sdk (gsd-sdk now on PATH)`);
} else {
console.warn(` ${yellow}⚠${reset} Failed to install @gsd-build/sdk automatically.`);
const warnManual = (reason) => {
console.warn(` ${yellow}⚠${reset} ${reason}`);
console.warn(` Run manually: ${cyan}npm install -g @gsd-build/sdk${reset}`);
console.warn(` Then restart your shell so the updated PATH is picked up.`);
console.warn(` Without it, /gsd-* commands will fail with "command not found: gsd-sdk".`);
};
if (result.status !== 0) {
warnManual('Failed to install @gsd-build/sdk automatically.');
return;
}
// Verify gsd-sdk is actually resolvable on PATH. npm's global bin dir is
// not always on the current shell's PATH (Homebrew prefixes, nvm setups,
// unconfigured npm prefix), so a zero exit status from `npm install -g`
// alone is not proof of a working binary.
const resolverCmd = process.platform === 'win32' ? 'where' : 'which';
const verify = spawnSync(resolverCmd, ['gsd-sdk'], { encoding: 'utf-8' });
if (verify.status === 0 && verify.stdout && verify.stdout.trim()) {
console.log(` ${green}✓${reset} Installed @gsd-build/sdk (gsd-sdk resolved at ${verify.stdout.trim().split('\n')[0]})`);
} else {
warnManual('Installed @gsd-build/sdk but gsd-sdk is not on PATH — npm global bin may not be in your PATH.');
if (verify.stderr) console.warn(` resolver stderr: ${verify.stderr.trim()}`);
}
}