@module-federation/data-prefetch 1.0.16 → 2.0.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.
- package/LICENSE +1 -1
- package/README.md +3 -1
- package/dist/LICENSE +21 -0
- package/dist/babel.cjs +95 -0
- package/dist/babel.d.ts +1 -0
- package/dist/babel.js +5 -0
- package/dist/cli/babel.cjs +115 -0
- package/dist/cli/babel.d.ts +2 -4
- package/dist/cli/babel.js +50 -82
- package/dist/cli/index.cjs +217 -0
- package/dist/cli/index.d.ts +5 -8
- package/dist/cli/index.js +150 -197
- package/dist/cli.cjs +95 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +5 -0
- package/dist/common/constant.cjs +51 -0
- package/dist/common/constant.d.ts +1 -0
- package/dist/common/constant.js +5 -0
- package/dist/common/index.cjs +95 -0
- package/dist/common/index.js +5 -0
- package/dist/common/node-utils.cjs +100 -0
- package/dist/common/node-utils.d.ts +2 -0
- package/dist/common/node-utils.js +35 -0
- package/dist/common/runtime-utils.cjs +84 -0
- package/dist/common/runtime-utils.d.ts +5 -0
- package/dist/common/runtime-utils.js +29 -0
- package/dist/constant.cjs +51 -0
- package/dist/constant.d.ts +1 -0
- package/dist/constant.js +5 -0
- package/dist/index.cjs +106 -0
- package/dist/index.d.ts +2 -5
- package/dist/index.js +3 -346
- package/dist/logger/index.cjs +60 -0
- package/dist/logger/index.d.ts +2 -0
- package/dist/logger/index.js +10 -0
- package/dist/plugin.cjs +234 -0
- package/dist/plugin.d.ts +3 -5
- package/dist/plugin.js +167 -340
- package/dist/prefetch.cjs +197 -0
- package/dist/{prefetch-4e9646e4.d.ts → prefetch.d.ts} +14 -17
- package/dist/prefetch.js +149 -0
- package/dist/react/hooks.cjs +144 -0
- package/dist/react/hooks.d.ts +11 -0
- package/dist/react/hooks.js +86 -0
- package/dist/react/index.cjs +95 -0
- package/dist/react/index.d.ts +1 -16
- package/dist/react/index.js +2 -283
- package/dist/react/utils.cjs +65 -0
- package/dist/react/utils.d.ts +1 -0
- package/dist/react/utils.js +15 -0
- package/dist/react.cjs +95 -0
- package/dist/react.d.ts +1 -0
- package/dist/react.js +5 -0
- package/dist/universal/index.cjs +81 -0
- package/dist/universal/index.d.ts +2 -8
- package/dist/universal/index.js +24 -196
- package/dist/universal.cjs +95 -0
- package/dist/universal.d.ts +1 -0
- package/dist/universal.js +5 -0
- package/package.json +76 -40
- package/CHANGELOG.md +0 -9
- package/__tests__/babel.spec.ts +0 -75
- package/__tests__/prefetch.spec.ts +0 -138
- package/__tests__/react.spec.ts +0 -119
- 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/shared/index.d.ts +0 -5
- package/dist/shared/index.js +0 -48
- package/jest.config.js +0 -29
- package/project.json +0 -21
- package/src/cli/babel.ts +0 -94
- package/src/cli/index.ts +0 -171
- package/src/common/constant.ts +0 -1
- package/src/common/node-utils.ts +0 -24
- package/src/common/runtime-utils.ts +0 -34
- package/src/index.ts +0 -2
- package/src/logger/index.ts +0 -3
- package/src/plugin.ts +0 -191
- package/src/prefetch.ts +0 -207
- package/src/react/hooks.ts +0 -95
- package/src/react/index.ts +0 -1
- package/src/react/utils.ts +0 -11
- package/src/shared/index.ts +0 -26
- package/src/universal/index.ts +0 -27
- package/tsconfig.json +0 -27
- package/tsup.config.ts +0 -35
- /package/{src/common/index.ts → dist/common/index.d.ts} +0 -0
package/dist/plugin.js
CHANGED
|
@@ -1,346 +1,173 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
import { getResourceUrl } from "@module-federation/sdk";
|
|
2
|
+
import { getSignalFromManifest } from "./common/runtime-utils.js";
|
|
3
|
+
import { MFDataPrefetch } from "./prefetch.js";
|
|
4
|
+
import logger from "./logger/index.js";
|
|
5
|
+
import { SHARED_STRATEGY } from "./constant.js";
|
|
19
6
|
|
|
20
|
-
|
|
21
|
-
var plugin_exports = {};
|
|
22
|
-
__export(plugin_exports, {
|
|
23
|
-
default: () => plugin_default,
|
|
24
|
-
prefetchPlugin: () => prefetchPlugin
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(plugin_exports);
|
|
27
|
-
var import_sdk4 = require("@module-federation/sdk");
|
|
7
|
+
;// CONCATENATED MODULE: external "@module-federation/sdk"
|
|
28
8
|
|
|
29
|
-
|
|
30
|
-
var import_runtime = require("@module-federation/runtime");
|
|
31
|
-
var import_sdk = require("@module-federation/sdk");
|
|
32
|
-
var getPrefetchId = (id) => (0, import_sdk.encodeName)(`${id}/${import_sdk.MFPrefetchCommon.identifier}`);
|
|
33
|
-
var compatGetPrefetchId = (id) => (0, import_sdk.encodeName)(`${id}/VmokPrefetch`);
|
|
34
|
-
var getSignalFromManifest = (remoteSnapshot) => {
|
|
35
|
-
if (!remoteSnapshot) {
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
if (!("prefetchEntry" in remoteSnapshot) && !("prefetchInterface" in remoteSnapshot)) {
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
if (!remoteSnapshot.prefetchEntry && !remoteSnapshot.prefetchInterface) {
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
return true;
|
|
45
|
-
};
|
|
9
|
+
;// CONCATENATED MODULE: external "./common/runtime-utils.js"
|
|
46
10
|
|
|
47
|
-
|
|
48
|
-
var import_runtime2 = require("@module-federation/runtime");
|
|
49
|
-
var import_sdk2 = require("@module-federation/sdk");
|
|
50
|
-
globalThis.__FEDERATION__ ?? (globalThis.__FEDERATION__ = {});
|
|
51
|
-
var _a;
|
|
52
|
-
(_a = globalThis.__FEDERATION__).__PREFETCH__ ?? (_a.__PREFETCH__ = {
|
|
53
|
-
entryLoading: {},
|
|
54
|
-
instance: /* @__PURE__ */ new Map(),
|
|
55
|
-
__PREFETCH_EXPORTS__: {}
|
|
56
|
-
});
|
|
57
|
-
var MFDataPrefetch = class {
|
|
58
|
-
constructor(options) {
|
|
59
|
-
this.prefetchMemory = /* @__PURE__ */ new Map();
|
|
60
|
-
this.recordOutdate = {};
|
|
61
|
-
this._exports = {};
|
|
62
|
-
this._options = options;
|
|
63
|
-
this.global.instance.set(options.name, this);
|
|
64
|
-
}
|
|
65
|
-
get global() {
|
|
66
|
-
return globalThis.__FEDERATION__.__PREFETCH__;
|
|
67
|
-
}
|
|
68
|
-
static getInstance(id) {
|
|
69
|
-
return globalThis.__FEDERATION__.__PREFETCH__.instance.get(id);
|
|
70
|
-
}
|
|
71
|
-
async loadEntry(entry) {
|
|
72
|
-
const { name, remoteSnapshot, remote, origin } = this._options;
|
|
73
|
-
if (entry) {
|
|
74
|
-
const { buildVersion, globalName } = remoteSnapshot;
|
|
75
|
-
const uniqueKey = globalName || `${name}:${buildVersion}`;
|
|
76
|
-
if (!this.global.entryLoading[uniqueKey]) {
|
|
77
|
-
this.global.entryLoading[uniqueKey] = (0, import_sdk2.loadScript)(entry, {});
|
|
78
|
-
}
|
|
79
|
-
return this.global.entryLoading[uniqueKey];
|
|
80
|
-
} else {
|
|
81
|
-
const remoteInfo = (0, import_runtime2.getRemoteInfo)(remote);
|
|
82
|
-
const module2 = origin.moduleCache.get(remoteInfo.name);
|
|
83
|
-
return (0, import_runtime2.getRemoteEntry)({
|
|
84
|
-
origin,
|
|
85
|
-
remoteInfo,
|
|
86
|
-
remoteEntryExports: module2 ? module2.remoteEntryExports : void 0
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
getProjectExports() {
|
|
91
|
-
var _a2;
|
|
92
|
-
if (Object.keys(this._exports).length > 0) {
|
|
93
|
-
return this._exports;
|
|
94
|
-
}
|
|
95
|
-
const { name } = this._options;
|
|
96
|
-
const exportsPromise = (_a2 = globalThis.__FEDERATION__.__PREFETCH__.__PREFETCH_EXPORTS__) == null ? void 0 : _a2[name];
|
|
97
|
-
const resolve = exportsPromise.then(
|
|
98
|
-
(exports = {}) => {
|
|
99
|
-
const memory = {};
|
|
100
|
-
Object.keys(exports).forEach((key) => {
|
|
101
|
-
memory[key] = {};
|
|
102
|
-
const exportVal = exports[key];
|
|
103
|
-
Object.keys(exportVal).reduce(
|
|
104
|
-
(memo, current) => {
|
|
105
|
-
if (current.toLocaleLowerCase().endsWith("prefetch") || current.toLocaleLowerCase() === "default") {
|
|
106
|
-
memo[current] = exportVal[current];
|
|
107
|
-
}
|
|
108
|
-
return memo;
|
|
109
|
-
},
|
|
110
|
-
memory[key]
|
|
111
|
-
);
|
|
112
|
-
});
|
|
113
|
-
this.memorizeExports(memory);
|
|
114
|
-
}
|
|
115
|
-
);
|
|
116
|
-
return resolve;
|
|
117
|
-
}
|
|
118
|
-
memorizeExports(exports) {
|
|
119
|
-
this._exports = exports;
|
|
120
|
-
}
|
|
121
|
-
getExposeExports(id) {
|
|
122
|
-
const prefetchId = getPrefetchId(id);
|
|
123
|
-
const compatId = compatGetPrefetchId(id);
|
|
124
|
-
const prefetchExports = this._exports[prefetchId] || this._exports[compatId];
|
|
125
|
-
return prefetchExports || {};
|
|
126
|
-
}
|
|
127
|
-
prefetch(prefetchOptions) {
|
|
128
|
-
const { id, functionId = "default", refetchParams } = prefetchOptions;
|
|
129
|
-
let prefetchResult;
|
|
130
|
-
const prefetchId = getPrefetchId(id);
|
|
131
|
-
const compatId = compatGetPrefetchId(id);
|
|
132
|
-
const memorizeId = id + functionId;
|
|
133
|
-
const memory = this.prefetchMemory.get(memorizeId);
|
|
134
|
-
if (!this.checkOutdate(prefetchOptions) && memory) {
|
|
135
|
-
return memory;
|
|
136
|
-
}
|
|
137
|
-
const prefetchExports = this._exports[prefetchId] || this._exports[compatId];
|
|
138
|
-
if (!prefetchExports) {
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
const executePrefetch = prefetchExports[functionId];
|
|
142
|
-
if (typeof executePrefetch === "function") {
|
|
143
|
-
if (refetchParams) {
|
|
144
|
-
prefetchResult = executePrefetch(refetchParams);
|
|
145
|
-
} else {
|
|
146
|
-
prefetchResult = executePrefetch();
|
|
147
|
-
}
|
|
148
|
-
} else {
|
|
149
|
-
throw new Error(
|
|
150
|
-
`[Module Federation Data Prefetch]: No prefetch function called ${functionId} export in prefetch file`
|
|
151
|
-
);
|
|
152
|
-
}
|
|
153
|
-
this.memorize(memorizeId, prefetchResult);
|
|
154
|
-
return prefetchResult;
|
|
155
|
-
}
|
|
156
|
-
memorize(id, value) {
|
|
157
|
-
this.prefetchMemory.set(id, value);
|
|
158
|
-
}
|
|
159
|
-
markOutdate(markOptions, isOutdate) {
|
|
160
|
-
const { id, functionId = "default" } = markOptions;
|
|
161
|
-
if (!this.recordOutdate[id]) {
|
|
162
|
-
this.recordOutdate[id] = {};
|
|
163
|
-
}
|
|
164
|
-
this.recordOutdate[id][functionId] = isOutdate;
|
|
165
|
-
}
|
|
166
|
-
checkOutdate(outdateOptions) {
|
|
167
|
-
const { id, functionId = "default", cacheStrategy } = outdateOptions;
|
|
168
|
-
if (typeof cacheStrategy === "function") {
|
|
169
|
-
return cacheStrategy();
|
|
170
|
-
}
|
|
171
|
-
if (!this.recordOutdate[id]) {
|
|
172
|
-
this.recordOutdate[id] = {};
|
|
173
|
-
}
|
|
174
|
-
if (this.recordOutdate[id][functionId]) {
|
|
175
|
-
this.markOutdate(
|
|
176
|
-
{
|
|
177
|
-
id,
|
|
178
|
-
functionId
|
|
179
|
-
},
|
|
180
|
-
false
|
|
181
|
-
);
|
|
182
|
-
return true;
|
|
183
|
-
} else {
|
|
184
|
-
return false;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
};
|
|
11
|
+
;// CONCATENATED MODULE: external "./prefetch.js"
|
|
188
12
|
|
|
189
|
-
|
|
190
|
-
var import_sdk3 = require("@module-federation/sdk");
|
|
191
|
-
var logger_default = new import_sdk3.Logger("[Module Federation Data Prefetch]");
|
|
13
|
+
;// CONCATENATED MODULE: external "./logger/index.js"
|
|
192
14
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
15
|
+
;// CONCATENATED MODULE: external "./constant.js"
|
|
16
|
+
|
|
17
|
+
;// CONCATENATED MODULE: ./src/plugin.ts
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
const loadingArray = [];
|
|
24
|
+
let sharedFlag = SHARED_STRATEGY;
|
|
25
|
+
// eslint-disable-next-line max-lines-per-function
|
|
26
|
+
const prefetchPlugin = ()=>({
|
|
27
|
+
name: 'data-prefetch-runtime-plugin',
|
|
28
|
+
initContainer (options) {
|
|
29
|
+
const { remoteSnapshot, remoteInfo, id, origin } = options;
|
|
30
|
+
if (!id) {
|
|
31
|
+
return options;
|
|
32
|
+
}
|
|
33
|
+
const snapshot = remoteSnapshot;
|
|
34
|
+
const { name } = remoteInfo;
|
|
35
|
+
const prefetchOptions = {
|
|
36
|
+
name,
|
|
37
|
+
remote: remoteInfo,
|
|
38
|
+
origin,
|
|
39
|
+
remoteSnapshot: snapshot
|
|
40
|
+
};
|
|
41
|
+
const signal = getSignalFromManifest(snapshot);
|
|
42
|
+
if (!signal) {
|
|
43
|
+
return options;
|
|
44
|
+
}
|
|
45
|
+
if (sharedFlag !== SHARED_STRATEGY) {
|
|
46
|
+
throw new Error(`[Module Federation Data Prefetch]: If you want to use data prefetch, the shared strategy must be 'loaded-first'`);
|
|
47
|
+
}
|
|
48
|
+
const instance = MFDataPrefetch.getInstance(name) || new MFDataPrefetch(prefetchOptions);
|
|
49
|
+
let prefetchUrl;
|
|
50
|
+
// @ts-expect-error
|
|
51
|
+
if (snapshot.prefetchEntry) {
|
|
52
|
+
// @ts-expect-error
|
|
53
|
+
prefetchUrl = getResourceUrl(snapshot, snapshot.prefetchEntry);
|
|
54
|
+
}
|
|
55
|
+
const exist = loadingArray.find((loading)=>loading.id === id);
|
|
56
|
+
if (exist) {
|
|
57
|
+
return options;
|
|
58
|
+
}
|
|
59
|
+
const promise = instance.loadEntry(prefetchUrl).then(async ()=>{
|
|
60
|
+
const projectExports = instance.getProjectExports();
|
|
61
|
+
if (projectExports instanceof Promise) {
|
|
62
|
+
await projectExports;
|
|
63
|
+
}
|
|
64
|
+
return Promise.resolve().then(()=>{
|
|
65
|
+
const exports = instance.getExposeExports(id);
|
|
66
|
+
logger.info(`1. Start Prefetch initContainer: ${id} - ${performance.now()}`);
|
|
67
|
+
const result = Object.keys(exports).map((k)=>{
|
|
68
|
+
const value = instance.prefetch({
|
|
69
|
+
id,
|
|
70
|
+
functionId: k
|
|
71
|
+
});
|
|
72
|
+
const functionId = k;
|
|
73
|
+
return {
|
|
74
|
+
value,
|
|
75
|
+
functionId
|
|
76
|
+
};
|
|
77
|
+
});
|
|
78
|
+
return result;
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
loadingArray.push({
|
|
82
|
+
id,
|
|
83
|
+
promise
|
|
84
|
+
});
|
|
85
|
+
return options;
|
|
86
|
+
},
|
|
87
|
+
afterResolve (options) {
|
|
88
|
+
const { remoteSnapshot, remoteInfo, id, origin } = options;
|
|
89
|
+
const snapshot = remoteSnapshot;
|
|
90
|
+
const { name } = remoteInfo;
|
|
91
|
+
const prefetchOptions = {
|
|
92
|
+
name,
|
|
93
|
+
remote: remoteInfo,
|
|
94
|
+
origin,
|
|
95
|
+
remoteSnapshot: snapshot
|
|
96
|
+
};
|
|
97
|
+
const signal = getSignalFromManifest(snapshot);
|
|
98
|
+
if (!signal) {
|
|
99
|
+
return options;
|
|
100
|
+
}
|
|
101
|
+
const inited = loadingArray.some((info)=>info.id === id);
|
|
102
|
+
if (!inited) {
|
|
103
|
+
return options;
|
|
104
|
+
}
|
|
105
|
+
if (sharedFlag !== SHARED_STRATEGY) {
|
|
106
|
+
throw new Error(`[Module Federation Data Prefetch]: If you want to use data prefetch, the shared strategy must be 'loaded-first'`);
|
|
107
|
+
}
|
|
108
|
+
const instance = MFDataPrefetch.getInstance(name) || new MFDataPrefetch(prefetchOptions);
|
|
109
|
+
let prefetchUrl;
|
|
110
|
+
// @ts-expect-error
|
|
111
|
+
if (snapshot.prefetchEntry) {
|
|
112
|
+
// @ts-expect-error
|
|
113
|
+
prefetchUrl = getResourceUrl(snapshot, snapshot.prefetchEntry);
|
|
114
|
+
}
|
|
115
|
+
const index = loadingArray.findIndex((loading)=>loading.id === id);
|
|
116
|
+
// clear cache
|
|
117
|
+
if (index !== -1) {
|
|
118
|
+
loadingArray.splice(index, 1);
|
|
119
|
+
}
|
|
120
|
+
const promise = instance.loadEntry(prefetchUrl).then(async ()=>{
|
|
121
|
+
const projectExports = instance.getProjectExports();
|
|
122
|
+
if (projectExports instanceof Promise) {
|
|
123
|
+
await projectExports;
|
|
124
|
+
}
|
|
125
|
+
return Promise.resolve().then(()=>{
|
|
126
|
+
const exports = instance.getExposeExports(id);
|
|
127
|
+
logger.info(`1. Start Prefetch afterResolve: ${id} - ${performance.now()}`);
|
|
128
|
+
const result = Object.keys(exports).map((k)=>{
|
|
129
|
+
const value = instance.prefetch({
|
|
130
|
+
id,
|
|
131
|
+
functionId: k
|
|
132
|
+
});
|
|
133
|
+
const functionId = k;
|
|
134
|
+
return {
|
|
135
|
+
value,
|
|
136
|
+
functionId
|
|
137
|
+
};
|
|
138
|
+
});
|
|
139
|
+
return result;
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
loadingArray.push({
|
|
143
|
+
id,
|
|
144
|
+
promise
|
|
145
|
+
});
|
|
146
|
+
return options;
|
|
147
|
+
},
|
|
148
|
+
async onLoad (options) {
|
|
149
|
+
var _loadingArray_find;
|
|
150
|
+
const { remote, id } = options;
|
|
151
|
+
const { name } = remote;
|
|
152
|
+
const promise = (_loadingArray_find = loadingArray.find((loading)=>loading.id === id)) === null || _loadingArray_find === void 0 ? void 0 : _loadingArray_find.promise;
|
|
153
|
+
if (promise) {
|
|
154
|
+
const prefetch = await promise;
|
|
155
|
+
const prefetchValue = prefetch.map((result)=>result.value);
|
|
156
|
+
await Promise.all(prefetchValue);
|
|
157
|
+
const instance = MFDataPrefetch.getInstance(name);
|
|
158
|
+
prefetch.forEach((result)=>{
|
|
159
|
+
const { value, functionId } = result;
|
|
160
|
+
instance.memorize(id + functionId, value);
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
return options;
|
|
164
|
+
},
|
|
165
|
+
beforeLoadShare (options) {
|
|
166
|
+
const shareInfo = options.shareInfo;
|
|
167
|
+
sharedFlag = (shareInfo === null || shareInfo === void 0 ? void 0 : shareInfo.strategy) || sharedFlag;
|
|
168
|
+
return options;
|
|
169
|
+
}
|
|
316
170
|
});
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
var _a2;
|
|
321
|
-
const { remote, id } = options;
|
|
322
|
-
const { name } = remote;
|
|
323
|
-
const promise = (_a2 = loadingArray.find((loading) => loading.id === id)) == null ? void 0 : _a2.promise;
|
|
324
|
-
if (promise) {
|
|
325
|
-
const prefetch = await promise;
|
|
326
|
-
const prefetchValue = prefetch.map((result) => result.value);
|
|
327
|
-
await Promise.all(prefetchValue);
|
|
328
|
-
const instance = MFDataPrefetch.getInstance(name);
|
|
329
|
-
prefetch.forEach((result) => {
|
|
330
|
-
const { value, functionId } = result;
|
|
331
|
-
instance.memorize(id + functionId, value);
|
|
332
|
-
});
|
|
333
|
-
}
|
|
334
|
-
return options;
|
|
335
|
-
},
|
|
336
|
-
beforeLoadShare(options) {
|
|
337
|
-
const shareInfo = options.shareInfo;
|
|
338
|
-
sharedFlag = (shareInfo == null ? void 0 : shareInfo.strategy) || sharedFlag;
|
|
339
|
-
return options;
|
|
340
|
-
}
|
|
341
|
-
});
|
|
342
|
-
var plugin_default = prefetchPlugin;
|
|
343
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
344
|
-
0 && (module.exports = {
|
|
345
|
-
prefetchPlugin
|
|
346
|
-
});
|
|
171
|
+
/* ESM default export */ const src_plugin = (prefetchPlugin);
|
|
172
|
+
|
|
173
|
+
export { src_plugin as default, prefetchPlugin };
|