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

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,48 @@
1
1
  # @modern-js/plugin-garfish
2
2
 
3
+ ## 2.0.0-beta.2
4
+
5
+ ### Major Changes
6
+
7
+ - dda38c9c3e: chore: v2
8
+
9
+ ### Patch Changes
10
+
11
+ - 21d2ddb: feat: support async export provider for module federation
12
+ 支持模块联邦场景异步导出 provider
13
+ - 2344eb2: fix: loadApp when dom is mount
14
+ 修复 dom 未渲染时挂载子应用行为
15
+ - Updated dependencies [2344eb2]
16
+ - Updated dependencies [a11fcf8]
17
+ - Updated dependencies [b18fa8f3ed]
18
+ - Updated dependencies [c9e800d39a]
19
+ - Updated dependencies [3e57f2b]
20
+ - Updated dependencies [fbf5eed]
21
+ - Updated dependencies [a2509bfbdb]
22
+ - Updated dependencies [e4357f1]
23
+ - Updated dependencies [4369648ae2]
24
+ - Updated dependencies [92f0ead]
25
+ - Updated dependencies [92c0994]
26
+ - Updated dependencies [edd1cfb1af]
27
+ - Updated dependencies [cc971eabfc]
28
+ - Updated dependencies [5b9049f2e9]
29
+ - Updated dependencies [6bda14ed71]
30
+ - Updated dependencies [92004d1]
31
+ - Updated dependencies [b8bbe036c7]
32
+ - Updated dependencies [40ed587]
33
+ - Updated dependencies [60d5378632]
34
+ - Updated dependencies [d5a31df781]
35
+ - Updated dependencies [dda38c9c3e]
36
+ - Updated dependencies [8b8e1bb571]
37
+ - Updated dependencies [3bbea92b2a]
38
+ - Updated dependencies [18aaf42]
39
+ - Updated dependencies [fcace5b5b9]
40
+ - Updated dependencies [abf3421a75]
41
+ - Updated dependencies [543be9558e]
42
+ - Updated dependencies [14b712da84]
43
+ - @modern-js/runtime@2.0.0-beta.2
44
+ - @modern-js/utils@2.0.0-beta.2
45
+
3
46
  ## 2.0.0-beta.1
4
47
 
5
48
  ### 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) {
@@ -84,6 +84,7 @@ export default (({
84
84
  enableHtmlEntry
85
85
  } = getDefaultMicroFrontedConfig((_useConfig$deploy2 = useConfig.deploy) === null || _useConfig$deploy2 === void 0 ? void 0 : _useConfig$deploy2.microFrontend);
86
86
  if (!enableHtmlEntry) {
87
+ // FIXME: the handle the `disableCssExtract` config
87
88
  disableCssExtract = true;
88
89
  }
89
90
  }
@@ -244,14 +245,34 @@ export default (({
244
245
  code: nCode
245
246
  };
246
247
  },
248
+ modifyAsyncEntry({
249
+ entrypoint,
250
+ code
251
+ }) {
252
+ var _config$deploy2, _config$source;
253
+ // eslint-disable-next-line react-hooks/rules-of-hooks
254
+ const config = useResolvedConfigContext();
255
+ let finalCode = code;
256
+ if (config !== null && config !== void 0 && (_config$deploy2 = config.deploy) !== null && _config$deploy2 !== void 0 && _config$deploy2.microFrontend && config !== null && config !== void 0 && (_config$source = config.source) !== null && _config$source !== void 0 && _config$source.enableAsyncEntry) {
257
+ finalCode = generateAsyncEntry(code);
258
+ return {
259
+ entrypoint,
260
+ code: `${finalCode}`
261
+ };
262
+ }
263
+ return {
264
+ entrypoint,
265
+ code: finalCode
266
+ };
267
+ },
247
268
  modifyEntryExport({
248
269
  entrypoint,
249
270
  exportStatement
250
271
  }) {
251
- var _config$deploy2;
272
+ var _config$deploy3;
252
273
  // eslint-disable-next-line react-hooks/rules-of-hooks
253
274
  const config = useResolvedConfigContext();
254
- if (config !== null && config !== void 0 && (_config$deploy2 = config.deploy) !== null && _config$deploy2 !== void 0 && _config$deploy2.microFrontend) {
275
+ if (config !== null && config !== void 0 && (_config$deploy3 = config.deploy) !== null && _config$deploy3 !== void 0 && _config$deploy3.microFrontend) {
255
276
  const exportStatementCode = makeProvider();
256
277
  logger('exportStatement', exportStatementCode);
257
278
  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) {
@@ -93,6 +93,7 @@ var _default = ({
93
93
  enableHtmlEntry
94
94
  } = getDefaultMicroFrontedConfig((_useConfig$deploy2 = useConfig.deploy) === null || _useConfig$deploy2 === void 0 ? void 0 : _useConfig$deploy2.microFrontend);
95
95
  if (!enableHtmlEntry) {
96
+ // FIXME: the handle the `disableCssExtract` config
96
97
  disableCssExtract = true;
97
98
  }
98
99
  }
@@ -253,14 +254,34 @@ var _default = ({
253
254
  code: nCode
254
255
  };
255
256
  },
257
+ modifyAsyncEntry({
258
+ entrypoint,
259
+ code
260
+ }) {
261
+ var _config$deploy2, _config$source;
262
+ // eslint-disable-next-line react-hooks/rules-of-hooks
263
+ const config = useResolvedConfigContext();
264
+ 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);
267
+ return {
268
+ entrypoint,
269
+ code: `${finalCode}`
270
+ };
271
+ }
272
+ return {
273
+ entrypoint,
274
+ code: finalCode
275
+ };
276
+ },
256
277
  modifyEntryExport({
257
278
  entrypoint,
258
279
  exportStatement
259
280
  }) {
260
- var _config$deploy2;
281
+ var _config$deploy3;
261
282
  // eslint-disable-next-line react-hooks/rules-of-hooks
262
283
  const config = useResolvedConfigContext();
263
- if (config !== null && config !== void 0 && (_config$deploy2 = config.deploy) !== null && _config$deploy2 !== void 0 && _config$deploy2.microFrontend) {
284
+ if (config !== null && config !== void 0 && (_config$deploy3 = config.deploy) !== null && _config$deploy3 !== void 0 && _config$deploy3.microFrontend) {
264
285
  const exportStatementCode = (0, _utils2.makeProvider)();
265
286
  (0, _util.logger)('exportStatement', exportStatementCode);
266
287
  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) {
@@ -98,6 +98,7 @@ export default (function () {
98
98
  var _getDefaultMicroFront = getDefaultMicroFrontedConfig((_useConfig$deploy2 = useConfig.deploy) === null || _useConfig$deploy2 === void 0 ? void 0 : _useConfig$deploy2.microFrontend),
99
99
  enableHtmlEntry = _getDefaultMicroFront.enableHtmlEntry;
100
100
  if (!enableHtmlEntry) {
101
+ // FIXME: the handle the `disableCssExtract` config
101
102
  disableCssExtract = true;
102
103
  }
103
104
  }
@@ -252,13 +253,32 @@ export default (function () {
252
253
  code: nCode
253
254
  };
254
255
  },
255
- modifyEntryExport: function modifyEntryExport(_ref7) {
256
- var _config$deploy2;
256
+ modifyAsyncEntry: function modifyAsyncEntry(_ref7) {
257
+ var _config$deploy2, _config$source;
257
258
  var entrypoint = _ref7.entrypoint,
258
- exportStatement = _ref7.exportStatement;
259
+ code = _ref7.code;
259
260
  // eslint-disable-next-line react-hooks/rules-of-hooks
260
261
  var config = useResolvedConfigContext();
261
- if (config !== null && config !== void 0 && (_config$deploy2 = config.deploy) !== null && _config$deploy2 !== void 0 && _config$deploy2.microFrontend) {
262
+ var finalCode = code;
263
+ 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) {
264
+ finalCode = generateAsyncEntry(code);
265
+ return {
266
+ entrypoint: entrypoint,
267
+ code: "".concat(finalCode)
268
+ };
269
+ }
270
+ return {
271
+ entrypoint: entrypoint,
272
+ code: finalCode
273
+ };
274
+ },
275
+ modifyEntryExport: function modifyEntryExport(_ref8) {
276
+ var _config$deploy3;
277
+ var entrypoint = _ref8.entrypoint,
278
+ exportStatement = _ref8.exportStatement;
279
+ // eslint-disable-next-line react-hooks/rules-of-hooks
280
+ var config = useResolvedConfigContext();
281
+ if (config !== null && config !== void 0 && (_config$deploy3 = config.deploy) !== null && _config$deploy3 !== void 0 && _config$deploy3.microFrontend) {
262
282
  var exportStatementCode = makeProvider();
263
283
  logger('exportStatement', exportStatementCode);
264
284
  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.2",
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.2"
60
60
  },
61
61
  "peerDependencies": {
62
- "@modern-js/runtime": "^2.0.0-beta.1"
62
+ "@modern-js/runtime": "^2.0.0-beta.2"
63
63
  },
64
64
  "peerDependenciesMeta": {
65
65
  "@modern-js/runtime": {
@@ -71,9 +71,9 @@
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",
@@ -81,12 +81,13 @@
81
81
  "react-router-dom": "^6.2.1",
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.2",
85
+ "@modern-js/plugin-router-legacy": "2.0.0-beta.2",
86
+ "@modern-js/runtime": "2.0.0-beta.2",
87
+ "@modern-js/types": "2.0.0-beta.2",
88
+ "@scripts/build": "2.0.0-beta.2",
89
+ "@modern-js/app-tools": "2.0.0-beta.2",
90
+ "@scripts/jest-config": "2.0.0-beta.2"
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
  }