-
-
Notifications
You must be signed in to change notification settings - Fork 367
fix(enhanced): Add fallback parsing for container module exposes #4034
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
Changes from all commits
aef90ed
68ebd01
2955c59
ba44e59
ef84efd
b55085a
94d354c
754c028
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
it('should be able to handle spaces in path to exposes', async () => { | ||
const { default: test1 } = await import('./test 1'); | ||
const { default: test2 } = await import('./path with spaces/test-2'); | ||
expect(test1()).toBe('test 1'); | ||
expect(test2()).toBe('test 2'); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function test() { | ||
return 'test 2'; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function test() { | ||
return 'test 1'; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const { ModuleFederationPlugin } = require('../../../../dist/src'); | ||
|
||
module.exports = { | ||
mode: 'development', | ||
devtool: false, | ||
output: { | ||
publicPath: 'http://localhost:3000/', | ||
}, | ||
plugins: [ | ||
new ModuleFederationPlugin({ | ||
name: 'remote', | ||
filename: 'remoteEntry.js', | ||
manifest: true, | ||
exposes: { | ||
'./test-1': './test 1.js', | ||
'./test-2': './path with spaces/test-2.js', | ||
}, | ||
}), | ||
], | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -292,7 +292,25 @@ class ModuleHandler { | |
// identifier: container entry (default) [[".",{"import":["./src/routes/page.tsx"],"name":"__federation_expose_default_export"}]]' | ||
const data = identifier.split(' '); | ||
|
||
JSON.parse(data[3]).forEach(([prefixedName, file]) => { | ||
let entries: Array< | ||
[exposeKey: string, { import: string[]; name?: string }] | ||
> = []; | ||
|
||
try { | ||
// Prefer parsing exposes from stats first | ||
entries = JSON.parse(data[3]); | ||
} catch { | ||
// If that fails, fallback to the original options | ||
const exposes = this._options.exposes; | ||
|
||
if (!exposes || typeof exposes !== 'object') { | ||
return; | ||
} | ||
|
||
entries = Object.entries(exposes); | ||
} | ||
|
||
entries.forEach(([prefixedName, file]) => { | ||
Comment on lines
+295
to
+313
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm opting to maintain the current JSON parsing logic and wrap it in a @2heal1 @ScriptedAlchemy As you mentioned in the issue, there are probably better ways of solving this, but again, I lack the context to propose a long-term solution. You mentioned a short-term solution, but since the issue was closed, I figured it wouldn't hurt proposing this patch 😅. Also note I'm open to contribute and implement this in a different way if I can get some high level guidance (Just a couple of quick notes would be really helpful). |
||
// TODO: support multiple import | ||
exposesMap[getFileNameWithOutExt(file.import[0])] = getExposeItem({ | ||
exposeKey: prefixedName, | ||
|
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.
#4027 (comment)
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.
From my investigations
this.options.exposes
inModuleHandler
is always parsed intoby
ContainerManager.containerPluginExposesOptions
. But due to how everything is currently typed, TS thinks this could be the broader "unparsed"Exposes
shape.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.
This is how it looks like, for both
enhanced/ModuleFederationPlugin
andrspack/ModuleFederationPlugin
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.
Now, we could maintain this 100% decoupled and idempotently "re-parse" the entries
ModuleHandler
to ensure the type safety, but I would wait for a review first before increasing the complexity here. cc @ScriptedAlchemy @2heal1