Comparing version 1.0.0 to 1.1.0
25
index.js
@@ -51,10 +51,7 @@ var fs = require('fs') | ||
// hack to remove the already added sourceMappingURL from libsass | ||
css = css.replace(/\n\/\*#\s*sourceMappingURL\=.*\*\//, ''); | ||
css = css.replace(/\/\*#\s*sourceMappingURL\=.*\*\//, ''); | ||
applySourceMap(file, map); | ||
} | ||
file.path = ext(file.path, '.css'); | ||
file.contents = new Buffer(css); | ||
cb(null, file); | ||
handleOutput(css, file, cb); | ||
}; | ||
@@ -76,3 +73,13 @@ | ||
sass.render(opts); | ||
if ( opts.sync ) { | ||
try { | ||
var output = sass.renderSync(opts); | ||
opts.success(output, null); | ||
handleOutput(output, file, cb); | ||
} catch(err) { | ||
opts.error(err); | ||
} | ||
} else { | ||
sass.render(opts); | ||
} | ||
@@ -86,2 +93,8 @@ if (addedLocalDirPath) opts.includePaths.pop(); | ||
function handleOutput(output, file, cb) { | ||
file.path = ext(file.path, '.css'); | ||
file.contents = new Buffer(output); | ||
cb(null, file); | ||
} | ||
function getSourcesContent (sources) { | ||
@@ -88,0 +101,0 @@ sourcesContent = []; |
{ | ||
"name": "gulp-sass", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Gulp plugin for sass", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -45,2 +45,6 @@ [![Build Status](https://travis-ci.org/dlmanning/gulp-sass.svg?branch=master)](https://travis-ci.org/dlmanning/gulp-sass) | ||
#### `sync: true` | ||
If you pass `sync: true` into the options hash, sass.renderSync will be called, instead of sass.render. This should help when memory and/or cpu usage is getting very high when rendering many and/or big files. | ||
## Source Maps | ||
@@ -54,3 +58,3 @@ | ||
gulp.src('./scss/*.scss') | ||
.pipe(sourcemaps.init()); | ||
.pipe(sourcemaps.init()) | ||
.pipe(sass()) | ||
@@ -69,3 +73,3 @@ .pipe(sourcemaps.write()) | ||
gulp.src('./scss/*.scss') | ||
.pipe(sourcemaps.init()); | ||
.pipe(sourcemaps.init()) | ||
.pipe(sass()) | ||
@@ -72,0 +76,0 @@ .pipe(sourcemaps.write('./maps')) |
@@ -61,2 +61,22 @@ var assert = require('assert'); | ||
test('compile a single sass file synchronously', function (t) { | ||
var sassFile = createVinyl('mixins.scss'); | ||
var stream = gsass({sync: true}); | ||
stream.on('data', function (cssFile) { | ||
t.ok(cssFile, 'cssFile should exist'); | ||
t.ok(cssFile.path, 'cssFile.path should exist'); | ||
t.ok(cssFile.relative, 'cssFile.relative should exist'); | ||
t.ok(cssFile.contents, 'cssFile.contents should exist'); | ||
t.equal(cssFile.path, path.join(__dirname, 'scss', 'mixins.css')); | ||
t.equal( | ||
fs.readFileSync(path.join(__dirname, 'ref/mixins.css'), 'utf8'), | ||
cssFile.contents.toString(), | ||
'file compiles correctly to css' | ||
); | ||
t.end(); | ||
}) | ||
stream.write(sassFile); | ||
}); | ||
test('compile multiple sass files', function (t) { | ||
@@ -98,2 +118,15 @@ var files = [ | ||
test('emit error on sass errors when using sync true', function (t) { | ||
var stream = gsass({sync: true}); | ||
var errorFile = createVinyl('somefile.sass', | ||
new Buffer('body { font \'Comic Sans\'; }')); | ||
stream.on('error', function (err) { | ||
t.equal(err.message, | ||
'source string:1: error: property "font" must be followed by a \':\'\n' | ||
); | ||
t.end(); | ||
}); | ||
stream.write(errorFile); | ||
}); | ||
test('call custom error callback when opts.onError is given', function (t) { | ||
@@ -100,0 +133,0 @@ var stream = gsass({ onError: function (err) { |
13117
240
108