From 9cb5f1cb5cd70d63a5bf362da733d4c67cffe31a Mon Sep 17 00:00:00 2001 From: Martin O'Connor Date: Thu, 30 Jul 2015 12:33:15 -0400 Subject: [PATCH 1/3] Modify sourcemap paths of imported files relative to file.base instead of relative to file, if a different base is specified. --- index.js | 15 ++++++++++++++- test/main.js | 4 ++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index f881870..22d8270 100644 --- a/index.js +++ b/index.js @@ -57,6 +57,7 @@ var gulpSass = function gulpSass(options, sync) { if (file.sourceMap) { opts.sourceMap = file.path; opts.omitSourceMapUrl = true; + opts.sourceMapContents = true; } ////////////////////////////// @@ -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) { @@ -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 = sassFileSrc.substring(0, sassFileSrc.lastIndexOf('/')); + 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] = 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) diff --git a/test/main.js b/test/main.js index 5411621..f08ca36 100644 --- a/test/main.js +++ b/test/main.js @@ -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' ]; From fb26b3a2591e6a3f61b94159862134957ee64fc2 Mon Sep 17 00:00:00 2001 From: Martin O'Connor Date: Thu, 30 Jul 2015 14:32:41 -0400 Subject: [PATCH 2/3] Update file processing to a cross platform solution --- index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 22d8270..83f3dab 100644 --- a/index.js +++ b/index.js @@ -79,12 +79,14 @@ var gulpSass = function gulpSass(options, sync) { // 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 = sassFileSrc.substring(0, sassFileSrc.lastIndexOf('/')); + sassFileSrcPath = sassFileSrc.split(path.sep); + sassFileSrcPath.pop(); + sassFileSrcPath = sassFileSrcPath.join(path.sep); 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] = sassFileSrcPath + '/' + sassMap.sources[sourceFileIndex]; + sassMap.sources[sourceFileIndex] = path.join(sassFileSrcPath, sassMap.sources[sourceFileIndex]); } } } From 77e66a795a37c6fa2238deb8a81b9a66f9cd75e7 Mon Sep 17 00:00:00 2001 From: Martin O'Connor Date: Thu, 30 Jul 2015 22:26:15 -0400 Subject: [PATCH 3/3] Use path.dirname for enhanced readability --- index.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/index.js b/index.js index 83f3dab..97f907d 100644 --- a/index.js +++ b/index.js @@ -79,9 +79,7 @@ var gulpSass = function gulpSass(options, sync) { // 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 = sassFileSrc.split(path.sep); - sassFileSrcPath.pop(); - sassFileSrcPath = sassFileSrcPath.join(path.sep); + 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++) {