diff --git a/lib/stripped-build-plugins.js b/lib/stripped-build-plugins.js index 0376c36e2d4..24e0141bd2b 100644 --- a/lib/stripped-build-plugins.js +++ b/lib/stripped-build-plugins.js @@ -4,10 +4,21 @@ var filterImports = require('babel-plugin-filter-imports'); var featureFlags = require('babel-plugin-feature-flags'); var stripHeimdall = require('babel5-plugin-strip-heimdall'); +function uniqueAdd(obj, key, values) { + var a = obj[key] = obj[key] || []; + + for (var i = 0; i < values.length; i++) { + if (a.indexOf(values[i]) === -1) { + a.push(values[i]); + } + } +} + module.exports = function(environment) { var featuresJsonPath = __dirname + '/../config/features.json'; var featuresJson = fs.readFileSync(featuresJsonPath, { encoding: 'utf8' }); var features = JSON.parse(featuresJson); + var filteredImports = {}; // TODO explicitly set all features which are not enabled to `false`, so // they are stripped --> make this configurable or pass features @@ -25,34 +36,25 @@ module.exports = function(environment) { ]; if (process.env.INSTRUMENT_HEIMDALL === 'false') { - plugins.push( - stripHeimdall, - filterImports({ - 'ember-data/-private/debug': [ - 'instrument' - ] - }) - ); + plugins.push(stripHeimdall); + uniqueAdd(filteredImports, 'ember-data/-private/debug', ['instrument']); } else { console.warn('NOT STRIPPING HEIMDALL'); } if (environment === 'production') { - plugins.push( - filterImports({ - 'ember-data/-private/debug': [ - 'assert', - 'assertPolymorphicType', - 'debug', - 'deprecate', - 'info', - 'runInDebug', - 'warn', - 'debugSeal' - ] - }) - ); + uniqueAdd(filteredImports, 'ember-data/-private/debug', [ + 'assert', + 'assertPolymorphicType', + 'debug', + 'deprecate', + 'info', + 'runInDebug', + 'warn', + 'debugSeal' + ]); } + plugins.push(filterImports(filteredImports)); return plugins; };