Skip to content
Permalink
Browse files

Strips out BOOMR.debug and related messages for production builds

  • Loading branch information
nicjansma committed Dec 26, 2018
1 parent e3af081 commit d7c485df923e6af7e16379ff50970cb97442d0f6
Showing with 95 additions and 54 deletions.
  1. +12 −0 Gruntfile.js
  2. +14 −4 package-lock.json
  3. +1 −1 package.json
  4. +6 −4 plugins/angular.js
  5. +12 −7 plugins/auto-xhr.js
  6. +5 −3 plugins/backbone.js
  7. +9 −7 plugins/ember.js
  8. +16 −14 plugins/history.js
  9. +9 −5 plugins/iframe-delay.js
  10. +11 −9 plugins/spa.js
@@ -331,6 +331,17 @@ module.exports = function() {
end_comment: "END_DEBUG"
}
},
"debug-log": {
files: [{
src: buildRelease
}],
options: {
patterns: [
/BOOMR\.debug\(.*\);/g,
/debugLog\(.*\);/g
]
}
},
prod: {
files: [
{
@@ -920,6 +931,7 @@ module.exports = function() {
"!string-replace:debug-tests",
"string-replace:release",
"!strip_code:debug",
"!strip_code:debug-log",
"!strip_code:prod"
],

Some generated files are not rendered by default. Learn more.

@@ -53,7 +53,7 @@
"grunt-react": "^0.12.3",
"grunt-saucelabs": "^8.6.2",
"grunt-string-replace": "^1.0.0",
"grunt-strip-code": "^0.1.2",
"grunt-strip-code": "^1.0.6",
"grunt-template": "^0.2.3",
"gruntify-eslint": "^3.1.0",
"history": "^1.12.5",
@@ -115,14 +115,16 @@
return false;
}

/* BEGIN_DEBUG */
/**
* Debug logging for this $rootScope's ID
*
* @param {string} msg Message
*/
function log(msg) {
function debugLog(msg) {
BOOMR.debug($rootScope.$id + ": " + msg, "Angular");
}
/* END_DEBUG */

/**
* Fires the SPA route_change event.
@@ -167,7 +169,7 @@
return;
}

log("$routeChangeStart: " + (next ? next.templateUrl : ""));
debugLog("$routeChangeStart: " + (next ? next.templateUrl : ""));

fireRouteChange(event, next, current);

@@ -182,7 +184,7 @@
return;
}

log("$locationChangeStart: " + newState);
debugLog("$locationChangeStart: " + newState);

BOOMR.fireEvent("spa_init", [BOOMR.plugins.SPA.current_spa_nav(), newState]);

@@ -206,7 +208,7 @@
return;
}

log("$stateChangeStart: " + toState);
debugLog("$stateChangeStart: " + toState);

fireRouteChange(event, toState, toParams, fromState, fromParams);

@@ -328,9 +328,11 @@
return;
}

function log(msg) {
/* BEGIN_DEBUG */
function debugLog(msg) {
BOOMR.debug(msg, "AutoXHR");
}
/* END_DEBUG */

/**
* Tries to resolve `href` links from relative URLs.
@@ -566,7 +568,7 @@
// If we have a pending SPA event, send an aborted load beacon before
// adding the new SPA event
if (BOOMR.utils.inArray(ev.type, BOOMR.constants.BEACON_TYPE_SPAS)) {
log("Aborting previous SPA navigation");
debugLog("Aborting previous SPA navigation");

// mark the end of this navigation as now
last_ev.resource.timing.loadEventEnd = BOOMR.now();
@@ -655,7 +657,7 @@
// if this was a SPA soft nav with no URL change and did not trigger additional resources
// then we will not send a beacon
if (ev.type === "spa" && ev.total_nodes === 0 && ev.resource.url === self.lastSpaLocation) {
log("SPA beacon cancelled, no URL change or resources triggered");
debugLog("SPA beacon cancelled, no URL change or resources triggered");
BOOMR.fireEvent("spa_cancel");
this.pending_events[index] = undefined;
return;
@@ -1168,7 +1170,7 @@
a.href = url;

if (impl.excludeFilter(a)) {
log("Exclude for " + a.href + " matched. Excluding");
debugLog("Exclude for " + a.href + " matched. Excluding");
// excluded resource, so abort
return false;
}
@@ -1910,7 +1912,7 @@
if (impl.excludeFilter(a)) {
// this xhr should be excluded from instrumentation
excluded = true;
log("Exclude found for resource: " + a.href + " Skipping XHR instrumentation!");
debugLog("Exclude found for resource: " + a.href + " Skipping XHR instrumentation!");
// call the original open method
return orig_open.apply(req, arguments);
}
@@ -2175,15 +2177,18 @@
if (typeof impl.excludeFilters[idx].cb === "function") {
ctx = impl.excludeFilters[idx].ctx;
if (impl.excludeFilters[idx].name) {
log("Running filter: " + impl.excludeFilters[idx].name + " on URL: " + anchor.href);
debugLog("Running filter: " + impl.excludeFilters[idx].name + " on URL: " + anchor.href);
}

try {
ret = impl.excludeFilters[idx].cb.call(ctx, anchor);
if (ret) {
log("Found matching filter at: " +
/* BEGIN_DEBUG */
debugLog("Found matching filter at: " +
impl.excludeFilters[idx].name + " for URL: " +
anchor.href);
/* END_DEBUG */

return true;
}
}
@@ -100,16 +100,18 @@
return false;
}

/* BEGIN_DEBUG */
/**
* Debug logging
*
* @param {string} msg Message
*/
function log(msg) {
function debugLog(msg) {
BOOMR.debug(msg, "Backbone");
}
/* END_DEBUG */

log("Startup");
debugLog("Startup");

// Listen for the 'route' event on the Backbone Router, which is fired whenever a
// route changes (i.e. a soft navigation, which is associated with the
@@ -122,7 +124,7 @@

BOOMR.fireEvent("spa_init", [BOOMR.plugins.SPA.current_spa_nav(), BOOMR.window.document.URL]);

log("route");
debugLog("route");
BOOMR.plugins.SPA.route_change();
});

@@ -90,16 +90,18 @@
return false;
}

/* BEGIN_DEBUG */
/**
* Debug logging for this $rootScope's ID
*
* @param {string} msg Message
*/
function log(msg) {
function debugLog(msg) {
BOOMR.debug(msg, "Ember");
}
/* END_DEBUG */

log("Startup");
debugLog("Startup");

/**
* Called for the Ember `beforeModel` event.
@@ -118,10 +120,10 @@
return true;
}

log("beforeModel");
debugLog("beforeModel");

if (transition && transition.intent && transition.intent.url) {
log("[beforeModel] LastLocation: " + transition.intent.url);
debugLog("[beforeModel] LastLocation: " + transition.intent.url);

transition.promise.then(function() {
BOOMR.fireEvent("spa_init", [BOOMR.plugins.SPA.current_spa_nav(), BOOMR.window.document.URL]);
@@ -152,10 +154,10 @@
return true;
}

log("willTransition");
debugLog("willTransition");

if (transition && transition.intent && transition.intent.url) {
log("[willTransition] LastLocation: " + transition.intent.url);
debugLog("[willTransition] LastLocation: " + transition.intent.url);

transition.promise.then(function() {
BOOMR.fireEvent("spa_init", [BOOMR.plugins.SPA.current_spa_nav(), BOOMR.window.document.URL]);
@@ -181,7 +183,7 @@
return true;
}

log("didTransition");
debugLog("didTransition");
routeHooked = false;
}

@@ -124,7 +124,7 @@
* Clears routeChangeInProgress flag
*/
resetRouteChangeInProgress: function() {
log("resetting routeChangeInProgress");
debugLog("resetting routeChangeInProgress");
if (impl.routeChangeInProgress) {
clearTimeout(impl.routeChangeInProgress);
}
@@ -169,7 +169,7 @@
*/
routeChange: function(title, url) {
if (!impl.enabled) {
log("Not enabled - we've missed a routeChange");
debugLog("Not enabled - we've missed a routeChange");
impl.hadMissedRouteChange = true;
impl.resetRouteChangeInProgress();
}
@@ -181,12 +181,12 @@
}

if (!impl.routeChangeInProgress) {
log("routeChange triggered, sending route_change() event");
debugLog("routeChange triggered, sending route_change() event");
impl.spaInit(title, url);
BOOMR.plugins.SPA.route_change();
}
else {
log("routeChangeInProgress, not triggering");
debugLog("routeChangeInProgress, not triggering");
}
}
}
@@ -212,14 +212,16 @@

impl.a = BOOMR.window.document.createElement("A");

/* BEGIN_DEBUG */
/**
* Debug logging for this instance
*
* @param {string} msg Message
*/
function log(msg) {
function debugLog(msg) {
BOOMR.debug(msg, "History");
};
/* END_DEBUG */

/**
* Hook into `window.history` Object
@@ -242,7 +244,7 @@
*/
function aelPopstate() {
BOOMR.window.addEventListener("popstate", function(event) {
log("popstate");
debugLog("popstate");
impl.routeChange();
});
}
@@ -254,7 +256,7 @@
if (typeof history.pushState === "function") {
history.pushState = (function(_pushState) {
return function(state, title, url) {
log("pushState, title: " + title + " url: " + url);
debugLog("pushState, title: " + title + " url: " + url);
impl.routeChange(title, url);
return _pushState.apply(this, arguments);
};
@@ -274,11 +276,11 @@

// only issue route change if a nav is not in progress or the URL is changing
if (!BOOMR.plugins.SPA.isSpaNavInProgress() || toUrl !== fromUrl) {
log("replaceState, title: " + title + " url: " + url);
debugLog("replaceState, title: " + title + " url: " + url);
impl.routeChange(title, url);
}
else {
log("replaceState ignored (no URL change and a SPA nav is in progress), title: " + title + " url: " + url);
debugLog("replaceState ignored (no URL change and a SPA nav is in progress), title: " + title + " url: " + url);
}

return _replaceState.apply(this, arguments);
@@ -292,7 +294,7 @@
history.go = (function(_go) {
return function(index) {
var res;
log("go");
debugLog("go");
impl.routeChange(); // spa_init url will be the url before `go` runs
return _go.apply(this, arguments);
};
@@ -303,7 +305,7 @@
history.back = (function(_back) {
return function() {
var res;
log("back");
debugLog("back");
impl.routeChange(); // spa_init url will be the url before `back` runs
return _back.apply(this, arguments);
};
@@ -314,7 +316,7 @@
history.forward = (function(_forward) {
return function() {
var res;
log("forward");
debugLog("forward");
impl.routeChange(); // spa_init url will be the url before `forward` runs
return _forward.apply(this, arguments);
};
@@ -324,7 +326,7 @@
// listen for hash changes
BOOMR.window.addEventListener("hashchange", function(event) {
var url = (event || {}).newURL;
log("hashchange " + url);
debugLog("hashchange " + url);
impl.routeChange(null, url);
});

@@ -452,7 +454,7 @@
impl.hadMissedRouteChange = false;
BOOMR.plugins.SPA.route_change();
impl.setRouteChangeInProgress();
log("Hooked and hadMissedRouteChange sending route_change!");
debugLog("Hooked and hadMissedRouteChange sending route_change!");
}

return this;

0 comments on commit d7c485d

Please sign in to comment.
You can’t perform that action at this time.