@modern-js/plugin-garfish 1.3.0 → 1.3.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.
- package/.eslintrc.js +1 -1
- package/CHANGELOG.md +12 -0
- package/dist/js/modern/cli/index.js +190 -209
- package/dist/js/modern/cli/utils.js +1 -6
- package/dist/js/modern/index.js +2 -1
- package/dist/js/modern/runtime/index.js +2 -1
- package/dist/js/modern/runtime/loadable.js +36 -19
- package/dist/js/modern/runtime/plugin.js +14 -17
- package/dist/js/modern/runtime/utils/MApp.js +7 -10
- package/dist/js/modern/runtime/utils/apps.js +1 -4
- package/dist/js/node/cli/index.js +192 -213
- package/dist/js/node/cli/utils.js +1 -6
- package/dist/js/node/index.js +18 -3
- package/dist/js/node/runtime/index.js +25 -12
- package/dist/js/node/runtime/loadable.js +36 -19
- package/dist/js/node/runtime/plugin.js +11 -16
- package/dist/js/node/runtime/utils/MApp.js +7 -10
- package/dist/js/node/runtime/utils/apps.js +1 -4
- package/dist/js/treeshaking/cli/index.js +183 -199
- package/dist/js/treeshaking/cli/utils.js +2 -2
- package/dist/js/treeshaking/index.js +2 -1
- package/dist/js/treeshaking/runtime/index.js +2 -1
- package/dist/js/treeshaking/runtime/loadable.js +39 -25
- package/dist/js/treeshaking/runtime/plugin.js +15 -19
- package/dist/js/treeshaking/runtime/utils/MApp.js +23 -31
- package/dist/js/treeshaking/runtime/utils/apps.js +1 -2
- package/dist/types/cli/index.d.ts +1 -9
- package/dist/types/cli/utils.d.ts +1 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/runtime/index.d.ts +3 -1
- package/dist/types/runtime/loadable.d.ts +2 -8
- package/dist/types/runtime/plugin.d.ts +29 -3
- package/dist/types/runtime/useModuleApps.d.ts +7 -9
- package/dist/types/runtime/utils/MApp.d.ts +1 -15
- package/dist/types/runtime/utils/apps.d.ts +1 -1
- package/package.json +20 -8
- package/tests/cli.test.tsx +21 -43
- package/tests/hooks.test.tsx +1 -0
- package/tests/index.test.tsx +6 -3
- package/tsconfig.json +3 -2
- package/tests/__snapshots__/cli.test.tsx.snap +0 -71
package/dist/js/node/index.js
CHANGED
|
@@ -3,13 +3,28 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
var _exportNames = {};
|
|
6
7
|
Object.defineProperty(exports, "default", {
|
|
7
8
|
enumerable: true,
|
|
8
9
|
get: function () {
|
|
9
|
-
return
|
|
10
|
+
return _runtime.default;
|
|
10
11
|
}
|
|
11
12
|
});
|
|
12
13
|
|
|
13
|
-
var
|
|
14
|
+
var _runtime = _interopRequireWildcard(require("./runtime"));
|
|
14
15
|
|
|
15
|
-
function
|
|
16
|
+
Object.keys(_runtime).forEach(function (key) {
|
|
17
|
+
if (key === "default" || key === "__esModule") return;
|
|
18
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
19
|
+
if (key in exports && exports[key] === _runtime[key]) return;
|
|
20
|
+
Object.defineProperty(exports, key, {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function () {
|
|
23
|
+
return _runtime[key];
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
29
|
+
|
|
30
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
@@ -3,28 +3,41 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
|
|
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
|
-
|
|
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 (
|
|
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
|
-
|
|
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
|
-
} =
|
|
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 &&
|
|
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
|
-
},
|
|
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"
|
|
26
|
+
const _excluded = ["manifest"];
|
|
27
27
|
|
|
28
28
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
29
29
|
|
|
@@ -38,9 +38,9 @@ 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
46
|
apps = manifest === null || manifest === void 0 ? void 0 : manifest.modules;
|
|
@@ -54,35 +54,29 @@ async function initOptions(manifest = {}, options) {
|
|
|
54
54
|
} // get inject modules list
|
|
55
55
|
|
|
56
56
|
|
|
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
|
|
57
|
+
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) {
|
|
58
|
+
var _window3, _window3$modern_manif;
|
|
59
59
|
|
|
60
|
-
apps = (
|
|
60
|
+
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
61
|
(0, _util.logger)('modern_manifest', apps);
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
return _objectSpread({
|
|
64
|
+
return _objectSpread(_objectSpread({}, options), {}, {
|
|
65
65
|
apps
|
|
66
|
-
}
|
|
66
|
+
});
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
const GarfishPlugin = config => {
|
|
70
70
|
(0, _setExternal.default)();
|
|
71
71
|
|
|
72
72
|
const {
|
|
73
|
-
manifest
|
|
74
|
-
LoadingComponent
|
|
73
|
+
manifest
|
|
75
74
|
} = config,
|
|
76
75
|
options = _objectWithoutProperties(config, _excluded);
|
|
77
76
|
|
|
78
77
|
(0, _util.logger)('createPlugin', {
|
|
79
78
|
config
|
|
80
79
|
});
|
|
81
|
-
|
|
82
|
-
if (!manifest.LoadingComponent && LoadingComponent) {
|
|
83
|
-
manifest.LoadingComponent = LoadingComponent;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
80
|
const promise = initOptions(manifest, options);
|
|
87
81
|
return (0, _runtimeCore.createPlugin)(() => ({
|
|
88
82
|
hoc({
|
|
@@ -150,4 +144,5 @@ var _default = config => {
|
|
|
150
144
|
}));
|
|
151
145
|
};
|
|
152
146
|
|
|
147
|
+
var _default = GarfishPlugin;
|
|
153
148
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
84
|
+
(0, _util.logger)('MApp errorLoadApp', 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
|
-
|
|
92
|
+
(0, _util.logger)('MApp errorMountApp', 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
|
-
|
|
100
|
+
(0, _util.logger)('MApp errorUnmountApp', 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)(
|
|
136
|
+
return (0, _loadable.Loadable)(MApp)(manifest === null || manifest === void 0 ? void 0 : manifest.loadable);
|
|
140
137
|
}
|
|
@@ -34,9 +34,6 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
|
|
|
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
36
|
function getAppInstance(appInfo, manifest) {
|
|
37
|
-
const {
|
|
38
|
-
LoadingComponent
|
|
39
|
-
} = manifest;
|
|
40
37
|
let locationHref = '';
|
|
41
38
|
|
|
42
39
|
class MicroApp extends _react.default.Component {
|
|
@@ -176,7 +173,7 @@ function getAppInstance(appInfo, manifest) {
|
|
|
176
173
|
|
|
177
174
|
}
|
|
178
175
|
|
|
179
|
-
return (0, _loadable.Loadable)((0, _pluginRouter.withRouter)(MicroApp))(
|
|
176
|
+
return (0, _loadable.Loadable)((0, _pluginRouter.withRouter)(MicroApp))(manifest === null || manifest === void 0 ? void 0 : manifest.loadable);
|
|
180
177
|
}
|
|
181
178
|
|
|
182
179
|
function generateApps(options, manifest) {
|