@module-federation/data-prefetch 0.0.0-next-20240808065005 → 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 CHANGED
@@ -1,9 +1,9 @@
1
1
  @module-federation/data-prefetch
2
2
 
3
- ## 0.0.0-next-20240808065005
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
- - @module-federation/runtime@0.0.0-next-20240808065005
9
- - @module-federation/sdk@0.0.0-next-20240808065005
8
+ - @module-federation/runtime@0.0.0-next-20240808083234
9
+ - @module-federation/sdk@0.0.0-next-20240808083234
@@ -3,13 +3,12 @@ import {
3
3
  } from "./chunk-TTJJJ2WZ.js";
4
4
  import {
5
5
  MFDataPrefetch
6
- } from "./chunk-JEPJP5O3.js";
6
+ } from "./chunk-XYNYYK45.js";
7
7
  import {
8
8
  getSignalFromManifest
9
- } from "./chunk-EWCGK4XA.js";
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;
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  MFDataPrefetch
3
- } from "./chunk-JEPJP5O3.js";
3
+ } from "./chunk-XYNYYK45.js";
4
4
  import {
5
5
  getScope
6
- } from "./chunk-EWCGK4XA.js";
6
+ } from "./chunk-VWDP6NMM.js";
7
7
 
8
8
  // src/universal/index.ts
9
9
  function prefetch(options) {
@@ -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-EWCGK4XA.js";
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 prefetchExports = this._exports[prefetchId];
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
  }
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getPrefetchId
3
- } from "../chunk-EWCGK4XA.js";
3
+ } from "../chunk-VWDP6NMM.js";
4
4
 
5
5
  // src/cli/index.ts
6
6
  import path2 from "path";
package/dist/esm/index.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  prefetchPlugin
3
- } from "./chunk-WLE6YNDH.js";
3
+ } from "./chunk-TW3B6M25.js";
4
4
  import "./chunk-TTJJJ2WZ.js";
5
5
  import {
6
6
  MFDataPrefetch
7
- } from "./chunk-JEPJP5O3.js";
8
- import "./chunk-EWCGK4XA.js";
7
+ } from "./chunk-XYNYYK45.js";
8
+ import "./chunk-VWDP6NMM.js";
9
9
  export {
10
10
  MFDataPrefetch,
11
11
  prefetchPlugin
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  plugin_default,
3
3
  prefetchPlugin
4
- } from "./chunk-WLE6YNDH.js";
4
+ } from "./chunk-TW3B6M25.js";
5
5
  import "./chunk-TTJJJ2WZ.js";
6
- import "./chunk-JEPJP5O3.js";
7
- import "./chunk-EWCGK4XA.js";
6
+ import "./chunk-XYNYYK45.js";
7
+ import "./chunk-VWDP6NMM.js";
8
8
  export {
9
9
  plugin_default as default,
10
10
  prefetchPlugin
@@ -1,15 +1,15 @@
1
1
  import {
2
2
  prefetch
3
- } from "../chunk-QHQN3BPZ.js";
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-JEPJP5O3.js";
9
+ } from "../chunk-XYNYYK45.js";
10
10
  import {
11
11
  getScope
12
- } from "../chunk-EWCGK4XA.js";
12
+ } from "../chunk-VWDP6NMM.js";
13
13
 
14
14
  // src/react/hooks.ts
15
15
  import { useEffect as useEffect2, useState } from "react";
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  prefetch
3
- } from "../chunk-QHQN3BPZ.js";
4
- import "../chunk-JEPJP5O3.js";
5
- import "../chunk-EWCGK4XA.js";
3
+ } from "../chunk-V2LJYA45.js";
4
+ import "../chunk-XYNYYK45.js";
5
+ import "../chunk-VWDP6NMM.js";
6
6
  export {
7
7
  prefetch
8
8
  };
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 prefetchExports = this._exports[prefetchId];
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 prefetchExports = this._exports[prefetchId];
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;
@@ -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 prefetchExports = this._exports[prefetchId];
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
  }
@@ -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 prefetchExports = this._exports[prefetchId];
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/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-20240808065005",
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-20240808065005",
89
- "@module-federation/runtime": "0.0.0-next-20240808065005"
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",
@@ -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 { Module } from '@module-federation/runtime';
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 {
@@ -137,7 +137,9 @@ export class MFDataPrefetch {
137
137
 
138
138
  getExposeExports(id: string): PrefetchExports {
139
139
  const prefetchId = getPrefetchId(id);
140
- const prefetchExports = this._exports[prefetchId] as PrefetchExports;
140
+ const compatId = compatGetPrefetchId(id);
141
+ const prefetchExports =
142
+ this._exports[prefetchId] || (this._exports[compatId] as PrefetchExports);
141
143
  return prefetchExports || {};
142
144
  }
143
145
 
@@ -145,13 +147,15 @@ export class MFDataPrefetch {
145
147
  const { id, functionId = 'default', refetchParams } = prefetchOptions;
146
148
  let prefetchResult;
147
149
  const prefetchId = getPrefetchId(id);
150
+ const compatId = compatGetPrefetchId(id);
148
151
  const memorizeId = id + functionId;
149
152
  const memory = this.prefetchMemory.get(memorizeId);
150
153
  if (!this.checkOutdate(prefetchOptions) && memory) {
151
154
  return memory;
152
155
  }
153
156
 
154
- const prefetchExports = this._exports[prefetchId] as PrefetchExports;
157
+ const prefetchExports =
158
+ this._exports[prefetchId] || (this._exports[compatId] as PrefetchExports);
155
159
  if (!prefetchExports) {
156
160
  return;
157
161
  }