@modern-js/plugin-garfish 2.27.0 → 2.29.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.
@@ -87,20 +87,20 @@ export const makeRenderFunction = (code) => {
87
87
  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");
88
88
  };
89
89
  export function getRuntimeConfig(config) {
90
- var _config_runtime;
91
- if (config === null || config === void 0 ? void 0 : (_config_runtime = config.runtime) === null || _config_runtime === void 0 ? void 0 : _config_runtime.features) {
92
- var _config_runtime1;
93
- return config === null || config === void 0 ? void 0 : (_config_runtime1 = config.runtime) === null || _config_runtime1 === void 0 ? void 0 : _config_runtime1.features;
90
+ var _config_runtime, _config, _config1;
91
+ if ((_config = config) === null || _config === void 0 ? void 0 : (_config_runtime = _config.runtime) === null || _config_runtime === void 0 ? void 0 : _config_runtime.features) {
92
+ var _config_runtime1, _config2;
93
+ return (_config2 = config) === null || _config2 === void 0 ? void 0 : (_config_runtime1 = _config2.runtime) === null || _config_runtime1 === void 0 ? void 0 : _config_runtime1.features;
94
94
  }
95
- return (config === null || config === void 0 ? void 0 : config.runtime) || {};
95
+ return ((_config1 = config) === null || _config1 === void 0 ? void 0 : _config1.runtime) || {};
96
96
  }
97
97
  export function setRuntimeConfig(config, key, value) {
98
- var _config_runtime, _config_runtime1;
99
- 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])) {
98
+ var _config_runtime, _config, _config_runtime1, _config1, _config2, _config3;
99
+ if (((_config = config) === null || _config === void 0 ? void 0 : (_config_runtime = _config.runtime) === null || _config_runtime === void 0 ? void 0 : _config_runtime.features) && ((_config1 = config) === null || _config1 === void 0 ? void 0 : (_config_runtime1 = _config1.runtime) === null || _config_runtime1 === void 0 ? void 0 : _config_runtime1.features[key])) {
100
100
  config.runtime.features[key] = value;
101
101
  return void 0;
102
102
  }
103
- if ((config === null || config === void 0 ? void 0 : config.runtime) && (config === null || config === void 0 ? void 0 : config.runtime[key])) {
103
+ if (((_config2 = config) === null || _config2 === void 0 ? void 0 : _config2.runtime) && ((_config3 = config) === null || _config3 === void 0 ? void 0 : _config3.runtime[key])) {
104
104
  config.runtime[key] = value;
105
105
  return void 0;
106
106
  }
@@ -9,7 +9,7 @@ const DEFAULT_LOADABLE = {
9
9
  export function Loadable(WrapComponent) {
10
10
  return function(defaultLoadable) {
11
11
  return function Lodable(props) {
12
- var _props_loadable;
12
+ var _props_loadable, _state;
13
13
  const { loadable = defaultLoadable !== null && defaultLoadable !== void 0 ? defaultLoadable : DEFAULT_LOADABLE, ...otherProps } = props;
14
14
  let delayTimer = null;
15
15
  let timeoutTimer = null;
@@ -89,7 +89,7 @@ export function Loadable(WrapComponent) {
89
89
  isLoading: state.isLoading,
90
90
  pastDelay: state.pastDelay,
91
91
  timedOut: state.timedOut,
92
- error: state === null || state === void 0 ? void 0 : state.error,
92
+ error: (_state = state) === null || _state === void 0 ? void 0 : _state.error,
93
93
  retry
94
94
  }),
95
95
  /* @__PURE__ */ _jsx(WrapComponent, {
@@ -9,24 +9,27 @@ import setExternal from "./utils/setExternal";
9
9
  import { generateMApp } from "./utils/MApp";
10
10
  import { generateApps } from "./utils/apps";
11
11
  async function initOptions(manifest = {}, options) {
12
- var _window_modern_manifest, _window_modern_manifest1;
12
+ var _manifest, _manifest1, _window_modern_manifest, _window, _window_modern_manifest1, _window1;
13
13
  let apps = options.apps || [];
14
- if (manifest === null || manifest === void 0 ? void 0 : manifest.modules) {
15
- if ((manifest === null || manifest === void 0 ? void 0 : manifest.modules.length) > 0) {
16
- apps = manifest === null || manifest === void 0 ? void 0 : manifest.modules;
14
+ if ((_manifest = manifest) === null || _manifest === void 0 ? void 0 : _manifest.modules) {
15
+ var _manifest2;
16
+ if (((_manifest2 = manifest) === null || _manifest2 === void 0 ? void 0 : _manifest2.modules.length) > 0) {
17
+ var _manifest3;
18
+ apps = (_manifest3 = manifest) === null || _manifest3 === void 0 ? void 0 : _manifest3.modules;
17
19
  }
18
20
  logger("manifest modules", apps);
19
21
  }
20
- if (manifest === null || manifest === void 0 ? void 0 : manifest.getAppList) {
21
- const getAppList = await (manifest === null || manifest === void 0 ? void 0 : manifest.getAppList(manifest));
22
+ if ((_manifest1 = manifest) === null || _manifest1 === void 0 ? void 0 : _manifest1.getAppList) {
23
+ var _manifest4;
24
+ const getAppList = await ((_manifest4 = manifest) === null || _manifest4 === void 0 ? void 0 : _manifest4.getAppList(manifest));
22
25
  if (getAppList.length > 0) {
23
26
  apps = getAppList;
24
27
  }
25
28
  logger("getAppList modules", apps);
26
29
  }
27
- if ((window === null || window === void 0 ? void 0 : (_window_modern_manifest = window.modern_manifest) === null || _window_modern_manifest === void 0 ? void 0 : _window_modern_manifest.modules) && (window === null || window === void 0 ? void 0 : (_window_modern_manifest1 = window.modern_manifest) === null || _window_modern_manifest1 === void 0 ? void 0 : _window_modern_manifest1.modules.length) > 0) {
28
- var _window_modern_manifest2;
29
- apps = window === null || window === void 0 ? void 0 : (_window_modern_manifest2 = window.modern_manifest) === null || _window_modern_manifest2 === void 0 ? void 0 : _window_modern_manifest2.modules;
30
+ if (((_window = window) === null || _window === void 0 ? void 0 : (_window_modern_manifest = _window.modern_manifest) === null || _window_modern_manifest === void 0 ? void 0 : _window_modern_manifest.modules) && ((_window1 = window) === null || _window1 === void 0 ? void 0 : (_window_modern_manifest1 = _window1.modern_manifest) === null || _window_modern_manifest1 === void 0 ? void 0 : _window_modern_manifest1.modules.length) > 0) {
31
+ var _window_modern_manifest2, _window2;
32
+ apps = (_window2 = window) === null || _window2 === void 0 ? void 0 : (_window_modern_manifest2 = _window2.modern_manifest) === null || _window_modern_manifest2 === void 0 ? void 0 : _window_modern_manifest2.modules;
30
33
  logger("modern_manifest", apps);
31
34
  }
32
35
  return {
@@ -5,6 +5,7 @@ import Garfish from "garfish";
5
5
  import { logger, generateSubAppContainerKey } from "../../util";
6
6
  import { Loadable } from "../loadable";
7
7
  export function generateMApp(options, manifest) {
8
+ var _manifest;
8
9
  class MApp extends React.Component {
9
10
  componentDidMount() {
10
11
  const { domId } = this.state;
@@ -16,6 +17,7 @@ export function generateMApp(options, manifest) {
16
17
  const garfishOptions = {
17
18
  domGetter: `#${domId}`,
18
19
  beforeLoad(appInfo, ...args) {
20
+ var _beforeLoad;
19
21
  logger("MApp beforeLoad", [
20
22
  appInfo
21
23
  ]);
@@ -25,47 +27,52 @@ export function generateMApp(options, manifest) {
25
27
  error: null
26
28
  });
27
29
  }
28
- return beforeLoad === null || beforeLoad === void 0 ? void 0 : beforeLoad(appInfo, ...args);
30
+ return (_beforeLoad = beforeLoad) === null || _beforeLoad === void 0 ? void 0 : _beforeLoad(appInfo, ...args);
29
31
  },
30
32
  beforeMount(appInfo, ...args) {
33
+ var _beforeMount;
31
34
  logger("MApp beforeMount", args);
32
35
  if (appInfo.activeWhen) {
33
36
  setLoadingState({
34
37
  isLoading: false
35
38
  });
36
39
  }
37
- return beforeMount === null || beforeMount === void 0 ? void 0 : beforeMount(appInfo, ...args);
40
+ return (_beforeMount = beforeMount) === null || _beforeMount === void 0 ? void 0 : _beforeMount(appInfo, ...args);
38
41
  },
39
42
  errorLoadApp(error, appInfo, ...args) {
43
+ var _errorLoadApp;
40
44
  logger("MApp errorLoadApp", error, args);
41
45
  if (appInfo.activeWhen) {
42
46
  setLoadingState({
43
47
  error
44
48
  });
45
49
  }
46
- return errorLoadApp === null || errorLoadApp === void 0 ? void 0 : errorLoadApp(error, appInfo, ...args);
50
+ return (_errorLoadApp = errorLoadApp) === null || _errorLoadApp === void 0 ? void 0 : _errorLoadApp(error, appInfo, ...args);
47
51
  },
48
52
  errorMountApp(error, appInfo, ...args) {
53
+ var _errorMountApp;
49
54
  logger("MApp errorMountApp", error, args);
50
55
  if (appInfo.activeWhen) {
51
56
  setLoadingState({
52
57
  error
53
58
  });
54
59
  }
55
- return errorMountApp === null || errorMountApp === void 0 ? void 0 : errorMountApp(error, appInfo, ...args);
60
+ return (_errorMountApp = errorMountApp) === null || _errorMountApp === void 0 ? void 0 : _errorMountApp(error, appInfo, ...args);
56
61
  },
57
62
  errorUnmountApp(error, appInfo, ...args) {
63
+ var _errorUnmountApp;
58
64
  logger("MApp errorUnmountApp", error, args);
59
65
  if (appInfo.activeWhen) {
60
66
  setLoadingState({
61
67
  error
62
68
  });
63
69
  }
64
- return errorUnmountApp === null || errorUnmountApp === void 0 ? void 0 : errorUnmountApp(error, appInfo, ...args);
70
+ return (_errorUnmountApp = errorUnmountApp) === null || _errorUnmountApp === void 0 ? void 0 : _errorUnmountApp(error, appInfo, ...args);
65
71
  },
66
72
  customLoader: (provider) => {
73
+ var _manifest2;
67
74
  const { render, destroy, SubModuleComponent, jupiter_submodule_app_key } = provider;
68
- const componetRenderMode = (manifest === null || manifest === void 0 ? void 0 : manifest.componentRender) && (SubModuleComponent || jupiter_submodule_app_key);
75
+ const componetRenderMode = ((_manifest2 = manifest) === null || _manifest2 === void 0 ? void 0 : _manifest2.componentRender) && (SubModuleComponent || jupiter_submodule_app_key);
69
76
  return {
70
77
  mount: (appInfo) => {
71
78
  const transferProps = this.filterTransferProps();
@@ -79,13 +86,15 @@ export function generateMApp(options, manifest) {
79
86
  });
80
87
  return void 0;
81
88
  } else {
89
+ var _render;
82
90
  logger("MicroApp customer render", appInfo);
83
- return render === null || render === void 0 ? void 0 : render.apply(provider, [
91
+ return (_render = render) === null || _render === void 0 ? void 0 : _render.apply(provider, [
84
92
  appInfo
85
93
  ]);
86
94
  }
87
95
  },
88
96
  unmount: (appInfo) => {
97
+ var _destroy;
89
98
  const transferProps = this.filterTransferProps();
90
99
  appInfo.props = {
91
100
  ...appInfo.props,
@@ -95,7 +104,7 @@ export function generateMApp(options, manifest) {
95
104
  return void 0;
96
105
  }
97
106
  logger("MicroApp customer destroy", appInfo);
98
- return destroy === null || destroy === void 0 ? void 0 : destroy.apply(provider, [
107
+ return (_destroy = destroy) === null || _destroy === void 0 ? void 0 : _destroy.apply(provider, [
99
108
  appInfo
100
109
  ]);
101
110
  }
@@ -138,5 +147,5 @@ export function generateMApp(options, manifest) {
138
147
  });
139
148
  }
140
149
  }
141
- return Loadable(MApp)(manifest === null || manifest === void 0 ? void 0 : manifest.loadable);
150
+ return Loadable(MApp)((_manifest = manifest) === null || _manifest === void 0 ? void 0 : _manifest.loadable);
142
151
  }
@@ -22,17 +22,18 @@ export function pathJoin(...args) {
22
22
  return res || "/";
23
23
  }
24
24
  function getAppInstance(options, appInfo, manifest) {
25
+ var _manifest;
25
26
  let locationHref = "";
26
27
  function MicroApp(props) {
27
- var _context_router, _context_router_useRouteMatch, _context_router1, _context_router_useMatches, _context_router2, _context_router_useLocation;
28
+ var _context_router_useRouteMatch, _context_router, _context, _context_router_useMatches, _context_router1, _context1, _context_router_useLocation, _context_router2, _context2, _options;
28
29
  const appRef = useRef(null);
29
30
  const domId = generateSubAppContainerKey(appInfo);
30
31
  const [SubModuleComponent, setSubModuleComponent] = useState();
31
32
  const context = useContext(RuntimeReactContext);
32
- const 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);
33
- const 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);
34
- const 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);
35
- let basename = (options === null || options === void 0 ? void 0 : options.basename) || "/";
33
+ const match = (_context = 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);
34
+ const matchs = (_context1 = context) === null || _context1 === void 0 ? void 0 : (_context_router1 = _context1.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);
35
+ const location = (_context2 = context) === null || _context2 === void 0 ? void 0 : (_context_router2 = _context2.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);
36
+ let basename = ((_options = options) === null || _options === void 0 ? void 0 : _options.basename) || "/";
36
37
  if (matchs && matchs.length > 0) {
37
38
  const matchItem = {
38
39
  ...matchs[matchs.length - 1]
@@ -42,7 +43,8 @@ function getAppInstance(options, appInfo, manifest) {
42
43
  }
43
44
  basename = pathJoin(basename, matchItem.pathname || "/");
44
45
  } else if (match) {
45
- basename = pathJoin(basename, (match === null || match === void 0 ? void 0 : match.path) || "/");
46
+ var _match;
47
+ basename = pathJoin(basename, ((_match = match) === null || _match === void 0 ? void 0 : _match.path) || "/");
46
48
  }
47
49
  useEffect(() => {
48
50
  if (location && locationHref !== location.pathname && !Garfish.running) {
@@ -71,24 +73,27 @@ function getAppInstance(options, appInfo, manifest) {
71
73
  ...userProps
72
74
  },
73
75
  customLoader: (provider) => {
76
+ var _manifest2;
74
77
  const { render, destroy, SubModuleComponent: SubModuleComponent2, jupiter_submodule_app_key } = provider;
75
- const componetRenderMode = (manifest === null || manifest === void 0 ? void 0 : manifest.componentRender) && (SubModuleComponent2 || jupiter_submodule_app_key);
78
+ const componetRenderMode = ((_manifest2 = manifest) === null || _manifest2 === void 0 ? void 0 : _manifest2.componentRender) && (SubModuleComponent2 || jupiter_submodule_app_key);
76
79
  return {
77
80
  mount: (...props2) => {
78
81
  if (componetRenderMode) {
79
82
  setSubModuleComponent(SubModuleComponent2);
80
83
  return void 0;
81
84
  } else {
85
+ var _render;
82
86
  logger("MicroApp customer render", props2);
83
- return render === null || render === void 0 ? void 0 : render.apply(provider, props2);
87
+ return (_render = render) === null || _render === void 0 ? void 0 : _render.apply(provider, props2);
84
88
  }
85
89
  },
86
90
  unmount(...props2) {
91
+ var _destroy;
87
92
  if (componetRenderMode) {
88
93
  return void 0;
89
94
  }
90
95
  logger("MicroApp customer destroy", props2);
91
- return destroy === null || destroy === void 0 ? void 0 : destroy.apply(provider, props2);
96
+ return (_destroy = destroy) === null || _destroy === void 0 ? void 0 : _destroy.apply(provider, props2);
92
97
  }
93
98
  };
94
99
  }
@@ -111,17 +116,19 @@ function getAppInstance(options, appInfo, manifest) {
111
116
  isLoading: false
112
117
  });
113
118
  if (appInstance.mounted && appInstance.appInfo.cache) {
119
+ var _appInstance;
114
120
  logger(`MicroApp Garfish.loadApp "${appInfo.name}" show`, {
115
121
  appInfo: appInstance.appInfo,
116
122
  appInstance
117
123
  });
118
- await (appInstance === null || appInstance === void 0 ? void 0 : appInstance.show());
124
+ await ((_appInstance = appInstance) === null || _appInstance === void 0 ? void 0 : _appInstance.show());
119
125
  } else {
126
+ var _appInstance1;
120
127
  logger(`MicroApp Garfish.loadApp "${appInfo.name}" mount`, {
121
128
  appInfo: appInstance.appInfo,
122
129
  appInstance
123
130
  });
124
- await (appInstance === null || appInstance === void 0 ? void 0 : appInstance.mount());
131
+ await ((_appInstance1 = appInstance) === null || _appInstance1 === void 0 ? void 0 : _appInstance1.mount());
125
132
  }
126
133
  } catch (error) {
127
134
  setLoadingState({
@@ -153,7 +160,7 @@ function getAppInstance(options, appInfo, manifest) {
153
160
  })
154
161
  });
155
162
  }
156
- return Loadable(MicroApp)(manifest === null || manifest === void 0 ? void 0 : manifest.loadable);
163
+ return Loadable(MicroApp)((_manifest = manifest) === null || _manifest === void 0 ? void 0 : _manifest.loadable);
157
164
  }
158
165
  export function generateApps(options, manifest) {
159
166
  var _options_apps;
@@ -2,5 +2,6 @@ import createDebug from "debug";
2
2
  export const logger = createDebug("modern-js:plugin-garfish");
3
3
  export const SUBMODULE_APP_COMPONENT_KEY = "SubModuleComponent";
4
4
  export function generateSubAppContainerKey(moduleInfo) {
5
- return moduleInfo ? `modern_sub_app_container_${decodeURIComponent(moduleInfo === null || moduleInfo === void 0 ? void 0 : moduleInfo.name)}` : "modern_sub_app_container";
5
+ var _moduleInfo;
6
+ return moduleInfo ? `modern_sub_app_container_${decodeURIComponent((_moduleInfo = moduleInfo) === null || _moduleInfo === void 0 ? void 0 : _moduleInfo.name)}` : "modern_sub_app_container";
6
7
  }
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.27.0",
18
+ "version": "2.29.0",
19
19
  "jsnext:source": "./src/cli/index.ts",
20
20
  "types": "./dist/types/cli/index.d.ts",
21
21
  "typesVersions": {
@@ -70,10 +70,10 @@
70
70
  "hoist-non-react-statics": "^3.3.2",
71
71
  "react-loadable": "^5.5.0",
72
72
  "@swc/helpers": "0.5.1",
73
- "@modern-js/utils": "2.27.0"
73
+ "@modern-js/utils": "2.29.0"
74
74
  },
75
75
  "peerDependencies": {
76
- "@modern-js/runtime": "^2.27.0"
76
+ "@modern-js/runtime": "^2.29.0"
77
77
  },
78
78
  "devDependencies": {
79
79
  "@testing-library/dom": "^8.14.0",
@@ -90,13 +90,13 @@
90
90
  "react-router-dom": "^6.8.1",
91
91
  "typescript": "^5",
92
92
  "webpack-chain": "^6.5.1",
93
- "@modern-js/app-tools": "2.27.0",
94
- "@modern-js/core": "2.27.0",
95
- "@modern-js/plugin-router-v5": "2.27.0",
96
- "@modern-js/runtime": "2.27.0",
97
- "@modern-js/types": "2.27.0",
98
- "@scripts/build": "2.27.0",
99
- "@scripts/jest-config": "2.27.0"
93
+ "@modern-js/app-tools": "2.29.0",
94
+ "@modern-js/core": "2.29.0",
95
+ "@modern-js/plugin-router-v5": "2.29.0",
96
+ "@modern-js/runtime": "2.29.0",
97
+ "@modern-js/types": "2.29.0",
98
+ "@scripts/build": "2.29.0",
99
+ "@scripts/jest-config": "2.29.0"
100
100
  },
101
101
  "sideEffects": false,
102
102
  "publishConfig": {