@module-federation/modern-js 0.0.0-next-20240909092952 → 0.0.0-next-20240909101028
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/{dataLoader/ast/index.js → constant.js} +6 -6
- package/dist/cjs/cli/index.js +1 -5
- package/dist/cjs/cli/mfRuntimePlugins/inject-node-fetch.js +10 -7
- package/dist/cjs/cli/mfRuntimePlugins/resolve-entry-ipv4.js +38 -40
- package/dist/cjs/cli/ssrPlugin.js +1 -1
- package/dist/cjs/cli/utils.js +4 -8
- package/dist/cjs/cli/utils.spec.js +1 -1
- package/dist/cjs/constant.js +2 -32
- package/dist/cjs/runtime/index.js +1 -4
- package/dist/cjs/ssr-runtime/plugin.js +7 -7
- package/dist/esm/cli/constant.js +4 -0
- package/dist/esm/cli/index.js +1 -4
- package/dist/esm/cli/mfRuntimePlugins/inject-node-fetch.js +10 -7
- package/dist/esm/cli/ssrPlugin.js +1 -1
- package/dist/esm/cli/utils.js +3 -6
- package/dist/esm/cli/utils.spec.js +1 -1
- package/dist/esm/constant.js +1 -21
- package/dist/esm/runtime/index.js +1 -3
- package/dist/esm/ssr-runtime/plugin.js +10 -7
- package/dist/esm-node/cli/constant.js +4 -0
- package/dist/esm-node/cli/index.js +1 -5
- package/dist/esm-node/cli/mfRuntimePlugins/inject-node-fetch.js +10 -7
- package/dist/esm-node/cli/mfRuntimePlugins/resolve-entry-ipv4.js +38 -40
- package/dist/esm-node/cli/ssrPlugin.js +1 -1
- package/dist/esm-node/cli/utils.js +3 -6
- package/dist/esm-node/cli/utils.spec.js +1 -1
- package/dist/esm-node/constant.js +1 -21
- package/dist/esm-node/runtime/index.js +1 -3
- package/dist/esm-node/ssr-runtime/plugin.js +7 -7
- package/dist/types/cli/constant.d.ts +1 -0
- package/dist/types/cli/mfRuntimePlugins/inject-node-fetch.d.ts +2 -2
- package/dist/types/cli/utils.d.ts +0 -2
- package/dist/types/constant.d.ts +0 -10
- package/dist/types/runtime/index.d.ts +0 -1
- package/dist/types/types/index.d.ts +0 -9
- package/package.json +11 -40
- package/dist/cjs/cli/dataLoader/ast/constant.js +0 -49
- package/dist/cjs/cli/dataLoader/ast/generateRoutes.js +0 -141
- package/dist/cjs/cli/dataLoader/generateRouteFile.js +0 -143
- package/dist/cjs/cli/dataLoader/patchMFConfig.js +0 -132
- package/dist/cjs/cli/dataLoader/plugin.js +0 -194
- package/dist/cjs/cli/mfRuntimePlugins/node.js +0 -44
- package/dist/cjs/cli/server/dataLoaderPlugin.js +0 -82
- package/dist/cjs/cli/server/fetchRemoteFullRoutesMap.js +0 -69
- package/dist/cjs/interfaces/route.js +0 -16
- package/dist/cjs/runtime/dataLoader/plugin.js +0 -73
- package/dist/cjs/runtime/dataLoader/utils.js +0 -89
- package/dist/cjs/runtime/utils.js +0 -38
- package/dist/cjs/runtime/withMFRouteId.js +0 -31
- package/dist/esm/cli/dataLoader/ast/constant.js +0 -18
- package/dist/esm/cli/dataLoader/ast/generateRoutes.js +0 -108
- package/dist/esm/cli/dataLoader/ast/index.js +0 -4
- package/dist/esm/cli/dataLoader/generateRouteFile.js +0 -293
- package/dist/esm/cli/dataLoader/patchMFConfig.js +0 -98
- package/dist/esm/cli/dataLoader/plugin.js +0 -209
- package/dist/esm/cli/mfRuntimePlugins/node.js +0 -16
- package/dist/esm/cli/server/dataLoaderPlugin.js +0 -105
- package/dist/esm/cli/server/fetchRemoteFullRoutesMap.js +0 -88
- package/dist/esm/interfaces/route.js +0 -0
- package/dist/esm/runtime/dataLoader/plugin.js +0 -92
- package/dist/esm/runtime/dataLoader/utils.js +0 -63
- package/dist/esm/runtime/utils.js +0 -13
- package/dist/esm/runtime/withMFRouteId.js +0 -7
- package/dist/esm-node/cli/dataLoader/ast/constant.js +0 -18
- package/dist/esm-node/cli/dataLoader/ast/generateRoutes.js +0 -107
- package/dist/esm-node/cli/dataLoader/ast/index.js +0 -4
- package/dist/esm-node/cli/dataLoader/generateRouteFile.js +0 -108
- package/dist/esm-node/cli/dataLoader/patchMFConfig.js +0 -98
- package/dist/esm-node/cli/dataLoader/plugin.js +0 -159
- package/dist/esm-node/cli/mfRuntimePlugins/node.js +0 -14
- package/dist/esm-node/cli/server/dataLoaderPlugin.js +0 -62
- package/dist/esm-node/cli/server/fetchRemoteFullRoutesMap.js +0 -44
- package/dist/esm-node/interfaces/route.js +0 -0
- package/dist/esm-node/runtime/dataLoader/plugin.js +0 -49
- package/dist/esm-node/runtime/dataLoader/utils.js +0 -63
- package/dist/esm-node/runtime/utils.js +0 -13
- package/dist/esm-node/runtime/withMFRouteId.js +0 -7
- package/dist/types/cli/dataLoader/ast/constant.d.ts +0 -8
- package/dist/types/cli/dataLoader/ast/generateRoutes.d.ts +0 -5
- package/dist/types/cli/dataLoader/ast/index.d.ts +0 -1
- package/dist/types/cli/dataLoader/generateRouteFile.d.ts +0 -7
- package/dist/types/cli/dataLoader/patchMFConfig.d.ts +0 -10
- package/dist/types/cli/dataLoader/plugin.d.ts +0 -6
- package/dist/types/cli/mfRuntimePlugins/node.d.ts +0 -3
- package/dist/types/cli/server/dataLoaderPlugin.d.ts +0 -10
- package/dist/types/cli/server/fetchRemoteFullRoutesMap.d.ts +0 -10
- package/dist/types/interfaces/route.d.ts +0 -12
- package/dist/types/runtime/dataLoader/plugin.d.ts +0 -2
- package/dist/types/runtime/dataLoader/utils.d.ts +0 -19
- package/dist/types/runtime/utils.d.ts +0 -2
- package/dist/types/runtime/withMFRouteId.d.ts +0 -1
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var patchMFConfig_exports = {};
|
|
30
|
-
__export(patchMFConfig_exports, {
|
|
31
|
-
patchMFConfig: () => patchMFConfig
|
|
32
|
-
});
|
|
33
|
-
module.exports = __toCommonJS(patchMFConfig_exports);
|
|
34
|
-
var import_path = __toESM(require("path"));
|
|
35
|
-
var import_utils = require("@modern-js/utils");
|
|
36
|
-
var import_constant = require("../../constant");
|
|
37
|
-
var import_constant2 = require("../../constant");
|
|
38
|
-
var import_ast = require("./ast");
|
|
39
|
-
function generateExtraExposeFiles(options) {
|
|
40
|
-
const { internalDirectory, mfConfig, isServer, entries } = options;
|
|
41
|
-
const entryMap = {};
|
|
42
|
-
const outputDir = import_path.default.resolve(process.cwd(), "node_modules/.federation/data-loader");
|
|
43
|
-
import_utils.fs.ensureDirSync(outputDir);
|
|
44
|
-
const addSuffix = (fileName, ext = ".jsx") => {
|
|
45
|
-
if (!isServer) {
|
|
46
|
-
return `${fileName}${ext}`;
|
|
47
|
-
}
|
|
48
|
-
return `${fileName}.server${ext}`;
|
|
49
|
-
};
|
|
50
|
-
const generateEntryRoutes = (entry) => {
|
|
51
|
-
const outputEntryDir = import_path.default.resolve(outputDir, entry);
|
|
52
|
-
import_utils.fs.ensureDirSync(outputEntryDir);
|
|
53
|
-
const sourceDir = import_path.default.resolve(internalDirectory, entry);
|
|
54
|
-
const routesFilePath = import_path.default.resolve(sourceDir, addSuffix(import_constant2.MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME, ".js"));
|
|
55
|
-
const routesFileContent = import_utils.fs.readFileSync(routesFilePath, "utf-8");
|
|
56
|
-
const outputFullRoutesPath = import_path.default.resolve(outputEntryDir, addSuffix(import_constant2.MF_ROUTES));
|
|
57
|
-
(0, import_ast.generateRoutes)({
|
|
58
|
-
sourceCode: routesFileContent,
|
|
59
|
-
filePath: outputFullRoutesPath
|
|
60
|
-
});
|
|
61
|
-
const routeServerLoaderPath = import_path.default.resolve(sourceDir, `${import_constant.MODERN_JS_ROUTE_SERVER_LOADER}.js`);
|
|
62
|
-
const outputRouteServerLoaderPath = import_path.default.resolve(outputEntryDir, `${import_constant.MODERN_JS_ROUTE_SERVER_LOADER}.js`);
|
|
63
|
-
if (isServer) {
|
|
64
|
-
const routeServerLoaderContent = import_utils.fs.readFileSync(routeServerLoaderPath, "utf-8");
|
|
65
|
-
(0, import_ast.generateRoutes)({
|
|
66
|
-
sourceCode: routeServerLoaderContent,
|
|
67
|
-
filePath: outputRouteServerLoaderPath
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
entryMap[entry] = {
|
|
71
|
-
routesPath: outputFullRoutesPath,
|
|
72
|
-
routeServerLoaderPath: outputRouteServerLoaderPath
|
|
73
|
-
};
|
|
74
|
-
};
|
|
75
|
-
entries.forEach((entry) => {
|
|
76
|
-
generateEntryRoutes(entry);
|
|
77
|
-
});
|
|
78
|
-
return {
|
|
79
|
-
entryMap
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
function addExpose(options) {
|
|
83
|
-
const { mfConfig, isServer } = options;
|
|
84
|
-
if (mfConfig.remotes && mfConfig.exposes) {
|
|
85
|
-
throw new Error(`dataLoader only support for pure provider/consumer !`);
|
|
86
|
-
}
|
|
87
|
-
const { entryMap } = generateExtraExposeFiles(options);
|
|
88
|
-
const addExposeByEntry = (entry, routesPath, routeServerLoaderPath) => {
|
|
89
|
-
if (!mfConfig.exposes) {
|
|
90
|
-
mfConfig.exposes = {};
|
|
91
|
-
}
|
|
92
|
-
const routesKey = `./${entry}/${import_constant2.MF_ROUTES}`;
|
|
93
|
-
if (!mfConfig.exposes[routesKey]) {
|
|
94
|
-
mfConfig.exposes[routesKey] = routesPath;
|
|
95
|
-
}
|
|
96
|
-
const routeServerLoaderKey = `./${entry}/${import_constant.MODERN_JS_ROUTE_SERVER_LOADER}`;
|
|
97
|
-
if (isServer && !mfConfig.exposes[routeServerLoaderKey]) {
|
|
98
|
-
mfConfig.exposes[routeServerLoaderKey] = routeServerLoaderPath;
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
Object.keys(entryMap).forEach((entry) => {
|
|
102
|
-
const { routesPath, routeServerLoaderPath } = entryMap[entry];
|
|
103
|
-
addExposeByEntry(entry, routesPath, routeServerLoaderPath);
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
function addShared(options) {
|
|
107
|
-
const { metaName, mfConfig } = options;
|
|
108
|
-
const alias = `@${metaName}/runtime/router`;
|
|
109
|
-
if (!mfConfig.shared) {
|
|
110
|
-
mfConfig.shared = {
|
|
111
|
-
[alias]: {
|
|
112
|
-
singleton: true
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
} else {
|
|
116
|
-
if (!Array.isArray(mfConfig.shared)) {
|
|
117
|
-
mfConfig.shared[alias] = {
|
|
118
|
-
singleton: true
|
|
119
|
-
};
|
|
120
|
-
} else {
|
|
121
|
-
mfConfig.shared.push(alias);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
function patchMFConfig(options) {
|
|
126
|
-
addShared(options);
|
|
127
|
-
addExpose(options);
|
|
128
|
-
}
|
|
129
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
130
|
-
0 && (module.exports = {
|
|
131
|
-
patchMFConfig
|
|
132
|
-
});
|
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var plugin_exports = {};
|
|
30
|
-
__export(plugin_exports, {
|
|
31
|
-
default: () => plugin_default,
|
|
32
|
-
generateRoutes: () => import_ast.generateRoutes,
|
|
33
|
-
moduleFederationDataLoaderPlugin: () => moduleFederationDataLoaderPlugin
|
|
34
|
-
});
|
|
35
|
-
module.exports = __toCommonJS(plugin_exports);
|
|
36
|
-
var import_utils = require("../../runtime/utils");
|
|
37
|
-
var import_constant = require("../../constant");
|
|
38
|
-
var import_constant2 = require("../../constant");
|
|
39
|
-
var import_ast = require("./ast");
|
|
40
|
-
var import_generateRouteFile = require("./generateRouteFile");
|
|
41
|
-
var import_patchMFConfig = require("./patchMFConfig");
|
|
42
|
-
var import_path = __toESM(require("path"));
|
|
43
|
-
function _transformRuntimeOptions(buildOptions) {
|
|
44
|
-
const remotes = buildOptions.remotes || {};
|
|
45
|
-
const runtimeRemotes = Object.entries(remotes).map((remote) => {
|
|
46
|
-
const [alias, nameAndEntry] = remote;
|
|
47
|
-
const [name, entry] = nameAndEntry.split("@");
|
|
48
|
-
return {
|
|
49
|
-
name,
|
|
50
|
-
entry,
|
|
51
|
-
alias
|
|
52
|
-
};
|
|
53
|
-
});
|
|
54
|
-
return {
|
|
55
|
-
name: buildOptions.name,
|
|
56
|
-
remotes: runtimeRemotes
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
const moduleFederationDataLoaderPlugin = (enable, internalOptions, userConfig) => ({
|
|
60
|
-
name: "@modern-js/plugin-module-federation-data-loader",
|
|
61
|
-
pre: [
|
|
62
|
-
"@modern-js/plugin-module-federation-config"
|
|
63
|
-
],
|
|
64
|
-
post: [
|
|
65
|
-
"@modern-js/plugin-router",
|
|
66
|
-
"@modern-js/plugin-module-federation"
|
|
67
|
-
],
|
|
68
|
-
setup: async ({ useAppContext }) => {
|
|
69
|
-
if (!enable) {
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
const {
|
|
73
|
-
// patchMFConfig,
|
|
74
|
-
metaName = import_constant2.META_NAME,
|
|
75
|
-
serverPlugin = "@module-federation/modern-js/data-loader-server",
|
|
76
|
-
transformRuntimeOptions
|
|
77
|
-
} = userConfig;
|
|
78
|
-
const appContext = useAppContext();
|
|
79
|
-
const name = internalOptions.csrConfig.name;
|
|
80
|
-
const internalDirectory = appContext.internalDirectory.replace(import_constant2.META_NAME, metaName || import_constant2.META_NAME);
|
|
81
|
-
const transformRuntimeFn = transformRuntimeOptions || _transformRuntimeOptions;
|
|
82
|
-
const partialSSRRemotes = [];
|
|
83
|
-
const entries = /* @__PURE__ */ new Set();
|
|
84
|
-
let remotePathMap = {};
|
|
85
|
-
const ssrByRouteIdsMap = {};
|
|
86
|
-
const serverPluginOptions = {
|
|
87
|
-
runtimeOptions: transformRuntimeFn(internalOptions.csrConfig),
|
|
88
|
-
partialSSRRemotes,
|
|
89
|
-
ssrByRouteIdsMap
|
|
90
|
-
};
|
|
91
|
-
const csrConfig = internalOptions.csrConfig;
|
|
92
|
-
if (typeof csrConfig.remotes === "object" && Object.keys(csrConfig.remotes).length) {
|
|
93
|
-
const { entries: scanEntries, remotePathMap: scanRemotePathMap } = await (0, import_generateRouteFile.generateRouteFile)({
|
|
94
|
-
appDirectory: appContext.appDirectory
|
|
95
|
-
});
|
|
96
|
-
scanEntries.forEach((e) => entries.add(e));
|
|
97
|
-
remotePathMap = scanRemotePathMap;
|
|
98
|
-
} else {
|
|
99
|
-
entries.add(import_constant.DEFAULT_ENTRY);
|
|
100
|
-
}
|
|
101
|
-
return {
|
|
102
|
-
_internalRuntimePlugins: ({ entrypoint, plugins }) => {
|
|
103
|
-
plugins.push({
|
|
104
|
-
name: "ssrDataLoader",
|
|
105
|
-
path: "@module-federation/modern-js/data-loader",
|
|
106
|
-
config: {}
|
|
107
|
-
});
|
|
108
|
-
return {
|
|
109
|
-
entrypoint,
|
|
110
|
-
plugins
|
|
111
|
-
};
|
|
112
|
-
},
|
|
113
|
-
_internalServerPlugins({ plugins }) {
|
|
114
|
-
plugins.push({
|
|
115
|
-
name: serverPlugin,
|
|
116
|
-
options: serverPluginOptions
|
|
117
|
-
});
|
|
118
|
-
return {
|
|
119
|
-
plugins
|
|
120
|
-
};
|
|
121
|
-
},
|
|
122
|
-
async modifyFileSystemRoutes(options) {
|
|
123
|
-
const { routes, entrypoint } = options;
|
|
124
|
-
const { entryName } = entrypoint;
|
|
125
|
-
const prefix = (0, import_utils.transformName2Prefix)(internalOptions.csrConfig.name);
|
|
126
|
-
const modifyRouteIds = (route, pathName) => {
|
|
127
|
-
const currentPathName = route.path ? import_path.default.join(pathName, route.path) : pathName;
|
|
128
|
-
if (route.id) {
|
|
129
|
-
var _route_children;
|
|
130
|
-
const originalId = route.id;
|
|
131
|
-
route.originalId = originalId;
|
|
132
|
-
const remoteName = remotePathMap[currentPathName];
|
|
133
|
-
if (remoteName) {
|
|
134
|
-
const remoteIdPrefix = (0, import_utils.transformName2Prefix)(remoteName);
|
|
135
|
-
const isLayout = Boolean(route.children);
|
|
136
|
-
const newId = `${remoteIdPrefix}${isLayout ? "layout" : "page"}`;
|
|
137
|
-
ssrByRouteIdsMap[originalId] = newId;
|
|
138
|
-
route.id = newId;
|
|
139
|
-
if (!partialSSRRemotes.includes(remoteName)) {
|
|
140
|
-
partialSSRRemotes.push(remoteName);
|
|
141
|
-
}
|
|
142
|
-
} else {
|
|
143
|
-
route.id = `${prefix}${route.id}`;
|
|
144
|
-
}
|
|
145
|
-
(_route_children = route.children) === null || _route_children === void 0 ? void 0 : _route_children.forEach((r) => {
|
|
146
|
-
modifyRouteIds(r, currentPathName);
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
};
|
|
150
|
-
routes.forEach((route) => {
|
|
151
|
-
modifyRouteIds(route, entryName);
|
|
152
|
-
});
|
|
153
|
-
return options;
|
|
154
|
-
},
|
|
155
|
-
config: async () => {
|
|
156
|
-
return {
|
|
157
|
-
tools: {
|
|
158
|
-
// bundlerChain can not keep target order
|
|
159
|
-
rspack(_config, { isServer }) {
|
|
160
|
-
(0, import_patchMFConfig.patchMFConfig)({
|
|
161
|
-
mfConfig: isServer ? internalOptions.ssrConfig : internalOptions.csrConfig,
|
|
162
|
-
metaName,
|
|
163
|
-
isServer,
|
|
164
|
-
internalDirectory,
|
|
165
|
-
entries
|
|
166
|
-
});
|
|
167
|
-
},
|
|
168
|
-
// bundlerChain can not keep target order
|
|
169
|
-
webpack(_config, { isServer }) {
|
|
170
|
-
(0, import_patchMFConfig.patchMFConfig)({
|
|
171
|
-
mfConfig: isServer ? internalOptions.ssrConfig : internalOptions.csrConfig,
|
|
172
|
-
metaName,
|
|
173
|
-
isServer,
|
|
174
|
-
internalDirectory,
|
|
175
|
-
entries
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
},
|
|
179
|
-
source: {
|
|
180
|
-
define: {
|
|
181
|
-
MODERN_ROUTER_ID_PREFIX: JSON.stringify((0, import_utils.transformName2Prefix)(name))
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
var plugin_default = moduleFederationDataLoaderPlugin;
|
|
190
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
191
|
-
0 && (module.exports = {
|
|
192
|
-
generateRoutes,
|
|
193
|
-
moduleFederationDataLoaderPlugin
|
|
194
|
-
});
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var node_exports = {};
|
|
30
|
-
__export(node_exports, {
|
|
31
|
-
default: () => node_default
|
|
32
|
-
});
|
|
33
|
-
module.exports = __toCommonJS(node_exports);
|
|
34
|
-
var import_node_fetch = __toESM(require("node-fetch"));
|
|
35
|
-
const injectNodeFetchPlugin = () => ({
|
|
36
|
-
name: "inject-node-fetch-plugin",
|
|
37
|
-
beforeInit(args) {
|
|
38
|
-
if (!globalThis.fetch) {
|
|
39
|
-
globalThis.fetch = import_node_fetch.default;
|
|
40
|
-
}
|
|
41
|
-
return args;
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
var node_default = injectNodeFetchPlugin;
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var dataLoaderPlugin_exports = {};
|
|
20
|
-
__export(dataLoaderPlugin_exports, {
|
|
21
|
-
default: () => dataLoaderPlugin_default
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(dataLoaderPlugin_exports);
|
|
24
|
-
var import_runtime = require("@module-federation/enhanced/runtime");
|
|
25
|
-
var import_sdk = require("@module-federation/sdk");
|
|
26
|
-
var import_fetchRemoteFullRoutesMap = require("./fetchRemoteFullRoutesMap");
|
|
27
|
-
var import_utils = require("../../runtime/dataLoader/utils");
|
|
28
|
-
var import_constant = require("../../constant");
|
|
29
|
-
var dataLoaderPlugin_default = ({ runtimeOptions, partialSSRRemotes, ssrByRouteIdsMap }) => ({
|
|
30
|
-
name: "MFDataLoaderServerPlugin",
|
|
31
|
-
pre: [
|
|
32
|
-
"@modern-js/plugin-inject-resource"
|
|
33
|
-
],
|
|
34
|
-
setup(api) {
|
|
35
|
-
const { remotes, name } = runtimeOptions;
|
|
36
|
-
if (!remotes.length) {
|
|
37
|
-
return {};
|
|
38
|
-
}
|
|
39
|
-
let isHandled = false;
|
|
40
|
-
return {
|
|
41
|
-
prepare() {
|
|
42
|
-
const { middlewares } = api.useAppContext();
|
|
43
|
-
middlewares.push({
|
|
44
|
-
name: "MFDataLoaderServerPlugin",
|
|
45
|
-
handler: async (c, next) => {
|
|
46
|
-
const serverManifest = c.get("serverManifest");
|
|
47
|
-
const { loaderBundles, nestedRoutesJson } = serverManifest;
|
|
48
|
-
if (isHandled) {
|
|
49
|
-
await next();
|
|
50
|
-
} else {
|
|
51
|
-
var _api_useConfigContext_server;
|
|
52
|
-
const instance = (0, import_runtime.init)({
|
|
53
|
-
name,
|
|
54
|
-
remotes
|
|
55
|
-
});
|
|
56
|
-
const remoteFullRoutesMap = await (0, import_fetchRemoteFullRoutesMap.fetchRemoteFullRoutesMap)({
|
|
57
|
-
instance,
|
|
58
|
-
remotePath: (0, import_sdk.isBrowserEnv)() ? `${import_constant.DEFAULT_ENTRY}/${import_constant.MF_ROUTES}` : `${import_constant.DEFAULT_ENTRY}/${import_constant.MODERN_JS_ROUTE_SERVER_LOADER}`
|
|
59
|
-
});
|
|
60
|
-
const originalSSRByRouteIds = (_api_useConfigContext_server = api.useConfigContext().server) === null || _api_useConfigContext_server === void 0 ? void 0 : _api_useConfigContext_server.ssrByRouteIds;
|
|
61
|
-
if (originalSSRByRouteIds && partialSSRRemotes.length) {
|
|
62
|
-
const remoteSSRByRouteIds = (0, import_fetchRemoteFullRoutesMap.getSSRByRouteIds)(partialSSRRemotes, remoteFullRoutesMap) || [];
|
|
63
|
-
const ssrByRouteIds = /* @__PURE__ */ new Set([
|
|
64
|
-
...originalSSRByRouteIds,
|
|
65
|
-
...remoteSSRByRouteIds.map((id) => ssrByRouteIdsMap[id] || id)
|
|
66
|
-
]);
|
|
67
|
-
api.useConfigContext().server.ssrByRouteIds = Array.from(ssrByRouteIds);
|
|
68
|
-
}
|
|
69
|
-
(0, import_utils.injectRemoteRoutes)(loaderBundles, remoteFullRoutesMap);
|
|
70
|
-
(0, import_utils.injectRemoteRoutes)(nestedRoutesJson, remoteFullRoutesMap);
|
|
71
|
-
isHandled = true;
|
|
72
|
-
await next();
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
before: [
|
|
76
|
-
"render"
|
|
77
|
-
]
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
});
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var fetchRemoteFullRoutesMap_exports = {};
|
|
20
|
-
__export(fetchRemoteFullRoutesMap_exports, {
|
|
21
|
-
fetchRemoteFullRoutesMap: () => fetchRemoteFullRoutesMap,
|
|
22
|
-
getSSRByRouteIds: () => getSSRByRouteIds
|
|
23
|
-
});
|
|
24
|
-
module.exports = __toCommonJS(fetchRemoteFullRoutesMap_exports);
|
|
25
|
-
async function fetchRemoteFullRoutesMap(options) {
|
|
26
|
-
const { instance, remotePath } = options;
|
|
27
|
-
const { remotes } = instance.options;
|
|
28
|
-
const remoteRoutesMap = {};
|
|
29
|
-
if (!remotes.length) {
|
|
30
|
-
return remoteRoutesMap;
|
|
31
|
-
}
|
|
32
|
-
await Promise.all(remotes.map(async (remote) => {
|
|
33
|
-
const remoteId = `${remote.name}/${remotePath}`;
|
|
34
|
-
const { routes } = await instance.loadRemote(remoteId);
|
|
35
|
-
remoteRoutesMap[remote.name] = {
|
|
36
|
-
routes
|
|
37
|
-
};
|
|
38
|
-
}));
|
|
39
|
-
return remoteRoutesMap;
|
|
40
|
-
}
|
|
41
|
-
function getSSRByRouteIds(partialSSRRemotes, remoteRoutesMap) {
|
|
42
|
-
const remoteProviderRouteIds = /* @__PURE__ */ new Set();
|
|
43
|
-
const collectIds = (route) => {
|
|
44
|
-
remoteProviderRouteIds.add(route.id);
|
|
45
|
-
if (route.children) {
|
|
46
|
-
route.children.forEach((r) => {
|
|
47
|
-
collectIds(r);
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
Object.entries(remoteRoutesMap).forEach((item) => {
|
|
52
|
-
const [remoteName, routesObj] = item;
|
|
53
|
-
if (!partialSSRRemotes.includes(remoteName)) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
const { routes } = routesObj;
|
|
57
|
-
routes.forEach((route) => {
|
|
58
|
-
collectIds(route);
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
return [
|
|
62
|
-
...remoteProviderRouteIds
|
|
63
|
-
];
|
|
64
|
-
}
|
|
65
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
66
|
-
0 && (module.exports = {
|
|
67
|
-
fetchRemoteFullRoutesMap,
|
|
68
|
-
getSSRByRouteIds
|
|
69
|
-
});
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __copyProps = (to, from, except, desc) => {
|
|
7
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
-
for (let key of __getOwnPropNames(from))
|
|
9
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
-
}
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
-
var route_exports = {};
|
|
16
|
-
module.exports = __toCommonJS(route_exports);
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var plugin_exports = {};
|
|
20
|
-
__export(plugin_exports, {
|
|
21
|
-
ssrDataLoaderPlugin: () => ssrDataLoaderPlugin
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(plugin_exports);
|
|
24
|
-
var import_runtime = require("@module-federation/enhanced/runtime");
|
|
25
|
-
var import_constant = require("../../constant");
|
|
26
|
-
var import_utils = require("./utils");
|
|
27
|
-
const ssrDataLoaderPlugin = () => {
|
|
28
|
-
return {
|
|
29
|
-
name: "@modern-js/plugin-mf-data-loader",
|
|
30
|
-
post: [
|
|
31
|
-
"@modern-js/plugin-router"
|
|
32
|
-
],
|
|
33
|
-
setup: () => {
|
|
34
|
-
const remoteRoutesMap = {};
|
|
35
|
-
return {
|
|
36
|
-
async beforeRender() {
|
|
37
|
-
console.log("init");
|
|
38
|
-
if (Object.keys(remoteRoutesMap).length) {
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
const instance = (0, import_runtime.getInstance)();
|
|
42
|
-
if (!instance) {
|
|
43
|
-
console.log("no instance!");
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
if (!instance.options.remotes.length) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
await Promise.all(instance.options.remotes.map(async (remote) => {
|
|
50
|
-
const remoteId = `${remote.name}/${import_constant.DEFAULT_ENTRY}/${import_constant.MF_ROUTES}`;
|
|
51
|
-
const { routes } = await instance.loadRemote(remoteId);
|
|
52
|
-
remoteRoutesMap[remote.name] = {
|
|
53
|
-
routes
|
|
54
|
-
};
|
|
55
|
-
}));
|
|
56
|
-
},
|
|
57
|
-
// runtime plugin not save route , so it needs to inject again when trigger
|
|
58
|
-
modifyRoutes: (routes) => {
|
|
59
|
-
(0, import_utils.injectRemoteRoutes)({
|
|
60
|
-
entry: {
|
|
61
|
-
routes
|
|
62
|
-
}
|
|
63
|
-
}, remoteRoutesMap);
|
|
64
|
-
return routes;
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
};
|
|
70
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
71
|
-
0 && (module.exports = {
|
|
72
|
-
ssrDataLoaderPlugin
|
|
73
|
-
});
|