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