forked from tylerturdenpants/ember-attacher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
72 lines (57 loc) · 1.83 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* eslint-env node */
'use strict';
const FilterImports = require('babel-plugin-filter-imports');
const Funnel = require('broccoli-funnel');
module.exports = {
name: require('./package').name,
included(app) {
this._super.included.apply(this, arguments);
this._env = app.env;
this._setupBabelOptions(app.env);
},
_hasSetupBabelOptions: false,
_setupBabelOptions(env) {
if (this._hasSetupBabelOptions) {
return;
}
if (/production/.test(env)) {
// In some versions of Ember, this.options is undefined during tests
this.options = this.options || {};
// Make sure the babel options are accessible
const babelOptions = this.options.babel = this.options.babel || {};
babelOptions.plugins = babelOptions.plugins || [];
babelOptions.postTransformPlugins = babelOptions.postTransformPlugins || [];
const strippedImports = {
'imports': {
'ember-attacher/-debug/helpers': [
'assert',
'debug',
'debugOnError',
'stripInProduction'
]
}
};
babelOptions.plugins.push([FilterImports, strippedImports]);
}
this._hasSetupBabelOptions = true;
},
treeForAddon(tree) {
if (/production/.test(this._env)) {
tree = new Funnel(tree, { exclude: [/-debug/] });
}
return this._super.treeForAddon.call(this, tree);
},
treeForAddonTestSupport(tree) {
// intentionally not calling _super here
// so that can have our `import`'s be
// import { click, fillIn } from 'ember-native-dom-helpers';
const namespacedTree = new Funnel(tree, {
srcDir: '/',
destDir: `/${this.moduleName()}`,
annotation: `Addon#treeForTestSupport (${this.name})`
});
return this.preprocessJs(namespacedTree, '/', this.name, {
registry: this.registry
});
}
};