Adjust path-utils
This commit is contained in:
parent
96e251fd93
commit
9dd94fd9a0
1 changed files with 14 additions and 18 deletions
|
|
@ -53,31 +53,26 @@ export function normalizePath(p: string): string {
|
||||||
// Convert WSL or Unix-style Windows paths to Windows format
|
// Convert WSL or Unix-style Windows paths to Windows format
|
||||||
p = convertToWindowsPath(p);
|
p = convertToWindowsPath(p);
|
||||||
|
|
||||||
// Check if this is a UNC path before normalization
|
// Handle double backslashes, preserving leading UNC \\
|
||||||
const isUNCPath = p.startsWith('\\\\');
|
if (p.startsWith('\\\\')) {
|
||||||
|
// For UNC paths, normalize double backslashes *after* the leading marker
|
||||||
// For non-UNC paths, normalize double backslashes first
|
const restOfPath = p.substring(2).replace(/\\\\/g, '\\');
|
||||||
if (!isUNCPath) {
|
p = '\\\\' + restOfPath;
|
||||||
|
} else {
|
||||||
|
// For non-UNC paths, normalize all double backslashes
|
||||||
p = p.replace(/\\\\/g, '\\');
|
p = p.replace(/\\\\/g, '\\');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use Node's path normalization, which handles . and .. segments
|
// Use Node's path normalization, which handles . and .. segments
|
||||||
let normalized = path.normalize(p);
|
let normalized = path.normalize(p);
|
||||||
|
|
||||||
// Handle UNC paths after normalization to preserve the leading \\
|
// Fix UNC paths after normalization (path.normalize can remove a leading backslash)
|
||||||
if (isUNCPath) {
|
if (p.startsWith('\\\\') && !normalized.startsWith('\\\\')) {
|
||||||
// Ensure UNC path starts with exactly two backslashes
|
normalized = '\\' + normalized;
|
||||||
if (normalized.startsWith('\\') && !normalized.startsWith('\\\\')) {
|
|
||||||
normalized = '\\' + normalized;
|
|
||||||
}
|
|
||||||
// Normalize any remaining double backslashes in the rest of the path
|
|
||||||
normalized = normalized.replace(/^(\\\\)(.*)/, (match, leading, rest) => {
|
|
||||||
return leading + rest.replace(/\\\\/g, '\\');
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle Windows paths: convert slashes and ensure drive letter is capitalized
|
// Handle Windows paths: convert slashes and ensure drive letter is capitalized
|
||||||
if (normalized.match(/^[a-zA-Z]:|^\/mnt\/[a-z]\/|^\/[a-z]\//i)) {
|
if (normalized.match(/^[a-zA-Z]:/)) {
|
||||||
let result = normalized.replace(/\//g, '\\');
|
let result = normalized.replace(/\//g, '\\');
|
||||||
// Capitalize drive letter if present
|
// Capitalize drive letter if present
|
||||||
if (/^[a-z]:/.test(result)) {
|
if (/^[a-z]:/.test(result)) {
|
||||||
|
|
@ -86,8 +81,9 @@ export function normalizePath(p: string): string {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Leave other paths unchanged
|
// For all other paths (including relative paths), convert forward slashes to backslashes
|
||||||
return normalized;
|
// This ensures relative paths like "some/relative/path" become "some\\relative\\path"
|
||||||
|
return normalized.replace(/\//g, '\\');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue