Browse Source

The return of absolute Module loading

v0.7.4-release
Felix Geisendörfer 15 years ago
committed by Ryan Dahl
parent
commit
7069bee982
  1. 48
      src/node.js
  2. 4
      test/mjsunit/test-module-loading.js

48
src/node.js

@ -305,38 +305,34 @@ function findModulePath (id, dirs, callback) {
var dir = dirs[0]; var dir = dirs[0];
var rest = dirs.slice(1, dirs.length); var rest = dirs.slice(1, dirs.length);
var js = path.join(dir, id + ".js"); if (id.charAt(0) == '/') {
var addon = path.join(dir, id + ".node"); dir = '';
var indexJs = path.join(dir, id, "index.js"); rest = [];
var indexAddon = path.join(dir, id, "index.addon"); }
// TODO clean up the following atrocity!
path.exists(js, function (found) { var locations = [
if (found) { path.join(dir, id + ".js"),
callback(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; return;
} }
path.exists(addon, function (found) {
path.exists(location, function (found) {
if (found) { if (found) {
callback(addon); callback(location);
return; return;
} }
path.exists(indexJs, function (found) { searchLocations();
if (found) { })
callback(indexJs); };
return; searchLocations();
}
path.exists(indexAddon, function (found) {
if (found) {
callback(indexAddon);
return;
}
findModulePath(id, rest, callback);
});
});
});
});
} }
function loadModule (request, parent) { function loadModule (request, parent) {

4
test/mjsunit/test-module-loading.js

@ -5,6 +5,7 @@ debug("load test-module-loading.js");
var a = require("./fixtures/a"); var a = require("./fixtures/a");
var d = require("./fixtures/b/d"); var d = require("./fixtures/b/d");
var d2 = 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."); assertFalse(false, "testing the test program.");
@ -23,6 +24,9 @@ assertEquals("D", d.D());
assertInstanceof(d2.D, Function); assertInstanceof(d2.D, Function);
assertEquals("D", d2.D()); assertEquals("D", d2.D());
assertInstanceof(d3.D, Function);
assertEquals("D", d3.D());
process.addListener("exit", function () { process.addListener("exit", function () {
assertInstanceof(a.A, Function); assertInstanceof(a.A, Function);
assertEquals("A done", a.A()); assertEquals("A done", a.A());

Loading…
Cancel
Save