normalize.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = normalize;
  6. var _path = _interopRequireDefault(require("path"));
  7. var _normalizePath = _interopRequireDefault(require("normalize-path"));
  8. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  9. function escape(context, from) {
  10. if (from && _path.default.isAbsolute(from)) {
  11. return from;
  12. } // Ensure context is escaped before globbing
  13. // Handles special characters in paths
  14. const absoluteContext = _path.default.resolve(context) // Need refactor
  15. // eslint-disable-next-line no-useless-escape
  16. .replace(/[\*|\?|\!|\(|\)|\[|\]|\{|\}]/g, substring => `[${substring}]`);
  17. if (!from) {
  18. return absoluteContext;
  19. } // Cannot use path.join/resolve as it "fixes" the path separators
  20. if (absoluteContext.endsWith('/')) {
  21. return `${absoluteContext}${from}`;
  22. }
  23. return `${absoluteContext}/${from}`;
  24. }
  25. function normalize(context, from) {
  26. return (0, _normalizePath.default)(escape(context, from));
  27. }