@module-federation/data-prefetch 0.0.0-next-20240702090143 → 0.0.0-next-20240808083234
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 -5
- package/__tests__/prefetch.spec.ts +19 -8
- package/__tests__/react.spec.ts +5 -4
- package/dist/cli/babel.d.ts +1 -1
- package/dist/cli/babel.js +1 -1
- package/dist/cli/index.js +8 -5
- package/dist/esm/{chunk-WLE6YNDH.js → chunk-TW3B6M25.js} +2 -68
- package/dist/esm/{chunk-QHQN3BPZ.js → chunk-V2LJYA45.js} +2 -2
- package/dist/esm/{chunk-EWCGK4XA.js → chunk-VWDP6NMM.js} +2 -0
- package/dist/esm/{chunk-JEPJP5O3.js → chunk-XYNYYK45.js} +6 -3
- package/dist/esm/cli/babel.js +1 -1
- package/dist/esm/cli/index.js +9 -6
- 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 +5 -68
- package/dist/plugin.js +5 -68
- package/dist/react/index.js +5 -2
- package/dist/universal/index.js +5 -2
- package/jest.config.js +1 -1
- package/package.json +3 -3
- package/src/cli/babel.ts +2 -2
- package/src/cli/index.ts +8 -6
- package/src/common/runtime-utils.ts +3 -0
- package/src/plugin.ts +1 -95
- package/src/prefetch.ts +9 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
@module-federation/data-prefetch
|
|
2
2
|
|
|
3
|
-
## 0.0.0-next-
|
|
3
|
+
## 0.0.0-next-20240808083234
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
7
|
- 3ddab21: feat(@module-federation/data-prefetch): support data prefetch in Module Federation
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
- @module-federation/sdk@0.0.0-next-20240702090143
|
|
11
|
-
- @module-federation/runtime@0.0.0-next-20240702090143
|
|
8
|
+
- @module-federation/runtime@0.0.0-next-20240808083234
|
|
9
|
+
- @module-federation/sdk@0.0.0-next-20240808083234
|
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
// Import the necessary modules and functions
|
|
2
2
|
import { MFDataPrefetch } from '../src/prefetch';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
loadScript,
|
|
5
|
+
MFPrefetchCommon,
|
|
6
|
+
encodeName,
|
|
7
|
+
} from '@module-federation/sdk';
|
|
4
8
|
|
|
5
9
|
// Mock loadScript function from SDK
|
|
6
|
-
jest.mock('@module-federation/sdk', () =>
|
|
7
|
-
|
|
8
|
-
|
|
10
|
+
jest.mock('@module-federation/sdk', () => {
|
|
11
|
+
const originalModule = jest.requireActual('@module-federation/sdk');
|
|
12
|
+
return {
|
|
13
|
+
...originalModule,
|
|
14
|
+
loadScript: jest.fn(() => Promise.resolve()),
|
|
15
|
+
};
|
|
16
|
+
});
|
|
9
17
|
|
|
10
18
|
describe('MF Data Prefetch', () => {
|
|
11
19
|
let prefetch: MFDataPrefetch;
|
|
@@ -17,6 +25,7 @@ describe('MF Data Prefetch', () => {
|
|
|
17
25
|
globalName: 'TestGlobalName',
|
|
18
26
|
},
|
|
19
27
|
};
|
|
28
|
+
const exposeId = `${options.name}/button/${MFPrefetchCommon.identifier}`;
|
|
20
29
|
|
|
21
30
|
beforeEach(() => {
|
|
22
31
|
globalThis.__FEDERATION__.__PREFETCH__ = {
|
|
@@ -53,20 +62,22 @@ describe('MF Data Prefetch', () => {
|
|
|
53
62
|
nyPrefetch: () => {},
|
|
54
63
|
};
|
|
55
64
|
const projectExport = {
|
|
56
|
-
[
|
|
65
|
+
[encodeName(exposeId)]: exposeExport,
|
|
57
66
|
};
|
|
58
67
|
globalThis.__FEDERATION__.__PREFETCH__.__PREFETCH_EXPORTS__[options.name] =
|
|
59
68
|
Promise.resolve(projectExport);
|
|
60
69
|
|
|
61
70
|
await prefetch.getProjectExports();
|
|
62
|
-
expect(prefetch.getExposeExports(options.name)).toEqual(
|
|
71
|
+
expect(prefetch.getExposeExports(`${options.name}/button`)).toEqual(
|
|
72
|
+
exposeExport,
|
|
73
|
+
);
|
|
63
74
|
});
|
|
64
75
|
// Prefetching with memory and executing prefetch function
|
|
65
76
|
it('executes prefetch using prefetch function with and without memory', async () => {
|
|
66
77
|
const id = options.name;
|
|
67
78
|
const functionId = 'nyPrefetch';
|
|
68
79
|
const refetchParams = 'testParams';
|
|
69
|
-
const prefetchOptions = { id
|
|
80
|
+
const prefetchOptions = { id: `${id}/button`, functionId, refetchParams };
|
|
70
81
|
|
|
71
82
|
// Creating a mock prefetch function
|
|
72
83
|
const executePrefetch = jest.fn(() => 'Expected Result');
|
|
@@ -75,7 +86,7 @@ describe('MF Data Prefetch', () => {
|
|
|
75
86
|
// Mock Project Exports
|
|
76
87
|
globalThis.__FEDERATION__.__PREFETCH__.__PREFETCH_EXPORTS__[id] =
|
|
77
88
|
Promise.resolve({
|
|
78
|
-
[
|
|
89
|
+
[encodeName(exposeId)]: prefetchExports,
|
|
79
90
|
});
|
|
80
91
|
|
|
81
92
|
await prefetch.getProjectExports();
|
package/__tests__/react.spec.ts
CHANGED
|
@@ -57,8 +57,9 @@ describe('usePrefetch', () => {
|
|
|
57
57
|
const exposeExport = {
|
|
58
58
|
[functionId]: executePrefetch,
|
|
59
59
|
};
|
|
60
|
+
const exposeId = `${options.name}/button/${ModuleFederationSDK.MFPrefetchCommon.identifier}`;
|
|
60
61
|
const projectExport = {
|
|
61
|
-
[
|
|
62
|
+
[ModuleFederationSDK.encodeName(exposeId)]: exposeExport,
|
|
62
63
|
};
|
|
63
64
|
globalThis.__FEDERATION__.__PREFETCH__.__PREFETCH_EXPORTS__[options.name] =
|
|
64
65
|
Promise.resolve(projectExport);
|
|
@@ -76,7 +77,7 @@ describe('usePrefetch', () => {
|
|
|
76
77
|
|
|
77
78
|
it('should prefetch data on first mount', async () => {
|
|
78
79
|
const { result } = renderHook(() =>
|
|
79
|
-
usePrefetch({ id: options.name
|
|
80
|
+
usePrefetch({ id: `${options.name}/button`, functionId }),
|
|
80
81
|
);
|
|
81
82
|
await result.current[0];
|
|
82
83
|
expect(executePrefetch).toHaveBeenCalled();
|
|
@@ -86,14 +87,14 @@ describe('usePrefetch', () => {
|
|
|
86
87
|
|
|
87
88
|
it('should refetch data when refreshExecutor is called', async () => {
|
|
88
89
|
const { result } = renderHook(() =>
|
|
89
|
-
usePrefetch({ id: options.name
|
|
90
|
+
usePrefetch({ id: `${options.name}/button`, functionId }),
|
|
90
91
|
);
|
|
91
92
|
|
|
92
93
|
await result.current[0];
|
|
93
94
|
expect(executePrefetch).toHaveBeenCalled();
|
|
94
95
|
executePrefetch.mockClear();
|
|
95
96
|
const { result: newCallResult } = renderHook(() =>
|
|
96
|
-
usePrefetch({ id: options.name
|
|
97
|
+
usePrefetch({ id: `${options.name}/button`, functionId }),
|
|
97
98
|
);
|
|
98
99
|
await newCallResult.current[0];
|
|
99
100
|
expect(executePrefetch).not.toHaveBeenCalled();
|
package/dist/cli/babel.d.ts
CHANGED
package/dist/cli/babel.js
CHANGED
package/dist/cli/index.js
CHANGED
|
@@ -88,6 +88,14 @@ var PrefetchPlugin = class {
|
|
|
88
88
|
this.options.runtimePlugins.push(
|
|
89
89
|
import_path2.default.resolve(__dirname, "../esm/shared/index.js")
|
|
90
90
|
);
|
|
91
|
+
const encodedName = (0, import_sdk2.encodeName)(name);
|
|
92
|
+
const asyncEntryPath = import_path2.default.resolve(
|
|
93
|
+
compiler.options.context,
|
|
94
|
+
`node_modules/${TEMP_DIR}/${encodedName}/bootstrap.js`
|
|
95
|
+
);
|
|
96
|
+
if (import_fs_extra2.default.existsSync(asyncEntryPath)) {
|
|
97
|
+
import_fs_extra2.default.unlinkSync(asyncEntryPath);
|
|
98
|
+
}
|
|
91
99
|
if (!this.options.dataPrefetch) {
|
|
92
100
|
return;
|
|
93
101
|
}
|
|
@@ -118,11 +126,6 @@ var PrefetchPlugin = class {
|
|
|
118
126
|
if (!this._reWriteExports) {
|
|
119
127
|
return;
|
|
120
128
|
}
|
|
121
|
-
const encodedName = (0, import_sdk2.encodeName)(name);
|
|
122
|
-
const asyncEntryPath = import_path2.default.resolve(
|
|
123
|
-
compiler.options.context,
|
|
124
|
-
`node_modules/${TEMP_DIR}/${encodedName}/bootstrap.js`
|
|
125
|
-
);
|
|
126
129
|
const tempDirRealPath = import_path2.default.resolve(
|
|
127
130
|
compiler.options.context,
|
|
128
131
|
"node_modules",
|
|
@@ -3,13 +3,12 @@ import {
|
|
|
3
3
|
} from "./chunk-TTJJJ2WZ.js";
|
|
4
4
|
import {
|
|
5
5
|
MFDataPrefetch
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-XYNYYK45.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
|
};
|
|
@@ -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 {
|
|
@@ -91,19 +92,21 @@ var MFDataPrefetch = class {
|
|
|
91
92
|
}
|
|
92
93
|
getExposeExports(id) {
|
|
93
94
|
const prefetchId = getPrefetchId(id);
|
|
94
|
-
const
|
|
95
|
+
const compatId = compatGetPrefetchId(id);
|
|
96
|
+
const prefetchExports = this._exports[prefetchId] || this._exports[compatId];
|
|
95
97
|
return prefetchExports || {};
|
|
96
98
|
}
|
|
97
99
|
prefetch(prefetchOptions) {
|
|
98
100
|
const { id, functionId = "default", refetchParams } = prefetchOptions;
|
|
99
101
|
let prefetchResult;
|
|
100
102
|
const prefetchId = getPrefetchId(id);
|
|
103
|
+
const compatId = compatGetPrefetchId(id);
|
|
101
104
|
const memorizeId = id + functionId;
|
|
102
105
|
const memory = this.prefetchMemory.get(memorizeId);
|
|
103
106
|
if (!this.checkOutdate(prefetchOptions) && memory) {
|
|
104
107
|
return memory;
|
|
105
108
|
}
|
|
106
|
-
const prefetchExports = this._exports[prefetchId];
|
|
109
|
+
const prefetchExports = this._exports[prefetchId] || this._exports[compatId];
|
|
107
110
|
if (!prefetchExports) {
|
|
108
111
|
return;
|
|
109
112
|
}
|
package/dist/esm/cli/babel.js
CHANGED
package/dist/esm/cli/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getPrefetchId
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-VWDP6NMM.js";
|
|
4
4
|
|
|
5
5
|
// src/cli/index.ts
|
|
6
6
|
import path2 from "path";
|
|
@@ -60,6 +60,14 @@ var PrefetchPlugin = class {
|
|
|
60
60
|
this.options.runtimePlugins.push(
|
|
61
61
|
path2.resolve(__dirname, "../esm/shared/index.js")
|
|
62
62
|
);
|
|
63
|
+
const encodedName = encodeName(name);
|
|
64
|
+
const asyncEntryPath = path2.resolve(
|
|
65
|
+
compiler.options.context,
|
|
66
|
+
`node_modules/${TEMP_DIR}/${encodedName}/bootstrap.js`
|
|
67
|
+
);
|
|
68
|
+
if (fs2.existsSync(asyncEntryPath)) {
|
|
69
|
+
fs2.unlinkSync(asyncEntryPath);
|
|
70
|
+
}
|
|
63
71
|
if (!this.options.dataPrefetch) {
|
|
64
72
|
return;
|
|
65
73
|
}
|
|
@@ -90,11 +98,6 @@ var PrefetchPlugin = class {
|
|
|
90
98
|
if (!this._reWriteExports) {
|
|
91
99
|
return;
|
|
92
100
|
}
|
|
93
|
-
const encodedName = encodeName(name);
|
|
94
|
-
const asyncEntryPath = path2.resolve(
|
|
95
|
-
compiler.options.context,
|
|
96
|
-
`node_modules/${TEMP_DIR}/${encodedName}/bootstrap.js`
|
|
97
|
-
);
|
|
98
101
|
const tempDirRealPath = path2.resolve(
|
|
99
102
|
compiler.options.context,
|
|
100
103
|
"node_modules",
|
package/dist/esm/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
prefetchPlugin
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-TW3B6M25.js";
|
|
4
4
|
import "./chunk-TTJJJ2WZ.js";
|
|
5
5
|
import {
|
|
6
6
|
MFDataPrefetch
|
|
7
|
-
} from "./chunk-
|
|
8
|
-
import "./chunk-
|
|
7
|
+
} from "./chunk-XYNYYK45.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-TW3B6M25.js";
|
|
5
5
|
import "./chunk-TTJJJ2WZ.js";
|
|
6
|
-
import "./chunk-
|
|
7
|
-
import "./chunk-
|
|
6
|
+
import "./chunk-XYNYYK45.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-V2LJYA45.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-XYNYYK45.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;
|
|
@@ -127,19 +128,21 @@ var MFDataPrefetch = class {
|
|
|
127
128
|
}
|
|
128
129
|
getExposeExports(id) {
|
|
129
130
|
const prefetchId = getPrefetchId(id);
|
|
130
|
-
const
|
|
131
|
+
const compatId = compatGetPrefetchId(id);
|
|
132
|
+
const prefetchExports = this._exports[prefetchId] || this._exports[compatId];
|
|
131
133
|
return prefetchExports || {};
|
|
132
134
|
}
|
|
133
135
|
prefetch(prefetchOptions) {
|
|
134
136
|
const { id, functionId = "default", refetchParams } = prefetchOptions;
|
|
135
137
|
let prefetchResult;
|
|
136
138
|
const prefetchId = getPrefetchId(id);
|
|
139
|
+
const compatId = compatGetPrefetchId(id);
|
|
137
140
|
const memorizeId = id + functionId;
|
|
138
141
|
const memory = this.prefetchMemory.get(memorizeId);
|
|
139
142
|
if (!this.checkOutdate(prefetchOptions) && memory) {
|
|
140
143
|
return memory;
|
|
141
144
|
}
|
|
142
|
-
const prefetchExports = this._exports[prefetchId];
|
|
145
|
+
const prefetchExports = this._exports[prefetchId] || this._exports[compatId];
|
|
143
146
|
if (!prefetchExports) {
|
|
144
147
|
return;
|
|
145
148
|
}
|
|
@@ -192,7 +195,6 @@ var MFDataPrefetch = class {
|
|
|
192
195
|
};
|
|
193
196
|
|
|
194
197
|
// src/plugin.ts
|
|
195
|
-
var import_runtime2 = require("@module-federation/runtime");
|
|
196
198
|
var import_sdk4 = require("@module-federation/sdk");
|
|
197
199
|
|
|
198
200
|
// src/logger/index.ts
|
|
@@ -278,71 +280,6 @@ var prefetchPlugin = () => ({
|
|
|
278
280
|
}
|
|
279
281
|
return options;
|
|
280
282
|
},
|
|
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
283
|
beforeLoadShare(options) {
|
|
347
284
|
const shareInfo = options.shareInfo;
|
|
348
285
|
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;
|
|
@@ -127,19 +127,21 @@ var MFDataPrefetch = class {
|
|
|
127
127
|
}
|
|
128
128
|
getExposeExports(id) {
|
|
129
129
|
const prefetchId = getPrefetchId(id);
|
|
130
|
-
const
|
|
130
|
+
const compatId = compatGetPrefetchId(id);
|
|
131
|
+
const prefetchExports = this._exports[prefetchId] || this._exports[compatId];
|
|
131
132
|
return prefetchExports || {};
|
|
132
133
|
}
|
|
133
134
|
prefetch(prefetchOptions) {
|
|
134
135
|
const { id, functionId = "default", refetchParams } = prefetchOptions;
|
|
135
136
|
let prefetchResult;
|
|
136
137
|
const prefetchId = getPrefetchId(id);
|
|
138
|
+
const compatId = compatGetPrefetchId(id);
|
|
137
139
|
const memorizeId = id + functionId;
|
|
138
140
|
const memory = this.prefetchMemory.get(memorizeId);
|
|
139
141
|
if (!this.checkOutdate(prefetchOptions) && memory) {
|
|
140
142
|
return memory;
|
|
141
143
|
}
|
|
142
|
-
const prefetchExports = this._exports[prefetchId];
|
|
144
|
+
const prefetchExports = this._exports[prefetchId] || this._exports[compatId];
|
|
143
145
|
if (!prefetchExports) {
|
|
144
146
|
return;
|
|
145
147
|
}
|
|
@@ -274,71 +276,6 @@ var prefetchPlugin = () => ({
|
|
|
274
276
|
}
|
|
275
277
|
return options;
|
|
276
278
|
},
|
|
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
279
|
beforeLoadShare(options) {
|
|
343
280
|
const shareInfo = options.shareInfo;
|
|
344
281
|
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__ = {});
|
|
@@ -129,19 +130,21 @@ var MFDataPrefetch = class {
|
|
|
129
130
|
}
|
|
130
131
|
getExposeExports(id) {
|
|
131
132
|
const prefetchId = getPrefetchId(id);
|
|
132
|
-
const
|
|
133
|
+
const compatId = compatGetPrefetchId(id);
|
|
134
|
+
const prefetchExports = this._exports[prefetchId] || this._exports[compatId];
|
|
133
135
|
return prefetchExports || {};
|
|
134
136
|
}
|
|
135
137
|
prefetch(prefetchOptions) {
|
|
136
138
|
const { id, functionId = "default", refetchParams } = prefetchOptions;
|
|
137
139
|
let prefetchResult;
|
|
138
140
|
const prefetchId = getPrefetchId(id);
|
|
141
|
+
const compatId = compatGetPrefetchId(id);
|
|
139
142
|
const memorizeId = id + functionId;
|
|
140
143
|
const memory = this.prefetchMemory.get(memorizeId);
|
|
141
144
|
if (!this.checkOutdate(prefetchOptions) && memory) {
|
|
142
145
|
return memory;
|
|
143
146
|
}
|
|
144
|
-
const prefetchExports = this._exports[prefetchId];
|
|
147
|
+
const prefetchExports = this._exports[prefetchId] || this._exports[compatId];
|
|
145
148
|
if (!prefetchExports) {
|
|
146
149
|
return;
|
|
147
150
|
}
|
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__ = {});
|
|
@@ -122,19 +123,21 @@ var MFDataPrefetch = class {
|
|
|
122
123
|
}
|
|
123
124
|
getExposeExports(id) {
|
|
124
125
|
const prefetchId = getPrefetchId(id);
|
|
125
|
-
const
|
|
126
|
+
const compatId = compatGetPrefetchId(id);
|
|
127
|
+
const prefetchExports = this._exports[prefetchId] || this._exports[compatId];
|
|
126
128
|
return prefetchExports || {};
|
|
127
129
|
}
|
|
128
130
|
prefetch(prefetchOptions) {
|
|
129
131
|
const { id, functionId = "default", refetchParams } = prefetchOptions;
|
|
130
132
|
let prefetchResult;
|
|
131
133
|
const prefetchId = getPrefetchId(id);
|
|
134
|
+
const compatId = compatGetPrefetchId(id);
|
|
132
135
|
const memorizeId = id + functionId;
|
|
133
136
|
const memory = this.prefetchMemory.get(memorizeId);
|
|
134
137
|
if (!this.checkOutdate(prefetchOptions) && memory) {
|
|
135
138
|
return memory;
|
|
136
139
|
}
|
|
137
|
-
const prefetchExports = this._exports[prefetchId];
|
|
140
|
+
const prefetchExports = this._exports[prefetchId] || this._exports[compatId];
|
|
138
141
|
if (!prefetchExports) {
|
|
139
142
|
return;
|
|
140
143
|
}
|
package/jest.config.js
CHANGED
|
@@ -21,7 +21,7 @@ module.exports = {
|
|
|
21
21
|
'/node_modules/(?!((@byted/garfish-)|(byted-tea-sdk))).+\\.js$',
|
|
22
22
|
],
|
|
23
23
|
transform: {
|
|
24
|
-
'^.+\\.(t|j)sx?$': ['@swc/jest'],
|
|
24
|
+
'^.+\\.(t|j)sx?$': ['@swc/jest', { swcrc: false }],
|
|
25
25
|
},
|
|
26
26
|
rootDir: __dirname,
|
|
27
27
|
testMatch: ['<rootDir>__tests__/**/**.spec.[jt]s?(x)'],
|
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-20240808083234",
|
|
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-20240808083234",
|
|
89
|
+
"@module-federation/runtime": "0.0.0-next-20240808083234"
|
|
90
90
|
},
|
|
91
91
|
"scripts": {
|
|
92
92
|
"dev": "cross-env WATCH=true tsup",
|
package/src/cli/babel.ts
CHANGED
|
@@ -9,7 +9,7 @@ interface BabelPluginOptions {
|
|
|
9
9
|
hook_id: string;
|
|
10
10
|
import_pkg: string;
|
|
11
11
|
attribute: string;
|
|
12
|
-
|
|
12
|
+
name: string;
|
|
13
13
|
exposes: moduleFederationPlugin.ModuleFederationPluginOptions['exposes'];
|
|
14
14
|
}
|
|
15
15
|
|
|
@@ -18,7 +18,7 @@ export default (babel: { types: any }, options: BabelPluginOptions) => {
|
|
|
18
18
|
const t = babel.types;
|
|
19
19
|
let shouldHandle = false;
|
|
20
20
|
let scope = '';
|
|
21
|
-
const {
|
|
21
|
+
const { name, exposes } = options;
|
|
22
22
|
if (!exposes) {
|
|
23
23
|
return {};
|
|
24
24
|
}
|
package/src/cli/index.ts
CHANGED
|
@@ -41,6 +41,14 @@ export class PrefetchPlugin implements WebpackPluginInstance {
|
|
|
41
41
|
this.options.runtimePlugins!.push(
|
|
42
42
|
path.resolve(__dirname, '../esm/shared/index.js'),
|
|
43
43
|
);
|
|
44
|
+
const encodedName = encodeName(name as string);
|
|
45
|
+
const asyncEntryPath = path.resolve(
|
|
46
|
+
compiler.options.context,
|
|
47
|
+
`node_modules/${TEMP_DIR}/${encodedName}/bootstrap.js`,
|
|
48
|
+
);
|
|
49
|
+
if (fs.existsSync(asyncEntryPath)) {
|
|
50
|
+
fs.unlinkSync(asyncEntryPath);
|
|
51
|
+
}
|
|
44
52
|
if (!this.options.dataPrefetch) {
|
|
45
53
|
return;
|
|
46
54
|
}
|
|
@@ -73,12 +81,6 @@ export class PrefetchPlugin implements WebpackPluginInstance {
|
|
|
73
81
|
if (!this._reWriteExports) {
|
|
74
82
|
return;
|
|
75
83
|
}
|
|
76
|
-
|
|
77
|
-
const encodedName = encodeName(name as string);
|
|
78
|
-
const asyncEntryPath = path.resolve(
|
|
79
|
-
compiler.options.context,
|
|
80
|
-
`node_modules/${TEMP_DIR}/${encodedName}/bootstrap.js`,
|
|
81
|
-
);
|
|
82
84
|
const tempDirRealPath = path.resolve(
|
|
83
85
|
compiler.options.context,
|
|
84
86
|
'node_modules',
|
|
@@ -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 {
|
|
@@ -106,7 +106,8 @@ export class MFDataPrefetch {
|
|
|
106
106
|
globalThis.__FEDERATION__.__PREFETCH__.__PREFETCH_EXPORTS__?.[name];
|
|
107
107
|
const resolve = exportsPromise.then(
|
|
108
108
|
(exports: Record<string, Record<string, any>> = {}) => {
|
|
109
|
-
//
|
|
109
|
+
// Match prefetch based on the function name suffix so that other capabilities can be expanded later.
|
|
110
|
+
// Not all functions should be directly identified as prefetch functions
|
|
110
111
|
const memory: Record<string, Record<string, any>> = {};
|
|
111
112
|
Object.keys(exports).forEach((key) => {
|
|
112
113
|
memory[key] = {};
|
|
@@ -136,7 +137,9 @@ export class MFDataPrefetch {
|
|
|
136
137
|
|
|
137
138
|
getExposeExports(id: string): PrefetchExports {
|
|
138
139
|
const prefetchId = getPrefetchId(id);
|
|
139
|
-
const
|
|
140
|
+
const compatId = compatGetPrefetchId(id);
|
|
141
|
+
const prefetchExports =
|
|
142
|
+
this._exports[prefetchId] || (this._exports[compatId] as PrefetchExports);
|
|
140
143
|
return prefetchExports || {};
|
|
141
144
|
}
|
|
142
145
|
|
|
@@ -144,13 +147,15 @@ export class MFDataPrefetch {
|
|
|
144
147
|
const { id, functionId = 'default', refetchParams } = prefetchOptions;
|
|
145
148
|
let prefetchResult;
|
|
146
149
|
const prefetchId = getPrefetchId(id);
|
|
150
|
+
const compatId = compatGetPrefetchId(id);
|
|
147
151
|
const memorizeId = id + functionId;
|
|
148
152
|
const memory = this.prefetchMemory.get(memorizeId);
|
|
149
153
|
if (!this.checkOutdate(prefetchOptions) && memory) {
|
|
150
154
|
return memory;
|
|
151
155
|
}
|
|
152
156
|
|
|
153
|
-
const prefetchExports =
|
|
157
|
+
const prefetchExports =
|
|
158
|
+
this._exports[prefetchId] || (this._exports[compatId] as PrefetchExports);
|
|
154
159
|
if (!prefetchExports) {
|
|
155
160
|
return;
|
|
156
161
|
}
|