From 12f8db986359efe83dd7d0ca58c21b1c8b37e6de Mon Sep 17 00:00:00 2001 From: Daphne Maddox Date: Wed, 24 Dec 2014 21:14:44 -0800 Subject: [PATCH] update to node-sass version 2 beta Peg node-sass dependency at "2.0.0-beta". node-sass version 2 is still in beta, be wary of this branch. Handle object output from node-sass, read `css` and `map` properties, consistent with node-sass v2 API. Simplify handling of file/data and sourceComments/sourceMap options. --- index.js | 32 ++++++++++++++------------------ package.json | 6 +++--- test/test.js | 8 ++++---- 3 files changed, 21 insertions(+), 25 deletions(-) diff --git a/index.js b/index.js index 8c4e2a0af..9efd62dd0 100644 --- a/index.js +++ b/index.js @@ -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) { @@ -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) { @@ -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); @@ -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); } diff --git a/package.json b/package.json index c8ebb1a23..d8337ecec 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/test.js b/test/test.js index 06c6b0657..9064a2923 100644 --- a/test/test.js +++ b/test/test.js @@ -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(); }); @@ -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(); }); @@ -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(); }});