@modern-js/plugin-garfish 2.4.1-beta.0 → 2.6.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 +33 -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 +4 -0
- package/dist/{js/node → cjs}/index.js +4 -0
- package/dist/{js/node → cjs}/runtime/index.js +4 -0
- package/dist/{js/node → cjs}/runtime/loadable.js +21 -44
- package/dist/{js/node → cjs}/runtime/plugin.js +34 -82
- package/dist/{js/node → cjs}/runtime/useModuleApps.js +12 -20
- package/dist/{js/node → cjs}/runtime/utils/Context.js +4 -0
- package/dist/{js/node → cjs}/runtime/utils/MApp.js +8 -34
- package/dist/{js/node → cjs}/runtime/utils/apps.js +48 -94
- package/dist/{js/node → cjs}/runtime/utils/setExternal.js +4 -0
- package/dist/{js/node → cjs}/util.js +4 -0
- package/dist/{js/treeshaking → esm}/cli/utils.js +2 -2
- 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}/runtime/loadable.js +21 -46
- package/dist/esm-node/runtime/plugin.js +102 -0
- package/dist/esm-node/runtime/useModuleApps.js +36 -0
- package/dist/{js/modern → esm-node}/runtime/utils/MApp.js +4 -36
- package/dist/{js/modern → esm-node}/runtime/utils/apps.js +44 -96
- package/package.json +16 -17
- package/dist/js/modern/runtime/plugin.js +0 -156
- package/dist/js/modern/runtime/useModuleApps.js +0 -50
- /package/dist/{js/treeshaking → esm}/cli/index.js +0 -0
- /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}/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/utils/Context.js +0 -0
- /package/dist/{js/modern → esm-node}/runtime/utils/setExternal.js +0 -0
- /package/dist/{js/modern → esm-node}/util.js +0 -0
|
@@ -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 });
|
|
@@ -46,30 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
46
17
|
return to;
|
|
47
18
|
};
|
|
48
19
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
49
24
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
50
25
|
mod
|
|
51
26
|
));
|
|
52
27
|
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
28
|
var apps_exports = {};
|
|
74
29
|
__export(apps_exports, {
|
|
75
30
|
generateApps: () => generateApps,
|
|
@@ -112,7 +67,9 @@ function getAppInstance(options, appInfo, manifest) {
|
|
|
112
67
|
const location = (_f = (_e = context == null ? void 0 : context.router) == null ? void 0 : _e.useLocation) == null ? void 0 : _f.call(_e);
|
|
113
68
|
let basename = (options == null ? void 0 : options.basename) || "/";
|
|
114
69
|
if (matchs && matchs.length > 0) {
|
|
115
|
-
const matchItem =
|
|
70
|
+
const matchItem = {
|
|
71
|
+
...matchs[matchs.length - 1]
|
|
72
|
+
};
|
|
116
73
|
for (const key in matchItem.params) {
|
|
117
74
|
matchItem.pathname = matchItem.pathname.replace(
|
|
118
75
|
new RegExp(`/${matchItem.params[key]}$`),
|
|
@@ -133,8 +90,9 @@ function getAppInstance(options, appInfo, manifest) {
|
|
|
133
90
|
}
|
|
134
91
|
}, [location]);
|
|
135
92
|
(0, import_react.useEffect)(() => {
|
|
136
|
-
const
|
|
137
|
-
const loadAppOptions =
|
|
93
|
+
const { setLoadingState, ...userProps } = props;
|
|
94
|
+
const loadAppOptions = {
|
|
95
|
+
...appInfo,
|
|
138
96
|
insulationVariable: [
|
|
139
97
|
...appInfo.insulationVariable || [],
|
|
140
98
|
"_SERVER_DATA"
|
|
@@ -142,7 +100,10 @@ function getAppInstance(options, appInfo, manifest) {
|
|
|
142
100
|
domGetter: `#${domId}`,
|
|
143
101
|
basename,
|
|
144
102
|
cache: true,
|
|
145
|
-
props:
|
|
103
|
+
props: {
|
|
104
|
+
...appInfo.props,
|
|
105
|
+
...userProps
|
|
106
|
+
},
|
|
146
107
|
customLoader: (provider) => {
|
|
147
108
|
const {
|
|
148
109
|
render,
|
|
@@ -170,7 +131,7 @@ function getAppInstance(options, appInfo, manifest) {
|
|
|
170
131
|
}
|
|
171
132
|
};
|
|
172
133
|
}
|
|
173
|
-
}
|
|
134
|
+
};
|
|
174
135
|
setLoadingState({
|
|
175
136
|
isLoading: true,
|
|
176
137
|
error: null
|
|
@@ -178,51 +139,49 @@ function getAppInstance(options, appInfo, manifest) {
|
|
|
178
139
|
(0, import_util.logger)(`MicroApp Garfish.loadApp "${appInfo.name}"`, {
|
|
179
140
|
loadAppOptions
|
|
180
141
|
});
|
|
181
|
-
function renderApp() {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
142
|
+
async function renderApp() {
|
|
143
|
+
try {
|
|
144
|
+
const appInstance = await import_garfish.default.loadApp(
|
|
145
|
+
appInfo.name,
|
|
146
|
+
loadAppOptions
|
|
147
|
+
);
|
|
148
|
+
if (!appInstance) {
|
|
149
|
+
throw new Error(
|
|
150
|
+
`MicroApp Garfish.loadApp "${appInfo.name}" result is null`
|
|
187
151
|
);
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
152
|
+
}
|
|
153
|
+
appRef.current = appInstance;
|
|
154
|
+
setLoadingState({
|
|
155
|
+
isLoading: false
|
|
156
|
+
});
|
|
157
|
+
if (appInstance.mounted && appInstance.appInfo.cache) {
|
|
158
|
+
(0, import_util.logger)(`MicroApp Garfish.loadApp "${appInfo.name}" show`, {
|
|
159
|
+
appInfo: appInstance.appInfo,
|
|
160
|
+
appInstance
|
|
196
161
|
});
|
|
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
|
|
162
|
+
await (appInstance == null ? void 0 : appInstance.show());
|
|
163
|
+
} else {
|
|
164
|
+
(0, import_util.logger)(`MicroApp Garfish.loadApp "${appInfo.name}" mount`, {
|
|
165
|
+
appInfo: appInstance.appInfo,
|
|
166
|
+
appInstance
|
|
214
167
|
});
|
|
168
|
+
await (appInstance == null ? void 0 : appInstance.mount());
|
|
215
169
|
}
|
|
216
|
-
})
|
|
170
|
+
} catch (error) {
|
|
171
|
+
setLoadingState({
|
|
172
|
+
isLoading: true,
|
|
173
|
+
error
|
|
174
|
+
});
|
|
175
|
+
}
|
|
217
176
|
}
|
|
218
177
|
renderApp();
|
|
219
178
|
return () => {
|
|
220
|
-
var
|
|
179
|
+
var _a2, _b2;
|
|
221
180
|
if (appRef.current) {
|
|
222
181
|
const { appInfo: appInfo2 } = appRef.current;
|
|
223
182
|
if (appInfo2.cache) {
|
|
224
183
|
(0, import_util.logger)(`MicroApp Garfish.loadApp "${appInfo2.name}" hide`);
|
|
225
|
-
(
|
|
184
|
+
(_a2 = appRef.current) == null ? void 0 : _a2.hide();
|
|
226
185
|
} else {
|
|
227
186
|
(0, import_util.logger)(`MicroApp Garfish.loadApp "${appInfo2.name}" unmount`);
|
|
228
187
|
(_b2 = appRef.current) == null ? void 0 : _b2.unmount();
|
|
@@ -230,12 +189,7 @@ function getAppInstance(options, appInfo, manifest) {
|
|
|
230
189
|
}
|
|
231
190
|
};
|
|
232
191
|
}, []);
|
|
233
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
|
|
234
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
235
|
-
id: domId,
|
|
236
|
-
children: SubModuleComponent && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SubModuleComponent, {})
|
|
237
|
-
})
|
|
238
|
-
});
|
|
192
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { id: domId, children: SubModuleComponent && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SubModuleComponent, {}) }) });
|
|
239
193
|
}
|
|
240
194
|
return (0, import_loadable.Loadable)(MicroApp)(manifest == null ? void 0 : manifest.loadable);
|
|
241
195
|
}
|
|
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
19
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
24
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
25
|
mod
|
|
22
26
|
));
|
|
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
19
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
24
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
25
|
mod
|
|
22
26
|
));
|
|
@@ -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 };
|
|
@@ -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 {
|
|
@@ -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,39 +61,45 @@ 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
|
);
|
|
107
77
|
const showLoading = (state.isLoading || state.error) && LoadingComponent;
|
|
108
|
-
return /* @__PURE__ */ jsxs(Fragment, {
|
|
109
|
-
|
|
110
|
-
|
|
78
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
79
|
+
showLoading && /* @__PURE__ */ jsx(
|
|
80
|
+
LoadingComponent,
|
|
81
|
+
{
|
|
111
82
|
isLoading: state.isLoading,
|
|
112
83
|
pastDelay: state.pastDelay,
|
|
113
84
|
timedOut: state.timedOut,
|
|
114
85
|
error: state == null ? void 0 : state.error,
|
|
115
86
|
retry
|
|
116
|
-
}
|
|
117
|
-
|
|
87
|
+
}
|
|
88
|
+
),
|
|
89
|
+
/* @__PURE__ */ jsx(
|
|
90
|
+
WrapComponent,
|
|
91
|
+
{
|
|
118
92
|
style: { display: showLoading ? "none" : "block" },
|
|
119
93
|
setLoadingState: (props2) => {
|
|
120
94
|
if (props2.error && !LoadingComponent) {
|
|
121
95
|
throw props2.error;
|
|
122
96
|
}
|
|
123
97
|
setStateWithMountCheck(props2);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
98
|
+
},
|
|
99
|
+
...otherProps
|
|
100
|
+
}
|
|
101
|
+
)
|
|
102
|
+
] });
|
|
128
103
|
};
|
|
129
104
|
};
|
|
130
105
|
}
|
|
@@ -0,0 +1,102 @@
|
|
|
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, { value: this.state, children: /* @__PURE__ */ jsx(App, { ...this.props }) });
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return next({
|
|
94
|
+
App: hoistNonReactStatics(GetMicroFrontendApp, App)
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
export {
|
|
101
|
+
plugin_default as default
|
|
102
|
+
};
|
|
@@ -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
|
+
};
|