-
Notifications
You must be signed in to change notification settings - Fork 187
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
[TBD] feat(nf): Use es-module-shims during initFederation and loadRemoteModule to ensure having latest importMap #513
Conversation
…al `sms-module-shims` options into `index.html`
…ms-init-options feat(nf): Add `esmsInitOptions` to Angular builder to inject additional `esms-module-shims` options into `index.html`
…ap-to-head fix(nf): Inject `importmap-shim` to the `<head>` instead of the end of the `<body>`
…se-script-tags fix(nf): Remove orphans `</scripts>` tags during `updateScriptTags`
Fix esbuild Adapter Results
fix(nf): properly handle outputPath object
…l-peer-dep-conflict fix(dep): fix peer dependency `browser-sync` not aligned with root dependency
fix(test): fix jest tests
fix(lint): fix linting
…tion-config ci: init Github actions config file
…ule to ensure having latest importMap
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not process host during initFederation
During the build, an importmap.json
is already generated.
I just adapted the code to apply the same modifications done by the deleted processHostInfo
}; | ||
}, {}); | ||
|
||
const importMap = { imports }; | ||
const exposesImports = exposes.reduce((acc, cur) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not process host during initFederation
Add the exposes when the remotes are loaded independently
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remote unnecessary global cache for loading the remotes
To ensure every work like before, I covered the initFederation
and the processRemoteInfo
.
@@ -18,13 +16,8 @@ export async function initFederation( | |||
? await loadManifest(remotesOrManifestUrl) | |||
: remotesOrManifestUrl; | |||
|
|||
const hostImportMap = await processHostInfo(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not process host during initFederation
const remotesImportMap = await processRemoteInfos(remotes); | ||
|
||
const importMap = mergeImportMaps(hostImportMap, remotesImportMap); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remote unnecessary global cache for loading the remotes
No DOM modifications.
|
||
for (const shared of remoteInfo.shared) { | ||
const defaultExternalUrl = getDefaultExternalUrl(currentImportMap, shared); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not process host during initFederation
Host externals are directly read from es-module-shims
when processing the remotes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we are using importShim<Default, Exports>
from es-module-shims
I applied the same types to the loadRemoteModule
const options = normalizeOptions(optionsOrRemoteName, exposedModule); | ||
|
||
await ensureRemoteInitialized(options); | ||
|
||
const remoteName = getRemoteNameByOptions(options); | ||
const remote = getRemote(remoteName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remote unnecessary global cache for loading the remotes
The es-module-shims
is directly used to load modules instead of caching not-updated
} | ||
if (fileName === '/importmap.json') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also update the generated importmap.json
with the debug information like we do for the remoteEntry.json
@@ -51,5 +51,14 @@ export function updateScriptTags( | |||
); | |||
indexContent = indexContent.replace(/<script src="main.*?><\/script>/, ''); | |||
indexContent = indexContent.replace('</body>', `${htmlFragment}</body>`); | |||
|
|||
// add link to importmap.json | |||
const scriptTagImportMap = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not process host during initFederation
The Host importmap.json
is directly included in index.html
. No need to process it anymore.
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. |
I think I missed something sorry.
Ok, I understand.
It is an interesting idea to hook files using a service worker and it seems this is what they discussed with Zack Jackson. In the current code, one thing to notice is that injecting the exposes in the That PR can be split in two. |
Related to #489
Do not process host during
initFederation
importmap.json
is directly included inindex.html
. No need to process it anymore.es-module-shims
when processing the remotesRemote unnecessary global cache for loading the remotes
processRemoteInfo
and theloadRemoteModule
are using directlyes-module-shims
es-module-shims
is directly used to load modules instead of caching not-updatedProcess the remotes in parallel
Promises.all
for processing them 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 ;)