angular-architects / module-federation-plugin

MIT License
683 stars 184 forks source link

[TBD] feat(nf): Use es-module-shims during initFederation and loadRemoteModule to ensure having latest importMap #513

Closed jogelin closed 1 week ago

jogelin commented 2 months ago

Related to #489

Do not process host during initFederation

Remote unnecessary global cache for loading the remotes

Process the remotes in parallel

With that approach, I can now use the import map override principle natively. All of the modifications were not required but I thought it was interesting to improve the bootstrap at runtime.

I am of course open to the discussion ;)

manfredsteyer commented 1 month ago

Thanks for this. I'm afraid this won't work. Perhaps we have different ideas in mind.

One aspect of federation is that it negotiates the versions to use. It might decide to go with a higher minor version provided by a remote. Hence, we cannot directly include the host's import map.

Also, we cannot rely on import map overrides, as this is only supported via shims, while the idea of module federation is to eventually provide the option to work without shims.

jogelin commented 1 month ago

One aspect of federation is that it negotiates the versions to use. It might decide to go with a higher minor version provided by a remote. Hence, we cannot directly include the host's import map.

I think I missed something sorry. Could you indicate where in the code the negotiation of versions is done? Is it related to the externals cache? Because I kept the principle of using the version of the host or another remote when processing the remote (see the tests).

Also, we cannot rely on import map overrides, as this is only supported via shims, while the idea of module federation is to eventually provide the option to work without shims.

Ok, I understand. I don't know if you saw my tweet about the single-spa agenda? It seems it is in discussion for single-spa to use es-module-shims instead of SystemJS. Something really interesting in the post is the part:

We also discussed possible collaboration with Zack Jackson on module federation's new runtime (called MFP) and whether that could help. Also discuss whether a service worker would be necessary or helpful to hook into the browser's loading of modules.

It is an interesting idea to hook files using a service worker and it seems this is what they discussed with Zack Jackson. I don't want to push for the overrides, the goal is not to use the overrides but to provide a way to change dynamically the URL of a module. If we use a service worker, for example on the manifest, it will not be linked to es-module-shims anymore.

In the current code, one thing to notice is that injecting the exposes in the importmap does not change anything because the exposes are always read from the cache.

That PR can be split in two. If the injection of the host doesn't fit, the most important part is to keep the list of remotes up to date with the es-module-shims which is still used for now in the loadRemoteModule right? My question is why do we create a cache that is not up to date when we can directly use es-module-shims as a cache? Why do we use the importShim with an URL instead of using the key of the exposes?