@modern-js/plugin-garfish 2.4.1-beta.0 → 2.5.0

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 (43) hide show
  1. package/CHANGELOG.md +19 -3
  2. package/dist/{js/node → cjs}/cli/index.js +10 -41
  3. package/dist/{js/node → cjs}/cli/utils.js +5 -2
  4. package/dist/{js/node → cjs}/deps/index.js +0 -0
  5. package/dist/{js/node → cjs}/index.js +0 -0
  6. package/dist/{js/node → cjs}/runtime/index.js +0 -0
  7. package/dist/{js/node → cjs}/runtime/loadable.js +11 -38
  8. package/dist/{js/node → cjs}/runtime/plugin.js +32 -79
  9. package/dist/{js/node → cjs}/runtime/useModuleApps.js +8 -20
  10. package/dist/{js/node → cjs}/runtime/utils/Context.js +0 -0
  11. package/dist/{js/node → cjs}/runtime/utils/MApp.js +4 -30
  12. package/dist/{js/node → cjs}/runtime/utils/apps.js +43 -88
  13. package/dist/{js/node → cjs}/runtime/utils/setExternal.js +0 -0
  14. package/dist/{js/node → cjs}/util.js +0 -0
  15. package/dist/{js/treeshaking → esm}/cli/index.js +0 -0
  16. package/dist/{js/treeshaking → esm}/cli/utils.js +2 -2
  17. package/dist/{js/treeshaking → esm}/deps/index.js +0 -0
  18. package/dist/{js/treeshaking → esm}/index.js +0 -0
  19. package/dist/{js/treeshaking → esm}/runtime/index.js +0 -0
  20. package/dist/{js/treeshaking → esm}/runtime/loadable.js +0 -0
  21. package/dist/{js/treeshaking → esm}/runtime/plugin.js +0 -0
  22. package/dist/{js/treeshaking → esm}/runtime/useModuleApps.js +0 -0
  23. package/dist/{js/treeshaking → esm}/runtime/utils/Context.js +0 -0
  24. package/dist/{js/treeshaking → esm}/runtime/utils/MApp.js +0 -0
  25. package/dist/{js/treeshaking → esm}/runtime/utils/apps.js +0 -0
  26. package/dist/{js/treeshaking → esm}/runtime/utils/setExternal.js +0 -0
  27. package/dist/{js/treeshaking → esm}/util.js +0 -0
  28. package/dist/{js/modern → esm-node}/cli/index.js +10 -43
  29. package/dist/{js/modern → esm-node}/cli/utils.js +5 -2
  30. package/dist/{js/modern → esm-node}/deps/index.js +0 -0
  31. package/dist/{js/modern → esm-node}/index.js +0 -0
  32. package/dist/{js/modern → esm-node}/runtime/index.js +0 -0
  33. package/dist/{js/modern → esm-node}/runtime/loadable.js +11 -40
  34. package/dist/esm-node/runtime/plugin.js +107 -0
  35. package/dist/esm-node/runtime/useModuleApps.js +36 -0
  36. package/dist/{js/modern → esm-node}/runtime/utils/Context.js +0 -0
  37. package/dist/{js/modern → esm-node}/runtime/utils/MApp.js +4 -32
  38. package/dist/{js/modern → esm-node}/runtime/utils/apps.js +43 -90
  39. package/dist/{js/modern → esm-node}/runtime/utils/setExternal.js +0 -0
  40. package/dist/{js/modern → esm-node}/util.js +0 -0
  41. package/package.json +16 -17
  42. package/dist/js/modern/runtime/plugin.js +0 -156
  43. package/dist/js/modern/runtime/useModuleApps.js +0 -50
@@ -1,54 +1,3 @@
1
- var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __spreadValues = (a, b) => {
9
- for (var prop in b || (b = {}))
10
- if (__hasOwnProp.call(b, prop))
11
- __defNormalProp(a, prop, b[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- }
17
- return a;
18
- };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
- var __objRest = (source, exclude) => {
21
- var target = {};
22
- for (var prop in source)
23
- if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
24
- target[prop] = source[prop];
25
- if (source != null && __getOwnPropSymbols)
26
- for (var prop of __getOwnPropSymbols(source)) {
27
- if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
28
- target[prop] = source[prop];
29
- }
30
- return target;
31
- };
32
- var __async = (__this, __arguments, generator) => {
33
- return new Promise((resolve, reject) => {
34
- var fulfilled = (value) => {
35
- try {
36
- step(generator.next(value));
37
- } catch (e) {
38
- reject(e);
39
- }
40
- };
41
- var rejected = (value) => {
42
- try {
43
- step(generator.throw(value));
44
- } catch (e) {
45
- reject(e);
46
- }
47
- };
48
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
49
- step((generator = generator.apply(__this, __arguments)).next());
50
- });
51
- };
52
1
  import { Fragment, jsx } from "react/jsx-runtime";
53
2
  import { useContext, useState, useEffect, useRef } from "react";
54
3
  import { RuntimeReactContext } from "@modern-js/runtime";
@@ -85,7 +34,9 @@ function getAppInstance(options, appInfo, manifest) {
85
34
  const location = (_f = (_e = context == null ? void 0 : context.router) == null ? void 0 : _e.useLocation) == null ? void 0 : _f.call(_e);
86
35
  let basename = (options == null ? void 0 : options.basename) || "/";
87
36
  if (matchs && matchs.length > 0) {
88
- const matchItem = __spreadValues({}, matchs[matchs.length - 1]);
37
+ const matchItem = {
38
+ ...matchs[matchs.length - 1]
39
+ };
89
40
  for (const key in matchItem.params) {
90
41
  matchItem.pathname = matchItem.pathname.replace(
91
42
  new RegExp(`/${matchItem.params[key]}$`),
@@ -106,8 +57,9 @@ function getAppInstance(options, appInfo, manifest) {
106
57
  }
107
58
  }, [location]);
108
59
  useEffect(() => {
109
- const _a2 = props, { setLoadingState } = _a2, userProps = __objRest(_a2, ["setLoadingState"]);
110
- const loadAppOptions = __spreadProps(__spreadValues({}, appInfo), {
60
+ const { setLoadingState, ...userProps } = props;
61
+ const loadAppOptions = {
62
+ ...appInfo,
111
63
  insulationVariable: [
112
64
  ...appInfo.insulationVariable || [],
113
65
  "_SERVER_DATA"
@@ -115,7 +67,10 @@ function getAppInstance(options, appInfo, manifest) {
115
67
  domGetter: `#${domId}`,
116
68
  basename,
117
69
  cache: true,
118
- props: __spreadValues(__spreadValues({}, appInfo.props), userProps),
70
+ props: {
71
+ ...appInfo.props,
72
+ ...userProps
73
+ },
119
74
  customLoader: (provider) => {
120
75
  const {
121
76
  render,
@@ -143,7 +98,7 @@ function getAppInstance(options, appInfo, manifest) {
143
98
  }
144
99
  };
145
100
  }
146
- });
101
+ };
147
102
  setLoadingState({
148
103
  isLoading: true,
149
104
  error: null
@@ -151,51 +106,49 @@ function getAppInstance(options, appInfo, manifest) {
151
106
  logger(`MicroApp Garfish.loadApp "${appInfo.name}"`, {
152
107
  loadAppOptions
153
108
  });
154
- function renderApp() {
155
- return __async(this, null, function* () {
156
- try {
157
- const appInstance = yield Garfish.loadApp(
158
- appInfo.name,
159
- loadAppOptions
109
+ async function renderApp() {
110
+ try {
111
+ const appInstance = await Garfish.loadApp(
112
+ appInfo.name,
113
+ loadAppOptions
114
+ );
115
+ if (!appInstance) {
116
+ throw new Error(
117
+ `MicroApp Garfish.loadApp "${appInfo.name}" result is null`
160
118
  );
161
- if (!appInstance) {
162
- throw new Error(
163
- `MicroApp Garfish.loadApp "${appInfo.name}" result is null`
164
- );
165
- }
166
- appRef.current = appInstance;
167
- setLoadingState({
168
- isLoading: false
119
+ }
120
+ appRef.current = appInstance;
121
+ setLoadingState({
122
+ isLoading: false
123
+ });
124
+ if (appInstance.mounted && appInstance.appInfo.cache) {
125
+ logger(`MicroApp Garfish.loadApp "${appInfo.name}" show`, {
126
+ appInfo: appInstance.appInfo,
127
+ appInstance
169
128
  });
170
- if (appInstance.mounted && appInstance.appInfo.cache) {
171
- logger(`MicroApp Garfish.loadApp "${appInfo.name}" show`, {
172
- appInfo: appInstance.appInfo,
173
- appInstance
174
- });
175
- yield appInstance == null ? void 0 : appInstance.show();
176
- } else {
177
- logger(`MicroApp Garfish.loadApp "${appInfo.name}" mount`, {
178
- appInfo: appInstance.appInfo,
179
- appInstance
180
- });
181
- yield appInstance == null ? void 0 : appInstance.mount();
182
- }
183
- } catch (error) {
184
- setLoadingState({
185
- isLoading: true,
186
- error
129
+ await (appInstance == null ? void 0 : appInstance.show());
130
+ } else {
131
+ logger(`MicroApp Garfish.loadApp "${appInfo.name}" mount`, {
132
+ appInfo: appInstance.appInfo,
133
+ appInstance
187
134
  });
135
+ await (appInstance == null ? void 0 : appInstance.mount());
188
136
  }
189
- });
137
+ } catch (error) {
138
+ setLoadingState({
139
+ isLoading: true,
140
+ error
141
+ });
142
+ }
190
143
  }
191
144
  renderApp();
192
145
  return () => {
193
- var _a3, _b2;
146
+ var _a2, _b2;
194
147
  if (appRef.current) {
195
148
  const { appInfo: appInfo2 } = appRef.current;
196
149
  if (appInfo2.cache) {
197
150
  logger(`MicroApp Garfish.loadApp "${appInfo2.name}" hide`);
198
- (_a3 = appRef.current) == null ? void 0 : _a3.hide();
151
+ (_a2 = appRef.current) == null ? void 0 : _a2.hide();
199
152
  } else {
200
153
  logger(`MicroApp Garfish.loadApp "${appInfo2.name}" unmount`);
201
154
  (_b2 = appRef.current) == null ? void 0 : _b2.unmount();
File without changes
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "2.4.1-beta.0",
14
+ "version": "2.5.0",
15
15
  "jsnext:source": "./src/cli/index.ts",
16
16
  "types": "./dist/types/cli/index.d.ts",
17
17
  "typesVersions": {
@@ -33,26 +33,25 @@
33
33
  ]
34
34
  }
35
35
  },
36
- "main": "./dist/js/node/cli/index.js",
37
- "module": "./dist/js/treeshaking/runtime/index.js",
38
- "jsnext:modern": "./dist/js/modern/cli/index.js",
36
+ "main": "./dist/cjs/cli/index.js",
37
+ "module": "./dist/esm/runtime/index.js",
39
38
  "exports": {
40
39
  "./types": "./type.d.ts",
41
40
  ".": {
42
41
  "jsnext:source": "./src/cli/index.ts",
43
- "default": "./dist/js/node/cli/index.js"
42
+ "default": "./dist/cjs/cli/index.js"
44
43
  },
45
44
  "./cli": {
46
45
  "jsnext:source": "./src/cli/index.ts",
47
- "default": "./dist/js/node/cli/index.js"
46
+ "default": "./dist/cjs/cli/index.js"
48
47
  },
49
48
  "./deps": {
50
49
  "jsnext:source": "./src/deps/index.ts",
51
- "default": "./dist/js/treeshaking/deps/index.js"
50
+ "default": "./dist/esm/deps/index.js"
52
51
  },
53
52
  "./runtime": {
54
53
  "jsnext:source": "./src/index.ts",
55
- "default": "./dist/js/treeshaking/runtime/index.js"
54
+ "default": "./dist/esm/runtime/index.js"
56
55
  }
57
56
  },
58
57
  "dependencies": {
@@ -63,10 +62,10 @@
63
62
  "garfish": "^1.8.1",
64
63
  "hoist-non-react-statics": "^3.3.2",
65
64
  "react-loadable": "^5.5.0",
66
- "@modern-js/utils": "2.4.1-beta.0"
65
+ "@modern-js/utils": "2.5.0"
67
66
  },
68
67
  "peerDependencies": {
69
- "@modern-js/runtime": "^2.4.1-beta.0"
68
+ "@modern-js/runtime": "^2.5.0"
70
69
  },
71
70
  "peerDependenciesMeta": {
72
71
  "@modern-js/runtime": {
@@ -88,13 +87,13 @@
88
87
  "react-router-dom": "^6.6.0",
89
88
  "typescript": "^4",
90
89
  "webpack-chain": "^6.5.1",
91
- "@modern-js/app-tools": "3.0.0-beta.0",
92
- "@modern-js/core": "2.4.1-beta.0",
93
- "@modern-js/runtime": "2.4.1-beta.0",
94
- "@modern-js/plugin-router-v5": "2.4.1-beta.0",
95
- "@modern-js/types": "2.4.0",
96
- "@scripts/build": "2.4.0",
97
- "@scripts/jest-config": "2.4.0"
90
+ "@modern-js/app-tools": "2.5.0",
91
+ "@modern-js/core": "2.5.0",
92
+ "@modern-js/runtime": "2.5.0",
93
+ "@modern-js/plugin-router-v5": "2.5.0",
94
+ "@modern-js/types": "2.5.0",
95
+ "@scripts/build": "2.5.0",
96
+ "@scripts/jest-config": "2.5.0"
98
97
  },
99
98
  "sideEffects": false,
100
99
  "modernConfig": {},
@@ -1,156 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __spreadValues = (a, b) => {
9
- for (var prop in b || (b = {}))
10
- if (__hasOwnProp.call(b, prop))
11
- __defNormalProp(a, prop, b[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- }
17
- return a;
18
- };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
- var __objRest = (source, exclude) => {
21
- var target = {};
22
- for (var prop in source)
23
- if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
24
- target[prop] = source[prop];
25
- if (source != null && __getOwnPropSymbols)
26
- for (var prop of __getOwnPropSymbols(source)) {
27
- if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
28
- target[prop] = source[prop];
29
- }
30
- return target;
31
- };
32
- var __async = (__this, __arguments, generator) => {
33
- return new Promise((resolve, reject) => {
34
- var fulfilled = (value) => {
35
- try {
36
- step(generator.next(value));
37
- } catch (e) {
38
- reject(e);
39
- }
40
- };
41
- var rejected = (value) => {
42
- try {
43
- step(generator.throw(value));
44
- } catch (e) {
45
- reject(e);
46
- }
47
- };
48
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
49
- step((generator = generator.apply(__this, __arguments)).next());
50
- });
51
- };
52
- import { jsx } from "react/jsx-runtime";
53
- import GarfishInstance from "garfish";
54
- import React from "react";
55
- import hoistNonReactStatics from "hoist-non-react-statics";
56
- import { logger } from "../util";
57
- import { GarfishProvider } from "./utils/Context";
58
- import setExternal from "./utils/setExternal";
59
- import { generateMApp } from "./utils/MApp";
60
- import { generateApps } from "./utils/apps";
61
- function initOptions() {
62
- return __async(this, arguments, function* (manifest = {}, options) {
63
- var _a, _b, _c;
64
- let apps = options.apps || [];
65
- if (manifest == null ? void 0 : manifest.modules) {
66
- if ((manifest == null ? void 0 : manifest.modules.length) > 0) {
67
- apps = manifest == null ? void 0 : manifest.modules;
68
- }
69
- logger("manifest modules", apps);
70
- }
71
- if (manifest == null ? void 0 : manifest.getAppList) {
72
- const getAppList = yield manifest == null ? void 0 : manifest.getAppList(manifest);
73
- if (getAppList.length > 0) {
74
- apps = getAppList;
75
- }
76
- logger("getAppList modules", apps);
77
- }
78
- if (((_a = window == null ? void 0 : window.modern_manifest) == null ? void 0 : _a.modules) && ((_b = window == null ? void 0 : window.modern_manifest) == null ? void 0 : _b.modules.length) > 0) {
79
- apps = (_c = window == null ? void 0 : window.modern_manifest) == null ? void 0 : _c.modules;
80
- logger("modern_manifest", apps);
81
- }
82
- return __spreadProps(__spreadValues({}, options), {
83
- apps
84
- });
85
- });
86
- }
87
- var plugin_default = (config) => ({
88
- name: "@modern-js/garfish-plugin",
89
- setup: () => {
90
- setExternal();
91
- const _a = config, { manifest } = _a, options = __objRest(_a, ["manifest"]);
92
- logger("createPlugin", config);
93
- const promise = initOptions(manifest, options);
94
- return {
95
- hoc({ App }, next) {
96
- class GetMicroFrontendApp extends React.Component {
97
- constructor(props) {
98
- super(props);
99
- this.state = {
100
- MApp: () => {
101
- logger("MApp init Component Render");
102
- return React.createElement("div");
103
- },
104
- apps: new Proxy(
105
- {},
106
- {
107
- get() {
108
- return () => React.createElement("div");
109
- }
110
- }
111
- ),
112
- appInfoList: []
113
- };
114
- const load = () => __async(this, null, function* () {
115
- GarfishInstance.setOptions(__spreadProps(__spreadValues({}, options), {
116
- insulationVariable: [
117
- ...options.insulationVariable || [],
118
- "_SERVER_DATA"
119
- ],
120
- apps: []
121
- }));
122
- const GarfishConfig = yield promise;
123
- const { appInfoList, apps } = generateApps(
124
- GarfishConfig,
125
- manifest
126
- );
127
- GarfishInstance.registerApp(appInfoList);
128
- const MApp = generateMApp(GarfishConfig, manifest);
129
- logger("initOptions result", { manifest, GarfishConfig });
130
- logger("generateApps", { MApp, apps, appInfoList });
131
- this.setState({
132
- MApp,
133
- apps,
134
- appInfoList
135
- });
136
- });
137
- load();
138
- }
139
- render() {
140
- logger("GarfishProvider state", this.state);
141
- return /* @__PURE__ */ jsx(GarfishProvider, {
142
- value: this.state,
143
- children: /* @__PURE__ */ jsx(App, __spreadValues({}, this.props))
144
- });
145
- }
146
- }
147
- return next({
148
- App: hoistNonReactStatics(GetMicroFrontendApp, App)
149
- });
150
- }
151
- };
152
- }
153
- });
154
- export {
155
- plugin_default as default
156
- };
@@ -1,50 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
- var __hasOwnProp = Object.prototype.hasOwnProperty;
4
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
- var __spreadValues = (a, b) => {
7
- for (var prop in b || (b = {}))
8
- if (__hasOwnProp.call(b, prop))
9
- __defNormalProp(a, prop, b[prop]);
10
- if (__getOwnPropSymbols)
11
- for (var prop of __getOwnPropSymbols(b)) {
12
- if (__propIsEnum.call(b, prop))
13
- __defNormalProp(a, prop, b[prop]);
14
- }
15
- return a;
16
- };
17
- import React, { useContext } from "react";
18
- import { logger } from "../util";
19
- import { GarfishContext } from "./utils/Context";
20
- function useModuleApps() {
21
- const { apps, MApp, appInfoList } = useContext(GarfishContext);
22
- logger("call useModuleApps", __spreadValues({
23
- MApp,
24
- apps: appInfoList
25
- }, apps));
26
- const Info = new Proxy(
27
- __spreadValues({
28
- MApp,
29
- apps: appInfoList
30
- }, apps),
31
- {
32
- get(target, p, receiver) {
33
- if (typeof p === "string" && p in target) {
34
- return Reflect.get(target, p, receiver);
35
- }
36
- return () => React.createElement("div");
37
- }
38
- }
39
- );
40
- return Info;
41
- }
42
- function useModuleApp() {
43
- const { MApp } = useContext(GarfishContext);
44
- logger("call useModuleApps", MApp);
45
- return MApp;
46
- }
47
- export {
48
- useModuleApp,
49
- useModuleApps
50
- };