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

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 (32) hide show
  1. package/CHANGELOG.md +83 -0
  2. package/dist/js/modern/cli/index.js +35 -48
  3. package/dist/js/modern/cli/utils.js +15 -9
  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 +34 -56
  10. package/dist/js/node/cli/utils.js +17 -15
  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 +54 -64
  22. package/dist/js/treeshaking/cli/utils.js +9 -9
  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 +4 -9
  29. package/dist/types/cli/utils.d.ts +4 -3
  30. package/dist/types/runtime/plugin.d.ts +0 -2
  31. package/dist/types/runtime/utils/setExternal.d.ts +0 -1
  32. package/package.json +15 -14
@@ -4,65 +4,43 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.generateApps = generateApps;
7
-
8
7
  var _path = _interopRequireDefault(require("path"));
9
-
10
8
  var _react = _interopRequireDefault(require("react"));
11
-
12
9
  var _garfish = _interopRequireDefault(require("garfish"));
13
-
14
10
  var _pluginRouterLegacy = require("@modern-js/plugin-router-legacy");
15
-
16
11
  var _util = require("../../util");
17
-
18
12
  var _loadable = require("../loadable");
19
-
20
13
  var _jsxRuntime = require("react/jsx-runtime");
21
-
22
14
  const _excluded = ["match", "history", "setLoadingState"];
23
-
24
15
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
-
26
16
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
27
-
28
17
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
29
-
30
18
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
31
-
32
19
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
33
-
34
20
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
35
-
36
21
  function getAppInstance(options, appInfo, manifest) {
37
22
  let locationHref = '';
38
-
39
23
  class MicroApp extends _react.default.Component {
40
24
  constructor(...args) {
41
25
  super(...args);
42
-
43
26
  _defineProperty(this, "state", {
44
27
  appInstance: null,
45
28
  domId: (0, _util.generateSubAppContainerKey)(appInfo),
46
29
  SubModuleComponent: undefined
47
30
  });
48
-
49
31
  _defineProperty(this, "unregisterHistoryListener", () => {});
50
32
  }
51
-
52
- // eslint-disable-next-line @typescript-eslint/naming-convention
53
- async UNSAFE_componentWillMount() {
33
+ async componentDidMount() {
54
34
  const _this$props = this.props,
55
- {
56
- match,
57
- history,
58
- setLoadingState
59
- } = _this$props,
60
- userProps = _objectWithoutProperties(_this$props, _excluded);
61
-
35
+ {
36
+ match,
37
+ history,
38
+ setLoadingState
39
+ } = _this$props,
40
+ userProps = _objectWithoutProperties(_this$props, _excluded);
62
41
  const {
63
42
  domId
64
43
  } = this.state;
65
-
66
44
  const loadAppOptions = _objectSpread(_objectSpread({}, appInfo), {}, {
67
45
  insulationVariable: [...(appInfo.insulationVariable || []), '_SERVER_DATA'],
68
46
  domGetter: `#${domId}`,
@@ -89,20 +67,16 @@ function getAppInstance(options, appInfo, manifest) {
89
67
  return render === null || render === void 0 ? void 0 : render.apply(provider, props);
90
68
  }
91
69
  },
92
-
93
70
  unmount(...props) {
94
71
  if (componetRenderMode) {
95
72
  return undefined;
96
73
  }
97
-
98
74
  (0, _util.logger)('MicroApp customer destroy', props);
99
75
  return destroy === null || destroy === void 0 ? void 0 : destroy.apply(provider, props);
100
76
  }
101
-
102
77
  };
103
78
  }
104
79
  });
105
-
106
80
  setLoadingState({
107
81
  isLoading: true,
108
82
  error: null
@@ -110,21 +84,19 @@ function getAppInstance(options, appInfo, manifest) {
110
84
  (0, _util.logger)(`MicroApp Garfish.loadApp "${appInfo.name}"`, {
111
85
  loadAppOptions
112
86
  });
113
-
114
87
  try {
115
88
  const appInstance = await _garfish.default.loadApp(appInfo.name, loadAppOptions);
116
-
117
89
  if (!appInstance) {
118
90
  throw new Error(`MicroApp Garfish.loadApp "${appInfo.name}" result is null`);
119
91
  }
120
92
 
93
+ // eslint-disable-next-line react/no-did-mount-set-state
121
94
  this.setState({
122
95
  appInstance
123
96
  });
124
97
  setLoadingState({
125
98
  isLoading: false
126
99
  });
127
-
128
100
  if (appInstance.mounted && appInstance.appInfo.cache) {
129
101
  (0, _util.logger)(`MicroApp Garfish.loadApp "${appInfo.name}" show`, {
130
102
  appInfo: appInstance.appInfo,
@@ -138,7 +110,6 @@ function getAppInstance(options, appInfo, manifest) {
138
110
  });
139
111
  await (appInstance === null || appInstance === void 0 ? void 0 : appInstance.mount());
140
112
  }
141
-
142
113
  this.unregisterHistoryListener = history === null || history === void 0 ? void 0 : history.listen(() => {
143
114
  if (locationHref !== history.location.pathname) {
144
115
  locationHref = history.location.pathname;
@@ -154,20 +125,16 @@ function getAppInstance(options, appInfo, manifest) {
154
125
  });
155
126
  }
156
127
  }
157
-
158
128
  async componentWillUnmount() {
159
129
  var _this$unregisterHisto;
160
-
161
130
  const {
162
131
  appInstance
163
132
  } = this.state;
164
133
  (_this$unregisterHisto = this.unregisterHistoryListener) === null || _this$unregisterHisto === void 0 ? void 0 : _this$unregisterHisto.call(this);
165
-
166
134
  if (appInstance) {
167
135
  const {
168
136
  appInfo
169
137
  } = appInstance;
170
-
171
138
  if (appInfo.cache) {
172
139
  (0, _util.logger)(`MicroApp Garfish.loadApp "${appInfo.name}" hide`);
173
140
  appInstance === null || appInstance === void 0 ? void 0 : appInstance.hide();
@@ -177,7 +144,6 @@ function getAppInstance(options, appInfo, manifest) {
177
144
  }
178
145
  }
179
146
  }
180
-
181
147
  render() {
182
148
  const {
183
149
  domId,
@@ -190,15 +156,11 @@ function getAppInstance(options, appInfo, manifest) {
190
156
  })
191
157
  });
192
158
  }
193
-
194
159
  }
195
-
196
160
  return (0, _loadable.Loadable)((0, _pluginRouterLegacy.withRouter)(MicroApp))(manifest === null || manifest === void 0 ? void 0 : manifest.loadable);
197
161
  }
198
-
199
162
  function generateApps(options, manifest) {
200
163
  var _options$apps;
201
-
202
164
  const apps = {};
203
165
  (_options$apps = options.apps) === null || _options$apps === void 0 ? void 0 : _options$apps.forEach(appInfo => {
204
166
  const Component = getAppInstance(options, appInfo, manifest);
@@ -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
  }
@@ -5,7 +5,7 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
5
5
  import path from 'path';
6
6
  import { createRuntimeExportsUtils, PLUGIN_SCHEMAS } from '@modern-js/utils';
7
7
  import { logger } from "../util";
8
- import { getRuntimeConfig, makeProvider, makeRenderFunction, setRuntimeConfig } from "./utils";
8
+ import { getRuntimeConfig, makeProvider, makeRenderFunction, setRuntimeConfig, generateAsyncEntry } from "./utils";
9
9
  export var externals = {
10
10
  'react-dom': 'react-dom',
11
11
  react: 'react'
@@ -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,33 @@ 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
- var _useConfig$output$dis, _useConfig$output, _useConfig$deploy;
93
-
84
+ var _useConfig$output, _useConfig$deploy;
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 = useConfig.output) === null || _useConfig$output === void 0 ? void 0 : _useConfig$output.disableCssExtract) || 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) {
101
+ // FIXME: the handle the `disableCssExtract` config
110
102
  disableCssExtract = true;
111
103
  }
112
104
  }
113
-
114
105
  return {
115
106
  output: {
116
107
  disableCssExtract: disableCssExtract
@@ -129,40 +120,33 @@ export default (function () {
129
120
  },
130
121
  webpackChain: function webpackChain(chain, _ref3) {
131
122
  var _resolveOptions$deplo, _resolveWebpackConfig;
132
-
133
123
  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;
124
+ _ref3$env = _ref3.env,
125
+ env = _ref3$env === void 0 ? process.env.NODE_ENV || 'development' : _ref3$env,
126
+ CHAIN_ID = _ref3.CHAIN_ID;
137
127
  // eslint-disable-next-line react-hooks/rules-of-hooks
138
128
  var resolveOptions = useResolvedConfigContext();
139
-
140
129
  if (resolveOptions !== null && resolveOptions !== void 0 && (_resolveOptions$deplo = resolveOptions.deploy) !== null && _resolveOptions$deplo !== void 0 && _resolveOptions$deplo.microFrontend) {
141
130
  var _resolveOptions$serve, _resolveOptions$deplo2;
142
-
143
131
  chain.output.libraryTarget('umd');
144
-
145
132
  if (resolveOptions !== null && resolveOptions !== void 0 && (_resolveOptions$serve = resolveOptions.server) !== null && _resolveOptions$serve !== void 0 && _resolveOptions$serve.port && env === 'development') {
146
133
  chain.output.publicPath("//localhost:".concat(resolveOptions.server.port, "/"));
147
- } // add comments avoid sourcemap abnormal
148
-
134
+ }
149
135
 
136
+ // add comments avoid sourcemap abnormal
150
137
  if (webpack.BannerPlugin) {
151
138
  chain.plugin(CHAIN_ID.PLUGIN.BANNER).use(webpack.BannerPlugin, [{
152
139
  banner: 'Micro front-end'
153
140
  }]);
154
141
  }
155
-
156
142
  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
-
143
+ _enableHtmlEntry = _getDefaultMicroFront2.enableHtmlEntry,
144
+ externalBasicLibrary = _getDefaultMicroFront2.externalBasicLibrary;
145
+ // external
161
146
  if (externalBasicLibrary) {
162
147
  chain.externals(externals);
163
- } // use html mode
164
-
165
-
148
+ }
149
+ // use html mode
166
150
  if (!_enableHtmlEntry) {
167
151
  chain.output.filename('index.js');
168
152
  chain.plugins["delete"]("".concat(CHAIN_ID.PLUGIN.HTML, "-main"));
@@ -172,7 +156,6 @@ export default (function () {
172
156
  });
173
157
  }
174
158
  }
175
-
176
159
  var resolveWebpackConfig = chain.toConfig();
177
160
  logger('webpackConfig', {
178
161
  output: resolveWebpackConfig.output,
@@ -193,13 +176,11 @@ export default (function () {
193
176
  },
194
177
  modifyEntryImports: function modifyEntryImports(_ref4) {
195
178
  var entrypoint = _ref4.entrypoint,
196
- imports = _ref4.imports;
179
+ imports = _ref4.imports;
197
180
  // eslint-disable-next-line react-hooks/rules-of-hooks
198
181
  var config = useResolvedConfigContext();
199
-
200
182
  var _getRuntimeConfig2 = getRuntimeConfig(config),
201
- masterApp = _getRuntimeConfig2.masterApp;
202
-
183
+ masterApp = _getRuntimeConfig2.masterApp;
203
184
  if (masterApp) {
204
185
  imports.push({
205
186
  value: runtimePluginName,
@@ -214,7 +195,6 @@ export default (function () {
214
195
  }]
215
196
  });
216
197
  }
217
-
218
198
  imports.push({
219
199
  value: runtimePluginName,
220
200
  specifiers: [{
@@ -236,13 +216,11 @@ export default (function () {
236
216
  },
237
217
  modifyEntryRuntimePlugins: function modifyEntryRuntimePlugins(_ref5) {
238
218
  var entrypoint = _ref5.entrypoint,
239
- plugins = _ref5.plugins;
219
+ plugins = _ref5.plugins;
240
220
  // eslint-disable-next-line react-hooks/rules-of-hooks
241
221
  var config = useResolvedConfigContext();
242
-
243
222
  var _getRuntimeConfig3 = getRuntimeConfig(config),
244
- masterApp = _getRuntimeConfig3.masterApp;
245
-
223
+ masterApp = _getRuntimeConfig3.masterApp;
246
224
  if (masterApp) {
247
225
  logger('garfishPlugin options', masterApp);
248
226
  plugins.push({
@@ -251,7 +229,6 @@ export default (function () {
251
229
  options: masterApp === true ? JSON.stringify({}) : JSON.stringify(masterApp)
252
230
  });
253
231
  }
254
-
255
232
  return {
256
233
  entrypoint: entrypoint,
257
234
  plugins: plugins
@@ -259,19 +236,16 @@ export default (function () {
259
236
  },
260
237
  modifyEntryRenderFunction: function modifyEntryRenderFunction(_ref6) {
261
238
  var _config$deploy;
262
-
263
239
  var entrypoint = _ref6.entrypoint,
264
- code = _ref6.code;
240
+ code = _ref6.code;
265
241
  // eslint-disable-next-line react-hooks/rules-of-hooks
266
242
  var config = useResolvedConfigContext();
267
-
268
243
  if (!(config !== null && config !== void 0 && (_config$deploy = config.deploy) !== null && _config$deploy !== void 0 && _config$deploy.microFrontend)) {
269
244
  return {
270
245
  entrypoint: entrypoint,
271
246
  code: code
272
247
  };
273
248
  }
274
-
275
249
  var nCode = makeRenderFunction(code);
276
250
  logger('makeRenderFunction', nCode);
277
251
  return {
@@ -279,15 +253,32 @@ export default (function () {
279
253
  code: nCode
280
254
  };
281
255
  },
282
- modifyEntryExport: function modifyEntryExport(_ref7) {
283
- var _config$deploy2;
284
-
256
+ modifyAsyncEntry: function modifyAsyncEntry(_ref7) {
257
+ var _config$deploy2, _config$source;
285
258
  var entrypoint = _ref7.entrypoint,
286
- exportStatement = _ref7.exportStatement;
259
+ code = _ref7.code;
287
260
  // eslint-disable-next-line react-hooks/rules-of-hooks
288
261
  var config = useResolvedConfigContext();
289
-
290
- if (config !== null && config !== void 0 && (_config$deploy2 = config.deploy) !== null && _config$deploy2 !== void 0 && _config$deploy2.microFrontend) {
262
+ var finalCode = code;
263
+ if (config !== null && config !== void 0 && (_config$deploy2 = config.deploy) !== null && _config$deploy2 !== void 0 && _config$deploy2.microFrontend && config !== null && config !== void 0 && (_config$source = config.source) !== null && _config$source !== void 0 && _config$source.enableAsyncEntry) {
264
+ finalCode = generateAsyncEntry(code);
265
+ return {
266
+ entrypoint: entrypoint,
267
+ code: "".concat(finalCode)
268
+ };
269
+ }
270
+ return {
271
+ entrypoint: entrypoint,
272
+ code: finalCode
273
+ };
274
+ },
275
+ modifyEntryExport: function modifyEntryExport(_ref8) {
276
+ var _config$deploy3;
277
+ var entrypoint = _ref8.entrypoint,
278
+ exportStatement = _ref8.exportStatement;
279
+ // eslint-disable-next-line react-hooks/rules-of-hooks
280
+ var config = useResolvedConfigContext();
281
+ if (config !== null && config !== void 0 && (_config$deploy3 = config.deploy) !== null && _config$deploy3 !== void 0 && _config$deploy3.microFrontend) {
291
282
  var exportStatementCode = makeProvider();
292
283
  logger('exportStatement', exportStatementCode);
293
284
  return {
@@ -295,7 +286,6 @@ export default (function () {
295
286
  exportStatement: exportStatementCode
296
287
  };
297
288
  }
298
-
299
289
  return {
300
290
  entrypoint: entrypoint,
301
291
  exportStatement: exportStatement
@@ -4,32 +4,32 @@ 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
+ }
32
+ export var generateAsyncEntry = function generateAsyncEntry(code) {
33
+ var transformCode = code.replace("import('./bootstrap.js');", "if (!window.__GARFISH__) { import('./bootstrap.js'); }");
34
+ return "\n export const provider = async (...args) => {\n const exports = await import('./bootstrap');\n return exports.provider.apply(null, args);\n };\n ".concat(transformCode, "\n ");
35
+ };
@@ -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))]