@module-federation/manifest 2.0.1 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  import { StatsExpose, StatsRemote, StatsShared, moduleFederationPlugin } from '@module-federation/sdk';
2
- import type { StatsModule } from 'webpack';
2
+ import type { StatsModule } from '../../../webpack/lib/stats/DefaultStatsFactoryPlugin.d';
3
3
  import type managerTypes from '@module-federation/managers';
4
4
  export declare const getExposeName: (exposeKey: string) => string;
5
5
  export declare function getExposeItem({ exposeKey, name, file, }: {
@@ -186,10 +186,51 @@ class StatsManager {
186
186
  const { exposeFileNameImportMap } = this._containerManager;
187
187
  const assets = {};
188
188
  chunks.forEach((chunk)=>{
189
- if (typeof chunk.name === 'string' && exposeFileNameImportMap[chunk.name]) {
190
- // TODO: support multiple import
191
- const exposeKey = exposeFileNameImportMap[chunk.name][0];
192
- assets[(0,external_utils_js_namespaceObject.getFileNameWithOutExt)(exposeKey)] = (0,external_utils_js_namespaceObject.getAssetsByChunk)(chunk, entryPointNames);
189
+ if (typeof chunk.name !== 'string') return;
190
+ // Support split chunks caused by splitChunks.maxSize:
191
+ // A chunk named "__federation_expose_Foo" may be split into
192
+ // "__federation_expose_Foo-<hash>" chunks, so we match both exact
193
+ // and prefix+dash patterns.
194
+ const matchedKey = exposeFileNameImportMap[chunk.name] !== undefined ? chunk.name : Object.keys(exposeFileNameImportMap).find((key)=>chunk.name.startsWith(key + '-'));
195
+ if (!matchedKey) return;
196
+ // TODO: support multiple import
197
+ const exposeKey = exposeFileNameImportMap[matchedKey][0];
198
+ const assetKey = (0,external_utils_js_namespaceObject.getFileNameWithOutExt)(exposeKey);
199
+ const chunkAssets = (0,external_utils_js_namespaceObject.getAssetsByChunk)(chunk, entryPointNames);
200
+ if (!assets[assetKey]) {
201
+ assets[assetKey] = chunkAssets;
202
+ } else {
203
+ // Merge split chunk assets, deduplicating with Set
204
+ assets[assetKey] = {
205
+ js: {
206
+ sync: [
207
+ ...new Set([
208
+ ...assets[assetKey].js.sync,
209
+ ...chunkAssets.js.sync
210
+ ])
211
+ ],
212
+ async: [
213
+ ...new Set([
214
+ ...assets[assetKey].js.async,
215
+ ...chunkAssets.js.async
216
+ ])
217
+ ]
218
+ },
219
+ css: {
220
+ sync: [
221
+ ...new Set([
222
+ ...assets[assetKey].css.sync,
223
+ ...chunkAssets.css.sync
224
+ ])
225
+ ],
226
+ async: [
227
+ ...new Set([
228
+ ...assets[assetKey].css.async,
229
+ ...chunkAssets.css.async
230
+ ])
231
+ ]
232
+ }
233
+ };
193
234
  }
194
235
  });
195
236
  return assets;
@@ -134,10 +134,51 @@ class StatsManager {
134
134
  const { exposeFileNameImportMap } = this._containerManager;
135
135
  const assets = {};
136
136
  chunks.forEach((chunk)=>{
137
- if (typeof chunk.name === 'string' && exposeFileNameImportMap[chunk.name]) {
138
- // TODO: support multiple import
139
- const exposeKey = exposeFileNameImportMap[chunk.name][0];
140
- assets[getFileNameWithOutExt(exposeKey)] = getAssetsByChunk(chunk, entryPointNames);
137
+ if (typeof chunk.name !== 'string') return;
138
+ // Support split chunks caused by splitChunks.maxSize:
139
+ // A chunk named "__federation_expose_Foo" may be split into
140
+ // "__federation_expose_Foo-<hash>" chunks, so we match both exact
141
+ // and prefix+dash patterns.
142
+ const matchedKey = exposeFileNameImportMap[chunk.name] !== undefined ? chunk.name : Object.keys(exposeFileNameImportMap).find((key)=>chunk.name.startsWith(key + '-'));
143
+ if (!matchedKey) return;
144
+ // TODO: support multiple import
145
+ const exposeKey = exposeFileNameImportMap[matchedKey][0];
146
+ const assetKey = getFileNameWithOutExt(exposeKey);
147
+ const chunkAssets = getAssetsByChunk(chunk, entryPointNames);
148
+ if (!assets[assetKey]) {
149
+ assets[assetKey] = chunkAssets;
150
+ } else {
151
+ // Merge split chunk assets, deduplicating with Set
152
+ assets[assetKey] = {
153
+ js: {
154
+ sync: [
155
+ ...new Set([
156
+ ...assets[assetKey].js.sync,
157
+ ...chunkAssets.js.sync
158
+ ])
159
+ ],
160
+ async: [
161
+ ...new Set([
162
+ ...assets[assetKey].js.async,
163
+ ...chunkAssets.js.async
164
+ ])
165
+ ]
166
+ },
167
+ css: {
168
+ sync: [
169
+ ...new Set([
170
+ ...assets[assetKey].css.sync,
171
+ ...chunkAssets.css.sync
172
+ ])
173
+ ],
174
+ async: [
175
+ ...new Set([
176
+ ...assets[assetKey].css.async,
177
+ ...chunkAssets.css.async
178
+ ])
179
+ ]
180
+ }
181
+ };
141
182
  }
142
183
  });
143
184
  return assets;
package/dist/utils.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { Chunk, Compilation, StatsCompilation, StatsModule } from 'webpack';
1
+ import { Chunk, Compilation } from 'webpack';
2
+ import type { StatsCompilation, StatsModule } from '../../../webpack/lib/stats/DefaultStatsFactoryPlugin.d';
2
3
  import { StatsAssets, moduleFederationPlugin, MetaDataTypes } from '@module-federation/sdk';
3
4
  export declare function getAssetsByChunkIDs(compilation: Compilation, chunkIDMap: Record<string, Set<string | number>>): Record<string, {
4
5
  js: string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/manifest",
3
- "version": "2.0.1",
3
+ "version": "2.1.0",
4
4
  "license": "MIT",
5
5
  "description": "Provide manifest/stats for webpack/rspack MF project .",
6
6
  "keywords": [
@@ -29,9 +29,9 @@
29
29
  "dependencies": {
30
30
  "find-pkg": "2.0.0",
31
31
  "chalk": "3.0.0",
32
- "@module-federation/sdk": "2.0.1",
33
- "@module-federation/dts-plugin": "2.0.1",
34
- "@module-federation/managers": "2.0.1"
32
+ "@module-federation/sdk": "2.1.0",
33
+ "@module-federation/managers": "2.1.0",
34
+ "@module-federation/dts-plugin": "2.1.0"
35
35
  },
36
36
  "exports": {
37
37
  ".": {