@module-federation/data-prefetch 0.6.6 → 0.6.7

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 (81) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/LICENSE +1 -1
  3. package/__tests__/prefetch.spec.ts +3 -2
  4. package/__tests__/react.spec.ts +1 -1
  5. package/dist/LICENSE +21 -0
  6. package/dist/babel.cjs.d.ts +2 -0
  7. package/dist/babel.cjs.js +62 -0
  8. package/dist/babel.esm.js +56 -0
  9. package/dist/cli.cjs.d.ts +1 -0
  10. package/dist/cli.cjs.js +3579 -0
  11. package/dist/cli.esm.js +3565 -0
  12. package/dist/index.cjs.d.ts +1 -0
  13. package/dist/index.cjs.js +15 -0
  14. package/dist/index.cjs2.js +7 -0
  15. package/dist/index.esm.js +6 -0
  16. package/dist/index.esm2.js +5 -0
  17. package/dist/package.json +99 -0
  18. package/dist/plugin.cjs.d.ts +2 -0
  19. package/dist/plugin.cjs.js +362 -0
  20. package/dist/plugin.esm.js +357 -0
  21. package/dist/prefetch.cjs.js +351 -0
  22. package/dist/prefetch.esm.js +349 -0
  23. package/dist/react.cjs.d.ts +1 -0
  24. package/dist/react.cjs.js +163 -0
  25. package/dist/react.esm.js +159 -0
  26. package/dist/runtime-utils.cjs.js +31 -0
  27. package/dist/runtime-utils.esm.js +26 -0
  28. package/dist/shared.cjs.d.ts +2 -0
  29. package/dist/shared.cjs.js +26 -0
  30. package/dist/shared.esm.js +24 -0
  31. package/dist/{cli → src/cli}/babel.d.ts +2 -4
  32. package/dist/{cli → src/cli}/index.d.ts +5 -8
  33. package/dist/src/common/constant.d.ts +1 -0
  34. package/dist/src/common/index.d.ts +1 -0
  35. package/dist/src/common/node-utils.d.ts +2 -0
  36. package/dist/src/common/runtime-utils.d.ts +5 -0
  37. package/dist/src/index.d.ts +2 -0
  38. package/dist/src/logger/index.d.ts +3 -0
  39. package/dist/src/plugin.d.ts +3 -0
  40. package/dist/{prefetch-4e9646e4.d.ts → src/prefetch.d.ts} +5 -7
  41. package/dist/src/react/hooks.d.ts +11 -0
  42. package/dist/src/react/index.d.ts +1 -0
  43. package/dist/src/react/utils.d.ts +1 -0
  44. package/dist/src/shared/index.d.ts +3 -0
  45. package/dist/src/universal/index.d.ts +2 -0
  46. package/dist/universal.cjs.d.ts +1 -0
  47. package/dist/universal.cjs.js +38 -0
  48. package/dist/universal.esm.js +34 -0
  49. package/jest.config.js +2 -2
  50. package/package.json +31 -28
  51. package/project.json +46 -4
  52. package/rollup.config.js +25 -0
  53. package/src/cli/index.ts +12 -10
  54. package/src/prefetch.ts +6 -2
  55. package/tsconfig.json +1 -1
  56. package/tsconfig.lib.json +10 -0
  57. package/dist/cli/babel.js +0 -84
  58. package/dist/cli/index.js +0 -205
  59. package/dist/esm/chunk-AJPO2B2T.js +0 -30
  60. package/dist/esm/chunk-EZUCZHGV.js +0 -11
  61. package/dist/esm/chunk-ISLXMAIA.js +0 -155
  62. package/dist/esm/chunk-KI4QGPIS.js +0 -32
  63. package/dist/esm/chunk-TTJJJ2WZ.js +0 -7
  64. package/dist/esm/chunk-VVZ6XIM6.js +0 -166
  65. package/dist/esm/cli/babel.js +0 -57
  66. package/dist/esm/cli/index.js +0 -178
  67. package/dist/esm/index.js +0 -13
  68. package/dist/esm/plugin.js +0 -12
  69. package/dist/esm/react/index.js +0 -94
  70. package/dist/esm/shared/index.js +0 -27
  71. package/dist/esm/universal/index.js +0 -9
  72. package/dist/index.d.ts +0 -5
  73. package/dist/index.js +0 -350
  74. package/dist/plugin.d.ts +0 -5
  75. package/dist/plugin.js +0 -346
  76. package/dist/react/index.d.ts +0 -16
  77. package/dist/react/index.js +0 -286
  78. package/dist/shared/index.d.ts +0 -5
  79. package/dist/shared/index.js +0 -48
  80. package/dist/universal/index.d.ts +0 -8
  81. package/dist/universal/index.js +0 -204
@@ -0,0 +1,163 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var react = require('react');
6
+ var index = require('./index.cjs2.js');
7
+ var prefetch = require('./prefetch.cjs.js');
8
+ var universal = require('./universal.cjs.js');
9
+ var runtimeUtils = require('./runtime-utils.cjs.js');
10
+ require('@module-federation/sdk');
11
+ require('@module-federation/runtime');
12
+
13
+ var useFirstMounted = function() {
14
+ var ref = react.useRef(true);
15
+ react.useEffect(function() {
16
+ ref.current = false;
17
+ }, []);
18
+ return ref.current;
19
+ };
20
+
21
+ function _array_like_to_array(arr, len) {
22
+ if (len == null || len > arr.length) len = arr.length;
23
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
24
+ return arr2;
25
+ }
26
+ function _array_with_holes(arr) {
27
+ if (Array.isArray(arr)) return arr;
28
+ }
29
+ function _define_property(obj, key, value) {
30
+ if (key in obj) {
31
+ Object.defineProperty(obj, key, {
32
+ value: value,
33
+ enumerable: true,
34
+ configurable: true,
35
+ writable: true
36
+ });
37
+ } else {
38
+ obj[key] = value;
39
+ }
40
+ return obj;
41
+ }
42
+ function _instanceof(left, right) {
43
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
44
+ return !!right[Symbol.hasInstance](left);
45
+ } else {
46
+ return left instanceof right;
47
+ }
48
+ }
49
+ function _iterable_to_array_limit(arr, i) {
50
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
51
+ if (_i == null) return;
52
+ var _arr = [];
53
+ var _n = true;
54
+ var _d = false;
55
+ var _s, _e;
56
+ try {
57
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
58
+ _arr.push(_s.value);
59
+ if (i && _arr.length === i) break;
60
+ }
61
+ } catch (err) {
62
+ _d = true;
63
+ _e = err;
64
+ } finally{
65
+ try {
66
+ if (!_n && _i["return"] != null) _i["return"]();
67
+ } finally{
68
+ if (_d) throw _e;
69
+ }
70
+ }
71
+ return _arr;
72
+ }
73
+ function _non_iterable_rest() {
74
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
75
+ }
76
+ function _object_spread(target) {
77
+ for(var i = 1; i < arguments.length; i++){
78
+ var source = arguments[i] != null ? arguments[i] : {};
79
+ var ownKeys = Object.keys(source);
80
+ if (typeof Object.getOwnPropertySymbols === "function") {
81
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
82
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
83
+ }));
84
+ }
85
+ ownKeys.forEach(function(key) {
86
+ _define_property(target, key, source[key]);
87
+ });
88
+ }
89
+ return target;
90
+ }
91
+ function _sliced_to_array(arr, i) {
92
+ return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
93
+ }
94
+ function _unsupported_iterable_to_array(o, minLen) {
95
+ if (!o) return;
96
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
97
+ var n = Object.prototype.toString.call(o).slice(8, -1);
98
+ if (n === "Object" && o.constructor) n = o.constructor.name;
99
+ if (n === "Map" || n === "Set") return Array.from(n);
100
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
101
+ }
102
+ var usePrefetch = function(options) {
103
+ var isFirstMounted = useFirstMounted();
104
+ if (isFirstMounted) {
105
+ var startTiming = performance.now();
106
+ index.logger.info("2. Start Get Prefetch Data: ".concat(options.id, " - ").concat(options.functionId || 'default', " - ").concat(startTiming));
107
+ }
108
+ var id = options.id, functionId = options.functionId, deferId = options.deferId;
109
+ var prefetchInfo = {
110
+ id: id,
111
+ functionId: functionId
112
+ };
113
+ var mfScope = runtimeUtils.getScope();
114
+ var state;
115
+ var prefetchResult = universal.prefetch(options);
116
+ if (deferId) {
117
+ if (_instanceof(prefetchResult, Promise)) {
118
+ state = prefetchResult.then(function(deferredData) {
119
+ return deferredData.data[deferId];
120
+ });
121
+ } else {
122
+ state = prefetchResult.data[deferId];
123
+ }
124
+ } else {
125
+ state = prefetchResult;
126
+ }
127
+ var _useState = _sliced_to_array(react.useState(state), 2), prefetchState = _useState[0], setPrefetchState = _useState[1];
128
+ var prefetchInstance = prefetch.MFDataPrefetch.getInstance(mfScope);
129
+ react.useEffect(function() {
130
+ var useEffectTiming = performance.now();
131
+ index.logger.info("3. Start Execute UseEffect: ".concat(options.id, " - ").concat(options.functionId || 'default', " - ").concat(useEffectTiming));
132
+ return function() {
133
+ prefetchInstance === null || prefetchInstance === void 0 ? void 0 : prefetchInstance.markOutdate(prefetchInfo, true);
134
+ };
135
+ }, []);
136
+ var refreshExecutor = function(refetchParams) {
137
+ var refetchOptions = _object_spread({}, options);
138
+ if (refetchParams) {
139
+ refetchOptions.refetchParams = refetchParams;
140
+ }
141
+ prefetchInstance === null || prefetchInstance === void 0 ? void 0 : prefetchInstance.markOutdate(prefetchInfo, true);
142
+ var newVal = universal.prefetch(refetchOptions);
143
+ var newState;
144
+ if (deferId) {
145
+ if (_instanceof(newVal, Promise)) {
146
+ newState = newVal.then(function(deferredData) {
147
+ return deferredData.data[deferId];
148
+ });
149
+ } else {
150
+ newState = newVal.data[deferId];
151
+ }
152
+ } else {
153
+ newState = newVal;
154
+ }
155
+ setPrefetchState(newState);
156
+ };
157
+ return [
158
+ prefetchState,
159
+ refreshExecutor
160
+ ];
161
+ };
162
+
163
+ exports.usePrefetch = usePrefetch;
@@ -0,0 +1,159 @@
1
+ import { useRef, useEffect, useState } from 'react';
2
+ import { l as logger } from './index.esm2.js';
3
+ import { M as MFDataPrefetch } from './prefetch.esm.js';
4
+ import { prefetch } from './universal.esm.js';
5
+ import { b as getScope } from './runtime-utils.esm.js';
6
+ import '@module-federation/sdk';
7
+ import '@module-federation/runtime';
8
+
9
+ var useFirstMounted = function() {
10
+ var ref = useRef(true);
11
+ useEffect(function() {
12
+ ref.current = false;
13
+ }, []);
14
+ return ref.current;
15
+ };
16
+
17
+ function _array_like_to_array(arr, len) {
18
+ if (len == null || len > arr.length) len = arr.length;
19
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
20
+ return arr2;
21
+ }
22
+ function _array_with_holes(arr) {
23
+ if (Array.isArray(arr)) return arr;
24
+ }
25
+ function _define_property(obj, key, value) {
26
+ if (key in obj) {
27
+ Object.defineProperty(obj, key, {
28
+ value: value,
29
+ enumerable: true,
30
+ configurable: true,
31
+ writable: true
32
+ });
33
+ } else {
34
+ obj[key] = value;
35
+ }
36
+ return obj;
37
+ }
38
+ function _instanceof(left, right) {
39
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
40
+ return !!right[Symbol.hasInstance](left);
41
+ } else {
42
+ return left instanceof right;
43
+ }
44
+ }
45
+ function _iterable_to_array_limit(arr, i) {
46
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
47
+ if (_i == null) return;
48
+ var _arr = [];
49
+ var _n = true;
50
+ var _d = false;
51
+ var _s, _e;
52
+ try {
53
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
54
+ _arr.push(_s.value);
55
+ if (i && _arr.length === i) break;
56
+ }
57
+ } catch (err) {
58
+ _d = true;
59
+ _e = err;
60
+ } finally{
61
+ try {
62
+ if (!_n && _i["return"] != null) _i["return"]();
63
+ } finally{
64
+ if (_d) throw _e;
65
+ }
66
+ }
67
+ return _arr;
68
+ }
69
+ function _non_iterable_rest() {
70
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
71
+ }
72
+ function _object_spread(target) {
73
+ for(var i = 1; i < arguments.length; i++){
74
+ var source = arguments[i] != null ? arguments[i] : {};
75
+ var ownKeys = Object.keys(source);
76
+ if (typeof Object.getOwnPropertySymbols === "function") {
77
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
78
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
79
+ }));
80
+ }
81
+ ownKeys.forEach(function(key) {
82
+ _define_property(target, key, source[key]);
83
+ });
84
+ }
85
+ return target;
86
+ }
87
+ function _sliced_to_array(arr, i) {
88
+ return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
89
+ }
90
+ function _unsupported_iterable_to_array(o, minLen) {
91
+ if (!o) return;
92
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
93
+ var n = Object.prototype.toString.call(o).slice(8, -1);
94
+ if (n === "Object" && o.constructor) n = o.constructor.name;
95
+ if (n === "Map" || n === "Set") return Array.from(n);
96
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
97
+ }
98
+ var usePrefetch = function(options) {
99
+ var isFirstMounted = useFirstMounted();
100
+ if (isFirstMounted) {
101
+ var startTiming = performance.now();
102
+ logger.info("2. Start Get Prefetch Data: ".concat(options.id, " - ").concat(options.functionId || 'default', " - ").concat(startTiming));
103
+ }
104
+ var id = options.id, functionId = options.functionId, deferId = options.deferId;
105
+ var prefetchInfo = {
106
+ id: id,
107
+ functionId: functionId
108
+ };
109
+ var mfScope = getScope();
110
+ var state;
111
+ var prefetchResult = prefetch(options);
112
+ if (deferId) {
113
+ if (_instanceof(prefetchResult, Promise)) {
114
+ state = prefetchResult.then(function(deferredData) {
115
+ return deferredData.data[deferId];
116
+ });
117
+ } else {
118
+ state = prefetchResult.data[deferId];
119
+ }
120
+ } else {
121
+ state = prefetchResult;
122
+ }
123
+ var _useState = _sliced_to_array(useState(state), 2), prefetchState = _useState[0], setPrefetchState = _useState[1];
124
+ var prefetchInstance = MFDataPrefetch.getInstance(mfScope);
125
+ useEffect(function() {
126
+ var useEffectTiming = performance.now();
127
+ logger.info("3. Start Execute UseEffect: ".concat(options.id, " - ").concat(options.functionId || 'default', " - ").concat(useEffectTiming));
128
+ return function() {
129
+ prefetchInstance === null || prefetchInstance === void 0 ? void 0 : prefetchInstance.markOutdate(prefetchInfo, true);
130
+ };
131
+ }, []);
132
+ var refreshExecutor = function(refetchParams) {
133
+ var refetchOptions = _object_spread({}, options);
134
+ if (refetchParams) {
135
+ refetchOptions.refetchParams = refetchParams;
136
+ }
137
+ prefetchInstance === null || prefetchInstance === void 0 ? void 0 : prefetchInstance.markOutdate(prefetchInfo, true);
138
+ var newVal = prefetch(refetchOptions);
139
+ var newState;
140
+ if (deferId) {
141
+ if (_instanceof(newVal, Promise)) {
142
+ newState = newVal.then(function(deferredData) {
143
+ return deferredData.data[deferId];
144
+ });
145
+ } else {
146
+ newState = newVal.data[deferId];
147
+ }
148
+ } else {
149
+ newState = newVal;
150
+ }
151
+ setPrefetchState(newState);
152
+ };
153
+ return [
154
+ prefetchState,
155
+ refreshExecutor
156
+ ];
157
+ };
158
+
159
+ export { usePrefetch };
@@ -0,0 +1,31 @@
1
+ 'use strict';
2
+
3
+ var runtime = require('@module-federation/runtime');
4
+ var sdk = require('@module-federation/sdk');
5
+
6
+ var getScope = function() {
7
+ return runtime.getInstance().options.name;
8
+ };
9
+ var getPrefetchId = function(id) {
10
+ return sdk.encodeName("".concat(id, "/").concat(sdk.MFPrefetchCommon.identifier));
11
+ };
12
+ var compatGetPrefetchId = function(id) {
13
+ return sdk.encodeName("".concat(id, "/VmokPrefetch"));
14
+ };
15
+ var getSignalFromManifest = function(remoteSnapshot) {
16
+ if (!remoteSnapshot) {
17
+ return false;
18
+ }
19
+ if (!('prefetchEntry' in remoteSnapshot) && !('prefetchInterface' in remoteSnapshot)) {
20
+ return false;
21
+ }
22
+ if (!remoteSnapshot.prefetchEntry && !remoteSnapshot.prefetchInterface) {
23
+ return false;
24
+ }
25
+ return true;
26
+ };
27
+
28
+ exports.compatGetPrefetchId = compatGetPrefetchId;
29
+ exports.getPrefetchId = getPrefetchId;
30
+ exports.getScope = getScope;
31
+ exports.getSignalFromManifest = getSignalFromManifest;
@@ -0,0 +1,26 @@
1
+ import { getInstance } from '@module-federation/runtime';
2
+ import { encodeName, MFPrefetchCommon } from '@module-federation/sdk';
3
+
4
+ var getScope = function() {
5
+ return getInstance().options.name;
6
+ };
7
+ var getPrefetchId = function(id) {
8
+ return encodeName("".concat(id, "/").concat(MFPrefetchCommon.identifier));
9
+ };
10
+ var compatGetPrefetchId = function(id) {
11
+ return encodeName("".concat(id, "/VmokPrefetch"));
12
+ };
13
+ var getSignalFromManifest = function(remoteSnapshot) {
14
+ if (!remoteSnapshot) {
15
+ return false;
16
+ }
17
+ if (!('prefetchEntry' in remoteSnapshot) && !('prefetchInterface' in remoteSnapshot)) {
18
+ return false;
19
+ }
20
+ if (!remoteSnapshot.prefetchEntry && !remoteSnapshot.prefetchInterface) {
21
+ return false;
22
+ }
23
+ return true;
24
+ };
25
+
26
+ export { getSignalFromManifest as a, getScope as b, compatGetPrefetchId as c, getPrefetchId as g };
@@ -0,0 +1,2 @@
1
+ export * from "./src/shared/index";
2
+ export { default } from "./src/shared/index";
@@ -0,0 +1,26 @@
1
+ 'use strict';
2
+
3
+ var sharedStrategy = function() {
4
+ return {
5
+ name: 'shared-strategy',
6
+ beforeInit: function beforeInit(args) {
7
+ var userOptions = args.userOptions;
8
+ var shared = userOptions.shared;
9
+ if (shared) {
10
+ Object.keys(shared).forEach(function(sharedKey) {
11
+ var sharedConfigs = shared[sharedKey];
12
+ var arraySharedConfigs = Array.isArray(sharedConfigs) ? sharedConfigs : [
13
+ sharedConfigs
14
+ ];
15
+ arraySharedConfigs.forEach(function(s) {
16
+ s.strategy = 'loaded-first';
17
+ });
18
+ });
19
+ console.warn("[Module Federation Data Prefetch]: Your shared strategy is set to 'loaded-first', this is a necessary condition for data prefetch");
20
+ }
21
+ return args;
22
+ }
23
+ };
24
+ };
25
+
26
+ module.exports = sharedStrategy;
@@ -0,0 +1,24 @@
1
+ var sharedStrategy = function() {
2
+ return {
3
+ name: 'shared-strategy',
4
+ beforeInit: function beforeInit(args) {
5
+ var userOptions = args.userOptions;
6
+ var shared = userOptions.shared;
7
+ if (shared) {
8
+ Object.keys(shared).forEach(function(sharedKey) {
9
+ var sharedConfigs = shared[sharedKey];
10
+ var arraySharedConfigs = Array.isArray(sharedConfigs) ? sharedConfigs : [
11
+ sharedConfigs
12
+ ];
13
+ arraySharedConfigs.forEach(function(s) {
14
+ s.strategy = 'loaded-first';
15
+ });
16
+ });
17
+ console.warn("[Module Federation Data Prefetch]: Your shared strategy is set to 'loaded-first', this is a necessary condition for data prefetch");
18
+ }
19
+ return args;
20
+ }
21
+ };
22
+ };
23
+
24
+ export { sharedStrategy as default };
@@ -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,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,30 +1,29 @@
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__: {
8
7
  entryLoading: Record<string, undefined | Promise<void>>;
9
8
  instance: Map<string, MFDataPrefetch>;
10
- __PREFETCH_EXPORTS__: Record<string, Promise<Record<string, any>>>;
9
+ __PREFETCH_EXPORTS__: Record<string, () => Promise<Record<string, any>>>;
11
10
  };
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,3 @@
1
+ import type { FederationRuntimePlugin } from '@module-federation/runtime';
2
+ declare const sharedStrategy: () => FederationRuntimePlugin;
3
+ export default sharedStrategy;
@@ -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,38 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var prefetch$1 = require('./prefetch.cjs.js');
6
+ var runtimeUtils = require('./runtime-utils.cjs.js');
7
+ require('@module-federation/runtime');
8
+ require('@module-federation/sdk');
9
+
10
+ function _instanceof(left, right) {
11
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
12
+ return !!right[Symbol.hasInstance](left);
13
+ } else {
14
+ return left instanceof right;
15
+ }
16
+ }
17
+ function prefetch(options) {
18
+ var id = options.id, _options_functionId = options.functionId, functionId = _options_functionId === void 0 ? 'default' : _options_functionId;
19
+ var mfScope = runtimeUtils.getScope();
20
+ var prefetchInstance = prefetch$1.MFDataPrefetch.getInstance(mfScope) || new prefetch$1.MFDataPrefetch({
21
+ name: mfScope
22
+ });
23
+ var res = prefetchInstance.getProjectExports();
24
+ if (_instanceof(res, Promise)) {
25
+ var promise = res.then(function() {
26
+ var result = prefetchInstance.prefetch(options);
27
+ prefetchInstance.memorize(id + functionId, result);
28
+ return result;
29
+ });
30
+ return promise;
31
+ } else {
32
+ var result = prefetchInstance.prefetch(options);
33
+ prefetchInstance.memorize(id + functionId, result);
34
+ return result;
35
+ }
36
+ }
37
+
38
+ exports.prefetch = prefetch;
@@ -0,0 +1,34 @@
1
+ import { M as MFDataPrefetch } from './prefetch.esm.js';
2
+ import { b as getScope } from './runtime-utils.esm.js';
3
+ import '@module-federation/runtime';
4
+ import '@module-federation/sdk';
5
+
6
+ function _instanceof(left, right) {
7
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
8
+ return !!right[Symbol.hasInstance](left);
9
+ } else {
10
+ return left instanceof right;
11
+ }
12
+ }
13
+ function prefetch(options) {
14
+ var id = options.id, _options_functionId = options.functionId, functionId = _options_functionId === void 0 ? 'default' : _options_functionId;
15
+ var mfScope = getScope();
16
+ var prefetchInstance = MFDataPrefetch.getInstance(mfScope) || new MFDataPrefetch({
17
+ name: mfScope
18
+ });
19
+ var res = prefetchInstance.getProjectExports();
20
+ if (_instanceof(res, Promise)) {
21
+ var promise = res.then(function() {
22
+ var result = prefetchInstance.prefetch(options);
23
+ prefetchInstance.memorize(id + functionId, result);
24
+ return result;
25
+ });
26
+ return promise;
27
+ } else {
28
+ var result = prefetchInstance.prefetch(options);
29
+ prefetchInstance.memorize(id + functionId, result);
30
+ return result;
31
+ }
32
+ }
33
+
34
+ export { prefetch };
package/jest.config.js CHANGED
@@ -24,6 +24,6 @@ module.exports = {
24
24
  '^.+\\.(t|j)sx?$': ['@swc/jest', { swcrc: false }],
25
25
  },
26
26
  rootDir: __dirname,
27
- testMatch: ['<rootDir>__tests__/**/**.spec.[jt]s?(x)'],
28
- testPathIgnorePatterns: ['/node_modules/', '/dev/'],
27
+ testMatch: ['<rootDir>/__tests__/**/*.spec.[jt]s?(x)'],
28
+ testPathIgnorePatterns: ['/node_modules/'],
29
29
  };