mirror of https://github.com/nodejs/node.git
parent
6bf294d71a
commit
2085909aeb
|
@ -179,7 +179,6 @@ function resolveModulePath(request, parent) {
|
|||
var id, paths;
|
||||
if (request.charAt(0) == "." && (request.charAt(1) == "/" || request.charAt(1) == ".")) {
|
||||
// Relative request
|
||||
debug("RELATIVE: requested:" + request + " set ID to: "+id+" from "+parent.id);
|
||||
|
||||
var exts = ['js', 'node'], ext;
|
||||
var extensions = Object.keys(extensionCache);
|
||||
|
@ -191,6 +190,12 @@ function resolveModulePath(request, parent) {
|
|||
var parentIdPath = path.dirname(parent.id +
|
||||
(path.basename(parent.filename).match(new RegExp('^index\\.(' + exts.join('|') + ')$')) ? "/" : ""));
|
||||
id = path.join(parentIdPath, request);
|
||||
// make sure require('./path') and require('path') get distinct ids, even
|
||||
// when called from the toplevel js file
|
||||
if (parentIdPath == '.' && ! id.match(new RegExp('/'))) {
|
||||
id = './' + id;
|
||||
}
|
||||
debug("RELATIVE: requested:" + request + " set ID to: "+id+" from "+parent.id);
|
||||
paths = [path.dirname(parent.filename)];
|
||||
} else {
|
||||
id = request;
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
// This is actually more a fixture than a test. It is used to make
|
||||
// sure that require('./path') and require('path') do different things.
|
||||
// It has to be in the same directory as the test 'test-module-loading.js'
|
||||
// and it has to have the same name as an internal module.
|
||||
exports.path_func = function() { return "path_func"}
|
|
@ -48,6 +48,13 @@ var root = require("../fixtures/cycles/root"),
|
|||
assert.equal(root.foo, foo);
|
||||
assert.equal(root.sayHello(), root.hello);
|
||||
|
||||
debug("test name clashes");
|
||||
// this one exists and should import the local module
|
||||
var my_path = require("./path");
|
||||
assert.equal(true, my_path.path_func instanceof Function);
|
||||
// this one does not exist and should throw
|
||||
assert.throws(function() { require("./utils")});
|
||||
|
||||
var errorThrown = false;
|
||||
try {
|
||||
require("../fixtures/throws_error");
|
||||
|
|
Loading…
Reference in New Issue