feat: Added support for shared-mapping glob patterns#1083
Conversation
870abe1 to
97cae9d
Compare
|
Thanks for working on this. I’d be happy to test it against a real monorepo setup once it’s ready. |
97cae9d to
f240548
Compare
|
Cheers! This should properly resolve shared-mappings with a glob (wildcard). |
|
Hi @maciekv, I prepared a release candidate for this specific feature. Do you mind double checking? Let me know what you find. $ npm install @softarc/native-federation@3.5.5-RC1 |
|
Hi @Aukevanoost ! Thanks for the quick turnaround on this! I tested RC 3.5.5-RC1 with Good news: The wildcard resolution works correctly — Problem: The app crashes at runtime with a white page:
What happens:
The core issue: Our code imports individual files via wildcard tsconfig paths: NF registers the shared mapping as |
|
Hi @maciekv, I see. This is actually pretty fixable! But I think the real question here is, what is the desired behavior? If native-federation bundles every little component or service into a separate entrypoint, then the bundles will become so small that they will lose their usefulness. Since every mapped path is transformed to an individual bundle. I do understand that it should work at all times, therefore, I can see if I can rewrite the imports to the nearest entrypoint (barrel file). this way we're not polluting the How does that sound? In theory you wouldn't want the users of your library to be dependent directly on the internals of your shared library anyway (encapsulation rules). It might make sense for treeshaking purposes in an SPA, but not for shared libraries of your micro frontends. You'd prefer to bundle them into virtual "packages" that can be reused. Let me know what you think |
|
That sounds like a very reasonable approach. Rewriting imports to the nearest barrel file at build time keeps the shared bundles at a sensible granularity, while remaining transparent for developers — no need to change existing import paths in the codebase. We already have index.ts barrel files in all 27 feature directories, so this should work well in our setup. One small suggestion: it would be helpful if resolveTsConfigWildcard logged a warning when it skips a directory that has no index file, e.g.: Right now it silently skips, which makes debugging difficult. Happy to test it once it's ready. |
|
Hi @maciekv, I did a little bit more digging and came across some other complications:
So, to conclude, this will result in a breaking change. Native federation will need to see what is being imported before it starts processing wildcard exports. I will work on this on our next major v4 since it already contains breaking changes and gives us an opportunity to do it the right way. For you this means (unfortunately) that you'll have to change your imports to use exclusively the barrel files for now.(which in my opinion in this case is the safer way anyway since it mimicks an external library). I will add the warning you asked about and leave it like this. I am fully aware that barrel files are not a silver bullet but for shared libraries, you need a more coarse-grained approach for reliable dependency sharing. If you want you can create an issue on the v4 library with this information to keep track of my progress. Cheers for your time and the testing! |
Closes #1081