mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 16:48:26 +00:00
Update contributing, deduplicate more functions
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import fs from "node:fs/promises";
|
||||
|
||||
let wslCached: boolean | null = null;
|
||||
@@ -9,6 +10,40 @@ export function isWSLEnv(): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Synchronously check if running in WSL.
|
||||
* Checks env vars first, then /proc/version.
|
||||
*/
|
||||
export function isWSLSync(): boolean {
|
||||
if (process.platform !== "linux") {
|
||||
return false;
|
||||
}
|
||||
if (isWSLEnv()) {
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
const release = readFileSync("/proc/version", "utf8").toLowerCase();
|
||||
return release.includes("microsoft") || release.includes("wsl");
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Synchronously check if running in WSL2.
|
||||
*/
|
||||
export function isWSL2Sync(): boolean {
|
||||
if (!isWSLSync()) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
const version = readFileSync("/proc/version", "utf8").toLowerCase();
|
||||
return version.includes("wsl2") || version.includes("microsoft-standard");
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export async function isWSL(): Promise<boolean> {
|
||||
if (wslCached !== null) {
|
||||
return wslCached;
|
||||
|
||||
Reference in New Issue
Block a user