Skip to content

Commit 1110f52

Browse files
authored
take manifest and translations in hosted extension (microsoft#183381)
* take manifest and translations in hosted extension * rename
1 parent 1c6825f commit 1110f52

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

src/vs/workbench/browser/web.api.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import type { IProgress, IProgressCompositeOptions, IProgressDialogOptions, IPro
1818
import type { ITextEditorOptions } from 'vs/platform/editor/common/editor';
1919
import type { EditorGroupLayout } from 'vs/workbench/services/editor/common/editorGroupsService';
2020
import type { IEmbedderTerminalOptions } from 'vs/workbench/services/terminal/common/embedderTerminalService';
21+
import { IExtensionManifest } from 'vs/platform/extensions/common/extensions';
22+
import { ITranslations } from 'vs/platform/extensionManagement/common/extensionNls';
2123

2224
/**
2325
* The `IWorkbench` interface is the API facade for web embedders
@@ -376,8 +378,9 @@ export type MarketplaceExtension = ExtensionId | { readonly id: ExtensionId; pre
376378
export interface HostedExtension {
377379
readonly location: UriComponents;
378380
readonly preRelease?: boolean;
381+
readonly packageJSON?: IExtensionManifest;
382+
readonly defaultPackageTranslations?: ITranslations | null;
379383
readonly packageNLSUris?: Map<string, UriComponents>;
380-
readonly fallbackPackageNLSUri?: UriComponents;
381384
readonly readmeUri?: UriComponents;
382385
readonly changelogUri?: UriComponents;
383386
}

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

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ type GalleryExtensionInfo = { readonly id: string; preRelease?: boolean; migrate
4848
interface HostedExtensionInfo {
4949
readonly location: UriComponents;
5050
readonly preRelease?: boolean;
51-
readonly packageNLSUris?: Map<string, UriComponents>;
52-
readonly fallbackPackageNLSUri?: UriComponents;
51+
readonly packageJSON?: IExtensionManifest;
52+
readonly defaultPackageTranslations?: ITranslations | null;
53+
readonly packagetNLSUris?: Map<string, UriComponents>;
5354
readonly readmeUri?: UriComponents;
5455
readonly changelogUri?: UriComponents;
5556
}
@@ -66,7 +67,8 @@ function isHostedExtensionInfo(obj: unknown): obj is HostedExtensionInfo {
6667
const hostedExtensionInfo = obj as HostedExtensionInfo | undefined;
6768
return isUriComponents(hostedExtensionInfo?.location)
6869
&& (hostedExtensionInfo?.preRelease === undefined || typeof hostedExtensionInfo.preRelease === 'boolean')
69-
&& (hostedExtensionInfo?.fallbackPackageNLSUri === undefined || isUriComponents(hostedExtensionInfo?.fallbackPackageNLSUri))
70+
&& (hostedExtensionInfo?.packageJSON === undefined || typeof hostedExtensionInfo.packageJSON === 'object')
71+
&& (hostedExtensionInfo?.defaultPackageTranslations === undefined || hostedExtensionInfo?.defaultPackageTranslations === null || typeof hostedExtensionInfo.defaultPackageTranslations === 'object')
7072
&& (hostedExtensionInfo?.changelogUri === undefined || isUriComponents(hostedExtensionInfo?.changelogUri))
7173
&& (hostedExtensionInfo?.readmeUri === undefined || isUriComponents(hostedExtensionInfo?.readmeUri));
7274
}
@@ -241,11 +243,12 @@ export class WebExtensionsScannerService extends Disposable implements IWebExten
241243
return [];
242244
}
243245
const result: IScannedExtension[] = [];
244-
await Promise.allSettled(extensionLocations.map(async ({ location, preRelease, packageNLSUris, fallbackPackageNLSUri, readmeUri, changelogUri }) => {
246+
await Promise.allSettled(extensionLocations.map(async ({ location, preRelease, packagetNLSUris, packageJSON, defaultPackageTranslations, readmeUri, changelogUri }) => {
245247
try {
246248
const webExtension = await this.toWebExtension(URI.revive(location), undefined,
247-
packageNLSUris ? [...packageNLSUris.entries()].reduce((result, [key, value]) => { result.set(key, URI.revive(value)); return result; }, new Map<string, URI>()) : undefined,
248-
URI.revive(fallbackPackageNLSUri),
249+
packageJSON,
250+
packagetNLSUris ? [...packagetNLSUris.entries()].reduce((result, [key, value]) => { result.set(key, URI.revive(value)); return result; }, new Map<string, URI>()) : undefined,
251+
defaultPackageTranslations,
249252
URI.revive(readmeUri),
250253
URI.revive(changelogUri),
251254
{ preRelease });
@@ -472,7 +475,7 @@ export class WebExtensionsScannerService extends Disposable implements IWebExten
472475
}
473476

474477
async addExtension(location: URI, metadata: Metadata, profileLocation: URI): Promise<IScannedExtension> {
475-
const webExtension = await this.toWebExtension(location, undefined, undefined, undefined, undefined, undefined, metadata);
478+
const webExtension = await this.toWebExtension(location, undefined, undefined, undefined, undefined, undefined, undefined, metadata);
476479
const extension = await this.toScannedExtension(webExtension, false);
477480
await this.addToInstalledExtensions([webExtension], profileLocation);
478481
return extension;
@@ -611,6 +614,7 @@ export class WebExtensionsScannerService extends Disposable implements IWebExten
611614
return this.toWebExtension(
612615
extensionLocation,
613616
galleryExtension.identifier,
617+
undefined,
614618
packageNLSResources,
615619
fallbackPackageNLSResource ? URI.parse(fallbackPackageNLSResource) : null,
616620
galleryExtension.assets.readme ? URI.parse(galleryExtension.assets.readme.uri) : undefined,
@@ -630,12 +634,13 @@ export class WebExtensionsScannerService extends Disposable implements IWebExten
630634
return packageNLSResources;
631635
}
632636

633-
private async toWebExtension(extensionLocation: URI, identifier?: IExtensionIdentifier, packageNLSUris?: Map<string, URI>, fallbackPackageNLSUri?: URI | null, readmeUri?: URI, changelogUri?: URI, metadata?: Metadata): Promise<IWebExtension> {
634-
let manifest: IExtensionManifest;
635-
try {
636-
manifest = await this.getExtensionManifest(extensionLocation);
637-
} catch (error) {
638-
throw new Error(`Error while fetching manifest from the location '${extensionLocation.toString()}'. ${getErrorMessage(error)}`);
637+
private async toWebExtension(extensionLocation: URI, identifier?: IExtensionIdentifier, manifest?: IExtensionManifest, packageNLSUris?: Map<string, URI>, fallbackPackageNLSUri?: URI | ITranslations | null, readmeUri?: URI, changelogUri?: URI, metadata?: Metadata): Promise<IWebExtension> {
638+
if (!manifest) {
639+
try {
640+
manifest = await this.getExtensionManifest(extensionLocation);
641+
} catch (error) {
642+
throw new Error(`Error while fetching manifest from the location '${extensionLocation.toString()}'. ${getErrorMessage(error)}`);
643+
}
639644
}
640645

641646
if (!this.extensionManifestPropertiesService.canExecuteOnWeb(manifest)) {
@@ -650,7 +655,7 @@ export class WebExtensionsScannerService extends Disposable implements IWebExten
650655
fallbackPackageNLSUri = undefined;
651656
}
652657
}
653-
const defaultManifestTranslations: ITranslations | null | undefined = fallbackPackageNLSUri ? await this.getTranslations(fallbackPackageNLSUri) : null;
658+
const defaultManifestTranslations: ITranslations | null | undefined = fallbackPackageNLSUri ? URI.isUri(fallbackPackageNLSUri) ? await this.getTranslations(fallbackPackageNLSUri) : fallbackPackageNLSUri : null;
654659

655660
return {
656661
identifier: { id: getGalleryExtensionId(manifest.publisher, manifest.name), uuid: identifier?.uuid },
@@ -660,7 +665,7 @@ export class WebExtensionsScannerService extends Disposable implements IWebExten
660665
readmeUri,
661666
changelogUri,
662667
packageNLSUris,
663-
fallbackPackageNLSUri: fallbackPackageNLSUri ? fallbackPackageNLSUri : undefined,
668+
fallbackPackageNLSUri: URI.isUri(fallbackPackageNLSUri) ? fallbackPackageNLSUri : undefined,
664669
defaultManifestTranslations,
665670
metadata,
666671
};

0 commit comments

Comments
 (0)