@module-federation/data-prefetch 2.0.0 → 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.
- package/dist/babel.cjs +95 -0
- package/dist/babel.d.ts +1 -2
- package/dist/babel.js +5 -0
- package/dist/cli/babel.cjs +115 -0
- package/dist/cli/babel.js +52 -0
- package/dist/cli/index.cjs +217 -0
- package/dist/{cli.esm.js → cli/index.js} +78 -73
- package/dist/cli.cjs +95 -0
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +5 -0
- package/dist/common/constant.cjs +51 -0
- package/dist/common/constant.js +5 -0
- package/dist/common/index.cjs +95 -0
- package/dist/common/index.js +5 -0
- package/dist/common/node-utils.cjs +100 -0
- package/dist/common/node-utils.js +35 -0
- package/dist/common/runtime-utils.cjs +84 -0
- package/dist/common/runtime-utils.js +29 -0
- package/dist/constant.cjs +51 -0
- package/dist/constant.js +5 -0
- package/dist/index.cjs +106 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +7 -0
- package/dist/logger/index.cjs +60 -0
- package/dist/logger/index.js +10 -0
- package/dist/plugin.cjs +234 -0
- package/dist/plugin.d.ts +3 -2
- package/dist/plugin.js +173 -0
- package/dist/prefetch.cjs +197 -0
- package/dist/prefetch.js +149 -0
- package/dist/react/hooks.cjs +144 -0
- package/dist/{react.esm.js → react/hooks.js} +42 -30
- package/dist/react/index.cjs +95 -0
- package/dist/react/index.js +5 -0
- package/dist/react/utils.cjs +65 -0
- package/dist/react/utils.js +15 -0
- package/dist/react.cjs +95 -0
- package/dist/react.d.ts +1 -1
- package/dist/react.js +5 -0
- package/dist/universal/index.cjs +81 -0
- package/dist/{universal.esm.js → universal/index.js} +14 -10
- package/dist/universal.cjs +95 -0
- package/dist/universal.d.ts +1 -1
- package/dist/universal.js +5 -0
- package/package.json +47 -21
- package/dist/babel.cjs.cjs +0 -54
- package/dist/babel.cjs.cjs.map +0 -1
- package/dist/babel.cjs.d.ts +0 -2
- package/dist/babel.esm.js +0 -52
- package/dist/babel.esm.js.map +0 -1
- package/dist/cli.cjs.cjs +0 -156
- package/dist/cli.cjs.cjs.map +0 -1
- package/dist/cli.cjs.d.ts +0 -1
- package/dist/cli.esm.js.map +0 -1
- package/dist/constant.cjs.cjs +0 -6
- package/dist/constant.cjs.cjs.map +0 -1
- package/dist/constant.esm.js +0 -4
- package/dist/constant.esm.js.map +0 -1
- package/dist/index.cjs.cjs +0 -10
- package/dist/index.cjs.cjs.map +0 -1
- package/dist/index.cjs.d.ts +0 -1
- package/dist/index.cjs2.cjs +0 -8
- package/dist/index.cjs2.cjs.map +0 -1
- package/dist/index.esm.js +0 -3
- package/dist/index.esm.js.map +0 -1
- package/dist/index.esm2.js +0 -6
- package/dist/index.esm2.js.map +0 -1
- package/dist/plugin.cjs.cjs +0 -158
- package/dist/plugin.cjs.cjs.map +0 -1
- package/dist/plugin.cjs.d.ts +0 -2
- package/dist/plugin.esm.js +0 -153
- package/dist/plugin.esm.js.map +0 -1
- package/dist/prefetch.cjs.cjs +0 -182
- package/dist/prefetch.cjs.cjs.map +0 -1
- package/dist/prefetch.esm.js +0 -179
- package/dist/prefetch.esm.js.map +0 -1
- package/dist/react.cjs.cjs +0 -76
- package/dist/react.cjs.cjs.map +0 -1
- package/dist/react.cjs.d.ts +0 -1
- package/dist/react.esm.js.map +0 -1
- package/dist/runtime-utils.cjs.cjs +0 -29
- package/dist/runtime-utils.cjs.cjs.map +0 -1
- package/dist/runtime-utils.esm.js +0 -24
- package/dist/runtime-utils.esm.js.map +0 -1
- package/dist/src/index.d.ts +0 -2
- package/dist/src/plugin.d.ts +0 -3
- package/dist/universal.cjs.cjs +0 -30
- package/dist/universal.cjs.cjs.map +0 -1
- package/dist/universal.cjs.d.ts +0 -1
- package/dist/universal.esm.js.map +0 -1
- /package/dist/{src/cli → cli}/babel.d.ts +0 -0
- /package/dist/{src/cli → cli}/index.d.ts +0 -0
- /package/dist/{src/common → common}/constant.d.ts +0 -0
- /package/dist/{src/common → common}/index.d.ts +0 -0
- /package/dist/{src/common → common}/node-utils.d.ts +0 -0
- /package/dist/{src/common → common}/runtime-utils.d.ts +0 -0
- /package/dist/{src/constant.d.ts → constant.d.ts} +0 -0
- /package/dist/{src/logger → logger}/index.d.ts +0 -0
- /package/dist/{src/prefetch.d.ts → prefetch.d.ts} +0 -0
- /package/dist/{src/react → react}/hooks.d.ts +0 -0
- /package/dist/{src/react → react}/index.d.ts +0 -0
- /package/dist/{src/react → react}/utils.d.ts +0 -0
- /package/dist/{src/universal → universal}/index.d.ts +0 -0
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 });
|
package/dist/babel.d.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export { default } from "./src/cli/babel";
|
|
1
|
+
export * from './cli/babel';
|
package/dist/babel.js
ADDED
|
@@ -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 });
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
|
|
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 {};
|
|
19
|
+
}
|
|
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 });
|