From 31a3218ae668a11266f8dfaaf8337a0cac38a6a3 Mon Sep 17 00:00:00 2001 From: Eugene ONeill Date: Tue, 29 Sep 2015 19:17:23 -0700 Subject: [PATCH 1/3] add the .file property to options before handing off to node-sass --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index adb4c10..f96bc0b 100644 --- a/index.js +++ b/index.js @@ -36,6 +36,7 @@ var gulpSass = function gulpSass(options, sync) { opts = assign({}, options); opts.data = file.contents.toString(); + opts.file = file.path; // Ensure `indentedSyntax` is true if a `.sass` file if (path.extname(file.path) === '.sass') { From 058b42c80aa0540c52cae1484c6472d972f8ffe7 Mon Sep 17 00:00:00 2001 From: Eugene ONeill Date: Thu, 1 Oct 2015 16:40:45 -0700 Subject: [PATCH 2/3] remove unnecessary includePaths adjusts now that we're setting file property correctly --- index.js | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/index.js b/index.js index f96bc0b..4bc06d3 100644 --- a/index.js +++ b/index.js @@ -36,6 +36,8 @@ var gulpSass = function gulpSass(options, sync) { opts = assign({}, options); opts.data = file.contents.toString(); + + // we set the file path here so that libsass can correctly resolve import paths opts.file = file.path; // Ensure `indentedSyntax` is true if a `.sass` file @@ -43,18 +45,6 @@ var gulpSass = function gulpSass(options, sync) { opts.indentedSyntax = true; } - // Ensure file's parent directory in the include path - if (opts.includePaths) { - if (typeof opts.includePaths === 'string') { - opts.includePaths = [opts.includePaths]; - } - } - else { - opts.includePaths = []; - } - - opts.includePaths.unshift(path.dirname(file.path)); - // Generate Source Maps if plugin source-map present if (file.sourceMap) { opts.sourceMap = file.path; From cc31400b553c639421df899d5d000e0ffc27b20a Mon Sep 17 00:00:00 2001 From: Eugene ONeill Date: Thu, 3 Dec 2015 15:43:08 -0800 Subject: [PATCH 3/3] fix sourcemap transform --- index.js | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/index.js b/index.js index 4bc06d3..0224526 100644 --- a/index.js +++ b/index.js @@ -60,35 +60,33 @@ var gulpSass = function gulpSass(options, sync) { sassMapFile, sassFileSrc, sassFileSrcPath, - sourceFileIndex, - filteredSources; + sourceFileIndex; // Build Source Maps! if (sassObj.map) { // Transform map into JSON sassMap = JSON.parse(sassObj.map.toString()); // Grab the stdout and transform it into stdin - sassMapFile = sassMap.file.replace('stdout', 'stdin'); + 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]); - } - } + sourceFileIndex = sassMap.sources.indexOf(sassMapFile); + sassMap.sources = sassMap.sources.map(function(source, index) { + return (index === sourceFileIndex) ? source : path.join(sassFileSrcPath, source); + }); } + // Remove 'stdin' from souces and replace with filenames! - filteredSources = sassMap.sources.filter(function(src) { - if (src.indexOf('stdin') === -1) { + sassMap.sources = sassMap.sources.filter(function(src) { + if (src !== 'stdin') { return src; } }); - sassMap.sources = filteredSources; - sassMap.sources.unshift(sassFileSrc); + // Replace the map file with the original file name (but new extension) sassMap.file = gutil.replaceExtension(sassFileSrc, '.css'); // Apply the map