diff --git a/.travis.yml b/.travis.yml index f8fcf47..0728a4d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,6 +24,7 @@ env: - EMBER_TRY_SCENARIO=ember-beta - EMBER_TRY_SCENARIO=ember-canary - EMBER_TRY_SCENARIO=ember-default + # - EMBER_TRY_SCENARIO=fastboot-addon-tests matrix: fast_finish: true diff --git a/app/initializers/rollbar.js b/app/initializers/rollbar.js index 6db6f72..281bc58 100644 --- a/app/initializers/rollbar.js +++ b/app/initializers/rollbar.js @@ -1,47 +1,51 @@ /* global Rollbar */ import Ember from 'ember'; -export default { - name: 'rollbar', - initialize: function() { - var errorLogger = Ember.Logger.error; - Ember.Logger.error = function() { - var args = Array.prototype.slice.call(arguments), - err = isError(args[0]) ? args[0] : new Error(stringify(args)); +const { typeOf, Logger } = Ember; - if (window.Rollbar) { - Rollbar.error.call(Rollbar, err); - } - errorLogger.apply(this, arguments); - }; - var warnLogger = Ember.Logger.warn; - Ember.Logger.warn = function() { - if (window.Rollbar) { - Rollbar.warning.apply(Rollbar, arguments); - } - warnLogger.apply(this, arguments); - }; - var infoLogger = Ember.Logger.info; - Ember.Logger.info = function() { - if (window.Rollbar) { - Rollbar.info.apply(Rollbar, arguments); - } - infoLogger.apply(this, arguments); - }; - var debugLogger = Ember.Logger.debug; - Ember.Logger.debug = function() { - if (window.Rollbar) { - Rollbar.debug.apply(Rollbar, arguments); - } - debugLogger.apply(this, arguments); - }; - } -}; - -var stringify = function(object){ +function stringify(object) { return JSON ? JSON.stringify(object) : object.toString(); -}; +} -var isError = function(object){ - return Ember.typeOf(object) === 'error'; +function isError(object) { + return typeOf(object) === 'error'; +} + +function initialize() { + let errorLogger = Logger.error; + Logger.error = function() { + let args = Array.prototype.slice.call(arguments); + let err = isError(args[0]) ? args[0] : new Error(stringify(args)); + + if (window.Rollbar) { + Rollbar.error.call(Rollbar, err); + } + errorLogger.apply(this, arguments); + }; + let warnLogger = Logger.warn; + Logger.warn = function() { + if (window.Rollbar) { + Rollbar.warning(...arguments); + } + warnLogger.apply(this, arguments); + }; + let infoLogger = Logger.info; + Logger.info = function() { + if (window.Rollbar) { + Rollbar.info(...arguments); + } + infoLogger.apply(this, arguments); + }; + let debugLogger = Logger.debug; + Logger.debug = function() { + if (window.Rollbar) { + Rollbar.debug(...arguments); + } + debugLogger.apply(this, arguments); + }; +} + +export default { + name: 'rollbar', + initialize }; diff --git a/blueprints/ember-cli-rollbar/index.js b/blueprints/ember-cli-rollbar/index.js new file mode 100644 index 0000000..d351e54 --- /dev/null +++ b/blueprints/ember-cli-rollbar/index.js @@ -0,0 +1,13 @@ +/* eslint-env node */ +/* eslint-disable object-shorthand */ + +module.exports = { + description: 'Default ember-cli-rollbar blueprint.', + normalizeEntityName: function() {}, + + afterInstall: function() { + return this.addPackagesToProject([ + { name: 'rollbar' } + ]); + } +}; diff --git a/client/.gitkeep b/client/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/client/rollbar.js b/client/rollbar.js deleted file mode 100644 index 664f5d6..0000000 --- a/client/rollbar.js +++ /dev/null @@ -1,3 +0,0 @@ -window._rollbarConfig = ROLLBAR_CONFIG; -!function(t){function e(n){if(r[n])return r[n].exports;var o=r[n]={exports:{},id:n,loaded:!1};return t[n].call(o.exports,o,o.exports,e),o.loaded=!0,o.exports}var r={};return e.m=t,e.c=r,e.p="",e(0)}([function(t,e,r){"use strict";var n=r(1),o=window&&window._rollbarConfig,i=o&&o.globalAlias||"Rollbar",a=window&&window[i]&&"function"==typeof window[i].shimId&&void 0!==window[i].shimId();if(window&&!window._rollbarStartTime&&(window._rollbarStartTime=(new Date).getTime()),!a&&o){var s=new n(o);window[i]=s}else window.rollbar=n,window._rollbarDidLoad=!0;t.exports=n},function(t,e,r){"use strict";function n(t,e){this.options=c.extend(!0,b,t);var r=new l(this.options,h,d);this.client=e||new u(this.options,r,p,"browser"),i(this.client.notifier),a(this.client.queue),this.options.captureUncaught&&(f.captureUncaughtExceptions(window,this),f.wrapGlobals(window,this)),this.options.captureUnhandledRejections&&f.captureUnhandledRejections(window,this)}function o(t){var e="Rollbar is not initialized";p.error(e),t&&t(new Error(e))}function i(t){t.addTransform(g.handleItemWithError).addTransform(g.ensureItemHasSomethingToSay).addTransform(g.addBaseInfo).addTransform(g.addRequestInfo(window)).addTransform(g.addClientInfo(window)).addTransform(g.addPluginInfo(window)).addTransform(g.addBody).addTransform(g.scrubPayload).addTransform(g.userTransform).addTransform(g.itemToPayload)}function a(t){t.addPredicate(m.checkIgnore).addPredicate(m.userCheckIgnore).addPredicate(m.urlIsWhitelisted).addPredicate(m.messageIsIgnored)}function s(t){for(var e=0,r=t.length;e=1&&r>=e}function o(t,e,r,n,o){var a=null;return r&&(r=new Error(r)),r||n||(a=i(t,e,o)),{error:r,shouldSend:n,payload:a}}function i(t,e,r){var n=e.environment||e.payload&&e.payload.environment,o={body:{message:{body:"maxItems has been hit. Ignoring errors until reset.",extra:{maxItems:r}}},language:"javascript",environment:n,notifier:{version:e.notifier&&e.notifier.version||e.version}};return"browser"===t?(o.platform="browser",o.framework="browser-js",o.notifier.name="rollbar-browser-js"):"server"===t&&(o.framework=e.framework||"node-js",o.notifier.name=e.notifier.name),o}r.globalSettings={startTime:(new Date).getTime(),maxItems:void 0,itemsPerMinute:void 0},r.prototype.configureGlobal=function(t){void 0!==t.startTime&&(r.globalSettings.startTime=t.startTime),void 0!==t.maxItems&&(r.globalSettings.maxItems=t.maxItems),void 0!==t.itemsPerMinute&&(r.globalSettings.itemsPerMinute=t.itemsPerMinute)},r.prototype.shouldSend=function(t,e){e=e||(new Date).getTime(),e-this.startTime>=6e4&&(this.startTime=e,this.perMinCounter=0);var i=r.globalSettings.maxItems,a=r.globalSettings.itemsPerMinute;if(n(t,i,this.counter))return o(this.platform,this.platformOptions,i+" max items reached",!1);if(n(t,a,this.perMinCounter))return o(this.platform,this.platformOptions,a+" items per minute reached",!1);this.counter++,this.perMinCounter++;var s=!n(t,i,this.counter);return o(this.platform,this.platformOptions,null,s,i)},r.prototype.setPlatformOptions=function(t,e){this.platform=t,this.platformOptions=e},t.exports=r},function(t,e,r){"use strict";function n(t,e,r,n){this.rateLimiter=t,this.api=e,this.logger=r,this.options=n,this.predicates=[],this.pendingRequests=[],this.retryQueue=[],this.retryHandle=null,this.waitCallback=null}var o=r(5);n.prototype.configure=function(t){this.api&&this.api.configure(t);var e=this.options;return this.options=o.extend(!0,{},e,t),this},n.prototype.addPredicate=function(t){return o.isFunction(t)&&this.predicates.push(t),this},n.prototype.addItem=function(t,e){e&&o.isFunction(e)||(e=function(){});var r=this._applyPredicates(t);if(r.stop)return void e(r.err);if(this.waitCallback)return void e();this._maybeLog(t),this.pendingRequests.push(t);try{this._makeApiRequest(t,function(r,n){this._dequeuePendingRequest(t),e(r,n)}.bind(this))}catch(r){this._dequeuePendingRequest(t),e(r)}},n.prototype.wait=function(t){o.isFunction(t)&&(this.waitCallback=t,0==this.pendingRequests.length&&this.waitCallback())},n.prototype._applyPredicates=function(t){for(var e=null,r=0,n=this.predicates.length;r=0;r--)if(this.pendingRequests[r]==t)return this.pendingRequests.splice(r,1),void(e&&o.isFunction(this.waitCallback)&&this.waitCallback())},n.prototype._maybeLog=function(t){if(this.logger&&this.options.verbose){var e=o.get(t,"data.body.trace.exception.message");if(e=e||o.get(t,"data.body.trace_chain.0.exception.message"))return void this.logger.error(e);e=o.get(t,"data.body.message.body"),e&&this.logger.log(e)}},t.exports=n},function(t,e,r){"use strict";function n(){if(!N&&(N=!0,s(JSON)&&(a(JSON.stringify)&&(I.stringify=JSON.stringify),a(JSON.parse)&&(I.parse=JSON.parse)),!a(I.stringify)||!a(I.parse))){var t=r(7);t(I)}}function o(t,e){return e===i(t)}function i(t){var e=typeof t;return"object"!==e?e:t?t instanceof Error?"error":{}.toString.call(t).match(/\s([a-zA-Z]+)/)[1].toLowerCase():"null"}function a(t){return o(t,"function")}function s(t){return!o(t,"undefined")}function u(t){var e=i(t);return"object"===e||"array"===e}function c(t){return o(t,"error")}function l(t,e,r){return function(){var n=r||this;try{return e.apply(n,arguments)}catch(e){t.error(e)}}}function p(t,e){var r,n,i,a=o(t,"object"),s=o(t,"array"),u=[];if(a)for(r in t)Object.prototype.hasOwnProperty.call(t,r)&&u.push(r);else if(s)for(i=0;is)?(a=e.path,e.path=a.substring(0,s)+i+"&"+a.substring(s+1)):u!==-1?(a=e.path,e.path=a.substring(0,u)+i+a.substring(u)):e.path=e.path+i}function v(t,e){if(e=e||t.protocol,!e&&t.port&&(80===t.port?e="http:":443===t.port&&(e="https:")),e=e||"https:",!t.hostname)return null;var r=e+"//"+t.hostname;return t.port&&(r=r+":"+t.port),t.path&&(r+=t.path),r}function y(t,e){var r,n;try{r=I.stringify(t)}catch(o){if(e&&a(e))try{r=e(t)}catch(t){n=t}else n=o}return{error:n,value:r}}function b(t){var e,r;try{e=I.parse(t)}catch(t){r=t}return{error:r,value:e}}function w(t,e,r,n,o,i,a,s){var u={url:e||"",line:r,column:n};u.func=s.guessFunctionName(u.url,u.line),u.context=s.gatherContext(u.url,u.line);var c=document&&document.location&&document.location.href,l=window&&window.navigator&&window.navigator.userAgent;return{mode:i,message:o?String(o):t||a,url:c,stack:[u],useragent:l}}function x(t,e,r,n){for(var o,a,s,u,c,p,f=[],d=0,g=t.length;d0&&(s=S(!0,{},s),s.extraArgs=f);var b={message:o,err:a,custom:s,timestamp:(new Date).getTime(),callback:u,uuid:h()};return s&&void 0!==s.level&&(b.level=s.level,delete s.level),n&&c&&(b.request=c),b._originalArgs=t,b}function k(t,e){if(t){var r=e.split("."),n=t;try{for(var o=0,i=r.length;o255&&(e.context=e.context.substr(0,255))}return{access_token:t,data:e}}function o(t,e,r){var n=e.hostname,o=e.protocol,i=e.port,a=e.path,s=e.search,u=t.proxy;if(t.endpoint){var c=r.parse(t.endpoint);n=c.hostname,o=c.protocol,i=c.port,a=c.pathname,s=c.search}return{hostname:n,protocol:o,port:i,path:a,search:s,proxy:u}}function i(t,e,r){var n=t.protocol||"https:",o=t.port||("http:"===n?80:"https:"===n?443:void 0),i=t.hostname;return e=a(t.path,e),t.search&&(e+=t.search),t.proxy&&(e=n+"//"+i+e,i=t.proxy.host||t.proxy.hostname,o=t.proxy.port,n=t.proxy.protocol||n),{protocol:n,hostname:i,path:e,port:o,method:r}}function a(t,e){var r=/\/$/.test(t),n=/^\//.test(e);return r&&n?e=e.substring(1):r||n||(e="/"+e),t+e}var s=r(5);t.exports={buildPayload:n,getTransportFromOptions:o,transportOptions:i,appendPathToPath:a}},function(t,e,r){"use strict";function n(){var t=Array.prototype.slice.call(arguments,0);t.unshift("Rollbar:"),s.ieVersion()<=8?console.error(a.apply(null,t)):console.error.apply(console,t)}function o(){var t=Array.prototype.slice.call(arguments,0);t.unshift("Rollbar:"),s.ieVersion()<=8?console.info(a.apply(null,t)):console.info.apply(console,t)}function i(){var t=Array.prototype.slice.call(arguments,0);t.unshift("Rollbar:"),s.ieVersion()<=8?console.log(a.apply(null,t)):console.log.apply(console,t)}function a(){for(var t=[],e=0;e500&&(r=r.substr(0,500)+"...")):"undefined"==typeof r&&(r="undefined"),t.push(r)}return t.join(" ")}r(12);var s=r(13),u=r(5);t.exports={error:n,info:o,log:i}},function(t,e){!function(t){"use strict";t.console||(t.console={});for(var e,r,n=t.console,o=function(){},i=["memory"],a="assert,clear,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,markTimeline,profile,profiles,profileEnd,show,table,time,timeEnd,timeline,timelineEnd,timeStamp,trace,warn".split(",");e=i.pop();)n[e]||(n[e]={});for(;r=a.pop();)n[r]||(n[r]=o)}("undefined"==typeof window?this:window)},function(t,e){"use strict";function r(){var t;if(!document)return t;for(var e=3,r=document.createElement("div"),n=r.getElementsByTagName("i");r.innerHTML="",n[0];);return e>4?e:t}var n={ieVersion:r};t.exports=n},function(t,e){"use strict";function r(t,e,r){if(t){var o;"function"==typeof e._rollbarOldOnError?o=e._rollbarOldOnError:t.onerror&&!t.onerror.belongsToShim&&(o=t.onerror,e._rollbarOldOnError=o);var i=function(){var r=Array.prototype.slice.call(arguments,0);n(t,e,o,r)};i.belongsToShim=r,t.onerror=i}}function n(t,e,r,n){t._rollbarWrappedError&&(n[4]||(n[4]=t._rollbarWrappedError),n[5]||(n[5]=t._rollbarWrappedError._rollbarContext),t._rollbarWrappedError=null),e.handleUncaughtException.apply(e,n),r&&r.apply(t,n)}function o(t,e,r){if(t){"function"==typeof t._rollbarURH&&t._rollbarURH.belongsToShim&&t.removeEventListener("unhandledrejection",t._rollbarURH);var n=function(t){var r=t.reason,n=t.promise,o=t.detail;!r&&o&&(r=o.reason,n=o.promise),e&&e.handleUnhandledRejection&&e.handleUnhandledRejection(r,n)};n.belongsToShim=r,t._rollbarURH=n,t.addEventListener("unhandledrejection",n)}}function i(t,e,r){if(t){var n,o,i="EventTarget,Window,Node,ApplicationCache,AudioTrackList,ChannelMergerNode,CryptoOperation,EventSource,FileReader,HTMLUnknownElement,IDBDatabase,IDBRequest,IDBTransaction,KeyOperation,MediaController,MessagePort,ModalWindow,Notification,SVGElementInstance,Screen,TextTrack,TextTrackCue,TextTrackList,WebSocket,WebSocketWorker,Worker,XMLHttpRequest,XMLHttpRequestEventTarget,XMLHttpRequestUpload".split(",");for(n=0;n=400&&t.status<600}function c(t,e){var r=new Error(t);return r.code=e||"ENOTFOUND",r}var l=r(5),p=r(11);t.exports={get:n,post:o}},function(t,e){"use strict";function r(t){var e,r,n={protocol:null,auth:null,host:null,path:null,hash:null,href:t,hostname:null,port:null,pathname:null,search:null,query:null};if(e=t.indexOf("//"),e!==-1?(n.protocol=t.substring(0,e),r=e+2):r=0,e=t.indexOf("@",r),e!==-1&&(n.auth=t.substring(r,e),r=e+1),e=t.indexOf("/",r),e===-1){if(e=t.indexOf("?",r),e===-1)return e=t.indexOf("#",r),e===-1?n.host=t.substring(r):(n.host=t.substring(r,e),n.hash=t.substring(e)),n.hostname=n.host.split(":")[0],n.port=n.host.split(":")[1],n.port&&(n.port=parseInt(n.port,10)),n;n.host=t.substring(r,e),n.hostname=n.host.split(":")[0],n.port=n.host.split(":")[1],n.port&&(n.port=parseInt(n.port,10)),r=e}else n.host=t.substring(r,e),n.hostname=n.host.split(":")[0],n.port=n.host.split(":")[1],n.port&&(n.port=parseInt(n.port,10)),r=e;if(e=t.indexOf("#",r),e===-1?n.path=t.substring(r):(n.path=t.substring(r,e),n.hash=t.substring(e)),n.path){var o=n.path.split("?");n.pathname=o[0],n.query=o[1],n.search=n.query?"?"+n.query:null}return n}t.exports={parse:r}},function(t,e,r){"use strict";function n(t,e,r){if(t.data=t.data||{},t.err)try{t.stackInfo=t.err._savedStackTrace||m.parse(t.err)}catch(e){v.error("Error while parsing the error object.",e),t.message=t.err.message||t.err.description||t.message||String(t.err),delete t.err}r(null,t)}function o(t,e,r){t.message||t.stackInfo||t.custom||r(new Error("No message, stack info, or custom data"),null),r(null,t)}function i(t,e,r){var n=e.payload&&e.payload.environment||e.environment;t.data=g.extend(!0,{},t.data,{environment:n,level:t.level,endpoint:e.endpoint,platform:"browser",framework:"browser-js",language:"javascript",server:{},notifier:{name:"rollbar-browser-js",version:e.version}}),r(null,t)}function a(t){ -return function(e,r,n){return t&&t.location?(g.set(e,"data.request",{url:t.location.href,query_string:t.location.search,user_ip:"$remote_ip"}),void n(null,e)):n(null,e)}}function s(t){return function(e,r,n){return t?(g.set(e,"data.client",{runtime_ms:e.timestamp-t._rollbarStartTime,timestamp:Math.round(e.timestamp/1e3),javascript:{browser:t.navigator.userAgent,language:t.navigator.language,cookie_enabled:t.navigator.cookieEnabled,screen:{width:t.screen.width,height:t.screen.height}}}),void n(null,e)):n(null,e)}}function u(t){return function(e,r,n){if(!t||!t.navigator)return n(null,e);for(var o,i=[],a=t.navigator.plugins||[],s=0,u=a.length;s-1&&(e=e.replace(/eval code/g,"eval").replace(/(\(eval at [^\()]*)|(\)\,.*$)/g,""));var r=e.replace(/^\s+/,"").replace(/\(eval code/g,"(").split(/\s+/).slice(1),n=this.extractLocation(r.pop()),o=r.join(" ")||void 0,i="eval"===n[0]?void 0:n[0];return new t(o,void 0,i,n[1],n[2],e)},this)},parseFFOrSafari:function(n){var o=r(n.stack.split("\n"),function(t){return!t.match(i)},this);return e(o,function(e){if(e.indexOf(" > eval")>-1&&(e=e.replace(/ line (\d+)(?: > eval line \d+)* > eval\:\d+\:\d+/g,":$1")),e.indexOf("@")===-1&&e.indexOf(":")===-1)return new t(e);var r=e.split("@"),n=this.extractLocation(r.pop()),o=r.shift()||void 0;return new t(o,void 0,n[0],n[1],n[2],e)},this)},parseOpera:function(t){return!t.stacktrace||t.message.indexOf("\n")>-1&&t.message.split("\n").length>t.stacktrace.split("\n").length?this.parseOpera9(t):t.stack?this.parseOpera11(t):this.parseOpera10(t)},parseOpera9:function(e){for(var r=/Line (\d+).*script (?:in )?(\S+)/i,n=e.message.split("\n"),o=[],i=2,a=n.length;i/,"$2").replace(/\([^\)]*\)/g,"")||void 0;i.match(/\(([^\)]*)\)/)&&(r=i.replace(/^[^\(]+\(([^\)]*)\)$/,"$1"));var s=void 0===r||"[arguments not available]"===r?void 0:r.split(",");return new t(a,s,o[0],o[1],o[2],e)},this)}}})},function(t,e,r){var n,o,i;!function(r,a){"use strict";o=[],n=a,i="function"==typeof n?n.apply(e,o):n,!(void 0!==i&&(t.exports=i))}(this,function(){"use strict";function t(t){return!isNaN(parseFloat(t))&&isFinite(t)}function e(t,e,r,n,o,i){void 0!==t&&this.setFunctionName(t),void 0!==e&&this.setArgs(e),void 0!==r&&this.setFileName(r),void 0!==n&&this.setLineNumber(n),void 0!==o&&this.setColumnNumber(o),void 0!==i&&this.setSource(i)}return e.prototype={getFunctionName:function(){return this.functionName},setFunctionName:function(t){this.functionName=String(t)},getArgs:function(){return this.args},setArgs:function(t){if("[object Array]"!==Object.prototype.toString.call(t))throw new TypeError("Args must be an Array");this.args=t},getFileName:function(){return this.fileName},setFileName:function(t){this.fileName=String(t)},getLineNumber:function(){return this.lineNumber},setLineNumber:function(e){if(!t(e))throw new TypeError("Line Number must be a Number");this.lineNumber=Number(e)},getColumnNumber:function(){return this.columnNumber},setColumnNumber:function(e){if(!t(e))throw new TypeError("Column Number must be a Number");this.columnNumber=Number(e)},getSource:function(){return this.source},setSource:function(t){this.source=String(t)},toString:function(){var e=this.getFunctionName()||"{anonymous}",r="("+(this.getArgs()||[]).join(",")+")",n=this.getFileName()?"@"+this.getFileName():"",o=t(this.getLineNumber())?":"+this.getLineNumber():"",i=t(this.getColumnNumber())?":"+this.getColumnNumber():"";return e+r+n+o+i}},e})},function(t,e,r){"use strict";function n(t,e){var r=t.level,n=c.LEVELS[r]||0,o=c.LEVELS[e.reportLevel]||0;return!(nember-fastboot-addon-tests diff --git a/fastboot-tests/index-test.js b/fastboot-tests/index-test.js new file mode 100644 index 0000000..39351f3 --- /dev/null +++ b/fastboot-tests/index-test.js @@ -0,0 +1,22 @@ +'use strict'; + +const expect = require('chai').expect; +const setupTest = require('ember-fastboot-addon-tests').setupTest; + +describe('index', function() { + setupTest('fastboot'/* , options */); + + it('renders', function() { + return this.visit('/') + .then(function(res) { + let $ = res.jQuery; + let response = res.response; + + // add your real tests here + expect(response.statusCode).to.equal(200); + expect($('body').length).to.equal(1); + expect($('h1').text().trim()).to.equal('ember-fastboot-addon-tests'); + }); + }); + +}); diff --git a/index.js b/index.js index 153c567..c3c8c71 100644 --- a/index.js +++ b/index.js @@ -1,50 +1,57 @@ /* eslint-env node */ -/* eslint no-var: "off", object-shorthand: "off" */ +/* eslint-disable object-shorthand */ 'use strict'; -var merge = require('lodash/merge'); -var replace = require('broccoli-string-replace'); -var mergeTrees = require('broccoli-merge-trees'); -var path = require('path'); +const fastbootTransform = require('fastboot-transform'); +const mergeTrees = require('broccoli-merge-trees'); +const writeFile = require('broccoli-file-creator'); module.exports = { name: 'ember-cli-rollbar', - included: function(app) { - var config = this.project.config(this.app.env).rollbar || {}; - var defaultEnabled = this.app.env !== 'development' && this.app.env !== 'test'; - var enabled = config.enabled == null ? defaultEnabled : config.enabled; - if (process.env.EMBER_CLI_FASTBOOT !== 'true') { - app.import('vendor/rollbar.js', { - prepend: true - }); - app.import('vendor/rollbar-module.js'); + options: { + nodeAssets: { + 'rollbar': function() { + return { + vendor: { + srcDir: 'dist', + include: ['*.js'], + processTree(input) { + return fastbootTransform(input); + } + } + }; + } } }, - treeForVendor: function(vt) { - var vendorTree = this._super.treeForVendor(vt); - if (process.env.EMBER_CLI_FASTBOOT !== 'true') { - var config = this.project.config(this.app.env).rollbar || {}; - config = merge({ - enabled: this.app.env !== 'development' && this.app.env !== 'test', - captureUncaught: true, - payload: { - environment: this.app.env - } - }, config); - var clientTree = replace(path.join(__dirname, 'client'), { - files: ['rollbar.js'], - pattern: { - match: /ROLLBAR_CONFIG/g, - replacement: JSON.stringify(config) - } - }); + _getConfig() { + let env = this.app.env; + // If 'enabled' is not defined in the config, it is intelligently decided on. + // Note that this doesn't affect whether the snipped it *included*. + // It is always included, but this determines whether or not it's enabled. + let defaultEnabled = env !== 'development' && env !== 'test'; + let config = this.project.config(env).rollbar || {}; + config.enabled = typeof config.enabled !== 'undefined' ? config.enabled : defaultEnabled; + return config; + }, - return mergeTrees([vendorTree, clientTree], { - overwrite: true - }); - } else { - return vendorTree; - } + _generateConfigTree() { + return writeFile('ember-cli-rollbar/config.js', ` + window._rollbarConfig = ${JSON.stringify(this._getConfig())}; + `); + }, + + treeForVendor(tree) { + tree = mergeTrees([tree, this._generateConfigTree()]); + return this._super.treeForVendor.call(this, tree); + }, + + included: function(app) { + this._super.included.apply(this, arguments); + + // Always include, but it may be disabled based on the configuration. + app.import('vendor/rollbar/rollbar.snippet.js', { prepend: true }); + app.import('vendor/ember-cli-rollbar/config.js', { prepend: true }); + app.import('vendor/rollbar-module.js'); } }; diff --git a/package.json b/package.json index 4a25176..7710c8a 100644 --- a/package.json +++ b/package.json @@ -15,36 +15,37 @@ "scripts": { "build": "ember build", "start": "ember server", - "test": "ember try:each", - "update-snippet": "tasks/update-snippet.sh" + "test": "ember try:each" }, "dependencies": { - "broccoli-merge-trees": "^1.1.1", - "broccoli-string-replace": "^0.1.1", + "broccoli-file-creator": "^1.1.1", + "broccoli-merge-trees": "^2.0.0", "ember-cli-babel": "^6.3.0", - "lodash": "^4.11.1" + "ember-cli-node-assets": "^0.2.2", + "fastboot-transform": "^0.1.2" }, "devDependencies": { "broccoli-asset-rev": "^2.4.5", - "ember-ajax": "^3.0.0", + "chai": "^4.1.2", "ember-cli": "~2.15.1", "ember-cli-dependency-checker": "^2.0.0", "ember-cli-eslint": "^4.0.0", "ember-cli-htmlbars": "^2.0.1", "ember-cli-htmlbars-inline-precompile": "^1.0.0", "ember-cli-inject-live-reload": "^1.4.1", - "ember-cli-qunit": "^4.0.0", + "ember-cli-qunit": "^4.0.1", "ember-cli-shims": "^1.1.0", "ember-cli-sri": "^2.1.0", "ember-cli-uglify": "^1.2.0", "ember-disable-prototype-extensions": "^1.1.2", "ember-export-application-global": "^2.0.0", + "ember-fastboot-addon-tests": "^0.4.0", "ember-load-initializers": "^1.0.0", "ember-resolver": "^4.0.0", - "ember-try": "^0.2.17", "ember-source": "~2.15.0", "ember-welcome-page": "^3.0.0", - "loader.js": "^4.2.3" + "loader.js": "^4.2.3", + "rollbar": "^2.2.8" }, "engines": { "node": "^4.5 || 6.* || >= 7.*" diff --git a/tasks/update-snippet.sh b/tasks/update-snippet.sh deleted file mode 100755 index 19853e8..0000000 --- a/tasks/update-snippet.sh +++ /dev/null @@ -1,22 +0,0 @@ -snippeturl="https://raw.githubusercontent.com/rollbar/rollbar.js/master/dist/rollbar.snippet.js" -packageurl="https://raw.githubusercontent.com/rollbar/rollbar.js/master/package.json" - -echo "/*jshint ignore:start*/" > client/rollbar.js -echo "window._rollbarConfig = ROLLBAR_CONFIG;" > client/rollbar.js -curl --silent $snippeturl >> client/rollbar.js -echo "/*jshint ignore:end*/" >> client/rollbar.js -if $(git diff-index --quiet --cached HEAD); then - echo "Committing changes ..." - version=$(curl --silent $packageurl | grep 'version": "' | head -n 1 | cut -d '"' -f 4) - git add addon/snippet.js - git commit -m "update rollbar snippet to version $version" - echo "Publishing changes ..." - npm version patch -m "update rollbar snippet to version $version" - git push origin master - git push origin --tags - npm publish -else - echo "Git index is dirty, skipping git commit and npm publish steps" -fi - -echo "Snippet updated!" diff --git a/vendor/rollbar-module.js b/vendor/rollbar-module.js index 7b94763..c11c8cc 100644 --- a/vendor/rollbar-module.js +++ b/vendor/rollbar-module.js @@ -1,5 +1,5 @@ (function() { - /* globals define, Rollbar */ + /* globals define */ function generateModule(name, values) { define(name, [], function() { @@ -9,5 +9,5 @@ }); } - generateModule('rollbar', { 'default': Rollbar }); + generateModule('rollbar', { 'default': window.Rollbar }); })();