Skip to content

Commit 228c609

Browse files
authored
fix: access 'process' through global variable (#399)
1 parent ff785f0 commit 228c609

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

lib/client.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,25 @@ extend(Raven.prototype, {
3737

3838
if (arguments.length === 0) {
3939
// no arguments, use default from environment
40-
dsn = process.env.SENTRY_DSN;
40+
dsn = global.process.env.SENTRY_DSN;
4141
options = {};
4242
}
4343
if (typeof dsn === 'object') {
4444
// They must only be passing through options
4545
options = dsn;
46-
dsn = process.env.SENTRY_DSN;
46+
dsn = global.process.env.SENTRY_DSN;
4747
}
4848
options = options || {};
4949

5050
this.raw_dsn = dsn;
5151
this.dsn = utils.parseDSN(dsn);
52-
this.name = options.name || process.env.SENTRY_NAME || require('os').hostname();
53-
this.root = options.root || process.cwd();
52+
this.name = options.name || global.process.env.SENTRY_NAME || require('os').hostname();
53+
this.root = options.root || global.process.cwd();
5454
this.transport = options.transport || transports[this.dsn.protocol];
5555
this.sendTimeout = options.sendTimeout || 1;
56-
this.release = options.release || process.env.SENTRY_RELEASE || '';
56+
this.release = options.release || global.process.env.SENTRY_RELEASE || '';
5757
this.environment =
58-
options.environment || process.env.SENTRY_ENVIRONMENT || process.env.NODE_ENV || '';
58+
options.environment || global.process.env.SENTRY_ENVIRONMENT || global.process.env.NODE_ENV || '';
5959

6060
// autoBreadcrumbs: true enables all, autoBreadcrumbs: false disables all
6161
// autoBreadcrumbs: { http: true } enables a single type
@@ -94,7 +94,7 @@ extend(Raven.prototype, {
9494

9595
this.onFatalError = this.defaultOnFatalError = function(err, sendErr, eventId) {
9696
console.error(err && err.stack ? err.stack : err);
97-
process.exit(1);
97+
global.process.exit(1);
9898
};
9999
this.uncaughtErrorHandler = this.makeErrorHandler();
100100

@@ -112,11 +112,11 @@ extend(Raven.prototype, {
112112
this.onFatalError = cb;
113113
}
114114

115-
process.on('uncaughtException', this.uncaughtErrorHandler);
115+
global.process.on('uncaughtException', this.uncaughtErrorHandler);
116116

117117
if (this.captureUnhandledRejections) {
118118
var self = this;
119-
process.on('unhandledRejection', function(reason) {
119+
global.process.on('unhandledRejection', function(reason) {
120120
self.captureException(reason, function(sendErr, eventId) {
121121
if (!sendErr) utils.consoleAlert('unhandledRejection captured: ' + eventId);
122122
});
@@ -136,8 +136,8 @@ extend(Raven.prototype, {
136136
instrumentor.deinstrument(this);
137137

138138
// todo: this works for tests for now, but isn't what we ultimately want to be doing
139-
process.removeAllListeners('uncaughtException');
140-
process.removeAllListeners('unhandledRejection');
139+
global.process.removeAllListeners('uncaughtException');
140+
global.process.removeAllListeners('unhandledRejection');
141141

142142
this.installed = false;
143143

@@ -252,8 +252,8 @@ extend(Raven.prototype, {
252252
kwargs.modules = utils.getModules();
253253
kwargs.server_name = kwargs.server_name || this.name;
254254

255-
if (typeof process.version !== 'undefined') {
256-
kwargs.extra.node = process.version;
255+
if (typeof global.process.version !== 'undefined') {
256+
kwargs.extra.node = global.process.version;
257257
}
258258

259259
kwargs.environment = kwargs.environment || this.environment;

lib/utils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ function getFunction(line) {
132132

133133
var mainModule =
134134
((require.main && require.main.filename && path.dirname(require.main.filename)) ||
135-
process.cwd()) + '/';
135+
global.process.cwd()) + '/';
136136

137137
function getModule(filename, base) {
138138
if (!base) base = mainModule;

test/raven.client.js

+2
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ describe('raven.Client', function() {
268268
zlib.deflate = old;
269269

270270
var kwargs = JSON.parse(skwargs);
271+
// Remove superfluous node version data to simplify the test itself
272+
delete kwargs.extra.node;
271273
kwargs.should.have.property('extra', {
272274
foo: '[Circular ~]'
273275
});

0 commit comments

Comments
 (0)