fix(packages): resolve npm bin entrypoint detection (#567)

Fix npm/global bin entrypoint detection for CLI and MCP server by normalizing real entry paths, including symlinked invocations.
This commit is contained in:
Guoyu Su
2026-05-31 14:04:44 +08:00
committed by GitHub
parent 2face7394b
commit c58e85bec5
7 changed files with 127 additions and 4 deletions
+21
View File
@@ -0,0 +1,21 @@
import { realpathSync } from "node:fs";
import { normalize, resolve } from "node:path";
import { fileURLToPath } from "node:url";
export function isMainModule(moduleUrl: string, argvPath: string | undefined): boolean {
if (!argvPath) return false;
return normalizeEntryPath(fileURLToPath(moduleUrl)) === normalizeEntryPath(argvPath);
}
function normalizeEntryPath(path: string): string {
const normalized = normalize(realpathIfPossible(resolve(path)));
return process.platform === "win32" ? normalized.toLowerCase() : normalized;
}
function realpathIfPossible(path: string): string {
try {
return realpathSync.native(path);
} catch {
return path;
}
}
+1
View File
@@ -3,6 +3,7 @@ export * from "./bridge.js";
export * from "./connections.js";
export * from "./database.js";
export * from "./diagnostics.js";
export * from "./entrypoint.js";
export * from "./format.js";
export * from "./paths.js";
export * from "./schema-context.js";