@bleedingdev/mf-manifest 2.9.1

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.
@@ -0,0 +1,543 @@
1
+ "use strict";
2
+ const __rslib_import_meta_url__ = /*#__PURE__*/ (function () {
3
+ return typeof document === 'undefined'
4
+ ? new (require('url'.replace('', '')).URL)('file:' + __filename).href
5
+ : (document.currentScript && document.currentScript.src) ||
6
+ new URL('main.js', document.baseURI).href;
7
+ })();
8
+ ;
9
+ // The require scope
10
+ var __webpack_require__ = {};
11
+
12
+ // webpack/runtime/compat_get_default_export
13
+ (() => {
14
+ // getDefaultExport function for compatibility with non-ESM modules
15
+ __webpack_require__.n = (module) => {
16
+ var getter = module && module.__esModule ?
17
+ () => (module['default']) :
18
+ () => (module);
19
+ __webpack_require__.d(getter, { a: getter });
20
+ return getter;
21
+ };
22
+
23
+ })();
24
+ // webpack/runtime/define_property_getters
25
+ (() => {
26
+ __webpack_require__.d = (exports, getters, values) => {
27
+ var define = (defs, kind) => {
28
+ for(var key in defs) {
29
+ if(__webpack_require__.o(defs, key) && !__webpack_require__.o(exports, key)) {
30
+ Object.defineProperty(exports, key, { enumerable: true, [kind]: defs[key] });
31
+ }
32
+ }
33
+ };
34
+ define(getters, "get");
35
+ define(values, "value");
36
+ };
37
+ })();
38
+ // webpack/runtime/has_own_property
39
+ (() => {
40
+ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
41
+ })();
42
+ // webpack/runtime/make_namespace_object
43
+ (() => {
44
+ // define __esModule on exports
45
+ __webpack_require__.r = (exports) => {
46
+ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
47
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
48
+ }
49
+ Object.defineProperty(exports, '__esModule', { value: true });
50
+ };
51
+ })();
52
+ var __webpack_exports__ = {};
53
+ // ESM COMPAT FLAG
54
+ __webpack_require__.r(__webpack_exports__);
55
+
56
+ // EXPORTS
57
+ __webpack_require__.d(__webpack_exports__, {
58
+ StatsManager: () => (/* binding */ StatsManager)
59
+ });
60
+
61
+ ;// CONCATENATED MODULE: external "@module-federation/sdk"
62
+ const sdk_namespaceObject = require("@module-federation/sdk");
63
+ ;// CONCATENATED MODULE: external "./utils.js"
64
+ const external_utils_js_namespaceObject = require("./utils.js");
65
+ ;// CONCATENATED MODULE: external "./logger.js"
66
+ const external_logger_js_namespaceObject = require("./logger.js");
67
+ var external_logger_js_default = /*#__PURE__*/__webpack_require__.n(external_logger_js_namespaceObject);
68
+ ;// CONCATENATED MODULE: external "@module-federation/managers"
69
+ const managers_namespaceObject = require("@module-federation/managers");
70
+ ;// CONCATENATED MODULE: external "./constants.js"
71
+ const external_constants_js_namespaceObject = require("./constants.js");
72
+ ;// CONCATENATED MODULE: external "./ModuleHandler.js"
73
+ const external_ModuleHandler_js_namespaceObject = require("./ModuleHandler.js");
74
+ ;// CONCATENATED MODULE: ./src/StatsManager.ts
75
+ /* eslint-disable max-lines-per-function */ /* eslint-disable @typescript-eslint/member-ordering */ /* eslint-disable max-depth */
76
+
77
+
78
+
79
+
80
+
81
+ class StatsManager {
82
+ getBuildInfo(context, target) {
83
+ const rootPath = context || process.cwd();
84
+ const pkg = this._pkgJsonManager.readPKGJson(rootPath);
85
+ const statsBuildInfo = {
86
+ buildVersion: managers_namespaceObject.utils.getBuildVersion(rootPath),
87
+ buildName: managers_namespaceObject.utils.getBuildName() || pkg['name']
88
+ };
89
+ if (this._sharedManager.enableTreeShaking) {
90
+ statsBuildInfo.target = target ? Array.isArray(target) ? target : [
91
+ target
92
+ ] : [];
93
+ statsBuildInfo.plugins = this._options.treeShakingSharedPlugins || [];
94
+ statsBuildInfo.excludePlugins = this._options.treeShakingSharedExcludePlugins || [];
95
+ }
96
+ return statsBuildInfo;
97
+ }
98
+ get fileName() {
99
+ return (0,sdk_namespaceObject.getManifestFileName)(this._options.manifest).statsFileName;
100
+ }
101
+ setMetaDataPublicPath(metaData, compiler) {
102
+ if (this._options.getPublicPath) {
103
+ if ('publicPath' in metaData) {
104
+ // @ts-ignore
105
+ delete metaData.publicPath;
106
+ }
107
+ metaData.getPublicPath = this._options.getPublicPath;
108
+ } else {
109
+ metaData.publicPath = this.getPublicPath(compiler);
110
+ }
111
+ return metaData;
112
+ }
113
+ _getMetaData(compiler, compilation, extraOptions) {
114
+ const { context } = compiler.options;
115
+ const { _options: { name } } = this;
116
+ const buildInfo = this.getBuildInfo(context, compilation.options.target || '');
117
+ const type = this._pkgJsonManager.getExposeGarfishModuleType(context || process.cwd());
118
+ const getRemoteEntryName = ()=>{
119
+ if (!this._containerManager.enable) {
120
+ return '';
121
+ }
122
+ (0,external_utils_js_namespaceObject.assert)(name, 'name is required');
123
+ const remoteEntryPoint = compilation.entrypoints.get(name);
124
+ (0,external_utils_js_namespaceObject.assert)(remoteEntryPoint, 'Can not get remoteEntry entryPoint!');
125
+ const remoteEntryNameChunk = compilation.namedChunks.get(name);
126
+ (0,external_utils_js_namespaceObject.assert)(remoteEntryNameChunk, 'Can not get remoteEntry chunk!');
127
+ const files = Array.from(remoteEntryNameChunk.files).filter((f)=>!f.includes(external_constants_js_namespaceObject.HOT_UPDATE_SUFFIX) && !f.endsWith('.css'));
128
+ (0,external_utils_js_namespaceObject.assert)(files.length > 0, 'no files found for remoteEntry chunk');
129
+ (0,external_utils_js_namespaceObject.assert)(files.length === 1, `remoteEntry chunk should not have multiple files!, current files: ${files.join(',')}`);
130
+ const remoteEntryName = files[0];
131
+ return remoteEntryName;
132
+ };
133
+ const globalName = this._containerManager.globalEntryName;
134
+ (0,external_utils_js_namespaceObject.assert)(globalName, 'Can not get library.name, please ensure you have set library.name and the type is "string" !');
135
+ (0,external_utils_js_namespaceObject.assert)(this._pluginVersion, 'Can not get pluginVersion, please ensure you have set pluginVersion !');
136
+ const metaData = {
137
+ name: name,
138
+ type,
139
+ buildInfo,
140
+ remoteEntry: {
141
+ name: getRemoteEntryName(),
142
+ path: '',
143
+ // The runtime loader type follows the configured container library type.
144
+ type: this._options?.library?.type || 'global'
145
+ },
146
+ types: (0,external_utils_js_namespaceObject.getTypesMetaInfo)(this._options, compiler.context),
147
+ globalName: globalName,
148
+ pluginVersion: this._pluginVersion
149
+ };
150
+ return this.setMetaDataPublicPath(metaData, compiler);
151
+ }
152
+ _getFilteredModules(stats) {
153
+ const filteredModules = stats.modules.filter((module)=>{
154
+ if (!module || !module.name) {
155
+ return false;
156
+ }
157
+ const array = [
158
+ module.name.includes('container entry'),
159
+ module.name.includes('remote '),
160
+ module.name.includes('shared module '),
161
+ module.name.includes('provide module ')
162
+ ];
163
+ return array.some((item)=>item);
164
+ });
165
+ return filteredModules;
166
+ }
167
+ _getModuleAssets(compilation, entryPointNames) {
168
+ const { chunks } = compilation;
169
+ const { exposeFileNameImportMap } = this._containerManager;
170
+ const assets = {};
171
+ chunks.forEach((chunk)=>{
172
+ if (typeof chunk.name !== 'string') return;
173
+ // Support split chunks caused by splitChunks.maxSize:
174
+ // A chunk named "__federation_expose_Foo" may be split into
175
+ // "__federation_expose_Foo-<hash>" chunks, so we match both exact
176
+ // and prefix+dash patterns.
177
+ const matchedKey = exposeFileNameImportMap[chunk.name] !== undefined ? chunk.name : Object.keys(exposeFileNameImportMap).find((key)=>chunk.name.startsWith(key + '-'));
178
+ if (!matchedKey) return;
179
+ // TODO: support multiple import
180
+ const exposeKey = exposeFileNameImportMap[matchedKey][0];
181
+ const assetKey = (0,external_utils_js_namespaceObject.getFileNameWithOutExt)(exposeKey);
182
+ const chunkAssets = (0,external_utils_js_namespaceObject.getAssetsByChunk)(chunk, entryPointNames);
183
+ if (!assets[assetKey]) {
184
+ assets[assetKey] = chunkAssets;
185
+ } else {
186
+ // Merge split chunk assets, deduplicating with Set
187
+ assets[assetKey] = {
188
+ js: {
189
+ sync: [
190
+ ...new Set([
191
+ ...assets[assetKey].js.sync,
192
+ ...chunkAssets.js.sync
193
+ ])
194
+ ],
195
+ async: [
196
+ ...new Set([
197
+ ...assets[assetKey].js.async,
198
+ ...chunkAssets.js.async
199
+ ])
200
+ ]
201
+ },
202
+ css: {
203
+ sync: [
204
+ ...new Set([
205
+ ...assets[assetKey].css.sync,
206
+ ...chunkAssets.css.sync
207
+ ])
208
+ ],
209
+ async: [
210
+ ...new Set([
211
+ ...assets[assetKey].css.async,
212
+ ...chunkAssets.css.async
213
+ ])
214
+ ]
215
+ }
216
+ };
217
+ }
218
+ });
219
+ return assets;
220
+ }
221
+ _getProvideSharedAssets(compilation, stats, entryPointNames) {
222
+ const sharedModules = stats.modules.filter((module)=>{
223
+ if (!module || !module.name) {
224
+ return false;
225
+ }
226
+ const array = [
227
+ module.name.includes('consume shared module ')
228
+ ];
229
+ return array.some((item)=>item);
230
+ });
231
+ const manifestOverrideChunkIDMap = {};
232
+ const effectiveSharedModules = (0,external_utils_js_namespaceObject.getSharedModules)(stats, sharedModules);
233
+ effectiveSharedModules.forEach((item)=>{
234
+ const [sharedModuleName, sharedModule] = item;
235
+ if (!manifestOverrideChunkIDMap[sharedModuleName]) {
236
+ manifestOverrideChunkIDMap[sharedModuleName] = {
237
+ async: new Set(),
238
+ sync: new Set()
239
+ };
240
+ }
241
+ sharedModule.chunks.forEach((chunkID)=>{
242
+ const chunk = (0,external_utils_js_namespaceObject.findChunk)(chunkID, compilation.chunks);
243
+ manifestOverrideChunkIDMap[sharedModuleName].sync.add(chunkID);
244
+ if (!chunk) {
245
+ return;
246
+ }
247
+ [
248
+ ...chunk.groupsIterable
249
+ ].forEach((group)=>{
250
+ if (group.name && !entryPointNames.includes(group.name)) {
251
+ manifestOverrideChunkIDMap[sharedModuleName].sync.add(group.id);
252
+ }
253
+ });
254
+ });
255
+ });
256
+ const assets = {
257
+ js: {
258
+ async: [],
259
+ sync: []
260
+ },
261
+ css: {
262
+ async: [],
263
+ sync: []
264
+ }
265
+ };
266
+ Object.keys(manifestOverrideChunkIDMap).forEach((override)=>{
267
+ const asyncAssets = (0,external_utils_js_namespaceObject.getAssetsByChunkIDs)(compilation, {
268
+ [override]: manifestOverrideChunkIDMap[override].async
269
+ });
270
+ const syncAssets = (0,external_utils_js_namespaceObject.getAssetsByChunkIDs)(compilation, {
271
+ [override]: manifestOverrideChunkIDMap[override].sync
272
+ });
273
+ assets[override] = {
274
+ js: {
275
+ async: asyncAssets[override].js,
276
+ sync: syncAssets[override].js
277
+ },
278
+ css: {
279
+ async: asyncAssets[override].css,
280
+ sync: syncAssets[override].css
281
+ }
282
+ };
283
+ });
284
+ return assets;
285
+ }
286
+ async _generateStats(compiler, compilation, extraOptions) {
287
+ try {
288
+ const { name, manifest: manifestOptions = {}, exposes = {} } = this._options;
289
+ const metaData = this._getMetaData(compiler, compilation, extraOptions);
290
+ const stats = {
291
+ id: name,
292
+ name: name,
293
+ metaData,
294
+ shared: [],
295
+ remotes: [],
296
+ exposes: []
297
+ };
298
+ if (typeof manifestOptions === 'object' && manifestOptions.disableAssetsAnalyze) {
299
+ const remotes = this._remoteManager.statsRemoteWithEmptyUsedIn;
300
+ stats.remotes = remotes;
301
+ stats.exposes = Object.keys(exposes).map((exposeKey)=>{
302
+ return (0,external_ModuleHandler_js_namespaceObject.getExposeItem)({
303
+ exposeKey,
304
+ name: name,
305
+ file: {
306
+ import: exposes[exposeKey].import
307
+ }
308
+ });
309
+ });
310
+ stats.shared = Object.entries(this._sharedManager.normalizedOptions).reduce((sum, cur)=>{
311
+ const [pkgName, normalizedShareOptions] = cur;
312
+ sum.push((0,external_ModuleHandler_js_namespaceObject.getShareItem)({
313
+ pkgName,
314
+ normalizedShareOptions,
315
+ pkgVersion: normalizedShareOptions.version || managers_namespaceObject.UNKNOWN_MODULE_NAME,
316
+ hostName: name
317
+ }));
318
+ return sum;
319
+ }, []);
320
+ return stats;
321
+ }
322
+ const liveStats = compilation.getStats();
323
+ const statsOptions = {
324
+ all: false,
325
+ modules: true,
326
+ builtAt: true,
327
+ hash: true,
328
+ ids: true,
329
+ version: true,
330
+ entrypoints: true,
331
+ assets: false,
332
+ chunks: false,
333
+ reasons: true
334
+ };
335
+ if (this._bundler === 'webpack') {
336
+ statsOptions['cached'] = true;
337
+ }
338
+ statsOptions['cachedModules'] = true;
339
+ const webpackStats = liveStats.toJson(statsOptions);
340
+ const filteredModules = this._getFilteredModules(webpackStats);
341
+ const moduleHandler = new external_ModuleHandler_js_namespaceObject.ModuleHandler(this._options, filteredModules, {
342
+ bundler: this._bundler
343
+ });
344
+ const { remotes, exposesMap, sharedMap } = moduleHandler.collect();
345
+ const entryPointNames = [
346
+ ...compilation.entrypoints.values()
347
+ ].map((e)=>e.name).filter((v)=>!!v);
348
+ await Promise.all([
349
+ new Promise((resolve)=>{
350
+ const sharedAssets = this._getProvideSharedAssets(compilation, webpackStats, entryPointNames);
351
+ Object.keys(sharedMap).forEach((sharedKey)=>{
352
+ const assets = sharedAssets[sharedKey];
353
+ if (assets) {
354
+ sharedMap[sharedKey].assets = assets;
355
+ }
356
+ });
357
+ resolve();
358
+ }),
359
+ new Promise((resolve)=>{
360
+ const moduleAssets = this._getModuleAssets(compilation, entryPointNames);
361
+ Object.keys(exposesMap).forEach((exposeKey)=>{
362
+ const assets = moduleAssets[exposeKey];
363
+ if (assets) {
364
+ exposesMap[exposeKey].assets = assets;
365
+ }
366
+ exposesMap[exposeKey].requires = Array.from(new Set(exposesMap[exposeKey].requires));
367
+ });
368
+ resolve();
369
+ })
370
+ ]);
371
+ await Promise.all([
372
+ new Promise((resolve)=>{
373
+ const remoteMemo = new Set();
374
+ stats.remotes = remotes.map((remote)=>{
375
+ remoteMemo.add(remote.federationContainerName);
376
+ return {
377
+ ...remote,
378
+ usedIn: Array.from(remote.usedIn.values())
379
+ };
380
+ });
381
+ const statsRemoteWithEmptyUsedIn = this._remoteManager.statsRemoteWithEmptyUsedIn;
382
+ statsRemoteWithEmptyUsedIn.forEach((remoteInfo)=>{
383
+ if (!remoteMemo.has(remoteInfo.federationContainerName)) {
384
+ stats.remotes.push(remoteInfo);
385
+ }
386
+ });
387
+ resolve();
388
+ }),
389
+ new Promise((resolve)=>{
390
+ stats.shared = Object.values(sharedMap).map((shared)=>({
391
+ ...shared,
392
+ usedIn: Array.from(shared.usedIn)
393
+ }));
394
+ resolve();
395
+ })
396
+ ]);
397
+ await new Promise((resolve)=>{
398
+ const sharedAssets = stats.shared.reduce((sum, shared)=>{
399
+ const { js, css } = shared.assets;
400
+ [
401
+ ...js.sync,
402
+ ...js.async,
403
+ ...css.async,
404
+ css.sync
405
+ ].forEach((asset)=>{
406
+ sum.add(asset);
407
+ });
408
+ return sum;
409
+ }, new Set());
410
+ const { fileExposeKeyMap } = this._containerManager;
411
+ stats.exposes = [];
412
+ Object.entries(fileExposeKeyMap).forEach(([exposeFileWithoutExt, exposeKeySet])=>{
413
+ const expose = exposesMap[exposeFileWithoutExt] || {
414
+ assets: {
415
+ js: {
416
+ sync: [],
417
+ async: []
418
+ },
419
+ css: {
420
+ sync: [],
421
+ async: []
422
+ }
423
+ }
424
+ };
425
+ exposeKeySet.forEach((exposeKey)=>{
426
+ const { js, css } = expose.assets;
427
+ const exposeModuleName = (0,external_ModuleHandler_js_namespaceObject.getExposeName)(exposeKey);
428
+ stats.exposes.push({
429
+ ...expose,
430
+ path: exposeKey,
431
+ id: (0,sdk_namespaceObject.composeKeyWithSeparator)(this._options.name, exposeModuleName),
432
+ name: exposeModuleName,
433
+ assets: {
434
+ js: {
435
+ sync: js.sync.filter((asset)=>!sharedAssets.has(asset)),
436
+ async: js.async.filter((asset)=>!sharedAssets.has(asset))
437
+ },
438
+ css: {
439
+ sync: css.sync.filter((asset)=>!sharedAssets.has(asset)),
440
+ async: css.async.filter((asset)=>!sharedAssets.has(asset))
441
+ }
442
+ }
443
+ });
444
+ });
445
+ });
446
+ Object.values(exposesMap).map((expose)=>{
447
+ const { js, css } = expose.assets;
448
+ return {
449
+ ...expose,
450
+ assets: {
451
+ js: {
452
+ sync: js.sync.filter((asset)=>!sharedAssets.has(asset)),
453
+ async: js.async.filter((asset)=>!sharedAssets.has(asset))
454
+ },
455
+ css: {
456
+ sync: css.sync.filter((asset)=>!sharedAssets.has(asset)),
457
+ async: css.async.filter((asset)=>!sharedAssets.has(asset))
458
+ }
459
+ }
460
+ };
461
+ });
462
+ resolve();
463
+ });
464
+ return stats;
465
+ } catch (err) {
466
+ throw err;
467
+ }
468
+ }
469
+ getPublicPath(compiler) {
470
+ if (this._publicPath) {
471
+ return this._publicPath;
472
+ }
473
+ const { output: { publicPath: originalPublicPath } } = compiler.options;
474
+ let publicPath = originalPublicPath;
475
+ this._publicPath = publicPath;
476
+ return publicPath;
477
+ }
478
+ init(options, { pluginVersion, bundler }) {
479
+ this._options = options;
480
+ this._pluginVersion = pluginVersion;
481
+ this._bundler = bundler;
482
+ this._containerManager = new managers_namespaceObject.ContainerManager();
483
+ this._containerManager.init(options);
484
+ this._remoteManager = new managers_namespaceObject.RemoteManager();
485
+ this._remoteManager.init(options);
486
+ this._sharedManager = new managers_namespaceObject.SharedManager();
487
+ this._sharedManager.init(options);
488
+ }
489
+ updateStats(stats, compiler) {
490
+ const { metaData } = stats;
491
+ const configuredRemoteEntryType = this._options.library?.type;
492
+ if (configuredRemoteEntryType && metaData.remoteEntry) {
493
+ // Rspack may pre-emit stats with the default `global` type even when
494
+ // the configured container library and emitted remote entry are ESM.
495
+ // The configured library is authoritative for runtime loader selection.
496
+ metaData.remoteEntry.type = configuredRemoteEntryType;
497
+ }
498
+ if (!metaData.types) {
499
+ metaData.types = (0,external_utils_js_namespaceObject.getTypesMetaInfo)(this._options, compiler.context);
500
+ }
501
+ if (!metaData.pluginVersion) {
502
+ metaData.pluginVersion = this._pluginVersion;
503
+ }
504
+ this.setMetaDataPublicPath(metaData, compiler);
505
+ return stats;
506
+ }
507
+ async generateStats(compiler, compilation) {
508
+ try {
509
+ const stats = await this._generateStats(compiler, compilation);
510
+ return stats;
511
+ } catch (err) {
512
+ throw err;
513
+ }
514
+ }
515
+ validate(compiler) {
516
+ const { output: { publicPath } } = compiler.options;
517
+ if (typeof publicPath !== 'string') {
518
+ external_logger_js_default().warn(`Manifest will not generate, because publicPath can only be string, but got '${publicPath}'`);
519
+ return false;
520
+ } else if (publicPath === 'auto') {
521
+ external_logger_js_default().warn(`Manifest will use absolute path resolution via its host at runtime, reason: publicPath='${publicPath}'`);
522
+ return true;
523
+ }
524
+ return true;
525
+ }
526
+ constructor(){
527
+ this._options = {};
528
+ this._bundler = 'webpack';
529
+ this._containerManager = new managers_namespaceObject.ContainerManager();
530
+ this._remoteManager = new managers_namespaceObject.RemoteManager();
531
+ this._sharedManager = new managers_namespaceObject.SharedManager();
532
+ this._pkgJsonManager = new managers_namespaceObject.PKGJsonManager();
533
+ }
534
+ }
535
+
536
+
537
+ exports.StatsManager = __webpack_exports__.StatsManager;
538
+ for(var __rspack_i in __webpack_exports__) {
539
+ if(["StatsManager"].indexOf(__rspack_i) === -1) {
540
+ exports[__rspack_i] = __webpack_exports__[__rspack_i];
541
+ }
542
+ }
543
+ Object.defineProperty(exports, '__esModule', { value: true });