MCPcopy
hub / github.com/Effect-TS/effect / resolve

Function resolve

packages/platform/src/internal/path.ts:142–190  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

140}
141
142const resolve: Api.Path["resolve"] = function resolve() {
143 let resolvedPath = ""
144 let resolvedAbsolute = false
145 let cwd: string | undefined = undefined
146
147 for (let i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
148 let path: string
149 if (i >= 0) {
150 path = arguments[i]
151 } else {
152 const process = (globalThis as any).process
153 if (
154 cwd === undefined && "process" in globalThis &&
155 typeof process === "object" &&
156 process !== null &&
157 typeof process.cwd === "function"
158 ) {
159 cwd = process.cwd()
160 }
161 path = cwd!
162 }
163
164 // Skip empty entries
165 if (path.length === 0) {
166 continue
167 }
168
169 resolvedPath = path + "/" + resolvedPath
170 resolvedAbsolute = path.charCodeAt(0) === 47 /*/*/
171 }
172
173 // At this point the path should be resolved to a full absolute path, but
174 // handle relative paths to be safe (might happen when process.cwd() fails)
175
176 // Normalize the path
177 resolvedPath = normalizeStringPosix(resolvedPath, !resolvedAbsolute)
178
179 if (resolvedAbsolute) {
180 if (resolvedPath.length > 0) {
181 return "/" + resolvedPath
182 } else {
183 return "/"
184 }
185 } else if (resolvedPath.length > 0) {
186 return resolvedPath
187 } else {
188 return "."
189 }
190}
191
192const CHAR_FORWARD_SLASH = 47
193

Callers 10

toFileUrlFunction · 0.85
Effect.tst.tsFile · 0.85
promise.test.tsFile · 0.85
tryPromise.test.tsFile · 0.85
runtimePromiseFunction · 0.85
runtimePromiseFunction · 0.85
validateMethod · 0.85
runtimePromiseFunction · 0.85
core-effect.tsFile · 0.85
runtime.tsFile · 0.85

Calls 1

normalizeStringPosixFunction · 0.85

Tested by

no test coverage detected