@@ -22,16 +22,11 @@ module.exports = function (options) {
22
22
}
23
23
24
24
if ( file . sourceMap ) {
25
- opts . sourceComments = 'map' ;
26
25
opts . sourceMap = file . path ;
27
26
}
28
27
29
- if ( opts . sourceComments === 'map' || opts . sourceComments === 'normal' ) {
30
- opts . sourceMap = opts . sourceMap || '' ;
31
- opts . file = file . path ;
32
- } else {
33
- opts . data = file . contents . toString ( ) ;
34
- }
28
+ opts . data = file . contents . toString ( ) ;
29
+ opts . file = file . path ;
35
30
36
31
if ( opts . includePaths && Array . isArray ( opts . includePaths ) ) {
37
32
if ( opts . includePaths . indexOf ( fileDir ) === - 1 ) {
@@ -41,26 +36,27 @@ module.exports = function (options) {
41
36
opts . includePaths = [ fileDir ] ;
42
37
}
43
38
44
- opts . success = function ( css , sourceMap ) {
45
- if ( typeof opts . onSuccess === 'function' ) opts . onSuccess ( css , sourceMap ) ;
39
+ opts . success = function ( obj ) {
40
+ if ( typeof opts . onSuccess === 'function' ) opts . onSuccess ( obj ) ;
46
41
47
- if ( sourceMap ) {
42
+ if ( obj . map && obj . map . length || obj . map . version ) {
48
43
// hack to remove the already added sourceMappingURL from libsass
49
- css = css . replace ( / \/ \* # \s * s o u r c e M a p p i n g U R L \= .* \* \/ / , '' ) ;
44
+ obj . css = obj . css . replace ( / \/ \* # \s * s o u r c e M a p p i n g U R L \= .* \* \/ / , '' ) ;
50
45
51
46
// libsass gives us sources' paths relative to file;
52
47
// gulp-sourcemaps needs sources' paths relative to file.base;
53
48
// so alter the sources' paths to please gulp-sourcemaps.
54
- sourceMap = JSON . parse ( sourceMap ) ;
55
- sourceMap . sources = sourceMap . sources . map ( function ( source ) {
49
+ obj . map = obj . map . version ? obj . map : JSON . parse ( sourceMap ) ;
50
+ obj . map . sources = obj . map . sources . map ( function ( source ) {
56
51
var abs = path . resolve ( path . dirname ( file . path ) , source ) ;
57
52
return path . relative ( file . base , abs ) ;
58
53
} ) ;
59
- sourceMap = JSON . stringify ( sourceMap ) ;
54
+ obj . map = JSON . stringify ( obj . map ) ;
60
55
61
- applySourceMap ( file , sourceMap ) ;
56
+ applySourceMap ( file , obj . map ) ;
62
57
}
63
- handleOutput ( css , file , cb ) ;
58
+
59
+ handleOutput ( obj , file , cb ) ;
64
60
} ;
65
61
66
62
opts . error = function ( err ) {
@@ -80,7 +76,7 @@ module.exports = function (options) {
80
76
if ( opts . sync ) {
81
77
try {
82
78
var output = nodeSass . renderSync ( opts ) ;
83
- opts . success ( output , null ) ;
79
+ opts . success ( output ) ;
84
80
handleOutput ( output , file , cb ) ;
85
81
} catch ( err ) {
86
82
opts . error ( err ) ;
@@ -96,7 +92,7 @@ module.exports = function (options) {
96
92
97
93
function handleOutput ( output , file , cb ) {
98
94
file . path = ext ( file . path , '.css' ) ;
99
- file . contents = new Buffer ( output ) ;
95
+ file . contents = new Buffer ( output . css ) ;
100
96
cb ( null , file ) ;
101
97
}
102
98
0 commit comments