Rename API to importPlugin (#50554)

* Rename API to importPlugin

* Make it internal too
This commit is contained in:
Sheetal Nandi
2022-08-31 14:21:56 -07:00
committed by GitHub
parent 19defbfe57
commit d293e723a2
6 changed files with 22 additions and 23 deletions
+2 -2
View File
@@ -4068,7 +4068,7 @@ namespace ts.server {
/*@internal*/
requestEnablePlugin(project: Project, pluginConfigEntry: PluginImport, searchPaths: string[], pluginConfigOverrides: Map<any> | undefined) {
if (!this.host.importServicePlugin && !this.host.require) {
if (!this.host.importPlugin && !this.host.require) {
this.logger.info("Plugins were requested but not running in environment that supports 'require'. Nothing will be loaded");
return;
}
@@ -4080,7 +4080,7 @@ namespace ts.server {
}
// If the host supports dynamic import, begin enabling the plugin asynchronously.
if (this.host.importServicePlugin) {
if (this.host.importPlugin) {
const importPromise = project.beginEnablePluginAsync(pluginConfigEntry, searchPaths, pluginConfigOverrides);
this.pendingPluginEnablements ??= new Map();
let promises = this.pendingPluginEnablements.get(project);
+5 -6
View File
@@ -256,12 +256,12 @@ namespace ts.server {
/*@internal*/
public static async importServicePluginAsync(moduleName: string, initialDir: string, host: ServerHost, log: (message: string) => void, logErrors?: (message: string) => void): Promise<{} | undefined> {
Debug.assertIsDefined(host.importServicePlugin);
Debug.assertIsDefined(host.importPlugin);
const resolvedPath = combinePaths(initialDir, "node_modules");
log(`Dynamically importing ${moduleName} from ${initialDir} (resolved to ${resolvedPath})`);
let result: ModuleImportResult;
try {
result = await host.importServicePlugin(resolvedPath, moduleName);
result = await host.importPlugin(resolvedPath, moduleName);
}
catch (e) {
result = { module: undefined, error: e };
@@ -1607,7 +1607,7 @@ namespace ts.server {
protected enableGlobalPlugins(options: CompilerOptions, pluginConfigOverrides: Map<any> | undefined): void {
const host = this.projectService.host;
if (!host.require && !host.importServicePlugin) {
if (!host.require && !host.importPlugin) {
this.projectService.logger.info("Plugins were requested but not running in environment that supports 'require'. Nothing will be loaded");
return;
}
@@ -1658,7 +1658,7 @@ namespace ts.server {
*/
/*@internal*/
async beginEnablePluginAsync(pluginConfigEntry: PluginImport, searchPaths: string[], pluginConfigOverrides: Map<any> | undefined): Promise<BeginEnablePluginResult> {
Debug.assertIsDefined(this.projectService.host.importServicePlugin);
Debug.assertIsDefined(this.projectService.host.importPlugin);
let errorLogs: string[] | undefined;
const log = (message: string) => this.projectService.logger.info(message);
@@ -2522,8 +2522,7 @@ namespace ts.server {
/*@internal*/
enablePluginsWithOptions(options: CompilerOptions, pluginConfigOverrides: ESMap<string, any> | undefined): void {
const host = this.projectService.host;
if (!host.require && !host.importServicePlugin) {
if (!host.require && !host.importPlugin) {
this.projectService.logger.info("Plugins were requested but not running in environment that supports 'require'. Nothing will be loaded");
return;
}
+2 -1
View File
@@ -20,6 +20,7 @@ declare namespace ts.server {
gc?(): void;
trace?(s: string): void;
require?(initialPath: string, moduleName: string): ModuleImportResult;
importServicePlugin?(root: string, moduleName: string): Promise<ModuleImportResult>;
/*@internal*/
importPlugin?(root: string, moduleName: string): Promise<ModuleImportResult>;
}
}