Skip to content

Commit

Permalink
Update middleware.js
Browse files Browse the repository at this point in the history
I believe a closing bracket in the wrong place is causing issue
#58

Edit by @am11: Removes the unnecessary `else` and return from if-block
early.
  • Loading branch information
Esther authored and am11 committed Sep 16, 2015
1 parent 56a4045 commit 22fa1d4
Showing 1 changed file with 77 additions and 77 deletions.
154 changes: 77 additions & 77 deletions middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,113 +106,113 @@ module.exports = function(options) {
}

if (!/\.css$/.test(path)) {
next();
} else {
var cssPath = join(dest, path),
sassPath = join(src, path.replace(/\.css$/, sassExtension)),
sassDir = dirname(sassPath);

if (root) {
cssPath = join(root, dest, path.replace(new RegExp('^' + dest), ''));
sassPath = join(root, src, path
.replace(new RegExp('^' + dest), '')
.replace(/\.css$/, sassExtension));
return next();
}

var cssPath = join(dest, path),
sassPath = join(src, path.replace(/\.css$/, sassExtension)),
sassDir = dirname(sassPath);
}

if (debug) {
log('source', sassPath);
log('dest', options.response ? '<response>' : cssPath);
}
if (root) {
cssPath = join(root, dest, path.replace(new RegExp('^' + dest), ''));
sassPath = join(root, src, path
.replace(new RegExp('^' + dest), '')
.replace(/\.css$/, sassExtension));
sassDir = dirname(sassPath);
}

// When render is done, respond to the request accordingly
var done = function(err, result) {
var data;
if (debug) {
log('source', sassPath);
log('dest', options.response ? '<response>' : cssPath);
}

if (err) {
var file = sassPath;
if (err.file && err.file != 'stdin') {
file = err.file;
}
// When render is done, respond to the request accordingly
var done = function(err, result) {
var data;

if (err) {
var file = sassPath;
if (err.file && err.file != 'stdin') {
file = err.file;
}

var fileLineColumn = file + ':' + err.line + ':' + err.column;
data = err.message.replace(/^ +/, '') + '\n\nin ' + fileLineColumn;
if (debug) logError(data);
var fileLineColumn = file + ':' + err.line + ':' + err.column;
data = err.message.replace(/^ +/, '') + '\n\nin ' + fileLineColumn;
if (debug) logError(data);

error(err);
error(err);

return next(err);
return next(err);
}

data = result.css;

if (debug) {
log('render', options.response ? '<response>' : sassPath);

if (sourceMap) {
log('render', this.options.sourceMap);
}
}
imports[sassPath] = result.stats.includedFiles;

data = result.css;
var cssDone = true;
var sourceMapDone = true;

if (debug) {
log('render', options.response ? '<response>' : sassPath);
function doneWriting() {
if (!cssDone || !sourceMapDone) {
return;
}

if (sourceMap) {
log('render', this.options.sourceMap);
}
if (options.response === false) {
return next(sassMiddlewareError);
}
imports[sassPath] = result.stats.includedFiles;

var cssDone = true;
var sourceMapDone = true;
res.writeHead(200, {
'Content-Type': 'text/css',
'Cache-Control': 'max-age=0'
});
res.end(data);
}

function doneWriting() {
if (!cssDone || !sourceMapDone) {
return;
}
// If response is falsey, also write to file
if (options.response) {
return doneWriting();
}

if (options.response === false) {
return next(sassMiddlewareError);
}
cssDone = false;
sourceMapDone = !sourceMap;

res.writeHead(200, {
'Content-Type': 'text/css',
'Cache-Control': 'max-age=0'
});
res.end(data);
mkdirp(dirname(cssPath), '0700', function(err) {
if (err) {
return error(err);
}

// If response is falsey, also write to file
if (options.response) {
return doneWriting();
}
fs.writeFile(cssPath, data, 'utf8', function(err) {
if (err) {
return error(err);
}

cssDone = false;
sourceMapDone = !sourceMap;
cssDone = true;
doneWriting();
});
});

mkdirp(dirname(cssPath), '0700', function(err) {
if (sourceMap) {
var sourceMapPath = this.options.sourceMap;
mkdirp(dirname(sourceMapPath), '0700', function(err) {
if (err) {
return error(err);
}

fs.writeFile(cssPath, data, 'utf8', function(err) {
fs.writeFile(sourceMapPath, result.map, 'utf8', function(err) {
if (err) {
return error(err);
}

cssDone = true;
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);
}
sourceMapDone = true;
doneWriting();
});
});
}
}
}

Expand Down

0 comments on commit 22fa1d4

Please sign in to comment.