@module-federation/nextjs-mf 5.3.2 → 5.4.0
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/lib/ModuleFederationPlugin.js +3 -1
- package/lib/NextFederationPlugin.js +18 -1051
- package/lib/_virtual/_commonjsHelpers.js +44 -0
- package/lib/_virtual/_path.js +11 -0
- package/lib/_virtual/_tslib.js +176 -0
- package/lib/_virtual/fs.js +7 -0
- package/lib/_virtual/fs2.js +7 -0
- package/lib/_virtual/options.js +7 -0
- package/lib/_virtual/utils.js +7 -0
- package/lib/client/MFClient.d.ts +4 -1
- package/lib/client/MFClient.d.ts.map +1 -1
- package/lib/client/MFClient.js +35 -19
- package/lib/client/RemoteContainer.js +1 -0
- package/lib/client/RemotePages.d.ts +2 -1
- package/lib/client/RemotePages.d.ts.map +1 -1
- package/lib/client/RemotePages.js +38 -12
- package/lib/dependencies/webpack/lib/container/options.js +102 -0
- package/lib/dependencies/webpack/lib/sharing/utils.js +104 -0
- package/lib/dependencies/webpack/lib/util/fs.js +359 -0
- package/lib/internal.js +35 -18
- package/lib/loaders/UrlNode.js +3 -1
- package/lib/loaders/patchNextClientPageLoader.js +1 -1
- package/lib/node-plugin/streaming/CommonJsChunkLoadingPlugin.js +92 -0
- package/lib/node-plugin/streaming/LoadFileChunkLoadingRuntimeModule.js +412 -0
- package/lib/node-plugin/streaming/NodeRuntime.js +247 -0
- package/lib/node-plugin/streaming/index.js +44 -0
- package/lib/node-plugin/streaming/loadScript.js +57 -0
- package/lib/plugins/DevHmrFixInvalidPongPlugin.js +14 -0
- package/lib/utils.js +16 -7
- package/package.json +4 -3
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
6
|
+
|
|
7
|
+
function getDefaultExportFromCjs (x) {
|
|
8
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function getDefaultExportFromNamespaceIfPresent (n) {
|
|
12
|
+
return n && Object.prototype.hasOwnProperty.call(n, 'default') ? n['default'] : n;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function getDefaultExportFromNamespaceIfNotNamed (n) {
|
|
16
|
+
return n && Object.prototype.hasOwnProperty.call(n, 'default') && Object.keys(n).length === 1 ? n['default'] : n;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function getAugmentedNamespace(n) {
|
|
20
|
+
var f = n.default;
|
|
21
|
+
if (typeof f == "function") {
|
|
22
|
+
var a = function () {
|
|
23
|
+
return f.apply(this, arguments);
|
|
24
|
+
};
|
|
25
|
+
a.prototype = f.prototype;
|
|
26
|
+
} else a = {};
|
|
27
|
+
Object.defineProperty(a, '__esModule', {value: true});
|
|
28
|
+
Object.keys(n).forEach(function (k) {
|
|
29
|
+
var d = Object.getOwnPropertyDescriptor(n, k);
|
|
30
|
+
Object.defineProperty(a, k, d.get ? d : {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return n[k];
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
return a;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
exports.commonjsGlobal = commonjsGlobal;
|
|
41
|
+
exports.getAugmentedNamespace = getAugmentedNamespace;
|
|
42
|
+
exports.getDefaultExportFromCjs = getDefaultExportFromCjs;
|
|
43
|
+
exports.getDefaultExportFromNamespaceIfNotNamed = getDefaultExportFromNamespaceIfNotNamed;
|
|
44
|
+
exports.getDefaultExportFromNamespaceIfPresent = getDefaultExportFromNamespaceIfPresent;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var path = require('path');
|
|
4
|
+
|
|
5
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
6
|
+
|
|
7
|
+
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
module.exports = path__default["default"];
|
package/lib/_virtual/_tslib.js
CHANGED
|
@@ -16,6 +16,60 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
16
16
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
17
17
|
PERFORMANCE OF THIS SOFTWARE.
|
|
18
18
|
***************************************************************************** */
|
|
19
|
+
/* global Reflect, Promise */
|
|
20
|
+
|
|
21
|
+
var extendStatics = function(d, b) {
|
|
22
|
+
extendStatics = Object.setPrototypeOf ||
|
|
23
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
24
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
25
|
+
return extendStatics(d, b);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
function __extends(d, b) {
|
|
29
|
+
if (typeof b !== "function" && b !== null)
|
|
30
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
31
|
+
extendStatics(d, b);
|
|
32
|
+
function __() { this.constructor = d; }
|
|
33
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
exports.__assign = function() {
|
|
37
|
+
exports.__assign = Object.assign || function __assign(t) {
|
|
38
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
39
|
+
s = arguments[i];
|
|
40
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
41
|
+
}
|
|
42
|
+
return t;
|
|
43
|
+
};
|
|
44
|
+
return exports.__assign.apply(this, arguments);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
function __rest(s, e) {
|
|
48
|
+
var t = {};
|
|
49
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
50
|
+
t[p] = s[p];
|
|
51
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
52
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
53
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
54
|
+
t[p[i]] = s[p[i]];
|
|
55
|
+
}
|
|
56
|
+
return t;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function __decorate(decorators, target, key, desc) {
|
|
60
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
61
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
62
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
63
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function __param(paramIndex, decorator) {
|
|
67
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function __metadata(metadataKey, metadataValue) {
|
|
71
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
|
|
72
|
+
}
|
|
19
73
|
|
|
20
74
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
21
75
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
@@ -55,6 +109,22 @@ function __generator(thisArg, body) {
|
|
|
55
109
|
}
|
|
56
110
|
}
|
|
57
111
|
|
|
112
|
+
var __createBinding = Object.create ? (function(o, m, k, k2) {
|
|
113
|
+
if (k2 === undefined) k2 = k;
|
|
114
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
115
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
116
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
117
|
+
}
|
|
118
|
+
Object.defineProperty(o, k2, desc);
|
|
119
|
+
}) : (function(o, m, k, k2) {
|
|
120
|
+
if (k2 === undefined) k2 = k;
|
|
121
|
+
o[k2] = m[k];
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
function __exportStar(m, o) {
|
|
125
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);
|
|
126
|
+
}
|
|
127
|
+
|
|
58
128
|
function __values(o) {
|
|
59
129
|
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
60
130
|
if (m) return m.call(o);
|
|
@@ -84,6 +154,22 @@ function __read(o, n) {
|
|
|
84
154
|
return ar;
|
|
85
155
|
}
|
|
86
156
|
|
|
157
|
+
/** @deprecated */
|
|
158
|
+
function __spread() {
|
|
159
|
+
for (var ar = [], i = 0; i < arguments.length; i++)
|
|
160
|
+
ar = ar.concat(__read(arguments[i]));
|
|
161
|
+
return ar;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** @deprecated */
|
|
165
|
+
function __spreadArrays() {
|
|
166
|
+
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
|
167
|
+
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
168
|
+
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
169
|
+
r[k] = a[j];
|
|
170
|
+
return r;
|
|
171
|
+
}
|
|
172
|
+
|
|
87
173
|
function __spreadArray(to, from, pack) {
|
|
88
174
|
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
89
175
|
if (ar || !(i in from)) {
|
|
@@ -92,10 +178,100 @@ function __spreadArray(to, from, pack) {
|
|
|
92
178
|
}
|
|
93
179
|
}
|
|
94
180
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function __await(v) {
|
|
184
|
+
return this instanceof __await ? (this.v = v, this) : new __await(v);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function __asyncGenerator(thisArg, _arguments, generator) {
|
|
188
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
189
|
+
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
190
|
+
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
191
|
+
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
|
|
192
|
+
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
193
|
+
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
194
|
+
function fulfill(value) { resume("next", value); }
|
|
195
|
+
function reject(value) { resume("throw", value); }
|
|
196
|
+
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function __asyncDelegator(o) {
|
|
200
|
+
var i, p;
|
|
201
|
+
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
|
|
202
|
+
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function __asyncValues(o) {
|
|
206
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
207
|
+
var m = o[Symbol.asyncIterator], i;
|
|
208
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
209
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
210
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function __makeTemplateObject(cooked, raw) {
|
|
214
|
+
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
|
215
|
+
return cooked;
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
var __setModuleDefault = Object.create ? (function(o, v) {
|
|
219
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
220
|
+
}) : function(o, v) {
|
|
221
|
+
o["default"] = v;
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
function __importStar(mod) {
|
|
225
|
+
if (mod && mod.__esModule) return mod;
|
|
226
|
+
var result = {};
|
|
227
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
228
|
+
__setModuleDefault(result, mod);
|
|
229
|
+
return result;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function __importDefault(mod) {
|
|
233
|
+
return (mod && mod.__esModule) ? mod : { default: mod };
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
237
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
238
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
239
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
|
243
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
244
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
245
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
246
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function __classPrivateFieldIn(state, receiver) {
|
|
250
|
+
if (receiver === null || (typeof receiver !== "object" && typeof receiver !== "function")) throw new TypeError("Cannot use 'in' operator on non-object");
|
|
251
|
+
return typeof state === "function" ? receiver === state : state.has(receiver);
|
|
95
252
|
}
|
|
96
253
|
|
|
254
|
+
exports.__asyncDelegator = __asyncDelegator;
|
|
255
|
+
exports.__asyncGenerator = __asyncGenerator;
|
|
256
|
+
exports.__asyncValues = __asyncValues;
|
|
257
|
+
exports.__await = __await;
|
|
97
258
|
exports.__awaiter = __awaiter;
|
|
259
|
+
exports.__classPrivateFieldGet = __classPrivateFieldGet;
|
|
260
|
+
exports.__classPrivateFieldIn = __classPrivateFieldIn;
|
|
261
|
+
exports.__classPrivateFieldSet = __classPrivateFieldSet;
|
|
262
|
+
exports.__createBinding = __createBinding;
|
|
263
|
+
exports.__decorate = __decorate;
|
|
264
|
+
exports.__exportStar = __exportStar;
|
|
265
|
+
exports.__extends = __extends;
|
|
98
266
|
exports.__generator = __generator;
|
|
267
|
+
exports.__importDefault = __importDefault;
|
|
268
|
+
exports.__importStar = __importStar;
|
|
269
|
+
exports.__makeTemplateObject = __makeTemplateObject;
|
|
270
|
+
exports.__metadata = __metadata;
|
|
271
|
+
exports.__param = __param;
|
|
99
272
|
exports.__read = __read;
|
|
273
|
+
exports.__rest = __rest;
|
|
274
|
+
exports.__spread = __spread;
|
|
100
275
|
exports.__spreadArray = __spreadArray;
|
|
276
|
+
exports.__spreadArrays = __spreadArrays;
|
|
101
277
|
exports.__values = __values;
|
package/lib/client/MFClient.d.ts
CHANGED
|
@@ -6,6 +6,9 @@ import { RemoteContainer } from './RemoteContainer';
|
|
|
6
6
|
declare type EventTypes = 'loadedRemoteRoute' | 'loadedLocalRoute';
|
|
7
7
|
/** Remote Container string eg `home@https://example.com/_next/static/chunks/remoteEntry.js` */
|
|
8
8
|
export declare type RemoteString = string;
|
|
9
|
+
export declare type MFClientOptions = {
|
|
10
|
+
mode: 'production' | 'development';
|
|
11
|
+
};
|
|
9
12
|
/**
|
|
10
13
|
* The main class for Module Federation on the client side in runtime.
|
|
11
14
|
* Instance of this class is a Singleton and stored in `window.mf_client` variable.
|
|
@@ -21,7 +24,7 @@ export declare class MFClient {
|
|
|
21
24
|
events: EventEmitter<EventTypes>;
|
|
22
25
|
/** Original nextjs PageLoader which passed by `patchNextClientPageLoader.js` */
|
|
23
26
|
private _nextPageLoader;
|
|
24
|
-
constructor(nextPageLoader: PageLoader);
|
|
27
|
+
constructor(nextPageLoader: PageLoader, opts: MFClientOptions);
|
|
25
28
|
/**
|
|
26
29
|
* This method returns sorted list of local and federated pages.
|
|
27
30
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MFClient.d.ts","sourceRoot":"","sources":["../../src/client/MFClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,8BAA8B,CAAC;AAC3D,OAAO,YAAY,MAAM,eAAe,CAAC;AAEzC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,aAAK,UAAU,GAAG,mBAAmB,GAAG,kBAAkB,CAAC;AAE3D,+FAA+F;AAC/F,oBAAY,YAAY,GAAG,MAAM,CAAC;AAElC;;;GAGG;AACH,qBAAa,QAAQ;IACnB,iCAAiC;IACjC,OAAO,EAAE,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,CAAM;IACpD,mDAAmD;IACnD,aAAa,EAAE,aAAa,CAAC;IAC7B,0BAA0B;IAC1B,WAAW,EAAE,WAAW,CAAC;IACzB,iEAAiE;IACjE,MAAM,EAAE,YAAY,CAAC,UAAU,CAAC,CAAC;IACjC,gFAAgF;IAChF,OAAO,CAAC,eAAe,CAAa;gBAExB,cAAc,EAAE,UAAU;
|
|
1
|
+
{"version":3,"file":"MFClient.d.ts","sourceRoot":"","sources":["../../src/client/MFClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,8BAA8B,CAAC;AAC3D,OAAO,YAAY,MAAM,eAAe,CAAC;AAEzC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,aAAK,UAAU,GAAG,mBAAmB,GAAG,kBAAkB,CAAC;AAE3D,+FAA+F;AAC/F,oBAAY,YAAY,GAAG,MAAM,CAAC;AAElC,oBAAY,eAAe,GAAG;IAC5B,IAAI,EAAE,YAAY,GAAG,aAAa,CAAC;CACpC,CAAC;AAEF;;;GAGG;AACH,qBAAa,QAAQ;IACnB,iCAAiC;IACjC,OAAO,EAAE,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,CAAM;IACpD,mDAAmD;IACnD,aAAa,EAAE,aAAa,CAAC;IAC7B,0BAA0B;IAC1B,WAAW,EAAE,WAAW,CAAC;IACzB,iEAAiE;IACjE,MAAM,EAAE,YAAY,CAAC,UAAU,CAAC,CAAC;IACjC,gFAAgF;IAChF,OAAO,CAAC,eAAe,CAAa;gBAExB,cAAc,EAAE,UAAU,EAAE,IAAI,EAAE,eAAe;IAuB7D;;;;;;OAMG;IACG,WAAW;IAIjB;;;;;;;OAOG;IACH,mBAAmB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO;IAInD;;;;;OAKG;IACH,cAAc,CAAC,SAAS,EAAE,YAAY;IAMtC;;;;;;;OAOG;IACG,eAAe,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAKzE;;;OAGG;IACH,OAAO,CAAC,cAAc;IAyCtB;;;OAGG;IACH,OAAO,CAAC,mBAAmB;CA4D5B"}
|
package/lib/client/MFClient.js
CHANGED
|
@@ -18,7 +18,7 @@ var EventEmitter__default = /*#__PURE__*/_interopDefaultLegacy(EventEmitter);
|
|
|
18
18
|
* Instance of this class is a Singleton and stored in `window.mf_client` variable.
|
|
19
19
|
*/
|
|
20
20
|
var MFClient = /** @class */ (function () {
|
|
21
|
-
function MFClient(nextPageLoader) {
|
|
21
|
+
function MFClient(nextPageLoader, opts) {
|
|
22
22
|
var _this = this;
|
|
23
23
|
var _a, _b;
|
|
24
24
|
/** List of registered remotes */
|
|
@@ -26,7 +26,7 @@ var MFClient = /** @class */ (function () {
|
|
|
26
26
|
this._nextPageLoader = nextPageLoader;
|
|
27
27
|
this.events = new EventEmitter__default["default"]();
|
|
28
28
|
var cfg = ((_b = (_a = global === null || global === void 0 ? void 0 : global.__NEXT_DATA__) === null || _a === void 0 ? void 0 : _a.props) === null || _b === void 0 ? void 0 : _b.mfRoutes) || {};
|
|
29
|
-
this.remotePages = new RemotePages.RemotePages();
|
|
29
|
+
this.remotePages = new RemotePages.RemotePages(opts === null || opts === void 0 ? void 0 : opts.mode);
|
|
30
30
|
Object.keys(cfg).forEach(function (remoteStr) {
|
|
31
31
|
var remote = _this.registerRemote(remoteStr);
|
|
32
32
|
_this.remotePages.addRoutes(cfg[remoteStr], remote);
|
|
@@ -109,7 +109,7 @@ var MFClient = /** @class */ (function () {
|
|
|
109
109
|
}
|
|
110
110
|
// replace loadRoute logic
|
|
111
111
|
routeLoader.loadRoute = function (route, prefetch) { return _tslib.__awaiter(_this, void 0, void 0, function () {
|
|
112
|
-
var routeInfo;
|
|
112
|
+
var routeInfo, e_1;
|
|
113
113
|
return _tslib.__generator(this, function (_a) {
|
|
114
114
|
switch (_a.label) {
|
|
115
115
|
case 0: return [4 /*yield*/, this.combinedPages.isLocalRoute(route)];
|
|
@@ -119,13 +119,22 @@ var MFClient = /** @class */ (function () {
|
|
|
119
119
|
case 2:
|
|
120
120
|
routeInfo = _a.sent();
|
|
121
121
|
this.events.emit('loadedLocalRoute', routeInfo, prefetch);
|
|
122
|
-
return [3 /*break*/,
|
|
123
|
-
case 3:
|
|
122
|
+
return [3 /*break*/, 7];
|
|
123
|
+
case 3:
|
|
124
|
+
_a.trys.push([3, 5, , 7]);
|
|
125
|
+
return [4 /*yield*/, this.remotePages.getRouteInfo(route)];
|
|
124
126
|
case 4:
|
|
125
127
|
routeInfo = _a.sent();
|
|
126
128
|
this.events.emit('loadedRemoteRoute', routeInfo, prefetch, this.remotePages.routeToRemote(route));
|
|
127
|
-
|
|
128
|
-
case 5:
|
|
129
|
+
return [3 /*break*/, 7];
|
|
130
|
+
case 5:
|
|
131
|
+
e_1 = _a.sent();
|
|
132
|
+
return [4 /*yield*/, routeLoader._loadRouteOriginal(route)];
|
|
133
|
+
case 6:
|
|
134
|
+
// as fallback try to use original loadRoute for keeping nextjs logic for routes load errors
|
|
135
|
+
routeInfo = _a.sent();
|
|
136
|
+
return [3 /*break*/, 7];
|
|
137
|
+
case 7: return [2 /*return*/, routeInfo];
|
|
129
138
|
}
|
|
130
139
|
});
|
|
131
140
|
}); };
|
|
@@ -148,16 +157,19 @@ var MFClient = /** @class */ (function () {
|
|
|
148
157
|
}
|
|
149
158
|
// replace routeLoader.whenEntrypoint logic
|
|
150
159
|
routeLoader.whenEntrypoint = function (route) { return _tslib.__awaiter(_this, void 0, void 0, function () {
|
|
151
|
-
var route_1, awaitRemotes_1, routeInfo_1, routeInfo;
|
|
160
|
+
var route_1, awaitRemotes_1, routeInfo_1, e_2, routeInfo;
|
|
152
161
|
var _this = this;
|
|
153
162
|
return _tslib.__generator(this, function (_a) {
|
|
154
163
|
switch (_a.label) {
|
|
155
164
|
case 0:
|
|
156
|
-
if (!(route === '/_error')) return [3 /*break*/,
|
|
157
|
-
|
|
165
|
+
if (!(route === '/_error')) return [3 /*break*/, 9];
|
|
166
|
+
_a.label = 1;
|
|
158
167
|
case 1:
|
|
168
|
+
_a.trys.push([1, 8, , 9]);
|
|
169
|
+
return [4 /*yield*/, this.pathnameToRoute(window.location.pathname)];
|
|
170
|
+
case 2:
|
|
159
171
|
route_1 = _a.sent();
|
|
160
|
-
if (!!route_1) return [3 /*break*/,
|
|
172
|
+
if (!!route_1) return [3 /*break*/, 5];
|
|
161
173
|
awaitRemotes_1 = [];
|
|
162
174
|
Object.values(this.remotes).forEach(function (remote) {
|
|
163
175
|
if (!remote.isLoaded()) {
|
|
@@ -168,23 +180,27 @@ var MFClient = /** @class */ (function () {
|
|
|
168
180
|
}
|
|
169
181
|
});
|
|
170
182
|
return [4 /*yield*/, Promise.all(awaitRemotes_1)];
|
|
171
|
-
case
|
|
183
|
+
case 3:
|
|
172
184
|
_a.sent();
|
|
173
185
|
return [4 /*yield*/, this.pathnameToRoute(window.location.pathname)];
|
|
174
|
-
case 3:
|
|
175
|
-
route_1 = _a.sent();
|
|
176
|
-
_a.label = 4;
|
|
177
186
|
case 4:
|
|
178
|
-
|
|
187
|
+
route_1 = _a.sent();
|
|
188
|
+
_a.label = 5;
|
|
189
|
+
case 5:
|
|
190
|
+
if (!route_1) return [3 /*break*/, 7];
|
|
179
191
|
// TODO: fix router properties for the first page load of federated page http://localhost:3000/shop/products/B
|
|
180
192
|
console.warn('replace entrypoint /_error by', route_1);
|
|
181
193
|
return [4 /*yield*/, this.remotePages.getRouteInfo(route_1)];
|
|
182
|
-
case
|
|
194
|
+
case 6:
|
|
183
195
|
routeInfo_1 = _a.sent();
|
|
184
196
|
this.events.emit('loadedRemoteRoute', routeInfo_1, false, this.remotePages.routeToRemote(route_1));
|
|
185
197
|
return [2 /*return*/, routeInfo_1];
|
|
186
|
-
case
|
|
187
|
-
case
|
|
198
|
+
case 7: return [3 /*break*/, 9];
|
|
199
|
+
case 8:
|
|
200
|
+
e_2 = _a.sent();
|
|
201
|
+
return [3 /*break*/, 9];
|
|
202
|
+
case 9: return [4 /*yield*/, routeLoader._whenEntrypointOriginal(route)];
|
|
203
|
+
case 10:
|
|
188
204
|
routeInfo = _a.sent();
|
|
189
205
|
return [2 /*return*/, routeInfo];
|
|
190
206
|
}
|
|
@@ -14,7 +14,8 @@ export declare class RemotePages {
|
|
|
14
14
|
paths: Record<PathPrefix, RemoteContainer>;
|
|
15
15
|
pageListCache: string[] | undefined;
|
|
16
16
|
private asyncLoadedPageMaps;
|
|
17
|
-
|
|
17
|
+
private mode?;
|
|
18
|
+
constructor(mode?: 'production' | 'development');
|
|
18
19
|
/**
|
|
19
20
|
* Add remote routes for specific RemoteContainer which serves them.
|
|
20
21
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RemotePages.d.ts","sourceRoot":"","sources":["../../src/client/RemotePages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"RemotePages.d.ts","sourceRoot":"","sources":["../../src/client/RemotePages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAG7D,oBAAY,UAAU,GAAG,MAAM,CAAC;AAEhC,oBAAY,cAAc,GAAG,GAAG,CAAC,eAAe,EAAE,UAAU,GAAG,UAAU,EAAE,CAAC,CAAC;AAE7E,oBAAY,SAAS,GAAG;IACtB,SAAS,EAAE,GAAG,CAAC;IACf,OAAO,EAAE,GAAG,CAAC;IACb,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,CAAC;AAEF;;;GAGG;AACH,qBAAa,WAAW;IACtB,KAAK,EAAE,MAAM,CAAC,UAAU,EAAE,eAAe,CAAC,CAAM;IAChD,aAAa,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IACpC,OAAO,CAAC,mBAAmB,CAAuB;IAClD,OAAO,CAAC,IAAI,CAAC,CAA+B;gBAEhC,IAAI,CAAC,EAAE,YAAY,GAAG,aAAa;IAM/C;;OAEG;IACH,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,MAAM,EAAE,eAAe;IAW5D;;OAEG;IACG,iBAAiB,CACrB,MAAM,EAAE,eAAe,GACtB,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC;IAc/B;;;OAGG;IACG,iBAAiB,CAAC,KAAK,EAAE,MAAM;IAmBrC;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAIhC;;OAEG;IACH,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS;IAsBzD;;OAEG;IACH,WAAW;IAQX;;OAEG;IACG,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;CAiDlE"}
|
|
@@ -3,20 +3,38 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var _tslib = require('../_virtual/_tslib.js');
|
|
6
|
+
var React = require('react');
|
|
7
|
+
|
|
8
|
+
function _interopNamespace(e) {
|
|
9
|
+
if (e && e.__esModule) return e;
|
|
10
|
+
var n = Object.create(null);
|
|
11
|
+
if (e) {
|
|
12
|
+
Object.keys(e).forEach(function (k) {
|
|
13
|
+
if (k !== 'default') {
|
|
14
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
15
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function () { return e[k]; }
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
n["default"] = e;
|
|
23
|
+
return Object.freeze(n);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
6
27
|
|
|
7
28
|
/**
|
|
8
29
|
* A class which prepares/loads a list of remotes pages and knows how
|
|
9
30
|
* to prepare NextJS pseudo-module of route data.
|
|
10
31
|
*/
|
|
11
32
|
var RemotePages = /** @class */ (function () {
|
|
12
|
-
function RemotePages(
|
|
13
|
-
var _this = this;
|
|
33
|
+
function RemotePages(mode) {
|
|
14
34
|
this.paths = {};
|
|
15
35
|
this.asyncLoadedPageMaps = new Set();
|
|
16
36
|
this.pageListCache = undefined;
|
|
17
|
-
|
|
18
|
-
_this.addRoutes(routes, remote);
|
|
19
|
-
});
|
|
37
|
+
this.mode = mode;
|
|
20
38
|
}
|
|
21
39
|
/**
|
|
22
40
|
* Add remote routes for specific RemoteContainer which serves them.
|
|
@@ -149,13 +167,21 @@ var RemotePages = /** @class */ (function () {
|
|
|
149
167
|
return [3 /*break*/, 3];
|
|
150
168
|
case 2:
|
|
151
169
|
e_1 = _a.sent();
|
|
152
|
-
|
|
153
|
-
//
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
170
|
+
if (this.mode !== 'development') {
|
|
171
|
+
// in PROD throw error, nextjs will reload the page according to its internal logic
|
|
172
|
+
throw e_1;
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
// in DEV mod show error in browser
|
|
176
|
+
console.warn(e_1);
|
|
177
|
+
routeInfo = {
|
|
178
|
+
component: function () {
|
|
179
|
+
return React__namespace.createElement('div', null, React__namespace.createElement('div', null, 'This page is shown only in DEVELOPMENT mode. In PRODUCTION NextJS will reload this page trying to obtain it again from the server.'), React__namespace.createElement('div', null, 'Federated page ', route, ' load error:'), React__namespace.createElement('div', null, React__namespace.createElement('b', null, e_1.message)));
|
|
180
|
+
},
|
|
181
|
+
exports: {},
|
|
182
|
+
styles: [],
|
|
183
|
+
};
|
|
184
|
+
}
|
|
159
185
|
return [3 /*break*/, 3];
|
|
160
186
|
case 3: return [2 /*return*/, routeInfo];
|
|
161
187
|
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
require('../../../../_virtual/_commonjsHelpers.js');
|
|
6
|
+
var options = require('../../../../_virtual/options.js');
|
|
7
|
+
|
|
8
|
+
/*
|
|
9
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
10
|
+
Author Tobias Koppers @sokra
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
"use strict";
|
|
14
|
+
|
|
15
|
+
/** @template T @typedef {(string | Record<string, string | string[] | T>)[] | Record<string, string | string[] | T>} ContainerOptionsFormat */
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @template T
|
|
19
|
+
* @template N
|
|
20
|
+
* @param {ContainerOptionsFormat<T>} options options passed by the user
|
|
21
|
+
* @param {function(string | string[], string) : N} normalizeSimple normalize a simple item
|
|
22
|
+
* @param {function(T, string) : N} normalizeOptions normalize a complex item
|
|
23
|
+
* @param {function(string, N): void} fn processing function
|
|
24
|
+
* @returns {void}
|
|
25
|
+
*/
|
|
26
|
+
const process = (options, normalizeSimple, normalizeOptions, fn) => {
|
|
27
|
+
const array = items => {
|
|
28
|
+
for (const item of items) {
|
|
29
|
+
if (typeof item === "string") {
|
|
30
|
+
fn(item, normalizeSimple(item, item));
|
|
31
|
+
} else if (item && typeof item === "object") {
|
|
32
|
+
object(item);
|
|
33
|
+
} else {
|
|
34
|
+
throw new Error("Unexpected options format");
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
const object = obj => {
|
|
39
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
40
|
+
if (typeof value === "string" || Array.isArray(value)) {
|
|
41
|
+
fn(key, normalizeSimple(value, key));
|
|
42
|
+
} else {
|
|
43
|
+
fn(key, normalizeOptions(value, key));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
if (!options) {
|
|
48
|
+
return;
|
|
49
|
+
} else if (Array.isArray(options)) {
|
|
50
|
+
array(options);
|
|
51
|
+
} else if (typeof options === "object") {
|
|
52
|
+
object(options);
|
|
53
|
+
} else {
|
|
54
|
+
throw new Error("Unexpected options format");
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @template T
|
|
60
|
+
* @template R
|
|
61
|
+
* @param {ContainerOptionsFormat<T>} options options passed by the user
|
|
62
|
+
* @param {function(string | string[], string) : R} normalizeSimple normalize a simple item
|
|
63
|
+
* @param {function(T, string) : R} normalizeOptions normalize a complex item
|
|
64
|
+
* @returns {[string, R][]} parsed options
|
|
65
|
+
*/
|
|
66
|
+
const parseOptions = (options, normalizeSimple, normalizeOptions) => {
|
|
67
|
+
/** @type {[string, R][]} */
|
|
68
|
+
const items = [];
|
|
69
|
+
process(options, normalizeSimple, normalizeOptions, (key, value) => {
|
|
70
|
+
items.push([key, value]);
|
|
71
|
+
});
|
|
72
|
+
return items;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* @template T
|
|
77
|
+
* @param {string} scope scope name
|
|
78
|
+
* @param {ContainerOptionsFormat<T>} options options passed by the user
|
|
79
|
+
* @returns {Record<string, string | string[] | T>} options to spread or pass
|
|
80
|
+
*/
|
|
81
|
+
const scope = (scope, options) => {
|
|
82
|
+
/** @type {Record<string, string | string[] | T>} */
|
|
83
|
+
const obj = {};
|
|
84
|
+
process(
|
|
85
|
+
options,
|
|
86
|
+
item => /** @type {string | string[] | T} */ (item),
|
|
87
|
+
item => /** @type {string | string[] | T} */ (item),
|
|
88
|
+
(key, value) => {
|
|
89
|
+
obj[
|
|
90
|
+
key.startsWith("./") ? `${scope}${key.slice(1)}` : `${scope}/${key}`
|
|
91
|
+
] = value;
|
|
92
|
+
}
|
|
93
|
+
);
|
|
94
|
+
return obj;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
var parseOptions_1 = options.__exports.parseOptions = parseOptions;
|
|
98
|
+
var scope_1 = options.__exports.scope = scope;
|
|
99
|
+
|
|
100
|
+
exports["default"] = options.__exports;
|
|
101
|
+
exports.parseOptions = parseOptions_1;
|
|
102
|
+
exports.scope = scope_1;
|