microsoft / microsoft/TypeScript
Plugin probe path starts in incorrect location?
@sheetalkamat 已经在做这个了。
开始于 2025年10月17日。
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.3k
- 平均合并
- 2 天 4 小时
- 30 天内合并 PR
- 132
描述
The code to determine the global plugin search path is I think incorrect?
It joins the executing file path which includes the typescript.js or tsserver.js filename, with the ../../.. string which results in a path like: X/node_modules/typescript/lib/tsserver.js/../../.. which means that the resultant path for this example is actually X/node_modules to which the resolve process appends a second node_modules folder resulting in looking for plugins in X/node_modules/node_modules so plugins never resolve.
protected getGlobalPluginSearchPaths(): string[] {
// Search any globally-specified probe paths, then our peer node_modules
return [
...this.projectService.pluginProbeLocations,
// ../../.. to walk from X/node_modules/typescript/lib/tsserver.js to X/node_modules/
combinePaths(this.projectService.getExecutingFilePath(), "../../.."),
];
}
https://github.com/microsoft/TypeScript/blob/main/src/server/project.ts#L2110
The actual resolve then happens here and the node_modules folder is appended:
public static importServicePluginSync<T = {}>(
pluginConfigEntry: PluginImport,
searchPaths: string[],
host: ServerHost,
log: (message: string) => void,
): PluginImportResult<T> {
Debug.assertIsDefined(host.require);
let errorLogs: string[] | undefined;
let resolvedModule: T | undefined;
for (const initialDir of searchPaths) {
const resolvedPath = normalizeSlashes(host.resolvePath(combinePaths(initialDir, "node_modules")));
log(`Loading ${pluginConfigEntry.name} from ${initialDir} (resolved to ${resolvedPath})`);
const result = host.require(resolvedPath, pluginConfigEntry.name); // TODO: GH#18217
if (!result.error) {
resolvedModule = result.module as T;
break;
}
const err = result.error.stack || result.error.message || JSON.stringify(result.error);
(errorLogs ??= []).push(`Failed to load module '${pluginConfigEntry.name}' from ${resolvedPath}: ${err}`);
}
return { pluginConfigEntry, resolvedModule, errorLogs };
}
https://github.com/microsoft/TypeScript/blob/main/src/server/project.ts#L500
I believe this may be the root cause of a number of different issues raised here:
https://github.com/microsoft/TypeScript/issues/61584
https://github.com/microsoft/TypeScript/issues/44289
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
评估
这个 Issue 还没有评估数据。