Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify sourcemap paths of imported files #320

Merged
merged 4 commits into from Sep 19, 2015
Merged
Show file tree
Hide file tree
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
15 changes: 14 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ var gulpSass = function gulpSass(options, sync) {
if (file.sourceMap) {
opts.sourceMap = file.path;
opts.omitSourceMapUrl = true;
opts.sourceMapContents = true;
}

//////////////////////////////
Expand All @@ -65,7 +66,9 @@ var gulpSass = function gulpSass(options, sync) {
filePush = function filePush(sassObj) {
var sassMap,
sassMapFile,
sassFileSrc;
sassFileSrc,
sassFileSrcPath,
sourceFileIndex;

// Build Source Maps!
if (sassObj.map) {
Expand All @@ -75,6 +78,16 @@ var gulpSass = function gulpSass(options, sync) {
sassMapFile = sassMap.file.replace('stdout', 'stdin');
// Grab the base file name that's being worked on
sassFileSrc = file.relative;
// Grab the path portion of the file that's being worked on
sassFileSrcPath = path.dirname(sassFileSrc);
if (sassFileSrcPath) {
//Prepend the path to all files in the sources array except the file that's being worked on
for (sourceFileIndex = 0; sourceFileIndex < sassMap.sources.length; sourceFileIndex++) {
if (sourceFileIndex !== sassMap.sources.indexOf(sassMapFile)) {
sassMap.sources[sourceFileIndex] = path.join(sassFileSrcPath, sassMap.sources[sourceFileIndex]);
}
}
}
// Replace the stdin with the original file name
sassMap.sources[sassMap.sources.indexOf(sassMapFile)] = sassFileSrc;
// Replace the map file with the original file name (but new extension)
Expand Down
4 changes: 2 additions & 2 deletions test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,8 @@ describe('gulp-sass -- sync compile', function() {

it('should work with gulp-sourcemaps and autoprefixer with different file.base', function(done) {
var expectedSources = [
'includes/_cats.scss',
'includes/_dogs.sass',
'scss/includes/_cats.scss',
'scss/includes/_dogs.sass',
'scss/inheritance.scss'
];

Expand Down