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

Fix incorrect source path normalization, when the path is either rooted in a drive letter or a file url. #834

Merged
merged 1 commit into from
Oct 9, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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