@modern-js/plugin-garfish 1.4.3 → 1.4.4-beta.3
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/dist/js/modern/cli/index.js +4 -4
- package/dist/js/modern/cli/utils.js +1 -1
- package/dist/js/modern/runtime/plugin.js +78 -76
- package/dist/js/node/cli/index.js +4 -5
- package/dist/js/node/cli/utils.js +1 -1
- package/dist/js/node/runtime/plugin.js +78 -74
- package/dist/js/treeshaking/cli/index.js +5 -4
- package/dist/js/treeshaking/cli/utils.js +1 -1
- package/dist/js/treeshaking/runtime/plugin.js +111 -109
- package/dist/types/cli/index.d.ts +3 -1
- package/dist/types/runtime/plugin.d.ts +5 -28
- package/package.json +5 -2
- package/tests/__snapshots__/cli.test.tsx.snap +7 -0
- package/tests/cli.test.tsx +37 -3
|
@@ -13,7 +13,8 @@ export const externals = {
|
|
|
13
13
|
react: 'react'
|
|
14
14
|
};
|
|
15
15
|
export default (({
|
|
16
|
-
runtimePluginName: _runtimePluginName = '@modern-js/runtime/plugins'
|
|
16
|
+
runtimePluginName: _runtimePluginName = '@modern-js/runtime/plugins',
|
|
17
|
+
mfPackagePath: _mfPackagePath = path.resolve(__dirname, '../../../../')
|
|
17
18
|
} = {}) => ({
|
|
18
19
|
name: '@modern-js/plugin-garfish',
|
|
19
20
|
setup: ({
|
|
@@ -129,11 +130,10 @@ export default (({
|
|
|
129
130
|
},
|
|
130
131
|
|
|
131
132
|
addRuntimeExports() {
|
|
132
|
-
const
|
|
133
|
-
const addExportStatement = `export { default as garfish, default as masterApp } from '${mfPackage}'`;
|
|
133
|
+
const addExportStatement = `export { default as garfish, default as masterApp } from '${_mfPackagePath}'`;
|
|
134
134
|
logger('exportStatement', addExportStatement);
|
|
135
135
|
pluginsExportsUtils.addExport(addExportStatement);
|
|
136
|
-
runtimeExportsUtils.addExport(`export * from '${
|
|
136
|
+
runtimeExportsUtils.addExport(`export * from '${_mfPackagePath}'`);
|
|
137
137
|
},
|
|
138
138
|
|
|
139
139
|
modifyEntryImports({
|
|
@@ -72,7 +72,7 @@ export function getRuntimeConfig(config) {
|
|
|
72
72
|
return config === null || config === void 0 ? void 0 : (_config$runtime2 = config.runtime) === null || _config$runtime2 === void 0 ? void 0 : _config$runtime2.features;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
return config === null || config === void 0 ? void 0 : config.runtime;
|
|
75
|
+
return (config === null || config === void 0 ? void 0 : config.runtime) || {};
|
|
76
76
|
} // support legacy config
|
|
77
77
|
|
|
78
78
|
export function setRuntimeConfig(config, key, value) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _merge from "lodash/merge";
|
|
1
2
|
const _excluded = ["manifest"];
|
|
2
3
|
|
|
3
4
|
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,8 +11,6 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
10
11
|
|
|
11
12
|
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
13
|
|
|
13
|
-
// eslint-disable-next-line filenames/match-exported
|
|
14
|
-
import { createPlugin } from '@modern-js/runtime-core';
|
|
15
14
|
import React from 'react';
|
|
16
15
|
import hoistNonReactStatics from 'hoist-non-react-statics';
|
|
17
16
|
import { logger } from "../util";
|
|
@@ -56,83 +55,86 @@ async function initOptions(manifest = {}, options) {
|
|
|
56
55
|
return _objectSpread(_objectSpread({}, options), {}, {
|
|
57
56
|
apps
|
|
58
57
|
});
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
return
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
58
|
+
} // export default GarfishPlugin;
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
export default (defaultConfig => ({
|
|
62
|
+
name: '@modern-js/garfish-plugin',
|
|
63
|
+
setup: config => {
|
|
64
|
+
setExternal();
|
|
65
|
+
|
|
66
|
+
const _merge2 = _merge(defaultConfig, config),
|
|
67
|
+
{
|
|
68
|
+
manifest
|
|
69
|
+
} = _merge2,
|
|
70
|
+
options = _objectWithoutProperties(_merge2, _excluded);
|
|
71
|
+
|
|
72
|
+
logger('createPlugin', {
|
|
73
|
+
config
|
|
74
|
+
});
|
|
75
|
+
const promise = initOptions(manifest, options);
|
|
76
|
+
return {
|
|
77
|
+
hoc({
|
|
78
|
+
App
|
|
79
|
+
}, next) {
|
|
80
|
+
class GetMicroFrontendApp extends React.Component {
|
|
81
|
+
constructor(props) {
|
|
82
|
+
super(props);
|
|
83
|
+
this.state = {
|
|
84
|
+
MApp: () => {
|
|
85
|
+
logger('MApp init Component Render');
|
|
86
|
+
return /*#__PURE__*/React.createElement('div');
|
|
87
|
+
},
|
|
88
|
+
apps: new Proxy({}, {
|
|
89
|
+
get() {
|
|
90
|
+
return () => /*#__PURE__*/React.createElement('div');
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
}),
|
|
94
|
+
appInfoList: []
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const load = async () => {
|
|
98
|
+
const GarfishConfig = await promise;
|
|
99
|
+
logger('initOptions result', {
|
|
100
|
+
manifest,
|
|
101
|
+
GarfishConfig
|
|
102
|
+
});
|
|
103
|
+
const MApp = generateMApp(GarfishConfig, manifest);
|
|
104
|
+
const {
|
|
105
|
+
appInfoList,
|
|
106
|
+
apps
|
|
107
|
+
} = generateApps(GarfishConfig, manifest);
|
|
108
|
+
logger('generateApps', {
|
|
109
|
+
MApp,
|
|
110
|
+
apps,
|
|
111
|
+
appInfoList
|
|
112
|
+
});
|
|
113
|
+
this.setState({
|
|
114
|
+
MApp,
|
|
115
|
+
apps,
|
|
116
|
+
appInfoList
|
|
117
|
+
});
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
load();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
render() {
|
|
124
|
+
logger('GarfishProvider state', this.state);
|
|
125
|
+
return /*#__PURE__*/_jsx(GarfishProvider, {
|
|
126
|
+
value: this.state,
|
|
127
|
+
children: /*#__PURE__*/_jsx(App, _objectSpread(_objectSpread({}, this.props), this.state))
|
|
114
128
|
});
|
|
115
|
-
}
|
|
129
|
+
}
|
|
116
130
|
|
|
117
|
-
load();
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
render() {
|
|
121
|
-
logger('GarfishProvider state', this.state);
|
|
122
|
-
return /*#__PURE__*/_jsx(GarfishProvider, {
|
|
123
|
-
value: this.state,
|
|
124
|
-
children: /*#__PURE__*/_jsx(App, _objectSpread(_objectSpread({}, this.props), this.state))
|
|
125
|
-
});
|
|
126
131
|
}
|
|
127
132
|
|
|
133
|
+
return next({
|
|
134
|
+
App: hoistNonReactStatics(GetMicroFrontendApp, App)
|
|
135
|
+
});
|
|
128
136
|
}
|
|
129
137
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
}));
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
export default GarfishPlugin;
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
}));
|
|
@@ -28,7 +28,8 @@ const externals = {
|
|
|
28
28
|
exports.externals = externals;
|
|
29
29
|
|
|
30
30
|
var _default = ({
|
|
31
|
-
runtimePluginName: _runtimePluginName = '@modern-js/runtime/plugins'
|
|
31
|
+
runtimePluginName: _runtimePluginName = '@modern-js/runtime/plugins',
|
|
32
|
+
mfPackagePath: _mfPackagePath = _path.default.resolve(__dirname, '../../../../')
|
|
32
33
|
} = {}) => ({
|
|
33
34
|
name: '@modern-js/plugin-garfish',
|
|
34
35
|
setup: ({
|
|
@@ -144,12 +145,10 @@ var _default = ({
|
|
|
144
145
|
},
|
|
145
146
|
|
|
146
147
|
addRuntimeExports() {
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
const addExportStatement = `export { default as garfish, default as masterApp } from '${mfPackage}'`;
|
|
148
|
+
const addExportStatement = `export { default as garfish, default as masterApp } from '${_mfPackagePath}'`;
|
|
150
149
|
(0, _util.logger)('exportStatement', addExportStatement);
|
|
151
150
|
pluginsExportsUtils.addExport(addExportStatement);
|
|
152
|
-
runtimeExportsUtils.addExport(`export * from '${
|
|
151
|
+
runtimeExportsUtils.addExport(`export * from '${_mfPackagePath}'`);
|
|
153
152
|
},
|
|
154
153
|
|
|
155
154
|
modifyEntryImports({
|
|
@@ -87,7 +87,7 @@ function getRuntimeConfig(config) {
|
|
|
87
87
|
return config === null || config === void 0 ? void 0 : (_config$runtime2 = config.runtime) === null || _config$runtime2 === void 0 ? void 0 : _config$runtime2.features;
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
return config === null || config === void 0 ? void 0 : config.runtime;
|
|
90
|
+
return (config === null || config === void 0 ? void 0 : config.runtime) || {};
|
|
91
91
|
} // support legacy config
|
|
92
92
|
|
|
93
93
|
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _merge3 = _interopRequireDefault(require("lodash/merge"));
|
|
9
9
|
|
|
10
10
|
var _react = _interopRequireDefault(require("react"));
|
|
11
11
|
|
|
@@ -72,84 +72,88 @@ async function initOptions(manifest = {}, options) {
|
|
|
72
72
|
return _objectSpread(_objectSpread({}, options), {}, {
|
|
73
73
|
apps
|
|
74
74
|
});
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
return
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
75
|
+
} // export default GarfishPlugin;
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
var _default = defaultConfig => ({
|
|
79
|
+
name: '@modern-js/garfish-plugin',
|
|
80
|
+
setup: config => {
|
|
81
|
+
(0, _setExternal.default)();
|
|
82
|
+
|
|
83
|
+
const _merge2 = (0, _merge3.default)(defaultConfig, config),
|
|
84
|
+
{
|
|
85
|
+
manifest
|
|
86
|
+
} = _merge2,
|
|
87
|
+
options = _objectWithoutProperties(_merge2, _excluded);
|
|
88
|
+
|
|
89
|
+
(0, _util.logger)('createPlugin', {
|
|
90
|
+
config
|
|
91
|
+
});
|
|
92
|
+
const promise = initOptions(manifest, options);
|
|
93
|
+
return {
|
|
94
|
+
hoc({
|
|
95
|
+
App
|
|
96
|
+
}, next) {
|
|
97
|
+
class GetMicroFrontendApp extends _react.default.Component {
|
|
98
|
+
constructor(props) {
|
|
99
|
+
super(props);
|
|
100
|
+
this.state = {
|
|
101
|
+
MApp: () => {
|
|
102
|
+
(0, _util.logger)('MApp init Component Render');
|
|
103
|
+
return /*#__PURE__*/_react.default.createElement('div');
|
|
104
|
+
},
|
|
105
|
+
apps: new Proxy({}, {
|
|
106
|
+
get() {
|
|
107
|
+
return () => /*#__PURE__*/_react.default.createElement('div');
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
}),
|
|
111
|
+
appInfoList: []
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const load = async () => {
|
|
115
|
+
const GarfishConfig = await promise;
|
|
116
|
+
(0, _util.logger)('initOptions result', {
|
|
117
|
+
manifest,
|
|
118
|
+
GarfishConfig
|
|
119
|
+
});
|
|
120
|
+
const MApp = (0, _MApp.generateMApp)(GarfishConfig, manifest);
|
|
121
|
+
const {
|
|
122
|
+
appInfoList,
|
|
123
|
+
apps
|
|
124
|
+
} = (0, _apps.generateApps)(GarfishConfig, manifest);
|
|
125
|
+
(0, _util.logger)('generateApps', {
|
|
126
|
+
MApp,
|
|
127
|
+
apps,
|
|
128
|
+
appInfoList
|
|
129
|
+
});
|
|
130
|
+
this.setState({
|
|
131
|
+
MApp,
|
|
132
|
+
apps,
|
|
133
|
+
appInfoList
|
|
134
|
+
});
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
load();
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
render() {
|
|
141
|
+
(0, _util.logger)('GarfishProvider state', this.state);
|
|
142
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Context.GarfishProvider, {
|
|
143
|
+
value: this.state,
|
|
144
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(App, _objectSpread(_objectSpread({}, this.props), this.state))
|
|
130
145
|
});
|
|
131
|
-
}
|
|
146
|
+
}
|
|
132
147
|
|
|
133
|
-
load();
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
render() {
|
|
137
|
-
(0, _util.logger)('GarfishProvider state', this.state);
|
|
138
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Context.GarfishProvider, {
|
|
139
|
-
value: this.state,
|
|
140
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(App, _objectSpread(_objectSpread({}, this.props), this.state))
|
|
141
|
-
});
|
|
142
148
|
}
|
|
143
149
|
|
|
150
|
+
return next({
|
|
151
|
+
App: (0, _hoistNonReactStatics.default)(GetMicroFrontendApp, App)
|
|
152
|
+
});
|
|
144
153
|
}
|
|
145
154
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
}));
|
|
152
|
-
};
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
});
|
|
153
158
|
|
|
154
|
-
var _default = GarfishPlugin;
|
|
155
159
|
exports.default = _default;
|
|
@@ -23,7 +23,9 @@ export var externals = {
|
|
|
23
23
|
export default (function () {
|
|
24
24
|
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
25
25
|
_ref$runtimePluginNam = _ref.runtimePluginName,
|
|
26
|
-
runtimePluginName = _ref$runtimePluginNam === void 0 ? '@modern-js/runtime/plugins' : _ref$runtimePluginNam
|
|
26
|
+
runtimePluginName = _ref$runtimePluginNam === void 0 ? '@modern-js/runtime/plugins' : _ref$runtimePluginNam,
|
|
27
|
+
_ref$mfPackagePath = _ref.mfPackagePath,
|
|
28
|
+
mfPackagePath = _ref$mfPackagePath === void 0 ? path.resolve(__dirname, '../../../../') : _ref$mfPackagePath;
|
|
27
29
|
|
|
28
30
|
return {
|
|
29
31
|
name: '@modern-js/plugin-garfish',
|
|
@@ -153,11 +155,10 @@ export default (function () {
|
|
|
153
155
|
};
|
|
154
156
|
},
|
|
155
157
|
addRuntimeExports: function addRuntimeExports() {
|
|
156
|
-
var
|
|
157
|
-
var addExportStatement = "export { default as garfish, default as masterApp } from '".concat(mfPackage, "'");
|
|
158
|
+
var addExportStatement = "export { default as garfish, default as masterApp } from '".concat(mfPackagePath, "'");
|
|
158
159
|
logger('exportStatement', addExportStatement);
|
|
159
160
|
pluginsExportsUtils.addExport(addExportStatement);
|
|
160
|
-
runtimeExportsUtils.addExport("export * from '".concat(
|
|
161
|
+
runtimeExportsUtils.addExport("export * from '".concat(mfPackagePath, "'"));
|
|
161
162
|
},
|
|
162
163
|
modifyEntryImports: function modifyEntryImports(_ref5) {
|
|
163
164
|
var entrypoint = _ref5.entrypoint,
|
|
@@ -15,7 +15,7 @@ export function getRuntimeConfig(config) {
|
|
|
15
15
|
return config === null || config === void 0 ? void 0 : (_config$runtime2 = config.runtime) === null || _config$runtime2 === void 0 ? void 0 : _config$runtime2.features;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
return config === null || config === void 0 ? void 0 : config.runtime;
|
|
18
|
+
return (config === null || config === void 0 ? void 0 : config.runtime) || {};
|
|
19
19
|
} // support legacy config
|
|
20
20
|
|
|
21
21
|
export function setRuntimeConfig(config, key, value) {
|
|
@@ -1,5 +1,6 @@
|
|
|
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
|
+
import _merge from "lodash/merge";
|
|
3
4
|
var _excluded = ["manifest"];
|
|
4
5
|
|
|
5
6
|
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; }
|
|
@@ -38,8 +39,6 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try
|
|
|
38
39
|
|
|
39
40
|
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); }); }; }
|
|
40
41
|
|
|
41
|
-
// eslint-disable-next-line filenames/match-exported
|
|
42
|
-
import { createPlugin } from '@modern-js/runtime-core';
|
|
43
42
|
import React from 'react';
|
|
44
43
|
import hoistNonReactStatics from 'hoist-non-react-statics';
|
|
45
44
|
import { logger } from "../util";
|
|
@@ -51,7 +50,8 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
51
50
|
|
|
52
51
|
function initOptions() {
|
|
53
52
|
return _initOptions.apply(this, arguments);
|
|
54
|
-
}
|
|
53
|
+
} // export default GarfishPlugin;
|
|
54
|
+
|
|
55
55
|
|
|
56
56
|
function _initOptions() {
|
|
57
57
|
_initOptions = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
@@ -120,115 +120,117 @@ function _initOptions() {
|
|
|
120
120
|
return _initOptions.apply(this, arguments);
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
var
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
var
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
var load = /*#__PURE__*/function () {
|
|
165
|
-
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
166
|
-
var GarfishConfig, MApp, _generateApps, appInfoList, apps;
|
|
167
|
-
|
|
168
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
169
|
-
while (1) {
|
|
170
|
-
switch (_context.prev = _context.next) {
|
|
171
|
-
case 0:
|
|
172
|
-
_context.next = 2;
|
|
173
|
-
return promise;
|
|
174
|
-
|
|
175
|
-
case 2:
|
|
176
|
-
GarfishConfig = _context.sent;
|
|
177
|
-
logger('initOptions result', {
|
|
178
|
-
manifest: manifest,
|
|
179
|
-
GarfishConfig: GarfishConfig
|
|
180
|
-
});
|
|
181
|
-
MApp = generateMApp(GarfishConfig, manifest);
|
|
182
|
-
_generateApps = generateApps(GarfishConfig, manifest), appInfoList = _generateApps.appInfoList, apps = _generateApps.apps;
|
|
183
|
-
logger('generateApps', {
|
|
184
|
-
MApp: MApp,
|
|
185
|
-
apps: apps,
|
|
186
|
-
appInfoList: appInfoList
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
_this.setState({
|
|
190
|
-
MApp: MApp,
|
|
191
|
-
apps: apps,
|
|
192
|
-
appInfoList: appInfoList
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
case 8:
|
|
196
|
-
case "end":
|
|
197
|
-
return _context.stop();
|
|
198
|
-
}
|
|
123
|
+
export default (function (defaultConfig) {
|
|
124
|
+
return {
|
|
125
|
+
name: '@modern-js/garfish-plugin',
|
|
126
|
+
setup: function setup(config) {
|
|
127
|
+
setExternal();
|
|
128
|
+
|
|
129
|
+
var _merge2 = _merge(defaultConfig, config),
|
|
130
|
+
manifest = _merge2.manifest,
|
|
131
|
+
options = _objectWithoutProperties(_merge2, _excluded);
|
|
132
|
+
|
|
133
|
+
logger('createPlugin', {
|
|
134
|
+
config: config
|
|
135
|
+
});
|
|
136
|
+
var promise = initOptions(manifest, options);
|
|
137
|
+
return {
|
|
138
|
+
hoc: function hoc(_ref, next) {
|
|
139
|
+
var App = _ref.App;
|
|
140
|
+
|
|
141
|
+
var GetMicroFrontendApp = /*#__PURE__*/function (_React$Component) {
|
|
142
|
+
_inherits(GetMicroFrontendApp, _React$Component);
|
|
143
|
+
|
|
144
|
+
var _super = _createSuper(GetMicroFrontendApp);
|
|
145
|
+
|
|
146
|
+
function GetMicroFrontendApp(props) {
|
|
147
|
+
var _this;
|
|
148
|
+
|
|
149
|
+
_classCallCheck(this, GetMicroFrontendApp);
|
|
150
|
+
|
|
151
|
+
_this = _super.call(this, props);
|
|
152
|
+
_this.state = {
|
|
153
|
+
MApp: function MApp() {
|
|
154
|
+
logger('MApp init Component Render');
|
|
155
|
+
return /*#__PURE__*/React.createElement('div');
|
|
156
|
+
},
|
|
157
|
+
apps: new Proxy({}, {
|
|
158
|
+
get: function get() {
|
|
159
|
+
return function () {
|
|
160
|
+
return /*#__PURE__*/React.createElement('div');
|
|
161
|
+
};
|
|
199
162
|
}
|
|
200
|
-
},
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
return function load() {
|
|
204
|
-
return _ref2.apply(this, arguments);
|
|
163
|
+
}),
|
|
164
|
+
appInfoList: []
|
|
205
165
|
};
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
166
|
+
|
|
167
|
+
var load = /*#__PURE__*/function () {
|
|
168
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
169
|
+
var GarfishConfig, MApp, _generateApps, appInfoList, apps;
|
|
170
|
+
|
|
171
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
172
|
+
while (1) {
|
|
173
|
+
switch (_context.prev = _context.next) {
|
|
174
|
+
case 0:
|
|
175
|
+
_context.next = 2;
|
|
176
|
+
return promise;
|
|
177
|
+
|
|
178
|
+
case 2:
|
|
179
|
+
GarfishConfig = _context.sent;
|
|
180
|
+
logger('initOptions result', {
|
|
181
|
+
manifest: manifest,
|
|
182
|
+
GarfishConfig: GarfishConfig
|
|
183
|
+
});
|
|
184
|
+
MApp = generateMApp(GarfishConfig, manifest);
|
|
185
|
+
_generateApps = generateApps(GarfishConfig, manifest), appInfoList = _generateApps.appInfoList, apps = _generateApps.apps;
|
|
186
|
+
logger('generateApps', {
|
|
187
|
+
MApp: MApp,
|
|
188
|
+
apps: apps,
|
|
189
|
+
appInfoList: appInfoList
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
_this.setState({
|
|
193
|
+
MApp: MApp,
|
|
194
|
+
apps: apps,
|
|
195
|
+
appInfoList: appInfoList
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
case 8:
|
|
199
|
+
case "end":
|
|
200
|
+
return _context.stop();
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}, _callee);
|
|
204
|
+
}));
|
|
205
|
+
|
|
206
|
+
return function load() {
|
|
207
|
+
return _ref2.apply(this, arguments);
|
|
208
|
+
};
|
|
209
|
+
}();
|
|
210
|
+
|
|
211
|
+
load();
|
|
212
|
+
return _this;
|
|
220
213
|
}
|
|
221
|
-
}]);
|
|
222
214
|
|
|
223
|
-
|
|
224
|
-
|
|
215
|
+
_createClass(GetMicroFrontendApp, [{
|
|
216
|
+
key: "render",
|
|
217
|
+
value: function render() {
|
|
218
|
+
logger('GarfishProvider state', this.state);
|
|
219
|
+
return /*#__PURE__*/_jsx(GarfishProvider, {
|
|
220
|
+
value: this.state,
|
|
221
|
+
children: /*#__PURE__*/_jsx(App, _objectSpread(_objectSpread({}, this.props), this.state))
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
}]);
|
|
225
225
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
};
|
|
231
|
-
});
|
|
232
|
-
};
|
|
226
|
+
return GetMicroFrontendApp;
|
|
227
|
+
}(React.Component);
|
|
233
228
|
|
|
234
|
-
|
|
229
|
+
return next({
|
|
230
|
+
App: hoistNonReactStatics(GetMicroFrontendApp, App)
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
});
|
|
@@ -6,9 +6,11 @@ export declare const externals: {
|
|
|
6
6
|
export declare type LifeCycle = CliHookCallbacks;
|
|
7
7
|
|
|
8
8
|
declare const _default: ({
|
|
9
|
-
runtimePluginName
|
|
9
|
+
runtimePluginName,
|
|
10
|
+
mfPackagePath
|
|
10
11
|
}?: {
|
|
11
12
|
runtimePluginName?: string | undefined;
|
|
13
|
+
mfPackagePath?: string | undefined;
|
|
12
14
|
}) => CliPlugin;
|
|
13
15
|
|
|
14
16
|
export default _default;
|
|
@@ -1,29 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { Plugin } from '@modern-js/runtime-core';
|
|
2
2
|
import { Config } from './useModuleApps';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
provide: import("@modern-js/runtime-core").Pipeline<{
|
|
8
|
-
element: JSX.Element;
|
|
9
|
-
readonly props: import("@modern-js/runtime-core/src/plugin").AppProps;
|
|
10
|
-
readonly context: import("@modern-js/runtime-core").RuntimeContext;
|
|
11
|
-
}, JSX.Element>;
|
|
12
|
-
client: import("@modern-js/runtime-core").AsyncPipeline<{
|
|
13
|
-
App: React.ComponentType<any>;
|
|
14
|
-
readonly context?: import("@modern-js/runtime-core").RuntimeContext | undefined;
|
|
15
|
-
rootElement: HTMLElement;
|
|
16
|
-
}, void>;
|
|
17
|
-
server: import("@modern-js/runtime-core").AsyncPipeline<{
|
|
18
|
-
App: React.ComponentType<any>;
|
|
19
|
-
readonly context?: import("@modern-js/runtime-core").RuntimeContext | undefined;
|
|
20
|
-
}, string>;
|
|
21
|
-
init: import("@modern-js/runtime-core").AsyncPipeline<{
|
|
22
|
-
context: import("@modern-js/runtime-core").RuntimeContext;
|
|
23
|
-
}, unknown>;
|
|
24
|
-
pickContext: import("@modern-js/runtime-core").Pipeline<{
|
|
25
|
-
context: import("@modern-js/runtime-core").RuntimeContext;
|
|
26
|
-
pickedContext: import("@modern-js/runtime-core").TRuntimeContext;
|
|
27
|
-
}, import("@modern-js/runtime-core").TRuntimeContext>;
|
|
28
|
-
}, Record<string, never>>;
|
|
29
|
-
export default GarfishPlugin;
|
|
3
|
+
|
|
4
|
+
declare const _default: (defaultConfig: Partial<Config>) => Plugin;
|
|
5
|
+
|
|
6
|
+
export default _default;
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.4.3",
|
|
14
|
+
"version": "1.4.4-beta.3",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/runtime/index.d.ts",
|
|
17
17
|
"typesVersions": {
|
|
@@ -52,6 +52,7 @@
|
|
|
52
52
|
"debug": "^4.3.2",
|
|
53
53
|
"garfish": "^1.3.3",
|
|
54
54
|
"hoist-non-react-statics": "^3.3.2",
|
|
55
|
+
"lodash": "^4.17.21",
|
|
55
56
|
"react-loadable": "^5.5.0"
|
|
56
57
|
},
|
|
57
58
|
"devDependencies": {
|
|
@@ -67,6 +68,7 @@
|
|
|
67
68
|
"@testing-library/user-event": "^13.5.0",
|
|
68
69
|
"@types/hoist-non-react-statics": "^3.3.1",
|
|
69
70
|
"@types/jest": "^26.0.24",
|
|
71
|
+
"@types/lodash": "^4.14.181",
|
|
70
72
|
"@types/node": "^14",
|
|
71
73
|
"@types/react": "^17",
|
|
72
74
|
"@types/react-dom": "^17",
|
|
@@ -86,7 +88,8 @@
|
|
|
86
88
|
"modernConfig": {},
|
|
87
89
|
"publishConfig": {
|
|
88
90
|
"registry": "https://registry.npmjs.org/",
|
|
89
|
-
"access": "public"
|
|
91
|
+
"access": "public",
|
|
92
|
+
"types": "./dist/types/runtime/index.d.ts"
|
|
90
93
|
},
|
|
91
94
|
"scripts": {
|
|
92
95
|
"new": "modern new",
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
|
+
exports[`plugin-garfish cli cli addRuntimeExports 1`] = `
|
|
4
|
+
Array [
|
|
5
|
+
"export { default as garfish, default as masterApp } from '@modern-js/test/plugin-garfish'",
|
|
6
|
+
"export * from '@modern-js/test/plugin-garfish'",
|
|
7
|
+
]
|
|
8
|
+
`;
|
|
9
|
+
|
|
3
10
|
exports[`plugin-garfish cli cli get runtime config 1`] = `
|
|
4
11
|
Object {
|
|
5
12
|
"masterApp": Object {
|
package/tests/cli.test.tsx
CHANGED
|
@@ -1,9 +1,24 @@
|
|
|
1
1
|
import '@testing-library/jest-dom';
|
|
2
|
-
import { manager } from '@modern-js/core';
|
|
2
|
+
import { Hooks, manager, ToRunners } from '@modern-js/core';
|
|
3
3
|
import WebpackChain from 'webpack-chain';
|
|
4
4
|
import GarfishPlugin, { externals } from '../src/cli';
|
|
5
5
|
import { getRuntimeConfig, makeRenderFunction, setRuntimeConfig } from '../src/cli/utils';
|
|
6
6
|
|
|
7
|
+
const addExportList = [];
|
|
8
|
+
jest.mock('@modern-js/utils', () => {
|
|
9
|
+
const originalModule = jest.requireActual('@modern-js/utils');
|
|
10
|
+
return {
|
|
11
|
+
__esModule: true,
|
|
12
|
+
...originalModule,
|
|
13
|
+
createRuntimeExportsUtils: ()=>({
|
|
14
|
+
addExport: (val: any)=> {
|
|
15
|
+
addExportList.push(val);
|
|
16
|
+
},
|
|
17
|
+
getPath: ()=> 'test',
|
|
18
|
+
}),
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
|
|
7
22
|
describe('plugin-garfish cli', () => {
|
|
8
23
|
test('cli garfish basename', async () => {
|
|
9
24
|
expect(GarfishPlugin().name).toBe('@modern-js/plugin-garfish');
|
|
@@ -21,7 +36,7 @@ describe('plugin-garfish cli', () => {
|
|
|
21
36
|
},
|
|
22
37
|
}
|
|
23
38
|
} as any);
|
|
24
|
-
|
|
39
|
+
|
|
25
40
|
expect(configHistoryOptions.resolved.runtime.masterApp.basename).toBe('/test');
|
|
26
41
|
|
|
27
42
|
const configHistory: any = await runner.resolvedConfig({
|
|
@@ -34,7 +49,7 @@ describe('plugin-garfish cli', () => {
|
|
|
34
49
|
},
|
|
35
50
|
}
|
|
36
51
|
} as any);
|
|
37
|
-
|
|
52
|
+
|
|
38
53
|
expect(configHistory.resolved.runtime.masterApp.basename).toBe('/test2');
|
|
39
54
|
});
|
|
40
55
|
|
|
@@ -202,4 +217,23 @@ describe('plugin-garfish cli', () => {
|
|
|
202
217
|
expect(generateConfig.externals).toBeUndefined();
|
|
203
218
|
expect(generateConfig.output.filename).toBeUndefined();
|
|
204
219
|
});
|
|
220
|
+
|
|
221
|
+
test('cli addRuntimeExports', async ()=>{
|
|
222
|
+
const resolveConfig: any = {};
|
|
223
|
+
const mfPackagePath = '@modern-js/test/plugin-garfish';
|
|
224
|
+
const plugin = GarfishPlugin({
|
|
225
|
+
mfPackagePath,
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
const lifecycle = await plugin.setup({
|
|
229
|
+
useResolvedConfigContext: () => resolveConfig,
|
|
230
|
+
useAppContext: ()=>({
|
|
231
|
+
internalDirectory: 'test'
|
|
232
|
+
}),
|
|
233
|
+
} as any);
|
|
234
|
+
|
|
235
|
+
lifecycle && lifecycle.config();
|
|
236
|
+
lifecycle && lifecycle.addRuntimeExports()
|
|
237
|
+
expect(addExportList).toMatchSnapshot();
|
|
238
|
+
});
|
|
205
239
|
});
|