-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathindex.js
75 lines (62 loc) · 2.12 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
'use strict';
function isProductionEnv() {
return /production/.test(process.env.EMBER_ENV);
}
module.exports = {
name: require('./package').name,
_getParentOptions() {
let options;
// The parent can either be an Addon or a Project. If it's an addon,
// we want to use the app instead. This public method probably wasn't meant
// for this, but it's named well enough that we can use it for this purpose.
if (this.parent && !this.parent.isEmberCLIProject) {
options = this.parent.options = this.parent.options || {};
} else {
options = this.app.options = this.app.options || {};
}
return options;
},
included(parent) {
this._super.included.apply(this, arguments);
let parentOptions = this._getParentOptions();
// Create babel options if they do not exist
parentOptions.babel = parentOptions.babel || {};
parentOptions.babel.plugins = parentOptions.babel.plugins || [];
// We emit macros from our babel plugin, which means our parent also needs
// the macros babel plugin.
this.addons
.find((a) => a.name === '@embroider/macros')
.installBabelPlugin(parent);
if (isProductionEnv()) {
let hasPlugin = parentOptions.babel.plugins
.filter((definition) => Array.isArray(definition))
.some(
(definition) =>
definition[2] === 'filter-imports:ember-classic-decorator'
);
if (!hasPlugin) {
parentOptions.babel.plugins.push([
require.resolve('babel-plugin-filter-imports'),
{
imports: {
'ember-classic-decorator': ['default'],
},
},
'filter-imports:ember-classic-decorator',
]);
}
} else {
this.import('vendor/classic-decorator/index.js');
let hasPlugin = parentOptions.babel.plugins.some(
(definition) =>
typeof definition === 'string' &&
definition.match('classic-decorator-transform')
);
if (!hasPlugin) {
parentOptions.babel.plugins.push(
require.resolve('./lib/classic-decorator-transform-v4')
);
}
}
},
};