@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
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2020 ScriptedAlchemy LLC (Zack Jackson) Zhou Shaw (zhouxiao)
3
+ Copyright (c) 2024-present nieyan(nyqykk)
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1 +1,3 @@
1
- Module Federation Data Prefetch(https://module-federation.io/zh/guide/performance/prefetch.html)
1
+ # @module-federation/data-prefetch
2
+
3
+ See [documentation](https://module-federation.io/zh/guide/performance/prefetch.html) for more details .
package/dist/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-present nieyan(nyqykk)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/babel.cjs ADDED
@@ -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
+ "./cli/babel": (function (module) {
11
+ module.exports = require("./cli/babel.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 _cli_babel__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./cli/babel");
83
+ /* ESM import */var _cli_babel__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_cli_babel__WEBPACK_IMPORTED_MODULE_0__);
84
+
85
+ /* ESM reexport (unknown) */ var __WEBPACK_REEXPORT_OBJECT__ = {};
86
+ /* ESM reexport (unknown) */ for( var __WEBPACK_IMPORT_KEY__ in _cli_babel__WEBPACK_IMPORTED_MODULE_0__) if(__WEBPACK_IMPORT_KEY__ !== "default") __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] =function(key) { return _cli_babel__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 './cli/babel';
package/dist/babel.js ADDED
@@ -0,0 +1,5 @@
1
+ export * from "./cli/babel.js";
2
+
3
+ ;// CONCATENATED MODULE: ./src/babel.ts
4
+
5
+
@@ -0,0 +1,115 @@
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
+ // The require scope
10
+ var __webpack_require__ = {};
11
+
12
+ /************************************************************************/
13
+ // webpack/runtime/compat_get_default_export
14
+ (() => {
15
+ // getDefaultExport function for compatibility with non-ESM modules
16
+ __webpack_require__.n = (module) => {
17
+ var getter = module && module.__esModule ?
18
+ () => (module['default']) :
19
+ () => (module);
20
+ __webpack_require__.d(getter, { a: getter });
21
+ return getter;
22
+ };
23
+
24
+ })();
25
+ // webpack/runtime/define_property_getters
26
+ (() => {
27
+ __webpack_require__.d = (exports, definition) => {
28
+ for(var key in definition) {
29
+ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
30
+ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
31
+ }
32
+ }
33
+ };
34
+ })();
35
+ // webpack/runtime/has_own_property
36
+ (() => {
37
+ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
38
+ })();
39
+ // webpack/runtime/make_namespace_object
40
+ (() => {
41
+ // define __esModule on exports
42
+ __webpack_require__.r = (exports) => {
43
+ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
44
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
45
+ }
46
+ Object.defineProperty(exports, '__esModule', { value: true });
47
+ };
48
+ })();
49
+ /************************************************************************/
50
+ var __webpack_exports__ = {};
51
+ // ESM COMPAT FLAG
52
+ __webpack_require__.r(__webpack_exports__);
53
+
54
+ // EXPORTS
55
+ __webpack_require__.d(__webpack_exports__, {
56
+ "default": () => (/* binding */ cli_babel)
57
+ });
58
+
59
+ ;// CONCATENATED MODULE: external "path"
60
+ const external_path_namespaceObject = require("path");
61
+ var external_path_default = /*#__PURE__*/__webpack_require__.n(external_path_namespaceObject);
62
+ ;// CONCATENATED MODULE: ./src/cli/babel.ts
63
+ // no used now
64
+
65
+ const attribute = 'id';
66
+ const hookId = 'usePrefetch';
67
+ const importPackage = '@module-federation/data-prefetch/react';
68
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
69
+ /* ESM default export */ const cli_babel = (((babel, options)=>{
70
+ const t = babel.types;
71
+ let shouldHandle = false;
72
+ let scope = '';
73
+ const { name, exposes } = options;
74
+ if (!exposes) {
75
+ return {};
76
+ }
77
+ const exposesKey = Object.keys(exposes);
78
+ const processedExposes = exposesKey.map((expose)=>({
79
+ key: expose.replace('.', ''),
80
+ value: external_path_default().resolve(// @ts-ignore
81
+ typeof exposes[expose] === 'string' ? exposes[expose] : exposes[expose].import)
82
+ }));
83
+ return {
84
+ visitor: {
85
+ ImportDeclaration (nodePath, // biome-ignore lint/suspicious/noExplicitAny: <explanation>
86
+ state) {
87
+ const source = nodePath.node.source.value;
88
+ const { specifiers } = nodePath.node;
89
+ const { filename } = state.file.opts;
90
+ if (source === importPackage) {
91
+ shouldHandle = specifiers.some((specifier)=>specifier.imported && specifier.imported.name === hookId && processedExposes.find(// biome-ignore lint/suspicious/noAssignInExpressions: <explanation>
92
+ (expose)=>expose.value === filename && (scope = expose.key)));
93
+ }
94
+ },
95
+ CallExpression (nodePath) {
96
+ if (shouldHandle && t.isIdentifier(nodePath.node.callee, {
97
+ name: hookId
98
+ }) && nodePath.node.arguments.length > 0) {
99
+ const objectExpression = nodePath.node.arguments[0];
100
+ if (objectExpression && t.isObjectExpression(objectExpression) && !objectExpression.properties.find((p)=>p.key.name === attribute)) {
101
+ objectExpression.properties.push(t.objectProperty(t.identifier(attribute), t.stringLiteral(name + scope)));
102
+ }
103
+ }
104
+ }
105
+ }
106
+ };
107
+ }));
108
+
109
+ exports["default"] = __webpack_exports__["default"];
110
+ for(var __webpack_i__ in __webpack_exports__) {
111
+ if(["default"].indexOf(__webpack_i__) === -1) {
112
+ exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
113
+ }
114
+ }
115
+ Object.defineProperty(exports, '__esModule', { value: true });
@@ -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;
package/dist/cli/babel.js CHANGED
@@ -1,84 +1,52 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
- mod
23
- ));
24
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ import path from "path";
25
2
 
26
- // src/cli/babel.ts
27
- var babel_exports = {};
28
- __export(babel_exports, {
29
- default: () => babel_default
30
- });
31
- module.exports = __toCommonJS(babel_exports);
32
- var import_path = __toESM(require("path"));
33
- var attribute = "id";
34
- var hookId = "usePrefetch";
35
- var importPackage = "@module-federation/data-prefetch/react";
36
- var babel_default = (babel, options) => {
37
- const t = babel.types;
38
- let shouldHandle = false;
39
- let scope = "";
40
- const { name, exposes } = options;
41
- if (!exposes) {
42
- return {};
43
- }
44
- const exposesKey = Object.keys(exposes);
45
- const processedExposes = exposesKey.map((expose) => ({
46
- key: expose.replace(".", ""),
47
- value: import_path.default.resolve(
48
- typeof exposes[expose] === "string" ? exposes[expose] : exposes[expose].import
49
- )
50
- }));
51
- return {
52
- visitor: {
53
- ImportDeclaration(nodePath, state) {
54
- const source = nodePath.node.source.value;
55
- const { specifiers } = nodePath.node;
56
- const { filename } = state.file.opts;
57
- if (source === importPackage) {
58
- shouldHandle = specifiers.some(
59
- (specifier) => specifier.imported && specifier.imported.name === hookId && processedExposes.find(
60
- (expose) => expose.value === filename && (scope = expose.key)
61
- )
62
- );
63
- }
64
- },
65
- CallExpression(nodePath) {
66
- if (shouldHandle && t.isIdentifier(nodePath.node.callee, { name: hookId }) && nodePath.node.arguments.length > 0) {
67
- const objectExpression = nodePath.node.arguments[0];
68
- if (objectExpression && t.isObjectExpression(objectExpression) && !objectExpression.properties.find(
69
- (p) => p.key.name === attribute
70
- )) {
71
- objectExpression.properties.push(
72
- t.objectProperty(
73
- t.identifier(attribute),
74
- t.stringLiteral(name + scope)
75
- )
76
- );
77
- }
78
- }
79
- }
3
+ ;// CONCATENATED MODULE: external "path"
4
+
5
+ ;// CONCATENATED MODULE: ./src/cli/babel.ts
6
+ // no used now
7
+
8
+ const attribute = 'id';
9
+ const hookId = 'usePrefetch';
10
+ const importPackage = '@module-federation/data-prefetch/react';
11
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
12
+ /* ESM default export */ const cli_babel = (((babel, options)=>{
13
+ const t = babel.types;
14
+ let shouldHandle = false;
15
+ let scope = '';
16
+ const { name, exposes } = options;
17
+ if (!exposes) {
18
+ return {};
80
19
  }
81
- };
82
- };
83
- // Annotate the CommonJS export names for ESM import in node:
84
- 0 && (module.exports = {});
20
+ const exposesKey = Object.keys(exposes);
21
+ const processedExposes = exposesKey.map((expose)=>({
22
+ key: expose.replace('.', ''),
23
+ value: path.resolve(// @ts-ignore
24
+ typeof exposes[expose] === 'string' ? exposes[expose] : exposes[expose].import)
25
+ }));
26
+ return {
27
+ visitor: {
28
+ ImportDeclaration (nodePath, // biome-ignore lint/suspicious/noExplicitAny: <explanation>
29
+ state) {
30
+ const source = nodePath.node.source.value;
31
+ const { specifiers } = nodePath.node;
32
+ const { filename } = state.file.opts;
33
+ if (source === importPackage) {
34
+ shouldHandle = specifiers.some((specifier)=>specifier.imported && specifier.imported.name === hookId && processedExposes.find(// biome-ignore lint/suspicious/noAssignInExpressions: <explanation>
35
+ (expose)=>expose.value === filename && (scope = expose.key)));
36
+ }
37
+ },
38
+ CallExpression (nodePath) {
39
+ if (shouldHandle && t.isIdentifier(nodePath.node.callee, {
40
+ name: hookId
41
+ }) && nodePath.node.arguments.length > 0) {
42
+ const objectExpression = nodePath.node.arguments[0];
43
+ if (objectExpression && t.isObjectExpression(objectExpression) && !objectExpression.properties.find((p)=>p.key.name === attribute)) {
44
+ objectExpression.properties.push(t.objectProperty(t.identifier(attribute), t.stringLiteral(name + scope)));
45
+ }
46
+ }
47
+ }
48
+ }
49
+ };
50
+ }));
51
+
52
+ export { cli_babel as default };
@@ -0,0 +1,217 @@
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
+ // The require scope
10
+ var __webpack_require__ = {};
11
+
12
+ /************************************************************************/
13
+ // webpack/runtime/compat_get_default_export
14
+ (() => {
15
+ // getDefaultExport function for compatibility with non-ESM modules
16
+ __webpack_require__.n = (module) => {
17
+ var getter = module && module.__esModule ?
18
+ () => (module['default']) :
19
+ () => (module);
20
+ __webpack_require__.d(getter, { a: getter });
21
+ return getter;
22
+ };
23
+
24
+ })();
25
+ // webpack/runtime/define_property_getters
26
+ (() => {
27
+ __webpack_require__.d = (exports, definition) => {
28
+ for(var key in definition) {
29
+ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
30
+ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
31
+ }
32
+ }
33
+ };
34
+ })();
35
+ // webpack/runtime/has_own_property
36
+ (() => {
37
+ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
38
+ })();
39
+ // webpack/runtime/make_namespace_object
40
+ (() => {
41
+ // define __esModule on exports
42
+ __webpack_require__.r = (exports) => {
43
+ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
44
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
45
+ }
46
+ Object.defineProperty(exports, '__esModule', { value: true });
47
+ };
48
+ })();
49
+ /************************************************************************/
50
+ var __webpack_exports__ = {};
51
+ // ESM COMPAT FLAG
52
+ __webpack_require__.r(__webpack_exports__);
53
+
54
+ // EXPORTS
55
+ __webpack_require__.d(__webpack_exports__, {
56
+ PrefetchPlugin: () => (/* binding */ PrefetchPlugin),
57
+ getFederationGlobalScope: () => (/* binding */ getFederationGlobalScope)
58
+ });
59
+
60
+ ;// CONCATENATED MODULE: external "path"
61
+ const external_path_namespaceObject = require("path");
62
+ var external_path_default = /*#__PURE__*/__webpack_require__.n(external_path_namespaceObject);
63
+ ;// CONCATENATED MODULE: external "fs-extra"
64
+ const external_fs_extra_namespaceObject = require("fs-extra");
65
+ var external_fs_extra_default = /*#__PURE__*/__webpack_require__.n(external_fs_extra_namespaceObject);
66
+ ;// CONCATENATED MODULE: external "@module-federation/sdk"
67
+ const sdk_namespaceObject = require("@module-federation/sdk");
68
+ ;// CONCATENATED MODULE: external "@module-federation/sdk/normalize-webpack-path"
69
+ const normalize_webpack_path_namespaceObject = require("@module-federation/sdk/normalize-webpack-path");
70
+ ;// CONCATENATED MODULE: external "../common/constant.cjs"
71
+ const constant_cjs_namespaceObject = require("../common/constant.cjs");
72
+ ;// CONCATENATED MODULE: external "../common/node-utils.cjs"
73
+ const node_utils_cjs_namespaceObject = require("../common/node-utils.cjs");
74
+ ;// CONCATENATED MODULE: external "../common/runtime-utils.cjs"
75
+ const runtime_utils_cjs_namespaceObject = require("../common/runtime-utils.cjs");
76
+ ;// CONCATENATED MODULE: external "../constant.cjs"
77
+ const external_constant_cjs_namespaceObject = require("../constant.cjs");
78
+ ;// CONCATENATED MODULE: ./src/cli/index.ts
79
+
80
+
81
+
82
+
83
+
84
+
85
+
86
+
87
+ const { RuntimeGlobals, Template } = require((0,normalize_webpack_path_namespaceObject.normalizeWebpackPath)('webpack'));
88
+ const createBundlerLogger = typeof sdk_namespaceObject.createInfrastructureLogger === 'function' ? sdk_namespaceObject.createInfrastructureLogger : sdk_namespaceObject.createLogger;
89
+ const logger = createBundlerLogger('[ Module Federation Data Prefetch Plugin ]');
90
+ function getFederationGlobalScope(runtimeGlobals) {
91
+ return `${runtimeGlobals.require || '__webpack_require__'}.federation`;
92
+ }
93
+ class PrefetchPlugin {
94
+ // eslint-disable-next-line max-lines-per-function
95
+ apply(compiler) {
96
+ var _this_options_runtimePlugins;
97
+ (0,sdk_namespaceObject.bindLoggerToCompiler)(logger, compiler, 'PrefetchPlugin');
98
+ const { name, exposes } = this.options;
99
+ if (!exposes) {
100
+ return;
101
+ }
102
+ if (!compiler.options.context) {
103
+ throw new Error('compiler.options.context is not defined');
104
+ }
105
+ const { runtimePlugins } = this.options;
106
+ if (!Array.isArray(runtimePlugins)) {
107
+ this.options.runtimePlugins = [];
108
+ }
109
+ const runtimePath = external_path_default().resolve(__dirname, './plugin.esm.js');
110
+ if (!((_this_options_runtimePlugins = this.options.runtimePlugins) === null || _this_options_runtimePlugins === void 0 ? void 0 : _this_options_runtimePlugins.includes(runtimePath))) {
111
+ this.options.runtimePlugins.push(runtimePath);
112
+ }
113
+ if (this.options.shareStrategy !== external_constant_cjs_namespaceObject.SHARED_STRATEGY) {
114
+ this.options.shareStrategy = external_constant_cjs_namespaceObject.SHARED_STRATEGY;
115
+ logger.warn(`[Module Federation Data Prefetch]: Your shared strategy is set to '${external_constant_cjs_namespaceObject.SHARED_STRATEGY}', this is a necessary condition for data prefetch`);
116
+ }
117
+ const encodedName = (0,sdk_namespaceObject.encodeName)(name);
118
+ const asyncEntryPath = external_path_default().resolve(compiler.options.context, `node_modules/${constant_cjs_namespaceObject.TEMP_DIR}/${encodedName}/bootstrap.js`);
119
+ if (external_fs_extra_default().existsSync(asyncEntryPath)) {
120
+ external_fs_extra_default().unlinkSync(asyncEntryPath);
121
+ }
122
+ if (!this.options.dataPrefetch) {
123
+ return;
124
+ }
125
+ const prefetchs = [];
126
+ const exposeAlias = Object.keys(exposes);
127
+ exposeAlias.forEach((alias)=>{
128
+ let exposePath;
129
+ // @ts-ignore
130
+ const exposeValue = exposes[alias];
131
+ if (typeof exposeValue === 'string') {
132
+ exposePath = exposeValue;
133
+ } else {
134
+ exposePath = exposeValue.import[0];
135
+ }
136
+ const targetPaths = (0,node_utils_cjs_namespaceObject.fixPrefetchPath)(exposePath);
137
+ for (const pathItem of targetPaths){
138
+ const absolutePath = external_path_default().resolve(compiler.options.context, pathItem);
139
+ if ((0,node_utils_cjs_namespaceObject.fileExistsWithCaseSync)(absolutePath)) {
140
+ prefetchs.push(pathItem);
141
+ const absoluteAlias = alias.replace('.', '');
142
+ this._reWriteExports += `export * as ${(0,runtime_utils_cjs_namespaceObject.getPrefetchId)(`${name}${absoluteAlias}`)} from '${absolutePath}';\n`;
143
+ break;
144
+ }
145
+ }
146
+ });
147
+ if (!this._reWriteExports) {
148
+ return;
149
+ }
150
+ const tempDirRealPath = external_path_default().resolve(compiler.options.context, 'node_modules', constant_cjs_namespaceObject.TEMP_DIR);
151
+ if (!external_fs_extra_default().existsSync(tempDirRealPath)) {
152
+ external_fs_extra_default().mkdirSync(tempDirRealPath);
153
+ }
154
+ if (!external_fs_extra_default().existsSync(`${tempDirRealPath}/${encodedName}`)) {
155
+ external_fs_extra_default().mkdirSync(`${tempDirRealPath}/${encodedName}`);
156
+ }
157
+ external_fs_extra_default().writeFileSync(asyncEntryPath, this._reWriteExports);
158
+ new compiler.webpack.DefinePlugin({
159
+ FederationDataPrefetch: JSON.stringify(asyncEntryPath)
160
+ }).apply(compiler);
161
+ }
162
+ static addRuntime(compiler, options) {
163
+ const encodedName = (0,sdk_namespaceObject.encodeName)(options.name);
164
+ if (!compiler.options.context) {
165
+ throw new Error('compiler.options.context is not defined');
166
+ }
167
+ const prefetchEntry = external_path_default().resolve(compiler.options.context, `node_modules/.mf/${encodedName}/bootstrap.js`);
168
+ const federationGlobal = getFederationGlobalScope(RuntimeGlobals || {});
169
+ return Template.asString([
170
+ external_fs_extra_default().existsSync(prefetchEntry) ? Template.indent([
171
+ 'function injectPrefetch() {',
172
+ Template.indent([
173
+ `globalThis.__FEDERATION__ = globalThis.__FEDERATION__ || {};`,
174
+ `globalThis.__FEDERATION__['${sdk_namespaceObject.MFPrefetchCommon.globalKey}'] = globalThis.__FEDERATION__['${sdk_namespaceObject.MFPrefetchCommon.globalKey}'] || {`,
175
+ `entryLoading: {},`,
176
+ `instance: new Map(),`,
177
+ `__PREFETCH_EXPORTS__: {},`,
178
+ `};`,
179
+ `globalThis.__FEDERATION__['${sdk_namespaceObject.MFPrefetchCommon.globalKey}']['${sdk_namespaceObject.MFPrefetchCommon.exportsKey}'] = globalThis.__FEDERATION__['${sdk_namespaceObject.MFPrefetchCommon.globalKey}']['${sdk_namespaceObject.MFPrefetchCommon.exportsKey}'] || {};`,
180
+ `globalThis.__FEDERATION__['${sdk_namespaceObject.MFPrefetchCommon.globalKey}']['${sdk_namespaceObject.MFPrefetchCommon.exportsKey}']['${options.name}'] = function(){ return import('${prefetchEntry}');}`
181
+ ]),
182
+ '}',
183
+ `${federationGlobal}.prefetch = injectPrefetch`
184
+ ]) : '',
185
+ Template.indent([
186
+ `if(!${federationGlobal}.isMFRemote && ${federationGlobal}.prefetch){`,
187
+ `${federationGlobal}.prefetch()`,
188
+ '}'
189
+ ])
190
+ ]);
191
+ }
192
+ static setRemoteIdentifier() {
193
+ const federationGlobal = getFederationGlobalScope(RuntimeGlobals || {});
194
+ return Template.indent([
195
+ `${federationGlobal}.isMFRemote = true;`
196
+ ]);
197
+ }
198
+ static removeRemoteIdentifier() {
199
+ const federationGlobal = getFederationGlobalScope(RuntimeGlobals || {});
200
+ return Template.indent([
201
+ `${federationGlobal}.isMFRemote = false;`
202
+ ]);
203
+ }
204
+ constructor(options){
205
+ this.options = options;
206
+ this._reWriteExports = '';
207
+ }
208
+ }
209
+
210
+ exports.PrefetchPlugin = __webpack_exports__.PrefetchPlugin;
211
+ exports.getFederationGlobalScope = __webpack_exports__.getFederationGlobalScope;
212
+ for(var __webpack_i__ in __webpack_exports__) {
213
+ if(["PrefetchPlugin","getFederationGlobalScope"].indexOf(__webpack_i__) === -1) {
214
+ exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
215
+ }
216
+ }
217
+ Object.defineProperty(exports, '__esModule', { value: true });
@@ -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 {};