@module-federation/data-prefetch 0.0.0-next-20241010063233 → 0.0.0-next-20241010084324

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.
Files changed (87) hide show
  1. package/CHANGELOG.md +4 -29
  2. package/LICENSE +1 -1
  3. package/dist/{src/cli → cli}/babel.d.ts +4 -2
  4. package/dist/cli/babel.js +84 -0
  5. package/dist/{src/cli → cli}/index.d.ts +8 -5
  6. package/dist/cli/index.js +207 -0
  7. package/dist/esm/chunk-AJPO2B2T.js +30 -0
  8. package/dist/esm/chunk-BGNOVRH5.js +166 -0
  9. package/dist/esm/chunk-EZUCZHGV.js +11 -0
  10. package/dist/esm/chunk-ISF7VMBW.js +156 -0
  11. package/dist/esm/chunk-OCDMSRMZ.js +32 -0
  12. package/dist/esm/chunk-TTJJJ2WZ.js +7 -0
  13. package/dist/esm/cli/babel.js +57 -0
  14. package/dist/esm/cli/index.js +180 -0
  15. package/dist/esm/index.js +13 -0
  16. package/dist/esm/plugin.js +12 -0
  17. package/dist/esm/react/index.js +94 -0
  18. package/dist/esm/shared/index.js +27 -0
  19. package/dist/esm/universal/index.js +9 -0
  20. package/dist/index.d.ts +5 -0
  21. package/dist/index.js +351 -0
  22. package/dist/plugin.d.ts +5 -0
  23. package/dist/plugin.js +347 -0
  24. package/dist/{src/prefetch.d.ts → prefetch-c08be471.d.ts} +6 -4
  25. package/dist/react/index.d.ts +16 -0
  26. package/dist/react/index.js +287 -0
  27. package/dist/shared/index.d.ts +5 -0
  28. package/dist/shared/index.js +48 -0
  29. package/dist/universal/index.d.ts +8 -0
  30. package/dist/universal/index.js +205 -0
  31. package/package.json +30 -33
  32. package/project.json +6 -48
  33. package/src/cli/index.ts +2 -2
  34. package/tsconfig.json +1 -1
  35. package/.swcrc +0 -29
  36. package/dist/LICENSE +0 -21
  37. package/dist/babel.cjs.d.ts +0 -2
  38. package/dist/babel.cjs.js +0 -50
  39. package/dist/babel.esm.d.ts +0 -2
  40. package/dist/babel.esm.js +0 -48
  41. package/dist/cli.cjs.d.ts +0 -1
  42. package/dist/cli.cjs.js +0 -155
  43. package/dist/cli.esm.d.ts +0 -1
  44. package/dist/cli.esm.js +0 -152
  45. package/dist/index.cjs.d.ts +0 -1
  46. package/dist/index.cjs.js +0 -13
  47. package/dist/index.cjs2.js +0 -7
  48. package/dist/index.esm.d.ts +0 -1
  49. package/dist/index.esm.js +0 -6
  50. package/dist/index.esm2.js +0 -5
  51. package/dist/package.json +0 -100
  52. package/dist/plugin.cjs.d.ts +0 -2
  53. package/dist/plugin.cjs.js +0 -159
  54. package/dist/plugin.esm.d.ts +0 -2
  55. package/dist/plugin.esm.js +0 -154
  56. package/dist/polyfills.cjs.js +0 -14
  57. package/dist/polyfills.esm.js +0 -12
  58. package/dist/prefetch.cjs.js +0 -142
  59. package/dist/prefetch.esm.js +0 -140
  60. package/dist/react.cjs.d.ts +0 -1
  61. package/dist/react.cjs.js +0 -77
  62. package/dist/react.esm.d.ts +0 -1
  63. package/dist/react.esm.js +0 -75
  64. package/dist/runtime-utils.cjs.js +0 -27
  65. package/dist/runtime-utils.esm.js +0 -22
  66. package/dist/shared.cjs.d.ts +0 -2
  67. package/dist/shared.cjs.js +0 -24
  68. package/dist/shared.esm.d.ts +0 -2
  69. package/dist/shared.esm.js +0 -22
  70. package/dist/src/common/constant.d.ts +0 -1
  71. package/dist/src/common/index.d.ts +0 -1
  72. package/dist/src/common/node-utils.d.ts +0 -2
  73. package/dist/src/common/runtime-utils.d.ts +0 -5
  74. package/dist/src/index.d.ts +0 -2
  75. package/dist/src/logger/index.d.ts +0 -3
  76. package/dist/src/plugin.d.ts +0 -3
  77. package/dist/src/react/hooks.d.ts +0 -11
  78. package/dist/src/react/index.d.ts +0 -1
  79. package/dist/src/react/utils.d.ts +0 -1
  80. package/dist/src/shared/index.d.ts +0 -3
  81. package/dist/src/universal/index.d.ts +0 -2
  82. package/dist/universal.cjs.d.ts +0 -1
  83. package/dist/universal.cjs.js +0 -29
  84. package/dist/universal.esm.d.ts +0 -1
  85. package/dist/universal.esm.js +0 -27
  86. package/rollup.config.js +0 -46
  87. package/tsconfig.lib.json +0 -10
@@ -0,0 +1,156 @@
1
+ import {
2
+ compatGetPrefetchId,
3
+ getPrefetchId
4
+ } from "./chunk-AJPO2B2T.js";
5
+
6
+ // src/prefetch.ts
7
+ import {
8
+ getRemoteEntry,
9
+ getRemoteInfo
10
+ } from "@module-federation/runtime";
11
+ import {
12
+ loadScript
13
+ } from "@module-federation/sdk";
14
+ globalThis.__FEDERATION__ ?? (globalThis.__FEDERATION__ = {});
15
+ var _a;
16
+ (_a = globalThis.__FEDERATION__).__PREFETCH__ ?? (_a.__PREFETCH__ = {
17
+ entryLoading: {},
18
+ instance: /* @__PURE__ */ new Map(),
19
+ __PREFETCH_EXPORTS__: {}
20
+ });
21
+ var MFDataPrefetch = class {
22
+ constructor(options) {
23
+ this.prefetchMemory = /* @__PURE__ */ new Map();
24
+ this.recordOutdate = {};
25
+ this._exports = {};
26
+ this._options = options;
27
+ this.global.instance.set(options.name, this);
28
+ }
29
+ get global() {
30
+ return globalThis.__FEDERATION__.__PREFETCH__;
31
+ }
32
+ static getInstance(id) {
33
+ return globalThis.__FEDERATION__.__PREFETCH__.instance.get(id);
34
+ }
35
+ async loadEntry(entry) {
36
+ const { name, remoteSnapshot, remote, origin } = this._options;
37
+ if (entry) {
38
+ const { buildVersion, globalName } = remoteSnapshot;
39
+ const uniqueKey = globalName || `${name}:${buildVersion}`;
40
+ if (!this.global.entryLoading[uniqueKey]) {
41
+ this.global.entryLoading[uniqueKey] = loadScript(entry, {});
42
+ }
43
+ return this.global.entryLoading[uniqueKey];
44
+ } else {
45
+ const remoteInfo = getRemoteInfo(remote);
46
+ const module = origin.moduleCache.get(remoteInfo.name);
47
+ return getRemoteEntry({
48
+ origin,
49
+ remoteInfo,
50
+ remoteEntryExports: module ? module.remoteEntryExports : void 0
51
+ });
52
+ }
53
+ }
54
+ getProjectExports() {
55
+ var _a2;
56
+ if (Object.keys(this._exports).length > 0) {
57
+ return this._exports;
58
+ }
59
+ const { name } = this._options;
60
+ const exportsPromiseFn = (_a2 = globalThis.__FEDERATION__.__PREFETCH__.__PREFETCH_EXPORTS__) == null ? void 0 : _a2[name];
61
+ const exportsPromise = typeof exportsPromiseFn === "function" ? exportsPromiseFn() : Promise.resolve({});
62
+ const resolve = exportsPromise.then(
63
+ (exports = {}) => {
64
+ const memory = {};
65
+ Object.keys(exports).forEach((key) => {
66
+ memory[key] = {};
67
+ const exportVal = exports[key];
68
+ Object.keys(exportVal).reduce(
69
+ (memo, current) => {
70
+ if (current.toLocaleLowerCase().endsWith("prefetch") || current.toLocaleLowerCase() === "default") {
71
+ memo[current] = exportVal[current];
72
+ }
73
+ return memo;
74
+ },
75
+ memory[key]
76
+ );
77
+ });
78
+ this.memorizeExports(memory);
79
+ }
80
+ );
81
+ return resolve;
82
+ }
83
+ memorizeExports(exports) {
84
+ this._exports = exports;
85
+ }
86
+ getExposeExports(id) {
87
+ const prefetchId = getPrefetchId(id);
88
+ const compatId = compatGetPrefetchId(id);
89
+ const prefetchExports = this._exports[prefetchId] || this._exports[compatId];
90
+ return prefetchExports || {};
91
+ }
92
+ prefetch(prefetchOptions) {
93
+ const { id, functionId = "default", refetchParams } = prefetchOptions;
94
+ let prefetchResult;
95
+ const prefetchId = getPrefetchId(id);
96
+ const compatId = compatGetPrefetchId(id);
97
+ const memorizeId = id + functionId;
98
+ const memory = this.prefetchMemory.get(memorizeId);
99
+ if (!this.checkOutdate(prefetchOptions) && memory) {
100
+ return memory;
101
+ }
102
+ const prefetchExports = this._exports[prefetchId] || this._exports[compatId];
103
+ if (!prefetchExports) {
104
+ return;
105
+ }
106
+ const executePrefetch = prefetchExports[functionId];
107
+ if (typeof executePrefetch === "function") {
108
+ if (refetchParams) {
109
+ prefetchResult = executePrefetch(refetchParams);
110
+ } else {
111
+ prefetchResult = executePrefetch();
112
+ }
113
+ } else {
114
+ throw new Error(
115
+ `[Module Federation Data Prefetch]: No prefetch function called ${functionId} export in prefetch file`
116
+ );
117
+ }
118
+ this.memorize(memorizeId, prefetchResult);
119
+ return prefetchResult;
120
+ }
121
+ memorize(id, value) {
122
+ this.prefetchMemory.set(id, value);
123
+ }
124
+ markOutdate(markOptions, isOutdate) {
125
+ const { id, functionId = "default" } = markOptions;
126
+ if (!this.recordOutdate[id]) {
127
+ this.recordOutdate[id] = {};
128
+ }
129
+ this.recordOutdate[id][functionId] = isOutdate;
130
+ }
131
+ checkOutdate(outdateOptions) {
132
+ const { id, functionId = "default", cacheStrategy } = outdateOptions;
133
+ if (typeof cacheStrategy === "function") {
134
+ return cacheStrategy();
135
+ }
136
+ if (!this.recordOutdate[id]) {
137
+ this.recordOutdate[id] = {};
138
+ }
139
+ if (this.recordOutdate[id][functionId]) {
140
+ this.markOutdate(
141
+ {
142
+ id,
143
+ functionId
144
+ },
145
+ false
146
+ );
147
+ return true;
148
+ } else {
149
+ return false;
150
+ }
151
+ }
152
+ };
153
+
154
+ export {
155
+ MFDataPrefetch
156
+ };
@@ -0,0 +1,32 @@
1
+ import {
2
+ MFDataPrefetch
3
+ } from "./chunk-ISF7VMBW.js";
4
+ import {
5
+ getScope
6
+ } from "./chunk-AJPO2B2T.js";
7
+
8
+ // src/universal/index.ts
9
+ function prefetch(options) {
10
+ const { id, functionId = "default" } = options;
11
+ const mfScope = getScope();
12
+ const prefetchInstance = MFDataPrefetch.getInstance(mfScope) || new MFDataPrefetch({
13
+ name: mfScope
14
+ });
15
+ const res = prefetchInstance.getProjectExports();
16
+ if (res instanceof Promise) {
17
+ const promise = res.then(() => {
18
+ const result = prefetchInstance.prefetch(options);
19
+ prefetchInstance.memorize(id + functionId, result);
20
+ return result;
21
+ });
22
+ return promise;
23
+ } else {
24
+ const result = prefetchInstance.prefetch(options);
25
+ prefetchInstance.memorize(id + functionId, result);
26
+ return result;
27
+ }
28
+ }
29
+
30
+ export {
31
+ prefetch
32
+ };
@@ -0,0 +1,7 @@
1
+ // src/logger/index.ts
2
+ import { Logger } from "@module-federation/sdk";
3
+ var logger_default = new Logger("[Module Federation Data Prefetch]");
4
+
5
+ export {
6
+ logger_default
7
+ };
@@ -0,0 +1,57 @@
1
+ import "../chunk-EZUCZHGV.js";
2
+
3
+ // src/cli/babel.ts
4
+ import path from "path";
5
+ var attribute = "id";
6
+ var hookId = "usePrefetch";
7
+ var importPackage = "@module-federation/data-prefetch/react";
8
+ var babel_default = (babel, options) => {
9
+ const t = babel.types;
10
+ let shouldHandle = false;
11
+ let scope = "";
12
+ const { name, exposes } = options;
13
+ if (!exposes) {
14
+ return {};
15
+ }
16
+ const exposesKey = Object.keys(exposes);
17
+ const processedExposes = exposesKey.map((expose) => ({
18
+ key: expose.replace(".", ""),
19
+ value: path.resolve(
20
+ typeof exposes[expose] === "string" ? exposes[expose] : exposes[expose].import
21
+ )
22
+ }));
23
+ return {
24
+ visitor: {
25
+ ImportDeclaration(nodePath, state) {
26
+ const source = nodePath.node.source.value;
27
+ const { specifiers } = nodePath.node;
28
+ const { filename } = state.file.opts;
29
+ if (source === importPackage) {
30
+ shouldHandle = specifiers.some(
31
+ (specifier) => specifier.imported && specifier.imported.name === hookId && processedExposes.find(
32
+ (expose) => expose.value === filename && (scope = expose.key)
33
+ )
34
+ );
35
+ }
36
+ },
37
+ CallExpression(nodePath) {
38
+ if (shouldHandle && t.isIdentifier(nodePath.node.callee, { name: hookId }) && nodePath.node.arguments.length > 0) {
39
+ const objectExpression = nodePath.node.arguments[0];
40
+ if (objectExpression && t.isObjectExpression(objectExpression) && !objectExpression.properties.find(
41
+ (p) => p.key.name === attribute
42
+ )) {
43
+ objectExpression.properties.push(
44
+ t.objectProperty(
45
+ t.identifier(attribute),
46
+ t.stringLiteral(name + scope)
47
+ )
48
+ );
49
+ }
50
+ }
51
+ }
52
+ }
53
+ };
54
+ };
55
+ export {
56
+ babel_default as default
57
+ };
@@ -0,0 +1,180 @@
1
+ import {
2
+ getPrefetchId
3
+ } from "../chunk-AJPO2B2T.js";
4
+ import {
5
+ __require
6
+ } from "../chunk-EZUCZHGV.js";
7
+
8
+ // src/cli/index.ts
9
+ import path2 from "path";
10
+ import fs2 from "fs-extra";
11
+ import {
12
+ encodeName,
13
+ MFPrefetchCommon
14
+ } from "@module-federation/sdk";
15
+ import { normalizeWebpackPath } from "@module-federation/sdk/normalize-webpack-path";
16
+
17
+ // src/common/constant.ts
18
+ var TEMP_DIR = ".mf";
19
+
20
+ // src/common/node-utils.ts
21
+ import path from "path";
22
+ import fs from "fs-extra";
23
+ var fileExistsWithCaseSync = (filepath) => {
24
+ const dir = path.dirname(filepath);
25
+ if (filepath === "/" || filepath === ".") {
26
+ return true;
27
+ }
28
+ const filenames = fs.readdirSync(dir);
29
+ if (filenames.indexOf(path.basename(filepath)) === -1) {
30
+ return false;
31
+ }
32
+ return fileExistsWithCaseSync(dir);
33
+ };
34
+ var fixPrefetchPath = (exposePath) => {
35
+ const pathExt = [".js", ".ts"];
36
+ const extReg = /\.(ts|js|tsx|jsx)$/;
37
+ if (extReg.test(exposePath)) {
38
+ return pathExt.map((ext) => exposePath.replace(extReg, `.prefetch${ext}`));
39
+ } else {
40
+ return pathExt.map((ext) => exposePath + `.prefetch${ext}`);
41
+ }
42
+ };
43
+
44
+ // src/cli/index.ts
45
+ var { RuntimeGlobals, Template } = __require(normalizeWebpackPath("webpack"));
46
+ function getFederationGlobalScope(runtimeGlobals) {
47
+ return `${runtimeGlobals.require || "__webpack_require__"}.federation`;
48
+ }
49
+ var PrefetchPlugin = class {
50
+ constructor(options) {
51
+ this.options = options;
52
+ this._reWriteExports = "";
53
+ }
54
+ apply(compiler) {
55
+ var _a, _b;
56
+ const { name, exposes } = this.options;
57
+ if (!exposes) {
58
+ return;
59
+ }
60
+ if (!compiler.options.context) {
61
+ throw new Error("compiler.options.context is not defined");
62
+ }
63
+ const { runtimePlugins } = this.options;
64
+ if (!Array.isArray(runtimePlugins)) {
65
+ this.options.runtimePlugins = [];
66
+ }
67
+ const runtimePath = path2.resolve(__dirname, "../esm/plugin.js");
68
+ const sharedPath = path2.resolve(__dirname, "../esm/shared/index.js");
69
+ if (!((_a = this.options.runtimePlugins) == null ? void 0 : _a.includes(runtimePath))) {
70
+ this.options.runtimePlugins.push(runtimePath);
71
+ }
72
+ if (!((_b = this.options.runtimePlugins) == null ? void 0 : _b.includes(sharedPath))) {
73
+ this.options.runtimePlugins.push(sharedPath);
74
+ }
75
+ const encodedName = encodeName(name);
76
+ const asyncEntryPath = path2.resolve(
77
+ compiler.options.context,
78
+ `node_modules/${TEMP_DIR}/${encodedName}/bootstrap.js`
79
+ );
80
+ if (fs2.existsSync(asyncEntryPath)) {
81
+ fs2.unlinkSync(asyncEntryPath);
82
+ }
83
+ if (!this.options.dataPrefetch) {
84
+ return;
85
+ }
86
+ const prefetchs = [];
87
+ const exposeAlias = Object.keys(exposes);
88
+ exposeAlias.forEach((alias) => {
89
+ let exposePath;
90
+ const exposeValue = exposes[alias];
91
+ if (typeof exposeValue === "string") {
92
+ exposePath = exposeValue;
93
+ } else {
94
+ exposePath = exposeValue.import[0];
95
+ }
96
+ const targetPaths = fixPrefetchPath(exposePath);
97
+ for (const pathItem of targetPaths) {
98
+ const absolutePath = path2.resolve(compiler.options.context, pathItem);
99
+ if (fileExistsWithCaseSync(absolutePath)) {
100
+ prefetchs.push(pathItem);
101
+ const absoluteAlias = alias.replace(".", "");
102
+ this._reWriteExports += `export * as ${getPrefetchId(
103
+ `${name}${absoluteAlias}`
104
+ )} from '${absolutePath}';
105
+ `;
106
+ break;
107
+ }
108
+ }
109
+ });
110
+ if (!this._reWriteExports) {
111
+ return;
112
+ }
113
+ const tempDirRealPath = path2.resolve(
114
+ compiler.options.context,
115
+ "node_modules",
116
+ TEMP_DIR
117
+ );
118
+ if (!fs2.existsSync(tempDirRealPath)) {
119
+ fs2.mkdirSync(tempDirRealPath);
120
+ }
121
+ if (!fs2.existsSync(`${tempDirRealPath}/${encodedName}`)) {
122
+ fs2.mkdirSync(`${tempDirRealPath}/${encodedName}`);
123
+ }
124
+ fs2.writeFileSync(asyncEntryPath, this._reWriteExports);
125
+ new compiler.webpack.DefinePlugin({
126
+ FederationDataPrefetch: JSON.stringify(asyncEntryPath)
127
+ }).apply(compiler);
128
+ }
129
+ static addRuntime(compiler, options) {
130
+ const encodedName = encodeName(options.name);
131
+ if (!compiler.options.context) {
132
+ throw new Error("compiler.options.context is not defined");
133
+ }
134
+ const prefetchEntry = path2.resolve(
135
+ compiler.options.context,
136
+ `node_modules/.mf/${encodedName}/bootstrap.js`
137
+ );
138
+ const federationGlobal = getFederationGlobalScope(
139
+ RuntimeGlobals || {}
140
+ );
141
+ return Template.asString([
142
+ fs2.existsSync(prefetchEntry) ? Template.indent([
143
+ "function injectPrefetch() {",
144
+ Template.indent([
145
+ `globalThis.__FEDERATION__ = globalThis.__FEDERATION__ || {};`,
146
+ `globalThis.__FEDERATION__['${MFPrefetchCommon.globalKey}'] = globalThis.__FEDERATION__['${MFPrefetchCommon.globalKey}'] || {`,
147
+ `entryLoading: {},`,
148
+ `instance: new Map(),`,
149
+ `__PREFETCH_EXPORTS__: {},`,
150
+ `};`,
151
+ `globalThis.__FEDERATION__['${MFPrefetchCommon.globalKey}']['${MFPrefetchCommon.exportsKey}'] = globalThis.__FEDERATION__['${MFPrefetchCommon.globalKey}']['${MFPrefetchCommon.exportsKey}'] || {};`,
152
+ `globalThis.__FEDERATION__['${MFPrefetchCommon.globalKey}']['${MFPrefetchCommon.exportsKey}']['${options.name}'] = function(){ return import('${prefetchEntry}');}`
153
+ ]),
154
+ "}",
155
+ `${federationGlobal}.prefetch = injectPrefetch`
156
+ ]) : "",
157
+ Template.indent([
158
+ `if(!${federationGlobal}.isMFRemote && ${federationGlobal}.prefetch){`,
159
+ `${federationGlobal}.prefetch()`,
160
+ "}"
161
+ ])
162
+ ]);
163
+ }
164
+ static setRemoteIdentifier() {
165
+ const federationGlobal = getFederationGlobalScope(
166
+ RuntimeGlobals || {}
167
+ );
168
+ return Template.indent([`${federationGlobal}.isMFRemote = true;`]);
169
+ }
170
+ static removeRemoteIdentifier() {
171
+ const federationGlobal = getFederationGlobalScope(
172
+ RuntimeGlobals || {}
173
+ );
174
+ return Template.indent([`${federationGlobal}.isMFRemote = false;`]);
175
+ }
176
+ };
177
+ export {
178
+ PrefetchPlugin,
179
+ getFederationGlobalScope
180
+ };
@@ -0,0 +1,13 @@
1
+ import {
2
+ prefetchPlugin
3
+ } from "./chunk-BGNOVRH5.js";
4
+ import "./chunk-TTJJJ2WZ.js";
5
+ import {
6
+ MFDataPrefetch
7
+ } from "./chunk-ISF7VMBW.js";
8
+ import "./chunk-AJPO2B2T.js";
9
+ import "./chunk-EZUCZHGV.js";
10
+ export {
11
+ MFDataPrefetch,
12
+ prefetchPlugin
13
+ };
@@ -0,0 +1,12 @@
1
+ import {
2
+ plugin_default,
3
+ prefetchPlugin
4
+ } from "./chunk-BGNOVRH5.js";
5
+ import "./chunk-TTJJJ2WZ.js";
6
+ import "./chunk-ISF7VMBW.js";
7
+ import "./chunk-AJPO2B2T.js";
8
+ import "./chunk-EZUCZHGV.js";
9
+ export {
10
+ plugin_default as default,
11
+ prefetchPlugin
12
+ };
@@ -0,0 +1,94 @@
1
+ import {
2
+ prefetch
3
+ } from "../chunk-OCDMSRMZ.js";
4
+ import {
5
+ logger_default
6
+ } from "../chunk-TTJJJ2WZ.js";
7
+ import {
8
+ MFDataPrefetch
9
+ } from "../chunk-ISF7VMBW.js";
10
+ import {
11
+ getScope
12
+ } from "../chunk-AJPO2B2T.js";
13
+ import "../chunk-EZUCZHGV.js";
14
+
15
+ // src/react/hooks.ts
16
+ import { useEffect as useEffect2, useState } from "react";
17
+
18
+ // src/react/utils.ts
19
+ import { useEffect, useRef } from "react";
20
+ var useFirstMounted = () => {
21
+ const ref = useRef(true);
22
+ useEffect(() => {
23
+ ref.current = false;
24
+ }, []);
25
+ return ref.current;
26
+ };
27
+
28
+ // src/react/hooks.ts
29
+ var usePrefetch = (options) => {
30
+ const isFirstMounted = useFirstMounted();
31
+ if (isFirstMounted) {
32
+ const startTiming = performance.now();
33
+ logger_default.info(
34
+ `2. Start Get Prefetch Data: ${options.id} - ${options.functionId || "default"} - ${startTiming}`
35
+ );
36
+ }
37
+ const { id, functionId, deferId } = options;
38
+ const prefetchInfo = {
39
+ id,
40
+ functionId
41
+ };
42
+ const mfScope = getScope();
43
+ let state;
44
+ const prefetchResult = prefetch(options);
45
+ if (deferId) {
46
+ if (prefetchResult instanceof Promise) {
47
+ state = prefetchResult.then(
48
+ (deferredData) => deferredData.data[deferId]
49
+ );
50
+ } else {
51
+ state = prefetchResult.data[deferId];
52
+ }
53
+ } else {
54
+ state = prefetchResult;
55
+ }
56
+ const [prefetchState, setPrefetchState] = useState(
57
+ state
58
+ );
59
+ const prefetchInstance = MFDataPrefetch.getInstance(mfScope);
60
+ useEffect2(() => {
61
+ const useEffectTiming = performance.now();
62
+ logger_default.info(
63
+ `3. Start Execute UseEffect: ${options.id} - ${options.functionId || "default"} - ${useEffectTiming}`
64
+ );
65
+ return () => {
66
+ prefetchInstance == null ? void 0 : prefetchInstance.markOutdate(prefetchInfo, true);
67
+ };
68
+ }, []);
69
+ const refreshExecutor = (refetchParams) => {
70
+ const refetchOptions = {
71
+ ...options
72
+ };
73
+ if (refetchParams) {
74
+ refetchOptions.refetchParams = refetchParams;
75
+ }
76
+ prefetchInstance == null ? void 0 : prefetchInstance.markOutdate(prefetchInfo, true);
77
+ const newVal = prefetch(refetchOptions);
78
+ let newState;
79
+ if (deferId) {
80
+ if (newVal instanceof Promise) {
81
+ newState = newVal.then((deferredData) => deferredData.data[deferId]);
82
+ } else {
83
+ newState = newVal.data[deferId];
84
+ }
85
+ } else {
86
+ newState = newVal;
87
+ }
88
+ setPrefetchState(newState);
89
+ };
90
+ return [prefetchState, refreshExecutor];
91
+ };
92
+ export {
93
+ usePrefetch
94
+ };
@@ -0,0 +1,27 @@
1
+ import "../chunk-EZUCZHGV.js";
2
+
3
+ // src/shared/index.ts
4
+ var sharedStrategy = () => ({
5
+ name: "shared-strategy",
6
+ beforeInit(args) {
7
+ const { userOptions } = args;
8
+ const shared = userOptions.shared;
9
+ if (shared) {
10
+ Object.keys(shared).forEach((sharedKey) => {
11
+ const sharedConfigs = shared[sharedKey];
12
+ const arraySharedConfigs = Array.isArray(sharedConfigs) ? sharedConfigs : [sharedConfigs];
13
+ arraySharedConfigs.forEach((s) => {
14
+ s.strategy = "loaded-first";
15
+ });
16
+ });
17
+ console.warn(
18
+ `[Module Federation Data Prefetch]: Your shared strategy is set to 'loaded-first', this is a necessary condition for data prefetch`
19
+ );
20
+ }
21
+ return args;
22
+ }
23
+ });
24
+ var shared_default = sharedStrategy;
25
+ export {
26
+ shared_default as default
27
+ };
@@ -0,0 +1,9 @@
1
+ import {
2
+ prefetch
3
+ } from "../chunk-OCDMSRMZ.js";
4
+ import "../chunk-ISF7VMBW.js";
5
+ import "../chunk-AJPO2B2T.js";
6
+ import "../chunk-EZUCZHGV.js";
7
+ export {
8
+ prefetch
9
+ };
@@ -0,0 +1,5 @@
1
+ export { D as DataPrefetchOptions, M as MFDataPrefetch, p as prefetchOptions } from './prefetch-c08be471.js';
2
+ export { default as prefetchPlugin } from './plugin.js';
3
+ import '@module-federation/runtime';
4
+ import '@module-federation/sdk';
5
+ import '@module-federation/runtime/types';