@module-federation/managers 0.1.11 → 0.1.13

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
@@ -81,7 +81,88 @@ var BasicPluginOptionsManager = /*#__PURE__*/ function() {
81
81
  return BasicPluginOptionsManager;
82
82
  }();
83
83
 
84
- var LOCAL_BUILD_VERSION = "local";
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
+ }
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;
113
+ }
114
+ return obj;
115
+ }
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
+
165
+ var LOCAL_BUILD_VERSION = 'local';
85
166
 
86
167
  function _array_like_to_array$2(arr, len) {
87
168
  if (len == null || len > arr.length) len = arr.length;
@@ -135,7 +216,7 @@ function processFn(options, normalizeSimple, normalizeOptions, fn) {
135
216
  try {
136
217
  for(var _iterator = Object.entries(obj)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
137
218
  var _step_value = _sliced_to_array$2(_step.value, 2), key = _step_value[0], value = _step_value[1];
138
- if (typeof value === "string") {
219
+ if (typeof value === 'string') {
139
220
  fn(key, normalizeSimple(value, key));
140
221
  } else {
141
222
  fn(key, normalizeOptions(value, key));
@@ -161,12 +242,12 @@ function processFn(options, normalizeSimple, normalizeOptions, fn) {
161
242
  try {
162
243
  for(var _iterator = items[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
163
244
  var item = _step.value;
164
- if (typeof item === "string") {
245
+ if (typeof item === 'string') {
165
246
  fn(item, normalizeSimple(item, item));
166
- } else if (item && typeof item === "object") {
247
+ } else if (item && typeof item === 'object') {
167
248
  object(item);
168
249
  } else {
169
- throw new Error("Unexpected options format");
250
+ throw new Error('Unexpected options format');
170
251
  }
171
252
  }
172
253
  } catch (err) {
@@ -188,10 +269,10 @@ function processFn(options, normalizeSimple, normalizeOptions, fn) {
188
269
  return;
189
270
  } else if (Array.isArray(options)) {
190
271
  array(options);
191
- } else if (typeof options === "object") {
272
+ } else if (typeof options === 'object') {
192
273
  object(options);
193
274
  } else {
194
- throw new Error("Unexpected options format");
275
+ throw new Error('Unexpected options format');
195
276
  }
196
277
  }
197
278
  function parseOptions(options, normalizeSimple, normalizeOptions) {
@@ -205,10 +286,17 @@ function parseOptions(options, normalizeSimple, normalizeOptions) {
205
286
  return items;
206
287
  }
207
288
  function getBuildVersion() {
208
- return process.env["MF_BUILD_VERSION"] || LOCAL_BUILD_VERSION;
289
+ if (process.env['MF_BUILD_VERSION']) {
290
+ return process.env['MF_BUILD_VERSION'];
291
+ }
292
+ var pkg = new PKGJsonManager().readPKGJson();
293
+ if ((pkg === null || pkg === void 0 ? void 0 : pkg['version']) && typeof pkg['version'] === 'string') {
294
+ return pkg['version'];
295
+ }
296
+ return LOCAL_BUILD_VERSION;
209
297
  }
210
298
  function getBuildName() {
211
- return process.env["MF_BUILD_NAME"];
299
+ return process.env['MF_BUILD_NAME'];
212
300
  }
213
301
  // RegExp for version string
214
302
  var VERSION_PATTERN_REGEXP = /^([\d^=v<>~]|[*xX]$)/;
@@ -241,12 +329,12 @@ function _assert_this_initialized$2(self) {
241
329
  }
242
330
  return self;
243
331
  }
244
- function _class_call_check$3(instance, Constructor) {
332
+ function _class_call_check$2(instance, Constructor) {
245
333
  if (!(instance instanceof Constructor)) {
246
334
  throw new TypeError("Cannot call a class as a function");
247
335
  }
248
336
  }
249
- function _defineProperties$3(target, props) {
337
+ function _defineProperties$2(target, props) {
250
338
  for(var i = 0; i < props.length; i++){
251
339
  var descriptor = props[i];
252
340
  descriptor.enumerable = descriptor.enumerable || false;
@@ -255,12 +343,12 @@ function _defineProperties$3(target, props) {
255
343
  Object.defineProperty(target, descriptor.key, descriptor);
256
344
  }
257
345
  }
258
- function _create_class$3(Constructor, protoProps, staticProps) {
259
- if (protoProps) _defineProperties$3(Constructor.prototype, protoProps);
260
- if (staticProps) _defineProperties$3(Constructor, staticProps);
346
+ function _create_class$2(Constructor, protoProps, staticProps) {
347
+ if (protoProps) _defineProperties$2(Constructor.prototype, protoProps);
348
+ if (staticProps) _defineProperties$2(Constructor, staticProps);
261
349
  return Constructor;
262
350
  }
263
- function _define_property$3(obj, key, value) {
351
+ function _define_property$2(obj, key, value) {
264
352
  if (key in obj) {
265
353
  Object.defineProperty(obj, key, {
266
354
  value: value,
@@ -381,9 +469,9 @@ function _create_super$2(Derived) {
381
469
  };
382
470
  }
383
471
  function normalizeExposeModuleName(exposeKey) {
384
- var relativePath = path__default["default"].relative(".", exposeKey);
472
+ var relativePath = path__default["default"].relative('.', exposeKey);
385
473
  if (!relativePath) {
386
- return "ExposeEntry";
474
+ return 'ExposeEntry';
387
475
  }
388
476
  return relativePath;
389
477
  }
@@ -391,14 +479,14 @@ var ContainerManager = /*#__PURE__*/ function(BasicPluginOptionsManager) {
391
479
  _inherits$2(ContainerManager, BasicPluginOptionsManager);
392
480
  var _super = _create_super$2(ContainerManager);
393
481
  function ContainerManager() {
394
- _class_call_check$3(this, ContainerManager);
482
+ _class_call_check$2(this, ContainerManager);
395
483
  var _this;
396
484
  _this = _super.apply(this, arguments);
397
- _define_property$3(_assert_this_initialized$2(_this), "_manifestModuleInfos", void 0);
398
- _define_property$3(_assert_this_initialized$2(_this), "_parsedOptions", void 0);
485
+ _define_property$2(_assert_this_initialized$2(_this), "_manifestModuleInfos", void 0);
486
+ _define_property$2(_assert_this_initialized$2(_this), "_parsedOptions", void 0);
399
487
  return _this;
400
488
  }
401
- _create_class$3(ContainerManager, [
489
+ _create_class$2(ContainerManager, [
402
490
  {
403
491
  key: "enable",
404
492
  get: function get() {
@@ -410,10 +498,10 @@ var ContainerManager = /*#__PURE__*/ function(BasicPluginOptionsManager) {
410
498
  get: function get() {
411
499
  var _this_options = this.options, name = _this_options.name, library = _this_options.library;
412
500
  if (library) {
413
- if (typeof library.name === "string") {
501
+ if (typeof library.name === 'string') {
414
502
  return library.name;
415
503
  }
416
- return undefined;
504
+ return name;
417
505
  }
418
506
  return name;
419
507
  }
@@ -481,7 +569,7 @@ var ContainerManager = /*#__PURE__*/ function(BasicPluginOptionsManager) {
481
569
  var _item = _sliced_to_array$1(item, 2), exposeKey = _item[0], exposeObject = _item[1];
482
570
  sum[exposeKey] = [];
483
571
  exposeObject.import.forEach(function(item) {
484
- var relativePath = path__default["default"].relative(".", item.replace(path__default["default"].extname(item), ""));
572
+ var relativePath = path__default["default"].relative('.', item.replace(path__default["default"].extname(item), ''));
485
573
  sum[exposeKey].push(relativePath);
486
574
  });
487
575
  return sum;
@@ -525,7 +613,7 @@ var ContainerManager = /*#__PURE__*/ function(BasicPluginOptionsManager) {
525
613
  get: // { '.' : './src/Button.jsx' } => { index: ['./src/Button.jsx'] }
526
614
  function get() {
527
615
  return Object.values(this.manifestModuleInfos).reduce(function(sum, cur) {
528
- var entry = cur.name === "ExposeEntry" ? "index" : cur.name.slice(0, 1).toLowerCase() + cur.name.slice(1);
616
+ var entry = cur.name === 'ExposeEntry' ? 'index' : cur.name.slice(0, 1).toLowerCase() + cur.name.slice(1);
529
617
  sum[entry] = cur.file;
530
618
  return sum;
531
619
  }, {});
@@ -574,87 +662,6 @@ var ContainerManager = /*#__PURE__*/ function(BasicPluginOptionsManager) {
574
662
  return ContainerManager;
575
663
  }(BasicPluginOptionsManager);
576
664
 
577
- function _class_call_check$2(instance, Constructor) {
578
- if (!(instance instanceof Constructor)) {
579
- throw new TypeError("Cannot call a class as a function");
580
- }
581
- }
582
- function _defineProperties$2(target, props) {
583
- for(var i = 0; i < props.length; i++){
584
- var descriptor = props[i];
585
- descriptor.enumerable = descriptor.enumerable || false;
586
- descriptor.configurable = true;
587
- if ("value" in descriptor) descriptor.writable = true;
588
- Object.defineProperty(target, descriptor.key, descriptor);
589
- }
590
- }
591
- function _create_class$2(Constructor, protoProps, staticProps) {
592
- if (protoProps) _defineProperties$2(Constructor.prototype, protoProps);
593
- if (staticProps) _defineProperties$2(Constructor, staticProps);
594
- return Constructor;
595
- }
596
- function _define_property$2(obj, key, value) {
597
- if (key in obj) {
598
- Object.defineProperty(obj, key, {
599
- value: value,
600
- enumerable: true,
601
- configurable: true,
602
- writable: true
603
- });
604
- } else {
605
- obj[key] = value;
606
- }
607
- return obj;
608
- }
609
- var PKGJsonManager = /*#__PURE__*/ function() {
610
- function PKGJsonManager() {
611
- _class_call_check$2(this, PKGJsonManager);
612
- _define_property$2(this, "_pkg", void 0);
613
- }
614
- _create_class$2(PKGJsonManager, [
615
- {
616
- key: "setPKGJson",
617
- value: function setPKGJson(pkg) {
618
- this._pkg = pkg;
619
- }
620
- },
621
- {
622
- key: "readPKGJson",
623
- value: function readPKGJson() {
624
- var ctx = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : process.cwd();
625
- if (this._pkg) {
626
- return this._pkg;
627
- }
628
- try {
629
- // eslint-disable-next-line no-restricted-globals
630
- var pkg = JSON.parse(fs__default["default"].readFileSync(path__default["default"].resolve(ctx, "package.json"), "utf8"));
631
- this._pkg = pkg;
632
- return pkg;
633
- } catch (_err) {
634
- try {
635
- var pkg1 = finder__default["default"].sync(ctx);
636
- this._pkg = pkg1;
637
- return pkg1;
638
- } catch (err) {
639
- console.error(err);
640
- return {};
641
- }
642
- }
643
- }
644
- },
645
- {
646
- key: "getExposeGarfishModuleType",
647
- value: function getExposeGarfishModuleType() {
648
- var ctx = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : process.cwd();
649
- var _pkg_mf;
650
- var pkg = this.readPKGJson(ctx);
651
- 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;
652
- }
653
- }
654
- ]);
655
- return PKGJsonManager;
656
- }();
657
-
658
665
  function _assert_this_initialized$1(self) {
659
666
  if (self === void 0) {
660
667
  throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
@@ -793,10 +800,10 @@ function _create_super$1(Derived) {
793
800
  };
794
801
  }
795
802
  function getEntry(remoteObj) {
796
- if (typeof remoteObj === "string") {
803
+ if (typeof remoteObj === 'string') {
797
804
  return remoteObj;
798
805
  }
799
- if (typeof remoteObj.external === "string") {
806
+ if (typeof remoteObj.external === 'string') {
800
807
  return remoteObj.external;
801
808
  }
802
809
  throw new Error('Not support "array" remote value yet!');
@@ -826,7 +833,7 @@ var RemoteManager = /*#__PURE__*/ function(BasicPluginOptionsManager) {
826
833
  return Object.keys(this.normalizedOptions).reduce(function(sum, cur) {
827
834
  var normalizedOption = _this.normalizedOptions[cur];
828
835
  var curObj;
829
- if ("entry" in normalizedOption) {
836
+ if ('entry' in normalizedOption) {
830
837
  curObj = {
831
838
  entry: normalizedOption.entry,
832
839
  alias: normalizedOption.alias,
@@ -861,7 +868,7 @@ var RemoteManager = /*#__PURE__*/ function(BasicPluginOptionsManager) {
861
868
  var _this = this;
862
869
  return Object.keys(this.normalizedOptions).reduce(function(sum, remoteAlias) {
863
870
  var remoteInfo = _this.normalizedOptions[remoteAlias];
864
- sum[remoteAlias] = sdk.composeKeyWithSeparator(remoteInfo.name, "entry" in remoteInfo ? remoteInfo.entry : remoteInfo.version);
871
+ sum[remoteAlias] = sdk.composeKeyWithSeparator(remoteInfo.name, 'entry' in remoteInfo ? remoteInfo.entry : remoteInfo.version);
865
872
  return sum;
866
873
  }, {});
867
874
  }
@@ -887,7 +894,7 @@ var RemoteManager = /*#__PURE__*/ function(BasicPluginOptionsManager) {
887
894
  }
888
895
  var parsedOptions;
889
896
  try {
890
- parsedOptions = sdk.parseEntry(typeof remoteInfo === "string" ? remoteInfo : getEntry(remoteInfo), "", "@");
897
+ parsedOptions = sdk.parseEntry(typeof remoteInfo === 'string' ? remoteInfo : getEntry(remoteInfo), '', '@');
891
898
  } catch (e) {
892
899
  // noop
893
900
  }
@@ -896,7 +903,7 @@ var RemoteManager = /*#__PURE__*/ function(BasicPluginOptionsManager) {
896
903
  }
897
904
  sum[remoteAlias] = _object_spread_props$1(_object_spread$1({}, parsedOptions), {
898
905
  alias: remoteAlias,
899
- shareScope: typeof remoteInfo === "object" ? remoteInfo.shareScope || "default" : "default"
906
+ shareScope: typeof remoteInfo === 'object' ? remoteInfo.shareScope || 'default' : 'default'
900
907
  });
901
908
  return sum;
902
909
  }, {});
@@ -1130,7 +1137,7 @@ var SharedManager = /*#__PURE__*/ function(BasicPluginOptionsManager) {
1130
1137
  }, {});
1131
1138
  return {
1132
1139
  shared: shared,
1133
- shareScope: this.options.shareScope || "default"
1140
+ shareScope: this.options.shareScope || 'default'
1134
1141
  };
1135
1142
  }
1136
1143
  },
@@ -1138,12 +1145,12 @@ var SharedManager = /*#__PURE__*/ function(BasicPluginOptionsManager) {
1138
1145
  key: "findPkg",
1139
1146
  value: function findPkg1(name, shareConfig) {
1140
1147
  try {
1141
- var pkgPath = "";
1148
+ var pkgPath = '';
1142
1149
  var depName = name;
1143
1150
  if (shareConfig.import) {
1144
1151
  if (path__default["default"].isAbsolute(shareConfig.import)) {
1145
1152
  pkgPath = shareConfig.import;
1146
- } else if (shareConfig.import.startsWith(".")) {
1153
+ } else if (shareConfig.import.startsWith('.')) {
1147
1154
  pkgPath = path__default["default"].resolve(process.cwd(), shareConfig.import);
1148
1155
  }
1149
1156
  } else {
@@ -1158,15 +1165,15 @@ var SharedManager = /*#__PURE__*/ function(BasicPluginOptionsManager) {
1158
1165
  });
1159
1166
  var pkgJsonPath = finder__default["default"].sync(pkgPath);
1160
1167
  return {
1161
- pkg: JSON.parse(fs__default$1["default"].readFileSync(pkgJsonPath, "utf-8")),
1162
- path: "",
1163
- pkgPath: ""
1168
+ pkg: JSON.parse(fs__default$1["default"].readFileSync(pkgJsonPath, 'utf-8')),
1169
+ path: '',
1170
+ pkgPath: ''
1164
1171
  };
1165
1172
  } catch (err) {
1166
1173
  return {
1167
1174
  pkg: {},
1168
- path: "",
1169
- pkgPath: ""
1175
+ path: '',
1176
+ pkgPath: ''
1170
1177
  };
1171
1178
  }
1172
1179
  }
@@ -1177,7 +1184,7 @@ var SharedManager = /*#__PURE__*/ function(BasicPluginOptionsManager) {
1177
1184
  var defaultSharedConfig = {
1178
1185
  singleton: true,
1179
1186
  requiredVersion: undefined,
1180
- shareScope: "default"
1187
+ shareScope: 'default'
1181
1188
  };
1182
1189
  return _object_spread({}, defaultSharedConfig, sharedConfig);
1183
1190
  }
@@ -1188,7 +1195,7 @@ var SharedManager = /*#__PURE__*/ function(BasicPluginOptionsManager) {
1188
1195
  var _this = this;
1189
1196
  var normalizedShared = {};
1190
1197
  var sharedOptions = parseOptions(options, function(item, key) {
1191
- if (typeof item !== "string") throw new Error("Unexpected array in shared");
1198
+ if (typeof item !== 'string') throw new Error('Unexpected array in shared');
1192
1199
  var config = item === key || !isRequiredVersion(item) ? {
1193
1200
  import: item
1194
1201
  } : {
@@ -1204,9 +1211,9 @@ var SharedManager = /*#__PURE__*/ function(BasicPluginOptionsManager) {
1204
1211
  var pkgInfo = _this.findPkg(sharedName, sharedOptions);
1205
1212
  var sharedConfig = _this.transformSharedConfig(sharedOptions[sharedName]);
1206
1213
  normalizedShared[sharedName] = _object_spread_props(_object_spread({}, sharedConfig), {
1207
- requiredVersion: typeof sharedConfig.requiredVersion !== "undefined" ? sharedConfig.requiredVersion : "^".concat(pkgInfo.pkg["version"]),
1214
+ requiredVersion: typeof sharedConfig.requiredVersion !== 'undefined' ? sharedConfig.requiredVersion : "^".concat(pkgInfo.pkg['version']),
1208
1215
  name: sharedName,
1209
- version: pkgInfo.pkg["version"],
1216
+ version: pkgInfo.pkg['version'],
1210
1217
  eager: Boolean(sharedConfig.eager)
1211
1218
  });
1212
1219
  });
package/dist/index.esm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import path from 'path';
2
- import { generateExposeFilename, MFModuleType, composeKeyWithSeparator, parseEntry } from '@module-federation/sdk';
2
+ import { MFModuleType, generateExposeFilename, composeKeyWithSeparator, parseEntry } from '@module-federation/sdk';
3
3
  import finder from 'find-pkg';
4
4
  import fs from 'fs';
5
5
  import fs$1 from 'fs-extra';
@@ -70,7 +70,88 @@ var BasicPluginOptionsManager = /*#__PURE__*/ function() {
70
70
  return BasicPluginOptionsManager;
71
71
  }();
72
72
 
73
- var LOCAL_BUILD_VERSION = "local";
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
+ }
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;
102
+ }
103
+ return obj;
104
+ }
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
+
154
+ var LOCAL_BUILD_VERSION = 'local';
74
155
 
75
156
  function _array_like_to_array$2(arr, len) {
76
157
  if (len == null || len > arr.length) len = arr.length;
@@ -124,7 +205,7 @@ function processFn(options, normalizeSimple, normalizeOptions, fn) {
124
205
  try {
125
206
  for(var _iterator = Object.entries(obj)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
126
207
  var _step_value = _sliced_to_array$2(_step.value, 2), key = _step_value[0], value = _step_value[1];
127
- if (typeof value === "string") {
208
+ if (typeof value === 'string') {
128
209
  fn(key, normalizeSimple(value, key));
129
210
  } else {
130
211
  fn(key, normalizeOptions(value, key));
@@ -150,12 +231,12 @@ function processFn(options, normalizeSimple, normalizeOptions, fn) {
150
231
  try {
151
232
  for(var _iterator = items[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
152
233
  var item = _step.value;
153
- if (typeof item === "string") {
234
+ if (typeof item === 'string') {
154
235
  fn(item, normalizeSimple(item, item));
155
- } else if (item && typeof item === "object") {
236
+ } else if (item && typeof item === 'object') {
156
237
  object(item);
157
238
  } else {
158
- throw new Error("Unexpected options format");
239
+ throw new Error('Unexpected options format');
159
240
  }
160
241
  }
161
242
  } catch (err) {
@@ -177,10 +258,10 @@ function processFn(options, normalizeSimple, normalizeOptions, fn) {
177
258
  return;
178
259
  } else if (Array.isArray(options)) {
179
260
  array(options);
180
- } else if (typeof options === "object") {
261
+ } else if (typeof options === 'object') {
181
262
  object(options);
182
263
  } else {
183
- throw new Error("Unexpected options format");
264
+ throw new Error('Unexpected options format');
184
265
  }
185
266
  }
186
267
  function parseOptions(options, normalizeSimple, normalizeOptions) {
@@ -194,10 +275,17 @@ function parseOptions(options, normalizeSimple, normalizeOptions) {
194
275
  return items;
195
276
  }
196
277
  function getBuildVersion() {
197
- return process.env["MF_BUILD_VERSION"] || LOCAL_BUILD_VERSION;
278
+ if (process.env['MF_BUILD_VERSION']) {
279
+ return process.env['MF_BUILD_VERSION'];
280
+ }
281
+ var pkg = new PKGJsonManager().readPKGJson();
282
+ if ((pkg === null || pkg === void 0 ? void 0 : pkg['version']) && typeof pkg['version'] === 'string') {
283
+ return pkg['version'];
284
+ }
285
+ return LOCAL_BUILD_VERSION;
198
286
  }
199
287
  function getBuildName() {
200
- return process.env["MF_BUILD_NAME"];
288
+ return process.env['MF_BUILD_NAME'];
201
289
  }
202
290
  // RegExp for version string
203
291
  var VERSION_PATTERN_REGEXP = /^([\d^=v<>~]|[*xX]$)/;
@@ -230,12 +318,12 @@ function _assert_this_initialized$2(self) {
230
318
  }
231
319
  return self;
232
320
  }
233
- function _class_call_check$3(instance, Constructor) {
321
+ function _class_call_check$2(instance, Constructor) {
234
322
  if (!(instance instanceof Constructor)) {
235
323
  throw new TypeError("Cannot call a class as a function");
236
324
  }
237
325
  }
238
- function _defineProperties$3(target, props) {
326
+ function _defineProperties$2(target, props) {
239
327
  for(var i = 0; i < props.length; i++){
240
328
  var descriptor = props[i];
241
329
  descriptor.enumerable = descriptor.enumerable || false;
@@ -244,12 +332,12 @@ function _defineProperties$3(target, props) {
244
332
  Object.defineProperty(target, descriptor.key, descriptor);
245
333
  }
246
334
  }
247
- function _create_class$3(Constructor, protoProps, staticProps) {
248
- if (protoProps) _defineProperties$3(Constructor.prototype, protoProps);
249
- if (staticProps) _defineProperties$3(Constructor, staticProps);
335
+ function _create_class$2(Constructor, protoProps, staticProps) {
336
+ if (protoProps) _defineProperties$2(Constructor.prototype, protoProps);
337
+ if (staticProps) _defineProperties$2(Constructor, staticProps);
250
338
  return Constructor;
251
339
  }
252
- function _define_property$3(obj, key, value) {
340
+ function _define_property$2(obj, key, value) {
253
341
  if (key in obj) {
254
342
  Object.defineProperty(obj, key, {
255
343
  value: value,
@@ -370,9 +458,9 @@ function _create_super$2(Derived) {
370
458
  };
371
459
  }
372
460
  function normalizeExposeModuleName(exposeKey) {
373
- var relativePath = path.relative(".", exposeKey);
461
+ var relativePath = path.relative('.', exposeKey);
374
462
  if (!relativePath) {
375
- return "ExposeEntry";
463
+ return 'ExposeEntry';
376
464
  }
377
465
  return relativePath;
378
466
  }
@@ -380,14 +468,14 @@ var ContainerManager = /*#__PURE__*/ function(BasicPluginOptionsManager) {
380
468
  _inherits$2(ContainerManager, BasicPluginOptionsManager);
381
469
  var _super = _create_super$2(ContainerManager);
382
470
  function ContainerManager() {
383
- _class_call_check$3(this, ContainerManager);
471
+ _class_call_check$2(this, ContainerManager);
384
472
  var _this;
385
473
  _this = _super.apply(this, arguments);
386
- _define_property$3(_assert_this_initialized$2(_this), "_manifestModuleInfos", void 0);
387
- _define_property$3(_assert_this_initialized$2(_this), "_parsedOptions", void 0);
474
+ _define_property$2(_assert_this_initialized$2(_this), "_manifestModuleInfos", void 0);
475
+ _define_property$2(_assert_this_initialized$2(_this), "_parsedOptions", void 0);
388
476
  return _this;
389
477
  }
390
- _create_class$3(ContainerManager, [
478
+ _create_class$2(ContainerManager, [
391
479
  {
392
480
  key: "enable",
393
481
  get: function get() {
@@ -399,10 +487,10 @@ var ContainerManager = /*#__PURE__*/ function(BasicPluginOptionsManager) {
399
487
  get: function get() {
400
488
  var _this_options = this.options, name = _this_options.name, library = _this_options.library;
401
489
  if (library) {
402
- if (typeof library.name === "string") {
490
+ if (typeof library.name === 'string') {
403
491
  return library.name;
404
492
  }
405
- return undefined;
493
+ return name;
406
494
  }
407
495
  return name;
408
496
  }
@@ -470,7 +558,7 @@ var ContainerManager = /*#__PURE__*/ function(BasicPluginOptionsManager) {
470
558
  var _item = _sliced_to_array$1(item, 2), exposeKey = _item[0], exposeObject = _item[1];
471
559
  sum[exposeKey] = [];
472
560
  exposeObject.import.forEach(function(item) {
473
- var relativePath = path.relative(".", item.replace(path.extname(item), ""));
561
+ var relativePath = path.relative('.', item.replace(path.extname(item), ''));
474
562
  sum[exposeKey].push(relativePath);
475
563
  });
476
564
  return sum;
@@ -514,7 +602,7 @@ var ContainerManager = /*#__PURE__*/ function(BasicPluginOptionsManager) {
514
602
  get: // { '.' : './src/Button.jsx' } => { index: ['./src/Button.jsx'] }
515
603
  function get() {
516
604
  return Object.values(this.manifestModuleInfos).reduce(function(sum, cur) {
517
- var entry = cur.name === "ExposeEntry" ? "index" : cur.name.slice(0, 1).toLowerCase() + cur.name.slice(1);
605
+ var entry = cur.name === 'ExposeEntry' ? 'index' : cur.name.slice(0, 1).toLowerCase() + cur.name.slice(1);
518
606
  sum[entry] = cur.file;
519
607
  return sum;
520
608
  }, {});
@@ -563,87 +651,6 @@ var ContainerManager = /*#__PURE__*/ function(BasicPluginOptionsManager) {
563
651
  return ContainerManager;
564
652
  }(BasicPluginOptionsManager);
565
653
 
566
- function _class_call_check$2(instance, Constructor) {
567
- if (!(instance instanceof Constructor)) {
568
- throw new TypeError("Cannot call a class as a function");
569
- }
570
- }
571
- function _defineProperties$2(target, props) {
572
- for(var i = 0; i < props.length; i++){
573
- var descriptor = props[i];
574
- descriptor.enumerable = descriptor.enumerable || false;
575
- descriptor.configurable = true;
576
- if ("value" in descriptor) descriptor.writable = true;
577
- Object.defineProperty(target, descriptor.key, descriptor);
578
- }
579
- }
580
- function _create_class$2(Constructor, protoProps, staticProps) {
581
- if (protoProps) _defineProperties$2(Constructor.prototype, protoProps);
582
- if (staticProps) _defineProperties$2(Constructor, staticProps);
583
- return Constructor;
584
- }
585
- function _define_property$2(obj, key, value) {
586
- if (key in obj) {
587
- Object.defineProperty(obj, key, {
588
- value: value,
589
- enumerable: true,
590
- configurable: true,
591
- writable: true
592
- });
593
- } else {
594
- obj[key] = value;
595
- }
596
- return obj;
597
- }
598
- var PKGJsonManager = /*#__PURE__*/ function() {
599
- function PKGJsonManager() {
600
- _class_call_check$2(this, PKGJsonManager);
601
- _define_property$2(this, "_pkg", void 0);
602
- }
603
- _create_class$2(PKGJsonManager, [
604
- {
605
- key: "setPKGJson",
606
- value: function setPKGJson(pkg) {
607
- this._pkg = pkg;
608
- }
609
- },
610
- {
611
- key: "readPKGJson",
612
- value: function readPKGJson() {
613
- var ctx = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : process.cwd();
614
- if (this._pkg) {
615
- return this._pkg;
616
- }
617
- try {
618
- // eslint-disable-next-line no-restricted-globals
619
- var pkg = JSON.parse(fs.readFileSync(path.resolve(ctx, "package.json"), "utf8"));
620
- this._pkg = pkg;
621
- return pkg;
622
- } catch (_err) {
623
- try {
624
- var pkg1 = finder.sync(ctx);
625
- this._pkg = pkg1;
626
- return pkg1;
627
- } catch (err) {
628
- console.error(err);
629
- return {};
630
- }
631
- }
632
- }
633
- },
634
- {
635
- key: "getExposeGarfishModuleType",
636
- value: function getExposeGarfishModuleType() {
637
- var ctx = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : process.cwd();
638
- var _pkg_mf;
639
- var pkg = this.readPKGJson(ctx);
640
- 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;
641
- }
642
- }
643
- ]);
644
- return PKGJsonManager;
645
- }();
646
-
647
654
  function _assert_this_initialized$1(self) {
648
655
  if (self === void 0) {
649
656
  throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
@@ -782,10 +789,10 @@ function _create_super$1(Derived) {
782
789
  };
783
790
  }
784
791
  function getEntry(remoteObj) {
785
- if (typeof remoteObj === "string") {
792
+ if (typeof remoteObj === 'string') {
786
793
  return remoteObj;
787
794
  }
788
- if (typeof remoteObj.external === "string") {
795
+ if (typeof remoteObj.external === 'string') {
789
796
  return remoteObj.external;
790
797
  }
791
798
  throw new Error('Not support "array" remote value yet!');
@@ -815,7 +822,7 @@ var RemoteManager = /*#__PURE__*/ function(BasicPluginOptionsManager) {
815
822
  return Object.keys(this.normalizedOptions).reduce(function(sum, cur) {
816
823
  var normalizedOption = _this.normalizedOptions[cur];
817
824
  var curObj;
818
- if ("entry" in normalizedOption) {
825
+ if ('entry' in normalizedOption) {
819
826
  curObj = {
820
827
  entry: normalizedOption.entry,
821
828
  alias: normalizedOption.alias,
@@ -850,7 +857,7 @@ var RemoteManager = /*#__PURE__*/ function(BasicPluginOptionsManager) {
850
857
  var _this = this;
851
858
  return Object.keys(this.normalizedOptions).reduce(function(sum, remoteAlias) {
852
859
  var remoteInfo = _this.normalizedOptions[remoteAlias];
853
- sum[remoteAlias] = composeKeyWithSeparator(remoteInfo.name, "entry" in remoteInfo ? remoteInfo.entry : remoteInfo.version);
860
+ sum[remoteAlias] = composeKeyWithSeparator(remoteInfo.name, 'entry' in remoteInfo ? remoteInfo.entry : remoteInfo.version);
854
861
  return sum;
855
862
  }, {});
856
863
  }
@@ -876,7 +883,7 @@ var RemoteManager = /*#__PURE__*/ function(BasicPluginOptionsManager) {
876
883
  }
877
884
  var parsedOptions;
878
885
  try {
879
- parsedOptions = parseEntry(typeof remoteInfo === "string" ? remoteInfo : getEntry(remoteInfo), "", "@");
886
+ parsedOptions = parseEntry(typeof remoteInfo === 'string' ? remoteInfo : getEntry(remoteInfo), '', '@');
880
887
  } catch (e) {
881
888
  // noop
882
889
  }
@@ -885,7 +892,7 @@ var RemoteManager = /*#__PURE__*/ function(BasicPluginOptionsManager) {
885
892
  }
886
893
  sum[remoteAlias] = _object_spread_props$1(_object_spread$1({}, parsedOptions), {
887
894
  alias: remoteAlias,
888
- shareScope: typeof remoteInfo === "object" ? remoteInfo.shareScope || "default" : "default"
895
+ shareScope: typeof remoteInfo === 'object' ? remoteInfo.shareScope || 'default' : 'default'
889
896
  });
890
897
  return sum;
891
898
  }, {});
@@ -1119,7 +1126,7 @@ var SharedManager = /*#__PURE__*/ function(BasicPluginOptionsManager) {
1119
1126
  }, {});
1120
1127
  return {
1121
1128
  shared: shared,
1122
- shareScope: this.options.shareScope || "default"
1129
+ shareScope: this.options.shareScope || 'default'
1123
1130
  };
1124
1131
  }
1125
1132
  },
@@ -1127,12 +1134,12 @@ var SharedManager = /*#__PURE__*/ function(BasicPluginOptionsManager) {
1127
1134
  key: "findPkg",
1128
1135
  value: function findPkg1(name, shareConfig) {
1129
1136
  try {
1130
- var pkgPath = "";
1137
+ var pkgPath = '';
1131
1138
  var depName = name;
1132
1139
  if (shareConfig.import) {
1133
1140
  if (path.isAbsolute(shareConfig.import)) {
1134
1141
  pkgPath = shareConfig.import;
1135
- } else if (shareConfig.import.startsWith(".")) {
1142
+ } else if (shareConfig.import.startsWith('.')) {
1136
1143
  pkgPath = path.resolve(process.cwd(), shareConfig.import);
1137
1144
  }
1138
1145
  } else {
@@ -1147,15 +1154,15 @@ var SharedManager = /*#__PURE__*/ function(BasicPluginOptionsManager) {
1147
1154
  });
1148
1155
  var pkgJsonPath = finder.sync(pkgPath);
1149
1156
  return {
1150
- pkg: JSON.parse(fs$1.readFileSync(pkgJsonPath, "utf-8")),
1151
- path: "",
1152
- pkgPath: ""
1157
+ pkg: JSON.parse(fs$1.readFileSync(pkgJsonPath, 'utf-8')),
1158
+ path: '',
1159
+ pkgPath: ''
1153
1160
  };
1154
1161
  } catch (err) {
1155
1162
  return {
1156
1163
  pkg: {},
1157
- path: "",
1158
- pkgPath: ""
1164
+ path: '',
1165
+ pkgPath: ''
1159
1166
  };
1160
1167
  }
1161
1168
  }
@@ -1166,7 +1173,7 @@ var SharedManager = /*#__PURE__*/ function(BasicPluginOptionsManager) {
1166
1173
  var defaultSharedConfig = {
1167
1174
  singleton: true,
1168
1175
  requiredVersion: undefined,
1169
- shareScope: "default"
1176
+ shareScope: 'default'
1170
1177
  };
1171
1178
  return _object_spread({}, defaultSharedConfig, sharedConfig);
1172
1179
  }
@@ -1177,7 +1184,7 @@ var SharedManager = /*#__PURE__*/ function(BasicPluginOptionsManager) {
1177
1184
  var _this = this;
1178
1185
  var normalizedShared = {};
1179
1186
  var sharedOptions = parseOptions(options, function(item, key) {
1180
- if (typeof item !== "string") throw new Error("Unexpected array in shared");
1187
+ if (typeof item !== 'string') throw new Error('Unexpected array in shared');
1181
1188
  var config = item === key || !isRequiredVersion(item) ? {
1182
1189
  import: item
1183
1190
  } : {
@@ -1193,9 +1200,9 @@ var SharedManager = /*#__PURE__*/ function(BasicPluginOptionsManager) {
1193
1200
  var pkgInfo = _this.findPkg(sharedName, sharedOptions);
1194
1201
  var sharedConfig = _this.transformSharedConfig(sharedOptions[sharedName]);
1195
1202
  normalizedShared[sharedName] = _object_spread_props(_object_spread({}, sharedConfig), {
1196
- requiredVersion: typeof sharedConfig.requiredVersion !== "undefined" ? sharedConfig.requiredVersion : "^".concat(pkgInfo.pkg["version"]),
1203
+ requiredVersion: typeof sharedConfig.requiredVersion !== 'undefined' ? sharedConfig.requiredVersion : "^".concat(pkgInfo.pkg['version']),
1197
1204
  name: sharedName,
1198
- version: pkgInfo.pkg["version"],
1205
+ version: pkgInfo.pkg['version'],
1199
1206
  eager: Boolean(sharedConfig.eager)
1200
1207
  });
1201
1208
  });
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/managers",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "license": "MIT",
5
5
  "description": "Provide managers for helping handle mf data .",
6
6
  "keywords": [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/managers",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "license": "MIT",
5
5
  "description": "Provide managers for helping handle mf data .",
6
6
  "keywords": [
@@ -21,7 +21,7 @@
21
21
  "dependencies": {
22
22
  "find-pkg": "2.0.0",
23
23
  "fs-extra": "9.1.0",
24
- "@module-federation/sdk": "0.1.11"
24
+ "@module-federation/sdk": "0.1.13"
25
25
  },
26
26
  "devDependencies": {
27
27
  "webpack": "5.76.0"