import { dirname, join, resolve, win32 } from "node:path"; /** * Recognize native Windows paths even when a portability test supplies one on * a Unix host. Production paths on Windows are handled by the native path * implementation; the explicit drive/UNC forms keep synthetic tests honest. */ export function isWindowsStylePath(value: string): boolean { return process.platform === "win32" ? win32.isAbsolute(value) : /^[a-zA-Z]:[\\/]/.test(value) || value.startsWith("\\\\") || value.startsWith("\\") || value.startsWith("//"); } export function joinPortablePath(...parts: string[]): string { return parts.some(isWindowsStylePath) ? win32.join(...parts) : join(...parts); } export function dirnamePortablePath(value: string): string { return isWindowsStylePath(value) ? win32.dirname(value) : dirname(value); } export function resolvePortablePath(base: string, child: string): string { return isWindowsStylePath(base) || isWindowsStylePath(child) ? win32.resolve(base, child) : resolve(base, child); } export function normalizePortablePath(value: string): string { return isWindowsStylePath(value) ? win32.normalize(value) : resolve(value); } export function samePortablePath(left: string | undefined, right: string | undefined): boolean { if (!left || !right) return false; if (isWindowsStylePath(left) || isWindowsStylePath(right)) { const normalize = (value: string) => normalizePortablePath(value).replace(/[\\/]+$/, "").toLowerCase(); return normalize(left) === normalize(right); } return normalizePortablePath(left) === normalizePortablePath(right); }