@modern-js/plugin-garfish 1.4.2 → 1.4.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/CHANGELOG.md +9 -0
- package/dist/js/modern/cli/index.js +202 -211
- package/dist/js/modern/cli/utils.js +7 -5
- package/dist/js/modern/runtime/index.js +1 -1
- package/dist/js/modern/runtime/plugin.js +1 -2
- package/dist/js/modern/runtime/useModuleApps.js +28 -21
- package/dist/js/node/cli/index.js +202 -218
- package/dist/js/node/cli/utils.js +7 -5
- package/dist/js/node/runtime/index.js +0 -6
- package/dist/js/node/runtime/plugin.js +1 -2
- package/dist/js/node/runtime/useModuleApps.js +32 -23
- package/dist/js/treeshaking/cli/index.js +216 -221
- package/dist/js/treeshaking/cli/utils.js +1 -1
- package/dist/js/treeshaking/runtime/index.js +1 -1
- package/dist/js/treeshaking/runtime/plugin.js +1 -2
- package/dist/js/treeshaking/runtime/useModuleApps.js +29 -21
- package/dist/types/cli/index.d.ts +7 -31
- package/dist/types/cli/utils.d.ts +1 -1
- package/dist/types/runtime/index.d.ts +1 -1
- package/dist/types/runtime/plugin.d.ts +2 -2
- package/dist/types/runtime/useModuleApps.d.ts +7 -7
- package/dist/types/runtime/utils/Context.d.ts +1 -1
- package/dist/types/runtime/utils/apps.d.ts +2 -2
- package/package.json +4 -5
- package/tests/__snapshots__/cli.test.tsx.snap +82 -0
- package/tests/cli.test.tsx +80 -96
- package/tests/hooks.test.tsx +1 -7
- package/tests/index.test.tsx +7 -7
|
@@ -14,261 +14,256 @@ function _asyncToGenerator(fn) { return function () { var self = this, args = ar
|
|
|
14
14
|
|
|
15
15
|
import path from 'path';
|
|
16
16
|
import { createRuntimeExportsUtils, PLUGIN_SCHEMAS } from '@modern-js/utils';
|
|
17
|
-
import { createPlugin, useAppContext, useResolvedConfigContext } from '@modern-js/core';
|
|
18
17
|
import { logger } from "../util";
|
|
19
18
|
import { getRuntimeConfig, makeProvider, makeRenderFunction, setRuntimeConfig } from "./utils";
|
|
20
19
|
export var externals = {
|
|
21
20
|
'react-dom': 'react-dom',
|
|
22
21
|
react: 'react'
|
|
23
22
|
};
|
|
24
|
-
export
|
|
25
|
-
var _ref =
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
var pluginsExportsUtils;
|
|
76
|
-
var runtimeExportsUtils;
|
|
77
|
-
return {
|
|
78
|
-
validateSchema: validateSchema,
|
|
79
|
-
resolvedConfig: resolvedConfig,
|
|
80
|
-
config: function config() {
|
|
81
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
82
|
-
var config = useAppContext();
|
|
83
|
-
pluginsExportsUtils = createRuntimeExportsUtils(config.internalDirectory, 'plugins');
|
|
84
|
-
runtimeExportsUtils = createRuntimeExportsUtils(config.internalDirectory, 'index');
|
|
85
|
-
return {
|
|
86
|
-
source: {
|
|
87
|
-
alias: {
|
|
88
|
-
'@modern-js/runtime/plugins': pluginsExportsUtils.getPath()
|
|
89
|
-
}
|
|
90
|
-
},
|
|
91
|
-
tools: {
|
|
92
|
-
webpack: function webpack(webpackConfig, _ref4) {
|
|
93
|
-
var _resolveOptions$deplo, _resolveWebpackConfig;
|
|
23
|
+
export default (function () {
|
|
24
|
+
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
25
|
+
_ref$runtimePluginNam = _ref.runtimePluginName,
|
|
26
|
+
runtimePluginName = _ref$runtimePluginNam === void 0 ? '@modern-js/runtime/plugins' : _ref$runtimePluginNam;
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
name: '@modern-js/plugin-garfish',
|
|
30
|
+
setup: function setup(_ref2) {
|
|
31
|
+
var useAppContext = _ref2.useAppContext,
|
|
32
|
+
useResolvedConfigContext = _ref2.useResolvedConfigContext;
|
|
33
|
+
var pluginsExportsUtils;
|
|
34
|
+
var runtimeExportsUtils;
|
|
35
|
+
return {
|
|
36
|
+
validateSchema: function validateSchema() {
|
|
37
|
+
return PLUGIN_SCHEMAS['@modern-js/plugin-garfish'];
|
|
38
|
+
},
|
|
39
|
+
resolvedConfig: function () {
|
|
40
|
+
var _resolvedConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(config) {
|
|
41
|
+
var resolved, _getRuntimeConfig, masterApp, router, nConfig, _router$historyOption;
|
|
42
|
+
|
|
43
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
44
|
+
while (1) {
|
|
45
|
+
switch (_context.prev = _context.next) {
|
|
46
|
+
case 0:
|
|
47
|
+
resolved = config.resolved;
|
|
48
|
+
_getRuntimeConfig = getRuntimeConfig(resolved), masterApp = _getRuntimeConfig.masterApp, router = _getRuntimeConfig.router;
|
|
49
|
+
nConfig = {
|
|
50
|
+
resolved: _objectSpread({}, resolved)
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
if (masterApp) {
|
|
54
|
+
// basename does not exist use router's basename
|
|
55
|
+
setRuntimeConfig(nConfig.resolved, 'masterApp', Object.assign(_typeof(masterApp) === 'object' ? _objectSpread({}, masterApp) : {}, {
|
|
56
|
+
basename: (router === null || router === void 0 ? void 0 : (_router$historyOption = router.historyOptions) === null || _router$historyOption === void 0 ? void 0 : _router$historyOption.basename) || (router === null || router === void 0 ? void 0 : router.basename) || '/'
|
|
57
|
+
}));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
logger("resolvedConfig", {
|
|
61
|
+
runtime: nConfig.resolved.runtime,
|
|
62
|
+
deploy: nConfig.resolved.deploy,
|
|
63
|
+
server: nConfig.resolved.server
|
|
64
|
+
});
|
|
65
|
+
return _context.abrupt("return", nConfig);
|
|
66
|
+
|
|
67
|
+
case 6:
|
|
68
|
+
case "end":
|
|
69
|
+
return _context.stop();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}, _callee);
|
|
73
|
+
}));
|
|
94
74
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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();
|
|
75
|
+
function resolvedConfig(_x) {
|
|
76
|
+
return _resolvedConfig.apply(this, arguments);
|
|
77
|
+
}
|
|
101
78
|
|
|
102
|
-
|
|
103
|
-
|
|
79
|
+
return resolvedConfig;
|
|
80
|
+
}(),
|
|
81
|
+
config: function config() {
|
|
82
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
83
|
+
var config = useAppContext(); // eslint-disable-next-line react-hooks/rules-of-hooks
|
|
104
84
|
|
|
105
|
-
|
|
85
|
+
var resolveOptions = useResolvedConfigContext();
|
|
86
|
+
pluginsExportsUtils = createRuntimeExportsUtils(config.internalDirectory, 'plugins');
|
|
87
|
+
runtimeExportsUtils = createRuntimeExportsUtils(config.internalDirectory, 'index');
|
|
88
|
+
return {
|
|
89
|
+
source: {
|
|
90
|
+
alias: {
|
|
91
|
+
'@modern-js/runtime/plugins': pluginsExportsUtils.getPath()
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
tools: {
|
|
95
|
+
webpack: function webpack(webpackConfig, _ref3) {
|
|
96
|
+
var _resolveOptions$deplo, _resolveWebpackConfig;
|
|
97
|
+
|
|
98
|
+
var chain = _ref3.chain,
|
|
99
|
+
_webpack = _ref3.webpack,
|
|
100
|
+
_ref3$env = _ref3.env,
|
|
101
|
+
env = _ref3$env === void 0 ? process.env.NODE_ENV || 'development' : _ref3$env;
|
|
102
|
+
|
|
103
|
+
if (resolveOptions !== null && resolveOptions !== void 0 && (_resolveOptions$deplo = resolveOptions.deploy) !== null && _resolveOptions$deplo !== void 0 && _resolveOptions$deplo.microFrontend) {
|
|
104
|
+
var _resolveOptions$serve, _resolveOptions$deplo2, _resolveOptions$deplo3;
|
|
105
|
+
|
|
106
|
+
chain.output.libraryTarget('umd');
|
|
107
|
+
chain.devServer.headers({
|
|
108
|
+
'Access-Control-Allow-Origin': '*'
|
|
109
|
+
});
|
|
106
110
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
111
|
+
if (resolveOptions !== null && resolveOptions !== void 0 && (_resolveOptions$serve = resolveOptions.server) !== null && _resolveOptions$serve !== void 0 && _resolveOptions$serve.port) {
|
|
112
|
+
chain.output.publicPath(env === 'development' ? "//localhost:".concat(resolveOptions.server.port, "/") : webpackConfig.output.publicPath);
|
|
113
|
+
} // add comments avoid sourcemap abnormal
|
|
110
114
|
|
|
111
115
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
116
|
+
if (_webpack.BannerPlugin) {
|
|
117
|
+
chain.plugin('banner').use(_webpack.BannerPlugin, [{
|
|
118
|
+
banner: 'Micro front-end'
|
|
119
|
+
}]);
|
|
120
|
+
}
|
|
117
121
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
122
|
+
var _ref4 = _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 : {},
|
|
123
|
+
_ref4$enableHtmlEntry = _ref4.enableHtmlEntry,
|
|
124
|
+
enableHtmlEntry = _ref4$enableHtmlEntry === void 0 ? true : _ref4$enableHtmlEntry,
|
|
125
|
+
_ref4$externalBasicLi = _ref4.externalBasicLibrary,
|
|
126
|
+
externalBasicLibrary = _ref4$externalBasicLi === void 0 ? false : _ref4$externalBasicLi; // external
|
|
123
127
|
|
|
124
128
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
129
|
+
if (externalBasicLibrary) {
|
|
130
|
+
chain.externals(externals);
|
|
131
|
+
} // use html mode
|
|
128
132
|
|
|
129
133
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
134
|
+
if (!enableHtmlEntry) {
|
|
135
|
+
chain.output.filename('index.js');
|
|
136
|
+
chain.plugins["delete"]('html-main');
|
|
137
|
+
chain.optimization.runtimeChunk(false);
|
|
138
|
+
chain.optimization.splitChunks({
|
|
139
|
+
chunks: 'async'
|
|
140
|
+
});
|
|
141
|
+
}
|
|
137
142
|
}
|
|
138
|
-
}
|
|
139
143
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
144
|
+
var resolveWebpackConfig = chain.toConfig();
|
|
145
|
+
logger('webpackConfig', {
|
|
146
|
+
output: resolveWebpackConfig.output,
|
|
147
|
+
externals: resolveWebpackConfig.externals,
|
|
148
|
+
env: env,
|
|
149
|
+
alias: (_resolveWebpackConfig = resolveWebpackConfig.resolve) === null || _resolveWebpackConfig === void 0 ? void 0 : _resolveWebpackConfig.alias
|
|
150
|
+
});
|
|
151
|
+
}
|
|
147
152
|
}
|
|
153
|
+
};
|
|
154
|
+
},
|
|
155
|
+
addRuntimeExports: function addRuntimeExports() {
|
|
156
|
+
var mfPackage = path.resolve(__dirname, '../../../../');
|
|
157
|
+
var addExportStatement = "export { default as garfish, default as masterApp } from '".concat(mfPackage, "'");
|
|
158
|
+
logger('exportStatement', addExportStatement);
|
|
159
|
+
pluginsExportsUtils.addExport(addExportStatement);
|
|
160
|
+
runtimeExportsUtils.addExport("export * from '".concat(mfPackage, "'"));
|
|
161
|
+
},
|
|
162
|
+
modifyEntryImports: function modifyEntryImports(_ref5) {
|
|
163
|
+
var entrypoint = _ref5.entrypoint,
|
|
164
|
+
imports = _ref5.imports;
|
|
165
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
166
|
+
var config = useResolvedConfigContext();
|
|
167
|
+
|
|
168
|
+
var _getRuntimeConfig2 = getRuntimeConfig(config),
|
|
169
|
+
masterApp = _getRuntimeConfig2.masterApp;
|
|
170
|
+
|
|
171
|
+
if (masterApp) {
|
|
172
|
+
imports.push({
|
|
173
|
+
value: runtimePluginName,
|
|
174
|
+
specifiers: [{
|
|
175
|
+
imported: 'garfish'
|
|
176
|
+
}]
|
|
177
|
+
});
|
|
178
|
+
imports.push({
|
|
179
|
+
value: runtimePluginName,
|
|
180
|
+
specifiers: [{
|
|
181
|
+
imported: 'masterApp'
|
|
182
|
+
}]
|
|
183
|
+
});
|
|
148
184
|
}
|
|
149
|
-
|
|
150
|
-
},
|
|
151
|
-
addRuntimeExports: function addRuntimeExports() {
|
|
152
|
-
var mfPackage = path.resolve(__dirname, '../../../../');
|
|
153
|
-
var addExportStatement = "export { default as garfish, default as masterApp } from '".concat(mfPackage, "'");
|
|
154
|
-
logger('exportStatement', addExportStatement);
|
|
155
|
-
pluginsExportsUtils.addExport(addExportStatement);
|
|
156
|
-
runtimeExportsUtils.addExport("export * from '".concat(mfPackage, "'"));
|
|
157
|
-
},
|
|
158
|
-
modifyEntryImports: function modifyEntryImports(_ref6) {
|
|
159
|
-
var entrypoint = _ref6.entrypoint,
|
|
160
|
-
imports = _ref6.imports;
|
|
161
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
162
|
-
var config = useResolvedConfigContext();
|
|
163
|
-
|
|
164
|
-
var _getRuntimeConfig2 = getRuntimeConfig(config),
|
|
165
|
-
masterApp = _getRuntimeConfig2.masterApp;
|
|
166
|
-
|
|
167
|
-
if (masterApp) {
|
|
168
|
-
imports.push({
|
|
169
|
-
value: runtimePluginName,
|
|
170
|
-
specifiers: [{
|
|
171
|
-
imported: 'garfish'
|
|
172
|
-
}]
|
|
173
|
-
});
|
|
185
|
+
|
|
174
186
|
imports.push({
|
|
175
|
-
value:
|
|
187
|
+
value: 'react-dom',
|
|
176
188
|
specifiers: [{
|
|
177
|
-
imported: '
|
|
189
|
+
imported: 'unmountComponentAtNode'
|
|
190
|
+
}, {
|
|
191
|
+
imported: 'createPortal'
|
|
178
192
|
}]
|
|
179
193
|
});
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
masterApp = _getRuntimeConfig3.masterApp;
|
|
203
|
-
|
|
204
|
-
if (masterApp) {
|
|
205
|
-
logger('garfishPlugin options', masterApp);
|
|
206
|
-
plugins.push({
|
|
207
|
-
name: 'garfish',
|
|
208
|
-
args: 'masterApp',
|
|
209
|
-
options: masterApp === true ? JSON.stringify({}) : JSON.stringify(masterApp)
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
return {
|
|
214
|
-
entrypoint: entrypoint,
|
|
215
|
-
plugins: plugins
|
|
216
|
-
};
|
|
217
|
-
},
|
|
218
|
-
modifyEntryRenderFunction: function modifyEntryRenderFunction(_ref8) {
|
|
219
|
-
var _config$deploy;
|
|
194
|
+
return {
|
|
195
|
+
imports: imports,
|
|
196
|
+
entrypoint: entrypoint
|
|
197
|
+
};
|
|
198
|
+
},
|
|
199
|
+
modifyEntryRuntimePlugins: function modifyEntryRuntimePlugins(_ref6) {
|
|
200
|
+
var entrypoint = _ref6.entrypoint,
|
|
201
|
+
plugins = _ref6.plugins;
|
|
202
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
203
|
+
var config = useResolvedConfigContext();
|
|
204
|
+
|
|
205
|
+
var _getRuntimeConfig3 = getRuntimeConfig(config),
|
|
206
|
+
masterApp = _getRuntimeConfig3.masterApp;
|
|
207
|
+
|
|
208
|
+
if (masterApp) {
|
|
209
|
+
logger('garfishPlugin options', masterApp);
|
|
210
|
+
plugins.push({
|
|
211
|
+
name: 'garfish',
|
|
212
|
+
args: 'masterApp',
|
|
213
|
+
options: masterApp === true ? JSON.stringify({}) : JSON.stringify(masterApp)
|
|
214
|
+
});
|
|
215
|
+
}
|
|
220
216
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
217
|
+
return {
|
|
218
|
+
entrypoint: entrypoint,
|
|
219
|
+
plugins: plugins
|
|
220
|
+
};
|
|
221
|
+
},
|
|
222
|
+
modifyEntryRenderFunction: function modifyEntryRenderFunction(_ref7) {
|
|
223
|
+
var _config$deploy;
|
|
224
|
+
|
|
225
|
+
var entrypoint = _ref7.entrypoint,
|
|
226
|
+
code = _ref7.code;
|
|
227
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
228
|
+
var config = useResolvedConfigContext();
|
|
229
|
+
|
|
230
|
+
if (!(config !== null && config !== void 0 && (_config$deploy = config.deploy) !== null && _config$deploy !== void 0 && _config$deploy.microFrontend)) {
|
|
231
|
+
return {
|
|
232
|
+
entrypoint: entrypoint,
|
|
233
|
+
code: code
|
|
234
|
+
};
|
|
235
|
+
}
|
|
225
236
|
|
|
226
|
-
|
|
237
|
+
var nCode = makeRenderFunction(code);
|
|
238
|
+
logger('makeRenderFunction', nCode);
|
|
227
239
|
return {
|
|
228
240
|
entrypoint: entrypoint,
|
|
229
|
-
code:
|
|
241
|
+
code: nCode
|
|
230
242
|
};
|
|
231
|
-
}
|
|
243
|
+
},
|
|
244
|
+
modifyEntryExport: function modifyEntryExport(_ref8) {
|
|
245
|
+
var _config$deploy2;
|
|
246
|
+
|
|
247
|
+
var entrypoint = _ref8.entrypoint,
|
|
248
|
+
exportStatement = _ref8.exportStatement;
|
|
249
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
250
|
+
var config = useResolvedConfigContext();
|
|
251
|
+
|
|
252
|
+
if (config !== null && config !== void 0 && (_config$deploy2 = config.deploy) !== null && _config$deploy2 !== void 0 && _config$deploy2.microFrontend) {
|
|
253
|
+
var exportStatementCode = makeProvider();
|
|
254
|
+
logger('exportStatement', exportStatementCode);
|
|
255
|
+
return {
|
|
256
|
+
entrypoint: entrypoint,
|
|
257
|
+
exportStatement: exportStatementCode
|
|
258
|
+
};
|
|
259
|
+
}
|
|
232
260
|
|
|
233
|
-
var nCode = makeRenderFunction(code);
|
|
234
|
-
logger('makeRenderFunction', nCode);
|
|
235
|
-
return {
|
|
236
|
-
entrypoint: entrypoint,
|
|
237
|
-
code: nCode
|
|
238
|
-
};
|
|
239
|
-
},
|
|
240
|
-
modifyEntryExport: function modifyEntryExport(_ref9) {
|
|
241
|
-
var _config$deploy2;
|
|
242
|
-
|
|
243
|
-
var entrypoint = _ref9.entrypoint,
|
|
244
|
-
exportStatement = _ref9.exportStatement;
|
|
245
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
246
|
-
var config = useResolvedConfigContext();
|
|
247
|
-
|
|
248
|
-
if (config !== null && config !== void 0 && (_config$deploy2 = config.deploy) !== null && _config$deploy2 !== void 0 && _config$deploy2.microFrontend) {
|
|
249
|
-
var exportStatementCode = makeProvider();
|
|
250
|
-
logger('exportStatement', exportStatementCode);
|
|
251
261
|
return {
|
|
252
262
|
entrypoint: entrypoint,
|
|
253
|
-
exportStatement:
|
|
263
|
+
exportStatement: exportStatement
|
|
254
264
|
};
|
|
255
265
|
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
entrypoint: entrypoint,
|
|
259
|
-
exportStatement: exportStatement
|
|
260
|
-
};
|
|
261
|
-
}
|
|
262
|
-
};
|
|
266
|
+
};
|
|
267
|
+
}
|
|
263
268
|
};
|
|
264
|
-
};
|
|
265
|
-
export default createPlugin(initializer({
|
|
266
|
-
resolvedConfig: resolvedConfig,
|
|
267
|
-
validateSchema: function validateSchema() {
|
|
268
|
-
return PLUGIN_SCHEMAS['@modern-js/plugin-garfish'];
|
|
269
|
-
}
|
|
270
|
-
}, {
|
|
271
|
-
runtimePluginName: '@modern-js/runtime/plugins'
|
|
272
|
-
}), {
|
|
273
|
-
name: '@modern-js/plugin-garfish'
|
|
274
269
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export var makeProvider = function makeProvider() {
|
|
2
|
-
return "\nexport const provider = function ({basename, dom
|
|
2
|
+
return "\nexport const provider = function ({basename, dom}) {\n return {\n render({basename, dom, props}) {\n const SubApp = render({ props, basename });\n const node = dom.querySelector('#' + MOUNT_ID) || dom;\n const App = function () {\n return React.createElement(SubApp, props)\n };\n bootstrap(App, 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
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 ";
|
|
@@ -152,8 +152,7 @@ var GarfishPlugin = function GarfishPlugin(config) {
|
|
|
152
152
|
return /*#__PURE__*/React.createElement('div');
|
|
153
153
|
},
|
|
154
154
|
apps: new Proxy({}, {
|
|
155
|
-
get: function get(
|
|
156
|
-
logger('apps init Component Render', _p);
|
|
155
|
+
get: function get() {
|
|
157
156
|
return function () {
|
|
158
157
|
return /*#__PURE__*/React.createElement('div');
|
|
159
158
|
};
|
|
@@ -1,12 +1,37 @@
|
|
|
1
|
-
|
|
1
|
+
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
|
+
|
|
3
|
+
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
|
+
|
|
5
|
+
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
|
+
|
|
7
|
+
import React, { useContext } from 'react';
|
|
2
8
|
import { logger } from "../util";
|
|
3
9
|
import { GarfishContext } from "./utils/Context";
|
|
4
10
|
export function useModuleApps() {
|
|
5
11
|
var _useContext = useContext(GarfishContext),
|
|
6
|
-
apps = _useContext.apps
|
|
12
|
+
apps = _useContext.apps,
|
|
13
|
+
MApp = _useContext.MApp,
|
|
14
|
+
appInfoList = _useContext.appInfoList;
|
|
15
|
+
|
|
16
|
+
logger('call useModuleApps', _objectSpread({
|
|
17
|
+
MApp: MApp,
|
|
18
|
+
apps: appInfoList
|
|
19
|
+
}, apps));
|
|
20
|
+
var Info = new Proxy(_objectSpread({
|
|
21
|
+
MApp: MApp,
|
|
22
|
+
apps: appInfoList
|
|
23
|
+
}, apps), {
|
|
24
|
+
get: function get(target, p, receiver) {
|
|
25
|
+
if (typeof p === 'string' && p in target) {
|
|
26
|
+
return Reflect.get(target, p, receiver);
|
|
27
|
+
}
|
|
7
28
|
|
|
8
|
-
|
|
9
|
-
|
|
29
|
+
return function () {
|
|
30
|
+
return /*#__PURE__*/React.createElement('div');
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
return Info;
|
|
10
35
|
}
|
|
11
36
|
export function useModuleApp() {
|
|
12
37
|
var _useContext2 = useContext(GarfishContext),
|
|
@@ -14,21 +39,4 @@ export function useModuleApp() {
|
|
|
14
39
|
|
|
15
40
|
logger('call useModuleApps', MApp);
|
|
16
41
|
return MApp;
|
|
17
|
-
}
|
|
18
|
-
export function useMicroApps() {
|
|
19
|
-
var _useContext3 = useContext(GarfishContext),
|
|
20
|
-
MApp = _useContext3.MApp,
|
|
21
|
-
appInfoList = _useContext3.appInfoList,
|
|
22
|
-
apps = _useContext3.apps;
|
|
23
|
-
|
|
24
|
-
logger('call useMicroApps', {
|
|
25
|
-
MApp: MApp,
|
|
26
|
-
apps: appInfoList,
|
|
27
|
-
Components: apps
|
|
28
|
-
});
|
|
29
|
-
return {
|
|
30
|
-
MApp: MApp,
|
|
31
|
-
apps: appInfoList,
|
|
32
|
-
Components: apps
|
|
33
|
-
};
|
|
34
42
|
}
|
|
@@ -1,38 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { CliHookCallbacks, CliPlugin } from '@modern-js/core';
|
|
2
2
|
export declare const externals: {
|
|
3
3
|
'react-dom': string;
|
|
4
4
|
react: string;
|
|
5
5
|
};
|
|
6
|
-
declare type
|
|
7
|
-
declare type NonVoidPromiseAble<T> = T extends void | Promise<any> ? never : T;
|
|
8
|
-
export declare type LifeCycle = NonVoidPromiseAble<ReturnType<Initializer>>;
|
|
9
|
-
export declare const resolvedConfig: NonNullable<LifeCycle['resolvedConfig']>;
|
|
10
|
-
export declare const initializer: (hooks: {
|
|
11
|
-
resolvedConfig: LifeCycle['resolvedConfig'];
|
|
12
|
-
validateSchema: LifeCycle['validateSchema'];
|
|
13
|
-
}, initializerConfig: {
|
|
14
|
-
runtimePluginName?: string;
|
|
15
|
-
defaultEnableHtmlEntry?: boolean;
|
|
16
|
-
defaultExternalBasicLibrary?: boolean;
|
|
17
|
-
}) => Initializer;
|
|
6
|
+
export declare type LifeCycle = CliHookCallbacks;
|
|
18
7
|
|
|
19
|
-
declare const _default:
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
validateSchema: import("@modern-js/core").ParallelWorkflow<void, unknown>;
|
|
25
|
-
prepare: import("@modern-js/core").AsyncWorkflow<void, void>;
|
|
26
|
-
commands: import("@modern-js/core").AsyncWorkflow<{
|
|
27
|
-
program: import("commander").Command;
|
|
28
|
-
}, void>;
|
|
29
|
-
watchFiles: import("@modern-js/core").ParallelWorkflow<void, unknown>;
|
|
30
|
-
fileChange: import("@modern-js/core").AsyncWorkflow<{
|
|
31
|
-
filename: string;
|
|
32
|
-
eventType: "add" | "unlink" | "change";
|
|
33
|
-
}, void>;
|
|
34
|
-
beforeExit: import("@modern-js/core").AsyncWorkflow<void, void>;
|
|
35
|
-
beforeRestart: import("@modern-js/core").AsyncWorkflow<void, void>;
|
|
36
|
-
} & import("@modern-js/core").ClearDraftProgress<import("@modern-js/core").Hooks>>>>;
|
|
8
|
+
declare const _default: ({
|
|
9
|
+
runtimePluginName
|
|
10
|
+
}?: {
|
|
11
|
+
runtimePluginName?: string | undefined;
|
|
12
|
+
}) => CliPlugin;
|
|
37
13
|
|
|
38
14
|
export default _default;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NormalizedConfig } from '@modern-js/core';
|
|
1
|
+
import type { NormalizedConfig } from '@modern-js/core';
|
|
2
2
|
export declare const makeProvider: () => string;
|
|
3
3
|
export declare const makeRenderFunction: (code: string) => string;
|
|
4
4
|
export declare function getRuntimeConfig(config: Partial<NormalizedConfig>): any;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { default } from './plugin';
|
|
2
|
-
export { useModuleApps,
|
|
2
|
+
export { useModuleApps, useModuleApp } from './useModuleApps';
|
|
3
3
|
export type { Manifest, ModuleInfo } from './useModuleApps';
|
|
4
4
|
export { default as Garfish } from 'garfish';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Config } from './useModuleApps';
|
|
3
|
-
declare const GarfishPlugin: (config: Config) => import("@modern-js/core").Plugin<
|
|
3
|
+
declare const GarfishPlugin: (config: Config) => import("@modern-js/core").Plugin<{
|
|
4
4
|
hoc: import("@modern-js/runtime-core").Pipeline<{
|
|
5
5
|
App: React.ComponentType<any>;
|
|
6
6
|
}, React.ComponentType<any>>;
|
|
@@ -25,5 +25,5 @@ declare const GarfishPlugin: (config: Config) => import("@modern-js/core").Plugi
|
|
|
25
25
|
context: import("@modern-js/runtime-core").RuntimeContext;
|
|
26
26
|
pickedContext: import("@modern-js/runtime-core").TRuntimeContext;
|
|
27
27
|
}, import("@modern-js/runtime-core").TRuntimeContext>;
|
|
28
|
-
}
|
|
28
|
+
}, Record<string, never>>;
|
|
29
29
|
export default GarfishPlugin;
|