Skip to content

Commit 97b60c4

Browse files
committed
Better module dir detection, add warning
1 parent 685d6e5 commit 97b60c4

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

lib/module.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ Module._findPath = function(request, paths) {
169169
}
170170

171171
if (filename) {
172+
if (request === '.' && i > 0) {
173+
console.error(`(node) warning: require('.') resolved to ${filename}`);
174+
}
172175
Module._pathCache[cacheKey] = filename;
173176
return filename;
174177
}
@@ -210,12 +213,15 @@ Module._resolveLookupPaths = function(request, parent) {
210213
if (parent) {
211214
if (!parent.paths) parent.paths = [];
212215
paths = parent.paths.concat(paths);
213-
// For '.', put PWD at the front of the resolve paths
214-
// TODO(silverwind): Treat '.' exactly the same as './'
215-
if (request === '.') {
216-
paths.splice(0, 0, path.resolve(request));
217-
}
218216
}
217+
218+
// For '.', put the module's dir at the front of the resolve paths
219+
// TODO(silverwind): Treat '.' exactly the same as './'
220+
if (request === '.') {
221+
paths.splice(0, 0, parent && parent.filename ?
222+
path.dirname(parent.filename) : path.resolve('request'));
223+
}
224+
219225
return [request, paths];
220226
}
221227

0 commit comments

Comments
 (0)