Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ function __federation_method_setRemote(name: string, config: IRemoteConfig): voi
interface IRemoteConfig {
url: (() => Promise<string>) | string;
format: "esm" | "systemjs" | "var";
from: "vite" | "webpack;
from: "vite" | "webpack";
}
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I noticed a small typo here

```

Expand Down
10 changes: 6 additions & 4 deletions packages/lib/src/dev/remote-development.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const loadJS = async (url, fn) => {
}
function get(name, ${REMOTE_FROM_PARAMETER}){
return import(/* @vite-ignore */ name).then(module => ()=> {
if (${REMOTE_FROM_PARAMETER} === 'webpack') {
if ((globalThis.__federation_shared_remote_from__ ?? ${REMOTE_FROM_PARAMETER}) === 'webpack') {
return Object.prototype.toString.call(module).indexOf('Module') > -1 && module.default ? module.default : module
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

as per my PR description, if you think it's better to rebind the share scope instead of taking __federation_shared_remote_from__ to be the accepted remote from, let me know. This does have the downside of not allowing a merge in the case of a conflicting share scope format.

}
return module
Expand Down Expand Up @@ -141,7 +141,7 @@ function __federation_method_wrapDefault(module ,need){
return module;
}

function __federation_method_getRemote(remoteName, componentName){
function __federation_method_getRemote(remoteName, componentName) {
return __federation_method_ensure(remoteName).then((remote) => remote.get(componentName).then(factory => factory()));
}

Expand Down Expand Up @@ -395,7 +395,9 @@ export {__federation_method_ensure, __federation_method_getRemote , __federation
const idx = moduleFilePath.indexOf(cwdPath)

const relativePath =
idx === 0 ? posix.join(base, moduleFilePath.slice(cwdPath.length)) : null
idx === 0
? posix.join(base, moduleFilePath.slice(cwdPath.length))
: null

const sharedName = item[0]
const obj = item[1]
Expand All @@ -406,7 +408,7 @@ export {__federation_method_ensure, __federation_method_getRemote , __federation
const url = origin
? `'${origin}${pathname}'`
: `window.location.origin+'${pathname}'`
str += `get:()=> get(${url}, ${REMOTE_FROM_PARAMETER})`
str += `get:() => get(${url}, ${REMOTE_FROM_PARAMETER})`
res.push(`'${sharedName}':{'${obj.version}':{${str}}}`)
}
}
Expand Down
9 changes: 5 additions & 4 deletions packages/lib/src/prod/remote-production.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export function prodRemotePlugin(

function get(name, ${REMOTE_FROM_PARAMETER}) {
return __federation_import(name).then(module => () => {
if (${REMOTE_FROM_PARAMETER} === 'webpack') {
if ((globalThis.__federation_shared_remote_from__ ?? ${REMOTE_FROM_PARAMETER}) === 'webpack') {
return Object.prototype.toString.call(module).indexOf('Module') > -1 && module.default ? module.default : module
}
return module
Expand All @@ -147,11 +147,12 @@ export function prodRemotePlugin(
}

const wrapShareModule = ${REMOTE_FROM_PARAMETER} => {
globalThis.__federation_shared_remote_from__ = ${REMOTE_FROM_PARAMETER};
return merge({
${getModuleMarker('shareScope')}
}, (globalThis.__federation_shared__ || {})['${shareScope}'] || {});
}

async function __federation_import(name) {
currentImports[name] ??= import(name)
return currentImports[name]
Expand All @@ -168,7 +169,7 @@ export function prodRemotePlugin(
const callback = () => {
if (!remote.inited) {
remote.lib = window[remoteId];
remote.lib.init(wrapShareModule(remote.from))
remote.lib.init(wrapShareModule(remote.from));
remote.inited = true;
}
resolve(remote.lib);
Expand Down Expand Up @@ -291,7 +292,7 @@ export function prodRemotePlugin(
let str = ''
if (typeof obj === 'object') {
const fileUrl = `import.meta.ROLLUP_FILE_URL_${obj.emitFile}`
str += `get:()=>get(${fileUrl}, ${REMOTE_FROM_PARAMETER}), loaded:1`
str += `get:() => get(${fileUrl}, ${REMOTE_FROM_PARAMETER}), loaded:1`
res.push(`'${arr[0]}':{'${obj.version}':{${str}}}`)
}
})
Expand Down