@@ -28,61 +28,54 @@ export namespace functionRuntimeUtils {
2828 this . properties . isActivationEvent = 'true' ;
2929 const settingKey : string = 'showCoreToolsWarning' ;
3030 if ( getFuncExtensionSetting < boolean > ( settingKey ) ) {
31- try {
32- const localVersion : string | null = await getLocalFunctionRuntimeVersion ( ) ;
33- if ( localVersion === null ) {
34- return ;
35- }
36- this . properties . localVersion = localVersion ;
37- const major : number = semver . major ( localVersion ) ;
38- const newestVersion : string | null = await getNewestFunctionRuntimeVersion ( major ) ;
39- if ( newestVersion === null ) {
40- return ;
41- }
31+ const localVersion : string | null = await getLocalFunctionRuntimeVersion ( ) ;
32+ if ( localVersion === null ) {
33+ return ;
34+ }
35+ this . properties . localVersion = localVersion ;
36+ const major : number = semver . major ( localVersion ) ;
37+ const newestVersion : string | undefined = await getNewestFunctionRuntimeVersion ( major , this ) ;
38+ if ( ! newestVersion ) {
39+ return ;
40+ }
4241
43- if ( semver . gt ( newestVersion , localVersion ) ) {
44- const packageManager : PackageManager | undefined = await getFuncPackageManager ( true /* isFuncInstalled */ ) ;
45- let message : string = localize (
46- 'azFunc.outdatedFunctionRuntime' ,
47- 'Update your Azure Functions Core Tools ({0}) to the latest ({1}) for the best experience.' ,
48- localVersion ,
49- newestVersion
50- ) ;
51- const v2 : string = localize ( 'v2BreakingChanges' , 'v2 is in preview and may have breaking changes (which are automatically applied to Azure).' ) ;
52- if ( major === FunctionRuntimeTag . core ) {
53- message += ` ${ v2 } ` ;
54- }
55- const update : vscode . MessageItem = { title : 'Update' } ;
56- let result : vscode . MessageItem ;
42+ if ( semver . gt ( newestVersion , localVersion ) ) {
43+ const packageManager : PackageManager | undefined = await getFuncPackageManager ( true /* isFuncInstalled */ ) ;
44+ let message : string = localize (
45+ 'azFunc.outdatedFunctionRuntime' ,
46+ 'Update your Azure Functions Core Tools ({0}) to the latest ({1}) for the best experience.' ,
47+ localVersion ,
48+ newestVersion
49+ ) ;
50+ const v2 : string = localize ( 'v2BreakingChanges' , 'v2 is in preview and may have breaking changes (which are automatically applied to Azure).' ) ;
51+ if ( major === FunctionRuntimeTag . core ) {
52+ message += ` ${ v2 } ` ;
53+ }
54+ const update : vscode . MessageItem = { title : 'Update' } ;
55+ let result : vscode . MessageItem ;
5756
58- do {
59- result = packageManager !== undefined ? await ext . ui . showWarningMessage ( message , update , DialogResponses . learnMore , DialogResponses . dontWarnAgain ) :
60- await ext . ui . showWarningMessage ( message , DialogResponses . learnMore , DialogResponses . dontWarnAgain ) ;
61- if ( result === DialogResponses . learnMore ) {
62- // tslint:disable-next-line:no-unsafe-any
63- opn ( 'https://aka.ms/azFuncOutdated' ) ;
64- } else if ( result === update ) {
65- switch ( major ) {
66- case FunctionRuntimeTag . latest :
67- // tslint:disable-next-line:no-non-null-assertion
68- await attemptToInstallLatestFunctionRuntime ( packageManager ! , 'v1' ) ;
69- case FunctionRuntimeTag . core :
70- // tslint:disable-next-line:no-non-null-assertion
71- await attemptToInstallLatestFunctionRuntime ( packageManager ! , 'v2' ) ;
72- default :
73- break ;
74- }
75- } else if ( result === DialogResponses . dontWarnAgain ) {
76- await updateGlobalSetting ( settingKey , false ) ;
57+ do {
58+ result = packageManager !== undefined ? await ext . ui . showWarningMessage ( message , update , DialogResponses . learnMore , DialogResponses . dontWarnAgain ) :
59+ await ext . ui . showWarningMessage ( message , DialogResponses . learnMore , DialogResponses . dontWarnAgain ) ;
60+ if ( result === DialogResponses . learnMore ) {
61+ // tslint:disable-next-line:no-unsafe-any
62+ opn ( 'https://aka.ms/azFuncOutdated' ) ;
63+ } else if ( result === update ) {
64+ switch ( major ) {
65+ case FunctionRuntimeTag . latest :
66+ // tslint:disable-next-line:no-non-null-assertion
67+ await attemptToInstallLatestFunctionRuntime ( packageManager ! , 'v1' ) ;
68+ case FunctionRuntimeTag . core :
69+ // tslint:disable-next-line:no-non-null-assertion
70+ await attemptToInstallLatestFunctionRuntime ( packageManager ! , 'v2' ) ;
71+ default :
72+ break ;
7773 }
74+ } else if ( result === DialogResponses . dontWarnAgain ) {
75+ await updateGlobalSetting ( settingKey , false ) ;
7876 }
79- while ( result === DialogResponses . learnMore ) ;
80- }
81- } catch ( error ) {
82- if ( ! parseError ( error ) . isUserCancelledError ) {
83- ext . outputChannel . appendLine ( `Error occurred when checking the version of 'Azure Functions Core Tools': ${ parseError ( error ) . message } ` ) ;
84- throw error ;
8577 }
78+ while ( result === DialogResponses . learnMore ) ;
8679 }
8780 }
8881 } ) ;
@@ -127,17 +120,22 @@ export namespace functionRuntimeUtils {
127120 return null ;
128121 }
129122
130- async function getNewestFunctionRuntimeVersion ( major : number ) : Promise < string | null > {
131- const npmRegistryUri : string = 'https://aka.ms/W2mvv3' ;
132- type distTags = { core : string , docker : string , latest : string } ;
133- const distTags : distTags = < distTags > JSON . parse ( ( await < Thenable < string > > request ( npmRegistryUri ) . promise ( ) ) ) ;
134- switch ( major ) {
135- case FunctionRuntimeTag . latest :
136- return distTags . latest ;
137- case FunctionRuntimeTag . core :
138- return distTags . core ;
139- default :
140- return null ;
123+ async function getNewestFunctionRuntimeVersion ( major : number , actionContext : IActionContext ) : Promise < string | undefined > {
124+ try {
125+ const npmRegistryUri : string = 'https://aka.ms/W2mvv3' ;
126+ type distTags = { core : string , docker : string , latest : string } ;
127+ const distTags : distTags = < distTags > JSON . parse ( ( await < Thenable < string > > request ( npmRegistryUri ) . promise ( ) ) ) ;
128+ switch ( major ) {
129+ case FunctionRuntimeTag . latest :
130+ return distTags . latest ;
131+ case FunctionRuntimeTag . core :
132+ return distTags . core ;
133+ default :
134+ }
135+ } catch ( error ) {
136+ actionContext . properties . latestRuntimeError = parseError ( error ) . message ;
141137 }
138+
139+ return undefined ;
142140 }
143141}
0 commit comments