node-sass-middleware
Advanced tools
Comparing version 0.8.0 to 0.9.0
@@ -60,5 +60,13 @@ "use strict"; | ||
var sassMiddlewareError = null; | ||
// This function will be called if something goes wrong | ||
var error = options.error || function() { }; | ||
var error = function(err) { | ||
if (options.error) { | ||
options.error(err); | ||
} | ||
sassMiddlewareError = err; | ||
}; | ||
// Source directory (required) | ||
@@ -136,50 +144,70 @@ var src = options.src || function() { | ||
return next(err); | ||
} else { | ||
data = result.css; | ||
} | ||
if (debug) { | ||
log('render', options.response ? '<response>' : sassPath); | ||
data = result.css; | ||
if (sourceMap) { | ||
log('render', this.options.sourceMap); | ||
if (debug) { | ||
log('render', options.response ? '<response>' : sassPath); | ||
if (sourceMap) { | ||
log('render', this.options.sourceMap); | ||
} | ||
} | ||
imports[sassPath] = result.stats.includedFiles; | ||
var cssDone = true; | ||
var sourceMapDone = true; | ||
function doneWriting() { | ||
if (cssDone && sourceMapDone) { | ||
if (options.response === false) { | ||
next(sassMiddlewareError); | ||
} else { | ||
res.writeHead(200, { | ||
'Content-Type': 'text/css', | ||
'Cache-Control': 'max-age=0' | ||
}); | ||
res.end(data); | ||
} | ||
} | ||
imports[sassPath] = result.stats.includedFiles; | ||
} | ||
// If response is falsey, also write to file | ||
if (!options.response) { | ||
mkdirp(dirname(cssPath), '0700', function(err) { | ||
// If response is falsey, also write to file | ||
if (!options.response) { | ||
cssDone = false; | ||
sourceMapDone = !sourceMap; | ||
mkdirp(dirname(cssPath), '0700', function(err) { | ||
if (err) { | ||
return error(err); | ||
} | ||
fs.writeFile(cssPath, data, 'utf8', function(err) { | ||
if (err) { | ||
return error(err); | ||
} | ||
cssDone = true; | ||
doneWriting(); | ||
}); | ||
}); | ||
fs.writeFile(cssPath, data, 'utf8', function(err) { | ||
if (sourceMap) { | ||
var sourceMapPath = this.options.sourceMap; | ||
mkdirp(dirname(sourceMapPath), '0700', function(err) { | ||
if (err) { | ||
return error(err); | ||
} | ||
fs.writeFile(sourceMapPath, result.map, 'utf8', function(err) { | ||
if (err) { | ||
return error(err); | ||
} | ||
sourceMapDone = true; | ||
doneWriting(); | ||
}); | ||
}); | ||
if (sourceMap) { | ||
var sourceMapPath = this.options.sourceMap; | ||
mkdirp(dirname(sourceMapPath), '0700', function(err) { | ||
if (err) { | ||
return error(err); | ||
} | ||
fs.writeFile(sourceMapPath, result.map, 'utf8', function(err) { | ||
if (err) { | ||
return error(err); | ||
} | ||
}); | ||
}); | ||
} | ||
} | ||
} else { | ||
doneWriting(); | ||
} | ||
res.writeHead(200, { | ||
'Content-Type': 'text/css', | ||
'Cache-Control': 'max-age=0' | ||
}); | ||
res.end(data); | ||
} | ||
@@ -186,0 +214,0 @@ |
@@ -5,3 +5,3 @@ { | ||
"description": "Connect middleware for node-sass", | ||
"version": "0.8.0", | ||
"version": "0.9.0", | ||
"scripts": { | ||
@@ -35,3 +35,3 @@ "test": "./node_modules/mocha/bin/mocha" | ||
"mkdirp": "^0.5.1", | ||
"node-sass": "^3.1.1" | ||
"node-sass": "^3.1.2" | ||
}, | ||
@@ -41,5 +41,5 @@ "devDependencies": { | ||
"mocha": "^2.2.5", | ||
"should": "^6.0.1", | ||
"should": "^6.0.3", | ||
"supertest": "^1.0.1" | ||
} | ||
} |
@@ -95,10 +95,8 @@ 'use strict'; | ||
} else { | ||
(function checkFile() { | ||
if (fs.existsSync(test_cssFile)) { | ||
fs.readFileSync(test_cssFile).toString().should.equal(result.css.toString()); | ||
done(); | ||
} else { | ||
setTimeout(checkFile, 25); | ||
} | ||
}()); | ||
if (fs.existsSync(test_cssFile)) { | ||
fs.readFileSync(test_cssFile).toString().should.equal(result.css.toString()); | ||
done(); | ||
} else { | ||
done(new Error('file was not written before request ends')); | ||
} | ||
} | ||
@@ -108,2 +106,30 @@ }); | ||
it('only writes the compiled contents out to the expected file without serving them', function(done) { | ||
var filesrc = fs.readFileSync(test_scssFile), | ||
result = sass.renderSync({ data: filesrc.toString() }), | ||
anotherResponse = 'something else', | ||
server = connect() | ||
.use(middleware({ | ||
response: false, | ||
src: __dirname, | ||
dest: __dirname | ||
})); | ||
server.use(function(req, res) { | ||
res.end(anotherResponse); | ||
}); | ||
request(server) | ||
.get('/test.css') | ||
.expect(anotherResponse) | ||
.expect(200, function (err) { | ||
if (err) { | ||
done(err); | ||
} else { | ||
fs.readFileSync(test_cssFile).toString().should.equal(result.css.toString()); | ||
done(); | ||
} | ||
}); | ||
}); | ||
}); | ||
@@ -110,0 +136,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31151
729
Updatednode-sass@^3.1.2