identifier.js 450 B

12345678910111213141516
  1. "use strict";
  2. const path = require("path");
  3. const looksLikeAbsolutePath = (maybeAbsolutePath) => {
  4. return /^(?:[a-z]:\\|\/)/i.test(maybeAbsolutePath);
  5. };
  6. const normalizePathSeparator = (p) => p.replace(/\\/g, "/");
  7. exports.makePathsRelative = (context, identifier) => {
  8. return identifier
  9. .split(/([|! ])/)
  10. .map(str => looksLikeAbsolutePath(str) ?
  11. normalizePathSeparator(path.relative(context, str)) : str)
  12. .join("");
  13. };