Last change
on this file since 8d391a1 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
918 bytes
|
Line | |
---|
1 | // unix absolute paths are also absolute on win32, so we use this for both
|
---|
2 | const { 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']
|
---|
10 | module.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.substr(root.length)
|
---|
20 | r += root
|
---|
21 | parsed = parse(path)
|
---|
22 | }
|
---|
23 | return [r, path]
|
---|
24 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.