Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adopt to web platform specifier #182072

Merged
merged 1 commit into from May 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -18,6 +18,7 @@ import { TelemetryLevel } from 'vs/platform/telemetry/common/telemetry';
import { getTelemetryLevel, supportsTelemetry } from 'vs/platform/telemetry/common/telemetryUtils';
import { RemoteAuthorities } from 'vs/base/common/network';
import { getRemoteServerRootPath } from 'vs/platform/remote/common/remoteHosts';
import { TargetPlatform } from 'vs/platform/extensions/common/extensions';

const WEB_EXTENSION_RESOURCE_END_POINT = 'web-extension-resource';

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

export function migratePlatformSpecificExtensionGalleryResourceURL(resource: URI, targetPlatform: TargetPlatform): URI | undefined {
if (resource.query !== `target=${targetPlatform}`) {
return undefined;
}
const paths = resource.path.split('/');
if (!paths[3]) {
return undefined;
}
paths[3] = `${paths[3]}+${targetPlatform}`;
return resource.with({ query: null, path: paths.join('/') });
}

export abstract class AbstractExtensionResourceLoaderService implements IExtensionResourceLoaderService {

Expand Down Expand Up @@ -72,15 +84,24 @@ export abstract class AbstractExtensionResourceLoaderService implements IExtensi
return this._extensionGalleryResourceUrlTemplate !== undefined;
}

public getExtensionGalleryResourceURL(galleryExtension: { publisher: string; name: string; version: string }, path?: string): URI | undefined {
public getExtensionGalleryResourceURL({ publisher, name, version, targetPlatform }: { publisher: string; name: string; version: string; targetPlatform?: TargetPlatform }, path?: string): URI | undefined {
if (this._extensionGalleryResourceUrlTemplate) {
const uri = URI.parse(format2(this._extensionGalleryResourceUrlTemplate, { publisher: galleryExtension.publisher, name: galleryExtension.name, version: galleryExtension.version, path: 'extension' }));
const uri = URI.parse(format2(this._extensionGalleryResourceUrlTemplate, {
publisher,
name,
version: targetPlatform !== undefined
&& targetPlatform !== TargetPlatform.UNDEFINED
&& targetPlatform !== TargetPlatform.UNKNOWN
&& targetPlatform !== TargetPlatform.UNIVERSAL
? `${version}+${targetPlatform}`
: version,
path: 'extension'
}));
return this._isWebExtensionResourceEndPoint(uri) ? uri.with({ scheme: RemoteAuthorities.getPreferredWebSchema() }) : uri;
}
return undefined;
}


public abstract readExtensionResource(uri: URI): Promise<string>;

protected isExtensionGalleryResource(uri: URI) {
Expand Down
Expand Up @@ -25,7 +25,7 @@ import { isString, isUndefined } from 'vs/base/common/types';
import { getErrorMessage } from 'vs/base/common/errors';
import { ResourceMap } from 'vs/base/common/map';
import { IExtensionManifestPropertiesService } from 'vs/workbench/services/extensions/common/extensionManifestPropertiesService';
import { IExtensionResourceLoaderService } from 'vs/platform/extensionResourceLoader/common/extensionResourceLoader';
import { IExtensionResourceLoaderService, migratePlatformSpecificExtensionGalleryResourceURL } from 'vs/platform/extensionResourceLoader/common/extensionResourceLoader';
import { Action2, registerAction2 } from 'vs/platform/actions/common/actions';
import { Categories } from 'vs/platform/action/common/actionCommonCategories';
import { IsWebContext } from 'vs/platform/contextkey/common/contextkeys';
Expand Down Expand Up @@ -559,11 +559,16 @@ export class WebExtensionsScannerService extends Disposable implements IWebExten
}

private async toWebExtensionFromGallery(galleryExtension: IGalleryExtension, metadata?: Metadata): Promise<IWebExtension> {
let extensionLocation = this.extensionResourceLoaderService.getExtensionGalleryResourceURL(galleryExtension, 'extension');
const extensionLocation = this.extensionResourceLoaderService.getExtensionGalleryResourceURL({
publisher: galleryExtension.publisher,
name: galleryExtension.name,
version: galleryExtension.version,
targetPlatform: galleryExtension.properties.targetPlatform === TargetPlatform.WEB ? TargetPlatform.WEB : undefined
}, 'extension');

if (!extensionLocation) {
throw new Error('No extension gallery service configured.');
}
extensionLocation = galleryExtension.properties.targetPlatform === TargetPlatform.WEB ? extensionLocation.with({ query: `${extensionLocation.query ? `${extensionLocation.query}&` : ''}target=${galleryExtension.properties.targetPlatform}` }) : extensionLocation;
const extensionResources = await this.listExtensionResources(extensionLocation);
const packageNLSResources = this.getPackageNLSResourceMapFromResources(extensionResources);

Expand Down Expand Up @@ -829,6 +834,11 @@ export class WebExtensionsScannerService extends Disposable implements IWebExten
webExtension.defaultManifestTranslations = null;
}
}
const migratedLocation = migratePlatformSpecificExtensionGalleryResourceURL(webExtension.location, TargetPlatform.WEB);
if (migratedLocation) {
update = true;
webExtension.location = migratedLocation;
}
return webExtension;
}));
if (update) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if one of the web extension promises throws? That means we will never reach this code. Should there be some sort of finally handling here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a try/catch for each promise to log the error.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right! I missed that.

Expand Down