Skip to content

Commit

Permalink
fix(manifest): add default exposes fields if set disableAssetsAnalyze…
Browse files Browse the repository at this point in the history
…: true
  • Loading branch information
2heal1 committed Dec 24, 2024
1 parent 222aa5b commit e53d36d
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 21 deletions.
5 changes: 5 additions & 0 deletions .changeset/metal-bags-admire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@module-federation/manifest': patch
---

fix(manifest): add default exposes fields if set disableAssetsAnalyze: true
55 changes: 36 additions & 19 deletions packages/manifest/src/ModuleHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,37 @@ type ShareMap = { [sharedKey: string]: StatsShared };
type ExposeMap = { [exposeImportValue: string]: StatsExpose };
type RemotesConsumerMap = { [remoteKey: string]: StatsRemote };

export function getExposeItem({
exposeKey,
name,
file,
}: {
exposeKey: string;
name: string;
file: { import: string[] };
}): StatsExpose {
const exposeModuleName = exposeKey.replace('./', '');

return {
path: exposeKey,
id: `${name}:${exposeModuleName}`,
name: exposeModuleName,
// @ts-ignore to deduplicate
requires: new Set(),
file: path.relative(process.cwd(), file.import[0]),
assets: {
js: {
async: [],
sync: [],
},
css: {
async: [],
sync: [],
},
},
};
}

class ModuleHandler {
private _options: moduleFederationPlugin.ModuleFederationPluginOptions;
private _bundler: 'webpack' | 'rspack' = 'webpack';
Expand Down Expand Up @@ -258,26 +289,12 @@ class ModuleHandler {
const data = identifier.split(' ');

JSON.parse(data[3]).forEach(([prefixedName, file]) => {
const exposeModuleName = prefixedName.replace('./', '');
// TODO: support multiple import
exposesMap[getFileNameWithOutExt(file.import[0])] = {
path: prefixedName,
id: `${this._options.name}:${exposeModuleName}`,
name: exposeModuleName,
// @ts-ignore to deduplicate
requires: new Set(),
file: path.relative(process.cwd(), file.import[0]),
assets: {
js: {
async: [],
sync: [],
},
css: {
async: [],
sync: [],
},
},
};
exposesMap[getFileNameWithOutExt(file.import[0])] = getExposeItem({
exposeKey: prefixedName,
name: this._options.name!,
file,
});
});
}

Expand Down
17 changes: 15 additions & 2 deletions packages/manifest/src/StatsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import {
utils,
} from '@module-federation/managers';
import { HOT_UPDATE_SUFFIX, PLUGIN_IDENTIFIER } from './constants';
import { ModuleHandler } from './ModuleHandler';
import { ModuleHandler, getExposeItem } from './ModuleHandler';
import { StatsInfo } from './types';

class StatsManager {
Expand Down Expand Up @@ -300,7 +300,11 @@ class StatsManager {
extraOptions?: {},
): Promise<Stats> {
try {
const { name, manifest: manifestOptions = {} } = this._options;
const {
name,
manifest: manifestOptions = {},
exposes = {},
} = this._options;

const metaData = this._getMetaData(compiler, compilation, extraOptions);

Expand All @@ -320,6 +324,15 @@ class StatsManager {
const remotes: StatsRemote[] =
this._remoteManager.statsRemoteWithEmptyUsedIn;
stats.remotes = remotes;
stats.exposes = Object.keys(exposes).map((exposeKey) => {
return getExposeItem({
exposeKey,
name: name!,
file: {
import: exposes[exposeKey].import,
},
});
});
return stats;
}

Expand Down

0 comments on commit e53d36d

Please sign in to comment.