fix: 释放 Windows 插件目录占用#419
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces logic to ensure that plugins are properly terminated before they are removed from the registry or the installed list. The review feedback suggests simplifying the path identification and list filtering logic in the development projects API for better readability. Additionally, it points out that a try-catch block in the plugins API is redundant because the underlying kill method already handles internal errors.
| const registryEntry = registry.projects[projectName] | ||
| const devEffectiveName = toDevPluginName(projectName) | ||
| const plugins = this.deps.readInstalledPlugins() | ||
| const installedDevPlugin = plugins.find( | ||
| (p) => p?.isDevelopment && p?.name === devEffectiveName | ||
| ) | ||
| const runningPluginPath = | ||
| typeof installedDevPlugin?.path === 'string' && installedDevPlugin.path | ||
| ? installedDevPlugin.path | ||
| : registryEntry.projectPath | ||
|
|
||
| if (typeof runningPluginPath === 'string' && runningPluginPath) { | ||
| this.deps.pluginManager?.killPlugin(runningPluginPath) | ||
| } | ||
|
|
||
| if (installedDevPlugin?.isDevelopment) { | ||
| this.deps.writeInstalledPlugins( | ||
| plugins.filter((p) => !(p?.isDevelopment && p?.name === devEffectiveName)) | ||
| ) | ||
| } |
There was a problem hiding this comment.
The logic for identifying the plugin path and removing it from the installed list can be simplified. Using the object reference returned by find for the filter operation is more efficient and readable. Additionally, the fallback logic for killPath can be expressed more concisely.
| const registryEntry = registry.projects[projectName] | |
| const devEffectiveName = toDevPluginName(projectName) | |
| const plugins = this.deps.readInstalledPlugins() | |
| const installedDevPlugin = plugins.find( | |
| (p) => p?.isDevelopment && p?.name === devEffectiveName | |
| ) | |
| const runningPluginPath = | |
| typeof installedDevPlugin?.path === 'string' && installedDevPlugin.path | |
| ? installedDevPlugin.path | |
| : registryEntry.projectPath | |
| if (typeof runningPluginPath === 'string' && runningPluginPath) { | |
| this.deps.pluginManager?.killPlugin(runningPluginPath) | |
| } | |
| if (installedDevPlugin?.isDevelopment) { | |
| this.deps.writeInstalledPlugins( | |
| plugins.filter((p) => !(p?.isDevelopment && p?.name === devEffectiveName)) | |
| ) | |
| } | |
| const registryEntry = registry.projects[projectName] | |
| const devEffectiveName = toDevPluginName(projectName) | |
| const plugins = this.deps.readInstalledPlugins() | |
| const installedDevPlugin = plugins.find( | |
| (p) => p?.isDevelopment && p?.name === devEffectiveName | |
| ) | |
| const killPath = installedDevPlugin?.path || registryEntry.projectPath | |
| if (killPath) { | |
| this.deps.pluginManager?.killPlugin(killPath) | |
| } | |
| if (installedDevPlugin) { | |
| this.deps.writeInstalledPlugins(plugins.filter((p) => p !== installedDevPlugin)) | |
| } |
There was a problem hiding this comment.
已收敛 killPath 分支,并补了针对性测试。这里保留按 isDevelopment + name 清理已安装列表,而不是只按对象引用删 1 条,因为删除开发项目时需要把同名开发态残留项一并清掉,避免脏数据下继续留下旧路径记录。
| try { | ||
| this.pluginManager?.killPlugin(pluginPath) | ||
| } catch (error) { | ||
| console.warn('[Plugins] failed to release running plugin before delete:', { | ||
| pluginPath, | ||
| error | ||
| }) | ||
| } |
There was a problem hiding this comment.
外层 ry/catch 已移除,删除前现在直接调用 his.pluginManager?.killPlugin(pluginPath)。另外补了删除路径上的回归测试。
There was a problem hiding this comment.
已去掉 deletePlugin 外层的 try/catch,删除前直接调用 pluginManager.killPlugin(pluginPath)。同时补了删除路径上的回归测试。
Summary