@module-federation/data-prefetch 0.6.6 → 0.6.7
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/CHANGELOG.md +17 -0
- package/LICENSE +1 -1
- package/__tests__/prefetch.spec.ts +3 -2
- package/__tests__/react.spec.ts +1 -1
- package/dist/LICENSE +21 -0
- package/dist/babel.cjs.d.ts +2 -0
- package/dist/babel.cjs.js +62 -0
- package/dist/babel.esm.js +56 -0
- package/dist/cli.cjs.d.ts +1 -0
- package/dist/cli.cjs.js +3579 -0
- package/dist/cli.esm.js +3565 -0
- package/dist/index.cjs.d.ts +1 -0
- package/dist/index.cjs.js +15 -0
- package/dist/index.cjs2.js +7 -0
- package/dist/index.esm.js +6 -0
- package/dist/index.esm2.js +5 -0
- package/dist/package.json +99 -0
- package/dist/plugin.cjs.d.ts +2 -0
- package/dist/plugin.cjs.js +362 -0
- package/dist/plugin.esm.js +357 -0
- package/dist/prefetch.cjs.js +351 -0
- package/dist/prefetch.esm.js +349 -0
- package/dist/react.cjs.d.ts +1 -0
- package/dist/react.cjs.js +163 -0
- package/dist/react.esm.js +159 -0
- package/dist/runtime-utils.cjs.js +31 -0
- package/dist/runtime-utils.esm.js +26 -0
- package/dist/shared.cjs.d.ts +2 -0
- package/dist/shared.cjs.js +26 -0
- package/dist/shared.esm.js +24 -0
- package/dist/{cli → src/cli}/babel.d.ts +2 -4
- package/dist/{cli → src/cli}/index.d.ts +5 -8
- package/dist/src/common/constant.d.ts +1 -0
- package/dist/src/common/index.d.ts +1 -0
- package/dist/src/common/node-utils.d.ts +2 -0
- package/dist/src/common/runtime-utils.d.ts +5 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/logger/index.d.ts +3 -0
- package/dist/src/plugin.d.ts +3 -0
- package/dist/{prefetch-4e9646e4.d.ts → src/prefetch.d.ts} +5 -7
- package/dist/src/react/hooks.d.ts +11 -0
- package/dist/src/react/index.d.ts +1 -0
- package/dist/src/react/utils.d.ts +1 -0
- package/dist/src/shared/index.d.ts +3 -0
- package/dist/src/universal/index.d.ts +2 -0
- package/dist/universal.cjs.d.ts +1 -0
- package/dist/universal.cjs.js +38 -0
- package/dist/universal.esm.js +34 -0
- package/jest.config.js +2 -2
- package/package.json +31 -28
- package/project.json +46 -4
- package/rollup.config.js +25 -0
- package/src/cli/index.ts +12 -10
- package/src/prefetch.ts +6 -2
- package/tsconfig.json +1 -1
- package/tsconfig.lib.json +10 -0
- package/dist/cli/babel.js +0 -84
- package/dist/cli/index.js +0 -205
- package/dist/esm/chunk-AJPO2B2T.js +0 -30
- package/dist/esm/chunk-EZUCZHGV.js +0 -11
- package/dist/esm/chunk-ISLXMAIA.js +0 -155
- package/dist/esm/chunk-KI4QGPIS.js +0 -32
- package/dist/esm/chunk-TTJJJ2WZ.js +0 -7
- package/dist/esm/chunk-VVZ6XIM6.js +0 -166
- package/dist/esm/cli/babel.js +0 -57
- package/dist/esm/cli/index.js +0 -178
- package/dist/esm/index.js +0 -13
- package/dist/esm/plugin.js +0 -12
- package/dist/esm/react/index.js +0 -94
- package/dist/esm/shared/index.js +0 -27
- package/dist/esm/universal/index.js +0 -9
- package/dist/index.d.ts +0 -5
- package/dist/index.js +0 -350
- package/dist/plugin.d.ts +0 -5
- package/dist/plugin.js +0 -346
- package/dist/react/index.d.ts +0 -16
- package/dist/react/index.js +0 -286
- package/dist/shared/index.d.ts +0 -5
- package/dist/shared/index.js +0 -48
- package/dist/universal/index.d.ts +0 -8
- package/dist/universal/index.js +0 -204
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var runtime = require('@module-federation/runtime');
|
|
4
|
+
var sdk = require('@module-federation/sdk');
|
|
5
|
+
var runtimeUtils = require('./runtime-utils.cjs.js');
|
|
6
|
+
|
|
7
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
8
|
+
try {
|
|
9
|
+
var info = gen[key](arg);
|
|
10
|
+
var value = info.value;
|
|
11
|
+
} catch (error) {
|
|
12
|
+
reject(error);
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
if (info.done) {
|
|
16
|
+
resolve(value);
|
|
17
|
+
} else {
|
|
18
|
+
Promise.resolve(value).then(_next, _throw);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function _async_to_generator(fn) {
|
|
22
|
+
return function() {
|
|
23
|
+
var self = this, args = arguments;
|
|
24
|
+
return new Promise(function(resolve, reject) {
|
|
25
|
+
var gen = fn.apply(self, args);
|
|
26
|
+
function _next(value) {
|
|
27
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
28
|
+
}
|
|
29
|
+
function _throw(err) {
|
|
30
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
31
|
+
}
|
|
32
|
+
_next(undefined);
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function _class_call_check(instance, Constructor) {
|
|
37
|
+
if (!(instance instanceof Constructor)) {
|
|
38
|
+
throw new TypeError("Cannot call a class as a function");
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function _defineProperties(target, props) {
|
|
42
|
+
for(var i = 0; i < props.length; i++){
|
|
43
|
+
var descriptor = props[i];
|
|
44
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
45
|
+
descriptor.configurable = true;
|
|
46
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
47
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
51
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
52
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
53
|
+
return Constructor;
|
|
54
|
+
}
|
|
55
|
+
function _define_property(obj, key, value) {
|
|
56
|
+
if (key in obj) {
|
|
57
|
+
Object.defineProperty(obj, key, {
|
|
58
|
+
value: value,
|
|
59
|
+
enumerable: true,
|
|
60
|
+
configurable: true,
|
|
61
|
+
writable: true
|
|
62
|
+
});
|
|
63
|
+
} else {
|
|
64
|
+
obj[key] = value;
|
|
65
|
+
}
|
|
66
|
+
return obj;
|
|
67
|
+
}
|
|
68
|
+
function _ts_generator(thisArg, body) {
|
|
69
|
+
var f, y, t, g, _ = {
|
|
70
|
+
label: 0,
|
|
71
|
+
sent: function() {
|
|
72
|
+
if (t[0] & 1) throw t[1];
|
|
73
|
+
return t[1];
|
|
74
|
+
},
|
|
75
|
+
trys: [],
|
|
76
|
+
ops: []
|
|
77
|
+
};
|
|
78
|
+
return g = {
|
|
79
|
+
next: verb(0),
|
|
80
|
+
"throw": verb(1),
|
|
81
|
+
"return": verb(2)
|
|
82
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
83
|
+
return this;
|
|
84
|
+
}), g;
|
|
85
|
+
function verb(n) {
|
|
86
|
+
return function(v) {
|
|
87
|
+
return step([
|
|
88
|
+
n,
|
|
89
|
+
v
|
|
90
|
+
]);
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function step(op) {
|
|
94
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
95
|
+
while(_)try {
|
|
96
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
97
|
+
if (y = 0, t) op = [
|
|
98
|
+
op[0] & 2,
|
|
99
|
+
t.value
|
|
100
|
+
];
|
|
101
|
+
switch(op[0]){
|
|
102
|
+
case 0:
|
|
103
|
+
case 1:
|
|
104
|
+
t = op;
|
|
105
|
+
break;
|
|
106
|
+
case 4:
|
|
107
|
+
_.label++;
|
|
108
|
+
return {
|
|
109
|
+
value: op[1],
|
|
110
|
+
done: false
|
|
111
|
+
};
|
|
112
|
+
case 5:
|
|
113
|
+
_.label++;
|
|
114
|
+
y = op[1];
|
|
115
|
+
op = [
|
|
116
|
+
0
|
|
117
|
+
];
|
|
118
|
+
continue;
|
|
119
|
+
case 7:
|
|
120
|
+
op = _.ops.pop();
|
|
121
|
+
_.trys.pop();
|
|
122
|
+
continue;
|
|
123
|
+
default:
|
|
124
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
125
|
+
_ = 0;
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
129
|
+
_.label = op[1];
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
133
|
+
_.label = t[1];
|
|
134
|
+
t = op;
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
if (t && _.label < t[2]) {
|
|
138
|
+
_.label = t[2];
|
|
139
|
+
_.ops.push(op);
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
if (t[2]) _.ops.pop();
|
|
143
|
+
_.trys.pop();
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
op = body.call(thisArg, _);
|
|
147
|
+
} catch (e) {
|
|
148
|
+
op = [
|
|
149
|
+
6,
|
|
150
|
+
e
|
|
151
|
+
];
|
|
152
|
+
y = 0;
|
|
153
|
+
} finally{
|
|
154
|
+
f = t = 0;
|
|
155
|
+
}
|
|
156
|
+
if (op[0] & 5) throw op[1];
|
|
157
|
+
return {
|
|
158
|
+
value: op[0] ? op[1] : void 0,
|
|
159
|
+
done: true
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
var // @ts-ignore init global variable for test
|
|
164
|
+
_globalThis, _globalThis___FEDERATION__;
|
|
165
|
+
var ___FEDERATION__;
|
|
166
|
+
(___FEDERATION__ = (_globalThis = globalThis).__FEDERATION__) !== null && ___FEDERATION__ !== void 0 ? ___FEDERATION__ : _globalThis.__FEDERATION__ = {};
|
|
167
|
+
var ___PREFETCH__;
|
|
168
|
+
(___PREFETCH__ = (_globalThis___FEDERATION__ = globalThis.__FEDERATION__).__PREFETCH__) !== null && ___PREFETCH__ !== void 0 ? ___PREFETCH__ : _globalThis___FEDERATION__.__PREFETCH__ = {
|
|
169
|
+
entryLoading: {},
|
|
170
|
+
instance: new Map(),
|
|
171
|
+
__PREFETCH_EXPORTS__: {}
|
|
172
|
+
};
|
|
173
|
+
var MFDataPrefetch = /*#__PURE__*/ function() {
|
|
174
|
+
function MFDataPrefetch(options) {
|
|
175
|
+
_class_call_check(this, MFDataPrefetch);
|
|
176
|
+
_define_property(this, "prefetchMemory", void 0);
|
|
177
|
+
_define_property(this, "recordOutdate", void 0);
|
|
178
|
+
_define_property(this, "_exports", void 0);
|
|
179
|
+
_define_property(this, "_options", void 0);
|
|
180
|
+
this.prefetchMemory = new Map();
|
|
181
|
+
this.recordOutdate = {};
|
|
182
|
+
this._exports = {};
|
|
183
|
+
this._options = options;
|
|
184
|
+
this.global.instance.set(options.name, this);
|
|
185
|
+
}
|
|
186
|
+
_create_class(MFDataPrefetch, [
|
|
187
|
+
{
|
|
188
|
+
key: "global",
|
|
189
|
+
get: function get() {
|
|
190
|
+
return globalThis.__FEDERATION__.__PREFETCH__;
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
key: "loadEntry",
|
|
195
|
+
value: function loadEntry(entry) {
|
|
196
|
+
var _this = this;
|
|
197
|
+
return _async_to_generator(function() {
|
|
198
|
+
var _this__options, name, remoteSnapshot, remote, origin, buildVersion, globalName, uniqueKey, remoteInfo, module;
|
|
199
|
+
return _ts_generator(this, function(_state) {
|
|
200
|
+
_this__options = _this._options, name = _this__options.name, remoteSnapshot = _this__options.remoteSnapshot, remote = _this__options.remote, origin = _this__options.origin;
|
|
201
|
+
if (entry) {
|
|
202
|
+
buildVersion = remoteSnapshot.buildVersion, globalName = remoteSnapshot.globalName;
|
|
203
|
+
uniqueKey = globalName || "".concat(name, ":").concat(buildVersion);
|
|
204
|
+
if (!_this.global.entryLoading[uniqueKey]) {
|
|
205
|
+
_this.global.entryLoading[uniqueKey] = sdk.loadScript(entry, {});
|
|
206
|
+
}
|
|
207
|
+
return [
|
|
208
|
+
2,
|
|
209
|
+
_this.global.entryLoading[uniqueKey]
|
|
210
|
+
];
|
|
211
|
+
} else {
|
|
212
|
+
remoteInfo = runtime.getRemoteInfo(remote);
|
|
213
|
+
module = origin.moduleCache.get(remoteInfo.name);
|
|
214
|
+
return [
|
|
215
|
+
2,
|
|
216
|
+
runtime.getRemoteEntry({
|
|
217
|
+
origin: origin,
|
|
218
|
+
remoteInfo: remoteInfo,
|
|
219
|
+
remoteEntryExports: module ? module.remoteEntryExports : undefined
|
|
220
|
+
})
|
|
221
|
+
];
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
})();
|
|
225
|
+
}
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
key: "getProjectExports",
|
|
229
|
+
value: function getProjectExports() {
|
|
230
|
+
var _this = this;
|
|
231
|
+
var _globalThis___FEDERATION_____PREFETCH_____PREFETCH_EXPORTS__;
|
|
232
|
+
if (Object.keys(this._exports).length > 0) {
|
|
233
|
+
return this._exports;
|
|
234
|
+
}
|
|
235
|
+
var name = this._options.name;
|
|
236
|
+
var exportsPromiseFn = (_globalThis___FEDERATION_____PREFETCH_____PREFETCH_EXPORTS__ = globalThis.__FEDERATION__.__PREFETCH__.__PREFETCH_EXPORTS__) === null || _globalThis___FEDERATION_____PREFETCH_____PREFETCH_EXPORTS__ === void 0 ? void 0 : _globalThis___FEDERATION_____PREFETCH_____PREFETCH_EXPORTS__[name];
|
|
237
|
+
var exportsPromise = typeof exportsPromiseFn === 'function' ? exportsPromiseFn() : Promise.resolve({});
|
|
238
|
+
var resolve = exportsPromise.then(function() {
|
|
239
|
+
var exports = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
240
|
+
// Match prefetch based on the function name suffix so that other capabilities can be expanded later.
|
|
241
|
+
// Not all functions should be directly identified as prefetch functions
|
|
242
|
+
var memory = {};
|
|
243
|
+
Object.keys(exports).forEach(function(key) {
|
|
244
|
+
memory[key] = {};
|
|
245
|
+
var exportVal = exports[key];
|
|
246
|
+
Object.keys(exportVal).reduce(function(memo, current) {
|
|
247
|
+
if (current.toLocaleLowerCase().endsWith('prefetch') || current.toLocaleLowerCase() === 'default') {
|
|
248
|
+
memo[current] = exportVal[current];
|
|
249
|
+
}
|
|
250
|
+
return memo;
|
|
251
|
+
}, memory[key]);
|
|
252
|
+
});
|
|
253
|
+
_this.memorizeExports(memory);
|
|
254
|
+
});
|
|
255
|
+
return resolve;
|
|
256
|
+
}
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
key: "memorizeExports",
|
|
260
|
+
value: function memorizeExports(exports) {
|
|
261
|
+
this._exports = exports;
|
|
262
|
+
}
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
key: "getExposeExports",
|
|
266
|
+
value: function getExposeExports(id) {
|
|
267
|
+
var prefetchId = runtimeUtils.getPrefetchId(id);
|
|
268
|
+
var compatId = runtimeUtils.compatGetPrefetchId(id);
|
|
269
|
+
var prefetchExports = this._exports[prefetchId] || this._exports[compatId];
|
|
270
|
+
return prefetchExports || {};
|
|
271
|
+
}
|
|
272
|
+
},
|
|
273
|
+
{
|
|
274
|
+
key: "prefetch",
|
|
275
|
+
value: function prefetch(prefetchOptions) {
|
|
276
|
+
var id = prefetchOptions.id, _prefetchOptions_functionId = prefetchOptions.functionId, functionId = _prefetchOptions_functionId === void 0 ? 'default' : _prefetchOptions_functionId, refetchParams = prefetchOptions.refetchParams;
|
|
277
|
+
var prefetchResult;
|
|
278
|
+
var prefetchId = runtimeUtils.getPrefetchId(id);
|
|
279
|
+
var compatId = runtimeUtils.compatGetPrefetchId(id);
|
|
280
|
+
var memorizeId = id + functionId;
|
|
281
|
+
var memory = this.prefetchMemory.get(memorizeId);
|
|
282
|
+
if (!this.checkOutdate(prefetchOptions) && memory) {
|
|
283
|
+
return memory;
|
|
284
|
+
}
|
|
285
|
+
var prefetchExports = this._exports[prefetchId] || this._exports[compatId];
|
|
286
|
+
if (!prefetchExports) {
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
var executePrefetch = prefetchExports[functionId];
|
|
290
|
+
if (typeof executePrefetch === 'function') {
|
|
291
|
+
if (refetchParams) {
|
|
292
|
+
prefetchResult = executePrefetch(refetchParams);
|
|
293
|
+
} else {
|
|
294
|
+
prefetchResult = executePrefetch();
|
|
295
|
+
}
|
|
296
|
+
} else {
|
|
297
|
+
throw new Error("[Module Federation Data Prefetch]: No prefetch function called ".concat(functionId, " export in prefetch file"));
|
|
298
|
+
}
|
|
299
|
+
this.memorize(memorizeId, prefetchResult);
|
|
300
|
+
return prefetchResult;
|
|
301
|
+
}
|
|
302
|
+
},
|
|
303
|
+
{
|
|
304
|
+
key: "memorize",
|
|
305
|
+
value: function memorize(id, value) {
|
|
306
|
+
this.prefetchMemory.set(id, value);
|
|
307
|
+
}
|
|
308
|
+
},
|
|
309
|
+
{
|
|
310
|
+
key: "markOutdate",
|
|
311
|
+
value: function markOutdate(markOptions, isOutdate) {
|
|
312
|
+
var id = markOptions.id, _markOptions_functionId = markOptions.functionId, functionId = _markOptions_functionId === void 0 ? 'default' : _markOptions_functionId;
|
|
313
|
+
if (!this.recordOutdate[id]) {
|
|
314
|
+
this.recordOutdate[id] = {};
|
|
315
|
+
}
|
|
316
|
+
this.recordOutdate[id][functionId] = isOutdate;
|
|
317
|
+
}
|
|
318
|
+
},
|
|
319
|
+
{
|
|
320
|
+
key: "checkOutdate",
|
|
321
|
+
value: function checkOutdate(outdateOptions) {
|
|
322
|
+
var id = outdateOptions.id, _outdateOptions_functionId = outdateOptions.functionId, functionId = _outdateOptions_functionId === void 0 ? 'default' : _outdateOptions_functionId, cacheStrategy = outdateOptions.cacheStrategy;
|
|
323
|
+
if (typeof cacheStrategy === 'function') {
|
|
324
|
+
return cacheStrategy();
|
|
325
|
+
}
|
|
326
|
+
if (!this.recordOutdate[id]) {
|
|
327
|
+
this.recordOutdate[id] = {};
|
|
328
|
+
}
|
|
329
|
+
if (this.recordOutdate[id][functionId]) {
|
|
330
|
+
this.markOutdate({
|
|
331
|
+
id: id,
|
|
332
|
+
functionId: functionId
|
|
333
|
+
}, false);
|
|
334
|
+
return true;
|
|
335
|
+
} else {
|
|
336
|
+
return false;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
], [
|
|
341
|
+
{
|
|
342
|
+
key: "getInstance",
|
|
343
|
+
value: function getInstance(id) {
|
|
344
|
+
return globalThis.__FEDERATION__.__PREFETCH__.instance.get(id);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
]);
|
|
348
|
+
return MFDataPrefetch;
|
|
349
|
+
}();
|
|
350
|
+
|
|
351
|
+
exports.MFDataPrefetch = MFDataPrefetch;
|
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
import { getRemoteInfo, getRemoteEntry } from '@module-federation/runtime';
|
|
2
|
+
import { loadScript } from '@module-federation/sdk';
|
|
3
|
+
import { g as getPrefetchId, c as compatGetPrefetchId } from './runtime-utils.esm.js';
|
|
4
|
+
|
|
5
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
6
|
+
try {
|
|
7
|
+
var info = gen[key](arg);
|
|
8
|
+
var value = info.value;
|
|
9
|
+
} catch (error) {
|
|
10
|
+
reject(error);
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (info.done) {
|
|
14
|
+
resolve(value);
|
|
15
|
+
} else {
|
|
16
|
+
Promise.resolve(value).then(_next, _throw);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function _async_to_generator(fn) {
|
|
20
|
+
return function() {
|
|
21
|
+
var self = this, args = arguments;
|
|
22
|
+
return new Promise(function(resolve, reject) {
|
|
23
|
+
var gen = fn.apply(self, args);
|
|
24
|
+
function _next(value) {
|
|
25
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
26
|
+
}
|
|
27
|
+
function _throw(err) {
|
|
28
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
29
|
+
}
|
|
30
|
+
_next(undefined);
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function _class_call_check(instance, Constructor) {
|
|
35
|
+
if (!(instance instanceof Constructor)) {
|
|
36
|
+
throw new TypeError("Cannot call a class as a function");
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function _defineProperties(target, props) {
|
|
40
|
+
for(var i = 0; i < props.length; i++){
|
|
41
|
+
var descriptor = props[i];
|
|
42
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
43
|
+
descriptor.configurable = true;
|
|
44
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
45
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
49
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
50
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
51
|
+
return Constructor;
|
|
52
|
+
}
|
|
53
|
+
function _define_property(obj, key, value) {
|
|
54
|
+
if (key in obj) {
|
|
55
|
+
Object.defineProperty(obj, key, {
|
|
56
|
+
value: value,
|
|
57
|
+
enumerable: true,
|
|
58
|
+
configurable: true,
|
|
59
|
+
writable: true
|
|
60
|
+
});
|
|
61
|
+
} else {
|
|
62
|
+
obj[key] = value;
|
|
63
|
+
}
|
|
64
|
+
return obj;
|
|
65
|
+
}
|
|
66
|
+
function _ts_generator(thisArg, body) {
|
|
67
|
+
var f, y, t, g, _ = {
|
|
68
|
+
label: 0,
|
|
69
|
+
sent: function() {
|
|
70
|
+
if (t[0] & 1) throw t[1];
|
|
71
|
+
return t[1];
|
|
72
|
+
},
|
|
73
|
+
trys: [],
|
|
74
|
+
ops: []
|
|
75
|
+
};
|
|
76
|
+
return g = {
|
|
77
|
+
next: verb(0),
|
|
78
|
+
"throw": verb(1),
|
|
79
|
+
"return": verb(2)
|
|
80
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
81
|
+
return this;
|
|
82
|
+
}), g;
|
|
83
|
+
function verb(n) {
|
|
84
|
+
return function(v) {
|
|
85
|
+
return step([
|
|
86
|
+
n,
|
|
87
|
+
v
|
|
88
|
+
]);
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function step(op) {
|
|
92
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
93
|
+
while(_)try {
|
|
94
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
95
|
+
if (y = 0, t) op = [
|
|
96
|
+
op[0] & 2,
|
|
97
|
+
t.value
|
|
98
|
+
];
|
|
99
|
+
switch(op[0]){
|
|
100
|
+
case 0:
|
|
101
|
+
case 1:
|
|
102
|
+
t = op;
|
|
103
|
+
break;
|
|
104
|
+
case 4:
|
|
105
|
+
_.label++;
|
|
106
|
+
return {
|
|
107
|
+
value: op[1],
|
|
108
|
+
done: false
|
|
109
|
+
};
|
|
110
|
+
case 5:
|
|
111
|
+
_.label++;
|
|
112
|
+
y = op[1];
|
|
113
|
+
op = [
|
|
114
|
+
0
|
|
115
|
+
];
|
|
116
|
+
continue;
|
|
117
|
+
case 7:
|
|
118
|
+
op = _.ops.pop();
|
|
119
|
+
_.trys.pop();
|
|
120
|
+
continue;
|
|
121
|
+
default:
|
|
122
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
123
|
+
_ = 0;
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
127
|
+
_.label = op[1];
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
131
|
+
_.label = t[1];
|
|
132
|
+
t = op;
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
if (t && _.label < t[2]) {
|
|
136
|
+
_.label = t[2];
|
|
137
|
+
_.ops.push(op);
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
if (t[2]) _.ops.pop();
|
|
141
|
+
_.trys.pop();
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
op = body.call(thisArg, _);
|
|
145
|
+
} catch (e) {
|
|
146
|
+
op = [
|
|
147
|
+
6,
|
|
148
|
+
e
|
|
149
|
+
];
|
|
150
|
+
y = 0;
|
|
151
|
+
} finally{
|
|
152
|
+
f = t = 0;
|
|
153
|
+
}
|
|
154
|
+
if (op[0] & 5) throw op[1];
|
|
155
|
+
return {
|
|
156
|
+
value: op[0] ? op[1] : void 0,
|
|
157
|
+
done: true
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
var // @ts-ignore init global variable for test
|
|
162
|
+
_globalThis, _globalThis___FEDERATION__;
|
|
163
|
+
var ___FEDERATION__;
|
|
164
|
+
(___FEDERATION__ = (_globalThis = globalThis).__FEDERATION__) !== null && ___FEDERATION__ !== void 0 ? ___FEDERATION__ : _globalThis.__FEDERATION__ = {};
|
|
165
|
+
var ___PREFETCH__;
|
|
166
|
+
(___PREFETCH__ = (_globalThis___FEDERATION__ = globalThis.__FEDERATION__).__PREFETCH__) !== null && ___PREFETCH__ !== void 0 ? ___PREFETCH__ : _globalThis___FEDERATION__.__PREFETCH__ = {
|
|
167
|
+
entryLoading: {},
|
|
168
|
+
instance: new Map(),
|
|
169
|
+
__PREFETCH_EXPORTS__: {}
|
|
170
|
+
};
|
|
171
|
+
var MFDataPrefetch = /*#__PURE__*/ function() {
|
|
172
|
+
function MFDataPrefetch(options) {
|
|
173
|
+
_class_call_check(this, MFDataPrefetch);
|
|
174
|
+
_define_property(this, "prefetchMemory", void 0);
|
|
175
|
+
_define_property(this, "recordOutdate", void 0);
|
|
176
|
+
_define_property(this, "_exports", void 0);
|
|
177
|
+
_define_property(this, "_options", void 0);
|
|
178
|
+
this.prefetchMemory = new Map();
|
|
179
|
+
this.recordOutdate = {};
|
|
180
|
+
this._exports = {};
|
|
181
|
+
this._options = options;
|
|
182
|
+
this.global.instance.set(options.name, this);
|
|
183
|
+
}
|
|
184
|
+
_create_class(MFDataPrefetch, [
|
|
185
|
+
{
|
|
186
|
+
key: "global",
|
|
187
|
+
get: function get() {
|
|
188
|
+
return globalThis.__FEDERATION__.__PREFETCH__;
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
key: "loadEntry",
|
|
193
|
+
value: function loadEntry(entry) {
|
|
194
|
+
var _this = this;
|
|
195
|
+
return _async_to_generator(function() {
|
|
196
|
+
var _this__options, name, remoteSnapshot, remote, origin, buildVersion, globalName, uniqueKey, remoteInfo, module;
|
|
197
|
+
return _ts_generator(this, function(_state) {
|
|
198
|
+
_this__options = _this._options, name = _this__options.name, remoteSnapshot = _this__options.remoteSnapshot, remote = _this__options.remote, origin = _this__options.origin;
|
|
199
|
+
if (entry) {
|
|
200
|
+
buildVersion = remoteSnapshot.buildVersion, globalName = remoteSnapshot.globalName;
|
|
201
|
+
uniqueKey = globalName || "".concat(name, ":").concat(buildVersion);
|
|
202
|
+
if (!_this.global.entryLoading[uniqueKey]) {
|
|
203
|
+
_this.global.entryLoading[uniqueKey] = loadScript(entry, {});
|
|
204
|
+
}
|
|
205
|
+
return [
|
|
206
|
+
2,
|
|
207
|
+
_this.global.entryLoading[uniqueKey]
|
|
208
|
+
];
|
|
209
|
+
} else {
|
|
210
|
+
remoteInfo = getRemoteInfo(remote);
|
|
211
|
+
module = origin.moduleCache.get(remoteInfo.name);
|
|
212
|
+
return [
|
|
213
|
+
2,
|
|
214
|
+
getRemoteEntry({
|
|
215
|
+
origin: origin,
|
|
216
|
+
remoteInfo: remoteInfo,
|
|
217
|
+
remoteEntryExports: module ? module.remoteEntryExports : undefined
|
|
218
|
+
})
|
|
219
|
+
];
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
})();
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
key: "getProjectExports",
|
|
227
|
+
value: function getProjectExports() {
|
|
228
|
+
var _this = this;
|
|
229
|
+
var _globalThis___FEDERATION_____PREFETCH_____PREFETCH_EXPORTS__;
|
|
230
|
+
if (Object.keys(this._exports).length > 0) {
|
|
231
|
+
return this._exports;
|
|
232
|
+
}
|
|
233
|
+
var name = this._options.name;
|
|
234
|
+
var exportsPromiseFn = (_globalThis___FEDERATION_____PREFETCH_____PREFETCH_EXPORTS__ = globalThis.__FEDERATION__.__PREFETCH__.__PREFETCH_EXPORTS__) === null || _globalThis___FEDERATION_____PREFETCH_____PREFETCH_EXPORTS__ === void 0 ? void 0 : _globalThis___FEDERATION_____PREFETCH_____PREFETCH_EXPORTS__[name];
|
|
235
|
+
var exportsPromise = typeof exportsPromiseFn === 'function' ? exportsPromiseFn() : Promise.resolve({});
|
|
236
|
+
var resolve = exportsPromise.then(function() {
|
|
237
|
+
var exports = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
238
|
+
// Match prefetch based on the function name suffix so that other capabilities can be expanded later.
|
|
239
|
+
// Not all functions should be directly identified as prefetch functions
|
|
240
|
+
var memory = {};
|
|
241
|
+
Object.keys(exports).forEach(function(key) {
|
|
242
|
+
memory[key] = {};
|
|
243
|
+
var exportVal = exports[key];
|
|
244
|
+
Object.keys(exportVal).reduce(function(memo, current) {
|
|
245
|
+
if (current.toLocaleLowerCase().endsWith('prefetch') || current.toLocaleLowerCase() === 'default') {
|
|
246
|
+
memo[current] = exportVal[current];
|
|
247
|
+
}
|
|
248
|
+
return memo;
|
|
249
|
+
}, memory[key]);
|
|
250
|
+
});
|
|
251
|
+
_this.memorizeExports(memory);
|
|
252
|
+
});
|
|
253
|
+
return resolve;
|
|
254
|
+
}
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
key: "memorizeExports",
|
|
258
|
+
value: function memorizeExports(exports) {
|
|
259
|
+
this._exports = exports;
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
key: "getExposeExports",
|
|
264
|
+
value: function getExposeExports(id) {
|
|
265
|
+
var prefetchId = getPrefetchId(id);
|
|
266
|
+
var compatId = compatGetPrefetchId(id);
|
|
267
|
+
var prefetchExports = this._exports[prefetchId] || this._exports[compatId];
|
|
268
|
+
return prefetchExports || {};
|
|
269
|
+
}
|
|
270
|
+
},
|
|
271
|
+
{
|
|
272
|
+
key: "prefetch",
|
|
273
|
+
value: function prefetch(prefetchOptions) {
|
|
274
|
+
var id = prefetchOptions.id, _prefetchOptions_functionId = prefetchOptions.functionId, functionId = _prefetchOptions_functionId === void 0 ? 'default' : _prefetchOptions_functionId, refetchParams = prefetchOptions.refetchParams;
|
|
275
|
+
var prefetchResult;
|
|
276
|
+
var prefetchId = getPrefetchId(id);
|
|
277
|
+
var compatId = compatGetPrefetchId(id);
|
|
278
|
+
var memorizeId = id + functionId;
|
|
279
|
+
var memory = this.prefetchMemory.get(memorizeId);
|
|
280
|
+
if (!this.checkOutdate(prefetchOptions) && memory) {
|
|
281
|
+
return memory;
|
|
282
|
+
}
|
|
283
|
+
var prefetchExports = this._exports[prefetchId] || this._exports[compatId];
|
|
284
|
+
if (!prefetchExports) {
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
var executePrefetch = prefetchExports[functionId];
|
|
288
|
+
if (typeof executePrefetch === 'function') {
|
|
289
|
+
if (refetchParams) {
|
|
290
|
+
prefetchResult = executePrefetch(refetchParams);
|
|
291
|
+
} else {
|
|
292
|
+
prefetchResult = executePrefetch();
|
|
293
|
+
}
|
|
294
|
+
} else {
|
|
295
|
+
throw new Error("[Module Federation Data Prefetch]: No prefetch function called ".concat(functionId, " export in prefetch file"));
|
|
296
|
+
}
|
|
297
|
+
this.memorize(memorizeId, prefetchResult);
|
|
298
|
+
return prefetchResult;
|
|
299
|
+
}
|
|
300
|
+
},
|
|
301
|
+
{
|
|
302
|
+
key: "memorize",
|
|
303
|
+
value: function memorize(id, value) {
|
|
304
|
+
this.prefetchMemory.set(id, value);
|
|
305
|
+
}
|
|
306
|
+
},
|
|
307
|
+
{
|
|
308
|
+
key: "markOutdate",
|
|
309
|
+
value: function markOutdate(markOptions, isOutdate) {
|
|
310
|
+
var id = markOptions.id, _markOptions_functionId = markOptions.functionId, functionId = _markOptions_functionId === void 0 ? 'default' : _markOptions_functionId;
|
|
311
|
+
if (!this.recordOutdate[id]) {
|
|
312
|
+
this.recordOutdate[id] = {};
|
|
313
|
+
}
|
|
314
|
+
this.recordOutdate[id][functionId] = isOutdate;
|
|
315
|
+
}
|
|
316
|
+
},
|
|
317
|
+
{
|
|
318
|
+
key: "checkOutdate",
|
|
319
|
+
value: function checkOutdate(outdateOptions) {
|
|
320
|
+
var id = outdateOptions.id, _outdateOptions_functionId = outdateOptions.functionId, functionId = _outdateOptions_functionId === void 0 ? 'default' : _outdateOptions_functionId, cacheStrategy = outdateOptions.cacheStrategy;
|
|
321
|
+
if (typeof cacheStrategy === 'function') {
|
|
322
|
+
return cacheStrategy();
|
|
323
|
+
}
|
|
324
|
+
if (!this.recordOutdate[id]) {
|
|
325
|
+
this.recordOutdate[id] = {};
|
|
326
|
+
}
|
|
327
|
+
if (this.recordOutdate[id][functionId]) {
|
|
328
|
+
this.markOutdate({
|
|
329
|
+
id: id,
|
|
330
|
+
functionId: functionId
|
|
331
|
+
}, false);
|
|
332
|
+
return true;
|
|
333
|
+
} else {
|
|
334
|
+
return false;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
], [
|
|
339
|
+
{
|
|
340
|
+
key: "getInstance",
|
|
341
|
+
value: function getInstance(id) {
|
|
342
|
+
return globalThis.__FEDERATION__.__PREFETCH__.instance.get(id);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
]);
|
|
346
|
+
return MFDataPrefetch;
|
|
347
|
+
}();
|
|
348
|
+
|
|
349
|
+
export { MFDataPrefetch as M };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/react/index";
|