UNPKG

1.12 kBJavaScriptView Raw
1const SHOULD_INCLUDE_HELPERS = new WeakMap();
2
3function shouldIncludeHelpers(addonOrProject) {
4 // Currently we check for @ember-decorators transforms specifically, but we
5 // could check for any number of heuristics in this function. What we want is
6 // to default to on if we reasonably believe that users will incur massive
7 // cost for inlining helpers. Stage 2+ decorators are a very clear indicator
8 // that helpers should be included, at 12kb for the helpers, it pays for
9 // itself after usage in 5 files. With stage 1 decorators, it pays for itself
10 // after 25 files.
11 if (addonOrProject.pkg && addonOrProject.pkg.name === '@ember-decorators/babel-transforms') {
12 return true;
13 }
14
15 if (addonOrProject.addons) {
16 return addonOrProject.addons.some(shouldIncludeHelpers);
17 }
18
19 return false;
20}
21
22
23module.exports = function defaultShouldIncludeHelpers(project) {
24 if (SHOULD_INCLUDE_HELPERS.has(project)) {
25 return SHOULD_INCLUDE_HELPERS.get(project);
26 }
27
28 let shouldInclude = shouldIncludeHelpers(project);
29
30 SHOULD_INCLUDE_HELPERS.set(project, shouldInclude);
31
32 return shouldInclude;
33}
34