Open History to see the last commit
1// @effect-diagnostics nodeBuiltinImport:off
2import * as NodeFS from "node:fs";
3import * as NodeURL from "node:url";
4
5/** Fallback for supported Node 22.16, 22.17 and 23.11, where import.meta.main is undefined. */
6export const isEntrypoint = (input: {
7 readonly moduleUrl: string;
8 readonly entryPath: string | undefined;
9 readonly runtimeMain: boolean | undefined;
10}): boolean => {
11 if (input.runtimeMain !== undefined) {
12 return input.runtimeMain;
13 }
14 if (input.entryPath === undefined || input.entryPath === "") {
15 return false;
16 }
17 if (input.moduleUrl === NodeURL.pathToFileURL(input.entryPath).href) {
18 return true;
19 }
20 // npm/npx keep the symlink in argv[1], but Node resolves the module URL.
21 try {
22 return input.moduleUrl === NodeURL.pathToFileURL(NodeFS.realpathSync(input.entryPath)).href;
23 } catch {
24 return false;
25 }
26};