* path.resolve([from ...], to) * @param {...string} args * @returns {string}
(...args)
| 188 | * @returns {string} |
| 189 | */ |
| 190 | resolve(...args) { |
| 191 | let resolvedDevice = ''; |
| 192 | let resolvedTail = ''; |
| 193 | let resolvedAbsolute = false; |
| 194 | |
| 195 | for (let i = args.length - 1; i >= -1; i--) { |
| 196 | let path; |
| 197 | if (i >= 0) { |
| 198 | path = args[i]; |
| 199 | validateString(path, `paths[${i}]`); |
| 200 | |
| 201 | // Skip empty entries |
| 202 | if (path.length === 0) { |
| 203 | continue; |
| 204 | } |
| 205 | } else if (resolvedDevice.length === 0) { |
| 206 | path = process.cwd(); |
| 207 | // Fast path for current directory |
| 208 | if (args.length === 0 || ((args.length === 1 && (args[0] === '' || args[0] === '.')) && |
| 209 | isPathSeparator(StringPrototypeCharCodeAt(path, 0)))) { |
| 210 | if (!isWindows) { |
| 211 | path = StringPrototypeReplace(path, forwardSlashRegExp, '\\'); |
| 212 | } |
| 213 | return path; |
| 214 | } |
| 215 | } else { |
| 216 | // Windows has the concept of drive-specific current working |
| 217 | // directories. If we've resolved a drive letter but not yet an |
| 218 | // absolute path, get cwd for that drive, or the process cwd if |
| 219 | // the drive cwd is not available. We're sure the device is not |
| 220 | // a UNC path at this points, because UNC paths are always absolute. |
| 221 | path = process.env[`=${resolvedDevice}`] || process.cwd(); |
| 222 | |
| 223 | // Verify that a cwd was found and that it actually points |
| 224 | // to our drive. If not, default to the drive's root. |
| 225 | if (path === undefined || |
| 226 | (StringPrototypeToLowerCase(StringPrototypeSlice(path, 0, 2)) !== |
| 227 | StringPrototypeToLowerCase(resolvedDevice) && |
| 228 | StringPrototypeCharCodeAt(path, 2) === CHAR_BACKWARD_SLASH)) { |
| 229 | path = `${resolvedDevice}\\`; |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | const len = path.length; |
| 234 | let rootEnd = 0; |
| 235 | let device = ''; |
| 236 | let isAbsolute = false; |
| 237 | const code = StringPrototypeCharCodeAt(path, 0); |
| 238 | |
| 239 | // Try to match a root |
| 240 | if (len === 1) { |
| 241 | if (isPathSeparator(code)) { |
| 242 | // `path` contains just a path separator |
| 243 | rootEnd = 1; |
| 244 | isAbsolute = true; |
| 245 | } |
| 246 | } else if (isPathSeparator(code)) { |
| 247 | // Possible UNC root |
no test coverage detected
searching dependent graphs…