Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions .babelrc

This file was deleted.

6 changes: 1 addition & 5 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@
"browser": true,
"builtin": true
},
"parserOptions": {
"ecmaVersion": 6
},
"globals": {
"require": false,
"Promise": true
"require": false
},
"rules": {
"block-scoped-var": 2,
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ docs/doctrees

build
node_modules
plugins/combinations
npm-debug.log

scratch/
Expand Down
253 changes: 147 additions & 106 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,106 +2,165 @@
module.exports = function(grunt) {
var path = require('path');
var os = require('os');
var through = require('through2');
var proxyquire = require('proxyquireify');
var versionify = require('browserify-versionify');
var derequire = require('derequire/plugin');
var collapser = require('bundle-collapser/plugin');

var excludedPlugins = ['react-native'];

var plugins = grunt.file.expand('plugins/*.js').filter(function(plugin) {
var plugins = grunt.option('plugins');
// Create plugin paths and verify they exist
plugins = (plugins ? plugins.split(',') : []).map(function(plugin) {
var p = 'plugins/' + plugin + '.js';

if (!grunt.file.exists(p))
throw new Error("Plugin '" + plugin + "' not found in plugins directory.");

return p;
});

// custom browserify transformer to re-write plugins to
// self-register with Raven via addPlugin
function AddPluginBrowserifyTransformer() {
return function(file) {
return through(function(buf, enc, next) {
buf = buf.toString('utf8');
if (/plugins/.test(file)) {
buf += "\nrequire('../src/singleton').addPlugin(module.exports);";
}
this.push(buf);
next();
});
};
}

// Taken from http://dzone.com/snippets/calculate-all-combinations
var combine = function(a) {
var fn = function(n, src, got, all) {
if (n === 0) {
all.push(got);
return;
}

for (var j = 0; j < src.length; j++) {
fn(n - 1, src.slice(j + 1), got.concat([src[j]]), all);
}
};

var excluded = excludedPlugins.map(function(plugin) {
return 'plugins/' + plugin + '.js';
});

// Remove the plugins that we don't want to build
a = a.filter(function(n) {
return excluded.indexOf(n) === -1;
});

var all = [a];

for (var i = 0; i < a.length; i++) {
fn(i, a, [], all);
}

return all;
};

var plugins = grunt.file.expand('plugins/*.js');

var cleanedPlugins = plugins.filter(function(plugin) {
var pluginName = path.basename(plugin, '.js');

return excludedPlugins.indexOf(pluginName) === -1;
});

// These files are generated with the 'generate:plugins-combined' npm script
var pluginCombinations = grunt.file.expand('plugins/combinations/*.js');
var pluginSingleFiles = cleanedPlugins.map(function(plugin) {
var filename = path.basename(plugin);

var tests = grunt.file.expand('test/**/*.test.js');
var file = {};
file.src = plugin;
file.dest = path.join('build', 'plugins', filename);

var rollupConfig = {
core: {
options: [
{
input: {
input: 'src/singleton.js'
},
output: {
file: 'build/raven.js',
name: 'Raven',
banner: grunt.file.read('template/_copyright.js')
}
}
]
return file;
});

var pluginCombinations = combine(plugins);
var pluginConcatFiles = pluginCombinations.reduce(function(dict, comb) {
var key = comb.map(function(plugin) {
return path.basename(plugin, '.js');
});
key.sort();

var dest = path.join('build/', key.join(','), '/raven.js');
dict[dest] = ['src/singleton.js'].concat(comb);

return dict;
}, {});

var browserifyConfig = {
options: {
banner: grunt.file.read('template/_copyright.js'),
browserifyOptions: {
standalone: 'Raven' // umd
},
transform: [versionify],
plugin: [derequire, collapser]
},
plugins: {
options: []
core: {
src: 'src/singleton.js',
dest: 'build/raven.js'
},
pluginCombinations: {
options: []
'plugins-combined': {
files: pluginConcatFiles,
options: {
transform: [[versionify], [new AddPluginBrowserifyTransformer()]]
}
},
tests: {
options: []
test: {
src: 'test/**/*.test.js',
dest: 'build/raven.test.js',
options: {
browserifyOptions: {
debug: false // source maps
},
ignore: ['react-native'],
plugin: [proxyquire.plugin]
}
}
};

// Create a dedicated entry in rollup config for each individual
// plugin (each needs a unique `standalone` config)
plugins.forEach(function(plugin) {
var name = plugin
// Create a dedicated entry in browserify config for
// each individual plugin (each needs a unique `standalone`
// config)
var browserifyPluginTaskNames = [];
pluginSingleFiles.forEach(function(item) {
var name = item.src
.replace(/.*\//, '') // everything before slash
.replace('.js', ''); // extension
var capsName = name.charAt(0).toUpperCase() + name.slice(1);
var config = {
input: {
input: plugin
},
output: {
file: path.join('build', 'plugins', path.basename(plugin)),
name: 'Raven.Plugins.' + capsName,
banner: grunt.file.read('template/_copyright.js')
}
};

rollupConfig.plugins.options.push(config);
});

// Create a dedicated entry in rollup config for each individual plugin combination
pluginCombinations.forEach(function(pluginCombination) {
var config = {
input: {
input: pluginCombination
},
output: {
file: path.join('build', path.basename(pluginCombination, '.js'), 'raven.js'),
name: 'Raven',
banner: grunt.file.read('template/_copyright.js')
}
};

rollupConfig.pluginCombinations.options.push(config);
});

// Transpile all test scripts
tests.forEach(function(test) {
var config = {
input: {
input: test
},
output: {
file: path.join('build', path.basename(test)),
name: path.basename(test, '.js')
src: item.src,
dest: item.dest,
options: {
browserifyOptions: {
// e.g. Raven.Plugins.Angular
standalone: 'Raven.Plugins.' + capsName
}
}
};

rollupConfig.tests.options.push(config);
browserifyConfig[name] = config;
browserifyPluginTaskNames.push('browserify:' + name);
});

var awsConfigPath = path.join(os.homedir(), '.aws', 'raven-js.json');
var gruntConfig = {
pkg: grunt.file.readJSON('package.json'),
aws: grunt.file.exists(awsConfigPath) ? grunt.file.readJSON(awsConfigPath) : {},

clean: ['build', 'plugins/combinations'],
clean: ['build'],

rollup: rollupConfig,
browserify: browserifyConfig,

uglify: {
options: {
Expand Down Expand Up @@ -218,30 +277,6 @@ module.exports = function(grunt) {
grunt.initConfig(gruntConfig);

// Custom Grunt tasks
grunt.registerMultiTask('rollup', 'Create the bundles', function() {
var build = require('./scripts/build');
var options = this.options();
var done = this.async();

var promises = Object.keys(options).map(function(key) {
return build(options[key].input, options[key].output);
});

Promise.all(promises)
.then(function() {
done();
})
['catch'](function(error) {
grunt.fail.warn(error);
});
});

grunt.registerTask('generate-plugin-combinations', function() {
var dest = './plugins/combinations';
grunt.file.mkdir(dest);
require('./scripts/generate-plugin-combinations')(plugins, dest);
});

grunt.registerTask('version', function() {
var pkg = grunt.config.get('pkg');

Expand Down Expand Up @@ -280,28 +315,34 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-copy');

// 3rd party Grunt tasks
grunt.loadNpmTasks('grunt-browserify');
grunt.loadNpmTasks('grunt-release');
grunt.loadNpmTasks('grunt-s3');
grunt.loadNpmTasks('grunt-gitinfo');
grunt.loadNpmTasks('grunt-sri');

// Build tasks
grunt.registerTask('_prep', ['gitinfo', 'version']);
grunt.registerTask('build.test', ['_prep', 'rollup:core', 'rollup:tests']);
grunt.registerTask('build.core', ['_prep', 'rollup:core']);
grunt.registerTask('build.plugins', [
grunt.registerTask('_prep', ['clean', 'gitinfo', 'version']);
grunt.registerTask(
'browserify.core',
['_prep', 'browserify:core'].concat(browserifyPluginTaskNames)
);
grunt.registerTask('browserify.plugins-combined', [
'_prep',
'generate-plugin-combinations',
'rollup:plugins',
'rollup:pluginCombinations',
'browserify:plugins-combined'
]);
grunt.registerTask('build.test', ['_prep', 'browserify.core', 'browserify:test']);
grunt.registerTask('build.core', ['browserify.core', 'uglify', 'sri:dist']);
grunt.registerTask('build.plugins-combined', [
'browserify.plugins-combined',
'uglify',
'sri:dist',
'sri:build'
]);
grunt.registerTask('build', ['build.core', 'build.plugins', 'uglify']);

grunt.registerTask('dist', ['clean', 'build', 'copy:dist', 'sri:dist']);
grunt.registerTask('build', ['build.plugins-combined']);
grunt.registerTask('dist', ['build.core', 'copy:dist']);

// Test tasks
grunt.registerTask('test:ci', ['config:ci', 'build:test']);
grunt.registerTask('test:ci', ['config:ci', 'build.test']);

// Webserver tasks
grunt.registerTask('run:test', ['build.test', 'connect:test']);
Expand Down
13 changes: 1 addition & 12 deletions karma.unit.config.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
var commonConfig = require('./karma.config');

var testFiles = [
'test/globals.js',
'build/angular.test.js',
'build/console.test.js',
'build/json-stringify-safe.test.js',
'build/raven.test.js',
'build/react-native.test.js',
'build/tracekit.test.js',
'build/tracekit-parser.test.js',
'build/utils.test.js',
'build/vue.test.js',
];
var testFiles = ['test/globals.js', 'build/raven.test.js'];

module.exports = function(config) {
var testConfig = Object.assign(
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading