@modern-js/plugin-garfish 1.5.0 → 1.5.3

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 CHANGED
@@ -1,5 +1,28 @@
1
1
  # @modern-js/plugin-garfish
2
2
 
3
+ ## 1.5.2
4
+
5
+ ### Patch Changes
6
+
7
+ - a1198d509: feat: bump babel 7.18.0
8
+ - df0694aba: fix(garfish-plugin): app static properties missing
9
+ - Updated dependencies [a1198d509]
10
+ - @modern-js/plugin-router@1.2.15
11
+
12
+ ## 1.5.1
13
+
14
+ ### Patch Changes
15
+
16
+ - 6451a098: fix: cyclic dependencies of @modern-js/core and @moden-js/webpack
17
+ - 45d5643a: feat(webpack): support modify html-webpack-plugin
18
+ - Updated dependencies [be7262e2]
19
+ - Updated dependencies [6451a098]
20
+ - Updated dependencies [d5a2cfd8]
21
+ - Updated dependencies [437367c6]
22
+ - @modern-js/runtime-core@1.4.7
23
+ - @modern-js/utils@1.7.6
24
+ - @modern-js/plugin-router@1.2.14
25
+
3
26
  ## 1.5.0
4
27
 
5
28
  ### Minor Changes
@@ -103,7 +103,8 @@ export default (({
103
103
  },
104
104
  source: {
105
105
  alias: {
106
- '@modern-js/runtime/plugins': pluginsExportsUtils.getPath()
106
+ '@modern-js/runtime/plugins': pluginsExportsUtils.getPath(),
107
+ '@modern-js/runtime/garfish': _mfPackagePath
107
108
  }
108
109
  },
109
110
  tools: {
@@ -150,7 +151,7 @@ export default (({
150
151
 
151
152
  if (!enableHtmlEntry) {
152
153
  chain.output.filename('index.js');
153
- chain.plugins.delete('html-main');
154
+ chain.plugins.delete(`${CHAIN_ID.PLUGIN.HTML}-main`);
154
155
  chain.optimization.runtimeChunk(false);
155
156
  chain.optimization.splitChunks({
156
157
  chunks: 'async'
@@ -172,7 +173,7 @@ export default (({
172
173
  },
173
174
 
174
175
  addRuntimeExports() {
175
- const addExportStatement = `export { default as garfish, default as masterApp } from '${_mfPackagePath}'`;
176
+ const addExportStatement = `export { default as garfish, default as masterApp, hoistNonReactStatics } from '${_mfPackagePath}'`;
176
177
  logger('exportStatement', addExportStatement);
177
178
  pluginsExportsUtils.addExport(addExportStatement);
178
179
  runtimeExportsUtils.addExport(`export * from '${_mfPackagePath}'`);
@@ -203,6 +204,12 @@ export default (({
203
204
  });
204
205
  }
205
206
 
207
+ imports.push({
208
+ value: _runtimePluginName,
209
+ specifiers: [{
210
+ imported: 'hoistNonReactStatics'
211
+ }]
212
+ });
206
213
  imports.push({
207
214
  value: 'react-dom',
208
215
  specifiers: [{
@@ -7,7 +7,7 @@ export const provider = function ({basename, dom}) {
7
7
  const App = function () {
8
8
  return React.createElement(SubApp, props)
9
9
  };
10
- bootstrap(App, node);
10
+ bootstrap(hoistNonReactStatics(App,SubApp), node);
11
11
  },
12
12
  destroy({ dom }) {
13
13
  const node = dom.querySelector('#' + MOUNT_ID) || dom;
@@ -32,16 +32,20 @@ export const provider = function ({basename, dom}) {
32
32
  if (typeof __GARFISH_EXPORTS__ !== 'undefined') {
33
33
  __GARFISH_EXPORTS__.provider = provider;
34
34
  }
35
+
36
+ function renderInGarfish () {
37
+ if (IS_BROWSER && window.Garfish && window.Garfish.activeApps && window.Garfish.activeApps.length !== 0) return true;
38
+ if (IS_BROWSER && window.Garfish && window.Garfish.apps && Object.keys(window.Garfish.apps).length !== 0) return true;
39
+ if (typeof __GARFISH_EXPORTS__ !== 'undefined') return true;
40
+ return false;
41
+ }
35
42
  `;
36
43
  export const makeRenderFunction = code => {
37
44
  const inGarfishToRender = `
38
45
  const { basename, props } = arguments[0] || {};
39
- let renderByGarfish = false;
46
+ let renderByGarfish = renderInGarfish();
40
47
  const renderByProvider = !!basename;
41
48
 
42
- if (IS_BROWSER && window.Garfish && window.Garfish.activeApps && window.Garfish.activeApps.length !== 0) renderByGarfish = true;
43
- if (IS_BROWSER && window.Garfish && window.Garfish.apps && Object.keys(window.Garfish.apps).length !== 0) renderByGarfish = true;
44
- if (typeof __GARFISH_EXPORTS__ !== 'undefined') renderByGarfish = true;
45
49
  if (renderByGarfish && !renderByProvider) return null;
46
50
 
47
51
  function RouterPlugin (routerConfig) {
@@ -1,3 +1,4 @@
1
1
  export { default } from "./plugin";
2
2
  export { useModuleApps, useModuleApp } from "./useModuleApps";
3
- export { default as Garfish, default as garfish } from 'garfish';
3
+ export { default as Garfish, default as garfish } from 'garfish';
4
+ export { default as hoistNonReactStatics } from 'hoist-non-react-statics';
@@ -144,7 +144,14 @@ export function Loadable(WrapComponent) {
144
144
  style: {
145
145
  display: showLoading ? 'none' : 'block'
146
146
  },
147
- setLoadingState: props => this.setStateWithMountCheck(props)
147
+ setLoadingState: props => {
148
+ // loading is not provided and there is a rendering exception
149
+ if (props.error && !LoadingComponent) {
150
+ throw props.error;
151
+ }
152
+
153
+ this.setStateWithMountCheck(props);
154
+ }
148
155
  }, otherProps))]
149
156
  });
150
157
  }
@@ -51,49 +51,101 @@ export function generateMApp(options, manifest) {
51
51
  const garfishOptions = _objectSpread(_objectSpread({
52
52
  domGetter: `#${domId}`,
53
53
 
54
- beforeLoad(...args) {
55
- logger('MApp beforeLoad', args);
56
- setLoadingState({
57
- isLoading: true,
58
- error: null
59
- });
60
- return beforeLoad === null || beforeLoad === void 0 ? void 0 : beforeLoad(...args);
54
+ beforeLoad(appInfo, ...args) {
55
+ logger('MApp beforeLoad', [appInfo]);
56
+
57
+ if (appInfo.activeWhen) {
58
+ setLoadingState({
59
+ isLoading: true,
60
+ error: null
61
+ });
62
+ }
63
+
64
+ return beforeLoad === null || beforeLoad === void 0 ? void 0 : beforeLoad(appInfo, ...args);
61
65
  },
62
66
 
63
- beforeMount(...args) {
67
+ beforeMount(appInfo, ...args) {
64
68
  logger('MApp beforeMount', args);
65
- setLoadingState({
66
- isLoading: false
67
- });
68
- return beforeMount === null || beforeMount === void 0 ? void 0 : beforeMount(...args);
69
+
70
+ if (appInfo.activeWhen) {
71
+ setLoadingState({
72
+ isLoading: false
73
+ });
74
+ }
75
+
76
+ return beforeMount === null || beforeMount === void 0 ? void 0 : beforeMount(appInfo, ...args);
69
77
  },
70
78
 
71
- errorLoadApp(error, ...args) {
79
+ errorLoadApp(error, appInfo, ...args) {
72
80
  logger('MApp errorLoadApp', error, args);
73
- setLoadingState({
74
- error
75
- });
76
- return errorLoadApp === null || errorLoadApp === void 0 ? void 0 : errorLoadApp(error, ...args);
81
+
82
+ if (appInfo.activeWhen) {
83
+ setLoadingState({
84
+ error
85
+ });
86
+ }
87
+
88
+ return errorLoadApp === null || errorLoadApp === void 0 ? void 0 : errorLoadApp(error, appInfo, ...args);
77
89
  },
78
90
 
79
- errorMountApp(error, ...args) {
91
+ errorMountApp(error, appInfo, ...args) {
80
92
  logger('MApp errorMountApp', error, args);
81
- setLoadingState({
82
- error
83
- });
84
- return errorMountApp === null || errorMountApp === void 0 ? void 0 : errorMountApp(error, ...args);
93
+
94
+ if (appInfo.activeWhen) {
95
+ setLoadingState({
96
+ error
97
+ });
98
+ }
99
+
100
+ return errorMountApp === null || errorMountApp === void 0 ? void 0 : errorMountApp(error, appInfo, ...args);
85
101
  },
86
102
 
87
- errorUnmountApp(error, ...args) {
103
+ errorUnmountApp(error, appInfo, ...args) {
88
104
  logger('MApp errorUnmountApp', error, args);
89
- setLoadingState({
90
- error
91
- });
92
- return errorUnmountApp === null || errorUnmountApp === void 0 ? void 0 : errorUnmountApp(error, ...args);
105
+
106
+ if (appInfo.activeWhen) {
107
+ setLoadingState({
108
+ error
109
+ });
110
+ }
111
+
112
+ return errorUnmountApp === null || errorUnmountApp === void 0 ? void 0 : errorUnmountApp(error, appInfo, ...args);
93
113
  }
94
114
 
95
115
  }, otherOptions), {}, {
96
- insulationVariable: [...(otherOptions.insulationVariable || []), '_SERVER_DATA']
116
+ insulationVariable: [...(otherOptions.insulationVariable || []), '_SERVER_DATA'],
117
+ customLoader: provider => {
118
+ const {
119
+ render,
120
+ destroy,
121
+ SubModuleComponent,
122
+ jupiter_submodule_app_key
123
+ } = provider;
124
+ const componetRenderMode = (manifest === null || manifest === void 0 ? void 0 : manifest.componentRender) && (SubModuleComponent || jupiter_submodule_app_key);
125
+ return {
126
+ mount: (...props) => {
127
+ if (componetRenderMode) {
128
+ this.setState({
129
+ SubModuleComponent: SubModuleComponent !== null && SubModuleComponent !== void 0 ? SubModuleComponent : jupiter_submodule_app_key
130
+ });
131
+ return undefined;
132
+ } else {
133
+ logger('MicroApp customer render', props);
134
+ return render === null || render === void 0 ? void 0 : render.apply(provider, props);
135
+ }
136
+ },
137
+
138
+ unmount(...props) {
139
+ if (componetRenderMode) {
140
+ return undefined;
141
+ }
142
+
143
+ logger('MicroApp customer destroy', props);
144
+ return destroy === null || destroy === void 0 ? void 0 : destroy.apply(provider, props);
145
+ }
146
+
147
+ };
148
+ }
97
149
  });
98
150
 
99
151
  logger('MApp componentDidMount', {
@@ -115,8 +167,12 @@ export function generateMApp(options, manifest) {
115
167
  }
116
168
 
117
169
  render() {
170
+ const {
171
+ SubModuleComponent
172
+ } = this.state;
118
173
  return /*#__PURE__*/_jsx("div", {
119
- id: generateSubAppContainerKey()
174
+ id: generateSubAppContainerKey(),
175
+ children: SubModuleComponent && /*#__PURE__*/_jsx(SubModuleComponent, {})
120
176
  });
121
177
  }
122
178
 
@@ -18,12 +18,7 @@ import Garfish from 'garfish';
18
18
  import { withRouter } from '@modern-js/plugin-router'; // import Loadable from 'react-loadable';
19
19
 
20
20
  import { logger, generateSubAppContainerKey } from "../../util";
21
- import { Loadable } from "../loadable"; // type Provider = {
22
- // render: () => void;
23
- // destroy: () => void;
24
- // [SUBMODULE_APP_COMPONENT_KEY]?: React.ComponentType<any>;
25
- // };
26
-
21
+ import { Loadable } from "../loadable";
27
22
  import { jsx as _jsx } from "react/jsx-runtime";
28
23
  import { Fragment as _Fragment } from "react/jsx-runtime";
29
24
 
@@ -36,7 +31,8 @@ function getAppInstance(options, appInfo, manifest) {
36
31
 
37
32
  _defineProperty(this, "state", {
38
33
  appInstance: null,
39
- domId: generateSubAppContainerKey(appInfo)
34
+ domId: generateSubAppContainerKey(appInfo),
35
+ SubModuleComponent: undefined
40
36
  });
41
37
 
42
38
  _defineProperty(this, "unregisterHistoryListener", () => {});
@@ -65,15 +61,29 @@ function getAppInstance(options, appInfo, manifest) {
65
61
  customLoader: provider => {
66
62
  const {
67
63
  render,
68
- destroy
64
+ destroy,
65
+ SubModuleComponent,
66
+ jupiter_submodule_app_key
69
67
  } = provider;
68
+ const componetRenderMode = (manifest === null || manifest === void 0 ? void 0 : manifest.componentRender) && (SubModuleComponent || jupiter_submodule_app_key);
70
69
  return {
71
- mount(...props) {
72
- logger('MicroApp customer render', props);
73
- return render === null || render === void 0 ? void 0 : render.apply(provider, props);
70
+ mount: (...props) => {
71
+ if (componetRenderMode) {
72
+ this.setState({
73
+ SubModuleComponent: SubModuleComponent !== null && SubModuleComponent !== void 0 ? SubModuleComponent : jupiter_submodule_app_key
74
+ });
75
+ return undefined;
76
+ } else {
77
+ logger('MicroApp customer render', props);
78
+ return render === null || render === void 0 ? void 0 : render.apply(provider, props);
79
+ }
74
80
  },
75
81
 
76
82
  unmount(...props) {
83
+ if (componetRenderMode) {
84
+ return undefined;
85
+ }
86
+
77
87
  logger('MicroApp customer destroy', props);
78
88
  return destroy === null || destroy === void 0 ? void 0 : destroy.apply(provider, props);
79
89
  }
@@ -159,11 +169,13 @@ function getAppInstance(options, appInfo, manifest) {
159
169
 
160
170
  render() {
161
171
  const {
162
- domId
172
+ domId,
173
+ SubModuleComponent
163
174
  } = this.state;
164
175
  return /*#__PURE__*/_jsx(_Fragment, {
165
176
  children: /*#__PURE__*/_jsx("div", {
166
- id: domId
177
+ id: domId,
178
+ children: SubModuleComponent && /*#__PURE__*/_jsx(SubModuleComponent, {})
167
179
  })
168
180
  });
169
181
  }
@@ -120,7 +120,8 @@ var _default = ({
120
120
  },
121
121
  source: {
122
122
  alias: {
123
- '@modern-js/runtime/plugins': pluginsExportsUtils.getPath()
123
+ '@modern-js/runtime/plugins': pluginsExportsUtils.getPath(),
124
+ '@modern-js/runtime/garfish': _mfPackagePath
124
125
  }
125
126
  },
126
127
  tools: {
@@ -167,7 +168,7 @@ var _default = ({
167
168
 
168
169
  if (!enableHtmlEntry) {
169
170
  chain.output.filename('index.js');
170
- chain.plugins.delete('html-main');
171
+ chain.plugins.delete(`${CHAIN_ID.PLUGIN.HTML}-main`);
171
172
  chain.optimization.runtimeChunk(false);
172
173
  chain.optimization.splitChunks({
173
174
  chunks: 'async'
@@ -189,7 +190,7 @@ var _default = ({
189
190
  },
190
191
 
191
192
  addRuntimeExports() {
192
- const addExportStatement = `export { default as garfish, default as masterApp } from '${_mfPackagePath}'`;
193
+ const addExportStatement = `export { default as garfish, default as masterApp, hoistNonReactStatics } from '${_mfPackagePath}'`;
193
194
  (0, _util.logger)('exportStatement', addExportStatement);
194
195
  pluginsExportsUtils.addExport(addExportStatement);
195
196
  runtimeExportsUtils.addExport(`export * from '${_mfPackagePath}'`);
@@ -220,6 +221,12 @@ var _default = ({
220
221
  });
221
222
  }
222
223
 
224
+ imports.push({
225
+ value: _runtimePluginName,
226
+ specifiers: [{
227
+ imported: 'hoistNonReactStatics'
228
+ }]
229
+ });
223
230
  imports.push({
224
231
  value: 'react-dom',
225
232
  specifiers: [{
@@ -16,7 +16,7 @@ export const provider = function ({basename, dom}) {
16
16
  const App = function () {
17
17
  return React.createElement(SubApp, props)
18
18
  };
19
- bootstrap(App, node);
19
+ bootstrap(hoistNonReactStatics(App,SubApp), node);
20
20
  },
21
21
  destroy({ dom }) {
22
22
  const node = dom.querySelector('#' + MOUNT_ID) || dom;
@@ -41,6 +41,13 @@ export const provider = function ({basename, dom}) {
41
41
  if (typeof __GARFISH_EXPORTS__ !== 'undefined') {
42
42
  __GARFISH_EXPORTS__.provider = provider;
43
43
  }
44
+
45
+ function renderInGarfish () {
46
+ if (IS_BROWSER && window.Garfish && window.Garfish.activeApps && window.Garfish.activeApps.length !== 0) return true;
47
+ if (IS_BROWSER && window.Garfish && window.Garfish.apps && Object.keys(window.Garfish.apps).length !== 0) return true;
48
+ if (typeof __GARFISH_EXPORTS__ !== 'undefined') return true;
49
+ return false;
50
+ }
44
51
  `;
45
52
 
46
53
  exports.makeProvider = makeProvider;
@@ -48,12 +55,9 @@ exports.makeProvider = makeProvider;
48
55
  const makeRenderFunction = code => {
49
56
  const inGarfishToRender = `
50
57
  const { basename, props } = arguments[0] || {};
51
- let renderByGarfish = false;
58
+ let renderByGarfish = renderInGarfish();
52
59
  const renderByProvider = !!basename;
53
60
 
54
- if (IS_BROWSER && window.Garfish && window.Garfish.activeApps && window.Garfish.activeApps.length !== 0) renderByGarfish = true;
55
- if (IS_BROWSER && window.Garfish && window.Garfish.apps && Object.keys(window.Garfish.apps).length !== 0) renderByGarfish = true;
56
- if (typeof __GARFISH_EXPORTS__ !== 'undefined') renderByGarfish = true;
57
61
  if (renderByGarfish && !renderByProvider) return null;
58
62
 
59
63
  function RouterPlugin (routerConfig) {
@@ -21,6 +21,12 @@ Object.defineProperty(exports, "garfish", {
21
21
  return _garfish.default;
22
22
  }
23
23
  });
24
+ Object.defineProperty(exports, "hoistNonReactStatics", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _hoistNonReactStatics.default;
28
+ }
29
+ });
24
30
  Object.defineProperty(exports, "useModuleApp", {
25
31
  enumerable: true,
26
32
  get: function () {
@@ -40,4 +46,6 @@ var _useModuleApps = require("./useModuleApps");
40
46
 
41
47
  var _garfish = _interopRequireDefault(require("garfish"));
42
48
 
49
+ var _hoistNonReactStatics = _interopRequireDefault(require("hoist-non-react-statics"));
50
+
43
51
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -153,7 +153,14 @@ function Loadable(WrapComponent) {
153
153
  style: {
154
154
  display: showLoading ? 'none' : 'block'
155
155
  },
156
- setLoadingState: props => this.setStateWithMountCheck(props)
156
+ setLoadingState: props => {
157
+ // loading is not provided and there is a rendering exception
158
+ if (props.error && !LoadingComponent) {
159
+ throw props.error;
160
+ }
161
+
162
+ this.setStateWithMountCheck(props);
163
+ }
157
164
  }, otherProps))]
158
165
  });
159
166
  }
@@ -64,49 +64,101 @@ function generateMApp(options, manifest) {
64
64
  const garfishOptions = _objectSpread(_objectSpread({
65
65
  domGetter: `#${domId}`,
66
66
 
67
- beforeLoad(...args) {
68
- (0, _util.logger)('MApp beforeLoad', args);
69
- setLoadingState({
70
- isLoading: true,
71
- error: null
72
- });
73
- return beforeLoad === null || beforeLoad === void 0 ? void 0 : beforeLoad(...args);
67
+ beforeLoad(appInfo, ...args) {
68
+ (0, _util.logger)('MApp beforeLoad', [appInfo]);
69
+
70
+ if (appInfo.activeWhen) {
71
+ setLoadingState({
72
+ isLoading: true,
73
+ error: null
74
+ });
75
+ }
76
+
77
+ return beforeLoad === null || beforeLoad === void 0 ? void 0 : beforeLoad(appInfo, ...args);
74
78
  },
75
79
 
76
- beforeMount(...args) {
80
+ beforeMount(appInfo, ...args) {
77
81
  (0, _util.logger)('MApp beforeMount', args);
78
- setLoadingState({
79
- isLoading: false
80
- });
81
- return beforeMount === null || beforeMount === void 0 ? void 0 : beforeMount(...args);
82
+
83
+ if (appInfo.activeWhen) {
84
+ setLoadingState({
85
+ isLoading: false
86
+ });
87
+ }
88
+
89
+ return beforeMount === null || beforeMount === void 0 ? void 0 : beforeMount(appInfo, ...args);
82
90
  },
83
91
 
84
- errorLoadApp(error, ...args) {
92
+ errorLoadApp(error, appInfo, ...args) {
85
93
  (0, _util.logger)('MApp errorLoadApp', error, args);
86
- setLoadingState({
87
- error
88
- });
89
- return errorLoadApp === null || errorLoadApp === void 0 ? void 0 : errorLoadApp(error, ...args);
94
+
95
+ if (appInfo.activeWhen) {
96
+ setLoadingState({
97
+ error
98
+ });
99
+ }
100
+
101
+ return errorLoadApp === null || errorLoadApp === void 0 ? void 0 : errorLoadApp(error, appInfo, ...args);
90
102
  },
91
103
 
92
- errorMountApp(error, ...args) {
104
+ errorMountApp(error, appInfo, ...args) {
93
105
  (0, _util.logger)('MApp errorMountApp', error, args);
94
- setLoadingState({
95
- error
96
- });
97
- return errorMountApp === null || errorMountApp === void 0 ? void 0 : errorMountApp(error, ...args);
106
+
107
+ if (appInfo.activeWhen) {
108
+ setLoadingState({
109
+ error
110
+ });
111
+ }
112
+
113
+ return errorMountApp === null || errorMountApp === void 0 ? void 0 : errorMountApp(error, appInfo, ...args);
98
114
  },
99
115
 
100
- errorUnmountApp(error, ...args) {
116
+ errorUnmountApp(error, appInfo, ...args) {
101
117
  (0, _util.logger)('MApp errorUnmountApp', error, args);
102
- setLoadingState({
103
- error
104
- });
105
- return errorUnmountApp === null || errorUnmountApp === void 0 ? void 0 : errorUnmountApp(error, ...args);
118
+
119
+ if (appInfo.activeWhen) {
120
+ setLoadingState({
121
+ error
122
+ });
123
+ }
124
+
125
+ return errorUnmountApp === null || errorUnmountApp === void 0 ? void 0 : errorUnmountApp(error, appInfo, ...args);
106
126
  }
107
127
 
108
128
  }, otherOptions), {}, {
109
- insulationVariable: [...(otherOptions.insulationVariable || []), '_SERVER_DATA']
129
+ insulationVariable: [...(otherOptions.insulationVariable || []), '_SERVER_DATA'],
130
+ customLoader: provider => {
131
+ const {
132
+ render,
133
+ destroy,
134
+ SubModuleComponent,
135
+ jupiter_submodule_app_key
136
+ } = provider;
137
+ const componetRenderMode = (manifest === null || manifest === void 0 ? void 0 : manifest.componentRender) && (SubModuleComponent || jupiter_submodule_app_key);
138
+ return {
139
+ mount: (...props) => {
140
+ if (componetRenderMode) {
141
+ this.setState({
142
+ SubModuleComponent: SubModuleComponent !== null && SubModuleComponent !== void 0 ? SubModuleComponent : jupiter_submodule_app_key
143
+ });
144
+ return undefined;
145
+ } else {
146
+ (0, _util.logger)('MicroApp customer render', props);
147
+ return render === null || render === void 0 ? void 0 : render.apply(provider, props);
148
+ }
149
+ },
150
+
151
+ unmount(...props) {
152
+ if (componetRenderMode) {
153
+ return undefined;
154
+ }
155
+
156
+ (0, _util.logger)('MicroApp customer destroy', props);
157
+ return destroy === null || destroy === void 0 ? void 0 : destroy.apply(provider, props);
158
+ }
159
+
160
+ };
161
+ }
110
162
  });
111
163
 
112
164
  (0, _util.logger)('MApp componentDidMount', {
@@ -129,8 +181,12 @@ function generateMApp(options, manifest) {
129
181
  }
130
182
 
131
183
  render() {
184
+ const {
185
+ SubModuleComponent
186
+ } = this.state;
132
187
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
133
- id: (0, _util.generateSubAppContainerKey)()
188
+ id: (0, _util.generateSubAppContainerKey)(),
189
+ children: SubModuleComponent && /*#__PURE__*/(0, _jsxRuntime.jsx)(SubModuleComponent, {})
134
190
  });
135
191
  }
136
192
 
@@ -42,7 +42,8 @@ function getAppInstance(options, appInfo, manifest) {
42
42
 
43
43
  _defineProperty(this, "state", {
44
44
  appInstance: null,
45
- domId: (0, _util.generateSubAppContainerKey)(appInfo)
45
+ domId: (0, _util.generateSubAppContainerKey)(appInfo),
46
+ SubModuleComponent: undefined
46
47
  });
47
48
 
48
49
  _defineProperty(this, "unregisterHistoryListener", () => {});
@@ -71,15 +72,29 @@ function getAppInstance(options, appInfo, manifest) {
71
72
  customLoader: provider => {
72
73
  const {
73
74
  render,
74
- destroy
75
+ destroy,
76
+ SubModuleComponent,
77
+ jupiter_submodule_app_key
75
78
  } = provider;
79
+ const componetRenderMode = (manifest === null || manifest === void 0 ? void 0 : manifest.componentRender) && (SubModuleComponent || jupiter_submodule_app_key);
76
80
  return {
77
- mount(...props) {
78
- (0, _util.logger)('MicroApp customer render', props);
79
- return render === null || render === void 0 ? void 0 : render.apply(provider, props);
81
+ mount: (...props) => {
82
+ if (componetRenderMode) {
83
+ this.setState({
84
+ SubModuleComponent: SubModuleComponent !== null && SubModuleComponent !== void 0 ? SubModuleComponent : jupiter_submodule_app_key
85
+ });
86
+ return undefined;
87
+ } else {
88
+ (0, _util.logger)('MicroApp customer render', props);
89
+ return render === null || render === void 0 ? void 0 : render.apply(provider, props);
90
+ }
80
91
  },
81
92
 
82
93
  unmount(...props) {
94
+ if (componetRenderMode) {
95
+ return undefined;
96
+ }
97
+
83
98
  (0, _util.logger)('MicroApp customer destroy', props);
84
99
  return destroy === null || destroy === void 0 ? void 0 : destroy.apply(provider, props);
85
100
  }
@@ -165,11 +180,13 @@ function getAppInstance(options, appInfo, manifest) {
165
180
 
166
181
  render() {
167
182
  const {
168
- domId
183
+ domId,
184
+ SubModuleComponent
169
185
  } = this.state;
170
186
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
171
187
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
172
- id: domId
188
+ id: domId,
189
+ children: SubModuleComponent && /*#__PURE__*/(0, _jsxRuntime.jsx)(SubModuleComponent, {})
173
190
  })
174
191
  });
175
192
  }
@@ -1,7 +1,7 @@
1
+ import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
1
2
  import _typeof from "@babel/runtime/helpers/esm/typeof";
2
3
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
4
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
4
- import _regeneratorRuntime from "@babel/runtime/regenerator";
5
5
  import path from 'path';
6
6
  import { createRuntimeExportsUtils, PLUGIN_SCHEMAS } from '@modern-js/utils';
7
7
  import { logger } from "../util";
@@ -44,10 +44,10 @@ export default (function () {
44
44
  return PLUGIN_SCHEMAS['@modern-js/plugin-garfish'];
45
45
  },
46
46
  resolvedConfig: function () {
47
- var _resolvedConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(config) {
47
+ var _resolvedConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(config) {
48
48
  var resolved, _getRuntimeConfig, masterApp, router, nConfig, _router$historyOption;
49
49
 
50
- return _regeneratorRuntime.wrap(function _callee$(_context) {
50
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
51
51
  while (1) {
52
52
  switch (_context.prev = _context.next) {
53
53
  case 0:
@@ -115,7 +115,8 @@ export default (function () {
115
115
  },
116
116
  source: {
117
117
  alias: {
118
- '@modern-js/runtime/plugins': pluginsExportsUtils.getPath()
118
+ '@modern-js/runtime/plugins': pluginsExportsUtils.getPath(),
119
+ '@modern-js/runtime/garfish': mfPackagePath
119
120
  }
120
121
  },
121
122
  tools: {
@@ -162,7 +163,7 @@ export default (function () {
162
163
 
163
164
  if (!_enableHtmlEntry) {
164
165
  chain.output.filename('index.js');
165
- chain.plugins["delete"]('html-main');
166
+ chain.plugins["delete"]("".concat(CHAIN_ID.PLUGIN.HTML, "-main"));
166
167
  chain.optimization.runtimeChunk(false);
167
168
  chain.optimization.splitChunks({
168
169
  chunks: 'async'
@@ -183,7 +184,7 @@ export default (function () {
183
184
  };
184
185
  },
185
186
  addRuntimeExports: function addRuntimeExports() {
186
- var addExportStatement = "export { default as garfish, default as masterApp } from '".concat(mfPackagePath, "'");
187
+ var addExportStatement = "export { default as garfish, default as masterApp, hoistNonReactStatics } from '".concat(mfPackagePath, "'");
187
188
  logger('exportStatement', addExportStatement);
188
189
  pluginsExportsUtils.addExport(addExportStatement);
189
190
  runtimeExportsUtils.addExport("export * from '".concat(mfPackagePath, "'"));
@@ -212,6 +213,12 @@ export default (function () {
212
213
  });
213
214
  }
214
215
 
216
+ imports.push({
217
+ value: runtimePluginName,
218
+ specifiers: [{
219
+ imported: 'hoistNonReactStatics'
220
+ }]
221
+ });
215
222
  imports.push({
216
223
  value: 'react-dom',
217
224
  specifiers: [{
@@ -1,8 +1,8 @@
1
1
  export var makeProvider = function makeProvider() {
2
- return "\nexport const provider = function ({basename, dom}) {\n return {\n render({basename, dom, props}) {\n const SubApp = render({ props, basename });\n const node = dom.querySelector('#' + MOUNT_ID) || dom;\n const App = function () {\n return React.createElement(SubApp, props)\n };\n bootstrap(App, node);\n },\n destroy({ dom }) {\n const node = dom.querySelector('#' + MOUNT_ID) || dom;\n\n if (node) {\n unmountComponentAtNode(node);\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";
2
+ return "\nexport const provider = function ({basename, dom}) {\n return {\n render({basename, dom, props}) {\n const SubApp = render({ props, basename });\n const node = dom.querySelector('#' + MOUNT_ID) || dom;\n const App = function () {\n return React.createElement(SubApp, props)\n };\n bootstrap(hoistNonReactStatics(App,SubApp), node);\n },\n destroy({ dom }) {\n const node = dom.querySelector('#' + MOUNT_ID) || dom;\n\n if (node) {\n unmountComponentAtNode(node);\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 renderInGarfish () {\n if (IS_BROWSER && window.Garfish && window.Garfish.activeApps && window.Garfish.activeApps.length !== 0) return true;\n if (IS_BROWSER && window.Garfish && window.Garfish.apps && Object.keys(window.Garfish.apps).length !== 0) return true;\n if (typeof __GARFISH_EXPORTS__ !== 'undefined') return true;\n return false;\n}\n";
3
3
  };
4
4
  export var makeRenderFunction = function makeRenderFunction(code) {
5
- var inGarfishToRender = "\n const { basename, props } = arguments[0] || {};\n let renderByGarfish = false;\n const renderByProvider = !!basename;\n\n if (IS_BROWSER && window.Garfish && window.Garfish.activeApps && window.Garfish.activeApps.length !== 0) renderByGarfish = true;\n if (IS_BROWSER && window.Garfish && window.Garfish.apps && Object.keys(window.Garfish.apps).length !== 0) renderByGarfish = true;\n if (typeof __GARFISH_EXPORTS__ !== 'undefined') renderByGarfish = true;\n if (renderByGarfish && !renderByProvider) return null;\n\n function RouterPlugin (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 ";
5
+ var inGarfishToRender = "\n const { basename, props } = arguments[0] || {};\n let renderByGarfish = renderInGarfish();\n const renderByProvider = !!basename;\n\n if (renderByGarfish && !renderByProvider) return null;\n\n function RouterPlugin (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 ";
6
6
  return inGarfishToRender + code.replace("router(", "RouterPlugin(").replace('IS_BROWSER', "IS_BROWSER && !renderByGarfish");
7
7
  }; // support legacy config
8
8
 
@@ -1,3 +1,4 @@
1
1
  export { default } from "./plugin";
2
2
  export { useModuleApps, useModuleApp } from "./useModuleApps";
3
- export { default as Garfish, default as garfish } from 'garfish';
3
+ export { default as Garfish, default as garfish } from 'garfish';
4
+ export { default as hoistNonReactStatics } from 'hoist-non-react-statics';
@@ -160,7 +160,12 @@ export function Loadable(WrapComponent) {
160
160
  display: showLoading ? 'none' : 'block'
161
161
  },
162
162
  setLoadingState: function setLoadingState(props) {
163
- return _this3.setStateWithMountCheck(props);
163
+ // loading is not provided and there is a rendering exception
164
+ if (props.error && !LoadingComponent) {
165
+ throw props.error;
166
+ }
167
+
168
+ _this3.setStateWithMountCheck(props);
164
169
  }
165
170
  }, otherProps))]
166
171
  });
@@ -1,4 +1,5 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
2
3
  import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
3
4
  import _createClass from "@babel/runtime/helpers/esm/createClass";
4
5
  import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
@@ -8,7 +9,6 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
8
9
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
9
10
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
10
11
  var _excluded = ["manifest"];
11
- import _regeneratorRuntime from "@babel/runtime/regenerator";
12
12
  import React from 'react';
13
13
  import hoistNonReactStatics from 'hoist-non-react-statics';
14
14
  import { logger } from "../util";
@@ -24,7 +24,7 @@ function initOptions() {
24
24
 
25
25
 
26
26
  function _initOptions() {
27
- _initOptions = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
27
+ _initOptions = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
28
28
  var _window, _window$modern_manife, _window2, _window2$modern_manif;
29
29
 
30
30
  var manifest,
@@ -35,7 +35,7 @@ function _initOptions() {
35
35
  _window3$modern_manif,
36
36
  _args2 = arguments;
37
37
 
38
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
38
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
39
39
  while (1) {
40
40
  switch (_context2.prev = _context2.next) {
41
41
  case 0:
@@ -133,10 +133,10 @@ export default (function (config) {
133
133
  });
134
134
 
135
135
  var load = /*#__PURE__*/function () {
136
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
136
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
137
137
  var GarfishConfig, MApp, _generateApps, appInfoList, apps;
138
138
 
139
- return _regeneratorRuntime.wrap(function _callee$(_context) {
139
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
140
140
  while (1) {
141
141
  switch (_context.prev = _context.next) {
142
142
  case 0:
@@ -41,6 +41,8 @@ export function generateMApp(options, manifest) {
41
41
  _createClass(MApp, [{
42
42
  key: "componentDidMount",
43
43
  value: function componentDidMount() {
44
+ var _this2 = this;
45
+
44
46
  var domId = this.state.domId;
45
47
  var setLoadingState = this.props.setLoadingState;
46
48
 
@@ -58,64 +60,121 @@ export function generateMApp(options, manifest) {
58
60
 
59
61
  var garfishOptions = _objectSpread(_objectSpread({
60
62
  domGetter: "#".concat(domId),
61
- beforeLoad: function beforeLoad() {
62
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
63
- args[_key2] = arguments[_key2];
63
+ beforeLoad: function beforeLoad(appInfo) {
64
+ logger('MApp beforeLoad', [appInfo]);
65
+
66
+ if (appInfo.activeWhen) {
67
+ setLoadingState({
68
+ isLoading: true,
69
+ error: null
70
+ });
71
+ }
72
+
73
+ for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
74
+ args[_key2 - 1] = arguments[_key2];
64
75
  }
65
76
 
66
- logger('MApp beforeLoad', args);
67
- setLoadingState({
68
- isLoading: true,
69
- error: null
70
- });
71
- return _beforeLoad === null || _beforeLoad === void 0 ? void 0 : _beforeLoad.apply(void 0, args);
77
+ return _beforeLoad === null || _beforeLoad === void 0 ? void 0 : _beforeLoad.apply(void 0, [appInfo].concat(args));
72
78
  },
73
- beforeMount: function beforeMount() {
74
- for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
75
- args[_key3] = arguments[_key3];
79
+ beforeMount: function beforeMount(appInfo) {
80
+ for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
81
+ args[_key3 - 1] = arguments[_key3];
76
82
  }
77
83
 
78
84
  logger('MApp beforeMount', args);
79
- setLoadingState({
80
- isLoading: false
81
- });
82
- return _beforeMount === null || _beforeMount === void 0 ? void 0 : _beforeMount.apply(void 0, args);
85
+
86
+ if (appInfo.activeWhen) {
87
+ setLoadingState({
88
+ isLoading: false
89
+ });
90
+ }
91
+
92
+ return _beforeMount === null || _beforeMount === void 0 ? void 0 : _beforeMount.apply(void 0, [appInfo].concat(args));
83
93
  },
84
- errorLoadApp: function errorLoadApp(error) {
85
- for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
86
- args[_key4 - 1] = arguments[_key4];
94
+ errorLoadApp: function errorLoadApp(error, appInfo) {
95
+ for (var _len4 = arguments.length, args = new Array(_len4 > 2 ? _len4 - 2 : 0), _key4 = 2; _key4 < _len4; _key4++) {
96
+ args[_key4 - 2] = arguments[_key4];
87
97
  }
88
98
 
89
99
  logger('MApp errorLoadApp', error, args);
90
- setLoadingState({
91
- error: error
92
- });
93
- return _errorLoadApp === null || _errorLoadApp === void 0 ? void 0 : _errorLoadApp.apply(void 0, [error].concat(args));
100
+
101
+ if (appInfo.activeWhen) {
102
+ setLoadingState({
103
+ error: error
104
+ });
105
+ }
106
+
107
+ return _errorLoadApp === null || _errorLoadApp === void 0 ? void 0 : _errorLoadApp.apply(void 0, [error, appInfo].concat(args));
94
108
  },
95
- errorMountApp: function errorMountApp(error) {
96
- for (var _len5 = arguments.length, args = new Array(_len5 > 1 ? _len5 - 1 : 0), _key5 = 1; _key5 < _len5; _key5++) {
97
- args[_key5 - 1] = arguments[_key5];
109
+ errorMountApp: function errorMountApp(error, appInfo) {
110
+ for (var _len5 = arguments.length, args = new Array(_len5 > 2 ? _len5 - 2 : 0), _key5 = 2; _key5 < _len5; _key5++) {
111
+ args[_key5 - 2] = arguments[_key5];
98
112
  }
99
113
 
100
114
  logger('MApp errorMountApp', error, args);
101
- setLoadingState({
102
- error: error
103
- });
104
- return _errorMountApp === null || _errorMountApp === void 0 ? void 0 : _errorMountApp.apply(void 0, [error].concat(args));
115
+
116
+ if (appInfo.activeWhen) {
117
+ setLoadingState({
118
+ error: error
119
+ });
120
+ }
121
+
122
+ return _errorMountApp === null || _errorMountApp === void 0 ? void 0 : _errorMountApp.apply(void 0, [error, appInfo].concat(args));
105
123
  },
106
- errorUnmountApp: function errorUnmountApp(error) {
107
- for (var _len6 = arguments.length, args = new Array(_len6 > 1 ? _len6 - 1 : 0), _key6 = 1; _key6 < _len6; _key6++) {
108
- args[_key6 - 1] = arguments[_key6];
124
+ errorUnmountApp: function errorUnmountApp(error, appInfo) {
125
+ for (var _len6 = arguments.length, args = new Array(_len6 > 2 ? _len6 - 2 : 0), _key6 = 2; _key6 < _len6; _key6++) {
126
+ args[_key6 - 2] = arguments[_key6];
109
127
  }
110
128
 
111
129
  logger('MApp errorUnmountApp', error, args);
112
- setLoadingState({
113
- error: error
114
- });
115
- return _errorUnmountApp === null || _errorUnmountApp === void 0 ? void 0 : _errorUnmountApp.apply(void 0, [error].concat(args));
130
+
131
+ if (appInfo.activeWhen) {
132
+ setLoadingState({
133
+ error: error
134
+ });
135
+ }
136
+
137
+ return _errorUnmountApp === null || _errorUnmountApp === void 0 ? void 0 : _errorUnmountApp.apply(void 0, [error, appInfo].concat(args));
116
138
  }
117
139
  }, otherOptions), {}, {
118
- insulationVariable: [].concat(_toConsumableArray(otherOptions.insulationVariable || []), ['_SERVER_DATA'])
140
+ insulationVariable: [].concat(_toConsumableArray(otherOptions.insulationVariable || []), ['_SERVER_DATA']),
141
+ customLoader: function customLoader(provider) {
142
+ var render = provider.render,
143
+ destroy = provider.destroy,
144
+ SubModuleComponent = provider.SubModuleComponent,
145
+ jupiter_submodule_app_key = provider.jupiter_submodule_app_key;
146
+ var componetRenderMode = (manifest === null || manifest === void 0 ? void 0 : manifest.componentRender) && (SubModuleComponent || jupiter_submodule_app_key);
147
+ return {
148
+ mount: function mount() {
149
+ if (componetRenderMode) {
150
+ _this2.setState({
151
+ SubModuleComponent: SubModuleComponent !== null && SubModuleComponent !== void 0 ? SubModuleComponent : jupiter_submodule_app_key
152
+ });
153
+
154
+ return undefined;
155
+ } else {
156
+ for (var _len7 = arguments.length, props = new Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
157
+ props[_key7] = arguments[_key7];
158
+ }
159
+
160
+ logger('MicroApp customer render', props);
161
+ return render === null || render === void 0 ? void 0 : render.apply(provider, props);
162
+ }
163
+ },
164
+ unmount: function unmount() {
165
+ if (componetRenderMode) {
166
+ return undefined;
167
+ }
168
+
169
+ for (var _len8 = arguments.length, props = new Array(_len8), _key8 = 0; _key8 < _len8; _key8++) {
170
+ props[_key8] = arguments[_key8];
171
+ }
172
+
173
+ logger('MicroApp customer destroy', props);
174
+ return destroy === null || destroy === void 0 ? void 0 : destroy.apply(provider, props);
175
+ }
176
+ };
177
+ }
119
178
  });
120
179
 
121
180
  logger('MApp componentDidMount', {
@@ -139,8 +198,10 @@ export function generateMApp(options, manifest) {
139
198
  }, {
140
199
  key: "render",
141
200
  value: function render() {
201
+ var SubModuleComponent = this.state.SubModuleComponent;
142
202
  return /*#__PURE__*/_jsx("div", {
143
- id: generateSubAppContainerKey()
203
+ id: generateSubAppContainerKey(),
204
+ children: SubModuleComponent && /*#__PURE__*/_jsx(SubModuleComponent, {})
144
205
  });
145
206
  }
146
207
  }]);
@@ -1,3 +1,4 @@
1
+ import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
1
2
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
3
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
4
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
@@ -9,7 +10,6 @@ import _inherits from "@babel/runtime/helpers/esm/inherits";
9
10
  import _createSuper from "@babel/runtime/helpers/esm/createSuper";
10
11
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
11
12
  var _excluded = ["match", "history", "setLoadingState"];
12
- import _regeneratorRuntime from "@babel/runtime/regenerator";
13
13
  // The loading logic of the current component refers to react-loadable https://github.com/jamiebuilds/react-loadable
14
14
  import path from 'path';
15
15
  import React from 'react'; // eslint-disable-next-line import/no-named-as-default
@@ -18,12 +18,7 @@ import Garfish from 'garfish';
18
18
  import { withRouter } from '@modern-js/plugin-router'; // import Loadable from 'react-loadable';
19
19
 
20
20
  import { logger, generateSubAppContainerKey } from "../../util";
21
- import { Loadable } from "../loadable"; // type Provider = {
22
- // render: () => void;
23
- // destroy: () => void;
24
- // [SUBMODULE_APP_COMPONENT_KEY]?: React.ComponentType<any>;
25
- // };
26
-
21
+ import { Loadable } from "../loadable";
27
22
  import { jsx as _jsx } from "react/jsx-runtime";
28
23
  import { Fragment as _Fragment } from "react/jsx-runtime";
29
24
 
@@ -48,7 +43,8 @@ function getAppInstance(options, appInfo, manifest) {
48
43
 
49
44
  _defineProperty(_assertThisInitialized(_this), "state", {
50
45
  appInstance: null,
51
- domId: generateSubAppContainerKey(appInfo)
46
+ domId: generateSubAppContainerKey(appInfo),
47
+ SubModuleComponent: undefined
52
48
  });
53
49
 
54
50
  _defineProperty(_assertThisInitialized(_this), "unregisterHistoryListener", function () {});
@@ -60,10 +56,12 @@ function getAppInstance(options, appInfo, manifest) {
60
56
  key: "UNSAFE_componentWillMount",
61
57
  value: // eslint-disable-next-line @typescript-eslint/naming-convention
62
58
  function () {
63
- var _UNSAFE_componentWillMount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
59
+ var _UNSAFE_componentWillMount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
60
+ var _this2 = this;
61
+
64
62
  var _this$props, match, history, setLoadingState, userProps, domId, loadAppOptions, appInstance;
65
63
 
66
- return _regeneratorRuntime.wrap(function _callee$(_context) {
64
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
67
65
  while (1) {
68
66
  switch (_context.prev = _context.next) {
69
67
  case 0:
@@ -77,17 +75,32 @@ function getAppInstance(options, appInfo, manifest) {
77
75
  props: _objectSpread(_objectSpread({}, appInfo.props), userProps),
78
76
  customLoader: function customLoader(provider) {
79
77
  var render = provider.render,
80
- destroy = provider.destroy;
78
+ destroy = provider.destroy,
79
+ SubModuleComponent = provider.SubModuleComponent,
80
+ jupiter_submodule_app_key = provider.jupiter_submodule_app_key;
81
+ var componetRenderMode = (manifest === null || manifest === void 0 ? void 0 : manifest.componentRender) && (SubModuleComponent || jupiter_submodule_app_key);
81
82
  return {
82
83
  mount: function mount() {
83
- for (var _len2 = arguments.length, props = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
84
- props[_key2] = arguments[_key2];
84
+ if (componetRenderMode) {
85
+ _this2.setState({
86
+ SubModuleComponent: SubModuleComponent !== null && SubModuleComponent !== void 0 ? SubModuleComponent : jupiter_submodule_app_key
87
+ });
88
+
89
+ return undefined;
90
+ } else {
91
+ for (var _len2 = arguments.length, props = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
92
+ props[_key2] = arguments[_key2];
93
+ }
94
+
95
+ logger('MicroApp customer render', props);
96
+ return render === null || render === void 0 ? void 0 : render.apply(provider, props);
85
97
  }
86
-
87
- logger('MicroApp customer render', props);
88
- return render === null || render === void 0 ? void 0 : render.apply(provider, props);
89
98
  },
90
99
  unmount: function unmount() {
100
+ if (componetRenderMode) {
101
+ return undefined;
102
+ }
103
+
91
104
  for (var _len3 = arguments.length, props = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
92
105
  props[_key3] = arguments[_key3];
93
106
  }
@@ -188,12 +201,12 @@ function getAppInstance(options, appInfo, manifest) {
188
201
  }, {
189
202
  key: "componentWillUnmount",
190
203
  value: function () {
191
- var _componentWillUnmount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
204
+ var _componentWillUnmount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
192
205
  var _this$unregisterHisto;
193
206
 
194
207
  var appInstance, _appInfo;
195
208
 
196
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
209
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
197
210
  while (1) {
198
211
  switch (_context2.prev = _context2.next) {
199
212
  case 0:
@@ -229,10 +242,13 @@ function getAppInstance(options, appInfo, manifest) {
229
242
  }, {
230
243
  key: "render",
231
244
  value: function render() {
232
- var domId = this.state.domId;
245
+ var _this$state = this.state,
246
+ domId = _this$state.domId,
247
+ SubModuleComponent = _this$state.SubModuleComponent;
233
248
  return /*#__PURE__*/_jsx(_Fragment, {
234
249
  children: /*#__PURE__*/_jsx("div", {
235
- id: domId
250
+ id: domId,
251
+ children: SubModuleComponent && /*#__PURE__*/_jsx(SubModuleComponent, {})
236
252
  })
237
253
  });
238
254
  }
@@ -1,4 +1,5 @@
1
1
  export { default } from './plugin';
2
2
  export { useModuleApps, useModuleApp } from './useModuleApps';
3
3
  export type { Manifest, ModuleInfo } from './useModuleApps';
4
- export { default as Garfish, default as garfish } from 'garfish';
4
+ export { default as Garfish, default as garfish } from 'garfish';
5
+ export { default as hoistNonReactStatics } from 'hoist-non-react-statics';
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
+ import { RouteComponentProps } from '@modern-js/plugin-router';
2
3
  import { LoadableConfig, MicroComponentProps } from './useModuleApps';
3
- export interface MicroProps {
4
+ export interface MicroProps extends RouteComponentProps {
4
5
  setLoadingState: (state: {
5
6
  isLoading?: boolean;
6
7
  error?: unknown;
@@ -10,6 +10,7 @@ export declare type ModulesInfo = Array<ModuleInfo>;
10
10
  export declare type Manifest = {
11
11
  modules?: ModulesInfo;
12
12
  loadable?: LoadableConfig;
13
+ componentRender?: boolean;
13
14
  getAppList?: (info: any) => Promise<Array<GarfishInterfaces.AppInfo>>;
14
15
  };
15
16
  export declare type LoadingComponent = React.ComponentType<{
@@ -1,6 +1,10 @@
1
1
  import React from 'react';
2
- import Garfish from 'garfish';
2
+ import Garfish, { interfaces } from 'garfish';
3
3
  import { Manifest, MicroComponentProps, ModulesInfo } from '../useModuleApps';
4
+ export interface Provider extends interfaces.Provider {
5
+ SubModuleComponent?: React.ComponentType<any>;
6
+ jupiter_submodule_app_key?: React.ComponentType<any>;
7
+ }
4
8
  export interface AppMap {
5
9
  [key: string]: React.FC<MicroComponentProps>;
6
10
  }
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.5.0",
14
+ "version": "1.5.3",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/runtime/index.d.ts",
17
17
  "typesVersions": {
@@ -54,15 +54,23 @@
54
54
  "@types/debug": "^4.1.7",
55
55
  "@types/react-loadable": "^5.5.6",
56
56
  "debug": "^4.3.2",
57
- "garfish": "^1.5.5",
57
+ "garfish": "^1.8.1",
58
58
  "hoist-non-react-statics": "^3.3.2",
59
59
  "react-loadable": "^5.5.0"
60
60
  },
61
+ "peerDependencies": {
62
+ "@modern-js/plugin-router": "^1.2.15"
63
+ },
64
+ "peerDependenciesMeta": {
65
+ "@modern-js/plugin-router": {
66
+ "optional": true
67
+ }
68
+ },
61
69
  "devDependencies": {
62
- "@modern-js/core": "1.11.0",
63
- "@modern-js/plugin-router": "1.2.14",
64
- "@modern-js/runtime-core": "1.4.6",
65
- "@modern-js/types": "1.5.3",
70
+ "@modern-js/core": "1.11.2",
71
+ "@modern-js/plugin-router": "1.2.15",
72
+ "@modern-js/runtime-core": "1.4.10",
73
+ "@modern-js/types": "1.5.4",
66
74
  "@scripts/build": "0.0.0",
67
75
  "@scripts/jest-config": "0.0.0",
68
76
  "@testing-library/jest-dom": "^5.16.1",
@@ -82,11 +90,6 @@
82
90
  "typescript": "^4",
83
91
  "webpack-chain": "^6.5.1"
84
92
  },
85
- "peerDependencies": {
86
- "@modern-js/plugin-router": "^1.2.14",
87
- "@modern-js/runtime-core": "^1.4.6",
88
- "react": "^17"
89
- },
90
93
  "sideEffects": false,
91
94
  "modernConfig": {},
92
95
  "publishConfig": {
package/type.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- declare module '@modern-js/runtime' {
1
+ declare module '@modern-js/runtime/garfish' {
2
2
  export const useModuleApp: typeof import('./dist/types/runtime').useModuleApp;
3
3
  export const useModuleApps: typeof import('./dist/types/runtime').useModuleApps;
4
- export const useMicroApps: typeof import('./dist/types/runtime').useMicroApps;
4
+ export const Garfish: typeof import('./dist/types/runtime').Garfish;
5
+ export const garfish: typeof import('./dist/types/runtime').garfish;
5
6
  }