mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-02 01:25:39 -05:00
Integrate into vscode node module factory workflow (#6685)
* integrate into vscode node module factory workflow * add missing file * fix compile errors * fix compile errors * change uppercase * fix compile
This commit is contained in:
File diff suppressed because it is too large
Load Diff
85
src/sql/workbench/api/node/extHostRequireInterceptor.ts
Normal file
85
src/sql/workbench/api/node/extHostRequireInterceptor.ts
Normal file
@@ -0,0 +1,85 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { TernarySearchTree } from 'vs/base/common/map';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { nullExtensionDescription } from 'vs/workbench/services/extensions/common/extensions';
|
||||
import { ExtensionIdentifier, IExtensionDescription } from 'vs/platform/extensions/common/extensions';
|
||||
import { INodeModuleFactory } from 'vs/workbench/api/node/extHostRequireInterceptor';
|
||||
import * as azdata from 'azdata';
|
||||
import * as sqlops from 'sqlops';
|
||||
import { IAzdataExtensionApiFactory, ISqlopsExtensionApiFactory } from 'sql/workbench/api/common/sqlExtHost.api.impl';
|
||||
|
||||
export class AzdataNodeModuleFactory implements INodeModuleFactory {
|
||||
public readonly nodeModuleName = 'azdata';
|
||||
|
||||
private readonly _extApiImpl = new Map<string, typeof azdata>();
|
||||
private _defaultApiImpl: typeof azdata;
|
||||
|
||||
constructor(
|
||||
private readonly _apiFactory: IAzdataExtensionApiFactory,
|
||||
private readonly _extensionPaths: TernarySearchTree<IExtensionDescription>
|
||||
) {
|
||||
}
|
||||
|
||||
public load(request: string, parent: { filename: string; }): any {
|
||||
|
||||
// get extension id from filename and api for extension
|
||||
const ext = this._extensionPaths.findSubstr(URI.file(parent.filename).fsPath);
|
||||
if (ext) {
|
||||
let apiImpl = this._extApiImpl.get(ExtensionIdentifier.toKey(ext.identifier));
|
||||
if (!apiImpl) {
|
||||
apiImpl = this._apiFactory(ext);
|
||||
this._extApiImpl.set(ExtensionIdentifier.toKey(ext.identifier), apiImpl);
|
||||
}
|
||||
return apiImpl;
|
||||
}
|
||||
|
||||
// fall back to a default implementation
|
||||
if (!this._defaultApiImpl) {
|
||||
let extensionPathsPretty = '';
|
||||
this._extensionPaths.forEach((value, index) => extensionPathsPretty += `\t${index} -> ${value.identifier.value}\n`);
|
||||
console.warn(`Could not identify extension for 'azdata' require call from ${parent.filename}. These are the extension path mappings: \n${extensionPathsPretty}`);
|
||||
this._defaultApiImpl = this._apiFactory(nullExtensionDescription);
|
||||
}
|
||||
return this._defaultApiImpl;
|
||||
}
|
||||
}
|
||||
|
||||
export class SqlopsNodeModuleFactory implements INodeModuleFactory {
|
||||
public readonly nodeModuleName = 'sqlops';
|
||||
|
||||
private readonly _extApiImpl = new Map<string, typeof sqlops>();
|
||||
private _defaultApiImpl: typeof sqlops;
|
||||
|
||||
constructor(
|
||||
private readonly _apiFactory: ISqlopsExtensionApiFactory,
|
||||
private readonly _extensionPaths: TernarySearchTree<IExtensionDescription>
|
||||
) {
|
||||
}
|
||||
|
||||
public load(request: string, parent: { filename: string; }): any {
|
||||
|
||||
// get extension id from filename and api for extension
|
||||
const ext = this._extensionPaths.findSubstr(URI.file(parent.filename).fsPath);
|
||||
if (ext) {
|
||||
let apiImpl = this._extApiImpl.get(ExtensionIdentifier.toKey(ext.identifier));
|
||||
if (!apiImpl) {
|
||||
apiImpl = this._apiFactory(ext);
|
||||
this._extApiImpl.set(ExtensionIdentifier.toKey(ext.identifier), apiImpl);
|
||||
}
|
||||
return apiImpl;
|
||||
}
|
||||
|
||||
// fall back to a default implementation
|
||||
if (!this._defaultApiImpl) {
|
||||
let extensionPathsPretty = '';
|
||||
this._extensionPaths.forEach((value, index) => extensionPathsPretty += `\t${index} -> ${value.identifier.value}\n`);
|
||||
console.warn(`Could not identify extension for 'sqlops' require call from ${parent.filename}. These are the extension path mappings: \n${extensionPathsPretty}`);
|
||||
this._defaultApiImpl = this._apiFactory(nullExtensionDescription);
|
||||
}
|
||||
return this._defaultApiImpl;
|
||||
}
|
||||
}
|
||||
@@ -11,13 +11,16 @@ import { connectProxyResolver } from 'vs/workbench/services/extensions/node/prox
|
||||
import { AbstractExtHostExtensionService } from 'vs/workbench/api/common/extHostExtensionService';
|
||||
import { ExtHostDownloadService } from 'vs/workbench/api/node/extHostDownloadService';
|
||||
import { CLIServer } from 'vs/workbench/api/node/extHostCLIServer';
|
||||
import { initializeExtensionApi, createApiFactory } from 'sql/workbench/api/common/sqlExtHost.api.impl'; // {{SQL CARBON EDIT}} use our extension initalizer
|
||||
import { createAzdataApiFactory, createSqlopsApiFactory } from 'sql/workbench/api/common/sqlExtHost.api.impl'; // {{SQL CARBON EDIT}} use our extension initalizer
|
||||
import { AzdataNodeModuleFactory, SqlopsNodeModuleFactory } from 'sql/workbench/api/node/extHostRequireInterceptor'; // {{SQL CARBON EDIT}} use our extension initalizer
|
||||
|
||||
export class ExtHostExtensionService extends AbstractExtHostExtensionService {
|
||||
|
||||
protected async _beforeAlmostReadyToRunExtensions(): Promise<void> {
|
||||
// initialize API and register actors
|
||||
const extensionApiFactory = this._instaService.invokeFunction(createApiFactory);
|
||||
const extensionApiFactory = this._instaService.invokeFunction(createApiFactoryAndRegisterActors);
|
||||
const sqlopsExtensionApiFactory = this._instaService.invokeFunction(createSqlopsApiFactory); // {{SQL CARBON EDIT}} // add factory
|
||||
const azdataExtensionApiFactory = this._instaService.invokeFunction(createAzdataApiFactory); // {{SQL CARBON EDIT}} // add factory
|
||||
|
||||
// Register Download command
|
||||
this._instaService.createInstance(ExtHostDownloadService);
|
||||
@@ -31,9 +34,9 @@ export class ExtHostExtensionService extends AbstractExtHostExtensionService {
|
||||
// Module loading tricks
|
||||
const configProvider = await this._extHostConfiguration.getConfigProvider();
|
||||
const extensionPaths = await this.getExtensionPathIndex();
|
||||
// {{SQL CARBON EDIT}} - disable VSCodeNodeModuleFactory and use older initializeExtensionApi
|
||||
// NodeModuleRequireInterceptor.INSTANCE.register(new VSCodeNodeModuleFactory(this._extensionApiFactory, extensionPaths, this._registry, configProvider));
|
||||
await initializeExtensionApi(this, extensionApiFactory, this._registry, configProvider);
|
||||
NodeModuleRequireInterceptor.INSTANCE.register(new AzdataNodeModuleFactory(azdataExtensionApiFactory, extensionPaths)); // {{SQL CARBON EDIT}} // add node module
|
||||
NodeModuleRequireInterceptor.INSTANCE.register(new SqlopsNodeModuleFactory(sqlopsExtensionApiFactory, extensionPaths)); // {{SQL CARBON EDIT}} // add node module
|
||||
NodeModuleRequireInterceptor.INSTANCE.register(new VSCodeNodeModuleFactory(extensionApiFactory, extensionPaths, this._registry, configProvider));
|
||||
NodeModuleRequireInterceptor.INSTANCE.register(new KeytarNodeModuleFactory(this._extHostContext.getProxy(MainContext.MainThreadKeytar), this._initData.environment));
|
||||
if (this._initData.remote.isRemote) {
|
||||
NodeModuleRequireInterceptor.INSTANCE.register(new OpenNodeModuleFactory(
|
||||
|
||||
@@ -19,7 +19,7 @@ interface LoadFunction {
|
||||
(request: string, parent: { filename: string; }, isMain: any): any;
|
||||
}
|
||||
|
||||
interface INodeModuleFactory {
|
||||
export interface INodeModuleFactory { //{{SQL CARBON EDIT}} export interface
|
||||
readonly nodeModuleName: string | string[];
|
||||
load(request: string, parent: { filename: string; }, isMain: any, original: LoadFunction): any;
|
||||
alternaiveModuleName?(name: string): string | undefined;
|
||||
|
||||
Reference in New Issue
Block a user