Browse Source

The return of relative module loading

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

2
src/node.js

@ -342,7 +342,7 @@ function loadModule (request, parent) {
debug("loadModule REQUEST " + JSON.stringify(request) + " parent: " + JSON.stringify(parent)); debug("loadModule REQUEST " + JSON.stringify(request) + " parent: " + JSON.stringify(parent));
var id, paths; var id, paths;
if (request.charAt(0) == "." && request.charAt(1) == "/") { if (request.charAt(0) == "." && (request.charAt(1) == "/" || request.charAt(1) == ".")) {
// Relative request // Relative request
id = path.join(path.dirname(parent.id), request); id = path.join(path.dirname(parent.id), request);
paths = [path.dirname(parent.filename)]; paths = [path.dirname(parent.filename)];

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

@ -5,7 +5,10 @@ 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");
// Absolute
var d3 = require(require('path').dirname(__filename)+"/fixtures/b/d"); var d3 = require(require('path').dirname(__filename)+"/fixtures/b/d");
// Relative
var d4 = require("../mjsunit/fixtures/b/d");
assertFalse(false, "testing the test program."); assertFalse(false, "testing the test program.");
@ -27,6 +30,9 @@ assertEquals("D", d2.D());
assertInstanceof(d3.D, Function); assertInstanceof(d3.D, Function);
assertEquals("D", d3.D()); assertEquals("D", d3.D());
assertInstanceof(d4.D, Function);
assertEquals("D", d4.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