@module-federation/modern-js 0.21.5 → 0.22.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/cjs/cli/configPlugin.js +301 -357
- package/dist/cjs/cli/index.js +103 -93
- package/dist/cjs/cli/mfRuntimePlugins/inject-node-fetch.js +51 -41
- package/dist/cjs/cli/mfRuntimePlugins/resolve-entry-ipv4.js +73 -75
- package/dist/cjs/cli/mfRuntimePlugins/shared-strategy.js +50 -40
- package/dist/cjs/cli/server/data-fetch-server-plugin.js +55 -44
- package/dist/cjs/cli/ssrPlugin.js +266 -298
- package/dist/cjs/cli/utils.js +84 -81
- package/dist/cjs/constant.js +37 -28
- package/dist/cjs/interfaces/bundler.js +17 -15
- package/dist/cjs/logger.js +37 -25
- package/dist/cjs/react/index.js +55 -19
- package/dist/cjs/react/plugin.js +62 -37
- package/dist/cjs/react/v18.js +55 -19
- package/dist/cjs/react/v19.js +55 -19
- package/dist/cjs/runtime/index.js +55 -19
- package/dist/cjs/server/fileCache.js +76 -76
- package/dist/cjs/server/index.js +65 -57
- package/dist/cjs/server/staticMiddleware.js +84 -84
- package/dist/cjs/ssr-runtime/SSRLiveReload.js +40 -34
- package/dist/cjs/ssr-runtime/devPlugin.js +63 -67
- package/dist/cjs/ssr-runtime/injectDataFetchFunctionPlugin.js +44 -36
- package/dist/cjs/types/index.js +17 -15
- package/dist/esm/cli/configPlugin.mjs +305 -0
- package/dist/esm/cli/index.mjs +83 -0
- package/dist/esm/cli/mfRuntimePlugins/inject-node-fetch.mjs +12 -0
- package/dist/esm/cli/mfRuntimePlugins/resolve-entry-ipv4.mjs +58 -0
- package/dist/esm/cli/mfRuntimePlugins/shared-strategy.mjs +21 -0
- package/dist/esm/cli/server/data-fetch-server-plugin.mjs +17 -0
- package/dist/esm/cli/ssrPlugin.mjs +254 -0
- package/dist/esm/cli/utils.mjs +40 -0
- package/dist/esm/constant.mjs +3 -0
- package/dist/esm/logger.mjs +5 -0
- package/dist/esm/react/plugin.mjs +3 -0
- package/dist/esm/server/fileCache.mjs +90 -0
- package/dist/esm/server/index.mjs +36 -0
- package/dist/esm/server/staticMiddleware.mjs +87 -0
- package/dist/esm/ssr-runtime/SSRLiveReload.mjs +22 -0
- package/dist/esm/ssr-runtime/devPlugin.mjs +70 -0
- package/dist/esm/ssr-runtime/injectDataFetchFunctionPlugin.mjs +34 -0
- package/dist/esm-node/cli/configPlugin.mjs +263 -0
- package/dist/esm-node/cli/index.mjs +67 -0
- package/dist/esm-node/cli/mfRuntimePlugins/inject-node-fetch.mjs +10 -0
- package/dist/esm-node/cli/mfRuntimePlugins/resolve-entry-ipv4.mjs +46 -0
- package/dist/esm-node/cli/mfRuntimePlugins/shared-strategy.mjs +19 -0
- package/dist/esm-node/cli/server/data-fetch-server-plugin.mjs +15 -0
- package/dist/esm-node/cli/ssrPlugin.mjs +228 -0
- package/dist/esm-node/cli/utils.mjs +40 -0
- package/dist/esm-node/constant.mjs +3 -0
- package/dist/esm-node/logger.mjs +5 -0
- package/dist/esm-node/react/plugin.mjs +3 -0
- package/dist/esm-node/server/fileCache.mjs +37 -0
- package/dist/esm-node/server/index.mjs +34 -0
- package/dist/esm-node/server/staticMiddleware.mjs +42 -0
- package/dist/esm-node/ssr-runtime/SSRLiveReload.mjs +15 -0
- package/dist/esm-node/ssr-runtime/devPlugin.mjs +33 -0
- package/dist/esm-node/ssr-runtime/injectDataFetchFunctionPlugin.mjs +14 -0
- package/package.json +32 -31
- package/dist/cjs/cli/configPlugin.spec.js +0 -112
- package/dist/cjs/server/fileCache.spec.js +0 -28
- package/dist/cjs/server/staticMiddleware.spec.js +0 -185
- package/dist/esm/cli/configPlugin.js +0 -395
- package/dist/esm/cli/configPlugin.spec.js +0 -108
- package/dist/esm/cli/index.js +0 -92
- package/dist/esm/cli/mfRuntimePlugins/inject-node-fetch.js +0 -16
- package/dist/esm/cli/mfRuntimePlugins/resolve-entry-ipv4.js +0 -74
- package/dist/esm/cli/mfRuntimePlugins/shared-strategy.js +0 -25
- package/dist/esm/cli/server/data-fetch-server-plugin.js +0 -20
- package/dist/esm/cli/ssrPlugin.js +0 -305
- package/dist/esm/cli/utils.js +0 -53
- package/dist/esm/constant.js +0 -6
- package/dist/esm/logger.js +0 -7
- package/dist/esm/react/plugin.js +0 -5
- package/dist/esm/server/fileCache.js +0 -98
- package/dist/esm/server/fileCache.spec.js +0 -50
- package/dist/esm/server/index.js +0 -41
- package/dist/esm/server/staticMiddleware.js +0 -104
- package/dist/esm/server/staticMiddleware.spec.js +0 -328
- package/dist/esm/ssr-runtime/SSRLiveReload.js +0 -26
- package/dist/esm/ssr-runtime/devPlugin.js +0 -73
- package/dist/esm/ssr-runtime/injectDataFetchFunctionPlugin.js +0 -34
- package/dist/esm-node/cli/configPlugin.js +0 -347
- package/dist/esm-node/cli/configPlugin.spec.js +0 -89
- package/dist/esm-node/cli/index.js +0 -72
- package/dist/esm-node/cli/mfRuntimePlugins/inject-node-fetch.js +0 -14
- package/dist/esm-node/cli/mfRuntimePlugins/resolve-entry-ipv4.js +0 -62
- package/dist/esm-node/cli/mfRuntimePlugins/shared-strategy.js +0 -23
- package/dist/esm-node/cli/server/data-fetch-server-plugin.js +0 -18
- package/dist/esm-node/cli/ssrPlugin.js +0 -280
- package/dist/esm-node/cli/utils.js +0 -53
- package/dist/esm-node/constant.js +0 -6
- package/dist/esm-node/logger.js +0 -7
- package/dist/esm-node/react/plugin.js +0 -5
- package/dist/esm-node/server/fileCache.js +0 -49
- package/dist/esm-node/server/fileCache.spec.js +0 -27
- package/dist/esm-node/server/index.js +0 -39
- package/dist/esm-node/server/staticMiddleware.js +0 -55
- package/dist/esm-node/server/staticMiddleware.spec.js +0 -162
- package/dist/esm-node/ssr-runtime/SSRLiveReload.js +0 -19
- package/dist/esm-node/ssr-runtime/devPlugin.js +0 -37
- package/dist/esm-node/ssr-runtime/injectDataFetchFunctionPlugin.js +0 -16
- /package/dist/esm/interfaces/{bundler.js → bundler.mjs} +0 -0
- /package/dist/esm/react/{index.js → index.mjs} +0 -0
- /package/dist/esm/react/{v18.js → v18.mjs} +0 -0
- /package/dist/esm/react/{v19.js → v19.mjs} +0 -0
- /package/dist/esm/runtime/{index.js → index.mjs} +0 -0
- /package/dist/esm/types/{index.js → index.mjs} +0 -0
- /package/dist/esm-node/interfaces/{bundler.js → bundler.mjs} +0 -0
- /package/dist/esm-node/react/{index.js → index.mjs} +0 -0
- /package/dist/esm-node/react/{v18.js → v18.mjs} +0 -0
- /package/dist/esm-node/react/{v19.js → v19.mjs} +0 -0
- /package/dist/esm-node/runtime/{index.js → index.mjs} +0 -0
- /package/dist/esm-node/types/{index.js → index.mjs} +0 -0
|
@@ -1,43 +1,49 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
SSRLiveReload: ()=>SSRLiveReload
|
|
22
28
|
});
|
|
23
|
-
|
|
24
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
29
|
+
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
|
|
25
30
|
function SSRLiveReload() {
|
|
26
|
-
|
|
27
|
-
return
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
dangerouslySetInnerHTML: {
|
|
32
|
-
__html: String.raw`
|
|
31
|
+
if ('development' !== process.env.NODE_ENV) return null;
|
|
32
|
+
return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("script", {
|
|
33
|
+
suppressHydrationWarning: true,
|
|
34
|
+
dangerouslySetInnerHTML: {
|
|
35
|
+
__html: String.raw`
|
|
33
36
|
if(${globalThis.shouldUpdate}){
|
|
34
37
|
location.reload();
|
|
35
38
|
}
|
|
36
39
|
`
|
|
37
|
-
|
|
38
|
-
|
|
40
|
+
}
|
|
41
|
+
});
|
|
39
42
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
exports.SSRLiveReload = __webpack_exports__.SSRLiveReload;
|
|
44
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
45
|
+
"SSRLiveReload"
|
|
46
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
47
|
+
Object.defineProperty(exports, '__esModule', {
|
|
48
|
+
value: true
|
|
43
49
|
});
|
|
@@ -1,71 +1,67 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
)
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var devPlugin_exports = {};
|
|
30
|
-
__export(devPlugin_exports, {
|
|
31
|
-
mfSSRDevPlugin: () => mfSSRDevPlugin
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
mfSSRDevPlugin: ()=>mfSSRDevPlugin
|
|
32
28
|
});
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
29
|
+
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
|
|
30
|
+
const external_SSRLiveReload_js_namespaceObject = require("./SSRLiveReload.js");
|
|
31
|
+
const lazy_utils_namespaceObject = require("@module-federation/bridge-react/lazy-utils");
|
|
32
|
+
const mfSSRDevPlugin = ()=>({
|
|
33
|
+
name: '@module-federation/modern-js',
|
|
34
|
+
setup: (api)=>{
|
|
35
|
+
api.onBeforeRender(async ()=>{
|
|
36
|
+
if ("u" > typeof window) return;
|
|
37
|
+
globalThis.shouldUpdate = false;
|
|
38
|
+
const nodeUtils = await import("@module-federation/node/utils");
|
|
39
|
+
const shouldUpdate = await nodeUtils.revalidate();
|
|
40
|
+
console.log('shouldUpdate: ', shouldUpdate);
|
|
41
|
+
if (shouldUpdate) {
|
|
42
|
+
console.log('should RELOAD', shouldUpdate);
|
|
43
|
+
await nodeUtils.flushChunks();
|
|
44
|
+
(0, lazy_utils_namespaceObject.flushDataFetch)();
|
|
45
|
+
globalThis.shouldUpdate = true;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
api.wrapRoot((App)=>{
|
|
49
|
+
const AppWrapper = (props)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
|
|
50
|
+
children: [
|
|
51
|
+
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_SSRLiveReload_js_namespaceObject.SSRLiveReload, {}),
|
|
52
|
+
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(App, {
|
|
53
|
+
...props
|
|
54
|
+
})
|
|
55
|
+
]
|
|
56
|
+
});
|
|
57
|
+
return AppWrapper;
|
|
58
|
+
});
|
|
59
|
+
}
|
|
54
60
|
});
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
})
|
|
62
|
-
]
|
|
63
|
-
});
|
|
64
|
-
return AppWrapper;
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
69
|
-
0 && (module.exports = {
|
|
70
|
-
mfSSRDevPlugin
|
|
61
|
+
exports.mfSSRDevPlugin = __webpack_exports__.mfSSRDevPlugin;
|
|
62
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
63
|
+
"mfSSRDevPlugin"
|
|
64
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
65
|
+
Object.defineProperty(exports, '__esModule', {
|
|
66
|
+
value: true
|
|
71
67
|
});
|
|
@@ -1,40 +1,48 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
injectDataFetchFunctionPlugin: ()=>injectDataFetchFunctionPlugin
|
|
22
28
|
});
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
const data_fetch_utils_namespaceObject = require("@module-federation/bridge-react/data-fetch-utils");
|
|
30
|
+
const lazy_utils_namespaceObject = require("@module-federation/bridge-react/lazy-utils");
|
|
31
|
+
const injectDataFetchFunctionPlugin = ({ fetchServerQuery })=>({
|
|
32
|
+
name: '@module-federation/inject-data-fetch-function-plugin',
|
|
33
|
+
setup: (api)=>{
|
|
34
|
+
api.onBeforeRender(async ()=>{
|
|
35
|
+
(0, lazy_utils_namespaceObject.setSSREnv)({
|
|
36
|
+
fetchServerQuery
|
|
37
|
+
});
|
|
38
|
+
await (0, data_fetch_utils_namespaceObject.callDataFetch)();
|
|
39
|
+
});
|
|
40
|
+
}
|
|
34
41
|
});
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
42
|
+
exports.injectDataFetchFunctionPlugin = __webpack_exports__.injectDataFetchFunctionPlugin;
|
|
43
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
44
|
+
"injectDataFetchFunctionPlugin"
|
|
45
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
46
|
+
Object.defineProperty(exports, '__esModule', {
|
|
47
|
+
value: true
|
|
40
48
|
});
|
package/dist/cjs/types/index.js
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
var
|
|
16
|
-
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.r = (exports1)=>{
|
|
5
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
6
|
+
value: 'Module'
|
|
7
|
+
});
|
|
8
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
9
|
+
value: true
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
})();
|
|
13
|
+
var __webpack_exports__ = {};
|
|
14
|
+
__webpack_require__.r(__webpack_exports__);
|
|
15
|
+
for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
16
|
+
Object.defineProperty(exports, '__esModule', {
|
|
17
|
+
value: true
|
|
18
|
+
});
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
import { _ } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
+
import { _ as _object_spread__ } from "@swc/helpers/_/_object_spread";
|
|
3
|
+
import { _ as _object_spread_props__ } from "@swc/helpers/_/_object_spread_props";
|
|
4
|
+
import { _ as _to_consumable_array__ } from "@swc/helpers/_/_to_consumable_array";
|
|
5
|
+
import { _ as _type_of__ } from "@swc/helpers/_/_type_of";
|
|
6
|
+
import { _ as _ts_generator__ } from "@swc/helpers/_/_ts_generator";
|
|
7
|
+
import path from "path";
|
|
8
|
+
import { getIPV4, isDev, isWebTarget, skipByTarget } from "./utils.mjs";
|
|
9
|
+
import { encodeName } from "@module-federation/sdk";
|
|
10
|
+
import { bundle } from "@modern-js/node-bundle-require";
|
|
11
|
+
import { LOCALHOST, PLUGIN_IDENTIFIER } from "../constant.mjs";
|
|
12
|
+
import { addDataFetchExposes, autoDeleteSplitChunkCacheGroups } from "@module-federation/rsbuild-plugin/utils";
|
|
13
|
+
import logger from "../logger.mjs";
|
|
14
|
+
var defaultPath = path.resolve(process.cwd(), 'module-federation.config.ts');
|
|
15
|
+
function setEnv(enableSSR) {
|
|
16
|
+
if (enableSSR) process.env['MF_SSR_PRJ'] = 'true';
|
|
17
|
+
}
|
|
18
|
+
var getMFConfig = function(userConfig) {
|
|
19
|
+
return _(function() {
|
|
20
|
+
var config, configPath, mfConfigPath, preBundlePath, mfConfig;
|
|
21
|
+
return _ts_generator__(this, function(_state) {
|
|
22
|
+
switch(_state.label){
|
|
23
|
+
case 0:
|
|
24
|
+
config = userConfig.config, configPath = userConfig.configPath;
|
|
25
|
+
if (config) return [
|
|
26
|
+
2,
|
|
27
|
+
config
|
|
28
|
+
];
|
|
29
|
+
mfConfigPath = configPath ? configPath : defaultPath;
|
|
30
|
+
return [
|
|
31
|
+
4,
|
|
32
|
+
bundle(mfConfigPath)
|
|
33
|
+
];
|
|
34
|
+
case 1:
|
|
35
|
+
preBundlePath = _state.sent();
|
|
36
|
+
return [
|
|
37
|
+
4,
|
|
38
|
+
import(preBundlePath)
|
|
39
|
+
];
|
|
40
|
+
case 2:
|
|
41
|
+
mfConfig = _state.sent().default;
|
|
42
|
+
return [
|
|
43
|
+
2,
|
|
44
|
+
mfConfig
|
|
45
|
+
];
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
})();
|
|
49
|
+
};
|
|
50
|
+
var injectRuntimePlugins = function(runtimePlugin, runtimePlugins) {
|
|
51
|
+
var pluginName = 'string' == typeof runtimePlugin ? runtimePlugin : runtimePlugin[0];
|
|
52
|
+
var hasPlugin = runtimePlugins.some(function(existingPlugin) {
|
|
53
|
+
if ('string' == typeof existingPlugin) return existingPlugin === pluginName;
|
|
54
|
+
return existingPlugin[0] === pluginName;
|
|
55
|
+
});
|
|
56
|
+
if (!hasPlugin) runtimePlugins.push(runtimePlugin);
|
|
57
|
+
};
|
|
58
|
+
var replaceRemoteUrl = function(mfConfig, remoteIpStrategy) {
|
|
59
|
+
if (remoteIpStrategy && 'inherit' === remoteIpStrategy) return;
|
|
60
|
+
if (!mfConfig.remotes) return;
|
|
61
|
+
var ipv4 = getIPV4();
|
|
62
|
+
var handleRemoteObject = function(remoteObject) {
|
|
63
|
+
Object.keys(remoteObject).forEach(function(remoteKey) {
|
|
64
|
+
var remote = remoteObject[remoteKey];
|
|
65
|
+
if (Array.isArray(remote)) return;
|
|
66
|
+
if ('string' == typeof remote && remote.includes(LOCALHOST)) remoteObject[remoteKey] = remote.replace(LOCALHOST, ipv4);
|
|
67
|
+
if ((void 0 === remote ? "undefined" : _type_of__(remote)) === 'object' && !Array.isArray(remote.external) && remote.external.includes(LOCALHOST)) remote.external = remote.external.replace(LOCALHOST, ipv4);
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
if (Array.isArray(mfConfig.remotes)) mfConfig.remotes.forEach(function(remoteObject) {
|
|
71
|
+
if ('string' == typeof remoteObject) return;
|
|
72
|
+
handleRemoteObject(remoteObject);
|
|
73
|
+
});
|
|
74
|
+
else if ('string' != typeof mfConfig.remotes) handleRemoteObject(mfConfig.remotes);
|
|
75
|
+
};
|
|
76
|
+
var patchDTSConfig = function(mfConfig, isServer) {
|
|
77
|
+
if (isServer) return;
|
|
78
|
+
var ModernJSRuntime = '@module-federation/modern-js/runtime';
|
|
79
|
+
if (false !== mfConfig.dts) {
|
|
80
|
+
var _mfConfig_dts, _mfConfig_dts1;
|
|
81
|
+
if ('boolean' == typeof mfConfig.dts || void 0 === mfConfig.dts) mfConfig.dts = {
|
|
82
|
+
consumeTypes: {
|
|
83
|
+
runtimePkgs: [
|
|
84
|
+
ModernJSRuntime
|
|
85
|
+
]
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
else if ((null == (_mfConfig_dts = mfConfig.dts) ? void 0 : _mfConfig_dts.consumeTypes) || (null == (_mfConfig_dts1 = mfConfig.dts) ? void 0 : _mfConfig_dts1.consumeTypes) === void 0) {
|
|
89
|
+
var _mfConfig_dts2;
|
|
90
|
+
if ('boolean' == typeof mfConfig.dts.consumeTypes || (null == (_mfConfig_dts2 = mfConfig.dts) ? void 0 : _mfConfig_dts2.consumeTypes) === void 0) mfConfig.dts.consumeTypes = {
|
|
91
|
+
runtimePkgs: [
|
|
92
|
+
ModernJSRuntime
|
|
93
|
+
]
|
|
94
|
+
};
|
|
95
|
+
else {
|
|
96
|
+
mfConfig.dts.consumeTypes.runtimePkgs = mfConfig.dts.consumeTypes.runtimePkgs || [];
|
|
97
|
+
if (!mfConfig.dts.consumeTypes.runtimePkgs.includes(ModernJSRuntime)) mfConfig.dts.consumeTypes.runtimePkgs.push(ModernJSRuntime);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
var patchMFConfig = function(mfConfig, isServer, remoteIpStrategy, enableSSR) {
|
|
103
|
+
replaceRemoteUrl(mfConfig, remoteIpStrategy);
|
|
104
|
+
addDataFetchExposes(mfConfig.exposes, isServer);
|
|
105
|
+
if (void 0 === mfConfig.remoteType) mfConfig.remoteType = "script";
|
|
106
|
+
if (!mfConfig.name) throw new Error("".concat(PLUGIN_IDENTIFIER, " mfConfig.name can not be empty!"));
|
|
107
|
+
var runtimePlugins = _to_consumable_array__(mfConfig.runtimePlugins || []);
|
|
108
|
+
patchDTSConfig(mfConfig, isServer);
|
|
109
|
+
injectRuntimePlugins(require.resolve('@module-federation/modern-js/shared-strategy'), runtimePlugins);
|
|
110
|
+
if (enableSSR && isDev()) injectRuntimePlugins(require.resolve('@module-federation/modern-js/resolve-entry-ipv4'), runtimePlugins);
|
|
111
|
+
if (isServer) {
|
|
112
|
+
injectRuntimePlugins(require.resolve('@module-federation/node/runtimePlugin'), runtimePlugins);
|
|
113
|
+
if (isDev()) injectRuntimePlugins(require.resolve('@module-federation/node/record-dynamic-remote-entry-hash-plugin'), runtimePlugins);
|
|
114
|
+
injectRuntimePlugins(require.resolve('@module-federation/modern-js/inject-node-fetch'), runtimePlugins);
|
|
115
|
+
if (mfConfig.library) {
|
|
116
|
+
if (!mfConfig.library.type) mfConfig.library.type = 'commonjs-module';
|
|
117
|
+
if (!mfConfig.library.name) mfConfig.library.name = mfConfig.name;
|
|
118
|
+
} else mfConfig.library = {
|
|
119
|
+
type: 'commonjs-module',
|
|
120
|
+
name: mfConfig.name
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
mfConfig.runtimePlugins = runtimePlugins;
|
|
124
|
+
if (!isServer) {
|
|
125
|
+
var _mfConfig_library;
|
|
126
|
+
if ((null == (_mfConfig_library = mfConfig.library) ? void 0 : _mfConfig_library.type) === 'commonjs-module') mfConfig.library.type = 'global';
|
|
127
|
+
return mfConfig;
|
|
128
|
+
}
|
|
129
|
+
mfConfig.dts = false;
|
|
130
|
+
mfConfig.dev = false;
|
|
131
|
+
return mfConfig;
|
|
132
|
+
};
|
|
133
|
+
function patchIgnoreWarning(chain) {
|
|
134
|
+
var ignoreWarnings = chain.get('ignoreWarnings') || [];
|
|
135
|
+
var ignoredMsgs = [
|
|
136
|
+
"external script",
|
|
137
|
+
'process.env.WS_NO_BUFFER_UTIL',
|
|
138
|
+
"Can't resolve 'utf-8-validate"
|
|
139
|
+
];
|
|
140
|
+
ignoreWarnings.push(function(warning) {
|
|
141
|
+
if (ignoredMsgs.some(function(msg) {
|
|
142
|
+
return warning.message.includes(msg);
|
|
143
|
+
})) return true;
|
|
144
|
+
return false;
|
|
145
|
+
});
|
|
146
|
+
chain.ignoreWarnings(ignoreWarnings);
|
|
147
|
+
}
|
|
148
|
+
function addMyTypes2Ignored(chain, mfConfig) {
|
|
149
|
+
var watchOptions = chain.get('watchOptions');
|
|
150
|
+
if (!watchOptions || !watchOptions.ignored) return void chain.watchOptions({
|
|
151
|
+
ignored: /[\\/](?:\.git|node_modules|@mf-types)[\\/]/
|
|
152
|
+
});
|
|
153
|
+
var ignored = watchOptions.ignored;
|
|
154
|
+
var DEFAULT_IGNORED_GLOB = '**/@mf-types/**';
|
|
155
|
+
if (Array.isArray(ignored)) {
|
|
156
|
+
if (false !== mfConfig.dts && 'object' === _type_of__(mfConfig.dts) && 'object' === _type_of__(mfConfig.dts.consumeTypes) && mfConfig.dts.consumeTypes.remoteTypesFolder) chain.watchOptions(_object_spread_props__(_object_spread__({}, watchOptions), {
|
|
157
|
+
ignored: ignored.concat("**/".concat(mfConfig.dts.consumeTypes.remoteTypesFolder, "/**"))
|
|
158
|
+
}));
|
|
159
|
+
else chain.watchOptions(_object_spread_props__(_object_spread__({}, watchOptions), {
|
|
160
|
+
ignored: ignored.concat(DEFAULT_IGNORED_GLOB)
|
|
161
|
+
}));
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
if ('string' != typeof ignored) return void chain.watchOptions(_object_spread_props__(_object_spread__({}, watchOptions), {
|
|
165
|
+
ignored: /[\\/](?:\.git|node_modules|@mf-types)[\\/]/
|
|
166
|
+
}));
|
|
167
|
+
chain.watchOptions(_object_spread_props__(_object_spread__({}, watchOptions), {
|
|
168
|
+
ignored: ignored.concat(DEFAULT_IGNORED_GLOB)
|
|
169
|
+
}));
|
|
170
|
+
}
|
|
171
|
+
function patchBundlerConfig(options) {
|
|
172
|
+
var _modernjsConfig_deploy;
|
|
173
|
+
var chain = options.chain, modernjsConfig = options.modernjsConfig, isServer = options.isServer, mfConfig = options.mfConfig, enableSSR = options.enableSSR;
|
|
174
|
+
chain.optimization.delete('runtimeChunk');
|
|
175
|
+
patchIgnoreWarning(chain);
|
|
176
|
+
if (!chain.output.get('chunkLoadingGlobal')) chain.output.chunkLoadingGlobal("chunk_".concat(mfConfig.name));
|
|
177
|
+
if (!chain.output.get('uniqueName')) chain.output.uniqueName(mfConfig.name);
|
|
178
|
+
var splitChunkConfig = chain.optimization.splitChunks.entries();
|
|
179
|
+
if (!isServer) autoDeleteSplitChunkCacheGroups(mfConfig, splitChunkConfig);
|
|
180
|
+
if (!isServer && enableSSR && splitChunkConfig && (void 0 === splitChunkConfig ? "undefined" : _type_of__(splitChunkConfig)) === 'object' && splitChunkConfig.cacheGroups) {
|
|
181
|
+
splitChunkConfig.chunks = 'async';
|
|
182
|
+
logger.warn('splitChunks.chunks = async is not allowed with stream SSR mode, it will auto changed to "async"');
|
|
183
|
+
}
|
|
184
|
+
if (isDev() && 'auto' === chain.output.get('publicPath')) {
|
|
185
|
+
var _modernjsConfig_dev, _modernjsConfig_server;
|
|
186
|
+
var port = (null == (_modernjsConfig_dev = modernjsConfig.dev) ? void 0 : _modernjsConfig_dev.port) || (null == (_modernjsConfig_server = modernjsConfig.server) ? void 0 : _modernjsConfig_server.port) || 8080;
|
|
187
|
+
var publicPath = "http://localhost:".concat(port, "/");
|
|
188
|
+
chain.output.publicPath(publicPath);
|
|
189
|
+
}
|
|
190
|
+
if (isServer && enableSSR) {
|
|
191
|
+
var uniqueName = mfConfig.name || chain.output.get('uniqueName');
|
|
192
|
+
var chunkFileName = chain.output.get('chunkFilename');
|
|
193
|
+
if ('string' == typeof chunkFileName && uniqueName && !chunkFileName.includes(uniqueName)) {
|
|
194
|
+
var suffix = "".concat(encodeName(uniqueName), "-[contenthash].js");
|
|
195
|
+
chain.output.chunkFilename(chunkFileName.replace('.js', suffix));
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (isDev() && enableSSR && !isServer) chain.resolve.fallback.set('crypto', false).set('stream', false).set('vm', false);
|
|
199
|
+
if ((null == (_modernjsConfig_deploy = modernjsConfig.deploy) ? void 0 : _modernjsConfig_deploy.microFrontend) && Object.keys(mfConfig.exposes || {}).length) chain.optimization.usedExports(false);
|
|
200
|
+
}
|
|
201
|
+
var moduleFederationConfigPlugin = function(userConfig) {
|
|
202
|
+
return {
|
|
203
|
+
name: '@modern-js/plugin-module-federation-config',
|
|
204
|
+
pre: [
|
|
205
|
+
'@modern-js/plugin-initialize'
|
|
206
|
+
],
|
|
207
|
+
post: [
|
|
208
|
+
'@modern-js/plugin-module-federation'
|
|
209
|
+
],
|
|
210
|
+
setup: function(api) {
|
|
211
|
+
return _(function() {
|
|
212
|
+
var _userConfig_userConfig, _modernjsConfig_server, modernjsConfig, mfConfig, csrConfig, ssrConfig, _ref, enableSSR;
|
|
213
|
+
return _ts_generator__(this, function(_state) {
|
|
214
|
+
switch(_state.label){
|
|
215
|
+
case 0:
|
|
216
|
+
modernjsConfig = api.getConfig();
|
|
217
|
+
return [
|
|
218
|
+
4,
|
|
219
|
+
getMFConfig(userConfig.originPluginOptions)
|
|
220
|
+
];
|
|
221
|
+
case 1:
|
|
222
|
+
mfConfig = _state.sent();
|
|
223
|
+
csrConfig = userConfig.csrConfig || JSON.parse(JSON.stringify(mfConfig));
|
|
224
|
+
ssrConfig = userConfig.ssrConfig || JSON.parse(JSON.stringify(mfConfig));
|
|
225
|
+
userConfig.ssrConfig = ssrConfig;
|
|
226
|
+
userConfig.csrConfig = csrConfig;
|
|
227
|
+
enableSSR = Boolean(null != (_ref = null == (_userConfig_userConfig = userConfig.userConfig) ? void 0 : _userConfig_userConfig.ssr) ? _ref : Boolean(null == modernjsConfig ? void 0 : null == (_modernjsConfig_server = modernjsConfig.server) ? void 0 : _modernjsConfig_server.ssr));
|
|
228
|
+
api.modifyBundlerChain(function(chain) {
|
|
229
|
+
var target = chain.get('target');
|
|
230
|
+
if (skipByTarget(target)) return;
|
|
231
|
+
var isWeb = isWebTarget(target);
|
|
232
|
+
addMyTypes2Ignored(chain, isWeb ? csrConfig : ssrConfig);
|
|
233
|
+
var targetMFConfig = isWeb ? csrConfig : ssrConfig;
|
|
234
|
+
patchMFConfig(targetMFConfig, !isWeb, userConfig.remoteIpStrategy || 'ipv4', enableSSR);
|
|
235
|
+
patchBundlerConfig({
|
|
236
|
+
chain: chain,
|
|
237
|
+
isServer: !isWeb,
|
|
238
|
+
modernjsConfig: modernjsConfig,
|
|
239
|
+
mfConfig: mfConfig,
|
|
240
|
+
enableSSR: enableSSR
|
|
241
|
+
});
|
|
242
|
+
if (isWeb) userConfig.distOutputDir = chain.output.get('path') || path.resolve(process.cwd(), 'dist');
|
|
243
|
+
else if (enableSSR) {
|
|
244
|
+
var _userConfig, _userConfig_userConfig;
|
|
245
|
+
(_userConfig = userConfig).userConfig || (_userConfig.userConfig = {});
|
|
246
|
+
(_userConfig_userConfig = userConfig.userConfig).ssr || (_userConfig_userConfig.ssr = {});
|
|
247
|
+
if (true === userConfig.userConfig.ssr) userConfig.userConfig.ssr = {};
|
|
248
|
+
userConfig.userConfig.ssr.distOutputDir = chain.output.get('path') || path.resolve(process.cwd(), 'dist/bundles');
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
api.config(function() {
|
|
252
|
+
var _modernjsConfig_tools, _userConfig_csrConfig, _modernjsConfig_source, _modernjsConfig_source1, _modernjsConfig_dev;
|
|
253
|
+
var bundlerType = 'rspack' === api.getAppContext().bundlerType ? 'rspack' : 'webpack';
|
|
254
|
+
var ipv4 = getIPV4();
|
|
255
|
+
if (void 0 === userConfig.remoteIpStrategy) if (enableSSR) userConfig.remoteIpStrategy = 'ipv4';
|
|
256
|
+
else userConfig.remoteIpStrategy = 'inherit';
|
|
257
|
+
var devServerConfig = null == (_modernjsConfig_tools = modernjsConfig.tools) ? void 0 : _modernjsConfig_tools.devServer;
|
|
258
|
+
var corsWarnMsgs = [
|
|
259
|
+
'View https://module-federation.io/guide/troubleshooting/other.html#cors-warn for more details.'
|
|
260
|
+
];
|
|
261
|
+
if ((void 0 === devServerConfig ? "undefined" : _type_of__(devServerConfig)) !== 'object' || !('headers' in devServerConfig)) corsWarnMsgs.unshift('Detect devServer.headers is empty, mf modern plugin will add default cors header: devServer.headers["Access-Control-Allow-Headers"] = "*". It is recommended to specify an allowlist of trusted origins instead.');
|
|
262
|
+
var exposes = null == (_userConfig_csrConfig = userConfig.csrConfig) ? void 0 : _userConfig_csrConfig.exposes;
|
|
263
|
+
var hasExposes = exposes && Array.isArray(exposes) ? exposes.length : Object.keys(null != exposes ? exposes : {}).length;
|
|
264
|
+
if (corsWarnMsgs.length > 1 && hasExposes) logger.warn(corsWarnMsgs.join('\n'));
|
|
265
|
+
var corsHeaders = hasExposes ? {
|
|
266
|
+
'Access-Control-Allow-Origin': '*',
|
|
267
|
+
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
|
|
268
|
+
'Access-Control-Allow-Headers': '*'
|
|
269
|
+
} : void 0;
|
|
270
|
+
var defineConfig = {
|
|
271
|
+
REMOTE_IP_STRATEGY: JSON.stringify(userConfig.remoteIpStrategy)
|
|
272
|
+
};
|
|
273
|
+
if (enableSSR && isDev()) defineConfig['FEDERATION_IPV4'] = JSON.stringify(ipv4);
|
|
274
|
+
var _ref;
|
|
275
|
+
return {
|
|
276
|
+
tools: {
|
|
277
|
+
devServer: {
|
|
278
|
+
headers: corsHeaders
|
|
279
|
+
}
|
|
280
|
+
},
|
|
281
|
+
resolve: {
|
|
282
|
+
alias: {
|
|
283
|
+
'@modern-js/runtime/mf': require.resolve('@module-federation/modern-js/runtime')
|
|
284
|
+
}
|
|
285
|
+
},
|
|
286
|
+
source: {
|
|
287
|
+
define: defineConfig,
|
|
288
|
+
enableAsyncEntry: 'rspack' === bundlerType ? null != (_ref = null == (_modernjsConfig_source = modernjsConfig.source) ? void 0 : _modernjsConfig_source.enableAsyncEntry) ? _ref : true : null == (_modernjsConfig_source1 = modernjsConfig.source) ? void 0 : _modernjsConfig_source1.enableAsyncEntry
|
|
289
|
+
},
|
|
290
|
+
dev: {
|
|
291
|
+
assetPrefix: (null == modernjsConfig ? void 0 : null == (_modernjsConfig_dev = modernjsConfig.dev) ? void 0 : _modernjsConfig_dev.assetPrefix) ? modernjsConfig.dev.assetPrefix : true
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
});
|
|
295
|
+
return [
|
|
296
|
+
2
|
|
297
|
+
];
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
})();
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
};
|
|
304
|
+
var configPlugin = moduleFederationConfigPlugin;
|
|
305
|
+
export { addMyTypes2Ignored, configPlugin as default, getMFConfig, isWebTarget, moduleFederationConfigPlugin, patchBundlerConfig, patchMFConfig, setEnv, skipByTarget };
|