41428e476ab163202805a03566037afbb58746b0ce4300a5b43c0c761504c507a0caa75bd1014aa9c7ae3d331acfe8e6155ec416634590e067ff788883a09f 1.2 KB

1234567891011121314151617181920212223242526272829
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.stripAbsolutePath = void 0;
  4. // unix absolute paths are also absolute on win32, so we use this for both
  5. const node_path_1 = require("node:path");
  6. const { 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']
  13. const 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. };
  28. exports.stripAbsolutePath = stripAbsolutePath;
  29. //# sourceMappingURL=strip-absolute-path.js.map