Extract config file resolution from OptionsManager #3564
Extract config file resolution from OptionsManager #3564loganfsmyth merged 4 commits intobabel:masterfrom
Conversation
`build-config-chain.js` creates an array of options which will be passed to `OptionsManager#mergeOptions`. The advantage of separating it out is that `build-config-chain` has a very minimal dependency list. The eventual intent is to allow the require hook to lazy load only when required. In other words, if no required files ever match the patterns `ignore` / `only` patterns, the bulk of babel-core, and the associated plugins, will never be loaded.
Current coverage is 87.96%@@ master #3564 diff @@
==========================================
Files 194 195 +1
Lines 9640 9790 +150
Methods 1101 1118 +17
Messages 0 0
Branches 2204 2252 +48
==========================================
+ Hits 8475 8612 +137
- Misses 1165 1178 +13
Partials 0 0
|
|
Any feedback on this from the Babel team? |
|
So you're not just left here - Sorry, haven't been able to look at this (haven't really looked options in much detail anyway) |
|
I'm totally for this as long as we're sure the config ordering will still be identical. The amount of state tracked inside the OptionsManager has been a little crazy to follow. So I understand your long-term goal, you'd like to be confident in the options used for a file without having to load babel-core itself? Are you planning another step once this lands to expose an API to do that? I'm all for all of this, I wish Babel had better logic for caching builds safely, but at least this is a step in a better direction. |
Yes and Yes. I am happy to keep plugging away at that goal. I would prefer to do it in smaller PR's so the core team can comment on the progression and help steer the implementation details, but I can just continue to pile on to this PR if you want proven benefits before merging. |
I spent a lot of time ensuring that, and I really do think I got it right. An added benefit of this change is that config ordering is now testable/tested. |
|
Let's do this |
|
Thanks for all the work + tests @jamestalmage! 🎉 |
|
I think the benefits for overall readability and API clarity are worth it in their own right, but also happy to iterate on public APIs for config access too. Thanks for the help! |
|
Awesome! Thanks! |
|
"extended" plugin refers to which plugin? |
|
@montogeek Not sure I understand? Babel lets you use to pull in config from a different config file. |
|
@loganfsmyth Thanks for the reply, I missed this option, I asked because found some errors when migrating tests to Jest |
Currently OptionsManager encompasses a number of tasks:
.babelrc/.babelignoreextendsoption to find base configurations which are being extended.This PR separates
1and2from3.build-config-chain.jsnow does all the file system searching, and builds a list of configs that should be merged.OptionsManager#mergeOptionsno longer calls itself recursively.The entire operation is essentially reduced to:
Great care was taken to ensure that
build-config-chain.jsbuilds the list of options in the same order as they would have been merged inOptionsManagerpreviously.build-config-chain.js- has a very minimal dependency list, and building the chain does not require loading up any of the rest ofbabel-core, or any plugins. I believe this could be used to greatly reduce performance hits caused byrequire-ing lots of modules that may never be used. Additional refactoring tobabel-registercould prevent loading upbabel-coreunless it is actually needed.avajs/ava#945 improves performance of AVA test suites some 30%-50% by precompiling in the main process, and avoiding
babel-registerfor child processes. However, it does not work well for dynamic requires.My eventual goal is to reduce the penalty for
babel-registerto near-zero when it isn't needed (because AVA successfully precompiled everything in the main process), but still have it in place in case of dynamic requires.I think this has practical use outside of the AVA use cases described above. For one, I think it just provides a better separation of concerns. Secondly, I think it would be fairly easy to inspect the chain and determine if more aggressive caching was possible.