relative.js 442 B

123456789101112131415
  1. "use strict";
  2. var path = require("path");
  3. module.exports = function relative(sourceRoot, filename) {
  4. var rootPath = sourceRoot.replace(/\\/g, "/").split("/")[1];
  5. var fileRootPath = filename.replace(/\\/g, "/").split("/")[1];
  6. // If the file is in a completely different root folder use the absolute path of file.
  7. if (rootPath && rootPath !== fileRootPath) {
  8. return filename;
  9. }
  10. return path.relative(sourceRoot, filename);
  11. };