@modern-js/plugin-garfish 2.0.0-beta.2 → 2.0.0-beta.4

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 (53) hide show
  1. package/CHANGELOG.md +125 -0
  2. package/dist/js/modern/cli/index.js +164 -158
  3. package/dist/js/modern/cli/utils.js +31 -23
  4. package/dist/js/modern/global.d.js +0 -0
  5. package/dist/js/modern/index.js +5 -2
  6. package/dist/js/modern/modern-app.env.d.js +0 -0
  7. package/dist/js/modern/runtime/global.d.js +0 -0
  8. package/dist/js/modern/runtime/index.js +12 -4
  9. package/dist/js/modern/runtime/loadable.js +74 -56
  10. package/dist/js/modern/runtime/plugin.js +114 -79
  11. package/dist/js/modern/runtime/useModuleApps.js +40 -26
  12. package/dist/js/modern/runtime/utils/Context.js +6 -3
  13. package/dist/js/modern/runtime/utils/MApp.js +76 -72
  14. package/dist/js/modern/runtime/utils/apps.js +177 -142
  15. package/dist/js/modern/runtime/utils/setExternal.js +11 -11
  16. package/dist/js/modern/type.d.js +0 -0
  17. package/dist/js/modern/util.js +11 -9
  18. package/dist/js/node/cli/index.js +184 -169
  19. package/dist/js/node/cli/utils.js +45 -30
  20. package/dist/js/node/global.d.js +0 -0
  21. package/dist/js/node/index.js +29 -24
  22. package/dist/js/node/modern-app.env.d.js +0 -0
  23. package/dist/js/node/runtime/global.d.js +0 -0
  24. package/dist/js/node/runtime/index.js +35 -44
  25. package/dist/js/node/runtime/loadable.js +95 -61
  26. package/dist/js/node/runtime/plugin.js +147 -95
  27. package/dist/js/node/runtime/useModuleApps.js +64 -34
  28. package/dist/js/node/runtime/utils/Context.js +30 -10
  29. package/dist/js/node/runtime/utils/MApp.js +107 -84
  30. package/dist/js/node/runtime/utils/apps.js +204 -146
  31. package/dist/js/node/runtime/utils/setExternal.js +35 -18
  32. package/dist/js/node/type.d.js +0 -0
  33. package/dist/js/node/util.js +34 -19
  34. package/dist/js/treeshaking/cli/index.js +402 -285
  35. package/dist/js/treeshaking/cli/utils.js +28 -31
  36. package/dist/js/treeshaking/global.d.js +1 -0
  37. package/dist/js/treeshaking/index.js +3 -2
  38. package/dist/js/treeshaking/modern-app.env.d.js +1 -0
  39. package/dist/js/treeshaking/runtime/global.d.js +1 -0
  40. package/dist/js/treeshaking/runtime/index.js +5 -4
  41. package/dist/js/treeshaking/runtime/loadable.js +230 -109
  42. package/dist/js/treeshaking/runtime/plugin.js +469 -168
  43. package/dist/js/treeshaking/runtime/useModuleApps.js +55 -31
  44. package/dist/js/treeshaking/runtime/utils/Context.js +3 -3
  45. package/dist/js/treeshaking/runtime/utils/MApp.js +348 -180
  46. package/dist/js/treeshaking/runtime/utils/apps.js +536 -230
  47. package/dist/js/treeshaking/runtime/utils/setExternal.js +12 -11
  48. package/dist/js/treeshaking/type.d.js +1 -0
  49. package/dist/js/treeshaking/util.js +7 -9
  50. package/dist/types/cli/index.d.ts +2 -0
  51. package/dist/types/runtime/plugin.d.ts +2 -0
  52. package/dist/types/runtime/utils/setExternal.d.ts +1 -0
  53. package/package.json +11 -11
package/CHANGELOG.md CHANGED
@@ -1,5 +1,130 @@
1
1
  # @modern-js/plugin-garfish
2
2
 
3
+ ## 2.0.0-beta.4
4
+
5
+ ### Major Changes
6
+
7
+ - dda38c9c3e: chore: v2
8
+
9
+ ### Patch Changes
10
+
11
+ - 6604f1b: feat: support router basename
12
+ feat: router 插件支持设置 basename
13
+ - 21d2ddb59c: feat: support async export provider for module federation
14
+ 支持模块联邦场景异步导出 provider
15
+ - cce8ecee2d: fix: handle some `TODO` & `FIXME`, change some tests
16
+ fix: 处理一些 `TODO` 和 `FIXME`, 修改了一些 tests
17
+ - 2344eb26ed: fix: loadApp when dom is mount
18
+ 修复 dom 未渲染时挂载子应用行为
19
+ - Updated dependencies [2344eb26ed]
20
+ - Updated dependencies [a11fcf8b50]
21
+ - Updated dependencies [a931594]
22
+ - Updated dependencies [e7ce063]
23
+ - Updated dependencies [b18fa8f3ed]
24
+ - Updated dependencies [7879e8f]
25
+ - Updated dependencies [50d4675]
26
+ - Updated dependencies [c9e800d39a]
27
+ - Updated dependencies [6604f1b]
28
+ - Updated dependencies [6aca875]
29
+ - Updated dependencies [fda836f]
30
+ - Updated dependencies [d6bc321]
31
+ - Updated dependencies [3e57f2bd58]
32
+ - Updated dependencies [2e6031955e]
33
+ - Updated dependencies [c5798d2]
34
+ - Updated dependencies [fbf5eed5aa]
35
+ - Updated dependencies [a2509bfbdb]
36
+ - Updated dependencies [a7c6883]
37
+ - Updated dependencies [425e57092d]
38
+ - Updated dependencies [e4357f1856]
39
+ - Updated dependencies [7b7d12c]
40
+ - Updated dependencies [4369648ae2]
41
+ - Updated dependencies [92f0eade39]
42
+ - Updated dependencies [92c0994468]
43
+ - Updated dependencies [2cc2eb3]
44
+ - Updated dependencies [edd1cfb1af]
45
+ - Updated dependencies [cc971eabfc]
46
+ - Updated dependencies [5b9049f2e9]
47
+ - Updated dependencies [6bda14ed71]
48
+ - Updated dependencies [92004d1906]
49
+ - Updated dependencies [b8bbe036c7]
50
+ - Updated dependencies [40ed5874c6]
51
+ - Updated dependencies [60d5378632]
52
+ - Updated dependencies [d5a31df781]
53
+ - Updated dependencies [dda38c9c3e]
54
+ - Updated dependencies [8b8e1bb571]
55
+ - Updated dependencies [3bbea92b2a]
56
+ - Updated dependencies [9144c21]
57
+ - Updated dependencies [b710adb843]
58
+ - Updated dependencies [18aaf42249]
59
+ - Updated dependencies [34702d5]
60
+ - Updated dependencies [fcace5b5b9]
61
+ - Updated dependencies [ea7cf06]
62
+ - Updated dependencies [bbe4c4a]
63
+ - Updated dependencies [e4558a0]
64
+ - Updated dependencies [abf3421a75]
65
+ - Updated dependencies [543be9558e]
66
+ - Updated dependencies [14b712da84]
67
+ - @modern-js/runtime@2.0.0-beta.4
68
+ - @modern-js/utils@2.0.0-beta.4
69
+
70
+ ## 2.0.0-beta.3
71
+
72
+ ### Major Changes
73
+
74
+ - dda38c9c3e: chore: v2
75
+
76
+ ### Patch Changes
77
+
78
+ - 6604f1b: feat: support router basename
79
+ feat: router 插件支持设置 basename
80
+ - 21d2ddb: feat: support async export provider for module federation
81
+ 支持模块联邦场景异步导出 provider
82
+ - cce8ece: fix: handle some `TODO` & `FIXME`, change some tests
83
+ fix: 处理一些 `TODO` 和 `FIXME`, 修改了一些 tests
84
+ - 2344eb26ed: fix: loadApp when dom is mount
85
+ 修复 dom 未渲染时挂载子应用行为
86
+ - Updated dependencies [2344eb26ed]
87
+ - Updated dependencies [a11fcf8b50]
88
+ - Updated dependencies [e7ce063]
89
+ - Updated dependencies [b18fa8f3ed]
90
+ - Updated dependencies [c9e800d39a]
91
+ - Updated dependencies [6604f1b]
92
+ - Updated dependencies [6aca875]
93
+ - Updated dependencies [fda836f]
94
+ - Updated dependencies [3e57f2bd58]
95
+ - Updated dependencies [2e60319]
96
+ - Updated dependencies [fbf5eed5aa]
97
+ - Updated dependencies [a2509bfbdb]
98
+ - Updated dependencies [425e570]
99
+ - Updated dependencies [e4357f1]
100
+ - Updated dependencies [4369648ae2]
101
+ - Updated dependencies [92f0eade39]
102
+ - Updated dependencies [92c0994468]
103
+ - Updated dependencies [edd1cfb1af]
104
+ - Updated dependencies [cc971eabfc]
105
+ - Updated dependencies [5b9049f2e9]
106
+ - Updated dependencies [6bda14ed71]
107
+ - Updated dependencies [92004d1906]
108
+ - Updated dependencies [b8bbe036c7]
109
+ - Updated dependencies [40ed5874c6]
110
+ - Updated dependencies [60d5378632]
111
+ - Updated dependencies [d5a31df781]
112
+ - Updated dependencies [dda38c9c3e]
113
+ - Updated dependencies [8b8e1bb571]
114
+ - Updated dependencies [3bbea92b2a]
115
+ - Updated dependencies [b710adb]
116
+ - Updated dependencies [18aaf42249]
117
+ - Updated dependencies [34702d5]
118
+ - Updated dependencies [fcace5b5b9]
119
+ - Updated dependencies [ea7cf06]
120
+ - Updated dependencies [bbe4c4a]
121
+ - Updated dependencies [e4558a0]
122
+ - Updated dependencies [abf3421a75]
123
+ - Updated dependencies [543be9558e]
124
+ - Updated dependencies [14b712da84]
125
+ - @modern-js/runtime@2.0.0-beta.3
126
+ - @modern-js/utils@2.0.0-beta.3
127
+
3
128
  ## 2.0.0-beta.2
4
129
 
5
130
  ### Major Changes
@@ -1,61 +1,94 @@
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
- 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; }
3
- 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; }
4
- import path from 'path';
5
- import { createRuntimeExportsUtils, PLUGIN_SCHEMAS } from '@modern-js/utils';
6
- import { logger } from "../util";
7
- import { getRuntimeConfig, makeProvider, makeRenderFunction, setRuntimeConfig, generateAsyncEntry } from "./utils";
8
- export const externals = {
9
- 'react-dom': 'react-dom',
10
- react: 'react'
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
4
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __spreadValues = (a, b) => {
7
+ for (var prop in b || (b = {}))
8
+ if (__hasOwnProp.call(b, prop))
9
+ __defNormalProp(a, prop, b[prop]);
10
+ if (__getOwnPropSymbols)
11
+ for (var prop of __getOwnPropSymbols(b)) {
12
+ if (__propIsEnum.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ }
15
+ return a;
16
+ };
17
+ var __async = (__this, __arguments, generator) => {
18
+ return new Promise((resolve, reject) => {
19
+ var fulfilled = (value) => {
20
+ try {
21
+ step(generator.next(value));
22
+ } catch (e) {
23
+ reject(e);
24
+ }
25
+ };
26
+ var rejected = (value) => {
27
+ try {
28
+ step(generator.throw(value));
29
+ } catch (e) {
30
+ reject(e);
31
+ }
32
+ };
33
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
34
+ step((generator = generator.apply(__this, __arguments)).next());
35
+ });
11
36
  };
12
- export function getDefaultMicroFrontedConfig(microFrontend) {
37
+ import path from "path";
38
+ import { createRuntimeExportsUtils, PLUGIN_SCHEMAS } from "@modern-js/utils";
39
+ import { logger } from "../util";
40
+ import {
41
+ getRuntimeConfig,
42
+ makeProvider,
43
+ makeRenderFunction,
44
+ setRuntimeConfig,
45
+ generateAsyncEntry
46
+ } from "./utils";
47
+ const externals = { "react-dom": "react-dom", react: "react" };
48
+ function getDefaultMicroFrontedConfig(microFrontend) {
13
49
  if (microFrontend === true) {
14
50
  return {
15
51
  enableHtmlEntry: true,
16
52
  externalBasicLibrary: false,
17
- moduleApp: ''
53
+ moduleApp: ""
18
54
  };
19
55
  }
20
- return _objectSpread({
56
+ return __spreadValues({
21
57
  enableHtmlEntry: true,
22
58
  externalBasicLibrary: false
23
59
  }, microFrontend);
24
60
  }
25
- export default (({
26
- pluginName: _pluginName = '@modern-js/plugin-garfish',
27
- runtimePluginName: _runtimePluginName = '@modern-js/runtime/plugins',
28
- mfPackagePath: _mfPackagePath = path.resolve(__dirname, '../../../../')
61
+ var cli_default = ({
62
+ pluginName = "@modern-js/plugin-garfish",
63
+ runtimePluginName = "@modern-js/runtime/plugins",
64
+ mfPackagePath = path.resolve(__dirname, "../../../../")
29
65
  } = {}) => ({
30
- name: '@modern-js/plugin-garfish',
31
- setup: ({
32
- useAppContext,
33
- useResolvedConfigContext,
34
- useConfigContext
35
- }) => {
66
+ name: "@modern-js/plugin-garfish",
67
+ setup: ({ useAppContext, useResolvedConfigContext, useConfigContext }) => {
36
68
  let pluginsExportsUtils;
37
69
  let runtimeExportsUtils;
38
70
  return {
39
71
  validateSchema() {
40
- return PLUGIN_SCHEMAS['@modern-js/plugin-garfish'];
72
+ return PLUGIN_SCHEMAS["@modern-js/plugin-garfish"];
41
73
  },
42
- resolvedConfig: async config => {
43
- const {
44
- resolved
45
- } = config;
46
- const {
47
- masterApp,
48
- router
49
- } = getRuntimeConfig(resolved);
74
+ resolvedConfig: (config) => __async(void 0, null, function* () {
75
+ var _a;
76
+ const { resolved } = config;
77
+ const { masterApp, router } = getRuntimeConfig(resolved);
50
78
  const nConfig = {
51
- resolved: _objectSpread({}, resolved)
79
+ resolved: __spreadValues({}, resolved)
52
80
  };
53
81
  if (masterApp) {
54
- var _router$historyOption;
55
- // basename does not exist use router's basename
56
- setRuntimeConfig(nConfig.resolved, 'masterApp', Object.assign(typeof masterApp === 'object' ? _objectSpread({}, masterApp) : {}, {
57
- 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) || '/'
58
- }));
82
+ setRuntimeConfig(
83
+ nConfig.resolved,
84
+ "masterApp",
85
+ Object.assign(
86
+ typeof masterApp === "object" ? __spreadValues({}, masterApp) : {},
87
+ {
88
+ basename: ((_a = router == null ? void 0 : router.historyOptions) == null ? void 0 : _a.basename) || (router == null ? void 0 : router.basename) || "/"
89
+ }
90
+ )
91
+ );
59
92
  }
60
93
  logger(`resolvedConfig`, {
61
94
  output: nConfig.resolved.output,
@@ -64,27 +97,26 @@ export default (({
64
97
  server: nConfig.resolved.server
65
98
  });
66
99
  return nConfig;
67
- },
100
+ }),
68
101
  config() {
69
- var _useConfig$output, _useConfig$deploy;
70
- // eslint-disable-next-line react-hooks/rules-of-hooks
102
+ var _a, _b, _c;
71
103
  const useConfig = useConfigContext();
72
- logger('useConfig', useConfig);
73
-
74
- // eslint-disable-next-line react-hooks/rules-of-hooks
104
+ logger("useConfig", useConfig);
75
105
  const config = useAppContext();
76
- pluginsExportsUtils = createRuntimeExportsUtils(config.internalDirectory, 'plugins');
77
- runtimeExportsUtils = createRuntimeExportsUtils(config.internalDirectory, 'index');
78
- let disableCssExtract = ((_useConfig$output = useConfig.output) === null || _useConfig$output === void 0 ? void 0 : _useConfig$output.disableCssExtract) || false;
79
-
80
- // When the micro-frontend application js entry, there is no need to extract css, close cssExtract
81
- if ((_useConfig$deploy = useConfig.deploy) !== null && _useConfig$deploy !== void 0 && _useConfig$deploy.microFrontend) {
82
- var _useConfig$deploy2;
83
- const {
84
- enableHtmlEntry
85
- } = getDefaultMicroFrontedConfig((_useConfig$deploy2 = useConfig.deploy) === null || _useConfig$deploy2 === void 0 ? void 0 : _useConfig$deploy2.microFrontend);
106
+ pluginsExportsUtils = createRuntimeExportsUtils(
107
+ config.internalDirectory,
108
+ "plugins"
109
+ );
110
+ runtimeExportsUtils = createRuntimeExportsUtils(
111
+ config.internalDirectory,
112
+ "index"
113
+ );
114
+ let disableCssExtract = ((_a = useConfig.output) == null ? void 0 : _a.disableCssExtract) || false;
115
+ if ((_b = useConfig.deploy) == null ? void 0 : _b.microFrontend) {
116
+ const { enableHtmlEntry } = getDefaultMicroFrontedConfig(
117
+ (_c = useConfig.deploy) == null ? void 0 : _c.microFrontend
118
+ );
86
119
  if (!enableHtmlEntry) {
87
- // FIXME: the handle the `disableCssExtract` config
88
120
  disableCssExtract = true;
89
121
  }
90
122
  }
@@ -94,61 +126,54 @@ export default (({
94
126
  },
95
127
  source: {
96
128
  alias: {
97
- '@modern-js/runtime/plugins': pluginsExportsUtils.getPath(),
98
- '@modern-js/runtime/garfish': _mfPackagePath
129
+ "@modern-js/runtime/plugins": pluginsExportsUtils.getPath(),
130
+ "@modern-js/runtime/garfish": mfPackagePath
99
131
  }
100
132
  },
101
133
  tools: {
102
134
  devServer: {
103
135
  headers: {
104
- 'Access-Control-Allow-Origin': '*'
136
+ "Access-Control-Allow-Origin": "*"
105
137
  }
106
138
  },
107
139
  webpackChain: (chain, {
108
140
  webpack,
109
- env: _env = process.env.NODE_ENV || 'development',
141
+ env = process.env.NODE_ENV || "development",
110
142
  CHAIN_ID
111
143
  }) => {
112
- var _resolveOptions$deplo, _resolveWebpackConfig;
113
- // eslint-disable-next-line react-hooks/rules-of-hooks
144
+ var _a2, _b2, _c2, _d;
114
145
  const resolveOptions = useResolvedConfigContext();
115
- if (resolveOptions !== null && resolveOptions !== void 0 && (_resolveOptions$deplo = resolveOptions.deploy) !== null && _resolveOptions$deplo !== void 0 && _resolveOptions$deplo.microFrontend) {
116
- var _resolveOptions$serve, _resolveOptions$deplo2;
117
- chain.output.libraryTarget('umd');
118
- if (resolveOptions !== null && resolveOptions !== void 0 && (_resolveOptions$serve = resolveOptions.server) !== null && _resolveOptions$serve !== void 0 && _resolveOptions$serve.port && _env === 'development') {
119
- chain.output.publicPath(`//localhost:${resolveOptions.server.port}/`);
146
+ if ((_a2 = resolveOptions == null ? void 0 : resolveOptions.deploy) == null ? void 0 : _a2.microFrontend) {
147
+ chain.output.libraryTarget("umd");
148
+ if (((_b2 = resolveOptions == null ? void 0 : resolveOptions.server) == null ? void 0 : _b2.port) && env === "development") {
149
+ chain.output.publicPath(
150
+ `//localhost:${resolveOptions.server.port}/`
151
+ );
120
152
  }
121
-
122
- // add comments avoid sourcemap abnormal
123
153
  if (webpack.BannerPlugin) {
124
- chain.plugin(CHAIN_ID.PLUGIN.BANNER).use(webpack.BannerPlugin, [{
125
- banner: 'Micro front-end'
126
- }]);
154
+ chain.plugin(CHAIN_ID.PLUGIN.BANNER).use(webpack.BannerPlugin, [{ banner: "Micro front-end" }]);
127
155
  }
128
- const {
129
- enableHtmlEntry,
130
- externalBasicLibrary
131
- } = getDefaultMicroFrontedConfig((_resolveOptions$deplo2 = resolveOptions.deploy) === null || _resolveOptions$deplo2 === void 0 ? void 0 : _resolveOptions$deplo2.microFrontend);
132
- // external
156
+ const { enableHtmlEntry, externalBasicLibrary } = getDefaultMicroFrontedConfig(
157
+ (_c2 = resolveOptions.deploy) == null ? void 0 : _c2.microFrontend
158
+ );
133
159
  if (externalBasicLibrary) {
134
160
  chain.externals(externals);
135
161
  }
136
- // use html mode
137
162
  if (!enableHtmlEntry) {
138
- chain.output.filename('index.js');
163
+ chain.output.filename("index.js");
139
164
  chain.plugins.delete(`${CHAIN_ID.PLUGIN.HTML}-main`);
140
165
  chain.optimization.runtimeChunk(false);
141
166
  chain.optimization.splitChunks({
142
- chunks: 'async'
167
+ chunks: "async"
143
168
  });
144
169
  }
145
170
  }
146
171
  const resolveWebpackConfig = chain.toConfig();
147
- logger('webpackConfig', {
172
+ logger("webpackConfig", {
148
173
  output: resolveWebpackConfig.output,
149
174
  externals: resolveWebpackConfig.externals,
150
- env: _env,
151
- alias: (_resolveWebpackConfig = resolveWebpackConfig.resolve) === null || _resolveWebpackConfig === void 0 ? void 0 : _resolveWebpackConfig.alias,
175
+ env,
176
+ alias: (_d = resolveWebpackConfig.resolve) == null ? void 0 : _d.alias,
152
177
  plugins: resolveWebpackConfig.plugins
153
178
  });
154
179
  }
@@ -156,104 +181,84 @@ export default (({
156
181
  };
157
182
  },
158
183
  addRuntimeExports() {
159
- const addExportStatement = `export { default as garfish, default as masterApp, hoistNonReactStatics } from '${_pluginName}'`;
160
- logger('exportStatement', addExportStatement);
184
+ const addExportStatement = `export { default as garfish, default as masterApp, hoistNonReactStatics } from '${pluginName}'`;
185
+ logger("exportStatement", addExportStatement);
161
186
  pluginsExportsUtils.addExport(addExportStatement);
162
- runtimeExportsUtils.addExport(`export * from '${_mfPackagePath}'`);
187
+ runtimeExportsUtils.addExport(`export * from '${mfPackagePath}'`);
163
188
  },
164
- modifyEntryImports({
165
- entrypoint,
166
- imports
167
- }) {
168
- // eslint-disable-next-line react-hooks/rules-of-hooks
189
+ modifyEntryImports({ entrypoint, imports }) {
169
190
  const config = useResolvedConfigContext();
170
- const {
171
- masterApp
172
- } = getRuntimeConfig(config);
191
+ const { masterApp } = getRuntimeConfig(config);
173
192
  if (masterApp) {
174
193
  imports.push({
175
- value: _runtimePluginName,
176
- specifiers: [{
177
- imported: 'garfish'
178
- }]
194
+ value: runtimePluginName,
195
+ specifiers: [
196
+ {
197
+ imported: "garfish"
198
+ }
199
+ ]
179
200
  });
180
201
  imports.push({
181
- value: _runtimePluginName,
182
- specifiers: [{
183
- imported: 'masterApp'
184
- }]
202
+ value: runtimePluginName,
203
+ specifiers: [
204
+ {
205
+ imported: "masterApp"
206
+ }
207
+ ]
185
208
  });
186
209
  }
187
210
  imports.push({
188
- value: _runtimePluginName,
189
- specifiers: [{
190
- imported: 'hoistNonReactStatics'
191
- }]
211
+ value: runtimePluginName,
212
+ specifiers: [
213
+ {
214
+ imported: "hoistNonReactStatics"
215
+ }
216
+ ]
192
217
  });
193
218
  imports.push({
194
- value: 'react-dom',
195
- specifiers: [{
196
- imported: 'unmountComponentAtNode'
197
- }, {
198
- imported: 'createPortal'
199
- }]
219
+ value: "react-dom",
220
+ specifiers: [
221
+ {
222
+ imported: "unmountComponentAtNode"
223
+ },
224
+ {
225
+ imported: "createPortal"
226
+ }
227
+ ]
200
228
  });
201
- return {
202
- imports,
203
- entrypoint
204
- };
229
+ return { imports, entrypoint };
205
230
  },
206
- modifyEntryRuntimePlugins({
207
- entrypoint,
208
- plugins
209
- }) {
210
- // eslint-disable-next-line react-hooks/rules-of-hooks
231
+ modifyEntryRuntimePlugins({ entrypoint, plugins }) {
211
232
  const config = useResolvedConfigContext();
212
- const {
213
- masterApp
214
- } = getRuntimeConfig(config);
233
+ const { masterApp } = getRuntimeConfig(config);
215
234
  if (masterApp) {
216
- logger('garfishPlugin options', masterApp);
235
+ logger("garfishPlugin options", masterApp);
217
236
  plugins.push({
218
- name: 'garfish',
219
- args: 'masterApp',
237
+ name: "garfish",
238
+ args: "masterApp",
220
239
  options: masterApp === true ? JSON.stringify({}) : JSON.stringify(masterApp)
221
240
  });
222
241
  }
223
- return {
224
- entrypoint,
225
- plugins
226
- };
242
+ return { entrypoint, plugins };
227
243
  },
228
- modifyEntryRenderFunction({
229
- entrypoint,
230
- code
231
- }) {
232
- var _config$deploy;
233
- // eslint-disable-next-line react-hooks/rules-of-hooks
244
+ modifyEntryRenderFunction({ entrypoint, code }) {
245
+ var _a;
234
246
  const config = useResolvedConfigContext();
235
- if (!(config !== null && config !== void 0 && (_config$deploy = config.deploy) !== null && _config$deploy !== void 0 && _config$deploy.microFrontend)) {
236
- return {
237
- entrypoint,
238
- code
239
- };
247
+ if (!((_a = config == null ? void 0 : config.deploy) == null ? void 0 : _a.microFrontend)) {
248
+ return { entrypoint, code };
240
249
  }
241
250
  const nCode = makeRenderFunction(code);
242
- logger('makeRenderFunction', nCode);
251
+ logger("makeRenderFunction", nCode);
243
252
  return {
244
253
  entrypoint,
245
254
  code: nCode
246
255
  };
247
256
  },
248
- modifyAsyncEntry({
249
- entrypoint,
250
- code
251
- }) {
252
- var _config$deploy2, _config$source;
253
- // eslint-disable-next-line react-hooks/rules-of-hooks
257
+ modifyAsyncEntry({ entrypoint, code }) {
258
+ var _a, _b;
254
259
  const config = useResolvedConfigContext();
255
260
  let finalCode = code;
256
- if (config !== null && config !== void 0 && (_config$deploy2 = config.deploy) !== null && _config$deploy2 !== void 0 && _config$deploy2.microFrontend && config !== null && config !== void 0 && (_config$source = config.source) !== null && _config$source !== void 0 && _config$source.enableAsyncEntry) {
261
+ if (((_a = config == null ? void 0 : config.deploy) == null ? void 0 : _a.microFrontend) && ((_b = config == null ? void 0 : config.source) == null ? void 0 : _b.enableAsyncEntry)) {
257
262
  finalCode = generateAsyncEntry(code);
258
263
  return {
259
264
  entrypoint,
@@ -265,16 +270,12 @@ export default (({
265
270
  code: finalCode
266
271
  };
267
272
  },
268
- modifyEntryExport({
269
- entrypoint,
270
- exportStatement
271
- }) {
272
- var _config$deploy3;
273
- // eslint-disable-next-line react-hooks/rules-of-hooks
273
+ modifyEntryExport({ entrypoint, exportStatement }) {
274
+ var _a;
274
275
  const config = useResolvedConfigContext();
275
- if (config !== null && config !== void 0 && (_config$deploy3 = config.deploy) !== null && _config$deploy3 !== void 0 && _config$deploy3.microFrontend) {
276
+ if ((_a = config == null ? void 0 : config.deploy) == null ? void 0 : _a.microFrontend) {
276
277
  const exportStatementCode = makeProvider();
277
- logger('exportStatement', exportStatementCode);
278
+ logger("exportStatement", exportStatementCode);
278
279
  return {
279
280
  entrypoint,
280
281
  exportStatement: exportStatementCode
@@ -287,4 +288,9 @@ export default (({
287
288
  }
288
289
  };
289
290
  }
290
- }));
291
+ });
292
+ export {
293
+ cli_default as default,
294
+ externals,
295
+ getDefaultMicroFrontedConfig
296
+ };
@@ -1,4 +1,4 @@
1
- export const makeProvider = () => `
1
+ const makeProvider = () => `
2
2
  export const provider = function ({basename, dom}) {
3
3
  return {
4
4
  render({basename, dom, props, appName}) {
@@ -79,40 +79,41 @@ function generateAppWrapperAndRootDom ({ App, props, dom }) {
79
79
  return { AppWrapper, mountNode }
80
80
  }
81
81
  `;
82
- export const makeRenderFunction = code => {
82
+ const makeRenderFunction = (code) => {
83
83
  const inGarfishToRender = `
84
84
  const { basename, props, dom, appName } = typeof arguments[0] === 'object' && arguments[0] || {};
85
85
  if (!canContinueRender({ dom, appName })) return null;
86
86
  let { AppWrapper, mountNode } = generateAppWrapperAndRootDom({App, props, dom});
87
87
  `;
88
- return inGarfishToRender + code.replace(`router(`, `generateRouterPlugin(basename,`).replace('(App)', `(AppWrapper)`).replace(/MOUNT_ID/g, 'mountNode').replace(`bootstrap(AppWrapper, mountNode, root`, 'bootstrap(AppWrapper, mountNode, root = IS_REACT18 ? ReactDOM.createRoot(mountNode) : null');
88
+ return inGarfishToRender + code.replace(`router(`, `generateRouterPlugin(basename,`).replace("(App)", `(AppWrapper)`).replace(/MOUNT_ID/g, "mountNode").replace(
89
+ `bootstrap(AppWrapper, mountNode, root`,
90
+ "bootstrap(AppWrapper, mountNode, root = IS_REACT18 ? ReactDOM.createRoot(mountNode) : null"
91
+ );
89
92
  };
90
-
91
- // support legacy config
92
- export function getRuntimeConfig(config) {
93
- var _config$runtime;
94
- if (config !== null && config !== void 0 && (_config$runtime = config.runtime) !== null && _config$runtime !== void 0 && _config$runtime.features) {
95
- var _config$runtime2;
96
- return config === null || config === void 0 ? void 0 : (_config$runtime2 = config.runtime) === null || _config$runtime2 === void 0 ? void 0 : _config$runtime2.features;
93
+ function getRuntimeConfig(config) {
94
+ var _a, _b;
95
+ if ((_a = config == null ? void 0 : config.runtime) == null ? void 0 : _a.features) {
96
+ return (_b = config == null ? void 0 : config.runtime) == null ? void 0 : _b.features;
97
97
  }
98
- return (config === null || config === void 0 ? void 0 : config.runtime) || {};
98
+ return (config == null ? void 0 : config.runtime) || {};
99
99
  }
100
-
101
- // support legacy config
102
- export function setRuntimeConfig(config, key, value) {
103
- var _config$runtime3, _config$runtime4;
104
- 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]) {
100
+ function setRuntimeConfig(config, key, value) {
101
+ var _a, _b;
102
+ if (((_a = config == null ? void 0 : config.runtime) == null ? void 0 : _a.features) && ((_b = config == null ? void 0 : config.runtime) == null ? void 0 : _b.features[key])) {
105
103
  config.runtime.features[key] = value;
106
- return undefined;
104
+ return void 0;
107
105
  }
108
- if (config !== null && config !== void 0 && config.runtime && config !== null && config !== void 0 && config.runtime[key]) {
106
+ if ((config == null ? void 0 : config.runtime) && (config == null ? void 0 : config.runtime[key])) {
109
107
  config.runtime[key] = value;
110
- return undefined;
108
+ return void 0;
111
109
  }
112
- return undefined;
110
+ return void 0;
113
111
  }
114
- export const generateAsyncEntry = code => {
115
- const transformCode = code.replace(`import('./bootstrap.js');`, `if (!window.__GARFISH__) { import('./bootstrap.js'); }`);
112
+ const generateAsyncEntry = (code) => {
113
+ const transformCode = code.replace(
114
+ `import('./bootstrap.js');`,
115
+ `if (!window.__GARFISH__) { import('./bootstrap.js'); }`
116
+ );
116
117
  return `
117
118
  export const provider = async (...args) => {
118
119
  const exports = await import('./bootstrap');
@@ -120,4 +121,11 @@ export const generateAsyncEntry = code => {
120
121
  };
121
122
  ${transformCode}
122
123
  `;
123
- };
124
+ };
125
+ export {
126
+ generateAsyncEntry,
127
+ getRuntimeConfig,
128
+ makeProvider,
129
+ makeRenderFunction,
130
+ setRuntimeConfig
131
+ };
File without changes
@@ -1,2 +1,5 @@
1
- export { default } from "./runtime";
2
- export * from "./runtime";
1
+ import { default as default2 } from "./runtime";
2
+ export * from "./runtime";
3
+ export {
4
+ default2 as default
5
+ };