Skip to content

Commit

Permalink
Fixes code included in production builds [#108] (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew A Lee authored Sep 27, 2019
1 parent eddb7cb commit b671586
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
7 changes: 5 additions & 2 deletions addon/instance-initializers/axe-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function initialize(appInstance) {

const {
turnAuditOff: configuredTurnAuditOff,
excludeAxeCore,
excludeAxeCore = false,
axeOptions = {},
axeCallback,
visualNoiseLevel: configuredVisualNoiseLevel,
Expand All @@ -59,7 +59,10 @@ export function initialize(appInstance) {

// Avoid modifying the Component class if the visual audit feature is configured disabled
// and axe-core is excluded from the dev build
if (turnAuditOff && excludeAxeCore) { return; }
if ((turnAuditOff && excludeAxeCore) || typeof axe === 'undefined') {
hasRan = true;
return;
}

Component.reopen({
/**
Expand Down
27 changes: 25 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,34 @@ module.exports = {
treeForApp: function(tree) {
var checker = new VersionChecker(this);
var isProductionBuild = process.env.EMBER_ENV === 'production';
var isOldEmber = checker.for('ember', 'bower').lt('1.13.0');
var isOldEmber = checker.forEmber().lt('1.13.0');

if (isProductionBuild || isOldEmber) {
tree = new Funnel(tree, {
exclude: [/instance-initializers\/axe-component|violations-helper.js/]
exclude: [/instance-initializers\/(axe-component|violations-helper)\.js/]
});
}

return tree;
},

/**
* Exclude all addon code during build if this is a
* production build or if the version of Ember being used is less than 1.13.
* @override
*/
treeForAddon: function() {
var tree = this._super.treeForAddon.apply(this, arguments);
var checker = new VersionChecker(this);
var isProductionBuild = process.env.EMBER_ENV === 'production';
var isOldEmber = checker.forEmber().lt('1.13.0');

if (isProductionBuild || isOldEmber) {
tree = new Funnel(tree, {
exclude: [
/instance-initializers\/(axe-component|violations-helper)\.js/,
/utils\/(concurrent-axe|format-violation|is-background-replaced-element|violations-helper)\.js/
]
});
}

Expand Down

0 comments on commit b671586

Please sign in to comment.