Created
January 21, 2015 22:34
-
-
Save gregglind/a6e636742a04274a9bf1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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