Update contributing, deduplicate more functions

This commit is contained in:
quotentiroler
2026-02-09 19:21:33 -08:00
parent 453eaed4dc
commit cc87c0ed7c
13 changed files with 96 additions and 100 deletions

View File

@@ -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;