Skip to content

Commit

Permalink
Merge pull request #117 from RiaanN/path-separator-fix
Browse files Browse the repository at this point in the history
Fix path issues with source maps
  • Loading branch information
sindresorhus committed Feb 20, 2015
2 parents de879a5 + ac88c56 commit 0bd3211
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
* text=auto
/test/fixtures/* text eol=lf
10 changes: 8 additions & 2 deletions tasks/lib/sourcemap.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ exports.init = function(grunt) {
// prior sourcemap and return src with sourceMappingURL removed.
SourceMapConcatHelper.prototype.addlines = function(src, filename) {
var relativeFilename = path.relative(path.dirname(this.dest), filename);

// sourceMap path references are URLs, so ensure forward slashes are used for paths passed to sourcemap library
relativeFilename = relativeFilename.replace(/\\/g, '/');
var node;
if (
/\/\/[@#]\s+sourceMappingURL=(.+)/.test(src) ||
Expand All @@ -121,6 +122,8 @@ exports.init = function(grunt) {
// Consider the relative path from source files to new sourcemap.
var sourcePathToSourceMapPath =
path.relative(path.dirname(this.dest), path.dirname(sourceMapPath));
// sourceMap path references are URLs, so ensure forward slashes are used for paths passed to sourcemap library
sourcePathToSourceMapPath = sourcePathToSourceMapPath.replace(/\\/g, '/');
// Store the sourceMap so that it may later be consumed.
this.maps.push([
sourceMapConsumer, relativeFilename, sourcePathToSourceMapPath
Expand Down Expand Up @@ -170,8 +173,11 @@ exports.init = function(grunt) {

// Return a string for inline use or write the source map to disk.
SourceMapConcatHelper.prototype._write = function() {
// ensure we're using forward slashes, because these are URLs
var file = path.relative(path.dirname(this.dest), this.files.dest);
file = file.replace(/\\/g, '/');
var code_map = this.node.toStringWithSourceMap({
file: path.relative(path.dirname(this.dest), this.files.dest)
file: file
});
// Consume the new sourcemap.
var generator = SourceMapGenerator.fromSourceMap(
Expand Down

0 comments on commit 0bd3211

Please sign in to comment.