@modern-js/plugin-garfish 2.0.0-beta.0 → 2.0.0-beta.1

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.
Files changed (31) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/dist/js/modern/cli/index.js +10 -44
  3. package/dist/js/modern/cli/utils.js +4 -8
  4. package/dist/js/modern/runtime/loadable.js +3 -17
  5. package/dist/js/modern/runtime/plugin.js +11 -33
  6. package/dist/js/modern/runtime/useModuleApps.js +0 -5
  7. package/dist/js/modern/runtime/utils/MApp.js +9 -42
  8. package/dist/js/modern/runtime/utils/apps.js +12 -41
  9. package/dist/js/node/cli/index.js +10 -53
  10. package/dist/js/node/cli/utils.js +4 -14
  11. package/dist/js/node/index.js +0 -4
  12. package/dist/js/node/runtime/index.js +0 -5
  13. package/dist/js/node/runtime/loadable.js +3 -22
  14. package/dist/js/node/runtime/plugin.js +11 -47
  15. package/dist/js/node/runtime/useModuleApps.js +0 -12
  16. package/dist/js/node/runtime/utils/Context.js +0 -4
  17. package/dist/js/node/runtime/utils/MApp.js +7 -49
  18. package/dist/js/node/runtime/utils/apps.js +8 -46
  19. package/dist/js/node/runtime/utils/setExternal.js +0 -9
  20. package/dist/js/node/util.js +1 -4
  21. package/dist/js/treeshaking/cli/index.js +29 -59
  22. package/dist/js/treeshaking/cli/utils.js +4 -8
  23. package/dist/js/treeshaking/runtime/loadable.js +29 -39
  24. package/dist/js/treeshaking/runtime/plugin.js +9 -42
  25. package/dist/js/treeshaking/runtime/useModuleApps.js +4 -7
  26. package/dist/js/treeshaking/runtime/utils/MApp.js +13 -46
  27. package/dist/js/treeshaking/runtime/utils/apps.js +16 -56
  28. package/dist/types/cli/index.d.ts +0 -2
  29. package/dist/types/runtime/plugin.d.ts +0 -2
  30. package/dist/types/runtime/utils/setExternal.d.ts +0 -1
  31. package/package.json +11 -11
@@ -4,26 +4,17 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _react = _interopRequireDefault(require("react"));
9
-
10
8
  var _reactDom = _interopRequireDefault(require("react-dom"));
11
-
12
9
  var _garfish = _interopRequireDefault(require("garfish"));
13
-
14
10
  var _util = require("../../util");
15
-
16
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
-
18
12
  var _default = () => {
19
13
  (0, _util.logger)('setExternal ', {
20
14
  react: _react.default,
21
15
  'react-dom': _reactDom.default
22
16
  });
23
-
24
17
  _garfish.default.setExternal('react', _react.default);
25
-
26
18
  _garfish.default.setExternal('react-dom', _reactDom.default);
27
19
  };
28
-
29
20
  exports.default = _default;
@@ -6,19 +6,16 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.SUBMODULE_APP_COMPONENT_KEY = void 0;
7
7
  exports.generateSubAppContainerKey = generateSubAppContainerKey;
8
8
  exports.logger = void 0;
9
-
10
9
  var _debug = _interopRequireDefault(require("debug"));
11
-
12
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
11
  /**
15
12
  * Tips: this package will be bundled and running in the browser, do not import from `@modern-js/utils`.
16
13
  */
14
+
17
15
  const logger = (0, _debug.default)('modern-js:plugin-garfish');
18
16
  exports.logger = logger;
19
17
  const SUBMODULE_APP_COMPONENT_KEY = 'SubModuleComponent';
20
18
  exports.SUBMODULE_APP_COMPONENT_KEY = SUBMODULE_APP_COMPONENT_KEY;
21
-
22
19
  function generateSubAppContainerKey(moduleInfo) {
23
20
  return moduleInfo ? `modern_sub_app_container_${decodeURIComponent(moduleInfo === null || moduleInfo === void 0 ? void 0 : moduleInfo.name)}` : 'modern_sub_app_container';
24
21
  }
@@ -18,7 +18,6 @@ export function getDefaultMicroFrontedConfig(microFrontend) {
18
18
  moduleApp: ''
19
19
  };
20
20
  }
21
-
22
21
  return _objectSpread({
23
22
  enableHtmlEntry: true,
24
23
  externalBasicLibrary: false
@@ -26,19 +25,18 @@ export function getDefaultMicroFrontedConfig(microFrontend) {
26
25
  }
27
26
  export default (function () {
28
27
  var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
29
- _ref$pluginName = _ref.pluginName,
30
- pluginName = _ref$pluginName === void 0 ? '@modern-js/plugin-garfish' : _ref$pluginName,
31
- _ref$runtimePluginNam = _ref.runtimePluginName,
32
- runtimePluginName = _ref$runtimePluginNam === void 0 ? '@modern-js/runtime/plugins' : _ref$runtimePluginNam,
33
- _ref$mfPackagePath = _ref.mfPackagePath,
34
- mfPackagePath = _ref$mfPackagePath === void 0 ? path.resolve(__dirname, '../../../../') : _ref$mfPackagePath;
35
-
28
+ _ref$pluginName = _ref.pluginName,
29
+ pluginName = _ref$pluginName === void 0 ? '@modern-js/plugin-garfish' : _ref$pluginName,
30
+ _ref$runtimePluginNam = _ref.runtimePluginName,
31
+ runtimePluginName = _ref$runtimePluginNam === void 0 ? '@modern-js/runtime/plugins' : _ref$runtimePluginNam,
32
+ _ref$mfPackagePath = _ref.mfPackagePath,
33
+ mfPackagePath = _ref$mfPackagePath === void 0 ? path.resolve(__dirname, '../../../../') : _ref$mfPackagePath;
36
34
  return {
37
35
  name: '@modern-js/plugin-garfish',
38
36
  setup: function setup(_ref2) {
39
37
  var useAppContext = _ref2.useAppContext,
40
- useResolvedConfigContext = _ref2.useResolvedConfigContext,
41
- useConfigContext = _ref2.useConfigContext;
38
+ useResolvedConfigContext = _ref2.useResolvedConfigContext,
39
+ useConfigContext = _ref2.useConfigContext;
42
40
  var pluginsExportsUtils;
43
41
  var runtimeExportsUtils;
44
42
  return {
@@ -48,7 +46,6 @@ export default (function () {
48
46
  resolvedConfig: function () {
49
47
  var _resolvedConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(config) {
50
48
  var resolved, _getRuntimeConfig, masterApp, router, nConfig, _router$historyOption;
51
-
52
49
  return _regeneratorRuntime().wrap(function _callee$(_context) {
53
50
  while (1) {
54
51
  switch (_context.prev = _context.next) {
@@ -58,14 +55,12 @@ export default (function () {
58
55
  nConfig = {
59
56
  resolved: _objectSpread({}, resolved)
60
57
  };
61
-
62
58
  if (masterApp) {
63
59
  // basename does not exist use router's basename
64
60
  setRuntimeConfig(nConfig.resolved, 'masterApp', Object.assign(_typeof(masterApp) === 'object' ? _objectSpread({}, masterApp) : {}, {
65
61
  basename: (router === null || router === void 0 ? void 0 : (_router$historyOption = router.historyOptions) === null || _router$historyOption === void 0 ? void 0 : _router$historyOption.basename) || (router === null || router === void 0 ? void 0 : router.basename) || '/'
66
62
  }));
67
63
  }
68
-
69
64
  logger("resolvedConfig", {
70
65
  output: nConfig.resolved.output,
71
66
  runtime: nConfig.resolved.runtime,
@@ -73,7 +68,6 @@ export default (function () {
73
68
  server: nConfig.resolved.server
74
69
  });
75
70
  return _context.abrupt("return", nConfig);
76
-
77
71
  case 6:
78
72
  case "end":
79
73
  return _context.stop();
@@ -81,36 +75,32 @@ export default (function () {
81
75
  }
82
76
  }, _callee);
83
77
  }));
84
-
85
78
  function resolvedConfig(_x) {
86
79
  return _resolvedConfig.apply(this, arguments);
87
80
  }
88
-
89
81
  return resolvedConfig;
90
82
  }(),
91
83
  config: function config() {
92
84
  var _useConfig$output$dis, _useConfig$output, _useConfig$deploy;
93
-
94
85
  // eslint-disable-next-line react-hooks/rules-of-hooks
95
86
  var useConfig = useConfigContext();
96
- logger('useConfig', useConfig); // eslint-disable-next-line react-hooks/rules-of-hooks
87
+ logger('useConfig', useConfig);
97
88
 
89
+ // eslint-disable-next-line react-hooks/rules-of-hooks
98
90
  var config = useAppContext();
99
91
  pluginsExportsUtils = createRuntimeExportsUtils(config.internalDirectory, 'plugins');
100
92
  runtimeExportsUtils = createRuntimeExportsUtils(config.internalDirectory, 'index');
101
- var disableCssExtract = (_useConfig$output$dis = (_useConfig$output = useConfig.output) === null || _useConfig$output === void 0 ? void 0 : _useConfig$output.disableCssExtract) !== null && _useConfig$output$dis !== void 0 ? _useConfig$output$dis : false; // When the micro-frontend application js entry, there is no need to extract css, close cssExtract
93
+ var disableCssExtract = (_useConfig$output$dis = (_useConfig$output = useConfig.output) === null || _useConfig$output === void 0 ? void 0 : _useConfig$output.disableCssExtract) !== null && _useConfig$output$dis !== void 0 ? _useConfig$output$dis : false;
102
94
 
95
+ // When the micro-frontend application js entry, there is no need to extract css, close cssExtract
103
96
  if ((_useConfig$deploy = useConfig.deploy) !== null && _useConfig$deploy !== void 0 && _useConfig$deploy.microFrontend) {
104
97
  var _useConfig$deploy2;
105
-
106
98
  var _getDefaultMicroFront = getDefaultMicroFrontedConfig((_useConfig$deploy2 = useConfig.deploy) === null || _useConfig$deploy2 === void 0 ? void 0 : _useConfig$deploy2.microFrontend),
107
- enableHtmlEntry = _getDefaultMicroFront.enableHtmlEntry;
108
-
99
+ enableHtmlEntry = _getDefaultMicroFront.enableHtmlEntry;
109
100
  if (!enableHtmlEntry) {
110
101
  disableCssExtract = true;
111
102
  }
112
103
  }
113
-
114
104
  return {
115
105
  output: {
116
106
  disableCssExtract: disableCssExtract
@@ -129,40 +119,33 @@ export default (function () {
129
119
  },
130
120
  webpackChain: function webpackChain(chain, _ref3) {
131
121
  var _resolveOptions$deplo, _resolveWebpackConfig;
132
-
133
122
  var webpack = _ref3.webpack,
134
- _ref3$env = _ref3.env,
135
- env = _ref3$env === void 0 ? process.env.NODE_ENV || 'development' : _ref3$env,
136
- CHAIN_ID = _ref3.CHAIN_ID;
123
+ _ref3$env = _ref3.env,
124
+ env = _ref3$env === void 0 ? process.env.NODE_ENV || 'development' : _ref3$env,
125
+ CHAIN_ID = _ref3.CHAIN_ID;
137
126
  // eslint-disable-next-line react-hooks/rules-of-hooks
138
127
  var resolveOptions = useResolvedConfigContext();
139
-
140
128
  if (resolveOptions !== null && resolveOptions !== void 0 && (_resolveOptions$deplo = resolveOptions.deploy) !== null && _resolveOptions$deplo !== void 0 && _resolveOptions$deplo.microFrontend) {
141
129
  var _resolveOptions$serve, _resolveOptions$deplo2;
142
-
143
130
  chain.output.libraryTarget('umd');
144
-
145
131
  if (resolveOptions !== null && resolveOptions !== void 0 && (_resolveOptions$serve = resolveOptions.server) !== null && _resolveOptions$serve !== void 0 && _resolveOptions$serve.port && env === 'development') {
146
132
  chain.output.publicPath("//localhost:".concat(resolveOptions.server.port, "/"));
147
- } // add comments avoid sourcemap abnormal
148
-
133
+ }
149
134
 
135
+ // add comments avoid sourcemap abnormal
150
136
  if (webpack.BannerPlugin) {
151
137
  chain.plugin(CHAIN_ID.PLUGIN.BANNER).use(webpack.BannerPlugin, [{
152
138
  banner: 'Micro front-end'
153
139
  }]);
154
140
  }
155
-
156
141
  var _getDefaultMicroFront2 = getDefaultMicroFrontedConfig((_resolveOptions$deplo2 = resolveOptions.deploy) === null || _resolveOptions$deplo2 === void 0 ? void 0 : _resolveOptions$deplo2.microFrontend),
157
- _enableHtmlEntry = _getDefaultMicroFront2.enableHtmlEntry,
158
- externalBasicLibrary = _getDefaultMicroFront2.externalBasicLibrary; // external
159
-
160
-
142
+ _enableHtmlEntry = _getDefaultMicroFront2.enableHtmlEntry,
143
+ externalBasicLibrary = _getDefaultMicroFront2.externalBasicLibrary;
144
+ // external
161
145
  if (externalBasicLibrary) {
162
146
  chain.externals(externals);
163
- } // use html mode
164
-
165
-
147
+ }
148
+ // use html mode
166
149
  if (!_enableHtmlEntry) {
167
150
  chain.output.filename('index.js');
168
151
  chain.plugins["delete"]("".concat(CHAIN_ID.PLUGIN.HTML, "-main"));
@@ -172,7 +155,6 @@ export default (function () {
172
155
  });
173
156
  }
174
157
  }
175
-
176
158
  var resolveWebpackConfig = chain.toConfig();
177
159
  logger('webpackConfig', {
178
160
  output: resolveWebpackConfig.output,
@@ -193,13 +175,11 @@ export default (function () {
193
175
  },
194
176
  modifyEntryImports: function modifyEntryImports(_ref4) {
195
177
  var entrypoint = _ref4.entrypoint,
196
- imports = _ref4.imports;
178
+ imports = _ref4.imports;
197
179
  // eslint-disable-next-line react-hooks/rules-of-hooks
198
180
  var config = useResolvedConfigContext();
199
-
200
181
  var _getRuntimeConfig2 = getRuntimeConfig(config),
201
- masterApp = _getRuntimeConfig2.masterApp;
202
-
182
+ masterApp = _getRuntimeConfig2.masterApp;
203
183
  if (masterApp) {
204
184
  imports.push({
205
185
  value: runtimePluginName,
@@ -214,7 +194,6 @@ export default (function () {
214
194
  }]
215
195
  });
216
196
  }
217
-
218
197
  imports.push({
219
198
  value: runtimePluginName,
220
199
  specifiers: [{
@@ -236,13 +215,11 @@ export default (function () {
236
215
  },
237
216
  modifyEntryRuntimePlugins: function modifyEntryRuntimePlugins(_ref5) {
238
217
  var entrypoint = _ref5.entrypoint,
239
- plugins = _ref5.plugins;
218
+ plugins = _ref5.plugins;
240
219
  // eslint-disable-next-line react-hooks/rules-of-hooks
241
220
  var config = useResolvedConfigContext();
242
-
243
221
  var _getRuntimeConfig3 = getRuntimeConfig(config),
244
- masterApp = _getRuntimeConfig3.masterApp;
245
-
222
+ masterApp = _getRuntimeConfig3.masterApp;
246
223
  if (masterApp) {
247
224
  logger('garfishPlugin options', masterApp);
248
225
  plugins.push({
@@ -251,7 +228,6 @@ export default (function () {
251
228
  options: masterApp === true ? JSON.stringify({}) : JSON.stringify(masterApp)
252
229
  });
253
230
  }
254
-
255
231
  return {
256
232
  entrypoint: entrypoint,
257
233
  plugins: plugins
@@ -259,19 +235,16 @@ export default (function () {
259
235
  },
260
236
  modifyEntryRenderFunction: function modifyEntryRenderFunction(_ref6) {
261
237
  var _config$deploy;
262
-
263
238
  var entrypoint = _ref6.entrypoint,
264
- code = _ref6.code;
239
+ code = _ref6.code;
265
240
  // eslint-disable-next-line react-hooks/rules-of-hooks
266
241
  var config = useResolvedConfigContext();
267
-
268
242
  if (!(config !== null && config !== void 0 && (_config$deploy = config.deploy) !== null && _config$deploy !== void 0 && _config$deploy.microFrontend)) {
269
243
  return {
270
244
  entrypoint: entrypoint,
271
245
  code: code
272
246
  };
273
247
  }
274
-
275
248
  var nCode = makeRenderFunction(code);
276
249
  logger('makeRenderFunction', nCode);
277
250
  return {
@@ -281,12 +254,10 @@ export default (function () {
281
254
  },
282
255
  modifyEntryExport: function modifyEntryExport(_ref7) {
283
256
  var _config$deploy2;
284
-
285
257
  var entrypoint = _ref7.entrypoint,
286
- exportStatement = _ref7.exportStatement;
258
+ exportStatement = _ref7.exportStatement;
287
259
  // eslint-disable-next-line react-hooks/rules-of-hooks
288
260
  var config = useResolvedConfigContext();
289
-
290
261
  if (config !== null && config !== void 0 && (_config$deploy2 = config.deploy) !== null && _config$deploy2 !== void 0 && _config$deploy2.microFrontend) {
291
262
  var exportStatementCode = makeProvider();
292
263
  logger('exportStatement', exportStatementCode);
@@ -295,7 +266,6 @@ export default (function () {
295
266
  exportStatement: exportStatementCode
296
267
  };
297
268
  }
298
-
299
269
  return {
300
270
  entrypoint: entrypoint,
301
271
  exportStatement: exportStatement
@@ -4,32 +4,28 @@ export var makeProvider = function makeProvider() {
4
4
  export var makeRenderFunction = function makeRenderFunction(code) {
5
5
  var inGarfishToRender = "\n const { basename, props, dom, appName } = typeof arguments[0] === 'object' && arguments[0] || {};\n if (!canContinueRender({ dom, appName })) return null;\n let { AppWrapper, mountNode } = generateAppWrapperAndRootDom({App, props, dom});\n ";
6
6
  return inGarfishToRender + code.replace("router(", "generateRouterPlugin(basename,").replace('(App)', "(AppWrapper)").replace(/MOUNT_ID/g, 'mountNode').replace("bootstrap(AppWrapper, mountNode, root", 'bootstrap(AppWrapper, mountNode, root = IS_REACT18 ? ReactDOM.createRoot(mountNode) : null');
7
- }; // support legacy config
7
+ };
8
8
 
9
+ // support legacy config
9
10
  export function getRuntimeConfig(config) {
10
11
  var _config$runtime;
11
-
12
12
  if (config !== null && config !== void 0 && (_config$runtime = config.runtime) !== null && _config$runtime !== void 0 && _config$runtime.features) {
13
13
  var _config$runtime2;
14
-
15
14
  return config === null || config === void 0 ? void 0 : (_config$runtime2 = config.runtime) === null || _config$runtime2 === void 0 ? void 0 : _config$runtime2.features;
16
15
  }
17
-
18
16
  return (config === null || config === void 0 ? void 0 : config.runtime) || {};
19
- } // support legacy config
17
+ }
20
18
 
19
+ // support legacy config
21
20
  export function setRuntimeConfig(config, key, value) {
22
21
  var _config$runtime3, _config$runtime4;
23
-
24
22
  if (config !== null && config !== void 0 && (_config$runtime3 = config.runtime) !== null && _config$runtime3 !== void 0 && _config$runtime3.features && config !== null && config !== void 0 && (_config$runtime4 = config.runtime) !== null && _config$runtime4 !== void 0 && _config$runtime4.features[key]) {
25
23
  config.runtime.features[key] = value;
26
24
  return undefined;
27
25
  }
28
-
29
26
  if (config !== null && config !== void 0 && config.runtime && config !== null && config !== void 0 && config.runtime[key]) {
30
27
  config.runtime[key] = value;
31
28
  return undefined;
32
29
  }
33
-
34
30
  return undefined;
35
31
  }
@@ -17,50 +17,43 @@ export function Loadable(WrapComponent) {
17
17
  return function (defaultLoadable) {
18
18
  return function Lodable(props) {
19
19
  var _props$loadable2;
20
-
21
20
  var _props$loadable = props.loadable,
22
- loadable = _props$loadable === void 0 ? defaultLoadable !== null && defaultLoadable !== void 0 ? defaultLoadable : DEFAULT_LOADABLE : _props$loadable,
23
- otherProps = _objectWithoutProperties(props, _excluded);
24
-
21
+ loadable = _props$loadable === void 0 ? defaultLoadable !== null && defaultLoadable !== void 0 ? defaultLoadable : DEFAULT_LOADABLE : _props$loadable,
22
+ otherProps = _objectWithoutProperties(props, _excluded);
25
23
  var delayTimer = null;
26
24
  var timeoutTimer = null;
27
-
28
25
  var _useState = useState(function () {
29
- var delay = loadable.delay,
26
+ var delay = loadable.delay,
30
27
  timeout = loadable.timeout;
31
- var initState = {
32
- error: null,
33
- pastDelay: false,
34
- timedOut: false,
35
- isLoading: false
36
- };
37
-
38
- if (typeof delay === 'number') {
39
- if (delay === 0) {
40
- initState.pastDelay = true;
41
- } else {
42
- delayTimer = setTimeout(function () {
28
+ var initState = {
29
+ error: null,
30
+ pastDelay: false,
31
+ timedOut: false,
32
+ isLoading: false
33
+ };
34
+ if (typeof delay === 'number') {
35
+ if (delay === 0) {
36
+ initState.pastDelay = true;
37
+ } else {
38
+ delayTimer = setTimeout(function () {
39
+ setStateWithMountCheck({
40
+ pastDelay: true
41
+ });
42
+ }, delay);
43
+ }
44
+ }
45
+ if (typeof timeout === 'number') {
46
+ timeoutTimer = setTimeout(function () {
43
47
  setStateWithMountCheck({
44
- pastDelay: true
48
+ timedOut: true
45
49
  });
46
- }, delay);
50
+ }, timeout);
47
51
  }
48
- }
49
-
50
- if (typeof timeout === 'number') {
51
- timeoutTimer = setTimeout(function () {
52
- setStateWithMountCheck({
53
- timedOut: true
54
- });
55
- }, timeout);
56
- }
57
-
58
- return initState;
59
- }),
60
- _useState2 = _slicedToArray(_useState, 2),
61
- state = _useState2[0],
62
- setState = _useState2[1];
63
-
52
+ return initState;
53
+ }),
54
+ _useState2 = _slicedToArray(_useState, 2),
55
+ state = _useState2[0],
56
+ setState = _useState2[1];
64
57
  var LoadingComponent = (_props$loadable2 = props.loadable) === null || _props$loadable2 === void 0 ? void 0 : _props$loadable2.loading;
65
58
  useEffect(function () {
66
59
  logger('Loadable render state', {
@@ -74,12 +67,10 @@ export function Loadable(WrapComponent) {
74
67
  isLoading: false,
75
68
  error: null
76
69
  });
77
-
78
70
  if (delayTimer) {
79
71
  clearTimeout(delayTimer);
80
72
  delayTimer = null;
81
73
  }
82
-
83
74
  if (timeoutTimer) {
84
75
  clearTimeout(timeoutTimer);
85
76
  timeoutTimer = null;
@@ -115,7 +106,6 @@ export function Loadable(WrapComponent) {
115
106
  if (props.error && !LoadingComponent) {
116
107
  throw props.error;
117
108
  }
118
-
119
109
  setStateWithMountCheck(props);
120
110
  }
121
111
  }, otherProps))]
@@ -19,24 +19,19 @@ import setExternal from "./utils/setExternal";
19
19
  import { generateMApp } from "./utils/MApp";
20
20
  import { generateApps } from "./utils/apps";
21
21
  import { jsx as _jsx } from "react/jsx-runtime";
22
-
23
22
  function initOptions() {
24
23
  return _initOptions.apply(this, arguments);
25
24
  } // export default GarfishPlugin;
26
-
27
-
28
25
  function _initOptions() {
29
26
  _initOptions = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
30
27
  var _window, _window$modern_manife, _window2, _window2$modern_manif;
31
-
32
28
  var manifest,
33
- options,
34
- apps,
35
- getAppList,
36
- _window3,
37
- _window3$modern_manif,
38
- _args2 = arguments;
39
-
29
+ options,
30
+ apps,
31
+ getAppList,
32
+ _window3,
33
+ _window3$modern_manif,
34
+ _args2 = arguments;
40
35
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
41
36
  while (1) {
42
37
  switch (_context2.prev = _context2.next) {
@@ -44,44 +39,35 @@ function _initOptions() {
44
39
  manifest = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {};
45
40
  options = _args2.length > 1 ? _args2[1] : undefined;
46
41
  apps = options.apps || []; // use manifest modules
47
-
48
42
  if (manifest !== null && manifest !== void 0 && manifest.modules) {
49
43
  if ((manifest === null || manifest === void 0 ? void 0 : manifest.modules.length) > 0) {
50
44
  apps = manifest === null || manifest === void 0 ? void 0 : manifest.modules;
51
45
  }
52
-
53
46
  logger('manifest modules', apps);
54
- } // get module list
55
-
47
+ }
56
48
 
49
+ // get module list
57
50
  if (!(manifest !== null && manifest !== void 0 && manifest.getAppList)) {
58
51
  _context2.next = 10;
59
52
  break;
60
53
  }
61
-
62
54
  _context2.next = 7;
63
55
  return manifest === null || manifest === void 0 ? void 0 : manifest.getAppList(manifest);
64
-
65
56
  case 7:
66
57
  getAppList = _context2.sent;
67
-
68
58
  if (getAppList.length > 0) {
69
59
  apps = getAppList;
70
60
  }
71
-
72
61
  logger('getAppList modules', apps);
73
-
74
62
  case 10:
75
63
  // get inject modules list
76
64
  if ((_window = window) !== null && _window !== void 0 && (_window$modern_manife = _window.modern_manifest) !== null && _window$modern_manife !== void 0 && _window$modern_manife.modules && ((_window2 = window) === null || _window2 === void 0 ? void 0 : (_window2$modern_manif = _window2.modern_manifest) === null || _window2$modern_manif === void 0 ? void 0 : _window2$modern_manif.modules.length) > 0) {
77
65
  apps = (_window3 = window) === null || _window3 === void 0 ? void 0 : (_window3$modern_manif = _window3.modern_manifest) === null || _window3$modern_manif === void 0 ? void 0 : _window3$modern_manif.modules;
78
66
  logger('modern_manifest', apps);
79
67
  }
80
-
81
68
  return _context2.abrupt("return", _objectSpread(_objectSpread({}, options), {}, {
82
69
  apps: apps
83
70
  }));
84
-
85
71
  case 12:
86
72
  case "end":
87
73
  return _context2.stop();
@@ -91,34 +77,25 @@ function _initOptions() {
91
77
  }));
92
78
  return _initOptions.apply(this, arguments);
93
79
  }
94
-
95
80
  export default (function (config) {
96
81
  return {
97
82
  name: '@modern-js/garfish-plugin',
98
83
  setup: function setup() {
99
84
  setExternal();
100
-
101
85
  var manifest = config.manifest,
102
- options = _objectWithoutProperties(config, _excluded);
103
-
86
+ options = _objectWithoutProperties(config, _excluded);
104
87
  logger('createPlugin', config);
105
88
  var promise = initOptions(manifest, options);
106
89
  return {
107
90
  hoc: function hoc(_ref, next) {
108
91
  var App = _ref.App;
109
-
110
92
  var GetMicroFrontendApp = /*#__PURE__*/function (_React$Component) {
111
93
  _inherits(GetMicroFrontendApp, _React$Component);
112
-
113
94
  var _super = _createSuper(GetMicroFrontendApp);
114
-
115
95
  function GetMicroFrontendApp(props) {
116
96
  var _this;
117
-
118
97
  _classCallCheck(this, GetMicroFrontendApp);
119
-
120
98
  _this = _super.call(this, props);
121
-
122
99
  _defineProperty(_assertThisInitialized(_this), "state", {
123
100
  MApp: function MApp() {
124
101
  logger('MApp init Component Render');
@@ -133,11 +110,9 @@ export default (function (config) {
133
110
  }),
134
111
  appInfoList: []
135
112
  });
136
-
137
113
  var load = /*#__PURE__*/function () {
138
114
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
139
115
  var GarfishConfig, _generateApps, appInfoList, apps, MApp;
140
-
141
116
  return _regeneratorRuntime().wrap(function _callee$(_context) {
142
117
  while (1) {
143
118
  switch (_context.prev = _context.next) {
@@ -148,7 +123,6 @@ export default (function (config) {
148
123
  }));
149
124
  _context.next = 3;
150
125
  return promise;
151
-
152
126
  case 3:
153
127
  GarfishConfig = _context.sent;
154
128
  _generateApps = generateApps(GarfishConfig, manifest), appInfoList = _generateApps.appInfoList, apps = _generateApps.apps;
@@ -163,13 +137,11 @@ export default (function (config) {
163
137
  apps: apps,
164
138
  appInfoList: appInfoList
165
139
  });
166
-
167
140
  _this.setState({
168
141
  MApp: MApp,
169
142
  apps: apps,
170
143
  appInfoList: appInfoList
171
144
  });
172
-
173
145
  case 10:
174
146
  case "end":
175
147
  return _context.stop();
@@ -177,16 +149,13 @@ export default (function (config) {
177
149
  }
178
150
  }, _callee);
179
151
  }));
180
-
181
152
  return function load() {
182
153
  return _ref2.apply(this, arguments);
183
154
  };
184
155
  }();
185
-
186
156
  load();
187
157
  return _this;
188
158
  }
189
-
190
159
  _createClass(GetMicroFrontendApp, [{
191
160
  key: "render",
192
161
  value: function render() {
@@ -197,10 +166,8 @@ export default (function (config) {
197
166
  });
198
167
  }
199
168
  }]);
200
-
201
169
  return GetMicroFrontendApp;
202
170
  }(React.Component);
203
-
204
171
  return next({
205
172
  App: hoistNonReactStatics(GetMicroFrontendApp, App)
206
173
  });
@@ -4,10 +4,9 @@ import { logger } from "../util";
4
4
  import { GarfishContext } from "./utils/Context";
5
5
  export function useModuleApps() {
6
6
  var _useContext = useContext(GarfishContext),
7
- apps = _useContext.apps,
8
- MApp = _useContext.MApp,
9
- appInfoList = _useContext.appInfoList;
10
-
7
+ apps = _useContext.apps,
8
+ MApp = _useContext.MApp,
9
+ appInfoList = _useContext.appInfoList;
11
10
  logger('call useModuleApps', _objectSpread({
12
11
  MApp: MApp,
13
12
  apps: appInfoList
@@ -20,7 +19,6 @@ export function useModuleApps() {
20
19
  if (typeof p === 'string' && p in target) {
21
20
  return Reflect.get(target, p, receiver);
22
21
  }
23
-
24
22
  return function () {
25
23
  return /*#__PURE__*/React.createElement('div');
26
24
  };
@@ -30,8 +28,7 @@ export function useModuleApps() {
30
28
  }
31
29
  export function useModuleApp() {
32
30
  var _useContext2 = useContext(GarfishContext),
33
- MApp = _useContext2.MApp;
34
-
31
+ MApp = _useContext2.MApp;
35
32
  logger('call useModuleApps', MApp);
36
33
  return MApp;
37
34
  }