join-path.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.build = exports.joinDirectoryPath = exports.joinPathWithBasePath = void 0;
  4. const path_1 = require("path");
  5. const utils_1 = require("../../utils");
  6. function joinPathWithBasePath(filename, directoryPath) {
  7. return directoryPath + filename;
  8. }
  9. exports.joinPathWithBasePath = joinPathWithBasePath;
  10. function joinPathWithRelativePath(root, options) {
  11. return function (filename, directoryPath) {
  12. const sameRoot = directoryPath.startsWith(root);
  13. if (sameRoot)
  14. return directoryPath.replace(root, "") + filename;
  15. else
  16. return ((0, utils_1.convertSlashes)((0, path_1.relative)(root, directoryPath), options.pathSeparator) +
  17. options.pathSeparator +
  18. filename);
  19. };
  20. }
  21. function joinPath(filename) {
  22. return filename;
  23. }
  24. function joinDirectoryPath(filename, directoryPath, separator) {
  25. return directoryPath + filename + separator;
  26. }
  27. exports.joinDirectoryPath = joinDirectoryPath;
  28. function build(root, options) {
  29. const { relativePaths, includeBasePath } = options;
  30. return relativePaths && root
  31. ? joinPathWithRelativePath(root, options)
  32. : includeBasePath
  33. ? joinPathWithBasePath
  34. : joinPath;
  35. }
  36. exports.build = build;