Skip to content

Commit ed8bda3

Browse files
fix: remove resourceQuery from dts generation (#3629)
1 parent 4868df8 commit ed8bda3

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

.changeset/gold-garlics-fix.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@module-federation/dts-plugin': patch
3+
---
4+
5+
remove query strings from exposed modules to fix tsc resolves

.changeset/nine-lies-hear.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@module-federation/node': patch
3+
---
4+
5+
support undoPath and rootOutputDir for correct remote chunk resolution in node

packages/dts-plugin/src/plugins/DtsPlugin.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,26 @@ export class DtsPlugin implements WebpackPluginInstance {
4444
apply(compiler: Compiler) {
4545
const { options } = this;
4646

47-
const normalizedDtsOptions = normalizeDtsOptions(options, compiler.context);
47+
// Create a shallow clone of the options object to avoid mutating the original
48+
const clonedOptions = { ...options };
49+
50+
// Clean up query parameters in exposes paths without mutating original
51+
if (options.exposes && typeof options.exposes === 'object') {
52+
const cleanedExposes: Record<string, any> = {};
53+
Object.entries(options.exposes).forEach(([key, value]) => {
54+
if (typeof value === 'string') {
55+
cleanedExposes[key] = value.split('?')[0];
56+
} else {
57+
cleanedExposes[key] = value;
58+
}
59+
});
60+
clonedOptions.exposes = cleanedExposes;
61+
}
62+
63+
const normalizedDtsOptions = normalizeDtsOptions(
64+
clonedOptions,
65+
compiler.context,
66+
);
4867

4968
if (typeof normalizedDtsOptions !== 'object') {
5069
return;
@@ -67,22 +86,22 @@ export class DtsPlugin implements WebpackPluginInstance {
6786
// Because the plugin will delete dist/@mf-types.zip while generating types, which will be used in GenerateTypesPlugin
6887
// So it should apply after GenerateTypesPlugin
6988
new DevPlugin(
70-
options,
89+
clonedOptions,
7190
normalizedDtsOptions,
7291
generateTypesPromise,
7392
fetchRemoteTypeUrlsPromise,
7493
).apply(compiler);
7594

7695
// The exposes files may use remote types, so it need to consume types first, otherwise the generate types will fail
7796
new GenerateTypesPlugin(
78-
options,
97+
clonedOptions,
7998
normalizedDtsOptions,
8099
fetchRemoteTypeUrlsPromise,
81100
generateTypesPromiseResolve,
82101
).apply(compiler);
83102

84103
new ConsumeTypesPlugin(
85-
options,
104+
clonedOptions,
86105
normalizedDtsOptions,
87106
fetchRemoteTypeUrlsResolve,
88107
).apply(compiler);

0 commit comments

Comments
 (0)