Skip to content

Commit 39246f6

Browse files
Mathias Buusisaacs
authored andcommitted
Closes nodejs#1177 remove one node_modules optimization
to better support certain project structures.
1 parent 88552c5 commit 39246f6

File tree

3 files changed

+2
-36
lines changed

3 files changed

+2
-36
lines changed

doc/api/modules.markdown

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ parent directory of the current module, and adds `/node_modules`, and
6868
attempts to load the module from that location.
6969

7070
If it is not found there, then it moves to the parent directory, and so
71-
on, until either the module is found, or the root of the tree is
72-
reached.
71+
on, until the root of the tree is reached.
7372

7473
For example, if the file at `'/home/ry/projects/foo.js'` called
7574
`require('bar.js')`, then node would look in the following locations, in
@@ -83,28 +82,6 @@ this order:
8382
This allows programs to localize their dependencies, so that they do not
8483
clash.
8584

86-
#### Optimizations to the `node_modules` Lookup Process
87-
88-
When there are many levels of nested dependencies, it is possible for
89-
these file trees to get fairly long. The following optimizations are thus
90-
made to the process.
91-
92-
First, `/node_modules` is never appended to a folder already ending in
93-
`/node_modules`.
94-
95-
Second, if the file calling `require()` is already inside a `node_modules`
96-
hierarchy, then the top-most `node_modules` folder is treated as the
97-
root of the search tree.
98-
99-
For example, if the file at
100-
`'/home/ry/projects/foo/node_modules/bar/node_modules/baz/quux.js'`
101-
called `require('asdf.js')`, then node would search the following
102-
locations:
103-
104-
* `/home/ry/projects/foo/node_modules/bar/node_modules/baz/node_modules/asdf.js`
105-
* `/home/ry/projects/foo/node_modules/bar/node_modules/asdf.js`
106-
* `/home/ry/projects/foo/node_modules/asdf.js`
107-
10885
### Folders as Modules
10986

11087
It is convenient to organize programs and libraries into self-contained

lib/module.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,7 @@ Module._nodeModulePaths = function(from) {
199199
var paths = [];
200200
var parts = from.split(splitRe);
201201

202-
var root = parts.indexOf('node_modules') - 1;
203-
if (root < 0) root = 0;
204-
205-
var tip = parts.length - 1;
206-
207-
for (var tip = parts.length - 1; tip >= root; tip --) {
202+
for (var tip = parts.length - 1; tip >= 0; tip --) {
208203
// don't search in .../node_modules/node_modules
209204
if (parts[tip] === 'node_modules') continue;
210205
var dir = parts.slice(0, tip + 1).concat('node_modules').join(joiner);

test/fixtures/node_modules/baz/index.js

Lines changed: 0 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)