@modern-js/plugin-garfish 1.4.2 → 1.4.4-beta.2
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 +8 -6
- 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 +201 -218
- package/dist/js/node/cli/utils.js +8 -6
- 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 +217 -221
- package/dist/js/treeshaking/cli/utils.js +2 -2
- 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 +9 -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 +6 -6
- 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,257 @@ 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
|
-
|
|
76
|
-
|
|
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
|
+
_ref$mfPackagePath = _ref.mfPackagePath,
|
|
28
|
+
mfPackagePath = _ref$mfPackagePath === void 0 ? path.resolve(__dirname, '../../../../') : _ref$mfPackagePath;
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
name: '@modern-js/plugin-garfish',
|
|
32
|
+
setup: function setup(_ref2) {
|
|
33
|
+
var useAppContext = _ref2.useAppContext,
|
|
34
|
+
useResolvedConfigContext = _ref2.useResolvedConfigContext;
|
|
35
|
+
var pluginsExportsUtils;
|
|
36
|
+
var runtimeExportsUtils;
|
|
37
|
+
return {
|
|
38
|
+
validateSchema: function validateSchema() {
|
|
39
|
+
return PLUGIN_SCHEMAS['@modern-js/plugin-garfish'];
|
|
40
|
+
},
|
|
41
|
+
resolvedConfig: function () {
|
|
42
|
+
var _resolvedConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(config) {
|
|
43
|
+
var resolved, _getRuntimeConfig, masterApp, router, nConfig, _router$historyOption;
|
|
44
|
+
|
|
45
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
46
|
+
while (1) {
|
|
47
|
+
switch (_context.prev = _context.next) {
|
|
48
|
+
case 0:
|
|
49
|
+
resolved = config.resolved;
|
|
50
|
+
_getRuntimeConfig = getRuntimeConfig(resolved), masterApp = _getRuntimeConfig.masterApp, router = _getRuntimeConfig.router;
|
|
51
|
+
nConfig = {
|
|
52
|
+
resolved: _objectSpread({}, resolved)
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
if (masterApp) {
|
|
56
|
+
// basename does not exist use router's basename
|
|
57
|
+
setRuntimeConfig(nConfig.resolved, 'masterApp', Object.assign(_typeof(masterApp) === 'object' ? _objectSpread({}, masterApp) : {}, {
|
|
58
|
+
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) || '/'
|
|
59
|
+
}));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
logger("resolvedConfig", {
|
|
63
|
+
runtime: nConfig.resolved.runtime,
|
|
64
|
+
deploy: nConfig.resolved.deploy,
|
|
65
|
+
server: nConfig.resolved.server
|
|
66
|
+
});
|
|
67
|
+
return _context.abrupt("return", nConfig);
|
|
68
|
+
|
|
69
|
+
case 6:
|
|
70
|
+
case "end":
|
|
71
|
+
return _context.stop();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}, _callee);
|
|
75
|
+
}));
|
|
94
76
|
|
|
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();
|
|
77
|
+
function resolvedConfig(_x) {
|
|
78
|
+
return _resolvedConfig.apply(this, arguments);
|
|
79
|
+
}
|
|
101
80
|
|
|
102
|
-
|
|
103
|
-
|
|
81
|
+
return resolvedConfig;
|
|
82
|
+
}(),
|
|
83
|
+
config: function config() {
|
|
84
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
85
|
+
var config = useAppContext(); // eslint-disable-next-line react-hooks/rules-of-hooks
|
|
104
86
|
|
|
105
|
-
|
|
87
|
+
var resolveOptions = useResolvedConfigContext();
|
|
88
|
+
pluginsExportsUtils = createRuntimeExportsUtils(config.internalDirectory, 'plugins');
|
|
89
|
+
runtimeExportsUtils = createRuntimeExportsUtils(config.internalDirectory, 'index');
|
|
90
|
+
return {
|
|
91
|
+
source: {
|
|
92
|
+
alias: {
|
|
93
|
+
'@modern-js/runtime/plugins': pluginsExportsUtils.getPath()
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
tools: {
|
|
97
|
+
webpack: function webpack(webpackConfig, _ref3) {
|
|
98
|
+
var _resolveOptions$deplo, _resolveWebpackConfig;
|
|
99
|
+
|
|
100
|
+
var chain = _ref3.chain,
|
|
101
|
+
_webpack = _ref3.webpack,
|
|
102
|
+
_ref3$env = _ref3.env,
|
|
103
|
+
env = _ref3$env === void 0 ? process.env.NODE_ENV || 'development' : _ref3$env;
|
|
104
|
+
|
|
105
|
+
if (resolveOptions !== null && resolveOptions !== void 0 && (_resolveOptions$deplo = resolveOptions.deploy) !== null && _resolveOptions$deplo !== void 0 && _resolveOptions$deplo.microFrontend) {
|
|
106
|
+
var _resolveOptions$serve, _resolveOptions$deplo2, _resolveOptions$deplo3;
|
|
107
|
+
|
|
108
|
+
chain.output.libraryTarget('umd');
|
|
109
|
+
chain.devServer.headers({
|
|
110
|
+
'Access-Control-Allow-Origin': '*'
|
|
111
|
+
});
|
|
106
112
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
113
|
+
if (resolveOptions !== null && resolveOptions !== void 0 && (_resolveOptions$serve = resolveOptions.server) !== null && _resolveOptions$serve !== void 0 && _resolveOptions$serve.port) {
|
|
114
|
+
chain.output.publicPath(env === 'development' ? "//localhost:".concat(resolveOptions.server.port, "/") : webpackConfig.output.publicPath);
|
|
115
|
+
} // add comments avoid sourcemap abnormal
|
|
110
116
|
|
|
111
117
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
118
|
+
if (_webpack.BannerPlugin) {
|
|
119
|
+
chain.plugin('banner').use(_webpack.BannerPlugin, [{
|
|
120
|
+
banner: 'Micro front-end'
|
|
121
|
+
}]);
|
|
122
|
+
}
|
|
117
123
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
124
|
+
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 : {},
|
|
125
|
+
_ref4$enableHtmlEntry = _ref4.enableHtmlEntry,
|
|
126
|
+
enableHtmlEntry = _ref4$enableHtmlEntry === void 0 ? true : _ref4$enableHtmlEntry,
|
|
127
|
+
_ref4$externalBasicLi = _ref4.externalBasicLibrary,
|
|
128
|
+
externalBasicLibrary = _ref4$externalBasicLi === void 0 ? false : _ref4$externalBasicLi; // external
|
|
123
129
|
|
|
124
130
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
131
|
+
if (externalBasicLibrary) {
|
|
132
|
+
chain.externals(externals);
|
|
133
|
+
} // use html mode
|
|
128
134
|
|
|
129
135
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
136
|
+
if (!enableHtmlEntry) {
|
|
137
|
+
chain.output.filename('index.js');
|
|
138
|
+
chain.plugins["delete"]('html-main');
|
|
139
|
+
chain.optimization.runtimeChunk(false);
|
|
140
|
+
chain.optimization.splitChunks({
|
|
141
|
+
chunks: 'async'
|
|
142
|
+
});
|
|
143
|
+
}
|
|
137
144
|
}
|
|
138
|
-
}
|
|
139
145
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
146
|
+
var resolveWebpackConfig = chain.toConfig();
|
|
147
|
+
logger('webpackConfig', {
|
|
148
|
+
output: resolveWebpackConfig.output,
|
|
149
|
+
externals: resolveWebpackConfig.externals,
|
|
150
|
+
env: env,
|
|
151
|
+
alias: (_resolveWebpackConfig = resolveWebpackConfig.resolve) === null || _resolveWebpackConfig === void 0 ? void 0 : _resolveWebpackConfig.alias
|
|
152
|
+
});
|
|
153
|
+
}
|
|
147
154
|
}
|
|
155
|
+
};
|
|
156
|
+
},
|
|
157
|
+
addRuntimeExports: function addRuntimeExports() {
|
|
158
|
+
var addExportStatement = "export { default as garfish, default as masterApp } from '".concat(mfPackagePath, "'");
|
|
159
|
+
logger('exportStatement', addExportStatement);
|
|
160
|
+
pluginsExportsUtils.addExport(addExportStatement);
|
|
161
|
+
runtimeExportsUtils.addExport("export * from '".concat(mfPackagePath, "'"));
|
|
162
|
+
},
|
|
163
|
+
modifyEntryImports: function modifyEntryImports(_ref5) {
|
|
164
|
+
var entrypoint = _ref5.entrypoint,
|
|
165
|
+
imports = _ref5.imports;
|
|
166
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
167
|
+
var config = useResolvedConfigContext();
|
|
168
|
+
|
|
169
|
+
var _getRuntimeConfig2 = getRuntimeConfig(config),
|
|
170
|
+
masterApp = _getRuntimeConfig2.masterApp;
|
|
171
|
+
|
|
172
|
+
if (masterApp) {
|
|
173
|
+
imports.push({
|
|
174
|
+
value: runtimePluginName,
|
|
175
|
+
specifiers: [{
|
|
176
|
+
imported: 'garfish'
|
|
177
|
+
}]
|
|
178
|
+
});
|
|
179
|
+
imports.push({
|
|
180
|
+
value: runtimePluginName,
|
|
181
|
+
specifiers: [{
|
|
182
|
+
imported: 'masterApp'
|
|
183
|
+
}]
|
|
184
|
+
});
|
|
148
185
|
}
|
|
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
|
-
});
|
|
186
|
+
|
|
174
187
|
imports.push({
|
|
175
|
-
value:
|
|
188
|
+
value: 'react-dom',
|
|
176
189
|
specifiers: [{
|
|
177
|
-
imported: '
|
|
190
|
+
imported: 'unmountComponentAtNode'
|
|
191
|
+
}, {
|
|
192
|
+
imported: 'createPortal'
|
|
178
193
|
}]
|
|
179
194
|
});
|
|
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;
|
|
195
|
+
return {
|
|
196
|
+
imports: imports,
|
|
197
|
+
entrypoint: entrypoint
|
|
198
|
+
};
|
|
199
|
+
},
|
|
200
|
+
modifyEntryRuntimePlugins: function modifyEntryRuntimePlugins(_ref6) {
|
|
201
|
+
var entrypoint = _ref6.entrypoint,
|
|
202
|
+
plugins = _ref6.plugins;
|
|
203
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
204
|
+
var config = useResolvedConfigContext();
|
|
205
|
+
|
|
206
|
+
var _getRuntimeConfig3 = getRuntimeConfig(config),
|
|
207
|
+
masterApp = _getRuntimeConfig3.masterApp;
|
|
208
|
+
|
|
209
|
+
if (masterApp) {
|
|
210
|
+
logger('garfishPlugin options', masterApp);
|
|
211
|
+
plugins.push({
|
|
212
|
+
name: 'garfish',
|
|
213
|
+
args: 'masterApp',
|
|
214
|
+
options: masterApp === true ? JSON.stringify({}) : JSON.stringify(masterApp)
|
|
215
|
+
});
|
|
216
|
+
}
|
|
220
217
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
218
|
+
return {
|
|
219
|
+
entrypoint: entrypoint,
|
|
220
|
+
plugins: plugins
|
|
221
|
+
};
|
|
222
|
+
},
|
|
223
|
+
modifyEntryRenderFunction: function modifyEntryRenderFunction(_ref7) {
|
|
224
|
+
var _config$deploy;
|
|
225
|
+
|
|
226
|
+
var entrypoint = _ref7.entrypoint,
|
|
227
|
+
code = _ref7.code;
|
|
228
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
229
|
+
var config = useResolvedConfigContext();
|
|
230
|
+
|
|
231
|
+
if (!(config !== null && config !== void 0 && (_config$deploy = config.deploy) !== null && _config$deploy !== void 0 && _config$deploy.microFrontend)) {
|
|
232
|
+
return {
|
|
233
|
+
entrypoint: entrypoint,
|
|
234
|
+
code: code
|
|
235
|
+
};
|
|
236
|
+
}
|
|
225
237
|
|
|
226
|
-
|
|
238
|
+
var nCode = makeRenderFunction(code);
|
|
239
|
+
logger('makeRenderFunction', nCode);
|
|
227
240
|
return {
|
|
228
241
|
entrypoint: entrypoint,
|
|
229
|
-
code:
|
|
242
|
+
code: nCode
|
|
230
243
|
};
|
|
231
|
-
}
|
|
244
|
+
},
|
|
245
|
+
modifyEntryExport: function modifyEntryExport(_ref8) {
|
|
246
|
+
var _config$deploy2;
|
|
247
|
+
|
|
248
|
+
var entrypoint = _ref8.entrypoint,
|
|
249
|
+
exportStatement = _ref8.exportStatement;
|
|
250
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
251
|
+
var config = useResolvedConfigContext();
|
|
252
|
+
|
|
253
|
+
if (config !== null && config !== void 0 && (_config$deploy2 = config.deploy) !== null && _config$deploy2 !== void 0 && _config$deploy2.microFrontend) {
|
|
254
|
+
var exportStatementCode = makeProvider();
|
|
255
|
+
logger('exportStatement', exportStatementCode);
|
|
256
|
+
return {
|
|
257
|
+
entrypoint: entrypoint,
|
|
258
|
+
exportStatement: exportStatementCode
|
|
259
|
+
};
|
|
260
|
+
}
|
|
232
261
|
|
|
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
262
|
return {
|
|
252
263
|
entrypoint: entrypoint,
|
|
253
|
-
exportStatement:
|
|
264
|
+
exportStatement: exportStatement
|
|
254
265
|
};
|
|
255
266
|
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
entrypoint: entrypoint,
|
|
259
|
-
exportStatement: exportStatement
|
|
260
|
-
};
|
|
261
|
-
}
|
|
262
|
-
};
|
|
267
|
+
};
|
|
268
|
+
}
|
|
263
269
|
};
|
|
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
270
|
});
|
|
@@ -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 ";
|
|
@@ -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) {
|
|
@@ -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,16 @@
|
|
|
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
|
-
|
|
25
|
-
|
|
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
|
+
mfPackagePath
|
|
11
|
+
}?: {
|
|
12
|
+
runtimePluginName?: string | undefined;
|
|
13
|
+
mfPackagePath?: string | undefined;
|
|
14
|
+
}) => CliPlugin;
|
|
37
15
|
|
|
38
16
|
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';
|