@modern-js/plugin-garfish 2.4.1-beta.0 → 2.5.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 +19 -3
- package/dist/{js/node → cjs}/cli/index.js +10 -41
- package/dist/{js/node → cjs}/cli/utils.js +5 -2
- package/dist/{js/node → cjs}/deps/index.js +0 -0
- package/dist/{js/node → cjs}/index.js +0 -0
- package/dist/{js/node → cjs}/runtime/index.js +0 -0
- package/dist/{js/node → cjs}/runtime/loadable.js +11 -38
- package/dist/{js/node → cjs}/runtime/plugin.js +32 -79
- package/dist/{js/node → cjs}/runtime/useModuleApps.js +8 -20
- package/dist/{js/node → cjs}/runtime/utils/Context.js +0 -0
- package/dist/{js/node → cjs}/runtime/utils/MApp.js +4 -30
- package/dist/{js/node → cjs}/runtime/utils/apps.js +43 -88
- package/dist/{js/node → cjs}/runtime/utils/setExternal.js +0 -0
- package/dist/{js/node → cjs}/util.js +0 -0
- package/dist/{js/treeshaking → esm}/cli/index.js +0 -0
- package/dist/{js/treeshaking → esm}/cli/utils.js +2 -2
- package/dist/{js/treeshaking → esm}/deps/index.js +0 -0
- package/dist/{js/treeshaking → esm}/index.js +0 -0
- package/dist/{js/treeshaking → esm}/runtime/index.js +0 -0
- package/dist/{js/treeshaking → esm}/runtime/loadable.js +0 -0
- package/dist/{js/treeshaking → esm}/runtime/plugin.js +0 -0
- package/dist/{js/treeshaking → esm}/runtime/useModuleApps.js +0 -0
- package/dist/{js/treeshaking → esm}/runtime/utils/Context.js +0 -0
- package/dist/{js/treeshaking → esm}/runtime/utils/MApp.js +0 -0
- package/dist/{js/treeshaking → esm}/runtime/utils/apps.js +0 -0
- package/dist/{js/treeshaking → esm}/runtime/utils/setExternal.js +0 -0
- package/dist/{js/treeshaking → esm}/util.js +0 -0
- package/dist/{js/modern → esm-node}/cli/index.js +10 -43
- package/dist/{js/modern → esm-node}/cli/utils.js +5 -2
- package/dist/{js/modern → esm-node}/deps/index.js +0 -0
- package/dist/{js/modern → esm-node}/index.js +0 -0
- package/dist/{js/modern → esm-node}/runtime/index.js +0 -0
- package/dist/{js/modern → esm-node}/runtime/loadable.js +11 -40
- package/dist/esm-node/runtime/plugin.js +107 -0
- package/dist/esm-node/runtime/useModuleApps.js +36 -0
- package/dist/{js/modern → esm-node}/runtime/utils/Context.js +0 -0
- package/dist/{js/modern → esm-node}/runtime/utils/MApp.js +4 -32
- package/dist/{js/modern → esm-node}/runtime/utils/apps.js +43 -90
- package/dist/{js/modern → esm-node}/runtime/utils/setExternal.js +0 -0
- package/dist/{js/modern → esm-node}/util.js +0 -0
- package/package.json +16 -17
- package/dist/js/modern/runtime/plugin.js +0 -156
- package/dist/js/modern/runtime/useModuleApps.js +0 -50
|
@@ -1,38 +1,9 @@
|
|
|
1
1
|
var __create = Object.create;
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
|
-
var __defProps = Object.defineProperties;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
5
|
var __getProtoOf = Object.getPrototypeOf;
|
|
9
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
-
var __spreadValues = (a, b) => {
|
|
13
|
-
for (var prop in b || (b = {}))
|
|
14
|
-
if (__hasOwnProp.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
if (__getOwnPropSymbols)
|
|
17
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
-
if (__propIsEnum.call(b, prop))
|
|
19
|
-
__defNormalProp(a, prop, b[prop]);
|
|
20
|
-
}
|
|
21
|
-
return a;
|
|
22
|
-
};
|
|
23
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
|
-
var __objRest = (source, exclude) => {
|
|
25
|
-
var target = {};
|
|
26
|
-
for (var prop in source)
|
|
27
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
28
|
-
target[prop] = source[prop];
|
|
29
|
-
if (source != null && __getOwnPropSymbols)
|
|
30
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
31
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
32
|
-
target[prop] = source[prop];
|
|
33
|
-
}
|
|
34
|
-
return target;
|
|
35
|
-
};
|
|
36
7
|
var __export = (target, all) => {
|
|
37
8
|
for (var name in all)
|
|
38
9
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -50,26 +21,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
50
21
|
mod
|
|
51
22
|
));
|
|
52
23
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
53
|
-
var __async = (__this, __arguments, generator) => {
|
|
54
|
-
return new Promise((resolve, reject) => {
|
|
55
|
-
var fulfilled = (value) => {
|
|
56
|
-
try {
|
|
57
|
-
step(generator.next(value));
|
|
58
|
-
} catch (e) {
|
|
59
|
-
reject(e);
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
var rejected = (value) => {
|
|
63
|
-
try {
|
|
64
|
-
step(generator.throw(value));
|
|
65
|
-
} catch (e) {
|
|
66
|
-
reject(e);
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
70
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
71
|
-
});
|
|
72
|
-
};
|
|
73
24
|
var apps_exports = {};
|
|
74
25
|
__export(apps_exports, {
|
|
75
26
|
generateApps: () => generateApps,
|
|
@@ -112,7 +63,9 @@ function getAppInstance(options, appInfo, manifest) {
|
|
|
112
63
|
const location = (_f = (_e = context == null ? void 0 : context.router) == null ? void 0 : _e.useLocation) == null ? void 0 : _f.call(_e);
|
|
113
64
|
let basename = (options == null ? void 0 : options.basename) || "/";
|
|
114
65
|
if (matchs && matchs.length > 0) {
|
|
115
|
-
const matchItem =
|
|
66
|
+
const matchItem = {
|
|
67
|
+
...matchs[matchs.length - 1]
|
|
68
|
+
};
|
|
116
69
|
for (const key in matchItem.params) {
|
|
117
70
|
matchItem.pathname = matchItem.pathname.replace(
|
|
118
71
|
new RegExp(`/${matchItem.params[key]}$`),
|
|
@@ -133,8 +86,9 @@ function getAppInstance(options, appInfo, manifest) {
|
|
|
133
86
|
}
|
|
134
87
|
}, [location]);
|
|
135
88
|
(0, import_react.useEffect)(() => {
|
|
136
|
-
const
|
|
137
|
-
const loadAppOptions =
|
|
89
|
+
const { setLoadingState, ...userProps } = props;
|
|
90
|
+
const loadAppOptions = {
|
|
91
|
+
...appInfo,
|
|
138
92
|
insulationVariable: [
|
|
139
93
|
...appInfo.insulationVariable || [],
|
|
140
94
|
"_SERVER_DATA"
|
|
@@ -142,7 +96,10 @@ function getAppInstance(options, appInfo, manifest) {
|
|
|
142
96
|
domGetter: `#${domId}`,
|
|
143
97
|
basename,
|
|
144
98
|
cache: true,
|
|
145
|
-
props:
|
|
99
|
+
props: {
|
|
100
|
+
...appInfo.props,
|
|
101
|
+
...userProps
|
|
102
|
+
},
|
|
146
103
|
customLoader: (provider) => {
|
|
147
104
|
const {
|
|
148
105
|
render,
|
|
@@ -170,7 +127,7 @@ function getAppInstance(options, appInfo, manifest) {
|
|
|
170
127
|
}
|
|
171
128
|
};
|
|
172
129
|
}
|
|
173
|
-
}
|
|
130
|
+
};
|
|
174
131
|
setLoadingState({
|
|
175
132
|
isLoading: true,
|
|
176
133
|
error: null
|
|
@@ -178,51 +135,49 @@ function getAppInstance(options, appInfo, manifest) {
|
|
|
178
135
|
(0, import_util.logger)(`MicroApp Garfish.loadApp "${appInfo.name}"`, {
|
|
179
136
|
loadAppOptions
|
|
180
137
|
});
|
|
181
|
-
function renderApp() {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
138
|
+
async function renderApp() {
|
|
139
|
+
try {
|
|
140
|
+
const appInstance = await import_garfish.default.loadApp(
|
|
141
|
+
appInfo.name,
|
|
142
|
+
loadAppOptions
|
|
143
|
+
);
|
|
144
|
+
if (!appInstance) {
|
|
145
|
+
throw new Error(
|
|
146
|
+
`MicroApp Garfish.loadApp "${appInfo.name}" result is null`
|
|
187
147
|
);
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
148
|
+
}
|
|
149
|
+
appRef.current = appInstance;
|
|
150
|
+
setLoadingState({
|
|
151
|
+
isLoading: false
|
|
152
|
+
});
|
|
153
|
+
if (appInstance.mounted && appInstance.appInfo.cache) {
|
|
154
|
+
(0, import_util.logger)(`MicroApp Garfish.loadApp "${appInfo.name}" show`, {
|
|
155
|
+
appInfo: appInstance.appInfo,
|
|
156
|
+
appInstance
|
|
196
157
|
});
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
yield appInstance == null ? void 0 : appInstance.show();
|
|
203
|
-
} else {
|
|
204
|
-
(0, import_util.logger)(`MicroApp Garfish.loadApp "${appInfo.name}" mount`, {
|
|
205
|
-
appInfo: appInstance.appInfo,
|
|
206
|
-
appInstance
|
|
207
|
-
});
|
|
208
|
-
yield appInstance == null ? void 0 : appInstance.mount();
|
|
209
|
-
}
|
|
210
|
-
} catch (error) {
|
|
211
|
-
setLoadingState({
|
|
212
|
-
isLoading: true,
|
|
213
|
-
error
|
|
158
|
+
await (appInstance == null ? void 0 : appInstance.show());
|
|
159
|
+
} else {
|
|
160
|
+
(0, import_util.logger)(`MicroApp Garfish.loadApp "${appInfo.name}" mount`, {
|
|
161
|
+
appInfo: appInstance.appInfo,
|
|
162
|
+
appInstance
|
|
214
163
|
});
|
|
164
|
+
await (appInstance == null ? void 0 : appInstance.mount());
|
|
215
165
|
}
|
|
216
|
-
})
|
|
166
|
+
} catch (error) {
|
|
167
|
+
setLoadingState({
|
|
168
|
+
isLoading: true,
|
|
169
|
+
error
|
|
170
|
+
});
|
|
171
|
+
}
|
|
217
172
|
}
|
|
218
173
|
renderApp();
|
|
219
174
|
return () => {
|
|
220
|
-
var
|
|
175
|
+
var _a2, _b2;
|
|
221
176
|
if (appRef.current) {
|
|
222
177
|
const { appInfo: appInfo2 } = appRef.current;
|
|
223
178
|
if (appInfo2.cache) {
|
|
224
179
|
(0, import_util.logger)(`MicroApp Garfish.loadApp "${appInfo2.name}" hide`);
|
|
225
|
-
(
|
|
180
|
+
(_a2 = appRef.current) == null ? void 0 : _a2.hide();
|
|
226
181
|
} else {
|
|
227
182
|
(0, import_util.logger)(`MicroApp Garfish.loadApp "${appInfo2.name}" unmount`);
|
|
228
183
|
(_b2 = appRef.current) == null ? void 0 : _b2.unmount();
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -3,7 +3,7 @@ var makeProvider = function() {
|
|
|
3
3
|
};
|
|
4
4
|
var makeRenderFunction = function(code) {
|
|
5
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
|
-
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
|
|
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
9
|
var _config_runtime;
|
|
@@ -27,6 +27,6 @@ function setRuntimeConfig(config, key, value) {
|
|
|
27
27
|
}
|
|
28
28
|
var generateAsyncEntry = function(code) {
|
|
29
29
|
var transformCode = code.replace("import('./bootstrap.js');", "if (!window.__GARFISH__) { import('./bootstrap.js'); }");
|
|
30
|
-
return "\n export const provider = async (...args) => {\n const exports = await import('./bootstrap');\n return exports.provider.apply(null, args);\n };\n ".concat(transformCode, "\n ");
|
|
30
|
+
return "\n export const provider = async (...args) => {\n const exports = await import('./bootstrap');\n return exports.provider.apply(null, args);\n };\n ".concat(transformCode, "\n if (typeof __GARFISH_EXPORTS__ !== 'undefined') {\n __GARFISH_EXPORTS__.provider = provider;\n }\n ");
|
|
31
31
|
};
|
|
32
32
|
export { generateAsyncEntry, getRuntimeConfig, makeProvider, makeRenderFunction, setRuntimeConfig };
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,39 +1,3 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
-
var __spreadValues = (a, b) => {
|
|
7
|
-
for (var prop in b || (b = {}))
|
|
8
|
-
if (__hasOwnProp.call(b, prop))
|
|
9
|
-
__defNormalProp(a, prop, b[prop]);
|
|
10
|
-
if (__getOwnPropSymbols)
|
|
11
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
-
if (__propIsEnum.call(b, prop))
|
|
13
|
-
__defNormalProp(a, prop, b[prop]);
|
|
14
|
-
}
|
|
15
|
-
return a;
|
|
16
|
-
};
|
|
17
|
-
var __async = (__this, __arguments, generator) => {
|
|
18
|
-
return new Promise((resolve, reject) => {
|
|
19
|
-
var fulfilled = (value) => {
|
|
20
|
-
try {
|
|
21
|
-
step(generator.next(value));
|
|
22
|
-
} catch (e) {
|
|
23
|
-
reject(e);
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
var rejected = (value) => {
|
|
27
|
-
try {
|
|
28
|
-
step(generator.throw(value));
|
|
29
|
-
} catch (e) {
|
|
30
|
-
reject(e);
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
34
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
35
|
-
});
|
|
36
|
-
};
|
|
37
1
|
import { createRuntimeExportsUtils, PLUGIN_SCHEMAS } from "@modern-js/utils";
|
|
38
2
|
import { logger } from "../util";
|
|
39
3
|
import {
|
|
@@ -52,10 +16,11 @@ function getDefaultMicroFrontedConfig(microFrontend) {
|
|
|
52
16
|
moduleApp: ""
|
|
53
17
|
};
|
|
54
18
|
}
|
|
55
|
-
return
|
|
19
|
+
return {
|
|
56
20
|
enableHtmlEntry: true,
|
|
57
|
-
externalBasicLibrary: false
|
|
58
|
-
|
|
21
|
+
externalBasicLibrary: false,
|
|
22
|
+
...microFrontend
|
|
23
|
+
};
|
|
59
24
|
}
|
|
60
25
|
var cli_default = ({
|
|
61
26
|
pluginName = "@modern-js/plugin-garfish",
|
|
@@ -68,12 +33,14 @@ var cli_default = ({
|
|
|
68
33
|
validateSchema() {
|
|
69
34
|
return PLUGIN_SCHEMAS["@modern-js/plugin-garfish"];
|
|
70
35
|
},
|
|
71
|
-
resolvedConfig: (config) =>
|
|
36
|
+
resolvedConfig: async (config) => {
|
|
72
37
|
var _a, _b;
|
|
73
38
|
const { resolved } = config;
|
|
74
39
|
const { masterApp, router } = getRuntimeConfig(resolved);
|
|
75
40
|
const nConfig = {
|
|
76
|
-
resolved:
|
|
41
|
+
resolved: {
|
|
42
|
+
...resolved
|
|
43
|
+
}
|
|
77
44
|
};
|
|
78
45
|
if (masterApp) {
|
|
79
46
|
const useConfig = useConfigContext();
|
|
@@ -87,7 +54,7 @@ var cli_default = ({
|
|
|
87
54
|
nConfig.resolved,
|
|
88
55
|
"masterApp",
|
|
89
56
|
Object.assign(
|
|
90
|
-
typeof masterApp === "object" ?
|
|
57
|
+
typeof masterApp === "object" ? { ...masterApp } : {},
|
|
91
58
|
{
|
|
92
59
|
basename: baseUrl || ((_b = router == null ? void 0 : router.historyOptions) == null ? void 0 : _b.basename) || (router == null ? void 0 : router.basename) || "/"
|
|
93
60
|
}
|
|
@@ -101,7 +68,7 @@ var cli_default = ({
|
|
|
101
68
|
server: nConfig.resolved.server
|
|
102
69
|
});
|
|
103
70
|
return nConfig;
|
|
104
|
-
}
|
|
71
|
+
},
|
|
105
72
|
config() {
|
|
106
73
|
var _a, _b, _c;
|
|
107
74
|
const useConfig = useConfigContext();
|
|
@@ -89,8 +89,8 @@ const makeRenderFunction = (code) => {
|
|
|
89
89
|
`bootstrap(AppWrapper, mountNode, root`,
|
|
90
90
|
"bootstrap(AppWrapper, mountNode, root = IS_REACT18 ? ReactDOM.createRoot(mountNode) : null"
|
|
91
91
|
).replace(
|
|
92
|
-
`customBootstrap(AppWrapper
|
|
93
|
-
"customBootstrap(AppWrapper, mountNode
|
|
92
|
+
`customBootstrap(AppWrapper`,
|
|
93
|
+
"customBootstrap(AppWrapper, mountNode"
|
|
94
94
|
);
|
|
95
95
|
};
|
|
96
96
|
function getRuntimeConfig(config) {
|
|
@@ -123,6 +123,9 @@ const generateAsyncEntry = (code) => {
|
|
|
123
123
|
return exports.provider.apply(null, args);
|
|
124
124
|
};
|
|
125
125
|
${transformCode}
|
|
126
|
+
if (typeof __GARFISH_EXPORTS__ !== 'undefined') {
|
|
127
|
+
__GARFISH_EXPORTS__.provider = provider;
|
|
128
|
+
}
|
|
126
129
|
`;
|
|
127
130
|
};
|
|
128
131
|
export {
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,34 +1,3 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
var __objRest = (source, exclude) => {
|
|
21
|
-
var target = {};
|
|
22
|
-
for (var prop in source)
|
|
23
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
-
target[prop] = source[prop];
|
|
25
|
-
if (source != null && __getOwnPropSymbols)
|
|
26
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
-
target[prop] = source[prop];
|
|
29
|
-
}
|
|
30
|
-
return target;
|
|
31
|
-
};
|
|
32
1
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
33
2
|
import { useState, useEffect, useCallback } from "react";
|
|
34
3
|
import { logger } from "../util";
|
|
@@ -40,8 +9,8 @@ const DEFAULT_LOADABLE = {
|
|
|
40
9
|
function Loadable(WrapComponent) {
|
|
41
10
|
return function(defaultLoadable) {
|
|
42
11
|
return function Lodable(props) {
|
|
43
|
-
var
|
|
44
|
-
const
|
|
12
|
+
var _a;
|
|
13
|
+
const { loadable = defaultLoadable != null ? defaultLoadable : DEFAULT_LOADABLE, ...otherProps } = props;
|
|
45
14
|
let delayTimer = null;
|
|
46
15
|
let timeoutTimer = null;
|
|
47
16
|
const [state, setState] = useState(() => {
|
|
@@ -68,7 +37,7 @@ function Loadable(WrapComponent) {
|
|
|
68
37
|
}
|
|
69
38
|
return initState;
|
|
70
39
|
});
|
|
71
|
-
const LoadingComponent = (
|
|
40
|
+
const LoadingComponent = (_a = props.loadable) == null ? void 0 : _a.loading;
|
|
72
41
|
useEffect(() => {
|
|
73
42
|
logger("Loadable render state", {
|
|
74
43
|
state,
|
|
@@ -92,15 +61,16 @@ function Loadable(WrapComponent) {
|
|
|
92
61
|
};
|
|
93
62
|
}, []);
|
|
94
63
|
const retry = useCallback(() => {
|
|
95
|
-
setState(
|
|
64
|
+
setState({
|
|
65
|
+
...state,
|
|
96
66
|
error: null,
|
|
97
67
|
isLoading: true,
|
|
98
68
|
timedOut: false
|
|
99
|
-
})
|
|
69
|
+
});
|
|
100
70
|
}, [state]);
|
|
101
71
|
const setStateWithMountCheck = useCallback(
|
|
102
72
|
(newState) => {
|
|
103
|
-
setState((state2) =>
|
|
73
|
+
setState((state2) => ({ ...state2, ...newState }));
|
|
104
74
|
},
|
|
105
75
|
[state]
|
|
106
76
|
);
|
|
@@ -114,15 +84,16 @@ function Loadable(WrapComponent) {
|
|
|
114
84
|
error: state == null ? void 0 : state.error,
|
|
115
85
|
retry
|
|
116
86
|
}),
|
|
117
|
-
/* @__PURE__ */ jsx(WrapComponent,
|
|
87
|
+
/* @__PURE__ */ jsx(WrapComponent, {
|
|
118
88
|
style: { display: showLoading ? "none" : "block" },
|
|
119
89
|
setLoadingState: (props2) => {
|
|
120
90
|
if (props2.error && !LoadingComponent) {
|
|
121
91
|
throw props2.error;
|
|
122
92
|
}
|
|
123
93
|
setStateWithMountCheck(props2);
|
|
124
|
-
}
|
|
125
|
-
|
|
94
|
+
},
|
|
95
|
+
...otherProps
|
|
96
|
+
})
|
|
126
97
|
]
|
|
127
98
|
});
|
|
128
99
|
};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import GarfishInstance from "garfish";
|
|
3
|
+
import React from "react";
|
|
4
|
+
import hoistNonReactStatics from "hoist-non-react-statics";
|
|
5
|
+
import { logger } from "../util";
|
|
6
|
+
import { GarfishProvider } from "./utils/Context";
|
|
7
|
+
import setExternal from "./utils/setExternal";
|
|
8
|
+
import { generateMApp } from "./utils/MApp";
|
|
9
|
+
import { generateApps } from "./utils/apps";
|
|
10
|
+
async function initOptions(manifest = {}, options) {
|
|
11
|
+
var _a, _b, _c;
|
|
12
|
+
let apps = options.apps || [];
|
|
13
|
+
if (manifest == null ? void 0 : manifest.modules) {
|
|
14
|
+
if ((manifest == null ? void 0 : manifest.modules.length) > 0) {
|
|
15
|
+
apps = manifest == null ? void 0 : manifest.modules;
|
|
16
|
+
}
|
|
17
|
+
logger("manifest modules", apps);
|
|
18
|
+
}
|
|
19
|
+
if (manifest == null ? void 0 : manifest.getAppList) {
|
|
20
|
+
const getAppList = await (manifest == null ? void 0 : manifest.getAppList(manifest));
|
|
21
|
+
if (getAppList.length > 0) {
|
|
22
|
+
apps = getAppList;
|
|
23
|
+
}
|
|
24
|
+
logger("getAppList modules", apps);
|
|
25
|
+
}
|
|
26
|
+
if (((_a = window == null ? void 0 : window.modern_manifest) == null ? void 0 : _a.modules) && ((_b = window == null ? void 0 : window.modern_manifest) == null ? void 0 : _b.modules.length) > 0) {
|
|
27
|
+
apps = (_c = window == null ? void 0 : window.modern_manifest) == null ? void 0 : _c.modules;
|
|
28
|
+
logger("modern_manifest", apps);
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
...options,
|
|
32
|
+
apps
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
var plugin_default = (config) => ({
|
|
36
|
+
name: "@modern-js/garfish-plugin",
|
|
37
|
+
setup: () => {
|
|
38
|
+
setExternal();
|
|
39
|
+
const { manifest, ...options } = config;
|
|
40
|
+
logger("createPlugin", config);
|
|
41
|
+
const promise = initOptions(manifest, options);
|
|
42
|
+
return {
|
|
43
|
+
hoc({ App }, next) {
|
|
44
|
+
class GetMicroFrontendApp extends React.Component {
|
|
45
|
+
constructor(props) {
|
|
46
|
+
super(props);
|
|
47
|
+
this.state = {
|
|
48
|
+
MApp: () => {
|
|
49
|
+
logger("MApp init Component Render");
|
|
50
|
+
return React.createElement("div");
|
|
51
|
+
},
|
|
52
|
+
apps: new Proxy(
|
|
53
|
+
{},
|
|
54
|
+
{
|
|
55
|
+
get() {
|
|
56
|
+
return () => React.createElement("div");
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
),
|
|
60
|
+
appInfoList: []
|
|
61
|
+
};
|
|
62
|
+
const load = async () => {
|
|
63
|
+
GarfishInstance.setOptions({
|
|
64
|
+
...options,
|
|
65
|
+
insulationVariable: [
|
|
66
|
+
...options.insulationVariable || [],
|
|
67
|
+
"_SERVER_DATA"
|
|
68
|
+
],
|
|
69
|
+
apps: []
|
|
70
|
+
});
|
|
71
|
+
const GarfishConfig = await promise;
|
|
72
|
+
const { appInfoList, apps } = generateApps(
|
|
73
|
+
GarfishConfig,
|
|
74
|
+
manifest
|
|
75
|
+
);
|
|
76
|
+
GarfishInstance.registerApp(appInfoList);
|
|
77
|
+
const MApp = generateMApp(GarfishConfig, manifest);
|
|
78
|
+
logger("initOptions result", { manifest, GarfishConfig });
|
|
79
|
+
logger("generateApps", { MApp, apps, appInfoList });
|
|
80
|
+
this.setState({
|
|
81
|
+
MApp,
|
|
82
|
+
apps,
|
|
83
|
+
appInfoList
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
load();
|
|
87
|
+
}
|
|
88
|
+
render() {
|
|
89
|
+
logger("GarfishProvider state", this.state);
|
|
90
|
+
return /* @__PURE__ */ jsx(GarfishProvider, {
|
|
91
|
+
value: this.state,
|
|
92
|
+
children: /* @__PURE__ */ jsx(App, {
|
|
93
|
+
...this.props
|
|
94
|
+
})
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return next({
|
|
99
|
+
App: hoistNonReactStatics(GetMicroFrontendApp, App)
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
export {
|
|
106
|
+
plugin_default as default
|
|
107
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import React, { useContext } from "react";
|
|
2
|
+
import { logger } from "../util";
|
|
3
|
+
import { GarfishContext } from "./utils/Context";
|
|
4
|
+
function useModuleApps() {
|
|
5
|
+
const { apps, MApp, appInfoList } = useContext(GarfishContext);
|
|
6
|
+
logger("call useModuleApps", {
|
|
7
|
+
MApp,
|
|
8
|
+
apps: appInfoList,
|
|
9
|
+
...apps
|
|
10
|
+
});
|
|
11
|
+
const Info = new Proxy(
|
|
12
|
+
{
|
|
13
|
+
MApp,
|
|
14
|
+
apps: appInfoList,
|
|
15
|
+
...apps
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
get(target, p, receiver) {
|
|
19
|
+
if (typeof p === "string" && p in target) {
|
|
20
|
+
return Reflect.get(target, p, receiver);
|
|
21
|
+
}
|
|
22
|
+
return () => React.createElement("div");
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
);
|
|
26
|
+
return Info;
|
|
27
|
+
}
|
|
28
|
+
function useModuleApp() {
|
|
29
|
+
const { MApp } = useContext(GarfishContext);
|
|
30
|
+
logger("call useModuleApps", MApp);
|
|
31
|
+
return MApp;
|
|
32
|
+
}
|
|
33
|
+
export {
|
|
34
|
+
useModuleApp,
|
|
35
|
+
useModuleApps
|
|
36
|
+
};
|
|
File without changes
|
|
@@ -1,31 +1,3 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
-
var __spreadValues = (a, b) => {
|
|
7
|
-
for (var prop in b || (b = {}))
|
|
8
|
-
if (__hasOwnProp.call(b, prop))
|
|
9
|
-
__defNormalProp(a, prop, b[prop]);
|
|
10
|
-
if (__getOwnPropSymbols)
|
|
11
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
-
if (__propIsEnum.call(b, prop))
|
|
13
|
-
__defNormalProp(a, prop, b[prop]);
|
|
14
|
-
}
|
|
15
|
-
return a;
|
|
16
|
-
};
|
|
17
|
-
var __objRest = (source, exclude) => {
|
|
18
|
-
var target = {};
|
|
19
|
-
for (var prop in source)
|
|
20
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
21
|
-
target[prop] = source[prop];
|
|
22
|
-
if (source != null && __getOwnPropSymbols)
|
|
23
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
24
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
25
|
-
target[prop] = source[prop];
|
|
26
|
-
}
|
|
27
|
-
return target;
|
|
28
|
-
};
|
|
29
1
|
import { jsx } from "react/jsx-runtime";
|
|
30
2
|
import React from "react";
|
|
31
3
|
import Garfish from "garfish";
|
|
@@ -109,7 +81,7 @@ function generateMApp(options, manifest) {
|
|
|
109
81
|
return {
|
|
110
82
|
mount: (appInfo) => {
|
|
111
83
|
const transferProps = this.filterTransferProps();
|
|
112
|
-
appInfo.props =
|
|
84
|
+
appInfo.props = { ...appInfo.props, ...transferProps };
|
|
113
85
|
if (componetRenderMode) {
|
|
114
86
|
this.setState({
|
|
115
87
|
SubModuleComponent: SubModuleComponent != null ? SubModuleComponent : jupiter_submodule_app_key
|
|
@@ -122,7 +94,7 @@ function generateMApp(options, manifest) {
|
|
|
122
94
|
},
|
|
123
95
|
unmount: (appInfo) => {
|
|
124
96
|
const transferProps = this.filterTransferProps();
|
|
125
|
-
appInfo.props =
|
|
97
|
+
appInfo.props = { ...appInfo.props, ...transferProps };
|
|
126
98
|
if (componetRenderMode) {
|
|
127
99
|
return void 0;
|
|
128
100
|
}
|
|
@@ -145,14 +117,14 @@ function generateMApp(options, manifest) {
|
|
|
145
117
|
logger("MApp componentWillUnmount");
|
|
146
118
|
}
|
|
147
119
|
filterTransferProps() {
|
|
148
|
-
const
|
|
120
|
+
const { style, setLoadingState, ...others } = this.props;
|
|
149
121
|
return others;
|
|
150
122
|
}
|
|
151
123
|
render() {
|
|
152
124
|
const { style } = this.props;
|
|
153
125
|
const { SubModuleComponent } = this.state;
|
|
154
126
|
return /* @__PURE__ */ jsx("div", {
|
|
155
|
-
style:
|
|
127
|
+
style: { ...style },
|
|
156
128
|
id: generateSubAppContainerKey(),
|
|
157
129
|
children: SubModuleComponent && /* @__PURE__ */ jsx(SubModuleComponent, {})
|
|
158
130
|
});
|