@modern-js/plugin-garfish 2.3.0 → 2.4.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 +20 -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 +8 -3
- package/dist/js/treeshaking/cli/utils.js +1 -1
- package/dist/js/treeshaking/runtime/utils/apps.js +5 -1
- package/package.json +11 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @modern-js/plugin-garfish
|
|
2
2
|
|
|
3
|
+
## 2.4.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- b55f8c6: fix(garfish): load microApp can not match it's route
|
|
8
|
+
fix(garfish): server.baseUrl is in preference to router.basename
|
|
9
|
+
|
|
10
|
+
修复微前端模式下约定式路由和自控式路由子应用无法正确加载问题
|
|
11
|
+
修复 basename 优先级问题 server.baseUrl 高于 router.basename
|
|
12
|
+
|
|
13
|
+
- 8c2db5f: feat(core): improve support for exporting a function in config file
|
|
14
|
+
|
|
15
|
+
feat(core): 完善对配置文件中导出函数的支持
|
|
16
|
+
|
|
17
|
+
- Updated dependencies [98a2733]
|
|
18
|
+
- Updated dependencies [9e907ec]
|
|
19
|
+
- Updated dependencies [8c2db5f]
|
|
20
|
+
- @modern-js/utils@2.4.0
|
|
21
|
+
- @modern-js/runtime@2.4.0
|
|
22
|
+
|
|
3
23
|
## 2.3.0
|
|
4
24
|
|
|
5
25
|
### 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
|
}
|
|
@@ -183,7 +183,7 @@ var cli_default = function() {
|
|
|
183
183
|
},
|
|
184
184
|
resolvedConfig: function() {
|
|
185
185
|
var _ref = _asyncToGenerator(function(config) {
|
|
186
|
-
var resolved, ref, masterApp, router, nConfig, ref1;
|
|
186
|
+
var resolved, ref, masterApp, router, nConfig, ref1, ref2, useConfig, baseUrl;
|
|
187
187
|
return __generator(this, function(_state) {
|
|
188
188
|
resolved = config.resolved;
|
|
189
189
|
ref = getRuntimeConfig(resolved), masterApp = ref.masterApp, router = ref.router;
|
|
@@ -192,8 +192,13 @@ var cli_default = function() {
|
|
|
192
192
|
};
|
|
193
193
|
if (masterApp) {
|
|
194
194
|
;
|
|
195
|
+
useConfig = useConfigContext();
|
|
196
|
+
baseUrl = useConfig === null || useConfig === void 0 ? void 0 : (ref1 = useConfig.server) === null || ref1 === void 0 ? void 0 : ref1.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 : (ref2 = router.historyOptions) === null || ref2 === void 0 ? void 0 : ref2.basename) || (router === null || router === void 0 ? void 0 : router.basename) || "/"
|
|
197
202
|
}));
|
|
198
203
|
}
|
|
199
204
|
logger("resolvedConfig", {
|
|
@@ -243,7 +248,7 @@ var cli_default = function() {
|
|
|
243
248
|
}
|
|
244
249
|
},
|
|
245
250
|
webpackChain: function(chain, param) {
|
|
246
|
-
var webpack = param.webpack,
|
|
251
|
+
var webpack = param.webpack, env = param.env, CHAIN_ID = param.CHAIN_ID;
|
|
247
252
|
var ref, ref1;
|
|
248
253
|
var resolveOptions = useResolvedConfigContext();
|
|
249
254
|
if (resolveOptions === null || resolveOptions === void 0 ? void 0 : (ref = resolveOptions.deploy) === null || ref === void 0 ? void 0 : ref.microFrontend) {
|
|
@@ -2,7 +2,7 @@ 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) {
|
|
@@ -297,7 +297,11 @@ function getAppInstance(options, appInfo, manifest) {
|
|
|
297
297
|
var location = context === null || context === void 0 ? void 0 : (ref4 = context.router) === null || ref4 === void 0 ? void 0 : (ref5 = ref4.useLocation) === null || ref5 === void 0 ? void 0 : ref5.call(ref4);
|
|
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
|
}
|
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.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.0"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
|
-
"@modern-js/runtime": "^2.
|
|
69
|
+
"@modern-js/runtime": "^2.4.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": "2.
|
|
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": "2.4.0",
|
|
92
|
+
"@modern-js/core": "2.4.0",
|
|
93
|
+
"@modern-js/runtime": "2.4.0",
|
|
94
|
+
"@modern-js/plugin-router-v5": "2.4.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": {},
|