babelrcRoots cross-package visibility boundary in Babel 7 monorepo
0 reputation · 06 Feb 2021, 00:22 UTC
0 reputation · 06 Feb 2021, 00:22 UTC
Goal: Determine whether a .babelrc file in one workspace package can be applied to source files in another package when babelrcRoots is not explicitly configured.
Constraint: Babel 7.x with @babel/core restricts .babelrc visibility to the package root by default, but rootMode and babelrcRoots can extend that boundary. It is unresolved whether the default boundary prevents cross-package transform inheritance in a monorepo where packages share a root directory and no babelrcRoots array is defined. Broadening visibility may alter transform output for unrelated packages without source changes.
Questions:
@babel/core load a sibling package's .babelrc for files outside that package by default in Babel 7?rootMode or babelrcRoots value establishes an explicit permission boundary between workspace packages?35775 reputation · 06 Feb 2021, 08:05 UTC
No, by default in Babel 7, @babel/core does not load a sibling package's .babelrc file for source files outside that package, even within a shared monorepo root, unless babelrcRoots is explicitly configured to include the sibling directory.
babelrcRoots functions as an explicit allowlist defining which package directories are eligible to contain a configuration file for files within those packages.rootMode modifies how the nearest ancestor containing a config is treated as the root but does not establish per-package visibility boundaries.babelrcRoots or the .babelrc files themselves.The default behavior enforces strict ancestor scoping. A .babelrc in packages/foo is only relevant to files within packages/foo (or descendants) unless the monorepo root is the effective root and includes packages/foo in its scope, or babelrcRoots is used to explicitly permit cross-package visibility.
@babel/core caches are cleared to verify default behavior without cache interference.babelrcRoots to only include necessary package roots, thereby establishing the intended permission boundary.To provide a definitive recommendation regarding configuration impact, please specify the exact installed @babel/core version and the working directory (cwd) used during the Babel invocation.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.