join-path.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.joinPathWithBasePath = joinPathWithBasePath;
  4. exports.joinDirectoryPath = joinDirectoryPath;
  5. exports.build = build;
  6. const path_1 = require("path");
  7. const utils_1 = require("../../utils");
  8. function joinPathWithBasePath(filename, directoryPath) {
  9. return directoryPath + filename;
  10. }
  11. function joinPathWithRelativePath(root, options) {
  12. return function (filename, directoryPath) {
  13. const sameRoot = directoryPath.startsWith(root);
  14. if (sameRoot)
  15. return directoryPath.replace(root, "") + filename;
  16. else
  17. return ((0, utils_1.convertSlashes)((0, path_1.relative)(root, directoryPath), options.pathSeparator) +
  18. options.pathSeparator +
  19. filename);
  20. };
  21. }
  22. function joinPath(filename) {
  23. return filename;
  24. }
  25. function joinDirectoryPath(filename, directoryPath, separator) {
  26. return directoryPath + filename + separator;
  27. }
  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. }