@modern-js/plugin-garfish 2.3.0 → 2.4.1-beta.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/CHANGELOG.md +30 -0
- package/README.md +14 -18
- package/dist/js/modern/cli/index.js +10 -7
- package/dist/js/modern/cli/utils.js +1 -1
- package/dist/js/modern/runtime/utils/apps.js +8 -1
- package/dist/js/node/cli/index.js +10 -7
- package/dist/js/node/cli/utils.js +1 -1
- package/dist/js/node/runtime/utils/apps.js +8 -1
- package/dist/js/treeshaking/cli/index.js +27 -22
- package/dist/js/treeshaking/cli/utils.js +7 -7
- package/dist/js/treeshaking/runtime/loadable.js +5 -5
- package/dist/js/treeshaking/runtime/plugin.js +7 -7
- package/dist/js/treeshaking/runtime/useModuleApps.js +1 -1
- package/dist/js/treeshaking/runtime/utils/MApp.js +3 -3
- package/dist/js/treeshaking/runtime/utils/apps.js +17 -13
- package/package.json +11 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# @modern-js/plugin-garfish
|
|
2
2
|
|
|
3
|
+
## 2.4.1-beta.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [7a25271]
|
|
8
|
+
- Updated dependencies [11c053b]
|
|
9
|
+
- Updated dependencies [a0f2ab1]
|
|
10
|
+
- @modern-js/runtime@2.4.1-beta.0
|
|
11
|
+
- @modern-js/utils@2.4.1-beta.0
|
|
12
|
+
|
|
13
|
+
## 2.4.0
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- b55f8c6: fix(garfish): load microApp can not match it's route
|
|
18
|
+
fix(garfish): server.baseUrl is in preference to router.basename
|
|
19
|
+
|
|
20
|
+
修复微前端模式下约定式路由和自控式路由子应用无法正确加载问题
|
|
21
|
+
修复 basename 优先级问题 server.baseUrl 高于 router.basename
|
|
22
|
+
|
|
23
|
+
- 8c2db5f: feat(core): improve support for exporting a function in config file
|
|
24
|
+
|
|
25
|
+
feat(core): 完善对配置文件中导出函数的支持
|
|
26
|
+
|
|
27
|
+
- Updated dependencies [98a2733]
|
|
28
|
+
- Updated dependencies [9e907ec]
|
|
29
|
+
- Updated dependencies [8c2db5f]
|
|
30
|
+
- @modern-js/utils@2.4.0
|
|
31
|
+
- @modern-js/runtime@2.4.0
|
|
32
|
+
|
|
3
33
|
## 2.3.0
|
|
4
34
|
|
|
5
35
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -1,30 +1,26 @@
|
|
|
1
|
-
|
|
2
1
|
<p align="center">
|
|
3
2
|
<a href="https://modernjs.dev" target="blank"><img src="https://lf3-static.bytednsdoc.com/obj/eden-cn/ylaelkeh7nuhfnuhf/modernjs-cover.png" width="300" alt="Modern.js Logo" /></a>
|
|
4
3
|
</p>
|
|
4
|
+
|
|
5
|
+
<h1 align="center">Modern.js</h1>
|
|
6
|
+
|
|
5
7
|
<p align="center">
|
|
6
|
-
|
|
7
|
-
<br/>
|
|
8
|
-
<a href="https://modernjs.dev" target="blank">
|
|
9
|
-
modernjs.dev
|
|
10
|
-
</a>
|
|
11
|
-
</p>
|
|
12
|
-
<p align="center">
|
|
13
|
-
The meta-framework suite designed from scratch for frontend-focused modern web development
|
|
8
|
+
A Progressive React Framework for modern web development.
|
|
14
9
|
</p>
|
|
15
10
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
> The doc site ([modernjs.dev](https://modernjs.dev)) and articles are only available in Chinese for now, we are planning to add English versions soon.
|
|
11
|
+
## Getting Started
|
|
19
12
|
|
|
20
|
-
|
|
13
|
+
Please follow [Quick Start](https://modernjs.dev/en/guides/get-started/quick-start) to get started with Modern.js.
|
|
21
14
|
|
|
22
|
-
##
|
|
15
|
+
## Documentation
|
|
23
16
|
|
|
24
|
-
- [
|
|
25
|
-
- [
|
|
26
|
-
- [API References](https://modernjs.dev/docs/apis)
|
|
17
|
+
- [English Documentation](https://modernjs.dev/en/)
|
|
18
|
+
- [中文文档](https://modernjs.dev)
|
|
27
19
|
|
|
28
20
|
## Contributing
|
|
29
21
|
|
|
30
|
-
|
|
22
|
+
Please read the [Contributing Guide](https://github.com/modern-js-dev/modern.js/blob/main/CONTRIBUTING.md).
|
|
23
|
+
|
|
24
|
+
## License
|
|
25
|
+
|
|
26
|
+
Modern.js is [MIT licensed](https://github.com/modern-js-dev/modern.js/blob/main/LICENSE).
|
|
@@ -69,20 +69,27 @@ var cli_default = ({
|
|
|
69
69
|
return PLUGIN_SCHEMAS["@modern-js/plugin-garfish"];
|
|
70
70
|
},
|
|
71
71
|
resolvedConfig: (config) => __async(void 0, null, function* () {
|
|
72
|
-
var _a;
|
|
72
|
+
var _a, _b;
|
|
73
73
|
const { resolved } = config;
|
|
74
74
|
const { masterApp, router } = getRuntimeConfig(resolved);
|
|
75
75
|
const nConfig = {
|
|
76
76
|
resolved: __spreadValues({}, resolved)
|
|
77
77
|
};
|
|
78
78
|
if (masterApp) {
|
|
79
|
+
const useConfig = useConfigContext();
|
|
80
|
+
const baseUrl = (_a = useConfig == null ? void 0 : useConfig.server) == null ? void 0 : _a.baseUrl;
|
|
81
|
+
if (Array.isArray(baseUrl)) {
|
|
82
|
+
throw new Error(
|
|
83
|
+
"Now Micro-Front-End mode dose not support multiple baseUrl, you can set it as a string"
|
|
84
|
+
);
|
|
85
|
+
}
|
|
79
86
|
setRuntimeConfig(
|
|
80
87
|
nConfig.resolved,
|
|
81
88
|
"masterApp",
|
|
82
89
|
Object.assign(
|
|
83
90
|
typeof masterApp === "object" ? __spreadValues({}, masterApp) : {},
|
|
84
91
|
{
|
|
85
|
-
basename: ((
|
|
92
|
+
basename: baseUrl || ((_b = router == null ? void 0 : router.historyOptions) == null ? void 0 : _b.basename) || (router == null ? void 0 : router.basename) || "/"
|
|
86
93
|
}
|
|
87
94
|
)
|
|
88
95
|
);
|
|
@@ -129,11 +136,7 @@ var cli_default = ({
|
|
|
129
136
|
"Access-Control-Allow-Origin": "*"
|
|
130
137
|
}
|
|
131
138
|
},
|
|
132
|
-
webpackChain: (chain, {
|
|
133
|
-
webpack,
|
|
134
|
-
env = process.env.NODE_ENV || "development",
|
|
135
|
-
CHAIN_ID
|
|
136
|
-
}) => {
|
|
139
|
+
webpackChain: (chain, { webpack, env, CHAIN_ID }) => {
|
|
137
140
|
var _a2, _b2, _c2, _d, _e;
|
|
138
141
|
const resolveOptions = useResolvedConfigContext();
|
|
139
142
|
if ((_a2 = resolveOptions == null ? void 0 : resolveOptions.deploy) == null ? void 0 : _a2.microFrontend) {
|
|
@@ -83,7 +83,7 @@ const makeRenderFunction = (code) => {
|
|
|
83
83
|
const inGarfishToRender = `
|
|
84
84
|
const { basename, props, dom, appName } = typeof arguments[0] === 'object' && arguments[0] || {};
|
|
85
85
|
if (!canContinueRender({ dom, appName })) return null;
|
|
86
|
-
let { AppWrapper, mountNode } = generateAppWrapperAndRootDom({App, props, dom});
|
|
86
|
+
let { AppWrapper, mountNode } = generateAppWrapperAndRootDom({App, props: {...props, basename}, dom});
|
|
87
87
|
`;
|
|
88
88
|
return inGarfishToRender + code.replace(`router(`, `generateRouterPlugin(basename,`).replace("(App)", `(AppWrapper)`).replace(/MOUNT_ID/g, "mountNode").replace(
|
|
89
89
|
`bootstrap(AppWrapper, mountNode, root`,
|
|
@@ -85,7 +85,14 @@ function getAppInstance(options, appInfo, manifest) {
|
|
|
85
85
|
const location = (_f = (_e = context == null ? void 0 : context.router) == null ? void 0 : _e.useLocation) == null ? void 0 : _f.call(_e);
|
|
86
86
|
let basename = (options == null ? void 0 : options.basename) || "/";
|
|
87
87
|
if (matchs && matchs.length > 0) {
|
|
88
|
-
|
|
88
|
+
const matchItem = __spreadValues({}, matchs[matchs.length - 1]);
|
|
89
|
+
for (const key in matchItem.params) {
|
|
90
|
+
matchItem.pathname = matchItem.pathname.replace(
|
|
91
|
+
new RegExp(`/${matchItem.params[key]}$`),
|
|
92
|
+
""
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
basename = pathJoin(basename, matchItem.pathname || "/");
|
|
89
96
|
} else if (match) {
|
|
90
97
|
basename = pathJoin(basename, (match == null ? void 0 : match.path) || "/");
|
|
91
98
|
}
|
|
@@ -85,20 +85,27 @@ var cli_default = ({
|
|
|
85
85
|
return import_utils.PLUGIN_SCHEMAS["@modern-js/plugin-garfish"];
|
|
86
86
|
},
|
|
87
87
|
resolvedConfig: (config) => __async(void 0, null, function* () {
|
|
88
|
-
var _a;
|
|
88
|
+
var _a, _b;
|
|
89
89
|
const { resolved } = config;
|
|
90
90
|
const { masterApp, router } = (0, import_utils2.getRuntimeConfig)(resolved);
|
|
91
91
|
const nConfig = {
|
|
92
92
|
resolved: __spreadValues({}, resolved)
|
|
93
93
|
};
|
|
94
94
|
if (masterApp) {
|
|
95
|
+
const useConfig = useConfigContext();
|
|
96
|
+
const baseUrl = (_a = useConfig == null ? void 0 : useConfig.server) == null ? void 0 : _a.baseUrl;
|
|
97
|
+
if (Array.isArray(baseUrl)) {
|
|
98
|
+
throw new Error(
|
|
99
|
+
"Now Micro-Front-End mode dose not support multiple baseUrl, you can set it as a string"
|
|
100
|
+
);
|
|
101
|
+
}
|
|
95
102
|
(0, import_utils2.setRuntimeConfig)(
|
|
96
103
|
nConfig.resolved,
|
|
97
104
|
"masterApp",
|
|
98
105
|
Object.assign(
|
|
99
106
|
typeof masterApp === "object" ? __spreadValues({}, masterApp) : {},
|
|
100
107
|
{
|
|
101
|
-
basename: ((
|
|
108
|
+
basename: baseUrl || ((_b = router == null ? void 0 : router.historyOptions) == null ? void 0 : _b.basename) || (router == null ? void 0 : router.basename) || "/"
|
|
102
109
|
}
|
|
103
110
|
)
|
|
104
111
|
);
|
|
@@ -145,11 +152,7 @@ var cli_default = ({
|
|
|
145
152
|
"Access-Control-Allow-Origin": "*"
|
|
146
153
|
}
|
|
147
154
|
},
|
|
148
|
-
webpackChain: (chain, {
|
|
149
|
-
webpack,
|
|
150
|
-
env = process.env.NODE_ENV || "development",
|
|
151
|
-
CHAIN_ID
|
|
152
|
-
}) => {
|
|
155
|
+
webpackChain: (chain, { webpack, env, CHAIN_ID }) => {
|
|
153
156
|
var _a2, _b2, _c2, _d, _e;
|
|
154
157
|
const resolveOptions = useResolvedConfigContext();
|
|
155
158
|
if ((_a2 = resolveOptions == null ? void 0 : resolveOptions.deploy) == null ? void 0 : _a2.microFrontend) {
|
|
@@ -109,7 +109,7 @@ const makeRenderFunction = (code) => {
|
|
|
109
109
|
const inGarfishToRender = `
|
|
110
110
|
const { basename, props, dom, appName } = typeof arguments[0] === 'object' && arguments[0] || {};
|
|
111
111
|
if (!canContinueRender({ dom, appName })) return null;
|
|
112
|
-
let { AppWrapper, mountNode } = generateAppWrapperAndRootDom({App, props, dom});
|
|
112
|
+
let { AppWrapper, mountNode } = generateAppWrapperAndRootDom({App, props: {...props, basename}, dom});
|
|
113
113
|
`;
|
|
114
114
|
return inGarfishToRender + code.replace(`router(`, `generateRouterPlugin(basename,`).replace("(App)", `(AppWrapper)`).replace(/MOUNT_ID/g, "mountNode").replace(
|
|
115
115
|
`bootstrap(AppWrapper, mountNode, root`,
|
|
@@ -112,7 +112,14 @@ function getAppInstance(options, appInfo, manifest) {
|
|
|
112
112
|
const location = (_f = (_e = context == null ? void 0 : context.router) == null ? void 0 : _e.useLocation) == null ? void 0 : _f.call(_e);
|
|
113
113
|
let basename = (options == null ? void 0 : options.basename) || "/";
|
|
114
114
|
if (matchs && matchs.length > 0) {
|
|
115
|
-
|
|
115
|
+
const matchItem = __spreadValues({}, matchs[matchs.length - 1]);
|
|
116
|
+
for (const key in matchItem.params) {
|
|
117
|
+
matchItem.pathname = matchItem.pathname.replace(
|
|
118
|
+
new RegExp(`/${matchItem.params[key]}$`),
|
|
119
|
+
""
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
basename = pathJoin(basename, matchItem.pathname || "/");
|
|
116
123
|
} else if (match) {
|
|
117
124
|
basename = pathJoin(basename, (match == null ? void 0 : match.path) || "/");
|
|
118
125
|
}
|
|
@@ -171,7 +171,7 @@ function getDefaultMicroFrontedConfig(microFrontend) {
|
|
|
171
171
|
}, microFrontend);
|
|
172
172
|
}
|
|
173
173
|
var cli_default = function() {
|
|
174
|
-
var
|
|
174
|
+
var _ref = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, _ref_pluginName = _ref.pluginName, pluginName = _ref_pluginName === void 0 ? "@modern-js/plugin-garfish" : _ref_pluginName, _ref_runtimePluginName = _ref.runtimePluginName, runtimePluginName = _ref_runtimePluginName === void 0 ? "@modern-js/runtime/plugins" : _ref_runtimePluginName;
|
|
175
175
|
return {
|
|
176
176
|
name: "@modern-js/plugin-garfish",
|
|
177
177
|
setup: function(param) {
|
|
@@ -183,17 +183,22 @@ var cli_default = function() {
|
|
|
183
183
|
},
|
|
184
184
|
resolvedConfig: function() {
|
|
185
185
|
var _ref = _asyncToGenerator(function(config) {
|
|
186
|
-
var resolved,
|
|
186
|
+
var resolved, _getRuntimeConfig, masterApp, router, nConfig, _useConfig_server, _router_historyOptions, useConfig, baseUrl;
|
|
187
187
|
return __generator(this, function(_state) {
|
|
188
188
|
resolved = config.resolved;
|
|
189
|
-
|
|
189
|
+
_getRuntimeConfig = getRuntimeConfig(resolved), masterApp = _getRuntimeConfig.masterApp, router = _getRuntimeConfig.router;
|
|
190
190
|
nConfig = {
|
|
191
191
|
resolved: _objectSpread({}, resolved)
|
|
192
192
|
};
|
|
193
193
|
if (masterApp) {
|
|
194
194
|
;
|
|
195
|
+
useConfig = useConfigContext();
|
|
196
|
+
baseUrl = useConfig === null || useConfig === void 0 ? void 0 : (_useConfig_server = useConfig.server) === null || _useConfig_server === void 0 ? void 0 : _useConfig_server.baseUrl;
|
|
197
|
+
if (Array.isArray(baseUrl)) {
|
|
198
|
+
throw new Error("Now Micro-Front-End mode dose not support multiple baseUrl, you can set it as a string");
|
|
199
|
+
}
|
|
195
200
|
setRuntimeConfig(nConfig.resolved, "masterApp", Object.assign(typeof masterApp === "object" ? _objectSpread({}, masterApp) : {}, {
|
|
196
|
-
basename: (router === null || router === void 0 ? void 0 : (
|
|
201
|
+
basename: baseUrl || (router === null || router === void 0 ? void 0 : (_router_historyOptions = router.historyOptions) === null || _router_historyOptions === void 0 ? void 0 : _router_historyOptions.basename) || (router === null || router === void 0 ? void 0 : router.basename) || "/"
|
|
197
202
|
}));
|
|
198
203
|
}
|
|
199
204
|
logger("resolvedConfig", {
|
|
@@ -213,15 +218,15 @@ var cli_default = function() {
|
|
|
213
218
|
};
|
|
214
219
|
}(),
|
|
215
220
|
config: function config() {
|
|
216
|
-
var
|
|
221
|
+
var _useConfig_output, _useConfig_deploy;
|
|
217
222
|
var useConfig = useConfigContext();
|
|
218
223
|
logger("useConfig", useConfig);
|
|
219
224
|
var config = useAppContext();
|
|
220
225
|
pluginsExportsUtils = createRuntimeExportsUtils(config.internalDirectory, "plugins");
|
|
221
|
-
var disableCssExtract = ((
|
|
222
|
-
if ((
|
|
223
|
-
var
|
|
224
|
-
var enableHtmlEntry = getDefaultMicroFrontedConfig((
|
|
226
|
+
var disableCssExtract = ((_useConfig_output = useConfig.output) === null || _useConfig_output === void 0 ? void 0 : _useConfig_output.disableCssExtract) || false;
|
|
227
|
+
if ((_useConfig_deploy = useConfig.deploy) === null || _useConfig_deploy === void 0 ? void 0 : _useConfig_deploy.microFrontend) {
|
|
228
|
+
var _useConfig_deploy1;
|
|
229
|
+
var enableHtmlEntry = getDefaultMicroFrontedConfig((_useConfig_deploy1 = useConfig.deploy) === null || _useConfig_deploy1 === void 0 ? void 0 : _useConfig_deploy1.microFrontend).enableHtmlEntry;
|
|
225
230
|
if (!enableHtmlEntry) {
|
|
226
231
|
disableCssExtract = true;
|
|
227
232
|
}
|
|
@@ -243,13 +248,13 @@ var cli_default = function() {
|
|
|
243
248
|
}
|
|
244
249
|
},
|
|
245
250
|
webpackChain: function(chain, param) {
|
|
246
|
-
var webpack = param.webpack,
|
|
247
|
-
var
|
|
251
|
+
var webpack = param.webpack, env = param.env, CHAIN_ID = param.CHAIN_ID;
|
|
252
|
+
var _resolveOptions_deploy, _resolveWebpackConfig_resolve;
|
|
248
253
|
var resolveOptions = useResolvedConfigContext();
|
|
249
|
-
if (resolveOptions === null || resolveOptions === void 0 ? void 0 : (
|
|
250
|
-
var
|
|
254
|
+
if (resolveOptions === null || resolveOptions === void 0 ? void 0 : (_resolveOptions_deploy = resolveOptions.deploy) === null || _resolveOptions_deploy === void 0 ? void 0 : _resolveOptions_deploy.microFrontend) {
|
|
255
|
+
var _useConfig_dev, _resolveOptions_server, _resolveOptions_deploy1;
|
|
251
256
|
chain.output.libraryTarget("umd");
|
|
252
|
-
if (!((
|
|
257
|
+
if (!((_useConfig_dev = useConfig.dev) === null || _useConfig_dev === void 0 ? void 0 : _useConfig_dev.assetPrefix) && (resolveOptions === null || resolveOptions === void 0 ? void 0 : (_resolveOptions_server = resolveOptions.server) === null || _resolveOptions_server === void 0 ? void 0 : _resolveOptions_server.port) && env === "development") {
|
|
253
258
|
chain.output.publicPath("//localhost:".concat(resolveOptions.server.port, "/"));
|
|
254
259
|
}
|
|
255
260
|
if (webpack.BannerPlugin) {
|
|
@@ -259,7 +264,7 @@ var cli_default = function() {
|
|
|
259
264
|
}
|
|
260
265
|
]);
|
|
261
266
|
}
|
|
262
|
-
var
|
|
267
|
+
var _getDefaultMicroFrontedConfig = getDefaultMicroFrontedConfig((_resolveOptions_deploy1 = resolveOptions.deploy) === null || _resolveOptions_deploy1 === void 0 ? void 0 : _resolveOptions_deploy1.microFrontend), enableHtmlEntry = _getDefaultMicroFrontedConfig.enableHtmlEntry, externalBasicLibrary = _getDefaultMicroFrontedConfig.externalBasicLibrary;
|
|
263
268
|
if (externalBasicLibrary) {
|
|
264
269
|
chain.externals(externals);
|
|
265
270
|
}
|
|
@@ -277,7 +282,7 @@ var cli_default = function() {
|
|
|
277
282
|
output: resolveWebpackConfig.output,
|
|
278
283
|
externals: resolveWebpackConfig.externals,
|
|
279
284
|
env: env,
|
|
280
|
-
alias: (
|
|
285
|
+
alias: (_resolveWebpackConfig_resolve = resolveWebpackConfig.resolve) === null || _resolveWebpackConfig_resolve === void 0 ? void 0 : _resolveWebpackConfig_resolve.alias,
|
|
281
286
|
plugins: resolveWebpackConfig.plugins
|
|
282
287
|
});
|
|
283
288
|
}
|
|
@@ -361,9 +366,9 @@ var cli_default = function() {
|
|
|
361
366
|
},
|
|
362
367
|
modifyEntryRenderFunction: function modifyEntryRenderFunction(param) {
|
|
363
368
|
var entrypoint = param.entrypoint, code = param.code;
|
|
364
|
-
var
|
|
369
|
+
var _config_deploy;
|
|
365
370
|
var config = useResolvedConfigContext();
|
|
366
|
-
if (!(config === null || config === void 0 ? void 0 : (
|
|
371
|
+
if (!(config === null || config === void 0 ? void 0 : (_config_deploy = config.deploy) === null || _config_deploy === void 0 ? void 0 : _config_deploy.microFrontend)) {
|
|
367
372
|
return {
|
|
368
373
|
entrypoint: entrypoint,
|
|
369
374
|
code: code
|
|
@@ -378,10 +383,10 @@ var cli_default = function() {
|
|
|
378
383
|
},
|
|
379
384
|
modifyAsyncEntry: function modifyAsyncEntry(param) {
|
|
380
385
|
var entrypoint = param.entrypoint, code = param.code;
|
|
381
|
-
var
|
|
386
|
+
var _config_deploy, _config_source;
|
|
382
387
|
var config = useResolvedConfigContext();
|
|
383
388
|
var finalCode = code;
|
|
384
|
-
if ((config === null || config === void 0 ? void 0 : (
|
|
389
|
+
if ((config === null || config === void 0 ? void 0 : (_config_deploy = config.deploy) === null || _config_deploy === void 0 ? void 0 : _config_deploy.microFrontend) && (config === null || config === void 0 ? void 0 : (_config_source = config.source) === null || _config_source === void 0 ? void 0 : _config_source.enableAsyncEntry)) {
|
|
385
390
|
finalCode = generateAsyncEntry(code);
|
|
386
391
|
return {
|
|
387
392
|
entrypoint: entrypoint,
|
|
@@ -395,9 +400,9 @@ var cli_default = function() {
|
|
|
395
400
|
},
|
|
396
401
|
modifyEntryExport: function modifyEntryExport(param) {
|
|
397
402
|
var entrypoint = param.entrypoint, exportStatement = param.exportStatement;
|
|
398
|
-
var
|
|
403
|
+
var _config_deploy;
|
|
399
404
|
var config = useResolvedConfigContext();
|
|
400
|
-
if (config === null || config === void 0 ? void 0 : (
|
|
405
|
+
if (config === null || config === void 0 ? void 0 : (_config_deploy = config.deploy) === null || _config_deploy === void 0 ? void 0 : _config_deploy.microFrontend) {
|
|
401
406
|
var exportStatementCode = makeProvider();
|
|
402
407
|
logger("exportStatement", exportStatementCode);
|
|
403
408
|
return {
|
|
@@ -2,20 +2,20 @@ var makeProvider = function() {
|
|
|
2
2
|
return "\nexport const provider = function ({basename, dom}) {\n return {\n render({basename, dom, props, appName}) {\n render({ props, basename, dom, appName });\n },\n destroy({ dom }) {\n const node = dom.querySelector('#' + MOUNT_ID) || dom;\n\n if (node) {\n if (IS_REACT18) {\n root.unmount();\n } else {\n unmountComponentAtNode(node);\n }\n }\n },\n SubModuleComponent: (props) => {\n const SubApp = render({props, basename});\n\n return createPortal(<SubApp />, dom.querySelector('#' + MOUNT_ID) || dom);\n },\n jupiter_submodule_app_key: (props) => {\n const SubApp = render({props, basename});\n\n return createPortal(<SubApp />, dom.querySelector('#' + MOUNT_ID) || dom);\n }\n }\n};\n\nif (typeof __GARFISH_EXPORTS__ !== 'undefined') {\n __GARFISH_EXPORTS__.provider = provider;\n}\n\nfunction canContinueRender ({ dom, appName }) {\n var renderByGarfish =\n typeof __GARFISH_EXPORTS__ !== 'undefined'\n || typeof window !== 'undefined' && window.Garfish && window.Garfish.activeApps && window.Garfish.activeApps.some((app)=>app.appInfo.name === appName);\n let renderByProvider = dom || appName;\n if (renderByGarfish) {\n // Runs in the Garfish environment and is rendered by the provider\n if (renderByProvider) {\n return true;\n } else {\n // Runs in the Garfish environment and is not rendered by the provider\n return false;\n }\n } else {\n // Running in a non-Garfish environment\n return true;\n }\n}\n\nfunction generateRouterPlugin (basename,routerConfig) {\n if (basename) {\n routerConfig.basename = basename;\n if (routerConfig.supportHtml5History !== false) {\n if (!routerConfig.historyOptions) {\n routerConfig.historyOptions = {\n basename: basename\n };\n } else {\n routerConfig.historyOptions.basename = basename;\n }\n }\n }\n return router(routerConfig);\n}\n\nfunction generateAppWrapperAndRootDom ({ App, props: garfishProps, dom }) {\n let AppWrapper = App;\n if (garfishProps) {\n AppWrapper = function (props) {\n return React.createElement(App, { ...garfishProps, ...props });\n };\n AppWrapper = hoistNonReactStatics(AppWrapper, App);\n }\n const mountNode = dom ? (dom.querySelector('#' + MOUNT_ID) || dom) : document.getElementById(MOUNT_ID);\n return { AppWrapper, mountNode }\n}\n";
|
|
3
3
|
};
|
|
4
4
|
var makeRenderFunction = function(code) {
|
|
5
|
-
var inGarfishToRender = "\n const { basename, props, dom, appName } = typeof arguments[0] === 'object' && arguments[0] || {};\n if (!canContinueRender({ dom, appName })) return null;\n let { AppWrapper, mountNode } = generateAppWrapperAndRootDom({App, props, dom});\n ";
|
|
5
|
+
var inGarfishToRender = "\n const { basename, props, dom, appName } = typeof arguments[0] === 'object' && arguments[0] || {};\n if (!canContinueRender({ dom, appName })) return null;\n let { AppWrapper, mountNode } = generateAppWrapperAndRootDom({App, props: {...props, basename}, dom});\n ";
|
|
6
6
|
return inGarfishToRender + code.replace("router(", "generateRouterPlugin(basename,").replace("(App)", "(AppWrapper)").replace(/MOUNT_ID/g, "mountNode").replace("bootstrap(AppWrapper, mountNode, root", "bootstrap(AppWrapper, mountNode, root = IS_REACT18 ? ReactDOM.createRoot(mountNode) : null").replace("customBootstrap(AppWrapper)", "customBootstrap(AppWrapper, mountNode)");
|
|
7
7
|
};
|
|
8
8
|
function getRuntimeConfig(config) {
|
|
9
|
-
var
|
|
10
|
-
if (config === null || config === void 0 ? void 0 : (
|
|
11
|
-
var
|
|
12
|
-
return config === null || config === void 0 ? void 0 : (
|
|
9
|
+
var _config_runtime;
|
|
10
|
+
if (config === null || config === void 0 ? void 0 : (_config_runtime = config.runtime) === null || _config_runtime === void 0 ? void 0 : _config_runtime.features) {
|
|
11
|
+
var _config_runtime1;
|
|
12
|
+
return config === null || config === void 0 ? void 0 : (_config_runtime1 = config.runtime) === null || _config_runtime1 === void 0 ? void 0 : _config_runtime1.features;
|
|
13
13
|
}
|
|
14
14
|
return (config === null || config === void 0 ? void 0 : config.runtime) || {};
|
|
15
15
|
}
|
|
16
16
|
function setRuntimeConfig(config, key, value) {
|
|
17
|
-
var
|
|
18
|
-
if ((config === null || config === void 0 ? void 0 : (
|
|
17
|
+
var _config_runtime, _config_runtime1;
|
|
18
|
+
if ((config === null || config === void 0 ? void 0 : (_config_runtime = config.runtime) === null || _config_runtime === void 0 ? void 0 : _config_runtime.features) && (config === null || config === void 0 ? void 0 : (_config_runtime1 = config.runtime) === null || _config_runtime1 === void 0 ? void 0 : _config_runtime1.features[key])) {
|
|
19
19
|
config.runtime.features[key] = value;
|
|
20
20
|
return void 0;
|
|
21
21
|
}
|
|
@@ -134,13 +134,13 @@ var DEFAULT_LOADABLE = {
|
|
|
134
134
|
function Loadable(WrapComponent) {
|
|
135
135
|
return function(defaultLoadable) {
|
|
136
136
|
return function Lodable(props) {
|
|
137
|
-
var
|
|
138
|
-
var
|
|
137
|
+
var _props_loadable;
|
|
138
|
+
var _props_loadable1 = props.loadable, loadable = _props_loadable1 === void 0 ? defaultLoadable !== null && defaultLoadable !== void 0 ? defaultLoadable : DEFAULT_LOADABLE : _props_loadable1, otherProps = _objectWithoutProperties(props, [
|
|
139
139
|
"loadable"
|
|
140
140
|
]);
|
|
141
141
|
var delayTimer = null;
|
|
142
142
|
var timeoutTimer = null;
|
|
143
|
-
var
|
|
143
|
+
var _useState = _slicedToArray(useState(function() {
|
|
144
144
|
var delay = loadable.delay, timeout = loadable.timeout;
|
|
145
145
|
var initState = {
|
|
146
146
|
error: null,
|
|
@@ -167,8 +167,8 @@ function Loadable(WrapComponent) {
|
|
|
167
167
|
}, timeout);
|
|
168
168
|
}
|
|
169
169
|
return initState;
|
|
170
|
-
}), 2), state =
|
|
171
|
-
var LoadingComponent = (
|
|
170
|
+
}), 2), state = _useState[0], setState = _useState[1];
|
|
171
|
+
var LoadingComponent = (_props_loadable = props.loadable) === null || _props_loadable === void 0 ? void 0 : _props_loadable.loading;
|
|
172
172
|
useEffect(function() {
|
|
173
173
|
logger("Loadable render state", {
|
|
174
174
|
state: state,
|
|
@@ -325,7 +325,7 @@ function initOptions() {
|
|
|
325
325
|
}
|
|
326
326
|
function _initOptions() {
|
|
327
327
|
_initOptions = _asyncToGenerator(function() {
|
|
328
|
-
var manifest, options,
|
|
328
|
+
var manifest, options, _window_modern_manifest, _window_modern_manifest1, apps, getAppList, _window_modern_manifest2;
|
|
329
329
|
var _arguments = arguments;
|
|
330
330
|
return __generator(this, function(_state) {
|
|
331
331
|
switch(_state.label){
|
|
@@ -354,9 +354,9 @@ function _initOptions() {
|
|
|
354
354
|
logger("getAppList modules", apps);
|
|
355
355
|
_state.label = 2;
|
|
356
356
|
case 2:
|
|
357
|
-
if ((window === null || window === void 0 ? void 0 : (
|
|
357
|
+
if ((window === null || window === void 0 ? void 0 : (_window_modern_manifest = window.modern_manifest) === null || _window_modern_manifest === void 0 ? void 0 : _window_modern_manifest.modules) && (window === null || window === void 0 ? void 0 : (_window_modern_manifest1 = window.modern_manifest) === null || _window_modern_manifest1 === void 0 ? void 0 : _window_modern_manifest1.modules.length) > 0) {
|
|
358
358
|
;
|
|
359
|
-
apps = window === null || window === void 0 ? void 0 : (
|
|
359
|
+
apps = window === null || window === void 0 ? void 0 : (_window_modern_manifest2 = window.modern_manifest) === null || _window_modern_manifest2 === void 0 ? void 0 : _window_modern_manifest2.modules;
|
|
360
360
|
logger("modern_manifest", apps);
|
|
361
361
|
}
|
|
362
362
|
return [
|
|
@@ -383,9 +383,9 @@ var plugin_default = function(config) {
|
|
|
383
383
|
return {
|
|
384
384
|
hoc: function hoc(param, next) {
|
|
385
385
|
var App = param.App;
|
|
386
|
-
var GetMicroFrontendApp = /*#__PURE__*/ function(
|
|
386
|
+
var GetMicroFrontendApp = /*#__PURE__*/ function(_React_Component) {
|
|
387
387
|
"use strict";
|
|
388
|
-
_inherits(GetMicroFrontendApp,
|
|
388
|
+
_inherits(GetMicroFrontendApp, _React_Component);
|
|
389
389
|
var _super = _createSuper(GetMicroFrontendApp);
|
|
390
390
|
function GetMicroFrontendApp(props) {
|
|
391
391
|
_classCallCheck(this, GetMicroFrontendApp);
|
|
@@ -408,7 +408,7 @@ var plugin_default = function(config) {
|
|
|
408
408
|
var _this1 = _assertThisInitialized(_this);
|
|
409
409
|
var load = function() {
|
|
410
410
|
var _ref = _asyncToGenerator(function() {
|
|
411
|
-
var GarfishConfig,
|
|
411
|
+
var GarfishConfig, _generateApps, appInfoList, apps, MApp;
|
|
412
412
|
return __generator(this, function(_state) {
|
|
413
413
|
switch(_state.label){
|
|
414
414
|
case 0:
|
|
@@ -424,7 +424,7 @@ var plugin_default = function(config) {
|
|
|
424
424
|
];
|
|
425
425
|
case 1:
|
|
426
426
|
GarfishConfig = _state.sent();
|
|
427
|
-
|
|
427
|
+
_generateApps = generateApps(GarfishConfig, manifest), appInfoList = _generateApps.appInfoList, apps = _generateApps.apps;
|
|
428
428
|
GarfishInstance.registerApp(appInfoList);
|
|
429
429
|
MApp = generateMApp(GarfishConfig, manifest);
|
|
430
430
|
logger("initOptions result", {
|
|
@@ -30,7 +30,7 @@ import React, { useContext } from "react";
|
|
|
30
30
|
import { logger } from "../util";
|
|
31
31
|
import { GarfishContext } from "./utils/Context";
|
|
32
32
|
function useModuleApps() {
|
|
33
|
-
var
|
|
33
|
+
var _useContext = useContext(GarfishContext), apps = _useContext.apps, MApp = _useContext.MApp, appInfoList = _useContext.appInfoList;
|
|
34
34
|
logger("call useModuleApps", _objectSpread({
|
|
35
35
|
MApp: MApp,
|
|
36
36
|
apps: appInfoList
|
|
@@ -169,9 +169,9 @@ import Garfish from "garfish";
|
|
|
169
169
|
import { logger, generateSubAppContainerKey } from "../../util";
|
|
170
170
|
import { Loadable } from "../loadable";
|
|
171
171
|
function generateMApp(options, manifest) {
|
|
172
|
-
var MApp = /*#__PURE__*/ function(
|
|
172
|
+
var MApp = /*#__PURE__*/ function(_React_Component) {
|
|
173
173
|
"use strict";
|
|
174
|
-
_inherits(MApp,
|
|
174
|
+
_inherits(MApp, _React_Component);
|
|
175
175
|
var _super = _createSuper(MApp);
|
|
176
176
|
function MApp() {
|
|
177
177
|
_classCallCheck(this, MApp);
|
|
@@ -325,7 +325,7 @@ function generateMApp(options, manifest) {
|
|
|
325
325
|
{
|
|
326
326
|
key: "filterTransferProps",
|
|
327
327
|
value: function filterTransferProps() {
|
|
328
|
-
var
|
|
328
|
+
var _this_props = this.props, style = _this_props.style, setLoadingState = _this_props.setLoadingState, others = _objectWithoutProperties(_this_props, [
|
|
329
329
|
"style",
|
|
330
330
|
"setLoadingState"
|
|
331
331
|
]);
|
|
@@ -287,17 +287,21 @@ function pathJoin() {
|
|
|
287
287
|
}
|
|
288
288
|
function getAppInstance(options, appInfo, manifest) {
|
|
289
289
|
var MicroApp = function MicroApp(props) {
|
|
290
|
-
var
|
|
290
|
+
var _context_router, _context_router_useRouteMatch, _context_router1, _context_router_useMatches, _context_router2, _context_router_useLocation;
|
|
291
291
|
var appRef = useRef(null);
|
|
292
292
|
var domId = generateSubAppContainerKey(appInfo);
|
|
293
|
-
var
|
|
293
|
+
var _useState = _slicedToArray(useState(), 2), SubModuleComponent = _useState[0], setSubModuleComponent = _useState[1];
|
|
294
294
|
var context = useContext(RuntimeReactContext);
|
|
295
|
-
var match = context === null || context === void 0 ? void 0 : (
|
|
296
|
-
var matchs = context === null || context === void 0 ? void 0 : (
|
|
297
|
-
var location = context === null || context === void 0 ? void 0 : (
|
|
295
|
+
var match = context === null || context === void 0 ? void 0 : (_context_router = context.router) === null || _context_router === void 0 ? void 0 : (_context_router_useRouteMatch = _context_router.useRouteMatch) === null || _context_router_useRouteMatch === void 0 ? void 0 : _context_router_useRouteMatch.call(_context_router);
|
|
296
|
+
var matchs = context === null || context === void 0 ? void 0 : (_context_router1 = context.router) === null || _context_router1 === void 0 ? void 0 : (_context_router_useMatches = _context_router1.useMatches) === null || _context_router_useMatches === void 0 ? void 0 : _context_router_useMatches.call(_context_router1);
|
|
297
|
+
var location = context === null || context === void 0 ? void 0 : (_context_router2 = context.router) === null || _context_router2 === void 0 ? void 0 : (_context_router_useLocation = _context_router2.useLocation) === null || _context_router_useLocation === void 0 ? void 0 : _context_router_useLocation.call(_context_router2);
|
|
298
298
|
var basename = (options === null || options === void 0 ? void 0 : options.basename) || "/";
|
|
299
299
|
if (matchs && matchs.length > 0) {
|
|
300
|
-
|
|
300
|
+
var matchItem = _objectSpread({}, matchs[matchs.length - 1]);
|
|
301
|
+
for(var key in matchItem.params){
|
|
302
|
+
matchItem.pathname = matchItem.pathname.replace(new RegExp("/".concat(matchItem.params[key], "$")), "");
|
|
303
|
+
}
|
|
304
|
+
basename = pathJoin(basename, matchItem.pathname || "/");
|
|
301
305
|
} else if (match) {
|
|
302
306
|
basename = pathJoin(basename, (match === null || match === void 0 ? void 0 : match.path) || "/");
|
|
303
307
|
}
|
|
@@ -445,15 +449,15 @@ function getAppInstance(options, appInfo, manifest) {
|
|
|
445
449
|
renderApp();
|
|
446
450
|
return function() {
|
|
447
451
|
if (appRef.current) {
|
|
448
|
-
var
|
|
452
|
+
var _appRef_current = appRef.current, appInfo2 = _appRef_current.appInfo;
|
|
449
453
|
if (appInfo2.cache) {
|
|
450
|
-
var
|
|
454
|
+
var _appRef_current1;
|
|
451
455
|
logger('MicroApp Garfish.loadApp "'.concat(appInfo2.name, '" hide'));
|
|
452
|
-
(
|
|
456
|
+
(_appRef_current1 = appRef.current) === null || _appRef_current1 === void 0 ? void 0 : _appRef_current1.hide();
|
|
453
457
|
} else {
|
|
454
|
-
var
|
|
458
|
+
var _appRef_current2;
|
|
455
459
|
logger('MicroApp Garfish.loadApp "'.concat(appInfo2.name, '" unmount'));
|
|
456
|
-
(
|
|
460
|
+
(_appRef_current2 = appRef.current) === null || _appRef_current2 === void 0 ? void 0 : _appRef_current2.unmount();
|
|
457
461
|
}
|
|
458
462
|
}
|
|
459
463
|
};
|
|
@@ -469,9 +473,9 @@ function getAppInstance(options, appInfo, manifest) {
|
|
|
469
473
|
return Loadable(MicroApp)(manifest === null || manifest === void 0 ? void 0 : manifest.loadable);
|
|
470
474
|
}
|
|
471
475
|
function generateApps(options, manifest) {
|
|
472
|
-
var
|
|
476
|
+
var _options_apps;
|
|
473
477
|
var apps = {};
|
|
474
|
-
(
|
|
478
|
+
(_options_apps = options.apps) === null || _options_apps === void 0 ? void 0 : _options_apps.forEach(function(appInfo) {
|
|
475
479
|
var Component = getAppInstance(options, appInfo, manifest);
|
|
476
480
|
appInfo.Component = Component;
|
|
477
481
|
apps[appInfo.name] = Component;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@modern-js/plugin-garfish",
|
|
3
|
-
"description": "
|
|
3
|
+
"description": "A Progressive React Framework for modern web development.",
|
|
4
4
|
"homepage": "https://modernjs.dev",
|
|
5
5
|
"bugs": "https://github.com/modern-js-dev/modern.js/issues",
|
|
6
6
|
"repository": "modern-js-dev/modern.js",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "2.
|
|
14
|
+
"version": "2.4.1-beta.0",
|
|
15
15
|
"jsnext:source": "./src/cli/index.ts",
|
|
16
16
|
"types": "./dist/types/cli/index.d.ts",
|
|
17
17
|
"typesVersions": {
|
|
@@ -63,10 +63,10 @@
|
|
|
63
63
|
"garfish": "^1.8.1",
|
|
64
64
|
"hoist-non-react-statics": "^3.3.2",
|
|
65
65
|
"react-loadable": "^5.5.0",
|
|
66
|
-
"@modern-js/utils": "2.
|
|
66
|
+
"@modern-js/utils": "2.4.1-beta.0"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
|
-
"@modern-js/runtime": "^2.
|
|
69
|
+
"@modern-js/runtime": "^2.4.1-beta.0"
|
|
70
70
|
},
|
|
71
71
|
"peerDependenciesMeta": {
|
|
72
72
|
"@modern-js/runtime": {
|
|
@@ -88,13 +88,13 @@
|
|
|
88
88
|
"react-router-dom": "^6.6.0",
|
|
89
89
|
"typescript": "^4",
|
|
90
90
|
"webpack-chain": "^6.5.1",
|
|
91
|
-
"@modern-js/app-tools": "
|
|
92
|
-
"@modern-js/core": "2.
|
|
93
|
-
"@modern-js/runtime": "2.
|
|
94
|
-
"@modern-js/plugin-router-v5": "2.
|
|
95
|
-
"@modern-js/types": "2.
|
|
96
|
-
"@scripts/build": "2.
|
|
97
|
-
"@scripts/jest-config": "2.
|
|
91
|
+
"@modern-js/app-tools": "3.0.0-beta.0",
|
|
92
|
+
"@modern-js/core": "2.4.1-beta.0",
|
|
93
|
+
"@modern-js/runtime": "2.4.1-beta.0",
|
|
94
|
+
"@modern-js/plugin-router-v5": "2.4.1-beta.0",
|
|
95
|
+
"@modern-js/types": "2.4.0",
|
|
96
|
+
"@scripts/build": "2.4.0",
|
|
97
|
+
"@scripts/jest-config": "2.4.0"
|
|
98
98
|
},
|
|
99
99
|
"sideEffects": false,
|
|
100
100
|
"modernConfig": {},
|