Skip to content
Browse files

making require fully sync, fixing bug requiring from main index

  • Loading branch information...
1 parent 69ac342 commit 872874d9fdd690a192c71d5eb59c375b4435db13 @tblobaum committed Dec 25, 2011
View
26 index.js
@@ -4,29 +4,29 @@
* Copyright(c) Thomas Blobaum
* MIT Licensed
*/
-
+
function modulate (dirname, callback) {
- if (!callback) {
- var callback = dirname
- }
+ if (!callback)
+ callback = dirname
- if (typeof dirname == 'function') {
- var dirname = module.parent.paths[0].split("node_modules")[0]
- }
+ if (typeof dirname == 'function')
+ dirname = module.parent.paths[0].split("node_modules")[0]
+ console.log('requiring directory ... ', dirname)
var paths = require('findit').sync(dirname)
-
- paths.forEach(function (path) {
- if (!path.match(module.parent.id)) {
+ for (var l = paths.length, a=0; a < l; a++) {
+ var path = paths[a]
+ if (!path.match(module.parent.id) || module.parent.id === '.') {
var filename = path.split(dirname)[1].split(".js")[0]
+ console.log(' * ... ', filename)
callback(require(path), filename)
}
- })
-
- delete require.cache[__filename]
+ }
+
}
+delete require.cache[__filename]
module.exports = modulate
View
3 package.json
@@ -8,12 +8,13 @@
"url": "git://github.com/tblobaum/node-directory.git"
},
"scripts": {
- "test": "npm test"
+ "test": "node test/directory"
},
"engines": {
"node": "~0.6.1"
},
"dependencies": {
+ "sequence": "x",
"findit": "~0.1.2"
},
"devDependencies": {}
View
13 test/directory.js
@@ -0,0 +1,13 @@
+
+//require('tap')
+
+
+console.log('Testing node-directory...')
+
+var directory = require('../')
+
+directory(function (module, filename) {
+ console.log(filename)
+ this[filename] = module
+})
+
View
7 test/submodule/index.js
@@ -0,0 +1,7 @@
+
+console.log('submodule')
+
+require('directory')(function (module, filename) {
+ this[filename] = module
+})
+
View
7 test/submodule/submodule2/index.js
@@ -0,0 +1,7 @@
+
+console.log('submodule2')
+
+require('directory')(function (module, filename) {
+ this[filename] = module
+})
+
View
7 test/submodule/submodule2/submodule3/index.js
@@ -0,0 +1,7 @@
+
+console.log('submodule3')
+
+require('directory')(function (module, filename) {
+ this[filename] = module
+})
+
View
2 test/submodule/submodule2/submodule3/submodule4/hello.js
@@ -0,0 +1,2 @@
+
+console.log('Hello World')
View
7 test/submodule/submodule2/submodule3/submodule4/index.js
@@ -0,0 +1,7 @@
+
+console.log('submodule4')
+
+require('directory')(function (module, filename) {
+ this[filename] = module
+})
+

0 comments on commit 872874d

Please sign in to comment.
Something went wrong with that request. Please try again.