Skip to content

Commit

Permalink
Use absolute filepaths in sourcemap 'sources' list.
Browse files Browse the repository at this point in the history
  • Loading branch information
loganfsmyth committed Sep 2, 2018
1 parent 9621e24 commit 4582e25
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 63 deletions.
24 changes: 12 additions & 12 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ const pkg = require("../package.json");
const cache = require("./cache");
const transform = require("./transform");

const relative = require("./utils/relative");

const loaderUtils = require("loader-utils");

function subscribe(subscriber, metadata, context) {
Expand Down Expand Up @@ -77,19 +75,21 @@ async function loader(source, inputSourceMap, overrides) {
);
}

// Set babel-loader's default options.
const {
sourceRoot = process.cwd(),
sourceMap = this.sourceMap,
sourceFileName = relative(sourceRoot, filename),
} = loaderOptions;

const programmaticOptions = Object.assign({}, loaderOptions, {
filename,
inputSourceMap: inputSourceMap || undefined,
sourceRoot,
sourceMap,
sourceFileName,

// Set the default sourcemap behavior based on Webpack's mapping flag,
// but allow users to override if they want.
sourceMap:
loaderOptions.sourceMap === undefined
? this.sourceMap
: loaderOptions.sourceMap,

// Ensure that Webpack will get a full absolute path in the sourcemap
// so that it can properly map the module back to its internal cached
// modules.
sourceFileName: filename,
});
// Remove loader related options
delete programmaticOptions.cacheDirectory;
Expand Down
14 changes: 0 additions & 14 deletions src/utils/relative.js

This file was deleted.

49 changes: 49 additions & 0 deletions test/sourcemaps.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,52 @@ test.cb("should output webpack's sourcemap", t => {
});
});
});

test.cb("should output webpack's devtoolModuleFilename option", t => {
const config = Object.assign({}, globalConfig, {
devtool: "source-map",
output: {
path: t.context.directory,
devtoolModuleFilenameTemplate: "==[absolute-resource-path]==",
},
module: {
rules: [
{
test: /\.jsx?/,
loader: babelLoader + "?presets[]=@babel/env",
exclude: /node_modules/,
},
],
},
});

webpack(config, (err, stats) => {
t.is(err, null);
t.is(stats.compilation.errors.length, 0);
t.is(stats.compilation.warnings.length, 0);

fs.readdir(t.context.directory, (err, files) => {
t.is(err, null);

const map = files.filter(file => file.indexOf(".map") !== -1);

t.true(map.length > 0);

if (map.length > 0) {
fs.readFile(path.resolve(t.context.directory, map[0]), (err, data) => {
t.is(err, null);

// The full absolute path is included in the sourcemap properly
t.not(
data
.toString()
.indexOf(JSON.stringify(`==${globalConfig.entry}==`)),
-1,
);

t.end();
});
}
});
});
});
37 changes: 0 additions & 37 deletions test/utils/relative.test.js

This file was deleted.

0 comments on commit 4582e25

Please sign in to comment.