* Returns the resolved pathname. * @param {string | Buffer | URL} p * @param {string | { encoding?: string | null; }} [options] * @returns {string | Buffer}
(p, options)
| 3232 | * @returns {string | Buffer} |
| 3233 | */ |
| 3234 | function realpathSync(p, options) { |
| 3235 | const h = vfsState.handlers; |
| 3236 | if (h !== null) { |
| 3237 | const result = h.realpathSync(p, options); |
| 3238 | if (result !== undefined) return result; |
| 3239 | } |
| 3240 | options = getOptions(options); |
| 3241 | p = toPathIfFileURL(p); |
| 3242 | if (typeof p !== 'string') { |
| 3243 | p += ''; |
| 3244 | } |
| 3245 | validatePath(p); |
| 3246 | p = pathModule.resolve(p); |
| 3247 | |
| 3248 | const cache = options[realpathCacheKey]; |
| 3249 | const maybeCachedResult = cache?.get(p); |
| 3250 | if (maybeCachedResult) { |
| 3251 | return maybeCachedResult; |
| 3252 | } |
| 3253 | |
| 3254 | const seenLinks = new SafeMap(); |
| 3255 | const knownHard = new SafeSet(); |
| 3256 | const original = p; |
| 3257 | |
| 3258 | // Current character position in p |
| 3259 | let pos; |
| 3260 | // The partial path so far, including a trailing slash if any |
| 3261 | let current; |
| 3262 | // The partial path without a trailing slash (except when pointing at a root) |
| 3263 | let base; |
| 3264 | // The partial path scanned in the previous round, with slash |
| 3265 | let previous; |
| 3266 | |
| 3267 | // Skip over roots |
| 3268 | current = base = splitRoot(p); |
| 3269 | pos = current.length; |
| 3270 | |
| 3271 | // On windows, check that the root exists. On unix there is no need. |
| 3272 | if (isWindows) { |
| 3273 | const out = binding.lstat(base, false, undefined, true /* throwIfNoEntry */); |
| 3274 | if (out === undefined) { |
| 3275 | return; |
| 3276 | } |
| 3277 | knownHard.add(base); |
| 3278 | } |
| 3279 | |
| 3280 | // Walk down the path, swapping out linked path parts for their real |
| 3281 | // values |
| 3282 | // NB: p.length changes. |
| 3283 | while (pos < p.length) { |
| 3284 | // find the next part |
| 3285 | const result = nextPart(p, pos); |
| 3286 | previous = current; |
| 3287 | if (result === -1) { |
| 3288 | const last = StringPrototypeSlice(p, pos); |
| 3289 | current += last; |
| 3290 | base = previous + last; |
| 3291 | pos = p.length; |
no test coverage detected
searching dependent graphs…