@modern-js/plugin-garfish 1.3.0 → 1.4.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 (41) hide show
  1. package/.eslintrc.js +1 -1
  2. package/CHANGELOG.md +35 -0
  3. package/dist/js/modern/cli/index.js +204 -225
  4. package/dist/js/modern/cli/utils.js +85 -31
  5. package/dist/js/modern/index.js +2 -1
  6. package/dist/js/modern/runtime/index.js +2 -1
  7. package/dist/js/modern/runtime/loadable.js +36 -19
  8. package/dist/js/modern/runtime/plugin.js +24 -19
  9. package/dist/js/modern/runtime/utils/MApp.js +7 -10
  10. package/dist/js/modern/runtime/utils/apps.js +3 -9
  11. package/dist/js/node/cli/index.js +207 -222
  12. package/dist/js/node/cli/utils.js +89 -31
  13. package/dist/js/node/index.js +18 -3
  14. package/dist/js/node/runtime/index.js +25 -12
  15. package/dist/js/node/runtime/loadable.js +36 -19
  16. package/dist/js/node/runtime/plugin.js +21 -18
  17. package/dist/js/node/runtime/utils/MApp.js +7 -10
  18. package/dist/js/node/runtime/utils/apps.js +3 -9
  19. package/dist/js/treeshaking/cli/index.js +124 -121
  20. package/dist/js/treeshaking/cli/utils.js +33 -4
  21. package/dist/js/treeshaking/index.js +2 -1
  22. package/dist/js/treeshaking/runtime/index.js +2 -1
  23. package/dist/js/treeshaking/runtime/loadable.js +39 -25
  24. package/dist/js/treeshaking/runtime/plugin.js +29 -24
  25. package/dist/js/treeshaking/runtime/utils/MApp.js +23 -31
  26. package/dist/js/treeshaking/runtime/utils/apps.js +22 -24
  27. package/dist/types/cli/index.d.ts +18 -10
  28. package/dist/types/cli/utils.d.ts +5 -2
  29. package/dist/types/index.d.ts +2 -1
  30. package/dist/types/runtime/index.d.ts +3 -1
  31. package/dist/types/runtime/loadable.d.ts +2 -8
  32. package/dist/types/runtime/plugin.d.ts +29 -3
  33. package/dist/types/runtime/useModuleApps.d.ts +7 -9
  34. package/dist/types/runtime/utils/MApp.d.ts +1 -15
  35. package/dist/types/runtime/utils/apps.d.ts +1 -1
  36. package/package.json +21 -9
  37. package/tests/cli.test.tsx +203 -33
  38. package/tests/hooks.test.tsx +1 -0
  39. package/tests/index.test.tsx +6 -3
  40. package/tsconfig.json +3 -2
  41. package/tests/__snapshots__/cli.test.tsx.snap +0 -71
@@ -1,4 +1,4 @@
1
- var _excluded = ["validateSchema", "externals", "componentKey"];
1
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
2
2
 
3
3
  function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
4
 
@@ -8,76 +8,75 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
8
8
 
9
9
  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; }
10
10
 
11
- 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; }
11
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
12
12
 
13
- 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; }
13
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
14
14
 
15
15
  import path from 'path';
16
- import { createRuntimeExportsUtils, getEntryOptions, PLUGIN_SCHEMAS } from '@modern-js/utils';
16
+ import { createRuntimeExportsUtils, PLUGIN_SCHEMAS } from '@modern-js/utils';
17
17
  import { createPlugin, useAppContext, useResolvedConfigContext } from '@modern-js/core';
18
18
  import { logger } from "../util";
19
- import { makeProvider, makeRenderFunction } from "./utils";
20
-
21
- function getRuntimeConfig(config) {
22
- var _config$runtime;
23
-
24
- if (config !== null && config !== void 0 && (_config$runtime = config.runtime) !== null && _config$runtime !== void 0 && _config$runtime.feature) {
25
- var _config$runtime2;
26
-
27
- return config === null || config === void 0 ? void 0 : (_config$runtime2 = config.runtime) === null || _config$runtime2 === void 0 ? void 0 : _config$runtime2.feature;
28
- }
29
-
30
- return config === null || config === void 0 ? void 0 : config.runtime;
31
- }
32
-
33
- function setRuntimeConfig(config, key, value) {
34
- var _config$runtime3, _config$runtime4;
35
-
36
- if (config !== null && config !== void 0 && config.runtime && config !== null && config !== void 0 && config.runtime[key]) {
37
- config.runtime[key] = value;
38
- }
19
+ import { getRuntimeConfig, makeProvider, makeRenderFunction, setRuntimeConfig } from "./utils";
20
+ export var externals = {
21
+ 'react-dom': 'react-dom',
22
+ react: 'react'
23
+ };
24
+ export var resolvedConfig = /*#__PURE__*/function () {
25
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(config) {
26
+ var resolved, _getRuntimeConfig, masterApp, router, nConfig, _router$historyOption;
27
+
28
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
29
+ while (1) {
30
+ switch (_context.prev = _context.next) {
31
+ case 0:
32
+ resolved = config.resolved;
33
+ _getRuntimeConfig = getRuntimeConfig(resolved), masterApp = _getRuntimeConfig.masterApp, router = _getRuntimeConfig.router;
34
+ nConfig = {
35
+ resolved: _objectSpread({}, resolved)
36
+ };
37
+
38
+ if (masterApp) {
39
+ // basename does not exist use router's basename
40
+ setRuntimeConfig(nConfig.resolved, 'masterApp', Object.assign(_typeof(masterApp) === 'object' ? _objectSpread({}, masterApp) : {}, {
41
+ basename: (router === null || router === void 0 ? void 0 : (_router$historyOption = router.historyOptions) === null || _router$historyOption === void 0 ? void 0 : _router$historyOption.basename) || '/'
42
+ }));
43
+ }
39
44
 
40
- if (config !== null && config !== void 0 && (_config$runtime3 = config.runtime) !== null && _config$runtime3 !== void 0 && _config$runtime3.feature && config !== null && config !== void 0 && (_config$runtime4 = config.runtime) !== null && _config$runtime4 !== void 0 && _config$runtime4.feature[key]) {
41
- config.runtime.feature[key] = value;
42
- }
43
- }
45
+ logger("resolvedConfig", {
46
+ runtime: nConfig.resolved.runtime,
47
+ deploy: nConfig.resolved.deploy,
48
+ server: nConfig.resolved.server
49
+ });
50
+ return _context.abrupt("return", nConfig);
44
51
 
45
- export var initializer = function initializer(_ref) {
46
- var validateSchema = _ref.validateSchema,
47
- externals = _ref.externals,
48
- componentKey = _ref.componentKey,
49
- otherLifeCycle = _objectWithoutProperties(_ref, _excluded);
52
+ case 6:
53
+ case "end":
54
+ return _context.stop();
55
+ }
56
+ }
57
+ }, _callee);
58
+ }));
50
59
 
60
+ return function resolvedConfig(_x) {
61
+ return _ref.apply(this, arguments);
62
+ };
63
+ }();
64
+ export var initializer = function initializer( // eslint-disable-next-line @typescript-eslint/no-shadow
65
+ _ref2, _ref3) {
66
+ var resolvedConfig = _ref2.resolvedConfig,
67
+ validateSchema = _ref2.validateSchema;
68
+ var _ref3$runtimePluginNa = _ref3.runtimePluginName,
69
+ runtimePluginName = _ref3$runtimePluginNa === void 0 ? '@modern-js/runtime/plugins' : _ref3$runtimePluginNa,
70
+ _ref3$defaultEnableHt = _ref3.defaultEnableHtmlEntry,
71
+ defaultEnableHtmlEntry = _ref3$defaultEnableHt === void 0 ? true : _ref3$defaultEnableHt,
72
+ _ref3$defaultExternal = _ref3.defaultExternalBasicLibrary,
73
+ defaultExternalBasicLibrary = _ref3$defaultExternal === void 0 ? false : _ref3$defaultExternal;
51
74
  return function () {
52
- var configMap = new Map();
53
75
  var pluginsExportsUtils;
54
76
  var runtimeExportsUtils;
55
- return _objectSpread({
56
- resolvedConfig: function resolvedConfig(config) {
57
- var resolved = config.resolved;
58
-
59
- var _getRuntimeConfig = getRuntimeConfig(resolved),
60
- masterApp = _getRuntimeConfig.masterApp,
61
- router = _getRuntimeConfig.router;
62
-
63
- var nConfig = {
64
- resolved: _objectSpread({}, resolved)
65
- };
66
-
67
- if (masterApp) {
68
- // basename does not exist use router's basename
69
- setRuntimeConfig(nConfig.resolved, 'masterApp', Object.assign(_typeof(masterApp) === 'object' ? _objectSpread({}, masterApp) : {}, {
70
- basename: (router === null || router === void 0 ? void 0 : router.basename) || '/'
71
- }));
72
- }
73
-
74
- logger("resolvedConfig", {
75
- runtime: nConfig.resolved.runtime,
76
- deploy: nConfig.resolved.deploy,
77
- server: nConfig.resolved.server
78
- });
79
- return nConfig;
80
- },
77
+ return {
78
+ validateSchema: validateSchema,
79
+ resolvedConfig: resolvedConfig,
81
80
  config: function config() {
82
81
  // eslint-disable-next-line react-hooks/rules-of-hooks
83
82
  var config = useAppContext();
@@ -90,34 +89,37 @@ export var initializer = function initializer(_ref) {
90
89
  }
91
90
  },
92
91
  tools: {
93
- webpack: function webpack(webpackConfig, _ref2) {
94
- var _resolvedConfig$deplo;
95
-
96
- var chain = _ref2.chain,
97
- _webpack = _ref2.webpack;
98
- var env = process.env.NODE_ENV; // eslint-disable-next-line react-hooks/rules-of-hooks
92
+ webpack: function webpack(webpackConfig, _ref4) {
93
+ var _resolveOptions$deplo, _resolveWebpackConfig;
99
94
 
100
- var resolvedConfig = useResolvedConfigContext();
95
+ var chain = _ref4.chain,
96
+ _webpack = _ref4.webpack,
97
+ _ref4$env = _ref4.env,
98
+ env = _ref4$env === void 0 ? process.env.NODE_ENV || 'development' : _ref4$env;
99
+ // eslint-disable-next-line react-hooks/rules-of-hooks
100
+ var resolveOptions = useResolvedConfigContext();
101
101
 
102
- if (resolvedConfig !== null && resolvedConfig !== void 0 && (_resolvedConfig$deplo = resolvedConfig.deploy) !== null && _resolvedConfig$deplo !== void 0 && _resolvedConfig$deplo.microFrontend) {
103
- var _resolvedConfig$deplo2, _resolvedConfig$deplo3;
102
+ if (resolveOptions !== null && resolveOptions !== void 0 && (_resolveOptions$deplo = resolveOptions.deploy) !== null && _resolveOptions$deplo !== void 0 && _resolveOptions$deplo.microFrontend) {
103
+ var _resolveOptions$serve, _resolveOptions$deplo2, _resolveOptions$deplo3;
104
104
 
105
105
  chain.output.libraryTarget('umd');
106
106
 
107
- if (resolvedConfig.server.port) {
108
- chain.output.publicPath(env === 'development' ? "//localhost:".concat(resolvedConfig.server.port, "/") : webpackConfig.output.publicPath);
107
+ if (resolveOptions !== null && resolveOptions !== void 0 && (_resolveOptions$serve = resolveOptions.server) !== null && _resolveOptions$serve !== void 0 && _resolveOptions$serve.port) {
108
+ chain.output.publicPath(env === 'development' ? "//localhost:".concat(resolveOptions.server.port, "/") : webpackConfig.output.publicPath);
109
109
  } // add comments avoid sourcemap abnormal
110
110
 
111
111
 
112
- chain.plugin('banner').use(_webpack.BannerPlugin, [{
113
- banner: 'Micro front-end'
114
- }]);
112
+ if (_webpack.BannerPlugin) {
113
+ chain.plugin('banner').use(_webpack.BannerPlugin, [{
114
+ banner: 'Micro front-end'
115
+ }]);
116
+ }
115
117
 
116
- var _ref3 = _typeof(resolvedConfig === null || resolvedConfig === void 0 ? void 0 : (_resolvedConfig$deplo2 = resolvedConfig.deploy) === null || _resolvedConfig$deplo2 === void 0 ? void 0 : _resolvedConfig$deplo2.microFrontend) === 'object' ? resolvedConfig === null || resolvedConfig === void 0 ? void 0 : (_resolvedConfig$deplo3 = resolvedConfig.deploy) === null || _resolvedConfig$deplo3 === void 0 ? void 0 : _resolvedConfig$deplo3.microFrontend : {},
117
- _ref3$enableHtmlEntry = _ref3.enableHtmlEntry,
118
- enableHtmlEntry = _ref3$enableHtmlEntry === void 0 ? true : _ref3$enableHtmlEntry,
119
- _ref3$externalBasicLi = _ref3.externalBasicLibrary,
120
- externalBasicLibrary = _ref3$externalBasicLi === void 0 ? true : _ref3$externalBasicLi; // external
118
+ var _ref5 = _typeof(resolveOptions === null || resolveOptions === void 0 ? void 0 : (_resolveOptions$deplo2 = resolveOptions.deploy) === null || _resolveOptions$deplo2 === void 0 ? void 0 : _resolveOptions$deplo2.microFrontend) === 'object' ? resolveOptions === null || resolveOptions === void 0 ? void 0 : (_resolveOptions$deplo3 = resolveOptions.deploy) === null || _resolveOptions$deplo3 === void 0 ? void 0 : _resolveOptions$deplo3.microFrontend : {},
119
+ _ref5$enableHtmlEntry = _ref5.enableHtmlEntry,
120
+ enableHtmlEntry = _ref5$enableHtmlEntry === void 0 ? defaultEnableHtmlEntry : _ref5$enableHtmlEntry,
121
+ _ref5$externalBasicLi = _ref5.externalBasicLibrary,
122
+ externalBasicLibrary = _ref5$externalBasicLi === void 0 ? defaultExternalBasicLibrary : _ref5$externalBasicLi; // external
121
123
 
122
124
 
123
125
  if (externalBasicLibrary) {
@@ -139,7 +141,8 @@ export var initializer = function initializer(_ref) {
139
141
  logger('webpackConfig', {
140
142
  output: resolveWebpackConfig.output,
141
143
  externals: resolveWebpackConfig.externals,
142
- env: env
144
+ env: env,
145
+ alias: (_resolveWebpackConfig = resolveWebpackConfig.resolve) === null || _resolveWebpackConfig === void 0 ? void 0 : _resolveWebpackConfig.alias
143
146
  });
144
147
  }
145
148
  }
@@ -147,35 +150,33 @@ export var initializer = function initializer(_ref) {
147
150
  },
148
151
  addRuntimeExports: function addRuntimeExports() {
149
152
  var mfPackage = path.resolve(__dirname, '../../../../');
150
- var addExportStatement = "export { default as garfish } from '".concat(mfPackage, "'");
153
+ var addExportStatement = "export { default as garfish, default as masterApp } from '".concat(mfPackage, "'");
151
154
  logger('exportStatement', addExportStatement);
152
155
  pluginsExportsUtils.addExport(addExportStatement);
153
156
  runtimeExportsUtils.addExport("export * from '".concat(mfPackage, "'"));
154
157
  },
155
- validateSchema: validateSchema,
156
- modifyEntryImports: function modifyEntryImports(_ref4) {
157
- var entrypoint = _ref4.entrypoint,
158
- imports = _ref4.imports;
158
+ modifyEntryImports: function modifyEntryImports(_ref6) {
159
+ var entrypoint = _ref6.entrypoint,
160
+ imports = _ref6.imports;
159
161
  // eslint-disable-next-line react-hooks/rules-of-hooks
160
- var resolvedConfig = useResolvedConfigContext(); // support legacy config
161
-
162
- var _getRuntimeConfig2 = getRuntimeConfig(resolvedConfig),
163
- masterApp = _getRuntimeConfig2.masterApp; // eslint-disable-next-line react-hooks/rules-of-hooks
164
-
165
-
166
- var _useAppContext = useAppContext(),
167
- packageName = _useAppContext.packageName;
162
+ var config = useResolvedConfigContext();
168
163
 
169
- var masterAppConfig = getEntryOptions(entrypoint.entryName, masterApp, resolvedConfig.runtimeByEntries, packageName);
170
- configMap.set(entrypoint.entryName, masterAppConfig);
164
+ var _getRuntimeConfig2 = getRuntimeConfig(config),
165
+ masterApp = _getRuntimeConfig2.masterApp;
171
166
 
172
- if (masterAppConfig) {
167
+ if (masterApp) {
173
168
  imports.push({
174
- value: '@modern-js/runtime/plugins',
169
+ value: runtimePluginName,
175
170
  specifiers: [{
176
171
  imported: 'garfish'
177
172
  }]
178
173
  });
174
+ imports.push({
175
+ value: runtimePluginName,
176
+ specifiers: [{
177
+ imported: 'masterApp'
178
+ }]
179
+ });
179
180
  }
180
181
 
181
182
  imports.push({
@@ -191,17 +192,21 @@ export var initializer = function initializer(_ref) {
191
192
  entrypoint: entrypoint
192
193
  };
193
194
  },
194
- modifyEntryRuntimePlugins: function modifyEntryRuntimePlugins(_ref5) {
195
- var entrypoint = _ref5.entrypoint,
196
- plugins = _ref5.plugins;
197
- var masterAppConfig = configMap.get(entrypoint.entryName);
195
+ modifyEntryRuntimePlugins: function modifyEntryRuntimePlugins(_ref7) {
196
+ var entrypoint = _ref7.entrypoint,
197
+ plugins = _ref7.plugins;
198
+ // eslint-disable-next-line react-hooks/rules-of-hooks
199
+ var config = useResolvedConfigContext();
200
+
201
+ var _getRuntimeConfig3 = getRuntimeConfig(config),
202
+ masterApp = _getRuntimeConfig3.masterApp;
198
203
 
199
- if (masterAppConfig) {
200
- logger('garfishPlugin options', masterAppConfig);
204
+ if (masterApp) {
205
+ logger('garfishPlugin options', masterApp);
201
206
  plugins.push({
202
207
  name: 'garfish',
203
208
  args: 'masterApp',
204
- options: JSON.stringify(masterAppConfig)
209
+ options: masterApp === true ? JSON.stringify({}) : JSON.stringify(masterApp)
205
210
  });
206
211
  }
207
212
 
@@ -210,11 +215,11 @@ export var initializer = function initializer(_ref) {
210
215
  plugins: plugins
211
216
  };
212
217
  },
213
- modifyEntryRenderFunction: function modifyEntryRenderFunction(_ref6) {
218
+ modifyEntryRenderFunction: function modifyEntryRenderFunction(_ref8) {
214
219
  var _config$deploy;
215
220
 
216
- var entrypoint = _ref6.entrypoint,
217
- code = _ref6.code;
221
+ var entrypoint = _ref8.entrypoint,
222
+ code = _ref8.code;
218
223
  // eslint-disable-next-line react-hooks/rules-of-hooks
219
224
  var config = useResolvedConfigContext();
220
225
 
@@ -232,16 +237,16 @@ export var initializer = function initializer(_ref) {
232
237
  code: nCode
233
238
  };
234
239
  },
235
- modifyEntryExport: function modifyEntryExport(_ref7) {
236
- var _resolvedConfig$deplo4;
240
+ modifyEntryExport: function modifyEntryExport(_ref9) {
241
+ var _config$deploy2;
237
242
 
238
- var entrypoint = _ref7.entrypoint,
239
- exportStatement = _ref7.exportStatement;
243
+ var entrypoint = _ref9.entrypoint,
244
+ exportStatement = _ref9.exportStatement;
240
245
  // eslint-disable-next-line react-hooks/rules-of-hooks
241
- var resolvedConfig = useResolvedConfigContext();
246
+ var config = useResolvedConfigContext();
242
247
 
243
- if (resolvedConfig !== null && resolvedConfig !== void 0 && (_resolvedConfig$deplo4 = resolvedConfig.deploy) !== null && _resolvedConfig$deplo4 !== void 0 && _resolvedConfig$deplo4.microFrontend) {
244
- var exportStatementCode = makeProvider(componentKey);
248
+ if (config !== null && config !== void 0 && (_config$deploy2 = config.deploy) !== null && _config$deploy2 !== void 0 && _config$deploy2.microFrontend) {
249
+ var exportStatementCode = makeProvider();
245
250
  logger('exportStatement', exportStatementCode);
246
251
  return {
247
252
  entrypoint: entrypoint,
@@ -254,18 +259,16 @@ export var initializer = function initializer(_ref) {
254
259
  exportStatement: exportStatement
255
260
  };
256
261
  }
257
- }, otherLifeCycle);
262
+ };
258
263
  };
259
264
  };
260
265
  export default createPlugin(initializer({
266
+ resolvedConfig: resolvedConfig,
261
267
  validateSchema: function validateSchema() {
262
268
  return PLUGIN_SCHEMAS['@modern-js/plugin-garfish'];
263
- },
264
- externals: {
265
- 'react-dom': 'react-dom',
266
- react: 'react'
267
- },
268
- componentKey: 'dynamicComponent'
269
+ }
270
+ }, {
271
+ runtimePluginName: '@modern-js/runtime/plugins'
269
272
  }), {
270
273
  name: '@modern-js/plugin-garfish'
271
274
  });
@@ -1,6 +1,35 @@
1
- export var makeProvider = function makeProvider(componentKey) {
2
- return "\n export const provider = function ({basename, dom, ...props}) {\n return {\n render({basename, dom}) {\n const SubApp = render(props, basename);\n const node = dom.querySelector('#' + MOUNT_ID) || dom;\n\n bootstrap(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 ".concat(componentKey, ": () => {\n const SubApp = render(props, basename);\n\n return createPortal(<SubApp />, dom.querySelector('#' + MOUNT_ID) || dom);\n }\n }\n };\n if (typeof __GARFISH_EXPORTS__ !== 'undefined') {\n __GARFISH_EXPORTS__.provider = provider;\n }\n");
1
+ export var makeProvider = function makeProvider() {
2
+ return "\nexport const provider = function ({basename, dom, ...props}) {\n return {\n render({basename, dom}) {\n console.log('App.config', App.config);\n const SubApp = render({props, basename});\n const node = dom.querySelector('#' + MOUNT_ID) || dom;\n bootstrap(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";
3
3
  };
4
4
  export var makeRenderFunction = function makeRenderFunction(code) {
5
- return code.replace('IS_BROWSER', "\n IS_BROWSER &&\n typeof __GARFISH_EXPORTS__ === 'undefined'\n ").replace('(App)', '(() => <App {...(arguments[0] || {})} />)').replace('"basename":"/"', '"basename":arguments[1] || "/"');
6
- };
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 ";
6
+ return inGarfishToRender + code.replace("router(", "RouterPlugin(").replace('IS_BROWSER', "IS_BROWSER && !renderByGarfish");
7
+ }; // support legacy config
8
+
9
+ export function getRuntimeConfig(config) {
10
+ var _config$runtime;
11
+
12
+ if (config !== null && config !== void 0 && (_config$runtime = config.runtime) !== null && _config$runtime !== void 0 && _config$runtime.features) {
13
+ var _config$runtime2;
14
+
15
+ return config === null || config === void 0 ? void 0 : (_config$runtime2 = config.runtime) === null || _config$runtime2 === void 0 ? void 0 : _config$runtime2.features;
16
+ }
17
+
18
+ return config === null || config === void 0 ? void 0 : config.runtime;
19
+ } // support legacy config
20
+
21
+ export function setRuntimeConfig(config, key, value) {
22
+ var _config$runtime3, _config$runtime4;
23
+
24
+ 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
+ config.runtime.features[key] = value;
26
+ return undefined;
27
+ }
28
+
29
+ if (config !== null && config !== void 0 && config.runtime && config !== null && config !== void 0 && config.runtime[key]) {
30
+ config.runtime[key] = value;
31
+ return undefined;
32
+ }
33
+
34
+ return undefined;
35
+ }
@@ -1 +1,2 @@
1
- export { default } from "./cli";
1
+ export { default } from "./runtime";
2
+ export * from "./runtime";
@@ -1,2 +1,3 @@
1
1
  export { default } from "./plugin";
2
- export * from "./useModuleApps";
2
+ export { useModuleApps, useMicroApps, useModuleApp } from "./useModuleApps";
3
+ export { default as Garfish } from 'garfish';
@@ -1,11 +1,17 @@
1
1
  function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
2
 
3
+ var _excluded = ["loadable"];
4
+
3
5
  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; }
4
6
 
5
7
  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; }
6
8
 
7
9
  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; }
8
10
 
11
+ 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; }
12
+
13
+ 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; }
14
+
9
15
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
10
16
 
11
17
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
@@ -33,7 +39,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
33
39
  import { Fragment as _Fragment } from "react/jsx-runtime";
34
40
  import { jsxs as _jsxs } from "react/jsx-runtime";
35
41
  export function Loadable(WrapComponent) {
36
- return function (defaultLoadingComponent) {
42
+ return function (defaultLoadable) {
37
43
  return /*#__PURE__*/function (_React$Component) {
38
44
  _inherits(LoadableComponent, _React$Component);
39
45
 
@@ -50,9 +56,6 @@ export function Loadable(WrapComponent) {
50
56
 
51
57
  _this = _super.call.apply(_super, [this].concat(args));
52
58
  _this.state = {
53
- LoadingComponent: defaultLoadingComponent,
54
- timeout: 10000,
55
- delay: 200,
56
59
  error: null,
57
60
  pastDelay: false,
58
61
  timedOut: false,
@@ -82,17 +85,14 @@ export function Loadable(WrapComponent) {
82
85
  var _this2 = this;
83
86
 
84
87
  this.mounted = true;
85
- var loadingConfig = this.props.loadingConfig;
86
-
87
- if (loadingConfig !== null && loadingConfig !== void 0 && loadingConfig.LoadingComponent) {
88
- this.setStateWithMountCheck({
89
- LoadingComponent: loadingConfig.LoadingComponent
90
- });
91
- }
92
-
93
- var _this$state = this.state,
94
- delay = _this$state.delay,
95
- timeout = _this$state.timeout;
88
+ var _this$props$loadable = this.props.loadable,
89
+ loadable = _this$props$loadable === void 0 ? defaultLoadable || {
90
+ delay: 200,
91
+ timeout: 10000,
92
+ loading: null
93
+ } : _this$props$loadable;
94
+ var delay = loadable.delay,
95
+ timeout = loadable.timeout;
96
96
 
97
97
  if (typeof delay === 'number') {
98
98
  if (delay === 0) {
@@ -133,7 +133,6 @@ export function Loadable(WrapComponent) {
133
133
  return;
134
134
  }
135
135
 
136
- logger('Loadable state', this.state);
137
136
  this.setState(newState);
138
137
  }
139
138
  }, {
@@ -147,16 +146,31 @@ export function Loadable(WrapComponent) {
147
146
  value: function render() {
148
147
  var _this3 = this;
149
148
 
150
- // eslint-disable-next-line @typescript-eslint/no-shadow
151
- var _this$state2 = this.state,
152
- isLoading = _this$state2.isLoading,
153
- error = _this$state2.error,
154
- pastDelay = _this$state2.pastDelay,
155
- timedOut = _this$state2.timedOut,
156
- LoadingComponent = _this$state2.LoadingComponent;
149
+ var _this$state = this.state,
150
+ isLoading = _this$state.isLoading,
151
+ error = _this$state.error,
152
+ pastDelay = _this$state.pastDelay,
153
+ timedOut = _this$state.timedOut;
154
+
155
+ var _this$props = this.props,
156
+ _this$props$loadable2 = _this$props.loadable,
157
+ loadable = _this$props$loadable2 === void 0 ? defaultLoadable || {
158
+ delay: 200,
159
+ timeout: 10000,
160
+ loading: null
161
+ } : _this$props$loadable2,
162
+ otherProps = _objectWithoutProperties(_this$props, _excluded);
163
+
164
+ var LoadingComponent = loadable.loading;
165
+ logger('Loadable render state', {
166
+ state: this.state,
167
+ props: otherProps,
168
+ loadable: loadable,
169
+ defaultLoadable: defaultLoadable
170
+ });
157
171
  var showLoading = (isLoading || error) && LoadingComponent;
158
172
  return /*#__PURE__*/_jsxs(_Fragment, {
159
- children: [showLoading && LoadingComponent && /*#__PURE__*/_jsx(LoadingComponent, {
173
+ children: [showLoading && /*#__PURE__*/_jsx(LoadingComponent, {
160
174
  isLoading: isLoading,
161
175
  pastDelay: pastDelay,
162
176
  timedOut: timedOut,
@@ -169,7 +183,7 @@ export function Loadable(WrapComponent) {
169
183
  setLoadingState: function setLoadingState(props) {
170
184
  return _this3.setStateWithMountCheck(props);
171
185
  }
172
- }, this.props))]
186
+ }, otherProps))]
173
187
  });
174
188
  }
175
189
  }]);