Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FXVsD1DgdzZLiPuwtKzMSY
14 lines
479 B
JavaScript
14 lines
479 B
JavaScript
import { realpathSync } from "node:fs";
|
|
import { pathToFileURL } from "node:url";
|
|
|
|
// Node resolves symlinks in the main module's import.meta.url but argv[1] keeps the invoked
|
|
// spelling (a symlinked skills dir, or /tmp vs /private/tmp on macOS), so compare real paths.
|
|
export function isMainModule(importMetaUrl) {
|
|
if (!process.argv[1]) return false;
|
|
try {
|
|
return pathToFileURL(realpathSync(process.argv[1])).href === importMetaUrl;
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|