Skip to content
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

Add multi project support to babel plugin relay #4934

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

tomfuhrer
Copy link

Add multi-project configuration support to babel-plugin-relay

Fixes #4909 - This PR addresses the bug where eagerEsModules: true doesn't work with multi-project Relay configurations.

What is changing?

The Babel plugin now aligns with the Relay compiler's configuration system by supporting multi-project configurations:

  • Reads and respects the same multi-project configuration format as the Relay compiler
  • Maps file paths to specific projects based on directory structure, just like the compiler
  • Applies the correct project-specific settings (including eagerEsModules) based on file location
  • Provides helpful warnings when files match multiple projects with conflicting settings

Why is this important?

Previously, there was a configuration mismatch between the Babel plugin and the Relay compiler. While the compiler supported different settings for different parts of a codebase through its multi-project configuration, the Babel plugin did not properly handle this format.

This implementation brings parity between the two tools, ensuring consistent behavior throughout the Relay toolchain. Users can now define their configuration once and have it work correctly for both the Relay compiler and the Babel plugin.

Most importantly, it fixes a bug where eagerEsModules: true would not work correctly in multi-project configurations.

Implementation details

  • Added path-aware logic to match the compiler's behavior for mapping files to projects
  • Projects are matched using the most specific path, with exact matches taking precedence
  • When a file matches multiple projects, the first project's settings are used with a warning for conflicts
  • Thoroughly tested with a comprehensive suite covering various scenarios and edge cases
  • Updated the README to document the new functionality

Backwards compatibility

This change is fully backward compatible with existing single-project configurations.

Testing

The implementation is covered by a comprehensive test suite that verifies:

  • Basic project mapping functionality (matching the compiler's behavior)
  • Path matching and prioritization
  • Configuration merging behavior
  • Edge cases like null projects, empty arrays, etc.
  • Cross-platform path handling
  • Proper ES module generation with eagerEsModules: true

All existing tests continue to pass, ensuring backward compatibility.

This commit adds support for multi-project Relay configurations to the Babel plugin.
Now, the plugin can correctly determine which project configuration to use based on
the file path, matching the behavior of the Relay compiler.

Key changes:
- Add functions to map file paths to project configurations
- Implement project prioritization for files matching multiple projects
- Add warnings for conflicting project settings
- Map multi-project field names to single-project equivalents (output → artifactDirectory)
- Update type definitions to include multi-project configuration fields

The plugin still maintains backward compatibility with single-project configurations.
This commit adds a thorough test suite for the multi-project configuration
feature in babel-plugin-relay. The tests verify:

- File path to project mapping functionality
- Project-specific setting application
- Most specific path matching prioritization
- Handling of multiple matching projects
- Warning generation for conflicting settings
- Cross-platform path handling
- Various edge cases (null projects, empty arrays, etc.)
- Combination of global and project-specific settings

These tests ensure the plugin correctly handles multi-project Relay configurations,
matching the existing behavior of the Relay compiler.
@facebook-github-bot
Copy link
Contributor

@tyao1 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

babel-plugin-relay bug: eagerEsModules: true only works with single-project Relay configs.
2 participants