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

Commit

Permalink
Fix incorrect source path normalization, when the path is either root…
Browse files Browse the repository at this point in the history
…ed in a drive letter or a file url.
  • Loading branch information
thomas-darling authored and guybedford committed Oct 16, 2017
1 parent bd97d6c commit 51b9e45
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 51b9e45

Please sign in to comment.