1// unix absolute paths are also absolute on win32, so we use this for both 2const { isAbsolute, parse } = require('path').win32 3 4// returns [root, stripped] 5// Note that windows will think that //x/y/z/a has a "root" of //x/y, and in 6// those cases, we want to sanitize it to x/y/z/a, not z/a, so we strip / 7// explicitly if it's the first character. 8// drive-specific relative paths on Windows get their root stripped off even 9// though they are not absolute, so `c:../foo` becomes ['c:', '../foo'] 10module.exports = path => { 11 let r = '' 12 13 let parsed = parse(path) 14 while (isAbsolute(path) || parsed.root) { 15 // windows will think that //x/y/z has a "root" of //x/y/ 16 // but strip the //?/C:/ off of //?/C:/path 17 const root = path.charAt(0) === '/' && path.slice(0, 4) !== '//?/' ? '/' 18 : parsed.root 19 path = path.slice(root.length) 20 r += root 21 parsed = parse(path) 22 } 23 return [r, path] 24} 25