@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,9 +1,15 @@
1
+ const _excluded = ["loadable"];
2
+
1
3
  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; }
2
4
 
3
5
  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; }
4
6
 
5
7
  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; }
6
8
 
9
+ 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; }
10
+
11
+ 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; }
12
+
7
13
  // logical reference to https://github.com/jamiebuilds/react-loadable/blob/6201c5837b212d6244c57f3748f2b1375096beeb/src/index.js
8
14
  import React from 'react';
9
15
  import { logger } from "../util";
@@ -11,14 +17,11 @@ import { jsx as _jsx } from "react/jsx-runtime";
11
17
  import { Fragment as _Fragment } from "react/jsx-runtime";
12
18
  import { jsxs as _jsxs } from "react/jsx-runtime";
13
19
  export function Loadable(WrapComponent) {
14
- return function (defaultLoadingComponent) {
20
+ return function (defaultLoadable) {
15
21
  return class LoadableComponent extends React.Component {
16
22
  constructor(...args) {
17
23
  super(...args);
18
24
  this.state = {
19
- LoadingComponent: defaultLoadingComponent,
20
- timeout: 10000,
21
- delay: 200,
22
25
  error: null,
23
26
  pastDelay: false,
24
27
  timedOut: false,
@@ -42,19 +45,16 @@ export function Loadable(WrapComponent) {
42
45
  UNSAFE_componentWillMount() {
43
46
  this.mounted = true;
44
47
  const {
45
- loadingConfig
48
+ loadable = defaultLoadable || {
49
+ delay: 200,
50
+ timeout: 10000,
51
+ loading: null
52
+ }
46
53
  } = this.props;
47
-
48
- if (loadingConfig !== null && loadingConfig !== void 0 && loadingConfig.LoadingComponent) {
49
- this.setStateWithMountCheck({
50
- LoadingComponent: loadingConfig.LoadingComponent
51
- });
52
- }
53
-
54
54
  const {
55
55
  delay,
56
56
  timeout
57
- } = this.state;
57
+ } = loadable;
58
58
 
59
59
  if (typeof delay === 'number') {
60
60
  if (delay === 0) {
@@ -93,7 +93,6 @@ export function Loadable(WrapComponent) {
93
93
  return;
94
94
  }
95
95
 
96
- logger('Loadable state', this.state);
97
96
  this.setState(newState);
98
97
  }
99
98
 
@@ -103,17 +102,35 @@ export function Loadable(WrapComponent) {
103
102
  }
104
103
 
105
104
  render() {
106
- // eslint-disable-next-line @typescript-eslint/no-shadow
107
105
  const {
108
106
  isLoading,
109
107
  error,
110
108
  pastDelay,
111
- timedOut,
112
- LoadingComponent
109
+ timedOut
113
110
  } = this.state;
111
+
112
+ const _this$props = this.props,
113
+ {
114
+ loadable = defaultLoadable || {
115
+ delay: 200,
116
+ timeout: 10000,
117
+ loading: null
118
+ }
119
+ } = _this$props,
120
+ otherProps = _objectWithoutProperties(_this$props, _excluded);
121
+
122
+ const {
123
+ loading: LoadingComponent
124
+ } = loadable;
125
+ logger('Loadable render state', {
126
+ state: this.state,
127
+ props: otherProps,
128
+ loadable,
129
+ defaultLoadable
130
+ });
114
131
  const showLoading = (isLoading || error) && LoadingComponent;
115
132
  return /*#__PURE__*/_jsxs(_Fragment, {
116
- children: [showLoading && LoadingComponent && /*#__PURE__*/_jsx(LoadingComponent, {
133
+ children: [showLoading && /*#__PURE__*/_jsx(LoadingComponent, {
117
134
  isLoading: isLoading,
118
135
  pastDelay: pastDelay,
119
136
  timedOut: timedOut,
@@ -124,7 +141,7 @@ export function Loadable(WrapComponent) {
124
141
  display: showLoading ? 'none' : 'block'
125
142
  },
126
143
  setLoadingState: props => this.setStateWithMountCheck(props)
127
- }, this.props))]
144
+ }, otherProps))]
128
145
  });
129
146
  }
130
147
 
@@ -1,4 +1,4 @@
1
- const _excluded = ["manifest", "LoadingComponent"];
1
+ const _excluded = ["manifest"];
2
2
 
3
3
  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; }
4
4
 
@@ -10,6 +10,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
10
10
 
11
11
  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; }
12
12
 
13
+ // eslint-disable-next-line filenames/match-exported
13
14
  import { createPlugin } from '@modern-js/runtime-core';
14
15
  import React from 'react';
15
16
  import hoistNonReactStatics from 'hoist-non-react-statics';
@@ -21,51 +22,53 @@ import { generateApps } from "./utils/apps";
21
22
  import { jsx as _jsx } from "react/jsx-runtime";
22
23
 
23
24
  async function initOptions(manifest = {}, options) {
24
- var _window, _window$modern_manife;
25
+ var _window, _window$modern_manife, _window2, _window2$modern_manif;
25
26
 
26
- let apps = []; // use manifest modules
27
+ let apps = options.apps || []; // use manifest modules
27
28
 
28
29
  if (manifest !== null && manifest !== void 0 && manifest.modules) {
29
- apps = manifest === null || manifest === void 0 ? void 0 : manifest.modules;
30
+ if ((manifest === null || manifest === void 0 ? void 0 : manifest.modules.length) > 0) {
31
+ apps = manifest === null || manifest === void 0 ? void 0 : manifest.modules;
32
+ }
33
+
30
34
  logger('manifest modules', apps);
31
35
  } // get module list
32
36
 
33
37
 
34
38
  if (manifest !== null && manifest !== void 0 && manifest.getAppList) {
35
- apps = await (manifest === null || manifest === void 0 ? void 0 : manifest.getAppList());
39
+ const getAppList = await (manifest === null || manifest === void 0 ? void 0 : manifest.getAppList());
40
+
41
+ if (getAppList.length > 0) {
42
+ apps = getAppList;
43
+ }
44
+
36
45
  logger('getAppList modules', apps);
37
46
  } // get inject modules list
38
47
 
39
48
 
40
- if ((_window = window) !== null && _window !== void 0 && (_window$modern_manife = _window.modern_manifest) !== null && _window$modern_manife !== void 0 && _window$modern_manife.modules) {
41
- var _window2, _window2$modern_manif;
49
+ 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) {
50
+ var _window3, _window3$modern_manif;
42
51
 
43
- 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;
52
+ 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;
44
53
  logger('modern_manifest', apps);
45
54
  }
46
55
 
47
- return _objectSpread({
56
+ return _objectSpread(_objectSpread({}, options), {}, {
48
57
  apps
49
- }, options);
58
+ });
50
59
  }
51
60
 
52
- export default (config => {
61
+ const GarfishPlugin = config => {
53
62
  setExternal();
54
63
 
55
64
  const {
56
- manifest = {},
57
- LoadingComponent
65
+ manifest
58
66
  } = config,
59
67
  options = _objectWithoutProperties(config, _excluded);
60
68
 
61
69
  logger('createPlugin', {
62
70
  config
63
71
  });
64
-
65
- if (!manifest.LoadingComponent && LoadingComponent) {
66
- manifest.LoadingComponent = LoadingComponent;
67
- }
68
-
69
72
  const promise = initOptions(manifest, options);
70
73
  return createPlugin(() => ({
71
74
  hoc({
@@ -131,4 +134,6 @@ export default (config => {
131
134
  }
132
135
 
133
136
  }));
134
- });
137
+ };
138
+
139
+ export default GarfishPlugin;
@@ -16,9 +16,7 @@ import Garfish from 'garfish';
16
16
  import { logger, generateSubAppContainerKey } from "../../util";
17
17
  import { Loadable } from "../loadable";
18
18
  import { jsx as _jsx } from "react/jsx-runtime";
19
- export function generateMApp(options, {
20
- LoadingComponent
21
- }) {
19
+ export function generateMApp(options, manifest) {
22
20
  class MApp extends React.Component {
23
21
  constructor(...args) {
24
22
  super(...args);
@@ -53,7 +51,7 @@ export function generateMApp(options, {
53
51
  domGetter: `#${domId}`,
54
52
 
55
53
  beforeLoad(...args) {
56
- // logger('MApp beforeLoad', args);
54
+ logger('MApp beforeLoad', args);
57
55
  setLoadingState({
58
56
  isLoading: true,
59
57
  error: null
@@ -62,7 +60,7 @@ export function generateMApp(options, {
62
60
  },
63
61
 
64
62
  beforeMount(...args) {
65
- // logger('MApp beforeMount', args);
63
+ logger('MApp beforeMount', args);
66
64
  setLoadingState({
67
65
  isLoading: false
68
66
  });
@@ -70,7 +68,7 @@ export function generateMApp(options, {
70
68
  },
71
69
 
72
70
  errorLoadApp(error, ...args) {
73
- // logger('MApp errorLoadApp', args);
71
+ logger('MApp errorLoadApp', error, args);
74
72
  setLoadingState({
75
73
  error
76
74
  });
@@ -78,7 +76,7 @@ export function generateMApp(options, {
78
76
  },
79
77
 
80
78
  errorMountApp(error, ...args) {
81
- // logger('MApp errorMountApp', args);
79
+ logger('MApp errorMountApp', error, args);
82
80
  setLoadingState({
83
81
  error
84
82
  });
@@ -86,7 +84,7 @@ export function generateMApp(options, {
86
84
  },
87
85
 
88
86
  errorUnmountApp(error, ...args) {
89
- // logger('MApp errorUnmountApp', args);
87
+ logger('MApp errorUnmountApp', error, args);
90
88
  setLoadingState({
91
89
  error
92
90
  });
@@ -114,7 +112,6 @@ export function generateMApp(options, {
114
112
  }
115
113
 
116
114
  render() {
117
- logger('MApp render status', this.state);
118
115
  return /*#__PURE__*/_jsx("div", {
119
116
  id: generateSubAppContainerKey()
120
117
  });
@@ -122,5 +119,5 @@ export function generateMApp(options, {
122
119
 
123
120
  }
124
121
 
125
- return Loadable(MApp)(LoadingComponent);
122
+ return Loadable(MApp)(manifest === null || manifest === void 0 ? void 0 : manifest.loadable);
126
123
  }
@@ -27,10 +27,7 @@ import { Loadable } from "../loadable"; // type Provider = {
27
27
  import { jsx as _jsx } from "react/jsx-runtime";
28
28
  import { Fragment as _Fragment } from "react/jsx-runtime";
29
29
 
30
- function getAppInstance(appInfo, manifest) {
31
- const {
32
- LoadingComponent
33
- } = manifest;
30
+ function getAppInstance(options, appInfo, manifest) {
34
31
  let locationHref = '';
35
32
 
36
33
  class MicroApp extends React.Component {
@@ -55,9 +52,6 @@ function getAppInstance(appInfo, manifest) {
55
52
  const {
56
53
  domId
57
54
  } = this.state;
58
- const {
59
- options
60
- } = Garfish;
61
55
 
62
56
  const loadAppOptions = _objectSpread(_objectSpread({}, appInfo), {}, {
63
57
  domGetter: `#${domId}`,
@@ -170,7 +164,7 @@ function getAppInstance(appInfo, manifest) {
170
164
 
171
165
  }
172
166
 
173
- return Loadable(withRouter(MicroApp))(LoadingComponent);
167
+ return Loadable(withRouter(MicroApp))(manifest === null || manifest === void 0 ? void 0 : manifest.loadable);
174
168
  }
175
169
 
176
170
  export function generateApps(options, manifest) {
@@ -178,7 +172,7 @@ export function generateApps(options, manifest) {
178
172
 
179
173
  const apps = {};
180
174
  (_options$apps = options.apps) === null || _options$apps === void 0 ? void 0 : _options$apps.forEach(appInfo => {
181
- const Component = getAppInstance(appInfo, manifest);
175
+ const Component = getAppInstance(options, appInfo, manifest);
182
176
  appInfo.Component = Component;
183
177
  apps[appInfo.name] = Component;
184
178
  });