@@ -125,6 +125,11 @@ function tryExtensions(p, exts) {
125
125
}
126
126
127
127
128
+ const noopDeprecateRequireDot = util . deprecate ( function ( ) { } ,
129
+ `warning: require('.') did resolve outside the package directory. ` +
130
+ `This functionality will be deprecated soon.` ) ;
131
+
132
+
128
133
Module . _findPath = function ( request , paths ) {
129
134
var exts = Object . keys ( Module . _extensions ) ;
130
135
@@ -169,9 +174,8 @@ Module._findPath = function(request, paths) {
169
174
}
170
175
171
176
if ( filename ) {
172
- if ( request === '.' && i > 0 ) {
173
- console . error ( `(node) warning: require('.') resolved to ${ filename } ` ) ;
174
- }
177
+ // Warn once if '.' resolved outside the module dir
178
+ if ( request === '.' && i > 0 ) noopDeprecateRequireDot ( ) ;
175
179
Module . _pathCache [ cacheKey ] = filename ;
176
180
return filename ;
177
181
}
@@ -215,11 +219,14 @@ Module._resolveLookupPaths = function(request, parent) {
215
219
paths = parent . paths . concat ( paths ) ;
216
220
}
217
221
218
- // For '.', put the module's dir at the front of the resolve paths
219
- // TODO(silverwind): Treat '.' exactly the same as './'
222
+ // Maintain backwards compat with certain broken uses of require('.')
223
+ // by putting the module's directory in front of the lookup paths.
220
224
if ( request === '.' ) {
221
- paths . splice ( 0 , 0 , parent && parent . filename ?
222
- path . dirname ( parent . filename ) : path . resolve ( request ) ) ;
225
+ if ( parent && parent . filename ) {
226
+ paths . splice ( 0 , 0 , path . dirname ( parent . filename ) ) ;
227
+ } else {
228
+ paths . splice ( 0 , 0 , path . resolve ( request ) ) ;
229
+ }
223
230
}
224
231
225
232
return [ request , paths ] ;
0 commit comments