@modern-js/plugin-garfish 2.35.0 → 2.36.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/dist/cjs/cli/index.js +75 -76
- package/dist/cjs/cli/utils.js +39 -32
- package/dist/cjs/deps/index.js +35 -9
- package/dist/cjs/index.js +37 -10
- package/dist/cjs/runtime/index.js +43 -28
- package/dist/cjs/runtime/loadable.js +37 -20
- package/dist/cjs/runtime/plugin.js +68 -54
- package/dist/cjs/runtime/useModuleApps.js +43 -24
- package/dist/cjs/runtime/utils/Context.js +37 -18
- package/dist/cjs/runtime/utils/MApp.js +69 -52
- package/dist/cjs/runtime/utils/apps.js +72 -61
- package/dist/cjs/runtime/utils/setExternal.js +40 -18
- package/dist/cjs/util.js +40 -23
- package/dist/esm/cli/index.js +50 -53
- package/dist/esm/cli/utils.js +20 -13
- package/dist/esm/deps/index.js +4 -1
- package/dist/esm/index.js +4 -1
- package/dist/esm/runtime/index.js +10 -3
- package/dist/esm/runtime/loadable.js +10 -7
- package/dist/esm/runtime/plugin.js +19 -18
- package/dist/esm/runtime/useModuleApps.js +8 -4
- package/dist/esm/runtime/utils/Context.js +4 -1
- package/dist/esm/runtime/utils/MApp.js +17 -23
- package/dist/esm/runtime/utils/apps.js +25 -26
- package/dist/esm/runtime/utils/setExternal.js +4 -1
- package/dist/esm/util.js +9 -5
- package/dist/esm-node/cli/index.js +36 -38
- package/dist/esm-node/cli/utils.js +20 -13
- package/dist/esm-node/deps/index.js +4 -1
- package/dist/esm-node/index.js +4 -1
- package/dist/esm-node/runtime/index.js +10 -3
- package/dist/esm-node/runtime/loadable.js +6 -3
- package/dist/esm-node/runtime/plugin.js +10 -10
- package/dist/esm-node/runtime/useModuleApps.js +6 -2
- package/dist/esm-node/runtime/utils/Context.js +4 -1
- package/dist/esm-node/runtime/utils/MApp.js +13 -19
- package/dist/esm-node/runtime/utils/apps.js +18 -21
- package/dist/esm-node/runtime/utils/setExternal.js +4 -1
- package/dist/esm-node/util.js +9 -5
- package/package.json +10 -10
package/dist/esm/cli/utils.js
CHANGED
|
@@ -1,31 +1,38 @@
|
|
|
1
|
-
|
|
1
|
+
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 generateRootDom ({ dom, props, basename }) {\n const mountNode = dom ? (dom.querySelector('#' + MOUNT_ID) || dom) : document.getElementById(MOUNT_ID);\n const mergedProps = {\n ...props,\n basename,\n }\n return { mountNode, props: mergedProps }\n}\n";
|
|
3
3
|
};
|
|
4
|
-
|
|
4
|
+
var makeRenderFunction = function(code) {
|
|
5
5
|
var inGarfishToRender = "\n let { basename, props, dom, appName } = typeof arguments[0] === 'object' && arguments[0] || {};\n if (!canContinueRender({ dom, appName })) return null;\n const rootDomInfo = generateRootDom({dom, props, basename});\n let mountNode = rootDomInfo.mountNode;\n props = rootDomInfo.props;\n ";
|
|
6
6
|
return inGarfishToRender + code.replace("router(", "generateRouterPlugin(basename,").replace(/MOUNT_ID/g, "mountNode").replace("createApp({", "createApp({ props,").replace("bootstrap(AppWrapper, mountNode, root", "bootstrap(AppWrapper, mountNode, root = IS_REACT18 ? ReactDOM.createRoot(mountNode) : null").replace("customBootstrap(AppWrapper", "customBootstrap(AppWrapper, mountNode");
|
|
7
7
|
};
|
|
8
|
-
|
|
9
|
-
var _config_runtime
|
|
10
|
-
if (
|
|
11
|
-
var _config_runtime1
|
|
12
|
-
return
|
|
8
|
+
function getRuntimeConfig(config) {
|
|
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
|
-
return (
|
|
14
|
+
return (config === null || config === void 0 ? void 0 : config.runtime) || {};
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
var _config_runtime,
|
|
18
|
-
if ((
|
|
16
|
+
function setRuntimeConfig(config, key, value) {
|
|
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
|
}
|
|
22
|
-
if ((
|
|
22
|
+
if ((config === null || config === void 0 ? void 0 : config.runtime) && (config === null || config === void 0 ? void 0 : config.runtime[key])) {
|
|
23
23
|
config.runtime[key] = value;
|
|
24
24
|
return void 0;
|
|
25
25
|
}
|
|
26
26
|
return void 0;
|
|
27
27
|
}
|
|
28
|
-
|
|
28
|
+
var generateAsyncEntry = function(code) {
|
|
29
29
|
var transformCode = code.replace("import('./bootstrap.jsx');", "if (!window.__GARFISH__) { import('./bootstrap.jsx'); }");
|
|
30
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
|
+
export {
|
|
33
|
+
generateAsyncEntry,
|
|
34
|
+
getRuntimeConfig,
|
|
35
|
+
makeProvider,
|
|
36
|
+
makeRenderFunction,
|
|
37
|
+
setRuntimeConfig
|
|
38
|
+
};
|
package/dist/esm/deps/index.js
CHANGED
package/dist/esm/index.js
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { default as default2 } from "./plugin";
|
|
2
|
+
import { useModuleApps, useModuleApp } from "./useModuleApps";
|
|
3
|
+
import { default as default3, default as default4 } from "garfish";
|
|
4
|
+
export {
|
|
5
|
+
default3 as Garfish,
|
|
6
|
+
default2 as default,
|
|
7
|
+
default4 as garfish,
|
|
8
|
+
useModuleApp,
|
|
9
|
+
useModuleApps
|
|
10
|
+
};
|
|
@@ -10,10 +10,10 @@ var DEFAULT_LOADABLE = {
|
|
|
10
10
|
timeout: 1e4,
|
|
11
11
|
loading: null
|
|
12
12
|
};
|
|
13
|
-
|
|
13
|
+
function Loadable(WrapComponent) {
|
|
14
14
|
return function(defaultLoadable) {
|
|
15
15
|
return function Lodable(props) {
|
|
16
|
-
var _props_loadable
|
|
16
|
+
var _props_loadable;
|
|
17
17
|
var _props_loadable1 = props.loadable, loadable = _props_loadable1 === void 0 ? defaultLoadable !== null && defaultLoadable !== void 0 ? defaultLoadable : DEFAULT_LOADABLE : _props_loadable1, otherProps = _object_without_properties(props, [
|
|
18
18
|
"loadable"
|
|
19
19
|
]);
|
|
@@ -50,10 +50,10 @@ export function Loadable(WrapComponent) {
|
|
|
50
50
|
var LoadingComponent = (_props_loadable = props.loadable) === null || _props_loadable === void 0 ? void 0 : _props_loadable.loading;
|
|
51
51
|
useEffect(function() {
|
|
52
52
|
logger("Loadable render state", {
|
|
53
|
-
state
|
|
53
|
+
state,
|
|
54
54
|
props: otherProps,
|
|
55
|
-
loadable
|
|
56
|
-
defaultLoadable
|
|
55
|
+
loadable,
|
|
56
|
+
defaultLoadable
|
|
57
57
|
});
|
|
58
58
|
return function() {
|
|
59
59
|
setStateWithMountCheck({
|
|
@@ -93,8 +93,8 @@ export function Loadable(WrapComponent) {
|
|
|
93
93
|
isLoading: state.isLoading,
|
|
94
94
|
pastDelay: state.pastDelay,
|
|
95
95
|
timedOut: state.timedOut,
|
|
96
|
-
error:
|
|
97
|
-
retry
|
|
96
|
+
error: state === null || state === void 0 ? void 0 : state.error,
|
|
97
|
+
retry
|
|
98
98
|
}),
|
|
99
99
|
/* @__PURE__ */ _jsx(WrapComponent, _object_spread({
|
|
100
100
|
style: {
|
|
@@ -112,3 +112,6 @@ export function Loadable(WrapComponent) {
|
|
|
112
112
|
};
|
|
113
113
|
};
|
|
114
114
|
}
|
|
115
|
+
export {
|
|
116
|
+
Loadable
|
|
117
|
+
};
|
|
@@ -24,29 +24,27 @@ function initOptions() {
|
|
|
24
24
|
}
|
|
25
25
|
function _initOptions() {
|
|
26
26
|
_initOptions = _async_to_generator(function() {
|
|
27
|
-
var manifest, options,
|
|
27
|
+
var manifest, options, _window_modern_manifest, _window, _window_modern_manifest1, _window1, apps, getAppList, _window_modern_manifest2, _window2;
|
|
28
28
|
var _arguments = arguments;
|
|
29
29
|
return _ts_generator(this, function(_state) {
|
|
30
30
|
switch (_state.label) {
|
|
31
31
|
case 0:
|
|
32
32
|
manifest = _arguments.length > 0 && _arguments[0] !== void 0 ? _arguments[0] : {}, options = _arguments.length > 1 ? _arguments[1] : void 0;
|
|
33
33
|
apps = options.apps || [];
|
|
34
|
-
if (
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
;
|
|
38
|
-
apps = (_manifest3 = manifest) === null || _manifest3 === void 0 ? void 0 : _manifest3.modules;
|
|
34
|
+
if (manifest === null || manifest === void 0 ? void 0 : manifest.modules) {
|
|
35
|
+
if ((manifest === null || manifest === void 0 ? void 0 : manifest.modules.length) > 0) {
|
|
36
|
+
apps = manifest === null || manifest === void 0 ? void 0 : manifest.modules;
|
|
39
37
|
}
|
|
40
38
|
logger("manifest modules", apps);
|
|
41
39
|
}
|
|
42
|
-
if (!(
|
|
40
|
+
if (!(manifest === null || manifest === void 0 ? void 0 : manifest.getAppList))
|
|
43
41
|
return [
|
|
44
42
|
3,
|
|
45
43
|
2
|
|
46
44
|
];
|
|
47
45
|
return [
|
|
48
46
|
4,
|
|
49
|
-
|
|
47
|
+
manifest === null || manifest === void 0 ? void 0 : manifest.getAppList(manifest)
|
|
50
48
|
];
|
|
51
49
|
case 1:
|
|
52
50
|
getAppList = _state.sent();
|
|
@@ -64,7 +62,7 @@ function _initOptions() {
|
|
|
64
62
|
return [
|
|
65
63
|
2,
|
|
66
64
|
_object_spread_props(_object_spread({}, options), {
|
|
67
|
-
apps
|
|
65
|
+
apps
|
|
68
66
|
})
|
|
69
67
|
];
|
|
70
68
|
}
|
|
@@ -72,7 +70,7 @@ function _initOptions() {
|
|
|
72
70
|
});
|
|
73
71
|
return _initOptions.apply(this, arguments);
|
|
74
72
|
}
|
|
75
|
-
|
|
73
|
+
function plugin_default(config) {
|
|
76
74
|
return {
|
|
77
75
|
name: "@modern-js/garfish-plugin",
|
|
78
76
|
setup: function() {
|
|
@@ -130,18 +128,18 @@ export default function(config) {
|
|
|
130
128
|
GarfishInstance.registerApp(appInfoList);
|
|
131
129
|
MApp = generateMApp(GarfishConfig, manifest);
|
|
132
130
|
logger("initOptions result", {
|
|
133
|
-
manifest
|
|
134
|
-
GarfishConfig
|
|
131
|
+
manifest,
|
|
132
|
+
GarfishConfig
|
|
135
133
|
});
|
|
136
134
|
logger("generateApps", {
|
|
137
|
-
MApp
|
|
138
|
-
apps
|
|
139
|
-
appInfoList
|
|
135
|
+
MApp,
|
|
136
|
+
apps,
|
|
137
|
+
appInfoList
|
|
140
138
|
});
|
|
141
139
|
_this1.setState({
|
|
142
|
-
MApp
|
|
143
|
-
apps
|
|
144
|
-
appInfoList
|
|
140
|
+
MApp,
|
|
141
|
+
apps,
|
|
142
|
+
appInfoList
|
|
145
143
|
});
|
|
146
144
|
return [
|
|
147
145
|
2
|
|
@@ -179,3 +177,6 @@ export default function(config) {
|
|
|
179
177
|
};
|
|
180
178
|
}
|
|
181
179
|
;
|
|
180
|
+
export {
|
|
181
|
+
plugin_default as default
|
|
182
|
+
};
|
|
@@ -2,14 +2,14 @@ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
|
2
2
|
import React, { useContext } from "react";
|
|
3
3
|
import { logger } from "../util";
|
|
4
4
|
import { GarfishContext } from "./utils/Context";
|
|
5
|
-
|
|
5
|
+
function useModuleApps() {
|
|
6
6
|
var _useContext = useContext(GarfishContext), apps = _useContext.apps, MApp = _useContext.MApp, appInfoList = _useContext.appInfoList;
|
|
7
7
|
logger("call useModuleApps", _object_spread({
|
|
8
|
-
MApp
|
|
8
|
+
MApp,
|
|
9
9
|
apps: appInfoList
|
|
10
10
|
}, apps));
|
|
11
11
|
var Info = new Proxy(_object_spread({
|
|
12
|
-
MApp
|
|
12
|
+
MApp,
|
|
13
13
|
apps: appInfoList
|
|
14
14
|
}, apps), {
|
|
15
15
|
get: function get(target, p, receiver) {
|
|
@@ -23,8 +23,12 @@ export function useModuleApps() {
|
|
|
23
23
|
});
|
|
24
24
|
return Info;
|
|
25
25
|
}
|
|
26
|
-
|
|
26
|
+
function useModuleApp() {
|
|
27
27
|
var MApp = useContext(GarfishContext).MApp;
|
|
28
28
|
logger("call useModuleApps", MApp);
|
|
29
29
|
return MApp;
|
|
30
30
|
}
|
|
31
|
+
export {
|
|
32
|
+
useModuleApp,
|
|
33
|
+
useModuleApps
|
|
34
|
+
};
|
|
@@ -12,8 +12,7 @@ import React from "react";
|
|
|
12
12
|
import Garfish from "garfish";
|
|
13
13
|
import { logger, generateSubAppContainerKey } from "../../util";
|
|
14
14
|
import { Loadable } from "../loadable";
|
|
15
|
-
|
|
16
|
-
var _manifest;
|
|
15
|
+
function generateMApp(options, manifest) {
|
|
17
16
|
var MApp = /* @__PURE__ */ function(_React_Component) {
|
|
18
17
|
"use strict";
|
|
19
18
|
_inherits(MApp2, _React_Component);
|
|
@@ -44,7 +43,6 @@ export function generateMApp(options, manifest) {
|
|
|
44
43
|
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
45
44
|
args[_key - 1] = arguments[_key];
|
|
46
45
|
}
|
|
47
|
-
var _beforeLoad;
|
|
48
46
|
logger("MApp beforeLoad", [
|
|
49
47
|
appInfo
|
|
50
48
|
]);
|
|
@@ -54,7 +52,7 @@ export function generateMApp(options, manifest) {
|
|
|
54
52
|
error: null
|
|
55
53
|
});
|
|
56
54
|
}
|
|
57
|
-
return
|
|
55
|
+
return beforeLoad === null || beforeLoad === void 0 ? void 0 : beforeLoad.apply(void 0, [
|
|
58
56
|
appInfo
|
|
59
57
|
].concat(_to_consumable_array(args)));
|
|
60
58
|
},
|
|
@@ -62,14 +60,13 @@ export function generateMApp(options, manifest) {
|
|
|
62
60
|
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
63
61
|
args[_key - 1] = arguments[_key];
|
|
64
62
|
}
|
|
65
|
-
var _beforeMount;
|
|
66
63
|
logger("MApp beforeMount", args);
|
|
67
64
|
if (appInfo.activeWhen) {
|
|
68
65
|
setLoadingState({
|
|
69
66
|
isLoading: false
|
|
70
67
|
});
|
|
71
68
|
}
|
|
72
|
-
return
|
|
69
|
+
return beforeMount === null || beforeMount === void 0 ? void 0 : beforeMount.apply(void 0, [
|
|
73
70
|
appInfo
|
|
74
71
|
].concat(_to_consumable_array(args)));
|
|
75
72
|
},
|
|
@@ -77,14 +74,13 @@ export function generateMApp(options, manifest) {
|
|
|
77
74
|
for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
78
75
|
args[_key - 2] = arguments[_key];
|
|
79
76
|
}
|
|
80
|
-
var _errorLoadApp;
|
|
81
77
|
logger("MApp errorLoadApp", error, args);
|
|
82
78
|
if (appInfo.activeWhen) {
|
|
83
79
|
setLoadingState({
|
|
84
|
-
error
|
|
80
|
+
error
|
|
85
81
|
});
|
|
86
82
|
}
|
|
87
|
-
return
|
|
83
|
+
return errorLoadApp === null || errorLoadApp === void 0 ? void 0 : errorLoadApp.apply(void 0, [
|
|
88
84
|
error,
|
|
89
85
|
appInfo
|
|
90
86
|
].concat(_to_consumable_array(args)));
|
|
@@ -93,14 +89,13 @@ export function generateMApp(options, manifest) {
|
|
|
93
89
|
for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
94
90
|
args[_key - 2] = arguments[_key];
|
|
95
91
|
}
|
|
96
|
-
var _errorMountApp;
|
|
97
92
|
logger("MApp errorMountApp", error, args);
|
|
98
93
|
if (appInfo.activeWhen) {
|
|
99
94
|
setLoadingState({
|
|
100
|
-
error
|
|
95
|
+
error
|
|
101
96
|
});
|
|
102
97
|
}
|
|
103
|
-
return
|
|
98
|
+
return errorMountApp === null || errorMountApp === void 0 ? void 0 : errorMountApp.apply(void 0, [
|
|
104
99
|
error,
|
|
105
100
|
appInfo
|
|
106
101
|
].concat(_to_consumable_array(args)));
|
|
@@ -109,22 +104,20 @@ export function generateMApp(options, manifest) {
|
|
|
109
104
|
for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
110
105
|
args[_key - 2] = arguments[_key];
|
|
111
106
|
}
|
|
112
|
-
var _errorUnmountApp;
|
|
113
107
|
logger("MApp errorUnmountApp", error, args);
|
|
114
108
|
if (appInfo.activeWhen) {
|
|
115
109
|
setLoadingState({
|
|
116
|
-
error
|
|
110
|
+
error
|
|
117
111
|
});
|
|
118
112
|
}
|
|
119
|
-
return
|
|
113
|
+
return errorUnmountApp === null || errorUnmountApp === void 0 ? void 0 : errorUnmountApp.apply(void 0, [
|
|
120
114
|
error,
|
|
121
115
|
appInfo
|
|
122
116
|
].concat(_to_consumable_array(args)));
|
|
123
117
|
},
|
|
124
118
|
customLoader: function(provider) {
|
|
125
|
-
var _manifest2;
|
|
126
119
|
var render = provider.render, destroy = provider.destroy, SubModuleComponent = provider.SubModuleComponent, jupiter_submodule_app_key = provider.jupiter_submodule_app_key;
|
|
127
|
-
var componetRenderMode = (
|
|
120
|
+
var componetRenderMode = (manifest === null || manifest === void 0 ? void 0 : manifest.componentRender) && (SubModuleComponent || jupiter_submodule_app_key);
|
|
128
121
|
return {
|
|
129
122
|
mount: function(appInfo) {
|
|
130
123
|
var transferProps = _this.filterTransferProps();
|
|
@@ -135,22 +128,20 @@ export function generateMApp(options, manifest) {
|
|
|
135
128
|
});
|
|
136
129
|
return void 0;
|
|
137
130
|
} else {
|
|
138
|
-
var _render;
|
|
139
131
|
logger("MicroApp customer render", appInfo);
|
|
140
|
-
return
|
|
132
|
+
return render === null || render === void 0 ? void 0 : render.apply(provider, [
|
|
141
133
|
appInfo
|
|
142
134
|
]);
|
|
143
135
|
}
|
|
144
136
|
},
|
|
145
137
|
unmount: function(appInfo) {
|
|
146
|
-
var _destroy;
|
|
147
138
|
var transferProps = _this.filterTransferProps();
|
|
148
139
|
appInfo.props = _object_spread({}, appInfo.props, transferProps);
|
|
149
140
|
if (componetRenderMode) {
|
|
150
141
|
return void 0;
|
|
151
142
|
}
|
|
152
143
|
logger("MicroApp customer destroy", appInfo);
|
|
153
|
-
return
|
|
144
|
+
return destroy === null || destroy === void 0 ? void 0 : destroy.apply(provider, [
|
|
154
145
|
appInfo
|
|
155
146
|
]);
|
|
156
147
|
}
|
|
@@ -159,7 +150,7 @@ export function generateMApp(options, manifest) {
|
|
|
159
150
|
};
|
|
160
151
|
logger("MApp componentDidMount", {
|
|
161
152
|
garfishRunning: Garfish.running,
|
|
162
|
-
garfishOptions
|
|
153
|
+
garfishOptions
|
|
163
154
|
});
|
|
164
155
|
if (!Garfish.running) {
|
|
165
156
|
Garfish.run(garfishOptions);
|
|
@@ -200,5 +191,8 @@ export function generateMApp(options, manifest) {
|
|
|
200
191
|
]);
|
|
201
192
|
return MApp2;
|
|
202
193
|
}(React.Component);
|
|
203
|
-
return Loadable(MApp)(
|
|
194
|
+
return Loadable(MApp)(manifest === null || manifest === void 0 ? void 0 : manifest.loadable);
|
|
204
195
|
}
|
|
196
|
+
export {
|
|
197
|
+
generateMApp
|
|
198
|
+
};
|
|
@@ -11,7 +11,7 @@ import { RuntimeReactContext } from "@modern-js/runtime";
|
|
|
11
11
|
import Garfish from "garfish";
|
|
12
12
|
import { logger, generateSubAppContainerKey } from "../../util";
|
|
13
13
|
import { Loadable } from "../loadable";
|
|
14
|
-
|
|
14
|
+
function pathJoin() {
|
|
15
15
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
16
16
|
args[_key] = arguments[_key];
|
|
17
17
|
}
|
|
@@ -33,15 +33,15 @@ export function pathJoin() {
|
|
|
33
33
|
}
|
|
34
34
|
function getAppInstance(options, appInfo, manifest) {
|
|
35
35
|
var MicroApp = function MicroApp2(props) {
|
|
36
|
-
var _context_router_useRouteMatch, _context_router,
|
|
36
|
+
var _context_router_useRouteMatch, _context_router, _context_router_useMatches, _context_router1, _context_router_useLocation, _context_router2;
|
|
37
37
|
var appRef = useRef(null);
|
|
38
38
|
var domId = generateSubAppContainerKey(appInfo);
|
|
39
39
|
var _useState = _sliced_to_array(useState(), 2), SubModuleComponent = _useState[0], setSubModuleComponent = _useState[1];
|
|
40
40
|
var context = useContext(RuntimeReactContext);
|
|
41
|
-
var match =
|
|
42
|
-
var matchs =
|
|
43
|
-
var location =
|
|
44
|
-
var basename = (
|
|
41
|
+
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);
|
|
42
|
+
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);
|
|
43
|
+
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);
|
|
44
|
+
var basename = (options === null || options === void 0 ? void 0 : options.basename) || "/";
|
|
45
45
|
if (matchs && matchs.length > 0) {
|
|
46
46
|
var matchItem = _object_spread({}, matchs[matchs.length - 1]);
|
|
47
47
|
for (var key in matchItem.params) {
|
|
@@ -49,8 +49,7 @@ function getAppInstance(options, appInfo, manifest) {
|
|
|
49
49
|
}
|
|
50
50
|
basename = pathJoin(basename, matchItem.pathname || "/");
|
|
51
51
|
} else if (match) {
|
|
52
|
-
|
|
53
|
-
basename = pathJoin(basename, ((_match = match) === null || _match === void 0 ? void 0 : _match.path) || "/");
|
|
52
|
+
basename = pathJoin(basename, (match === null || match === void 0 ? void 0 : match.path) || "/");
|
|
54
53
|
}
|
|
55
54
|
useEffect(function() {
|
|
56
55
|
if (location && locationHref !== location.pathname && !Garfish.running) {
|
|
@@ -72,13 +71,12 @@ function getAppInstance(options, appInfo, manifest) {
|
|
|
72
71
|
"_SERVER_DATA"
|
|
73
72
|
]),
|
|
74
73
|
domGetter: "#".concat(domId),
|
|
75
|
-
basename
|
|
74
|
+
basename,
|
|
76
75
|
cache: true,
|
|
77
76
|
props: _object_spread({}, appInfo.props, userProps),
|
|
78
77
|
customLoader: function(provider) {
|
|
79
|
-
var _manifest2;
|
|
80
78
|
var render = provider.render, destroy = provider.destroy, SubModuleComponent2 = provider.SubModuleComponent, jupiter_submodule_app_key = provider.jupiter_submodule_app_key;
|
|
81
|
-
var componetRenderMode = (
|
|
79
|
+
var componetRenderMode = (manifest === null || manifest === void 0 ? void 0 : manifest.componentRender) && (SubModuleComponent2 || jupiter_submodule_app_key);
|
|
82
80
|
return {
|
|
83
81
|
mount: function() {
|
|
84
82
|
for (var _len = arguments.length, _$props = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
@@ -88,21 +86,19 @@ function getAppInstance(options, appInfo, manifest) {
|
|
|
88
86
|
setSubModuleComponent(SubModuleComponent2);
|
|
89
87
|
return void 0;
|
|
90
88
|
} else {
|
|
91
|
-
var _render;
|
|
92
89
|
logger("MicroApp customer render", _$props);
|
|
93
|
-
return
|
|
90
|
+
return render === null || render === void 0 ? void 0 : render.apply(provider, _$props);
|
|
94
91
|
}
|
|
95
92
|
},
|
|
96
93
|
unmount: function unmount() {
|
|
97
94
|
for (var _len = arguments.length, _$props = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
98
95
|
_$props[_key] = arguments[_key];
|
|
99
96
|
}
|
|
100
|
-
var _destroy;
|
|
101
97
|
if (componetRenderMode) {
|
|
102
98
|
return void 0;
|
|
103
99
|
}
|
|
104
100
|
logger("MicroApp customer destroy", _$props);
|
|
105
|
-
return
|
|
101
|
+
return destroy === null || destroy === void 0 ? void 0 : destroy.apply(provider, _$props);
|
|
106
102
|
}
|
|
107
103
|
};
|
|
108
104
|
}
|
|
@@ -112,14 +108,14 @@ function getAppInstance(options, appInfo, manifest) {
|
|
|
112
108
|
error: null
|
|
113
109
|
});
|
|
114
110
|
logger('MicroApp Garfish.loadApp "'.concat(appInfo.name, '"'), {
|
|
115
|
-
loadAppOptions
|
|
111
|
+
loadAppOptions
|
|
116
112
|
});
|
|
117
113
|
function renderApp() {
|
|
118
114
|
return _renderApp.apply(this, arguments);
|
|
119
115
|
}
|
|
120
116
|
function _renderApp() {
|
|
121
117
|
_renderApp = _async_to_generator(function() {
|
|
122
|
-
var appInstance,
|
|
118
|
+
var appInstance, error;
|
|
123
119
|
return _ts_generator(this, function(_state) {
|
|
124
120
|
switch (_state.label) {
|
|
125
121
|
case 0:
|
|
@@ -149,11 +145,11 @@ function getAppInstance(options, appInfo, manifest) {
|
|
|
149
145
|
];
|
|
150
146
|
logger('MicroApp Garfish.loadApp "'.concat(appInfo.name, '" show'), {
|
|
151
147
|
appInfo: appInstance.appInfo,
|
|
152
|
-
appInstance
|
|
148
|
+
appInstance
|
|
153
149
|
});
|
|
154
150
|
return [
|
|
155
151
|
4,
|
|
156
|
-
|
|
152
|
+
appInstance === null || appInstance === void 0 ? void 0 : appInstance.show()
|
|
157
153
|
];
|
|
158
154
|
case 2:
|
|
159
155
|
_state.sent();
|
|
@@ -164,11 +160,11 @@ function getAppInstance(options, appInfo, manifest) {
|
|
|
164
160
|
case 3:
|
|
165
161
|
logger('MicroApp Garfish.loadApp "'.concat(appInfo.name, '" mount'), {
|
|
166
162
|
appInfo: appInstance.appInfo,
|
|
167
|
-
appInstance
|
|
163
|
+
appInstance
|
|
168
164
|
});
|
|
169
165
|
return [
|
|
170
166
|
4,
|
|
171
|
-
|
|
167
|
+
appInstance === null || appInstance === void 0 ? void 0 : appInstance.mount()
|
|
172
168
|
];
|
|
173
169
|
case 4:
|
|
174
170
|
_state.sent();
|
|
@@ -182,7 +178,7 @@ function getAppInstance(options, appInfo, manifest) {
|
|
|
182
178
|
error = _state.sent();
|
|
183
179
|
setLoadingState({
|
|
184
180
|
isLoading: true,
|
|
185
|
-
error
|
|
181
|
+
error
|
|
186
182
|
});
|
|
187
183
|
return [
|
|
188
184
|
3,
|
|
@@ -220,11 +216,10 @@ function getAppInstance(options, appInfo, manifest) {
|
|
|
220
216
|
})
|
|
221
217
|
});
|
|
222
218
|
};
|
|
223
|
-
var _manifest;
|
|
224
219
|
var locationHref = "";
|
|
225
|
-
return Loadable(MicroApp)(
|
|
220
|
+
return Loadable(MicroApp)(manifest === null || manifest === void 0 ? void 0 : manifest.loadable);
|
|
226
221
|
}
|
|
227
|
-
|
|
222
|
+
function generateApps(options, manifest) {
|
|
228
223
|
var _options_apps;
|
|
229
224
|
var apps = {};
|
|
230
225
|
(_options_apps = options.apps) === null || _options_apps === void 0 ? void 0 : _options_apps.forEach(function(appInfo) {
|
|
@@ -233,7 +228,11 @@ export function generateApps(options, manifest) {
|
|
|
233
228
|
apps[appInfo.name] = Component;
|
|
234
229
|
});
|
|
235
230
|
return {
|
|
236
|
-
apps
|
|
231
|
+
apps,
|
|
237
232
|
appInfoList: options.apps || []
|
|
238
233
|
};
|
|
239
234
|
}
|
|
235
|
+
export {
|
|
236
|
+
generateApps,
|
|
237
|
+
pathJoin
|
|
238
|
+
};
|
|
@@ -2,7 +2,7 @@ import React from "react";
|
|
|
2
2
|
import ReactDOM from "react-dom";
|
|
3
3
|
import garfish from "garfish";
|
|
4
4
|
import { logger } from "../../util";
|
|
5
|
-
|
|
5
|
+
function setExternal_default() {
|
|
6
6
|
logger("setExternal ", {
|
|
7
7
|
react: React,
|
|
8
8
|
"react-dom": ReactDOM
|
|
@@ -11,3 +11,6 @@ export default function() {
|
|
|
11
11
|
garfish.setExternal("react-dom", ReactDOM);
|
|
12
12
|
}
|
|
13
13
|
;
|
|
14
|
+
export {
|
|
15
|
+
setExternal_default as default
|
|
16
|
+
};
|
package/dist/esm/util.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import createDebug from "debug";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
return moduleInfo ? "modern_sub_app_container_".concat(decodeURIComponent((_moduleInfo = moduleInfo) === null || _moduleInfo === void 0 ? void 0 : _moduleInfo.name)) : "modern_sub_app_container";
|
|
2
|
+
var logger = createDebug("modern-js:plugin-garfish");
|
|
3
|
+
var SUBMODULE_APP_COMPONENT_KEY = "SubModuleComponent";
|
|
4
|
+
function generateSubAppContainerKey(moduleInfo) {
|
|
5
|
+
return moduleInfo ? "modern_sub_app_container_".concat(decodeURIComponent(moduleInfo === null || moduleInfo === void 0 ? void 0 : moduleInfo.name)) : "modern_sub_app_container";
|
|
7
6
|
}
|
|
7
|
+
export {
|
|
8
|
+
SUBMODULE_APP_COMPONENT_KEY,
|
|
9
|
+
generateSubAppContainerKey,
|
|
10
|
+
logger
|
|
11
|
+
};
|