@modern-js/plugin-garfish 2.35.1 → 2.36.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.
- package/dist/cjs/cli/index.js +62 -63
- package/dist/cjs/cli/utils.js +31 -24
- package/dist/cjs/deps/index.js +35 -9
- package/dist/cjs/index.js +37 -10
- package/dist/cjs/runtime/index.js +43 -28
- package/dist/cjs/runtime/loadable.js +35 -18
- package/dist/cjs/runtime/plugin.js +62 -45
- package/dist/cjs/runtime/useModuleApps.js +43 -24
- package/dist/cjs/runtime/utils/Context.js +37 -18
- package/dist/cjs/runtime/utils/MApp.js +61 -35
- package/dist/cjs/runtime/utils/apps.js +61 -43
- package/dist/cjs/runtime/utils/setExternal.js +40 -18
- package/dist/cjs/util.js +39 -21
- package/dist/esm/cli/index.js +37 -40
- package/dist/esm/cli/utils.js +12 -5
- package/dist/esm/deps/index.js +4 -1
- package/dist/esm/index.js +4 -1
- package/dist/esm/runtime/index.js +10 -3
- package/dist/esm/runtime/loadable.js +8 -5
- package/dist/esm/runtime/plugin.js +13 -10
- package/dist/esm/runtime/useModuleApps.js +8 -4
- package/dist/esm/runtime/utils/Context.js +4 -1
- package/dist/esm/runtime/utils/MApp.js +8 -5
- package/dist/esm/runtime/utils/apps.js +12 -8
- package/dist/esm/runtime/utils/setExternal.js +4 -1
- package/dist/esm/util.js +8 -3
- package/dist/esm-node/cli/index.js +23 -25
- package/dist/esm-node/cli/utils.js +12 -5
- package/dist/esm-node/deps/index.js +4 -1
- package/dist/esm-node/index.js +4 -1
- package/dist/esm-node/runtime/index.js +10 -3
- package/dist/esm-node/runtime/loadable.js +4 -1
- package/dist/esm-node/runtime/plugin.js +4 -1
- package/dist/esm-node/runtime/useModuleApps.js +6 -2
- package/dist/esm-node/runtime/utils/Context.js +4 -1
- package/dist/esm-node/runtime/utils/MApp.js +4 -1
- package/dist/esm-node/runtime/utils/apps.js +6 -2
- package/dist/esm-node/runtime/utils/setExternal.js +4 -1
- package/dist/esm-node/util.js +8 -3
- package/package.json +10 -10
|
@@ -1,30 +1,43 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
6
9
|
for (var name in all)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return pathJoin;
|
|
15
|
-
},
|
|
16
|
-
generateApps: function() {
|
|
17
|
-
return generateApps;
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
17
|
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var apps_exports = {};
|
|
30
|
+
__export(apps_exports, {
|
|
31
|
+
generateApps: () => generateApps,
|
|
32
|
+
pathJoin: () => pathJoin
|
|
19
33
|
});
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const _loadable = require("../loadable");
|
|
34
|
+
module.exports = __toCommonJS(apps_exports);
|
|
35
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
36
|
+
var import_react = require("react");
|
|
37
|
+
var import_runtime = require("@modern-js/runtime");
|
|
38
|
+
var import_garfish = __toESM(require("garfish"));
|
|
39
|
+
var import_util = require("../../util");
|
|
40
|
+
var import_loadable = require("../loadable");
|
|
28
41
|
function pathJoin(...args) {
|
|
29
42
|
const res = args.reduce((res2, path) => {
|
|
30
43
|
let nPath = path;
|
|
@@ -46,10 +59,10 @@ function getAppInstance(options, appInfo, manifest) {
|
|
|
46
59
|
let locationHref = "";
|
|
47
60
|
function MicroApp(props) {
|
|
48
61
|
var _context_router_useRouteMatch, _context_router, _context_router_useMatches, _context_router1, _context_router_useLocation, _context_router2;
|
|
49
|
-
const appRef = (0,
|
|
50
|
-
const domId = (0,
|
|
51
|
-
const [SubModuleComponent, setSubModuleComponent] = (0,
|
|
52
|
-
const context = (0,
|
|
62
|
+
const appRef = (0, import_react.useRef)(null);
|
|
63
|
+
const domId = (0, import_util.generateSubAppContainerKey)(appInfo);
|
|
64
|
+
const [SubModuleComponent, setSubModuleComponent] = (0, import_react.useState)();
|
|
65
|
+
const context = (0, import_react.useContext)(import_runtime.RuntimeReactContext);
|
|
53
66
|
const match = context === null || context === void 0 ? void 0 : (_context_router = context.router) === null || _context_router === void 0 ? void 0 : (_context_router_useRouteMatch = _context_router.useRouteMatch) === null || _context_router_useRouteMatch === void 0 ? void 0 : _context_router_useRouteMatch.call(_context_router);
|
|
54
67
|
const matchs = context === null || context === void 0 ? void 0 : (_context_router1 = context.router) === null || _context_router1 === void 0 ? void 0 : (_context_router_useMatches = _context_router1.useMatches) === null || _context_router_useMatches === void 0 ? void 0 : _context_router_useMatches.call(_context_router1);
|
|
55
68
|
const location = context === null || context === void 0 ? void 0 : (_context_router2 = context.router) === null || _context_router2 === void 0 ? void 0 : (_context_router_useLocation = _context_router2.useLocation) === null || _context_router_useLocation === void 0 ? void 0 : _context_router_useLocation.call(_context_router2);
|
|
@@ -65,18 +78,18 @@ function getAppInstance(options, appInfo, manifest) {
|
|
|
65
78
|
} else if (match) {
|
|
66
79
|
basename = pathJoin(basename, (match === null || match === void 0 ? void 0 : match.path) || "/");
|
|
67
80
|
}
|
|
68
|
-
(0,
|
|
69
|
-
if (location && locationHref !== location.pathname && !
|
|
81
|
+
(0, import_react.useEffect)(() => {
|
|
82
|
+
if (location && locationHref !== location.pathname && !import_garfish.default.running) {
|
|
70
83
|
locationHref = location.pathname;
|
|
71
84
|
const popStateEvent = new PopStateEvent("popstate");
|
|
72
85
|
popStateEvent.garfish = true;
|
|
73
86
|
dispatchEvent(popStateEvent);
|
|
74
|
-
(0,
|
|
87
|
+
(0, import_util.logger)(`MicroApp Garfish.loadApp popstate`);
|
|
75
88
|
}
|
|
76
89
|
}, [
|
|
77
90
|
location
|
|
78
91
|
]);
|
|
79
|
-
(0,
|
|
92
|
+
(0, import_react.useEffect)(() => {
|
|
80
93
|
const { setLoadingState, ...userProps } = props;
|
|
81
94
|
const loadAppOptions = {
|
|
82
95
|
...appInfo,
|
|
@@ -100,7 +113,7 @@ function getAppInstance(options, appInfo, manifest) {
|
|
|
100
113
|
setSubModuleComponent(SubModuleComponent2);
|
|
101
114
|
return void 0;
|
|
102
115
|
} else {
|
|
103
|
-
(0,
|
|
116
|
+
(0, import_util.logger)("MicroApp customer render", props2);
|
|
104
117
|
return render === null || render === void 0 ? void 0 : render.apply(provider, props2);
|
|
105
118
|
}
|
|
106
119
|
},
|
|
@@ -108,7 +121,7 @@ function getAppInstance(options, appInfo, manifest) {
|
|
|
108
121
|
if (componetRenderMode) {
|
|
109
122
|
return void 0;
|
|
110
123
|
}
|
|
111
|
-
(0,
|
|
124
|
+
(0, import_util.logger)("MicroApp customer destroy", props2);
|
|
112
125
|
return destroy === null || destroy === void 0 ? void 0 : destroy.apply(provider, props2);
|
|
113
126
|
}
|
|
114
127
|
};
|
|
@@ -118,12 +131,12 @@ function getAppInstance(options, appInfo, manifest) {
|
|
|
118
131
|
isLoading: true,
|
|
119
132
|
error: null
|
|
120
133
|
});
|
|
121
|
-
(0,
|
|
134
|
+
(0, import_util.logger)(`MicroApp Garfish.loadApp "${appInfo.name}"`, {
|
|
122
135
|
loadAppOptions
|
|
123
136
|
});
|
|
124
137
|
async function renderApp() {
|
|
125
138
|
try {
|
|
126
|
-
const appInstance = await
|
|
139
|
+
const appInstance = await import_garfish.default.loadApp(appInfo.name, loadAppOptions);
|
|
127
140
|
if (!appInstance) {
|
|
128
141
|
throw new Error(`MicroApp Garfish.loadApp "${appInfo.name}" result is null`);
|
|
129
142
|
}
|
|
@@ -132,13 +145,13 @@ function getAppInstance(options, appInfo, manifest) {
|
|
|
132
145
|
isLoading: false
|
|
133
146
|
});
|
|
134
147
|
if (appInstance.mounted && appInstance.appInfo.cache) {
|
|
135
|
-
(0,
|
|
148
|
+
(0, import_util.logger)(`MicroApp Garfish.loadApp "${appInfo.name}" show`, {
|
|
136
149
|
appInfo: appInstance.appInfo,
|
|
137
150
|
appInstance
|
|
138
151
|
});
|
|
139
152
|
await (appInstance === null || appInstance === void 0 ? void 0 : appInstance.show());
|
|
140
153
|
} else {
|
|
141
|
-
(0,
|
|
154
|
+
(0, import_util.logger)(`MicroApp Garfish.loadApp "${appInfo.name}" mount`, {
|
|
142
155
|
appInfo: appInstance.appInfo,
|
|
143
156
|
appInstance
|
|
144
157
|
});
|
|
@@ -157,24 +170,24 @@ function getAppInstance(options, appInfo, manifest) {
|
|
|
157
170
|
const { appInfo: appInfo2 } = appRef.current;
|
|
158
171
|
if (appInfo2.cache) {
|
|
159
172
|
var _appRef_current;
|
|
160
|
-
(0,
|
|
173
|
+
(0, import_util.logger)(`MicroApp Garfish.loadApp "${appInfo2.name}" hide`);
|
|
161
174
|
(_appRef_current = appRef.current) === null || _appRef_current === void 0 ? void 0 : _appRef_current.hide();
|
|
162
175
|
} else {
|
|
163
176
|
var _appRef_current1;
|
|
164
|
-
(0,
|
|
177
|
+
(0, import_util.logger)(`MicroApp Garfish.loadApp "${appInfo2.name}" unmount`);
|
|
165
178
|
(_appRef_current1 = appRef.current) === null || _appRef_current1 === void 0 ? void 0 : _appRef_current1.unmount();
|
|
166
179
|
}
|
|
167
180
|
}
|
|
168
181
|
};
|
|
169
182
|
}, []);
|
|
170
|
-
return /* @__PURE__ */ (0,
|
|
171
|
-
children: /* @__PURE__ */ (0,
|
|
183
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
|
|
184
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
172
185
|
id: domId,
|
|
173
|
-
children: SubModuleComponent && /* @__PURE__ */ (0,
|
|
186
|
+
children: SubModuleComponent && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SubModuleComponent, {})
|
|
174
187
|
})
|
|
175
188
|
});
|
|
176
189
|
}
|
|
177
|
-
return (0,
|
|
190
|
+
return (0, import_loadable.Loadable)(MicroApp)(manifest === null || manifest === void 0 ? void 0 : manifest.loadable);
|
|
178
191
|
}
|
|
179
192
|
function generateApps(options, manifest) {
|
|
180
193
|
var _options_apps;
|
|
@@ -189,3 +202,8 @@ function generateApps(options, manifest) {
|
|
|
189
202
|
appInfoList: options.apps || []
|
|
190
203
|
};
|
|
191
204
|
}
|
|
205
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
206
|
+
0 && (module.exports = {
|
|
207
|
+
generateApps,
|
|
208
|
+
pathJoin
|
|
209
|
+
});
|
|
@@ -1,23 +1,45 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
9
17
|
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var setExternal_exports = {};
|
|
30
|
+
__export(setExternal_exports, {
|
|
31
|
+
default: () => setExternal_default
|
|
10
32
|
});
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
(0,
|
|
18
|
-
react:
|
|
19
|
-
"react-dom":
|
|
33
|
+
module.exports = __toCommonJS(setExternal_exports);
|
|
34
|
+
var import_react = __toESM(require("react"));
|
|
35
|
+
var import_react_dom = __toESM(require("react-dom"));
|
|
36
|
+
var import_garfish = __toESM(require("garfish"));
|
|
37
|
+
var import_util = require("../../util");
|
|
38
|
+
var setExternal_default = () => {
|
|
39
|
+
(0, import_util.logger)("setExternal ", {
|
|
40
|
+
react: import_react.default,
|
|
41
|
+
"react-dom": import_react_dom.default
|
|
20
42
|
});
|
|
21
|
-
|
|
22
|
-
|
|
43
|
+
import_garfish.default.setExternal("react", import_react.default);
|
|
44
|
+
import_garfish.default.setExternal("react-dom", import_react_dom.default);
|
|
23
45
|
};
|
package/dist/cjs/util.js
CHANGED
|
@@ -1,29 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
6
9
|
for (var name in all)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return logger;
|
|
15
|
-
},
|
|
16
|
-
SUBMODULE_APP_COMPONENT_KEY: function() {
|
|
17
|
-
return SUBMODULE_APP_COMPONENT_KEY;
|
|
18
|
-
},
|
|
19
|
-
generateSubAppContainerKey: function() {
|
|
20
|
-
return generateSubAppContainerKey;
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
21
17
|
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var util_exports = {};
|
|
30
|
+
__export(util_exports, {
|
|
31
|
+
SUBMODULE_APP_COMPONENT_KEY: () => SUBMODULE_APP_COMPONENT_KEY,
|
|
32
|
+
generateSubAppContainerKey: () => generateSubAppContainerKey,
|
|
33
|
+
logger: () => logger
|
|
22
34
|
});
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const logger = (0,
|
|
35
|
+
module.exports = __toCommonJS(util_exports);
|
|
36
|
+
var import_debug = __toESM(require("debug"));
|
|
37
|
+
const logger = (0, import_debug.default)("modern-js:plugin-garfish");
|
|
26
38
|
const SUBMODULE_APP_COMPONENT_KEY = "SubModuleComponent";
|
|
27
39
|
function generateSubAppContainerKey(moduleInfo) {
|
|
28
40
|
return moduleInfo ? `modern_sub_app_container_${decodeURIComponent(moduleInfo === null || moduleInfo === void 0 ? void 0 : moduleInfo.name)}` : "modern_sub_app_container";
|
|
29
41
|
}
|
|
42
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
43
|
+
0 && (module.exports = {
|
|
44
|
+
SUBMODULE_APP_COMPONENT_KEY,
|
|
45
|
+
generateSubAppContainerKey,
|
|
46
|
+
logger
|
|
47
|
+
});
|
package/dist/esm/cli/index.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
2
|
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
3
|
-
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
4
3
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
5
4
|
import { createRuntimeExportsUtils } from "@modern-js/utils";
|
|
6
5
|
import { logger } from "../util";
|
|
7
6
|
import { getRuntimeConfig, makeProvider, makeRenderFunction, setRuntimeConfig, generateAsyncEntry } from "./utils";
|
|
8
|
-
|
|
7
|
+
var externals = {
|
|
9
8
|
"react-dom": "react-dom",
|
|
10
9
|
react: "react"
|
|
11
10
|
};
|
|
12
|
-
|
|
11
|
+
function getDefaultMicroFrontedConfig(microFrontend) {
|
|
13
12
|
if (microFrontend === true) {
|
|
14
13
|
return {
|
|
15
14
|
enableHtmlEntry: true,
|
|
@@ -22,7 +21,7 @@ export function getDefaultMicroFrontedConfig(microFrontend) {
|
|
|
22
21
|
externalBasicLibrary: false
|
|
23
22
|
}, microFrontend);
|
|
24
23
|
}
|
|
25
|
-
|
|
24
|
+
var garfishPlugin = function() {
|
|
26
25
|
var _ref = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, _ref_pluginName = _ref.pluginName, pluginName = _ref_pluginName === void 0 ? "@modern-js/plugin-garfish" : _ref_pluginName, _ref_runtimePluginName = _ref.runtimePluginName, runtimePluginName = _ref_runtimePluginName === void 0 ? "@modern-js/runtime/plugins" : _ref_runtimePluginName;
|
|
27
26
|
return {
|
|
28
27
|
name: "@modern-js/plugin-garfish",
|
|
@@ -112,7 +111,7 @@ export var garfishPlugin = function() {
|
|
|
112
111
|
}
|
|
113
112
|
return {
|
|
114
113
|
output: {
|
|
115
|
-
disableCssExtract
|
|
114
|
+
disableCssExtract
|
|
116
115
|
},
|
|
117
116
|
source: {
|
|
118
117
|
alias: {
|
|
@@ -126,16 +125,6 @@ export var garfishPlugin = function() {
|
|
|
126
125
|
"Access-Control-Allow-Origin": "*"
|
|
127
126
|
}
|
|
128
127
|
},
|
|
129
|
-
webpackChain: function(chain, param2) {
|
|
130
|
-
var webpack = param2.webpack, CHAIN_ID = param2.CHAIN_ID;
|
|
131
|
-
if (webpack.BannerPlugin) {
|
|
132
|
-
chain.plugin(CHAIN_ID.PLUGIN.BANNER).use(webpack.BannerPlugin, [
|
|
133
|
-
{
|
|
134
|
-
banner: "Micro front-end"
|
|
135
|
-
}
|
|
136
|
-
]);
|
|
137
|
-
}
|
|
138
|
-
},
|
|
139
128
|
rspack: function(config3) {
|
|
140
129
|
var _resolveOptions_deploy;
|
|
141
130
|
var _config;
|
|
@@ -145,23 +134,25 @@ export var garfishPlugin = function() {
|
|
|
145
134
|
if ((resolveOptions === null || resolveOptions === void 0 ? void 0 : (_resolveOptions_deploy = resolveOptions.deploy) === null || _resolveOptions_deploy === void 0 ? void 0 : _resolveOptions_deploy.microFrontend) && !config3.externalsType) {
|
|
146
135
|
config3.externalsType = "commonjs";
|
|
147
136
|
}
|
|
148
|
-
var banner = config3.builtins.banner || [];
|
|
149
|
-
config3.builtins.banner = _to_consumable_array(Array.isArray(banner) ? banner : [
|
|
150
|
-
banner
|
|
151
|
-
]).concat([
|
|
152
|
-
{
|
|
153
|
-
banner: "Micro front-end"
|
|
154
|
-
}
|
|
155
|
-
]);
|
|
156
137
|
},
|
|
157
138
|
bundlerChain: function(chain, param2) {
|
|
158
|
-
var env = param2.env, CHAIN_ID = param2.CHAIN_ID;
|
|
139
|
+
var env = param2.env, CHAIN_ID = param2.CHAIN_ID, bundler = param2.bundler;
|
|
159
140
|
var _resolveOptions_deploy, _resolveConfig_resolve;
|
|
141
|
+
if (bundler.BannerPlugin) {
|
|
142
|
+
chain.plugin(CHAIN_ID.PLUGIN.BANNER).use(bundler.BannerPlugin, [
|
|
143
|
+
{
|
|
144
|
+
banner: "Micro front-end"
|
|
145
|
+
}
|
|
146
|
+
]);
|
|
147
|
+
}
|
|
160
148
|
var resolveOptions = useResolvedConfigContext();
|
|
161
149
|
if (resolveOptions === null || resolveOptions === void 0 ? void 0 : (_resolveOptions_deploy = resolveOptions.deploy) === null || _resolveOptions_deploy === void 0 ? void 0 : _resolveOptions_deploy.microFrontend) {
|
|
162
|
-
var _useConfig_dev, _resolveOptions_server, _resolveOptions_deploy1;
|
|
150
|
+
var _resolveOptions_dev, _useConfig_dev, _resolveOptions_server, _resolveOptions_deploy1;
|
|
163
151
|
chain.output.libraryTarget("umd");
|
|
164
|
-
|
|
152
|
+
var DEFAULT_ASSET_PREFIX = "/";
|
|
153
|
+
var resolvedAssetPrefix = (_resolveOptions_dev = resolveOptions.dev) === null || _resolveOptions_dev === void 0 ? void 0 : _resolveOptions_dev.assetPrefix;
|
|
154
|
+
var isUsingDefaultAssetPrefix = !((_useConfig_dev = useConfig.dev) === null || _useConfig_dev === void 0 ? void 0 : _useConfig_dev.assetPrefix) && (!resolvedAssetPrefix || resolvedAssetPrefix === DEFAULT_ASSET_PREFIX);
|
|
155
|
+
if (isUsingDefaultAssetPrefix && (resolveOptions === null || resolveOptions === void 0 ? void 0 : (_resolveOptions_server = resolveOptions.server) === null || _resolveOptions_server === void 0 ? void 0 : _resolveOptions_server.port) && env === "development") {
|
|
165
156
|
chain.output.publicPath("//localhost:".concat(resolveOptions.server.port, "/"));
|
|
166
157
|
}
|
|
167
158
|
var _getDefaultMicroFrontedConfig = getDefaultMicroFrontedConfig((_resolveOptions_deploy1 = resolveOptions.deploy) === null || _resolveOptions_deploy1 === void 0 ? void 0 : _resolveOptions_deploy1.microFrontend), enableHtmlEntry2 = _getDefaultMicroFrontedConfig.enableHtmlEntry, externalBasicLibrary = _getDefaultMicroFrontedConfig.externalBasicLibrary;
|
|
@@ -185,7 +176,7 @@ export var garfishPlugin = function() {
|
|
|
185
176
|
logger("bundlerConfig", {
|
|
186
177
|
output: resolveConfig.output,
|
|
187
178
|
externals: resolveConfig.externals,
|
|
188
|
-
env
|
|
179
|
+
env,
|
|
189
180
|
alias: (_resolveConfig_resolve = resolveConfig.resolve) === null || _resolveConfig_resolve === void 0 ? void 0 : _resolveConfig_resolve.alias,
|
|
190
181
|
plugins: resolveConfig.plugins
|
|
191
182
|
});
|
|
@@ -247,8 +238,8 @@ export var garfishPlugin = function() {
|
|
|
247
238
|
]
|
|
248
239
|
});
|
|
249
240
|
return {
|
|
250
|
-
imports
|
|
251
|
-
entrypoint
|
|
241
|
+
imports,
|
|
242
|
+
entrypoint
|
|
252
243
|
};
|
|
253
244
|
},
|
|
254
245
|
modifyEntryRuntimePlugins: function modifyEntryRuntimePlugins(param2) {
|
|
@@ -264,8 +255,8 @@ export var garfishPlugin = function() {
|
|
|
264
255
|
});
|
|
265
256
|
}
|
|
266
257
|
return {
|
|
267
|
-
entrypoint
|
|
268
|
-
plugins
|
|
258
|
+
entrypoint,
|
|
259
|
+
plugins
|
|
269
260
|
};
|
|
270
261
|
},
|
|
271
262
|
modifyEntryRenderFunction: function modifyEntryRenderFunction(param2) {
|
|
@@ -274,14 +265,14 @@ export var garfishPlugin = function() {
|
|
|
274
265
|
var config = useResolvedConfigContext();
|
|
275
266
|
if (!(config === null || config === void 0 ? void 0 : (_config_deploy = config.deploy) === null || _config_deploy === void 0 ? void 0 : _config_deploy.microFrontend)) {
|
|
276
267
|
return {
|
|
277
|
-
entrypoint
|
|
278
|
-
code
|
|
268
|
+
entrypoint,
|
|
269
|
+
code
|
|
279
270
|
};
|
|
280
271
|
}
|
|
281
272
|
var nCode = makeRenderFunction(code);
|
|
282
273
|
logger("makeRenderFunction", nCode);
|
|
283
274
|
return {
|
|
284
|
-
entrypoint
|
|
275
|
+
entrypoint,
|
|
285
276
|
code: nCode
|
|
286
277
|
};
|
|
287
278
|
},
|
|
@@ -293,12 +284,12 @@ export var garfishPlugin = function() {
|
|
|
293
284
|
if ((config === null || config === void 0 ? void 0 : (_config_deploy = config.deploy) === null || _config_deploy === void 0 ? void 0 : _config_deploy.microFrontend) && (config === null || config === void 0 ? void 0 : (_config_source = config.source) === null || _config_source === void 0 ? void 0 : _config_source.enableAsyncEntry)) {
|
|
294
285
|
finalCode = generateAsyncEntry(code);
|
|
295
286
|
return {
|
|
296
|
-
entrypoint
|
|
287
|
+
entrypoint,
|
|
297
288
|
code: "".concat(finalCode)
|
|
298
289
|
};
|
|
299
290
|
}
|
|
300
291
|
return {
|
|
301
|
-
entrypoint
|
|
292
|
+
entrypoint,
|
|
302
293
|
code: finalCode
|
|
303
294
|
};
|
|
304
295
|
},
|
|
@@ -310,17 +301,23 @@ export var garfishPlugin = function() {
|
|
|
310
301
|
var exportStatementCode = makeProvider();
|
|
311
302
|
logger("exportStatement", exportStatementCode);
|
|
312
303
|
return {
|
|
313
|
-
entrypoint
|
|
304
|
+
entrypoint,
|
|
314
305
|
exportStatement: exportStatementCode
|
|
315
306
|
};
|
|
316
307
|
}
|
|
317
308
|
return {
|
|
318
|
-
entrypoint
|
|
319
|
-
exportStatement
|
|
309
|
+
entrypoint,
|
|
310
|
+
exportStatement
|
|
320
311
|
};
|
|
321
312
|
}
|
|
322
313
|
};
|
|
323
314
|
}
|
|
324
315
|
};
|
|
325
316
|
};
|
|
326
|
-
|
|
317
|
+
var cli_default = garfishPlugin;
|
|
318
|
+
export {
|
|
319
|
+
cli_default as default,
|
|
320
|
+
externals,
|
|
321
|
+
garfishPlugin,
|
|
322
|
+
getDefaultMicroFrontedConfig
|
|
323
|
+
};
|
package/dist/esm/cli/utils.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
var makeProvider = function() {
|
|
2
2
|
return "\nexport const provider = function ({basename, dom}) {\n return {\n render({basename, dom, props, appName}) {\n render({ props, basename, dom, appName });\n },\n destroy({ dom }) {\n const node = dom.querySelector('#' + MOUNT_ID) || dom;\n\n if (node) {\n if (IS_REACT18) {\n root.unmount();\n } else {\n unmountComponentAtNode(node);\n }\n }\n },\n SubModuleComponent: (props) => {\n const SubApp = render({props, basename});\n\n return createPortal(<SubApp />, dom.querySelector('#' + MOUNT_ID) || dom);\n },\n jupiter_submodule_app_key: (props) => {\n const SubApp = render({props, basename});\n\n return createPortal(<SubApp />, dom.querySelector('#' + MOUNT_ID) || dom);\n }\n }\n};\n\nif (typeof __GARFISH_EXPORTS__ !== 'undefined') {\n __GARFISH_EXPORTS__.provider = provider;\n}\n\nfunction canContinueRender ({ dom, appName }) {\n var renderByGarfish =\n typeof __GARFISH_EXPORTS__ !== 'undefined'\n || typeof window !== 'undefined' && window.Garfish && window.Garfish.activeApps && window.Garfish.activeApps.some((app)=>app.appInfo.name === appName);\n let renderByProvider = dom || appName;\n if (renderByGarfish) {\n // Runs in the Garfish environment and is rendered by the provider\n if (renderByProvider) {\n return true;\n } else {\n // Runs in the Garfish environment and is not rendered by the provider\n return false;\n }\n } else {\n // Running in a non-Garfish environment\n return true;\n }\n}\n\nfunction generateRouterPlugin (basename,routerConfig) {\n if (basename) {\n routerConfig.basename = basename;\n if (routerConfig.supportHtml5History !== false) {\n if (!routerConfig.historyOptions) {\n routerConfig.historyOptions = {\n basename: basename\n };\n } else {\n routerConfig.historyOptions.basename = basename;\n }\n }\n }\n return router(routerConfig);\n}\n\nfunction generateRootDom ({ dom, props, basename }) {\n const mountNode = dom ? (dom.querySelector('#' + MOUNT_ID) || dom) : document.getElementById(MOUNT_ID);\n const mergedProps = {\n ...props,\n basename,\n }\n return { mountNode, props: mergedProps }\n}\n";
|
|
3
3
|
};
|
|
4
|
-
|
|
4
|
+
var makeRenderFunction = function(code) {
|
|
5
5
|
var inGarfishToRender = "\n let { basename, props, dom, appName } = typeof arguments[0] === 'object' && arguments[0] || {};\n if (!canContinueRender({ dom, appName })) return null;\n const rootDomInfo = generateRootDom({dom, props, basename});\n let mountNode = rootDomInfo.mountNode;\n props = rootDomInfo.props;\n ";
|
|
6
6
|
return inGarfishToRender + code.replace("router(", "generateRouterPlugin(basename,").replace(/MOUNT_ID/g, "mountNode").replace("createApp({", "createApp({ props,").replace("bootstrap(AppWrapper, mountNode, root", "bootstrap(AppWrapper, mountNode, root = IS_REACT18 ? ReactDOM.createRoot(mountNode) : null").replace("customBootstrap(AppWrapper", "customBootstrap(AppWrapper, mountNode");
|
|
7
7
|
};
|
|
8
|
-
|
|
8
|
+
function getRuntimeConfig(config) {
|
|
9
9
|
var _config_runtime;
|
|
10
10
|
if (config === null || config === void 0 ? void 0 : (_config_runtime = config.runtime) === null || _config_runtime === void 0 ? void 0 : _config_runtime.features) {
|
|
11
11
|
var _config_runtime1;
|
|
@@ -13,7 +13,7 @@ export function getRuntimeConfig(config) {
|
|
|
13
13
|
}
|
|
14
14
|
return (config === null || config === void 0 ? void 0 : config.runtime) || {};
|
|
15
15
|
}
|
|
16
|
-
|
|
16
|
+
function setRuntimeConfig(config, key, value) {
|
|
17
17
|
var _config_runtime, _config_runtime1;
|
|
18
18
|
if ((config === null || config === void 0 ? void 0 : (_config_runtime = config.runtime) === null || _config_runtime === void 0 ? void 0 : _config_runtime.features) && (config === null || config === void 0 ? void 0 : (_config_runtime1 = config.runtime) === null || _config_runtime1 === void 0 ? void 0 : _config_runtime1.features[key])) {
|
|
19
19
|
config.runtime.features[key] = value;
|
|
@@ -25,7 +25,14 @@ export function setRuntimeConfig(config, key, value) {
|
|
|
25
25
|
}
|
|
26
26
|
return void 0;
|
|
27
27
|
}
|
|
28
|
-
|
|
28
|
+
var generateAsyncEntry = function(code) {
|
|
29
29
|
var transformCode = code.replace("import('./bootstrap.jsx');", "if (!window.__GARFISH__) { import('./bootstrap.jsx'); }");
|
|
30
30
|
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 if (typeof __GARFISH_EXPORTS__ !== 'undefined') {\n __GARFISH_EXPORTS__.provider = provider;\n }\n ");
|
|
31
31
|
};
|
|
32
|
+
export {
|
|
33
|
+
generateAsyncEntry,
|
|
34
|
+
getRuntimeConfig,
|
|
35
|
+
makeProvider,
|
|
36
|
+
makeRenderFunction,
|
|
37
|
+
setRuntimeConfig
|
|
38
|
+
};
|
package/dist/esm/deps/index.js
CHANGED
package/dist/esm/index.js
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { default as default2 } from "./plugin";
|
|
2
|
+
import { useModuleApps, useModuleApp } from "./useModuleApps";
|
|
3
|
+
import { default as default3, default as default4 } from "garfish";
|
|
4
|
+
export {
|
|
5
|
+
default3 as Garfish,
|
|
6
|
+
default2 as default,
|
|
7
|
+
default4 as garfish,
|
|
8
|
+
useModuleApp,
|
|
9
|
+
useModuleApps
|
|
10
|
+
};
|
|
@@ -10,7 +10,7 @@ var DEFAULT_LOADABLE = {
|
|
|
10
10
|
timeout: 1e4,
|
|
11
11
|
loading: null
|
|
12
12
|
};
|
|
13
|
-
|
|
13
|
+
function Loadable(WrapComponent) {
|
|
14
14
|
return function(defaultLoadable) {
|
|
15
15
|
return function Lodable(props) {
|
|
16
16
|
var _props_loadable;
|
|
@@ -50,10 +50,10 @@ export function Loadable(WrapComponent) {
|
|
|
50
50
|
var LoadingComponent = (_props_loadable = props.loadable) === null || _props_loadable === void 0 ? void 0 : _props_loadable.loading;
|
|
51
51
|
useEffect(function() {
|
|
52
52
|
logger("Loadable render state", {
|
|
53
|
-
state
|
|
53
|
+
state,
|
|
54
54
|
props: otherProps,
|
|
55
|
-
loadable
|
|
56
|
-
defaultLoadable
|
|
55
|
+
loadable,
|
|
56
|
+
defaultLoadable
|
|
57
57
|
});
|
|
58
58
|
return function() {
|
|
59
59
|
setStateWithMountCheck({
|
|
@@ -94,7 +94,7 @@ export function Loadable(WrapComponent) {
|
|
|
94
94
|
pastDelay: state.pastDelay,
|
|
95
95
|
timedOut: state.timedOut,
|
|
96
96
|
error: state === null || state === void 0 ? void 0 : state.error,
|
|
97
|
-
retry
|
|
97
|
+
retry
|
|
98
98
|
}),
|
|
99
99
|
/* @__PURE__ */ _jsx(WrapComponent, _object_spread({
|
|
100
100
|
style: {
|
|
@@ -112,3 +112,6 @@ export function Loadable(WrapComponent) {
|
|
|
112
112
|
};
|
|
113
113
|
};
|
|
114
114
|
}
|
|
115
|
+
export {
|
|
116
|
+
Loadable
|
|
117
|
+
};
|