Skip to content

Commit 0e5f4af

Browse files
committed
microsoft#66397 Use galleryIdentifier instead of identfier in ILocalExtension
1 parent 9031a4f commit 0e5f4af

14 files changed

Lines changed: 68 additions & 77 deletions

File tree

src/vs/code/node/cliProcessMain.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import { StateService } from 'vs/platform/state/node/stateService';
3535
import { createSpdLogService } from 'vs/platform/log/node/spdlogService';
3636
import { ILogService, getLogLevel } from 'vs/platform/log/common/log';
3737
import { isPromiseCanceledError } from 'vs/base/common/errors';
38-
import { areSameExtensions, getGalleryExtensionIdFromLocal, adoptToGalleryExtensionId, getGalleryExtensionId } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
38+
import { areSameExtensions, adoptToGalleryExtensionId, getGalleryExtensionId } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
3939
import { URI } from 'vs/base/common/uri';
4040
import { getManifest } from 'vs/platform/extensionManagement/node/extensionManagementUtil';
4141
import { IExtensionManifest, ExtensionType } from 'vs/platform/extensions/common/extensions';
@@ -153,7 +153,7 @@ class Main {
153153
return Promise.reject(new Error(`${notFound(version ? `${id}@${version}` : id)}\n${useId}`));
154154
}
155155

156-
const [installedExtension] = installed.filter(e => areSameExtensions({ id: getGalleryExtensionIdFromLocal(e) }, { id }));
156+
const [installedExtension] = installed.filter(e => areSameExtensions(e.galleryIdentifier, { id }));
157157
if (installedExtension) {
158158
if (extension.version !== installedExtension.manifest.version) {
159159
if (version || force) {
@@ -186,7 +186,7 @@ class Main {
186186

187187
const extensionIdentifier = { id: getGalleryExtensionId(manifest.publisher, manifest.name) };
188188
const installedExtensions = await this.extensionManagementService.getInstalled(ExtensionType.User);
189-
const newer = installedExtensions.filter(local => areSameExtensions(extensionIdentifier, { id: getGalleryExtensionIdFromLocal(local) }) && semver.gt(local.manifest.version, manifest.version))[0];
189+
const newer = installedExtensions.filter(local => areSameExtensions(extensionIdentifier, local.galleryIdentifier) && semver.gt(local.manifest.version, manifest.version))[0];
190190

191191
if (newer && !force) {
192192
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));
@@ -225,7 +225,7 @@ class Main {
225225
return sequence(extensions.map(extension => () => {
226226
return getExtensionId(extension).then(id => {
227227
return this.extensionManagementService.getInstalled(ExtensionType.User).then(installed => {
228-
const [extension] = installed.filter(e => areSameExtensions({ id: getGalleryExtensionIdFromLocal(e) }, { id }));
228+
const [extension] = installed.filter(e => areSameExtensions(e.galleryIdentifier, { id }));
229229

230230
if (!extension) {
231231
return Promise.reject(new Error(`${notInstalled(id)}\n${useId}`));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export interface IGalleryMetadata {
9191
}
9292

9393
export interface ILocalExtension extends IExtension {
94-
manifest: IExtensionManifest; /** TODO:@sandy081 - remove the readonly relaxment */
94+
readonly manifest: IExtensionManifest;
9595
metadata: IGalleryMetadata;
9696
readmeUrl: URI | null;
9797
changelogUrl: URI | null;

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ export function getGalleryExtensionId(publisher: string, name: string): string {
2525
return `${publisher.toLocaleLowerCase()}.${name.toLocaleLowerCase()}`;
2626
}
2727

28-
export function getGalleryExtensionIdFromLocal(local: ILocalExtension): string {
29-
return local.manifest ? getGalleryExtensionId(local.manifest.publisher, local.manifest.name) : local.identifier.id;
30-
}
31-
3228
export const LOCAL_EXTENSION_ID_REGEX = /^([^.]+\..+)-(\d+\.\d+\.\d+(-.*)?)$/;
3329

3430
export function getIdFromLocalExtensionId(localExtensionId: string): string {
@@ -74,7 +70,7 @@ export function groupByExtension<T>(extensions: T[], getExtensionIdentifier: (t:
7470

7571
export function getLocalExtensionTelemetryData(extension: ILocalExtension): any {
7672
return {
77-
id: getGalleryExtensionIdFromLocal(extension),
73+
id: extension.galleryIdentifier.id,
7874
name: extension.manifest.name,
7975
galleryId: null,
8076
publisherId: extension.metadata ? extension.metadata.publisherId : null,

src/vs/platform/extensionManagement/node/extensionManagementIpc.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,9 @@ function transformOutgoingURI(uri: URI, transformer: IURITransformer | null): UR
2121

2222
function transformIncomingExtension(extension: ILocalExtension, transformer: IURITransformer | null): ILocalExtension {
2323
transformer = transformer ? transformer : DefaultURITransformer;
24-
const manfiest = extension.manifest;
25-
delete extension.manifest;
26-
extension = transformAndReviveIncomingURIs(extension, transformer);
27-
extension.manifest = manfiest;
28-
return extension;
24+
const manifest = extension.manifest;
25+
const transformed = transformAndReviveIncomingURIs({ ...extension, ...{ manifest: undefined } }, transformer);
26+
return { ...transformed, ...{ manifest } };
2927
}
3028

3129
function transformOutgoingExtension(extension: ILocalExtension, transformer: IURITransformer | null): ILocalExtension {

src/vs/platform/extensionManagement/node/extensionManagementService.ts

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
INSTALL_ERROR_MALICIOUS,
2222
INSTALL_ERROR_INCOMPATIBLE
2323
} from 'vs/platform/extensionManagement/common/extensionManagement';
24-
import { getGalleryExtensionIdFromLocal, adoptToGalleryExtensionId, areSameExtensions, getGalleryExtensionId, groupByExtension, getMaliciousExtensionsSet, getLocalExtensionId, getGalleryExtensionTelemetryData, getLocalExtensionTelemetryData, getIdFromLocalExtensionId, getLocalExtensionIdFromManifest, getLocalExtensionIdFromGallery } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
24+
import { adoptToGalleryExtensionId, areSameExtensions, getGalleryExtensionId, groupByExtension, getMaliciousExtensionsSet, getLocalExtensionId, getGalleryExtensionTelemetryData, getLocalExtensionTelemetryData, getIdFromLocalExtensionId, getLocalExtensionIdFromManifest, getLocalExtensionIdFromGallery } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
2525
import { localizeManifest } from '../common/extensionNls';
2626
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
2727
import { Limiter, always, createCancelablePromise, CancelablePromise, Queue } from 'vs/base/common/async';
@@ -150,7 +150,7 @@ export class ExtensionManagementService extends Disposable implements IExtension
150150
}
151151

152152
zip(extension: ILocalExtension): Promise<URI> {
153-
this.logService.trace('ExtensionManagementService#zip', extension.identifier.id);
153+
this.logService.trace('ExtensionManagementService#zip', extension.galleryIdentifier.id);
154154
return this.collectFiles(extension)
155155
.then(files => zip(path.join(tmpdir(), generateUuid()), files))
156156
.then(path => URI.file(path));
@@ -204,7 +204,7 @@ export class ExtensionManagementService extends Disposable implements IExtension
204204
const extensionIdentifier = { id: getGalleryExtensionId(manifest.publisher, manifest.name) };
205205
return this.getInstalled(ExtensionType.User)
206206
.then(installedExtensions => {
207-
const newer = installedExtensions.filter(local => areSameExtensions(extensionIdentifier, { id: getGalleryExtensionIdFromLocal(local) }) && semver.gt(local.manifest.version, manifest.version))[0];
207+
const newer = installedExtensions.filter(local => areSameExtensions(extensionIdentifier, local.galleryIdentifier) && semver.gt(local.manifest.version, manifest.version))[0];
208208
return newer ? this.uninstall(newer, true) : undefined;
209209
})
210210
.then(() => {
@@ -349,7 +349,7 @@ export class ExtensionManagementService extends Disposable implements IExtension
349349
}
350350

351351
reinstallFromGallery(extension: ILocalExtension): Promise<void> {
352-
this.logService.trace('ExtensionManagementService#reinstallFromGallery', extension.identifier.id);
352+
this.logService.trace('ExtensionManagementService#reinstallFromGallery', extension.galleryIdentifier.id);
353353
if (!this.galleryService.isEnabled()) {
354354
return Promise.reject(new Error(nls.localize('MarketPlaceDisabled', "Marketplace is not enabled")));
355355
}
@@ -367,7 +367,7 @@ export class ExtensionManagementService extends Disposable implements IExtension
367367
}
368368

369369
private getOperation(extensionToInstall: IExtensionIdentifier, installed: ILocalExtension[]): InstallOperation {
370-
return installed.some(i => areSameExtensions({ id: getGalleryExtensionIdFromLocal(i), uuid: i.identifier.uuid }, extensionToInstall)) ? InstallOperation.Update : InstallOperation.Install;
370+
return installed.some(i => areSameExtensions(i.galleryIdentifier, extensionToInstall)) ? InstallOperation.Update : InstallOperation.Install;
371371
}
372372

373373
private getTelemetryEvent(operation: InstallOperation): string {
@@ -530,7 +530,7 @@ export class ExtensionManagementService extends Disposable implements IExtension
530530
}
531531

532532
uninstall(extension: ILocalExtension, force = false): Promise<void> {
533-
this.logService.trace('ExtensionManagementService#uninstall', extension.identifier.id);
533+
this.logService.trace('ExtensionManagementService#uninstall', extension.galleryIdentifier.id);
534534
return this.toNonCancellablePromise(this.getInstalled(ExtensionType.User)
535535
.then(installed => {
536536
const extensionsToUninstall = installed
@@ -545,7 +545,7 @@ export class ExtensionManagementService extends Disposable implements IExtension
545545
}
546546

547547
updateMetadata(local: ILocalExtension, metadata: IGalleryMetadata): Promise<ILocalExtension> {
548-
this.logService.trace('ExtensionManagementService#updateMetadata', local.identifier.id);
548+
this.logService.trace('ExtensionManagementService#updateMetadata', local.galleryIdentifier.id);
549549
local.metadata = metadata;
550550
return this.saveMetadataForLocalExtension(local)
551551
.then(localExtension => {
@@ -572,11 +572,11 @@ export class ExtensionManagementService extends Disposable implements IExtension
572572
}
573573

574574
private findGalleryExtension(local: ILocalExtension): Promise<IGalleryExtension> {
575-
if (local.identifier.uuid) {
576-
return this.findGalleryExtensionById(local.identifier.uuid)
577-
.then(galleryExtension => galleryExtension ? galleryExtension : this.findGalleryExtensionByName(getGalleryExtensionIdFromLocal(local)));
575+
if (local.galleryIdentifier.uuid) {
576+
return this.findGalleryExtensionById(local.galleryIdentifier.uuid)
577+
.then(galleryExtension => galleryExtension ? galleryExtension : this.findGalleryExtensionByName(local.galleryIdentifier.id));
578578
}
579-
return this.findGalleryExtensionByName(getGalleryExtensionIdFromLocal(local));
579+
return this.findGalleryExtensionByName(local.galleryIdentifier.id);
580580
}
581581

582582
private findGalleryExtensionById(uuid: string): Promise<IGalleryExtension> {
@@ -672,31 +672,30 @@ export class ExtensionManagementService extends Disposable implements IExtension
672672
return Promise.resolve(pfs.exists(extension.location.fsPath))
673673
.then(exists => exists ? null : Promise.reject(new Error(nls.localize('notExists', "Could not find extension"))))
674674
.then(() => {
675-
this.logService.info('Uninstalling extension:', extension.identifier.id);
675+
this.logService.info('Uninstalling extension:', extension.galleryIdentifier.id);
676676
this._onUninstallExtension.fire(extension.identifier);
677677
});
678678
}
679679

680680
private uninstallExtension(local: ILocalExtension): Promise<void> {
681-
const id = getGalleryExtensionIdFromLocal(local);
682-
let promise = this.uninstallingExtensions.get(id);
681+
let promise = this.uninstallingExtensions.get(local.galleryIdentifier.id);
683682
if (!promise) {
684683
// Set all versions of the extension as uninstalled
685684
promise = createCancelablePromise(token => this.scanUserExtensions(false)
686-
.then(userExtensions => this.setUninstalled(...userExtensions.filter(u => areSameExtensions({ id: getGalleryExtensionIdFromLocal(u), uuid: u.identifier.uuid }, { id, uuid: local.identifier.uuid }))))
687-
.then(() => { this.uninstallingExtensions.delete(id); }));
688-
this.uninstallingExtensions.set(id, promise);
685+
.then(userExtensions => this.setUninstalled(...userExtensions.filter(u => areSameExtensions(u.galleryIdentifier, local.galleryIdentifier))))
686+
.then(() => { this.uninstallingExtensions.delete(local.galleryIdentifier.id); }));
687+
this.uninstallingExtensions.set(local.galleryIdentifier.id, promise);
689688
}
690689
return promise;
691690
}
692691

693692
private async postUninstallExtension(extension: ILocalExtension, error?: Error): Promise<void> {
694693
if (error) {
695-
this.logService.error('Failed to uninstall extension:', extension.identifier.id, error.message);
694+
this.logService.error('Failed to uninstall extension:', extension.galleryIdentifier.id, error.message);
696695
} else {
697-
this.logService.info('Successfully uninstalled extension:', extension.identifier.id);
696+
this.logService.info('Successfully uninstalled extension:', extension.galleryIdentifier.id);
698697
// only report if extension has a mapped gallery extension. UUID identifies the gallery extension.
699-
if (extension.identifier.uuid) {
698+
if (extension.galleryIdentifier.uuid) {
700699
await this.galleryService.reportStatistic(extension.manifest.publisher, extension.manifest.name, extension.manifest.version, StatisticType.Uninstall);
701700
}
702701
}
@@ -753,7 +752,7 @@ export class ExtensionManagementService extends Disposable implements IExtension
753752
.then(([uninstalled, extensions]) => {
754753
extensions = extensions.filter(e => !uninstalled[e.identifier.id]);
755754
if (excludeOutdated) {
756-
const byExtension: ILocalExtension[][] = groupByExtension(extensions, e => ({ id: getGalleryExtensionIdFromLocal(e), uuid: e.identifier.uuid }));
755+
const byExtension: ILocalExtension[][] = groupByExtension(extensions, e => e.galleryIdentifier);
757756
extensions = byExtension.map(p => p.sort((a, b) => semver.rcompare(a.manifest.version, b.manifest.version))[0]);
758757
}
759758
this.logService.info('Scanned user extensions:', extensions.length);
@@ -808,7 +807,7 @@ export class ExtensionManagementService extends Disposable implements IExtension
808807
const toRemove: ILocalExtension[] = [];
809808

810809
// Outdated extensions
811-
const byExtension: ILocalExtension[][] = groupByExtension(extensions, e => ({ id: getGalleryExtensionIdFromLocal(e), uuid: e.identifier.uuid }));
810+
const byExtension: ILocalExtension[][] = groupByExtension(extensions, e => e.galleryIdentifier);
812811
toRemove.push(...flatten(byExtension.map(p => p.sort((a, b) => semver.rcompare(a.manifest.version, b.manifest.version)).slice(1))));
813812

814813
return Promise.all(toRemove.map(extension => this.removeExtension(extension, 'outdated')));
@@ -822,8 +821,8 @@ export class ExtensionManagementService extends Disposable implements IExtension
822821
}
823822

824823
private removeExtension(extension: ILocalExtension, type: string): Promise<void> {
825-
this.logService.trace(`Deleting ${type} extension from disk`, extension.identifier.id);
826-
return pfs.rimraf(extension.location.fsPath).then(() => this.logService.info('Deleted from disk', extension.identifier.id));
824+
this.logService.trace(`Deleting ${type} extension from disk`, extension.galleryIdentifier.id, extension.location.fsPath);
825+
return pfs.rimraf(extension.location.fsPath).then(() => this.logService.info('Deleted from disk', extension.galleryIdentifier.id, extension.location.fsPath));
827826
}
828827

829828
private isUninstalled(id: string): Promise<boolean> {

src/vs/platform/localizations/node/localizations.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { IExtensionManagementService, ILocalExtension, IExtensionIdentifier } fr
99
import { Disposable } from 'vs/base/common/lifecycle';
1010
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
1111
import { Queue } from 'vs/base/common/async';
12-
import { areSameExtensions, getGalleryExtensionIdFromLocal, getIdFromLocalExtensionId } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
12+
import { areSameExtensions, getIdFromLocalExtensionId } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
1313
import { ILogService } from 'vs/platform/log/common/log';
1414
import { isValidLocalization, ILocalizationsService, LanguageType } from 'vs/platform/localizations/common/localizations';
1515
import product from 'vs/platform/node/product';
@@ -68,7 +68,7 @@ export class LocalizationsService extends Disposable implements ILocalizationsSe
6868

6969
private onDidInstallExtension(extension: ILocalExtension | undefined): void {
7070
if (extension && extension.manifest && extension.manifest.contributes && extension.manifest.contributes.localizations && extension.manifest.contributes.localizations.length) {
71-
this.logService.debug('Adding language packs from the extension', extension.identifier.id);
71+
this.logService.debug('Adding language packs from the extension', extension.galleryIdentifier.id);
7272
this.update();
7373
}
7474
}
@@ -136,7 +136,7 @@ class LanguagePacksCache extends Disposable {
136136
}
137137

138138
private createLanguagePacksFromExtension(languagePacks: { [language: string]: ILanguagePack }, extension: ILocalExtension): void {
139-
const extensionIdentifier = { id: getGalleryExtensionIdFromLocal(extension), uuid: extension.identifier.uuid };
139+
const extensionIdentifier = extension.galleryIdentifier;
140140
const localizations = extension.manifest.contributes && extension.manifest.contributes.localizations ? extension.manifest.contributes.localizations : [];
141141
for (const localizationContribution of localizations) {
142142
if (extension.location.scheme === Schemas.file && isValidLocalization(localizationContribution)) {

src/vs/workbench/parts/extensions/electron-browser/extensionTipsService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import { INotificationService } from 'vs/platform/notification/common/notificati
4040
import { Emitter, Event } from 'vs/base/common/event';
4141
import { assign } from 'vs/base/common/objects';
4242
import { URI } from 'vs/base/common/uri';
43-
import { areSameExtensions, getGalleryExtensionIdFromLocal } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
43+
import { areSameExtensions } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
4444
import { IExperimentService, ExperimentActionType, ExperimentState } from 'vs/workbench/parts/experiments/node/experimentService';
4545
import { CancellationToken } from 'vs/base/common/cancellation';
4646
import { getKeywordsForExtension } from 'vs/workbench/parts/extensions/electron-browser/extensionsUtils';
@@ -421,7 +421,7 @@ export class ExtensionTipsService extends Disposable implements IExtensionTipsSe
421421
}
422422

423423
this.extensionsService.getInstalled(ExtensionType.User).then(local => {
424-
const recommendations = filteredRecs.filter(({ extensionId }) => local.every(local => !areSameExtensions({ id: extensionId }, { id: getGalleryExtensionIdFromLocal(local) })));
424+
const recommendations = filteredRecs.filter(({ extensionId }) => local.every(local => !areSameExtensions({ id: extensionId }, local.galleryIdentifier)));
425425

426426
if (!recommendations.length) {
427427
return Promise.resolve(undefined);

0 commit comments

Comments
 (0)