@module-federation/data-prefetch 1.0.16 → 2.0.1

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 (98) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +3 -1
  3. package/dist/LICENSE +21 -0
  4. package/dist/babel.cjs +95 -0
  5. package/dist/babel.d.ts +1 -0
  6. package/dist/babel.js +5 -0
  7. package/dist/cli/babel.cjs +115 -0
  8. package/dist/cli/babel.d.ts +2 -4
  9. package/dist/cli/babel.js +50 -82
  10. package/dist/cli/index.cjs +217 -0
  11. package/dist/cli/index.d.ts +5 -8
  12. package/dist/cli/index.js +150 -197
  13. package/dist/cli.cjs +95 -0
  14. package/dist/cli.d.ts +1 -0
  15. package/dist/cli.js +5 -0
  16. package/dist/common/constant.cjs +51 -0
  17. package/dist/common/constant.d.ts +1 -0
  18. package/dist/common/constant.js +5 -0
  19. package/dist/common/index.cjs +95 -0
  20. package/dist/common/index.js +5 -0
  21. package/dist/common/node-utils.cjs +100 -0
  22. package/dist/common/node-utils.d.ts +2 -0
  23. package/dist/common/node-utils.js +35 -0
  24. package/dist/common/runtime-utils.cjs +84 -0
  25. package/dist/common/runtime-utils.d.ts +5 -0
  26. package/dist/common/runtime-utils.js +29 -0
  27. package/dist/constant.cjs +51 -0
  28. package/dist/constant.d.ts +1 -0
  29. package/dist/constant.js +5 -0
  30. package/dist/index.cjs +106 -0
  31. package/dist/index.d.ts +2 -5
  32. package/dist/index.js +3 -346
  33. package/dist/logger/index.cjs +60 -0
  34. package/dist/logger/index.d.ts +2 -0
  35. package/dist/logger/index.js +10 -0
  36. package/dist/plugin.cjs +234 -0
  37. package/dist/plugin.d.ts +3 -5
  38. package/dist/plugin.js +167 -340
  39. package/dist/prefetch.cjs +197 -0
  40. package/dist/{prefetch-4e9646e4.d.ts → prefetch.d.ts} +14 -17
  41. package/dist/prefetch.js +149 -0
  42. package/dist/react/hooks.cjs +144 -0
  43. package/dist/react/hooks.d.ts +11 -0
  44. package/dist/react/hooks.js +86 -0
  45. package/dist/react/index.cjs +95 -0
  46. package/dist/react/index.d.ts +1 -16
  47. package/dist/react/index.js +2 -283
  48. package/dist/react/utils.cjs +65 -0
  49. package/dist/react/utils.d.ts +1 -0
  50. package/dist/react/utils.js +15 -0
  51. package/dist/react.cjs +95 -0
  52. package/dist/react.d.ts +1 -0
  53. package/dist/react.js +5 -0
  54. package/dist/universal/index.cjs +81 -0
  55. package/dist/universal/index.d.ts +2 -8
  56. package/dist/universal/index.js +24 -196
  57. package/dist/universal.cjs +95 -0
  58. package/dist/universal.d.ts +1 -0
  59. package/dist/universal.js +5 -0
  60. package/package.json +76 -40
  61. package/CHANGELOG.md +0 -9
  62. package/__tests__/babel.spec.ts +0 -75
  63. package/__tests__/prefetch.spec.ts +0 -138
  64. package/__tests__/react.spec.ts +0 -119
  65. package/dist/esm/chunk-AJPO2B2T.js +0 -30
  66. package/dist/esm/chunk-EZUCZHGV.js +0 -11
  67. package/dist/esm/chunk-ISLXMAIA.js +0 -155
  68. package/dist/esm/chunk-KI4QGPIS.js +0 -32
  69. package/dist/esm/chunk-TTJJJ2WZ.js +0 -7
  70. package/dist/esm/chunk-VVZ6XIM6.js +0 -166
  71. package/dist/esm/cli/babel.js +0 -57
  72. package/dist/esm/cli/index.js +0 -178
  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/shared/index.d.ts +0 -5
  79. package/dist/shared/index.js +0 -48
  80. package/jest.config.js +0 -29
  81. package/project.json +0 -21
  82. package/src/cli/babel.ts +0 -94
  83. package/src/cli/index.ts +0 -171
  84. package/src/common/constant.ts +0 -1
  85. package/src/common/node-utils.ts +0 -24
  86. package/src/common/runtime-utils.ts +0 -34
  87. package/src/index.ts +0 -2
  88. package/src/logger/index.ts +0 -3
  89. package/src/plugin.ts +0 -191
  90. package/src/prefetch.ts +0 -207
  91. package/src/react/hooks.ts +0 -95
  92. package/src/react/index.ts +0 -1
  93. package/src/react/utils.ts +0 -11
  94. package/src/shared/index.ts +0 -26
  95. package/src/universal/index.ts +0 -27
  96. package/tsconfig.json +0 -27
  97. package/tsup.config.ts +0 -35
  98. /package/{src/common/index.ts → dist/common/index.d.ts} +0 -0
@@ -1,204 +1,32 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ import { MFDataPrefetch } from "../prefetch.js";
2
+ import { getScope } from "../common/runtime-utils.js";
19
3
 
20
- // src/universal/index.ts
21
- var universal_exports = {};
22
- __export(universal_exports, {
23
- prefetch: () => prefetch
24
- });
25
- module.exports = __toCommonJS(universal_exports);
4
+ ;// CONCATENATED MODULE: external "../prefetch.js"
26
5
 
27
- // src/prefetch.ts
28
- var import_runtime2 = require("@module-federation/runtime");
29
- var import_sdk2 = require("@module-federation/sdk");
6
+ ;// CONCATENATED MODULE: external "../common/runtime-utils.js"
30
7
 
31
- // src/common/runtime-utils.ts
32
- var import_runtime = require("@module-federation/runtime");
33
- var import_sdk = require("@module-federation/sdk");
34
- var getScope = () => {
35
- return (0, import_runtime.getInstance)().options.name;
36
- };
37
- var getPrefetchId = (id) => (0, import_sdk.encodeName)(`${id}/${import_sdk.MFPrefetchCommon.identifier}`);
38
- var compatGetPrefetchId = (id) => (0, import_sdk.encodeName)(`${id}/VmokPrefetch`);
8
+ ;// CONCATENATED MODULE: ./src/universal/index.ts
39
9
 
40
- // src/prefetch.ts
41
- globalThis.__FEDERATION__ ?? (globalThis.__FEDERATION__ = {});
42
- var _a;
43
- (_a = globalThis.__FEDERATION__).__PREFETCH__ ?? (_a.__PREFETCH__ = {
44
- entryLoading: {},
45
- instance: /* @__PURE__ */ new Map(),
46
- __PREFETCH_EXPORTS__: {}
47
- });
48
- var MFDataPrefetch = class {
49
- constructor(options) {
50
- this.prefetchMemory = /* @__PURE__ */ new Map();
51
- this.recordOutdate = {};
52
- this._exports = {};
53
- this._options = options;
54
- this.global.instance.set(options.name, this);
55
- }
56
- get global() {
57
- return globalThis.__FEDERATION__.__PREFETCH__;
58
- }
59
- static getInstance(id) {
60
- return globalThis.__FEDERATION__.__PREFETCH__.instance.get(id);
61
- }
62
- async loadEntry(entry) {
63
- const { name, remoteSnapshot, remote, origin } = this._options;
64
- if (entry) {
65
- const { buildVersion, globalName } = remoteSnapshot;
66
- const uniqueKey = globalName || `${name}:${buildVersion}`;
67
- if (!this.global.entryLoading[uniqueKey]) {
68
- this.global.entryLoading[uniqueKey] = (0, import_sdk2.loadScript)(entry, {});
69
- }
70
- return this.global.entryLoading[uniqueKey];
71
- } else {
72
- const remoteInfo = (0, import_runtime2.getRemoteInfo)(remote);
73
- const module2 = origin.moduleCache.get(remoteInfo.name);
74
- return (0, import_runtime2.getRemoteEntry)({
75
- origin,
76
- remoteInfo,
77
- remoteEntryExports: module2 ? module2.remoteEntryExports : void 0
78
- });
79
- }
80
- }
81
- getProjectExports() {
82
- var _a2;
83
- if (Object.keys(this._exports).length > 0) {
84
- return this._exports;
85
- }
86
- const { name } = this._options;
87
- const exportsPromise = (_a2 = globalThis.__FEDERATION__.__PREFETCH__.__PREFETCH_EXPORTS__) == null ? void 0 : _a2[name];
88
- const resolve = exportsPromise.then(
89
- (exports = {}) => {
90
- const memory = {};
91
- Object.keys(exports).forEach((key) => {
92
- memory[key] = {};
93
- const exportVal = exports[key];
94
- Object.keys(exportVal).reduce(
95
- (memo, current) => {
96
- if (current.toLocaleLowerCase().endsWith("prefetch") || current.toLocaleLowerCase() === "default") {
97
- memo[current] = exportVal[current];
98
- }
99
- return memo;
100
- },
101
- memory[key]
102
- );
103
- });
104
- this.memorizeExports(memory);
105
- }
106
- );
107
- return resolve;
108
- }
109
- memorizeExports(exports) {
110
- this._exports = exports;
111
- }
112
- getExposeExports(id) {
113
- const prefetchId = getPrefetchId(id);
114
- const compatId = compatGetPrefetchId(id);
115
- const prefetchExports = this._exports[prefetchId] || this._exports[compatId];
116
- return prefetchExports || {};
117
- }
118
- prefetch(prefetchOptions) {
119
- const { id, functionId = "default", refetchParams } = prefetchOptions;
120
- let prefetchResult;
121
- const prefetchId = getPrefetchId(id);
122
- const compatId = compatGetPrefetchId(id);
123
- const memorizeId = id + functionId;
124
- const memory = this.prefetchMemory.get(memorizeId);
125
- if (!this.checkOutdate(prefetchOptions) && memory) {
126
- return memory;
127
- }
128
- const prefetchExports = this._exports[prefetchId] || this._exports[compatId];
129
- if (!prefetchExports) {
130
- return;
131
- }
132
- const executePrefetch = prefetchExports[functionId];
133
- if (typeof executePrefetch === "function") {
134
- if (refetchParams) {
135
- prefetchResult = executePrefetch(refetchParams);
136
- } else {
137
- prefetchResult = executePrefetch();
138
- }
139
- } else {
140
- throw new Error(
141
- `[Module Federation Data Prefetch]: No prefetch function called ${functionId} export in prefetch file`
142
- );
143
- }
144
- this.memorize(memorizeId, prefetchResult);
145
- return prefetchResult;
146
- }
147
- memorize(id, value) {
148
- this.prefetchMemory.set(id, value);
149
- }
150
- markOutdate(markOptions, isOutdate) {
151
- const { id, functionId = "default" } = markOptions;
152
- if (!this.recordOutdate[id]) {
153
- this.recordOutdate[id] = {};
154
- }
155
- this.recordOutdate[id][functionId] = isOutdate;
156
- }
157
- checkOutdate(outdateOptions) {
158
- const { id, functionId = "default", cacheStrategy } = outdateOptions;
159
- if (typeof cacheStrategy === "function") {
160
- return cacheStrategy();
161
- }
162
- if (!this.recordOutdate[id]) {
163
- this.recordOutdate[id] = {};
164
- }
165
- if (this.recordOutdate[id][functionId]) {
166
- this.markOutdate(
167
- {
168
- id,
169
- functionId
170
- },
171
- false
172
- );
173
- return true;
174
- } else {
175
- return false;
176
- }
177
- }
178
- };
179
10
 
180
- // src/universal/index.ts
181
11
  function prefetch(options) {
182
- const { id, functionId = "default" } = options;
183
- const mfScope = getScope();
184
- const prefetchInstance = MFDataPrefetch.getInstance(mfScope) || new MFDataPrefetch({
185
- name: mfScope
186
- });
187
- const res = prefetchInstance.getProjectExports();
188
- if (res instanceof Promise) {
189
- const promise = res.then(() => {
190
- const result = prefetchInstance.prefetch(options);
191
- prefetchInstance.memorize(id + functionId, result);
192
- return result;
12
+ const { id, functionId = 'default' } = options;
13
+ const mfScope = getScope();
14
+ const prefetchInstance = MFDataPrefetch.getInstance(mfScope) || new MFDataPrefetch({
15
+ name: mfScope
193
16
  });
194
- return promise;
195
- } else {
196
- const result = prefetchInstance.prefetch(options);
197
- prefetchInstance.memorize(id + functionId, result);
198
- return result;
199
- }
17
+ const res = prefetchInstance.getProjectExports();
18
+ if (res instanceof Promise) {
19
+ const promise = res.then(()=>{
20
+ const result = prefetchInstance.prefetch(options);
21
+ prefetchInstance.memorize(id + functionId, result);
22
+ return result;
23
+ });
24
+ return promise;
25
+ } else {
26
+ const result = prefetchInstance.prefetch(options);
27
+ prefetchInstance.memorize(id + functionId, result);
28
+ return result;
29
+ }
200
30
  }
201
- // Annotate the CommonJS export names for ESM import in node:
202
- 0 && (module.exports = {
203
- prefetch
204
- });
31
+
32
+ export { prefetch };
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ const __rslib_import_meta_url__ = /*#__PURE__*/ (function () {
3
+ return typeof document === 'undefined'
4
+ ? new (require('url'.replace('', '')).URL)('file:' + __filename).href
5
+ : (document.currentScript && document.currentScript.src) ||
6
+ new URL('main.js', document.baseURI).href;
7
+ })();
8
+ ;
9
+ var __webpack_modules__ = ({
10
+ "./universal/index": (function (module) {
11
+ module.exports = require("./universal/index.cjs");
12
+
13
+ }),
14
+
15
+ });
16
+ /************************************************************************/
17
+ // The module cache
18
+ var __webpack_module_cache__ = {};
19
+
20
+ // The require function
21
+ function __webpack_require__(moduleId) {
22
+
23
+ // Check if module is in cache
24
+ var cachedModule = __webpack_module_cache__[moduleId];
25
+ if (cachedModule !== undefined) {
26
+ return cachedModule.exports;
27
+ }
28
+ // Create a new module (and put it into the cache)
29
+ var module = (__webpack_module_cache__[moduleId] = {
30
+ exports: {}
31
+ });
32
+ // Execute the module function
33
+ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
34
+
35
+ // Return the exports of the module
36
+ return module.exports;
37
+
38
+ }
39
+
40
+ /************************************************************************/
41
+ // webpack/runtime/compat_get_default_export
42
+ (() => {
43
+ // getDefaultExport function for compatibility with non-ESM modules
44
+ __webpack_require__.n = (module) => {
45
+ var getter = module && module.__esModule ?
46
+ () => (module['default']) :
47
+ () => (module);
48
+ __webpack_require__.d(getter, { a: getter });
49
+ return getter;
50
+ };
51
+
52
+ })();
53
+ // webpack/runtime/define_property_getters
54
+ (() => {
55
+ __webpack_require__.d = (exports, definition) => {
56
+ for(var key in definition) {
57
+ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
58
+ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
59
+ }
60
+ }
61
+ };
62
+ })();
63
+ // webpack/runtime/has_own_property
64
+ (() => {
65
+ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
66
+ })();
67
+ // webpack/runtime/make_namespace_object
68
+ (() => {
69
+ // define __esModule on exports
70
+ __webpack_require__.r = (exports) => {
71
+ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
72
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
73
+ }
74
+ Object.defineProperty(exports, '__esModule', { value: true });
75
+ };
76
+ })();
77
+ /************************************************************************/
78
+ var __webpack_exports__ = {};
79
+ // This entry needs to be wrapped in an IIFE because it needs to be isolated against other modules in the chunk.
80
+ (() => {
81
+ __webpack_require__.r(__webpack_exports__);
82
+ /* ESM import */var _universal_index__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./universal/index");
83
+ /* ESM import */var _universal_index__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_universal_index__WEBPACK_IMPORTED_MODULE_0__);
84
+
85
+ /* ESM reexport (unknown) */ var __WEBPACK_REEXPORT_OBJECT__ = {};
86
+ /* ESM reexport (unknown) */ for( var __WEBPACK_IMPORT_KEY__ in _universal_index__WEBPACK_IMPORTED_MODULE_0__) if(__WEBPACK_IMPORT_KEY__ !== "default") __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] =function(key) { return _universal_index__WEBPACK_IMPORTED_MODULE_0__[key]; }.bind(0, __WEBPACK_IMPORT_KEY__)
87
+ /* ESM reexport (unknown) */ __webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
88
+
89
+
90
+ })();
91
+
92
+ for(var __webpack_i__ in __webpack_exports__) {
93
+ exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
94
+ }
95
+ Object.defineProperty(exports, '__esModule', { value: true });
@@ -0,0 +1 @@
1
+ export * from './universal/index';
@@ -0,0 +1,5 @@
1
+ export * from "./universal/index.js";
2
+
3
+ ;// CONCATENATED MODULE: ./src/universal.ts
4
+
5
+
package/package.json CHANGED
@@ -1,43 +1,74 @@
1
1
  {
2
2
  "name": "@module-federation/data-prefetch",
3
3
  "description": "Module Federation Data Prefetch",
4
- "version": "1.0.16",
4
+ "version": "2.0.1",
5
+ "type": "module",
5
6
  "author": "nieyan <nyqykk@foxmail.com>",
6
7
  "homepage": "https://github.com/module-federation/core",
7
8
  "license": "MIT",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/module-federation/core.git",
12
+ "directory": "packages/data-prefetch"
13
+ },
8
14
  "publishConfig": {
9
15
  "access": "public"
10
16
  },
17
+ "files": [
18
+ "dist",
19
+ "README.md",
20
+ "LICENSE"
21
+ ],
11
22
  "exports": {
12
23
  ".": {
13
- "import": "./dist/esm/index.js",
14
- "require": "./dist/index.js",
15
- "types": "./dist/index.d.ts"
24
+ "import": {
25
+ "types": "./dist/index.d.ts",
26
+ "default": "./dist/index.js"
27
+ },
28
+ "require": {
29
+ "types": "./dist/index.d.ts",
30
+ "default": "./dist/index.cjs"
31
+ }
16
32
  },
17
33
  "./react": {
18
- "import": "./dist/esm/react/index.js",
19
- "require": "./dist/react/index.js",
20
- "types": "./dist/react/index.d.ts"
34
+ "import": {
35
+ "types": "./dist/react.d.ts",
36
+ "default": "./dist/react.js"
37
+ },
38
+ "require": {
39
+ "types": "./dist/react.d.ts",
40
+ "default": "./dist/react.cjs"
41
+ }
21
42
  },
22
43
  "./cli": {
23
- "import": "./dist/esm/cli/index.js",
24
- "require": "./dist/cli/index.js",
25
- "types": "./dist/cli/index.d.ts"
44
+ "import": {
45
+ "types": "./dist/cli.d.ts",
46
+ "default": "./dist/cli.js"
47
+ },
48
+ "require": {
49
+ "types": "./dist/cli.d.ts",
50
+ "default": "./dist/cli.cjs"
51
+ }
26
52
  },
27
53
  "./babel-plugin": {
28
- "import": "./dist/esm/cli/babel.js",
29
- "require": "./dist/cli/babel.js",
30
- "types": "./dist/cli/babel.d.ts"
54
+ "import": {
55
+ "types": "./dist/babel.d.ts",
56
+ "default": "./dist/babel.js"
57
+ },
58
+ "require": {
59
+ "types": "./dist/babel.d.ts",
60
+ "default": "./dist/babel.cjs"
61
+ }
31
62
  },
32
63
  "./universal": {
33
- "import": "./dist/esm/universal/index.js",
34
- "require": "./dist/universal/index.js",
35
- "types": "./dist/universal/index.d.ts"
36
- },
37
- "./shared": {
38
- "import": "./dist/esm/shared/index.js",
39
- "require": "./dist/shared/index.js",
40
- "types": "./dist/shared/index.d.ts"
64
+ "import": {
65
+ "types": "./dist/universal.d.ts",
66
+ "default": "./dist/universal.js"
67
+ },
68
+ "require": {
69
+ "types": "./dist/universal.d.ts",
70
+ "default": "./dist/universal.cjs"
71
+ }
41
72
  }
42
73
  },
43
74
  "typesVersions": {
@@ -46,51 +77,56 @@
46
77
  "./dist/index.d.ts"
47
78
  ],
48
79
  "react": [
49
- "./dist/react/index.d.ts"
80
+ "./dist/react.d.ts"
50
81
  ],
51
82
  "cli": [
52
- "./dist/cli/index.d.ts"
83
+ "./dist/cli.d.ts"
53
84
  ],
54
85
  "universal": [
55
- "./dist/universal/index.d.ts"
86
+ "./dist/universal.d.ts"
56
87
  ],
57
- "shared": [
58
- "./dist/shared/index.d.ts"
88
+ "babel-plugin": [
89
+ "./dist/babel.d.ts"
59
90
  ]
60
91
  }
61
92
  },
62
- "main": "dist/index.js",
63
- "module": "dist/esm/index.js",
93
+ "main": "./dist/index.cjs",
94
+ "types": "./dist/index.d.ts",
95
+ "module": "./dist/index.js",
64
96
  "peerDependencies": {
65
97
  "react": ">=16.9.0",
66
98
  "react-dom": ">=16.9.0"
67
99
  },
100
+ "peerDependenciesMeta": {
101
+ "react": {
102
+ "optional": true
103
+ },
104
+ "react-dom": {
105
+ "optional": true
106
+ }
107
+ },
68
108
  "devDependencies": {
69
109
  "@testing-library/react-hooks": "^8.0.1",
70
- "@types/fs-extra": "9.0.6",
110
+ "@types/fs-extra": "9.0.13",
71
111
  "@types/jest": "^29.5.11",
72
- "@types/node": "^17.0.45",
112
+ "@types/node": "^20.19.5",
73
113
  "@types/react": "~18.0.38",
74
- "esbuild-plugin-replace": "^1.4.0",
75
114
  "jest": "^29.7.0",
76
115
  "jest-environment-jsdom": "^29.7.0",
77
116
  "minimist": "^1.2.8",
78
- "react": "^18.2.0",
79
- "react-dom": "^18.2.0",
80
- "react-router": "^6.21.3",
117
+ "react": "^18.3.1",
118
+ "react-dom": "^18.3.1",
119
+ "react-router": "^6.30.2",
81
120
  "react-test-renderer": "^18.2.0",
82
121
  "ts-jest": "29.0.1",
83
- "tsup": "6.2.0",
84
- "webpack": "5.75.0"
122
+ "webpack": "5.104.1"
85
123
  },
86
124
  "dependencies": {
87
125
  "fs-extra": "9.1.0",
88
- "@module-federation/sdk": "0.6.5",
89
- "@module-federation/runtime": "0.6.5"
126
+ "@module-federation/runtime": "2.0.1",
127
+ "@module-federation/sdk": "2.0.1"
90
128
  },
91
129
  "scripts": {
92
- "dev": "cross-env WATCH=true tsup",
93
- "build": "rm -rf dist && tsup",
94
130
  "test": "jest"
95
131
  }
96
132
  }
package/CHANGELOG.md DELETED
@@ -1,9 +0,0 @@
1
- @module-federation/data-prefetch
2
-
3
- ## 1.0.16
4
-
5
- ### Patch Changes
6
-
7
- - 3070e26: feat(@module-federation/data-prefetch): support data prefetch in Module Federation
8
- - @module-federation/runtime@0.6.5
9
- - @module-federation/sdk@0.6.5
@@ -1,75 +0,0 @@
1
- /// <reference types="jest" />
2
-
3
- import path from 'path';
4
- import fs from 'fs';
5
- import { BabelFileResult, transformFileSync } from '@babel/core';
6
- // @ts-ignore no use
7
- import type from '@types/jest';
8
-
9
- import babelPlugin from '../src/cli/babel';
10
-
11
- const emptyRegexp = /\s+/g;
12
- describe('Babel Plugin Test', () => {
13
- const options = {
14
- name: '@mf/test',
15
- exposes: { './expose': path.resolve(__dirname, 'test') },
16
- };
17
-
18
- const testFilePath = path.join(__dirname, './test');
19
-
20
- beforeEach(() => {
21
- fs.mkdirSync(path.dirname(testFilePath), { recursive: true });
22
- fs.closeSync(fs.openSync(testFilePath, 'w'));
23
- });
24
-
25
- afterEach(() => {
26
- fs.unlinkSync(testFilePath);
27
- });
28
-
29
- // Check if the plugin will add the id parameter when it is not present
30
- test('it adds id argument to usePrefetch call when it is absent', () => {
31
- const input = `
32
- import { usePrefetch } from "@module-federation/data-prefetch/react";
33
- usePrefetch({});
34
- `;
35
-
36
- const expected = `
37
- import { usePrefetch } from "@module-federation/data-prefetch/react";
38
- usePrefetch({ id: "@mf/test/expose" });
39
- `;
40
-
41
- fs.writeFileSync(testFilePath, input);
42
- const { code } = transformFileSync(testFilePath, {
43
- plugins: [[babelPlugin, options]],
44
- configFile: false,
45
- }) as BabelFileResult;
46
-
47
- expect(code?.replace(emptyRegexp, '')).toBe(
48
- expected.replace(emptyRegexp, ''),
49
- );
50
- });
51
-
52
- // The plugin should retain the existing id parameter in the usePrefetch call
53
- test('it does not overwrite existing id argument in usePrefetch call', () => {
54
- const input = `
55
- import { usePrefetch } from "@module-federation/data-prefetch/react";
56
- usePrefetch({ id: "existingId" });
57
- `;
58
-
59
- const expected = `
60
- import { usePrefetch } from "@module-federation/data-prefetch/react";
61
- usePrefetch({ id: "existingId" });
62
- `;
63
-
64
- fs.writeFileSync(testFilePath, input);
65
- const { code } = transformFileSync(testFilePath, {
66
- plugins: [[babelPlugin, options]],
67
- configFile: false,
68
- babelrc: false,
69
- }) as BabelFileResult;
70
-
71
- expect(code?.replace(emptyRegexp, '')).toBe(
72
- expected.replace(emptyRegexp, ''),
73
- );
74
- });
75
- });