@module-federation/data-prefetch 0.0.0-next-20241015060033 → 0.0.0-next-20241016062654

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 (89) hide show
  1. package/.swcrc +29 -0
  2. package/CHANGELOG.md +41 -4
  3. package/LICENSE +1 -1
  4. package/dist/LICENSE +21 -0
  5. package/dist/babel.cjs.d.ts +2 -0
  6. package/dist/babel.cjs.js +50 -0
  7. package/dist/babel.esm.d.ts +2 -0
  8. package/dist/babel.esm.js +48 -0
  9. package/dist/cli.cjs.d.ts +1 -0
  10. package/dist/cli.cjs.js +156 -0
  11. package/dist/cli.esm.d.ts +1 -0
  12. package/dist/cli.esm.js +153 -0
  13. package/dist/constant.cjs.js +5 -0
  14. package/dist/constant.esm.js +3 -0
  15. package/dist/index.cjs.d.ts +1 -0
  16. package/dist/index.cjs.js +14 -0
  17. package/dist/index.cjs2.js +7 -0
  18. package/dist/index.esm.d.ts +1 -0
  19. package/dist/index.esm.js +7 -0
  20. package/dist/index.esm2.js +5 -0
  21. package/dist/package.json +88 -0
  22. package/dist/plugin.cjs.d.ts +2 -0
  23. package/dist/plugin.cjs.js +159 -0
  24. package/dist/plugin.esm.d.ts +2 -0
  25. package/dist/plugin.esm.js +154 -0
  26. package/dist/polyfills.cjs.js +14 -0
  27. package/dist/polyfills.esm.js +12 -0
  28. package/dist/prefetch.cjs.js +142 -0
  29. package/dist/prefetch.esm.js +140 -0
  30. package/dist/react.cjs.d.ts +1 -0
  31. package/dist/react.cjs.js +77 -0
  32. package/dist/react.esm.d.ts +1 -0
  33. package/dist/react.esm.js +75 -0
  34. package/dist/runtime-utils.cjs.js +27 -0
  35. package/dist/runtime-utils.esm.js +22 -0
  36. package/dist/{cli → src/cli}/babel.d.ts +2 -4
  37. package/dist/{cli → src/cli}/index.d.ts +5 -8
  38. package/dist/src/common/constant.d.ts +1 -0
  39. package/dist/src/common/index.d.ts +1 -0
  40. package/dist/src/common/node-utils.d.ts +2 -0
  41. package/dist/src/common/runtime-utils.d.ts +5 -0
  42. package/dist/src/constant.d.ts +1 -0
  43. package/dist/src/index.d.ts +2 -0
  44. package/dist/src/logger/index.d.ts +3 -0
  45. package/dist/src/plugin.d.ts +3 -0
  46. package/dist/{prefetch-c08be471.d.ts → src/prefetch.d.ts} +4 -6
  47. package/dist/src/react/hooks.d.ts +11 -0
  48. package/dist/src/react/index.d.ts +1 -0
  49. package/dist/src/react/utils.d.ts +1 -0
  50. package/dist/src/universal/index.d.ts +2 -0
  51. package/dist/universal.cjs.d.ts +1 -0
  52. package/dist/universal.cjs.js +29 -0
  53. package/dist/universal.esm.d.ts +1 -0
  54. package/dist/universal.esm.js +27 -0
  55. package/package.json +28 -37
  56. package/project.json +48 -6
  57. package/rollup.config.js +45 -0
  58. package/src/cli/index.ts +7 -4
  59. package/src/constant.ts +1 -0
  60. package/src/plugin.ts +4 -4
  61. package/tsconfig.json +1 -1
  62. package/tsconfig.lib.json +10 -0
  63. package/dist/cli/babel.js +0 -84
  64. package/dist/cli/index.js +0 -207
  65. package/dist/esm/chunk-AJPO2B2T.js +0 -30
  66. package/dist/esm/chunk-BGNOVRH5.js +0 -166
  67. package/dist/esm/chunk-EZUCZHGV.js +0 -11
  68. package/dist/esm/chunk-ISF7VMBW.js +0 -156
  69. package/dist/esm/chunk-OCDMSRMZ.js +0 -32
  70. package/dist/esm/chunk-TTJJJ2WZ.js +0 -7
  71. package/dist/esm/cli/babel.js +0 -57
  72. package/dist/esm/cli/index.js +0 -180
  73. package/dist/esm/index.js +0 -13
  74. package/dist/esm/plugin.js +0 -12
  75. package/dist/esm/react/index.js +0 -94
  76. package/dist/esm/shared/index.js +0 -27
  77. package/dist/esm/universal/index.js +0 -9
  78. package/dist/index.d.ts +0 -5
  79. package/dist/index.js +0 -351
  80. package/dist/plugin.d.ts +0 -5
  81. package/dist/plugin.js +0 -347
  82. package/dist/react/index.d.ts +0 -16
  83. package/dist/react/index.js +0 -287
  84. package/dist/shared/index.d.ts +0 -5
  85. package/dist/shared/index.js +0 -48
  86. package/dist/universal/index.d.ts +0 -8
  87. package/dist/universal/index.js +0 -205
  88. package/src/shared/index.ts +0 -26
  89. package/tsup.config.ts +0 -35
@@ -0,0 +1,140 @@
1
+ import { getRemoteInfo, getRemoteEntry } from '@module-federation/runtime';
2
+ import { loadScript } from '@module-federation/sdk';
3
+ import { b as getPrefetchId, c as compatGetPrefetchId } from './runtime-utils.esm.js';
4
+
5
+ var // @ts-ignore init global variable for test
6
+ _globalThis, _globalThis___FEDERATION__;
7
+ var ___FEDERATION__;
8
+ (___FEDERATION__ = (_globalThis = globalThis).__FEDERATION__) != null ? ___FEDERATION__ : _globalThis.__FEDERATION__ = {};
9
+ var ___PREFETCH__;
10
+ (___PREFETCH__ = (_globalThis___FEDERATION__ = globalThis.__FEDERATION__).__PREFETCH__) != null ? ___PREFETCH__ : _globalThis___FEDERATION__.__PREFETCH__ = {
11
+ entryLoading: {},
12
+ instance: new Map(),
13
+ __PREFETCH_EXPORTS__: {}
14
+ };
15
+ class MFDataPrefetch {
16
+ get global() {
17
+ return globalThis.__FEDERATION__.__PREFETCH__;
18
+ }
19
+ static getInstance(id) {
20
+ return globalThis.__FEDERATION__.__PREFETCH__.instance.get(id);
21
+ }
22
+ async loadEntry(entry) {
23
+ const { name, remoteSnapshot, remote, origin } = this._options;
24
+ if (entry) {
25
+ const { buildVersion, globalName } = remoteSnapshot;
26
+ const uniqueKey = globalName || `${name}:${buildVersion}`;
27
+ if (!this.global.entryLoading[uniqueKey]) {
28
+ this.global.entryLoading[uniqueKey] = loadScript(entry, {});
29
+ }
30
+ return this.global.entryLoading[uniqueKey];
31
+ } else {
32
+ const remoteInfo = getRemoteInfo(remote);
33
+ const module = origin.moduleCache.get(remoteInfo.name);
34
+ return getRemoteEntry({
35
+ origin: origin,
36
+ remoteInfo,
37
+ remoteEntryExports: module ? module.remoteEntryExports : undefined
38
+ });
39
+ }
40
+ }
41
+ getProjectExports() {
42
+ var _globalThis___FEDERATION_____PREFETCH_____PREFETCH_EXPORTS__;
43
+ if (Object.keys(this._exports).length > 0) {
44
+ return this._exports;
45
+ }
46
+ const { name } = this._options;
47
+ const exportsPromiseFn = (_globalThis___FEDERATION_____PREFETCH_____PREFETCH_EXPORTS__ = globalThis.__FEDERATION__.__PREFETCH__.__PREFETCH_EXPORTS__) == null ? void 0 : _globalThis___FEDERATION_____PREFETCH_____PREFETCH_EXPORTS__[name];
48
+ const exportsPromise = typeof exportsPromiseFn === 'function' ? exportsPromiseFn() : Promise.resolve({});
49
+ const resolve = exportsPromise.then((exports = {})=>{
50
+ // Match prefetch based on the function name suffix so that other capabilities can be expanded later.
51
+ // Not all functions should be directly identified as prefetch functions
52
+ const memory = {};
53
+ Object.keys(exports).forEach((key)=>{
54
+ memory[key] = {};
55
+ const exportVal = exports[key];
56
+ Object.keys(exportVal).reduce((memo, current)=>{
57
+ if (current.toLocaleLowerCase().endsWith('prefetch') || current.toLocaleLowerCase() === 'default') {
58
+ memo[current] = exportVal[current];
59
+ }
60
+ return memo;
61
+ }, memory[key]);
62
+ });
63
+ this.memorizeExports(memory);
64
+ });
65
+ return resolve;
66
+ }
67
+ memorizeExports(exports) {
68
+ this._exports = exports;
69
+ }
70
+ getExposeExports(id) {
71
+ const prefetchId = getPrefetchId(id);
72
+ const compatId = compatGetPrefetchId(id);
73
+ const prefetchExports = this._exports[prefetchId] || this._exports[compatId];
74
+ return prefetchExports || {};
75
+ }
76
+ prefetch(prefetchOptions) {
77
+ const { id, functionId = 'default', refetchParams } = prefetchOptions;
78
+ let prefetchResult;
79
+ const prefetchId = getPrefetchId(id);
80
+ const compatId = compatGetPrefetchId(id);
81
+ const memorizeId = id + functionId;
82
+ const memory = this.prefetchMemory.get(memorizeId);
83
+ if (!this.checkOutdate(prefetchOptions) && memory) {
84
+ return memory;
85
+ }
86
+ const prefetchExports = this._exports[prefetchId] || this._exports[compatId];
87
+ if (!prefetchExports) {
88
+ return;
89
+ }
90
+ const executePrefetch = prefetchExports[functionId];
91
+ if (typeof executePrefetch === 'function') {
92
+ if (refetchParams) {
93
+ prefetchResult = executePrefetch(refetchParams);
94
+ } else {
95
+ prefetchResult = executePrefetch();
96
+ }
97
+ } else {
98
+ throw new Error(`[Module Federation Data Prefetch]: No prefetch function called ${functionId} export in prefetch file`);
99
+ }
100
+ this.memorize(memorizeId, prefetchResult);
101
+ return prefetchResult;
102
+ }
103
+ memorize(id, value) {
104
+ this.prefetchMemory.set(id, value);
105
+ }
106
+ markOutdate(markOptions, isOutdate) {
107
+ const { id, functionId = 'default' } = markOptions;
108
+ if (!this.recordOutdate[id]) {
109
+ this.recordOutdate[id] = {};
110
+ }
111
+ this.recordOutdate[id][functionId] = isOutdate;
112
+ }
113
+ checkOutdate(outdateOptions) {
114
+ const { id, functionId = 'default', cacheStrategy } = outdateOptions;
115
+ if (typeof cacheStrategy === 'function') {
116
+ return cacheStrategy();
117
+ }
118
+ if (!this.recordOutdate[id]) {
119
+ this.recordOutdate[id] = {};
120
+ }
121
+ if (this.recordOutdate[id][functionId]) {
122
+ this.markOutdate({
123
+ id,
124
+ functionId
125
+ }, false);
126
+ return true;
127
+ } else {
128
+ return false;
129
+ }
130
+ }
131
+ constructor(options){
132
+ this.prefetchMemory = new Map();
133
+ this.recordOutdate = {};
134
+ this._exports = {};
135
+ this._options = options;
136
+ this.global.instance.set(options.name, this);
137
+ }
138
+ }
139
+
140
+ export { MFDataPrefetch as M };
@@ -0,0 +1 @@
1
+ export * from "./src/react/index";
@@ -0,0 +1,77 @@
1
+ 'use strict';
2
+
3
+ var polyfills = require('./polyfills.cjs.js');
4
+ var react = require('react');
5
+ var index = require('./index.cjs2.js');
6
+ var prefetch = require('./prefetch.cjs.js');
7
+ var universal = require('./universal.cjs.js');
8
+ var runtimeUtils = require('./runtime-utils.cjs.js');
9
+ require('@module-federation/sdk');
10
+ require('@module-federation/runtime');
11
+
12
+ const useFirstMounted = ()=>{
13
+ const ref = react.useRef(true);
14
+ react.useEffect(()=>{
15
+ ref.current = false;
16
+ }, []);
17
+ return ref.current;
18
+ };
19
+
20
+ const usePrefetch = (options)=>{
21
+ const isFirstMounted = useFirstMounted();
22
+ if (isFirstMounted) {
23
+ const startTiming = performance.now();
24
+ index.logger.info(`2. Start Get Prefetch Data: ${options.id} - ${options.functionId || 'default'} - ${startTiming}`);
25
+ }
26
+ const { id, functionId, deferId } = options;
27
+ const prefetchInfo = {
28
+ id,
29
+ functionId
30
+ };
31
+ const mfScope = runtimeUtils.getScope();
32
+ let state;
33
+ const prefetchResult = universal.prefetch(options);
34
+ if (deferId) {
35
+ if (prefetchResult instanceof Promise) {
36
+ state = prefetchResult.then((deferredData)=>deferredData.data[deferId]);
37
+ } else {
38
+ state = prefetchResult.data[deferId];
39
+ }
40
+ } else {
41
+ state = prefetchResult;
42
+ }
43
+ const [prefetchState, setPrefetchState] = react.useState(state);
44
+ const prefetchInstance = prefetch.MFDataPrefetch.getInstance(mfScope);
45
+ react.useEffect(()=>{
46
+ const useEffectTiming = performance.now();
47
+ index.logger.info(`3. Start Execute UseEffect: ${options.id} - ${options.functionId || 'default'} - ${useEffectTiming}`);
48
+ return ()=>{
49
+ prefetchInstance == null ? void 0 : prefetchInstance.markOutdate(prefetchInfo, true);
50
+ };
51
+ }, []);
52
+ const refreshExecutor = (refetchParams)=>{
53
+ const refetchOptions = polyfills._extends({}, options);
54
+ if (refetchParams) {
55
+ refetchOptions.refetchParams = refetchParams;
56
+ }
57
+ prefetchInstance == null ? void 0 : prefetchInstance.markOutdate(prefetchInfo, true);
58
+ const newVal = universal.prefetch(refetchOptions);
59
+ let newState;
60
+ if (deferId) {
61
+ if (newVal instanceof Promise) {
62
+ newState = newVal.then((deferredData)=>deferredData.data[deferId]);
63
+ } else {
64
+ newState = newVal.data[deferId];
65
+ }
66
+ } else {
67
+ newState = newVal;
68
+ }
69
+ setPrefetchState(newState);
70
+ };
71
+ return [
72
+ prefetchState,
73
+ refreshExecutor
74
+ ];
75
+ };
76
+
77
+ exports.usePrefetch = usePrefetch;
@@ -0,0 +1 @@
1
+ export * from "./src/react/index";
@@ -0,0 +1,75 @@
1
+ import { _ as _extends } from './polyfills.esm.js';
2
+ import { useRef, useEffect, useState } from 'react';
3
+ import { l as logger } from './index.esm2.js';
4
+ import { M as MFDataPrefetch } from './prefetch.esm.js';
5
+ import { prefetch } from './universal.esm.js';
6
+ import { g as getScope } from './runtime-utils.esm.js';
7
+ import '@module-federation/sdk';
8
+ import '@module-federation/runtime';
9
+
10
+ const useFirstMounted = ()=>{
11
+ const ref = useRef(true);
12
+ useEffect(()=>{
13
+ ref.current = false;
14
+ }, []);
15
+ return ref.current;
16
+ };
17
+
18
+ const usePrefetch = (options)=>{
19
+ const isFirstMounted = useFirstMounted();
20
+ if (isFirstMounted) {
21
+ const startTiming = performance.now();
22
+ logger.info(`2. Start Get Prefetch Data: ${options.id} - ${options.functionId || 'default'} - ${startTiming}`);
23
+ }
24
+ const { id, functionId, deferId } = options;
25
+ const prefetchInfo = {
26
+ id,
27
+ functionId
28
+ };
29
+ const mfScope = getScope();
30
+ let state;
31
+ const prefetchResult = prefetch(options);
32
+ if (deferId) {
33
+ if (prefetchResult instanceof Promise) {
34
+ state = prefetchResult.then((deferredData)=>deferredData.data[deferId]);
35
+ } else {
36
+ state = prefetchResult.data[deferId];
37
+ }
38
+ } else {
39
+ state = prefetchResult;
40
+ }
41
+ const [prefetchState, setPrefetchState] = useState(state);
42
+ const prefetchInstance = MFDataPrefetch.getInstance(mfScope);
43
+ useEffect(()=>{
44
+ const useEffectTiming = performance.now();
45
+ logger.info(`3. Start Execute UseEffect: ${options.id} - ${options.functionId || 'default'} - ${useEffectTiming}`);
46
+ return ()=>{
47
+ prefetchInstance == null ? void 0 : prefetchInstance.markOutdate(prefetchInfo, true);
48
+ };
49
+ }, []);
50
+ const refreshExecutor = (refetchParams)=>{
51
+ const refetchOptions = _extends({}, options);
52
+ if (refetchParams) {
53
+ refetchOptions.refetchParams = refetchParams;
54
+ }
55
+ prefetchInstance == null ? void 0 : prefetchInstance.markOutdate(prefetchInfo, true);
56
+ const newVal = prefetch(refetchOptions);
57
+ let newState;
58
+ if (deferId) {
59
+ if (newVal instanceof Promise) {
60
+ newState = newVal.then((deferredData)=>deferredData.data[deferId]);
61
+ } else {
62
+ newState = newVal.data[deferId];
63
+ }
64
+ } else {
65
+ newState = newVal;
66
+ }
67
+ setPrefetchState(newState);
68
+ };
69
+ return [
70
+ prefetchState,
71
+ refreshExecutor
72
+ ];
73
+ };
74
+
75
+ export { usePrefetch };
@@ -0,0 +1,27 @@
1
+ 'use strict';
2
+
3
+ var runtime = require('@module-federation/runtime');
4
+ var sdk = require('@module-federation/sdk');
5
+
6
+ const getScope = ()=>{
7
+ return runtime.getInstance().options.name;
8
+ };
9
+ const getPrefetchId = (id)=>sdk.encodeName(`${id}/${sdk.MFPrefetchCommon.identifier}`);
10
+ const compatGetPrefetchId = (id)=>sdk.encodeName(`${id}/VmokPrefetch`);
11
+ const getSignalFromManifest = (remoteSnapshot)=>{
12
+ if (!remoteSnapshot) {
13
+ return false;
14
+ }
15
+ if (!('prefetchEntry' in remoteSnapshot) && !('prefetchInterface' in remoteSnapshot)) {
16
+ return false;
17
+ }
18
+ if (!remoteSnapshot.prefetchEntry && !remoteSnapshot.prefetchInterface) {
19
+ return false;
20
+ }
21
+ return true;
22
+ };
23
+
24
+ exports.compatGetPrefetchId = compatGetPrefetchId;
25
+ exports.getPrefetchId = getPrefetchId;
26
+ exports.getScope = getScope;
27
+ exports.getSignalFromManifest = getSignalFromManifest;
@@ -0,0 +1,22 @@
1
+ import { getInstance } from '@module-federation/runtime';
2
+ import { encodeName, MFPrefetchCommon } from '@module-federation/sdk';
3
+
4
+ const getScope = ()=>{
5
+ return getInstance().options.name;
6
+ };
7
+ const getPrefetchId = (id)=>encodeName(`${id}/${MFPrefetchCommon.identifier}`);
8
+ const compatGetPrefetchId = (id)=>encodeName(`${id}/VmokPrefetch`);
9
+ const getSignalFromManifest = (remoteSnapshot)=>{
10
+ if (!remoteSnapshot) {
11
+ return false;
12
+ }
13
+ if (!('prefetchEntry' in remoteSnapshot) && !('prefetchInterface' in remoteSnapshot)) {
14
+ return false;
15
+ }
16
+ if (!remoteSnapshot.prefetchEntry && !remoteSnapshot.prefetchInterface) {
17
+ return false;
18
+ }
19
+ return true;
20
+ };
21
+
22
+ export { getSignalFromManifest as a, getPrefetchId as b, compatGetPrefetchId as c, getScope as g };
@@ -1,5 +1,4 @@
1
- import { moduleFederationPlugin } from '@module-federation/sdk';
2
-
1
+ import type { moduleFederationPlugin } from '@module-federation/sdk';
3
2
  interface BabelPluginOptions {
4
3
  hook_id: string;
5
4
  import_pkg: string;
@@ -35,5 +34,4 @@ declare const _default: (babel: {
35
34
  }): void;
36
35
  };
37
36
  };
38
-
39
- export { _default as default };
37
+ export default _default;
@@ -1,10 +1,8 @@
1
- import * as webpack from 'webpack';
2
- import { WebpackPluginInstance, Compiler } from 'webpack';
3
1
  import { moduleFederationPlugin } from '@module-federation/sdk';
4
-
5
- declare const RuntimeGlobals: typeof webpack.RuntimeGlobals;
6
- declare function getFederationGlobalScope(runtimeGlobals: typeof RuntimeGlobals): string;
7
- declare class PrefetchPlugin implements WebpackPluginInstance {
2
+ import type { Compiler, WebpackPluginInstance } from 'webpack';
3
+ declare const RuntimeGlobals: typeof import("webpack").RuntimeGlobals;
4
+ export declare function getFederationGlobalScope(runtimeGlobals: typeof RuntimeGlobals): string;
5
+ export declare class PrefetchPlugin implements WebpackPluginInstance {
8
6
  options: moduleFederationPlugin.ModuleFederationPluginOptions;
9
7
  private _reWriteExports;
10
8
  constructor(options: moduleFederationPlugin.ModuleFederationPluginOptions);
@@ -15,5 +13,4 @@ declare class PrefetchPlugin implements WebpackPluginInstance {
15
13
  static setRemoteIdentifier(): string;
16
14
  static removeRemoteIdentifier(): string;
17
15
  }
18
-
19
- export { PrefetchPlugin, getFederationGlobalScope };
16
+ export {};
@@ -0,0 +1 @@
1
+ export declare const TEMP_DIR = ".mf";
@@ -0,0 +1 @@
1
+ export * from './constant';
@@ -0,0 +1,2 @@
1
+ export declare const fileExistsWithCaseSync: (filepath: string) => boolean;
2
+ export declare const fixPrefetchPath: (exposePath: string) => Array<string>;
@@ -0,0 +1,5 @@
1
+ import { ModuleInfo } from '@module-federation/sdk';
2
+ export declare const getScope: () => string;
3
+ export declare const getPrefetchId: (id: string) => string;
4
+ export declare const compatGetPrefetchId: (id: string) => string;
5
+ export declare const getSignalFromManifest: (remoteSnapshot: ModuleInfo) => boolean;
@@ -0,0 +1 @@
1
+ export declare const SHARED_STRATEGY = "loaded-first";
@@ -0,0 +1,2 @@
1
+ export * from './prefetch';
2
+ export * from './plugin';
@@ -0,0 +1,3 @@
1
+ import { Logger } from '@module-federation/sdk';
2
+ declare const _default: Logger;
3
+ export default _default;
@@ -0,0 +1,3 @@
1
+ import type { FederationRuntimePlugin } from '@module-federation/runtime/types';
2
+ export declare const prefetchPlugin: () => FederationRuntimePlugin;
3
+ export default prefetchPlugin;
@@ -1,7 +1,6 @@
1
1
  import { FederationHost } from '@module-federation/runtime';
2
2
  import { ModuleInfo } from '@module-federation/sdk';
3
3
  import { Remote } from '@module-federation/runtime/types';
4
-
5
4
  declare module '@module-federation/runtime' {
6
5
  interface Federation {
7
6
  __PREFETCH__: {
@@ -12,19 +11,19 @@ declare module '@module-federation/runtime' {
12
11
  }
13
12
  }
14
13
  type PrefetchExports = Record<string, any>;
15
- interface DataPrefetchOptions {
14
+ export interface DataPrefetchOptions {
16
15
  name: string;
17
16
  remote?: Remote;
18
17
  origin?: FederationHost;
19
18
  remoteSnapshot?: ModuleInfo;
20
19
  }
21
- interface prefetchOptions {
20
+ export interface prefetchOptions {
22
21
  id: string;
23
22
  functionId?: string;
24
23
  cacheStrategy?: () => boolean;
25
24
  refetchParams?: any;
26
25
  }
27
- declare class MFDataPrefetch {
26
+ export declare class MFDataPrefetch {
28
27
  prefetchMemory: Map<string, Promise<any>>;
29
28
  recordOutdate: Record<string, Record<string, boolean>>;
30
29
  private _exports;
@@ -41,5 +40,4 @@ declare class MFDataPrefetch {
41
40
  markOutdate(markOptions: Omit<prefetchOptions, 'cacheStrategy'>, isOutdate: boolean): void;
42
41
  checkOutdate(outdateOptions: prefetchOptions): boolean;
43
42
  }
44
-
45
- export { DataPrefetchOptions as D, MFDataPrefetch as M, prefetchOptions as p };
43
+ export {};
@@ -0,0 +1,11 @@
1
+ import { type prefetchOptions } from '../prefetch';
2
+ type refetchParams = any;
3
+ type prefetchReturnType<T> = [
4
+ Promise<T>,
5
+ (refetchParams?: refetchParams) => void
6
+ ];
7
+ type UsePrefetchOptions = prefetchOptions & {
8
+ deferId?: string;
9
+ };
10
+ export declare const usePrefetch: <T>(options: UsePrefetchOptions) => prefetchReturnType<T>;
11
+ export {};
@@ -0,0 +1 @@
1
+ export * from './hooks';
@@ -0,0 +1 @@
1
+ export declare const useFirstMounted: () => boolean;
@@ -0,0 +1,2 @@
1
+ import { type prefetchOptions } from '../prefetch';
2
+ export declare function prefetch(options: prefetchOptions): Promise<any>;
@@ -0,0 +1 @@
1
+ export * from "./src/universal/index";
@@ -0,0 +1,29 @@
1
+ 'use strict';
2
+
3
+ var prefetch$1 = require('./prefetch.cjs.js');
4
+ var runtimeUtils = require('./runtime-utils.cjs.js');
5
+ require('@module-federation/runtime');
6
+ require('@module-federation/sdk');
7
+
8
+ function prefetch(options) {
9
+ const { id, functionId = 'default' } = options;
10
+ const mfScope = runtimeUtils.getScope();
11
+ const prefetchInstance = prefetch$1.MFDataPrefetch.getInstance(mfScope) || new prefetch$1.MFDataPrefetch({
12
+ name: mfScope
13
+ });
14
+ const res = prefetchInstance.getProjectExports();
15
+ if (res instanceof Promise) {
16
+ const promise = res.then(()=>{
17
+ const result = prefetchInstance.prefetch(options);
18
+ prefetchInstance.memorize(id + functionId, result);
19
+ return result;
20
+ });
21
+ return promise;
22
+ } else {
23
+ const result = prefetchInstance.prefetch(options);
24
+ prefetchInstance.memorize(id + functionId, result);
25
+ return result;
26
+ }
27
+ }
28
+
29
+ exports.prefetch = prefetch;
@@ -0,0 +1 @@
1
+ export * from "./src/universal/index";
@@ -0,0 +1,27 @@
1
+ import { M as MFDataPrefetch } from './prefetch.esm.js';
2
+ import { g as getScope } from './runtime-utils.esm.js';
3
+ import '@module-federation/runtime';
4
+ import '@module-federation/sdk';
5
+
6
+ function prefetch(options) {
7
+ const { id, functionId = 'default' } = options;
8
+ const mfScope = getScope();
9
+ const prefetchInstance = MFDataPrefetch.getInstance(mfScope) || new MFDataPrefetch({
10
+ name: mfScope
11
+ });
12
+ const res = prefetchInstance.getProjectExports();
13
+ if (res instanceof Promise) {
14
+ const promise = res.then(()=>{
15
+ const result = prefetchInstance.prefetch(options);
16
+ prefetchInstance.memorize(id + functionId, result);
17
+ return result;
18
+ });
19
+ return promise;
20
+ } else {
21
+ const result = prefetchInstance.prefetch(options);
22
+ prefetchInstance.memorize(id + functionId, result);
23
+ return result;
24
+ }
25
+ }
26
+
27
+ export { prefetch };