From f816c23b2259404e03fe191a12c4fd00d0903e79 Mon Sep 17 00:00:00 2001 From: Sandeep Somavarapu Date: Mon, 22 Jun 2020 15:36:09 +0200 Subject: [PATCH] Use service endpoint url for builtin extensions --- resources/serverless/code-web.js | 17 ++--- .../builtinExtensionsScannerService.ts | 44 ------------ .../builtinExtensionsScannerService.ts | 70 +++++++++++++++++++ src/vs/workbench/workbench.common.main.ts | 4 +- src/vs/workbench/workbench.web.api.ts | 5 ++ 5 files changed, 83 insertions(+), 57 deletions(-) delete mode 100644 src/vs/platform/extensions/browser/builtinExtensionsScannerService.ts create mode 100644 src/vs/workbench/services/extensionManagement/browser/builtinExtensionsScannerService.ts diff --git a/resources/serverless/code-web.js b/resources/serverless/code-web.js index 3f35bea7bc8..893844cf92d 100644 --- a/resources/serverless/code-web.js +++ b/resources/serverless/code-web.js @@ -61,10 +61,6 @@ const exists = (path) => util.promisify(fs.exists)(path); const readFile = (path) => util.promisify(fs.readFile)(path); const CharCode_PC = '%'.charCodeAt(0); -function toStaticExtensionUri(path) { - return { scheme: SCHEME, authority: AUTHORITY, path: `/static-extension/${path}` }; -} - async function initialize() { const builtinExtensions = []; const webpackConfigs = []; @@ -84,9 +80,9 @@ async function initialize() { } const readme = children.filter(child => /^readme(\.txt|\.md|)$/i.test(child))[0]; - const readmeUrl = readme ? toStaticExtensionUri(path.join(extensionPath, readme)) : undefined; + const readmePath = readme ? path.join(extensionPath, readme) : undefined; const changelog = children.filter(child => /^changelog(\.txt|\.md|)$/i.test(child))[0]; - const changelogUrl = changelog ? toStaticExtensionUri(path.join(extensionPath, changelog)) : undefined; + const changelogPath = changelog ? path.join(extensionPath, changelog) : undefined; const packageJSONPath = path.join(EXTENSIONS_ROOT, folderName, 'package.json'); if (await exists(packageJSONPath)) { @@ -122,11 +118,11 @@ async function initialize() { const packageNLSPath = path.join(folderName, 'package.nls.json'); const packageNLSExists = await exists(path.join(EXTENSIONS_ROOT, packageNLSPath)); builtinExtensions.push({ + extensionPath: folderName, packageJSON, - location: toStaticExtensionUri(folderName), - packageNLSUrl: packageNLSExists ? toStaticExtensionUri(packageNLSPath) : undefined, - readmeUrl, - changelogUrl + packageNLSPath: packageNLSExists ? packageNLSPath : undefined, + readmePath, + changelogPath }); } catch (e) { console.log(e); @@ -271,6 +267,7 @@ async function handleRoot(req, res) { folderUri: ghPath ? { scheme: 'github', authority: 'HEAD', path: ghPath } : { scheme: 'memfs', path: `/sample-folder` }, + builtinExtensionsServiceUrl: `${SCHEME}://${AUTHORITY}/static-extension` })); const data = (await util.promisify(fs.readFile)(WEB_MAIN)).toString() diff --git a/src/vs/platform/extensions/browser/builtinExtensionsScannerService.ts b/src/vs/platform/extensions/browser/builtinExtensionsScannerService.ts deleted file mode 100644 index 74a0c367750..00000000000 --- a/src/vs/platform/extensions/browser/builtinExtensionsScannerService.ts +++ /dev/null @@ -1,44 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -import { IBuiltinExtensionsScannerService, IScannedExtension, ExtensionType } from 'vs/platform/extensions/common/extensions'; -import { isWeb } from 'vs/base/common/platform'; -import { URI } from 'vs/base/common/uri'; - -export class BuiltinExtensionsScannerService implements IBuiltinExtensionsScannerService { - - declare readonly _serviceBrand: undefined; - - private readonly builtinExtensions: IScannedExtension[] = []; - - constructor( - ) { - if (isWeb) { - // Find builtin extensions by checking for DOM - const builtinExtensionsElement = document.getElementById('vscode-workbench-builtin-extensions'); - const builtinExtensionsElementAttribute = builtinExtensionsElement ? builtinExtensionsElement.getAttribute('data-settings') : undefined; - if (builtinExtensionsElementAttribute) { - try { - const builtinExtensions: IScannedExtension[] = JSON.parse(builtinExtensionsElementAttribute); - this.builtinExtensions = builtinExtensions.map(e => { - location: URI.revive(e.location), - type: ExtensionType.System, - packageJSON: e.packageJSON, - packageNLSUrl: URI.revive(e.packageNLSUrl), - readmeUrl: URI.revive(e.readmeUrl), - changelogUrl: URI.revive(e.changelogUrl), - }); - } catch (error) { /* ignore error*/ } - } - } - } - - async scanBuiltinExtensions(): Promise { - if (isWeb) { - return this.builtinExtensions; - } - throw new Error('not supported'); - } -} diff --git a/src/vs/workbench/services/extensionManagement/browser/builtinExtensionsScannerService.ts b/src/vs/workbench/services/extensionManagement/browser/builtinExtensionsScannerService.ts new file mode 100644 index 00000000000..161c9702395 --- /dev/null +++ b/src/vs/workbench/services/extensionManagement/browser/builtinExtensionsScannerService.ts @@ -0,0 +1,70 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import { IBuiltinExtensionsScannerService, IScannedExtension, ExtensionType } from 'vs/platform/extensions/common/extensions'; +import { isWeb } from 'vs/base/common/platform'; +import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService'; +import { IUriIdentityService } from 'vs/workbench/services/uriIdentity/common/uriIdentity'; +import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; +import { URI } from 'vs/base/common/uri'; + +interface IScannedBuiltinExtension { + extensionPath: string, + packageJSON: any, + packageNLSPath?: string, + readmePath?: string, + changelogPath?: string, +} + +export class BuiltinExtensionsScannerService implements IBuiltinExtensionsScannerService { + + declare readonly _serviceBrand: undefined; + + private readonly builtinExtensions: IScannedExtension[] = []; + + constructor( + @IWorkbenchEnvironmentService environmentService: IWorkbenchEnvironmentService, + @IUriIdentityService uriIdentityService: IUriIdentityService, + ) { + + const builtinExtensionsServiceUrl = environmentService.options?.builtinExtensionsServiceUrl ? URI.parse(environmentService.options?.builtinExtensionsServiceUrl) : undefined; + if (isWeb && builtinExtensionsServiceUrl) { + + let scannedBuiltinExtensions: IScannedBuiltinExtension[] = []; + + if (environmentService.isBuilt) { + // Built time configuration (do NOT modify) + scannedBuiltinExtensions = JSON.parse('{{BUILD->INSERT_BUILTIN_EXTENSIONS}}'); + } else { + // Find builtin extensions by checking for DOM + const builtinExtensionsElement = document.getElementById('vscode-workbench-builtin-extensions'); + const builtinExtensionsElementAttribute = builtinExtensionsElement ? builtinExtensionsElement.getAttribute('data-settings') : undefined; + if (builtinExtensionsElementAttribute) { + try { + scannedBuiltinExtensions = JSON.parse(builtinExtensionsElementAttribute); + } catch (error) { /* ignore error*/ } + } + } + + this.builtinExtensions = scannedBuiltinExtensions.map(e => { + location: uriIdentityService.extUri.joinPath(builtinExtensionsServiceUrl!, e.extensionPath), + type: ExtensionType.System, + packageJSON: e.packageJSON, + packageNLSUrl: e.packageNLSPath ? uriIdentityService.extUri.joinPath(builtinExtensionsServiceUrl!, e.packageNLSPath) : undefined, + readmeUrl: e.readmePath ? uriIdentityService.extUri.joinPath(builtinExtensionsServiceUrl!, e.readmePath) : undefined, + changelogUrl: e.changelogPath ? uriIdentityService.extUri.joinPath(builtinExtensionsServiceUrl!, e.changelogPath) : undefined, + }); + } + } + + async scanBuiltinExtensions(): Promise { + if (isWeb) { + return this.builtinExtensions; + } + throw new Error('not supported'); + } +} + +registerSingleton(IBuiltinExtensionsScannerService, BuiltinExtensionsScannerService); diff --git a/src/vs/workbench/workbench.common.main.ts b/src/vs/workbench/workbench.common.main.ts index 9b249fc1161..e353ad93ff1 100644 --- a/src/vs/workbench/workbench.common.main.ts +++ b/src/vs/workbench/workbench.common.main.ts @@ -75,6 +75,7 @@ import 'vs/workbench/services/themes/browser/workbenchThemeService'; import 'vs/workbench/services/label/common/labelService'; import 'vs/workbench/services/extensionManagement/common/webExtensionsScannerService'; import 'vs/workbench/services/extensionManagement/common/extensionEnablementService'; +import 'vs/workbench/services/extensionManagement/browser/builtinExtensionsScannerService'; import 'vs/workbench/services/notification/common/notificationService'; import 'vs/workbench/services/userDataSync/common/userDataSyncUtil'; import 'vs/workbench/services/remote/common/remoteExplorerService'; @@ -90,8 +91,6 @@ import 'vs/workbench/services/hover/browser/hoverService'; import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; import { ExtensionGalleryService } from 'vs/platform/extensionManagement/common/extensionGalleryService'; import { GlobalExtensionEnablementService } from 'vs/platform/extensionManagement/common/extensionEnablementService'; -import { IBuiltinExtensionsScannerService } from 'vs/platform/extensions/common/extensions'; -import { BuiltinExtensionsScannerService } from 'vs/platform/extensions/browser/builtinExtensionsScannerService'; import { IExtensionGalleryService, IGlobalExtensionEnablementService } from 'vs/platform/extensionManagement/common/extensionManagement'; import { ContextViewService } from 'vs/platform/contextview/browser/contextViewService'; import { IContextViewService } from 'vs/platform/contextview/browser/contextView'; @@ -117,7 +116,6 @@ import { IOpenerService } from 'vs/platform/opener/common/opener'; import { IUserDataSyncResourceEnablementService } from 'vs/platform/userDataSync/common/userDataSync'; import { UserDataSyncResourceEnablementService } from 'vs/platform/userDataSync/common/userDataSyncResourceEnablementService'; -registerSingleton(IBuiltinExtensionsScannerService, BuiltinExtensionsScannerService); registerSingleton(IUserDataSyncResourceEnablementService, UserDataSyncResourceEnablementService); registerSingleton(IGlobalExtensionEnablementService, GlobalExtensionEnablementService); registerSingleton(IExtensionGalleryService, ExtensionGalleryService, true); diff --git a/src/vs/workbench/workbench.web.api.ts b/src/vs/workbench/workbench.web.api.ts index e2be11afcc1..05124a2197b 100644 --- a/src/vs/workbench/workbench.web.api.ts +++ b/src/vs/workbench/workbench.web.api.ts @@ -260,6 +260,11 @@ interface IWorkbenchConstructionOptions { */ readonly staticExtensions?: ReadonlyArray; + /** + * Service end-point hosting builtin extensions + */ + readonly builtinExtensionsServiceUrl?: string; + /** * Support for URL callbacks. */