Skip to content

Commit

Permalink
Better module dir detection, add warning
Browse files Browse the repository at this point in the history
  • Loading branch information
silverwind committed Apr 7, 2015
1 parent 685d6e5 commit 712e75c
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ Module._findPath = function(request, paths) {
}

if (filename) {
if (request === '.' && i > 0) {
console.error(`(node) warning: require('.') resolved to ${filename}`);
}
Module._pathCache[cacheKey] = filename;
return filename;
}
Expand Down Expand Up @@ -210,12 +213,15 @@ Module._resolveLookupPaths = function(request, parent) {
if (parent) {
if (!parent.paths) parent.paths = [];
paths = parent.paths.concat(paths);
// For '.', put PWD at the front of the resolve paths
// TODO(silverwind): Treat '.' exactly the same as './'
if (request === '.') {
paths.splice(0, 0, path.resolve(request));
}
}

// For '.', put the module's dir at the front of the resolve paths
// TODO(silverwind): Treat '.' exactly the same as './'
if (request === '.') {
paths.splice(0, 0, parent && parent.filename ?
path.dirname(parent.filename) : path.resolve(request));
}

return [request, paths];
}

Expand Down

0 comments on commit 712e75c

Please sign in to comment.