mirror of
https://github.com/nexu-io/openmotion.git
synced 2026-12-01 23:51:42 +08:00
10 lines
374 B
TypeScript
10 lines
374 B
TypeScript
import { realpathSync } from 'node:fs';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
// Node resolves the module URL through symlinks, while argv[1] can retain them.
|
|
export function isMain(moduleUrl: string): boolean {
|
|
if (!process.argv[1]) return false;
|
|
try { return realpathSync(process.argv[1]) === realpathSync(fileURLToPath(moduleUrl)); }
|
|
catch { return false; }
|
|
}
|