Merge pull request #353 from eoneill/master
Add the .file property to options before handing off to node-sass
This commit is contained in:
commit
74d6a1a6ab
37
index.js
37
index.js
|
@ -37,23 +37,14 @@ var gulpSass = function gulpSass(options, sync) {
|
||||||
opts = assign({}, options);
|
opts = assign({}, options);
|
||||||
opts.data = file.contents.toString();
|
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
|
// Ensure `indentedSyntax` is true if a `.sass` file
|
||||||
if (path.extname(file.path) === '.sass') {
|
if (path.extname(file.path) === '.sass') {
|
||||||
opts.indentedSyntax = true;
|
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
|
// Generate Source Maps if plugin source-map present
|
||||||
if (file.sourceMap) {
|
if (file.sourceMap) {
|
||||||
opts.sourceMap = file.path;
|
opts.sourceMap = file.path;
|
||||||
|
@ -69,35 +60,33 @@ var gulpSass = function gulpSass(options, sync) {
|
||||||
sassMapFile,
|
sassMapFile,
|
||||||
sassFileSrc,
|
sassFileSrc,
|
||||||
sassFileSrcPath,
|
sassFileSrcPath,
|
||||||
sourceFileIndex,
|
sourceFileIndex;
|
||||||
filteredSources;
|
|
||||||
|
|
||||||
// Build Source Maps!
|
// Build Source Maps!
|
||||||
if (sassObj.map) {
|
if (sassObj.map) {
|
||||||
// Transform map into JSON
|
// Transform map into JSON
|
||||||
sassMap = JSON.parse(sassObj.map.toString());
|
sassMap = JSON.parse(sassObj.map.toString());
|
||||||
// Grab the stdout and transform it into stdin
|
// 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
|
// Grab the base file name that's being worked on
|
||||||
sassFileSrc = file.relative;
|
sassFileSrc = file.relative;
|
||||||
// Grab the path portion of the file that's being worked on
|
// Grab the path portion of the file that's being worked on
|
||||||
sassFileSrcPath = path.dirname(sassFileSrc);
|
sassFileSrcPath = path.dirname(sassFileSrc);
|
||||||
if (sassFileSrcPath) {
|
if (sassFileSrcPath) {
|
||||||
//Prepend the path to all files in the sources array except the file that's being worked on
|
//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++) {
|
sourceFileIndex = sassMap.sources.indexOf(sassMapFile);
|
||||||
if (sourceFileIndex !== sassMap.sources.indexOf(sassMapFile)) {
|
sassMap.sources = sassMap.sources.map(function(source, index) {
|
||||||
sassMap.sources[sourceFileIndex] = path.join(sassFileSrcPath, sassMap.sources[sourceFileIndex]);
|
return (index === sourceFileIndex) ? source : path.join(sassFileSrcPath, source);
|
||||||
}
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove 'stdin' from souces and replace with filenames!
|
// Remove 'stdin' from souces and replace with filenames!
|
||||||
filteredSources = sassMap.sources.filter(function(src) {
|
sassMap.sources = sassMap.sources.filter(function(src) {
|
||||||
if (src.indexOf('stdin') === -1) {
|
if (src !== 'stdin') {
|
||||||
return src;
|
return src;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
sassMap.sources = filteredSources;
|
|
||||||
sassMap.sources.unshift(sassFileSrc);
|
|
||||||
// Replace the map file with the original file name (but new extension)
|
// Replace the map file with the original file name (but new extension)
|
||||||
sassMap.file = gutil.replaceExtension(sassFileSrc, '.css');
|
sassMap.file = gutil.replaceExtension(sassFileSrc, '.css');
|
||||||
// Apply the map
|
// Apply the map
|
||||||
|
|
Loading…
Reference in a new issue