Skip to content

Commit 7d3ecfa

Browse files
committed
fix: handle plugin method name conflicts with warning
1 parent bb31049 commit 7d3ecfa

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

packages/unplugin-devpilot/src/core/ws-server.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,13 @@ export function startWebSocketServer(port: number): WebSocketServer {
4242

4343
// Merge all plugin server methods
4444
const allPluginMethods: Record<string, (...args: any[]) => any> = {};
45-
for (const methods of Object.values(pluginServerMethods)) {
46-
Object.assign(allPluginMethods, methods);
45+
for (const [namespace, methods] of Object.entries(pluginServerMethods)) {
46+
for (const [name, fn] of Object.entries(methods)) {
47+
if (allPluginMethods[name]) {
48+
console.warn(`[unplugin-devpilot] Method "${name}" from plugin "${namespace}" conflicts with an existing method. The previous one will be overwritten.`);
49+
}
50+
allPluginMethods[name] = fn;
51+
}
4752
}
4853

4954
const serverFunctions: ServerFunctions = {

0 commit comments

Comments
 (0)