uninstall duplicate versions

fixes #9903
This commit is contained in:
Joao Moreno 2016-08-15 15:27:07 +02:00
parent 57fb7c95d5
commit 52c1ba498b
4 changed files with 21 additions and 21 deletions

View file

@ -125,19 +125,16 @@ class Main {
private uninstallExtension(ids: string[]): TPromise<any> {
return sequence(ids.map(id => () => {
return this.extensionManagementService.getInstalled(true).then(installed => {
const extensions = installed.filter(e => getId(e.manifest) === id);
return this.extensionManagementService.getInstalled().then(installed => {
const [extension] = installed.filter(e => getId(e.manifest) === id);
if (extensions.length === 0) {
if (!extension) {
return TPromise.wrapError(`${ notInstalled(id) }\n${ useId }`);
}
console.log(localize('uninstalling', "Uninstalling {0}...", id));
const promises = extensions
.map(extension => this.extensionManagementService.uninstall(extension));
return TPromise.join(promises)
return this.extensionManagementService.uninstall(extension)
.then(() => console.log(localize('successUninstall', "Extension '{0}' was successfully uninstalled!", id)));
});
}));

View file

@ -113,7 +113,7 @@ export interface IExtensionManagementService {
install(extension: IGalleryExtension): TPromise<void>;
install(zipPath: string): TPromise<void>;
uninstall(extension: ILocalExtension): TPromise<void>;
getInstalled(includeDuplicateVersions?: boolean): TPromise<ILocalExtension[]>;
getInstalled(): TPromise<ILocalExtension[]>;
}
export const IExtensionTipsService = createDecorator<IExtensionTipsService>('extensionTipsService');

View file

@ -17,7 +17,7 @@ export interface IExtensionManagementChannel extends IChannel {
call(command: 'event:onDidUninstallExtension'): TPromise<void>;
call(command: 'install', extensionOrPath: ILocalExtension | string): TPromise<ILocalExtension>;
call(command: 'uninstall', extension: ILocalExtension): TPromise<void>;
call(command: 'getInstalled', includeDuplicateVersions: boolean): TPromise<ILocalExtension[]>;
call(command: 'getInstalled'): TPromise<ILocalExtension[]>;
call(command: string, arg: any): TPromise<any>;
}
@ -33,7 +33,7 @@ export class ExtensionManagementChannel implements IExtensionManagementChannel {
case 'event:onDidUninstallExtension': return eventToCall(this.service.onDidUninstallExtension);
case 'install': return this.service.install(arg);
case 'uninstall': return this.service.uninstall(arg);
case 'getInstalled': return this.service.getInstalled(arg);
case 'getInstalled': return this.service.getInstalled();
}
}
}
@ -66,7 +66,7 @@ export class ExtensionManagementChannelClient implements IExtensionManagementSer
return this.channel.call('uninstall', extension);
}
getInstalled(includeDuplicateVersions?: boolean): TPromise<ILocalExtension[]> {
return this.channel.call('getInstalled', includeDuplicateVersions);
getInstalled(): TPromise<ILocalExtension[]> {
return this.channel.call('getInstalled');
}
}

View file

@ -203,7 +203,16 @@ export class ExtensionManagementService implements IExtensionManagementService {
}
uninstall(extension: ILocalExtension): TPromise<void> {
const id = extension.id;
return this.getAllInstalled().then<void>(installed => {
const promises = installed
.filter(e => e.manifest.publisher === extension.manifest.publisher && e.manifest.name === extension.manifest.name)
.map(({ id }) => this.uninstallExtension(id));
return TPromise.join(promises);
});
}
private uninstallExtension(id: string): TPromise<void> {
const extensionPath = path.join(this.extensionsPath, id);
return pfs.exists(extensionPath)
@ -215,14 +224,8 @@ export class ExtensionManagementService implements IExtensionManagementService {
.then(() => this._onDidUninstallExtension.fire(id));
}
getInstalled(includeDuplicateVersions: boolean = false): TPromise<ILocalExtension[]> {
const all = this.getAllInstalled();
if (includeDuplicateVersions) {
return all;
}
return all.then(extensions => {
getInstalled(): TPromise<ILocalExtension[]> {
return this.getAllInstalled().then(extensions => {
const byId = values(groupBy(extensions, p => `${ p.manifest.publisher }.${ p.manifest.name }`));
return byId.map(p => p.sort((a, b) => semver.rcompare(a.manifest.version, b.manifest.version))[0]);
});