substack/node-browserify — pull request #94 by znerol (2011-11-26 20:17:31+00:00)
Title: Fix loading toplevel directory from subdir in prelude

Consider the following package structure:

* package.json:

{ "name":"testpkg",
"main":"./index.js",
"browserify":"./browser.js"
}

* index.js:

exports.stuff = 'for node';

* browser.js:

exports.stuff = 'for browser';
window.onload = function() {
alert('code loaded, it works!');
}

* entry.js:

require('./subdir/require-super');

* subdir/require-super.js:

require('../');

When running the browsified version of entry.js in a browser, the following error is thrown:

Uncaught Error: Cannot find module '../'

The loadAsDirectory function of the prelude script prepended to browserified modules strips off trailing slashes before concatenating the argument with '/package.js' and '/index'. If the argument is a single slash, i.e. a path pointing to the root directory, it should be preserved when passing to path.resolve subsequently.

Fix this problem by stripping off trailing slashes only for package/index lookup.