module: prioritize current directory for local lookup by phillipj · Pull Request #5689 · nodejs/node (original) (raw)
- Does
make -j8 test
(UNIX) orvcbuild test nosign
(Windows) pass with
this change (including linting)? - Is the commit message formatted according to CONTRIBUTING.md?
- If this change fixes a bug (or a performance problem), is a regression
test (or a benchmark) included? - Is a documentation update included (if this change modifies
existing APIs, or introduces new ones)?
Affected core subsystem(s)
module, test
Description of change
This fixes an issue reported in #5684 about module in node_modules
being preferred over a local file with the same name, when resolved in repl (or --eval mode). The bug originates from the fact that Module._resolveLookupPaths()
puts node_modules before the current directory when run from repl or --eval.
Previous results from Module._resolveLookupPaths('./lodash')
:
[ './lodash', [ '/Users/phillipj/Dev/repl-lookup-test/node_modules', '/Users/phillipj/Dev/node_modules', '/Users/phillipj/node_modules', '/Users/node_modules', '/node_modules', '.', '/Users/phillipj/.node_modules', '/Users/phillipj/.node_libraries', '/Users/phillipj/Dev/node/out/lib/node' ] ]
Fixed results from Module._resolveLookupPaths('./lodash')
:
[ './lodash', [ '.', '/Users/phillipj/Dev/repl-lookup-test/node_modules', '/Users/phillipj/Dev/node_modules', '/Users/phillipj/node_modules', '/Users/node_modules', '/node_modules', '/Users/phillipj/.node_modules', '/Users/phillipj/.node_libraries', '/Users/phillipj/Dev/node/out/lib/node' ] ]