()
| 140 | } |
| 141 | |
| 142 | const 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 | |
| 192 | const CHAR_FORWARD_SLASH = 47 |
| 193 |
no test coverage detected