@module-federation/managers 0.2.3 → 0.2.4

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