@modern-js/plugin-garfish 2.0.0-beta.3 → 2.0.0-beta.5

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 (58) hide show
  1. package/CHANGELOG.md +67 -0
  2. package/dist/js/modern/cli/index.js +167 -157
  3. package/dist/js/modern/cli/types.js +0 -0
  4. package/dist/js/modern/cli/utils.js +31 -23
  5. package/dist/js/modern/global.d.js +0 -0
  6. package/dist/js/modern/index.js +5 -2
  7. package/dist/js/modern/modern-app.env.d.js +0 -0
  8. package/dist/js/modern/runtime/global.d.js +0 -0
  9. package/dist/js/modern/runtime/index.js +12 -4
  10. package/dist/js/modern/runtime/loadable.js +74 -56
  11. package/dist/js/modern/runtime/plugin.js +114 -79
  12. package/dist/js/modern/runtime/useModuleApps.js +40 -26
  13. package/dist/js/modern/runtime/utils/Context.js +6 -3
  14. package/dist/js/modern/runtime/utils/MApp.js +76 -72
  15. package/dist/js/modern/runtime/utils/apps.js +181 -132
  16. package/dist/js/modern/runtime/utils/setExternal.js +11 -11
  17. package/dist/js/modern/util.js +11 -9
  18. package/dist/js/node/cli/index.js +191 -169
  19. package/dist/js/node/cli/types.js +0 -0
  20. package/dist/js/node/cli/utils.js +53 -30
  21. package/dist/js/node/global.d.js +0 -0
  22. package/dist/js/node/index.js +31 -24
  23. package/dist/js/node/modern-app.env.d.js +0 -0
  24. package/dist/js/node/runtime/global.d.js +0 -0
  25. package/dist/js/node/runtime/index.js +42 -43
  26. package/dist/js/node/runtime/loadable.js +97 -61
  27. package/dist/js/node/runtime/plugin.js +147 -95
  28. package/dist/js/node/runtime/useModuleApps.js +67 -34
  29. package/dist/js/node/runtime/utils/Context.js +35 -10
  30. package/dist/js/node/runtime/utils/MApp.js +109 -84
  31. package/dist/js/node/runtime/utils/apps.js +210 -135
  32. package/dist/js/node/runtime/utils/setExternal.js +37 -18
  33. package/dist/js/node/util.js +40 -19
  34. package/dist/js/treeshaking/cli/index.js +403 -284
  35. package/dist/js/treeshaking/cli/types.js +1 -0
  36. package/dist/js/treeshaking/cli/utils.js +28 -31
  37. package/dist/js/treeshaking/global.d.js +1 -0
  38. package/dist/js/treeshaking/index.js +3 -2
  39. package/dist/js/treeshaking/modern-app.env.d.js +1 -0
  40. package/dist/js/treeshaking/runtime/global.d.js +1 -0
  41. package/dist/js/treeshaking/runtime/index.js +5 -4
  42. package/dist/js/treeshaking/runtime/loadable.js +230 -109
  43. package/dist/js/treeshaking/runtime/plugin.js +469 -168
  44. package/dist/js/treeshaking/runtime/useModuleApps.js +55 -31
  45. package/dist/js/treeshaking/runtime/utils/Context.js +3 -3
  46. package/dist/js/treeshaking/runtime/utils/MApp.js +348 -180
  47. package/dist/js/treeshaking/runtime/utils/apps.js +472 -224
  48. package/dist/js/treeshaking/runtime/utils/setExternal.js +12 -11
  49. package/dist/js/treeshaking/util.js +7 -9
  50. package/dist/types/cli/index.d.ts +3 -0
  51. package/dist/types/cli/types.d.ts +6 -0
  52. package/dist/types/runtime/index.d.ts +1 -1
  53. package/dist/types/runtime/loadable.d.ts +1 -2
  54. package/dist/types/runtime/plugin.d.ts +2 -0
  55. package/dist/types/runtime/utils/apps.d.ts +1 -0
  56. package/dist/types/runtime/utils/setExternal.d.ts +1 -0
  57. package/package.json +25 -20
  58. package/type.d.ts +5 -6
@@ -1,97 +1,144 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.externals = exports.default = void 0;
7
- exports.getDefaultMicroFrontedConfig = getDefaultMicroFrontedConfig;
8
- var _path = _interopRequireDefault(require("path"));
9
- var _utils = require("@modern-js/utils");
10
- var _util = require("../util");
11
- var _utils2 = require("./utils");
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
- 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; }
14
- 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; }
15
- 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; }
16
- const externals = {
17
- 'react-dom': 'react-dom',
18
- react: 'react'
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
9
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
+ var __spreadValues = (a, b) => {
11
+ for (var prop in b || (b = {}))
12
+ if (__hasOwnProp.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ if (__getOwnPropSymbols)
15
+ for (var prop of __getOwnPropSymbols(b)) {
16
+ if (__propIsEnum.call(b, prop))
17
+ __defNormalProp(a, prop, b[prop]);
18
+ }
19
+ return a;
20
+ };
21
+ var __export = (target, all) => {
22
+ for (var name in all)
23
+ __defProp(target, name, { get: all[name], enumerable: true });
24
+ };
25
+ var __copyProps = (to, from, except, desc) => {
26
+ if (from && typeof from === "object" || typeof from === "function") {
27
+ for (let key of __getOwnPropNames(from))
28
+ if (!__hasOwnProp.call(to, key) && key !== except)
29
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
30
+ }
31
+ return to;
19
32
  };
20
- exports.externals = externals;
33
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
34
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
35
+ mod
36
+ ));
37
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
+ var __async = (__this, __arguments, generator) => {
39
+ return new Promise((resolve, reject) => {
40
+ var fulfilled = (value) => {
41
+ try {
42
+ step(generator.next(value));
43
+ } catch (e) {
44
+ reject(e);
45
+ }
46
+ };
47
+ var rejected = (value) => {
48
+ try {
49
+ step(generator.throw(value));
50
+ } catch (e) {
51
+ reject(e);
52
+ }
53
+ };
54
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
55
+ step((generator = generator.apply(__this, __arguments)).next());
56
+ });
57
+ };
58
+ var cli_exports = {};
59
+ __export(cli_exports, {
60
+ default: () => cli_default,
61
+ externals: () => externals,
62
+ getDefaultMicroFrontedConfig: () => getDefaultMicroFrontedConfig
63
+ });
64
+ module.exports = __toCommonJS(cli_exports);
65
+ var import_path = __toESM(require("path"));
66
+ var import_utils = require("@modern-js/utils");
67
+ var import_util = require("../util");
68
+ var import_utils2 = require("./utils");
69
+ var import_types = require("./types");
70
+ const externals = { "react-dom": "react-dom", react: "react" };
21
71
  function getDefaultMicroFrontedConfig(microFrontend) {
22
72
  if (microFrontend === true) {
23
73
  return {
24
74
  enableHtmlEntry: true,
25
75
  externalBasicLibrary: false,
26
- moduleApp: ''
76
+ moduleApp: ""
27
77
  };
28
78
  }
29
- return _objectSpread({
79
+ return __spreadValues({
30
80
  enableHtmlEntry: true,
31
81
  externalBasicLibrary: false
32
82
  }, microFrontend);
33
83
  }
34
- var _default = ({
35
- pluginName: _pluginName = '@modern-js/plugin-garfish',
36
- runtimePluginName: _runtimePluginName = '@modern-js/runtime/plugins',
37
- mfPackagePath: _mfPackagePath = _path.default.resolve(__dirname, '../../../../')
84
+ var cli_default = ({
85
+ pluginName = "@modern-js/plugin-garfish",
86
+ runtimePluginName = "@modern-js/runtime/plugins",
87
+ mfPackagePath = import_path.default.resolve(__dirname, "../../../../")
38
88
  } = {}) => ({
39
- name: '@modern-js/plugin-garfish',
40
- setup: ({
41
- useAppContext,
42
- useResolvedConfigContext,
43
- useConfigContext
44
- }) => {
89
+ name: "@modern-js/plugin-garfish",
90
+ setup: ({ useAppContext, useResolvedConfigContext, useConfigContext }) => {
45
91
  let pluginsExportsUtils;
46
92
  let runtimeExportsUtils;
47
93
  return {
48
94
  validateSchema() {
49
- return _utils.PLUGIN_SCHEMAS['@modern-js/plugin-garfish'];
95
+ return import_utils.PLUGIN_SCHEMAS["@modern-js/plugin-garfish"];
50
96
  },
51
- resolvedConfig: async config => {
52
- const {
53
- resolved
54
- } = config;
55
- const {
56
- masterApp,
57
- router
58
- } = (0, _utils2.getRuntimeConfig)(resolved);
97
+ resolvedConfig: (config) => __async(void 0, null, function* () {
98
+ var _a;
99
+ const { resolved } = config;
100
+ const { masterApp, router } = (0, import_utils2.getRuntimeConfig)(resolved);
59
101
  const nConfig = {
60
- resolved: _objectSpread({}, resolved)
102
+ resolved: __spreadValues({}, resolved)
61
103
  };
62
104
  if (masterApp) {
63
- var _router$historyOption;
64
- // basename does not exist use router's basename
65
- (0, _utils2.setRuntimeConfig)(nConfig.resolved, 'masterApp', Object.assign(typeof masterApp === 'object' ? _objectSpread({}, masterApp) : {}, {
66
- 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) || '/'
67
- }));
105
+ (0, import_utils2.setRuntimeConfig)(
106
+ nConfig.resolved,
107
+ "masterApp",
108
+ Object.assign(
109
+ typeof masterApp === "object" ? __spreadValues({}, masterApp) : {},
110
+ {
111
+ basename: ((_a = router == null ? void 0 : router.historyOptions) == null ? void 0 : _a.basename) || (router == null ? void 0 : router.basename) || "/"
112
+ }
113
+ )
114
+ );
68
115
  }
69
- (0, _util.logger)(`resolvedConfig`, {
116
+ (0, import_util.logger)(`resolvedConfig`, {
70
117
  output: nConfig.resolved.output,
71
118
  runtime: nConfig.resolved.runtime,
72
119
  deploy: nConfig.resolved.deploy,
73
120
  server: nConfig.resolved.server
74
121
  });
75
122
  return nConfig;
76
- },
123
+ }),
77
124
  config() {
78
- var _useConfig$output, _useConfig$deploy;
79
- // eslint-disable-next-line react-hooks/rules-of-hooks
125
+ var _a, _b, _c;
80
126
  const useConfig = useConfigContext();
81
- (0, _util.logger)('useConfig', useConfig);
82
-
83
- // eslint-disable-next-line react-hooks/rules-of-hooks
127
+ (0, import_util.logger)("useConfig", useConfig);
84
128
  const config = useAppContext();
85
- pluginsExportsUtils = (0, _utils.createRuntimeExportsUtils)(config.internalDirectory, 'plugins');
86
- runtimeExportsUtils = (0, _utils.createRuntimeExportsUtils)(config.internalDirectory, 'index');
87
- let disableCssExtract = ((_useConfig$output = useConfig.output) === null || _useConfig$output === void 0 ? void 0 : _useConfig$output.disableCssExtract) || false;
88
-
89
- // When the micro-frontend application js entry, there is no need to extract css, close cssExtract
90
- if ((_useConfig$deploy = useConfig.deploy) !== null && _useConfig$deploy !== void 0 && _useConfig$deploy.microFrontend) {
91
- var _useConfig$deploy2;
92
- const {
93
- enableHtmlEntry
94
- } = getDefaultMicroFrontedConfig((_useConfig$deploy2 = useConfig.deploy) === null || _useConfig$deploy2 === void 0 ? void 0 : _useConfig$deploy2.microFrontend);
129
+ pluginsExportsUtils = (0, import_utils.createRuntimeExportsUtils)(
130
+ config.internalDirectory,
131
+ "plugins"
132
+ );
133
+ runtimeExportsUtils = (0, import_utils.createRuntimeExportsUtils)(
134
+ config.internalDirectory,
135
+ "index"
136
+ );
137
+ let disableCssExtract = ((_a = useConfig.output) == null ? void 0 : _a.disableCssExtract) || false;
138
+ if ((_b = useConfig.deploy) == null ? void 0 : _b.microFrontend) {
139
+ const { enableHtmlEntry } = getDefaultMicroFrontedConfig(
140
+ (_c = useConfig.deploy) == null ? void 0 : _c.microFrontend
141
+ );
95
142
  if (!enableHtmlEntry) {
96
143
  disableCssExtract = true;
97
144
  }
@@ -102,61 +149,54 @@ var _default = ({
102
149
  },
103
150
  source: {
104
151
  alias: {
105
- '@modern-js/runtime/plugins': pluginsExportsUtils.getPath(),
106
- '@modern-js/runtime/garfish': _mfPackagePath
152
+ "@modern-js/runtime/plugins": pluginsExportsUtils.getPath(),
153
+ "@modern-js/runtime/garfish": mfPackagePath
107
154
  }
108
155
  },
109
156
  tools: {
110
157
  devServer: {
111
158
  headers: {
112
- 'Access-Control-Allow-Origin': '*'
159
+ "Access-Control-Allow-Origin": "*"
113
160
  }
114
161
  },
115
162
  webpackChain: (chain, {
116
163
  webpack,
117
- env: _env = process.env.NODE_ENV || 'development',
164
+ env = process.env.NODE_ENV || "development",
118
165
  CHAIN_ID
119
166
  }) => {
120
- var _resolveOptions$deplo, _resolveWebpackConfig;
121
- // eslint-disable-next-line react-hooks/rules-of-hooks
167
+ var _a2, _b2, _c2, _d;
122
168
  const resolveOptions = useResolvedConfigContext();
123
- if (resolveOptions !== null && resolveOptions !== void 0 && (_resolveOptions$deplo = resolveOptions.deploy) !== null && _resolveOptions$deplo !== void 0 && _resolveOptions$deplo.microFrontend) {
124
- var _resolveOptions$serve, _resolveOptions$deplo2;
125
- chain.output.libraryTarget('umd');
126
- if (resolveOptions !== null && resolveOptions !== void 0 && (_resolveOptions$serve = resolveOptions.server) !== null && _resolveOptions$serve !== void 0 && _resolveOptions$serve.port && _env === 'development') {
127
- chain.output.publicPath(`//localhost:${resolveOptions.server.port}/`);
169
+ if ((_a2 = resolveOptions == null ? void 0 : resolveOptions.deploy) == null ? void 0 : _a2.microFrontend) {
170
+ chain.output.libraryTarget("umd");
171
+ if (((_b2 = resolveOptions == null ? void 0 : resolveOptions.server) == null ? void 0 : _b2.port) && env === "development") {
172
+ chain.output.publicPath(
173
+ `//localhost:${resolveOptions.server.port}/`
174
+ );
128
175
  }
129
-
130
- // add comments avoid sourcemap abnormal
131
176
  if (webpack.BannerPlugin) {
132
- chain.plugin(CHAIN_ID.PLUGIN.BANNER).use(webpack.BannerPlugin, [{
133
- banner: 'Micro front-end'
134
- }]);
177
+ chain.plugin(CHAIN_ID.PLUGIN.BANNER).use(webpack.BannerPlugin, [{ banner: "Micro front-end" }]);
135
178
  }
136
- const {
137
- enableHtmlEntry,
138
- externalBasicLibrary
139
- } = getDefaultMicroFrontedConfig((_resolveOptions$deplo2 = resolveOptions.deploy) === null || _resolveOptions$deplo2 === void 0 ? void 0 : _resolveOptions$deplo2.microFrontend);
140
- // external
179
+ const { enableHtmlEntry, externalBasicLibrary } = getDefaultMicroFrontedConfig(
180
+ (_c2 = resolveOptions.deploy) == null ? void 0 : _c2.microFrontend
181
+ );
141
182
  if (externalBasicLibrary) {
142
183
  chain.externals(externals);
143
184
  }
144
- // use html mode
145
185
  if (!enableHtmlEntry) {
146
- chain.output.filename('index.js');
186
+ chain.output.filename("index.js");
147
187
  chain.plugins.delete(`${CHAIN_ID.PLUGIN.HTML}-main`);
148
188
  chain.optimization.runtimeChunk(false);
149
189
  chain.optimization.splitChunks({
150
- chunks: 'async'
190
+ chunks: "async"
151
191
  });
152
192
  }
153
193
  }
154
194
  const resolveWebpackConfig = chain.toConfig();
155
- (0, _util.logger)('webpackConfig', {
195
+ (0, import_util.logger)("webpackConfig", {
156
196
  output: resolveWebpackConfig.output,
157
197
  externals: resolveWebpackConfig.externals,
158
- env: _env,
159
- alias: (_resolveWebpackConfig = resolveWebpackConfig.resolve) === null || _resolveWebpackConfig === void 0 ? void 0 : _resolveWebpackConfig.alias,
198
+ env,
199
+ alias: (_d = resolveWebpackConfig.resolve) == null ? void 0 : _d.alias,
160
200
  plugins: resolveWebpackConfig.plugins
161
201
  });
162
202
  }
@@ -164,105 +204,87 @@ var _default = ({
164
204
  };
165
205
  },
166
206
  addRuntimeExports() {
167
- const addExportStatement = `export { default as garfish, default as masterApp, hoistNonReactStatics } from '${_pluginName}'`;
168
- (0, _util.logger)('exportStatement', addExportStatement);
207
+ const addExportStatement = `export { default as garfish, default as masterApp, hoistNonReactStatics } from '${pluginName}/runtime'`;
208
+ (0, import_util.logger)("exportStatement", addExportStatement);
169
209
  pluginsExportsUtils.addExport(addExportStatement);
170
- runtimeExportsUtils.addExport(`export * from '${_mfPackagePath}'`);
210
+ runtimeExportsUtils.addExport(
211
+ `export * from '${mfPackagePath}/runtime'`
212
+ );
171
213
  },
172
- modifyEntryImports({
173
- entrypoint,
174
- imports
175
- }) {
176
- // eslint-disable-next-line react-hooks/rules-of-hooks
214
+ modifyEntryImports({ entrypoint, imports }) {
177
215
  const config = useResolvedConfigContext();
178
- const {
179
- masterApp
180
- } = (0, _utils2.getRuntimeConfig)(config);
216
+ const { masterApp } = (0, import_utils2.getRuntimeConfig)(config);
181
217
  if (masterApp) {
182
218
  imports.push({
183
- value: _runtimePluginName,
184
- specifiers: [{
185
- imported: 'garfish'
186
- }]
219
+ value: runtimePluginName,
220
+ specifiers: [
221
+ {
222
+ imported: "garfish"
223
+ }
224
+ ]
187
225
  });
188
226
  imports.push({
189
- value: _runtimePluginName,
190
- specifiers: [{
191
- imported: 'masterApp'
192
- }]
227
+ value: runtimePluginName,
228
+ specifiers: [
229
+ {
230
+ imported: "masterApp"
231
+ }
232
+ ]
193
233
  });
194
234
  }
195
235
  imports.push({
196
- value: _runtimePluginName,
197
- specifiers: [{
198
- imported: 'hoistNonReactStatics'
199
- }]
236
+ value: runtimePluginName,
237
+ specifiers: [
238
+ {
239
+ imported: "hoistNonReactStatics"
240
+ }
241
+ ]
200
242
  });
201
243
  imports.push({
202
- value: 'react-dom',
203
- specifiers: [{
204
- imported: 'unmountComponentAtNode'
205
- }, {
206
- imported: 'createPortal'
207
- }]
244
+ value: "react-dom",
245
+ specifiers: [
246
+ {
247
+ imported: "unmountComponentAtNode"
248
+ },
249
+ {
250
+ imported: "createPortal"
251
+ }
252
+ ]
208
253
  });
209
- return {
210
- imports,
211
- entrypoint
212
- };
254
+ return { imports, entrypoint };
213
255
  },
214
- modifyEntryRuntimePlugins({
215
- entrypoint,
216
- plugins
217
- }) {
218
- // eslint-disable-next-line react-hooks/rules-of-hooks
256
+ modifyEntryRuntimePlugins({ entrypoint, plugins }) {
219
257
  const config = useResolvedConfigContext();
220
- const {
221
- masterApp
222
- } = (0, _utils2.getRuntimeConfig)(config);
258
+ const { masterApp } = (0, import_utils2.getRuntimeConfig)(config);
223
259
  if (masterApp) {
224
- (0, _util.logger)('garfishPlugin options', masterApp);
260
+ (0, import_util.logger)("garfishPlugin options", masterApp);
225
261
  plugins.push({
226
- name: 'garfish',
227
- args: 'masterApp',
262
+ name: "garfish",
263
+ args: "masterApp",
228
264
  options: masterApp === true ? JSON.stringify({}) : JSON.stringify(masterApp)
229
265
  });
230
266
  }
231
- return {
232
- entrypoint,
233
- plugins
234
- };
267
+ return { entrypoint, plugins };
235
268
  },
236
- modifyEntryRenderFunction({
237
- entrypoint,
238
- code
239
- }) {
240
- var _config$deploy;
241
- // eslint-disable-next-line react-hooks/rules-of-hooks
269
+ modifyEntryRenderFunction({ entrypoint, code }) {
270
+ var _a;
242
271
  const config = useResolvedConfigContext();
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
- };
272
+ if (!((_a = config == null ? void 0 : config.deploy) == null ? void 0 : _a.microFrontend)) {
273
+ return { entrypoint, code };
248
274
  }
249
- const nCode = (0, _utils2.makeRenderFunction)(code);
250
- (0, _util.logger)('makeRenderFunction', nCode);
275
+ const nCode = (0, import_utils2.makeRenderFunction)(code);
276
+ (0, import_util.logger)("makeRenderFunction", nCode);
251
277
  return {
252
278
  entrypoint,
253
279
  code: nCode
254
280
  };
255
281
  },
256
- modifyAsyncEntry({
257
- entrypoint,
258
- code
259
- }) {
260
- var _config$deploy2, _config$source;
261
- // eslint-disable-next-line react-hooks/rules-of-hooks
282
+ modifyAsyncEntry({ entrypoint, code }) {
283
+ var _a, _b;
262
284
  const config = useResolvedConfigContext();
263
285
  let finalCode = code;
264
- 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) {
265
- finalCode = (0, _utils2.generateAsyncEntry)(code);
286
+ 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)) {
287
+ finalCode = (0, import_utils2.generateAsyncEntry)(code);
266
288
  return {
267
289
  entrypoint,
268
290
  code: `${finalCode}`
@@ -273,16 +295,12 @@ var _default = ({
273
295
  code: finalCode
274
296
  };
275
297
  },
276
- modifyEntryExport({
277
- entrypoint,
278
- exportStatement
279
- }) {
280
- var _config$deploy3;
281
- // eslint-disable-next-line react-hooks/rules-of-hooks
298
+ modifyEntryExport({ entrypoint, exportStatement }) {
299
+ var _a;
282
300
  const config = useResolvedConfigContext();
283
- if (config !== null && config !== void 0 && (_config$deploy3 = config.deploy) !== null && _config$deploy3 !== void 0 && _config$deploy3.microFrontend) {
284
- const exportStatementCode = (0, _utils2.makeProvider)();
285
- (0, _util.logger)('exportStatement', exportStatementCode);
301
+ if ((_a = config == null ? void 0 : config.deploy) == null ? void 0 : _a.microFrontend) {
302
+ const exportStatementCode = (0, import_utils2.makeProvider)();
303
+ (0, import_util.logger)("exportStatement", exportStatementCode);
286
304
  return {
287
305
  entrypoint,
288
306
  exportStatement: exportStatementCode
@@ -296,4 +314,8 @@ var _default = ({
296
314
  };
297
315
  }
298
316
  });
299
- exports.default = _default;
317
+ // Annotate the CommonJS export names for ESM import in node:
318
+ 0 && (module.exports = {
319
+ externals,
320
+ getDefaultMicroFrontedConfig
321
+ });
File without changes
@@ -1,12 +1,29 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var utils_exports = {};
19
+ __export(utils_exports, {
20
+ generateAsyncEntry: () => generateAsyncEntry,
21
+ getRuntimeConfig: () => getRuntimeConfig,
22
+ makeProvider: () => makeProvider,
23
+ makeRenderFunction: () => makeRenderFunction,
24
+ setRuntimeConfig: () => setRuntimeConfig
5
25
  });
6
- exports.generateAsyncEntry = void 0;
7
- exports.getRuntimeConfig = getRuntimeConfig;
8
- exports.makeRenderFunction = exports.makeProvider = void 0;
9
- exports.setRuntimeConfig = setRuntimeConfig;
26
+ module.exports = __toCommonJS(utils_exports);
10
27
  const makeProvider = () => `
11
28
  export const provider = function ({basename, dom}) {
12
29
  return {
@@ -88,42 +105,41 @@ function generateAppWrapperAndRootDom ({ App, props, dom }) {
88
105
  return { AppWrapper, mountNode }
89
106
  }
90
107
  `;
91
- exports.makeProvider = makeProvider;
92
- const makeRenderFunction = code => {
108
+ const makeRenderFunction = (code) => {
93
109
  const inGarfishToRender = `
94
110
  const { basename, props, dom, appName } = typeof arguments[0] === 'object' && arguments[0] || {};
95
111
  if (!canContinueRender({ dom, appName })) return null;
96
112
  let { AppWrapper, mountNode } = generateAppWrapperAndRootDom({App, props, dom});
97
113
  `;
98
- 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');
114
+ return inGarfishToRender + code.replace(`router(`, `generateRouterPlugin(basename,`).replace("(App)", `(AppWrapper)`).replace(/MOUNT_ID/g, "mountNode").replace(
115
+ `bootstrap(AppWrapper, mountNode, root`,
116
+ "bootstrap(AppWrapper, mountNode, root = IS_REACT18 ? ReactDOM.createRoot(mountNode) : null"
117
+ );
99
118
  };
100
-
101
- // support legacy config
102
- exports.makeRenderFunction = makeRenderFunction;
103
119
  function getRuntimeConfig(config) {
104
- var _config$runtime;
105
- if (config !== null && config !== void 0 && (_config$runtime = config.runtime) !== null && _config$runtime !== void 0 && _config$runtime.features) {
106
- var _config$runtime2;
107
- return config === null || config === void 0 ? void 0 : (_config$runtime2 = config.runtime) === null || _config$runtime2 === void 0 ? void 0 : _config$runtime2.features;
120
+ var _a, _b;
121
+ if ((_a = config == null ? void 0 : config.runtime) == null ? void 0 : _a.features) {
122
+ return (_b = config == null ? void 0 : config.runtime) == null ? void 0 : _b.features;
108
123
  }
109
- return (config === null || config === void 0 ? void 0 : config.runtime) || {};
124
+ return (config == null ? void 0 : config.runtime) || {};
110
125
  }
111
-
112
- // support legacy config
113
126
  function setRuntimeConfig(config, key, value) {
114
- var _config$runtime3, _config$runtime4;
115
- 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]) {
127
+ var _a, _b;
128
+ 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])) {
116
129
  config.runtime.features[key] = value;
117
- return undefined;
130
+ return void 0;
118
131
  }
119
- if (config !== null && config !== void 0 && config.runtime && config !== null && config !== void 0 && config.runtime[key]) {
132
+ if ((config == null ? void 0 : config.runtime) && (config == null ? void 0 : config.runtime[key])) {
120
133
  config.runtime[key] = value;
121
- return undefined;
134
+ return void 0;
122
135
  }
123
- return undefined;
136
+ return void 0;
124
137
  }
125
- const generateAsyncEntry = code => {
126
- const transformCode = code.replace(`import('./bootstrap.js');`, `if (!window.__GARFISH__) { import('./bootstrap.js'); }`);
138
+ const generateAsyncEntry = (code) => {
139
+ const transformCode = code.replace(
140
+ `import('./bootstrap.js');`,
141
+ `if (!window.__GARFISH__) { import('./bootstrap.js'); }`
142
+ );
127
143
  return `
128
144
  export const provider = async (...args) => {
129
145
  const exports = await import('./bootstrap');
@@ -132,4 +148,11 @@ const generateAsyncEntry = code => {
132
148
  ${transformCode}
133
149
  `;
134
150
  };
135
- exports.generateAsyncEntry = generateAsyncEntry;
151
+ // Annotate the CommonJS export names for ESM import in node:
152
+ 0 && (module.exports = {
153
+ generateAsyncEntry,
154
+ getRuntimeConfig,
155
+ makeProvider,
156
+ makeRenderFunction,
157
+ setRuntimeConfig
158
+ });
File without changes