New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better support monorepos by allowing users to opt into autoconfiguring "root" #8636
Conversation
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/9029/ |
I think that we can be more conservative: instead of having an option to enable
To me |
We could limit it like this, I'm just not sure I seeing a compelling reason to do so.
That was my concern with That said, maybe that's not the end of the world since setting |
I'd recommend reading over http://babeljs.io/docs/en/config-files if you haven't. It goes into some of the details about how config files work.
Babel has a
Generally walking upward and merging is something that I've not found particularly intuitive. If you want behavior like this, you can use Merging for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer this path for the monorepo support.
Alright, closing in favor of #8660. |
Definitely curious for feedback on this one.
The Problem
In Babel 7, we've limited the expected scope of config files a lot, which has caused some migration pains for users. Because the scope of
.babelrc
files is now limited to a single package, users are trying to transition to usebabel.config.js
files. The issue is that, by default, Babel expects that file to be in the working directory of the build, and that is commonly not the case for monorepo users.Current Requirements
Currently, the workaround is that users have to manually pass the name, e.g.
which is painful, and similar steps would need to be taken for anything that runs in a per-package way. This means that monorepos that have repo-wide builds, like Babel's monorepo, work fine, but monorepos with per-package logic end up requiring lots of manual configuration. This is particularly painful for packages that are commonly used without any options (like
@babel/register
), or provide no way to easily pass options (likebabel-jest
).This PR
This PR proposes to allow
--root true
orroot: true
(where beforeroot
was only a string, and defaulted tocwd
), which would walk up the directory structure looking for ababel.config.js
file, and setroot
to that directory, and would throw an error if no root was found.What this would allow is for users to opt into more intelligent 'root' handling. Specifically, they would have to opt in because this option then requires the presence of a
babel.config.js
in your repo.For cases like
@babel/register
andbabel-jest
, we could consider exposing extra entrypoints to handle this in an automated way, for example@babel/register/auto-root
could be exposed as an entry point for users who want to use it in the context of a monorepo. Andbabel-jest
can expose ababel-jest/auto-root
that doesmodule.exports = require(".").createTransformer({ root: true });
, so users would opt into monorepo-global configs by using these special entry points.Questions
One of the benefits of dropping the unbounded-searching behavior we had for
.babelrc
files in Babel 6 is that it meant that it was easy to accidentally pick up a configuration that you didn't mean to apply.babel.config.js
files are specifically loaded from a single location to avoid issues like this. This PR requires an opt-in and throws loudly when ababel.config.js
isn't found to try to avoid any concerns about this kind off thing. If we opted into searching as the default, it's also not at all clear what should happen when the file isn't found. Do we use the working directory asroot
? That would mean that the addition of ababel.config.js
into the monorepo root would change theroot
value and potentially change what.babelrc
files are considered valid, sinceroot
is the default value forbabelrcRoots
. To me that seems like it would be a pretty bad experience for users. Changing defaults now would also likely be a breaking change.What do folks think about using alternative module entry points for this? It still requires monorepo users to do additional steps, but at least it's something that we could clearly document and recommend. It's also infinitely better than expecting people to do all of this themselves in any monorepo project that they need to migrate.
What do you think about overloading
root
here? I thinkroot: false
at least makes sense as "there is no root, so don't load config files", butroot: true
meaning to automatically search for the root isn't necessarily super discoverable. I also consideredmonorepo: true
or something, but I wasn't convinced that it was any more clear, and it meant that the behavior ofroot
then depends tangentially on another flag that users may or may not expect.