@module-federation/managers 0.2.3 → 0.2.5

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.
package/dist/index.cjs.js CHANGED
@@ -15,257 +15,72 @@ var finder__default = /*#__PURE__*/_interopDefaultLegacy(finder);
15
15
  var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
16
16
  var fs__default$1 = /*#__PURE__*/_interopDefaultLegacy(fs$1);
17
17
 
18
- function _class_call_check$4(instance, Constructor) {
19
- if (!(instance instanceof Constructor)) {
20
- throw new TypeError("Cannot call a class as a function");
18
+ class BasicPluginOptionsManager {
19
+ get enable() {
20
+ return Boolean(this._options);
21
21
  }
22
- }
23
- function _defineProperties$4(target, props) {
24
- for(var i = 0; i < props.length; i++){
25
- var descriptor = props[i];
26
- descriptor.enumerable = descriptor.enumerable || false;
27
- descriptor.configurable = true;
28
- if ("value" in descriptor) descriptor.writable = true;
29
- Object.defineProperty(target, descriptor.key, descriptor);
22
+ get options() {
23
+ return this._options;
30
24
  }
31
- }
32
- function _create_class$4(Constructor, protoProps, staticProps) {
33
- if (protoProps) _defineProperties$4(Constructor.prototype, protoProps);
34
- if (staticProps) _defineProperties$4(Constructor, staticProps);
35
- return Constructor;
36
- }
37
- function _define_property$4(obj, key, value) {
38
- if (key in obj) {
39
- Object.defineProperty(obj, key, {
40
- value: value,
41
- enumerable: true,
42
- configurable: true,
43
- writable: true
44
- });
45
- } else {
46
- obj[key] = value;
25
+ init(options, extraArgs) {
26
+ this._options = options;
27
+ }
28
+ setOptions(options) {
29
+ this._options = options;
47
30
  }
48
- return obj;
49
31
  }
50
- var BasicPluginOptionsManager = /*#__PURE__*/ function() {
51
- function BasicPluginOptionsManager() {
52
- _class_call_check$4(this, BasicPluginOptionsManager);
53
- _define_property$4(this, "_options", void 0);
32
+
33
+ class PKGJsonManager {
34
+ setPKGJson(pkg) {
35
+ this._pkg = pkg;
54
36
  }
55
- _create_class$4(BasicPluginOptionsManager, [
56
- {
57
- key: "enable",
58
- get: function get() {
59
- return Boolean(this._options);
60
- }
61
- },
62
- {
63
- key: "options",
64
- get: function get() {
65
- return this._options;
66
- }
67
- },
68
- {
69
- key: "init",
70
- value: function init(options, extraArgs) {
71
- this._options = options;
72
- }
73
- },
74
- {
75
- key: "setOptions",
76
- value: function setOptions(options) {
77
- this._options = options;
37
+ readPKGJson(ctx = process.cwd()) {
38
+ if (this._pkg) {
39
+ return this._pkg;
40
+ }
41
+ try {
42
+ // eslint-disable-next-line no-restricted-globals
43
+ const pkg = JSON.parse(fs__default["default"].readFileSync(path__default["default"].resolve(ctx, 'package.json'), 'utf8'));
44
+ this._pkg = pkg;
45
+ return pkg;
46
+ } catch (_err) {
47
+ try {
48
+ const pkg = finder__default["default"].sync(ctx);
49
+ this._pkg = pkg;
50
+ return pkg;
51
+ } catch (err) {
52
+ console.error(err);
53
+ return {};
78
54
  }
79
55
  }
80
- ]);
81
- return BasicPluginOptionsManager;
82
- }();
83
-
84
- function _class_call_check$3(instance, Constructor) {
85
- if (!(instance instanceof Constructor)) {
86
- throw new TypeError("Cannot call a class as a function");
87
- }
88
- }
89
- function _defineProperties$3(target, props) {
90
- for(var i = 0; i < props.length; i++){
91
- var descriptor = props[i];
92
- descriptor.enumerable = descriptor.enumerable || false;
93
- descriptor.configurable = true;
94
- if ("value" in descriptor) descriptor.writable = true;
95
- Object.defineProperty(target, descriptor.key, descriptor);
96
56
  }
97
- }
98
- function _create_class$3(Constructor, protoProps, staticProps) {
99
- if (protoProps) _defineProperties$3(Constructor.prototype, protoProps);
100
- if (staticProps) _defineProperties$3(Constructor, staticProps);
101
- return Constructor;
102
- }
103
- function _define_property$3(obj, key, value) {
104
- if (key in obj) {
105
- Object.defineProperty(obj, key, {
106
- value: value,
107
- enumerable: true,
108
- configurable: true,
109
- writable: true
110
- });
111
- } else {
112
- obj[key] = value;
57
+ getExposeGarfishModuleType(ctx = process.cwd()) {
58
+ var _pkg_mf;
59
+ const pkg = this.readPKGJson(ctx);
60
+ return (pkg == null ? void 0 : (_pkg_mf = pkg['mf']) == null ? void 0 : _pkg_mf.type) === sdk.MFModuleType.NPM ? sdk.MFModuleType.NPM : sdk.MFModuleType.APP;
113
61
  }
114
- return obj;
115
62
  }
116
- var PKGJsonManager = /*#__PURE__*/ function() {
117
- function PKGJsonManager() {
118
- _class_call_check$3(this, PKGJsonManager);
119
- _define_property$3(this, "_pkg", void 0);
120
- }
121
- _create_class$3(PKGJsonManager, [
122
- {
123
- key: "setPKGJson",
124
- value: function setPKGJson(pkg) {
125
- this._pkg = pkg;
126
- }
127
- },
128
- {
129
- key: "readPKGJson",
130
- value: function readPKGJson() {
131
- var ctx = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : process.cwd();
132
- if (this._pkg) {
133
- return this._pkg;
134
- }
135
- try {
136
- // eslint-disable-next-line no-restricted-globals
137
- var pkg = JSON.parse(fs__default["default"].readFileSync(path__default["default"].resolve(ctx, 'package.json'), 'utf8'));
138
- this._pkg = pkg;
139
- return pkg;
140
- } catch (_err) {
141
- try {
142
- var pkg1 = finder__default["default"].sync(ctx);
143
- this._pkg = pkg1;
144
- return pkg1;
145
- } catch (err) {
146
- console.error(err);
147
- return {};
148
- }
149
- }
150
- }
151
- },
152
- {
153
- key: "getExposeGarfishModuleType",
154
- value: function getExposeGarfishModuleType() {
155
- var ctx = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : process.cwd();
156
- var _pkg_mf;
157
- var pkg = this.readPKGJson(ctx);
158
- return (pkg === null || pkg === void 0 ? void 0 : (_pkg_mf = pkg['mf']) === null || _pkg_mf === void 0 ? void 0 : _pkg_mf.type) === sdk.MFModuleType.NPM ? sdk.MFModuleType.NPM : sdk.MFModuleType.APP;
159
- }
160
- }
161
- ]);
162
- return PKGJsonManager;
163
- }();
164
63
 
165
- var LOCAL_BUILD_VERSION = 'local';
64
+ const LOCAL_BUILD_VERSION = 'local';
166
65
 
167
- function _array_like_to_array$2(arr, len) {
168
- if (len == null || len > arr.length) len = arr.length;
169
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
170
- return arr2;
171
- }
172
- function _array_with_holes$2(arr) {
173
- if (Array.isArray(arr)) return arr;
174
- }
175
- function _iterable_to_array_limit$2(arr, i) {
176
- var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
177
- if (_i == null) return;
178
- var _arr = [];
179
- var _n = true;
180
- var _d = false;
181
- var _s, _e;
182
- try {
183
- for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
184
- _arr.push(_s.value);
185
- if (i && _arr.length === i) break;
186
- }
187
- } catch (err) {
188
- _d = true;
189
- _e = err;
190
- } finally{
191
- try {
192
- if (!_n && _i["return"] != null) _i["return"]();
193
- } finally{
194
- if (_d) throw _e;
195
- }
196
- }
197
- return _arr;
198
- }
199
- function _non_iterable_rest$2() {
200
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
201
- }
202
- function _sliced_to_array$2(arr, i) {
203
- return _array_with_holes$2(arr) || _iterable_to_array_limit$2(arr, i) || _unsupported_iterable_to_array$2(arr, i) || _non_iterable_rest$2();
204
- }
205
- function _type_of$3(obj) {
206
- "@swc/helpers - typeof";
207
- return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
208
- }
209
- function _unsupported_iterable_to_array$2(o, minLen) {
210
- if (!o) return;
211
- if (typeof o === "string") return _array_like_to_array$2(o, minLen);
212
- var n = Object.prototype.toString.call(o).slice(8, -1);
213
- if (n === "Object" && o.constructor) n = o.constructor.name;
214
- if (n === "Map" || n === "Set") return Array.from(n);
215
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$2(o, minLen);
216
- }
217
66
  function processFn(options, normalizeSimple, normalizeOptions, fn) {
218
- var object = function(obj) {
219
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
220
- try {
221
- for(var _iterator = Object.entries(obj)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
222
- var _step_value = _sliced_to_array$2(_step.value, 2), key = _step_value[0], value = _step_value[1];
223
- if (typeof value === 'string') {
224
- fn(key, normalizeSimple(value, key));
225
- } else {
226
- fn(key, normalizeOptions(value, key));
227
- }
228
- }
229
- } catch (err) {
230
- _didIteratorError = true;
231
- _iteratorError = err;
232
- } finally{
233
- try {
234
- if (!_iteratorNormalCompletion && _iterator.return != null) {
235
- _iterator.return();
236
- }
237
- } finally{
238
- if (_didIteratorError) {
239
- throw _iteratorError;
240
- }
67
+ const object = (obj)=>{
68
+ for (const [key, value] of Object.entries(obj)){
69
+ if (typeof value === 'string') {
70
+ fn(key, normalizeSimple(value, key));
71
+ } else {
72
+ fn(key, normalizeOptions(value, key));
241
73
  }
242
74
  }
243
75
  };
244
- var array = function(items) {
245
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
246
- try {
247
- for(var _iterator = items[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
248
- var item = _step.value;
249
- if (typeof item === 'string') {
250
- fn(item, normalizeSimple(item, item));
251
- } else if (item && (typeof item === "undefined" ? "undefined" : _type_of$3(item)) === 'object') {
252
- object(item);
253
- } else {
254
- throw new Error('Unexpected options format');
255
- }
256
- }
257
- } catch (err) {
258
- _didIteratorError = true;
259
- _iteratorError = err;
260
- } finally{
261
- try {
262
- if (!_iteratorNormalCompletion && _iterator.return != null) {
263
- _iterator.return();
264
- }
265
- } finally{
266
- if (_didIteratorError) {
267
- throw _iteratorError;
268
- }
76
+ const array = (items)=>{
77
+ for (const item of items){
78
+ if (typeof item === 'string') {
79
+ fn(item, normalizeSimple(item, item));
80
+ } else if (item && typeof item === 'object') {
81
+ object(item);
82
+ } else {
83
+ throw new Error('Unexpected options format');
269
84
  }
270
85
  }
271
86
  };
@@ -273,15 +88,15 @@ function processFn(options, normalizeSimple, normalizeOptions, fn) {
273
88
  return;
274
89
  } else if (Array.isArray(options)) {
275
90
  array(options);
276
- } else if ((typeof options === "undefined" ? "undefined" : _type_of$3(options)) === 'object') {
91
+ } else if (typeof options === 'object') {
277
92
  object(options);
278
93
  } else {
279
94
  throw new Error('Unexpected options format');
280
95
  }
281
96
  }
282
97
  function parseOptions(options, normalizeSimple, normalizeOptions) {
283
- var items = [];
284
- processFn(options, normalizeSimple, normalizeOptions, function(key, value) {
98
+ const items = [];
99
+ processFn(options, normalizeSimple, normalizeOptions, (key, value)=>{
285
100
  items.push([
286
101
  key,
287
102
  value
@@ -293,8 +108,8 @@ function getBuildVersion() {
293
108
  if (process.env['MF_BUILD_VERSION']) {
294
109
  return process.env['MF_BUILD_VERSION'];
295
110
  }
296
- var pkg = new PKGJsonManager().readPKGJson();
297
- if ((pkg === null || pkg === void 0 ? void 0 : pkg['version']) && typeof pkg['version'] === 'string') {
111
+ const pkg = new PKGJsonManager().readPKGJson();
112
+ if ((pkg == null ? void 0 : pkg['version']) && typeof pkg['version'] === 'string') {
298
113
  return pkg['version'];
299
114
  }
300
115
  return LOCAL_BUILD_VERSION;
@@ -303,7 +118,7 @@ function getBuildName() {
303
118
  return process.env['MF_BUILD_NAME'];
304
119
  }
305
120
  // RegExp for version string
306
- var VERSION_PATTERN_REGEXP = /^([\d^=v<>~]|[*xX]$)/;
121
+ const VERSION_PATTERN_REGEXP = /^([\d^=v<>~]|[*xX]$)/;
307
122
  function isRequiredVersion(str) {
308
123
  return VERSION_PATTERN_REGEXP.test(str);
309
124
  }
@@ -316,493 +131,152 @@ var utils = /*#__PURE__*/Object.freeze({
316
131
  isRequiredVersion: isRequiredVersion
317
132
  });
318
133
 
319
- function _array_like_to_array$1(arr, len) {
320
- if (len == null || len > arr.length) len = arr.length;
321
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
322
- return arr2;
323
- }
324
- function _array_with_holes$1(arr) {
325
- if (Array.isArray(arr)) return arr;
326
- }
327
- function _array_without_holes(arr) {
328
- if (Array.isArray(arr)) return _array_like_to_array$1(arr);
329
- }
330
- function _assert_this_initialized$2(self) {
331
- if (self === void 0) {
332
- throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
333
- }
334
- return self;
335
- }
336
- function _class_call_check$2(instance, Constructor) {
337
- if (!(instance instanceof Constructor)) {
338
- throw new TypeError("Cannot call a class as a function");
339
- }
340
- }
341
- function _defineProperties$2(target, props) {
342
- for(var i = 0; i < props.length; i++){
343
- var descriptor = props[i];
344
- descriptor.enumerable = descriptor.enumerable || false;
345
- descriptor.configurable = true;
346
- if ("value" in descriptor) descriptor.writable = true;
347
- Object.defineProperty(target, descriptor.key, descriptor);
348
- }
349
- }
350
- function _create_class$2(Constructor, protoProps, staticProps) {
351
- if (protoProps) _defineProperties$2(Constructor.prototype, protoProps);
352
- if (staticProps) _defineProperties$2(Constructor, staticProps);
353
- return Constructor;
354
- }
355
- function _define_property$2(obj, key, value) {
356
- if (key in obj) {
357
- Object.defineProperty(obj, key, {
358
- value: value,
359
- enumerable: true,
360
- configurable: true,
361
- writable: true
362
- });
363
- } else {
364
- obj[key] = value;
365
- }
366
- return obj;
367
- }
368
- function _get_prototype_of$2(o) {
369
- _get_prototype_of$2 = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
370
- return o.__proto__ || Object.getPrototypeOf(o);
371
- };
372
- return _get_prototype_of$2(o);
373
- }
374
- function _inherits$2(subClass, superClass) {
375
- if (typeof superClass !== "function" && superClass !== null) {
376
- throw new TypeError("Super expression must either be null or a function");
377
- }
378
- subClass.prototype = Object.create(superClass && superClass.prototype, {
379
- constructor: {
380
- value: subClass,
381
- writable: true,
382
- configurable: true
383
- }
384
- });
385
- if (superClass) _set_prototype_of$2(subClass, superClass);
386
- }
387
- function _iterable_to_array(iter) {
388
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
389
- }
390
- function _iterable_to_array_limit$1(arr, i) {
391
- var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
392
- if (_i == null) return;
393
- var _arr = [];
394
- var _n = true;
395
- var _d = false;
396
- var _s, _e;
397
- try {
398
- for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
399
- _arr.push(_s.value);
400
- if (i && _arr.length === i) break;
401
- }
402
- } catch (err) {
403
- _d = true;
404
- _e = err;
405
- } finally{
406
- try {
407
- if (!_n && _i["return"] != null) _i["return"]();
408
- } finally{
409
- if (_d) throw _e;
410
- }
411
- }
412
- return _arr;
413
- }
414
- function _non_iterable_rest$1() {
415
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
416
- }
417
- function _non_iterable_spread() {
418
- throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
419
- }
420
- function _possible_constructor_return$2(self, call) {
421
- if (call && (_type_of$2(call) === "object" || typeof call === "function")) {
422
- return call;
423
- }
424
- return _assert_this_initialized$2(self);
425
- }
426
- function _set_prototype_of$2(o, p) {
427
- _set_prototype_of$2 = Object.setPrototypeOf || function setPrototypeOf(o, p) {
428
- o.__proto__ = p;
429
- return o;
430
- };
431
- return _set_prototype_of$2(o, p);
432
- }
433
- function _sliced_to_array$1(arr, i) {
434
- return _array_with_holes$1(arr) || _iterable_to_array_limit$1(arr, i) || _unsupported_iterable_to_array$1(arr, i) || _non_iterable_rest$1();
435
- }
436
- function _to_consumable_array(arr) {
437
- return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array$1(arr) || _non_iterable_spread();
438
- }
439
- function _type_of$2(obj) {
440
- "@swc/helpers - typeof";
441
- return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
442
- }
443
- function _unsupported_iterable_to_array$1(o, minLen) {
444
- if (!o) return;
445
- if (typeof o === "string") return _array_like_to_array$1(o, minLen);
446
- var n = Object.prototype.toString.call(o).slice(8, -1);
447
- if (n === "Object" && o.constructor) n = o.constructor.name;
448
- if (n === "Map" || n === "Set") return Array.from(n);
449
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$1(o, minLen);
450
- }
451
- function _is_native_reflect_construct$2() {
452
- if (typeof Reflect === "undefined" || !Reflect.construct) return false;
453
- if (Reflect.construct.sham) return false;
454
- if (typeof Proxy === "function") return true;
455
- try {
456
- Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
457
- return true;
458
- } catch (e) {
459
- return false;
460
- }
461
- }
462
- function _create_super$2(Derived) {
463
- var hasNativeReflectConstruct = _is_native_reflect_construct$2();
464
- return function _createSuperInternal() {
465
- var Super = _get_prototype_of$2(Derived), result;
466
- if (hasNativeReflectConstruct) {
467
- var NewTarget = _get_prototype_of$2(this).constructor;
468
- result = Reflect.construct(Super, arguments, NewTarget);
469
- } else {
470
- result = Super.apply(this, arguments);
471
- }
472
- return _possible_constructor_return$2(this, result);
473
- };
474
- }
475
134
  function normalizeExposeModuleName(exposeKey) {
476
- var relativePath = path__default["default"].relative('.', exposeKey);
135
+ const relativePath = path__default["default"].relative('.', exposeKey);
477
136
  if (!relativePath) {
478
137
  return 'ExposeEntry';
479
138
  }
480
139
  return relativePath;
481
140
  }
482
- var ContainerManager = /*#__PURE__*/ function(BasicPluginOptionsManager) {
483
- _inherits$2(ContainerManager, BasicPluginOptionsManager);
484
- var _super = _create_super$2(ContainerManager);
485
- function ContainerManager() {
486
- _class_call_check$2(this, ContainerManager);
487
- var _this;
488
- _this = _super.apply(this, arguments);
489
- _define_property$2(_assert_this_initialized$2(_this), "_manifestModuleInfos", void 0);
490
- _define_property$2(_assert_this_initialized$2(_this), "_parsedOptions", void 0);
491
- return _this;
141
+ let ContainerManager = class ContainerManager extends BasicPluginOptionsManager {
142
+ get enable() {
143
+ return Boolean(this.options.name && this.options.exposes && (Array.isArray(this.options.exposes) ? this.options.exposes.length > 0 : Object.keys(this.options.exposes).length > 0));
492
144
  }
493
- _create_class$2(ContainerManager, [
494
- {
495
- key: "enable",
496
- get: function get() {
497
- return Boolean(this.options.name && this.options.exposes && (Array.isArray(this.options.exposes) ? this.options.exposes.length > 0 : Object.keys(this.options.exposes).length > 0));
498
- }
499
- },
500
- {
501
- key: "globalEntryName",
502
- get: function get() {
503
- var _this_options = this.options, name = _this_options.name, library = _this_options.library;
504
- if (library) {
505
- if (typeof library.name === 'string') {
506
- return library.name;
507
- }
508
- return name;
509
- }
510
- return name;
511
- }
512
- },
513
- {
514
- key: "containerPluginExposesOptions",
515
- get: function get() {
516
- var exposes = this.options.exposes;
517
- var parsedOptions = parseOptions(exposes, function(item, key) {
518
- return {
519
- import: Array.isArray(item) ? item : [
520
- item
521
- ],
522
- name: sdk.generateExposeFilename(key, false)
523
- };
524
- }, function(item, key) {
525
- return {
526
- import: Array.isArray(item.import) ? item.import : [
527
- item.import
528
- ],
529
- name: item.name || sdk.generateExposeFilename(key, false)
530
- };
531
- });
532
- return parsedOptions.reduce(function(sum, item) {
533
- var _item = _sliced_to_array$1(item, 2), exposeKey = _item[0], exposeObj = _item[1];
534
- sum[exposeKey] = exposeObj;
535
- return sum;
536
- }, {});
537
- }
538
- },
539
- {
540
- key: "exposeFileNameImportMap",
541
- get: // { '.' : './src/Button.jsx' } => { '__federation_expose_Component' : ['src/Buttton'] }
542
- function get() {
543
- var exposes = this.options.exposes;
544
- var parsedOptions = parseOptions(exposes, function(item, key) {
545
- return {
546
- import: Array.isArray(item) ? item : [
547
- item
548
- ],
549
- name: sdk.generateExposeFilename(key, false)
550
- };
551
- }, function(item, key) {
552
- return {
553
- import: Array.isArray(item.import) ? item.import : [
554
- item.import
555
- ],
556
- name: item.name || sdk.generateExposeFilename(key, false)
557
- };
558
- });
559
- return parsedOptions.reduce(function(sum, item) {
560
- var _item = _sliced_to_array$1(item, 2); _item[0]; var exposeObj = _item[1];
561
- var name = exposeObj.name, importPath = exposeObj.import;
562
- sum[name] = importPath;
563
- return sum;
564
- }, {});
565
- }
566
- },
567
- {
568
- key: "exposeObject",
569
- get: // { '.' : './src/Button.jsx' } => { '.' : ['src/Button'] }
570
- function get() {
571
- var parsedOptions = this._parseOptions();
572
- return parsedOptions.reduce(function(sum, item) {
573
- var _item = _sliced_to_array$1(item, 2), exposeKey = _item[0], exposeObject = _item[1];
574
- sum[exposeKey] = [];
575
- exposeObject.import.forEach(function(item) {
576
- var relativePath = path__default["default"].relative('.', item.replace(path__default["default"].extname(item), ''));
577
- sum[exposeKey].push(relativePath);
578
- });
579
- return sum;
580
- }, {});
581
- }
582
- },
583
- {
584
- key: "exposeFiles",
585
- get: // { '.' : './src/Button.jsx' } => ['./src/Button.jsx']
586
- function get() {
587
- var parsedOptions = this._parseOptions();
588
- return parsedOptions.reduce(function(sum, item) {
589
- var _sum;
590
- var _item = _sliced_to_array$1(item, 2); _item[0]; var exposeObject = _item[1];
591
- (_sum = sum).push.apply(_sum, _to_consumable_array(exposeObject.import));
592
- return sum;
593
- }, []);
594
- }
595
- },
596
- {
597
- key: "manifestModuleInfos",
598
- get: function get() {
599
- if (this._manifestModuleInfos) {
600
- return this._manifestModuleInfos;
601
- }
602
- // { '.' : './src/Button.jsx' } => { '.' : { name: 'ExposeEntry', file: './src/Button.jsx', requires: {} } }
603
- var parsedOptions = this._parseOptions();
604
- this._manifestModuleInfos = parsedOptions.reduce(function(sum, item) {
605
- var _item = _sliced_to_array$1(item, 2), exposeKey = _item[0], exposeObject = _item[1];
606
- sum[exposeKey] = {
607
- name: exposeObject.name || normalizeExposeModuleName(exposeKey),
608
- file: exposeObject.import
609
- };
610
- return sum;
611
- }, {});
612
- return this._manifestModuleInfos;
613
- }
614
- },
615
- {
616
- key: "webpackEntry",
617
- get: // { '.' : './src/Button.jsx' } => { index: ['./src/Button.jsx'] }
618
- function get() {
619
- return Object.values(this.manifestModuleInfos).reduce(function(sum, cur) {
620
- var entry = cur.name === 'ExposeEntry' ? 'index' : cur.name.slice(0, 1).toLowerCase() + cur.name.slice(1);
621
- sum[entry] = cur.file;
622
- return sum;
623
- }, {});
624
- }
625
- },
626
- {
627
- key: "_parseOptions",
628
- value: function _parseOptions() {
629
- if (this._parsedOptions) {
630
- return this._parsedOptions;
631
- }
632
- this._parsedOptions = parseOptions(this.options.exposes, function(item) {
633
- return {
634
- import: Array.isArray(item) ? item : [
635
- item
636
- ],
637
- name: undefined
638
- };
639
- }, function(item) {
640
- return {
641
- import: Array.isArray(item.import) ? item.import : [
642
- item.import
643
- ],
644
- name: undefined
645
- };
646
- });
647
- return this._parsedOptions;
648
- }
649
- },
650
- {
651
- key: "init",
652
- value: function init(options) {
653
- this.setOptions(options);
654
- this.validate(options.name);
655
- }
656
- },
657
- {
658
- key: "validate",
659
- value: function validate(name) {
660
- if (!name) {
661
- throw new Error("container name can not be empty!");
662
- }
145
+ get globalEntryName() {
146
+ const { name, library } = this.options;
147
+ if (library) {
148
+ if (typeof library.name === 'string') {
149
+ return library.name;
663
150
  }
151
+ return name;
664
152
  }
665
- ]);
666
- return ContainerManager;
667
- }(BasicPluginOptionsManager);
668
-
669
- function _assert_this_initialized$1(self) {
670
- if (self === void 0) {
671
- throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
672
- }
673
- return self;
674
- }
675
- function _class_call_check$1(instance, Constructor) {
676
- if (!(instance instanceof Constructor)) {
677
- throw new TypeError("Cannot call a class as a function");
678
- }
679
- }
680
- function _defineProperties$1(target, props) {
681
- for(var i = 0; i < props.length; i++){
682
- var descriptor = props[i];
683
- descriptor.enumerable = descriptor.enumerable || false;
684
- descriptor.configurable = true;
685
- if ("value" in descriptor) descriptor.writable = true;
686
- Object.defineProperty(target, descriptor.key, descriptor);
687
- }
688
- }
689
- function _create_class$1(Constructor, protoProps, staticProps) {
690
- if (protoProps) _defineProperties$1(Constructor.prototype, protoProps);
691
- if (staticProps) _defineProperties$1(Constructor, staticProps);
692
- return Constructor;
693
- }
694
- function _define_property$1(obj, key, value) {
695
- if (key in obj) {
696
- Object.defineProperty(obj, key, {
697
- value: value,
698
- enumerable: true,
699
- configurable: true,
700
- writable: true
701
- });
702
- } else {
703
- obj[key] = value;
704
- }
705
- return obj;
706
- }
707
- function _get_prototype_of$1(o) {
708
- _get_prototype_of$1 = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
709
- return o.__proto__ || Object.getPrototypeOf(o);
710
- };
711
- return _get_prototype_of$1(o);
712
- }
713
- function _inherits$1(subClass, superClass) {
714
- if (typeof superClass !== "function" && superClass !== null) {
715
- throw new TypeError("Super expression must either be null or a function");
716
- }
717
- subClass.prototype = Object.create(superClass && superClass.prototype, {
718
- constructor: {
719
- value: subClass,
720
- writable: true,
721
- configurable: true
722
- }
723
- });
724
- if (superClass) _set_prototype_of$1(subClass, superClass);
725
- }
726
- function _object_spread$1(target) {
727
- for(var i = 1; i < arguments.length; i++){
728
- var source = arguments[i] != null ? arguments[i] : {};
729
- var ownKeys = Object.keys(source);
730
- if (typeof Object.getOwnPropertySymbols === "function") {
731
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
732
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
153
+ return name;
154
+ }
155
+ get containerPluginExposesOptions() {
156
+ const { exposes } = this.options;
157
+ const parsedOptions = parseOptions(exposes, (item, key)=>({
158
+ import: Array.isArray(item) ? item : [
159
+ item
160
+ ],
161
+ name: sdk.generateExposeFilename(key, false)
162
+ }), (item, key)=>({
163
+ import: Array.isArray(item.import) ? item.import : [
164
+ item.import
165
+ ],
166
+ name: item.name || sdk.generateExposeFilename(key, false)
733
167
  }));
734
- }
735
- ownKeys.forEach(function(key) {
736
- _define_property$1(target, key, source[key]);
737
- });
738
- }
739
- return target;
740
- }
741
- function ownKeys$1(object, enumerableOnly) {
742
- var keys = Object.keys(object);
743
- if (Object.getOwnPropertySymbols) {
744
- var symbols = Object.getOwnPropertySymbols(object);
745
- if (enumerableOnly) {
746
- symbols = symbols.filter(function(sym) {
747
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
168
+ return parsedOptions.reduce((sum, item)=>{
169
+ const [exposeKey, exposeObj] = item;
170
+ sum[exposeKey] = exposeObj;
171
+ return sum;
172
+ }, {});
173
+ }
174
+ // { '.' : './src/Button.jsx' } => { '__federation_expose_Component' : ['src/Buttton'] }
175
+ get exposeFileNameImportMap() {
176
+ const { exposes } = this.options;
177
+ const parsedOptions = parseOptions(exposes, (item, key)=>({
178
+ import: Array.isArray(item) ? item : [
179
+ item
180
+ ],
181
+ name: sdk.generateExposeFilename(key, false)
182
+ }), (item, key)=>({
183
+ import: Array.isArray(item.import) ? item.import : [
184
+ item.import
185
+ ],
186
+ name: item.name || sdk.generateExposeFilename(key, false)
187
+ }));
188
+ return parsedOptions.reduce((sum, item)=>{
189
+ const [_exposeKey, exposeObj] = item;
190
+ const { name, import: importPath } = exposeObj;
191
+ sum[name] = importPath;
192
+ return sum;
193
+ }, {});
194
+ }
195
+ // { '.' : './src/Button.jsx' } => { '.' : ['src/Button'] }
196
+ get exposeObject() {
197
+ const parsedOptions = this._parseOptions();
198
+ return parsedOptions.reduce((sum, item)=>{
199
+ const [exposeKey, exposeObject] = item;
200
+ sum[exposeKey] = [];
201
+ exposeObject.import.forEach((item)=>{
202
+ const relativePath = path__default["default"].relative('.', item.replace(path__default["default"].extname(item), ''));
203
+ sum[exposeKey].push(relativePath);
748
204
  });
205
+ return sum;
206
+ }, {});
207
+ }
208
+ // { '.' : './src/Button.jsx' } => ['./src/Button.jsx']
209
+ get exposeFiles() {
210
+ const parsedOptions = this._parseOptions();
211
+ return parsedOptions.reduce((sum, item)=>{
212
+ const [_exposeKey, exposeObject] = item;
213
+ sum.push(...exposeObject.import);
214
+ return sum;
215
+ }, []);
216
+ }
217
+ get manifestModuleInfos() {
218
+ if (this._manifestModuleInfos) {
219
+ return this._manifestModuleInfos;
749
220
  }
750
- keys.push.apply(keys, symbols);
751
- }
752
- return keys;
753
- }
754
- function _object_spread_props$1(target, source) {
755
- source = source != null ? source : {};
756
- if (Object.getOwnPropertyDescriptors) {
757
- Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
758
- } else {
759
- ownKeys$1(Object(source)).forEach(function(key) {
760
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
761
- });
221
+ // { '.' : './src/Button.jsx' } => { '.' : { name: 'ExposeEntry', file: './src/Button.jsx', requires: {} } }
222
+ const parsedOptions = this._parseOptions();
223
+ this._manifestModuleInfos = parsedOptions.reduce((sum, item)=>{
224
+ const [exposeKey, exposeObject] = item;
225
+ sum[exposeKey] = {
226
+ name: exposeObject.name || normalizeExposeModuleName(exposeKey),
227
+ file: exposeObject.import
228
+ };
229
+ return sum;
230
+ }, {});
231
+ return this._manifestModuleInfos;
232
+ }
233
+ // { '.' : './src/Button.jsx' } => { index: ['./src/Button.jsx'] }
234
+ get webpackEntry() {
235
+ return Object.values(this.manifestModuleInfos).reduce((sum, cur)=>{
236
+ const entry = cur.name === 'ExposeEntry' ? 'index' : cur.name.slice(0, 1).toLowerCase() + cur.name.slice(1);
237
+ sum[entry] = cur.file;
238
+ return sum;
239
+ }, {});
240
+ }
241
+ _parseOptions() {
242
+ if (this._parsedOptions) {
243
+ return this._parsedOptions;
244
+ }
245
+ this._parsedOptions = parseOptions(this.options.exposes, (item)=>({
246
+ import: Array.isArray(item) ? item : [
247
+ item
248
+ ],
249
+ name: undefined
250
+ }), (item)=>({
251
+ import: Array.isArray(item.import) ? item.import : [
252
+ item.import
253
+ ],
254
+ name: undefined
255
+ }));
256
+ return this._parsedOptions;
762
257
  }
763
- return target;
764
- }
765
- function _possible_constructor_return$1(self, call) {
766
- if (call && (_type_of$1(call) === "object" || typeof call === "function")) {
767
- return call;
258
+ init(options) {
259
+ this.setOptions(options);
260
+ this.validate(options.name);
768
261
  }
769
- return _assert_this_initialized$1(self);
770
- }
771
- function _set_prototype_of$1(o, p) {
772
- _set_prototype_of$1 = Object.setPrototypeOf || function setPrototypeOf(o, p) {
773
- o.__proto__ = p;
774
- return o;
775
- };
776
- return _set_prototype_of$1(o, p);
777
- }
778
- function _type_of$1(obj) {
779
- "@swc/helpers - typeof";
780
- return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
781
- }
782
- function _is_native_reflect_construct$1() {
783
- if (typeof Reflect === "undefined" || !Reflect.construct) return false;
784
- if (Reflect.construct.sham) return false;
785
- if (typeof Proxy === "function") return true;
786
- try {
787
- Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
788
- return true;
789
- } catch (e) {
790
- return false;
262
+ validate(name) {
263
+ if (!name) {
264
+ throw new Error(`container name can not be empty!`);
265
+ }
791
266
  }
792
- }
793
- function _create_super$1(Derived) {
794
- var hasNativeReflectConstruct = _is_native_reflect_construct$1();
795
- return function _createSuperInternal() {
796
- var Super = _get_prototype_of$1(Derived), result;
797
- if (hasNativeReflectConstruct) {
798
- var NewTarget = _get_prototype_of$1(this).constructor;
799
- result = Reflect.construct(Super, arguments, NewTarget);
800
- } else {
801
- result = Super.apply(this, arguments);
267
+ };
268
+
269
+ function _extends() {
270
+ _extends = Object.assign || function assign(target) {
271
+ for(var i = 1; i < arguments.length; i++){
272
+ var source = arguments[i];
273
+ for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
802
274
  }
803
- return _possible_constructor_return$1(this, result);
275
+ return target;
804
276
  };
277
+ return _extends.apply(this, arguments);
805
278
  }
279
+
806
280
  function getEntry(remoteObj) {
807
281
  if (typeof remoteObj === 'string') {
808
282
  return remoteObj;
@@ -812,429 +286,188 @@ function getEntry(remoteObj) {
812
286
  }
813
287
  throw new Error('Not support "array" remote value yet!');
814
288
  }
815
- var RemoteManager = /*#__PURE__*/ function(BasicPluginOptionsManager) {
816
- _inherits$1(RemoteManager, BasicPluginOptionsManager);
817
- var _super = _create_super$1(RemoteManager);
818
- function RemoteManager() {
819
- _class_call_check$1(this, RemoteManager);
820
- var _this;
821
- _this = _super.apply(this, arguments);
822
- _define_property$1(_assert_this_initialized$1(_this), "normalizedOptions", {});
823
- return _this;
824
- }
825
- _create_class$1(RemoteManager, [
826
- {
827
- key: "enable",
828
- get: function get() {
829
- return Boolean(this.remotes && (Array.isArray(this.remotes) ? this.remotes.length > 0 : Object.keys(this.remotes).length > 0));
830
- }
831
- },
832
- {
833
- key: "statsRemoteWithEmptyUsedIn",
834
- get: function get() {
835
- var _this = this;
836
- var name = this.options.name;
837
- return Object.keys(this.normalizedOptions).reduce(function(sum, cur) {
838
- var normalizedOption = _this.normalizedOptions[cur];
839
- var curObj;
840
- if ('entry' in normalizedOption) {
841
- curObj = {
842
- entry: normalizedOption.entry,
843
- alias: normalizedOption.alias,
844
- moduleName: normalizedOption.name,
845
- federationContainerName: normalizedOption.name,
846
- consumingFederationContainerName: name,
847
- usedIn: []
848
- };
849
- } else {
850
- curObj = {
851
- alias: normalizedOption.alias,
852
- moduleName: normalizedOption.name,
853
- version: normalizedOption.version,
854
- federationContainerName: normalizedOption.name,
855
- consumingFederationContainerName: name,
856
- usedIn: []
857
- };
858
- }
859
- sum.push(curObj);
860
- return sum;
861
- }, []);
862
- }
863
- },
864
- {
865
- key: "dtsRemotes",
866
- get: // 'micro-app-sub3': 'app:@garfish/micro-app-sub3:0.0.4',
867
- // ↓↓↓
868
- // {
869
- // 'micro-app-sub3': @garfish/micro-app-sub3:0.0.4
870
- // }
871
- function get() {
872
- var _this = this;
873
- return Object.keys(this.normalizedOptions).reduce(function(sum, remoteAlias) {
874
- var remoteInfo = _this.normalizedOptions[remoteAlias];
875
- sum[remoteAlias] = sdk.composeKeyWithSeparator(remoteInfo.name, 'entry' in remoteInfo ? remoteInfo.entry : remoteInfo.version);
876
- return sum;
877
- }, {});
878
- }
879
- },
880
- {
881
- key: "remotes",
882
- get: function get() {
883
- return this.options.remotes;
289
+ let RemoteManager = class RemoteManager extends BasicPluginOptionsManager {
290
+ get enable() {
291
+ return Boolean(this.remotes && (Array.isArray(this.remotes) ? this.remotes.length > 0 : Object.keys(this.remotes).length > 0));
292
+ }
293
+ get statsRemoteWithEmptyUsedIn() {
294
+ const { name } = this.options;
295
+ return Object.keys(this.normalizedOptions).reduce((sum, cur)=>{
296
+ const normalizedOption = this.normalizedOptions[cur];
297
+ let curObj;
298
+ if ('entry' in normalizedOption) {
299
+ curObj = {
300
+ entry: normalizedOption.entry,
301
+ alias: normalizedOption.alias,
302
+ moduleName: normalizedOption.name,
303
+ federationContainerName: normalizedOption.name,
304
+ consumingFederationContainerName: name,
305
+ usedIn: []
306
+ };
307
+ } else {
308
+ curObj = {
309
+ alias: normalizedOption.alias,
310
+ moduleName: normalizedOption.name,
311
+ version: normalizedOption.version,
312
+ federationContainerName: normalizedOption.name,
313
+ consumingFederationContainerName: name,
314
+ usedIn: []
315
+ };
884
316
  }
885
- },
886
- {
887
- // INFO: only support remoteType: script now
888
- key: "normalizeOptions",
889
- value: function normalizeOptions() {
890
- var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
891
- this.normalizedOptions = Object.keys(options).reduce(function(sum, remoteAlias) {
892
- if (Array.isArray(options)) {
893
- return sum;
894
- }
895
- var remoteInfo = options[remoteAlias];
896
- if (Array.isArray(remoteInfo)) {
897
- return sum;
898
- }
899
- var parsedOptions;
900
- try {
901
- parsedOptions = sdk.parseEntry(typeof remoteInfo === 'string' ? remoteInfo : getEntry(remoteInfo), '', '@');
902
- } catch (e) {
903
- // noop
904
- }
905
- if (!parsedOptions) {
906
- return sum;
907
- }
908
- sum[remoteAlias] = _object_spread_props$1(_object_spread$1({}, parsedOptions), {
909
- alias: remoteAlias,
910
- shareScope: (typeof remoteInfo === "undefined" ? "undefined" : _type_of$1(remoteInfo)) === 'object' ? remoteInfo.shareScope || 'default' : 'default'
911
- });
912
- return sum;
913
- }, {});
317
+ sum.push(curObj);
318
+ return sum;
319
+ }, []);
320
+ }
321
+ // 'micro-app-sub3': 'app:@garfish/micro-app-sub3:0.0.4',
322
+ // ↓↓↓
323
+ // {
324
+ // 'micro-app-sub3': @garfish/micro-app-sub3:0.0.4
325
+ // }
326
+ get dtsRemotes() {
327
+ return Object.keys(this.normalizedOptions).reduce((sum, remoteAlias)=>{
328
+ const remoteInfo = this.normalizedOptions[remoteAlias];
329
+ sum[remoteAlias] = sdk.composeKeyWithSeparator(remoteInfo.name, 'entry' in remoteInfo ? remoteInfo.entry : remoteInfo.version);
330
+ return sum;
331
+ }, {});
332
+ }
333
+ get remotes() {
334
+ return this.options.remotes;
335
+ }
336
+ // INFO: only support remoteType: script now
337
+ normalizeOptions(options = {}) {
338
+ this.normalizedOptions = Object.keys(options).reduce((sum, remoteAlias)=>{
339
+ if (Array.isArray(options)) {
340
+ return sum;
341
+ }
342
+ const remoteInfo = options[remoteAlias];
343
+ if (Array.isArray(remoteInfo)) {
344
+ return sum;
345
+ }
346
+ let parsedOptions;
347
+ try {
348
+ parsedOptions = sdk.parseEntry(typeof remoteInfo === 'string' ? remoteInfo : getEntry(remoteInfo), '', '@');
349
+ } catch (e) {
350
+ // noop
914
351
  }
915
- },
916
- {
917
- key: "init",
918
- value: function init(options) {
919
- this.setOptions(options);
920
- this.normalizeOptions(options.remotes);
352
+ if (!parsedOptions) {
353
+ return sum;
921
354
  }
922
- }
923
- ]);
924
- return RemoteManager;
925
- }(BasicPluginOptionsManager);
926
-
927
- function _array_like_to_array(arr, len) {
928
- if (len == null || len > arr.length) len = arr.length;
929
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
930
- return arr2;
931
- }
932
- function _array_with_holes(arr) {
933
- if (Array.isArray(arr)) return arr;
934
- }
935
- function _assert_this_initialized(self) {
936
- if (self === void 0) {
937
- throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
938
- }
939
- return self;
940
- }
941
- function _class_call_check(instance, Constructor) {
942
- if (!(instance instanceof Constructor)) {
943
- throw new TypeError("Cannot call a class as a function");
944
- }
945
- }
946
- function _defineProperties(target, props) {
947
- for(var i = 0; i < props.length; i++){
948
- var descriptor = props[i];
949
- descriptor.enumerable = descriptor.enumerable || false;
950
- descriptor.configurable = true;
951
- if ("value" in descriptor) descriptor.writable = true;
952
- Object.defineProperty(target, descriptor.key, descriptor);
355
+ sum[remoteAlias] = _extends({}, parsedOptions, {
356
+ alias: remoteAlias,
357
+ shareScope: typeof remoteInfo === 'object' ? remoteInfo.shareScope || 'default' : 'default'
358
+ });
359
+ return sum;
360
+ }, {});
953
361
  }
954
- }
955
- function _create_class(Constructor, protoProps, staticProps) {
956
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
957
- if (staticProps) _defineProperties(Constructor, staticProps);
958
- return Constructor;
959
- }
960
- function _define_property(obj, key, value) {
961
- if (key in obj) {
962
- Object.defineProperty(obj, key, {
963
- value: value,
964
- enumerable: true,
965
- configurable: true,
966
- writable: true
967
- });
968
- } else {
969
- obj[key] = value;
362
+ init(options) {
363
+ this.setOptions(options);
364
+ this.normalizeOptions(options.remotes);
970
365
  }
971
- return obj;
972
- }
973
- function _get_prototype_of(o) {
974
- _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
975
- return o.__proto__ || Object.getPrototypeOf(o);
976
- };
977
- return _get_prototype_of(o);
978
- }
979
- function _inherits(subClass, superClass) {
980
- if (typeof superClass !== "function" && superClass !== null) {
981
- throw new TypeError("Super expression must either be null or a function");
366
+ constructor(...args){
367
+ super(...args);
368
+ this.normalizedOptions = {};
982
369
  }
983
- subClass.prototype = Object.create(superClass && superClass.prototype, {
984
- constructor: {
985
- value: subClass,
986
- writable: true,
987
- configurable: true
988
- }
989
- });
990
- if (superClass) _set_prototype_of(subClass, superClass);
991
- }
992
- function _iterable_to_array_limit(arr, i) {
993
- var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
994
- if (_i == null) return;
995
- var _arr = [];
996
- var _n = true;
997
- var _d = false;
998
- var _s, _e;
999
- try {
1000
- for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
1001
- _arr.push(_s.value);
1002
- if (i && _arr.length === i) break;
1003
- }
1004
- } catch (err) {
1005
- _d = true;
1006
- _e = err;
1007
- } finally{
370
+ };
371
+
372
+ let SharedManager = class SharedManager extends BasicPluginOptionsManager {
373
+ get enable() {
374
+ return Boolean(Object.keys(this.sharedPluginOptions.shared).length);
375
+ }
376
+ get sharedPluginOptions() {
377
+ const normalizedShared = this.normalizedOptions;
378
+ const shared = Object.keys(normalizedShared).reduce((sum, cur)=>{
379
+ const { singleton, requiredVersion, version, eager, shareScope, import: sharedImport } = normalizedShared[cur];
380
+ sum[cur] = {
381
+ singleton,
382
+ requiredVersion,
383
+ version,
384
+ eager,
385
+ shareScope,
386
+ import: sharedImport
387
+ };
388
+ return sum;
389
+ }, {});
390
+ return {
391
+ shared,
392
+ shareScope: this.options.shareScope || 'default'
393
+ };
394
+ }
395
+ findPkg(name, shareConfig) {
1008
396
  try {
1009
- if (!_n && _i["return"] != null) _i["return"]();
1010
- } finally{
1011
- if (_d) throw _e;
1012
- }
1013
- }
1014
- return _arr;
1015
- }
1016
- function _non_iterable_rest() {
1017
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
1018
- }
1019
- function _object_spread(target) {
1020
- for(var i = 1; i < arguments.length; i++){
1021
- var source = arguments[i] != null ? arguments[i] : {};
1022
- var ownKeys = Object.keys(source);
1023
- if (typeof Object.getOwnPropertySymbols === "function") {
1024
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
1025
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
1026
- }));
1027
- }
1028
- ownKeys.forEach(function(key) {
1029
- _define_property(target, key, source[key]);
1030
- });
1031
- }
1032
- return target;
1033
- }
1034
- function ownKeys(object, enumerableOnly) {
1035
- var keys = Object.keys(object);
1036
- if (Object.getOwnPropertySymbols) {
1037
- var symbols = Object.getOwnPropertySymbols(object);
1038
- if (enumerableOnly) {
1039
- symbols = symbols.filter(function(sym) {
1040
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
397
+ let pkgPath = '';
398
+ let depName = name;
399
+ if (shareConfig.import) {
400
+ if (path__default["default"].isAbsolute(shareConfig.import)) {
401
+ pkgPath = shareConfig.import;
402
+ } else if (shareConfig.import.startsWith('.')) {
403
+ pkgPath = path__default["default"].resolve(process.cwd(), shareConfig.import);
404
+ }
405
+ } else {
406
+ if (shareConfig.packageName) {
407
+ depName = shareConfig.packageName;
408
+ }
409
+ }
410
+ pkgPath = pkgPath || require.resolve(depName, {
411
+ paths: [
412
+ process.cwd()
413
+ ]
1041
414
  });
415
+ const pkgJsonPath = finder__default["default"].sync(pkgPath);
416
+ return {
417
+ pkg: JSON.parse(fs__default$1["default"].readFileSync(pkgJsonPath, 'utf-8')),
418
+ path: '',
419
+ pkgPath: ''
420
+ };
421
+ } catch (err) {
422
+ return {
423
+ pkg: {},
424
+ path: '',
425
+ pkgPath: ''
426
+ };
1042
427
  }
1043
- keys.push.apply(keys, symbols);
1044
428
  }
1045
- return keys;
1046
- }
1047
- function _object_spread_props(target, source) {
1048
- source = source != null ? source : {};
1049
- if (Object.getOwnPropertyDescriptors) {
1050
- Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
1051
- } else {
1052
- ownKeys(Object(source)).forEach(function(key) {
1053
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
429
+ transformSharedConfig(sharedConfig) {
430
+ const defaultSharedConfig = {
431
+ singleton: true,
432
+ requiredVersion: undefined,
433
+ shareScope: 'default'
434
+ };
435
+ return _extends({}, defaultSharedConfig, sharedConfig);
436
+ }
437
+ normalizeOptions(options) {
438
+ const normalizedShared = {};
439
+ const sharedOptions = parseOptions(options, (item, key)=>{
440
+ if (typeof item !== 'string') throw new Error('Unexpected array in shared');
441
+ const config = item === key || !isRequiredVersion(item) ? {
442
+ import: item
443
+ } : {
444
+ import: key,
445
+ requiredVersion: item
446
+ };
447
+ return config;
448
+ }, (item)=>item);
449
+ sharedOptions.forEach((item)=>{
450
+ const [sharedName, sharedOptions] = item;
451
+ const pkgInfo = this.findPkg(sharedName, sharedOptions);
452
+ const sharedConfig = this.transformSharedConfig(sharedOptions[sharedName]);
453
+ normalizedShared[sharedName] = _extends({}, sharedConfig, {
454
+ requiredVersion: typeof sharedConfig.requiredVersion !== 'undefined' ? sharedConfig.requiredVersion : `^${pkgInfo.pkg['version']}`,
455
+ name: sharedName,
456
+ version: pkgInfo.pkg['version'],
457
+ eager: Boolean(sharedConfig.eager)
458
+ });
1054
459
  });
460
+ this.normalizedOptions = normalizedShared;
1055
461
  }
1056
- return target;
1057
- }
1058
- function _possible_constructor_return(self, call) {
1059
- if (call && (_type_of(call) === "object" || typeof call === "function")) {
1060
- return call;
462
+ init(options) {
463
+ this.setOptions(options);
464
+ this.normalizeOptions(options.shared);
1061
465
  }
1062
- return _assert_this_initialized(self);
1063
- }
1064
- function _set_prototype_of(o, p) {
1065
- _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
1066
- o.__proto__ = p;
1067
- return o;
1068
- };
1069
- return _set_prototype_of(o, p);
1070
- }
1071
- function _sliced_to_array(arr, i) {
1072
- return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
1073
- }
1074
- function _type_of(obj) {
1075
- "@swc/helpers - typeof";
1076
- return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
1077
- }
1078
- function _unsupported_iterable_to_array(o, minLen) {
1079
- if (!o) return;
1080
- if (typeof o === "string") return _array_like_to_array(o, minLen);
1081
- var n = Object.prototype.toString.call(o).slice(8, -1);
1082
- if (n === "Object" && o.constructor) n = o.constructor.name;
1083
- if (n === "Map" || n === "Set") return Array.from(n);
1084
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
1085
- }
1086
- function _is_native_reflect_construct() {
1087
- if (typeof Reflect === "undefined" || !Reflect.construct) return false;
1088
- if (Reflect.construct.sham) return false;
1089
- if (typeof Proxy === "function") return true;
1090
- try {
1091
- Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
1092
- return true;
1093
- } catch (e) {
1094
- return false;
1095
- }
1096
- }
1097
- function _create_super(Derived) {
1098
- var hasNativeReflectConstruct = _is_native_reflect_construct();
1099
- return function _createSuperInternal() {
1100
- var Super = _get_prototype_of(Derived), result;
1101
- if (hasNativeReflectConstruct) {
1102
- var NewTarget = _get_prototype_of(this).constructor;
1103
- result = Reflect.construct(Super, arguments, NewTarget);
1104
- } else {
1105
- result = Super.apply(this, arguments);
1106
- }
1107
- return _possible_constructor_return(this, result);
1108
- };
1109
- }
1110
- var SharedManager = /*#__PURE__*/ function(BasicPluginOptionsManager) {
1111
- _inherits(SharedManager, BasicPluginOptionsManager);
1112
- var _super = _create_super(SharedManager);
1113
- function SharedManager() {
1114
- _class_call_check(this, SharedManager);
1115
- var _this;
1116
- _this = _super.apply(this, arguments);
1117
- _define_property(_assert_this_initialized(_this), "normalizedOptions", {});
1118
- return _this;
466
+ constructor(...args){
467
+ super(...args);
468
+ this.normalizedOptions = {};
1119
469
  }
1120
- _create_class(SharedManager, [
1121
- {
1122
- key: "enable",
1123
- get: function get() {
1124
- return Boolean(Object.keys(this.sharedPluginOptions.shared).length);
1125
- }
1126
- },
1127
- {
1128
- key: "sharedPluginOptions",
1129
- get: function get() {
1130
- var normalizedShared = this.normalizedOptions;
1131
- var shared = Object.keys(normalizedShared).reduce(function(sum, cur) {
1132
- var _normalizedShared_cur = normalizedShared[cur], singleton = _normalizedShared_cur.singleton, requiredVersion = _normalizedShared_cur.requiredVersion, version = _normalizedShared_cur.version, eager = _normalizedShared_cur.eager, shareScope = _normalizedShared_cur.shareScope, sharedImport = _normalizedShared_cur.import;
1133
- sum[cur] = {
1134
- singleton: singleton,
1135
- requiredVersion: requiredVersion,
1136
- version: version,
1137
- eager: eager,
1138
- shareScope: shareScope,
1139
- import: sharedImport
1140
- };
1141
- return sum;
1142
- }, {});
1143
- return {
1144
- shared: shared,
1145
- shareScope: this.options.shareScope || 'default'
1146
- };
1147
- }
1148
- },
1149
- {
1150
- key: "findPkg",
1151
- value: function findPkg1(name, shareConfig) {
1152
- try {
1153
- var pkgPath = '';
1154
- var depName = name;
1155
- if (shareConfig.import) {
1156
- if (path__default["default"].isAbsolute(shareConfig.import)) {
1157
- pkgPath = shareConfig.import;
1158
- } else if (shareConfig.import.startsWith('.')) {
1159
- pkgPath = path__default["default"].resolve(process.cwd(), shareConfig.import);
1160
- }
1161
- } else {
1162
- if (shareConfig.packageName) {
1163
- depName = shareConfig.packageName;
1164
- }
1165
- }
1166
- pkgPath = pkgPath || require.resolve(depName, {
1167
- paths: [
1168
- process.cwd()
1169
- ]
1170
- });
1171
- var pkgJsonPath = finder__default["default"].sync(pkgPath);
1172
- return {
1173
- pkg: JSON.parse(fs__default$1["default"].readFileSync(pkgJsonPath, 'utf-8')),
1174
- path: '',
1175
- pkgPath: ''
1176
- };
1177
- } catch (err) {
1178
- return {
1179
- pkg: {},
1180
- path: '',
1181
- pkgPath: ''
1182
- };
1183
- }
1184
- }
1185
- },
1186
- {
1187
- key: "transformSharedConfig",
1188
- value: function transformSharedConfig(sharedConfig) {
1189
- var defaultSharedConfig = {
1190
- singleton: true,
1191
- requiredVersion: undefined,
1192
- shareScope: 'default'
1193
- };
1194
- return _object_spread({}, defaultSharedConfig, sharedConfig);
1195
- }
1196
- },
1197
- {
1198
- key: "normalizeOptions",
1199
- value: function normalizeOptions(options) {
1200
- var _this = this;
1201
- var normalizedShared = {};
1202
- var sharedOptions = parseOptions(options, function(item, key) {
1203
- if (typeof item !== 'string') throw new Error('Unexpected array in shared');
1204
- var config = item === key || !isRequiredVersion(item) ? {
1205
- import: item
1206
- } : {
1207
- import: key,
1208
- requiredVersion: item
1209
- };
1210
- return config;
1211
- }, function(item) {
1212
- return item;
1213
- });
1214
- sharedOptions.forEach(function(item) {
1215
- var _item = _sliced_to_array(item, 2), sharedName = _item[0], sharedOptions = _item[1];
1216
- var pkgInfo = _this.findPkg(sharedName, sharedOptions);
1217
- var sharedConfig = _this.transformSharedConfig(sharedOptions[sharedName]);
1218
- normalizedShared[sharedName] = _object_spread_props(_object_spread({}, sharedConfig), {
1219
- requiredVersion: typeof sharedConfig.requiredVersion !== 'undefined' ? sharedConfig.requiredVersion : "^".concat(pkgInfo.pkg['version']),
1220
- name: sharedName,
1221
- version: pkgInfo.pkg['version'],
1222
- eager: Boolean(sharedConfig.eager)
1223
- });
1224
- });
1225
- this.normalizedOptions = normalizedShared;
1226
- }
1227
- },
1228
- {
1229
- key: "init",
1230
- value: function init(options) {
1231
- this.setOptions(options);
1232
- this.normalizeOptions(options.shared);
1233
- }
1234
- }
1235
- ]);
1236
- return SharedManager;
1237
- }(BasicPluginOptionsManager);
470
+ };
1238
471
 
1239
472
  var types = /*#__PURE__*/Object.freeze({
1240
473
  __proto__: null