1 | const semver = require("semver");
|
2 | const resolvePackagePath = require("resolve-package-path");
|
3 |
|
4 | function _getDebugMacroPlugins(appRoot) {
|
5 | const isProduction = process.env.EMBER_ENV === "production";
|
6 | const isDebug = !isProduction;
|
7 |
|
8 | const emberDebugOptions = {
|
9 | flags: [
|
10 | {
|
11 | source: "@glimmer/env",
|
12 | flags: { DEBUG: isDebug, CI: !!process.env.CI },
|
13 | },
|
14 | ],
|
15 |
|
16 | debugTools: {
|
17 | isDebug,
|
18 | source: "@ember/debug",
|
19 | assertPredicateIndex: 1,
|
20 | },
|
21 | };
|
22 |
|
23 | const emberApplicationDeprecationsOptions = {
|
24 |
|
25 | externalizeHelpers: {
|
26 | global: "Ember",
|
27 | },
|
28 |
|
29 | debugTools: {
|
30 | isDebug,
|
31 | source: "@ember/application/deprecations",
|
32 | assertPredicateIndex: 1,
|
33 | },
|
34 | };
|
35 |
|
36 | if (_emberVersionRequiresModulesAPIPolyfill(appRoot)) {
|
37 | emberDebugOptions.externalizeHelpers = {
|
38 | global: "Ember",
|
39 | };
|
40 | emberApplicationDeprecationsOptions.externalizeHelpers = {
|
41 | global: "Ember",
|
42 | };
|
43 | } else {
|
44 | emberDebugOptions.externalizeHelpers = {
|
45 | module: "@ember/debug",
|
46 | };
|
47 | emberApplicationDeprecationsOptions.externalizeHelpers = {
|
48 | module: "@ember/application/deprecations",
|
49 | };
|
50 | }
|
51 |
|
52 | return [
|
53 | [
|
54 | require.resolve("babel-plugin-debug-macros"),
|
55 | emberDebugOptions,
|
56 | "@ember/debug stripping",
|
57 | ],
|
58 | [
|
59 | require.resolve("babel-plugin-debug-macros"),
|
60 | emberApplicationDeprecationsOptions,
|
61 | "@ember/application/deprecations stripping",
|
62 | ],
|
63 | ];
|
64 | }
|
65 |
|
66 | function _emberVersionRequiresModulesAPIPolyfill(appRoot) {
|
67 | let packagePath = resolvePackagePath("ember-source", appRoot);
|
68 | if (packagePath === null) {
|
69 | return true;
|
70 | }
|
71 |
|
72 | let pkg = require(packagePath);
|
73 | return pkg && semver.lt(pkg.version, "3.27.0-alpha.1");
|
74 | }
|
75 |
|
76 | function _getEmberModulesAPIPolyfill(appRoot, config) {
|
77 | if (config.disableEmberModulesAPIPolyfill) {
|
78 | return;
|
79 | }
|
80 |
|
81 | if (_emberVersionRequiresModulesAPIPolyfill(appRoot)) {
|
82 | const ignore = _getEmberModulesAPIIgnore(appRoot, config);
|
83 |
|
84 | return [
|
85 | [require.resolve("babel-plugin-ember-modules-api-polyfill"), { ignore }],
|
86 | ];
|
87 | }
|
88 | }
|
89 |
|
90 | function _shouldIgnoreEmberString(appRoot) {
|
91 | return resolvePackagePath("@ember/string", appRoot) !== null;
|
92 | }
|
93 |
|
94 | function _shouldIgnoreJQuery(appRoot) {
|
95 | let packagePath = resolvePackagePath("@ember/jquery", appRoot);
|
96 | if (packagePath === null) {
|
97 | return true;
|
98 | }
|
99 | let pkg = require(packagePath);
|
100 | return pkg && semver.gt(pkg.version, "0.6.0");
|
101 | }
|
102 |
|
103 | function _emberDataVersionRequiresPackagesPolyfill(appRoot) {
|
104 | let packagePath = resolvePackagePath("ember-data", appRoot);
|
105 | if (packagePath === null) {
|
106 | return false;
|
107 | }
|
108 | let pkg = require(packagePath);
|
109 | return pkg && semver.lt(pkg.version, "3.12.0-alpha.0");
|
110 | }
|
111 |
|
112 | function _getEmberModulesAPIIgnore(appRoot, config) {
|
113 | const ignore = {
|
114 | "@ember/debug": ["assert", "deprecate", "warn"],
|
115 | "@ember/application/deprecations": ["deprecate"],
|
116 | };
|
117 |
|
118 | if (config.shouldIgnoreEmberString || _shouldIgnoreEmberString(appRoot)) {
|
119 | ignore["@ember/string"] = [
|
120 | "fmt",
|
121 | "loc",
|
122 | "w",
|
123 | "decamelize",
|
124 | "dasherize",
|
125 | "camelize",
|
126 | "classify",
|
127 | "underscore",
|
128 | "capitalize",
|
129 | "setStrings",
|
130 | "getStrings",
|
131 | "getString",
|
132 | ];
|
133 | }
|
134 | if (config.shouldIgnoreJQuery || _shouldIgnoreJQuery(appRoot)) {
|
135 | ignore["jquery"] = ["default"];
|
136 | }
|
137 |
|
138 | return ignore;
|
139 | }
|
140 |
|
141 | function _getEmberDataPackagesPolyfill(appRoot, config) {
|
142 | if (config.emberDataVersionRequiresPackagesPolyfill) {
|
143 | return [[require.resolve("babel-plugin-ember-data-packages-polyfill")]];
|
144 | }
|
145 | return _emberDataVersionRequiresPackagesPolyfill(appRoot);
|
146 | }
|
147 |
|
148 | function _getModuleResolutionPlugins(config) {
|
149 | if (!config.disableModuleResolution) {
|
150 | const resolvePath = require("../lib/relative-module-paths")
|
151 | .resolveRelativeModulePath;
|
152 | return [
|
153 | [require.resolve("babel-plugin-module-resolver"), { resolvePath }],
|
154 | [
|
155 | require.resolve("@babel/plugin-transform-modules-amd"),
|
156 | { noInterop: true },
|
157 | ],
|
158 | ];
|
159 | }
|
160 | }
|
161 |
|
162 | function _getProposalDecoratorsAndClassPlugins(config) {
|
163 | if (!config.shouldIgnoreDecoratorAndClassPlugins) {
|
164 | return [
|
165 | |
166 |
|
167 |
|
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 |
|
175 | ["@babel/plugin-transform-class-static-block"],
|
176 | ["@babel/plugin-proposal-decorators", { legacy: true }],
|
177 | ["@babel/plugin-proposal-class-properties"],
|
178 | ];
|
179 | }
|
180 | }
|
181 |
|
182 |
|
183 |
|
184 |
|
185 |
|
186 |
|
187 |
|
188 |
|
189 |
|
190 |
|
191 |
|
192 |
|
193 |
|
194 |
|
195 |
|
196 |
|
197 |
|
198 | module.exports = function (appRoot, config = {}) {
|
199 | return []
|
200 | .concat(
|
201 | _getProposalDecoratorsAndClassPlugins(config),
|
202 | _getDebugMacroPlugins(appRoot),
|
203 | _getEmberModulesAPIPolyfill(appRoot, config),
|
204 | _getEmberDataPackagesPolyfill(appRoot, config),
|
205 | _getModuleResolutionPlugins(config)
|
206 | )
|
207 | .filter(Boolean);
|
208 | };
|
209 |
|
210 | module.exports.getDebugMacroPlugins = _getDebugMacroPlugins;
|
211 | module.exports.getEmberModulesAPIPolyfill = _getEmberModulesAPIPolyfill;
|
212 | module.exports.getEmberDataPackagesPolyfill = _getEmberDataPackagesPolyfill;
|
213 | module.exports.getModuleResolutionPlugins = _getModuleResolutionPlugins;
|
214 | module.exports.getProposalDecoratorsAndClassPlugins = _getProposalDecoratorsAndClassPlugins;
|