Skip to content

Commit

Permalink
safe merge filtered imports
Browse files Browse the repository at this point in the history
  • Loading branch information
runspired committed Sep 30, 2016
1 parent b49e4ee commit 7a1a957
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions lib/stripped-build-plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
};

0 comments on commit 7a1a957

Please sign in to comment.