diff --git a/src/index.js b/src/index.js index 36c3d641..f129a0b1 100644 --- a/src/index.js +++ b/src/index.js @@ -3,7 +3,6 @@ const loaderUtils = require("loader-utils"); const path = require("path"); const cache = require("./fs-cache.js"); const exists = require("./utils/exists"); -const relative = require("./utils/relative"); const read = require("./utils/read"); const resolveRc = require("./resolve-rc.js"); const pkg = require("../package.json"); @@ -143,7 +142,7 @@ module.exports = function(source, inputSourceMap) { } if (options.sourceFileName === undefined) { - options.sourceFileName = relative(options.sourceRoot, options.filename); + options.sourceFileName = options.filename; } const cacheDirectory = options.cacheDirectory; diff --git a/src/utils/relative.js b/src/utils/relative.js deleted file mode 100644 index 377b969a..00000000 --- a/src/utils/relative.js +++ /dev/null @@ -1,13 +0,0 @@ -const path = require("path"); - -module.exports = function relative(sourceRoot, filename) { - const rootPath = sourceRoot.replace(/\\/g, "/").split("/")[1]; - const fileRootPath = filename.replace(/\\/g, "/").split("/")[1]; - - // If the file is in a completely different root folder use the absolute path of file. - if (rootPath && rootPath !== fileRootPath) { - return filename; - } - - return path.relative(sourceRoot, filename); -}; diff --git a/test/utils/relative.test.js b/test/utils/relative.test.js deleted file mode 100644 index 96183b2d..00000000 --- a/test/utils/relative.test.js +++ /dev/null @@ -1,37 +0,0 @@ -import test from "ava"; -import os from "os"; -import relative from "../../lib/utils/relative.js"; - -if (os.platform() === "win32") { - test("should get correct relative path - depth 0 - windows", t => { - t.is(relative("C:\\the\\root", "C:\\the\\root\\one.js"), "one.js"); - }); - - test("should get correct relative path - depth 1 - windows", t => { - t.is(relative("C:\\the\\root", "C:\\the\\rootone.js"), "..\\rootone.js"); - }); - - test("should get correct relative path - depth 2 - windows", t => { - t.is(relative("C:\\the\\root", "C:\\therootone.js"), "C:\\therootone.js"); - }); - - test("should get correct relative path with main root - depth 0 - windows", t => { - t.is(relative("C:\\", "C:\\the\\root\\one.js"), "the\\root\\one.js"); - }); -} else { - test("should get correct relative path - depth 0", t => { - t.is(relative("/the/root", "/the/root/one.js"), "one.js"); - }); - - test("should get correct relative path - depth 1", t => { - t.is(relative("/the/root", "/the/rootone.js"), "../rootone.js"); - }); - - test("should get correct relative path - depth 2", t => { - t.is(relative("/the/root", "/therootone.js"), "/therootone.js"); - }); - - test("should get correct relative path with main root - depth 0", t => { - t.is(relative("/", "/the/root/one.js"), "the/root/one.js"); - }); -}