UNPKG

1.95 kBJavaScriptView Raw
1const {
2 _addDecoratorPlugins,
3 _addTypeScriptPlugin,
4 _getAddonProvidedConfig,
5 _shouldCompileModules,
6 _shouldIncludeHelpers,
7 _shouldHandleTypeScript,
8 _shouldIncludeDecoratorPlugins,
9 _getHelpersPlugin,
10 _getDebugMacroPlugins,
11 _getEmberModulesAPIPolyfill,
12 _getEmberDataPackagesPolyfill,
13 _getModulesPlugin,
14 _getPresetEnv,
15} = require("./babel-options-util");
16
17module.exports = function getBabelOptions(config, appInstance) {
18 let { parent, project } = appInstance;
19 let addonProvidedConfig = _getAddonProvidedConfig(config);
20 let shouldIncludeHelpers = _shouldIncludeHelpers(config, appInstance);
21 let shouldHandleTypeScript = _shouldHandleTypeScript(config, parent, project);
22 let shouldIncludeDecoratorPlugins = _shouldIncludeDecoratorPlugins(config);
23
24 let emberCLIBabelConfig = config["ember-cli-babel"];
25 let shouldRunPresetEnv = true;
26
27 if (emberCLIBabelConfig) {
28 shouldRunPresetEnv = !emberCLIBabelConfig.disablePresetEnv;
29 }
30
31 let options = {};
32
33 let userPlugins = addonProvidedConfig.plugins;
34 let userPostTransformPlugins = addonProvidedConfig.postTransformPlugins;
35
36 if (shouldHandleTypeScript) {
37 userPlugins = _addTypeScriptPlugin(userPlugins.slice(), parent, project);
38 }
39
40 if (shouldIncludeDecoratorPlugins) {
41 userPlugins = _addDecoratorPlugins(
42 userPlugins.slice(),
43 addonProvidedConfig.options,
44 config,
45 parent,
46 project
47 );
48 }
49
50 options.plugins = []
51 .concat(
52 shouldIncludeHelpers && _getHelpersPlugin(project),
53 userPlugins,
54 _getDebugMacroPlugins(config, project),
55 _getEmberModulesAPIPolyfill(config, parent, project),
56 _getEmberDataPackagesPolyfill(config, parent),
57 _shouldCompileModules(config, project) && _getModulesPlugin(),
58 userPostTransformPlugins
59 ).filter(Boolean);
60
61 options.presets = [
62 shouldRunPresetEnv && _getPresetEnv(addonProvidedConfig, project),
63 ].filter(Boolean);
64
65 return options;
66};