Skip to content

Commit 906b224

Browse files
committed
Use browserify to generate plugin versions of raven
1 parent f64a8c7 commit 906b224

File tree

5 files changed

+62
-71
lines changed

5 files changed

+62
-71
lines changed

Gruntfile.js

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
12
module.exports = function(grunt) {
23
"use strict";
34

45
var _ = require('lodash');
56
var path = require('path');
7+
var through = require('through2');
68

79
var excludedPlugins = [
810
'react-native'
@@ -58,7 +60,7 @@ module.exports = function(grunt) {
5860
key.sort();
5961

6062
var dest = path.join('build/', key.join(','), '/raven.js');
61-
dict[dest] = ['build/raven.js'].concat(comb);
63+
dict[dest] = ['src/raven.js'].concat(comb);
6264

6365
return dict;
6466
}, {});
@@ -68,26 +70,38 @@ module.exports = function(grunt) {
6870
aws: grunt.file.exists('aws.json') ? grunt.file.readJSON('aws.json'): {},
6971

7072
clean: ['build'],
71-
concat: {
72-
options: {
73-
separator: '\n',
74-
process: true
75-
},
76-
plugins: {
77-
files: pluginConcatFiles
78-
}
79-
},
8073

8174
browserify: {
75+
options: {
76+
browserifyOptions: {
77+
banner: grunt.file.read('template/_copyright.js'),
78+
standalone: 'Raven', // umd
79+
},
80+
transform: [
81+
[
82+
// custom transformer to re-write plugins to self-register
83+
// with Raven
84+
new function () {
85+
return function (file, options) {
86+
return through(function (buf, enc, next) {
87+
var buf = buf.toString('utf8');
88+
if (/plugins/.test(file)) {
89+
buf += "\nRaven.addPlugin(module.exports.install);";
90+
}
91+
this.push(buf);
92+
next();
93+
});
94+
}
95+
}
96+
]
97+
]
98+
},
8299
core: {
83100
src: 'src/raven.js',
84101
dest: 'build/raven.js',
85-
options: {
86-
banner: grunt.file.read('template/_copyright.js'),
87-
browserifyOptions: {
88-
standalone: 'Raven' // umd
89-
}
90-
}
102+
},
103+
plugins: {
104+
files: pluginConcatFiles
91105
}
92106
},
93107

@@ -252,15 +266,13 @@ module.exports = function(grunt) {
252266

253267
// Grunt contrib tasks
254268
grunt.loadNpmTasks('grunt-contrib-uglify');
255-
grunt.loadNpmTasks('grunt-contrib-concat');
256269
grunt.loadNpmTasks('grunt-contrib-clean');
257270
grunt.loadNpmTasks('grunt-contrib-jshint');
258271
grunt.loadNpmTasks('grunt-contrib-connect');
259272
grunt.loadNpmTasks('grunt-contrib-copy');
260273

261274
// 3rd party Grunt tasks
262275
grunt.loadNpmTasks('grunt-browserify');
263-
grunt.loadNpmTasks('grunt-exorcise');
264276
grunt.loadNpmTasks('grunt-mocha');
265277
grunt.loadNpmTasks('grunt-release');
266278
grunt.loadNpmTasks('grunt-s3');
@@ -269,10 +281,10 @@ module.exports = function(grunt) {
269281

270282
// Build tasks
271283
grunt.registerTask('_prep', ['clean', 'gitinfo', 'version']);
272-
grunt.registerTask('concat.core', ['browserify', 'exorcise']);
273-
grunt.registerTask('concat.plugins', ['concat:plugins']);
274-
grunt.registerTask('build.core', ['_prep', 'concat.core', 'uglify', 'fixSourceMaps', 'sri:dist']);
275-
grunt.registerTask('build.all', ['_prep', 'concat.core', 'concat.plugins', 'uglify', 'fixSourceMaps', 'sri:dist', 'sri:build']);
284+
grunt.registerTask('browserify.core', ['_prep', 'browserify:core']);
285+
grunt.registerTask('browserify.plugins', ['_prep', 'browserify:plugins']);
286+
grunt.registerTask('build.core', ['browserify.core', 'uglify', 'fixSourceMaps', 'sri:dist']);
287+
grunt.registerTask('build.all', ['browserify.plugins', 'uglify', 'fixSourceMaps', 'sri:dist', 'sri:build']);
276288
grunt.registerTask('build', ['build.all']);
277289
grunt.registerTask('dist', ['build.core', 'copy:dist']);
278290

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
"grunt-sri": "mattrobenolt/grunt-sri#pretty",
3131
"jquery": "^2.1.4",
3232
"lodash": "~2.4.0",
33-
"sinon": "~1.7.3"
33+
"sinon": "~1.7.3",
34+
"through2": "^2.0.0"
3435
},
3536
"keywords": [
3637
"exceptions",

plugins/angular.js

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,8 @@
33
*
44
* Provides an $exceptionHandler for Angular.js
55
*/
6-
;(function(window) {
7-
'use strict';
86

9-
var angular = window.angular,
10-
Raven = window.Raven;
11-
12-
// quit if angular isn't on the page
13-
if (!(angular && Raven)) return;
7+
var Raven = require('../src/raven');
148

159
function RavenProvider() {
1610
this.$get = ['$window', function($window, $log) {
@@ -35,28 +29,33 @@ function exceptionHandler(Raven, $delegate) {
3529
// See https://github.com/angular/angular.js/blob/v1.4.7/src/minErr.js
3630
var angularPattern = /^\[((?:[$a-zA-Z0-9]+:)?(?:[$a-zA-Z0-9]+))\] (.+?)\n(\S+)$/;
3731

38-
Raven.addPlugin(function () {
32+
function install() {
33+
var angular = window.angular;
34+
if (!angular) return;
35+
3936
angular.module('ngRaven', [])
4037
.provider('Raven', RavenProvider)
4138
.config(['$provide', ExceptionHandlerProvider]);
42-
});
43-
44-
Raven.setDataCallback(function(data) {
45-
// We only care about mutating an exception
46-
var exception = data.exception;
47-
if (exception) {
48-
exception = exception.values[0];
49-
var matches = angularPattern.exec(exception.value);
50-
51-
if (matches) {
52-
// This type now becomes something like: $rootScope:inprog
53-
exception.type = matches[1];
54-
exception.value = matches[2];
55-
data.message = exception.type + ': ' + exception.value;
56-
// auto set a new tag specifically for the angular error url
57-
data.extra.angularDocs = matches[3].substr(0, 250);
39+
40+
Raven.setDataCallback(function(data) {
41+
// We only care about mutating an exception
42+
var exception = data.exception;
43+
if (exception) {
44+
exception = exception.values[0];
45+
var matches = angularPattern.exec(exception.value);
46+
47+
if (matches) {
48+
// This type now becomes something like: $rootScope:inprog
49+
exception.type = matches[1];
50+
exception.value = matches[2];
51+
data.message = exception.type + ': ' + exception.value;
52+
// auto set a new tag specifically for the angular error url
53+
data.extra.angularDocs = matches[3].substr(0, 250);
54+
}
5855
}
59-
}
60-
});
56+
});
57+
}
6158

62-
}(typeof window !== 'undefined' ? window : this));
59+
module.exports = {
60+
install: install
61+
};

template/_footer.js

Lines changed: 0 additions & 19 deletions
This file was deleted.

template/_header.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)