-
-
Notifications
You must be signed in to change notification settings - Fork 250
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
feat(dts-plugin,sdk,website-new): added option to use a base path when resolving types from relative remote urls #3042
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: b44c45e The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Deploy Preview for module-federation-docs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
9b00854
to
4d44ce2
Compare
@sbvice you should be able to resolve the remotes base path with the existing information in federation. This is how we do it for node.js etc since node doesnt have document.currentScript.src, if you want basepath for the remote you should rather look at something like finding the remote configs in the host and getting the base path of the remote entry path, then use that to construct the url when its not known. Something like this is what ive used before. function getPathFromFederation() {
// Access the global federation manager or create a fallback object
var federationManager = globalThis.__FEDERATION__ || {};
// Access the current Webpack instance's federation details or create a fallback object
var instance = __webpack_require__.federation.instance || {};
// Function to aggregate all known remote module paths
var getAllKnownRemotes = function() {
var found = {};
// Iterate over all federation instances to collect module cache entries
(federationManager.__INSTANCES__ || []).forEach((instance) => {
if(instance){
instance.moduleCache.forEach((value, key) => {
found[key] = value;
});
}
});
return found;
};
// Retrieve the combined remote cache from all federation instances
const combinedRemoteCache = getAllKnownRemotes();
// Get the name of the current host from the instance
const hostName = instance.name;
// Find the path for the current host in the remote cache
const foundPath = combinedRemoteCache[hostName];
// If a path is not found, return undefined to indicate the absence of an entry path
if (!foundPath) { return undefined; }
// Return the entry path for the found remote module
const entryPath = foundPath.remoteInfo.entry;
return entryPath;
} |
Since this is compile time, DTS manager already has this which handles compile time.
|
@ScriptedAlchemy thank you for the tips! I will try this again. From my previous attempts DTS was failing just trying to retrieve the initial |
Yeah. So when it's relative, you can use the runtime plugin as well to patch it or update configs. The get public path was designed to do this, though. Since federation has the ability to serve lock files, one could change the origins, etc., on edge servers. So get public path allows places where we can't automatically determine it. Otherwise, usually, how I make auto mode work is by "looking upwards" since, for it to even try to load, someone usually provides an absolute URL. Since yours is relative at the path, then yeah, the public path function or a runtime plugin if you want additional customizations. |
Can over our doc site at the options for runtime and runtime plugins. I also have a folder in examples repo |
Closing PR, open new one or file issue if you have any other questions or need to make ammendments |
Thanks Zack! I haven’t had a chance to try hooking into the runtime yet, but that may be my only option since it doesn’t appear DTS uses the host’s publicPath or getPublicPath federation config when resolving the initial remote configuration manifest json when the remote is relative. Perhaps that should be the fix then.
|
Ahh i see what you mean, get public path is for the HOST and you want the remote to. Do you have a repo around that shows the issue? we can reopen this pr again, just wanted to get some correspondence so we make sure theres not an existing solution here in my source. |
@ScriptedAlchemy hey. I'm writing this because I was following this pull request and it got closed :(
|
Ideally, I need a repo so I can replicate this and reopen the PR with a test case. Then, I can see if I can adjust the runtime without adding a new API or if this implementation will be fine. |
Hey there @ScriptedAlchemy I threw together an example today for you to play around with. Hopefully this helps illustrate what I'm trying to do and helps you determine if this is something we need. Let me know if I can help in any way. |
Perfect 👌 thank you |
…n resolving types from relative remote urls
673f969
to
b44c45e
Compare
Would love to see this merged encountering an issue that this would solve 👍 |
Supply base path when resolving relative remote types
Added a new optional
remoteBasePath
property toDtsHostOptions
to aid in resolving types from relative remote URLs.Related Issue
#2963
Types of changes
Checklist