Skip to content

Commit 1296ced

Browse files
author
James Halliday
committed
fix for the process path leak test
1 parent 282b0db commit 1296ced

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

index.js

+17-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ var insertGlobals = require('insert-module-globals');
1818
var umd = require('umd');
1919
var derequire = require('derequire');
2020
var commondir = require('commondir');
21+
var merge = require('xtend');
2122

2223
var path = require('path');
2324
var inherits = require('inherits');
@@ -27,6 +28,7 @@ var copy = require('shallow-copy');
2728

2829
var emptyModulePath = path.join(__dirname, 'lib/_empty.js');
2930
var excludeModulePath = path.join(__dirname, 'lib/_exclude.js');
31+
var processPath = require.resolve('process/browser.js');
3032

3133
module.exports = function (opts, xopts) {
3234
if (opts === undefined) opts = {};
@@ -120,7 +122,7 @@ Browserify.prototype._hash = function (id) {
120122
var basedir = this._basedir;
121123
if (!basedir) basedir = process.cwd();
122124
return hash(path.relative(basedir, id));
123-
}
125+
};
124126

125127
Browserify.prototype.noParse = function(file) {
126128
var self = this;
@@ -308,11 +310,22 @@ Browserify.prototype.bundle = function (opts, cb) {
308310
if (self._noParse.indexOf(file) >= 0) {
309311
return through2();
310312
}
311-
return insertGlobals(file, {
313+
var inserter = insertGlobals(file, {
312314
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),
314322
basedir: basedir
315323
});
324+
inserter.on('global', function (name) {
325+
if (name !== 'process') return;
326+
self._mapped[self._hash(processPath)] = processPath;
327+
});
328+
return inserter;
316329
} ].concat(self._globalTransforms);
317330
}
318331
else opts.globalTransform = self._globalTransforms;
@@ -747,7 +760,7 @@ Browserify.prototype._resolve = function (id, parent, cb) {
747760

748761
result(file, pkg);
749762
});
750-
763+
751764
function findPackage (basedir, cb) {
752765
var dirs = parents(basedir);
753766
(function next () {

package.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
"http-browserify": "~1.3.1",
4444
"https-browserify": "~0.0.0",
4545
"inherits": "~2.0.1",
46-
"insert-module-globals": "~5.0.1",
47-
"module-deps": "~1.10.0",
46+
"insert-module-globals": "~6.0.0",
47+
"module-deps": "~2.0.0",
4848
"os-browserify": "~0.1.1",
4949
"parents": "~0.0.1",
5050
"path-browserify": "~0.0.0",
@@ -64,7 +64,9 @@
6464
"umd": "~2.0.0",
6565
"url": "~0.10.1",
6666
"util": "~0.10.1",
67-
"vm-browserify": "~0.0.1"
67+
"vm-browserify": "~0.0.1",
68+
"xtend": "^3.0.0",
69+
"process": "^0.7.0"
6870
},
6971
"devDependencies": {
7072
"backbone": "~0.9.2",

0 commit comments

Comments
 (0)