@@ -18,6 +18,7 @@ var insertGlobals = require('insert-module-globals');
18
18
var umd = require ( 'umd' ) ;
19
19
var derequire = require ( 'derequire' ) ;
20
20
var commondir = require ( 'commondir' ) ;
21
+ var merge = require ( 'xtend' ) ;
21
22
22
23
var path = require ( 'path' ) ;
23
24
var inherits = require ( 'inherits' ) ;
@@ -27,6 +28,7 @@ var copy = require('shallow-copy');
27
28
28
29
var emptyModulePath = path . join ( __dirname , 'lib/_empty.js' ) ;
29
30
var excludeModulePath = path . join ( __dirname , 'lib/_exclude.js' ) ;
31
+ var processPath = require . resolve ( 'process/browser.js' ) ;
30
32
31
33
module . exports = function ( opts , xopts ) {
32
34
if ( opts === undefined ) opts = { } ;
@@ -120,7 +122,7 @@ Browserify.prototype._hash = function (id) {
120
122
var basedir = this . _basedir ;
121
123
if ( ! basedir ) basedir = process . cwd ( ) ;
122
124
return hash ( path . relative ( basedir , id ) ) ;
123
- }
125
+ } ;
124
126
125
127
Browserify . prototype . noParse = function ( file ) {
126
128
var self = this ;
@@ -308,11 +310,22 @@ Browserify.prototype.bundle = function (opts, cb) {
308
310
if ( self . _noParse . indexOf ( file ) >= 0 ) {
309
311
return through2 ( ) ;
310
312
}
311
- return insertGlobals ( file , {
313
+ var inserter = insertGlobals ( file , {
312
314
always : opts . insertGlobals ,
313
- vars : opts . insertGlobalVars ,
315
+ vars : merge ( {
316
+ process : function ( ) {
317
+ return 'require('
318
+ + JSON . stringify ( self . _hash ( processPath ) )
319
+ + ')' ;
320
+ }
321
+ } , opts . insertGlobalVars ) ,
314
322
basedir : basedir
315
323
} ) ;
324
+ inserter . on ( 'global' , function ( name ) {
325
+ if ( name !== 'process' ) return ;
326
+ self . _mapped [ self . _hash ( processPath ) ] = processPath ;
327
+ } ) ;
328
+ return inserter ;
316
329
} ] . concat ( self . _globalTransforms ) ;
317
330
}
318
331
else opts . globalTransform = self . _globalTransforms ;
@@ -747,7 +760,7 @@ Browserify.prototype._resolve = function (id, parent, cb) {
747
760
748
761
result ( file , pkg ) ;
749
762
} ) ;
750
-
763
+
751
764
function findPackage ( basedir , cb ) {
752
765
var dirs = parents ( basedir ) ;
753
766
( function next ( ) {
0 commit comments