Commit b4cc20a9 by Andrew Nesbitt

Merge pull request #344 from timrwood/fix-source-map-urls

Make sourceMap sources paths relative to the sourceMap location.
parents a63cc366 c5abc621
......@@ -140,6 +140,14 @@ exports.renderSync = function(options) {
return output;
};
var makeSourceMapUrlsRelative = function (sourceMap, dir) {
var map = JSON.parse(sourceMap);
map.sources = map.sources.map(function (source) {
return path.relative(dir, source);
});
return JSON.stringify(map);
};
/**
Same as `render()` but with an extra `outFile` property in `options` and writes
the CSS and sourceMap (if requested) to the filesystem.
......@@ -170,6 +178,7 @@ exports.renderFile = function(options) {
if (options.sourceMap) {
dir = path.dirname(options.outFile);
sourceMapFile = path.resolve(dir, options.sourceMap);
sourceMap = makeSourceMapUrlsRelative(sourceMap, path.dirname(sourceMapFile));
fs.writeFile(sourceMapFile, sourceMap, function(err) {
if (err) {
return options.error(err);
......
......@@ -260,6 +260,26 @@ describe('render to file', function() {
});
});
it('should save source paths relative to the sourceMap file', function(done) {
var includedFilesFile = path.resolve(__dirname, 'included_files.scss');
var relativeOutFile = path.resolve(__dirname, 'some_path/out.scss');
sass.renderFile({
file: includedFilesFile,
outFile: relativeOutFile,
sourceMap: true,
success: function (cssFile, sourceMapFile) {
var mapObject = JSON.parse(filesWritten[sourceMapFile]);
assert.ok(mapObject.sources.indexOf('../included_files.scss') > -1);
assert.ok(mapObject.sources.indexOf('../sample.scss') > -1);
assert.ok(mapObject.sources.indexOf('../image_path.scss') > -1);
done();
},
error: function (error) {
done(error);
}
});
});
});
describe('precision support', function() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment