@modern-js/plugin-garfish 2.0.0-beta.5 → 2.0.0-beta.6
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 +75 -0
- package/dist/js/modern/runtime/plugin.js +1 -1
- package/dist/js/modern/runtime/utils/apps.js +124 -138
- package/dist/js/node/runtime/plugin.js +1 -1
- package/dist/js/node/runtime/utils/apps.js +125 -140
- package/dist/js/treeshaking/runtime/plugin.js +1 -1
- package/dist/js/treeshaking/runtime/utils/apps.js +287 -229
- package/dist/types/runtime/loadable.d.ts +2 -1
- package/dist/types/runtime/utils/apps.d.ts +0 -1
- package/package.json +13 -14
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,80 @@
|
|
|
1
1
|
# @modern-js/plugin-garfish
|
|
2
2
|
|
|
3
|
+
## 2.0.0-beta.6
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- dda38c9c3e: chore: v2
|
|
8
|
+
|
|
9
|
+
### Minor Changes
|
|
10
|
+
|
|
11
|
+
- df7ee2d: feat: runtime user config types extends
|
|
12
|
+
feat: runtime 用户配置类型扩展
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- 6604f1b8b3: feat: support router basename
|
|
17
|
+
feat: router 插件支持设置 basename
|
|
18
|
+
- 21d2ddb59c: feat: support async export provider for module federation
|
|
19
|
+
支持模块联邦场景异步导出 provider
|
|
20
|
+
- cce8ecee2d: fix: handle some `TODO` & `FIXME`, change some tests
|
|
21
|
+
fix: 处理一些 `TODO` 和 `FIXME`, 修改了一些 tests
|
|
22
|
+
- 2344eb26ed: fix: loadApp when dom is mount
|
|
23
|
+
修复 dom 未渲染时挂载子应用行为
|
|
24
|
+
- Updated dependencies [2344eb26ed]
|
|
25
|
+
- Updated dependencies [a11fcf8b50]
|
|
26
|
+
- Updated dependencies [a93159440e]
|
|
27
|
+
- Updated dependencies [e7ce0636d1]
|
|
28
|
+
- Updated dependencies [b18fa8f3ed]
|
|
29
|
+
- Updated dependencies [7879e8f711]
|
|
30
|
+
- Updated dependencies [50d4675e5b]
|
|
31
|
+
- Updated dependencies [c9e800d39a]
|
|
32
|
+
- Updated dependencies [6604f1b8b3]
|
|
33
|
+
- Updated dependencies [6aca875011]
|
|
34
|
+
- Updated dependencies [fda836fe8a]
|
|
35
|
+
- Updated dependencies [d6bc321747]
|
|
36
|
+
- Updated dependencies [3e57f2bd58]
|
|
37
|
+
- Updated dependencies [2e6031955e]
|
|
38
|
+
- Updated dependencies [c5798d284f]
|
|
39
|
+
- Updated dependencies [fbf5eed5aa]
|
|
40
|
+
- Updated dependencies [a2509bfbdb]
|
|
41
|
+
- Updated dependencies [a7c68832b3]
|
|
42
|
+
- Updated dependencies [425e57092d]
|
|
43
|
+
- Updated dependencies [e4357f1856]
|
|
44
|
+
- Updated dependencies [7b7d12cf8f]
|
|
45
|
+
- Updated dependencies [4369648ae2]
|
|
46
|
+
- Updated dependencies [7efeed4]
|
|
47
|
+
- Updated dependencies [92f0eade39]
|
|
48
|
+
- Updated dependencies [df7ee2d]
|
|
49
|
+
- Updated dependencies [92c0994468]
|
|
50
|
+
- Updated dependencies [2cc2eb35ba]
|
|
51
|
+
- Updated dependencies [edd1cfb1af]
|
|
52
|
+
- Updated dependencies [cc971eabfc]
|
|
53
|
+
- Updated dependencies [5b9049f2e9]
|
|
54
|
+
- Updated dependencies [6bda14ed71]
|
|
55
|
+
- Updated dependencies [92004d1906]
|
|
56
|
+
- Updated dependencies [b8bbe036c7]
|
|
57
|
+
- Updated dependencies [40ed5874c6]
|
|
58
|
+
- Updated dependencies [60d5378632]
|
|
59
|
+
- Updated dependencies [d5a31df781]
|
|
60
|
+
- Updated dependencies [dda38c9c3e]
|
|
61
|
+
- Updated dependencies [8b8e1bb571]
|
|
62
|
+
- Updated dependencies [3bbea92b2a]
|
|
63
|
+
- Updated dependencies [21d7521]
|
|
64
|
+
- Updated dependencies [9144c21d27]
|
|
65
|
+
- Updated dependencies [b710adb843]
|
|
66
|
+
- Updated dependencies [18aaf42249]
|
|
67
|
+
- Updated dependencies [34702d5d47]
|
|
68
|
+
- Updated dependencies [fcace5b5b9]
|
|
69
|
+
- Updated dependencies [ea7cf06257]
|
|
70
|
+
- Updated dependencies [bbe4c4ab64]
|
|
71
|
+
- Updated dependencies [e4558a0bc4]
|
|
72
|
+
- Updated dependencies [abf3421a75]
|
|
73
|
+
- Updated dependencies [543be9558e]
|
|
74
|
+
- Updated dependencies [14b712da84]
|
|
75
|
+
- @modern-js/runtime@2.0.0-beta.6
|
|
76
|
+
- @modern-js/utils@2.0.0-beta.6
|
|
77
|
+
|
|
3
78
|
## 2.0.0-beta.4
|
|
4
79
|
|
|
5
80
|
### Major Changes
|
|
@@ -140,7 +140,7 @@ var plugin_default = (config) => ({
|
|
|
140
140
|
logger("GarfishProvider state", this.state);
|
|
141
141
|
return /* @__PURE__ */ jsx(GarfishProvider, {
|
|
142
142
|
value: this.state,
|
|
143
|
-
children: /* @__PURE__ */ jsx(App, __spreadValues({}, this.props))
|
|
143
|
+
children: /* @__PURE__ */ jsx(App, __spreadValues(__spreadValues({}, this.props), this.state))
|
|
144
144
|
});
|
|
145
145
|
}
|
|
146
146
|
}
|
|
@@ -50,160 +50,147 @@ var __async = (__this, __arguments, generator) => {
|
|
|
50
50
|
});
|
|
51
51
|
};
|
|
52
52
|
import { Fragment, jsx } from "react/jsx-runtime";
|
|
53
|
-
import
|
|
54
|
-
import
|
|
53
|
+
import path from "path";
|
|
54
|
+
import React from "react";
|
|
55
55
|
import Garfish from "garfish";
|
|
56
|
+
import { withRouter } from "@modern-js/plugin-router-v5/runtime";
|
|
56
57
|
import { logger, generateSubAppContainerKey } from "../../util";
|
|
57
58
|
import { Loadable } from "../loadable";
|
|
58
|
-
function pathJoin(...args) {
|
|
59
|
-
const res = args.reduce((res2, path) => {
|
|
60
|
-
let nPath = path;
|
|
61
|
-
if (!nPath || typeof nPath !== "string") {
|
|
62
|
-
return res2;
|
|
63
|
-
}
|
|
64
|
-
if (nPath[0] !== "/") {
|
|
65
|
-
nPath = `/${nPath}`;
|
|
66
|
-
}
|
|
67
|
-
const lastIndex = path.length - 1;
|
|
68
|
-
if (nPath[lastIndex] === "/") {
|
|
69
|
-
nPath = nPath.substring(0, lastIndex);
|
|
70
|
-
}
|
|
71
|
-
return res2 + nPath;
|
|
72
|
-
}, "");
|
|
73
|
-
return res || "/";
|
|
74
|
-
}
|
|
75
59
|
function getAppInstance(options, appInfo, manifest) {
|
|
76
60
|
let locationHref = "";
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
if (matchs && matchs.length > 0) {
|
|
88
|
-
basename = pathJoin(basename, matchs[matchs.length - 1].pathname || "/");
|
|
89
|
-
} else if (match) {
|
|
90
|
-
basename = pathJoin(basename, (match == null ? void 0 : match.path) || "/");
|
|
61
|
+
class MicroApp extends React.Component {
|
|
62
|
+
constructor() {
|
|
63
|
+
super(...arguments);
|
|
64
|
+
this.state = {
|
|
65
|
+
appInstance: null,
|
|
66
|
+
domId: generateSubAppContainerKey(appInfo),
|
|
67
|
+
SubModuleComponent: void 0
|
|
68
|
+
};
|
|
69
|
+
this.unregisterHistoryListener = () => {
|
|
70
|
+
};
|
|
91
71
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
if (componetRenderMode) {
|
|
132
|
-
return void 0;
|
|
72
|
+
componentDidMount() {
|
|
73
|
+
return __async(this, null, function* () {
|
|
74
|
+
const _a = this.props, { match, history, setLoadingState } = _a, userProps = __objRest(_a, ["match", "history", "setLoadingState"]);
|
|
75
|
+
const { domId } = this.state;
|
|
76
|
+
const loadAppOptions = __spreadProps(__spreadValues({}, appInfo), {
|
|
77
|
+
insulationVariable: [
|
|
78
|
+
...appInfo.insulationVariable || [],
|
|
79
|
+
"_SERVER_DATA"
|
|
80
|
+
],
|
|
81
|
+
domGetter: `#${domId}`,
|
|
82
|
+
basename: path.join((options == null ? void 0 : options.basename) || "/", (match == null ? void 0 : match.path) || "/"),
|
|
83
|
+
cache: true,
|
|
84
|
+
props: __spreadValues(__spreadValues({}, appInfo.props), userProps),
|
|
85
|
+
customLoader: (provider) => {
|
|
86
|
+
const {
|
|
87
|
+
render,
|
|
88
|
+
destroy,
|
|
89
|
+
SubModuleComponent,
|
|
90
|
+
jupiter_submodule_app_key
|
|
91
|
+
} = provider;
|
|
92
|
+
const componetRenderMode = (manifest == null ? void 0 : manifest.componentRender) && (SubModuleComponent || jupiter_submodule_app_key);
|
|
93
|
+
return {
|
|
94
|
+
mount: (...props) => {
|
|
95
|
+
if (componetRenderMode) {
|
|
96
|
+
this.setState({
|
|
97
|
+
SubModuleComponent: SubModuleComponent != null ? SubModuleComponent : jupiter_submodule_app_key
|
|
98
|
+
});
|
|
99
|
+
return void 0;
|
|
100
|
+
} else {
|
|
101
|
+
logger("MicroApp customer render", props);
|
|
102
|
+
return render == null ? void 0 : render.apply(provider, props);
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
unmount(...props) {
|
|
106
|
+
if (componetRenderMode) {
|
|
107
|
+
return void 0;
|
|
108
|
+
}
|
|
109
|
+
logger("MicroApp customer destroy", props);
|
|
110
|
+
return destroy == null ? void 0 : destroy.apply(provider, props);
|
|
133
111
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
try {
|
|
150
|
-
const appInstance = yield Garfish.loadApp(
|
|
151
|
-
appInfo.name,
|
|
152
|
-
loadAppOptions
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
setLoadingState({
|
|
116
|
+
isLoading: true,
|
|
117
|
+
error: null
|
|
118
|
+
});
|
|
119
|
+
logger(`MicroApp Garfish.loadApp "${appInfo.name}"`, {
|
|
120
|
+
loadAppOptions
|
|
121
|
+
});
|
|
122
|
+
try {
|
|
123
|
+
const appInstance = yield Garfish.loadApp(appInfo.name, loadAppOptions);
|
|
124
|
+
if (!appInstance) {
|
|
125
|
+
throw new Error(
|
|
126
|
+
`MicroApp Garfish.loadApp "${appInfo.name}" result is null`
|
|
153
127
|
);
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
128
|
+
}
|
|
129
|
+
this.setState({
|
|
130
|
+
appInstance
|
|
131
|
+
});
|
|
132
|
+
setLoadingState({
|
|
133
|
+
isLoading: false
|
|
134
|
+
});
|
|
135
|
+
if (appInstance.mounted && appInstance.appInfo.cache) {
|
|
136
|
+
logger(`MicroApp Garfish.loadApp "${appInfo.name}" show`, {
|
|
137
|
+
appInfo: appInstance.appInfo,
|
|
138
|
+
appInstance
|
|
162
139
|
});
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
yield appInstance == null ? void 0 : appInstance.show();
|
|
169
|
-
} else {
|
|
170
|
-
logger(`MicroApp Garfish.loadApp "${appInfo.name}" mount`, {
|
|
171
|
-
appInfo: appInstance.appInfo,
|
|
172
|
-
appInstance
|
|
173
|
-
});
|
|
174
|
-
yield appInstance == null ? void 0 : appInstance.mount();
|
|
175
|
-
}
|
|
176
|
-
} catch (error) {
|
|
177
|
-
setLoadingState({
|
|
178
|
-
isLoading: true,
|
|
179
|
-
error
|
|
140
|
+
yield appInstance == null ? void 0 : appInstance.show();
|
|
141
|
+
} else {
|
|
142
|
+
logger(`MicroApp Garfish.loadApp "${appInfo.name}" mount`, {
|
|
143
|
+
appInfo: appInstance.appInfo,
|
|
144
|
+
appInstance
|
|
180
145
|
});
|
|
146
|
+
yield appInstance == null ? void 0 : appInstance.mount();
|
|
181
147
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
148
|
+
this.unregisterHistoryListener = history == null ? void 0 : history.listen(() => {
|
|
149
|
+
if (locationHref !== history.location.pathname) {
|
|
150
|
+
locationHref = history.location.pathname;
|
|
151
|
+
const popStateEvent = new PopStateEvent("popstate");
|
|
152
|
+
dispatchEvent(popStateEvent);
|
|
153
|
+
logger(`MicroApp Garfish.loadApp popstate`);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
} catch (error) {
|
|
157
|
+
setLoadingState({
|
|
158
|
+
isLoading: true,
|
|
159
|
+
error
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
componentWillUnmount() {
|
|
165
|
+
return __async(this, null, function* () {
|
|
166
|
+
var _a;
|
|
167
|
+
const { appInstance } = this.state;
|
|
168
|
+
(_a = this.unregisterHistoryListener) == null ? void 0 : _a.call(this);
|
|
169
|
+
if (appInstance) {
|
|
170
|
+
const { appInfo: appInfo2 } = appInstance;
|
|
189
171
|
if (appInfo2.cache) {
|
|
190
172
|
logger(`MicroApp Garfish.loadApp "${appInfo2.name}" hide`);
|
|
191
|
-
|
|
173
|
+
appInstance == null ? void 0 : appInstance.hide();
|
|
192
174
|
} else {
|
|
193
175
|
logger(`MicroApp Garfish.loadApp "${appInfo2.name}" unmount`);
|
|
194
|
-
|
|
176
|
+
appInstance == null ? void 0 : appInstance.unmount();
|
|
195
177
|
}
|
|
196
178
|
}
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
children:
|
|
203
|
-
|
|
204
|
-
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
render() {
|
|
182
|
+
const { domId, SubModuleComponent } = this.state;
|
|
183
|
+
return /* @__PURE__ */ jsx(Fragment, {
|
|
184
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
185
|
+
id: domId,
|
|
186
|
+
children: SubModuleComponent && /* @__PURE__ */ jsx(SubModuleComponent, {})
|
|
187
|
+
})
|
|
188
|
+
});
|
|
189
|
+
}
|
|
205
190
|
}
|
|
206
|
-
return Loadable(MicroApp)(
|
|
191
|
+
return Loadable(withRouter(MicroApp))(
|
|
192
|
+
manifest == null ? void 0 : manifest.loadable
|
|
193
|
+
);
|
|
207
194
|
}
|
|
208
195
|
function generateApps(options, manifest) {
|
|
209
196
|
var _a;
|
|
@@ -216,6 +203,5 @@ function generateApps(options, manifest) {
|
|
|
216
203
|
return { apps, appInfoList: options.apps || [] };
|
|
217
204
|
}
|
|
218
205
|
export {
|
|
219
|
-
generateApps
|
|
220
|
-
pathJoin
|
|
206
|
+
generateApps
|
|
221
207
|
};
|
|
@@ -166,7 +166,7 @@ var plugin_default = (config) => ({
|
|
|
166
166
|
(0, import_util.logger)("GarfishProvider state", this.state);
|
|
167
167
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Context.GarfishProvider, {
|
|
168
168
|
value: this.state,
|
|
169
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, __spreadValues({}, this.props))
|
|
169
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, __spreadValues(__spreadValues({}, this.props), this.state))
|
|
170
170
|
});
|
|
171
171
|
}
|
|
172
172
|
}
|