This commit is contained in:
Sandeep Somavarapu
2018-12-03 15:51:12 +01:00
parent c2c2e48dd3
commit cbb9fa7385
2 changed files with 50 additions and 59 deletions

View File

@@ -7,6 +7,7 @@ import { localize } from 'vs/nls';
import product from 'vs/platform/node/product';
import pkg from 'vs/platform/node/package';
import * as path from 'path';
import * as semver from 'semver';
import { TPromise } from 'vs/base/common/winjs.base';
import { sequence } from 'vs/base/common/async';
@@ -35,10 +36,7 @@ import { StateService } from 'vs/platform/state/node/stateService';
import { createSpdLogService } from 'vs/platform/log/node/spdlogService';
import { ILogService, getLogLevel } from 'vs/platform/log/common/log';
import { isPromiseCanceledError } from 'vs/base/common/errors';
import { IDialogService } from 'vs/platform/dialogs/common/dialogs';
import { CommandLineDialogService } from 'vs/platform/dialogs/node/dialogService';
import { areSameExtensions, getGalleryExtensionIdFromLocal, adoptToGalleryExtensionId } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
import Severity from 'vs/base/common/severity';
import { areSameExtensions, getGalleryExtensionIdFromLocal, adoptToGalleryExtensionId, getGalleryExtensionId } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
import { URI } from 'vs/base/common/uri';
import { getManifest } from 'vs/platform/extensionManagement/node/extensionManagementUtil';
@@ -72,8 +70,7 @@ class Main {
constructor(
@IEnvironmentService private environmentService: IEnvironmentService,
@IExtensionManagementService private extensionManagementService: IExtensionManagementService,
@IExtensionGalleryService private extensionGalleryService: IExtensionGalleryService,
@IDialogService private dialogService: IDialogService
@IExtensionGalleryService private extensionGalleryService: IExtensionGalleryService
) { }
run(argv: ParsedArgs): TPromise<any> {
@@ -111,17 +108,22 @@ class Main {
.filter(e => /\.vsix$/i.test(e))
.map(id => () => {
const extension = path.isAbsolute(id) ? id : path.join(process.cwd(), id);
return this.extensionManagementService.install(URI.file(extension)).then(() => {
console.log(localize('successVsixInstall', "Extension '{0}' was successfully installed!", getBaseLabel(extension)));
}, error => {
if (isPromiseCanceledError(error)) {
console.log(localize('cancelVsixInstall', "Cancelled installing Extension '{0}'.", getBaseLabel(extension)));
return this.validate(extension, force)
.then(valid => {
if (valid) {
return this.extensionManagementService.install(URI.file(extension)).then(() => {
console.log(localize('successVsixInstall', "Extension '{0}' was successfully installed!", getBaseLabel(extension)));
}, error => {
if (isPromiseCanceledError(error)) {
console.log(localize('cancelVsixInstall', "Cancelled installing Extension '{0}'.", getBaseLabel(extension)));
return null;
} else {
return TPromise.wrapError(error);
}
});
}
return null;
} else {
return TPromise.wrapError(error);
}
});
});
});
const galleryTasks: Task[] = extensions
@@ -153,15 +155,8 @@ class Main {
console.log(localize('updateMessage', "Updating the Extension '{0}' to the version {1}", id, extension.version));
return this.installFromGallery(id, extension);
} else {
const updateMessage = localize('updateConfirmationMessage', "Extension '{0}' v{1} is already installed, but a newer version {2} is available in the marketplace. Would you like to update?", id, installedExtension.manifest.version, extension.version);
return this.dialogService.show(Severity.Info, updateMessage, [localize('yes', "Yes"), localize('no', "No")])
.then(option => {
if (option === 0) {
return this.installFromGallery(id, extension);
}
console.log(localize('cancelInstall', "Cancelled installing Extension '{0}'.", id));
return TPromise.as(null);
});
console.log(localize('forceUpdate', "Extension '{0}' v{1} is already installed, but a newer version {2} is available in the marketplace. Use '--force' option to update to newer version.", id, installedExtension.manifest.version, extension.version));
return Promise.resolve(null);
}
} else {
console.log(localize('alreadyInstalled', "Extension '{0}' is already installed.", version ? `${id}@${version}` : id));
@@ -178,6 +173,26 @@ class Main {
return sequence([...vsixTasks, ...galleryTasks]);
}
private validate(vsix: string, force: boolean): Thenable<boolean> {
return getManifest(vsix)
.then(manifest => {
if (manifest) {
const extensionIdentifier = { id: getGalleryExtensionId(manifest.publisher, manifest.name) };
return this.extensionManagementService.getInstalled(LocalExtensionType.User)
.then(installedExtensions => {
const newer = installedExtensions.filter(local => areSameExtensions(extensionIdentifier, { id: getGalleryExtensionIdFromLocal(local) }) && semver.gt(local.manifest.version, manifest.version))[0];
if (newer && !force) {
console.log(localize('forceDowngrade', "A newer version of this extension '{0}' v{1} is already installed. Use '--force' option to downgrade to older version.", newer.galleryIdentifier.id, newer.manifest.version, manifest.version));
return false;
}
return true;
});
} else {
return Promise.reject(new Error('Invalid vsix'));
}
});
}
private installFromGallery(id: string, extension: IGalleryExtension): TPromise<void> {
console.log(localize('installing', "Installing..."));
return this.extensionManagementService.installFromGallery(extension)
@@ -252,7 +267,6 @@ export function main(argv: ParsedArgs): TPromise<void> {
services.set(IRequestService, new SyncDescriptor(RequestService));
services.set(IExtensionManagementService, new SyncDescriptor(ExtensionManagementService));
services.set(IExtensionGalleryService, new SyncDescriptor(ExtensionGalleryService));
services.set(IDialogService, new SyncDescriptor(CommandLineDialogService));
const appenders: AppInsightsAppender[] = [];
if (isBuilt && !extensionDevelopmentLocationURI && !envService.args['disable-telemetry'] && product.enableTelemetry) {