-
Notifications
You must be signed in to change notification settings - Fork 35
/
index.js
117 lines (98 loc) · 2.88 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/* eslint-env node */
'use strict';
const Funnel = require('broccoli-funnel');
const StripClassCallCheck = require('babel6-plugin-strip-class-callcheck');
const fastbootTransform = require('fastboot-transform');
const VersionChecker = require('ember-cli-version-checker');
module.exports = {
name: 'ember-popper',
options: {
nodeAssets: {
'popper.js': {
srcDir: 'dist/umd',
import: {
include: ['popper.js'],
processTree(input) {
return fastbootTransform(input);
}
},
vendor: ['popper.js.map']
}
}
},
included(parent) {
this._super.included.apply(this, arguments);
let app = parent;
while (!app.import) {
app = app.parent;
}
const checker = new VersionChecker(app);
this._emberChecker = checker.forEmber();
this._env = app.env;
this._setupBabelOptions(app.env);
},
_hasSetupBabelOptions: false,
_setupBabelOptions(env) {
if (this._hasSetupBabelOptions) {
return;
}
if (/production/.test(env) || /test/.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.postTransformPlugins = babelOptions.postTransformPlugins || [];
babelOptions.postTransformPlugins.push(StripClassCallCheck);
}
this._hasSetupBabelOptions = true;
},
treeForAddonTemplates(tree) {
const { _emberChecker } = this;
if (_emberChecker.gte('2.10.0')) {
tree = new Funnel(tree, {
exclude: [
'components/-ember-popper-legacy.hbs',
'components/-ember-popper-legacy-1.11.hbs'
]
});
} else if (_emberChecker.gte('1.13.0')) {
tree = new Funnel(tree, {
exclude: [
'components/ember-popper.hbs',
'components/-ember-popper-legacy-1.11.hbs'
],
getDestinationPath: replaceLegacyPath
});
} else {
tree = new Funnel(tree, {
exclude: [
'components/ember-popper.hbs',
'components/-ember-popper-legacy.hbs'
],
getDestinationPath: replaceLegacyPath
});
}
return this._super.treeForAddonTemplates.call(this, tree);
},
treeForAddon(tree) {
const { _emberChecker } = this;
if (_emberChecker.gte('2.10.0')) {
tree = new Funnel(tree, {
exclude: [
'components/-ember-popper-legacy.js'
]
});
} else {
tree = new Funnel(tree, {
exclude: [
'components/ember-popper.js'
],
getDestinationPath: replaceLegacyPath
});
}
return this._super.treeForAddon.call(this, tree);
}
};
function replaceLegacyPath(relativePath) {
return relativePath.replace(/-ember-popper-legacy(-1.11)?/g, 'ember-popper');
}