From 38ed9a3db991a3f098d48f1e4ac734dc6d74fc15 Mon Sep 17 00:00:00 2001 From: Chris Nicola Date: Fri, 23 Jun 2017 17:50:48 -0700 Subject: [PATCH] Fix for sourcemap file locations babel-loader was setting `options.sourceFileName` to a relative path, but this does not seem to work correctly anymore with either webpack or babel itself and causes incorrect source map file data in webpack. Setting it to an absolute path seems to fix the problem. Fixes #480 and possibly also #93. --- src/index.js | 3 +-- src/utils/relative.js | 13 ------------- test/utils/relative.test.js | 37 ------------------------------------- 3 files changed, 1 insertion(+), 52 deletions(-) delete mode 100644 src/utils/relative.js delete mode 100644 test/utils/relative.test.js 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"); - }); -}