fix(cli): correctly handle auto-update for standalone binaries (#23038)

This commit is contained in:
Bryan Morgan
2026-03-18 21:52:23 -04:00
committed by GitHub
parent 5fa14dbe42
commit 8db2948361
4 changed files with 36 additions and 4 deletions

View File

@@ -202,7 +202,12 @@ describe('handleAutoUpdate', () => {
expect(mockSpawn).not.toHaveBeenCalled();
});
it.each([PackageManager.NPX, PackageManager.PNPX, PackageManager.BUNX])(
it.each([
PackageManager.NPX,
PackageManager.PNPX,
PackageManager.BUNX,
PackageManager.BINARY,
])(
'should suppress update notifications when running via %s',
(packageManager) => {
mockGetInstallationInfo.mockReturnValue({

View File

@@ -87,9 +87,12 @@ export function handleAutoUpdate(
);
if (
[PackageManager.NPX, PackageManager.PNPX, PackageManager.BUNX].includes(
installationInfo.packageManager,
)
[
PackageManager.NPX,
PackageManager.PNPX,
PackageManager.BUNX,
PackageManager.BINARY,
].includes(installationInfo.packageManager)
) {
return;
}

View File

@@ -58,6 +58,19 @@ describe('getInstallationInfo', () => {
process.argv = originalArgv;
});
it('should detect running as a standalone binary', () => {
vi.stubEnv('IS_BINARY', 'true');
process.argv[1] = '/path/to/binary';
const info = getInstallationInfo(projectRoot, true);
expect(info.packageManager).toBe(PackageManager.BINARY);
expect(info.isGlobal).toBe(true);
expect(info.updateMessage).toBe(
'Running as a standalone binary. Please update by downloading the latest version from GitHub.',
);
expect(info.updateCommand).toBeUndefined();
vi.unstubAllEnvs();
});
it('should return UNKNOWN when cliPath is not available', () => {
process.argv[1] = '';
const info = getInstallationInfo(projectRoot, true);

View File

@@ -21,6 +21,7 @@ export enum PackageManager {
BUNX = 'bunx',
HOMEBREW = 'homebrew',
NPX = 'npx',
BINARY = 'binary',
UNKNOWN = 'unknown',
}
@@ -41,6 +42,16 @@ export function getInstallationInfo(
}
try {
// Check for standalone binary first
if (process.env['IS_BINARY'] === 'true') {
return {
packageManager: PackageManager.BINARY,
isGlobal: true,
updateMessage:
'Running as a standalone binary. Please update by downloading the latest version from GitHub.',
};
}
// Normalize path separators to forward slashes for consistent matching.
const realPath = fs.realpathSync(cliPath).replace(/\\/g, '/');
const normalizedProjectRoot = projectRoot?.replace(/\\/g, '/');