From b76c095f80787e76a2e3a72bea3022f2fc4dded7 Mon Sep 17 00:00:00 2001 From: Paul Watts Date: Fri, 23 Jun 2017 08:39:18 -0700 Subject: [PATCH 1/4] New implementation This is basically a rewrite that: 1. Removes the included snippet, and instead includes the snippet from the rollbar node library. 2. Use a default addon blueprint to add the rollbar package to the host app. This allows the host to update the rollbar package without having to upgrade ember-cli-rollbar. 3. Use ember-cli-node-assets to include the vendor file. 4. Use broccoli-file-writer to generate the config. This does not yet support Fastboot -- that's coming up. --- blueprints/ember-cli-rollbar/index.js | 13 +++++ client/.gitkeep | 0 client/rollbar.js | 3 - index.js | 81 ++++++++++++++------------- package.json | 13 ++--- tasks/update-snippet.sh | 22 -------- 6 files changed, 62 insertions(+), 70 deletions(-) create mode 100644 blueprints/ember-cli-rollbar/index.js delete mode 100644 client/.gitkeep delete mode 100644 client/rollbar.js delete mode 100755 tasks/update-snippet.sh 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!(n= 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!" From 314d80852b42389f3430c26446f5d67fd05cc5ff Mon Sep 17 00:00:00 2001 From: Paul Watts Date: Fri, 23 Jun 2017 09:01:49 -0700 Subject: [PATCH 2/4] Update initializer Update to be consistent with the code style. --- app/initializers/rollbar.js | 84 +++++++++++++++++++------------------ 1 file changed, 44 insertions(+), 40 deletions(-) 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 }; From 96871445b821ccde48934a0891af81a63ebaa254 Mon Sep 17 00:00:00 2001 From: Paul Watts Date: Fri, 23 Jun 2017 09:50:21 -0700 Subject: [PATCH 3/4] Don't break Fastboot 1. Using the new Fastboot standards, don't run the snippet if Fastboot isn't defined, because the snippet requires 'document'. 2. Reference Rollbar using window.Rollbar in the vendor shim, because 'Rollbar' is undefined in Fastboot. 3. Add a very basic test to test these. Note this doesn't do much besides ensure that the app doesn't break when Fastboot is enabled. The vendor shim won't work, and since window.Rollbar won't be defined, it won't actually forward any of the calls. --- .travis.yml | 1 + config/ember-try.js | 7 ++++++ fastboot-tests/.eslintrc.js | 14 ++++++++++++ .../fixtures/fastboot/app/router.js | 12 ++++++++++ .../fixtures/fastboot/app/templates/index.hbs | 1 + fastboot-tests/index-test.js | 22 +++++++++++++++++++ index.js | 8 ++++--- package.json | 10 +++++---- vendor/rollbar-module.js | 4 ++-- 9 files changed, 70 insertions(+), 9 deletions(-) create mode 100644 fastboot-tests/.eslintrc.js create mode 100644 fastboot-tests/fixtures/fastboot/app/router.js create mode 100644 fastboot-tests/fixtures/fastboot/app/templates/index.hbs create mode 100644 fastboot-tests/index-test.js diff --git a/.travis.yml b/.travis.yml index f8fcf47..9064be5 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/config/ember-try.js b/config/ember-try.js index 21f6079..0f14409 100644 --- a/config/ember-try.js +++ b/config/ember-try.js @@ -78,6 +78,13 @@ module.exports = { npm: { devDependencies: {} } + }, + { + name: 'fastboot-addon-tests', + command: 'ember fastboot:test', + bower: { + dependencies: {} + } } ] }; diff --git a/fastboot-tests/.eslintrc.js b/fastboot-tests/.eslintrc.js new file mode 100644 index 0000000..a0e76cd --- /dev/null +++ b/fastboot-tests/.eslintrc.js @@ -0,0 +1,14 @@ +module.exports = { + root: true, + parserOptions: { + ecmaVersion: 2017, + sourceType: 'module' + }, + extends: [ + 'eslint:recommended' + ], + env: { + node: true, + mocha: true + } +}; diff --git a/fastboot-tests/fixtures/fastboot/app/router.js b/fastboot-tests/fixtures/fastboot/app/router.js new file mode 100644 index 0000000..cdc2578 --- /dev/null +++ b/fastboot-tests/fixtures/fastboot/app/router.js @@ -0,0 +1,12 @@ +import Ember from 'ember'; +import config from './config/environment'; + +const Router = Ember.Router.extend({ + location: config.locationType, + rootURL: config.rootURL +}); + +Router.map(function() { +}); + +export default Router; diff --git a/fastboot-tests/fixtures/fastboot/app/templates/index.hbs b/fastboot-tests/fixtures/fastboot/app/templates/index.hbs new file mode 100644 index 0000000..7d6fc1c --- /dev/null +++ b/fastboot-tests/fixtures/fastboot/app/templates/index.hbs @@ -0,0 +1 @@ +

ember-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 48c9bb6..c3c8c71 100644 --- a/index.js +++ b/index.js @@ -2,6 +2,7 @@ /* eslint-disable object-shorthand */ 'use strict'; +const fastbootTransform = require('fastboot-transform'); const mergeTrees = require('broccoli-merge-trees'); const writeFile = require('broccoli-file-creator'); @@ -13,9 +14,10 @@ module.exports = { return { vendor: { srcDir: 'dist', - include: [ - '*.js' - ] + include: ['*.js'], + processTree(input) { + return fastbootTransform(input); + } } }; } diff --git a/package.json b/package.json index e3922c0..7710c8a 100644 --- a/package.json +++ b/package.json @@ -21,29 +21,31 @@ "broccoli-file-creator": "^1.1.1", "broccoli-merge-trees": "^2.0.0", "ember-cli-babel": "^6.3.0", - "ember-cli-node-assets": "^0.2.2" + "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-source": "~2.15.0", "ember-welcome-page": "^3.0.0", "loader.js": "^4.2.3", - "rollbar": "^2.0.4" + "rollbar": "^2.2.8" }, "engines": { "node": "^4.5 || 6.* || >= 7.*" 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 }); })(); From c68a3936b3d68ad624ece6910d8beccaf775497d Mon Sep 17 00:00:00 2001 From: Paul Watts Date: Wed, 25 Oct 2017 17:15:54 -0500 Subject: [PATCH 4/4] Disable Fastboot tests They don't work with Node 4, and Fastboot doesn't really work to begin with. --- .travis.yml | 2 +- config/ember-try.js | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9064be5..0728a4d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,7 +24,7 @@ env: - EMBER_TRY_SCENARIO=ember-beta - EMBER_TRY_SCENARIO=ember-canary - EMBER_TRY_SCENARIO=ember-default - - EMBER_TRY_SCENARIO=fastboot-addon-tests + # - EMBER_TRY_SCENARIO=fastboot-addon-tests matrix: fast_finish: true diff --git a/config/ember-try.js b/config/ember-try.js index 0f14409..da3e86e 100644 --- a/config/ember-try.js +++ b/config/ember-try.js @@ -78,13 +78,14 @@ module.exports = { npm: { devDependencies: {} } - }, + } + /*, { name: 'fastboot-addon-tests', command: 'ember fastboot:test', bower: { dependencies: {} } - } + }*/ ] };