@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
@@ -1,142 +0,0 @@
1
- 'use strict';
2
-
3
- var runtime = require('@module-federation/runtime');
4
- var sdk = require('@module-federation/sdk');
5
- var runtimeUtils = require('./runtime-utils.cjs.js');
6
-
7
- var // @ts-ignore init global variable for test
8
- _globalThis, _globalThis___FEDERATION__;
9
- var ___FEDERATION__;
10
- (___FEDERATION__ = (_globalThis = globalThis).__FEDERATION__) != null ? ___FEDERATION__ : _globalThis.__FEDERATION__ = {};
11
- var ___PREFETCH__;
12
- (___PREFETCH__ = (_globalThis___FEDERATION__ = globalThis.__FEDERATION__).__PREFETCH__) != null ? ___PREFETCH__ : _globalThis___FEDERATION__.__PREFETCH__ = {
13
- entryLoading: {},
14
- instance: new Map(),
15
- __PREFETCH_EXPORTS__: {}
16
- };
17
- class MFDataPrefetch {
18
- get global() {
19
- return globalThis.__FEDERATION__.__PREFETCH__;
20
- }
21
- static getInstance(id) {
22
- return globalThis.__FEDERATION__.__PREFETCH__.instance.get(id);
23
- }
24
- async loadEntry(entry) {
25
- const { name, remoteSnapshot, remote, origin } = this._options;
26
- if (entry) {
27
- const { buildVersion, globalName } = remoteSnapshot;
28
- const uniqueKey = globalName || `${name}:${buildVersion}`;
29
- if (!this.global.entryLoading[uniqueKey]) {
30
- this.global.entryLoading[uniqueKey] = sdk.loadScript(entry, {});
31
- }
32
- return this.global.entryLoading[uniqueKey];
33
- } else {
34
- const remoteInfo = runtime.getRemoteInfo(remote);
35
- const module = origin.moduleCache.get(remoteInfo.name);
36
- return runtime.getRemoteEntry({
37
- origin: origin,
38
- remoteInfo,
39
- remoteEntryExports: module ? module.remoteEntryExports : undefined
40
- });
41
- }
42
- }
43
- getProjectExports() {
44
- var _globalThis___FEDERATION_____PREFETCH_____PREFETCH_EXPORTS__;
45
- if (Object.keys(this._exports).length > 0) {
46
- return this._exports;
47
- }
48
- const { name } = this._options;
49
- const exportsPromiseFn = (_globalThis___FEDERATION_____PREFETCH_____PREFETCH_EXPORTS__ = globalThis.__FEDERATION__.__PREFETCH__.__PREFETCH_EXPORTS__) == null ? void 0 : _globalThis___FEDERATION_____PREFETCH_____PREFETCH_EXPORTS__[name];
50
- const exportsPromise = typeof exportsPromiseFn === 'function' ? exportsPromiseFn() : Promise.resolve({});
51
- const resolve = exportsPromise.then((exports = {})=>{
52
- // Match prefetch based on the function name suffix so that other capabilities can be expanded later.
53
- // Not all functions should be directly identified as prefetch functions
54
- const memory = {};
55
- Object.keys(exports).forEach((key)=>{
56
- memory[key] = {};
57
- const exportVal = exports[key];
58
- Object.keys(exportVal).reduce((memo, current)=>{
59
- if (current.toLocaleLowerCase().endsWith('prefetch') || current.toLocaleLowerCase() === 'default') {
60
- memo[current] = exportVal[current];
61
- }
62
- return memo;
63
- }, memory[key]);
64
- });
65
- this.memorizeExports(memory);
66
- });
67
- return resolve;
68
- }
69
- memorizeExports(exports) {
70
- this._exports = exports;
71
- }
72
- getExposeExports(id) {
73
- const prefetchId = runtimeUtils.getPrefetchId(id);
74
- const compatId = runtimeUtils.compatGetPrefetchId(id);
75
- const prefetchExports = this._exports[prefetchId] || this._exports[compatId];
76
- return prefetchExports || {};
77
- }
78
- prefetch(prefetchOptions) {
79
- const { id, functionId = 'default', refetchParams } = prefetchOptions;
80
- let prefetchResult;
81
- const prefetchId = runtimeUtils.getPrefetchId(id);
82
- const compatId = runtimeUtils.compatGetPrefetchId(id);
83
- const memorizeId = id + functionId;
84
- const memory = this.prefetchMemory.get(memorizeId);
85
- if (!this.checkOutdate(prefetchOptions) && memory) {
86
- return memory;
87
- }
88
- const prefetchExports = this._exports[prefetchId] || this._exports[compatId];
89
- if (!prefetchExports) {
90
- return;
91
- }
92
- const executePrefetch = prefetchExports[functionId];
93
- if (typeof executePrefetch === 'function') {
94
- if (refetchParams) {
95
- prefetchResult = executePrefetch(refetchParams);
96
- } else {
97
- prefetchResult = executePrefetch();
98
- }
99
- } else {
100
- throw new Error(`[Module Federation Data Prefetch]: No prefetch function called ${functionId} export in prefetch file`);
101
- }
102
- this.memorize(memorizeId, prefetchResult);
103
- return prefetchResult;
104
- }
105
- memorize(id, value) {
106
- this.prefetchMemory.set(id, value);
107
- }
108
- markOutdate(markOptions, isOutdate) {
109
- const { id, functionId = 'default' } = markOptions;
110
- if (!this.recordOutdate[id]) {
111
- this.recordOutdate[id] = {};
112
- }
113
- this.recordOutdate[id][functionId] = isOutdate;
114
- }
115
- checkOutdate(outdateOptions) {
116
- const { id, functionId = 'default', cacheStrategy } = outdateOptions;
117
- if (typeof cacheStrategy === 'function') {
118
- return cacheStrategy();
119
- }
120
- if (!this.recordOutdate[id]) {
121
- this.recordOutdate[id] = {};
122
- }
123
- if (this.recordOutdate[id][functionId]) {
124
- this.markOutdate({
125
- id,
126
- functionId
127
- }, false);
128
- return true;
129
- } else {
130
- return false;
131
- }
132
- }
133
- constructor(options){
134
- this.prefetchMemory = new Map();
135
- this.recordOutdate = {};
136
- this._exports = {};
137
- this._options = options;
138
- this.global.instance.set(options.name, this);
139
- }
140
- }
141
-
142
- exports.MFDataPrefetch = MFDataPrefetch;
@@ -1,140 +0,0 @@
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 };
@@ -1 +0,0 @@
1
- export * from "./src/react/index";
package/dist/react.cjs.js DELETED
@@ -1,77 +0,0 @@
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;
@@ -1 +0,0 @@
1
- export * from "./src/react/index";
package/dist/react.esm.js DELETED
@@ -1,75 +0,0 @@
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 };
@@ -1,27 +0,0 @@
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;
@@ -1,22 +0,0 @@
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,2 +0,0 @@
1
- export * from "./src/shared/index";
2
- export { default } from "./src/shared/index";
@@ -1,24 +0,0 @@
1
- 'use strict';
2
-
3
- const sharedStrategy = ()=>({
4
- name: 'shared-strategy',
5
- beforeInit (args) {
6
- const { userOptions } = args;
7
- const shared = userOptions.shared;
8
- if (shared) {
9
- Object.keys(shared).forEach((sharedKey)=>{
10
- const sharedConfigs = shared[sharedKey];
11
- const arraySharedConfigs = Array.isArray(sharedConfigs) ? sharedConfigs : [
12
- sharedConfigs
13
- ];
14
- arraySharedConfigs.forEach((s)=>{
15
- s.strategy = 'loaded-first';
16
- });
17
- });
18
- console.warn(`[Module Federation Data Prefetch]: Your shared strategy is set to 'loaded-first', this is a necessary condition for data prefetch`);
19
- }
20
- return args;
21
- }
22
- });
23
-
24
- module.exports = sharedStrategy;
@@ -1,2 +0,0 @@
1
- export * from "./src/shared/index";
2
- export { default } from "./src/shared/index";
@@ -1,22 +0,0 @@
1
- const sharedStrategy = ()=>({
2
- name: 'shared-strategy',
3
- beforeInit (args) {
4
- const { userOptions } = args;
5
- const shared = userOptions.shared;
6
- if (shared) {
7
- Object.keys(shared).forEach((sharedKey)=>{
8
- const sharedConfigs = shared[sharedKey];
9
- const arraySharedConfigs = Array.isArray(sharedConfigs) ? sharedConfigs : [
10
- sharedConfigs
11
- ];
12
- arraySharedConfigs.forEach((s)=>{
13
- s.strategy = 'loaded-first';
14
- });
15
- });
16
- console.warn(`[Module Federation Data Prefetch]: Your shared strategy is set to 'loaded-first', this is a necessary condition for data prefetch`);
17
- }
18
- return args;
19
- }
20
- });
21
-
22
- export { sharedStrategy as default };
@@ -1 +0,0 @@
1
- export declare const TEMP_DIR = ".mf";
@@ -1 +0,0 @@
1
- export * from './constant';
@@ -1,2 +0,0 @@
1
- export declare const fileExistsWithCaseSync: (filepath: string) => boolean;
2
- export declare const fixPrefetchPath: (exposePath: string) => Array<string>;
@@ -1,5 +0,0 @@
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;
@@ -1,2 +0,0 @@
1
- export * from './prefetch';
2
- export * from './plugin';
@@ -1,3 +0,0 @@
1
- import { Logger } from '@module-federation/sdk';
2
- declare const _default: Logger;
3
- export default _default;
@@ -1,3 +0,0 @@
1
- import type { FederationRuntimePlugin } from '@module-federation/runtime/types';
2
- export declare const prefetchPlugin: () => FederationRuntimePlugin;
3
- export default prefetchPlugin;
@@ -1,11 +0,0 @@
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 {};
@@ -1 +0,0 @@
1
- export * from './hooks';
@@ -1 +0,0 @@
1
- export declare const useFirstMounted: () => boolean;
@@ -1,3 +0,0 @@
1
- import type { FederationRuntimePlugin } from '@module-federation/runtime';
2
- declare const sharedStrategy: () => FederationRuntimePlugin;
3
- export default sharedStrategy;
@@ -1,2 +0,0 @@
1
- import { type prefetchOptions } from '../prefetch';
2
- export declare function prefetch(options: prefetchOptions): Promise<any>;
@@ -1 +0,0 @@
1
- export * from "./src/universal/index";
@@ -1,29 +0,0 @@
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;
@@ -1 +0,0 @@
1
- export * from "./src/universal/index";