Skip to content

Commit 7facc10

Browse files
authored
fix(managers): correct manifest shared configuration (#3219)
1 parent c2b1efa commit 7facc10

File tree

8 files changed

+62
-34
lines changed

8 files changed

+62
-34
lines changed

.changeset/tough-yaks-lay.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@module-federation/managers': patch
3+
---
4+
5+
fix(managers): correct manifest shared configuration

packages/managers/__tests__/SharedManager.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ describe('SharedManager', () => {
1616
name: '@module-federation/shared-managers-test',
1717
shared: {
1818
react: {},
19+
'react-dom': { singleton: false, requiredVersion: '^18.0.0' },
1920
},
2021
};
2122
const sharedManager = new SharedManager();
@@ -33,6 +34,7 @@ describe('SharedManager', () => {
3334
].includes(key),
3435
),
3536
).toEqual(true);
37+
expect(sharedManager.normalizedOptions['react-dom']).toMatchSnapshot();
3638
});
3739

3840
it('sharedPluginOptions', () => {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`SharedManager normalizedOptions 1`] = `
4+
{
5+
"eager": false,
6+
"name": "react-dom",
7+
"requiredVersion": "^18.0.0",
8+
"shareScope": "default",
9+
"singleton": false,
10+
"version": "18.3.1",
11+
}
12+
`;

packages/managers/src/ContainerManager.ts

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type {
55
ManifestModuleInfos,
66
moduleFederationPlugin,
77
} from '@module-federation/sdk';
8-
import { getBuildVersion, parseOptions } from './utils';
8+
import { parseOptions } from './utils';
99
import type { EntryObject } from 'webpack';
1010
import { BasicPluginOptionsManager } from './BasicPluginOptionsManager';
1111

@@ -65,7 +65,7 @@ class ContainerManager extends BasicPluginOptionsManager<moduleFederationPlugin.
6565
const [exposeKey, exposeObj] = item;
6666
sum[exposeKey] = exposeObj;
6767
return sum;
68-
}, {});
68+
}, {} as moduleFederationPlugin.ExposesObject);
6969
}
7070
// { '.' : './src/Button.jsx' } => { '__federation_expose_Component' : ['src/Buttton'] }
7171
get exposeFileNameImportMap(): Record<string, string[]> {
@@ -81,30 +81,36 @@ class ContainerManager extends BasicPluginOptionsManager<moduleFederationPlugin.
8181
name: item.name || generateExposeFilename(key, false),
8282
}),
8383
);
84-
return parsedOptions.reduce((sum, item) => {
85-
const [_exposeKey, exposeObj] = item;
86-
const { name, import: importPath } = exposeObj;
87-
sum[name] = importPath;
88-
return sum;
89-
}, {});
84+
return parsedOptions.reduce(
85+
(sum, item) => {
86+
const [_exposeKey, exposeObj] = item;
87+
const { name, import: importPath } = exposeObj;
88+
sum[name] = importPath;
89+
return sum;
90+
},
91+
{} as Record<string, string[]>,
92+
);
9093
}
9194

9295
// { '.' : './src/Button.jsx' } => { '.' : ['src/Button'] }
93-
get exposeObject(): Record<string, string> {
96+
get exposeObject(): Record<string, string[]> {
9497
const parsedOptions = this._parseOptions();
9598

96-
return parsedOptions.reduce((sum, item) => {
97-
const [exposeKey, exposeObject] = item;
98-
sum[exposeKey] = [];
99-
exposeObject.import.forEach((item) => {
100-
const relativePath = path.relative(
101-
'.',
102-
item.replace(path.extname(item), ''),
103-
);
104-
sum[exposeKey].push(relativePath);
105-
});
106-
return sum;
107-
}, {});
99+
return parsedOptions.reduce(
100+
(sum, item) => {
101+
const [exposeKey, exposeObject] = item;
102+
sum[exposeKey] = [];
103+
exposeObject.import.forEach((item) => {
104+
const relativePath = path.relative(
105+
'.',
106+
item.replace(path.extname(item), ''),
107+
);
108+
sum[exposeKey].push(relativePath);
109+
});
110+
return sum;
111+
},
112+
{} as Record<string, string[]>,
113+
);
108114
}
109115

110116
// { '.' : './src/Button.jsx' } => ['./src/Button.jsx']

packages/managers/src/PKGJsonManager.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import path from 'path';
2+
// @ts-ignore this pkg miss types
23
import finder from 'find-pkg';
34
import fs from 'fs';
45
import { MFModuleType, logger } from '@module-federation/sdk';

packages/managers/src/RemoteManager.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,17 @@ class RemoteManager extends BasicPluginOptionsManager<moduleFederationPlugin.Mod
7777
// 'micro-app-sub3': @garfish/micro-app-sub3:0.0.4
7878
// }
7979
get dtsRemotes(): Record<string, string> {
80-
return Object.keys(this.normalizedOptions).reduce((sum, remoteAlias) => {
81-
const remoteInfo = this.normalizedOptions[remoteAlias];
82-
sum[remoteAlias] = composeKeyWithSeparator(
83-
remoteInfo.name,
84-
'entry' in remoteInfo ? remoteInfo.entry : remoteInfo.version,
85-
);
86-
return sum;
87-
}, {});
80+
return Object.keys(this.normalizedOptions).reduce(
81+
(sum, remoteAlias) => {
82+
const remoteInfo = this.normalizedOptions[remoteAlias];
83+
sum[remoteAlias] = composeKeyWithSeparator(
84+
remoteInfo.name,
85+
'entry' in remoteInfo ? remoteInfo.entry : remoteInfo.version,
86+
);
87+
return sum;
88+
},
89+
{} as Record<string, string>,
90+
);
8891
}
8992

9093
get remotes(): moduleFederationPlugin.ModuleFederationPluginOptions['remotes'] {

packages/managers/src/SharedManager.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ts-ignore this pkg miss types
12
import findPkg from 'find-pkg';
23
import path from 'path';
34
import fs from 'fs-extra';
@@ -40,7 +41,7 @@ class SharedManager extends BasicPluginOptionsManager<moduleFederationPlugin.Mod
4041
import: sharedImport,
4142
};
4243
return sum;
43-
}, {});
44+
}, {} as moduleFederationPlugin.SharedObject);
4445
return {
4546
shared,
4647
shareScope: this.options.shareScope || 'default',
@@ -127,9 +128,7 @@ class SharedManager extends BasicPluginOptionsManager<moduleFederationPlugin.Mod
127128
sharedOptions.forEach((item) => {
128129
const [sharedName, sharedOptions] = item;
129130
const pkgInfo = this.findPkg(sharedName, sharedOptions);
130-
const sharedConfig = this.transformSharedConfig(
131-
sharedOptions[sharedName],
132-
);
131+
const sharedConfig = this.transformSharedConfig(sharedOptions);
133132
normalizedShared[sharedName] = {
134133
...sharedConfig,
135134
requiredVersion:

packages/managers/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"skipLibCheck": true,
1515
"skipDefaultLibCheck": true,
1616
"declaration": true,
17-
"noImplicitAny": false
17+
"noImplicitAny": true
1818
},
1919
"files": [],
2020
"include": [],

0 commit comments

Comments
 (0)