-
-
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.
Merge pull request #251 from pzuraq/feat/externalize-helpers-by-default
Add ability to deduplicate babel helpers.
- Loading branch information
Showing
11 changed files
with
2,444 additions
and
1,042 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.