babel-middleware
Advanced tools
Comparing version 0.2.0 to 0.2.1
22
index.js
@@ -1,4 +0,6 @@ | ||
var babel = require('babel-core'); | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var crypto = require('crypto'); | ||
var babel = require('babel-core'); | ||
var micromatch = require('micromatch'); | ||
@@ -25,2 +27,3 @@ | ||
var exclude = options.exclude || []; | ||
var debug = options.debug || false; | ||
@@ -41,8 +44,14 @@ // filename to last known hash map | ||
function log() { | ||
if (debug) { | ||
console.log.apply(undefined, arguments); | ||
} | ||
} | ||
function pathForHash(hash) { | ||
return cachePath + '/' + hash + '.js'; | ||
return path.resolve(cachePath + '/' + hash + '.js'); | ||
} | ||
return function(req, res, next) { | ||
var src = srcPath + '/' + req.path; // XXX Need the correct path | ||
var src = path.resolve(srcPath + '/' + req.path); // XXX Need the correct path | ||
var hash = fileLastModifiedHash(src); | ||
@@ -54,3 +63,3 @@ var lastKnownHash = hashMap[src]; | ||
if (micromatch.any(req.path.replace(/^\/+|\/+$/g, ''), exclude)) { | ||
console.log('Excluded: %s (%s)', req.path, exclude); | ||
log('Excluded: %s (%s)', req.path, exclude); | ||
res.append('X-Babel-Cache', false); | ||
@@ -66,2 +75,4 @@ res.sendFile(src, {}, function(err) { | ||
log('Preparing: %s (%s)', src, hash); | ||
res.append('X-Babel-Cache', true); | ||
@@ -101,5 +112,7 @@ res.append('X-Babel-Cache-Hash', hash); | ||
if (isMemoryCache) { | ||
log('Serving (cached): %s', src); | ||
res.write(cacheMap[hash]); | ||
res.end(); | ||
} else { | ||
log('Serving (cached): %s', hashPath); | ||
res.sendFile(hashPath, {}, function(err) { | ||
@@ -145,2 +158,3 @@ if (err) { | ||
} | ||
log('Serving (uncached): %s', src); | ||
res.write(code); | ||
@@ -147,0 +161,0 @@ res.end(); |
{ | ||
"name": "babel-middleware", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Express/Connect middleware to pre-process requested JS files through Babel", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -45,2 +45,7 @@ babel-middleware | ||
### `debug: true|false` | ||
Print debug output. | ||
Default: _false_ | ||
LICENSE | ||
@@ -47,0 +52,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
27611
392
54