2026-10-14 16:00:18 +08:00
|
|
|
import { resolve } from "node:path";
|
2026-10-26 02:31:41 +08:00
|
|
|
import {
|
|
|
|
|
javaScriptRuntime,
|
|
|
|
|
type JavaScriptRuntime,
|
|
|
|
|
} from "../domain/runtimeVersion.js";
|
|
|
|
|
import { absoluteCallerPath } from "../filesystem/callerPath.js";
|
2026-10-14 16:00:18 +08:00
|
|
|
|
2026-10-26 02:31:41 +08:00
|
|
|
/** Runtime-specific absolute argv script selection, or undefined when none was supplied.
|
2026-10-18 06:18:34 +08:00
|
|
|
* Native executable paths have different traversal semantics and must not use this.
|
|
|
|
|
*/
|
2026-10-14 16:00:18 +08:00
|
|
|
export const normalizeEntrypointPath = (
|
|
|
|
|
entrypoint: string | undefined,
|
2026-10-26 02:31:41 +08:00
|
|
|
runtime: JavaScriptRuntime["id"] = javaScriptRuntime(process.versions).id,
|
2026-10-14 16:00:18 +08:00
|
|
|
): string | undefined =>
|
|
|
|
|
entrypoint === undefined || entrypoint.length === 0
|
|
|
|
|
? undefined
|
2026-10-26 02:31:41 +08:00
|
|
|
: runtime === "bun"
|
|
|
|
|
? absoluteCallerPath(entrypoint)
|
|
|
|
|
: resolve(entrypoint);
|
2026-10-14 16:00:18 +08:00
|
|
|
|
|
|
|
|
export const CURRENT_ENTRYPOINT_PATH = normalizeEntrypointPath(process.argv[1]);
|