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:
1 parent
2face7394b
commit
c58e85bec5
7 files changed
+127
-4
No files matched your search
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user