-
-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEAT] Adds an option to emit external babel helpers
This PR adds the `includeExternalHelpers` config option which allows users to explicitly opt into using externalized helpers for transpiled code. In large apps this can help with app size, especially in apps which are making heavy usage of new ES features like native classes and decorators. This option is a _global_ option, meaning it _must_ be configured in the root application. The reason for this is because there must be one canonical source of truth for which version of helpers are being used, and whether or not helpers are being used at all. If one addon decides to use helpers, the app must include them, and they must be the right version. By default, ec-babel will check the dependency tree to see if there are any addons which exist which will incur heavy expenses, such as decorators. If so, it'll externalize helpers by default. Eventually this behavior will be unnecessary due to treeshaking. The current setup will _only_ support babel 7 helpers. This can be expanded upon in the future, but the complexity of doing so makes it beyond the scope of the initial work here.
- Loading branch information
Showing
11 changed files
with
2,438 additions
and
1,043 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const SHOULD_INCLUDE_HELPERS = new WeakMap(); | ||
|
||
function shouldIncludeHelpers(addonOrProject) { | ||
// Currently we check for @ember-decorators transforms specifically, but we | ||
// could check for any number of heuristics in this function. What we want is | ||
// to default to on if we reasonably believe that users will incur massive | ||
// cost for inlining helpers. Stage 2+ decorators are a very clear indicator | ||
// that helpers should be included, at 12kb for the helpers, it pays for | ||
// itself after usage in 5 files. With stage 1 decorators, it pays for itself | ||
// after 25 files. | ||
if (addonOrProject.pkg && addonOrProject.pkg.name === '@ember-decorators/babel-transforms') { | ||
return true; | ||
} | ||
|
||
if (addonOrProject.addons) { | ||
return addonOrProject.addons.some(shouldIncludeHelpers); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
|
||
module.exports = function defaultShouldIncludeHelpers(project) { | ||
if (SHOULD_INCLUDE_HELPERS.has(project)) { | ||
return SHOULD_INCLUDE_HELPERS.get(project); | ||
} | ||
|
||
let shouldInclude = shouldIncludeHelpers(project); | ||
|
||
SHOULD_INCLUDE_HELPERS.set(project, shouldInclude); | ||
|
||
return shouldInclude; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'use strict'; | ||
|
||
module.exports = function findApp(addon) { | ||
let current = addon; | ||
let app; | ||
|
||
// Keep iterating upward until we don't have a grandparent. | ||
// Has to do this grandparent check because at some point we hit the project. | ||
do { | ||
app = current.app || app; | ||
} while (current.parent.parent && (current = current.parent)); | ||
|
||
return app; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
/* eslint-env node */ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.