From e53d36d4c7b9180deeaf3156b358579061ab4211 Mon Sep 17 00:00:00 2001 From: 2heal1 Date: Tue, 24 Dec 2024 12:58:01 +0800 Subject: [PATCH] fix(manifest): add default exposes fields if set disableAssetsAnalyze: true --- .changeset/metal-bags-admire.md | 5 +++ packages/manifest/src/ModuleHandler.ts | 55 +++++++++++++++++--------- packages/manifest/src/StatsManager.ts | 17 +++++++- 3 files changed, 56 insertions(+), 21 deletions(-) create mode 100644 .changeset/metal-bags-admire.md diff --git a/.changeset/metal-bags-admire.md b/.changeset/metal-bags-admire.md new file mode 100644 index 00000000000..df50c9537b6 --- /dev/null +++ b/.changeset/metal-bags-admire.md @@ -0,0 +1,5 @@ +--- +'@module-federation/manifest': patch +--- + +fix(manifest): add default exposes fields if set disableAssetsAnalyze: true diff --git a/packages/manifest/src/ModuleHandler.ts b/packages/manifest/src/ModuleHandler.ts index c58ff9dc8a1..00c08742a49 100644 --- a/packages/manifest/src/ModuleHandler.ts +++ b/packages/manifest/src/ModuleHandler.ts @@ -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'; @@ -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, + }); }); } diff --git a/packages/manifest/src/StatsManager.ts b/packages/manifest/src/StatsManager.ts index 70b8eed14ca..873624a1e84 100644 --- a/packages/manifest/src/StatsManager.ts +++ b/packages/manifest/src/StatsManager.ts @@ -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 { @@ -300,7 +300,11 @@ class StatsManager { extraOptions?: {}, ): Promise { try { - const { name, manifest: manifestOptions = {} } = this._options; + const { + name, + manifest: manifestOptions = {}, + exposes = {}, + } = this._options; const metaData = this._getMetaData(compiler, compilation, extraOptions); @@ -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; }