MCPcopy Create free account
hub / github.com/Effect-TS/effect / resolve

Function resolve

packages/effect/src/Path.ts:449–497  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

447}
448
449const resolve: Path["resolve"] = function resolve() {
450 let resolvedPath = ""
451 let resolvedAbsolute = false
452 let cwd: string | undefined = undefined
453
454 for (let i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
455 let path: string
456 if (i >= 0) {
457 path = arguments[i]
458 } else {
459 const process = (globalThis as any).process
460 if (
461 cwd === undefined && "process" in globalThis &&
462 typeof process === "object" &&
463 process !== null &&
464 typeof process.cwd === "function"
465 ) {
466 cwd = process.cwd()
467 }
468 path = cwd!
469 }
470
471 // Skip empty entries
472 if (path.length === 0) {
473 continue
474 }
475
476 resolvedPath = path + "/" + resolvedPath
477 resolvedAbsolute = path.charCodeAt(0) === 47 /*/*/
478 }
479
480 // At this point the path should be resolved to a full absolute path, but
481 // handle relative paths to be safe (might happen when process.cwd() fails)
482
483 // Normalize the path
484 resolvedPath = normalizeStringPosix(resolvedPath, !resolvedAbsolute)
485
486 if (resolvedAbsolute) {
487 if (resolvedPath.length > 0) {
488 return "/" + resolvedPath
489 } else {
490 return "/"
491 }
492 } else if (resolvedPath.length > 0) {
493 return resolvedPath
494 } else {
495 return "."
496 }
497}
498
499const CHAR_FORWARD_SLASH = 47
500

Callers 1

toFileUrlFunction · 0.70

Calls 1

normalizeStringPosixFunction · 0.85

Tested by

no test coverage detected