@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
@@ -3,28 +3,41 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- var _exportNames = {};
6
+ Object.defineProperty(exports, "Garfish", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _garfish.default;
10
+ }
11
+ });
7
12
  Object.defineProperty(exports, "default", {
8
13
  enumerable: true,
9
14
  get: function () {
10
15
  return _plugin.default;
11
16
  }
12
17
  });
18
+ Object.defineProperty(exports, "useMicroApps", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _useModuleApps.useMicroApps;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "useModuleApp", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _useModuleApps.useModuleApp;
28
+ }
29
+ });
30
+ Object.defineProperty(exports, "useModuleApps", {
31
+ enumerable: true,
32
+ get: function () {
33
+ return _useModuleApps.useModuleApps;
34
+ }
35
+ });
13
36
 
14
37
  var _plugin = _interopRequireDefault(require("./plugin"));
15
38
 
16
39
  var _useModuleApps = require("./useModuleApps");
17
40
 
18
- Object.keys(_useModuleApps).forEach(function (key) {
19
- if (key === "default" || key === "__esModule") return;
20
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
21
- if (key in exports && exports[key] === _useModuleApps[key]) return;
22
- Object.defineProperty(exports, key, {
23
- enumerable: true,
24
- get: function () {
25
- return _useModuleApps[key];
26
- }
27
- });
28
- });
41
+ var _garfish = _interopRequireDefault(require("garfish"));
29
42
 
30
43
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -11,6 +11,8 @@ var _util = require("../util");
11
11
 
12
12
  var _jsxRuntime = require("react/jsx-runtime");
13
13
 
14
+ const _excluded = ["loadable"];
15
+
14
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
17
 
16
18
  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; }
@@ -19,15 +21,16 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
19
21
 
20
22
  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; }
21
23
 
24
+ 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; }
25
+
26
+ 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; }
27
+
22
28
  function Loadable(WrapComponent) {
23
- return function (defaultLoadingComponent) {
29
+ return function (defaultLoadable) {
24
30
  return class LoadableComponent extends _react.default.Component {
25
31
  constructor(...args) {
26
32
  super(...args);
27
33
  this.state = {
28
- LoadingComponent: defaultLoadingComponent,
29
- timeout: 10000,
30
- delay: 200,
31
34
  error: null,
32
35
  pastDelay: false,
33
36
  timedOut: false,
@@ -51,19 +54,16 @@ function Loadable(WrapComponent) {
51
54
  UNSAFE_componentWillMount() {
52
55
  this.mounted = true;
53
56
  const {
54
- loadingConfig
57
+ loadable = defaultLoadable || {
58
+ delay: 200,
59
+ timeout: 10000,
60
+ loading: null
61
+ }
55
62
  } = this.props;
56
-
57
- if (loadingConfig !== null && loadingConfig !== void 0 && loadingConfig.LoadingComponent) {
58
- this.setStateWithMountCheck({
59
- LoadingComponent: loadingConfig.LoadingComponent
60
- });
61
- }
62
-
63
63
  const {
64
64
  delay,
65
65
  timeout
66
- } = this.state;
66
+ } = loadable;
67
67
 
68
68
  if (typeof delay === 'number') {
69
69
  if (delay === 0) {
@@ -102,7 +102,6 @@ function Loadable(WrapComponent) {
102
102
  return;
103
103
  }
104
104
 
105
- (0, _util.logger)('Loadable state', this.state);
106
105
  this.setState(newState);
107
106
  }
108
107
 
@@ -112,17 +111,35 @@ function Loadable(WrapComponent) {
112
111
  }
113
112
 
114
113
  render() {
115
- // eslint-disable-next-line @typescript-eslint/no-shadow
116
114
  const {
117
115
  isLoading,
118
116
  error,
119
117
  pastDelay,
120
- timedOut,
121
- LoadingComponent
118
+ timedOut
122
119
  } = this.state;
120
+
121
+ const _this$props = this.props,
122
+ {
123
+ loadable = defaultLoadable || {
124
+ delay: 200,
125
+ timeout: 10000,
126
+ loading: null
127
+ }
128
+ } = _this$props,
129
+ otherProps = _objectWithoutProperties(_this$props, _excluded);
130
+
131
+ const {
132
+ loading: LoadingComponent
133
+ } = loadable;
134
+ (0, _util.logger)('Loadable render state', {
135
+ state: this.state,
136
+ props: otherProps,
137
+ loadable,
138
+ defaultLoadable
139
+ });
123
140
  const showLoading = (isLoading || error) && LoadingComponent;
124
141
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
125
- children: [showLoading && LoadingComponent && /*#__PURE__*/(0, _jsxRuntime.jsx)(LoadingComponent, {
142
+ children: [showLoading && /*#__PURE__*/(0, _jsxRuntime.jsx)(LoadingComponent, {
126
143
  isLoading: isLoading,
127
144
  pastDelay: pastDelay,
128
145
  timedOut: timedOut,
@@ -133,7 +150,7 @@ function Loadable(WrapComponent) {
133
150
  display: showLoading ? 'none' : 'block'
134
151
  },
135
152
  setLoadingState: props => this.setStateWithMountCheck(props)
136
- }, this.props))]
153
+ }, otherProps))]
137
154
  });
138
155
  }
139
156
 
@@ -23,7 +23,7 @@ var _apps = require("./utils/apps");
23
23
 
24
24
  var _jsxRuntime = require("react/jsx-runtime");
25
25
 
26
- const _excluded = ["manifest", "LoadingComponent"];
26
+ const _excluded = ["manifest"];
27
27
 
28
28
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
29
29
 
@@ -38,51 +38,53 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
38
38
  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; }
39
39
 
40
40
  async function initOptions(manifest = {}, options) {
41
- var _window, _window$modern_manife;
41
+ var _window, _window$modern_manife, _window2, _window2$modern_manif;
42
42
 
43
- let apps = []; // use manifest modules
43
+ let apps = options.apps || []; // use manifest modules
44
44
 
45
45
  if (manifest !== null && manifest !== void 0 && manifest.modules) {
46
- apps = manifest === null || manifest === void 0 ? void 0 : manifest.modules;
46
+ if ((manifest === null || manifest === void 0 ? void 0 : manifest.modules.length) > 0) {
47
+ apps = manifest === null || manifest === void 0 ? void 0 : manifest.modules;
48
+ }
49
+
47
50
  (0, _util.logger)('manifest modules', apps);
48
51
  } // get module list
49
52
 
50
53
 
51
54
  if (manifest !== null && manifest !== void 0 && manifest.getAppList) {
52
- apps = await (manifest === null || manifest === void 0 ? void 0 : manifest.getAppList());
55
+ const getAppList = await (manifest === null || manifest === void 0 ? void 0 : manifest.getAppList());
56
+
57
+ if (getAppList.length > 0) {
58
+ apps = getAppList;
59
+ }
60
+
53
61
  (0, _util.logger)('getAppList modules', apps);
54
62
  } // get inject modules list
55
63
 
56
64
 
57
- if ((_window = window) !== null && _window !== void 0 && (_window$modern_manife = _window.modern_manifest) !== null && _window$modern_manife !== void 0 && _window$modern_manife.modules) {
58
- var _window2, _window2$modern_manif;
65
+ 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) {
66
+ var _window3, _window3$modern_manif;
59
67
 
60
- apps = (_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;
68
+ 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;
61
69
  (0, _util.logger)('modern_manifest', apps);
62
70
  }
63
71
 
64
- return _objectSpread({
72
+ return _objectSpread(_objectSpread({}, options), {}, {
65
73
  apps
66
- }, options);
74
+ });
67
75
  }
68
76
 
69
- var _default = config => {
77
+ const GarfishPlugin = config => {
70
78
  (0, _setExternal.default)();
71
79
 
72
80
  const {
73
- manifest = {},
74
- LoadingComponent
81
+ manifest
75
82
  } = config,
76
83
  options = _objectWithoutProperties(config, _excluded);
77
84
 
78
85
  (0, _util.logger)('createPlugin', {
79
86
  config
80
87
  });
81
-
82
- if (!manifest.LoadingComponent && LoadingComponent) {
83
- manifest.LoadingComponent = LoadingComponent;
84
- }
85
-
86
88
  const promise = initOptions(manifest, options);
87
89
  return (0, _runtimeCore.createPlugin)(() => ({
88
90
  hoc({
@@ -150,4 +152,5 @@ var _default = config => {
150
152
  }));
151
153
  };
152
154
 
155
+ var _default = GarfishPlugin;
153
156
  exports.default = _default;
@@ -29,9 +29,7 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
29
29
 
30
30
  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; }
31
31
 
32
- function generateMApp(options, {
33
- LoadingComponent
34
- }) {
32
+ function generateMApp(options, manifest) {
35
33
  class MApp extends _react.default.Component {
36
34
  constructor(...args) {
37
35
  super(...args);
@@ -66,7 +64,7 @@ function generateMApp(options, {
66
64
  domGetter: `#${domId}`,
67
65
 
68
66
  beforeLoad(...args) {
69
- // logger('MApp beforeLoad', args);
67
+ (0, _util.logger)('MApp beforeLoad', args);
70
68
  setLoadingState({
71
69
  isLoading: true,
72
70
  error: null
@@ -75,7 +73,7 @@ function generateMApp(options, {
75
73
  },
76
74
 
77
75
  beforeMount(...args) {
78
- // logger('MApp beforeMount', args);
76
+ (0, _util.logger)('MApp beforeMount', args);
79
77
  setLoadingState({
80
78
  isLoading: false
81
79
  });
@@ -83,7 +81,7 @@ function generateMApp(options, {
83
81
  },
84
82
 
85
83
  errorLoadApp(error, ...args) {
86
- // logger('MApp errorLoadApp', args);
84
+ (0, _util.logger)('MApp errorLoadApp', error, args);
87
85
  setLoadingState({
88
86
  error
89
87
  });
@@ -91,7 +89,7 @@ function generateMApp(options, {
91
89
  },
92
90
 
93
91
  errorMountApp(error, ...args) {
94
- // logger('MApp errorMountApp', args);
92
+ (0, _util.logger)('MApp errorMountApp', error, args);
95
93
  setLoadingState({
96
94
  error
97
95
  });
@@ -99,7 +97,7 @@ function generateMApp(options, {
99
97
  },
100
98
 
101
99
  errorUnmountApp(error, ...args) {
102
- // logger('MApp errorUnmountApp', args);
100
+ (0, _util.logger)('MApp errorUnmountApp', error, args);
103
101
  setLoadingState({
104
102
  error
105
103
  });
@@ -128,7 +126,6 @@ function generateMApp(options, {
128
126
  }
129
127
 
130
128
  render() {
131
- (0, _util.logger)('MApp render status', this.state);
132
129
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
133
130
  id: (0, _util.generateSubAppContainerKey)()
134
131
  });
@@ -136,5 +133,5 @@ function generateMApp(options, {
136
133
 
137
134
  }
138
135
 
139
- return (0, _loadable.Loadable)(MApp)(LoadingComponent);
136
+ return (0, _loadable.Loadable)(MApp)(manifest === null || manifest === void 0 ? void 0 : manifest.loadable);
140
137
  }
@@ -33,10 +33,7 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
33
33
 
34
34
  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; }
35
35
 
36
- function getAppInstance(appInfo, manifest) {
37
- const {
38
- LoadingComponent
39
- } = manifest;
36
+ function getAppInstance(options, appInfo, manifest) {
40
37
  let locationHref = '';
41
38
 
42
39
  class MicroApp extends _react.default.Component {
@@ -61,9 +58,6 @@ function getAppInstance(appInfo, manifest) {
61
58
  const {
62
59
  domId
63
60
  } = this.state;
64
- const {
65
- options
66
- } = _garfish.default;
67
61
 
68
62
  const loadAppOptions = _objectSpread(_objectSpread({}, appInfo), {}, {
69
63
  domGetter: `#${domId}`,
@@ -176,7 +170,7 @@ function getAppInstance(appInfo, manifest) {
176
170
 
177
171
  }
178
172
 
179
- return (0, _loadable.Loadable)((0, _pluginRouter.withRouter)(MicroApp))(LoadingComponent);
173
+ return (0, _loadable.Loadable)((0, _pluginRouter.withRouter)(MicroApp))(manifest === null || manifest === void 0 ? void 0 : manifest.loadable);
180
174
  }
181
175
 
182
176
  function generateApps(options, manifest) {
@@ -184,7 +178,7 @@ function generateApps(options, manifest) {
184
178
 
185
179
  const apps = {};
186
180
  (_options$apps = options.apps) === null || _options$apps === void 0 ? void 0 : _options$apps.forEach(appInfo => {
187
- const Component = getAppInstance(appInfo, manifest);
181
+ const Component = getAppInstance(options, appInfo, manifest);
188
182
  appInfo.Component = Component;
189
183
  apps[appInfo.name] = Component;
190
184
  });