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