Skip to content

Commit

Permalink
feat(code-stripping): remove classCallChecks for perf, strip unused c…
Browse files Browse the repository at this point in the history
…ode from builds
  • Loading branch information
runspired committed Sep 24, 2016
1 parent ce9f942 commit dc04f49
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 2 deletions.
32 changes: 32 additions & 0 deletions addon/-debug/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import Ember from 'ember';

const {
assert: emberAssert,
warn: emberWarn,
deprecate: emberDeprecate,
Logger
} = Ember;

export function instrument(cb) {
cb();
}

export function debug() {
Logger.debug(...arguments);
}

export function assert() {
emberAssert(...arguments);
}

export function warn() {
emberWarn(...arguments);
}

export function deprecate() {
emberDeprecate(...arguments);
}

export function stripInProduction(cb) {
cb();
}
4 changes: 2 additions & 2 deletions addon/components/vertical-collection/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import getTagDescendant from '../../utils/get-tag-descendant';
import proxied from '../../utils/proxied-array';
import ListRadar from '../../-private/radar/models/list-radar';
import identity from '../../-private/ember/utils/identity';

import { stripInProduction } from 'smoke-and-mirrors/-debug/helpers';
const {
get,
computed,
Expand Down Expand Up @@ -960,7 +960,7 @@ VerticalCollection.reopenClass({
positionalParams: ['items']
});

Ember.runInDebug(() => {
stripInProduction(() => {
VerticalCollection.reopen(DebugMixin);
});

Expand Down
51 changes: 51 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,52 @@
'use strict';

var chalk = require('chalk');
var stripClassCallCheck = require('babel5-plugin-strip-class-callcheck');
var filterImports = require('babel-plugin-filter-imports');
var Funnel = require('broccoli-funnel');

module.exports = {
name: 'smoke-and-mirrors',

init: function() {
this._super.init && this._super.init.apply(this, arguments);

this.options = this.options || {};
},

_hasSetupBabelOptions: false,
_setupBabelOptions: function(env) {
if (this._hasSetupBabelOptions) {
return;
}

var babelOptions = this.options.babel = this.options.babel || {};

babelOptions.plugins = babelOptions.plugins || [];
babelOptions.plugins.push({ transformer: stripClassCallCheck, position: 'after' });

if (/production/.test(env)) {
babelOptions.plugins.push(
filterImports({
'smoke-and-mirrors/-debug/helpers': [
'assert',
'warn',
'debug',
'instrument',
'deprecate',
'stripInProduction'
]})
);
}

this._hasSetupBabelOptions = true;
},

included: function(app) {
this._super.included.apply(this, arguments);

this._setupBabelOptions(app.env);

if (!/production/.test(app.env)) {
console.info(
chalk.grey("\n===================================================================\n") +
Expand All @@ -21,6 +62,16 @@ module.exports = {
}
},

treeForAddon: function() {
var tree = this._super.treeForAddon.apply(this, arguments);

if (/production/.test(this.app.env)) {
tree = new Funnel(tree, { exclude: [ /-debug/ ] });
}

return tree;
},

isDevelopingAddon: function() {
return false;
}
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
"ember-addon"
],
"dependencies": {
"babel-plugin-filter-imports": "^0.2.1",
"babel5-plugin-strip-class-callcheck": "^5.1.0",
"broccoli-funnel": "^1.0.7",
"chalk": "^1.1.3",
"ember-cli-babel": "^5.1.6",
"ember-cli-htmlbars": "^1.0.3",
Expand Down

0 comments on commit dc04f49

Please sign in to comment.