Skip to content

Commit f8ff0d8

Browse files
authored
fix(dts-plugin): api type file should not related with manifest config (#4230)
1 parent 633aeeb commit f8ff0d8

File tree

4 files changed

+15
-54
lines changed

4 files changed

+15
-54
lines changed

.changeset/fuzzy-lamps-confess.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@module-federation/dts-plugin': patch
3+
'@module-federation/manifest': patch
4+
---
5+
6+
fix(dts-plugin): api type file should not related with manifest config

packages/dts-plugin/src/core/lib/utils.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,14 @@ export const validateOptions = (options: HostOptions) => {
3333
};
3434

3535
export function retrieveTypesAssetsInfo(options: RemoteOptions) {
36-
const { moduleFederationConfig } = options;
3736
let apiTypesPath = '';
3837
let zipTypesPath = '';
3938

40-
let zipPrefix = '';
41-
4239
try {
4340
const { tsConfig, remoteOptions, mapComponentsToExpose } =
4441
retrieveRemoteConfig(options);
4542
if (!Object.keys(mapComponentsToExpose).length || !tsConfig.files.length) {
4643
return {
47-
zipPrefix,
4844
apiTypesPath,
4945
zipTypesPath,
5046
zipName: '',
@@ -58,22 +54,7 @@ export function retrieveTypesAssetsInfo(options: RemoteOptions) {
5854
apiTypesPath = retrieveMfAPITypesPath(tsConfig, remoteOptions);
5955
}
6056

61-
if (
62-
typeof moduleFederationConfig.manifest === 'object' &&
63-
moduleFederationConfig.manifest.filePath
64-
) {
65-
zipPrefix = moduleFederationConfig.manifest.filePath;
66-
} else if (
67-
typeof moduleFederationConfig.manifest === 'object' &&
68-
moduleFederationConfig.manifest.fileName
69-
) {
70-
zipPrefix = path.dirname(moduleFederationConfig.manifest.fileName);
71-
} else if (moduleFederationConfig.filename) {
72-
zipPrefix = path.dirname(moduleFederationConfig.filename);
73-
}
74-
7557
return {
76-
zipPrefix,
7758
apiTypesPath,
7859
zipTypesPath,
7960
zipName: path.basename(zipTypesPath),
@@ -82,7 +63,6 @@ export function retrieveTypesAssetsInfo(options: RemoteOptions) {
8263
} catch (err) {
8364
console.error(ansiColors.red(`Unable to compile federated types, ${err}`));
8465
return {
85-
zipPrefix,
8666
apiTypesPath: '',
8767
zipTypesPath: '',
8868
zipName: '',

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

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -162,29 +162,15 @@ export class GenerateTypesPlugin implements WebpackPluginInstance {
162162
logger.debug('start generating types...');
163163
await generateTypesAPI({ dtsManagerOptions });
164164
logger.debug('generate types success!');
165-
const config = dtsManagerOptions.remote.moduleFederationConfig;
166-
let zipPrefix = '';
167-
if (typeof config.manifest === 'object' && config.manifest.filePath) {
168-
zipPrefix = config.manifest.filePath;
169-
} else if (
170-
typeof config.manifest === 'object' &&
171-
config.manifest.fileName
172-
) {
173-
zipPrefix = path.dirname(config.manifest.fileName);
174-
} else if (config.filename) {
175-
zipPrefix = path.dirname(config.filename);
176-
}
177165

178166
if (isProd) {
179-
const zipAssetName = path.join(zipPrefix, zipName);
180-
const apiAssetName = path.join(zipPrefix, apiFileName);
181167
if (
182168
zipTypesPath &&
183-
!compilation.getAsset(zipAssetName) &&
169+
!compilation.getAsset(zipName) &&
184170
fs.existsSync(zipTypesPath)
185171
) {
186172
compilation.emitAsset(
187-
zipAssetName,
173+
zipName,
188174
new compiler.webpack.sources.RawSource(
189175
fs.readFileSync(zipTypesPath),
190176
false,
@@ -194,11 +180,11 @@ export class GenerateTypesPlugin implements WebpackPluginInstance {
194180

195181
if (
196182
apiTypesPath &&
197-
!compilation.getAsset(apiAssetName) &&
183+
!compilation.getAsset(apiFileName) &&
198184
fs.existsSync(apiTypesPath)
199185
) {
200186
compilation.emitAsset(
201-
apiAssetName,
187+
apiFileName,
202188
new compiler.webpack.sources.RawSource(
203189
fs.readFileSync(apiTypesPath),
204190
false,
@@ -212,11 +198,7 @@ export class GenerateTypesPlugin implements WebpackPluginInstance {
212198
};
213199
if (zipTypesPath && fs.existsSync(zipTypesPath)) {
214200
const zipContent = fs.readFileSync(zipTypesPath);
215-
const zipOutputPath = path.join(
216-
compiler.outputPath,
217-
zipPrefix,
218-
zipName,
219-
);
201+
const zipOutputPath = path.join(compiler.outputPath, zipName);
220202
await new Promise<void>((resolve, reject) => {
221203
compiler.outputFileSystem.mkdir(
222204
path.dirname(zipOutputPath),
@@ -248,11 +230,7 @@ export class GenerateTypesPlugin implements WebpackPluginInstance {
248230

249231
if (apiTypesPath && fs.existsSync(apiTypesPath)) {
250232
const apiContent = fs.readFileSync(apiTypesPath);
251-
const apiOutputPath = path.join(
252-
compiler.outputPath,
253-
zipPrefix,
254-
apiFileName,
255-
);
233+
const apiOutputPath = path.join(compiler.outputPath, apiFileName);
256234
await new Promise<void>((resolve, reject) => {
257235
compiler.outputFileSystem.mkdir(
258236
path.dirname(apiOutputPath),

packages/manifest/src/utils.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -259,20 +259,17 @@ export function getTypesMetaInfo(
259259
return defaultTypesMetaInfo;
260260
}
261261

262-
const { apiFileName, zipName, zipPrefix } = retrieveTypesAssetsInfo({
262+
const { apiFileName, zipName } = retrieveTypesAssetsInfo({
263263
...normalizedRemote,
264264
context,
265265
moduleFederationConfig: pluginOptions,
266266
});
267267

268-
const zip = path.join(zipPrefix, zipName);
269-
const api = path.join(zipPrefix, apiFileName);
270-
271268
return {
272269
path: '',
273270
name: '',
274-
zip,
275-
api,
271+
zip: zipName,
272+
api: apiFileName,
276273
};
277274
} catch (err) {
278275
logger.warn(

0 commit comments

Comments
 (0)