-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add support for resolving symlinks with real paths & relative pa…
…ths on
- Loading branch information
Showing
4 changed files
with
118 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,43 @@ | ||
import { sep, normalize } from "path"; | ||
import { PathSeparator } from "./types"; | ||
|
||
export function cleanPath(path: string) { | ||
let normalized = normalize(path); | ||
|
||
// we have to remove the last path separator | ||
// to account for / root path | ||
if (normalized.length > 1 && normalized[normalized.length - 1] === sep) | ||
normalized = normalized.substring(0, normalized.length - 1); | ||
|
||
return normalized; | ||
} | ||
|
||
const SLASHES_REGEX = /[\\/]/g; | ||
export function convertSlashes(path: string, separator: PathSeparator) { | ||
return path.replace(SLASHES_REGEX, separator); | ||
} | ||
import { sep, normalize, resolve } from "path"; | ||
import { PathSeparator } from "./types"; | ||
|
||
export function cleanPath(path: string) { | ||
let normalized = normalize(path); | ||
|
||
// we have to remove the last path separator | ||
// to account for / root path | ||
if (normalized.length > 1 && normalized[normalized.length - 1] === sep) | ||
normalized = normalized.substring(0, normalized.length - 1); | ||
|
||
return normalized; | ||
} | ||
|
||
const SLASHES_REGEX = /[\\/]/g; | ||
export function convertSlashes(path: string, separator: PathSeparator) { | ||
return path.replace(SLASHES_REGEX, separator); | ||
} | ||
|
||
export function normalizePath( | ||
path: string, | ||
options: { | ||
resolvePaths?: boolean; | ||
normalizePath?: boolean; | ||
pathSeparator: PathSeparator; | ||
} | ||
) { | ||
const { resolvePaths, normalizePath, pathSeparator } = options; | ||
const pathNeedsCleaning = | ||
(process.platform === "win32" && path.includes("/")) || | ||
path.startsWith("."); | ||
|
||
if (resolvePaths) path = resolve(path); | ||
if (normalizePath || pathNeedsCleaning) path = cleanPath(path); | ||
|
||
if (path === ".") return ""; | ||
|
||
const needsSeperator = path[path.length - 1] !== pathSeparator; | ||
return convertSlashes( | ||
needsSeperator ? path + pathSeparator : path, | ||
pathSeparator | ||
); | ||
} |
a42701c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for figuring this out! i think you forgot to update the docs to remove that one sentence that said this usecase wasn't supported