Skip to content

Conversation

@henryqdineen
Copy link
Collaborator

@henryqdineen henryqdineen commented Oct 22, 2025

What changed / motivation ?

At HubSpot we use a homegrown package manager for frontend packages that is optimized for our (mostly) closed ecosystem. This can present challenges when integrating third-party tooling but, more often than not, the tooling will support a way to configure module resolution.

This PR introduces a "custom" type to the unstable_moduleResolution configuration option that will allow us and others to plug-in our own resolution algorithm without relying on forks or error-prone patch-package patches. When using "custom" module resolution the consumer will need to provide their implementations for filePathResolver(), and getCanonicalFilePath().

I have tested this branch locally and it works for our needs. I am currently using patch-package on top of 0.16.2, although patching bundled code can be tricky and hard to maintain.

Acknowledgments

  • The usage of filePathResolver() and getCanonicalFilePath() leaks implementation details, or at least internal function naming, to the public API. If you prefer something more generic please recommend something.
  • This change will introduce config values of type function. I wasn't sure if you were intentionally trying to limit the config only static values but I don't see another way.

Omissions

  • I skipped updating docs as I don't expect this feature to be widely used. I considered prefixing likeexperimental_crossFileParsing.
  • createShortFilename() still has a implicit dependency on node_modules resolution for non-"haste" module resolution. I'm not familiar enough with that part of the codebase but we can add support in the future.

Linked PR/Issues

This seems like it could be useful to resolve/workaround #1282

Pre-flight checklist

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 22, 2025
@henryqdineen henryqdineen changed the title [babel-plugin] Support custom module resolution Oct 22, 2025
Copy link
Member

@mellyeliu mellyeliu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable overall. We may want to document the new custom config within https://stylexjs.com/docs/api/configuration/babel-plugin/#unstable_moduleresolution, but that can be done in a followup.

@mellyeliu mellyeliu merged commit f301f4f into facebook:main Oct 23, 2025
6 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

2 participants