Support "~" in getAbsoluteAndInOsFormat
This commit is contained in:
@ -1,4 +1,5 @@
|
|||||||
import { isAbsolute as pathIsAbsolute, sep as pathSep, join as pathJoin } from "path";
|
import { isAbsolute as pathIsAbsolute, sep as pathSep, join as pathJoin, resolve as pathResolve } from "path";
|
||||||
|
import * as os from "os";
|
||||||
|
|
||||||
export function getAbsoluteAndInOsFormatPath(params: { pathIsh: string; cwd: string }): string {
|
export function getAbsoluteAndInOsFormatPath(params: { pathIsh: string; cwd: string }): string {
|
||||||
const { pathIsh, cwd } = params;
|
const { pathIsh, cwd } = params;
|
||||||
@ -7,11 +8,17 @@ export function getAbsoluteAndInOsFormatPath(params: { pathIsh: string; cwd: str
|
|||||||
|
|
||||||
pathOut = pathOut.replace(/\//g, pathSep);
|
pathOut = pathOut.replace(/\//g, pathSep);
|
||||||
|
|
||||||
|
if (pathOut.startsWith("~")) {
|
||||||
|
pathOut = pathOut.replace("~", os.homedir());
|
||||||
|
}
|
||||||
|
|
||||||
pathOut = pathOut.endsWith(pathSep) ? pathOut.slice(0, -1) : pathOut;
|
pathOut = pathOut.endsWith(pathSep) ? pathOut.slice(0, -1) : pathOut;
|
||||||
|
|
||||||
if (!pathIsAbsolute(pathOut)) {
|
if (!pathIsAbsolute(pathOut)) {
|
||||||
pathOut = pathJoin(cwd, pathOut);
|
pathOut = pathJoin(cwd, pathOut);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pathOut = pathResolve(pathOut);
|
||||||
|
|
||||||
return pathOut;
|
return pathOut;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user