mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-13 06:20:23 -06:00
Rename API to importPlugin (#50554)
* Rename API to importPlugin * Make it internal too
This commit is contained in:
parent
19defbfe57
commit
d293e723a2
@ -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);
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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>;
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,7 +29,7 @@ namespace ts.projectSystem {
|
||||
}
|
||||
}
|
||||
|
||||
function setup(logLevel: server.LogLevel | undefined, options?: Partial<server.StartSessionOptions>, importServicePlugin?: server.ServerHost["importServicePlugin"]) {
|
||||
function setup(logLevel: server.LogLevel | undefined, options?: Partial<server.StartSessionOptions>, importPlugin?: server.ServerHost["importPlugin"]) {
|
||||
const host = createServerHost([libFile], { windowsStyleRoot: "c:/" });
|
||||
const messages: any[] = [];
|
||||
const webHost: server.WebHost = {
|
||||
@ -38,7 +38,7 @@ namespace ts.projectSystem {
|
||||
writeMessage: s => messages.push(s),
|
||||
};
|
||||
const webSys = server.createWebSystem(webHost, emptyArray, () => host.getExecutingFilePath());
|
||||
webSys.importServicePlugin = importServicePlugin;
|
||||
webSys.importPlugin = importPlugin;
|
||||
const logger = logLevel !== undefined ? new server.MainProcessLogger(logLevel, webHost) : nullLogger();
|
||||
const session = new TestWorkerSession(webSys, webHost, { serverMode: LanguageServiceMode.PartialSemantic, ...options }, logger);
|
||||
return { getMessages: () => messages, clearMessages: () => messages.length = 0, session };
|
||||
@ -161,7 +161,7 @@ namespace ts.projectSystem {
|
||||
it("plugins are not loaded immediately", async () => {
|
||||
let pluginModuleInstantiated = false;
|
||||
let pluginInvoked = false;
|
||||
const importServicePlugin = async (_root: string, _moduleName: string): Promise<server.ModuleImportResult> => {
|
||||
const importPlugin = async (_root: string, _moduleName: string): Promise<server.ModuleImportResult> => {
|
||||
await Promise.resolve(); // simulate at least a single turn delay
|
||||
pluginModuleInstantiated = true;
|
||||
return {
|
||||
@ -173,7 +173,7 @@ namespace ts.projectSystem {
|
||||
};
|
||||
};
|
||||
|
||||
const { session } = setup(/*logLevel*/ undefined, { globalPlugins: ["plugin-a"] }, importServicePlugin);
|
||||
const { session } = setup(/*logLevel*/ undefined, { globalPlugins: ["plugin-a"] }, importPlugin);
|
||||
const projectService = session.getProjectService();
|
||||
|
||||
session.executeCommand({ seq: 1, type: "request", command: protocol.CommandTypes.Open, arguments: { file: "^memfs:/foo.ts", content: "" } });
|
||||
@ -201,7 +201,7 @@ namespace ts.projectSystem {
|
||||
const pluginADeferred = Utils.defer();
|
||||
const pluginBDeferred = Utils.defer();
|
||||
const log: string[] = [];
|
||||
const importServicePlugin = async (_root: string, moduleName: string): Promise<server.ModuleImportResult> => {
|
||||
const importPlugin = async (_root: string, moduleName: string): Promise<server.ModuleImportResult> => {
|
||||
log.push(`request import ${moduleName}`);
|
||||
const promise = moduleName === "plugin-a" ? pluginADeferred.promise : pluginBDeferred.promise;
|
||||
await promise;
|
||||
@ -215,7 +215,7 @@ namespace ts.projectSystem {
|
||||
};
|
||||
};
|
||||
|
||||
const { session } = setup(/*logLevel*/ undefined, { globalPlugins: ["plugin-a", "plugin-b"] }, importServicePlugin);
|
||||
const { session } = setup(/*logLevel*/ undefined, { globalPlugins: ["plugin-a", "plugin-b"] }, importPlugin);
|
||||
const projectService = session.getProjectService();
|
||||
|
||||
session.executeCommand({ seq: 1, type: "request", command: protocol.CommandTypes.Open, arguments: { file: "^memfs:/foo.ts", content: "" } });
|
||||
@ -241,7 +241,7 @@ namespace ts.projectSystem {
|
||||
});
|
||||
|
||||
it("sends projectsUpdatedInBackground event", async () => {
|
||||
const importServicePlugin = async (_root: string, _moduleName: string): Promise<server.ModuleImportResult> => {
|
||||
const importPlugin = async (_root: string, _moduleName: string): Promise<server.ModuleImportResult> => {
|
||||
await Promise.resolve(); // simulate at least a single turn delay
|
||||
return {
|
||||
module: (() => ({ create: info => info.languageService })) as server.PluginModuleFactory,
|
||||
@ -249,7 +249,7 @@ namespace ts.projectSystem {
|
||||
};
|
||||
};
|
||||
|
||||
const { session, getMessages } = setup(/*logLevel*/ undefined, { globalPlugins: ["plugin-a"] }, importServicePlugin);
|
||||
const { session, getMessages } = setup(/*logLevel*/ undefined, { globalPlugins: ["plugin-a"] }, importPlugin);
|
||||
const projectService = session.getProjectService();
|
||||
|
||||
session.executeCommand({ seq: 1, type: "request", command: protocol.CommandTypes.Open, arguments: { file: "^memfs:/foo.ts", content: "" } });
|
||||
@ -270,7 +270,7 @@ namespace ts.projectSystem {
|
||||
const pluginAShouldLoad = Utils.defer();
|
||||
const pluginAExternalFilesRequested = Utils.defer();
|
||||
|
||||
const importServicePlugin = async (_root: string, _moduleName: string): Promise<server.ModuleImportResult> => {
|
||||
const importPlugin = async (_root: string, _moduleName: string): Promise<server.ModuleImportResult> => {
|
||||
// wait until the initial external files are requested from the project service.
|
||||
await pluginAShouldLoad.promise;
|
||||
|
||||
@ -287,7 +287,7 @@ namespace ts.projectSystem {
|
||||
};
|
||||
};
|
||||
|
||||
const { session } = setup(/*logLevel*/ undefined, { globalPlugins: ["plugin-a"] }, importServicePlugin);
|
||||
const { session } = setup(/*logLevel*/ undefined, { globalPlugins: ["plugin-a"] }, importPlugin);
|
||||
const projectService = session.getProjectService();
|
||||
|
||||
session.executeCommand({ seq: 1, type: "request", command: protocol.CommandTypes.Open, arguments: { file: "^memfs:/foo.ts", content: "" } });
|
||||
@ -316,7 +316,7 @@ namespace ts.projectSystem {
|
||||
it("project is closed before plugins are loaded", async () => {
|
||||
const pluginALoaded = Utils.defer();
|
||||
const projectClosed = Utils.defer();
|
||||
const importServicePlugin = async (_root: string, _moduleName: string): Promise<server.ModuleImportResult> => {
|
||||
const importPlugin = async (_root: string, _moduleName: string): Promise<server.ModuleImportResult> => {
|
||||
// mark that the plugin has started loading
|
||||
pluginALoaded.resolve();
|
||||
|
||||
@ -328,7 +328,7 @@ namespace ts.projectSystem {
|
||||
};
|
||||
};
|
||||
|
||||
const { session, getMessages } = setup(/*logLevel*/ undefined, { globalPlugins: ["plugin-a"] }, importServicePlugin);
|
||||
const { session, getMessages } = setup(/*logLevel*/ undefined, { globalPlugins: ["plugin-a"] }, importPlugin);
|
||||
const projectService = session.getProjectService();
|
||||
|
||||
session.executeCommand({ seq: 1, type: "request", command: protocol.CommandTypes.Open, arguments: { file: "^memfs:/foo.ts", content: "" } });
|
||||
|
||||
@ -162,7 +162,7 @@ namespace ts.server {
|
||||
clearImmediate: handle => clearTimeout(handle),
|
||||
/* eslint-enable no-restricted-globals */
|
||||
|
||||
importServicePlugin: async (initialDir: string, moduleName: string): Promise<ModuleImportResult> => {
|
||||
importPlugin: async (initialDir: string, moduleName: string): Promise<ModuleImportResult> => {
|
||||
const packageRoot = combinePaths(initialDir, moduleName);
|
||||
|
||||
let packageJson: any | undefined;
|
||||
|
||||
@ -7044,7 +7044,6 @@ declare namespace ts.server {
|
||||
gc?(): void;
|
||||
trace?(s: string): void;
|
||||
require?(initialPath: string, moduleName: string): ModuleImportResult;
|
||||
importServicePlugin?(root: string, moduleName: string): Promise<ModuleImportResult>;
|
||||
}
|
||||
}
|
||||
declare namespace ts.server {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user