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

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,106 @@
1
1
  # @modern-js/plugin-garfish
2
2
 
3
+ ## 2.0.0-beta.3
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
+ - 21d2ddb: feat: support async export provider for module federation
14
+ 支持模块联邦场景异步导出 provider
15
+ - cce8ece: 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 [e7ce063]
22
+ - Updated dependencies [b18fa8f3ed]
23
+ - Updated dependencies [c9e800d39a]
24
+ - Updated dependencies [6604f1b]
25
+ - Updated dependencies [6aca875]
26
+ - Updated dependencies [fda836f]
27
+ - Updated dependencies [3e57f2bd58]
28
+ - Updated dependencies [2e60319]
29
+ - Updated dependencies [fbf5eed5aa]
30
+ - Updated dependencies [a2509bfbdb]
31
+ - Updated dependencies [425e570]
32
+ - Updated dependencies [e4357f1]
33
+ - Updated dependencies [4369648ae2]
34
+ - Updated dependencies [92f0eade39]
35
+ - Updated dependencies [92c0994468]
36
+ - Updated dependencies [edd1cfb1af]
37
+ - Updated dependencies [cc971eabfc]
38
+ - Updated dependencies [5b9049f2e9]
39
+ - Updated dependencies [6bda14ed71]
40
+ - Updated dependencies [92004d1906]
41
+ - Updated dependencies [b8bbe036c7]
42
+ - Updated dependencies [40ed5874c6]
43
+ - Updated dependencies [60d5378632]
44
+ - Updated dependencies [d5a31df781]
45
+ - Updated dependencies [dda38c9c3e]
46
+ - Updated dependencies [8b8e1bb571]
47
+ - Updated dependencies [3bbea92b2a]
48
+ - Updated dependencies [b710adb]
49
+ - Updated dependencies [18aaf42249]
50
+ - Updated dependencies [34702d5]
51
+ - Updated dependencies [fcace5b5b9]
52
+ - Updated dependencies [ea7cf06]
53
+ - Updated dependencies [bbe4c4a]
54
+ - Updated dependencies [e4558a0]
55
+ - Updated dependencies [abf3421a75]
56
+ - Updated dependencies [543be9558e]
57
+ - Updated dependencies [14b712da84]
58
+ - @modern-js/runtime@2.0.0-beta.3
59
+ - @modern-js/utils@2.0.0-beta.3
60
+
61
+ ## 2.0.0-beta.2
62
+
63
+ ### Major Changes
64
+
65
+ - dda38c9c3e: chore: v2
66
+
67
+ ### Patch Changes
68
+
69
+ - 21d2ddb: feat: support async export provider for module federation
70
+ 支持模块联邦场景异步导出 provider
71
+ - 2344eb2: fix: loadApp when dom is mount
72
+ 修复 dom 未渲染时挂载子应用行为
73
+ - Updated dependencies [2344eb2]
74
+ - Updated dependencies [a11fcf8]
75
+ - Updated dependencies [b18fa8f3ed]
76
+ - Updated dependencies [c9e800d39a]
77
+ - Updated dependencies [3e57f2b]
78
+ - Updated dependencies [fbf5eed]
79
+ - Updated dependencies [a2509bfbdb]
80
+ - Updated dependencies [e4357f1]
81
+ - Updated dependencies [4369648ae2]
82
+ - Updated dependencies [92f0ead]
83
+ - Updated dependencies [92c0994]
84
+ - Updated dependencies [edd1cfb1af]
85
+ - Updated dependencies [cc971eabfc]
86
+ - Updated dependencies [5b9049f2e9]
87
+ - Updated dependencies [6bda14ed71]
88
+ - Updated dependencies [92004d1]
89
+ - Updated dependencies [b8bbe036c7]
90
+ - Updated dependencies [40ed587]
91
+ - Updated dependencies [60d5378632]
92
+ - Updated dependencies [d5a31df781]
93
+ - Updated dependencies [dda38c9c3e]
94
+ - Updated dependencies [8b8e1bb571]
95
+ - Updated dependencies [3bbea92b2a]
96
+ - Updated dependencies [18aaf42]
97
+ - Updated dependencies [fcace5b5b9]
98
+ - Updated dependencies [abf3421a75]
99
+ - Updated dependencies [543be9558e]
100
+ - Updated dependencies [14b712da84]
101
+ - @modern-js/runtime@2.0.0-beta.2
102
+ - @modern-js/utils@2.0.0-beta.2
103
+
3
104
  ## 2.0.0-beta.1
4
105
 
5
106
  ### Major Changes
@@ -4,7 +4,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
4
4
  import path from 'path';
5
5
  import { createRuntimeExportsUtils, PLUGIN_SCHEMAS } from '@modern-js/utils';
6
6
  import { logger } from "../util";
7
- import { getRuntimeConfig, makeProvider, makeRenderFunction, setRuntimeConfig } from "./utils";
7
+ import { getRuntimeConfig, makeProvider, makeRenderFunction, setRuntimeConfig, generateAsyncEntry } from "./utils";
8
8
  export const externals = {
9
9
  'react-dom': 'react-dom',
10
10
  react: 'react'
@@ -66,7 +66,7 @@ export default (({
66
66
  return nConfig;
67
67
  },
68
68
  config() {
69
- var _useConfig$output$dis, _useConfig$output, _useConfig$deploy;
69
+ var _useConfig$output, _useConfig$deploy;
70
70
  // eslint-disable-next-line react-hooks/rules-of-hooks
71
71
  const useConfig = useConfigContext();
72
72
  logger('useConfig', useConfig);
@@ -75,7 +75,7 @@ export default (({
75
75
  const config = useAppContext();
76
76
  pluginsExportsUtils = createRuntimeExportsUtils(config.internalDirectory, 'plugins');
77
77
  runtimeExportsUtils = createRuntimeExportsUtils(config.internalDirectory, 'index');
78
- let disableCssExtract = (_useConfig$output$dis = (_useConfig$output = useConfig.output) === null || _useConfig$output === void 0 ? void 0 : _useConfig$output.disableCssExtract) !== null && _useConfig$output$dis !== void 0 ? _useConfig$output$dis : false;
78
+ let disableCssExtract = ((_useConfig$output = useConfig.output) === null || _useConfig$output === void 0 ? void 0 : _useConfig$output.disableCssExtract) || false;
79
79
 
80
80
  // When the micro-frontend application js entry, there is no need to extract css, close cssExtract
81
81
  if ((_useConfig$deploy = useConfig.deploy) !== null && _useConfig$deploy !== void 0 && _useConfig$deploy.microFrontend) {
@@ -244,14 +244,34 @@ export default (({
244
244
  code: nCode
245
245
  };
246
246
  },
247
+ modifyAsyncEntry({
248
+ entrypoint,
249
+ code
250
+ }) {
251
+ var _config$deploy2, _config$source;
252
+ // eslint-disable-next-line react-hooks/rules-of-hooks
253
+ const config = useResolvedConfigContext();
254
+ let finalCode = code;
255
+ 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) {
256
+ finalCode = generateAsyncEntry(code);
257
+ return {
258
+ entrypoint,
259
+ code: `${finalCode}`
260
+ };
261
+ }
262
+ return {
263
+ entrypoint,
264
+ code: finalCode
265
+ };
266
+ },
247
267
  modifyEntryExport({
248
268
  entrypoint,
249
269
  exportStatement
250
270
  }) {
251
- var _config$deploy2;
271
+ var _config$deploy3;
252
272
  // eslint-disable-next-line react-hooks/rules-of-hooks
253
273
  const config = useResolvedConfigContext();
254
- if (config !== null && config !== void 0 && (_config$deploy2 = config.deploy) !== null && _config$deploy2 !== void 0 && _config$deploy2.microFrontend) {
274
+ if (config !== null && config !== void 0 && (_config$deploy3 = config.deploy) !== null && _config$deploy3 !== void 0 && _config$deploy3.microFrontend) {
255
275
  const exportStatementCode = makeProvider();
256
276
  logger('exportStatement', exportStatementCode);
257
277
  return {
@@ -110,4 +110,14 @@ export function setRuntimeConfig(config, key, value) {
110
110
  return undefined;
111
111
  }
112
112
  return undefined;
113
- }
113
+ }
114
+ export const generateAsyncEntry = code => {
115
+ const transformCode = code.replace(`import('./bootstrap.js');`, `if (!window.__GARFISH__) { import('./bootstrap.js'); }`);
116
+ return `
117
+ export const provider = async (...args) => {
118
+ const exports = await import('./bootstrap');
119
+ return exports.provider.apply(null, args);
120
+ };
121
+ ${transformCode}
122
+ `;
123
+ };
@@ -75,7 +75,7 @@ var _default = ({
75
75
  return nConfig;
76
76
  },
77
77
  config() {
78
- var _useConfig$output$dis, _useConfig$output, _useConfig$deploy;
78
+ var _useConfig$output, _useConfig$deploy;
79
79
  // eslint-disable-next-line react-hooks/rules-of-hooks
80
80
  const useConfig = useConfigContext();
81
81
  (0, _util.logger)('useConfig', useConfig);
@@ -84,7 +84,7 @@ var _default = ({
84
84
  const config = useAppContext();
85
85
  pluginsExportsUtils = (0, _utils.createRuntimeExportsUtils)(config.internalDirectory, 'plugins');
86
86
  runtimeExportsUtils = (0, _utils.createRuntimeExportsUtils)(config.internalDirectory, 'index');
87
- let disableCssExtract = (_useConfig$output$dis = (_useConfig$output = useConfig.output) === null || _useConfig$output === void 0 ? void 0 : _useConfig$output.disableCssExtract) !== null && _useConfig$output$dis !== void 0 ? _useConfig$output$dis : false;
87
+ let disableCssExtract = ((_useConfig$output = useConfig.output) === null || _useConfig$output === void 0 ? void 0 : _useConfig$output.disableCssExtract) || false;
88
88
 
89
89
  // When the micro-frontend application js entry, there is no need to extract css, close cssExtract
90
90
  if ((_useConfig$deploy = useConfig.deploy) !== null && _useConfig$deploy !== void 0 && _useConfig$deploy.microFrontend) {
@@ -253,14 +253,34 @@ var _default = ({
253
253
  code: nCode
254
254
  };
255
255
  },
256
+ modifyAsyncEntry({
257
+ entrypoint,
258
+ code
259
+ }) {
260
+ var _config$deploy2, _config$source;
261
+ // eslint-disable-next-line react-hooks/rules-of-hooks
262
+ const config = useResolvedConfigContext();
263
+ 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);
266
+ return {
267
+ entrypoint,
268
+ code: `${finalCode}`
269
+ };
270
+ }
271
+ return {
272
+ entrypoint,
273
+ code: finalCode
274
+ };
275
+ },
256
276
  modifyEntryExport({
257
277
  entrypoint,
258
278
  exportStatement
259
279
  }) {
260
- var _config$deploy2;
280
+ var _config$deploy3;
261
281
  // eslint-disable-next-line react-hooks/rules-of-hooks
262
282
  const config = useResolvedConfigContext();
263
- if (config !== null && config !== void 0 && (_config$deploy2 = config.deploy) !== null && _config$deploy2 !== void 0 && _config$deploy2.microFrontend) {
283
+ if (config !== null && config !== void 0 && (_config$deploy3 = config.deploy) !== null && _config$deploy3 !== void 0 && _config$deploy3.microFrontend) {
264
284
  const exportStatementCode = (0, _utils2.makeProvider)();
265
285
  (0, _util.logger)('exportStatement', exportStatementCode);
266
286
  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;
@@ -120,4 +121,15 @@ function setRuntimeConfig(config, key, value) {
120
121
  return undefined;
121
122
  }
122
123
  return undefined;
123
- }
124
+ }
125
+ const generateAsyncEntry = code => {
126
+ const transformCode = code.replace(`import('./bootstrap.js');`, `if (!window.__GARFISH__) { import('./bootstrap.js'); }`);
127
+ return `
128
+ export const provider = async (...args) => {
129
+ const exports = await import('./bootstrap');
130
+ return exports.provider.apply(null, args);
131
+ };
132
+ ${transformCode}
133
+ `;
134
+ };
135
+ exports.generateAsyncEntry = generateAsyncEntry;
@@ -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'
@@ -81,7 +81,7 @@ export default (function () {
81
81
  return resolvedConfig;
82
82
  }(),
83
83
  config: function config() {
84
- var _useConfig$output$dis, _useConfig$output, _useConfig$deploy;
84
+ var _useConfig$output, _useConfig$deploy;
85
85
  // eslint-disable-next-line react-hooks/rules-of-hooks
86
86
  var useConfig = useConfigContext();
87
87
  logger('useConfig', useConfig);
@@ -90,7 +90,7 @@ export default (function () {
90
90
  var config = useAppContext();
91
91
  pluginsExportsUtils = createRuntimeExportsUtils(config.internalDirectory, 'plugins');
92
92
  runtimeExportsUtils = createRuntimeExportsUtils(config.internalDirectory, 'index');
93
- var disableCssExtract = (_useConfig$output$dis = (_useConfig$output = useConfig.output) === null || _useConfig$output === void 0 ? void 0 : _useConfig$output.disableCssExtract) !== null && _useConfig$output$dis !== void 0 ? _useConfig$output$dis : false;
93
+ var disableCssExtract = ((_useConfig$output = useConfig.output) === null || _useConfig$output === void 0 ? void 0 : _useConfig$output.disableCssExtract) || false;
94
94
 
95
95
  // When the micro-frontend application js entry, there is no need to extract css, close cssExtract
96
96
  if ((_useConfig$deploy = useConfig.deploy) !== null && _useConfig$deploy !== void 0 && _useConfig$deploy.microFrontend) {
@@ -252,13 +252,32 @@ export default (function () {
252
252
  code: nCode
253
253
  };
254
254
  },
255
- modifyEntryExport: function modifyEntryExport(_ref7) {
256
- var _config$deploy2;
255
+ modifyAsyncEntry: function modifyAsyncEntry(_ref7) {
256
+ var _config$deploy2, _config$source;
257
257
  var entrypoint = _ref7.entrypoint,
258
- exportStatement = _ref7.exportStatement;
258
+ code = _ref7.code;
259
259
  // eslint-disable-next-line react-hooks/rules-of-hooks
260
260
  var config = useResolvedConfigContext();
261
- if (config !== null && config !== void 0 && (_config$deploy2 = config.deploy) !== null && _config$deploy2 !== void 0 && _config$deploy2.microFrontend) {
261
+ var finalCode = code;
262
+ 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) {
263
+ finalCode = generateAsyncEntry(code);
264
+ return {
265
+ entrypoint: entrypoint,
266
+ code: "".concat(finalCode)
267
+ };
268
+ }
269
+ return {
270
+ entrypoint: entrypoint,
271
+ code: finalCode
272
+ };
273
+ },
274
+ modifyEntryExport: function modifyEntryExport(_ref8) {
275
+ var _config$deploy3;
276
+ var entrypoint = _ref8.entrypoint,
277
+ exportStatement = _ref8.exportStatement;
278
+ // eslint-disable-next-line react-hooks/rules-of-hooks
279
+ var config = useResolvedConfigContext();
280
+ if (config !== null && config !== void 0 && (_config$deploy3 = config.deploy) !== null && _config$deploy3 !== void 0 && _config$deploy3.microFrontend) {
262
281
  var exportStatementCode = makeProvider();
263
282
  logger('exportStatement', exportStatementCode);
264
283
  return {
@@ -28,4 +28,8 @@ export function setRuntimeConfig(config, key, value) {
28
28
  return undefined;
29
29
  }
30
30
  return undefined;
31
- }
31
+ }
32
+ export var generateAsyncEntry = function generateAsyncEntry(code) {
33
+ var transformCode = code.replace("import('./bootstrap.js');", "if (!window.__GARFISH__) { import('./bootstrap.js'); }");
34
+ 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 ");
35
+ };
@@ -1,4 +1,5 @@
1
- import type { CliHookCallbacks, CliPlugin, useConfigContext } from '@modern-js/core';
1
+ import type { CliHookCallbacks, useConfigContext } from '@modern-js/core';
2
+ import type { CliPlugin, AppTools } from '@modern-js/app-tools';
2
3
  export declare type UseConfig = ReturnType<typeof useConfigContext>;
3
4
  export declare const externals: {
4
5
  'react-dom': string;
@@ -6,11 +7,7 @@ export declare const externals: {
6
7
  };
7
8
  export declare type LifeCycle = CliHookCallbacks;
8
9
  declare type NonInValidAble<T> = T extends null | undefined | false ? never : T;
9
- export declare function getDefaultMicroFrontedConfig(microFrontend: NonInValidAble<NonNullable<UseConfig['deploy']>['microFrontend']>): {
10
- enableHtmlEntry: boolean;
11
- externalBasicLibrary: boolean;
12
- moduleApp?: string | undefined;
13
- };
10
+ export declare function getDefaultMicroFrontedConfig(microFrontend: NonInValidAble<NonNullable<UseConfig['deploy']>['microFrontend']>): any;
14
11
  declare const _default: ({
15
12
  pluginName,
16
13
  runtimePluginName,
@@ -19,5 +16,5 @@ declare const _default: ({
19
16
  pluginName?: string | undefined;
20
17
  runtimePluginName?: string | undefined;
21
18
  mfPackagePath?: string | undefined;
22
- }) => CliPlugin;
19
+ }) => CliPlugin<AppTools>;
23
20
  export default _default;
@@ -1,5 +1,6 @@
1
- import type { NormalizedConfig } from '@modern-js/core';
1
+ import type { AppNormalizedConfig } from '@modern-js/app-tools';
2
2
  export declare const makeProvider: () => string;
3
3
  export declare const makeRenderFunction: (code: string) => string;
4
- export declare function getRuntimeConfig(config: Partial<NormalizedConfig>): any;
5
- export declare function setRuntimeConfig(config: Partial<NormalizedConfig>, key: string, value: any): undefined;
4
+ export declare function getRuntimeConfig(config: Partial<AppNormalizedConfig>): any;
5
+ export declare function setRuntimeConfig(config: Partial<AppNormalizedConfig>, 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": "2.0.0-beta.1",
14
+ "version": "2.0.0-beta.3",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/runtime/index.d.ts",
17
17
  "typesVersions": {
@@ -56,10 +56,10 @@
56
56
  "garfish": "^1.8.1",
57
57
  "hoist-non-react-statics": "^3.3.2",
58
58
  "react-loadable": "^5.5.0",
59
- "@modern-js/utils": "2.0.0-beta.1"
59
+ "@modern-js/utils": "2.0.0-beta.3"
60
60
  },
61
61
  "peerDependencies": {
62
- "@modern-js/runtime": "^2.0.0-beta.1"
62
+ "@modern-js/runtime": "^2.0.0-beta.3"
63
63
  },
64
64
  "peerDependenciesMeta": {
65
65
  "@modern-js/runtime": {
@@ -71,22 +71,23 @@
71
71
  "@testing-library/react": "^13.4.0",
72
72
  "@testing-library/react-hooks": "^8.0.1",
73
73
  "@testing-library/user-event": "^14.4.3",
74
- "@types/testing-library__jest-dom": "^5.14.3",
75
74
  "@types/jest": "^27",
76
75
  "@types/node": "^14",
76
+ "@types/testing-library__jest-dom": "^5.14.3",
77
77
  "jest": "^27",
78
78
  "jest-fetch-mock": "^3.0.3",
79
79
  "react": "^18",
80
80
  "react-dom": "^18",
81
- "react-router-dom": "^6.2.1",
81
+ "react-router-dom": "^6.4.4",
82
82
  "typescript": "^4",
83
83
  "webpack-chain": "^6.5.1",
84
- "@modern-js/core": "2.0.0-beta.1",
85
- "@modern-js/runtime": "2.0.0-beta.1",
86
- "@modern-js/plugin-router-legacy": "2.0.0-beta.1",
87
- "@modern-js/types": "2.0.0-beta.1",
88
- "@scripts/build": "2.0.0-beta.1",
89
- "@scripts/jest-config": "2.0.0-beta.1"
84
+ "@modern-js/core": "2.0.0-beta.3",
85
+ "@modern-js/plugin-router-legacy": "2.0.0-beta.3",
86
+ "@modern-js/runtime": "2.0.0-beta.3",
87
+ "@modern-js/types": "2.0.0-beta.3",
88
+ "@scripts/build": "2.0.0-beta.3",
89
+ "@modern-js/app-tools": "2.0.0-beta.3",
90
+ "@scripts/jest-config": "2.0.0-beta.3"
90
91
  },
91
92
  "sideEffects": false,
92
93
  "modernConfig": {},
@@ -95,8 +96,8 @@
95
96
  "access": "public"
96
97
  },
97
98
  "scripts": {
98
- "new": "modern new",
99
- "build": "modern build",
99
+ "new": "modern-lib new",
100
+ "build": "modern-lib build",
100
101
  "build:watch": "rm -rf ./dist && modern build --watch",
101
102
  "test": "jest --passWithNoTests"
102
103
  }