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

Remove stale code & old migration #176828

Merged
merged 2 commits into from Mar 13, 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
10 changes: 1 addition & 9 deletions build/lib/extensions.js

Large diffs are not rendered by default.

9 changes: 0 additions & 9 deletions build/lib/extensions.ts
Expand Up @@ -416,7 +416,6 @@ export interface IScannedBuiltinExtension {
extensionPath: string;
packageJSON: any;
packageNLS?: any;
browserNlsMetadataPath?: string;
readmePath?: string;
changelogPath?: string;
}
Expand All @@ -441,21 +440,13 @@ export function scanBuiltinExtensions(extensionsRoot: string, exclude: string[]
const children = fs.readdirSync(path.join(extensionsRoot, extensionFolder));
const packageNLSPath = children.filter(child => child === 'package.nls.json')[0];
const packageNLS = packageNLSPath ? JSON.parse(fs.readFileSync(path.join(extensionsRoot, extensionFolder, packageNLSPath)).toString()) : undefined;
let browserNlsMetadataPath: string | undefined;
if (packageJSON.browser) {
const browserEntrypointFolderPath = path.join(extensionFolder, path.dirname(packageJSON.browser));
if (fs.existsSync(path.join(extensionsRoot, browserEntrypointFolderPath, 'nls.metadata.json'))) {
browserNlsMetadataPath = path.join(browserEntrypointFolderPath, 'nls.metadata.json');
}
}
const readme = children.filter(child => /^readme(\.txt|\.md|)$/i.test(child))[0];
const changelog = children.filter(child => /^changelog(\.txt|\.md|)$/i.test(child))[0];

scannedExtensions.push({
extensionPath: extensionFolder,
packageJSON,
packageNLS,
browserNlsMetadataPath,
readmePath: readme ? path.join(extensionFolder, readme) : undefined,
changelogPath: changelog ? path.join(extensionFolder, changelog) : undefined,
});
Expand Down
2 changes: 0 additions & 2 deletions src/vs/platform/extensions/common/extensions.ts
Expand Up @@ -321,7 +321,6 @@ export interface IExtension {
readonly changelogUrl?: URI;
readonly isValid: boolean;
readonly validations: readonly [Severity, string][];
readonly browserNlsBundleUris?: { [language: string]: URI };
}

/**
Expand Down Expand Up @@ -454,7 +453,6 @@ export interface IRelaxedExtensionDescription extends IRelaxedExtensionManifest
isUserBuiltin: boolean;
isUnderDevelopment: boolean;
extensionLocation: URI;
browserNlsBundleUris?: { [language: string]: URI };
}

export type IExtensionDescription = Readonly<IRelaxedExtensionDescription>;
Expand Down
10 changes: 1 addition & 9 deletions src/vs/workbench/api/common/extHostExtensionService.ts
Expand Up @@ -276,18 +276,10 @@ export abstract class AbstractExtHostExtensionService extends Disposable impleme

public async getExtension(extensionId: string): Promise<IExtensionDescription | undefined> {
const ext = await this._mainThreadExtensionsProxy.$getExtension(extensionId);
let browserNlsBundleUris: { [language: string]: URI } | undefined;
if (ext?.browserNlsBundleUris) {
browserNlsBundleUris = {};
for (const language of Object.keys(ext.browserNlsBundleUris)) {
browserNlsBundleUris[language] = URI.revive(ext.browserNlsBundleUris[language]);
}
}
return ext && {
...ext,
identifier: new ExtensionIdentifier(ext.identifier.value),
extensionLocation: URI.revive(ext.extensionLocation),
browserNlsBundleUris
extensionLocation: URI.revive(ext.extensionLocation)
};
}

Expand Down
5 changes: 0 additions & 5 deletions src/vs/workbench/api/common/extensionHostMain.ts
Expand Up @@ -184,11 +184,6 @@ export class ExtensionHostMain {
private static _transform(initData: IExtensionHostInitData, rpcProtocol: RPCProtocol): IExtensionHostInitData {
initData.allExtensions.forEach((ext) => {
(<Mutable<IRelaxedExtensionDescription>>ext).extensionLocation = URI.revive(rpcProtocol.transformIncomingURIs(ext.extensionLocation));
const browserNlsBundleUris: { [language: string]: URI } = {};
if (ext.browserNlsBundleUris) {
Object.keys(ext.browserNlsBundleUris).forEach(lang => browserNlsBundleUris[lang] = URI.revive(rpcProtocol.transformIncomingURIs(ext.browserNlsBundleUris![lang])));
(<Mutable<IRelaxedExtensionDescription>>ext).browserNlsBundleUris = browserNlsBundleUris;
}
});
initData.environment.appRoot = URI.revive(rpcProtocol.transformIncomingURIs(initData.environment.appRoot));
const extDevLocs = initData.environment.extensionDevelopmentLocationURI;
Expand Down
Expand Up @@ -20,7 +20,6 @@ interface IBundledExtension {
extensionPath: string;
packageJSON: IExtensionManifest;
packageNLS?: any;
browserNlsMetadataPath?: string;
readmePath?: string;
changelogPath?: string;
}
Expand Down Expand Up @@ -67,19 +66,11 @@ export class BuiltinExtensionsScannerService implements IBuiltinExtensionsScanne

this.builtinExtensionsPromises = bundledExtensions.map(async e => {
const id = getGalleryExtensionId(e.packageJSON.publisher, e.packageJSON.name);
const browserNlsBundleUris: { [language: string]: URI } = {};
if (e.browserNlsMetadataPath) {
if (this.nlsUrl) {
browserNlsBundleUris[Language.value()] = uriIdentityService.extUri.joinPath(this.nlsUrl, id, 'main');
}
browserNlsBundleUris.en = uriIdentityService.extUri.resolvePath(builtinExtensionsServiceUrl!, e.browserNlsMetadataPath);
}
return {
identifier: { id },
location: uriIdentityService.extUri.joinPath(builtinExtensionsServiceUrl!, e.extensionPath),
type: ExtensionType.System,
isBuiltin: true,
browserNlsBundleUris,
manifest: e.packageNLS ? await this.localizeManifest(id, e.packageJSON, e.packageNLS) : e.packageJSON,
readmeUrl: e.readmePath ? uriIdentityService.extUri.joinPath(builtinExtensionsServiceUrl!, e.readmePath) : undefined,
changelogUrl: e.changelogPath ? uriIdentityService.extUri.joinPath(builtinExtensionsServiceUrl!, e.changelogPath) : undefined,
Expand Down
Expand Up @@ -79,7 +79,6 @@ interface IWebExtension {
// deprecated in favor of packageNLSUris & fallbackPackageNLSUri
packageNLSUri?: URI;
packageNLSUris?: Map<string, URI>;
bundleNLSUris?: Map<string, URI>;
fallbackPackageNLSUri?: URI;
defaultManifestTranslations?: ITranslations | null;
metadata?: Metadata;
Expand Down Expand Up @@ -441,7 +440,7 @@ export class WebExtensionsScannerService extends Disposable implements IWebExten
}

async addExtension(location: URI, metadata: Metadata, profileLocation: URI): Promise<IScannedExtension> {
const webExtension = await this.toWebExtension(location, undefined, undefined, undefined, undefined, undefined, undefined, metadata);
const webExtension = await this.toWebExtension(location, undefined, undefined, undefined, undefined, undefined, metadata);
const extension = await this.toScannedExtension(webExtension, false);
await this.addToInstalledExtensions([webExtension], profileLocation);
return extension;
Expand Down Expand Up @@ -569,15 +568,13 @@ export class WebExtensionsScannerService extends Disposable implements IWebExten
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);
const bundleNLSResources = this.getBundleNLSResourceMapFromResources(extensionResources);

// The fallback, in English, will fill in any gaps missing in the localized file.
const fallbackPackageNLSResource = extensionResources.find(e => basename(e) === 'package.nls.json');
return this.toWebExtension(
extensionLocation,
galleryExtension.identifier,
packageNLSResources,
bundleNLSResources,
fallbackPackageNLSResource ? URI.parse(fallbackPackageNLSResource) : null,
galleryExtension.assets.readme ? URI.parse(galleryExtension.assets.readme.uri) : undefined,
galleryExtension.assets.changelog ? URI.parse(galleryExtension.assets.changelog.uri) : undefined,
Expand All @@ -596,22 +593,7 @@ export class WebExtensionsScannerService extends Disposable implements IWebExten
return packageNLSResources;
}

private getBundleNLSResourceMapFromResources(extensionResources: string[]): Map<string, URI> {
const bundleNLSResources = new Map<string, URI>();
extensionResources.forEach(e => {
// Grab all nls.bundle.{language}.json files
const regexResult = /nls\.bundle\.([\w-]+)\.json/.exec(basename(e));
if (regexResult?.[1]) {
bundleNLSResources.set(regexResult[1], URI.parse(e));
}
if (basename(e) === 'nls.metadata.json') {
bundleNLSResources.set('en', URI.parse(e));
}
});
return bundleNLSResources;
}

private async toWebExtension(extensionLocation: URI, identifier?: IExtensionIdentifier, packageNLSUris?: Map<string, URI>, bundleNLSUris?: Map<string, URI>, fallbackPackageNLSUri?: URI | null, readmeUri?: URI, changelogUri?: URI, metadata?: Metadata): Promise<IWebExtension> {
private async toWebExtension(extensionLocation: URI, identifier?: IExtensionIdentifier, packageNLSUris?: Map<string, URI>, fallbackPackageNLSUri?: URI | null, readmeUri?: URI, changelogUri?: URI, metadata?: Metadata): Promise<IWebExtension> {
let manifest: IExtensionManifest;
try {
manifest = await this.getExtensionManifest(extensionLocation);
Expand All @@ -633,21 +615,6 @@ export class WebExtensionsScannerService extends Disposable implements IWebExten
}
const defaultManifestTranslations: ITranslations | null | undefined = fallbackPackageNLSUri ? await this.getTranslations(fallbackPackageNLSUri) : null;

if (bundleNLSUris === undefined && manifest.browser) {
const englishStringsUri = joinPath(
this.uriIdentityService.extUri.dirname(joinPath(extensionLocation, manifest.browser)),
'nls.metadata.json'
);

try {
await this.extensionResourceLoaderService.readExtensionResource(englishStringsUri);
bundleNLSUris = new Map();
bundleNLSUris.set('en', englishStringsUri);
} catch (error) {
// noop if file doesn't exist
}
}

return {
identifier: { id: getGalleryExtensionId(manifest.publisher, manifest.name), uuid: identifier?.uuid },
version: manifest.version,
Expand All @@ -656,7 +623,6 @@ export class WebExtensionsScannerService extends Disposable implements IWebExten
readmeUri,
changelogUri,
packageNLSUris,
bundleNLSUris,
fallbackPackageNLSUri: fallbackPackageNLSUri ? fallbackPackageNLSUri : undefined,
defaultManifestTranslations,
metadata,
Expand Down Expand Up @@ -705,20 +671,12 @@ export class WebExtensionsScannerService extends Disposable implements IWebExten
}
}

const browserNlsBundleUris: { [language: string]: URI } = {};
if (webExtension.bundleNLSUris) {
for (const [language, uri] of webExtension.bundleNLSUris) {
browserNlsBundleUris[language] = uri;
}
}

return {
identifier: { id: webExtension.identifier.id, uuid: webExtension.identifier.uuid || uuid },
location: webExtension.location,
manifest,
type,
isBuiltin,
browserNlsBundleUris,
readmeUrl: webExtension.readmeUri,
changelogUrl: webExtension.changelogUri,
metadata: webExtension.metadata,
Expand Down Expand Up @@ -749,29 +707,6 @@ export class WebExtensionsScannerService extends Disposable implements IWebExten
return manifest;
}

// TODO: @TylerLeonhardt/@Sandy081: Delete after 6 months
private _migratePackageNLSUrisPromise: Promise<void> | undefined;
private migratePackageNLSUris(): Promise<void> {
if (!this._migratePackageNLSUrisPromise) {
this._migratePackageNLSUrisPromise = (async () => {
const webExtensions = await this.withWebExtensions(this.userDataProfilesService.defaultProfile.extensionsResource);
if (webExtensions.some(e => !e.packageNLSUris && e.packageNLSUri)) {
const migratedExtensions = await Promise.all(webExtensions.map(async e => {
if (!e.packageNLSUris && e.packageNLSUri) {
e.fallbackPackageNLSUri = e.packageNLSUri;
const extensionResources = await this.listExtensionResources(e.location);
e.packageNLSUris = this.getPackageNLSResourceMapFromResources(extensionResources);
e.packageNLSUri = undefined;
}
return e;
}));
await this.withWebExtensions(this.userDataProfilesService.defaultProfile.extensionsResource, () => migratedExtensions);
}
})();
}
return this._migratePackageNLSUrisPromise;
}

private async getExtensionManifest(location: URI): Promise<IExtensionManifest> {
const url = joinPath(location, 'package.json');
const content = await this.extensionResourceLoaderService.readExtensionResource(url);
Expand All @@ -789,9 +724,6 @@ export class WebExtensionsScannerService extends Disposable implements IWebExten
}

private async readInstalledExtensions(profileLocation: URI): Promise<IWebExtension[]> {
if (this.uriIdentityService.extUri.isEqual(profileLocation, this.userDataProfilesService.defaultProfile.extensionsResource)) {
await this.migratePackageNLSUris();
}
return this.withWebExtensions(profileLocation);
}

Expand Down
3 changes: 1 addition & 2 deletions src/vs/workbench/services/extensions/common/extensions.ts
Expand Up @@ -480,8 +480,7 @@ export function toExtensionDescription(extension: IExtension, isUnderDevelopment
extensionLocation: extension.location,
...extension.manifest,
uuid: extension.identifier.uuid,
targetPlatform: extension.targetPlatform,
browserNlsBundleUris: extension.browserNlsBundleUris
targetPlatform: extension.targetPlatform
};
}

Expand Down