refactor(daemon): unify runtime binary detection

This commit is contained in:
Peter Steinberger
2026-02-26 22:38:57 +01:00
parent 58171c8918
commit 5dd264d2fb
3 changed files with 66 additions and 22 deletions

View File

@@ -1,11 +1,24 @@
import path from "node:path";
const NODE_VERSIONED_PATTERN = /^node(?:-\d+|\d+)(?:\.\d+)*(?:\.exe)?$/;
function normalizeRuntimeBasename(execPath: string): string {
const trimmed = execPath.trim().replace(/^["']|["']$/g, "");
const lastSlash = Math.max(trimmed.lastIndexOf("/"), trimmed.lastIndexOf("\\"));
const basename = lastSlash === -1 ? trimmed : trimmed.slice(lastSlash + 1);
return basename.toLowerCase();
}
export function isNodeRuntime(execPath: string): boolean {
const base = path.basename(execPath).toLowerCase();
return base === "node" || base === "node.exe";
const base = normalizeRuntimeBasename(execPath);
return (
base === "node" ||
base === "node.exe" ||
base === "nodejs" ||
base === "nodejs.exe" ||
NODE_VERSIONED_PATTERN.test(base)
);
}
export function isBunRuntime(execPath: string): boolean {
const base = path.basename(execPath).toLowerCase();
const base = normalizeRuntimeBasename(execPath);
return base === "bun" || base === "bun.exe";
}