| 13 | } |
| 14 | |
| 15 | export default function resolve (basePath, nameOrDot) { |
| 16 | const hasWinDrive = (path) => /^[a-zA-Z]:/.test(path) |
| 17 | const isWin = basePath.includes('\\') || nameOrDot.includes('\\') || hasWinDrive(basePath) || hasWinDrive(nameOrDot) |
| 18 | const sep = isWin ? '\\' : '/' |
| 19 | if (/^[a-zA-Z]:/.test(nameOrDot)) { |
| 20 | return nameOrDot.replace(/^\//, '').replace(/\//g, sep) |
| 21 | } |
| 22 | if (nameOrDot.startsWith('/')) { |
| 23 | return nameOrDot.replace(/\\/g, sep) |
| 24 | } |
| 25 | if (nameOrDot.startsWith('\\\\')) { |
| 26 | return nameOrDot |
| 27 | } |
| 28 | if (nameOrDot === '..') { |
| 29 | if (isWslDistroRoot(basePath)) { |
| 30 | return '/' |
| 31 | } |
| 32 | const baseEndsWithSep = basePath.endsWith(sep) |
| 33 | const parts = basePath.split(sep) |
| 34 | if (parts.length > 1) { |
| 35 | parts.pop() |
| 36 | if (isWin && parts.length === 1) { |
| 37 | return baseEndsWithSep ? '/' : parts.join(sep) |
| 38 | } |
| 39 | return parts.join(sep) || '/' |
| 40 | } |
| 41 | return '/' |
| 42 | } |
| 43 | if (isWslDistroRoot(basePath) && !basePath.endsWith(sep)) { |
| 44 | return basePath + sep + nameOrDot |
| 45 | } |
| 46 | const result = basePath.endsWith(sep) ? basePath + nameOrDot : basePath + sep + nameOrDot |
| 47 | return isWin && result.length === 3 && result.endsWith(':\\') ? '/' : result |
| 48 | } |
| 49 | |
| 50 | export const osResolve = (...args) => { |
| 51 | return window.pre.resolve(...args) |