Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

making require fully sync, fixing bug requiring from main index

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

0 comments on commit 872874d

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