@module-federation/manifest 0.0.0-next-20240223065734

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,1723 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var chalk = require('chalk');
6
+ var sdk = require('@module-federation/sdk');
7
+ var path = require('path');
8
+ var managers = require('@module-federation/managers');
9
+
10
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
11
+
12
+ var chalk__default = /*#__PURE__*/_interopDefaultLegacy(chalk);
13
+ var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
14
+
15
+ var PLUGIN_IDENTIFIER = "Module Federation Manifest Plugin";
16
+
17
+ function _array_like_to_array$2(arr, len) {
18
+ if (len == null || len > arr.length) len = arr.length;
19
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
20
+ return arr2;
21
+ }
22
+ function _array_with_holes$2(arr) {
23
+ if (Array.isArray(arr)) return arr;
24
+ }
25
+ function _array_without_holes$1(arr) {
26
+ if (Array.isArray(arr)) return _array_like_to_array$2(arr);
27
+ }
28
+ function _iterable_to_array$1(iter) {
29
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
30
+ }
31
+ function _iterable_to_array_limit$2(arr, i) {
32
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
33
+ if (_i == null) return;
34
+ var _arr = [];
35
+ var _n = true;
36
+ var _d = false;
37
+ var _s, _e;
38
+ try {
39
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
40
+ _arr.push(_s.value);
41
+ if (i && _arr.length === i) break;
42
+ }
43
+ } catch (err) {
44
+ _d = true;
45
+ _e = err;
46
+ } finally{
47
+ try {
48
+ if (!_n && _i["return"] != null) _i["return"]();
49
+ } finally{
50
+ if (_d) throw _e;
51
+ }
52
+ }
53
+ return _arr;
54
+ }
55
+ function _non_iterable_rest$2() {
56
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
57
+ }
58
+ function _non_iterable_spread$1() {
59
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
60
+ }
61
+ function _sliced_to_array$2(arr, i) {
62
+ return _array_with_holes$2(arr) || _iterable_to_array_limit$2(arr, i) || _unsupported_iterable_to_array$2(arr, i) || _non_iterable_rest$2();
63
+ }
64
+ function _to_consumable_array$1(arr) {
65
+ return _array_without_holes$1(arr) || _iterable_to_array$1(arr) || _unsupported_iterable_to_array$2(arr) || _non_iterable_spread$1();
66
+ }
67
+ function _unsupported_iterable_to_array$2(o, minLen) {
68
+ if (!o) return;
69
+ if (typeof o === "string") return _array_like_to_array$2(o, minLen);
70
+ var n = Object.prototype.toString.call(o).slice(8, -1);
71
+ if (n === "Object" && o.constructor) n = o.constructor.name;
72
+ if (n === "Map" || n === "Set") return Array.from(n);
73
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$2(o, minLen);
74
+ }
75
+ function getSharedModuleName(name) {
76
+ var _name_split = _sliced_to_array$2(name.split(" "), 5); _name_split[0]; _name_split[1]; _name_split[2]; _name_split[3]; var sharedInfo = _name_split[4];
77
+ return sharedInfo.split("@").slice(0, -1).join("@");
78
+ }
79
+ function getAssetsByChunkIDs(compilation, chunkIDMap) {
80
+ var arrayChunks = Array.from(compilation.chunks);
81
+ var assetMap = {};
82
+ Object.keys(chunkIDMap).forEach(function(key) {
83
+ var chunkIDs = Array.from(chunkIDMap[key]);
84
+ if (!assetMap[key]) {
85
+ assetMap[key] = {
86
+ css: new Set(),
87
+ js: new Set()
88
+ };
89
+ }
90
+ chunkIDs.forEach(function(chunkID) {
91
+ var chunk = arrayChunks.find(function(item) {
92
+ return item.id === chunkID;
93
+ });
94
+ if (chunk) {
95
+ _to_consumable_array$1(chunk.files).forEach(function(asset) {
96
+ if (asset.endsWith(".css")) {
97
+ assetMap[key].css.add(asset);
98
+ } else {
99
+ if (process.env["NODE_ENV"] === "development") {
100
+ if (!asset.includes(".hot-update")) {
101
+ assetMap[key].js.add(asset);
102
+ }
103
+ } else {
104
+ assetMap[key].js.add(asset);
105
+ }
106
+ }
107
+ });
108
+ }
109
+ });
110
+ });
111
+ var assets = {};
112
+ Object.keys(assetMap).map(function(key) {
113
+ assets[key] = {
114
+ js: Array.from(assetMap[key].js),
115
+ css: Array.from(assetMap[key].css)
116
+ };
117
+ });
118
+ return assets;
119
+ }
120
+ function findChunk(id, chunks) {
121
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
122
+ try {
123
+ for(var _iterator = chunks[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
124
+ var chunk = _step.value;
125
+ if (id === chunk.id) {
126
+ return chunk;
127
+ }
128
+ }
129
+ } catch (err) {
130
+ _didIteratorError = true;
131
+ _iteratorError = err;
132
+ } finally{
133
+ try {
134
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
135
+ _iterator.return();
136
+ }
137
+ } finally{
138
+ if (_didIteratorError) {
139
+ throw _iteratorError;
140
+ }
141
+ }
142
+ }
143
+ }
144
+ function getSharedModules(stats, sharedModules) {
145
+ var _stats_modules;
146
+ // 获取入口文件就是实际内容的 module
147
+ var entryContentModuleNames = [];
148
+ var effectiveSharedModules = ((_stats_modules = stats.modules) === null || _stats_modules === void 0 ? void 0 : _stats_modules.reduce(function(sum, module) {
149
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
150
+ try {
151
+ for(var _iterator = sharedModules[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
152
+ var sharedModule = _step.value;
153
+ if (sharedModule.name === module.issuerName) {
154
+ entryContentModuleNames.push(sharedModule.name);
155
+ sum.push([
156
+ getSharedModuleName(module.issuerName),
157
+ module
158
+ ]);
159
+ return sum;
160
+ }
161
+ }
162
+ } catch (err) {
163
+ _didIteratorError = true;
164
+ _iteratorError = err;
165
+ } finally{
166
+ try {
167
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
168
+ _iterator.return();
169
+ }
170
+ } finally{
171
+ if (_didIteratorError) {
172
+ throw _iteratorError;
173
+ }
174
+ }
175
+ }
176
+ return sum;
177
+ }, [])) || [];
178
+ // 获取入口文件仅作为 Re Export 的 module
179
+ var entryReExportModules = sharedModules.filter(function(sharedModule) {
180
+ return !entryContentModuleNames.includes(sharedModule.name);
181
+ });
182
+ if (entryReExportModules.length) {
183
+ effectiveSharedModules = effectiveSharedModules.concat(stats.modules.reduce(function(sum, module) {
184
+ var flag = false;
185
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
186
+ try {
187
+ for(var _iterator = entryReExportModules[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
188
+ var entryReExportModule = _step.value;
189
+ if (flag) {
190
+ break;
191
+ }
192
+ if (module.reasons) {
193
+ var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
194
+ try {
195
+ for(var _iterator1 = module.reasons[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
196
+ var issueModule = _step1.value;
197
+ if (issueModule.moduleName === entryReExportModule.name) {
198
+ sum.push([
199
+ getSharedModuleName(entryReExportModule.name),
200
+ module
201
+ ]);
202
+ flag = true;
203
+ break;
204
+ }
205
+ }
206
+ } catch (err) {
207
+ _didIteratorError1 = true;
208
+ _iteratorError1 = err;
209
+ } finally{
210
+ try {
211
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
212
+ _iterator1.return();
213
+ }
214
+ } finally{
215
+ if (_didIteratorError1) {
216
+ throw _iteratorError1;
217
+ }
218
+ }
219
+ }
220
+ }
221
+ }
222
+ } catch (err) {
223
+ _didIteratorError = true;
224
+ _iteratorError = err;
225
+ } finally{
226
+ try {
227
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
228
+ _iterator.return();
229
+ }
230
+ } finally{
231
+ if (_didIteratorError) {
232
+ throw _iteratorError;
233
+ }
234
+ }
235
+ }
236
+ return sum;
237
+ }, []));
238
+ }
239
+ return effectiveSharedModules;
240
+ }
241
+ function getAssetsByChunk(chunk) {
242
+ var assesSet = {
243
+ js: {
244
+ sync: new Set(),
245
+ async: new Set()
246
+ },
247
+ css: {
248
+ sync: new Set(),
249
+ async: new Set()
250
+ }
251
+ };
252
+ var collectChunkFiles = function(targetChunk, type) {
253
+ _to_consumable_array$1(targetChunk.groupsIterable).forEach(function(chunkGroup) {
254
+ chunkGroup.getFiles().forEach(function(file) {
255
+ if (file.endsWith(".css")) {
256
+ assesSet.css[type].add(file);
257
+ } else {
258
+ assesSet.js[type].add(file);
259
+ }
260
+ });
261
+ });
262
+ };
263
+ collectChunkFiles(chunk, "sync");
264
+ _to_consumable_array$1(chunk.getAllAsyncChunks()).forEach(function(asyncChunk) {
265
+ asyncChunk.files.forEach(function(file) {
266
+ if (file.endsWith(".css")) {
267
+ assesSet.css.async.add(file);
268
+ } else {
269
+ assesSet.js.async.add(file);
270
+ }
271
+ });
272
+ collectChunkFiles(asyncChunk, "async");
273
+ });
274
+ var assets = {
275
+ js: {
276
+ sync: Array.from(assesSet.js.sync),
277
+ async: Array.from(assesSet.js.async)
278
+ },
279
+ css: {
280
+ sync: Array.from(assesSet.css.sync),
281
+ async: Array.from(assesSet.css.async)
282
+ }
283
+ };
284
+ return assets;
285
+ }
286
+ function assert(condition, msg) {
287
+ if (!condition) {
288
+ error(msg);
289
+ }
290
+ }
291
+ function error(msg) {
292
+ throw new Error("[ ".concat(PLUGIN_IDENTIFIER, " ]: ").concat(msg));
293
+ }
294
+ function isDev() {
295
+ return process.env["NODE_ENV"] === "development";
296
+ }
297
+ function getFileNameWithOutExt(str) {
298
+ return str.replace(path__default["default"].extname(str), "");
299
+ }
300
+
301
+ function _class_call_check$3(instance, Constructor) {
302
+ if (!(instance instanceof Constructor)) {
303
+ throw new TypeError("Cannot call a class as a function");
304
+ }
305
+ }
306
+ function _defineProperties$3(target, props) {
307
+ for(var i = 0; i < props.length; i++){
308
+ var descriptor = props[i];
309
+ descriptor.enumerable = descriptor.enumerable || false;
310
+ descriptor.configurable = true;
311
+ if ("value" in descriptor) descriptor.writable = true;
312
+ Object.defineProperty(target, descriptor.key, descriptor);
313
+ }
314
+ }
315
+ function _create_class$3(Constructor, protoProps, staticProps) {
316
+ if (protoProps) _defineProperties$3(Constructor.prototype, protoProps);
317
+ if (staticProps) _defineProperties$3(Constructor, staticProps);
318
+ return Constructor;
319
+ }
320
+ function _define_property$3(obj, key, value) {
321
+ if (key in obj) {
322
+ Object.defineProperty(obj, key, {
323
+ value: value,
324
+ enumerable: true,
325
+ configurable: true,
326
+ writable: true
327
+ });
328
+ } else {
329
+ obj[key] = value;
330
+ }
331
+ return obj;
332
+ }
333
+ function _object_spread$2(target) {
334
+ for(var i = 1; i < arguments.length; i++){
335
+ var source = arguments[i] != null ? arguments[i] : {};
336
+ var ownKeys = Object.keys(source);
337
+ if (typeof Object.getOwnPropertySymbols === "function") {
338
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
339
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
340
+ }));
341
+ }
342
+ ownKeys.forEach(function(key) {
343
+ _define_property$3(target, key, source[key]);
344
+ });
345
+ }
346
+ return target;
347
+ }
348
+ function _tagged_template_literal$1(strings, raw) {
349
+ if (!raw) {
350
+ raw = strings.slice(0);
351
+ }
352
+ return Object.freeze(Object.defineProperties(strings, {
353
+ raw: {
354
+ value: Object.freeze(raw)
355
+ }
356
+ }));
357
+ }
358
+ function _templateObject$1() {
359
+ var data = _tagged_template_literal$1([
360
+ "{bold {greenBright [ ",
361
+ " ]} {greenBright Manifest Link:} {cyan ",
362
+ "",
363
+ "}}"
364
+ ]);
365
+ _templateObject$1 = function _templateObject() {
366
+ return data;
367
+ };
368
+ return data;
369
+ }
370
+ var ManifestManager = /*#__PURE__*/ function() {
371
+ function ManifestManager() {
372
+ _class_call_check$3(this, ManifestManager);
373
+ _define_property$3(this, "_options", {});
374
+ _define_property$3(this, "_manifest", void 0);
375
+ }
376
+ _create_class$3(ManifestManager, [
377
+ {
378
+ key: "manifest",
379
+ get: function get() {
380
+ return this._manifest;
381
+ }
382
+ },
383
+ {
384
+ key: "init",
385
+ value: function init(options) {
386
+ this._options = options;
387
+ }
388
+ },
389
+ {
390
+ key: "generateManifest",
391
+ value: function generateManifest(options) {
392
+ var compilation = options.compilation, publicPath = options.publicPath, stats = options.stats, compiler = options.compiler;
393
+ var _this__options = this._options, tmp = _this__options.manifest, manifestOptions = tmp === void 0 ? {} : tmp;
394
+ var manifest = _object_spread$2({}, stats);
395
+ manifest.exposes = Object.keys(stats.exposes).reduce(function(sum, cur) {
396
+ var statsExpose = manifest.exposes[cur];
397
+ var expose = {
398
+ id: statsExpose.id,
399
+ name: statsExpose.name,
400
+ assets: statsExpose.assets,
401
+ path: statsExpose.path
402
+ };
403
+ sum.push(expose);
404
+ return sum;
405
+ }, []);
406
+ manifest.shared = Object.keys(stats.shared).reduce(function(sum, cur) {
407
+ var statsShared = manifest.shared[cur];
408
+ var shared = {
409
+ id: statsShared.id,
410
+ name: statsShared.name,
411
+ version: statsShared.version,
412
+ singleton: statsShared.singleton,
413
+ requiredVersion: statsShared.requiredVersion,
414
+ hash: statsShared.hash,
415
+ assets: statsShared.assets
416
+ };
417
+ sum.push(shared);
418
+ return sum;
419
+ }, []);
420
+ manifest.remotes = Object.keys(stats.remotes).reduce(function(sum, cur) {
421
+ var statsRemote = manifest.remotes[cur];
422
+ // @ts-ignore version/entry will be added as follow
423
+ var remote = {
424
+ federationContainerName: statsRemote.federationContainerName,
425
+ moduleName: statsRemote.moduleName,
426
+ alias: statsRemote.alias
427
+ };
428
+ if ("entry" in statsRemote) {
429
+ // @ts-ignore
430
+ remote.entry = statsRemote.entry;
431
+ } else if ("version" in statsRemote) {
432
+ // @ts-ignore
433
+ remote.entry = statsRemote.version;
434
+ }
435
+ sum.push(remote);
436
+ return sum;
437
+ }, []);
438
+ this._manifest = manifest;
439
+ var manifestFilePath = typeof manifestOptions === "boolean" ? "" : manifestOptions.filePath || "";
440
+ var manifestFileName = sdk.simpleJoinRemoteEntry(manifestFilePath, sdk.ManifestFileName);
441
+ compilation.emitAsset(manifestFileName, new compiler.webpack.sources.RawSource(JSON.stringify(manifest, null, 2)));
442
+ if (isDev()) {
443
+ console.log(chalk__default["default"](_templateObject$1(), PLUGIN_IDENTIFIER, publicPath, manifestFileName));
444
+ }
445
+ }
446
+ }
447
+ ]);
448
+ return ManifestManager;
449
+ }();
450
+
451
+ function _array_like_to_array$1(arr, len) {
452
+ if (len == null || len > arr.length) len = arr.length;
453
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
454
+ return arr2;
455
+ }
456
+ function _array_with_holes$1(arr) {
457
+ if (Array.isArray(arr)) return arr;
458
+ }
459
+ function _class_call_check$2(instance, Constructor) {
460
+ if (!(instance instanceof Constructor)) {
461
+ throw new TypeError("Cannot call a class as a function");
462
+ }
463
+ }
464
+ function _defineProperties$2(target, props) {
465
+ for(var i = 0; i < props.length; i++){
466
+ var descriptor = props[i];
467
+ descriptor.enumerable = descriptor.enumerable || false;
468
+ descriptor.configurable = true;
469
+ if ("value" in descriptor) descriptor.writable = true;
470
+ Object.defineProperty(target, descriptor.key, descriptor);
471
+ }
472
+ }
473
+ function _create_class$2(Constructor, protoProps, staticProps) {
474
+ if (protoProps) _defineProperties$2(Constructor.prototype, protoProps);
475
+ if (staticProps) _defineProperties$2(Constructor, staticProps);
476
+ return Constructor;
477
+ }
478
+ function _define_property$2(obj, key, value) {
479
+ if (key in obj) {
480
+ Object.defineProperty(obj, key, {
481
+ value: value,
482
+ enumerable: true,
483
+ configurable: true,
484
+ writable: true
485
+ });
486
+ } else {
487
+ obj[key] = value;
488
+ }
489
+ return obj;
490
+ }
491
+ function _iterable_to_array_limit$1(arr, i) {
492
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
493
+ if (_i == null) return;
494
+ var _arr = [];
495
+ var _n = true;
496
+ var _d = false;
497
+ var _s, _e;
498
+ try {
499
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
500
+ _arr.push(_s.value);
501
+ if (i && _arr.length === i) break;
502
+ }
503
+ } catch (err) {
504
+ _d = true;
505
+ _e = err;
506
+ } finally{
507
+ try {
508
+ if (!_n && _i["return"] != null) _i["return"]();
509
+ } finally{
510
+ if (_d) throw _e;
511
+ }
512
+ }
513
+ return _arr;
514
+ }
515
+ function _non_iterable_rest$1() {
516
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
517
+ }
518
+ function _object_spread$1(target) {
519
+ for(var i = 1; i < arguments.length; i++){
520
+ var source = arguments[i] != null ? arguments[i] : {};
521
+ var ownKeys = Object.keys(source);
522
+ if (typeof Object.getOwnPropertySymbols === "function") {
523
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
524
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
525
+ }));
526
+ }
527
+ ownKeys.forEach(function(key) {
528
+ _define_property$2(target, key, source[key]);
529
+ });
530
+ }
531
+ return target;
532
+ }
533
+ function ownKeys$1(object, enumerableOnly) {
534
+ var keys = Object.keys(object);
535
+ if (Object.getOwnPropertySymbols) {
536
+ var symbols = Object.getOwnPropertySymbols(object);
537
+ if (enumerableOnly) {
538
+ symbols = symbols.filter(function(sym) {
539
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
540
+ });
541
+ }
542
+ keys.push.apply(keys, symbols);
543
+ }
544
+ return keys;
545
+ }
546
+ function _object_spread_props$1(target, source) {
547
+ source = source != null ? source : {};
548
+ if (Object.getOwnPropertyDescriptors) {
549
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
550
+ } else {
551
+ ownKeys$1(Object(source)).forEach(function(key) {
552
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
553
+ });
554
+ }
555
+ return target;
556
+ }
557
+ function _sliced_to_array$1(arr, i) {
558
+ return _array_with_holes$1(arr) || _iterable_to_array_limit$1(arr, i) || _unsupported_iterable_to_array$1(arr, i) || _non_iterable_rest$1();
559
+ }
560
+ function _unsupported_iterable_to_array$1(o, minLen) {
561
+ if (!o) return;
562
+ if (typeof o === "string") return _array_like_to_array$1(o, minLen);
563
+ var n = Object.prototype.toString.call(o).slice(8, -1);
564
+ if (n === "Object" && o.constructor) n = o.constructor.name;
565
+ if (n === "Map" || n === "Set") return Array.from(n);
566
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$1(o, minLen);
567
+ }
568
+ var ModuleHandler = /*#__PURE__*/ function() {
569
+ function ModuleHandler(options, modules, param) {
570
+ var bundler = param.bundler;
571
+ _class_call_check$2(this, ModuleHandler);
572
+ _define_property$2(this, "_options", void 0);
573
+ _define_property$2(this, "_bundler", "webpack");
574
+ _define_property$2(this, "_modules", void 0);
575
+ _define_property$2(this, "_remoteManager", new managers.RemoteManager());
576
+ _define_property$2(this, "_sharedManager", new managers.SharedManager());
577
+ this._options = options;
578
+ this._modules = modules;
579
+ this._bundler = bundler;
580
+ this._remoteManager = new managers.RemoteManager();
581
+ this._remoteManager.init(options);
582
+ this._sharedManager = new managers.SharedManager();
583
+ this._sharedManager.init(options);
584
+ }
585
+ _create_class$2(ModuleHandler, [
586
+ {
587
+ key: "isRspack",
588
+ get: function get() {
589
+ return this._bundler === "rspack";
590
+ }
591
+ },
592
+ {
593
+ key: "_handleSharedModule",
594
+ value: function _handleSharedModule(mod, sharedMap, exposesMap) {
595
+ var _this = this;
596
+ var identifier = mod.identifier, moduleType = mod.moduleType;
597
+ if (!identifier) {
598
+ return;
599
+ }
600
+ var sharedManagerNormalizedOptions = this._sharedManager.normalizedOptions;
601
+ var initShared = function(pkgName, pkgVersion) {
602
+ if (sharedMap[pkgName]) {
603
+ return;
604
+ }
605
+ sharedMap[pkgName] = _object_spread_props$1(_object_spread$1({}, sharedManagerNormalizedOptions[pkgName]), {
606
+ id: "".concat(_this._options.name, ":").concat(pkgName),
607
+ name: pkgName,
608
+ version: pkgVersion,
609
+ assets: {
610
+ js: {
611
+ async: [],
612
+ sync: []
613
+ },
614
+ css: {
615
+ async: [],
616
+ sync: []
617
+ }
618
+ },
619
+ // @ts-ignore to deduplicate
620
+ usedIn: new Set()
621
+ });
622
+ };
623
+ var collectRelationshipMap = function(mod, pkgName) {
624
+ var issuerName = mod.issuerName, reasons = mod.reasons;
625
+ if (issuerName) {
626
+ if (exposesMap[getFileNameWithOutExt(issuerName)]) {
627
+ var expose = exposesMap[getFileNameWithOutExt(issuerName)];
628
+ // @ts-ignore use Set to deduplicate
629
+ expose.requires.add(pkgName);
630
+ // @ts-ignore use Set to deduplicate
631
+ sharedMap[pkgName].usedIn.add(expose.path);
632
+ }
633
+ }
634
+ if (reasons) {
635
+ reasons.forEach(function(param) {
636
+ var resolvedModule = param.resolvedModule, moduleName = param.moduleName;
637
+ var exposeModName = _this.isRspack ? moduleName : resolvedModule;
638
+ // filters out entrypoints
639
+ if (exposeModName) {
640
+ if (exposesMap[getFileNameWithOutExt(exposeModName)]) {
641
+ var expose = exposesMap[getFileNameWithOutExt(exposeModName)];
642
+ // @ts-ignore to deduplicate
643
+ expose.requires.add(pkgName);
644
+ // @ts-ignore to deduplicate
645
+ sharedMap[pkgName].usedIn.add(expose.path);
646
+ }
647
+ }
648
+ });
649
+ }
650
+ };
651
+ var parseResolvedIdentifier = function(nameAndVersion) {
652
+ var name1 = "";
653
+ var version = "";
654
+ if (nameAndVersion.startsWith("@")) {
655
+ var splitInfo = nameAndVersion.split("@");
656
+ splitInfo[0] = "@";
657
+ name1 = splitInfo[0] + splitInfo[1];
658
+ version = splitInfo[2];
659
+ } else if (nameAndVersion.includes("@")) {
660
+ var ref;
661
+ ref = _sliced_to_array$1(nameAndVersion.split("@"), 2), name1 = ref[0], version = ref[1];
662
+ version = version.replace(/[\^~>|>=]/g, "");
663
+ }
664
+ return {
665
+ name: name1,
666
+ version: version
667
+ };
668
+ };
669
+ if (moduleType === "provide-module") {
670
+ // identifier(rspack) = provide shared module (default) react@18.2.0 = /temp/node_modules/.pnpm/react@18.2.0/node_modules/react/index.js
671
+ // identifier(webpack) = provide module (default) react@18.2.0 = /temp/node_modules/.pnpm/react@18.2.0/node_modules/react/index.js
672
+ var data = identifier.split(" ");
673
+ var nameAndVersion = this.isRspack ? data[4] : data[3];
674
+ var _parseResolvedIdentifier = parseResolvedIdentifier(nameAndVersion), name1 = _parseResolvedIdentifier.name, version = _parseResolvedIdentifier.version;
675
+ if (name1 && version) {
676
+ initShared(name1, version);
677
+ collectRelationshipMap(mod, name1);
678
+ }
679
+ }
680
+ if (moduleType === "consume-shared-module") {
681
+ // identifier(rspack) = consume shared module (default) lodash/get@^4.17.21 (strict) (fallback: /temp/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/get.js)
682
+ // identifier(webpack) = consume-shared-module|default|react-dom|!=1.8...2...0|false|/temp/node_modules/.pnpm/react-dom@18.2.0_react@18.2.0/node_modules/react-dom/index.js|true|false
683
+ var SEPARATOR = this.isRspack ? " " : "|";
684
+ var data1 = identifier.split(SEPARATOR);
685
+ var pkgName = "";
686
+ var pkgVersion = "";
687
+ if (this.isRspack) {
688
+ var nameAndVersion1 = data1[4];
689
+ var res = parseResolvedIdentifier(nameAndVersion1);
690
+ pkgName = res.name;
691
+ pkgVersion = res.version;
692
+ } else {
693
+ var pkgName1 = data1[2];
694
+ var pkgVersionRange = data1[3];
695
+ if (pkgVersionRange.startsWith("=")) {
696
+ data1[3].replace("=", "");
697
+ } else {
698
+ if (sharedManagerNormalizedOptions[pkgName1]) {
699
+ sharedManagerNormalizedOptions[pkgName1].version;
700
+ } else {
701
+ var fullPkgName = pkgName1.split("/").slice(0, -1).join("/");
702
+ // pkgName: react-dom/
703
+ if (sharedManagerNormalizedOptions["".concat(fullPkgName, "/")]) {
704
+ if (sharedManagerNormalizedOptions[fullPkgName]) {
705
+ sharedManagerNormalizedOptions[fullPkgName].version;
706
+ } else {
707
+ sharedManagerNormalizedOptions["".concat(fullPkgName, "/")].version;
708
+ }
709
+ }
710
+ }
711
+ }
712
+ }
713
+ if (pkgName && pkgVersion) {
714
+ initShared(pkgName, pkgVersion);
715
+ collectRelationshipMap(mod, pkgName);
716
+ }
717
+ }
718
+ }
719
+ },
720
+ {
721
+ key: "_handleRemoteModule",
722
+ value: function _handleRemoteModule(mod, remotes, remotesConsumerMap) {
723
+ var _this = this;
724
+ var identifier = mod.identifier, reasons = mod.reasons, nameForCondition = mod.nameForCondition;
725
+ if (!identifier) {
726
+ return;
727
+ }
728
+ var remoteManagerNormalizedOptions = this._remoteManager.normalizedOptions;
729
+ // identifier = remote (default) webpack/container/reference/app2 ./Button
730
+ var data = identifier.split(" ");
731
+ if (data.length === 4) {
732
+ var moduleName = data[3].replace("./", "");
733
+ var remoteAlias = data[2].replace("webpack/container/reference/", "");
734
+ var normalizedRemote = remoteManagerNormalizedOptions[remoteAlias];
735
+ var basicRemote = {
736
+ alias: normalizedRemote.alias,
737
+ consumingGarfishModuleName: name,
738
+ garfishModuleName: remoteManagerNormalizedOptions[remoteAlias].name,
739
+ moduleName: moduleName,
740
+ // @ts-ignore to deduplicate
741
+ usedIn: new Set()
742
+ };
743
+ if (!nameForCondition) {
744
+ return;
745
+ }
746
+ var remote;
747
+ if ("version" in normalizedRemote) {
748
+ remote = _object_spread_props$1(_object_spread$1({}, basicRemote), {
749
+ version: normalizedRemote.version
750
+ });
751
+ } else {
752
+ remote = _object_spread_props$1(_object_spread$1({}, basicRemote), {
753
+ entry: normalizedRemote.entry
754
+ });
755
+ }
756
+ remotes.push(remote);
757
+ remotesConsumerMap[nameForCondition] = remote;
758
+ }
759
+ if (reasons) {
760
+ reasons.forEach(function(param) {
761
+ var userRequest = param.userRequest, resolvedModule = param.resolvedModule, moduleName = param.moduleName;
762
+ var exposeModName = _this.isRspack ? moduleName : resolvedModule;
763
+ if (userRequest && exposeModName && remotesConsumerMap[userRequest]) {
764
+ // @ts-ignore to deduplicate
765
+ remotesConsumerMap[userRequest].usedIn.add(exposeModName.replace("./", ""));
766
+ }
767
+ });
768
+ }
769
+ }
770
+ },
771
+ {
772
+ key: "_handleContainerModule",
773
+ value: function _handleContainerModule(mod, exposesMap) {
774
+ var _this = this;
775
+ var identifier = mod.identifier;
776
+ if (!identifier) {
777
+ return;
778
+ }
779
+ // identifier: container entry (default) [[".",{"import":["./src/routes/page.tsx"],"name":"__federation_expose_default_export"}]]'
780
+ var data = identifier.split(" ");
781
+ JSON.parse(data[3]).forEach(function(param) {
782
+ var _param = _sliced_to_array$1(param, 2), prefixedName = _param[0], file = _param[1];
783
+ var exposeModuleName = prefixedName.replace("./", "");
784
+ // TODO: support multiple import
785
+ exposesMap[getFileNameWithOutExt(file.import[0])] = {
786
+ path: prefixedName,
787
+ id: "".concat(_this._options.name, ":").concat(exposeModuleName),
788
+ name: exposeModuleName,
789
+ // @ts-ignore to deduplicate
790
+ requires: new Set(),
791
+ file: path__default["default"].relative(process.cwd(), file.import[0]),
792
+ assets: {
793
+ js: {
794
+ async: [],
795
+ sync: []
796
+ },
797
+ css: {
798
+ async: [],
799
+ sync: []
800
+ }
801
+ }
802
+ };
803
+ });
804
+ }
805
+ },
806
+ {
807
+ key: "collect",
808
+ value: function collect() {
809
+ var _this = this;
810
+ var remotes = [];
811
+ var remotesConsumerMap = {};
812
+ var exposesMap = {};
813
+ var sharedMap = {};
814
+ var isSharedModule = function(moduleType) {
815
+ return Boolean(moduleType && [
816
+ "provide-module",
817
+ "consume-shared-module"
818
+ ].includes(moduleType));
819
+ };
820
+ var isContainerModule = function(identifier) {
821
+ var data = identifier.split(" ");
822
+ return Boolean(data[0] === "container" && data[1] === "entry");
823
+ };
824
+ var isRemoteModule = function(identifier) {
825
+ var data = identifier.split(" ");
826
+ return data[0] === "remote";
827
+ };
828
+ // handle remote/expose
829
+ this._modules.forEach(function(mod) {
830
+ var identifier = mod.identifier; mod.reasons; mod.nameForCondition; var moduleType = mod.moduleType;
831
+ if (!identifier) {
832
+ return;
833
+ }
834
+ if (isSharedModule(moduleType)) {
835
+ _this._handleSharedModule(mod, sharedMap, exposesMap);
836
+ }
837
+ if (isRemoteModule(identifier)) {
838
+ _this._handleRemoteModule(mod, remotes, remotesConsumerMap);
839
+ } else if (isContainerModule(identifier)) {
840
+ _this._handleContainerModule(mod, exposesMap);
841
+ }
842
+ });
843
+ return {
844
+ remotes: remotes,
845
+ exposesMap: exposesMap,
846
+ sharedMap: sharedMap
847
+ };
848
+ }
849
+ }
850
+ ]);
851
+ return ModuleHandler;
852
+ }();
853
+
854
+ /* eslint-disable max-lines-per-function */ /* eslint-disable @typescript-eslint/member-ordering */ /* eslint-disable max-depth */ function _array_like_to_array(arr, len) {
855
+ if (len == null || len > arr.length) len = arr.length;
856
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
857
+ return arr2;
858
+ }
859
+ function _array_with_holes(arr) {
860
+ if (Array.isArray(arr)) return arr;
861
+ }
862
+ function _array_without_holes(arr) {
863
+ if (Array.isArray(arr)) return _array_like_to_array(arr);
864
+ }
865
+ function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
866
+ try {
867
+ var info = gen[key](arg);
868
+ var value = info.value;
869
+ } catch (error) {
870
+ reject(error);
871
+ return;
872
+ }
873
+ if (info.done) {
874
+ resolve(value);
875
+ } else {
876
+ Promise.resolve(value).then(_next, _throw);
877
+ }
878
+ }
879
+ function _async_to_generator$1(fn) {
880
+ return function() {
881
+ var self = this, args = arguments;
882
+ return new Promise(function(resolve, reject) {
883
+ var gen = fn.apply(self, args);
884
+ function _next(value) {
885
+ asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "next", value);
886
+ }
887
+ function _throw(err) {
888
+ asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "throw", err);
889
+ }
890
+ _next(undefined);
891
+ });
892
+ };
893
+ }
894
+ function _class_call_check$1(instance, Constructor) {
895
+ if (!(instance instanceof Constructor)) {
896
+ throw new TypeError("Cannot call a class as a function");
897
+ }
898
+ }
899
+ function _defineProperties$1(target, props) {
900
+ for(var i = 0; i < props.length; i++){
901
+ var descriptor = props[i];
902
+ descriptor.enumerable = descriptor.enumerable || false;
903
+ descriptor.configurable = true;
904
+ if ("value" in descriptor) descriptor.writable = true;
905
+ Object.defineProperty(target, descriptor.key, descriptor);
906
+ }
907
+ }
908
+ function _create_class$1(Constructor, protoProps, staticProps) {
909
+ if (protoProps) _defineProperties$1(Constructor.prototype, protoProps);
910
+ if (staticProps) _defineProperties$1(Constructor, staticProps);
911
+ return Constructor;
912
+ }
913
+ function _define_property$1(obj, key, value) {
914
+ if (key in obj) {
915
+ Object.defineProperty(obj, key, {
916
+ value: value,
917
+ enumerable: true,
918
+ configurable: true,
919
+ writable: true
920
+ });
921
+ } else {
922
+ obj[key] = value;
923
+ }
924
+ return obj;
925
+ }
926
+ function _iterable_to_array(iter) {
927
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
928
+ }
929
+ function _iterable_to_array_limit(arr, i) {
930
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
931
+ if (_i == null) return;
932
+ var _arr = [];
933
+ var _n = true;
934
+ var _d = false;
935
+ var _s, _e;
936
+ try {
937
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
938
+ _arr.push(_s.value);
939
+ if (i && _arr.length === i) break;
940
+ }
941
+ } catch (err) {
942
+ _d = true;
943
+ _e = err;
944
+ } finally{
945
+ try {
946
+ if (!_n && _i["return"] != null) _i["return"]();
947
+ } finally{
948
+ if (_d) throw _e;
949
+ }
950
+ }
951
+ return _arr;
952
+ }
953
+ function _non_iterable_rest() {
954
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
955
+ }
956
+ function _non_iterable_spread() {
957
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
958
+ }
959
+ function _object_spread(target) {
960
+ for(var i = 1; i < arguments.length; i++){
961
+ var source = arguments[i] != null ? arguments[i] : {};
962
+ var ownKeys = Object.keys(source);
963
+ if (typeof Object.getOwnPropertySymbols === "function") {
964
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
965
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
966
+ }));
967
+ }
968
+ ownKeys.forEach(function(key) {
969
+ _define_property$1(target, key, source[key]);
970
+ });
971
+ }
972
+ return target;
973
+ }
974
+ function ownKeys(object, enumerableOnly) {
975
+ var keys = Object.keys(object);
976
+ if (Object.getOwnPropertySymbols) {
977
+ var symbols = Object.getOwnPropertySymbols(object);
978
+ if (enumerableOnly) {
979
+ symbols = symbols.filter(function(sym) {
980
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
981
+ });
982
+ }
983
+ keys.push.apply(keys, symbols);
984
+ }
985
+ return keys;
986
+ }
987
+ function _object_spread_props(target, source) {
988
+ source = source != null ? source : {};
989
+ if (Object.getOwnPropertyDescriptors) {
990
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
991
+ } else {
992
+ ownKeys(Object(source)).forEach(function(key) {
993
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
994
+ });
995
+ }
996
+ return target;
997
+ }
998
+ function _sliced_to_array(arr, i) {
999
+ return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
1000
+ }
1001
+ function _tagged_template_literal(strings, raw) {
1002
+ if (!raw) {
1003
+ raw = strings.slice(0);
1004
+ }
1005
+ return Object.freeze(Object.defineProperties(strings, {
1006
+ raw: {
1007
+ value: Object.freeze(raw)
1008
+ }
1009
+ }));
1010
+ }
1011
+ function _to_consumable_array(arr) {
1012
+ return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
1013
+ }
1014
+ function _unsupported_iterable_to_array(o, minLen) {
1015
+ if (!o) return;
1016
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
1017
+ var n = Object.prototype.toString.call(o).slice(8, -1);
1018
+ if (n === "Object" && o.constructor) n = o.constructor.name;
1019
+ if (n === "Map" || n === "Set") return Array.from(n);
1020
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
1021
+ }
1022
+ function _ts_generator$1(thisArg, body) {
1023
+ var f, y, t, g, _ = {
1024
+ label: 0,
1025
+ sent: function() {
1026
+ if (t[0] & 1) throw t[1];
1027
+ return t[1];
1028
+ },
1029
+ trys: [],
1030
+ ops: []
1031
+ };
1032
+ return g = {
1033
+ next: verb(0),
1034
+ "throw": verb(1),
1035
+ "return": verb(2)
1036
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
1037
+ return this;
1038
+ }), g;
1039
+ function verb(n) {
1040
+ return function(v) {
1041
+ return step([
1042
+ n,
1043
+ v
1044
+ ]);
1045
+ };
1046
+ }
1047
+ function step(op) {
1048
+ if (f) throw new TypeError("Generator is already executing.");
1049
+ while(_)try {
1050
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
1051
+ if (y = 0, t) op = [
1052
+ op[0] & 2,
1053
+ t.value
1054
+ ];
1055
+ switch(op[0]){
1056
+ case 0:
1057
+ case 1:
1058
+ t = op;
1059
+ break;
1060
+ case 4:
1061
+ _.label++;
1062
+ return {
1063
+ value: op[1],
1064
+ done: false
1065
+ };
1066
+ case 5:
1067
+ _.label++;
1068
+ y = op[1];
1069
+ op = [
1070
+ 0
1071
+ ];
1072
+ continue;
1073
+ case 7:
1074
+ op = _.ops.pop();
1075
+ _.trys.pop();
1076
+ continue;
1077
+ default:
1078
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
1079
+ _ = 0;
1080
+ continue;
1081
+ }
1082
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
1083
+ _.label = op[1];
1084
+ break;
1085
+ }
1086
+ if (op[0] === 6 && _.label < t[1]) {
1087
+ _.label = t[1];
1088
+ t = op;
1089
+ break;
1090
+ }
1091
+ if (t && _.label < t[2]) {
1092
+ _.label = t[2];
1093
+ _.ops.push(op);
1094
+ break;
1095
+ }
1096
+ if (t[2]) _.ops.pop();
1097
+ _.trys.pop();
1098
+ continue;
1099
+ }
1100
+ op = body.call(thisArg, _);
1101
+ } catch (e) {
1102
+ op = [
1103
+ 6,
1104
+ e
1105
+ ];
1106
+ y = 0;
1107
+ } finally{
1108
+ f = t = 0;
1109
+ }
1110
+ if (op[0] & 5) throw op[1];
1111
+ return {
1112
+ value: op[0] ? op[1] : void 0,
1113
+ done: true
1114
+ };
1115
+ }
1116
+ }
1117
+ function _templateObject() {
1118
+ var data = _tagged_template_literal([
1119
+ "{bold {red [ ",
1120
+ " ]: PublicPath can only be string, but got ",
1121
+ "}}"
1122
+ ]);
1123
+ _templateObject = function _templateObject() {
1124
+ return data;
1125
+ };
1126
+ return data;
1127
+ }
1128
+ var StatsManager = /*#__PURE__*/ function() {
1129
+ function StatsManager() {
1130
+ _class_call_check$1(this, StatsManager);
1131
+ _define_property$1(this, "_options", {});
1132
+ _define_property$1(this, "_publicPath", void 0);
1133
+ _define_property$1(this, "_pluginVersion", void 0);
1134
+ _define_property$1(this, "_bundler", "webpack");
1135
+ _define_property$1(this, "_containerManager", new managers.ContainerManager());
1136
+ _define_property$1(this, "_remoteManager", new managers.RemoteManager());
1137
+ _define_property$1(this, "_sharedManager", new managers.SharedManager());
1138
+ _define_property$1(this, "_pkgJsonManager", new managers.PKGJsonManager());
1139
+ }
1140
+ _create_class$1(StatsManager, [
1141
+ {
1142
+ key: "buildInfo",
1143
+ get: function get() {
1144
+ this._pkgJsonManager.getExposeGarfishModuleType();
1145
+ var pkg = this._pkgJsonManager.readPKGJson(process.cwd());
1146
+ return {
1147
+ buildVersion: managers.utils.getBuildVersion(),
1148
+ buildName: managers.utils.getBuildName() || pkg["name"]
1149
+ };
1150
+ }
1151
+ },
1152
+ {
1153
+ key: "_getMetaData",
1154
+ value: function _getMetaData(compiler, compilation, extraOptions) {
1155
+ var _this = this;
1156
+ var context = compiler.options.context;
1157
+ var _this1 = this, name = _this1._options.name, buildInfo = _this1.buildInfo;
1158
+ var type = this._pkgJsonManager.getExposeGarfishModuleType(context || process.cwd());
1159
+ var getRemoteEntryName = function() {
1160
+ if (!_this._containerManager.enable) {
1161
+ return "";
1162
+ }
1163
+ assert(name, "name is required");
1164
+ var remoteEntryPoint = compilation.entrypoints.get(name);
1165
+ assert(remoteEntryPoint, "Can not get remoteEntry entryPoint!");
1166
+ var remoteEntryNameChunk = compilation.namedChunks.get(name);
1167
+ assert(remoteEntryNameChunk, "Can not get remoteEntry chunk!");
1168
+ debugger;
1169
+ assert(Array.from(remoteEntryNameChunk.files).length === 1, "remoteEntry chunk should not have multiple files!");
1170
+ var remoteEntryName = _to_consumable_array(remoteEntryNameChunk.files)[0];
1171
+ return remoteEntryName;
1172
+ };
1173
+ var globalName = this._containerManager.globalEntryName;
1174
+ assert(globalName, 'Can not get library.name, please ensure you have set library.name and the type is "string" !');
1175
+ assert(this._pluginVersion, "Can not get pluginVersion, please ensure you have set pluginVersion !");
1176
+ var metaData = {
1177
+ name: name,
1178
+ type: type,
1179
+ buildInfo: buildInfo,
1180
+ remoteEntry: {
1181
+ name: getRemoteEntryName(),
1182
+ path: "",
1183
+ type: "global"
1184
+ },
1185
+ types: {
1186
+ name: "",
1187
+ path: ""
1188
+ },
1189
+ globalName: globalName,
1190
+ pluginVersion: this._pluginVersion
1191
+ };
1192
+ return _object_spread_props(_object_spread({}, metaData), {
1193
+ publicPath: this.getPublicPath(compiler)
1194
+ });
1195
+ }
1196
+ },
1197
+ {
1198
+ key: "_getFilteredModules",
1199
+ value: function _getFilteredModules(stats) {
1200
+ var filteredModules = stats.modules.filter(function(module) {
1201
+ if (!module || !module.name) {
1202
+ return false;
1203
+ }
1204
+ var array = [
1205
+ module.name.includes("container entry"),
1206
+ module.name.includes("remote "),
1207
+ module.name.includes("shared module "),
1208
+ module.name.includes("provide module ")
1209
+ ];
1210
+ return array.some(function(item) {
1211
+ return item;
1212
+ });
1213
+ });
1214
+ return filteredModules;
1215
+ }
1216
+ },
1217
+ {
1218
+ key: "_getModuleAssets",
1219
+ value: function _getModuleAssets(compilation) {
1220
+ var chunks = compilation.chunks;
1221
+ var exposeFileNameImportMap = this._containerManager.exposeFileNameImportMap;
1222
+ var assets = {};
1223
+ chunks.forEach(function(chunk) {
1224
+ if (typeof chunk.name === "string" && exposeFileNameImportMap[chunk.name]) {
1225
+ var exposeKey = exposeFileNameImportMap[chunk.name];
1226
+ assets[exposeKey] = getAssetsByChunk(chunk);
1227
+ }
1228
+ });
1229
+ return assets;
1230
+ }
1231
+ },
1232
+ {
1233
+ key: "_getProvideSharedAssets",
1234
+ value: function _getProvideSharedAssets(compilation, stats) {
1235
+ var sharedModules = stats.modules.filter(function(module) {
1236
+ if (!module || !module.name) {
1237
+ return false;
1238
+ }
1239
+ var array = [
1240
+ module.name.includes("consume shared module ")
1241
+ ];
1242
+ return array.some(function(item) {
1243
+ return item;
1244
+ });
1245
+ });
1246
+ var manifestOverrideChunkIDMap = {};
1247
+ var effectiveSharedModules = getSharedModules(stats, sharedModules);
1248
+ effectiveSharedModules.forEach(function(item) {
1249
+ var _item = _sliced_to_array(item, 2), sharedModuleName = _item[0], sharedModule = _item[1];
1250
+ if (!manifestOverrideChunkIDMap[sharedModuleName]) {
1251
+ manifestOverrideChunkIDMap[sharedModuleName] = {
1252
+ async: new Set(),
1253
+ sync: new Set()
1254
+ };
1255
+ }
1256
+ sharedModule.chunks.forEach(function(chunkID) {
1257
+ var chunk = findChunk(chunkID, compilation.chunks);
1258
+ manifestOverrideChunkIDMap[sharedModuleName].sync.add(chunkID);
1259
+ Array.from(chunk.getAllInitialChunks()).forEach(function(syncChunk) {
1260
+ syncChunk.id && manifestOverrideChunkIDMap[sharedModuleName].sync.add(syncChunk.id);
1261
+ });
1262
+ Array.from(chunk.getAllAsyncChunks()).forEach(function(asyncChunk) {
1263
+ asyncChunk.id && manifestOverrideChunkIDMap[sharedModuleName].async.add(asyncChunk.id);
1264
+ });
1265
+ });
1266
+ });
1267
+ var assets = {
1268
+ js: {
1269
+ async: [],
1270
+ sync: []
1271
+ },
1272
+ css: {
1273
+ async: [],
1274
+ sync: []
1275
+ }
1276
+ };
1277
+ Object.keys(manifestOverrideChunkIDMap).forEach(function(override) {
1278
+ var asyncAssets = getAssetsByChunkIDs(compilation, _define_property$1({}, override, manifestOverrideChunkIDMap[override].async));
1279
+ var syncAssets = getAssetsByChunkIDs(compilation, _define_property$1({}, override, manifestOverrideChunkIDMap[override].sync));
1280
+ assets[override] = {
1281
+ js: {
1282
+ async: asyncAssets[override].js,
1283
+ sync: syncAssets[override].js
1284
+ },
1285
+ css: {
1286
+ async: asyncAssets[override].css,
1287
+ sync: syncAssets[override].css
1288
+ }
1289
+ };
1290
+ });
1291
+ return assets;
1292
+ }
1293
+ },
1294
+ {
1295
+ key: "_generateStats",
1296
+ value: function _generateStats(compiler, compilation, extraOptions) {
1297
+ var _this = this;
1298
+ return _async_to_generator$1(function() {
1299
+ var _this__options, name, tmp, manifestOptions, metaData, stats, remotes, liveStats, webpackStats, filteredModules, moduleHandler, _moduleHandler_collect, remotes1, exposesMap, sharedMap, err;
1300
+ return _ts_generator$1(this, function(_state) {
1301
+ switch(_state.label){
1302
+ case 0:
1303
+ _state.trys.push([
1304
+ 0,
1305
+ 3,
1306
+ ,
1307
+ 4
1308
+ ]);
1309
+ _this__options = _this._options, name = _this__options.name, tmp = _this__options.manifest, manifestOptions = tmp === void 0 ? {} : tmp;
1310
+ metaData = _this._getMetaData(compiler, compilation, extraOptions);
1311
+ stats = {
1312
+ id: name,
1313
+ name: name,
1314
+ metaData: metaData,
1315
+ shared: [],
1316
+ remotes: [],
1317
+ exposes: []
1318
+ };
1319
+ if (typeof manifestOptions === "object" && manifestOptions.disableAssetsAnalyze) {
1320
+ remotes = _this._remoteManager.statsRemoteWithEmptyUsedIn;
1321
+ stats.remotes = remotes;
1322
+ return [
1323
+ 2,
1324
+ stats
1325
+ ];
1326
+ }
1327
+ liveStats = compilation.getStats();
1328
+ webpackStats = liveStats.toJson({
1329
+ all: false,
1330
+ modules: true,
1331
+ builtAt: true,
1332
+ hash: true,
1333
+ ids: true,
1334
+ version: true,
1335
+ entrypoints: true,
1336
+ assets: false,
1337
+ chunks: false,
1338
+ reasons: true
1339
+ });
1340
+ filteredModules = _this._getFilteredModules(webpackStats);
1341
+ moduleHandler = new ModuleHandler(_this._options, filteredModules, {
1342
+ bundler: _this._bundler
1343
+ });
1344
+ _moduleHandler_collect = moduleHandler.collect(), remotes1 = _moduleHandler_collect.remotes, exposesMap = _moduleHandler_collect.exposesMap, sharedMap = _moduleHandler_collect.sharedMap;
1345
+ return [
1346
+ 4,
1347
+ Promise.all([
1348
+ new Promise(function(resolve) {
1349
+ var sharedAssets = _this._getProvideSharedAssets(compilation, webpackStats);
1350
+ Object.keys(sharedMap).forEach(function(sharedKey) {
1351
+ var assets = sharedAssets[sharedKey];
1352
+ if (assets) {
1353
+ sharedMap[sharedKey].assets = assets;
1354
+ }
1355
+ });
1356
+ resolve();
1357
+ }),
1358
+ new Promise(function(resolve) {
1359
+ var moduleAssets = _this._getModuleAssets(compilation);
1360
+ Object.keys(exposesMap).forEach(function(exposeKey) {
1361
+ var assets = moduleAssets[exposeKey];
1362
+ if (assets) {
1363
+ exposesMap[exposeKey].assets = assets;
1364
+ }
1365
+ exposesMap[exposeKey].requires = Array.from(exposesMap[exposeKey].requires);
1366
+ });
1367
+ resolve();
1368
+ })
1369
+ ])
1370
+ ];
1371
+ case 1:
1372
+ _state.sent();
1373
+ return [
1374
+ 4,
1375
+ Promise.all([
1376
+ new Promise(function(resolve) {
1377
+ stats.remotes = remotes1.map(function(remote) {
1378
+ return _object_spread_props(_object_spread({}, remote), {
1379
+ usedIn: Array.from(remote.usedIn.values())
1380
+ });
1381
+ });
1382
+ resolve();
1383
+ }),
1384
+ new Promise(function(resolve) {
1385
+ stats.shared = Object.values(sharedMap).map(function(shared) {
1386
+ return _object_spread_props(_object_spread({}, shared), {
1387
+ usedIn: Array.from(shared.usedIn)
1388
+ });
1389
+ });
1390
+ resolve();
1391
+ }),
1392
+ new Promise(function(resolve) {
1393
+ stats.exposes = Object.values(exposesMap).map(function(expose) {
1394
+ return _object_spread({}, expose);
1395
+ });
1396
+ resolve();
1397
+ })
1398
+ ])
1399
+ ];
1400
+ case 2:
1401
+ _state.sent();
1402
+ return [
1403
+ 2,
1404
+ stats
1405
+ ];
1406
+ case 3:
1407
+ err = _state.sent();
1408
+ throw err;
1409
+ case 4:
1410
+ return [
1411
+ 2
1412
+ ];
1413
+ }
1414
+ });
1415
+ })();
1416
+ }
1417
+ },
1418
+ {
1419
+ key: "getPublicPath",
1420
+ value: function getPublicPath(compiler) {
1421
+ if (this._publicPath) {
1422
+ return this._publicPath;
1423
+ }
1424
+ var _compiler_options = compiler.options, _compiler_options_output = _compiler_options.output, originalPublicPath = _compiler_options_output.publicPath;
1425
+ var publicPath = originalPublicPath;
1426
+ this._publicPath = publicPath;
1427
+ return publicPath;
1428
+ }
1429
+ },
1430
+ {
1431
+ key: "init",
1432
+ value: function init(options, param) {
1433
+ var pluginVersion = param.pluginVersion, bundler = param.bundler;
1434
+ this._options = options;
1435
+ this._pluginVersion = pluginVersion;
1436
+ this._bundler = bundler;
1437
+ this._containerManager = new managers.ContainerManager();
1438
+ this._containerManager.init(options);
1439
+ this._remoteManager = new managers.RemoteManager();
1440
+ this._remoteManager.init(options);
1441
+ this._sharedManager = new managers.SharedManager();
1442
+ this._sharedManager.init(options);
1443
+ }
1444
+ },
1445
+ {
1446
+ key: "generateStats",
1447
+ value: function generateStats(compiler, compilation, extraOptions) {
1448
+ var _this = this;
1449
+ return _async_to_generator$1(function() {
1450
+ var stats, _this__options, tmp, manifestOptions, statsFilePath, statsFileName, err;
1451
+ return _ts_generator$1(this, function(_state) {
1452
+ switch(_state.label){
1453
+ case 0:
1454
+ _state.trys.push([
1455
+ 0,
1456
+ 2,
1457
+ ,
1458
+ 3
1459
+ ]);
1460
+ return [
1461
+ 4,
1462
+ _this._generateStats(compiler, compilation)
1463
+ ];
1464
+ case 1:
1465
+ stats = _state.sent();
1466
+ _this__options = _this._options, tmp = _this__options.manifest, manifestOptions = tmp === void 0 ? {} : tmp;
1467
+ statsFilePath = typeof manifestOptions === "boolean" ? "" : manifestOptions.filePath || "";
1468
+ statsFileName = sdk.simpleJoinRemoteEntry(statsFilePath, sdk.StatsFileName);
1469
+ compilation.emitAsset(statsFileName, new compiler.webpack.sources.RawSource(JSON.stringify(stats, null, 2)));
1470
+ return [
1471
+ 2,
1472
+ stats
1473
+ ];
1474
+ case 2:
1475
+ err = _state.sent();
1476
+ throw err;
1477
+ case 3:
1478
+ return [
1479
+ 2
1480
+ ];
1481
+ }
1482
+ });
1483
+ })();
1484
+ }
1485
+ },
1486
+ {
1487
+ key: "validate",
1488
+ value: function validate(compiler) {
1489
+ var _compiler_options = compiler.options, publicPath = _compiler_options.output.publicPath;
1490
+ if (typeof publicPath !== "string") {
1491
+ console.error(chalk__default["default"](_templateObject(), PLUGIN_IDENTIFIER, publicPath));
1492
+ process.exit(1);
1493
+ }
1494
+ }
1495
+ }
1496
+ ]);
1497
+ return StatsManager;
1498
+ }();
1499
+
1500
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
1501
+ try {
1502
+ var info = gen[key](arg);
1503
+ var value = info.value;
1504
+ } catch (error) {
1505
+ reject(error);
1506
+ return;
1507
+ }
1508
+ if (info.done) {
1509
+ resolve(value);
1510
+ } else {
1511
+ Promise.resolve(value).then(_next, _throw);
1512
+ }
1513
+ }
1514
+ function _async_to_generator(fn) {
1515
+ return function() {
1516
+ var self = this, args = arguments;
1517
+ return new Promise(function(resolve, reject) {
1518
+ var gen = fn.apply(self, args);
1519
+ function _next(value) {
1520
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
1521
+ }
1522
+ function _throw(err) {
1523
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
1524
+ }
1525
+ _next(undefined);
1526
+ });
1527
+ };
1528
+ }
1529
+ function _class_call_check(instance, Constructor) {
1530
+ if (!(instance instanceof Constructor)) {
1531
+ throw new TypeError("Cannot call a class as a function");
1532
+ }
1533
+ }
1534
+ function _defineProperties(target, props) {
1535
+ for(var i = 0; i < props.length; i++){
1536
+ var descriptor = props[i];
1537
+ descriptor.enumerable = descriptor.enumerable || false;
1538
+ descriptor.configurable = true;
1539
+ if ("value" in descriptor) descriptor.writable = true;
1540
+ Object.defineProperty(target, descriptor.key, descriptor);
1541
+ }
1542
+ }
1543
+ function _create_class(Constructor, protoProps, staticProps) {
1544
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
1545
+ if (staticProps) _defineProperties(Constructor, staticProps);
1546
+ return Constructor;
1547
+ }
1548
+ function _define_property(obj, key, value) {
1549
+ if (key in obj) {
1550
+ Object.defineProperty(obj, key, {
1551
+ value: value,
1552
+ enumerable: true,
1553
+ configurable: true,
1554
+ writable: true
1555
+ });
1556
+ } else {
1557
+ obj[key] = value;
1558
+ }
1559
+ return obj;
1560
+ }
1561
+ function _ts_generator(thisArg, body) {
1562
+ var f, y, t, g, _ = {
1563
+ label: 0,
1564
+ sent: function() {
1565
+ if (t[0] & 1) throw t[1];
1566
+ return t[1];
1567
+ },
1568
+ trys: [],
1569
+ ops: []
1570
+ };
1571
+ return g = {
1572
+ next: verb(0),
1573
+ "throw": verb(1),
1574
+ "return": verb(2)
1575
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
1576
+ return this;
1577
+ }), g;
1578
+ function verb(n) {
1579
+ return function(v) {
1580
+ return step([
1581
+ n,
1582
+ v
1583
+ ]);
1584
+ };
1585
+ }
1586
+ function step(op) {
1587
+ if (f) throw new TypeError("Generator is already executing.");
1588
+ while(_)try {
1589
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
1590
+ if (y = 0, t) op = [
1591
+ op[0] & 2,
1592
+ t.value
1593
+ ];
1594
+ switch(op[0]){
1595
+ case 0:
1596
+ case 1:
1597
+ t = op;
1598
+ break;
1599
+ case 4:
1600
+ _.label++;
1601
+ return {
1602
+ value: op[1],
1603
+ done: false
1604
+ };
1605
+ case 5:
1606
+ _.label++;
1607
+ y = op[1];
1608
+ op = [
1609
+ 0
1610
+ ];
1611
+ continue;
1612
+ case 7:
1613
+ op = _.ops.pop();
1614
+ _.trys.pop();
1615
+ continue;
1616
+ default:
1617
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
1618
+ _ = 0;
1619
+ continue;
1620
+ }
1621
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
1622
+ _.label = op[1];
1623
+ break;
1624
+ }
1625
+ if (op[0] === 6 && _.label < t[1]) {
1626
+ _.label = t[1];
1627
+ t = op;
1628
+ break;
1629
+ }
1630
+ if (t && _.label < t[2]) {
1631
+ _.label = t[2];
1632
+ _.ops.push(op);
1633
+ break;
1634
+ }
1635
+ if (t[2]) _.ops.pop();
1636
+ _.trys.pop();
1637
+ continue;
1638
+ }
1639
+ op = body.call(thisArg, _);
1640
+ } catch (e) {
1641
+ op = [
1642
+ 6,
1643
+ e
1644
+ ];
1645
+ y = 0;
1646
+ } finally{
1647
+ f = t = 0;
1648
+ }
1649
+ if (op[0] & 5) throw op[1];
1650
+ return {
1651
+ value: op[0] ? op[1] : void 0,
1652
+ done: true
1653
+ };
1654
+ }
1655
+ }
1656
+ var StatsPlugin = /*#__PURE__*/ function() {
1657
+ function StatsPlugin(options, param) {
1658
+ var pluginVersion = param.pluginVersion, bundler = param.bundler;
1659
+ _class_call_check(this, StatsPlugin);
1660
+ _define_property(this, "name", "StatsPlugin");
1661
+ _define_property(this, "_options", void 0);
1662
+ _define_property(this, "_statsManager", void 0);
1663
+ _define_property(this, "_manifestManager", void 0);
1664
+ this._options = options;
1665
+ this._statsManager = new StatsManager();
1666
+ this._statsManager.init(this._options, {
1667
+ pluginVersion: pluginVersion,
1668
+ bundler: bundler
1669
+ });
1670
+ this._manifestManager = new ManifestManager();
1671
+ this._manifestManager.init(this._options);
1672
+ }
1673
+ _create_class(StatsPlugin, [
1674
+ {
1675
+ key: "apply",
1676
+ value: function apply(compiler) {
1677
+ var _this = this;
1678
+ this._statsManager.validate(compiler);
1679
+ compiler.hooks.thisCompilation.tap("generateStats", function(compilation) {
1680
+ var _this1 = _this;
1681
+ compilation.hooks.processAssets.tapPromise({
1682
+ name: "generateStats",
1683
+ // @ts-ignore use runtime variable in case peer dep not installed
1684
+ stage: compilation.constructor.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER
1685
+ }, /*#__PURE__*/ _async_to_generator(function() {
1686
+ var stats;
1687
+ return _ts_generator(this, function(_state) {
1688
+ switch(_state.label){
1689
+ case 0:
1690
+ if (!_this1._options.manifest) return [
1691
+ 3,
1692
+ 2
1693
+ ];
1694
+ return [
1695
+ 4,
1696
+ _this1._statsManager.generateStats(compiler, compilation)
1697
+ ];
1698
+ case 1:
1699
+ stats = _state.sent();
1700
+ _this1._manifestManager.generateManifest({
1701
+ compilation: compilation,
1702
+ stats: stats,
1703
+ publicPath: _this1._statsManager.getPublicPath(compiler),
1704
+ compiler: compiler
1705
+ });
1706
+ _state.label = 2;
1707
+ case 2:
1708
+ return [
1709
+ 2
1710
+ ];
1711
+ }
1712
+ });
1713
+ }));
1714
+ });
1715
+ }
1716
+ }
1717
+ ]);
1718
+ return StatsPlugin;
1719
+ }();
1720
+
1721
+ exports.ManifestManager = ManifestManager;
1722
+ exports.StatsManager = StatsManager;
1723
+ exports.StatsPlugin = StatsPlugin;