(path)
| 86 | } |
| 87 | |
| 88 | function normalize(path) { |
| 89 | if (!path.length) return '.' |
| 90 | |
| 91 | // Normalise backslashes to forward slashes before any other processing. |
| 92 | path = path.replace(/\\/g, '/') |
| 93 | |
| 94 | const drivePrefix = getWindowsDrivePrefix(path) |
| 95 | // isAbsolute: Unix root ('/foo') OR Windows drive+slash ('C:/foo'). |
| 96 | const isAbsolute = |
| 97 | path[0] === '/' || (drivePrefix !== null && path[2] === '/') |
| 98 | const trailingSeparator = path.at(-1) === '/' |
| 99 | |
| 100 | // Strip the drive prefix before feeding into normalizeString so that the |
| 101 | // core algorithm only ever sees a plain POSIX-style string. |
| 102 | const pathBody = drivePrefix ? path.slice(2) : path |
| 103 | |
| 104 | let normalized = normalizeString(pathBody, !isAbsolute) |
| 105 | |
| 106 | if (!normalized.length) { |
| 107 | const root = drivePrefix |
| 108 | ? isAbsolute |
| 109 | ? drivePrefix + '/' |
| 110 | : drivePrefix |
| 111 | : isAbsolute |
| 112 | ? '/' |
| 113 | : '.' |
| 114 | return trailingSeparator && !isAbsolute ? root + '/' : root |
| 115 | } |
| 116 | if (trailingSeparator) normalized += '/' |
| 117 | |
| 118 | if (drivePrefix) { |
| 119 | return isAbsolute |
| 120 | ? `${drivePrefix}/${normalized}` |
| 121 | : `${drivePrefix}${normalized}` |
| 122 | } |
| 123 | return isAbsolute ? `/${normalized}` : normalized |
| 124 | } |
| 125 | |
| 126 | export function join(...args) { |
| 127 | if (args.length === 0) return '.' |
no test coverage detected
searching dependent graphs…