substack/node-browserify — pull request #282 by tristanls (2013-02-05 05:46:18+00:00)
Title: Implemented bundle.insert() that works like bundle.append() but before adding entry points

First, `browserify` is awsome.

I'm using it to bundle code for use inside a sandbox environment. As such, some of the `require`'d modules are provided by the environment.

When I have code like:
`index.js`
```javascript
var fromBrowserify = require( './myFile.js' ),
fromSandbox = require( 'magic-sandbox-string' );

// do stuff...
```

I would like to be able to `require.define( 'magic-sandbox-string', function (...` before the code above is bundled.

`bundle.prepend()` doesn't do this.
`bundle.append()` attaches the `require.define(..` code, but it only after generating above code, like so:

```javascript
// ...
require.define("/index.js", function( /* ... */ ) {
// ...
});
require("/index.js");

require.define( 'magic-sandbox-string', function(){} );
})();
```

What `bundle.insert()` does, is place the code where it can be used before final `require("/index.js");`, like so:

```javascript
// ...
require.define( 'magic-sandbox-string', function(){} );
require.define("/index.js", function( /* ... */ ) {
// ...
});
require("/index.js");
})();
```

I'm happy to write tests if you could give me a pointer as to where. I couldn't locate tests for `append` and `prepend`.

Cheers!

Tristan