@module-federation/data-prefetch 0.0.0-next-20240808065005 → 0.0.0-next-20240909062831
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 +3 -3
- package/dist/esm/{chunk-JEPJP5O3.js → chunk-57ZXBP7D.js} +8 -13
- package/dist/esm/{chunk-WLE6YNDH.js → chunk-H3DTWHY4.js} +2 -68
- package/dist/esm/{chunk-QHQN3BPZ.js → chunk-OIIVUMED.js} +2 -2
- package/dist/esm/{chunk-EWCGK4XA.js → chunk-VWDP6NMM.js} +2 -0
- package/dist/esm/cli/index.js +1 -1
- package/dist/esm/index.js +3 -3
- package/dist/esm/plugin.js +3 -3
- package/dist/esm/react/index.js +3 -3
- package/dist/esm/universal/index.js +3 -3
- package/dist/index.js +7 -78
- package/dist/plugin.js +7 -78
- package/dist/react/index.js +7 -12
- package/dist/universal/index.js +7 -12
- package/package.json +3 -3
- package/src/common/runtime-utils.ts +3 -0
- package/src/plugin.ts +1 -95
- package/src/prefetch.ts +8 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
@module-federation/data-prefetch
|
|
2
2
|
|
|
3
|
-
## 0.0.0-next-
|
|
3
|
+
## 0.0.0-next-20240909062831
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
7
|
- 3ddab21: feat(@module-federation/data-prefetch): support data prefetch in Module Federation
|
|
8
|
-
- @module-federation/runtime@0.0.0-next-
|
|
9
|
-
- @module-federation/sdk@0.0.0-next-
|
|
8
|
+
- @module-federation/runtime@0.0.0-next-20240909062831
|
|
9
|
+
- @module-federation/sdk@0.0.0-next-20240909062831
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
+
compatGetPrefetchId,
|
|
2
3
|
getPrefetchId
|
|
3
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-VWDP6NMM.js";
|
|
4
5
|
|
|
5
6
|
// src/prefetch.ts
|
|
6
7
|
import {
|
|
@@ -44,17 +45,9 @@ var MFDataPrefetch = class {
|
|
|
44
45
|
const remoteInfo = getRemoteInfo(remote);
|
|
45
46
|
const module = origin.moduleCache.get(remoteInfo.name);
|
|
46
47
|
return getRemoteEntry({
|
|
48
|
+
origin,
|
|
47
49
|
remoteInfo,
|
|
48
|
-
remoteEntryExports: module ? module.remoteEntryExports : void 0
|
|
49
|
-
createScriptHook: (url) => {
|
|
50
|
-
const res = origin.loaderHook.lifecycle.createScript.emit({
|
|
51
|
-
url
|
|
52
|
-
});
|
|
53
|
-
if (res instanceof HTMLScriptElement) {
|
|
54
|
-
return res;
|
|
55
|
-
}
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
50
|
+
remoteEntryExports: module ? module.remoteEntryExports : void 0
|
|
58
51
|
});
|
|
59
52
|
}
|
|
60
53
|
}
|
|
@@ -91,19 +84,21 @@ var MFDataPrefetch = class {
|
|
|
91
84
|
}
|
|
92
85
|
getExposeExports(id) {
|
|
93
86
|
const prefetchId = getPrefetchId(id);
|
|
94
|
-
const
|
|
87
|
+
const compatId = compatGetPrefetchId(id);
|
|
88
|
+
const prefetchExports = this._exports[prefetchId] || this._exports[compatId];
|
|
95
89
|
return prefetchExports || {};
|
|
96
90
|
}
|
|
97
91
|
prefetch(prefetchOptions) {
|
|
98
92
|
const { id, functionId = "default", refetchParams } = prefetchOptions;
|
|
99
93
|
let prefetchResult;
|
|
100
94
|
const prefetchId = getPrefetchId(id);
|
|
95
|
+
const compatId = compatGetPrefetchId(id);
|
|
101
96
|
const memorizeId = id + functionId;
|
|
102
97
|
const memory = this.prefetchMemory.get(memorizeId);
|
|
103
98
|
if (!this.checkOutdate(prefetchOptions) && memory) {
|
|
104
99
|
return memory;
|
|
105
100
|
}
|
|
106
|
-
const prefetchExports = this._exports[prefetchId];
|
|
101
|
+
const prefetchExports = this._exports[prefetchId] || this._exports[compatId];
|
|
107
102
|
if (!prefetchExports) {
|
|
108
103
|
return;
|
|
109
104
|
}
|
|
@@ -3,13 +3,12 @@ import {
|
|
|
3
3
|
} from "./chunk-TTJJJ2WZ.js";
|
|
4
4
|
import {
|
|
5
5
|
MFDataPrefetch
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-57ZXBP7D.js";
|
|
7
7
|
import {
|
|
8
8
|
getSignalFromManifest
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-VWDP6NMM.js";
|
|
10
10
|
|
|
11
11
|
// src/plugin.ts
|
|
12
|
-
import { Module } from "@module-federation/runtime";
|
|
13
12
|
import { getResourceUrl } from "@module-federation/sdk";
|
|
14
13
|
var loadingArray = [];
|
|
15
14
|
var strategy = "loaded-first";
|
|
@@ -89,71 +88,6 @@ var prefetchPlugin = () => ({
|
|
|
89
88
|
}
|
|
90
89
|
return options;
|
|
91
90
|
},
|
|
92
|
-
handlePreloadModule(options) {
|
|
93
|
-
const { remoteSnapshot, name, id, preloadConfig, origin, remote } = options;
|
|
94
|
-
const snapshot = remoteSnapshot;
|
|
95
|
-
const signal = getSignalFromManifest(snapshot);
|
|
96
|
-
if (!signal) {
|
|
97
|
-
return options;
|
|
98
|
-
}
|
|
99
|
-
const prefetchOptions = {
|
|
100
|
-
name,
|
|
101
|
-
origin,
|
|
102
|
-
remote,
|
|
103
|
-
remoteSnapshot: snapshot
|
|
104
|
-
};
|
|
105
|
-
const instance = MFDataPrefetch.getInstance(name) || new MFDataPrefetch(prefetchOptions);
|
|
106
|
-
let prefetchUrl;
|
|
107
|
-
if (snapshot.prefetchEntry) {
|
|
108
|
-
prefetchUrl = getResourceUrl(snapshot, snapshot.prefetchEntry);
|
|
109
|
-
}
|
|
110
|
-
if (!preloadConfig.prefetchInterface) {
|
|
111
|
-
instance.loadEntry(prefetchUrl);
|
|
112
|
-
return options;
|
|
113
|
-
}
|
|
114
|
-
const promise = instance.loadEntry(prefetchUrl).then(async () => {
|
|
115
|
-
let module = origin.moduleCache.get(remote.name);
|
|
116
|
-
const moduleOptions = {
|
|
117
|
-
host: origin,
|
|
118
|
-
remoteInfo: remote
|
|
119
|
-
};
|
|
120
|
-
if (!module) {
|
|
121
|
-
module = new Module(moduleOptions);
|
|
122
|
-
origin.moduleCache.set(remote.name, module);
|
|
123
|
-
}
|
|
124
|
-
const idPart = id.split("/");
|
|
125
|
-
let expose = idPart[idPart.length - 1];
|
|
126
|
-
if (expose !== ".") {
|
|
127
|
-
expose = `./${expose}`;
|
|
128
|
-
}
|
|
129
|
-
await module.get(id, expose, {}, remoteSnapshot);
|
|
130
|
-
const projectExports = instance.getProjectExports();
|
|
131
|
-
if (projectExports instanceof Promise) {
|
|
132
|
-
await projectExports;
|
|
133
|
-
}
|
|
134
|
-
const exports = instance.getExposeExports(id);
|
|
135
|
-
logger_default.info(
|
|
136
|
-
`1. PreloadRemote Start Prefetch: ${id} - ${performance.now()}`
|
|
137
|
-
);
|
|
138
|
-
const result = Object.keys(exports).map((k) => {
|
|
139
|
-
const value = instance.prefetch({
|
|
140
|
-
id,
|
|
141
|
-
functionId: k
|
|
142
|
-
});
|
|
143
|
-
const functionId = k;
|
|
144
|
-
return {
|
|
145
|
-
value,
|
|
146
|
-
functionId
|
|
147
|
-
};
|
|
148
|
-
});
|
|
149
|
-
return result;
|
|
150
|
-
});
|
|
151
|
-
loadingArray.push({
|
|
152
|
-
id,
|
|
153
|
-
promise
|
|
154
|
-
});
|
|
155
|
-
return options;
|
|
156
|
-
},
|
|
157
91
|
beforeLoadShare(options) {
|
|
158
92
|
const shareInfo = options.shareInfo;
|
|
159
93
|
sharedFlag = (shareInfo == null ? void 0 : shareInfo.strategy) || sharedFlag;
|
|
@@ -12,6 +12,7 @@ var getScope = (id) => {
|
|
|
12
12
|
return name;
|
|
13
13
|
};
|
|
14
14
|
var getPrefetchId = (id) => encodeName(`${id}/${MFPrefetchCommon.identifier}`);
|
|
15
|
+
var compatGetPrefetchId = (id) => encodeName(`${id}/VmokPrefetch`);
|
|
15
16
|
var getSignalFromManifest = (remoteSnapshot) => {
|
|
16
17
|
if (!remoteSnapshot) {
|
|
17
18
|
return false;
|
|
@@ -28,5 +29,6 @@ var getSignalFromManifest = (remoteSnapshot) => {
|
|
|
28
29
|
export {
|
|
29
30
|
getScope,
|
|
30
31
|
getPrefetchId,
|
|
32
|
+
compatGetPrefetchId,
|
|
31
33
|
getSignalFromManifest
|
|
32
34
|
};
|
package/dist/esm/cli/index.js
CHANGED
package/dist/esm/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
prefetchPlugin
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-H3DTWHY4.js";
|
|
4
4
|
import "./chunk-TTJJJ2WZ.js";
|
|
5
5
|
import {
|
|
6
6
|
MFDataPrefetch
|
|
7
|
-
} from "./chunk-
|
|
8
|
-
import "./chunk-
|
|
7
|
+
} from "./chunk-57ZXBP7D.js";
|
|
8
|
+
import "./chunk-VWDP6NMM.js";
|
|
9
9
|
export {
|
|
10
10
|
MFDataPrefetch,
|
|
11
11
|
prefetchPlugin
|
package/dist/esm/plugin.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
plugin_default,
|
|
3
3
|
prefetchPlugin
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-H3DTWHY4.js";
|
|
5
5
|
import "./chunk-TTJJJ2WZ.js";
|
|
6
|
-
import "./chunk-
|
|
7
|
-
import "./chunk-
|
|
6
|
+
import "./chunk-57ZXBP7D.js";
|
|
7
|
+
import "./chunk-VWDP6NMM.js";
|
|
8
8
|
export {
|
|
9
9
|
plugin_default as default,
|
|
10
10
|
prefetchPlugin
|
package/dist/esm/react/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
2
|
prefetch
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-OIIVUMED.js";
|
|
4
4
|
import {
|
|
5
5
|
logger_default
|
|
6
6
|
} from "../chunk-TTJJJ2WZ.js";
|
|
7
7
|
import {
|
|
8
8
|
MFDataPrefetch
|
|
9
|
-
} from "../chunk-
|
|
9
|
+
} from "../chunk-57ZXBP7D.js";
|
|
10
10
|
import {
|
|
11
11
|
getScope
|
|
12
|
-
} from "../chunk-
|
|
12
|
+
} from "../chunk-VWDP6NMM.js";
|
|
13
13
|
|
|
14
14
|
// src/react/hooks.ts
|
|
15
15
|
import { useEffect as useEffect2, useState } from "react";
|
package/dist/index.js
CHANGED
|
@@ -32,6 +32,7 @@ var import_sdk2 = require("@module-federation/sdk");
|
|
|
32
32
|
// src/common/runtime-utils.ts
|
|
33
33
|
var import_sdk = require("@module-federation/sdk");
|
|
34
34
|
var getPrefetchId = (id) => (0, import_sdk.encodeName)(`${id}/${import_sdk.MFPrefetchCommon.identifier}`);
|
|
35
|
+
var compatGetPrefetchId = (id) => (0, import_sdk.encodeName)(`${id}/VmokPrefetch`);
|
|
35
36
|
var getSignalFromManifest = (remoteSnapshot) => {
|
|
36
37
|
if (!remoteSnapshot) {
|
|
37
38
|
return false;
|
|
@@ -80,17 +81,9 @@ var MFDataPrefetch = class {
|
|
|
80
81
|
const remoteInfo = (0, import_runtime.getRemoteInfo)(remote);
|
|
81
82
|
const module2 = origin.moduleCache.get(remoteInfo.name);
|
|
82
83
|
return (0, import_runtime.getRemoteEntry)({
|
|
84
|
+
origin,
|
|
83
85
|
remoteInfo,
|
|
84
|
-
remoteEntryExports: module2 ? module2.remoteEntryExports : void 0
|
|
85
|
-
createScriptHook: (url) => {
|
|
86
|
-
const res = origin.loaderHook.lifecycle.createScript.emit({
|
|
87
|
-
url
|
|
88
|
-
});
|
|
89
|
-
if (res instanceof HTMLScriptElement) {
|
|
90
|
-
return res;
|
|
91
|
-
}
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
86
|
+
remoteEntryExports: module2 ? module2.remoteEntryExports : void 0
|
|
94
87
|
});
|
|
95
88
|
}
|
|
96
89
|
}
|
|
@@ -127,19 +120,21 @@ var MFDataPrefetch = class {
|
|
|
127
120
|
}
|
|
128
121
|
getExposeExports(id) {
|
|
129
122
|
const prefetchId = getPrefetchId(id);
|
|
130
|
-
const
|
|
123
|
+
const compatId = compatGetPrefetchId(id);
|
|
124
|
+
const prefetchExports = this._exports[prefetchId] || this._exports[compatId];
|
|
131
125
|
return prefetchExports || {};
|
|
132
126
|
}
|
|
133
127
|
prefetch(prefetchOptions) {
|
|
134
128
|
const { id, functionId = "default", refetchParams } = prefetchOptions;
|
|
135
129
|
let prefetchResult;
|
|
136
130
|
const prefetchId = getPrefetchId(id);
|
|
131
|
+
const compatId = compatGetPrefetchId(id);
|
|
137
132
|
const memorizeId = id + functionId;
|
|
138
133
|
const memory = this.prefetchMemory.get(memorizeId);
|
|
139
134
|
if (!this.checkOutdate(prefetchOptions) && memory) {
|
|
140
135
|
return memory;
|
|
141
136
|
}
|
|
142
|
-
const prefetchExports = this._exports[prefetchId];
|
|
137
|
+
const prefetchExports = this._exports[prefetchId] || this._exports[compatId];
|
|
143
138
|
if (!prefetchExports) {
|
|
144
139
|
return;
|
|
145
140
|
}
|
|
@@ -192,7 +187,6 @@ var MFDataPrefetch = class {
|
|
|
192
187
|
};
|
|
193
188
|
|
|
194
189
|
// src/plugin.ts
|
|
195
|
-
var import_runtime2 = require("@module-federation/runtime");
|
|
196
190
|
var import_sdk4 = require("@module-federation/sdk");
|
|
197
191
|
|
|
198
192
|
// src/logger/index.ts
|
|
@@ -278,71 +272,6 @@ var prefetchPlugin = () => ({
|
|
|
278
272
|
}
|
|
279
273
|
return options;
|
|
280
274
|
},
|
|
281
|
-
handlePreloadModule(options) {
|
|
282
|
-
const { remoteSnapshot, name, id, preloadConfig, origin, remote } = options;
|
|
283
|
-
const snapshot = remoteSnapshot;
|
|
284
|
-
const signal = getSignalFromManifest(snapshot);
|
|
285
|
-
if (!signal) {
|
|
286
|
-
return options;
|
|
287
|
-
}
|
|
288
|
-
const prefetchOptions = {
|
|
289
|
-
name,
|
|
290
|
-
origin,
|
|
291
|
-
remote,
|
|
292
|
-
remoteSnapshot: snapshot
|
|
293
|
-
};
|
|
294
|
-
const instance = MFDataPrefetch.getInstance(name) || new MFDataPrefetch(prefetchOptions);
|
|
295
|
-
let prefetchUrl;
|
|
296
|
-
if (snapshot.prefetchEntry) {
|
|
297
|
-
prefetchUrl = (0, import_sdk4.getResourceUrl)(snapshot, snapshot.prefetchEntry);
|
|
298
|
-
}
|
|
299
|
-
if (!preloadConfig.prefetchInterface) {
|
|
300
|
-
instance.loadEntry(prefetchUrl);
|
|
301
|
-
return options;
|
|
302
|
-
}
|
|
303
|
-
const promise = instance.loadEntry(prefetchUrl).then(async () => {
|
|
304
|
-
let module2 = origin.moduleCache.get(remote.name);
|
|
305
|
-
const moduleOptions = {
|
|
306
|
-
host: origin,
|
|
307
|
-
remoteInfo: remote
|
|
308
|
-
};
|
|
309
|
-
if (!module2) {
|
|
310
|
-
module2 = new import_runtime2.Module(moduleOptions);
|
|
311
|
-
origin.moduleCache.set(remote.name, module2);
|
|
312
|
-
}
|
|
313
|
-
const idPart = id.split("/");
|
|
314
|
-
let expose = idPart[idPart.length - 1];
|
|
315
|
-
if (expose !== ".") {
|
|
316
|
-
expose = `./${expose}`;
|
|
317
|
-
}
|
|
318
|
-
await module2.get(id, expose, {}, remoteSnapshot);
|
|
319
|
-
const projectExports = instance.getProjectExports();
|
|
320
|
-
if (projectExports instanceof Promise) {
|
|
321
|
-
await projectExports;
|
|
322
|
-
}
|
|
323
|
-
const exports = instance.getExposeExports(id);
|
|
324
|
-
logger_default.info(
|
|
325
|
-
`1. PreloadRemote Start Prefetch: ${id} - ${performance.now()}`
|
|
326
|
-
);
|
|
327
|
-
const result = Object.keys(exports).map((k) => {
|
|
328
|
-
const value = instance.prefetch({
|
|
329
|
-
id,
|
|
330
|
-
functionId: k
|
|
331
|
-
});
|
|
332
|
-
const functionId = k;
|
|
333
|
-
return {
|
|
334
|
-
value,
|
|
335
|
-
functionId
|
|
336
|
-
};
|
|
337
|
-
});
|
|
338
|
-
return result;
|
|
339
|
-
});
|
|
340
|
-
loadingArray.push({
|
|
341
|
-
id,
|
|
342
|
-
promise
|
|
343
|
-
});
|
|
344
|
-
return options;
|
|
345
|
-
},
|
|
346
275
|
beforeLoadShare(options) {
|
|
347
276
|
const shareInfo = options.shareInfo;
|
|
348
277
|
sharedFlag = (shareInfo == null ? void 0 : shareInfo.strategy) || sharedFlag;
|
package/dist/plugin.js
CHANGED
|
@@ -24,12 +24,12 @@ __export(plugin_exports, {
|
|
|
24
24
|
prefetchPlugin: () => prefetchPlugin
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(plugin_exports);
|
|
27
|
-
var import_runtime2 = require("@module-federation/runtime");
|
|
28
27
|
var import_sdk4 = require("@module-federation/sdk");
|
|
29
28
|
|
|
30
29
|
// src/common/runtime-utils.ts
|
|
31
30
|
var import_sdk = require("@module-federation/sdk");
|
|
32
31
|
var getPrefetchId = (id) => (0, import_sdk.encodeName)(`${id}/${import_sdk.MFPrefetchCommon.identifier}`);
|
|
32
|
+
var compatGetPrefetchId = (id) => (0, import_sdk.encodeName)(`${id}/VmokPrefetch`);
|
|
33
33
|
var getSignalFromManifest = (remoteSnapshot) => {
|
|
34
34
|
if (!remoteSnapshot) {
|
|
35
35
|
return false;
|
|
@@ -80,17 +80,9 @@ var MFDataPrefetch = class {
|
|
|
80
80
|
const remoteInfo = (0, import_runtime.getRemoteInfo)(remote);
|
|
81
81
|
const module2 = origin.moduleCache.get(remoteInfo.name);
|
|
82
82
|
return (0, import_runtime.getRemoteEntry)({
|
|
83
|
+
origin,
|
|
83
84
|
remoteInfo,
|
|
84
|
-
remoteEntryExports: module2 ? module2.remoteEntryExports : void 0
|
|
85
|
-
createScriptHook: (url) => {
|
|
86
|
-
const res = origin.loaderHook.lifecycle.createScript.emit({
|
|
87
|
-
url
|
|
88
|
-
});
|
|
89
|
-
if (res instanceof HTMLScriptElement) {
|
|
90
|
-
return res;
|
|
91
|
-
}
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
85
|
+
remoteEntryExports: module2 ? module2.remoteEntryExports : void 0
|
|
94
86
|
});
|
|
95
87
|
}
|
|
96
88
|
}
|
|
@@ -127,19 +119,21 @@ var MFDataPrefetch = class {
|
|
|
127
119
|
}
|
|
128
120
|
getExposeExports(id) {
|
|
129
121
|
const prefetchId = getPrefetchId(id);
|
|
130
|
-
const
|
|
122
|
+
const compatId = compatGetPrefetchId(id);
|
|
123
|
+
const prefetchExports = this._exports[prefetchId] || this._exports[compatId];
|
|
131
124
|
return prefetchExports || {};
|
|
132
125
|
}
|
|
133
126
|
prefetch(prefetchOptions) {
|
|
134
127
|
const { id, functionId = "default", refetchParams } = prefetchOptions;
|
|
135
128
|
let prefetchResult;
|
|
136
129
|
const prefetchId = getPrefetchId(id);
|
|
130
|
+
const compatId = compatGetPrefetchId(id);
|
|
137
131
|
const memorizeId = id + functionId;
|
|
138
132
|
const memory = this.prefetchMemory.get(memorizeId);
|
|
139
133
|
if (!this.checkOutdate(prefetchOptions) && memory) {
|
|
140
134
|
return memory;
|
|
141
135
|
}
|
|
142
|
-
const prefetchExports = this._exports[prefetchId];
|
|
136
|
+
const prefetchExports = this._exports[prefetchId] || this._exports[compatId];
|
|
143
137
|
if (!prefetchExports) {
|
|
144
138
|
return;
|
|
145
139
|
}
|
|
@@ -274,71 +268,6 @@ var prefetchPlugin = () => ({
|
|
|
274
268
|
}
|
|
275
269
|
return options;
|
|
276
270
|
},
|
|
277
|
-
handlePreloadModule(options) {
|
|
278
|
-
const { remoteSnapshot, name, id, preloadConfig, origin, remote } = options;
|
|
279
|
-
const snapshot = remoteSnapshot;
|
|
280
|
-
const signal = getSignalFromManifest(snapshot);
|
|
281
|
-
if (!signal) {
|
|
282
|
-
return options;
|
|
283
|
-
}
|
|
284
|
-
const prefetchOptions = {
|
|
285
|
-
name,
|
|
286
|
-
origin,
|
|
287
|
-
remote,
|
|
288
|
-
remoteSnapshot: snapshot
|
|
289
|
-
};
|
|
290
|
-
const instance = MFDataPrefetch.getInstance(name) || new MFDataPrefetch(prefetchOptions);
|
|
291
|
-
let prefetchUrl;
|
|
292
|
-
if (snapshot.prefetchEntry) {
|
|
293
|
-
prefetchUrl = (0, import_sdk4.getResourceUrl)(snapshot, snapshot.prefetchEntry);
|
|
294
|
-
}
|
|
295
|
-
if (!preloadConfig.prefetchInterface) {
|
|
296
|
-
instance.loadEntry(prefetchUrl);
|
|
297
|
-
return options;
|
|
298
|
-
}
|
|
299
|
-
const promise = instance.loadEntry(prefetchUrl).then(async () => {
|
|
300
|
-
let module2 = origin.moduleCache.get(remote.name);
|
|
301
|
-
const moduleOptions = {
|
|
302
|
-
host: origin,
|
|
303
|
-
remoteInfo: remote
|
|
304
|
-
};
|
|
305
|
-
if (!module2) {
|
|
306
|
-
module2 = new import_runtime2.Module(moduleOptions);
|
|
307
|
-
origin.moduleCache.set(remote.name, module2);
|
|
308
|
-
}
|
|
309
|
-
const idPart = id.split("/");
|
|
310
|
-
let expose = idPart[idPart.length - 1];
|
|
311
|
-
if (expose !== ".") {
|
|
312
|
-
expose = `./${expose}`;
|
|
313
|
-
}
|
|
314
|
-
await module2.get(id, expose, {}, remoteSnapshot);
|
|
315
|
-
const projectExports = instance.getProjectExports();
|
|
316
|
-
if (projectExports instanceof Promise) {
|
|
317
|
-
await projectExports;
|
|
318
|
-
}
|
|
319
|
-
const exports = instance.getExposeExports(id);
|
|
320
|
-
logger_default.info(
|
|
321
|
-
`1. PreloadRemote Start Prefetch: ${id} - ${performance.now()}`
|
|
322
|
-
);
|
|
323
|
-
const result = Object.keys(exports).map((k) => {
|
|
324
|
-
const value = instance.prefetch({
|
|
325
|
-
id,
|
|
326
|
-
functionId: k
|
|
327
|
-
});
|
|
328
|
-
const functionId = k;
|
|
329
|
-
return {
|
|
330
|
-
value,
|
|
331
|
-
functionId
|
|
332
|
-
};
|
|
333
|
-
});
|
|
334
|
-
return result;
|
|
335
|
-
});
|
|
336
|
-
loadingArray.push({
|
|
337
|
-
id,
|
|
338
|
-
promise
|
|
339
|
-
});
|
|
340
|
-
return options;
|
|
341
|
-
},
|
|
342
271
|
beforeLoadShare(options) {
|
|
343
272
|
const shareInfo = options.shareInfo;
|
|
344
273
|
sharedFlag = (shareInfo == null ? void 0 : shareInfo.strategy) || sharedFlag;
|
package/dist/react/index.js
CHANGED
|
@@ -46,6 +46,7 @@ var getScope = (id) => {
|
|
|
46
46
|
return name;
|
|
47
47
|
};
|
|
48
48
|
var getPrefetchId = (id) => (0, import_sdk2.encodeName)(`${id}/${import_sdk2.MFPrefetchCommon.identifier}`);
|
|
49
|
+
var compatGetPrefetchId = (id) => (0, import_sdk2.encodeName)(`${id}/VmokPrefetch`);
|
|
49
50
|
|
|
50
51
|
// src/prefetch.ts
|
|
51
52
|
globalThis.__FEDERATION__ ?? (globalThis.__FEDERATION__ = {});
|
|
@@ -82,17 +83,9 @@ var MFDataPrefetch = class {
|
|
|
82
83
|
const remoteInfo = (0, import_runtime.getRemoteInfo)(remote);
|
|
83
84
|
const module2 = origin.moduleCache.get(remoteInfo.name);
|
|
84
85
|
return (0, import_runtime.getRemoteEntry)({
|
|
86
|
+
origin,
|
|
85
87
|
remoteInfo,
|
|
86
|
-
remoteEntryExports: module2 ? module2.remoteEntryExports : void 0
|
|
87
|
-
createScriptHook: (url) => {
|
|
88
|
-
const res = origin.loaderHook.lifecycle.createScript.emit({
|
|
89
|
-
url
|
|
90
|
-
});
|
|
91
|
-
if (res instanceof HTMLScriptElement) {
|
|
92
|
-
return res;
|
|
93
|
-
}
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
88
|
+
remoteEntryExports: module2 ? module2.remoteEntryExports : void 0
|
|
96
89
|
});
|
|
97
90
|
}
|
|
98
91
|
}
|
|
@@ -129,19 +122,21 @@ var MFDataPrefetch = class {
|
|
|
129
122
|
}
|
|
130
123
|
getExposeExports(id) {
|
|
131
124
|
const prefetchId = getPrefetchId(id);
|
|
132
|
-
const
|
|
125
|
+
const compatId = compatGetPrefetchId(id);
|
|
126
|
+
const prefetchExports = this._exports[prefetchId] || this._exports[compatId];
|
|
133
127
|
return prefetchExports || {};
|
|
134
128
|
}
|
|
135
129
|
prefetch(prefetchOptions) {
|
|
136
130
|
const { id, functionId = "default", refetchParams } = prefetchOptions;
|
|
137
131
|
let prefetchResult;
|
|
138
132
|
const prefetchId = getPrefetchId(id);
|
|
133
|
+
const compatId = compatGetPrefetchId(id);
|
|
139
134
|
const memorizeId = id + functionId;
|
|
140
135
|
const memory = this.prefetchMemory.get(memorizeId);
|
|
141
136
|
if (!this.checkOutdate(prefetchOptions) && memory) {
|
|
142
137
|
return memory;
|
|
143
138
|
}
|
|
144
|
-
const prefetchExports = this._exports[prefetchId];
|
|
139
|
+
const prefetchExports = this._exports[prefetchId] || this._exports[compatId];
|
|
145
140
|
if (!prefetchExports) {
|
|
146
141
|
return;
|
|
147
142
|
}
|
package/dist/universal/index.js
CHANGED
|
@@ -39,6 +39,7 @@ var getScope = (id) => {
|
|
|
39
39
|
return name;
|
|
40
40
|
};
|
|
41
41
|
var getPrefetchId = (id) => (0, import_sdk.encodeName)(`${id}/${import_sdk.MFPrefetchCommon.identifier}`);
|
|
42
|
+
var compatGetPrefetchId = (id) => (0, import_sdk.encodeName)(`${id}/VmokPrefetch`);
|
|
42
43
|
|
|
43
44
|
// src/prefetch.ts
|
|
44
45
|
globalThis.__FEDERATION__ ?? (globalThis.__FEDERATION__ = {});
|
|
@@ -75,17 +76,9 @@ var MFDataPrefetch = class {
|
|
|
75
76
|
const remoteInfo = (0, import_runtime.getRemoteInfo)(remote);
|
|
76
77
|
const module2 = origin.moduleCache.get(remoteInfo.name);
|
|
77
78
|
return (0, import_runtime.getRemoteEntry)({
|
|
79
|
+
origin,
|
|
78
80
|
remoteInfo,
|
|
79
|
-
remoteEntryExports: module2 ? module2.remoteEntryExports : void 0
|
|
80
|
-
createScriptHook: (url) => {
|
|
81
|
-
const res = origin.loaderHook.lifecycle.createScript.emit({
|
|
82
|
-
url
|
|
83
|
-
});
|
|
84
|
-
if (res instanceof HTMLScriptElement) {
|
|
85
|
-
return res;
|
|
86
|
-
}
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
81
|
+
remoteEntryExports: module2 ? module2.remoteEntryExports : void 0
|
|
89
82
|
});
|
|
90
83
|
}
|
|
91
84
|
}
|
|
@@ -122,19 +115,21 @@ var MFDataPrefetch = class {
|
|
|
122
115
|
}
|
|
123
116
|
getExposeExports(id) {
|
|
124
117
|
const prefetchId = getPrefetchId(id);
|
|
125
|
-
const
|
|
118
|
+
const compatId = compatGetPrefetchId(id);
|
|
119
|
+
const prefetchExports = this._exports[prefetchId] || this._exports[compatId];
|
|
126
120
|
return prefetchExports || {};
|
|
127
121
|
}
|
|
128
122
|
prefetch(prefetchOptions) {
|
|
129
123
|
const { id, functionId = "default", refetchParams } = prefetchOptions;
|
|
130
124
|
let prefetchResult;
|
|
131
125
|
const prefetchId = getPrefetchId(id);
|
|
126
|
+
const compatId = compatGetPrefetchId(id);
|
|
132
127
|
const memorizeId = id + functionId;
|
|
133
128
|
const memory = this.prefetchMemory.get(memorizeId);
|
|
134
129
|
if (!this.checkOutdate(prefetchOptions) && memory) {
|
|
135
130
|
return memory;
|
|
136
131
|
}
|
|
137
|
-
const prefetchExports = this._exports[prefetchId];
|
|
132
|
+
const prefetchExports = this._exports[prefetchId] || this._exports[compatId];
|
|
138
133
|
if (!prefetchExports) {
|
|
139
134
|
return;
|
|
140
135
|
}
|
package/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.0.0-next-
|
|
4
|
+
"version": "0.0.0-next-20240909062831",
|
|
5
5
|
"author": "nieyan <nyqykk@foxmail.com>",
|
|
6
6
|
"homepage": "https://github.com/module-federation/core",
|
|
7
7
|
"license": "MIT",
|
|
@@ -85,8 +85,8 @@
|
|
|
85
85
|
},
|
|
86
86
|
"dependencies": {
|
|
87
87
|
"fs-extra": "9.1.0",
|
|
88
|
-
"@module-federation/sdk": "0.0.0-next-
|
|
89
|
-
"@module-federation/runtime": "0.0.0-next-
|
|
88
|
+
"@module-federation/sdk": "0.0.0-next-20240909062831",
|
|
89
|
+
"@module-federation/runtime": "0.0.0-next-20240909062831"
|
|
90
90
|
},
|
|
91
91
|
"scripts": {
|
|
92
92
|
"dev": "cross-env WATCH=true tsup",
|
|
@@ -16,6 +16,9 @@ export const getScope = (id: string): string => {
|
|
|
16
16
|
export const getPrefetchId = (id: string): string =>
|
|
17
17
|
encodeName(`${id}/${MFPrefetchCommon.identifier}`);
|
|
18
18
|
|
|
19
|
+
export const compatGetPrefetchId = (id: string): string =>
|
|
20
|
+
encodeName(`${id}/VmokPrefetch`);
|
|
21
|
+
|
|
19
22
|
export const getSignalFromManifest = (remoteSnapshot: ModuleInfo): boolean => {
|
|
20
23
|
if (!remoteSnapshot) {
|
|
21
24
|
return false;
|
package/src/plugin.ts
CHANGED
|
@@ -1,26 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
3
|
-
FederationRuntimePlugin,
|
|
4
|
-
RemoteInfo,
|
|
5
|
-
} from '@module-federation/runtime/types';
|
|
1
|
+
import type { FederationRuntimePlugin } from '@module-federation/runtime/types';
|
|
6
2
|
import { ModuleInfo, getResourceUrl } from '@module-federation/sdk';
|
|
7
3
|
|
|
8
4
|
import { getSignalFromManifest } from './common/runtime-utils';
|
|
9
5
|
import { MFDataPrefetch } from './prefetch';
|
|
10
6
|
import logger from './logger';
|
|
11
7
|
|
|
12
|
-
type depsPreloadArg = Omit<PreloadRemoteArgs, 'depsRemote'>;
|
|
13
|
-
|
|
14
|
-
interface PreloadRemoteArgs {
|
|
15
|
-
nameOrAlias: string;
|
|
16
|
-
exposes?: Array<string>;
|
|
17
|
-
resourceCategory?: 'all' | 'sync';
|
|
18
|
-
share?: boolean;
|
|
19
|
-
depsRemote?: boolean | Array<depsPreloadArg>;
|
|
20
|
-
filter?: (assetUrl: string) => boolean;
|
|
21
|
-
prefetchInterface?: boolean;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
8
|
interface Loading {
|
|
25
9
|
id: string;
|
|
26
10
|
promise: Promise<
|
|
@@ -122,84 +106,6 @@ export const prefetchPlugin = (): FederationRuntimePlugin => ({
|
|
|
122
106
|
return options;
|
|
123
107
|
},
|
|
124
108
|
|
|
125
|
-
handlePreloadModule(options) {
|
|
126
|
-
const { remoteSnapshot, name, id, preloadConfig, origin, remote } = options;
|
|
127
|
-
const snapshot = remoteSnapshot as ModuleInfo;
|
|
128
|
-
|
|
129
|
-
const signal = getSignalFromManifest(snapshot);
|
|
130
|
-
if (!signal) {
|
|
131
|
-
return options;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
const prefetchOptions = {
|
|
135
|
-
name,
|
|
136
|
-
origin,
|
|
137
|
-
remote,
|
|
138
|
-
remoteSnapshot: snapshot,
|
|
139
|
-
};
|
|
140
|
-
const instance =
|
|
141
|
-
MFDataPrefetch.getInstance(name) || new MFDataPrefetch(prefetchOptions);
|
|
142
|
-
|
|
143
|
-
let prefetchUrl;
|
|
144
|
-
// @ts-expect-error
|
|
145
|
-
if (snapshot.prefetchEntry) {
|
|
146
|
-
// @ts-expect-error
|
|
147
|
-
prefetchUrl = getResourceUrl(snapshot, snapshot.prefetchEntry);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
if (!preloadConfig.prefetchInterface) {
|
|
151
|
-
// @ts-ignore
|
|
152
|
-
instance.loadEntry(prefetchUrl);
|
|
153
|
-
return options;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
const promise = instance.loadEntry(prefetchUrl).then(async () => {
|
|
157
|
-
let module = origin.moduleCache.get(remote.name);
|
|
158
|
-
const moduleOptions = {
|
|
159
|
-
host: origin,
|
|
160
|
-
remoteInfo: remote as RemoteInfo,
|
|
161
|
-
};
|
|
162
|
-
if (!module) {
|
|
163
|
-
module = new Module(moduleOptions);
|
|
164
|
-
origin.moduleCache.set(remote.name, module);
|
|
165
|
-
}
|
|
166
|
-
const idPart = id.split('/');
|
|
167
|
-
let expose = idPart[idPart.length - 1];
|
|
168
|
-
if (expose !== '.') {
|
|
169
|
-
expose = `./${expose}`;
|
|
170
|
-
}
|
|
171
|
-
await module.get(id, expose, {}, remoteSnapshot);
|
|
172
|
-
|
|
173
|
-
const projectExports = instance!.getProjectExports();
|
|
174
|
-
if (projectExports instanceof Promise) {
|
|
175
|
-
await projectExports;
|
|
176
|
-
}
|
|
177
|
-
const exports = instance!.getExposeExports(id);
|
|
178
|
-
logger.info(
|
|
179
|
-
`1. PreloadRemote Start Prefetch: ${id} - ${performance.now()}`,
|
|
180
|
-
);
|
|
181
|
-
const result = Object.keys(exports).map((k) => {
|
|
182
|
-
const value = instance!.prefetch({
|
|
183
|
-
id,
|
|
184
|
-
functionId: k,
|
|
185
|
-
});
|
|
186
|
-
const functionId = k;
|
|
187
|
-
|
|
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
|
-
|
|
203
109
|
beforeLoadShare(options) {
|
|
204
110
|
const shareInfo = options.shareInfo;
|
|
205
111
|
sharedFlag = shareInfo?.strategy || sharedFlag;
|
package/src/prefetch.ts
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
} from '@module-federation/sdk';
|
|
11
11
|
import { Remote } from '@module-federation/runtime/types';
|
|
12
12
|
|
|
13
|
-
import { getPrefetchId } from './common/runtime-utils';
|
|
13
|
+
import { getPrefetchId, compatGetPrefetchId } from './common/runtime-utils';
|
|
14
14
|
|
|
15
15
|
declare module '@module-federation/runtime' {
|
|
16
16
|
export interface Federation {
|
|
@@ -82,17 +82,9 @@ export class MFDataPrefetch {
|
|
|
82
82
|
const remoteInfo = getRemoteInfo(remote as Remote);
|
|
83
83
|
const module = origin!.moduleCache.get(remoteInfo.name);
|
|
84
84
|
return getRemoteEntry({
|
|
85
|
+
origin: origin!,
|
|
85
86
|
remoteInfo,
|
|
86
87
|
remoteEntryExports: module ? module.remoteEntryExports : undefined,
|
|
87
|
-
createScriptHook: (url: string) => {
|
|
88
|
-
const res = origin!.loaderHook.lifecycle.createScript.emit({
|
|
89
|
-
url,
|
|
90
|
-
});
|
|
91
|
-
if (res instanceof HTMLScriptElement) {
|
|
92
|
-
return res;
|
|
93
|
-
}
|
|
94
|
-
return;
|
|
95
|
-
},
|
|
96
88
|
});
|
|
97
89
|
}
|
|
98
90
|
}
|
|
@@ -137,7 +129,9 @@ export class MFDataPrefetch {
|
|
|
137
129
|
|
|
138
130
|
getExposeExports(id: string): PrefetchExports {
|
|
139
131
|
const prefetchId = getPrefetchId(id);
|
|
140
|
-
const
|
|
132
|
+
const compatId = compatGetPrefetchId(id);
|
|
133
|
+
const prefetchExports =
|
|
134
|
+
this._exports[prefetchId] || (this._exports[compatId] as PrefetchExports);
|
|
141
135
|
return prefetchExports || {};
|
|
142
136
|
}
|
|
143
137
|
|
|
@@ -145,13 +139,15 @@ export class MFDataPrefetch {
|
|
|
145
139
|
const { id, functionId = 'default', refetchParams } = prefetchOptions;
|
|
146
140
|
let prefetchResult;
|
|
147
141
|
const prefetchId = getPrefetchId(id);
|
|
142
|
+
const compatId = compatGetPrefetchId(id);
|
|
148
143
|
const memorizeId = id + functionId;
|
|
149
144
|
const memory = this.prefetchMemory.get(memorizeId);
|
|
150
145
|
if (!this.checkOutdate(prefetchOptions) && memory) {
|
|
151
146
|
return memory;
|
|
152
147
|
}
|
|
153
148
|
|
|
154
|
-
const prefetchExports =
|
|
149
|
+
const prefetchExports =
|
|
150
|
+
this._exports[prefetchId] || (this._exports[compatId] as PrefetchExports);
|
|
155
151
|
if (!prefetchExports) {
|
|
156
152
|
return;
|
|
157
153
|
}
|