@module-federation/data-prefetch 0.6.7 → 0.6.9
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/.swcrc +29 -0
- package/CHANGELOG.md +18 -0
- package/dist/babel.cjs.js +23 -35
- package/dist/babel.esm.d.ts +2 -0
- package/dist/babel.esm.js +23 -31
- package/dist/cli.cjs.js +122 -3546
- package/dist/cli.esm.d.ts +1 -0
- package/dist/cli.esm.js +123 -3536
- package/dist/index.cjs.js +0 -2
- package/dist/index.esm.d.ts +1 -0
- package/dist/package.json +7 -6
- package/dist/plugin.cjs.js +95 -298
- package/dist/plugin.esm.d.ts +2 -0
- package/dist/plugin.esm.js +94 -297
- package/dist/polyfills.cjs.js +14 -0
- package/dist/polyfills.esm.js +12 -0
- package/dist/prefetch.cjs.js +118 -327
- package/dist/prefetch.esm.js +119 -328
- package/dist/react.cjs.js +31 -117
- package/dist/react.esm.d.ts +1 -0
- package/dist/react.esm.js +32 -116
- package/dist/runtime-utils.cjs.js +4 -8
- package/dist/runtime-utils.esm.js +5 -9
- package/dist/shared.cjs.js +10 -12
- package/dist/shared.esm.d.ts +2 -0
- package/dist/shared.esm.js +10 -12
- package/dist/universal.cjs.js +8 -17
- package/dist/universal.esm.d.ts +1 -0
- package/dist/universal.esm.js +9 -16
- package/package.json +5 -5
- package/project.json +2 -2
- package/rollup.config.js +22 -1
package/dist/index.cjs.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/index";
|
package/dist/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/data-prefetch",
|
|
3
3
|
"description": "Module Federation Data Prefetch",
|
|
4
|
-
"version": "0.6.
|
|
4
|
+
"version": "0.6.9",
|
|
5
5
|
"author": "nieyan <nyqykk@foxmail.com>",
|
|
6
6
|
"homepage": "https://github.com/module-federation/core",
|
|
7
7
|
"license": "MIT",
|
|
@@ -83,8 +83,8 @@
|
|
|
83
83
|
"jest": "^29.7.0",
|
|
84
84
|
"jest-environment-jsdom": "^29.7.0",
|
|
85
85
|
"minimist": "^1.2.8",
|
|
86
|
-
"react": "^18.
|
|
87
|
-
"react-dom": "^18.
|
|
86
|
+
"react": "^18.3.1",
|
|
87
|
+
"react-dom": "^18.3.1",
|
|
88
88
|
"react-router": "^6.21.3",
|
|
89
89
|
"react-test-renderer": "^18.2.0",
|
|
90
90
|
"ts-jest": "29.0.1",
|
|
@@ -92,8 +92,9 @@
|
|
|
92
92
|
"webpack": "5.75.0"
|
|
93
93
|
},
|
|
94
94
|
"dependencies": {
|
|
95
|
-
"@module-federation/sdk": "workspace:*",
|
|
96
95
|
"@module-federation/runtime": "workspace:*",
|
|
96
|
+
"@module-federation/sdk": "workspace:*",
|
|
97
97
|
"fs-extra": "9.1.0"
|
|
98
|
-
}
|
|
99
|
-
|
|
98
|
+
},
|
|
99
|
+
"types": "./index.esm.d.ts"
|
|
100
|
+
}
|
package/dist/plugin.cjs.js
CHANGED
|
@@ -8,355 +8,152 @@ var prefetch = require('./prefetch.cjs.js');
|
|
|
8
8
|
var index = require('./index.cjs2.js');
|
|
9
9
|
require('@module-federation/runtime');
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
var value = info.value;
|
|
15
|
-
} catch (error) {
|
|
16
|
-
reject(error);
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
if (info.done) {
|
|
20
|
-
resolve(value);
|
|
21
|
-
} else {
|
|
22
|
-
Promise.resolve(value).then(_next, _throw);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
function _async_to_generator(fn) {
|
|
26
|
-
return function() {
|
|
27
|
-
var self = this, args = arguments;
|
|
28
|
-
return new Promise(function(resolve, reject) {
|
|
29
|
-
var gen = fn.apply(self, args);
|
|
30
|
-
function _next(value) {
|
|
31
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
32
|
-
}
|
|
33
|
-
function _throw(err) {
|
|
34
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
35
|
-
}
|
|
36
|
-
_next(undefined);
|
|
37
|
-
});
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
function _instanceof(left, right) {
|
|
41
|
-
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
42
|
-
return !!right[Symbol.hasInstance](left);
|
|
43
|
-
} else {
|
|
44
|
-
return left instanceof right;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
function _ts_generator(thisArg, body) {
|
|
48
|
-
var f, y, t, g, _ = {
|
|
49
|
-
label: 0,
|
|
50
|
-
sent: function() {
|
|
51
|
-
if (t[0] & 1) throw t[1];
|
|
52
|
-
return t[1];
|
|
53
|
-
},
|
|
54
|
-
trys: [],
|
|
55
|
-
ops: []
|
|
56
|
-
};
|
|
57
|
-
return g = {
|
|
58
|
-
next: verb(0),
|
|
59
|
-
"throw": verb(1),
|
|
60
|
-
"return": verb(2)
|
|
61
|
-
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
62
|
-
return this;
|
|
63
|
-
}), g;
|
|
64
|
-
function verb(n) {
|
|
65
|
-
return function(v) {
|
|
66
|
-
return step([
|
|
67
|
-
n,
|
|
68
|
-
v
|
|
69
|
-
]);
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
function step(op) {
|
|
73
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
74
|
-
while(_)try {
|
|
75
|
-
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;
|
|
76
|
-
if (y = 0, t) op = [
|
|
77
|
-
op[0] & 2,
|
|
78
|
-
t.value
|
|
79
|
-
];
|
|
80
|
-
switch(op[0]){
|
|
81
|
-
case 0:
|
|
82
|
-
case 1:
|
|
83
|
-
t = op;
|
|
84
|
-
break;
|
|
85
|
-
case 4:
|
|
86
|
-
_.label++;
|
|
87
|
-
return {
|
|
88
|
-
value: op[1],
|
|
89
|
-
done: false
|
|
90
|
-
};
|
|
91
|
-
case 5:
|
|
92
|
-
_.label++;
|
|
93
|
-
y = op[1];
|
|
94
|
-
op = [
|
|
95
|
-
0
|
|
96
|
-
];
|
|
97
|
-
continue;
|
|
98
|
-
case 7:
|
|
99
|
-
op = _.ops.pop();
|
|
100
|
-
_.trys.pop();
|
|
101
|
-
continue;
|
|
102
|
-
default:
|
|
103
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
104
|
-
_ = 0;
|
|
105
|
-
continue;
|
|
106
|
-
}
|
|
107
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
108
|
-
_.label = op[1];
|
|
109
|
-
break;
|
|
110
|
-
}
|
|
111
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
112
|
-
_.label = t[1];
|
|
113
|
-
t = op;
|
|
114
|
-
break;
|
|
115
|
-
}
|
|
116
|
-
if (t && _.label < t[2]) {
|
|
117
|
-
_.label = t[2];
|
|
118
|
-
_.ops.push(op);
|
|
119
|
-
break;
|
|
120
|
-
}
|
|
121
|
-
if (t[2]) _.ops.pop();
|
|
122
|
-
_.trys.pop();
|
|
123
|
-
continue;
|
|
124
|
-
}
|
|
125
|
-
op = body.call(thisArg, _);
|
|
126
|
-
} catch (e) {
|
|
127
|
-
op = [
|
|
128
|
-
6,
|
|
129
|
-
e
|
|
130
|
-
];
|
|
131
|
-
y = 0;
|
|
132
|
-
} finally{
|
|
133
|
-
f = t = 0;
|
|
134
|
-
}
|
|
135
|
-
if (op[0] & 5) throw op[1];
|
|
136
|
-
return {
|
|
137
|
-
value: op[0] ? op[1] : void 0,
|
|
138
|
-
done: true
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
var loadingArray = [];
|
|
143
|
-
var strategy = 'loaded-first';
|
|
144
|
-
var sharedFlag = strategy;
|
|
11
|
+
const loadingArray = [];
|
|
12
|
+
const strategy = 'loaded-first';
|
|
13
|
+
let sharedFlag = strategy;
|
|
145
14
|
// eslint-disable-next-line max-lines-per-function
|
|
146
|
-
|
|
147
|
-
return {
|
|
15
|
+
const prefetchPlugin = ()=>({
|
|
148
16
|
name: 'data-prefetch-runtime-plugin',
|
|
149
|
-
initContainer
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
name
|
|
17
|
+
initContainer (options) {
|
|
18
|
+
const { remoteSnapshot, remoteInfo, id, origin } = options;
|
|
19
|
+
const snapshot = remoteSnapshot;
|
|
20
|
+
const { name } = remoteInfo;
|
|
21
|
+
const prefetchOptions = {
|
|
22
|
+
name,
|
|
155
23
|
remote: remoteInfo,
|
|
156
|
-
origin
|
|
24
|
+
origin,
|
|
157
25
|
remoteSnapshot: snapshot
|
|
158
26
|
};
|
|
159
|
-
|
|
27
|
+
const signal = runtimeUtils.getSignalFromManifest(snapshot);
|
|
160
28
|
if (!signal) {
|
|
161
29
|
return options;
|
|
162
30
|
}
|
|
163
31
|
if (sharedFlag !== strategy) {
|
|
164
|
-
throw new Error(
|
|
32
|
+
throw new Error(`[Module Federation Data Prefetch]: If you want to use data prefetch, the shared strategy must be 'loaded-first'`);
|
|
165
33
|
}
|
|
166
|
-
|
|
167
|
-
|
|
34
|
+
const instance = prefetch.MFDataPrefetch.getInstance(name) || new prefetch.MFDataPrefetch(prefetchOptions);
|
|
35
|
+
let prefetchUrl;
|
|
168
36
|
// @ts-expect-error
|
|
169
37
|
if (snapshot.prefetchEntry) {
|
|
170
38
|
// @ts-expect-error
|
|
171
39
|
prefetchUrl = sdk.getResourceUrl(snapshot, snapshot.prefetchEntry);
|
|
172
40
|
}
|
|
173
|
-
|
|
174
|
-
return loading.id === id;
|
|
175
|
-
});
|
|
41
|
+
const exist = loadingArray.find((loading)=>loading.id === id);
|
|
176
42
|
if (exist) {
|
|
177
43
|
return options;
|
|
178
44
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
Promise.resolve().then(function() {
|
|
200
|
-
var exports = instance.getExposeExports(id);
|
|
201
|
-
index.logger.info("1. Start Prefetch initContainer: ".concat(id, " - ").concat(performance.now()));
|
|
202
|
-
var result = Object.keys(exports).map(function(k) {
|
|
203
|
-
var value = instance.prefetch({
|
|
204
|
-
id: id,
|
|
205
|
-
functionId: k
|
|
206
|
-
});
|
|
207
|
-
var functionId = k;
|
|
208
|
-
return {
|
|
209
|
-
value: value,
|
|
210
|
-
functionId: functionId
|
|
211
|
-
};
|
|
212
|
-
});
|
|
213
|
-
return result;
|
|
214
|
-
})
|
|
215
|
-
];
|
|
216
|
-
}
|
|
45
|
+
const promise = instance.loadEntry(prefetchUrl).then(async ()=>{
|
|
46
|
+
const projectExports = instance.getProjectExports();
|
|
47
|
+
if (projectExports instanceof Promise) {
|
|
48
|
+
await projectExports;
|
|
49
|
+
}
|
|
50
|
+
return Promise.resolve().then(()=>{
|
|
51
|
+
const exports = instance.getExposeExports(id);
|
|
52
|
+
index.logger.info(`1. Start Prefetch initContainer: ${id} - ${performance.now()}`);
|
|
53
|
+
const result = Object.keys(exports).map((k)=>{
|
|
54
|
+
const value = instance.prefetch({
|
|
55
|
+
id,
|
|
56
|
+
functionId: k
|
|
57
|
+
});
|
|
58
|
+
const functionId = k;
|
|
59
|
+
return {
|
|
60
|
+
value,
|
|
61
|
+
functionId
|
|
62
|
+
};
|
|
63
|
+
});
|
|
64
|
+
return result;
|
|
217
65
|
});
|
|
218
|
-
})
|
|
66
|
+
});
|
|
219
67
|
loadingArray.push({
|
|
220
|
-
id
|
|
221
|
-
promise
|
|
68
|
+
id,
|
|
69
|
+
promise
|
|
222
70
|
});
|
|
223
71
|
return options;
|
|
224
72
|
},
|
|
225
|
-
afterResolve
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
name
|
|
73
|
+
afterResolve (options) {
|
|
74
|
+
const { remoteSnapshot, remoteInfo, id, origin } = options;
|
|
75
|
+
const snapshot = remoteSnapshot;
|
|
76
|
+
const { name } = remoteInfo;
|
|
77
|
+
const prefetchOptions = {
|
|
78
|
+
name,
|
|
231
79
|
remote: remoteInfo,
|
|
232
|
-
origin
|
|
80
|
+
origin,
|
|
233
81
|
remoteSnapshot: snapshot
|
|
234
82
|
};
|
|
235
|
-
|
|
83
|
+
const signal = runtimeUtils.getSignalFromManifest(snapshot);
|
|
236
84
|
if (!signal) {
|
|
237
85
|
return options;
|
|
238
86
|
}
|
|
239
|
-
|
|
240
|
-
return info.id === id;
|
|
241
|
-
});
|
|
87
|
+
const inited = loadingArray.some((info)=>info.id === id);
|
|
242
88
|
if (!inited) {
|
|
243
89
|
return options;
|
|
244
90
|
}
|
|
245
91
|
if (sharedFlag !== strategy) {
|
|
246
|
-
throw new Error(
|
|
92
|
+
throw new Error(`[Module Federation Data Prefetch]: If you want to use data prefetch, the shared strategy must be 'loaded-first'`);
|
|
247
93
|
}
|
|
248
|
-
|
|
249
|
-
|
|
94
|
+
const instance = prefetch.MFDataPrefetch.getInstance(name) || new prefetch.MFDataPrefetch(prefetchOptions);
|
|
95
|
+
let prefetchUrl;
|
|
250
96
|
// @ts-expect-error
|
|
251
97
|
if (snapshot.prefetchEntry) {
|
|
252
98
|
// @ts-expect-error
|
|
253
99
|
prefetchUrl = sdk.getResourceUrl(snapshot, snapshot.prefetchEntry);
|
|
254
100
|
}
|
|
255
|
-
|
|
256
|
-
return loading.id === id;
|
|
257
|
-
});
|
|
101
|
+
const index$1 = loadingArray.findIndex((loading)=>loading.id === id);
|
|
258
102
|
// clear cache
|
|
259
103
|
if (index$1 !== -1) {
|
|
260
104
|
loadingArray.splice(index$1, 1);
|
|
261
105
|
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
Promise.resolve().then(function() {
|
|
283
|
-
var exports = instance.getExposeExports(id);
|
|
284
|
-
index.logger.info("1. Start Prefetch afterResolve: ".concat(id, " - ").concat(performance.now()));
|
|
285
|
-
var result = Object.keys(exports).map(function(k) {
|
|
286
|
-
var value = instance.prefetch({
|
|
287
|
-
id: id,
|
|
288
|
-
functionId: k
|
|
289
|
-
});
|
|
290
|
-
var functionId = k;
|
|
291
|
-
return {
|
|
292
|
-
value: value,
|
|
293
|
-
functionId: functionId
|
|
294
|
-
};
|
|
295
|
-
});
|
|
296
|
-
return result;
|
|
297
|
-
})
|
|
298
|
-
];
|
|
299
|
-
}
|
|
106
|
+
const promise = instance.loadEntry(prefetchUrl).then(async ()=>{
|
|
107
|
+
const projectExports = instance.getProjectExports();
|
|
108
|
+
if (projectExports instanceof Promise) {
|
|
109
|
+
await projectExports;
|
|
110
|
+
}
|
|
111
|
+
return Promise.resolve().then(()=>{
|
|
112
|
+
const exports = instance.getExposeExports(id);
|
|
113
|
+
index.logger.info(`1. Start Prefetch afterResolve: ${id} - ${performance.now()}`);
|
|
114
|
+
const result = Object.keys(exports).map((k)=>{
|
|
115
|
+
const value = instance.prefetch({
|
|
116
|
+
id,
|
|
117
|
+
functionId: k
|
|
118
|
+
});
|
|
119
|
+
const functionId = k;
|
|
120
|
+
return {
|
|
121
|
+
value,
|
|
122
|
+
functionId
|
|
123
|
+
};
|
|
124
|
+
});
|
|
125
|
+
return result;
|
|
300
126
|
});
|
|
301
|
-
})
|
|
127
|
+
});
|
|
302
128
|
loadingArray.push({
|
|
303
|
-
id
|
|
304
|
-
promise
|
|
129
|
+
id,
|
|
130
|
+
promise
|
|
305
131
|
});
|
|
306
132
|
return options;
|
|
307
133
|
},
|
|
308
|
-
onLoad
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
3
|
|
322
|
-
];
|
|
323
|
-
return [
|
|
324
|
-
4,
|
|
325
|
-
promise
|
|
326
|
-
];
|
|
327
|
-
case 1:
|
|
328
|
-
prefetch$1 = _state.sent();
|
|
329
|
-
prefetchValue = prefetch$1.map(function(result) {
|
|
330
|
-
return result.value;
|
|
331
|
-
});
|
|
332
|
-
return [
|
|
333
|
-
4,
|
|
334
|
-
Promise.all(prefetchValue)
|
|
335
|
-
];
|
|
336
|
-
case 2:
|
|
337
|
-
_state.sent();
|
|
338
|
-
instance = prefetch.MFDataPrefetch.getInstance(name);
|
|
339
|
-
prefetch$1.forEach(function(result) {
|
|
340
|
-
var value = result.value, functionId = result.functionId;
|
|
341
|
-
instance.memorize(id + functionId, value);
|
|
342
|
-
});
|
|
343
|
-
_state.label = 3;
|
|
344
|
-
case 3:
|
|
345
|
-
return [
|
|
346
|
-
2,
|
|
347
|
-
options
|
|
348
|
-
];
|
|
349
|
-
}
|
|
134
|
+
async onLoad (options) {
|
|
135
|
+
var _loadingArray_find;
|
|
136
|
+
const { remote, id } = options;
|
|
137
|
+
const { name } = remote;
|
|
138
|
+
const promise = (_loadingArray_find = loadingArray.find((loading)=>loading.id === id)) == null ? void 0 : _loadingArray_find.promise;
|
|
139
|
+
if (promise) {
|
|
140
|
+
const prefetch$1 = await promise;
|
|
141
|
+
const prefetchValue = prefetch$1.map((result)=>result.value);
|
|
142
|
+
await Promise.all(prefetchValue);
|
|
143
|
+
const instance = prefetch.MFDataPrefetch.getInstance(name);
|
|
144
|
+
prefetch$1.forEach((result)=>{
|
|
145
|
+
const { value, functionId } = result;
|
|
146
|
+
instance.memorize(id + functionId, value);
|
|
350
147
|
});
|
|
351
|
-
}
|
|
148
|
+
}
|
|
149
|
+
return options;
|
|
352
150
|
},
|
|
353
|
-
beforeLoadShare
|
|
354
|
-
|
|
355
|
-
sharedFlag = (shareInfo
|
|
151
|
+
beforeLoadShare (options) {
|
|
152
|
+
const shareInfo = options.shareInfo;
|
|
153
|
+
sharedFlag = (shareInfo == null ? void 0 : shareInfo.strategy) || sharedFlag;
|
|
356
154
|
return options;
|
|
357
155
|
}
|
|
358
|
-
};
|
|
359
|
-
};
|
|
156
|
+
});
|
|
360
157
|
|
|
361
|
-
exports
|
|
158
|
+
exports.default = prefetchPlugin;
|
|
362
159
|
exports.prefetchPlugin = prefetchPlugin;
|