Skip to content

Commit 2cab593

Browse files
committed
Change plugins to use new CommonJS API
1 parent 5fd94ac commit 2cab593

File tree

9 files changed

+138
-153
lines changed

9 files changed

+138
-153
lines changed

plugins/angular.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
'use strict';
2-
31
/**
42
* Angular.js plugin
53
*
64
* Provides an $exceptionHandler for Angular.js
75
*/
6+
'use strict';
87

98
// See https://github.com/angular/angular.js/blob/v1.4.7/src/minErr.js
109
var angularPattern = /^\[((?:[$a-zA-Z0-9]+:)?(?:[$a-zA-Z0-9]+))\] (.+?)\n(\S+)$/;
1110

12-
function install() {
11+
function angularPlugin(Raven, angular) {
1312
/*jshint validthis:true*/
14-
var Raven = this;
13+
var angular = angular || window.angular;
14+
1515
function RavenProvider() {
1616
this.$get = ['$window', function($window) {
1717
return Raven;
@@ -58,4 +58,4 @@ function install() {
5858
});
5959
}
6060

61-
module.exports = install;
61+
module.exports = angularPlugin;

plugins/backbone.js

Lines changed: 43 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,57 +3,53 @@
33
*
44
* Patches Backbone.Events callbacks.
55
*/
6-
;(function(window) {
7-
'use strict';
86

9-
if (window.Raven) Raven.addPlugin(function backbonePlugin() {
7+
function backbonePlugin(Raven, Backbone) {
8+
var Backbone = Backbone || window.Backbone;
109

11-
var Backbone = window.Backbone;
10+
// quit if Backbone isn't on the page
11+
if (!Backbone) return;
1212

13-
// quit if Backbone isn't on the page
14-
if (!Backbone) return;
15-
16-
function makeBackboneEventsOn(oldOn) {
17-
return function BackboneEventsOn(name, callback, context) {
18-
var wrapCallback = function (cb) {
19-
if (Object.prototype.toString.call(cb) === '[object Function]') {
20-
var _callback = cb._callback || cb;
21-
cb = Raven.wrap(cb);
22-
cb._callback = _callback;
23-
}
24-
return cb;
25-
};
26-
if (Object.prototype.toString.call(name) === '[object Object]') {
27-
// Handle event maps.
28-
for (var key in name) {
29-
if (name.hasOwnProperty(key)) {
30-
name[key] = wrapCallback(name[key]);
13+
function makeBackboneEventsOn(oldOn) {
14+
return function BackboneEventsOn(name, callback, context) {
15+
var wrapCallback = function (cb) {
16+
if (Object.prototype.toString.call(cb) === '[object Function]') {
17+
var _callback = cb._callback || cb;
18+
cb = Raven.wrap(cb);
19+
cb._callback = _callback;
3120
}
21+
return cb;
22+
};
23+
if (Object.prototype.toString.call(name) === '[object Object]') {
24+
// Handle event maps.
25+
for (var key in name) {
26+
if (name.hasOwnProperty(key)) {
27+
name[key] = wrapCallback(name[key]);
28+
}
29+
}
30+
} else {
31+
callback = wrapCallback(callback);
3232
}
33-
} else {
34-
callback = wrapCallback(callback);
35-
}
36-
return oldOn.call(this, name, callback, context);
37-
};
38-
}
39-
40-
// We're too late to catch all of these by simply patching Backbone.Events.on
41-
var affectedObjects = [
42-
Backbone.Events,
43-
Backbone,
44-
Backbone.Model.prototype,
45-
Backbone.Collection.prototype,
46-
Backbone.View.prototype,
47-
Backbone.Router.prototype,
48-
Backbone.History.prototype
49-
], i = 0, l = affectedObjects.length;
50-
51-
for (; i < l; i++) {
52-
var affected = affectedObjects[i];
53-
affected.on = makeBackboneEventsOn(affected.on);
54-
affected.bind = affected.on;
33+
return oldOn.call(this, name, callback, context);
34+
};
35+
}
36+
37+
// We're too late to catch all of these by simply patching Backbone.Events.on
38+
var affectedObjects = [
39+
Backbone.Events,
40+
Backbone,
41+
Backbone.Model.prototype,
42+
Backbone.Collection.prototype,
43+
Backbone.View.prototype,
44+
Backbone.Router.prototype,
45+
Backbone.History.prototype
46+
], i = 0, l = affectedObjects.length;
47+
48+
for (; i < l; i++) {
49+
var affected = affectedObjects[i];
50+
affected.on = makeBackboneEventsOn(affected.on);
51+
affected.bind = affected.on;
52+
}
5553
}
5654

57-
});
58-
59-
}(typeof window !== 'undefined' ? window : this));
55+
module.exports = backbonePlugin;

plugins/console.js

Lines changed: 31 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,49 +4,41 @@
44
* Monkey patches console.* calls into Sentry messages with
55
* their appropriate log levels. (Experimental)
66
*/
7-
;(function(window) {
87
'use strict';
98

10-
if (window.Raven) Raven.addPlugin(function ConsolePlugin() {
11-
12-
var console = window.console || {};
13-
14-
var originalConsole = console,
15-
logLevels = ['debug', 'info', 'warn', 'error'],
16-
level = logLevels.pop();
17-
18-
var logForGivenLevel = function(level) {
19-
var originalConsoleLevel = console[level];
20-
21-
// warning level is the only level that doesn't map up
22-
// correctly with what Sentry expects.
23-
if (level === 'warn') level = 'warning';
24-
return function () {
25-
var args = [].slice.call(arguments);
26-
Raven.captureMessage('' + args[0], {level: level, logger: 'console', extra: { 'arguments': args }});
27-
28-
// this fails for some browsers. :(
29-
if (originalConsoleLevel) {
30-
// IE9 doesn't allow calling apply on console functions directly
31-
// See: https://stackoverflow.com/questions/5472938/does-ie9-support-console-log-and-is-it-a-real-function#answer-5473193
32-
Function.prototype.bind
33-
.call(originalConsoleLevel, originalConsole)
34-
.apply(originalConsole, args);
35-
}
9+
function consolePlugin(Raven, console) {
10+
var console = console || window.console || {};
11+
12+
var originalConsole = console,
13+
logLevels = ['debug', 'info', 'warn', 'error'],
14+
level = logLevels.pop();
15+
16+
var logForGivenLevel = function(level) {
17+
var originalConsoleLevel = console[level];
18+
19+
// warning level is the only level that doesn't map up
20+
// correctly with what Sentry expects.
21+
if (level === 'warn') level = 'warning';
22+
return function () {
23+
var args = [].slice.call(arguments);
24+
Raven.captureMessage('' + args[0], {level: level, logger: 'console', extra: { 'arguments': args }});
25+
26+
// this fails for some browsers. :(
27+
if (originalConsoleLevel) {
28+
// IE9 doesn't allow calling apply on console functions directly
29+
// See: https://stackoverflow.com/questions/5472938/does-ie9-support-console-log-and-is-it-a-real-function#answer-5473193
30+
Function.prototype.bind
31+
.call(originalConsoleLevel, originalConsole)
32+
.apply(originalConsole, args);
33+
}
34+
};
3635
};
37-
};
3836

3937

40-
while(level) {
41-
console[level] = logForGivenLevel(level);
42-
level = logLevels.pop();
38+
while(level) {
39+
console[level] = logForGivenLevel(level);
40+
level = logLevels.pop();
41+
}
4342
}
4443

45-
// export
46-
window.console = console;
47-
48-
// End of plugin factory
49-
});
50-
51-
// console would require `window`, so we don't allow it to be optional
52-
}(window));
44+
module.exports = consolePlugin;

plugins/ember.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
*/
66
'use strict';
77

8-
function install(Ember) {
8+
function emberPlugin(Raven, Ember) {
99
/*jshint validthis:true*/
10-
var Raven = this;
1110
Ember = Ember || window.Ember;
1211

1312
// quit if Ember isn't on the page
@@ -29,4 +28,4 @@ function install(Ember) {
2928
});
3029
}
3130

32-
module.exports = install;
31+
module.exports = emberPlugin;

plugins/jquery.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
*/
66
'use strict';
77

8-
function install(jQuery) {
8+
function jQueryPlugin(Raven, jQuery) {
99
/*jshint validthis:true*/
10-
var Raven = this;
1110
var $ = jQuery || window.jQuery;
1211

1312
// quit if jQuery isn't on the page
13+
if (!$) return;
1414

1515
var _oldEventAdd = $.event.add;
1616
$.event.add = function ravenEventAdd(elem, types, handler, data, selector) {
@@ -102,6 +102,4 @@ function install(jQuery) {
102102
};
103103
}
104104

105-
module.exports = {
106-
install: install
107-
};
105+
module.exports = jQueryPlugin;

plugins/native.js

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,29 @@
44
* Extends support for global error handling for asynchronous browser
55
* functions. Adopted from Closure Library's errorhandler.js.
66
*/
7-
;(function(window) {
8-
'use strict';
9-
10-
if (window.Raven) Raven.addPlugin(function nativePlugin() {
11-
12-
var _helper = function _helper(fnName) {
13-
var originalFn = window[fnName];
14-
window[fnName] = function ravenAsyncExtension() {
15-
// Make a copy of the arguments
16-
var args = [].slice.call(arguments);
17-
var originalCallback = args[0];
18-
if (typeof (originalCallback) === 'function') {
19-
args[0] = Raven.wrap(originalCallback);
20-
}
21-
// IE < 9 doesn't support .call/.apply on setInterval/setTimeout, but it
22-
// also supports only two arguments and doesn't care what this is, so we
23-
// can just call the original function directly.
24-
if (originalFn.apply) {
25-
return originalFn.apply(this, args);
26-
} else {
27-
return originalFn(args[0], args[1]);
28-
}
7+
function nativePlugin(Raven) {
8+
var _helper = function _helper(fnName) {
9+
var originalFn = window[fnName];
10+
window[fnName] = function ravenAsyncExtension() {
11+
// Make a copy of the arguments
12+
var args = [].slice.call(arguments);
13+
var originalCallback = args[0];
14+
if (typeof (originalCallback) === 'function') {
15+
args[0] = Raven.wrap(originalCallback);
16+
}
17+
// IE < 9 doesn't support .call/.apply on setInterval/setTimeout, but it
18+
// also supports only two arguments and doesn't care what this is, so we
19+
// can just call the original function directly.
20+
if (originalFn.apply) {
21+
return originalFn.apply(this, args);
22+
} else {
23+
return originalFn(args[0], args[1]);
24+
}
25+
};
2926
};
30-
};
31-
32-
_helper('setTimeout');
33-
_helper('setInterval');
3427

35-
// End of plugin factory
36-
});
28+
_helper('setTimeout');
29+
_helper('setInterval');
30+
}
3731

38-
}(typeof window !== 'undefined' ? window : this));
32+
module.exports = nativePlugin;

plugins/react-native.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,16 @@
77
* var Raven = require('raven-js');
88
* require('raven-js/plugins/react-native')(Raven);
99
*/
10+
'use strict';
1011

1112
var DEVICE_PATH_RE = /^\/var\/mobile\/Containers\/Bundle\/Application\/[^\/]+\/[^\.]+\.app/;
1213
function normalizeUrl(url) {
13-
"use strict";
14-
1514
return url
1615
.replace(/^file\:\/\//, '')
1716
.replace(DEVICE_PATH_RE, '');
1817
}
1918

20-
module.exports = function (Raven) {
21-
"use strict";
22-
19+
function reactNativePlugin(Raven) {
2320
function urlencode(obj) {
2421
var pairs = [];
2522
for (var key in obj) {
@@ -73,4 +70,6 @@ module.exports = function (Raven) {
7370
});
7471

7572
ErrorUtils.setGlobalHandler(Raven.captureException);
76-
};
73+
}
74+
75+
module.exports = reactNativePlugin;

plugins/require.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,13 @@
33
*
44
* Automatically wrap define/require callbacks. (Experimental)
55
*/
6-
;(function(window) {
76
'use strict';
87

9-
if (window.Raven) Raven.addPlugin(function RequirePlugin() {
10-
11-
if (typeof define === 'function' && define.amd) {
12-
window.define = Raven.wrap({deep: false}, define);
13-
window.require = Raven.wrap({deep: false}, require);
8+
function requirePlugin(Raven) {
9+
if (typeof define === 'function' && define.amd) {
10+
window.define = Raven.wrap({deep: false}, define);
11+
window.require = Raven.wrap({deep: false}, require);
12+
}
1413
}
1514

16-
// End of plugin factory
17-
});
18-
19-
}(window));
15+
module.exports = requirePlugin;

0 commit comments

Comments
 (0)