@modern-js/plugin-garfish 1.3.1 → 1.4.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 +38 -0
- package/dist/js/modern/cli/index.js +91 -93
- package/dist/js/modern/cli/utils.js +84 -25
- package/dist/js/modern/runtime/plugin.js +10 -2
- package/dist/js/modern/runtime/utils/MApp.js +3 -3
- package/dist/js/modern/runtime/utils/apps.js +2 -5
- package/dist/js/node/cli/index.js +97 -91
- package/dist/js/node/cli/utils.js +89 -26
- package/dist/js/node/runtime/plugin.js +10 -2
- package/dist/js/node/runtime/utils/MApp.js +3 -3
- package/dist/js/node/runtime/utils/apps.js +2 -5
- package/dist/js/treeshaking/cli/index.js +235 -216
- package/dist/js/treeshaking/cli/utils.js +32 -3
- package/dist/js/treeshaking/runtime/plugin.js +14 -5
- package/dist/js/treeshaking/runtime/utils/MApp.js +3 -3
- package/dist/js/treeshaking/runtime/utils/apps.js +21 -22
- package/dist/types/cli/index.d.ts +18 -2
- package/dist/types/cli/utils.d.ts +4 -1
- package/package.json +9 -10
- package/tests/cli.test.tsx +215 -23
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
2
|
+
|
|
1
3
|
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
4
|
|
|
3
5
|
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; }
|
|
@@ -6,250 +8,267 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
6
8
|
|
|
7
9
|
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; }
|
|
8
10
|
|
|
11
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
12
|
+
|
|
13
|
+
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); }); }; }
|
|
14
|
+
|
|
9
15
|
import path from 'path';
|
|
10
|
-
import { createRuntimeExportsUtils,
|
|
16
|
+
import { createRuntimeExportsUtils, PLUGIN_SCHEMAS } from '@modern-js/utils';
|
|
11
17
|
import { createPlugin, useAppContext, useResolvedConfigContext } from '@modern-js/core';
|
|
12
18
|
import { logger } from "../util";
|
|
13
|
-
import { makeProvider, makeRenderFunction } from "./utils";
|
|
14
|
-
|
|
15
|
-
function getRuntimeConfig(config) {
|
|
16
|
-
var _config$runtime;
|
|
17
|
-
|
|
18
|
-
if (config !== null && config !== void 0 && (_config$runtime = config.runtime) !== null && _config$runtime !== void 0 && _config$runtime.feature) {
|
|
19
|
-
var _config$runtime2;
|
|
20
|
-
|
|
21
|
-
return config === null || config === void 0 ? void 0 : (_config$runtime2 = config.runtime) === null || _config$runtime2 === void 0 ? void 0 : _config$runtime2.feature;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return config === null || config === void 0 ? void 0 : config.runtime;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function setRuntimeConfig(config, key, value) {
|
|
28
|
-
var _config$runtime3, _config$runtime4;
|
|
29
|
-
|
|
30
|
-
if (config !== null && config !== void 0 && config.runtime && config !== null && config !== void 0 && config.runtime[key]) {
|
|
31
|
-
config.runtime[key] = value;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (config !== null && config !== void 0 && (_config$runtime3 = config.runtime) !== null && _config$runtime3 !== void 0 && _config$runtime3.feature && config !== null && config !== void 0 && (_config$runtime4 = config.runtime) !== null && _config$runtime4 !== void 0 && _config$runtime4.feature[key]) {
|
|
35
|
-
config.runtime.feature[key] = value;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
var externals = {
|
|
19
|
+
import { getRuntimeConfig, makeProvider, makeRenderFunction, setRuntimeConfig } from "./utils";
|
|
20
|
+
export var externals = {
|
|
40
21
|
'react-dom': 'react-dom',
|
|
41
22
|
react: 'react'
|
|
42
23
|
};
|
|
43
|
-
export
|
|
44
|
-
var
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}));
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
logger("resolvedConfig", {
|
|
67
|
-
runtime: nConfig.resolved.runtime,
|
|
68
|
-
deploy: nConfig.resolved.deploy,
|
|
69
|
-
server: nConfig.resolved.server
|
|
70
|
-
});
|
|
71
|
-
return nConfig;
|
|
72
|
-
},
|
|
73
|
-
config: function config() {
|
|
74
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
75
|
-
var config = useAppContext();
|
|
76
|
-
pluginsExportsUtils = createRuntimeExportsUtils(config.internalDirectory, 'plugins');
|
|
77
|
-
runtimeExportsUtils = createRuntimeExportsUtils(config.internalDirectory, 'index');
|
|
78
|
-
return {
|
|
79
|
-
source: {
|
|
80
|
-
alias: {
|
|
81
|
-
'@modern-js/runtime/plugins': pluginsExportsUtils.getPath()
|
|
82
|
-
}
|
|
83
|
-
},
|
|
84
|
-
tools: {
|
|
85
|
-
webpack: function webpack(webpackConfig, _ref) {
|
|
86
|
-
var _resolvedConfig$deplo, _resolveWebpackConfig;
|
|
87
|
-
|
|
88
|
-
var chain = _ref.chain,
|
|
89
|
-
_webpack = _ref.webpack;
|
|
90
|
-
var env = process.env.NODE_ENV; // eslint-disable-next-line react-hooks/rules-of-hooks
|
|
91
|
-
|
|
92
|
-
var resolvedConfig = useResolvedConfigContext();
|
|
93
|
-
|
|
94
|
-
if (resolvedConfig !== null && resolvedConfig !== void 0 && (_resolvedConfig$deplo = resolvedConfig.deploy) !== null && _resolvedConfig$deplo !== void 0 && _resolvedConfig$deplo.microFrontend) {
|
|
95
|
-
var _resolvedConfig$deplo2, _resolvedConfig$deplo3;
|
|
96
|
-
|
|
97
|
-
chain.output.libraryTarget('umd');
|
|
98
|
-
|
|
99
|
-
if (resolvedConfig.server.port) {
|
|
100
|
-
chain.output.publicPath(env === 'development' ? "//localhost:".concat(resolvedConfig.server.port, "/") : webpackConfig.output.publicPath);
|
|
101
|
-
} // add comments avoid sourcemap abnormal
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
chain.plugin('banner').use(_webpack.BannerPlugin, [{
|
|
105
|
-
banner: 'Micro front-end'
|
|
106
|
-
}]);
|
|
107
|
-
|
|
108
|
-
var _ref2 = _typeof(resolvedConfig === null || resolvedConfig === void 0 ? void 0 : (_resolvedConfig$deplo2 = resolvedConfig.deploy) === null || _resolvedConfig$deplo2 === void 0 ? void 0 : _resolvedConfig$deplo2.microFrontend) === 'object' ? resolvedConfig === null || resolvedConfig === void 0 ? void 0 : (_resolvedConfig$deplo3 = resolvedConfig.deploy) === null || _resolvedConfig$deplo3 === void 0 ? void 0 : _resolvedConfig$deplo3.microFrontend : {},
|
|
109
|
-
_ref2$enableHtmlEntry = _ref2.enableHtmlEntry,
|
|
110
|
-
enableHtmlEntry = _ref2$enableHtmlEntry === void 0 ? true : _ref2$enableHtmlEntry,
|
|
111
|
-
_ref2$externalBasicLi = _ref2.externalBasicLibrary,
|
|
112
|
-
externalBasicLibrary = _ref2$externalBasicLi === void 0 ? true : _ref2$externalBasicLi; // external
|
|
113
|
-
|
|
24
|
+
export var resolvedConfig = /*#__PURE__*/function () {
|
|
25
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(config) {
|
|
26
|
+
var resolved, _getRuntimeConfig, masterApp, router, nConfig, _router$historyOption;
|
|
27
|
+
|
|
28
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
29
|
+
while (1) {
|
|
30
|
+
switch (_context.prev = _context.next) {
|
|
31
|
+
case 0:
|
|
32
|
+
resolved = config.resolved;
|
|
33
|
+
_getRuntimeConfig = getRuntimeConfig(resolved), masterApp = _getRuntimeConfig.masterApp, router = _getRuntimeConfig.router;
|
|
34
|
+
nConfig = {
|
|
35
|
+
resolved: _objectSpread({}, resolved)
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
if (masterApp) {
|
|
39
|
+
// basename does not exist use router's basename
|
|
40
|
+
setRuntimeConfig(nConfig.resolved, 'masterApp', Object.assign(_typeof(masterApp) === 'object' ? _objectSpread({}, masterApp) : {}, {
|
|
41
|
+
basename: (router === null || router === void 0 ? void 0 : (_router$historyOption = router.historyOptions) === null || _router$historyOption === void 0 ? void 0 : _router$historyOption.basename) || '/'
|
|
42
|
+
}));
|
|
43
|
+
}
|
|
114
44
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
45
|
+
logger("resolvedConfig", {
|
|
46
|
+
runtime: nConfig.resolved.runtime,
|
|
47
|
+
deploy: nConfig.resolved.deploy,
|
|
48
|
+
server: nConfig.resolved.server
|
|
49
|
+
});
|
|
50
|
+
return _context.abrupt("return", nConfig);
|
|
118
51
|
|
|
52
|
+
case 6:
|
|
53
|
+
case "end":
|
|
54
|
+
return _context.stop();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}, _callee);
|
|
58
|
+
}));
|
|
119
59
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
60
|
+
return function resolvedConfig(_x) {
|
|
61
|
+
return _ref.apply(this, arguments);
|
|
62
|
+
};
|
|
63
|
+
}();
|
|
64
|
+
export var initializer = function initializer( // eslint-disable-next-line @typescript-eslint/no-shadow
|
|
65
|
+
_ref2, _ref3) {
|
|
66
|
+
var resolvedConfig = _ref2.resolvedConfig,
|
|
67
|
+
validateSchema = _ref2.validateSchema;
|
|
68
|
+
var _ref3$runtimePluginNa = _ref3.runtimePluginName,
|
|
69
|
+
runtimePluginName = _ref3$runtimePluginNa === void 0 ? '@modern-js/runtime/plugins' : _ref3$runtimePluginNa,
|
|
70
|
+
_ref3$defaultEnableHt = _ref3.defaultEnableHtmlEntry,
|
|
71
|
+
defaultEnableHtmlEntry = _ref3$defaultEnableHt === void 0 ? true : _ref3$defaultEnableHt,
|
|
72
|
+
_ref3$defaultExternal = _ref3.defaultExternalBasicLibrary,
|
|
73
|
+
defaultExternalBasicLibrary = _ref3$defaultExternal === void 0 ? false : _ref3$defaultExternal;
|
|
74
|
+
return function () {
|
|
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()
|
|
128
89
|
}
|
|
90
|
+
},
|
|
91
|
+
tools: {
|
|
92
|
+
webpack: function webpack(webpackConfig, _ref4) {
|
|
93
|
+
var _resolveOptions$deplo, _resolveWebpackConfig;
|
|
94
|
+
|
|
95
|
+
var chain = _ref4.chain,
|
|
96
|
+
_webpack = _ref4.webpack,
|
|
97
|
+
_ref4$env = _ref4.env,
|
|
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();
|
|
101
|
+
|
|
102
|
+
if (resolveOptions !== null && resolveOptions !== void 0 && (_resolveOptions$deplo = resolveOptions.deploy) !== null && _resolveOptions$deplo !== void 0 && _resolveOptions$deplo.microFrontend) {
|
|
103
|
+
var _resolveOptions$serve, _resolveOptions$deplo2, _resolveOptions$deplo3;
|
|
104
|
+
|
|
105
|
+
chain.output.libraryTarget('umd');
|
|
106
|
+
|
|
107
|
+
if (resolveOptions !== null && resolveOptions !== void 0 && (_resolveOptions$serve = resolveOptions.server) !== null && _resolveOptions$serve !== void 0 && _resolveOptions$serve.port) {
|
|
108
|
+
chain.output.publicPath(env === 'development' ? "//localhost:".concat(resolveOptions.server.port, "/") : webpackConfig.output.publicPath);
|
|
109
|
+
} // add comments avoid sourcemap abnormal
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
if (_webpack.BannerPlugin) {
|
|
113
|
+
chain.plugin('banner').use(_webpack.BannerPlugin, [{
|
|
114
|
+
banner: 'Micro front-end'
|
|
115
|
+
}]);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
var _ref5 = _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 : {},
|
|
119
|
+
_ref5$enableHtmlEntry = _ref5.enableHtmlEntry,
|
|
120
|
+
enableHtmlEntry = _ref5$enableHtmlEntry === void 0 ? defaultEnableHtmlEntry : _ref5$enableHtmlEntry,
|
|
121
|
+
_ref5$externalBasicLi = _ref5.externalBasicLibrary,
|
|
122
|
+
externalBasicLibrary = _ref5$externalBasicLi === void 0 ? defaultExternalBasicLibrary : _ref5$externalBasicLi; // external
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
if (externalBasicLibrary) {
|
|
126
|
+
chain.externals(externals);
|
|
127
|
+
} // use html mode
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
if (!enableHtmlEntry) {
|
|
131
|
+
chain.output.filename('index.js');
|
|
132
|
+
chain.plugins["delete"]('html-main');
|
|
133
|
+
chain.optimization.runtimeChunk(false);
|
|
134
|
+
chain.optimization.splitChunks({
|
|
135
|
+
chunks: 'async'
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
129
139
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
140
|
+
var resolveWebpackConfig = chain.toConfig();
|
|
141
|
+
logger('webpackConfig', {
|
|
142
|
+
output: resolveWebpackConfig.output,
|
|
143
|
+
externals: resolveWebpackConfig.externals,
|
|
144
|
+
env: env,
|
|
145
|
+
alias: (_resolveWebpackConfig = resolveWebpackConfig.resolve) === null || _resolveWebpackConfig === void 0 ? void 0 : _resolveWebpackConfig.alias
|
|
146
|
+
});
|
|
147
|
+
}
|
|
137
148
|
}
|
|
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
|
+
});
|
|
174
|
+
imports.push({
|
|
175
|
+
value: runtimePluginName,
|
|
176
|
+
specifiers: [{
|
|
177
|
+
imported: 'masterApp'
|
|
178
|
+
}]
|
|
179
|
+
});
|
|
138
180
|
}
|
|
139
|
-
|
|
140
|
-
},
|
|
141
|
-
addRuntimeExports: function addRuntimeExports() {
|
|
142
|
-
var mfPackage = path.resolve(__dirname, '../../../../');
|
|
143
|
-
var addExportStatement = "export { default as garfish } from '".concat(mfPackage, "'");
|
|
144
|
-
logger('exportStatement', addExportStatement);
|
|
145
|
-
pluginsExportsUtils.addExport(addExportStatement);
|
|
146
|
-
runtimeExportsUtils.addExport("export * from '".concat(mfPackage, "'"));
|
|
147
|
-
},
|
|
148
|
-
validateSchema: function validateSchema() {
|
|
149
|
-
return PLUGIN_SCHEMAS['@modern-js/plugin-garfish'];
|
|
150
|
-
},
|
|
151
|
-
modifyEntryImports: function modifyEntryImports(_ref3) {
|
|
152
|
-
var entrypoint = _ref3.entrypoint,
|
|
153
|
-
imports = _ref3.imports;
|
|
154
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
155
|
-
var resolvedConfig = useResolvedConfigContext(); // support legacy config
|
|
156
|
-
|
|
157
|
-
var _getRuntimeConfig2 = getRuntimeConfig(resolvedConfig),
|
|
158
|
-
masterApp = _getRuntimeConfig2.masterApp; // eslint-disable-next-line react-hooks/rules-of-hooks
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
var _useAppContext = useAppContext(),
|
|
162
|
-
packageName = _useAppContext.packageName;
|
|
163
|
-
|
|
164
|
-
var masterAppConfig = getEntryOptions(entrypoint.entryName, masterApp, resolvedConfig.runtimeByEntries, packageName);
|
|
165
|
-
configMap.set(entrypoint.entryName, masterAppConfig);
|
|
166
|
-
|
|
167
|
-
if (masterAppConfig) {
|
|
181
|
+
|
|
168
182
|
imports.push({
|
|
169
|
-
value: '
|
|
183
|
+
value: 'react-dom',
|
|
170
184
|
specifiers: [{
|
|
171
|
-
imported: '
|
|
185
|
+
imported: 'unmountComponentAtNode'
|
|
186
|
+
}, {
|
|
187
|
+
imported: 'createPortal'
|
|
172
188
|
}]
|
|
173
189
|
});
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
plugins.push({
|
|
197
|
-
name: 'garfish',
|
|
198
|
-
args: 'masterApp',
|
|
199
|
-
options: JSON.stringify(masterAppConfig)
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
return {
|
|
204
|
-
entrypoint: entrypoint,
|
|
205
|
-
plugins: plugins
|
|
206
|
-
};
|
|
207
|
-
},
|
|
208
|
-
modifyEntryRenderFunction: function modifyEntryRenderFunction(_ref5) {
|
|
209
|
-
var _config$deploy;
|
|
190
|
+
return {
|
|
191
|
+
imports: imports,
|
|
192
|
+
entrypoint: entrypoint
|
|
193
|
+
};
|
|
194
|
+
},
|
|
195
|
+
modifyEntryRuntimePlugins: function modifyEntryRuntimePlugins(_ref7) {
|
|
196
|
+
var entrypoint = _ref7.entrypoint,
|
|
197
|
+
plugins = _ref7.plugins;
|
|
198
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
199
|
+
var config = useResolvedConfigContext();
|
|
200
|
+
|
|
201
|
+
var _getRuntimeConfig3 = getRuntimeConfig(config),
|
|
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
|
+
}
|
|
210
212
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
213
|
+
return {
|
|
214
|
+
entrypoint: entrypoint,
|
|
215
|
+
plugins: plugins
|
|
216
|
+
};
|
|
217
|
+
},
|
|
218
|
+
modifyEntryRenderFunction: function modifyEntryRenderFunction(_ref8) {
|
|
219
|
+
var _config$deploy;
|
|
220
|
+
|
|
221
|
+
var entrypoint = _ref8.entrypoint,
|
|
222
|
+
code = _ref8.code;
|
|
223
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
224
|
+
var config = useResolvedConfigContext();
|
|
225
|
+
|
|
226
|
+
if (!(config !== null && config !== void 0 && (_config$deploy = config.deploy) !== null && _config$deploy !== void 0 && _config$deploy.microFrontend)) {
|
|
227
|
+
return {
|
|
228
|
+
entrypoint: entrypoint,
|
|
229
|
+
code: code
|
|
230
|
+
};
|
|
231
|
+
}
|
|
215
232
|
|
|
216
|
-
|
|
233
|
+
var nCode = makeRenderFunction(code);
|
|
234
|
+
logger('makeRenderFunction', nCode);
|
|
217
235
|
return {
|
|
218
236
|
entrypoint: entrypoint,
|
|
219
|
-
code:
|
|
237
|
+
code: nCode
|
|
220
238
|
};
|
|
221
|
-
}
|
|
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
|
+
return {
|
|
252
|
+
entrypoint: entrypoint,
|
|
253
|
+
exportStatement: exportStatementCode
|
|
254
|
+
};
|
|
255
|
+
}
|
|
222
256
|
|
|
223
|
-
var nCode = makeRenderFunction(code);
|
|
224
|
-
logger('makeRenderFunction', nCode);
|
|
225
|
-
return {
|
|
226
|
-
entrypoint: entrypoint,
|
|
227
|
-
code: nCode
|
|
228
|
-
};
|
|
229
|
-
},
|
|
230
|
-
modifyEntryExport: function modifyEntryExport(_ref6) {
|
|
231
|
-
var _resolvedConfig$deplo4;
|
|
232
|
-
|
|
233
|
-
var entrypoint = _ref6.entrypoint,
|
|
234
|
-
exportStatement = _ref6.exportStatement;
|
|
235
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
236
|
-
var resolvedConfig = useResolvedConfigContext();
|
|
237
|
-
|
|
238
|
-
if (resolvedConfig !== null && resolvedConfig !== void 0 && (_resolvedConfig$deplo4 = resolvedConfig.deploy) !== null && _resolvedConfig$deplo4 !== void 0 && _resolvedConfig$deplo4.microFrontend) {
|
|
239
|
-
var exportStatementCode = makeProvider();
|
|
240
|
-
logger('exportStatement', exportStatementCode);
|
|
241
257
|
return {
|
|
242
258
|
entrypoint: entrypoint,
|
|
243
|
-
exportStatement:
|
|
259
|
+
exportStatement: exportStatement
|
|
244
260
|
};
|
|
245
261
|
}
|
|
246
|
-
|
|
247
|
-
return {
|
|
248
|
-
entrypoint: entrypoint,
|
|
249
|
-
exportStatement: exportStatement
|
|
250
|
-
};
|
|
251
|
-
}
|
|
262
|
+
};
|
|
252
263
|
};
|
|
264
|
+
};
|
|
265
|
+
export default createPlugin(initializer({
|
|
266
|
+
resolvedConfig: resolvedConfig,
|
|
267
|
+
validateSchema: function validateSchema() {
|
|
268
|
+
return PLUGIN_SCHEMAS['@modern-js/plugin-garfish'];
|
|
269
|
+
}
|
|
253
270
|
}, {
|
|
271
|
+
runtimePluginName: '@modern-js/runtime/plugins'
|
|
272
|
+
}), {
|
|
254
273
|
name: '@modern-js/plugin-garfish'
|
|
255
274
|
});
|
|
@@ -1,6 +1,35 @@
|
|
|
1
1
|
export var makeProvider = function makeProvider() {
|
|
2
|
-
return "\
|
|
2
|
+
return "\nexport const provider = function ({basename, dom, ...props}) {\n return {\n render({basename, dom}) {\n console.log('App.config', App.config);\n const SubApp = render({props, basename});\n const node = dom.querySelector('#' + MOUNT_ID) || dom;\n bootstrap(SubApp, 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
|
-
|
|
6
|
-
|
|
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 ";
|
|
6
|
+
return inGarfishToRender + code.replace("router(", "RouterPlugin(").replace('IS_BROWSER', "IS_BROWSER && !renderByGarfish");
|
|
7
|
+
}; // support legacy config
|
|
8
|
+
|
|
9
|
+
export function getRuntimeConfig(config) {
|
|
10
|
+
var _config$runtime;
|
|
11
|
+
|
|
12
|
+
if (config !== null && config !== void 0 && (_config$runtime = config.runtime) !== null && _config$runtime !== void 0 && _config$runtime.features) {
|
|
13
|
+
var _config$runtime2;
|
|
14
|
+
|
|
15
|
+
return config === null || config === void 0 ? void 0 : (_config$runtime2 = config.runtime) === null || _config$runtime2 === void 0 ? void 0 : _config$runtime2.features;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return config === null || config === void 0 ? void 0 : config.runtime;
|
|
19
|
+
} // support legacy config
|
|
20
|
+
|
|
21
|
+
export function setRuntimeConfig(config, key, value) {
|
|
22
|
+
var _config$runtime3, _config$runtime4;
|
|
23
|
+
|
|
24
|
+
if (config !== null && config !== void 0 && (_config$runtime3 = config.runtime) !== null && _config$runtime3 !== void 0 && _config$runtime3.features && config !== null && config !== void 0 && (_config$runtime4 = config.runtime) !== null && _config$runtime4 !== void 0 && _config$runtime4.features[key]) {
|
|
25
|
+
config.runtime.features[key] = value;
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (config !== null && config !== void 0 && config.runtime && config !== null && config !== void 0 && config.runtime[key]) {
|
|
30
|
+
config.runtime[key] = value;
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
@@ -60,6 +60,7 @@ function _initOptions() {
|
|
|
60
60
|
var manifest,
|
|
61
61
|
options,
|
|
62
62
|
apps,
|
|
63
|
+
getAppList,
|
|
63
64
|
_window3,
|
|
64
65
|
_window3$modern_manif,
|
|
65
66
|
_args2 = arguments;
|
|
@@ -73,13 +74,16 @@ function _initOptions() {
|
|
|
73
74
|
apps = options.apps || []; // use manifest modules
|
|
74
75
|
|
|
75
76
|
if (manifest !== null && manifest !== void 0 && manifest.modules) {
|
|
76
|
-
|
|
77
|
+
if ((manifest === null || manifest === void 0 ? void 0 : manifest.modules.length) > 0) {
|
|
78
|
+
apps = manifest === null || manifest === void 0 ? void 0 : manifest.modules;
|
|
79
|
+
}
|
|
80
|
+
|
|
77
81
|
logger('manifest modules', apps);
|
|
78
82
|
} // get module list
|
|
79
83
|
|
|
80
84
|
|
|
81
85
|
if (!(manifest !== null && manifest !== void 0 && manifest.getAppList)) {
|
|
82
|
-
_context2.next =
|
|
86
|
+
_context2.next = 10;
|
|
83
87
|
break;
|
|
84
88
|
}
|
|
85
89
|
|
|
@@ -87,10 +91,15 @@ function _initOptions() {
|
|
|
87
91
|
return manifest === null || manifest === void 0 ? void 0 : manifest.getAppList();
|
|
88
92
|
|
|
89
93
|
case 7:
|
|
90
|
-
|
|
94
|
+
getAppList = _context2.sent;
|
|
95
|
+
|
|
96
|
+
if (getAppList.length > 0) {
|
|
97
|
+
apps = getAppList;
|
|
98
|
+
}
|
|
99
|
+
|
|
91
100
|
logger('getAppList modules', apps);
|
|
92
101
|
|
|
93
|
-
case
|
|
102
|
+
case 10:
|
|
94
103
|
// get inject modules list
|
|
95
104
|
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) {
|
|
96
105
|
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;
|
|
@@ -101,7 +110,7 @@ function _initOptions() {
|
|
|
101
110
|
apps: apps
|
|
102
111
|
}));
|
|
103
112
|
|
|
104
|
-
case
|
|
113
|
+
case 12:
|
|
105
114
|
case "end":
|
|
106
115
|
return _context2.stop();
|
|
107
116
|
}
|
|
@@ -108,7 +108,7 @@ export function generateMApp(options, manifest) {
|
|
|
108
108
|
args[_key4 - 1] = arguments[_key4];
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
logger('MApp errorLoadApp', args);
|
|
111
|
+
logger('MApp errorLoadApp', error, args);
|
|
112
112
|
setLoadingState({
|
|
113
113
|
error: error
|
|
114
114
|
});
|
|
@@ -119,7 +119,7 @@ export function generateMApp(options, manifest) {
|
|
|
119
119
|
args[_key5 - 1] = arguments[_key5];
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
logger('MApp errorMountApp', args);
|
|
122
|
+
logger('MApp errorMountApp', error, args);
|
|
123
123
|
setLoadingState({
|
|
124
124
|
error: error
|
|
125
125
|
});
|
|
@@ -130,7 +130,7 @@ export function generateMApp(options, manifest) {
|
|
|
130
130
|
args[_key6 - 1] = arguments[_key6];
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
-
logger('MApp errorUnmountApp', args);
|
|
133
|
+
logger('MApp errorUnmountApp', error, args);
|
|
134
134
|
setLoadingState({
|
|
135
135
|
error: error
|
|
136
136
|
});
|