@modern-js/plugin-garfish 1.3.0 → 1.3.1

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.
Files changed (41) hide show
  1. package/.eslintrc.js +1 -1
  2. package/CHANGELOG.md +12 -0
  3. package/dist/js/modern/cli/index.js +190 -209
  4. package/dist/js/modern/cli/utils.js +1 -6
  5. package/dist/js/modern/index.js +2 -1
  6. package/dist/js/modern/runtime/index.js +2 -1
  7. package/dist/js/modern/runtime/loadable.js +36 -19
  8. package/dist/js/modern/runtime/plugin.js +14 -17
  9. package/dist/js/modern/runtime/utils/MApp.js +7 -10
  10. package/dist/js/modern/runtime/utils/apps.js +1 -4
  11. package/dist/js/node/cli/index.js +192 -213
  12. package/dist/js/node/cli/utils.js +1 -6
  13. package/dist/js/node/index.js +18 -3
  14. package/dist/js/node/runtime/index.js +25 -12
  15. package/dist/js/node/runtime/loadable.js +36 -19
  16. package/dist/js/node/runtime/plugin.js +11 -16
  17. package/dist/js/node/runtime/utils/MApp.js +7 -10
  18. package/dist/js/node/runtime/utils/apps.js +1 -4
  19. package/dist/js/treeshaking/cli/index.js +183 -199
  20. package/dist/js/treeshaking/cli/utils.js +2 -2
  21. package/dist/js/treeshaking/index.js +2 -1
  22. package/dist/js/treeshaking/runtime/index.js +2 -1
  23. package/dist/js/treeshaking/runtime/loadable.js +39 -25
  24. package/dist/js/treeshaking/runtime/plugin.js +15 -19
  25. package/dist/js/treeshaking/runtime/utils/MApp.js +23 -31
  26. package/dist/js/treeshaking/runtime/utils/apps.js +1 -2
  27. package/dist/types/cli/index.d.ts +1 -9
  28. package/dist/types/cli/utils.d.ts +1 -1
  29. package/dist/types/index.d.ts +2 -1
  30. package/dist/types/runtime/index.d.ts +3 -1
  31. package/dist/types/runtime/loadable.d.ts +2 -8
  32. package/dist/types/runtime/plugin.d.ts +29 -3
  33. package/dist/types/runtime/useModuleApps.d.ts +7 -9
  34. package/dist/types/runtime/utils/MApp.d.ts +1 -15
  35. package/dist/types/runtime/utils/apps.d.ts +1 -1
  36. package/package.json +20 -8
  37. package/tests/cli.test.tsx +21 -43
  38. package/tests/hooks.test.tsx +1 -0
  39. package/tests/index.test.tsx +6 -3
  40. package/tsconfig.json +3 -2
  41. package/tests/__snapshots__/cli.test.tsx.snap +0 -71
@@ -1,4 +1,4 @@
1
- const _excluded = ["manifest", "LoadingComponent"];
1
+ const _excluded = ["manifest"];
2
2
 
3
3
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
4
4
 
@@ -10,6 +10,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
10
10
 
11
11
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
12
12
 
13
+ // eslint-disable-next-line filenames/match-exported
13
14
  import { createPlugin } from '@modern-js/runtime-core';
14
15
  import React from 'react';
15
16
  import hoistNonReactStatics from 'hoist-non-react-statics';
@@ -21,9 +22,9 @@ import { generateApps } from "./utils/apps";
21
22
  import { jsx as _jsx } from "react/jsx-runtime";
22
23
 
23
24
  async function initOptions(manifest = {}, options) {
24
- var _window, _window$modern_manife;
25
+ var _window, _window$modern_manife, _window2, _window2$modern_manif;
25
26
 
26
- let apps = []; // use manifest modules
27
+ let apps = options.apps || []; // use manifest modules
27
28
 
28
29
  if (manifest !== null && manifest !== void 0 && manifest.modules) {
29
30
  apps = manifest === null || manifest === void 0 ? void 0 : manifest.modules;
@@ -37,35 +38,29 @@ async function initOptions(manifest = {}, options) {
37
38
  } // get inject modules list
38
39
 
39
40
 
40
- if ((_window = window) !== null && _window !== void 0 && (_window$modern_manife = _window.modern_manifest) !== null && _window$modern_manife !== void 0 && _window$modern_manife.modules) {
41
- var _window2, _window2$modern_manif;
41
+ 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) {
42
+ var _window3, _window3$modern_manif;
42
43
 
43
- apps = (_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;
44
+ 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;
44
45
  logger('modern_manifest', apps);
45
46
  }
46
47
 
47
- return _objectSpread({
48
+ return _objectSpread(_objectSpread({}, options), {}, {
48
49
  apps
49
- }, options);
50
+ });
50
51
  }
51
52
 
52
- export default (config => {
53
+ const GarfishPlugin = config => {
53
54
  setExternal();
54
55
 
55
56
  const {
56
- manifest = {},
57
- LoadingComponent
57
+ manifest
58
58
  } = config,
59
59
  options = _objectWithoutProperties(config, _excluded);
60
60
 
61
61
  logger('createPlugin', {
62
62
  config
63
63
  });
64
-
65
- if (!manifest.LoadingComponent && LoadingComponent) {
66
- manifest.LoadingComponent = LoadingComponent;
67
- }
68
-
69
64
  const promise = initOptions(manifest, options);
70
65
  return createPlugin(() => ({
71
66
  hoc({
@@ -131,4 +126,6 @@ export default (config => {
131
126
  }
132
127
 
133
128
  }));
134
- });
129
+ };
130
+
131
+ export default GarfishPlugin;
@@ -16,9 +16,7 @@ import Garfish from 'garfish';
16
16
  import { logger, generateSubAppContainerKey } from "../../util";
17
17
  import { Loadable } from "../loadable";
18
18
  import { jsx as _jsx } from "react/jsx-runtime";
19
- export function generateMApp(options, {
20
- LoadingComponent
21
- }) {
19
+ export function generateMApp(options, manifest) {
22
20
  class MApp extends React.Component {
23
21
  constructor(...args) {
24
22
  super(...args);
@@ -53,7 +51,7 @@ export function generateMApp(options, {
53
51
  domGetter: `#${domId}`,
54
52
 
55
53
  beforeLoad(...args) {
56
- // logger('MApp beforeLoad', args);
54
+ logger('MApp beforeLoad', args);
57
55
  setLoadingState({
58
56
  isLoading: true,
59
57
  error: null
@@ -62,7 +60,7 @@ export function generateMApp(options, {
62
60
  },
63
61
 
64
62
  beforeMount(...args) {
65
- // logger('MApp beforeMount', args);
63
+ logger('MApp beforeMount', args);
66
64
  setLoadingState({
67
65
  isLoading: false
68
66
  });
@@ -70,7 +68,7 @@ export function generateMApp(options, {
70
68
  },
71
69
 
72
70
  errorLoadApp(error, ...args) {
73
- // logger('MApp errorLoadApp', args);
71
+ logger('MApp errorLoadApp', args);
74
72
  setLoadingState({
75
73
  error
76
74
  });
@@ -78,7 +76,7 @@ export function generateMApp(options, {
78
76
  },
79
77
 
80
78
  errorMountApp(error, ...args) {
81
- // logger('MApp errorMountApp', args);
79
+ logger('MApp errorMountApp', args);
82
80
  setLoadingState({
83
81
  error
84
82
  });
@@ -86,7 +84,7 @@ export function generateMApp(options, {
86
84
  },
87
85
 
88
86
  errorUnmountApp(error, ...args) {
89
- // logger('MApp errorUnmountApp', args);
87
+ logger('MApp errorUnmountApp', args);
90
88
  setLoadingState({
91
89
  error
92
90
  });
@@ -114,7 +112,6 @@ export function generateMApp(options, {
114
112
  }
115
113
 
116
114
  render() {
117
- logger('MApp render status', this.state);
118
115
  return /*#__PURE__*/_jsx("div", {
119
116
  id: generateSubAppContainerKey()
120
117
  });
@@ -122,5 +119,5 @@ export function generateMApp(options, {
122
119
 
123
120
  }
124
121
 
125
- return Loadable(MApp)(LoadingComponent);
122
+ return Loadable(MApp)(manifest === null || manifest === void 0 ? void 0 : manifest.loadable);
126
123
  }
@@ -28,9 +28,6 @@ import { jsx as _jsx } from "react/jsx-runtime";
28
28
  import { Fragment as _Fragment } from "react/jsx-runtime";
29
29
 
30
30
  function getAppInstance(appInfo, manifest) {
31
- const {
32
- LoadingComponent
33
- } = manifest;
34
31
  let locationHref = '';
35
32
 
36
33
  class MicroApp extends React.Component {
@@ -170,7 +167,7 @@ function getAppInstance(appInfo, manifest) {
170
167
 
171
168
  }
172
169
 
173
- return Loadable(withRouter(MicroApp))(LoadingComponent);
170
+ return Loadable(withRouter(MicroApp))(manifest === null || manifest === void 0 ? void 0 : manifest.loadable);
174
171
  }
175
172
 
176
173
  export function generateApps(options, manifest) {
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.initializer = exports.default = void 0;
6
+ exports.default = void 0;
7
7
 
8
8
  var _path = _interopRequireDefault(require("path"));
9
9
 
@@ -15,8 +15,6 @@ var _util = require("../util");
15
15
 
16
16
  var _utils2 = require("./utils");
17
17
 
18
- const _excluded = ["validateSchema", "externals", "componentKey"];
19
-
20
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
19
 
22
20
  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; }
@@ -25,10 +23,6 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
25
23
 
26
24
  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; }
27
25
 
28
- function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
29
-
30
- function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
31
-
32
26
  function getRuntimeConfig(config) {
33
27
  var _config$runtime;
34
28
 
@@ -53,249 +47,234 @@ function setRuntimeConfig(config, key, value) {
53
47
  }
54
48
  }
55
49
 
56
- const initializer = _ref => {
57
- let {
58
- validateSchema,
59
- externals,
60
- componentKey
61
- } = _ref,
62
- otherLifeCycle = _objectWithoutProperties(_ref, _excluded);
63
-
64
- return () => {
65
- const configMap = new Map();
66
- let pluginsExportsUtils;
67
- let runtimeExportsUtils;
68
- return _objectSpread({
69
- resolvedConfig(config) {
70
- const {
71
- resolved
72
- } = config;
73
- const {
74
- masterApp,
75
- router
76
- } = getRuntimeConfig(resolved);
77
- const nConfig = {
78
- resolved: _objectSpread({}, resolved)
79
- };
50
+ const externals = {
51
+ 'react-dom': 'react-dom',
52
+ react: 'react'
53
+ };
80
54
 
81
- if (masterApp) {
82
- // basename does not exist use router's basename
83
- setRuntimeConfig(nConfig.resolved, 'masterApp', Object.assign(typeof masterApp === 'object' ? _objectSpread({}, masterApp) : {}, {
84
- basename: (router === null || router === void 0 ? void 0 : router.basename) || '/'
85
- }));
86
- }
55
+ var _default = (0, _core.createPlugin)(() => {
56
+ const configMap = new Map();
57
+ let pluginsExportsUtils;
58
+ let runtimeExportsUtils;
59
+ return {
60
+ resolvedConfig(config) {
61
+ const {
62
+ resolved
63
+ } = config;
64
+ const {
65
+ masterApp,
66
+ router
67
+ } = getRuntimeConfig(resolved);
68
+ const nConfig = {
69
+ resolved: _objectSpread({}, resolved)
70
+ };
71
+
72
+ if (masterApp) {
73
+ // basename does not exist use router's basename
74
+ setRuntimeConfig(nConfig.resolved, 'masterApp', Object.assign(typeof masterApp === 'object' ? _objectSpread({}, masterApp) : {}, {
75
+ basename: (router === null || router === void 0 ? void 0 : router.basename) || '/'
76
+ }));
77
+ }
87
78
 
88
- (0, _util.logger)(`resolvedConfig`, {
89
- runtime: nConfig.resolved.runtime,
90
- deploy: nConfig.resolved.deploy,
91
- server: nConfig.resolved.server
92
- });
93
- return nConfig;
94
- },
95
-
96
- config() {
97
- // eslint-disable-next-line react-hooks/rules-of-hooks
98
- const config = (0, _core.useAppContext)();
99
- pluginsExportsUtils = (0, _utils.createRuntimeExportsUtils)(config.internalDirectory, 'plugins');
100
- runtimeExportsUtils = (0, _utils.createRuntimeExportsUtils)(config.internalDirectory, 'index');
101
- return {
102
- source: {
103
- alias: {
104
- '@modern-js/runtime/plugins': pluginsExportsUtils.getPath()
105
- }
106
- },
107
- tools: {
108
- webpack: (webpackConfig, {
109
- chain,
110
- webpack
111
- }) => {
112
- var _resolvedConfig$deplo;
79
+ (0, _util.logger)(`resolvedConfig`, {
80
+ runtime: nConfig.resolved.runtime,
81
+ deploy: nConfig.resolved.deploy,
82
+ server: nConfig.resolved.server
83
+ });
84
+ return nConfig;
85
+ },
86
+
87
+ config() {
88
+ // eslint-disable-next-line react-hooks/rules-of-hooks
89
+ const config = (0, _core.useAppContext)();
90
+ pluginsExportsUtils = (0, _utils.createRuntimeExportsUtils)(config.internalDirectory, 'plugins');
91
+ runtimeExportsUtils = (0, _utils.createRuntimeExportsUtils)(config.internalDirectory, 'index');
92
+ return {
93
+ source: {
94
+ alias: {
95
+ '@modern-js/runtime/plugins': pluginsExportsUtils.getPath()
96
+ }
97
+ },
98
+ tools: {
99
+ webpack: (webpackConfig, {
100
+ chain,
101
+ webpack
102
+ }) => {
103
+ var _resolvedConfig$deplo, _resolveWebpackConfig;
113
104
 
114
- const env = process.env.NODE_ENV; // eslint-disable-next-line react-hooks/rules-of-hooks
105
+ const env = process.env.NODE_ENV; // eslint-disable-next-line react-hooks/rules-of-hooks
115
106
 
116
- const resolvedConfig = (0, _core.useResolvedConfigContext)();
107
+ const resolvedConfig = (0, _core.useResolvedConfigContext)();
117
108
 
118
- if (resolvedConfig !== null && resolvedConfig !== void 0 && (_resolvedConfig$deplo = resolvedConfig.deploy) !== null && _resolvedConfig$deplo !== void 0 && _resolvedConfig$deplo.microFrontend) {
119
- var _resolvedConfig$deplo2, _resolvedConfig$deplo3;
109
+ if (resolvedConfig !== null && resolvedConfig !== void 0 && (_resolvedConfig$deplo = resolvedConfig.deploy) !== null && _resolvedConfig$deplo !== void 0 && _resolvedConfig$deplo.microFrontend) {
110
+ var _resolvedConfig$deplo2, _resolvedConfig$deplo3;
120
111
 
121
- chain.output.libraryTarget('umd');
112
+ chain.output.libraryTarget('umd');
122
113
 
123
- if (resolvedConfig.server.port) {
124
- chain.output.publicPath(env === 'development' ? `//localhost:${resolvedConfig.server.port}/` : webpackConfig.output.publicPath);
125
- } // add comments avoid sourcemap abnormal
114
+ if (resolvedConfig.server.port) {
115
+ chain.output.publicPath(env === 'development' ? `//localhost:${resolvedConfig.server.port}/` : webpackConfig.output.publicPath);
116
+ } // add comments avoid sourcemap abnormal
126
117
 
127
118
 
128
- chain.plugin('banner').use(webpack.BannerPlugin, [{
129
- banner: 'Micro front-end'
130
- }]);
131
- const {
132
- enableHtmlEntry = true,
133
- externalBasicLibrary = true
134
- } = 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 : {}; // external
119
+ chain.plugin('banner').use(webpack.BannerPlugin, [{
120
+ banner: 'Micro front-end'
121
+ }]);
122
+ const {
123
+ enableHtmlEntry = true,
124
+ externalBasicLibrary = true
125
+ } = 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 : {}; // external
135
126
 
136
- if (externalBasicLibrary) {
137
- chain.externals(externals);
138
- } // use html mode
127
+ if (externalBasicLibrary) {
128
+ chain.externals(externals);
129
+ } // use html mode
139
130
 
140
131
 
141
- if (!enableHtmlEntry) {
142
- chain.output.filename('index.js');
143
- chain.plugins.delete('html-main');
144
- chain.optimization.runtimeChunk(false);
145
- chain.optimization.splitChunks({
146
- chunks: 'async'
147
- });
148
- }
132
+ if (!enableHtmlEntry) {
133
+ chain.output.filename('index.js');
134
+ chain.plugins.delete('html-main');
135
+ chain.optimization.runtimeChunk(false);
136
+ chain.optimization.splitChunks({
137
+ chunks: 'async'
138
+ });
149
139
  }
150
-
151
- const resolveWebpackConfig = chain.toConfig();
152
- (0, _util.logger)('webpackConfig', {
153
- output: resolveWebpackConfig.output,
154
- externals: resolveWebpackConfig.externals,
155
- env
156
- });
157
140
  }
158
- }
159
- };
160
- },
161
-
162
- addRuntimeExports() {
163
- const mfPackage = _path.default.resolve(__dirname, '../../../../');
164
-
165
- const addExportStatement = `export { default as garfish } from '${mfPackage}'`;
166
- (0, _util.logger)('exportStatement', addExportStatement);
167
- pluginsExportsUtils.addExport(addExportStatement);
168
- runtimeExportsUtils.addExport(`export * from '${mfPackage}'`);
169
- },
170
-
171
- validateSchema,
172
141
 
173
- modifyEntryImports({
174
- entrypoint,
175
- imports
176
- }) {
177
- // eslint-disable-next-line react-hooks/rules-of-hooks
178
- const resolvedConfig = (0, _core.useResolvedConfigContext)(); // support legacy config
179
-
180
- const {
181
- masterApp
182
- } = getRuntimeConfig(resolvedConfig); // eslint-disable-next-line react-hooks/rules-of-hooks
183
-
184
- const {
185
- packageName
186
- } = (0, _core.useAppContext)();
187
- const masterAppConfig = (0, _utils.getEntryOptions)(entrypoint.entryName, masterApp, resolvedConfig.runtimeByEntries, packageName);
188
- configMap.set(entrypoint.entryName, masterAppConfig);
189
-
190
- if (masterAppConfig) {
191
- imports.push({
192
- value: '@modern-js/runtime/plugins',
193
- specifiers: [{
194
- imported: 'garfish'
195
- }]
196
- });
142
+ const resolveWebpackConfig = chain.toConfig();
143
+ (0, _util.logger)('webpackConfig', {
144
+ output: resolveWebpackConfig.output,
145
+ externals: resolveWebpackConfig.externals,
146
+ env,
147
+ alias: (_resolveWebpackConfig = resolveWebpackConfig.resolve) === null || _resolveWebpackConfig === void 0 ? void 0 : _resolveWebpackConfig.alias
148
+ });
149
+ }
197
150
  }
198
-
151
+ };
152
+ },
153
+
154
+ addRuntimeExports() {
155
+ const mfPackage = _path.default.resolve(__dirname, '../../../../');
156
+
157
+ const addExportStatement = `export { default as garfish } from '${mfPackage}'`;
158
+ (0, _util.logger)('exportStatement', addExportStatement);
159
+ pluginsExportsUtils.addExport(addExportStatement);
160
+ runtimeExportsUtils.addExport(`export * from '${mfPackage}'`);
161
+ },
162
+
163
+ validateSchema() {
164
+ return _utils.PLUGIN_SCHEMAS['@modern-js/plugin-garfish'];
165
+ },
166
+
167
+ modifyEntryImports({
168
+ entrypoint,
169
+ imports
170
+ }) {
171
+ // eslint-disable-next-line react-hooks/rules-of-hooks
172
+ const resolvedConfig = (0, _core.useResolvedConfigContext)(); // support legacy config
173
+
174
+ const {
175
+ masterApp
176
+ } = getRuntimeConfig(resolvedConfig); // eslint-disable-next-line react-hooks/rules-of-hooks
177
+
178
+ const {
179
+ packageName
180
+ } = (0, _core.useAppContext)();
181
+ const masterAppConfig = (0, _utils.getEntryOptions)(entrypoint.entryName, masterApp, resolvedConfig.runtimeByEntries, packageName);
182
+ configMap.set(entrypoint.entryName, masterAppConfig);
183
+
184
+ if (masterAppConfig) {
199
185
  imports.push({
200
- value: 'react-dom',
186
+ value: '@modern-js/runtime/plugins',
201
187
  specifiers: [{
202
- imported: 'unmountComponentAtNode'
203
- }, {
204
- imported: 'createPortal'
188
+ imported: 'garfish'
205
189
  }]
206
190
  });
207
- return {
208
- imports,
209
- entrypoint
210
- };
211
- },
191
+ }
192
+
193
+ imports.push({
194
+ value: 'react-dom',
195
+ specifiers: [{
196
+ imported: 'unmountComponentAtNode'
197
+ }, {
198
+ imported: 'createPortal'
199
+ }]
200
+ });
201
+ return {
202
+ imports,
203
+ entrypoint
204
+ };
205
+ },
206
+
207
+ modifyEntryRuntimePlugins({
208
+ entrypoint,
209
+ plugins
210
+ }) {
211
+ const masterAppConfig = configMap.get(entrypoint.entryName);
212
+
213
+ if (masterAppConfig) {
214
+ (0, _util.logger)('garfishPlugin options', masterAppConfig);
215
+ plugins.push({
216
+ name: 'garfish',
217
+ args: 'masterApp',
218
+ options: JSON.stringify(masterAppConfig)
219
+ });
220
+ }
212
221
 
213
- modifyEntryRuntimePlugins({
222
+ return {
214
223
  entrypoint,
215
224
  plugins
216
- }) {
217
- const masterAppConfig = configMap.get(entrypoint.entryName);
218
-
219
- if (masterAppConfig) {
220
- (0, _util.logger)('garfishPlugin options', masterAppConfig);
221
- plugins.push({
222
- name: 'garfish',
223
- args: 'masterApp',
224
- options: JSON.stringify(masterAppConfig)
225
- });
226
- }
225
+ };
226
+ },
227
227
 
228
- return {
229
- entrypoint,
230
- plugins
231
- };
232
- },
228
+ modifyEntryRenderFunction({
229
+ entrypoint,
230
+ code
231
+ }) {
232
+ var _config$deploy;
233
233
 
234
- modifyEntryRenderFunction({
235
- entrypoint,
236
- code
237
- }) {
238
- var _config$deploy;
239
-
240
- // eslint-disable-next-line react-hooks/rules-of-hooks
241
- const config = (0, _core.useResolvedConfigContext)();
242
-
243
- if (!(config !== null && config !== void 0 && (_config$deploy = config.deploy) !== null && _config$deploy !== void 0 && _config$deploy.microFrontend)) {
244
- return {
245
- entrypoint,
246
- code
247
- };
248
- }
234
+ // eslint-disable-next-line react-hooks/rules-of-hooks
235
+ const config = (0, _core.useResolvedConfigContext)();
249
236
 
250
- const nCode = (0, _utils2.makeRenderFunction)(code);
251
- (0, _util.logger)('makeRenderFunction', nCode);
237
+ if (!(config !== null && config !== void 0 && (_config$deploy = config.deploy) !== null && _config$deploy !== void 0 && _config$deploy.microFrontend)) {
252
238
  return {
253
239
  entrypoint,
254
- code: nCode
240
+ code
255
241
  };
256
- },
242
+ }
257
243
 
258
- modifyEntryExport({
244
+ const nCode = (0, _utils2.makeRenderFunction)(code);
245
+ (0, _util.logger)('makeRenderFunction', nCode);
246
+ return {
259
247
  entrypoint,
260
- exportStatement
261
- }) {
262
- var _resolvedConfig$deplo4;
263
-
264
- // eslint-disable-next-line react-hooks/rules-of-hooks
265
- const resolvedConfig = (0, _core.useResolvedConfigContext)();
266
-
267
- if (resolvedConfig !== null && resolvedConfig !== void 0 && (_resolvedConfig$deplo4 = resolvedConfig.deploy) !== null && _resolvedConfig$deplo4 !== void 0 && _resolvedConfig$deplo4.microFrontend) {
268
- const exportStatementCode = (0, _utils2.makeProvider)(componentKey);
269
- (0, _util.logger)('exportStatement', exportStatementCode);
270
- return {
271
- entrypoint,
272
- exportStatement: exportStatementCode
273
- };
274
- }
275
-
248
+ code: nCode
249
+ };
250
+ },
251
+
252
+ modifyEntryExport({
253
+ entrypoint,
254
+ exportStatement
255
+ }) {
256
+ var _resolvedConfig$deplo4;
257
+
258
+ // eslint-disable-next-line react-hooks/rules-of-hooks
259
+ const resolvedConfig = (0, _core.useResolvedConfigContext)();
260
+
261
+ if (resolvedConfig !== null && resolvedConfig !== void 0 && (_resolvedConfig$deplo4 = resolvedConfig.deploy) !== null && _resolvedConfig$deplo4 !== void 0 && _resolvedConfig$deplo4.microFrontend) {
262
+ const exportStatementCode = (0, _utils2.makeProvider)();
263
+ (0, _util.logger)('exportStatement', exportStatementCode);
276
264
  return {
277
265
  entrypoint,
278
- exportStatement
266
+ exportStatement: exportStatementCode
279
267
  };
280
268
  }
281
269
 
282
- }, otherLifeCycle);
283
- };
284
- };
285
-
286
- exports.initializer = initializer;
287
-
288
- var _default = (0, _core.createPlugin)(initializer({
289
- validateSchema() {
290
- return _utils.PLUGIN_SCHEMAS['@modern-js/plugin-garfish'];
291
- },
270
+ return {
271
+ entrypoint,
272
+ exportStatement
273
+ };
274
+ }
292
275
 
293
- externals: {
294
- 'react-dom': 'react-dom',
295
- react: 'react'
296
- },
297
- componentKey: 'dynamicComponent'
298
- }), {
276
+ };
277
+ }, {
299
278
  name: '@modern-js/plugin-garfish'
300
279
  });
301
280
 
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.makeRenderFunction = exports.makeProvider = void 0;
7
7
 
8
- const makeProvider = componentKey => `
8
+ const makeProvider = () => `
9
9
  export const provider = function ({basename, dom, ...props}) {
10
10
  return {
11
11
  render({basename, dom}) {
@@ -24,11 +24,6 @@ const makeProvider = componentKey => `
24
24
  SubModuleComponent: (props) => {
25
25
  const SubApp = render(props, basename);
26
26
 
27
- return createPortal(<SubApp />, dom.querySelector('#' + MOUNT_ID) || dom);
28
- },
29
- ${componentKey}: () => {
30
- const SubApp = render(props, basename);
31
-
32
27
  return createPortal(<SubApp />, dom.querySelector('#' + MOUNT_ID) || dom);
33
28
  }
34
29
  }