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