Skip to content

Instantly share code, notes, and snippets.

@gregglind
Created January 21, 2015 22:34
Show Gist options
  • Save gregglind/a6e636742a04274a9bf1 to your computer and use it in GitHub Desktop.
Save gregglind/a6e636742a04274a9bf1 to your computer and use it in GitHub Desktop.
var fs = require("fs"),
path = require("path");
module.exports = function(blanket){
var traceur = require("traceur");
var oldLoaderJS = require.extensions['.js'];
require.extensions['.js'] = function(localModule, filename) {
var pattern = blanket.options("filter");
filename = blanket.normalizeBackslashes(filename);
if (blanket.matchPattern(filename,pattern)){
var content = fs.readFileSync(filename, 'utf8');
content = traceur.compile(content, {});
blanket.instrument({
inputFile: content,
inputFileName: filename
},function(instrumented){
var baseDirPath = blanket.normalizeBackslashes(path.dirname(filename))+'/.';
try{
instrumented = instrumented.replace(/require\s*\(\s*("|')\./g,'require($1'+baseDirPath);
localModule._compile(instrumented, filename);
}
catch(err){
console.log("Error parsing instrumented code: "+err);
}
});
}else{
oldLoaderJS(localModule,filename);
}
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment