From e29930b13760aee7bdbbd20f533c9e96cb477211 Mon Sep 17 00:00:00 2001 From: Clay Walker Date: Mon, 15 Sep 2014 17:01:59 -0700 Subject: [PATCH 1/4] Added support for CommonJS/browserify. --- src/raven.js | 2 +- template/_footer.js | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/raven.js b/src/raven.js index 32570b8aa1a6..9d0a74957835 100644 --- a/src/raven.js +++ b/src/raven.js @@ -4,7 +4,7 @@ // If there is no JSON, we no-op the core features of Raven // since JSON is required to encode the payload var _Raven = window.Raven, - hasJSON = !!(window.JSON && window.JSON.stringify), + hasJSON = !!(typeof JSON === 'object' && JSON.stringify), lastCapturedException, lastEventId, globalServer, diff --git a/template/_footer.js b/template/_footer.js index 0a9efcc022a6..588975d24ad1 100644 --- a/template/_footer.js +++ b/template/_footer.js @@ -1,9 +1,13 @@ // Expose Raven to the world -window.Raven = Raven; - -// AMD if (typeof define === 'function' && define.amd) { + // AMD define('raven', [], function() { return Raven; }); +} else if (typeof module === 'object') { + // CommonJS + module.exports = Raven; +} else { + // Everything else + window.Raven = Raven; } })(window); From 28e7551238fff853af8d4eb3b64975858dc59e73 Mon Sep 17 00:00:00 2001 From: Clay Walker Date: Mon, 15 Sep 2014 17:23:31 -0700 Subject: [PATCH 2/4] Fixed a file naming issue from changing the package.json name per #260. --- Gruntfile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gruntfile.js b/Gruntfile.js index 2abe02b11d26..8596b0f5c2c9 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -70,7 +70,7 @@ module.exports = function(grunt) { }, core: { src: coreFiles.concat(plugins), - dest: 'build/<%= pkg.name %>.js' + dest: 'build/raven.js' }, all: { files: pluginConcatFiles From 87c8b4e082764e488160ee225a692f8ff9fe2898 Mon Sep 17 00:00:00 2001 From: Clay Walker Date: Mon, 15 Sep 2014 20:42:40 -0700 Subject: [PATCH 3/4] Made use of isObject helper function per feedback. --- src/raven.js | 2 +- template/_footer.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/raven.js b/src/raven.js index 9d0a74957835..e3f5e321b6e1 100644 --- a/src/raven.js +++ b/src/raven.js @@ -4,7 +4,7 @@ // If there is no JSON, we no-op the core features of Raven // since JSON is required to encode the payload var _Raven = window.Raven, - hasJSON = !!(typeof JSON === 'object' && JSON.stringify), + hasJSON = !!(isObject(JSON) && JSON.stringify), lastCapturedException, lastEventId, globalServer, diff --git a/template/_footer.js b/template/_footer.js index 588975d24ad1..ca407a03ec25 100644 --- a/template/_footer.js +++ b/template/_footer.js @@ -2,7 +2,7 @@ if (typeof define === 'function' && define.amd) { // AMD define('raven', [], function() { return Raven; }); -} else if (typeof module === 'object') { +} else if (isObject(module)) { // CommonJS module.exports = Raven; } else { From 44be7407fa77fe515fddf8447241edb094414013 Mon Sep 17 00:00:00 2001 From: Clay Walker Date: Tue, 16 Sep 2014 10:36:51 -0700 Subject: [PATCH 4/4] Added AMD global for plugins per UMDJS and feedback in #261. Added support for strict CommonJS per UMDJS. --- template/_footer.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/template/_footer.js b/template/_footer.js index ca407a03ec25..2f97062899af 100644 --- a/template/_footer.js +++ b/template/_footer.js @@ -1,10 +1,15 @@ // Expose Raven to the world if (typeof define === 'function' && define.amd) { // AMD - define('raven', [], function() { return Raven; }); + define('raven', function(Raven) { + return (window.Raven = Raven); + }); } else if (isObject(module)) { - // CommonJS + // browserify module.exports = Raven; +} else if (isObject(exports)) { + // CommonJS + exports = Raven; } else { // Everything else window.Raven = Raven;