Skip to content

Commit adfff53

Browse files
committed
guard instlaling built in extensions in cli
1 parent e9aba23 commit adfff53

1 file changed

Lines changed: 26 additions & 5 deletions

File tree

src/vs/platform/extensionManagement/common/extensionManagementCLI.ts

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,11 @@ export class ExtensionManagementCLI {
182182
const { id, version, installOptions } = installExtensionInfo;
183183
const installedExtension = installed.find(i => areSameExtensions(i.identifier, { id }));
184184
if (installedExtension) {
185+
const builtinAutoUpdateMessage = this.validateBuiltinExtensionEnabledWithAutoUpdates(installedExtension);
186+
if (builtinAutoUpdateMessage) {
187+
this.logger.info(builtinAutoUpdateMessage);
188+
return false;
189+
}
185190
if (!force && (!version || (version === 'prerelease' && installedExtension.preRelease))) {
186191
this.logger.info(localize('alreadyInstalled-checkAndUpdate', "Extension '{0}' v{1} is already installed. Use '--force' option to update to latest version or provide '@<version>' to install a specific version, for example: '{2}@1.2.3'.", id, installedExtension.manifest.version, id));
187192
return false;
@@ -301,13 +306,22 @@ export class ExtensionManagementCLI {
301306
}
302307

303308
private async validateVSIX(manifest: IExtensionManifest, force: boolean, profileLocation: URI | undefined, installedExtensions: ILocalExtension[]): Promise<boolean> {
304-
if (!force) {
305-
const extensionIdentifier = { id: getGalleryExtensionId(manifest.publisher, manifest.name) };
306-
const newer = installedExtensions.find(local => areSameExtensions(extensionIdentifier, local.identifier) && gt(local.manifest.version, manifest.version));
307-
if (newer) {
308-
this.logger.info(localize('forceDowngrade', "A newer version of extension '{0}' v{1} is already installed. Use '--force' option to downgrade to older version.", newer.identifier.id, newer.manifest.version, manifest.version));
309+
const extensionIdentifier = { id: getGalleryExtensionId(manifest.publisher, manifest.name) };
310+
const existingExtension = installedExtensions.find(local => areSameExtensions(extensionIdentifier, local.identifier));
311+
312+
if (existingExtension) {
313+
const builtinAutoUpdateMessage = this.validateBuiltinExtensionEnabledWithAutoUpdates(existingExtension);
314+
if (builtinAutoUpdateMessage) {
315+
this.logger.info(builtinAutoUpdateMessage);
309316
return false;
310317
}
318+
319+
if (!force) {
320+
if (gt(existingExtension.manifest.version, manifest.version)) {
321+
this.logger.info(localize('forceDowngrade', "A newer version of extension '{0}' v{1} is already installed. Use '--force' option to downgrade to older version.", existingExtension.identifier.id, existingExtension.manifest.version, manifest.version));
322+
return false;
323+
}
324+
}
311325
}
312326

313327
return this.validateExtensionKind(manifest);
@@ -371,4 +385,11 @@ export class ExtensionManagementCLI {
371385
return this.location ? localize('notInstalleddOnLocation', "Extension '{0}' is not installed on {1}.", id, this.location) : localize('notInstalled', "Extension '{0}' is not installed.", id);
372386
}
373387

388+
private validateBuiltinExtensionEnabledWithAutoUpdates(extension: ILocalExtension): string | undefined {
389+
if (extension.isBuiltin && this.productService.builtInExtensionsEnabledWithAutoUpdates.some(e => e.toLowerCase() === extension.identifier.id.toLowerCase()) && !extension.forceAutoUpdate) {
390+
return localize('builtinAutoUpdate', "Extension '{0}' is a built-in extension and not allowed to be updated in the current product quality '{1}'.", extension.identifier.id, this.productService.quality);
391+
}
392+
return undefined;
393+
}
394+
374395
}

0 commit comments

Comments
 (0)