- Centralize process spawning/termination in `processRunner` for consistent Windows behavior - Add runtime environment detection to handle WSL-hosted command resolution - Update open/editor/browser launch logic to prefer Linux shims and fall back to Windows executables - Expand server tests for WSL launch paths and shared process helpers
55 lines
1.5 KiB
TypeScript
55 lines
1.5 KiB
TypeScript
import os from "node:os";
|
|
|
|
import type { ServerRuntimeEnvironment } from "@t3tools/contracts";
|
|
|
|
interface DetectServerRuntimeEnvironmentOptions {
|
|
readonly platform?: NodeJS.Platform;
|
|
readonly env?: NodeJS.ProcessEnv;
|
|
readonly osRelease?: string;
|
|
}
|
|
|
|
function normalizePlatform(platform: NodeJS.Platform): ServerRuntimeEnvironment["platform"] {
|
|
switch (platform) {
|
|
case "win32":
|
|
return "windows";
|
|
case "darwin":
|
|
return "macos";
|
|
default:
|
|
return "linux";
|
|
}
|
|
}
|
|
|
|
function detectWsl(options: {
|
|
readonly platform: NodeJS.Platform;
|
|
readonly env: NodeJS.ProcessEnv;
|
|
readonly osRelease: string;
|
|
}): boolean {
|
|
if (options.platform !== "linux") {
|
|
return false;
|
|
}
|
|
|
|
if (options.env.WSL_DISTRO_NAME || options.env.WSL_INTEROP) {
|
|
return true;
|
|
}
|
|
|
|
return options.osRelease.toLowerCase().includes("microsoft");
|
|
}
|
|
|
|
export function detectServerRuntimeEnvironment(
|
|
options: DetectServerRuntimeEnvironmentOptions = {},
|
|
): ServerRuntimeEnvironment {
|
|
const platform = options.platform ?? process.platform;
|
|
const env = options.env ?? process.env;
|
|
const osRelease = options.osRelease ?? os.release();
|
|
const normalizedPlatform = normalizePlatform(platform);
|
|
const isWsl = detectWsl({ platform, env, osRelease });
|
|
|
|
return {
|
|
platform: normalizedPlatform,
|
|
pathStyle: normalizedPlatform === "windows" ? "windows" : "posix",
|
|
isWsl,
|
|
windowsInteropMode: normalizedPlatform === "windows" ? "windows-native" : isWsl ? "wsl-hosted" : null,
|
|
wslDistroName: isWsl ? env.WSL_DISTRO_NAME?.trim() || null : null,
|
|
};
|
|
}
|