.svn directory in lib/types/, lib/plugins/ and lib/patches/ causes error #3

Closed
relovution opened this Issue Jun 23, 2011 · 1 comment

Comments

Projects
None yet
2 participants

Hello,

I'm currently using mongoose-dbref. Since I am required to use SVN on this project, I discovered the following error when trying to run my app:

Error: Cannot find module './types/.'Error: Cannot find module './types/.'
    at Function._resolveFilename (module.js:322:11)
    at Function._load (module.js:267:25)
    at require (module.js:367:19)
    at /home/jan//node_modules/mongoose-dbref/lib/index.js:45:14
    at Array.forEach (native)
    at /home/jan//node_modules/mongoose-dbref/lib/index.js:41:9
    at Object.install (/home/jan//node_modules/mongoose-dbref/lib/index.js:119:17)
    at Object.init (/home/jan//config/init.js:65:24)
    at Object. (/home/jan//server.js:1:88)
    at Module._compile (module.js:423:26)
Cannot find module './types/.'

It is caused by lib/index.js at around line 40, when it tries to load all files in the lib/types/ directory. Since SVN places a .svn directory in every version controlled directory, this breaks, since .svn minus the three last characters results in . which leads to the error above. The same happens for lib/plugins/ and lib/patches/. One sample (not very pretty, but functional) fix might be:

Index: node_modules/mongoose-dbref/lib/index.js
===================================================================
--- node_modules/mongoose-dbref/lib/index.js    (revision 311)
+++ node_modules/mongoose-dbref/lib/index.js    (working copy)
@@ -38,10 +38,13 @@
    } else {
        var files = require("fs").readdirSync(__dirname + "/types");
        files.forEach(function(filename) {
-           var base = filename.slice(0, filename.length-3);
-           var val = require("./types/" + base).loadType(mongoose);
-           if (typeof val === 'function')
-               loaded[val.name] = val;
+           var ext = filename.slice(-3);
+           if (ext == ".js") {
+               var base = filename.slice(0, filename.length-3);
+               var val = require("./types/" + base).loadType(mongoose);
+               if (typeof val === 'function')
+                   loaded[val.name] = val;
+           }
        });
    }
    return loaded;
@@ -69,10 +72,13 @@
    } else {
        var files = require("fs").readdirSync(__dirname + "/plugins");
        files.forEach(function(filename) {
-           var base = filename.slice(0, filename.length-3);
-           var val = require("./plugins/" + base).install(mongoose);
-           if (typeof val === 'function')
-               loaded[val.name] = val;
+           var ext = filename.slice(-3);
+           if (ext == ".js") {
+               var base = filename.slice(0, filename.length-3);
+               var val = require("./plugins/" + base).install(mongoose);
+               if (typeof val === 'function')
+                   loaded[val.name] = val;
+           }
        });
    }
    return loaded;
@@ -96,8 +102,11 @@
    } else {
        var files = require("fs").readdirSync(__dirname + "/patches");
        files.forEach(function(filename) {
-           var base = filename.slice(0, filename.length-3);
-           require("./patches/" + base).install(mongoose);
+           var ext = filename.slice(-3);
+           if (ext == ".js") {
+               var base = filename.slice(0, filename.length-3);
+               require("./patches/" + base).install(mongoose);
+           }
        });
    }
 }

Please let me know what you think. (Sorry that I have the "patch" only in this comment right now..)

Owner

goulash1971 commented Jun 24, 2011

It might not be pretty but i works - so I've updated the index.js with your changes (thanks !) and I've also added teh ability for a filter Function to be passed into the install methods so that more complex exclusions can occur (such as lstating directories etc).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment