2024-05-18 09:15:39 +02:00
|
|
|
import { isAbsolute as pathIsAbsolute, sep as pathSep, join as pathJoin, resolve as pathResolve } from "path";
|
|
|
|
import * as os from "os";
|
2023-09-03 23:26:34 +02:00
|
|
|
|
|
|
|
export function getAbsoluteAndInOsFormatPath(params: { pathIsh: string; cwd: string }): string {
|
|
|
|
const { pathIsh, cwd } = params;
|
|
|
|
|
|
|
|
let pathOut = pathIsh;
|
|
|
|
|
|
|
|
pathOut = pathOut.replace(/\//g, pathSep);
|
|
|
|
|
2024-05-18 09:15:39 +02:00
|
|
|
if (pathOut.startsWith("~")) {
|
|
|
|
pathOut = pathOut.replace("~", os.homedir());
|
|
|
|
}
|
|
|
|
|
2024-01-30 05:54:36 +01:00
|
|
|
pathOut = pathOut.endsWith(pathSep) ? pathOut.slice(0, -1) : pathOut;
|
|
|
|
|
2023-09-03 23:26:34 +02:00
|
|
|
if (!pathIsAbsolute(pathOut)) {
|
|
|
|
pathOut = pathJoin(cwd, pathOut);
|
|
|
|
}
|
|
|
|
|
2024-05-18 09:15:39 +02:00
|
|
|
pathOut = pathResolve(pathOut);
|
|
|
|
|
2023-09-03 23:26:34 +02:00
|
|
|
return pathOut;
|
|
|
|
}
|