@module-federation/manifest 0.1.5 → 0.1.7

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