MCPcopy
hub / github.com/wavetermdev/waveterm / normalizeMockPath

Function normalizeMockPath

frontend/preview/mock/mockfilesystem.ts:64–94  ·  view source on GitHub ↗
(path: string, basePath = MockHomePath)

Source from the content-addressed store, hash-verified

62};
63
64function normalizeMockPath(path: string, basePath = MockHomePath): string {
65 if (path == null || path === "") {
66 return basePath;
67 }
68 if (path.startsWith("wsh://")) {
69 const url = new URL(path);
70 path = url.pathname.replace(/^\/+/, "/");
71 }
72 if (path === "~") {
73 path = MockHomePath;
74 } else if (path.startsWith("~/")) {
75 path = MockHomePath + path.slice(1);
76 }
77 if (!path.startsWith("/")) {
78 path = `${basePath}/${path}`;
79 }
80 const parts = path.split("/");
81 const resolvedParts: string[] = [];
82 for (const part of parts) {
83 if (!part || part === ".") {
84 continue;
85 }
86 if (part === "..") {
87 resolvedParts.pop();
88 continue;
89 }
90 resolvedParts.push(part);
91 }
92 const resolvedPath = "/" + resolvedParts.join("/");
93 return resolvedPath === "" ? "/" : resolvedPath;
94}
95
96function getDirName(path: string): string {
97 if (path === "/") {

Callers 7

ensureDirFunction · 0.85
buildEntriesFunction · 0.85
makeNotFoundInfoFunction · 0.85
joinPathsFunction · 0.85
getEntryFunction · 0.85
fileListFunction · 0.85
fileJoinFunction · 0.85

Calls 2

popMethod · 0.80
pushMethod · 0.80

Tested by

no test coverage detected