var blanket =  require("./blanket").blanket;
//not completed, still needs a lot of work.
module.exports = function(subdir){
    var fs = require("fs");
    var oldLoader = require.extensions['.js'];
    var path = require("path");

    //you can pass in a string, a regex, or an array of files
    function matchPattern(filename){
        if (typeof subdir === 'string'){
            return filename.indexOf(subdir) > -1;
        }else if ( subdir instanceof Array ){
            return subdir.some(function(elem){
                return filename.indexOf(elem) > -1;
            });
        }else if (subdir instanceof RegExp){
            return subdir.test(filename);
        }else{
            throw Error("Bad file instrument indicator.  Must be a string, regex, or array.");
        }
    }

    //find current scripts
    require.extensions['.js'] = function(localModule, filename) {
        if (matchPattern(filename)){
            var content = fs.readFileSync(filename, 'utf8');
            blanket.instrument({
                inputFile: content,
                inputFileName: filename
            },function(instrumented){
                try{
                    instrumented = instrumented.replace(/require\("./g,"require(\""+path.dirname(filename)+"/.").replace(/require\('./g,"require('"+path.dirname(filename)+"/.");
                    
                    //try returning the module without exports first
                    var ret = eval(instrumented);
                    //We need to wrap the instrumented code in a closure
                    //in order to be able to correctly return the
                    //exports object from the eval
                    if (typeof ret !== 'undefined'){
                        var startWrapper = "(function(){\n";
                        var endWrapper = "\nreturn module.exports; })();";
                        ret = eval(startWrapper+instrumented+endWrapper);
                    }
                    
                    
                    //pass the exports back to the require statement
                    //that initiated all of this.
                    localModule.exports =  ret;
                }
                catch(err){
                    console.log("Error parsing instrumented code: "+err);
                }
            });
        }else{
            oldLoader(localModule,filename);
        }
    };
};

@@ -38,16 +38,93 @@
 lanket;%0A
+%0Afunction normalizeBackslashes(str) %7B%0A    return str.replace(/%5C%5C/g, '/');%0A%7D%0A%0A
 //not co
@@ -478,23 +478,45 @@
 indexOf(
+normalizeBackslashes(
 subdir)
+)
  %3E -1;%0A 
@@ -647,21 +647,43 @@
 indexOf(
+normalizeBackslashes(
 elem)
+)
  %3E -1;%0A 
@@ -1000,24 +1000,75 @@
 filename) %7B%0A
+        filename = normalizeBackslashes(filename);%0A
         if (
@@ -1300,16 +1300,103 @@
 ented)%7B%0A
+                var baseDirPath = normalizeBackslashes(path.dirname(filename)) + '/.';%0A
         
@@ -1479,25 +1479,25 @@
 e%5C(%22./g,
-%22
+'
 require(
 %5C%22%22+path
@@ -1492,40 +1492,72 @@
 ire(
-%5C%22%22+path.dirname(filename)+%22/.%22)
+%22'+baseDirPath);%0A                    instrumented = instrumented
 .rep
@@ -1592,35 +1592,19 @@
 ('%22+
-path.dirname(filename)+%22/.%22
+baseDirPath
 );%0A 

Normalize backslashes (by changing `\` to `/`) so node.js coverage can be run on Windows.