Skip to content

Commit de89c63

Browse files
authored
adopt to web platform specifier (microsoft#182072)
microsoft#180525 adopt to web platform specifier
1 parent 478551b commit de89c63

File tree

2 files changed

+38
-7
lines changed

2 files changed

+38
-7
lines changed

src/vs/platform/extensionResourceLoader/common/extensionResourceLoader.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { TelemetryLevel } from 'vs/platform/telemetry/common/telemetry';
1818
import { getTelemetryLevel, supportsTelemetry } from 'vs/platform/telemetry/common/telemetryUtils';
1919
import { RemoteAuthorities } from 'vs/base/common/network';
2020
import { getRemoteServerRootPath } from 'vs/platform/remote/common/remoteHosts';
21+
import { TargetPlatform } from 'vs/platform/extensions/common/extensions';
2122

2223
const WEB_EXTENSION_RESOURCE_END_POINT = 'web-extension-resource';
2324

@@ -42,9 +43,20 @@ export interface IExtensionResourceLoaderService {
4243
/**
4344
* Computes the URL of a extension gallery resource. Returns `undefined` if gallery does not provide extension resources.
4445
*/
45-
getExtensionGalleryResourceURL(galleryExtension: { publisher: string; name: string; version: string }, path?: string): URI | undefined;
46+
getExtensionGalleryResourceURL(galleryExtension: { publisher: string; name: string; version: string; targetPlatform?: TargetPlatform }, path?: string): URI | undefined;
4647
}
4748

49+
export function migratePlatformSpecificExtensionGalleryResourceURL(resource: URI, targetPlatform: TargetPlatform): URI | undefined {
50+
if (resource.query !== `target=${targetPlatform}`) {
51+
return undefined;
52+
}
53+
const paths = resource.path.split('/');
54+
if (!paths[3]) {
55+
return undefined;
56+
}
57+
paths[3] = `${paths[3]}+${targetPlatform}`;
58+
return resource.with({ query: null, path: paths.join('/') });
59+
}
4860

4961
export abstract class AbstractExtensionResourceLoaderService implements IExtensionResourceLoaderService {
5062

@@ -72,15 +84,24 @@ export abstract class AbstractExtensionResourceLoaderService implements IExtensi
7284
return this._extensionGalleryResourceUrlTemplate !== undefined;
7385
}
7486

75-
public getExtensionGalleryResourceURL(galleryExtension: { publisher: string; name: string; version: string }, path?: string): URI | undefined {
87+
public getExtensionGalleryResourceURL({ publisher, name, version, targetPlatform }: { publisher: string; name: string; version: string; targetPlatform?: TargetPlatform }, path?: string): URI | undefined {
7688
if (this._extensionGalleryResourceUrlTemplate) {
77-
const uri = URI.parse(format2(this._extensionGalleryResourceUrlTemplate, { publisher: galleryExtension.publisher, name: galleryExtension.name, version: galleryExtension.version, path: 'extension' }));
89+
const uri = URI.parse(format2(this._extensionGalleryResourceUrlTemplate, {
90+
publisher,
91+
name,
92+
version: targetPlatform !== undefined
93+
&& targetPlatform !== TargetPlatform.UNDEFINED
94+
&& targetPlatform !== TargetPlatform.UNKNOWN
95+
&& targetPlatform !== TargetPlatform.UNIVERSAL
96+
? `${version}+${targetPlatform}`
97+
: version,
98+
path: 'extension'
99+
}));
78100
return this._isWebExtensionResourceEndPoint(uri) ? uri.with({ scheme: RemoteAuthorities.getPreferredWebSchema() }) : uri;
79101
}
80102
return undefined;
81103
}
82104

83-
84105
public abstract readExtensionResource(uri: URI): Promise<string>;
85106

86107
protected isExtensionGalleryResource(uri: URI) {

src/vs/workbench/services/extensionManagement/browser/webExtensionsScannerService.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { isString, isUndefined } from 'vs/base/common/types';
2525
import { getErrorMessage } from 'vs/base/common/errors';
2626
import { ResourceMap } from 'vs/base/common/map';
2727
import { IExtensionManifestPropertiesService } from 'vs/workbench/services/extensions/common/extensionManifestPropertiesService';
28-
import { IExtensionResourceLoaderService } from 'vs/platform/extensionResourceLoader/common/extensionResourceLoader';
28+
import { IExtensionResourceLoaderService, migratePlatformSpecificExtensionGalleryResourceURL } from 'vs/platform/extensionResourceLoader/common/extensionResourceLoader';
2929
import { Action2, registerAction2 } from 'vs/platform/actions/common/actions';
3030
import { Categories } from 'vs/platform/action/common/actionCommonCategories';
3131
import { IsWebContext } from 'vs/platform/contextkey/common/contextkeys';
@@ -559,11 +559,16 @@ export class WebExtensionsScannerService extends Disposable implements IWebExten
559559
}
560560

561561
private async toWebExtensionFromGallery(galleryExtension: IGalleryExtension, metadata?: Metadata): Promise<IWebExtension> {
562-
let extensionLocation = this.extensionResourceLoaderService.getExtensionGalleryResourceURL(galleryExtension, 'extension');
562+
const extensionLocation = this.extensionResourceLoaderService.getExtensionGalleryResourceURL({
563+
publisher: galleryExtension.publisher,
564+
name: galleryExtension.name,
565+
version: galleryExtension.version,
566+
targetPlatform: galleryExtension.properties.targetPlatform === TargetPlatform.WEB ? TargetPlatform.WEB : undefined
567+
}, 'extension');
568+
563569
if (!extensionLocation) {
564570
throw new Error('No extension gallery service configured.');
565571
}
566-
extensionLocation = galleryExtension.properties.targetPlatform === TargetPlatform.WEB ? extensionLocation.with({ query: `${extensionLocation.query ? `${extensionLocation.query}&` : ''}target=${galleryExtension.properties.targetPlatform}` }) : extensionLocation;
567572
const extensionResources = await this.listExtensionResources(extensionLocation);
568573
const packageNLSResources = this.getPackageNLSResourceMapFromResources(extensionResources);
569574

@@ -829,6 +834,11 @@ export class WebExtensionsScannerService extends Disposable implements IWebExten
829834
webExtension.defaultManifestTranslations = null;
830835
}
831836
}
837+
const migratedLocation = migratePlatformSpecificExtensionGalleryResourceURL(webExtension.location, TargetPlatform.WEB);
838+
if (migratedLocation) {
839+
update = true;
840+
webExtension.location = migratedLocation;
841+
}
832842
return webExtension;
833843
}));
834844
if (update) {

0 commit comments

Comments
 (0)