Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Add support for Node 0.12 and node-sass 2.0. Fixes #23 #24

Merged
merged 2 commits into from
Feb 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: node_js
node_js:
- '0.10'
- '0.11'
- '0.12'
deploy:
provider: npm
email:
Expand Down
52 changes: 25 additions & 27 deletions middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ module.exports = function(options){
if (!src) { throw new Error('sass.middleware() requires "src" directory'); }

// Default dest dir to source
var dest = options.dest
? options.dest
: src;
var dest = options.dest || src;

var root = options.root || null;

Expand Down Expand Up @@ -111,31 +109,31 @@ module.exports = function(options){
var style = options.compile();
var paths = [];
delete imports[sassPath];
style.render(str, function(err, css){
if (err) { return next(err); }
if (debug) { log('render', options.response ? '<response>' : sassPath); }
imports[sassPath] = paths;

// If response is falsey, also write to file
if (!options.response) {
mkdirp(dirname(cssPath), 0700, function(err){
if (err) return error(err);
fs.writeFile(cssPath, css, 'utf8', function(err) {
if (err) return error(err);
});
});
}

res.writeHead(200, {
'Content-Type': 'text/css',
'Cache-Control': 'max-age=0'
});
res.end(css);
style.render({
data: str,
success: function(result){
if (debug) { log('render', options.response ? '<response>' : sassPath); }
imports[sassPath] = paths;

// If response is falsey, also write to file
if (!options.response) {
mkdirp(dirname(cssPath), 0700, function(err){
if (err) return error(err);
fs.writeFile(cssPath, result.css, 'utf8', function(err) {
if (err) return error(err);
});
});
}

}, {
include_paths: [ sassDir ].concat(options.include_paths || options.includePaths || []),
image_path: options.image_path || options.imagePath,
output_style: options.output_style || options.outputStyle
res.writeHead(200, {
'Content-Type': 'text/css',
'Cache-Control': 'max-age=0'
});
res.end(result.css);
},
includePaths: [ sassDir ].concat(options.include_paths || options.includePaths || []),
imagePath: options.image_path || options.imagePath,
outputStyle: options.output_style || options.outputStyle
});
});
};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
},
"dependencies": {
"mkdirp": "0.5.x",
"node-sass": "^1.0.0"
"node-sass": "^2.0.1"
},
"devDependencies": {
"connect": "^2.25.7",
Expand Down
10 changes: 5 additions & 5 deletions test/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,26 +54,26 @@ describe('Using middleware', function () {

it('serves the compiled contents of the relative scss file', function (done) {
var filesrc = fs.readFileSync(scssfile),
css = sass.renderSync(filesrc.toString());
result = sass.renderSync({ data: filesrc.toString() });
request(server)
.get('/test.css')
.expect(css)
.expect(result.css)
.expect(200, done);
});

it('writes the file contents out to the expected file', function (done) {
var filesrc = fs.readFileSync(scssfile),
css = sass.renderSync(filesrc.toString());
result = sass.renderSync({ data: filesrc.toString() });
request(server)
.get('/test.css')
.expect(css)
.expect(result.css)
.expect(200, function (err) {
if (err) {
done(err);
} else {
(function checkFile() {
if (fs.existsSync(cssfile)) {
fs.readFileSync(cssfile).toString().should.equal(css);
fs.readFileSync(cssfile).toString().should.equal(result.css);
done();
} else {
setTimeout(checkFile, 25);
Expand Down