@modern-js/plugin-garfish 2.54.6 → 2.55.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/code.js +75 -0
- package/dist/cjs/cli/index.js +45 -123
- package/dist/cjs/cli/template.js +48 -0
- package/dist/cjs/cli/utils.js +7 -100
- package/dist/cjs/runtime/index.js +8 -0
- package/dist/cjs/runtime/plugin.js +9 -4
- package/dist/cjs/runtime/provider.js +79 -0
- package/dist/cjs/runtime/render.js +81 -0
- package/dist/esm/cli/code.js +80 -0
- package/dist/esm/cli/index.js +72 -136
- package/dist/esm/cli/template.js +20 -0
- package/dist/esm/cli/utils.js +4 -92
- package/dist/esm/runtime/index.js +6 -1
- package/dist/esm/runtime/plugin.js +6 -6
- package/dist/esm/runtime/provider.js +74 -0
- package/dist/esm/runtime/render.js +77 -0
- package/dist/esm-node/cli/code.js +40 -0
- package/dist/esm-node/cli/index.js +47 -125
- package/dist/esm-node/cli/template.js +24 -0
- package/dist/esm-node/cli/utils.js +6 -97
- package/dist/esm-node/runtime/index.js +6 -1
- package/dist/esm-node/runtime/plugin.js +5 -4
- package/dist/esm-node/runtime/provider.js +55 -0
- package/dist/esm-node/runtime/render.js +56 -0
- package/dist/types/cli/code.d.ts +7 -0
- package/dist/types/cli/index.d.ts +12 -5
- package/dist/types/cli/template.d.ts +11 -0
- package/dist/types/cli/utils.d.ts +1 -3
- package/dist/types/runtime/index.d.ts +3 -1
- package/dist/types/runtime/plugin.d.ts +2 -2
- package/dist/types/runtime/provider.d.ts +17 -0
- package/dist/types/runtime/render.d.ts +5 -0
- package/package.json +13 -23
- package/type.d.ts +8 -1
- package/dist/cjs/deps/index.js +0 -38
- package/dist/cjs/index.js +0 -40
- package/dist/esm/deps/index.js +0 -4
- package/dist/esm/index.js +0 -5
- package/dist/esm-node/deps/index.js +0 -4
- package/dist/esm-node/index.js +0 -5
- package/dist/types/deps/index.d.ts +0 -2
- package/dist/types/index.d.ts +0 -2
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var render_exports = {};
|
|
20
|
+
__export(render_exports, {
|
|
21
|
+
garfishRender: () => garfishRender,
|
|
22
|
+
isRenderGarfish: () => isRenderGarfish
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(render_exports);
|
|
25
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
26
|
+
var import_browser = require("@modern-js/runtime/browser");
|
|
27
|
+
var import_react = require("@modern-js/runtime/react");
|
|
28
|
+
function isRenderGarfish(params) {
|
|
29
|
+
const renderByGarfish = typeof __GARFISH_EXPORTS__ !== "undefined" || typeof window !== "undefined" && window.Garfish && window.Garfish.activeApps && window.Garfish.activeApps.some((app) => {
|
|
30
|
+
var _app_appInfo;
|
|
31
|
+
return ((_app_appInfo = app.appInfo) === null || _app_appInfo === void 0 ? void 0 : _app_appInfo.name) === (params === null || params === void 0 ? void 0 : params.appName);
|
|
32
|
+
});
|
|
33
|
+
return renderByGarfish;
|
|
34
|
+
}
|
|
35
|
+
function canContinueRender({ dom, appName }) {
|
|
36
|
+
const renderByGarfish = isRenderGarfish({
|
|
37
|
+
appName
|
|
38
|
+
});
|
|
39
|
+
const renderByProvider = dom || appName;
|
|
40
|
+
if (renderByGarfish) {
|
|
41
|
+
if (renderByProvider) {
|
|
42
|
+
return true;
|
|
43
|
+
} else {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
} else {
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
async function garfishRender(mountId, customBootstrap, _params) {
|
|
51
|
+
const { basename, props, dom, appName } = (
|
|
52
|
+
// eslint-disable-next-line prefer-rest-params
|
|
53
|
+
typeof arguments[2] === "object" && arguments[2] || {}
|
|
54
|
+
);
|
|
55
|
+
if (canContinueRender({
|
|
56
|
+
dom,
|
|
57
|
+
appName
|
|
58
|
+
})) {
|
|
59
|
+
const ModernRoot = (0, import_react.createRoot)(null, {
|
|
60
|
+
router: {
|
|
61
|
+
basename
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
if (customBootstrap) {
|
|
65
|
+
return customBootstrap(ModernRoot, () => (0, import_browser.render)(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(ModernRoot, {
|
|
66
|
+
basename,
|
|
67
|
+
...props
|
|
68
|
+
}), dom || mountId));
|
|
69
|
+
}
|
|
70
|
+
return (0, import_browser.render)(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(ModernRoot, {
|
|
71
|
+
basename,
|
|
72
|
+
...props
|
|
73
|
+
}), dom || mountId);
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
78
|
+
0 && (module.exports = {
|
|
79
|
+
garfishRender,
|
|
80
|
+
isRenderGarfish
|
|
81
|
+
});
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
+
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { fs } from "@modern-js/utils";
|
|
5
|
+
import * as template from "./template";
|
|
6
|
+
import { generateAsyncEntryCode } from "./utils";
|
|
7
|
+
var ENTRY_POINT_FILE_NAME = "index.jsx";
|
|
8
|
+
var ENTRY_BOOTSTRAP_FILE_NAME = "bootstrap.jsx";
|
|
9
|
+
var generateCode = function() {
|
|
10
|
+
var _ref = _async_to_generator(function(entrypoints, appContext, config, appendEntryCode) {
|
|
11
|
+
var mountId, enableAsyncEntry, internalDirectory, internalSrcAlias, metaName, srcDirectory;
|
|
12
|
+
return _ts_generator(this, function(_state) {
|
|
13
|
+
switch (_state.label) {
|
|
14
|
+
case 0:
|
|
15
|
+
mountId = config.html.mountId;
|
|
16
|
+
enableAsyncEntry = config.source.enableAsyncEntry;
|
|
17
|
+
internalDirectory = appContext.internalDirectory, internalSrcAlias = appContext.internalSrcAlias, metaName = appContext.metaName, srcDirectory = appContext.srcDirectory;
|
|
18
|
+
return [
|
|
19
|
+
4,
|
|
20
|
+
Promise.all(entrypoints.map(function() {
|
|
21
|
+
var _ref2 = _async_to_generator(function(entrypoint) {
|
|
22
|
+
var entryName, isAutoMount, entry, customEntry, customBootstrap, appendCode, indexCode, indexFile, bootstrapFile;
|
|
23
|
+
return _ts_generator(this, function(_state2) {
|
|
24
|
+
switch (_state2.label) {
|
|
25
|
+
case 0:
|
|
26
|
+
entryName = entrypoint.entryName, isAutoMount = entrypoint.isAutoMount, entry = entrypoint.entry, customEntry = entrypoint.customEntry, customBootstrap = entrypoint.customBootstrap;
|
|
27
|
+
return [
|
|
28
|
+
4,
|
|
29
|
+
appendEntryCode({
|
|
30
|
+
entrypoint
|
|
31
|
+
})
|
|
32
|
+
];
|
|
33
|
+
case 1:
|
|
34
|
+
appendCode = _state2.sent();
|
|
35
|
+
if (isAutoMount) {
|
|
36
|
+
indexCode = template.index({
|
|
37
|
+
srcDirectory,
|
|
38
|
+
internalSrcAlias,
|
|
39
|
+
metaName,
|
|
40
|
+
entry,
|
|
41
|
+
entryName,
|
|
42
|
+
customEntry,
|
|
43
|
+
customBootstrap,
|
|
44
|
+
mountId,
|
|
45
|
+
appendCode
|
|
46
|
+
});
|
|
47
|
+
indexFile = path.resolve(internalDirectory, "./".concat(entryName, "/").concat(ENTRY_POINT_FILE_NAME));
|
|
48
|
+
fs.outputFileSync(indexFile, indexCode, "utf8");
|
|
49
|
+
if (enableAsyncEntry) {
|
|
50
|
+
bootstrapFile = path.resolve(internalDirectory, "./".concat(entryName, "/").concat(ENTRY_BOOTSTRAP_FILE_NAME));
|
|
51
|
+
fs.outputFileSync(bootstrapFile, generateAsyncEntryCode(appendCode), "utf8");
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return [
|
|
55
|
+
2
|
|
56
|
+
];
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
return function(entrypoint) {
|
|
61
|
+
return _ref2.apply(this, arguments);
|
|
62
|
+
};
|
|
63
|
+
}()))
|
|
64
|
+
];
|
|
65
|
+
case 1:
|
|
66
|
+
_state.sent();
|
|
67
|
+
return [
|
|
68
|
+
2
|
|
69
|
+
];
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
return function generateCode2(entrypoints, appContext, config, appendEntryCode) {
|
|
74
|
+
return _ref.apply(this, arguments);
|
|
75
|
+
};
|
|
76
|
+
}();
|
|
77
|
+
export {
|
|
78
|
+
ENTRY_BOOTSTRAP_FILE_NAME,
|
|
79
|
+
generateCode
|
|
80
|
+
};
|
package/dist/esm/cli/index.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
+
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
2
3
|
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
3
4
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
4
|
-
import { createRuntimeExportsUtils } from "@modern-js/utils";
|
|
5
|
+
import { createRuntimeExportsUtils, getEntryOptions } from "@modern-js/utils";
|
|
6
|
+
import { createAsyncWorkflow } from "@modern-js/core";
|
|
5
7
|
import { logger } from "../util";
|
|
6
|
-
import { getRuntimeConfig,
|
|
8
|
+
import { getRuntimeConfig, setRuntimeConfig } from "./utils";
|
|
9
|
+
import { generateCode } from "./code";
|
|
7
10
|
var externals = {
|
|
8
11
|
"react-dom": "react-dom",
|
|
9
12
|
react: "react"
|
|
@@ -21,16 +24,37 @@ function getDefaultMicroFrontedConfig(microFrontend) {
|
|
|
21
24
|
externalBasicLibrary: false
|
|
22
25
|
}, microFrontend);
|
|
23
26
|
}
|
|
27
|
+
var appendEntryCode = createAsyncWorkflow();
|
|
24
28
|
var garfishPlugin = function() {
|
|
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;
|
|
26
29
|
return {
|
|
27
30
|
name: "@modern-js/plugin-garfish",
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
pre: [
|
|
32
|
+
"@modern-js/runtime"
|
|
33
|
+
],
|
|
34
|
+
registerHook: {
|
|
35
|
+
appendEntryCode
|
|
36
|
+
},
|
|
37
|
+
setup: function(api) {
|
|
31
38
|
return {
|
|
39
|
+
_internalRuntimePlugins: function _internalRuntimePlugins(param) {
|
|
40
|
+
var entrypoint = param.entrypoint, plugins = param.plugins;
|
|
41
|
+
var userConfig = api.useResolvedConfigContext();
|
|
42
|
+
var _api_useAppContext = api.useAppContext(), packageName = _api_useAppContext.packageName, metaName = _api_useAppContext.metaName;
|
|
43
|
+
var runtimeConfig = getEntryOptions(entrypoint.entryName, entrypoint.isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName);
|
|
44
|
+
if (runtimeConfig === null || runtimeConfig === void 0 ? void 0 : runtimeConfig.masterApp) {
|
|
45
|
+
plugins.push({
|
|
46
|
+
name: "garfish",
|
|
47
|
+
path: "@".concat(metaName, "/plugin-garfish/runtime"),
|
|
48
|
+
config: (runtimeConfig === null || runtimeConfig === void 0 ? void 0 : runtimeConfig.masterApp) || {}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
entrypoint,
|
|
53
|
+
plugins
|
|
54
|
+
};
|
|
55
|
+
},
|
|
32
56
|
resolvedConfig: function() {
|
|
33
|
-
var
|
|
57
|
+
var _ref = _async_to_generator(function(config) {
|
|
34
58
|
var resolved, _getRuntimeConfig, masterApp, router, nConfig, _useConfig_server, _router_historyOptions, useConfig, baseUrl;
|
|
35
59
|
return _ts_generator(this, function(_state) {
|
|
36
60
|
resolved = config.resolved;
|
|
@@ -40,7 +64,7 @@ var garfishPlugin = function() {
|
|
|
40
64
|
};
|
|
41
65
|
if (masterApp) {
|
|
42
66
|
;
|
|
43
|
-
useConfig = useConfigContext();
|
|
67
|
+
useConfig = api.useConfigContext();
|
|
44
68
|
baseUrl = useConfig === null || useConfig === void 0 ? void 0 : (_useConfig_server = useConfig.server) === null || _useConfig_server === void 0 ? void 0 : _useConfig_server.baseUrl;
|
|
45
69
|
if (Array.isArray(baseUrl)) {
|
|
46
70
|
throw new Error("Now Micro-Front-End mode dose not support multiple baseUrl, you can set it as a string");
|
|
@@ -62,15 +86,14 @@ var garfishPlugin = function() {
|
|
|
62
86
|
});
|
|
63
87
|
});
|
|
64
88
|
return function(config) {
|
|
65
|
-
return
|
|
89
|
+
return _ref.apply(this, arguments);
|
|
66
90
|
};
|
|
67
91
|
}(),
|
|
68
92
|
config: function config() {
|
|
69
93
|
var _useConfig_output, _useConfig_deploy;
|
|
70
|
-
var useConfig = useConfigContext();
|
|
94
|
+
var useConfig = api.useConfigContext();
|
|
95
|
+
var _api_useAppContext = api.useAppContext(), metaName = _api_useAppContext.metaName, packageName = _api_useAppContext.packageName;
|
|
71
96
|
logger("useConfig", useConfig);
|
|
72
|
-
var config2 = useAppContext();
|
|
73
|
-
pluginsExportsUtils = createRuntimeExportsUtils(config2.internalDirectory, "plugins");
|
|
74
97
|
var disableCssExtract = ((_useConfig_output = useConfig.output) === null || _useConfig_output === void 0 ? void 0 : _useConfig_output.disableCssExtract) || false;
|
|
75
98
|
if ((_useConfig_deploy = useConfig.deploy) === null || _useConfig_deploy === void 0 ? void 0 : _useConfig_deploy.microFrontend) {
|
|
76
99
|
var _useConfig_deploy1;
|
|
@@ -84,10 +107,7 @@ var garfishPlugin = function() {
|
|
|
84
107
|
disableCssExtract
|
|
85
108
|
},
|
|
86
109
|
source: {
|
|
87
|
-
alias: {
|
|
88
|
-
"@modern-js/runtime/plugins": pluginsExportsUtils.getPath(),
|
|
89
|
-
"@modern-js/runtime/garfish": "@modern-js/plugin-garfish/runtime"
|
|
90
|
-
}
|
|
110
|
+
alias: _define_property({}, "@".concat(metaName, "/runtime/garfish"), "@".concat(metaName, "/plugin-garfish/runtime"))
|
|
91
111
|
},
|
|
92
112
|
tools: {
|
|
93
113
|
devServer: {
|
|
@@ -95,8 +115,8 @@ var garfishPlugin = function() {
|
|
|
95
115
|
"Access-Control-Allow-Origin": "*"
|
|
96
116
|
}
|
|
97
117
|
},
|
|
98
|
-
bundlerChain: function(chain,
|
|
99
|
-
var env =
|
|
118
|
+
bundlerChain: function(chain, param) {
|
|
119
|
+
var env = param.env, CHAIN_ID = param.CHAIN_ID, bundler = param.bundler;
|
|
100
120
|
var _resolveOptions_deploy, _resolveConfig_resolve;
|
|
101
121
|
if (bundler.BannerPlugin) {
|
|
102
122
|
chain.plugin("garfish-banner").use(bundler.BannerPlugin, [
|
|
@@ -105,7 +125,7 @@ var garfishPlugin = function() {
|
|
|
105
125
|
}
|
|
106
126
|
]);
|
|
107
127
|
}
|
|
108
|
-
var resolveOptions = useResolvedConfigContext();
|
|
128
|
+
var resolveOptions = api.useResolvedConfigContext();
|
|
109
129
|
if (resolveOptions === null || resolveOptions === void 0 ? void 0 : (_resolveOptions_deploy = resolveOptions.deploy) === null || _resolveOptions_deploy === void 0 ? void 0 : _resolveOptions_deploy.microFrontend) {
|
|
110
130
|
var _resolveOptions_dev, _useConfig_dev, _resolveOptions_server, _resolveOptions_deploy1;
|
|
111
131
|
chain.output.libraryTarget("umd");
|
|
@@ -130,7 +150,7 @@ var garfishPlugin = function() {
|
|
|
130
150
|
}
|
|
131
151
|
var uniqueName = chain.output.get("uniqueName");
|
|
132
152
|
if (!uniqueName) {
|
|
133
|
-
chain.output.uniqueName(
|
|
153
|
+
chain.output.uniqueName(packageName);
|
|
134
154
|
}
|
|
135
155
|
var resolveConfig = chain.toConfig();
|
|
136
156
|
logger("bundlerConfig", {
|
|
@@ -145,130 +165,46 @@ var garfishPlugin = function() {
|
|
|
145
165
|
};
|
|
146
166
|
},
|
|
147
167
|
addRuntimeExports: function addRuntimeExports() {
|
|
148
|
-
var config = useResolvedConfigContext();
|
|
168
|
+
var config = api.useResolvedConfigContext();
|
|
149
169
|
var masterApp = getRuntimeConfig(config).masterApp;
|
|
170
|
+
var _api_useAppContext = api.useAppContext(), internalDirectory = _api_useAppContext.internalDirectory, metaName = _api_useAppContext.metaName;
|
|
171
|
+
var pluginsExportsUtils = createRuntimeExportsUtils(internalDirectory, "plugins");
|
|
150
172
|
if (masterApp) {
|
|
151
|
-
var addExportStatement = "export { default as garfish, default as masterApp } from '".concat(
|
|
173
|
+
var addExportStatement = "export { default as garfish, default as masterApp } from '".concat(metaName, "/plugin-garfish/runtime'");
|
|
152
174
|
logger("exportStatement", addExportStatement);
|
|
153
175
|
pluginsExportsUtils.addExport(addExportStatement);
|
|
154
176
|
}
|
|
155
|
-
var otherExportStatement = "export { hoistNonReactStatics } from '".concat(pluginName, "/deps'");
|
|
156
|
-
logger("otherExportStatement", otherExportStatement);
|
|
157
|
-
pluginsExportsUtils.addExport(otherExportStatement);
|
|
158
177
|
},
|
|
159
|
-
|
|
160
|
-
var
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
}
|
|
187
|
-
]
|
|
188
|
-
});
|
|
189
|
-
imports.push({
|
|
190
|
-
value: "react-dom",
|
|
191
|
-
specifiers: [
|
|
192
|
-
{
|
|
193
|
-
imported: "unmountComponentAtNode"
|
|
194
|
-
},
|
|
195
|
-
{
|
|
196
|
-
imported: "createPortal"
|
|
178
|
+
generateEntryCode: function generateEntryCode(param) {
|
|
179
|
+
var entrypoints = param.entrypoints;
|
|
180
|
+
return _async_to_generator(function() {
|
|
181
|
+
var _resolveOptions_deploy, resolveOptions, appContext, resolvedConfig, appendEntryCode2;
|
|
182
|
+
return _ts_generator(this, function(_state) {
|
|
183
|
+
switch (_state.label) {
|
|
184
|
+
case 0:
|
|
185
|
+
resolveOptions = api.useResolvedConfigContext();
|
|
186
|
+
if (!(resolveOptions === null || resolveOptions === void 0 ? void 0 : (_resolveOptions_deploy = resolveOptions.deploy) === null || _resolveOptions_deploy === void 0 ? void 0 : _resolveOptions_deploy.microFrontend))
|
|
187
|
+
return [
|
|
188
|
+
3,
|
|
189
|
+
2
|
|
190
|
+
];
|
|
191
|
+
appContext = api.useAppContext();
|
|
192
|
+
resolvedConfig = api.useResolvedConfigContext();
|
|
193
|
+
appendEntryCode2 = api.useHookRunners().appendEntryCode;
|
|
194
|
+
return [
|
|
195
|
+
4,
|
|
196
|
+
generateCode(entrypoints, appContext, resolvedConfig, appendEntryCode2)
|
|
197
|
+
];
|
|
198
|
+
case 1:
|
|
199
|
+
_state.sent();
|
|
200
|
+
_state.label = 2;
|
|
201
|
+
case 2:
|
|
202
|
+
return [
|
|
203
|
+
2
|
|
204
|
+
];
|
|
197
205
|
}
|
|
198
|
-
]
|
|
199
|
-
});
|
|
200
|
-
return {
|
|
201
|
-
imports,
|
|
202
|
-
entrypoint
|
|
203
|
-
};
|
|
204
|
-
},
|
|
205
|
-
modifyEntryRuntimePlugins: function modifyEntryRuntimePlugins(param2) {
|
|
206
|
-
var entrypoint = param2.entrypoint, plugins = param2.plugins;
|
|
207
|
-
var config = useResolvedConfigContext();
|
|
208
|
-
var masterApp = getRuntimeConfig(config).masterApp;
|
|
209
|
-
if (masterApp) {
|
|
210
|
-
logger("garfishPlugin options", masterApp);
|
|
211
|
-
plugins.push({
|
|
212
|
-
name: "garfish",
|
|
213
|
-
args: "masterApp",
|
|
214
|
-
options: masterApp === true ? JSON.stringify({}) : JSON.stringify(masterApp)
|
|
215
206
|
});
|
|
216
|
-
}
|
|
217
|
-
return {
|
|
218
|
-
entrypoint,
|
|
219
|
-
plugins
|
|
220
|
-
};
|
|
221
|
-
},
|
|
222
|
-
modifyEntryRenderFunction: function modifyEntryRenderFunction(param2) {
|
|
223
|
-
var entrypoint = param2.entrypoint, code = param2.code;
|
|
224
|
-
var _config_deploy;
|
|
225
|
-
var config = useResolvedConfigContext();
|
|
226
|
-
if (!(config === null || config === void 0 ? void 0 : (_config_deploy = config.deploy) === null || _config_deploy === void 0 ? void 0 : _config_deploy.microFrontend)) {
|
|
227
|
-
return {
|
|
228
|
-
entrypoint,
|
|
229
|
-
code
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
var nCode = makeRenderFunction(code);
|
|
233
|
-
logger("makeRenderFunction", nCode);
|
|
234
|
-
return {
|
|
235
|
-
entrypoint,
|
|
236
|
-
code: nCode
|
|
237
|
-
};
|
|
238
|
-
},
|
|
239
|
-
modifyAsyncEntry: function modifyAsyncEntry(param2) {
|
|
240
|
-
var entrypoint = param2.entrypoint, code = param2.code;
|
|
241
|
-
var _config_deploy, _config_source;
|
|
242
|
-
var config = useResolvedConfigContext();
|
|
243
|
-
var finalCode = code;
|
|
244
|
-
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)) {
|
|
245
|
-
finalCode = generateAsyncEntry(code);
|
|
246
|
-
return {
|
|
247
|
-
entrypoint,
|
|
248
|
-
code: "".concat(finalCode)
|
|
249
|
-
};
|
|
250
|
-
}
|
|
251
|
-
return {
|
|
252
|
-
entrypoint,
|
|
253
|
-
code: finalCode
|
|
254
|
-
};
|
|
255
|
-
},
|
|
256
|
-
modifyEntryExport: function modifyEntryExport(param2) {
|
|
257
|
-
var entrypoint = param2.entrypoint, exportStatement = param2.exportStatement;
|
|
258
|
-
var _config_deploy;
|
|
259
|
-
var config = useResolvedConfigContext();
|
|
260
|
-
if (config === null || config === void 0 ? void 0 : (_config_deploy = config.deploy) === null || _config_deploy === void 0 ? void 0 : _config_deploy.microFrontend) {
|
|
261
|
-
var exportStatementCode = makeProvider();
|
|
262
|
-
logger("exportStatement", exportStatementCode);
|
|
263
|
-
return {
|
|
264
|
-
entrypoint,
|
|
265
|
-
exportStatement: exportStatementCode
|
|
266
|
-
};
|
|
267
|
-
}
|
|
268
|
-
return {
|
|
269
|
-
entrypoint,
|
|
270
|
-
exportStatement
|
|
271
|
-
};
|
|
207
|
+
})();
|
|
272
208
|
}
|
|
273
209
|
};
|
|
274
210
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { formatImportPath } from "@modern-js/utils";
|
|
2
|
+
var genRenderCode = function(param) {
|
|
3
|
+
var srcDirectory = param.srcDirectory, internalSrcAlias = param.internalSrcAlias, metaName = param.metaName, entry = param.entry, customEntry = param.customEntry, customBootstrap = param.customBootstrap, mountId = param.mountId;
|
|
4
|
+
return customEntry ? "import '".concat(entry.replace(srcDirectory, internalSrcAlias), "'\nexport * from '").concat(entry.replace(srcDirectory, internalSrcAlias), "'") : "import { garfishRender, createProvider } from '@".concat(metaName, "/plugin-garfish/runtime';\n\n").concat(customBootstrap ? "import customBootstrap from '".concat(formatImportPath(customBootstrap.replace(srcDirectory, internalSrcAlias)), "';") : "let customBootstrap;", "\ngarfishRender('").concat(mountId || "root", "', customBootstrap)\n\nexport const provider = createProvider(undefined, ").concat(customBootstrap ? "customBootstrap" : void 0, ");\n");
|
|
5
|
+
};
|
|
6
|
+
var index = function(param) {
|
|
7
|
+
var srcDirectory = param.srcDirectory, internalSrcAlias = param.internalSrcAlias, metaName = param.metaName, entry = param.entry, entryName = param.entryName, customEntry = param.customEntry, customBootstrap = param.customBootstrap, mountId = param.mountId, _param_appendCode = param.appendCode, appendCode = _param_appendCode === void 0 ? [] : _param_appendCode;
|
|
8
|
+
return "import '@".concat(metaName, "/runtime/registry/").concat(entryName, "';\n ").concat(genRenderCode({
|
|
9
|
+
srcDirectory,
|
|
10
|
+
internalSrcAlias,
|
|
11
|
+
metaName,
|
|
12
|
+
entry,
|
|
13
|
+
customEntry,
|
|
14
|
+
customBootstrap,
|
|
15
|
+
mountId
|
|
16
|
+
}), "\n ").concat(appendCode.join("\n"), "\n ");
|
|
17
|
+
};
|
|
18
|
+
export {
|
|
19
|
+
index
|
|
20
|
+
};
|
package/dist/esm/cli/utils.js
CHANGED
|
@@ -1,89 +1,3 @@
|
|
|
1
|
-
var makeProvider = function() {
|
|
2
|
-
return `
|
|
3
|
-
export const provider = function ({basename, dom}) {
|
|
4
|
-
return {
|
|
5
|
-
render({basename, dom, props, appName}) {
|
|
6
|
-
render({ props, basename, dom, appName });
|
|
7
|
-
},
|
|
8
|
-
destroy({ dom }) {
|
|
9
|
-
const node = dom.querySelector('#' + MOUNT_ID) || dom;
|
|
10
|
-
|
|
11
|
-
if (node) {
|
|
12
|
-
if (IS_REACT18) {
|
|
13
|
-
root.unmount();
|
|
14
|
-
} else {
|
|
15
|
-
unmountComponentAtNode(node);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
SubModuleComponent: (props) => {
|
|
20
|
-
const SubApp = render({props, basename});
|
|
21
|
-
|
|
22
|
-
return createPortal(<SubApp />, dom.querySelector('#' + MOUNT_ID) || dom);
|
|
23
|
-
},
|
|
24
|
-
jupiter_submodule_app_key: (props) => {
|
|
25
|
-
const SubApp = render({props, basename});
|
|
26
|
-
|
|
27
|
-
return createPortal(<SubApp />, dom.querySelector('#' + MOUNT_ID) || dom);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
if (typeof __GARFISH_EXPORTS__ !== 'undefined') {
|
|
33
|
-
__GARFISH_EXPORTS__.provider = provider;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function canContinueRender ({ dom, appName }) {
|
|
37
|
-
var renderByGarfish =
|
|
38
|
-
typeof __GARFISH_EXPORTS__ !== 'undefined'
|
|
39
|
-
|| typeof window !== 'undefined' && window.Garfish && window.Garfish.activeApps && window.Garfish.activeApps.some((app)=>app.appInfo.name === appName);
|
|
40
|
-
let renderByProvider = dom || appName;
|
|
41
|
-
if (renderByGarfish) {
|
|
42
|
-
// Runs in the Garfish environment and is rendered by the provider
|
|
43
|
-
if (renderByProvider) {
|
|
44
|
-
return true;
|
|
45
|
-
} else {
|
|
46
|
-
// Runs in the Garfish environment and is not rendered by the provider
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
} else {
|
|
50
|
-
// Running in a non-Garfish environment
|
|
51
|
-
return true;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function generateRouterPlugin (basename,routerConfig) {
|
|
56
|
-
if (basename) {
|
|
57
|
-
routerConfig.originalBaseUrl = basename.replace(/^\\/*/, "/");
|
|
58
|
-
// for compatibility with react router v5
|
|
59
|
-
routerConfig.basename = basename;
|
|
60
|
-
if (routerConfig.supportHtml5History !== false) {
|
|
61
|
-
if (!routerConfig.historyOptions) {
|
|
62
|
-
routerConfig.historyOptions = {
|
|
63
|
-
basename: basename
|
|
64
|
-
};
|
|
65
|
-
} else {
|
|
66
|
-
routerConfig.historyOptions.basename = basename;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return router(routerConfig);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function generateRootDom ({ dom, props, basename }) {
|
|
74
|
-
const mountNode = dom ? (dom.querySelector('#' + MOUNT_ID) || dom) : document.getElementById(MOUNT_ID);
|
|
75
|
-
const mergedProps = {
|
|
76
|
-
...props,
|
|
77
|
-
basename,
|
|
78
|
-
}
|
|
79
|
-
return { mountNode, props: mergedProps }
|
|
80
|
-
}
|
|
81
|
-
`;
|
|
82
|
-
};
|
|
83
|
-
var makeRenderFunction = function(code) {
|
|
84
|
-
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 ";
|
|
85
|
-
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").replace(/customBootstrap\((.*)\)/g, "customBootstrap($1, props)");
|
|
86
|
-
};
|
|
87
1
|
function getRuntimeConfig(config) {
|
|
88
2
|
var _config_runtime;
|
|
89
3
|
if (config === null || config === void 0 ? void 0 : (_config_runtime = config.runtime) === null || _config_runtime === void 0 ? void 0 : _config_runtime.features) {
|
|
@@ -104,14 +18,12 @@ function setRuntimeConfig(config, key, value) {
|
|
|
104
18
|
}
|
|
105
19
|
return void 0;
|
|
106
20
|
}
|
|
107
|
-
var
|
|
108
|
-
var
|
|
109
|
-
return "\n export const provider = async (...args) => {\n const exports = await import('./
|
|
21
|
+
var generateAsyncEntryCode = function() {
|
|
22
|
+
var appendCode = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
|
|
23
|
+
return "\n export const provider = async (...args) => {\n const exports = await import('./index.jsx');\n return exports.provider.apply(null, args);\n };\n if (!window.__GARFISH__) { import('./index.jsx'); }\n if (typeof __GARFISH_EXPORTS__ !== 'undefined') {\n __GARFISH_EXPORTS__.provider = provider;\n }\n\n ".concat(appendCode.join("\n"), "\n ");
|
|
110
24
|
};
|
|
111
25
|
export {
|
|
112
|
-
|
|
26
|
+
generateAsyncEntryCode,
|
|
113
27
|
getRuntimeConfig,
|
|
114
|
-
makeProvider,
|
|
115
|
-
makeRenderFunction,
|
|
116
28
|
setRuntimeConfig
|
|
117
29
|
};
|
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import { default as default2 } from "./plugin";
|
|
1
|
+
import { default as default2, garfishPlugin } from "./plugin";
|
|
2
2
|
import { useModuleApps, useModuleApp } from "./useModuleApps";
|
|
3
3
|
import { default as default3, default as default4 } from "garfish";
|
|
4
|
+
import { garfishRender } from "./render";
|
|
5
|
+
import { createProvider } from "./provider";
|
|
4
6
|
export {
|
|
5
7
|
default3 as Garfish,
|
|
8
|
+
createProvider,
|
|
6
9
|
default2 as default,
|
|
7
10
|
default4 as garfish,
|
|
11
|
+
garfishPlugin,
|
|
12
|
+
garfishRender,
|
|
8
13
|
useModuleApp,
|
|
9
14
|
useModuleApps
|
|
10
15
|
};
|
|
@@ -11,7 +11,6 @@ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
|
11
11
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
12
|
import GarfishInstance from "garfish";
|
|
13
13
|
import React from "react";
|
|
14
|
-
import hoistNonReactStatics from "hoist-non-react-statics";
|
|
15
14
|
import { logger } from "../util";
|
|
16
15
|
import { GarfishProvider } from "./utils/Context";
|
|
17
16
|
import setExternal from "./utils/setExternal";
|
|
@@ -68,7 +67,7 @@ function _initOptions() {
|
|
|
68
67
|
});
|
|
69
68
|
return _initOptions.apply(this, arguments);
|
|
70
69
|
}
|
|
71
|
-
function
|
|
70
|
+
var garfishPlugin = function(config) {
|
|
72
71
|
return {
|
|
73
72
|
name: "@modern-js/garfish-plugin",
|
|
74
73
|
setup: function() {
|
|
@@ -163,15 +162,16 @@ function plugin_default(config) {
|
|
|
163
162
|
return GetMicroFrontendApp2;
|
|
164
163
|
}(React.Component);
|
|
165
164
|
return next({
|
|
166
|
-
App:
|
|
165
|
+
App: GetMicroFrontendApp,
|
|
167
166
|
config: _$config
|
|
168
167
|
});
|
|
169
168
|
}
|
|
170
169
|
};
|
|
171
170
|
}
|
|
172
171
|
};
|
|
173
|
-
}
|
|
174
|
-
;
|
|
172
|
+
};
|
|
173
|
+
var plugin_default = garfishPlugin;
|
|
175
174
|
export {
|
|
176
|
-
plugin_default as default
|
|
175
|
+
plugin_default as default,
|
|
176
|
+
garfishPlugin
|
|
177
177
|
};
|