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:
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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";
|
||||
|
||||
Reference in New Issue
Block a user