Use service endpoint url for builtin extensions
This commit is contained in:
parent
919cf3630c
commit
f816c23b22
|
@ -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()
|
||||
|
|
|
@ -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 => <IScannedExtension>{
|
||||
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<IScannedExtension[]> {
|
||||
if (isWeb) {
|
||||
return this.builtinExtensions;
|
||||
}
|
||||
throw new Error('not supported');
|
||||
}
|
||||
}
|
|
@ -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 => <IScannedExtension>{
|
||||
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<IScannedExtension[]> {
|
||||
if (isWeb) {
|
||||
return this.builtinExtensions;
|
||||
}
|
||||
throw new Error('not supported');
|
||||
}
|
||||
}
|
||||
|
||||
registerSingleton(IBuiltinExtensionsScannerService, BuiltinExtensionsScannerService);
|
|
@ -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);
|
||||
|
|
|
@ -260,6 +260,11 @@ interface IWorkbenchConstructionOptions {
|
|||
*/
|
||||
readonly staticExtensions?: ReadonlyArray<IStaticExtension>;
|
||||
|
||||
/**
|
||||
* Service end-point hosting builtin extensions
|
||||
*/
|
||||
readonly builtinExtensionsServiceUrl?: string;
|
||||
|
||||
/**
|
||||
* Support for URL callbacks.
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue