Commit c5abc621 by Tim Wood

Make sourceMap sources paths relative to the sourceMap file location.

parent d918895d
......@@ -132,6 +132,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.
......@@ -162,6 +170,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