@module-federation/data-prefetch 2.0.0 → 2.1.0
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.cts +1 -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.d.ts +37 -0
- package/dist/cli/babel.js +52 -0
- package/dist/cli/index.cjs +230 -0
- package/dist/cli/index.d.ts +16 -0
- package/dist/cli/index.js +171 -0
- package/dist/cli.cjs +95 -0
- package/dist/cli.d.cts +1 -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.d.ts +1 -0
- package/dist/common/constant.js +5 -0
- package/dist/common/index.cjs +95 -0
- package/dist/common/index.d.ts +1 -0
- package/dist/common/index.js +5 -0
- package/dist/common/node-utils.cjs +100 -0
- package/dist/common/node-utils.d.ts +2 -0
- package/dist/common/node-utils.js +35 -0
- package/dist/common/runtime-utils.cjs +84 -0
- package/dist/common/runtime-utils.d.ts +5 -0
- package/dist/common/runtime-utils.js +29 -0
- package/dist/constant.cjs +51 -0
- package/dist/constant.d.ts +1 -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.d.ts +2 -0
- package/dist/logger/index.js +10 -0
- package/dist/plugin.cjs +234 -0
- package/dist/{src/plugin.d.ts → plugin.d.cts} +1 -1
- package/dist/plugin.d.ts +3 -2
- package/dist/plugin.js +173 -0
- package/dist/prefetch.cjs +197 -0
- package/dist/prefetch.d.ts +42 -0
- package/dist/prefetch.js +149 -0
- package/dist/react/hooks.cjs +144 -0
- package/dist/react/hooks.d.ts +11 -0
- package/dist/{react.esm.js → react/hooks.js} +42 -30
- package/dist/react/index.cjs +95 -0
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.js +5 -0
- package/dist/react/utils.cjs +65 -0
- package/dist/react/utils.d.ts +1 -0
- package/dist/react/utils.js +15 -0
- package/dist/react.cjs +95 -0
- package/dist/react.d.cts +1 -0
- package/dist/react.d.ts +1 -1
- package/dist/react.js +5 -0
- package/dist/universal/index.cjs +81 -0
- package/dist/universal/index.d.ts +2 -0
- package/dist/{universal.esm.js → universal/index.js} +14 -10
- package/dist/universal.cjs +95 -0
- package/dist/universal.d.cts +1 -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 +0 -153
- 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/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/babel.d.ts → cli/babel.d.cts} +0 -0
- /package/dist/{src/cli/index.d.ts → cli/index.d.cts} +0 -0
- /package/dist/{src/common/constant.d.ts → common/constant.d.cts} +0 -0
- /package/dist/{src/common/index.d.ts → common/index.d.cts} +0 -0
- /package/dist/{src/common/node-utils.d.ts → common/node-utils.d.cts} +0 -0
- /package/dist/{src/common/runtime-utils.d.ts → common/runtime-utils.d.cts} +0 -0
- /package/dist/{src/constant.d.ts → constant.d.cts} +0 -0
- /package/dist/{src/index.d.ts → index.d.cts} +0 -0
- /package/dist/{src/logger/index.d.ts → logger/index.d.cts} +0 -0
- /package/dist/{src/prefetch.d.ts → prefetch.d.cts} +0 -0
- /package/dist/{src/react/hooks.d.ts → react/hooks.d.cts} +0 -0
- /package/dist/{src/react/index.d.ts → react/index.d.cts} +0 -0
- /package/dist/{src/react/utils.d.ts → react/utils.d.cts} +0 -0
- /package/dist/{src/universal/index.d.ts → universal/index.d.cts} +0 -0
|
@@ -1,23 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { MFDataPrefetch } from "../prefetch.js";
|
|
2
|
+
import { getScope } from "../common/runtime-utils.js";
|
|
3
|
+
|
|
4
|
+
;// CONCATENATED MODULE: external "../prefetch.js"
|
|
5
|
+
|
|
6
|
+
;// CONCATENATED MODULE: external "../common/runtime-utils.js"
|
|
7
|
+
|
|
8
|
+
;// CONCATENATED MODULE: ./src/universal/index.ts
|
|
9
|
+
|
|
3
10
|
|
|
4
11
|
function prefetch(options) {
|
|
5
12
|
const { id, functionId = 'default' } = options;
|
|
6
13
|
const mfScope = getScope();
|
|
7
|
-
const prefetchInstance = MFDataPrefetch.getInstance(mfScope) ||
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
});
|
|
14
|
+
const prefetchInstance = MFDataPrefetch.getInstance(mfScope) || new MFDataPrefetch({
|
|
15
|
+
name: mfScope
|
|
16
|
+
});
|
|
11
17
|
const res = prefetchInstance.getProjectExports();
|
|
12
18
|
if (res instanceof Promise) {
|
|
13
|
-
const promise = res.then(()
|
|
19
|
+
const promise = res.then(()=>{
|
|
14
20
|
const result = prefetchInstance.prefetch(options);
|
|
15
21
|
prefetchInstance.memorize(id + functionId, result);
|
|
16
22
|
return result;
|
|
17
23
|
});
|
|
18
24
|
return promise;
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
25
|
+
} else {
|
|
21
26
|
const result = prefetchInstance.prefetch(options);
|
|
22
27
|
prefetchInstance.memorize(id + functionId, result);
|
|
23
28
|
return result;
|
|
@@ -25,4 +30,3 @@ function prefetch(options) {
|
|
|
25
30
|
}
|
|
26
31
|
|
|
27
32
|
export { prefetch };
|
|
28
|
-
//# sourceMappingURL=universal.esm.js.map
|
|
@@ -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';
|
package/dist/universal.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from './universal/index';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/data-prefetch",
|
|
3
3
|
"description": "Module Federation Data Prefetch",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.1.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "nieyan <nyqykk@foxmail.com>",
|
|
7
7
|
"homepage": "https://github.com/module-federation/core",
|
|
@@ -21,29 +21,54 @@
|
|
|
21
21
|
],
|
|
22
22
|
"exports": {
|
|
23
23
|
".": {
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
"import": {
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"default": "./dist/index.js"
|
|
27
|
+
},
|
|
28
|
+
"require": {
|
|
29
|
+
"types": "./dist/index.d.cts",
|
|
30
|
+
"default": "./dist/index.cjs"
|
|
31
|
+
}
|
|
27
32
|
},
|
|
28
33
|
"./react": {
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
-
|
|
34
|
+
"import": {
|
|
35
|
+
"types": "./dist/react.d.ts",
|
|
36
|
+
"default": "./dist/react.js"
|
|
37
|
+
},
|
|
38
|
+
"require": {
|
|
39
|
+
"types": "./dist/react.d.cts",
|
|
40
|
+
"default": "./dist/react.cjs"
|
|
41
|
+
}
|
|
32
42
|
},
|
|
33
43
|
"./cli": {
|
|
34
|
-
"
|
|
35
|
-
|
|
36
|
-
|
|
44
|
+
"import": {
|
|
45
|
+
"types": "./dist/cli.d.ts",
|
|
46
|
+
"default": "./dist/cli.js"
|
|
47
|
+
},
|
|
48
|
+
"require": {
|
|
49
|
+
"types": "./dist/cli.d.cts",
|
|
50
|
+
"default": "./dist/cli.cjs"
|
|
51
|
+
}
|
|
37
52
|
},
|
|
38
53
|
"./babel-plugin": {
|
|
39
|
-
"
|
|
40
|
-
|
|
41
|
-
|
|
54
|
+
"import": {
|
|
55
|
+
"types": "./dist/babel.d.ts",
|
|
56
|
+
"default": "./dist/babel.js"
|
|
57
|
+
},
|
|
58
|
+
"require": {
|
|
59
|
+
"types": "./dist/babel.d.cts",
|
|
60
|
+
"default": "./dist/babel.cjs"
|
|
61
|
+
}
|
|
42
62
|
},
|
|
43
63
|
"./universal": {
|
|
44
|
-
"
|
|
45
|
-
|
|
46
|
-
|
|
64
|
+
"import": {
|
|
65
|
+
"types": "./dist/universal.d.ts",
|
|
66
|
+
"default": "./dist/universal.js"
|
|
67
|
+
},
|
|
68
|
+
"require": {
|
|
69
|
+
"types": "./dist/universal.d.cts",
|
|
70
|
+
"default": "./dist/universal.cjs"
|
|
71
|
+
}
|
|
47
72
|
}
|
|
48
73
|
},
|
|
49
74
|
"typesVersions": {
|
|
@@ -65,8 +90,9 @@
|
|
|
65
90
|
]
|
|
66
91
|
}
|
|
67
92
|
},
|
|
68
|
-
"main": "dist/index.cjs
|
|
69
|
-
"
|
|
93
|
+
"main": "./dist/index.cjs",
|
|
94
|
+
"types": "./dist/index.d.ts",
|
|
95
|
+
"module": "./dist/index.js",
|
|
70
96
|
"peerDependencies": {
|
|
71
97
|
"react": ">=16.9.0",
|
|
72
98
|
"react-dom": ">=16.9.0"
|
|
@@ -93,12 +119,12 @@
|
|
|
93
119
|
"react-router": "^6.30.2",
|
|
94
120
|
"react-test-renderer": "^18.2.0",
|
|
95
121
|
"ts-jest": "29.0.1",
|
|
96
|
-
"webpack": "5.
|
|
122
|
+
"webpack": "5.104.1"
|
|
97
123
|
},
|
|
98
124
|
"dependencies": {
|
|
99
125
|
"fs-extra": "9.1.0",
|
|
100
|
-
"@module-federation/
|
|
101
|
-
"@module-federation/
|
|
126
|
+
"@module-federation/runtime": "2.1.0",
|
|
127
|
+
"@module-federation/sdk": "2.1.0"
|
|
102
128
|
},
|
|
103
129
|
"scripts": {
|
|
104
130
|
"test": "jest"
|
package/dist/babel.cjs.cjs
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var path = require('path');
|
|
4
|
-
|
|
5
|
-
const attribute = 'id';
|
|
6
|
-
const hookId = 'usePrefetch';
|
|
7
|
-
const importPackage = '@module-federation/data-prefetch/react';
|
|
8
|
-
var babel = (babel, options) => {
|
|
9
|
-
const t = babel.types;
|
|
10
|
-
let shouldHandle = false;
|
|
11
|
-
let scope = '';
|
|
12
|
-
const { name, exposes } = options;
|
|
13
|
-
if (!exposes) {
|
|
14
|
-
return {};
|
|
15
|
-
}
|
|
16
|
-
const exposesKey = Object.keys(exposes);
|
|
17
|
-
const processedExposes = exposesKey.map((expose) => ({
|
|
18
|
-
key: expose.replace('.', ''),
|
|
19
|
-
value: path.resolve(typeof exposes[expose] === 'string'
|
|
20
|
-
?
|
|
21
|
-
exposes[expose]
|
|
22
|
-
:
|
|
23
|
-
exposes[expose].import),
|
|
24
|
-
}));
|
|
25
|
-
return {
|
|
26
|
-
visitor: {
|
|
27
|
-
ImportDeclaration(nodePath, state) {
|
|
28
|
-
const source = nodePath.node.source.value;
|
|
29
|
-
const { specifiers } = nodePath.node;
|
|
30
|
-
const { filename } = state.file.opts;
|
|
31
|
-
if (source === importPackage) {
|
|
32
|
-
shouldHandle = specifiers.some((specifier) => specifier.imported &&
|
|
33
|
-
specifier.imported.name === hookId &&
|
|
34
|
-
processedExposes.find((expose) => expose.value === filename && (scope = expose.key)));
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
CallExpression(nodePath) {
|
|
38
|
-
if (shouldHandle &&
|
|
39
|
-
t.isIdentifier(nodePath.node.callee, { name: hookId }) &&
|
|
40
|
-
nodePath.node.arguments.length > 0) {
|
|
41
|
-
const objectExpression = nodePath.node.arguments[0];
|
|
42
|
-
if (objectExpression &&
|
|
43
|
-
t.isObjectExpression(objectExpression) &&
|
|
44
|
-
!objectExpression.properties.find((p) => p.key.name === attribute)) {
|
|
45
|
-
objectExpression.properties.push(t.objectProperty(t.identifier(attribute), t.stringLiteral(name + scope)));
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
};
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
module.exports = babel;
|
|
54
|
-
//# sourceMappingURL=babel.cjs.cjs.map
|
package/dist/babel.cjs.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"babel.cjs.cjs","sources":["../src/cli/babel.ts"],"sourcesContent":["import path from 'path';\nconst attribute = 'id';\nconst hookId = 'usePrefetch';\nconst importPackage = '@module-federation/data-prefetch/react';\nexport default (babel, options) => {\n const t = babel.types;\n let shouldHandle = false;\n let scope = '';\n const { name, exposes } = options;\n if (!exposes) {\n return {};\n }\n const exposesKey = Object.keys(exposes);\n const processedExposes = exposesKey.map((expose) => ({\n key: expose.replace('.', ''),\n value: path.resolve(typeof exposes[expose] === 'string'\n ?\n exposes[expose]\n :\n exposes[expose].import),\n }));\n return {\n visitor: {\n ImportDeclaration(nodePath, state) {\n const source = nodePath.node.source.value;\n const { specifiers } = nodePath.node;\n const { filename } = state.file.opts;\n if (source === importPackage) {\n shouldHandle = specifiers.some((specifier) => specifier.imported &&\n specifier.imported.name === hookId &&\n processedExposes.find((expose) => expose.value === filename && (scope = expose.key)));\n }\n },\n CallExpression(nodePath) {\n if (shouldHandle &&\n t.isIdentifier(nodePath.node.callee, { name: hookId }) &&\n nodePath.node.arguments.length > 0) {\n const objectExpression = nodePath.node.arguments[0];\n if (objectExpression &&\n t.isObjectExpression(objectExpression) &&\n !objectExpression.properties.find((p) => p.key.name === attribute)) {\n objectExpression.properties.push(t.objectProperty(t.identifier(attribute), t.stringLiteral(name + scope)));\n }\n }\n },\n },\n };\n};\n"],"names":[],"mappings":";;;;AACA,MAAM,SAAS,GAAG,IAAI;AACtB,MAA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B,SAAS,CAAC,QAAQ,CAAC,IAAI,KAAK,MAAM;AAC1D,wBAAwB,gBAAgB,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,KAAK,KAAK,QAAQ,KAAK,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;AAC7G,gBAAgB;AAChB,YAAY,CAAC;AACb,YAAY,cAAc,CAAC,QAAQ,EAAE;AACrC,gBAAgB,IAAI,YAAY;AAChC,oBAAoB,CAAC,CAAC,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;AAC1E,oBAAoB,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE;AACxD,oBAAoB,MAAM,gBAAgB,GAAG,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;AACvE,oBAAoB,IAAI,gBAAgB;AACxC,wBAAwB,CAAC,CAAC,kBAAkB,CAAC,gBAAgB,CAAC;AAC9D,wBAAwB,CAAC,gBAAgB,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,IAAI,KAAK,SAAS,CAAC,EAAE;AAC5F,wBAAwB,gBAAgB,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,aAAa,CAAC,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC;AAClI,oBAAoB;AACpB,gBAAgB;AAChB,YAAY,CAAC;AACb,SAAS;AACT,KAAK;AACL,CAAC;;;;"}
|
package/dist/babel.cjs.d.ts
DELETED
package/dist/babel.esm.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
|
|
3
|
-
const attribute = 'id';
|
|
4
|
-
const hookId = 'usePrefetch';
|
|
5
|
-
const importPackage = '@module-federation/data-prefetch/react';
|
|
6
|
-
var babel = (babel, options) => {
|
|
7
|
-
const t = babel.types;
|
|
8
|
-
let shouldHandle = false;
|
|
9
|
-
let scope = '';
|
|
10
|
-
const { name, exposes } = options;
|
|
11
|
-
if (!exposes) {
|
|
12
|
-
return {};
|
|
13
|
-
}
|
|
14
|
-
const exposesKey = Object.keys(exposes);
|
|
15
|
-
const processedExposes = exposesKey.map((expose) => ({
|
|
16
|
-
key: expose.replace('.', ''),
|
|
17
|
-
value: path.resolve(typeof exposes[expose] === 'string'
|
|
18
|
-
?
|
|
19
|
-
exposes[expose]
|
|
20
|
-
:
|
|
21
|
-
exposes[expose].import),
|
|
22
|
-
}));
|
|
23
|
-
return {
|
|
24
|
-
visitor: {
|
|
25
|
-
ImportDeclaration(nodePath, state) {
|
|
26
|
-
const source = nodePath.node.source.value;
|
|
27
|
-
const { specifiers } = nodePath.node;
|
|
28
|
-
const { filename } = state.file.opts;
|
|
29
|
-
if (source === importPackage) {
|
|
30
|
-
shouldHandle = specifiers.some((specifier) => specifier.imported &&
|
|
31
|
-
specifier.imported.name === hookId &&
|
|
32
|
-
processedExposes.find((expose) => expose.value === filename && (scope = expose.key)));
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
CallExpression(nodePath) {
|
|
36
|
-
if (shouldHandle &&
|
|
37
|
-
t.isIdentifier(nodePath.node.callee, { name: hookId }) &&
|
|
38
|
-
nodePath.node.arguments.length > 0) {
|
|
39
|
-
const objectExpression = nodePath.node.arguments[0];
|
|
40
|
-
if (objectExpression &&
|
|
41
|
-
t.isObjectExpression(objectExpression) &&
|
|
42
|
-
!objectExpression.properties.find((p) => p.key.name === attribute)) {
|
|
43
|
-
objectExpression.properties.push(t.objectProperty(t.identifier(attribute), t.stringLiteral(name + scope)));
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
};
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
export { babel as default };
|
|
52
|
-
//# sourceMappingURL=babel.esm.js.map
|
package/dist/babel.esm.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"babel.esm.js","sources":["../src/cli/babel.ts"],"sourcesContent":["import path from 'path';\nconst attribute = 'id';\nconst hookId = 'usePrefetch';\nconst importPackage = '@module-federation/data-prefetch/react';\nexport default (babel, options) => {\n const t = babel.types;\n let shouldHandle = false;\n let scope = '';\n const { name, exposes } = options;\n if (!exposes) {\n return {};\n }\n const exposesKey = Object.keys(exposes);\n const processedExposes = exposesKey.map((expose) => ({\n key: expose.replace('.', ''),\n value: path.resolve(typeof exposes[expose] === 'string'\n ?\n exposes[expose]\n :\n exposes[expose].import),\n }));\n return {\n visitor: {\n ImportDeclaration(nodePath, state) {\n const source = nodePath.node.source.value;\n const { specifiers } = nodePath.node;\n const { filename } = state.file.opts;\n if (source === importPackage) {\n shouldHandle = specifiers.some((specifier) => specifier.imported &&\n specifier.imported.name === hookId &&\n processedExposes.find((expose) => expose.value === filename && (scope = expose.key)));\n }\n },\n CallExpression(nodePath) {\n if (shouldHandle &&\n t.isIdentifier(nodePath.node.callee, { name: hookId }) &&\n nodePath.node.arguments.length > 0) {\n const objectExpression = nodePath.node.arguments[0];\n if (objectExpression &&\n t.isObjectExpression(objectExpression) &&\n !objectExpression.properties.find((p) => p.key.name === attribute)) {\n objectExpression.properties.push(t.objectProperty(t.identifier(attribute), t.stringLiteral(name + scope)));\n }\n }\n },\n },\n };\n};\n"],"names":[],"mappings":";;AACA,MAAM,SAAS,GAAG,IAAI;AACtB,MAAM,MAAM,GAAG,aAAa;AAC5B,MAAM,aAAa,GAAG,wCAAwC;AAC9D,YAAe,CAAC,KAAK,EAAE,OAAO,KAAK;AACnC,IAAI,MAAM,CAAC,GAAG,KAAK,CAAC,KAAK;AACzB,IAAI,IAAI,YAAY,GAAG,KAAK;AAC5B,IAAI,IAAI,KAAK,GAAG,EAAE;AAClB,IAAI,MAAM,EAAE,IAAI,EAAE,OA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AE;AACrC,gBAAgB,IAAI,YAAY;AAChC,oBAAoB,CAAC,CAAC,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;AAC1E,oBAAoB,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE;AACxD,oBAAoB,MAAM,gBAAgB,GAAG,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;AACvE,oBAAoB,IAAI,gBAAgB;AACxC,wBAAwB,CAAC,CAAC,kBAAkB,CAAC,gBAAgB,CAAC;AAC9D,wBAAwB,CAAC,gBAAgB,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,IAAI,KAAK,SAAS,CAAC,EAAE;AAC5F,wBAAwB,gBAAgB,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,aAAa,CAAC,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC;AAClI,oBAAoB;AACpB,gBAAgB;AAChB,YAAY,CAAC;AACb,SAAS;AACT,KAAK;AACL,CAAC;;;;"}
|
package/dist/cli.cjs.cjs
DELETED
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var path = require('path');
|
|
4
|
-
var fs = require('fs-extra');
|
|
5
|
-
var sdk = require('@module-federation/sdk');
|
|
6
|
-
var normalizeWebpackPath = require('@module-federation/sdk/normalize-webpack-path');
|
|
7
|
-
var runtimeUtils = require('./runtime-utils.cjs.cjs');
|
|
8
|
-
var constant = require('./constant.cjs.cjs');
|
|
9
|
-
|
|
10
|
-
const TEMP_DIR = '.mf';
|
|
11
|
-
|
|
12
|
-
const fileExistsWithCaseSync = (filepath) => {
|
|
13
|
-
const dir = path.dirname(filepath);
|
|
14
|
-
if (filepath === '/' || filepath === '.') {
|
|
15
|
-
return true;
|
|
16
|
-
}
|
|
17
|
-
const filenames = fs.readdirSync(dir);
|
|
18
|
-
if (filenames.indexOf(path.basename(filepath)) === -1) {
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
return fileExistsWithCaseSync(dir);
|
|
22
|
-
};
|
|
23
|
-
const fixPrefetchPath = (exposePath) => {
|
|
24
|
-
const pathExt = ['.js', '.ts'];
|
|
25
|
-
const extReg = /\.(ts|js|tsx|jsx)$/;
|
|
26
|
-
if (extReg.test(exposePath)) {
|
|
27
|
-
return pathExt.map((ext) => exposePath.replace(extReg, `.prefetch${ext}`));
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
return pathExt.map((ext) => exposePath + `.prefetch${ext}`);
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const { RuntimeGlobals, Template } = require(normalizeWebpackPath.normalizeWebpackPath('webpack'));
|
|
35
|
-
const createBundlerLogger = typeof sdk.createInfrastructureLogger === 'function'
|
|
36
|
-
? sdk.createInfrastructureLogger
|
|
37
|
-
: sdk.createLogger;
|
|
38
|
-
const logger = createBundlerLogger('[ Module Federation Data Prefetch Plugin ]');
|
|
39
|
-
function getFederationGlobalScope(runtimeGlobals) {
|
|
40
|
-
return `${runtimeGlobals.require || '__webpack_require__'}.federation`;
|
|
41
|
-
}
|
|
42
|
-
class PrefetchPlugin {
|
|
43
|
-
constructor(options) {
|
|
44
|
-
this.options = options;
|
|
45
|
-
this._reWriteExports = '';
|
|
46
|
-
}
|
|
47
|
-
apply(compiler) {
|
|
48
|
-
var _a;
|
|
49
|
-
sdk.bindLoggerToCompiler(logger, compiler, 'PrefetchPlugin');
|
|
50
|
-
const { name, exposes } = this.options;
|
|
51
|
-
if (!exposes) {
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
if (!compiler.options.context) {
|
|
55
|
-
throw new Error('compiler.options.context is not defined');
|
|
56
|
-
}
|
|
57
|
-
const { runtimePlugins } = this.options;
|
|
58
|
-
if (!Array.isArray(runtimePlugins)) {
|
|
59
|
-
this.options.runtimePlugins = [];
|
|
60
|
-
}
|
|
61
|
-
const runtimePath = path.resolve(__dirname, './plugin.esm.js');
|
|
62
|
-
if (!((_a = this.options.runtimePlugins) === null || _a === void 0 ? void 0 : _a.includes(runtimePath))) {
|
|
63
|
-
this.options.runtimePlugins.push(runtimePath);
|
|
64
|
-
}
|
|
65
|
-
if (this.options.shareStrategy !== constant.SHARED_STRATEGY) {
|
|
66
|
-
this.options.shareStrategy = constant.SHARED_STRATEGY;
|
|
67
|
-
logger.warn(`[Module Federation Data Prefetch]: Your shared strategy is set to '${constant.SHARED_STRATEGY}', this is a necessary condition for data prefetch`);
|
|
68
|
-
}
|
|
69
|
-
const encodedName = sdk.encodeName(name);
|
|
70
|
-
const asyncEntryPath = path.resolve(compiler.options.context, `node_modules/${TEMP_DIR}/${encodedName}/bootstrap.js`);
|
|
71
|
-
if (fs.existsSync(asyncEntryPath)) {
|
|
72
|
-
fs.unlinkSync(asyncEntryPath);
|
|
73
|
-
}
|
|
74
|
-
if (!this.options.dataPrefetch) {
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
const exposeAlias = Object.keys(exposes);
|
|
78
|
-
exposeAlias.forEach((alias) => {
|
|
79
|
-
let exposePath;
|
|
80
|
-
const exposeValue = exposes[alias];
|
|
81
|
-
if (typeof exposeValue === 'string') {
|
|
82
|
-
exposePath = exposeValue;
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
exposePath = exposeValue.import[0];
|
|
86
|
-
}
|
|
87
|
-
const targetPaths = fixPrefetchPath(exposePath);
|
|
88
|
-
for (const pathItem of targetPaths) {
|
|
89
|
-
const absolutePath = path.resolve(compiler.options.context, pathItem);
|
|
90
|
-
if (fileExistsWithCaseSync(absolutePath)) {
|
|
91
|
-
const absoluteAlias = alias.replace('.', '');
|
|
92
|
-
this._reWriteExports += `export * as ${runtimeUtils.getPrefetchId(`${name}${absoluteAlias}`)} from '${absolutePath}';\n`;
|
|
93
|
-
break;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
if (!this._reWriteExports) {
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
const tempDirRealPath = path.resolve(compiler.options.context, 'node_modules', TEMP_DIR);
|
|
101
|
-
if (!fs.existsSync(tempDirRealPath)) {
|
|
102
|
-
fs.mkdirSync(tempDirRealPath);
|
|
103
|
-
}
|
|
104
|
-
if (!fs.existsSync(`${tempDirRealPath}/${encodedName}`)) {
|
|
105
|
-
fs.mkdirSync(`${tempDirRealPath}/${encodedName}`);
|
|
106
|
-
}
|
|
107
|
-
fs.writeFileSync(asyncEntryPath, this._reWriteExports);
|
|
108
|
-
new compiler.webpack.DefinePlugin({
|
|
109
|
-
FederationDataPrefetch: JSON.stringify(asyncEntryPath),
|
|
110
|
-
}).apply(compiler);
|
|
111
|
-
}
|
|
112
|
-
static addRuntime(compiler, options) {
|
|
113
|
-
const encodedName = sdk.encodeName(options.name);
|
|
114
|
-
if (!compiler.options.context) {
|
|
115
|
-
throw new Error('compiler.options.context is not defined');
|
|
116
|
-
}
|
|
117
|
-
const prefetchEntry = path.resolve(compiler.options.context, `node_modules/.mf/${encodedName}/bootstrap.js`);
|
|
118
|
-
const federationGlobal = getFederationGlobalScope(RuntimeGlobals || {});
|
|
119
|
-
return Template.asString([
|
|
120
|
-
fs.existsSync(prefetchEntry)
|
|
121
|
-
? Template.indent([
|
|
122
|
-
'function injectPrefetch() {',
|
|
123
|
-
Template.indent([
|
|
124
|
-
`globalThis.__FEDERATION__ = globalThis.__FEDERATION__ || {};`,
|
|
125
|
-
`globalThis.__FEDERATION__['${sdk.MFPrefetchCommon.globalKey}'] = globalThis.__FEDERATION__['${sdk.MFPrefetchCommon.globalKey}'] || {`,
|
|
126
|
-
`entryLoading: {},`,
|
|
127
|
-
`instance: new Map(),`,
|
|
128
|
-
`__PREFETCH_EXPORTS__: {},`,
|
|
129
|
-
`};`,
|
|
130
|
-
`globalThis.__FEDERATION__['${sdk.MFPrefetchCommon.globalKey}']['${sdk.MFPrefetchCommon.exportsKey}'] = globalThis.__FEDERATION__['${sdk.MFPrefetchCommon.globalKey}']['${sdk.MFPrefetchCommon.exportsKey}'] || {};`,
|
|
131
|
-
`globalThis.__FEDERATION__['${sdk.MFPrefetchCommon.globalKey}']['${sdk.MFPrefetchCommon.exportsKey}']['${options.name}'] = function(){ return import('${prefetchEntry}');}`,
|
|
132
|
-
]),
|
|
133
|
-
'}',
|
|
134
|
-
`${federationGlobal}.prefetch = injectPrefetch`,
|
|
135
|
-
])
|
|
136
|
-
: '',
|
|
137
|
-
Template.indent([
|
|
138
|
-
`if(!${federationGlobal}.isMFRemote && ${federationGlobal}.prefetch){`,
|
|
139
|
-
`${federationGlobal}.prefetch()`,
|
|
140
|
-
'}',
|
|
141
|
-
]),
|
|
142
|
-
]);
|
|
143
|
-
}
|
|
144
|
-
static setRemoteIdentifier() {
|
|
145
|
-
const federationGlobal = getFederationGlobalScope(RuntimeGlobals || {});
|
|
146
|
-
return Template.indent([`${federationGlobal}.isMFRemote = true;`]);
|
|
147
|
-
}
|
|
148
|
-
static removeRemoteIdentifier() {
|
|
149
|
-
const federationGlobal = getFederationGlobalScope(RuntimeGlobals || {});
|
|
150
|
-
return Template.indent([`${federationGlobal}.isMFRemote = false;`]);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
exports.PrefetchPlugin = PrefetchPlugin;
|
|
155
|
-
exports.getFederationGlobalScope = getFederationGlobalScope;
|
|
156
|
-
//# sourceMappingURL=cli.cjs.cjs.map
|
package/dist/cli.cjs.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cli.cjs.cjs","sources":["../src/common/constant.ts","../src/common/node-utils.ts","../src/cli/index.ts"],"sourcesContent":["export const TEMP_DIR = '.mf';\n","import path from 'path';\nimport fs from 'fs-extra';\nexport const fileExistsWithCaseSync = (filepath) => {\n const dir = path.dirname(filepath);\n if (filepath === '/' || filepath === '.') {\n return true;\n }\n const filenames = fs.readdirSync(dir);\n if (filenames.indexOf(path.basename(filepath)) === -1) {\n return false;\n }\n return fileExistsWithCaseSync(dir);\n};\nexport const fixPrefetchPath = (exposePath) => {\n const pathExt = ['.js', '.ts'];\n const extReg = /\\.(ts|js|tsx|jsx)$/;\n if (extReg.test(exposePath)) {\n return pathExt.map((ext) => exposePath.replace(extReg, `.prefetch${ext}`));\n }\n else {\n return pathExt.map((ext) => exposePath + `.prefetch${ext}`);\n }\n};\n","import path from 'path';\nimport fs from 'fs-extra';\nimport { bindLoggerToCompiler, createInfrastructureLogger, createLogger, encodeName, MFPrefetchCommon, } from '@module-federation/sdk';\nimport { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\nimport { TEMP_DIR } from '../common/constant';\nimport { fileExistsWithCaseSync, fixPrefetchPath } from '../common/node-utils';\nimport { getPrefetchId } from '../common/runtime-utils';\nimport { SHARED_STRATEGY } from '../constant';\nconst { RuntimeGlobals, Template } = require(normalizeWebpackPath('webpack'));\nconst createBundlerLogger = typeof createInfrastructureLogger === 'function'\n ? createInfrastructureLogger\n : createLogger;\nconst logger = createBundlerLogger('[ Module Federation Data Prefetch Plugin ]');\nexport function getFederationGlobalScope(runtimeGlobals) {\n return `${runtimeGlobals.require || '__webpack_require__'}.federation`;\n}\nexport class PrefetchPlugin {\n constructor(options) {\n this.options = options;\n this._reWriteExports = '';\n }\n apply(compiler) {\n var _a;\n bindLoggerToCompiler(logger, compiler, 'PrefetchPlugin');\n const { name, exposes } = this.options;\n if (!exposes) {\n return;\n }\n if (!compiler.options.context) {\n throw new Error('compiler.options.context is not defined');\n }\n const { runtimePlugins } = this.options;\n if (!Array.isArray(runtimePlugins)) {\n this.options.runtimePlugins = [];\n }\n const runtimePath = path.resolve(__dirname, './plugin.esm.js');\n if (!((_a = this.options.runtimePlugins) === null || _a === void 0 ? void 0 : _a.includes(runtimePath))) {\n this.options.runtimePlugins.push(runtimePath);\n }\n if (this.options.shareStrategy !== SHARED_STRATEGY) {\n this.options.shareStrategy = SHARED_STRATEGY;\n logger.warn(`[Module Federation Data Prefetch]: Your shared strategy is set to '${SHARED_STRATEGY}', this is a necessary condition for data prefetch`);\n }\n const encodedName = encodeName(name);\n const asyncEntryPath = path.resolve(compiler.options.context, `node_modules/${TEMP_DIR}/${encodedName}/bootstrap.js`);\n if (fs.existsSync(asyncEntryPath)) {\n fs.unlinkSync(asyncEntryPath);\n }\n if (!this.options.dataPrefetch) {\n return;\n }\n const prefetchs = [];\n const exposeAlias = Object.keys(exposes);\n exposeAlias.forEach((alias) => {\n let exposePath;\n const exposeValue = exposes[alias];\n if (typeof exposeValue === 'string') {\n exposePath = exposeValue;\n }\n else {\n exposePath = exposeValue.import[0];\n }\n const targetPaths = fixPrefetchPath(exposePath);\n for (const pathItem of targetPaths) {\n const absolutePath = path.resolve(compiler.options.context, pathItem);\n if (fileExistsWithCaseSync(absolutePath)) {\n prefetchs.push(pathItem);\n const absoluteAlias = alias.replace('.', '');\n this._reWriteExports += `export * as ${getPrefetchId(`${name}${absoluteAlias}`)} from '${absolutePath}';\\n`;\n break;\n }\n }\n });\n if (!this._reWriteExports) {\n return;\n }\n const tempDirRealPath = path.resolve(compiler.options.context, 'node_modules', TEMP_DIR);\n if (!fs.existsSync(tempDirRealPath)) {\n fs.mkdirSync(tempDirRealPath);\n }\n if (!fs.existsSync(`${tempDirRealPath}/${encodedName}`)) {\n fs.mkdirSync(`${tempDirRealPath}/${encodedName}`);\n }\n fs.writeFileSync(asyncEntryPath, this._reWriteExports);\n new compiler.webpack.DefinePlugin({\n FederationDataPrefetch: JSON.stringify(asyncEntryPath),\n }).apply(compiler);\n }\n static addRuntime(compiler, options) {\n const encodedName = encodeName(options.name);\n if (!compiler.options.context) {\n throw new Error('compiler.options.context is not defined');\n }\n const prefetchEntry = path.resolve(compiler.options.context, `node_modules/.mf/${encodedName}/bootstrap.js`);\n const federationGlobal = getFederationGlobalScope(RuntimeGlobals || {});\n return Template.asString([\n fs.existsSync(prefetchEntry)\n ? Template.indent([\n 'function injectPrefetch() {',\n Template.indent([\n `globalThis.__FEDERATION__ = globalThis.__FEDERATION__ || {};`,\n `globalThis.__FEDERATION__['${MFPrefetchCommon.globalKey}'] = globalThis.__FEDERATION__['${MFPrefetchCommon.globalKey}'] || {`,\n `entryLoading: {},`,\n `instance: new Map(),`,\n `__PREFETCH_EXPORTS__: {},`,\n `};`,\n `globalThis.__FEDERATION__['${MFPrefetchCommon.globalKey}']['${MFPrefetchCommon.exportsKey}'] = globalThis.__FEDERATION__['${MFPrefetchCommon.globalKey}']['${MFPrefetchCommon.exportsKey}'] || {};`,\n `globalThis.__FEDERATION__['${MFPrefetchCommon.globalKey}']['${MFPrefetchCommon.exportsKey}']['${options.name}'] = function(){ return import('${prefetchEntry}');}`,\n ]),\n '}',\n `${federationGlobal}.prefetch = injectPrefetch`,\n ])\n : '',\n Template.indent([\n `if(!${federationGlobal}.isMFRemote && ${federationGlobal}.prefetch){`,\n `${federationGlobal}.prefetch()`,\n '}',\n ]),\n ]);\n }\n static setRemoteIdentifier() {\n const federationGlobal = getFederationGlobalScope(RuntimeGlobals || {});\n return Template.indent([`${federationGlobal}.isMFRemote = true;`]);\n }\n static removeRemoteIdentifier() {\n const federationGlobal = getFederationGlobalScope(RuntimeGlobals || {});\n return Template.indent([`${federationGlobal}.isMFRemote = false;`]);\n }\n}\n"],"names":["normalizeWebpackPath","createInfrastructureLogger","createLogger","bindLoggerToCompiler","SHARED_STRATEGY","encodeName","getPrefetchId","MFPrefetchCommon"],"mappings":";;;;;;;;;AAAO,MAAM,QAAQ,GAAG,KAAK;;ACEtB,MAAM,sBAAsB,GAAG,CAAC,QAAQ,KAAK;AACpD,IAAI,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;AACtC,IAAI,IAAI,QAAQ,KAAK,GAAG,IAAI,QAA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