import { IActionContext } from 'vscode-azureextensionui' ; import { funcPackageName , PackageManager } from '../constants' ; import { ext } from '../extensionVariables' ; import { FuncVersion } from '../FuncVersion' ; import { localize } from '../localize' ; import { cpUtils } from '../utils/cpUtils' ; import { nonNullValue } from '../utils/nonNull' ; import { getBrewPackageName , tryGetInstalledBrewPackageName } from './getBrewPackageName' ; import { getNpmDistTag , INpmDistTag } from './getNpmDistTag' ; export async function updateFuncCoreTools ( context , packageManager , version ) { ext . outputChannel . show ( ) ; switch ( packageManager ) { case PackageManager . npm : const distTag = await getNpmDistTag ( context , version ) ; await cpUtils . executeCommand ( ext . outputChannel , undefined , 'npm' , 'install' , '-g' , `${ funcPackageName }@${ distTag . tag }` ) ; break ; case PackageManager . brew : const brewPackageName = getBrewPackageName ( version ) ; const installedBrewPackageName = nonNullValue ( await tryGetInstalledBrewPackageName ( version ) , 'brewPackageName' ) ; if ( brewPackageName !== installedBrewPackageName ) { await cpUtils . executeCommand ( ext . outputChannel , undefined , 'brew' , 'uninstall' , installedBrewPackageName ) ; await cpUtils . executeCommand ( ext . outputChannel , undefined , 'brew' , 'install' , brewPackageName ) ; } else { await cpUtils . executeCommand ( ext . outputChannel , undefined , 'brew' , 'upgrade' , brewPackageName ) ; } break ; default : throw new RangeError ( localize ( 'invalidPackageManager' , 'Invalid package manager "{0}".' , packageManager ) ) ; } }