@modern-js/plugin-garfish 1.21.4 → 1.21.6

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # @modern-js/plugin-garfish
2
2
 
3
+ ## 1.21.6
4
+
5
+ ### Patch Changes
6
+
7
+ - 57f7399: feat: support async export provider for module federation
8
+ 支持模块联邦场景异步导出 provider
9
+ - Updated dependencies [bb7788d]
10
+ - Updated dependencies [e951ac1]
11
+ - @modern-js/runtime@1.21.6
12
+ - @modern-js/utils@1.21.6
13
+
14
+ ## 1.21.5
15
+
16
+ ### Patch Changes
17
+
18
+ - 6d8475f: fix: loadApp when dom is mount
19
+ 修复 dom 未渲染时挂载子应用行为
20
+ - Updated dependencies [a150632]
21
+ - Updated dependencies [29576fc]
22
+ - @modern-js/runtime@1.21.5
23
+ - @modern-js/utils@1.21.5
24
+
3
25
  ## 1.21.4
4
26
 
5
27
  ### Patch Changes
@@ -7,7 +7,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
7
7
  import path from 'path';
8
8
  import { createRuntimeExportsUtils, PLUGIN_SCHEMAS } from '@modern-js/utils';
9
9
  import { logger } from "../util";
10
- import { getRuntimeConfig, makeProvider, makeRenderFunction, setRuntimeConfig } from "./utils";
10
+ import { getRuntimeConfig, makeProvider, makeRenderFunction, setRuntimeConfig, generateAsyncEntry } from "./utils";
11
11
  export const externals = {
12
12
  'react-dom': 'react-dom',
13
13
  react: 'react'
@@ -274,16 +274,40 @@ export default (({
274
274
  };
275
275
  },
276
276
 
277
+ modifyAsyncEntry({
278
+ entrypoint,
279
+ code
280
+ }) {
281
+ var _config$deploy2, _config$source;
282
+
283
+ // eslint-disable-next-line react-hooks/rules-of-hooks
284
+ const config = useResolvedConfigContext();
285
+ let finalCode = code;
286
+
287
+ 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) {
288
+ finalCode = generateAsyncEntry(code);
289
+ return {
290
+ entrypoint,
291
+ code: `${finalCode}`
292
+ };
293
+ }
294
+
295
+ return {
296
+ entrypoint,
297
+ code: finalCode
298
+ };
299
+ },
300
+
277
301
  modifyEntryExport({
278
302
  entrypoint,
279
303
  exportStatement
280
304
  }) {
281
- var _config$deploy2;
305
+ var _config$deploy3;
282
306
 
283
307
  // eslint-disable-next-line react-hooks/rules-of-hooks
284
308
  const config = useResolvedConfigContext();
285
309
 
286
- if (config !== null && config !== void 0 && (_config$deploy2 = config.deploy) !== null && _config$deploy2 !== void 0 && _config$deploy2.microFrontend) {
310
+ if (config !== null && config !== void 0 && (_config$deploy3 = config.deploy) !== null && _config$deploy3 !== void 0 && _config$deploy3.microFrontend) {
287
311
  const exportStatementCode = makeProvider();
288
312
  logger('exportStatement', exportStatementCode);
289
313
  return {
@@ -114,4 +114,14 @@ export function setRuntimeConfig(config, key, value) {
114
114
  }
115
115
 
116
116
  return undefined;
117
- }
117
+ }
118
+ export const generateAsyncEntry = code => {
119
+ const transformCode = code.replace(`import('./bootstrap.js');`, `if (!window.__GARFISH__) { import('./bootstrap.js'); }`);
120
+ return `
121
+ export const provider = async (...args) => {
122
+ const exports = await import('./bootstrap');
123
+ return exports.provider.apply(null, args);
124
+ };
125
+ ${transformCode}
126
+ `;
127
+ };
@@ -38,8 +38,7 @@ function getAppInstance(options, appInfo, manifest) {
38
38
  _defineProperty(this, "unregisterHistoryListener", () => {});
39
39
  }
40
40
 
41
- // eslint-disable-next-line @typescript-eslint/naming-convention
42
- async UNSAFE_componentWillMount() {
41
+ async componentDidMount() {
43
42
  const _this$props = this.props,
44
43
  {
45
44
  match,
@@ -105,7 +104,8 @@ function getAppInstance(options, appInfo, manifest) {
105
104
 
106
105
  if (!appInstance) {
107
106
  throw new Error(`MicroApp Garfish.loadApp "${appInfo.name}" result is null`);
108
- }
107
+ } // eslint-disable-next-line react/no-did-mount-set-state
108
+
109
109
 
110
110
  this.setState({
111
111
  appInstance
@@ -291,16 +291,40 @@ var _default = ({
291
291
  };
292
292
  },
293
293
 
294
+ modifyAsyncEntry({
295
+ entrypoint,
296
+ code
297
+ }) {
298
+ var _config$deploy2, _config$source;
299
+
300
+ // eslint-disable-next-line react-hooks/rules-of-hooks
301
+ const config = useResolvedConfigContext();
302
+ let finalCode = code;
303
+
304
+ 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) {
305
+ finalCode = (0, _utils2.generateAsyncEntry)(code);
306
+ return {
307
+ entrypoint,
308
+ code: `${finalCode}`
309
+ };
310
+ }
311
+
312
+ return {
313
+ entrypoint,
314
+ code: finalCode
315
+ };
316
+ },
317
+
294
318
  modifyEntryExport({
295
319
  entrypoint,
296
320
  exportStatement
297
321
  }) {
298
- var _config$deploy2;
322
+ var _config$deploy3;
299
323
 
300
324
  // eslint-disable-next-line react-hooks/rules-of-hooks
301
325
  const config = useResolvedConfigContext();
302
326
 
303
- if (config !== null && config !== void 0 && (_config$deploy2 = config.deploy) !== null && _config$deploy2 !== void 0 && _config$deploy2.microFrontend) {
327
+ if (config !== null && config !== void 0 && (_config$deploy3 = config.deploy) !== null && _config$deploy3 !== void 0 && _config$deploy3.microFrontend) {
304
328
  const exportStatementCode = (0, _utils2.makeProvider)();
305
329
  (0, _util.logger)('exportStatement', exportStatementCode);
306
330
  return {
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.generateAsyncEntry = void 0;
6
7
  exports.getRuntimeConfig = getRuntimeConfig;
7
8
  exports.makeRenderFunction = exports.makeProvider = void 0;
8
9
  exports.setRuntimeConfig = setRuntimeConfig;
@@ -130,4 +131,17 @@ function setRuntimeConfig(config, key, value) {
130
131
  }
131
132
 
132
133
  return undefined;
133
- }
134
+ }
135
+
136
+ const generateAsyncEntry = code => {
137
+ const transformCode = code.replace(`import('./bootstrap.js');`, `if (!window.__GARFISH__) { import('./bootstrap.js'); }`);
138
+ return `
139
+ export const provider = async (...args) => {
140
+ const exports = await import('./bootstrap');
141
+ return exports.provider.apply(null, args);
142
+ };
143
+ ${transformCode}
144
+ `;
145
+ };
146
+
147
+ exports.generateAsyncEntry = generateAsyncEntry;
@@ -49,8 +49,7 @@ function getAppInstance(options, appInfo, manifest) {
49
49
  _defineProperty(this, "unregisterHistoryListener", () => {});
50
50
  }
51
51
 
52
- // eslint-disable-next-line @typescript-eslint/naming-convention
53
- async UNSAFE_componentWillMount() {
52
+ async componentDidMount() {
54
53
  const _this$props = this.props,
55
54
  {
56
55
  match,
@@ -116,7 +115,8 @@ function getAppInstance(options, appInfo, manifest) {
116
115
 
117
116
  if (!appInstance) {
118
117
  throw new Error(`MicroApp Garfish.loadApp "${appInfo.name}" result is null`);
119
- }
118
+ } // eslint-disable-next-line react/no-did-mount-set-state
119
+
120
120
 
121
121
  this.setState({
122
122
  appInstance
@@ -5,7 +5,7 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
5
5
  import path from 'path';
6
6
  import { createRuntimeExportsUtils, PLUGIN_SCHEMAS } from '@modern-js/utils';
7
7
  import { logger } from "../util";
8
- import { getRuntimeConfig, makeProvider, makeRenderFunction, setRuntimeConfig } from "./utils";
8
+ import { getRuntimeConfig, makeProvider, makeRenderFunction, setRuntimeConfig, generateAsyncEntry } from "./utils";
9
9
  export var externals = {
10
10
  'react-dom': 'react-dom',
11
11
  react: 'react'
@@ -279,15 +279,37 @@ export default (function () {
279
279
  code: nCode
280
280
  };
281
281
  },
282
- modifyEntryExport: function modifyEntryExport(_ref7) {
283
- var _config$deploy2;
282
+ modifyAsyncEntry: function modifyAsyncEntry(_ref7) {
283
+ var _config$deploy2, _config$source;
284
284
 
285
285
  var entrypoint = _ref7.entrypoint,
286
- exportStatement = _ref7.exportStatement;
286
+ code = _ref7.code;
287
287
  // eslint-disable-next-line react-hooks/rules-of-hooks
288
288
  var config = useResolvedConfigContext();
289
+ var finalCode = code;
289
290
 
290
- if (config !== null && config !== void 0 && (_config$deploy2 = config.deploy) !== null && _config$deploy2 !== void 0 && _config$deploy2.microFrontend) {
291
+ 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) {
292
+ finalCode = generateAsyncEntry(code);
293
+ return {
294
+ entrypoint: entrypoint,
295
+ code: "".concat(finalCode)
296
+ };
297
+ }
298
+
299
+ return {
300
+ entrypoint: entrypoint,
301
+ code: finalCode
302
+ };
303
+ },
304
+ modifyEntryExport: function modifyEntryExport(_ref8) {
305
+ var _config$deploy3;
306
+
307
+ var entrypoint = _ref8.entrypoint,
308
+ exportStatement = _ref8.exportStatement;
309
+ // eslint-disable-next-line react-hooks/rules-of-hooks
310
+ var config = useResolvedConfigContext();
311
+
312
+ if (config !== null && config !== void 0 && (_config$deploy3 = config.deploy) !== null && _config$deploy3 !== void 0 && _config$deploy3.microFrontend) {
291
313
  var exportStatementCode = makeProvider();
292
314
  logger('exportStatement', exportStatementCode);
293
315
  return {
@@ -32,4 +32,8 @@ export function setRuntimeConfig(config, key, value) {
32
32
  }
33
33
 
34
34
  return undefined;
35
- }
35
+ }
36
+ export var generateAsyncEntry = function generateAsyncEntry(code) {
37
+ var transformCode = code.replace("import('./bootstrap.js');", "if (!window.__GARFISH__) { import('./bootstrap.js'); }");
38
+ return "\n export const provider = async (...args) => {\n const exports = await import('./bootstrap');\n return exports.provider.apply(null, args);\n };\n ".concat(transformCode, "\n ");
39
+ };
@@ -53,10 +53,9 @@ function getAppInstance(options, appInfo, manifest) {
53
53
  }
54
54
 
55
55
  _createClass(MicroApp, [{
56
- key: "UNSAFE_componentWillMount",
57
- value: // eslint-disable-next-line @typescript-eslint/naming-convention
58
- function () {
59
- var _UNSAFE_componentWillMount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
56
+ key: "componentDidMount",
57
+ value: function () {
58
+ var _componentDidMount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
60
59
  var _this2 = this;
61
60
 
62
61
  var _this$props, match, history, setLoadingState, userProps, domId, loadAppOptions, appInstance;
@@ -133,6 +132,7 @@ function getAppInstance(options, appInfo, manifest) {
133
132
  throw new Error("MicroApp Garfish.loadApp \"".concat(appInfo.name, "\" result is null"));
134
133
 
135
134
  case 11:
135
+ // eslint-disable-next-line react/no-did-mount-set-state
136
136
  this.setState({
137
137
  appInstance: appInstance
138
138
  });
@@ -192,11 +192,11 @@ function getAppInstance(options, appInfo, manifest) {
192
192
  }, _callee, this, [[5, 25]]);
193
193
  }));
194
194
 
195
- function UNSAFE_componentWillMount() {
196
- return _UNSAFE_componentWillMount.apply(this, arguments);
195
+ function componentDidMount() {
196
+ return _componentDidMount.apply(this, arguments);
197
197
  }
198
198
 
199
- return UNSAFE_componentWillMount;
199
+ return componentDidMount;
200
200
  }()
201
201
  }, {
202
202
  key: "componentWillUnmount",
@@ -2,4 +2,5 @@ import type { NormalizedConfig } from '@modern-js/core';
2
2
  export declare const makeProvider: () => string;
3
3
  export declare const makeRenderFunction: (code: string) => string;
4
4
  export declare function getRuntimeConfig(config: Partial<NormalizedConfig>): any;
5
- export declare function setRuntimeConfig(config: Partial<NormalizedConfig>, key: string, value: any): undefined;
5
+ export declare function setRuntimeConfig(config: Partial<NormalizedConfig>, key: string, value: any): undefined;
6
+ export declare const generateAsyncEntry: (code: string) => string;
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.21.4",
14
+ "version": "1.21.6",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/runtime/index.d.ts",
17
17
  "typesVersions": {
@@ -50,16 +50,16 @@
50
50
  },
51
51
  "dependencies": {
52
52
  "@babel/runtime": "^7.18.0",
53
- "@modern-js/utils": "1.21.4",
54
53
  "@types/debug": "^4.1.7",
55
54
  "@types/react-loadable": "^5.5.6",
56
55
  "debug": "^4.3.2",
57
56
  "garfish": "^1.8.1",
58
57
  "hoist-non-react-statics": "^3.3.2",
59
- "react-loadable": "^5.5.0"
58
+ "react-loadable": "^5.5.0",
59
+ "@modern-js/utils": "1.21.6"
60
60
  },
61
61
  "peerDependencies": {
62
- "@modern-js/runtime": "^1.21.4"
62
+ "@modern-js/runtime": "^1.21.6"
63
63
  },
64
64
  "peerDependenciesMeta": {
65
65
  "@modern-js/runtime": {
@@ -67,11 +67,6 @@
67
67
  }
68
68
  },
69
69
  "devDependencies": {
70
- "@modern-js/core": "1.21.4",
71
- "@modern-js/runtime": "1.21.4",
72
- "@modern-js/types": "1.21.4",
73
- "@scripts/build": "1.21.4",
74
- "@scripts/jest-config": "1.21.4",
75
70
  "@testing-library/jest-dom": "^5.16.1",
76
71
  "@testing-library/react": "^12.0.0",
77
72
  "@testing-library/react-hooks": "^7.0.1",
@@ -86,7 +81,12 @@
86
81
  "react-dom": "^17.0.2",
87
82
  "react-router-dom": "^6.2.1",
88
83
  "typescript": "^4",
89
- "webpack-chain": "^6.5.1"
84
+ "webpack-chain": "^6.5.1",
85
+ "@modern-js/core": "1.21.6",
86
+ "@modern-js/runtime": "1.21.6",
87
+ "@modern-js/types": "1.21.6",
88
+ "@scripts/build": "1.21.6",
89
+ "@scripts/jest-config": "1.21.6"
90
90
  },
91
91
  "sideEffects": false,
92
92
  "modernConfig": {},