Merge pull request #371 from oysteinkrog/fix/wsl-drvfs-path-detection

Fix QMD when running under WSL (Windows Subsystem for Linux)
This commit is contained in:
Tobias Lütke 2026-03-14 08:10:25 -04:00 committed by GitHub
commit 4721e07975
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -271,7 +271,8 @@ export function isAbsolutePath(path: string): boolean {
if (path.startsWith('/')) {
// Check if it's a Git Bash style path like /c/ or /c/Users (C-Z only, not A or B)
// Requires path[2] === '/' to distinguish from Unix paths like /c or /cache
if (path.length >= 3 && path[2] === '/') {
// Skipped on WSL where /c/ is a valid drvfs mount point, not a drive letter
if (!isWSL() && path.length >= 3 && path[2] === '/') {
const driveLetter = path[1];
if (driveLetter && /[c-zC-Z]/.test(driveLetter)) {
return true;
@ -297,6 +298,14 @@ export function normalizePathSeparators(path: string): string {
return path.replace(/\\/g, '/');
}
/**
* Detect if running inside WSL (Windows Subsystem for Linux).
* On WSL, paths like /c/work/... are valid drvfs mount points, not Git Bash paths.
*/
function isWSL(): boolean {
return !!(process.env.WSL_DISTRO_NAME || process.env.WSL_INTEROP);
}
/**
* Get the relative path from a prefix.
* Returns null if path is not under prefix.
@ -349,8 +358,9 @@ export function resolve(...paths: string[]): string {
if (firstPath.length >= 2 && /[a-zA-Z]/.test(firstPath[0]!) && firstPath[1] === ':') {
windowsDrive = firstPath.slice(0, 2);
result = firstPath.slice(2);
} else if (firstPath.startsWith('/') && firstPath.length >= 3 && firstPath[2] === '/') {
} else if (!isWSL() && firstPath.startsWith('/') && firstPath.length >= 3 && firstPath[2] === '/') {
// Git Bash style: /c/ -> C: (C-Z drives only, not A or B)
// Skipped on WSL where /c/ is a valid drvfs mount point, not a drive letter
const driveLetter = firstPath[1];
if (driveLetter && /[c-zC-Z]/.test(driveLetter)) {
windowsDrive = driveLetter.toUpperCase() + ':';
@ -381,8 +391,9 @@ export function resolve(...paths: string[]): string {
if (p.length >= 2 && /[a-zA-Z]/.test(p[0]!) && p[1] === ':') {
windowsDrive = p.slice(0, 2);
result = p.slice(2);
} else if (p.startsWith('/') && p.length >= 3 && p[2] === '/') {
} else if (!isWSL() && p.startsWith('/') && p.length >= 3 && p[2] === '/') {
// Git Bash style (C-Z drives only, not A or B)
// Skipped on WSL where /c/ is a valid drvfs mount point, not a drive letter
const driveLetter = p[1];
if (driveLetter && /[c-zC-Z]/.test(driveLetter)) {
windowsDrive = driveLetter.toUpperCase() + ':';