substack/node-browserify — pull request #127 by nateps (2012-04-21 06:55:04+00:00)
Title: fix relative file target to use deepest node_modules directory

In the case of nested node_modules where the file root is not just a prefix of the other path, browserify will calculate the wrong relative path for the module target. It properly includes the module source but then cannot find the module in the browser.

For example:

arguments to /lib/wrap.js/makeTarget:
file: `/projects/marketing/node_modules/derby-examples/node_modules/derby/lib/derby.browser.js`
root: `/projects/marketing/node_modules/derby-examples/chat/lib/chat`
returns: `/node_modules/derby-examples/node_modules/derby/lib/derby.browser.js`

when it should return
`/node_modules/derby/lib/derby.browser.js`

Instead of starting the target path after the first node_modules directory, using the deepest node_modules directory fixes the issue.