| 65 | // posix version |
| 66 | /** JSDoc */ |
| 67 | export function resolve(...args: string[]): string { |
| 68 | let resolvedPath = ''; |
| 69 | let resolvedAbsolute = false; |
| 70 | |
| 71 | for (let i = args.length - 1; i >= -1 && !resolvedAbsolute; i--) { |
| 72 | const path = i >= 0 ? args[i] : '/'; |
| 73 | |
| 74 | // Skip empty entries |
| 75 | if (!path) { |
| 76 | continue; |
| 77 | } |
| 78 | |
| 79 | resolvedPath = `${path}/${resolvedPath}`; |
| 80 | resolvedAbsolute = path.charAt(0) === '/'; |
| 81 | } |
| 82 | |
| 83 | // At this point the path should be resolved to a full absolute path, but |
| 84 | // handle relative paths to be safe (might happen when process.cwd() fails) |
| 85 | |
| 86 | // Normalize the path |
| 87 | resolvedPath = normalizeArray( |
| 88 | resolvedPath.split('/').filter(p => !!p), |
| 89 | !resolvedAbsolute, |
| 90 | ).join('/'); |
| 91 | |
| 92 | return (resolvedAbsolute ? '/' : '') + resolvedPath || '.'; |
| 93 | } |
| 94 | |
| 95 | /** JSDoc */ |
| 96 | function trim(arr: string[]): string[] { |