66
77import type { CommandModule } from 'yargs' ;
88import {
9- updateExtensionByName ,
10- updateAllUpdatableExtensions ,
11- type ExtensionUpdateInfo ,
129 loadExtensions ,
1310 annotateActiveExtensions ,
14- checkForAllExtensionUpdates ,
1511} from '../../config/extension.js' ;
12+ import {
13+ updateAllUpdatableExtensions ,
14+ type ExtensionUpdateInfo ,
15+ checkForAllExtensionUpdates ,
16+ updateExtension ,
17+ } from '../../config/extensions/update.js' ;
18+ import { checkForExtensionUpdate } from '../../config/extensions/github.js' ;
1619import { getErrorMessage } from '../../utils/errors.js' ;
20+ import { ExtensionUpdateState } from '../../ui/state/extensions.js' ;
1721
1822interface UpdateArgs {
1923 name ?: string ;
@@ -37,7 +41,7 @@ export async function handleUpdate(args: UpdateArgs) {
3741 let updateInfos = await updateAllUpdatableExtensions (
3842 workingDir ,
3943 extensions ,
40- await checkForAllExtensionUpdates ( extensions , ( _ ) => { } ) ,
44+ await checkForAllExtensionUpdates ( extensions , new Map ( ) , ( _ ) => { } ) ,
4145 ( ) => { } ,
4246 ) ;
4347 updateInfos = updateInfos . filter (
@@ -54,13 +58,34 @@ export async function handleUpdate(args: UpdateArgs) {
5458 }
5559 if ( args . name )
5660 try {
61+ const extension = extensions . find (
62+ ( extension ) => extension . name === args . name ,
63+ ) ;
64+ if ( ! extension ) {
65+ console . log ( `Extension "${ args . name } " not found.` ) ;
66+ return ;
67+ }
68+ let updateState : ExtensionUpdateState | undefined ;
69+ if ( ! extension . installMetadata ) {
70+ console . log (
71+ `Unable to install extension "${ args . name } " due to missing install metadata` ,
72+ ) ;
73+ return ;
74+ }
75+ await checkForExtensionUpdate ( extension , ( newState ) => {
76+ updateState = newState ;
77+ } ) ;
78+ if ( updateState !== ExtensionUpdateState . UPDATE_AVAILABLE ) {
79+ console . log ( `Extension "${ args . name } " is already up to date.` ) ;
80+ return ;
81+ }
5782 // TODO(chrstnb): we should list extensions if the requested extension is not installed.
58- const updatedExtensionInfo = await updateExtensionByName (
59- args . name ,
83+ const updatedExtensionInfo = ( await updateExtension (
84+ extension ,
6085 workingDir ,
61- extensions ,
86+ updateState ,
6287 ( ) => { } ,
63- ) ;
88+ ) ) ! ;
6489 if (
6590 updatedExtensionInfo . originalVersion !==
6691 updatedExtensionInfo . updatedVersion
@@ -69,7 +94,7 @@ export async function handleUpdate(args: UpdateArgs) {
6994 `Extension "${ args . name } " successfully updated: ${ updatedExtensionInfo . originalVersion } → ${ updatedExtensionInfo . updatedVersion } .` ,
7095 ) ;
7196 } else {
72- console . log ( `Extension "${ args . name } " already up to date.` ) ;
97+ console . log ( `Extension "${ args . name } " is already up to date.` ) ;
7398 }
7499 } catch ( error ) {
75100 console . error ( getErrorMessage ( error ) ) ;
0 commit comments