Skip to content
This repository has been archived by the owner on Oct 9, 2020. It is now read-only.

Commit

Permalink
Merge pull request #834 from thomas-darling/master
Browse files Browse the repository at this point in the history
Fix incorrect source path normalization, when the path is either rooted in a drive letter or a file url.
  • Loading branch information
guybedford authored Oct 9, 2017
2 parents c7e1854 + 419fc56 commit 2fc876c
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions lib/sourcemaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,17 @@ exports.concatenateSourceMaps = function(outFile, mapsWithOffsets, basePath, sou

if (sourceMapContents && map.sourcesContent) {
for (var i=0; i<map.sources.length; i++) {
var source = path.normalize(path.isAbsolute(map.sources[i]) ? map.sources[i] : (map.sourceRoot || '') + map.sources[i]).replace(/\\/g, '/');

// If the source is an absolute path or file URL, use it as-is, otherwise prepend the sourceRoot.
var isAbsoluteOrFileUrl = path.isAbsolute(map.sources[i]) || isFileURL(map.sources[i]);
var source = isAbsoluteOrFileUrl ? map.sources[i] : (map.sourceRoot || '') + map.sources[i];

// If the source is still not a file URL, normalize the path.
if (!isFileURL(source))
{
source = path.normalize(source).replace(/\\/g, '/');
}

if (!source.match(/\/@traceur/)) {
if (!contentsBySource[source]) {
contentsBySource[source] = map.sourcesContent[i];
Expand Down Expand Up @@ -98,7 +108,11 @@ exports.concatenateSourceMaps = function(outFile, mapsWithOffsets, basePath, sou
if (isFileURL(source))
source = fromFileURL(source);

return path.isAbsolute(source) ? source : path.relative(outPath, path.resolve(basePath, source)).replace(/\\/g, '/');
// If the source is already a root-relative path, use it as-is, otherwise make it relative to the outPath.
var isRootRelative = /^[\\/]/.test(source);
source = (isRootRelative ? source : path.relative(outPath, path.resolve(basePath, source))).replace(/\\/g, '/');

return source;
});

return JSON.stringify(normalized);
Expand Down

0 comments on commit 2fc876c

Please sign in to comment.