@module-federation/utilities 1.7.0 → 1.7.1

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.
@@ -1,113 +1,78 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.importRemote = void 0;
4
- var tslib_1 = require("tslib");
5
- var REMOTE_ENTRY_FILE = 'remoteEntry.js';
6
- var loadRemote = function (url, scope, bustRemoteEntryCache) {
7
- return new Promise(function (resolve, reject) {
8
- var timestamp = bustRemoteEntryCache ? "?t=".concat(new Date().getTime()) : '';
9
- var webpackRequire = __webpack_require__;
10
- webpackRequire.l("".concat(url).concat(timestamp), function (event) {
11
- var _a;
12
- if ((event === null || event === void 0 ? void 0 : event.type) === 'load') {
13
- // Script loaded successfully:
14
- return resolve();
15
- }
16
- var realSrc = (_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.src;
17
- var error = new Error();
18
- error.message = 'Loading script failed.\n(missing: ' + realSrc + ')';
19
- error.name = 'ScriptExternalLoadError';
20
- reject(error);
21
- }, scope);
22
- });
23
- };
24
- var initSharing = function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
25
- var webpackShareScopes;
26
- return tslib_1.__generator(this, function (_a) {
27
- switch (_a.label) {
28
- case 0:
29
- webpackShareScopes = __webpack_share_scopes__;
30
- if (!!(webpackShareScopes === null || webpackShareScopes === void 0 ? void 0 : webpackShareScopes.default)) return [3 /*break*/, 2];
31
- return [4 /*yield*/, __webpack_init_sharing__('default')];
32
- case 1:
33
- _a.sent();
34
- _a.label = 2;
35
- case 2: return [2 /*return*/];
4
+ const tslib_1 = require("tslib");
5
+ const REMOTE_ENTRY_FILE = 'remoteEntry.js';
6
+ const loadRemote = (url, scope, bustRemoteEntryCache) => new Promise((resolve, reject) => {
7
+ const timestamp = bustRemoteEntryCache ? `?t=${new Date().getTime()}` : '';
8
+ const webpackRequire = __webpack_require__;
9
+ webpackRequire.l(`${url}${timestamp}`, (event) => {
10
+ var _a;
11
+ if ((event === null || event === void 0 ? void 0 : event.type) === 'load') {
12
+ // Script loaded successfully:
13
+ return resolve();
36
14
  }
37
- });
38
- }); };
15
+ const realSrc = (_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.src;
16
+ const error = new Error();
17
+ error.message = 'Loading script failed.\n(missing: ' + realSrc + ')';
18
+ error.name = 'ScriptExternalLoadError';
19
+ reject(error);
20
+ }, scope);
21
+ });
22
+ const initSharing = () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
23
+ const webpackShareScopes = __webpack_share_scopes__;
24
+ if (!(webpackShareScopes === null || webpackShareScopes === void 0 ? void 0 : webpackShareScopes.default)) {
25
+ yield __webpack_init_sharing__('default');
26
+ }
27
+ });
39
28
  // __initialized and __initializing flags prevent some concurrent re-initialization corner cases
40
- var initContainer = function (containerScope) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
41
- var webpackShareScopes, error_1;
42
- return tslib_1.__generator(this, function (_a) {
43
- switch (_a.label) {
44
- case 0:
45
- _a.trys.push([0, 3, , 4]);
46
- webpackShareScopes = __webpack_share_scopes__;
47
- if (!(!containerScope.__initialized && !containerScope.__initializing)) return [3 /*break*/, 2];
48
- containerScope.__initializing = true;
49
- return [4 /*yield*/, containerScope.init(webpackShareScopes.default)];
50
- case 1:
51
- _a.sent();
52
- containerScope.__initialized = true;
53
- delete containerScope.__initializing;
54
- _a.label = 2;
55
- case 2: return [3 /*break*/, 4];
56
- case 3:
57
- error_1 = _a.sent();
58
- console.error(error_1);
59
- return [3 /*break*/, 4];
60
- case 4: return [2 /*return*/];
29
+ const initContainer = (containerScope) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
30
+ try {
31
+ const webpackShareScopes = __webpack_share_scopes__;
32
+ if (!containerScope.__initialized && !containerScope.__initializing) {
33
+ containerScope.__initializing = true;
34
+ yield containerScope.init(webpackShareScopes.default);
35
+ containerScope.__initialized = true;
36
+ delete containerScope.__initializing;
61
37
  }
62
- });
63
- }); };
38
+ }
39
+ catch (error) {
40
+ console.error(error);
41
+ }
42
+ });
64
43
  /*
65
44
  Dynamically import a remote module using Webpack's loading mechanism:
66
45
  https://webpack.js.org/concepts/module-federation/
67
46
  */
68
- var importRemote = function (_a) {
69
- var url = _a.url, scope = _a.scope, module = _a.module, _b = _a.remoteEntryFileName, remoteEntryFileName = _b === void 0 ? REMOTE_ENTRY_FILE : _b, _c = _a.bustRemoteEntryCache, bustRemoteEntryCache = _c === void 0 ? true : _c;
70
- return tslib_1.__awaiter(void 0, void 0, void 0, function () {
71
- var remoteScope, remoteUrl, _d, moduleFactory, moduleFactory;
72
- return tslib_1.__generator(this, function (_e) {
73
- switch (_e.label) {
74
- case 0:
75
- remoteScope = scope;
76
- if (!!window[remoteScope]) return [3 /*break*/, 6];
77
- remoteUrl = '';
78
- if (!(typeof url === 'string')) return [3 /*break*/, 1];
79
- remoteUrl = url;
80
- return [3 /*break*/, 3];
81
- case 1: return [4 /*yield*/, url()];
82
- case 2:
83
- remoteUrl = _e.sent();
84
- _e.label = 3;
85
- case 3:
86
- // Load the remote and initialize the share scope if it's empty
87
- return [4 /*yield*/, Promise.all([
88
- loadRemote("".concat(remoteUrl, "/").concat(remoteEntryFileName), scope, bustRemoteEntryCache),
89
- initSharing(),
90
- ])];
91
- case 4:
92
- // Load the remote and initialize the share scope if it's empty
93
- _e.sent();
94
- if (!window[remoteScope]) {
95
- throw new Error("Remote loaded successfully but ".concat(scope, " could not be found! Verify that the name is correct in the Webpack configuration!"));
96
- }
97
- return [4 /*yield*/, Promise.all([
98
- initContainer(window[remoteScope]),
99
- window[remoteScope].get(module.startsWith('./') ? module : "./".concat(module)),
100
- ])];
101
- case 5:
102
- _d = _e.sent(), moduleFactory = _d[1];
103
- return [2 /*return*/, moduleFactory()];
104
- case 6: return [4 /*yield*/, window[remoteScope].get(module.startsWith('./') ? module : "./".concat(module))];
105
- case 7:
106
- moduleFactory = _e.sent();
107
- return [2 /*return*/, moduleFactory()];
108
- }
109
- });
110
- });
111
- };
47
+ const importRemote = ({ url, scope, module, remoteEntryFileName = REMOTE_ENTRY_FILE, bustRemoteEntryCache = true, }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
48
+ const remoteScope = scope;
49
+ if (!window[remoteScope]) {
50
+ let remoteUrl = '';
51
+ if (typeof url === 'string') {
52
+ remoteUrl = url;
53
+ }
54
+ else {
55
+ remoteUrl = yield url();
56
+ }
57
+ // Load the remote and initialize the share scope if it's empty
58
+ yield Promise.all([
59
+ loadRemote(`${remoteUrl}/${remoteEntryFileName}`, scope, bustRemoteEntryCache),
60
+ initSharing(),
61
+ ]);
62
+ if (!window[remoteScope]) {
63
+ throw new Error(`Remote loaded successfully but ${scope} could not be found! Verify that the name is correct in the Webpack configuration!`);
64
+ }
65
+ // Initialize the container to get shared modules and get the module factory:
66
+ const [, moduleFactory] = yield Promise.all([
67
+ initContainer(window[remoteScope]),
68
+ window[remoteScope].get(module.startsWith('./') ? module : `./${module}`),
69
+ ]);
70
+ return moduleFactory();
71
+ }
72
+ else {
73
+ const moduleFactory = yield window[remoteScope].get(module.startsWith('./') ? module : `./${module}`);
74
+ return moduleFactory();
75
+ }
76
+ });
112
77
  exports.importRemote = importRemote;
113
78
  //# sourceMappingURL=importRemote.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"importRemote.js","sourceRoot":"","sources":["../../../../../packages/utilities/src/utils/importRemote.ts"],"names":[],"mappings":";;;;AAgBA,IAAM,iBAAiB,GAAG,gBAAgB,CAAC;AAE3C,IAAM,UAAU,GAAG,UACjB,GAA+B,EAC/B,KAAmC,EACnC,oBAAiE;IAEjE,OAAA,IAAI,OAAO,CAAO,UAAC,OAAO,EAAE,MAAM;QAChC,IAAM,SAAS,GAAG,oBAAoB,CAAC,CAAC,CAAC,aAAM,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC3E,IAAM,cAA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,EAAC;wBAED,qBACpB,MAAM,CAAC,WAAW,CACnB,CAAC,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,YAAK,MAAM,CAAE,CAAC,EAAA;;oBAFjD,aAAa,GAAG,SAEiC;oBACvD,sBAAO,aAAa,EAAE,EAAC;;;;CAE1B,CAAC;AA7CW,QAAA,YAAY,gBA6CvB"}
1
+ {"version":3,"file":"importRemote.js","sourceRoot":"","sources":["../../../../../packages/utilities/src/utils/importRemote.ts"],"names":[],"mappings":";;;;AAgBA,MAAM,iBAAiB,GAAG,gBAAgB,CAAC;AAE3C,MAAM,UAAU,GAAG,CACjB,GAA+B,EAC/B,KAAmC,EACnC,oBAAiE,EACjE,EAAE,CACF,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;IACpC,MAAM,SAAS,GAAG,oBAAoB,CAAC,CAAC,CAAC,MAAM,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IAC3E,MAAM,cAAc,GAAG,mBAAgD,CAAC;IACxE,cAAc,CAAC,CAAC,CACd,GAAG,GAAG,GAAG,SAAS,EAAE,EACpB,CAAC,KAAK,EAAE,EAAE;;QACR,IAAI,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,IAAI,MAAK,MAAM,EAAE;YAC1B,8BAA8B;YAC9B,OAAO,OAAO,EAAE,CAAC;SAClB;QACD,MAAM,OAAO,GAAG,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,MAAM,0CAAE,GAAG,CAAC;QACnC,MAAM,KAAK,GAAG,IAAI,KAAK,EAAE,CAAC;QAC1B,KAAK,CAAC,OAAO,GAAG,oCAAoC,GAAG,OAAO,GAAG,GAAG,CAAC;QACrE,KAAK,CAAC,IAAI,GAAG,yBAAyB,CAAC;QACvC,MAAM,CAAC,KAAK,CAAC,CAAC;IA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AAG,CAAC;YAChB,UAAU,CACR,GAAG,SAAS,IAAI,mBAAmB,EAAE,EACrC,KAAK,EACL,oBAAoB,CACrB;YACD,WAAW,EAAE;SACd,CAAC,CAAC;QACH,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE;YACxB,MAAM,IAAI,KAAK,CACb,kCAAkC,KAAK,oFAAoF,CAC5H,CAAC;SACH;QACD,6EAA6E;QAC7E,MAAM,CAAC,EAAE,aAAa,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;YAC1C,aAAa,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;YACjC,MAAM,CAAC,WAAW,CAAuC,CAAC,GAAG,CAC5D,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,MAAM,EAAE,CACjD;SACF,CAAC,CAAC;QACH,OAAO,aAAa,EAAE,CAAC;KACxB;SAAM;QACL,MAAM,aAAa,GAAG,MACpB,MAAM,CAAC,WAAW,CACnB,CAAC,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,MAAM,EAAE,CAAC,CAAC;QACxD,OAAO,aAAa,EAAE,CAAC;KACxB;AACH,CAAC,CAAA,CAAC;AA7CW,QAAA,YAAY,gBA6CvB"}
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isObjectEmpty = void 0;
4
- var isObjectEmpty = function (obj) {
5
- for (var x in obj) {
4
+ const isObjectEmpty = (obj) => {
5
+ for (const x in obj) {
6
6
  return false;
7
7
  }
8
8
  return true;
@@ -1 +1 @@
1
- {"version":3,"file":"isEmpty.js","sourceRoot":"","sources":["../../../../../packages/utilities/src/utils/isEmpty.ts"],"names":[],"mappings":";;;AAAO,IAAM,aAAa,GAAG,UAAmB,GAAM;IACpD,KAAK,IAAM,CAAC,IAAI,GAAG,EAAE;QACnB,OAAO,KAAK,CAAC;KACd;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AALW,QAAA,aAAa,iBAKxB"}
1
+ {"version":3,"file":"isEmpty.js","sourceRoot":"","sources":["../../../../../packages/utilities/src/utils/isEmpty.ts"],"names":[],"mappings":";;;AAAO,MAAM,aAAa,GAAG,CAAmB,GAAM,EAAE,EAAE;IACxD,KAAK,MAAM,CAAC,IAAI,GAAG,EAAE;QACnB,OAAO,KAAK,CAAC;KACd;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AALW,QAAA,aAAa,iBAKxB"}