Skip to content

Commit

Permalink
Merge pull request sass#159 from laurelnaiad/node-sass-v2
Browse files Browse the repository at this point in the history
update to node-sass version 2 beta
  • Loading branch information
dlmanning committed Jan 14, 2015
2 parents f390117 + 12f8db9 commit 6ff4042
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 25 deletions.
32 changes: 14 additions & 18 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,11 @@ module.exports = function (options) {
}

if (file.sourceMap) {
opts.sourceComments = 'map';
opts.sourceMap = file.path;
}

if (opts.sourceComments === 'map' || opts.sourceComments === 'normal') {
opts.sourceMap = opts.sourceMap || '';
opts.file = file.path;
} else {
opts.data = file.contents.toString();
}
opts.data = file.contents.toString();
opts.file = file.path;

if (opts.includePaths && Array.isArray(opts.includePaths)) {
if (opts.includePaths.indexOf(fileDir) === -1) {
Expand All @@ -41,26 +36,27 @@ module.exports = function (options) {
opts.includePaths = [fileDir];
}

opts.success = function (css, sourceMap) {
if (typeof opts.onSuccess === 'function') opts.onSuccess(css, sourceMap);
opts.success = function (obj) {
if (typeof opts.onSuccess === 'function') opts.onSuccess(obj);

if (sourceMap) {
if (obj.map && obj.map.length || obj.map.version) {
// hack to remove the already added sourceMappingURL from libsass
css = css.replace(/\/\*#\s*sourceMappingURL\=.*\*\//, '');
obj.css = obj.css.replace(/\/\*#\s*sourceMappingURL\=.*\*\//, '');

// libsass gives us sources' paths relative to file;
// gulp-sourcemaps needs sources' paths relative to file.base;
// so alter the sources' paths to please gulp-sourcemaps.
sourceMap = JSON.parse(sourceMap);
sourceMap.sources = sourceMap.sources.map(function(source) {
obj.map = obj.map.version ? obj.map : JSON.parse(sourceMap);
obj.map.sources = obj.map.sources.map(function(source) {
var abs = path.resolve(path.dirname(file.path), source);
return path.relative(file.base, abs);
});
sourceMap = JSON.stringify(sourceMap);
obj.map = JSON.stringify(obj.map);

applySourceMap(file, sourceMap);
applySourceMap(file, obj.map);
}
handleOutput(css, file, cb);

handleOutput(obj, file, cb);
};

opts.error = function (err) {
Expand All @@ -80,7 +76,7 @@ module.exports = function (options) {
if ( opts.sync ) {
try {
var output = nodeSass.renderSync(opts);
opts.success(output, null);
opts.success(output);
handleOutput(output, file, cb);
} catch(err) {
opts.error(err);
Expand All @@ -96,7 +92,7 @@ module.exports = function (options) {

function handleOutput(output, file, cb) {
file.path = ext(file.path, '.css');
file.contents = new Buffer(output);
file.contents = new Buffer(output.css);
cb(null, file);
}

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
"url": "https://github.com/dlmanning/gulp-sass/issues"
},
"dependencies": {
"node-sass": "^1.0",
"clone": "~0.1.18",
"gulp-util": "^3.0",
"map-stream": "~0.1",
"vinyl-sourcemaps-apply": "~0.1.1",
"clone": "~0.1.18"
"node-sass": "2.0.0-beta",
"vinyl-sourcemaps-apply": "~0.1.1"
},
"devDependencies": {
"tape": "~2.3",
Expand Down
8 changes: 4 additions & 4 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ test('emit error on sass errors', function (t) {
new Buffer('body { font \'Comic Sans\'; }'));
stream.on('error', function (err) {
t.equal(err.message,
'stdin:1: property "font" must be followed by a \':\'\n'
'property "font" must be followed by a \':\''
);
t.end();
});
Expand All @@ -144,7 +144,7 @@ test('emit error on sass errors when using sync true', function (t) {
new Buffer('body { font \'Comic Sans\'; }'));
stream.on('error', function (err) {
t.equal(err.message,
'stdin:1: property "font" must be followed by a \':\'\n'
'property "font" must be followed by a \':\''
);
t.end();
});
Expand All @@ -153,8 +153,8 @@ test('emit error on sass errors when using sync true', function (t) {

test('call custom error callback when opts.onError is given', function (t) {
var stream = gsass({ onError: function (err) {
t.equal(err,
'stdin:1: property "font" must be followed by a \':\'\n'
t.equal(err.message,
'property "font" must be followed by a \':\''
);
t.end();
}});
Expand Down

0 comments on commit 6ff4042

Please sign in to comment.