11import * as vscode from 'vscode' ;
22import { pluginDocs } from './constants' ;
3- import { VersionPreference } from './enums' ;
4- import { executeCommand , isConfigFile , openUpgradeDocumentation , upgradeDevProxyWithPackageManager } from './helpers' ;
3+ import {
4+ PackageManager ,
5+ VersionPreference ,
6+ } from './enums' ;
7+ import { executeCommand , getPackageIdentifier , isConfigFile , openUpgradeDocumentation , upgradeDevProxyWithPackageManager } from './helpers' ;
58import { isDevProxyRunning , getDevProxyExe } from './detect' ;
69
710export const registerCommands = ( context : vscode . ExtensionContext , configuration : vscode . WorkspaceConfiguration ) => {
811 const versionPreference = configuration . get ( 'version' ) as VersionPreference ;
9- const devProxyExe = getDevProxyExe ( configuration . get ( 'version' ) as VersionPreference ) ;
12+ const devProxyExe = getDevProxyExe ( versionPreference ) ;
1013
1114 context . subscriptions . push (
1215 vscode . commands . registerCommand ( 'dev-proxy-toolkit.install' , async ( platform : NodeJS . Platform ) => {
1316 const message = vscode . window . setStatusBarMessage ( 'Installing Dev Proxy...' ) ;
1417
1518 // we are on windows so we can use winget
1619 if ( platform === 'win32' ) {
17- const id = versionPreference === VersionPreference . Stable ? 'Microsoft.DevProxy' : 'Microsoft.DevProxy.Beta' ;
20+ const id = getPackageIdentifier ( versionPreference , PackageManager . Winget ) ;
1821 // we first need to check if winget is installed, it is bundled with windows 11 but not windows 10
1922 try {
2023 await executeCommand ( 'winget --version' ) ;
@@ -37,7 +40,7 @@ export const registerCommands = (context: vscode.ExtensionContext, configuration
3740
3841 // we are on macos so we can use brew
3942 if ( platform === 'darwin' ) {
40- const id = versionPreference === VersionPreference . Stable ? 'dev-proxy' : 'dev-proxy-beta' ;
43+ const id = getPackageIdentifier ( versionPreference , PackageManager . Homebrew ) ;
4144 // check if brew is installed
4245 try {
4346 await executeCommand ( 'brew --version' ) ;
@@ -91,7 +94,13 @@ export const registerCommands = (context: vscode.ExtensionContext, configuration
9194
9295 // Handle Windows
9396 if ( platform === 'win32' ) {
94- const packageId = versionPreference === VersionPreference . Stable ? 'Microsoft.DevProxy' : 'Microsoft.DevProxy.Beta' ;
97+ const packageId = getPackageIdentifier ( versionPreference , PackageManager . Winget ) ;
98+
99+ if ( ! packageId ) {
100+ openUpgradeDocumentation ( ) ;
101+ return ;
102+ }
103+
95104 const upgradeCommand = `winget upgrade ${ packageId } --silent` ;
96105 const isBeta = versionPreference === VersionPreference . Beta ;
97106
@@ -104,7 +113,12 @@ export const registerCommands = (context: vscode.ExtensionContext, configuration
104113
105114 // Handle macOS
106115 if ( platform === 'darwin' ) {
107- const packageId = versionPreference === VersionPreference . Stable ? 'dev-proxy' : 'dev-proxy-beta' ;
116+ const packageId = getPackageIdentifier ( versionPreference , PackageManager . Homebrew ) ;
117+ if ( ! packageId ) {
118+ openUpgradeDocumentation ( ) ;
119+ return ;
120+ }
121+
108122 const upgradeCommand = `brew upgrade ${ packageId } ` ;
109123 const isBeta = versionPreference === VersionPreference . Beta ;
110124
0 commit comments