Files
dbx/packages/node-core/src/entrypoint.ts
T
Guoyu Su c58e85bec5 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.
2026-05-31 14:04:44 +08:00

22 lines
676 B
TypeScript

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;
}
}