@modern-js/plugin-garfish 2.27.0 → 2.29.0

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.
@@ -33,15 +33,15 @@ export function pathJoin() {
33
33
  }
34
34
  function getAppInstance(options, appInfo, manifest) {
35
35
  var MicroApp = function MicroApp2(props) {
36
- var _context_router, _context_router_useRouteMatch, _context_router1, _context_router_useMatches, _context_router2, _context_router_useLocation;
36
+ var _context_router_useRouteMatch, _context_router, _context, _context_router_useMatches, _context_router1, _context1, _context_router_useLocation, _context_router2, _context2, _options;
37
37
  var appRef = useRef(null);
38
38
  var domId = generateSubAppContainerKey(appInfo);
39
39
  var _useState = _sliced_to_array(useState(), 2), SubModuleComponent = _useState[0], setSubModuleComponent = _useState[1];
40
40
  var context = useContext(RuntimeReactContext);
41
- var match = context === null || context === void 0 ? void 0 : (_context_router = context.router) === null || _context_router === void 0 ? void 0 : (_context_router_useRouteMatch = _context_router.useRouteMatch) === null || _context_router_useRouteMatch === void 0 ? void 0 : _context_router_useRouteMatch.call(_context_router);
42
- var matchs = context === null || context === void 0 ? void 0 : (_context_router1 = context.router) === null || _context_router1 === void 0 ? void 0 : (_context_router_useMatches = _context_router1.useMatches) === null || _context_router_useMatches === void 0 ? void 0 : _context_router_useMatches.call(_context_router1);
43
- var location = context === null || context === void 0 ? void 0 : (_context_router2 = context.router) === null || _context_router2 === void 0 ? void 0 : (_context_router_useLocation = _context_router2.useLocation) === null || _context_router_useLocation === void 0 ? void 0 : _context_router_useLocation.call(_context_router2);
44
- var basename = (options === null || options === void 0 ? void 0 : options.basename) || "/";
41
+ var match = (_context = context) === null || _context === void 0 ? void 0 : (_context_router = _context.router) === null || _context_router === void 0 ? void 0 : (_context_router_useRouteMatch = _context_router.useRouteMatch) === null || _context_router_useRouteMatch === void 0 ? void 0 : _context_router_useRouteMatch.call(_context_router);
42
+ var matchs = (_context1 = context) === null || _context1 === void 0 ? void 0 : (_context_router1 = _context1.router) === null || _context_router1 === void 0 ? void 0 : (_context_router_useMatches = _context_router1.useMatches) === null || _context_router_useMatches === void 0 ? void 0 : _context_router_useMatches.call(_context_router1);
43
+ var location = (_context2 = context) === null || _context2 === void 0 ? void 0 : (_context_router2 = _context2.router) === null || _context_router2 === void 0 ? void 0 : (_context_router_useLocation = _context_router2.useLocation) === null || _context_router_useLocation === void 0 ? void 0 : _context_router_useLocation.call(_context_router2);
44
+ var basename = ((_options = options) === null || _options === void 0 ? void 0 : _options.basename) || "/";
45
45
  if (matchs && matchs.length > 0) {
46
46
  var matchItem = _object_spread({}, matchs[matchs.length - 1]);
47
47
  for (var key in matchItem.params) {
@@ -49,7 +49,8 @@ function getAppInstance(options, appInfo, manifest) {
49
49
  }
50
50
  basename = pathJoin(basename, matchItem.pathname || "/");
51
51
  } else if (match) {
52
- basename = pathJoin(basename, (match === null || match === void 0 ? void 0 : match.path) || "/");
52
+ var _match;
53
+ basename = pathJoin(basename, ((_match = match) === null || _match === void 0 ? void 0 : _match.path) || "/");
53
54
  }
54
55
  useEffect(function() {
55
56
  if (location && locationHref !== location.pathname && !Garfish.running) {
@@ -75,8 +76,9 @@ function getAppInstance(options, appInfo, manifest) {
75
76
  cache: true,
76
77
  props: _object_spread({}, appInfo.props, userProps),
77
78
  customLoader: function(provider) {
79
+ var _manifest2;
78
80
  var render = provider.render, destroy = provider.destroy, SubModuleComponent2 = provider.SubModuleComponent, jupiter_submodule_app_key = provider.jupiter_submodule_app_key;
79
- var componetRenderMode = (manifest === null || manifest === void 0 ? void 0 : manifest.componentRender) && (SubModuleComponent2 || jupiter_submodule_app_key);
81
+ var componetRenderMode = ((_manifest2 = manifest) === null || _manifest2 === void 0 ? void 0 : _manifest2.componentRender) && (SubModuleComponent2 || jupiter_submodule_app_key);
80
82
  return {
81
83
  mount: function() {
82
84
  for (var _len = arguments.length, _$props = new Array(_len), _key = 0; _key < _len; _key++) {
@@ -86,19 +88,21 @@ function getAppInstance(options, appInfo, manifest) {
86
88
  setSubModuleComponent(SubModuleComponent2);
87
89
  return void 0;
88
90
  } else {
91
+ var _render;
89
92
  logger("MicroApp customer render", _$props);
90
- return render === null || render === void 0 ? void 0 : render.apply(provider, _$props);
93
+ return (_render = render) === null || _render === void 0 ? void 0 : _render.apply(provider, _$props);
91
94
  }
92
95
  },
93
96
  unmount: function unmount() {
94
97
  for (var _len = arguments.length, _$props = new Array(_len), _key = 0; _key < _len; _key++) {
95
98
  _$props[_key] = arguments[_key];
96
99
  }
100
+ var _destroy;
97
101
  if (componetRenderMode) {
98
102
  return void 0;
99
103
  }
100
104
  logger("MicroApp customer destroy", _$props);
101
- return destroy === null || destroy === void 0 ? void 0 : destroy.apply(provider, _$props);
105
+ return (_destroy = destroy) === null || _destroy === void 0 ? void 0 : _destroy.apply(provider, _$props);
102
106
  }
103
107
  };
104
108
  }
@@ -115,7 +119,7 @@ function getAppInstance(options, appInfo, manifest) {
115
119
  }
116
120
  function _renderApp() {
117
121
  _renderApp = _async_to_generator(function() {
118
- var appInstance, error;
122
+ var appInstance, _appInstance, _appInstance1, error;
119
123
  return _ts_generator(this, function(_state) {
120
124
  switch (_state.label) {
121
125
  case 0:
@@ -149,7 +153,7 @@ function getAppInstance(options, appInfo, manifest) {
149
153
  });
150
154
  return [
151
155
  4,
152
- appInstance === null || appInstance === void 0 ? void 0 : appInstance.show()
156
+ (_appInstance = appInstance) === null || _appInstance === void 0 ? void 0 : _appInstance.show()
153
157
  ];
154
158
  case 2:
155
159
  _state.sent();
@@ -164,7 +168,7 @@ function getAppInstance(options, appInfo, manifest) {
164
168
  });
165
169
  return [
166
170
  4,
167
- appInstance === null || appInstance === void 0 ? void 0 : appInstance.mount()
171
+ (_appInstance1 = appInstance) === null || _appInstance1 === void 0 ? void 0 : _appInstance1.mount()
168
172
  ];
169
173
  case 4:
170
174
  _state.sent();
@@ -216,8 +220,9 @@ function getAppInstance(options, appInfo, manifest) {
216
220
  })
217
221
  });
218
222
  };
223
+ var _manifest;
219
224
  var locationHref = "";
220
- return Loadable(MicroApp)(manifest === null || manifest === void 0 ? void 0 : manifest.loadable);
225
+ return Loadable(MicroApp)((_manifest = manifest) === null || _manifest === void 0 ? void 0 : _manifest.loadable);
221
226
  }
222
227
  export function generateApps(options, manifest) {
223
228
  var _options_apps;
package/dist/esm/util.js CHANGED
@@ -2,5 +2,6 @@ import createDebug from "debug";
2
2
  export var logger = createDebug("modern-js:plugin-garfish");
3
3
  export var SUBMODULE_APP_COMPONENT_KEY = "SubModuleComponent";
4
4
  export function generateSubAppContainerKey(moduleInfo) {
5
- return moduleInfo ? "modern_sub_app_container_".concat(decodeURIComponent(moduleInfo === null || moduleInfo === void 0 ? void 0 : moduleInfo.name)) : "modern_sub_app_container";
5
+ var _moduleInfo;
6
+ return moduleInfo ? "modern_sub_app_container_".concat(decodeURIComponent((_moduleInfo = moduleInfo) === null || _moduleInfo === void 0 ? void 0 : _moduleInfo.name)) : "modern_sub_app_container";
6
7
  }
@@ -19,286 +19,284 @@ export function getDefaultMicroFrontedConfig(microFrontend) {
19
19
  ...microFrontend
20
20
  };
21
21
  }
22
- export const garfishPlugin = ({ pluginName = "@modern-js/plugin-garfish", runtimePluginName = "@modern-js/runtime/plugins" } = {}) => {
23
- return {
24
- name: "@modern-js/plugin-garfish",
25
- setup: ({ useAppContext, useResolvedConfigContext, useConfigContext }) => {
26
- let pluginsExportsUtils;
27
- return {
28
- validateSchema() {
29
- return [
30
- {
31
- target: "runtime.masterApp",
32
- schema: {
33
- type: [
34
- "boolean",
35
- "object"
36
- ]
37
- }
38
- },
39
- {
40
- target: "dev.withMasterApp",
41
- schema: {
42
- type: [
43
- "object"
44
- ]
45
- }
46
- },
47
- {
48
- target: "deploy.microFrontend",
49
- schema: {
50
- type: [
51
- "boolean",
52
- "object"
53
- ]
54
- }
22
+ export const garfishPlugin = ({ pluginName = "@modern-js/plugin-garfish", runtimePluginName = "@modern-js/runtime/plugins" } = {}) => ({
23
+ name: "@modern-js/plugin-garfish",
24
+ setup: ({ useAppContext, useResolvedConfigContext, useConfigContext }) => {
25
+ let pluginsExportsUtils;
26
+ return {
27
+ validateSchema() {
28
+ return [
29
+ {
30
+ target: "runtime.masterApp",
31
+ schema: {
32
+ type: [
33
+ "boolean",
34
+ "object"
35
+ ]
55
36
  }
56
- ];
57
- },
58
- resolvedConfig: async (config) => {
59
- const { resolved } = config;
60
- const { masterApp, router } = getRuntimeConfig(resolved);
61
- const nConfig = {
62
- resolved: {
63
- ...resolved
37
+ },
38
+ {
39
+ target: "dev.withMasterApp",
40
+ schema: {
41
+ type: [
42
+ "object"
43
+ ]
64
44
  }
65
- };
66
- if (masterApp) {
67
- var _useConfig_server, _router_historyOptions;
68
- const useConfig = useConfigContext();
69
- const baseUrl = useConfig === null || useConfig === void 0 ? void 0 : (_useConfig_server = useConfig.server) === null || _useConfig_server === void 0 ? void 0 : _useConfig_server.baseUrl;
70
- if (Array.isArray(baseUrl)) {
71
- throw new Error("Now Micro-Front-End mode dose not support multiple baseUrl, you can set it as a string");
45
+ },
46
+ {
47
+ target: "deploy.microFrontend",
48
+ schema: {
49
+ type: [
50
+ "boolean",
51
+ "object"
52
+ ]
72
53
  }
73
- setRuntimeConfig(nConfig.resolved, "masterApp", Object.assign(typeof masterApp === "object" ? {
74
- ...masterApp
75
- } : {}, {
76
- basename: baseUrl || (router === null || router === void 0 ? void 0 : (_router_historyOptions = router.historyOptions) === null || _router_historyOptions === void 0 ? void 0 : _router_historyOptions.basename) || (router === null || router === void 0 ? void 0 : router.basename) || "/"
77
- }));
78
54
  }
79
- logger(`resolvedConfig`, {
80
- output: nConfig.resolved.output,
81
- runtime: nConfig.resolved.runtime,
82
- deploy: nConfig.resolved.deploy,
83
- server: nConfig.resolved.server
84
- });
85
- return nConfig;
86
- },
87
- config() {
88
- var _useConfig_output, _useConfig_deploy;
55
+ ];
56
+ },
57
+ resolvedConfig: async (config) => {
58
+ const { resolved } = config;
59
+ const { masterApp, router } = getRuntimeConfig(resolved);
60
+ const nConfig = {
61
+ resolved: {
62
+ ...resolved
63
+ }
64
+ };
65
+ if (masterApp) {
66
+ var _useConfig_server, _useConfig, _router_historyOptions, _router, _router1;
89
67
  const useConfig = useConfigContext();
90
- logger("useConfig", useConfig);
91
- const config = useAppContext();
92
- pluginsExportsUtils = createRuntimeExportsUtils(config.internalDirectory, "plugins");
93
- let disableCssExtract = ((_useConfig_output = useConfig.output) === null || _useConfig_output === void 0 ? void 0 : _useConfig_output.disableCssExtract) || false;
94
- if ((_useConfig_deploy = useConfig.deploy) === null || _useConfig_deploy === void 0 ? void 0 : _useConfig_deploy.microFrontend) {
95
- var _useConfig_deploy1;
96
- const { enableHtmlEntry } = getDefaultMicroFrontedConfig((_useConfig_deploy1 = useConfig.deploy) === null || _useConfig_deploy1 === void 0 ? void 0 : _useConfig_deploy1.microFrontend);
97
- if (!enableHtmlEntry) {
98
- disableCssExtract = true;
99
- }
68
+ const baseUrl = (_useConfig = useConfig) === null || _useConfig === void 0 ? void 0 : (_useConfig_server = _useConfig.server) === null || _useConfig_server === void 0 ? void 0 : _useConfig_server.baseUrl;
69
+ if (Array.isArray(baseUrl)) {
70
+ throw new Error("Now Micro-Front-End mode dose not support multiple baseUrl, you can set it as a string");
100
71
  }
101
- return {
102
- output: {
103
- disableCssExtract
104
- },
105
- source: {
106
- alias: {
107
- "@modern-js/runtime/plugins": pluginsExportsUtils.getPath(),
108
- "@modern-js/runtime/garfish": "@modern-js/plugin-garfish/runtime"
72
+ setRuntimeConfig(nConfig.resolved, "masterApp", Object.assign(typeof masterApp === "object" ? {
73
+ ...masterApp
74
+ } : {}, {
75
+ basename: baseUrl || ((_router = router) === null || _router === void 0 ? void 0 : (_router_historyOptions = _router.historyOptions) === null || _router_historyOptions === void 0 ? void 0 : _router_historyOptions.basename) || ((_router1 = router) === null || _router1 === void 0 ? void 0 : _router1.basename) || "/"
76
+ }));
77
+ }
78
+ logger(`resolvedConfig`, {
79
+ output: nConfig.resolved.output,
80
+ runtime: nConfig.resolved.runtime,
81
+ deploy: nConfig.resolved.deploy,
82
+ server: nConfig.resolved.server
83
+ });
84
+ return nConfig;
85
+ },
86
+ config() {
87
+ var _useConfig_output, _useConfig_deploy;
88
+ const useConfig = useConfigContext();
89
+ logger("useConfig", useConfig);
90
+ const config = useAppContext();
91
+ pluginsExportsUtils = createRuntimeExportsUtils(config.internalDirectory, "plugins");
92
+ let disableCssExtract = ((_useConfig_output = useConfig.output) === null || _useConfig_output === void 0 ? void 0 : _useConfig_output.disableCssExtract) || false;
93
+ if ((_useConfig_deploy = useConfig.deploy) === null || _useConfig_deploy === void 0 ? void 0 : _useConfig_deploy.microFrontend) {
94
+ var _useConfig_deploy1;
95
+ const { enableHtmlEntry } = getDefaultMicroFrontedConfig((_useConfig_deploy1 = useConfig.deploy) === null || _useConfig_deploy1 === void 0 ? void 0 : _useConfig_deploy1.microFrontend);
96
+ if (!enableHtmlEntry) {
97
+ disableCssExtract = true;
98
+ }
99
+ }
100
+ return {
101
+ output: {
102
+ disableCssExtract
103
+ },
104
+ source: {
105
+ alias: {
106
+ "@modern-js/runtime/plugins": pluginsExportsUtils.getPath(),
107
+ "@modern-js/runtime/garfish": "@modern-js/plugin-garfish/runtime"
108
+ }
109
+ },
110
+ tools: {
111
+ devServer: {
112
+ headers: {
113
+ "Access-Control-Allow-Origin": "*"
109
114
  }
110
115
  },
111
- tools: {
112
- devServer: {
113
- headers: {
114
- "Access-Control-Allow-Origin": "*"
115
- }
116
- },
117
- webpackChain: (chain, { webpack, CHAIN_ID }) => {
118
- if (webpack.BannerPlugin) {
119
- chain.plugin(CHAIN_ID.PLUGIN.BANNER).use(webpack.BannerPlugin, [
120
- {
121
- banner: "Micro front-end"
122
- }
123
- ]);
124
- }
125
- },
126
- rspack: (config2) => {
127
- var _resolveOptions_deploy;
128
- var _config;
129
- var _builtins;
130
- (_builtins = (_config = config2).builtins) !== null && _builtins !== void 0 ? _builtins : _config.builtins = {};
131
- const resolveOptions = useResolvedConfigContext();
132
- if ((resolveOptions === null || resolveOptions === void 0 ? void 0 : (_resolveOptions_deploy = resolveOptions.deploy) === null || _resolveOptions_deploy === void 0 ? void 0 : _resolveOptions_deploy.microFrontend) && !config2.externalsType) {
133
- config2.externalsType = "commonjs";
134
- }
135
- const banner = config2.builtins.banner || [];
136
- config2.builtins.banner = [
137
- ...Array.isArray(banner) ? banner : [
138
- banner
139
- ],
116
+ webpackChain: (chain, { webpack, CHAIN_ID }) => {
117
+ if (webpack.BannerPlugin) {
118
+ chain.plugin(CHAIN_ID.PLUGIN.BANNER).use(webpack.BannerPlugin, [
140
119
  {
141
120
  banner: "Micro front-end"
142
121
  }
143
- ];
144
- },
145
- bundlerChain: (chain, { env, CHAIN_ID }) => {
146
- var _resolveOptions_deploy, _resolveConfig_resolve;
147
- const resolveOptions = useResolvedConfigContext();
148
- if (resolveOptions === null || resolveOptions === void 0 ? void 0 : (_resolveOptions_deploy = resolveOptions.deploy) === null || _resolveOptions_deploy === void 0 ? void 0 : _resolveOptions_deploy.microFrontend) {
149
- var _useConfig_dev, _resolveOptions_server, _resolveOptions_deploy1;
150
- chain.output.libraryTarget("umd");
151
- if (!((_useConfig_dev = useConfig.dev) === null || _useConfig_dev === void 0 ? void 0 : _useConfig_dev.assetPrefix) && (resolveOptions === null || resolveOptions === void 0 ? void 0 : (_resolveOptions_server = resolveOptions.server) === null || _resolveOptions_server === void 0 ? void 0 : _resolveOptions_server.port) && env === "development") {
152
- chain.output.publicPath(`//localhost:${resolveOptions.server.port}/`);
153
- }
154
- const { enableHtmlEntry, externalBasicLibrary } = getDefaultMicroFrontedConfig((_resolveOptions_deploy1 = resolveOptions.deploy) === null || _resolveOptions_deploy1 === void 0 ? void 0 : _resolveOptions_deploy1.microFrontend);
155
- if (externalBasicLibrary) {
156
- chain.externals(externals);
157
- }
158
- if (!enableHtmlEntry) {
159
- chain.output.filename("index.js");
160
- chain.plugins.delete(`${CHAIN_ID.PLUGIN.HTML}-main`);
161
- chain.optimization.runtimeChunk(false);
162
- chain.optimization.splitChunks({
163
- chunks: "async"
164
- });
165
- }
166
- }
167
- const resolveConfig = chain.toConfig();
168
- logger("bundlerConfig", {
169
- output: resolveConfig.output,
170
- externals: resolveConfig.externals,
171
- env,
172
- alias: (_resolveConfig_resolve = resolveConfig.resolve) === null || _resolveConfig_resolve === void 0 ? void 0 : _resolveConfig_resolve.alias,
173
- plugins: resolveConfig.plugins
174
- });
122
+ ]);
175
123
  }
176
- }
177
- };
178
- },
179
- addRuntimeExports() {
180
- const config = useResolvedConfigContext();
181
- const { masterApp } = getRuntimeConfig(config);
182
- if (masterApp) {
183
- const addExportStatement = `export { default as garfish, default as masterApp } from '${pluginName}/runtime'`;
184
- logger("exportStatement", addExportStatement);
185
- pluginsExportsUtils.addExport(addExportStatement);
186
- }
187
- const otherExportStatement = `export { hoistNonReactStatics } from '${pluginName}/deps'`;
188
- logger("otherExportStatement", otherExportStatement);
189
- pluginsExportsUtils.addExport(otherExportStatement);
190
- },
191
- modifyEntryImports({ entrypoint, imports }) {
192
- const config = useResolvedConfigContext();
193
- const { masterApp } = getRuntimeConfig(config);
194
- if (masterApp) {
195
- imports.push({
196
- value: runtimePluginName,
197
- specifiers: [
124
+ },
125
+ rspack: (config2) => {
126
+ var _resolveOptions_deploy, _resolveOptions;
127
+ var _config;
128
+ var _builtins;
129
+ (_builtins = (_config = config2).builtins) !== null && _builtins !== void 0 ? _builtins : _config.builtins = {};
130
+ const resolveOptions = useResolvedConfigContext();
131
+ if (((_resolveOptions = resolveOptions) === null || _resolveOptions === void 0 ? void 0 : (_resolveOptions_deploy = _resolveOptions.deploy) === null || _resolveOptions_deploy === void 0 ? void 0 : _resolveOptions_deploy.microFrontend) && !config2.externalsType) {
132
+ config2.externalsType = "commonjs";
133
+ }
134
+ const banner = config2.builtins.banner || [];
135
+ config2.builtins.banner = [
136
+ ...Array.isArray(banner) ? banner : [
137
+ banner
138
+ ],
198
139
  {
199
- imported: "garfish"
140
+ banner: "Micro front-end"
200
141
  }
201
- ]
202
- });
203
- imports.push({
204
- value: runtimePluginName,
205
- specifiers: [
206
- {
207
- imported: "masterApp"
142
+ ];
143
+ },
144
+ bundlerChain: (chain, { env, CHAIN_ID }) => {
145
+ var _resolveOptions_deploy, _resolveOptions, _resolveConfig_resolve;
146
+ const resolveOptions = useResolvedConfigContext();
147
+ if ((_resolveOptions = resolveOptions) === null || _resolveOptions === void 0 ? void 0 : (_resolveOptions_deploy = _resolveOptions.deploy) === null || _resolveOptions_deploy === void 0 ? void 0 : _resolveOptions_deploy.microFrontend) {
148
+ var _useConfig_dev, _resolveOptions_server, _resolveOptions1, _resolveOptions_deploy1;
149
+ chain.output.libraryTarget("umd");
150
+ if (!((_useConfig_dev = useConfig.dev) === null || _useConfig_dev === void 0 ? void 0 : _useConfig_dev.assetPrefix) && ((_resolveOptions1 = resolveOptions) === null || _resolveOptions1 === void 0 ? void 0 : (_resolveOptions_server = _resolveOptions1.server) === null || _resolveOptions_server === void 0 ? void 0 : _resolveOptions_server.port) && env === "development") {
151
+ chain.output.publicPath(`//localhost:${resolveOptions.server.port}/`);
208
152
  }
209
- ]
210
- });
153
+ const { enableHtmlEntry, externalBasicLibrary } = getDefaultMicroFrontedConfig((_resolveOptions_deploy1 = resolveOptions.deploy) === null || _resolveOptions_deploy1 === void 0 ? void 0 : _resolveOptions_deploy1.microFrontend);
154
+ if (externalBasicLibrary) {
155
+ chain.externals(externals);
156
+ }
157
+ if (!enableHtmlEntry) {
158
+ chain.output.filename("index.js");
159
+ chain.plugins.delete(`${CHAIN_ID.PLUGIN.HTML}-main`);
160
+ chain.optimization.runtimeChunk(false);
161
+ chain.optimization.splitChunks({
162
+ chunks: "async"
163
+ });
164
+ }
165
+ }
166
+ const resolveConfig = chain.toConfig();
167
+ logger("bundlerConfig", {
168
+ output: resolveConfig.output,
169
+ externals: resolveConfig.externals,
170
+ env,
171
+ alias: (_resolveConfig_resolve = resolveConfig.resolve) === null || _resolveConfig_resolve === void 0 ? void 0 : _resolveConfig_resolve.alias,
172
+ plugins: resolveConfig.plugins
173
+ });
174
+ }
211
175
  }
176
+ };
177
+ },
178
+ addRuntimeExports() {
179
+ const config = useResolvedConfigContext();
180
+ const { masterApp } = getRuntimeConfig(config);
181
+ if (masterApp) {
182
+ const addExportStatement = `export { default as garfish, default as masterApp } from '${pluginName}/runtime'`;
183
+ logger("exportStatement", addExportStatement);
184
+ pluginsExportsUtils.addExport(addExportStatement);
185
+ }
186
+ const otherExportStatement = `export { hoistNonReactStatics } from '${pluginName}/deps'`;
187
+ logger("otherExportStatement", otherExportStatement);
188
+ pluginsExportsUtils.addExport(otherExportStatement);
189
+ },
190
+ modifyEntryImports({ entrypoint, imports }) {
191
+ const config = useResolvedConfigContext();
192
+ const { masterApp } = getRuntimeConfig(config);
193
+ if (masterApp) {
212
194
  imports.push({
213
195
  value: runtimePluginName,
214
196
  specifiers: [
215
197
  {
216
- imported: "hoistNonReactStatics"
198
+ imported: "garfish"
217
199
  }
218
200
  ]
219
201
  });
220
202
  imports.push({
221
- value: "react-dom",
203
+ value: runtimePluginName,
222
204
  specifiers: [
223
205
  {
224
- imported: "unmountComponentAtNode"
225
- },
226
- {
227
- imported: "createPortal"
206
+ imported: "masterApp"
228
207
  }
229
208
  ]
230
209
  });
231
- return {
232
- imports,
233
- entrypoint
234
- };
235
- },
236
- modifyEntryRuntimePlugins({ entrypoint, plugins }) {
237
- const config = useResolvedConfigContext();
238
- const { masterApp } = getRuntimeConfig(config);
239
- if (masterApp) {
240
- logger("garfishPlugin options", masterApp);
241
- plugins.push({
242
- name: "garfish",
243
- args: "masterApp",
244
- options: masterApp === true ? JSON.stringify({}) : JSON.stringify(masterApp)
245
- });
246
- }
247
- return {
248
- entrypoint,
249
- plugins
250
- };
251
- },
252
- modifyEntryRenderFunction({ entrypoint, code }) {
253
- var _config_deploy;
254
- const config = useResolvedConfigContext();
255
- if (!(config === null || config === void 0 ? void 0 : (_config_deploy = config.deploy) === null || _config_deploy === void 0 ? void 0 : _config_deploy.microFrontend)) {
256
- return {
257
- entrypoint,
258
- code
259
- };
260
- }
261
- const nCode = makeRenderFunction(code);
262
- logger("makeRenderFunction", nCode);
210
+ }
211
+ imports.push({
212
+ value: runtimePluginName,
213
+ specifiers: [
214
+ {
215
+ imported: "hoistNonReactStatics"
216
+ }
217
+ ]
218
+ });
219
+ imports.push({
220
+ value: "react-dom",
221
+ specifiers: [
222
+ {
223
+ imported: "unmountComponentAtNode"
224
+ },
225
+ {
226
+ imported: "createPortal"
227
+ }
228
+ ]
229
+ });
230
+ return {
231
+ imports,
232
+ entrypoint
233
+ };
234
+ },
235
+ modifyEntryRuntimePlugins({ entrypoint, plugins }) {
236
+ const config = useResolvedConfigContext();
237
+ const { masterApp } = getRuntimeConfig(config);
238
+ if (masterApp) {
239
+ logger("garfishPlugin options", masterApp);
240
+ plugins.push({
241
+ name: "garfish",
242
+ args: "masterApp",
243
+ options: masterApp === true ? JSON.stringify({}) : JSON.stringify(masterApp)
244
+ });
245
+ }
246
+ return {
247
+ entrypoint,
248
+ plugins
249
+ };
250
+ },
251
+ modifyEntryRenderFunction({ entrypoint, code }) {
252
+ var _config_deploy, _config;
253
+ const config = useResolvedConfigContext();
254
+ if (!((_config = config) === null || _config === void 0 ? void 0 : (_config_deploy = _config.deploy) === null || _config_deploy === void 0 ? void 0 : _config_deploy.microFrontend)) {
263
255
  return {
264
256
  entrypoint,
265
- code: nCode
257
+ code
266
258
  };
267
- },
268
- modifyAsyncEntry({ entrypoint, code }) {
269
- var _config_deploy, _config_source;
270
- const config = useResolvedConfigContext();
271
- let finalCode = code;
272
- if ((config === null || config === void 0 ? void 0 : (_config_deploy = config.deploy) === null || _config_deploy === void 0 ? void 0 : _config_deploy.microFrontend) && (config === null || config === void 0 ? void 0 : (_config_source = config.source) === null || _config_source === void 0 ? void 0 : _config_source.enableAsyncEntry)) {
273
- finalCode = generateAsyncEntry(code);
274
- return {
275
- entrypoint,
276
- code: `${finalCode}`
277
- };
278
- }
259
+ }
260
+ const nCode = makeRenderFunction(code);
261
+ logger("makeRenderFunction", nCode);
262
+ return {
263
+ entrypoint,
264
+ code: nCode
265
+ };
266
+ },
267
+ modifyAsyncEntry({ entrypoint, code }) {
268
+ var _config_deploy, _config, _config_source, _config1;
269
+ const config = useResolvedConfigContext();
270
+ let finalCode = code;
271
+ if (((_config = config) === null || _config === void 0 ? void 0 : (_config_deploy = _config.deploy) === null || _config_deploy === void 0 ? void 0 : _config_deploy.microFrontend) && ((_config1 = config) === null || _config1 === void 0 ? void 0 : (_config_source = _config1.source) === null || _config_source === void 0 ? void 0 : _config_source.enableAsyncEntry)) {
272
+ finalCode = generateAsyncEntry(code);
279
273
  return {
280
274
  entrypoint,
281
- code: finalCode
275
+ code: `${finalCode}`
282
276
  };
283
- },
284
- modifyEntryExport({ entrypoint, exportStatement }) {
285
- var _config_deploy;
286
- const config = useResolvedConfigContext();
287
- if (config === null || config === void 0 ? void 0 : (_config_deploy = config.deploy) === null || _config_deploy === void 0 ? void 0 : _config_deploy.microFrontend) {
288
- const exportStatementCode = makeProvider();
289
- logger("exportStatement", exportStatementCode);
290
- return {
291
- entrypoint,
292
- exportStatement: exportStatementCode
293
- };
294
- }
277
+ }
278
+ return {
279
+ entrypoint,
280
+ code: finalCode
281
+ };
282
+ },
283
+ modifyEntryExport({ entrypoint, exportStatement }) {
284
+ var _config_deploy, _config;
285
+ const config = useResolvedConfigContext();
286
+ if ((_config = config) === null || _config === void 0 ? void 0 : (_config_deploy = _config.deploy) === null || _config_deploy === void 0 ? void 0 : _config_deploy.microFrontend) {
287
+ const exportStatementCode = makeProvider();
288
+ logger("exportStatement", exportStatementCode);
295
289
  return {
296
290
  entrypoint,
297
- exportStatement
291
+ exportStatement: exportStatementCode
298
292
  };
299
293
  }
300
- };
301
- }
302
- };
303
- };
294
+ return {
295
+ entrypoint,
296
+ exportStatement
297
+ };
298
+ }
299
+ };
300
+ }
301
+ });
304
302
  export default garfishPlugin;