felixge (owner)

Revisions

  • 913185 felixge Sun Nov 01 15:35:01 -0800 2009
gist: 223797 Download_button fork
public
Public Clone URL: git://gist.github.com/223797.git
Embed All Files: show embed
0001-The-return-of-absolute-Module-loading.patch #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
From fadd798bb16e8ed013214e8fe59c0efc66153dfb Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Felix=20Geisend=C3=B6rfer?= <felix@debuggable.com>
Date: Mon, 2 Nov 2009 00:34:16 +0100
Subject: [PATCH] The return of absolute Module loading
 
---
 src/node.js | 48 ++++++++++++++++-------------------
 test/mjsunit/test-module-loading.js | 4 +++
 2 files changed, 26 insertions(+), 26 deletions(-)
 
diff --git a/src/node.js b/src/node.js
index 79866b0..2833a03 100644
--- a/src/node.js
+++ b/src/node.js
@@ -305,38 +305,34 @@ function findModulePath (id, dirs, callback) {
   var dir = dirs[0];
   var rest = dirs.slice(1, dirs.length);
 
- var js = path.join(dir, id + ".js");
- var addon = path.join(dir, id + ".node");
- var indexJs = path.join(dir, id, "index.js");
- var indexAddon = path.join(dir, id, "index.addon");
+ if (id.charAt(0) == '/') {
+ dir = '';
+ rest = [];
+ }
 
- // TODO clean up the following atrocity!
-
- path.exists(js, function (found) {
- if (found) {
- callback(js);
+ var locations = [
+ path.join(dir, id + ".js"),
+ path.join(dir, id + ".node"),
+ path.join(dir, id, "index.js"),
+ path.join(dir, id, "index.addon"),
+ ];
+
+ var searchLocations = function() {
+ var location = locations.shift();
+ if (location === undefined) {
+ findModulePath(id, rest, callback);
       return;
     }
- path.exists(addon, function (found) {
+
+ path.exists(location, function (found) {
       if (found) {
- callback(addon);
+ callback(location);
         return;
       }
- path.exists(indexJs, function (found) {
- if (found) {
- callback(indexJs);
- return;
- }
- path.exists(indexAddon, function (found) {
- if (found) {
- callback(indexAddon);
- return;
- }
- findModulePath(id, rest, callback);
- });
- });
- });
- });
+ searchLocations();
+ })
+ };
+ searchLocations();
 }
 
 function loadModule (request, parent) {
diff --git a/test/mjsunit/test-module-loading.js b/test/mjsunit/test-module-loading.js
index 9659005..769c1b4 100644
--- a/test/mjsunit/test-module-loading.js
+++ b/test/mjsunit/test-module-loading.js
@@ -5,6 +5,7 @@ debug("load test-module-loading.js");
 var a = require("./fixtures/a");
 var d = require("./fixtures/b/d");
 var d2 = require("./fixtures/b/d");
+var d3 = require(require('path').dirname(__filename)+"/fixtures/b/d");
 
 assertFalse(false, "testing the test program.");
 
@@ -23,6 +24,9 @@ assertEquals("D", d.D());
 assertInstanceof(d2.D, Function);
 assertEquals("D", d2.D());
 
+assertInstanceof(d3.D, Function);
+assertEquals("D", d3.D());
+
 process.addListener("exit", function () {
   assertInstanceof(a.A, Function);
   assertEquals("A done", a.A());
--
1.6.3.3