@modern-js/plugin-garfish 2.54.5 → 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,75 @@
|
|
|
1
|
+
"use strict";
|
|
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 });
|
|
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 code_exports = {};
|
|
30
|
+
__export(code_exports, {
|
|
31
|
+
ENTRY_BOOTSTRAP_FILE_NAME: () => ENTRY_BOOTSTRAP_FILE_NAME,
|
|
32
|
+
generateCode: () => generateCode
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(code_exports);
|
|
35
|
+
var import_path = __toESM(require("path"));
|
|
36
|
+
var import_utils = require("@modern-js/utils");
|
|
37
|
+
var template = __toESM(require("./template"));
|
|
38
|
+
var import_utils2 = require("./utils");
|
|
39
|
+
const ENTRY_POINT_FILE_NAME = "index.jsx";
|
|
40
|
+
const ENTRY_BOOTSTRAP_FILE_NAME = "bootstrap.jsx";
|
|
41
|
+
const generateCode = async (entrypoints, appContext, config, appendEntryCode) => {
|
|
42
|
+
const { mountId } = config.html;
|
|
43
|
+
const { enableAsyncEntry } = config.source;
|
|
44
|
+
const { internalDirectory, internalSrcAlias, metaName, srcDirectory } = appContext;
|
|
45
|
+
await Promise.all(entrypoints.map(async (entrypoint) => {
|
|
46
|
+
const { entryName, isAutoMount, entry, customEntry, customBootstrap } = entrypoint;
|
|
47
|
+
const appendCode = await appendEntryCode({
|
|
48
|
+
entrypoint
|
|
49
|
+
});
|
|
50
|
+
if (isAutoMount) {
|
|
51
|
+
const indexCode = template.index({
|
|
52
|
+
srcDirectory,
|
|
53
|
+
internalSrcAlias,
|
|
54
|
+
metaName,
|
|
55
|
+
entry,
|
|
56
|
+
entryName,
|
|
57
|
+
customEntry,
|
|
58
|
+
customBootstrap,
|
|
59
|
+
mountId,
|
|
60
|
+
appendCode
|
|
61
|
+
});
|
|
62
|
+
const indexFile = import_path.default.resolve(internalDirectory, `./${entryName}/${ENTRY_POINT_FILE_NAME}`);
|
|
63
|
+
import_utils.fs.outputFileSync(indexFile, indexCode, "utf8");
|
|
64
|
+
if (enableAsyncEntry) {
|
|
65
|
+
const bootstrapFile = import_path.default.resolve(internalDirectory, `./${entryName}/${ENTRY_BOOTSTRAP_FILE_NAME}`);
|
|
66
|
+
import_utils.fs.outputFileSync(bootstrapFile, (0, import_utils2.generateAsyncEntryCode)(appendCode), "utf8");
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}));
|
|
70
|
+
};
|
|
71
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
72
|
+
0 && (module.exports = {
|
|
73
|
+
ENTRY_BOOTSTRAP_FILE_NAME,
|
|
74
|
+
generateCode
|
|
75
|
+
});
|
package/dist/cjs/cli/index.js
CHANGED
|
@@ -25,8 +25,10 @@ __export(cli_exports, {
|
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(cli_exports);
|
|
27
27
|
var import_utils = require("@modern-js/utils");
|
|
28
|
+
var import_core = require("@modern-js/core");
|
|
28
29
|
var import_util = require("../util");
|
|
29
30
|
var import_utils2 = require("./utils");
|
|
31
|
+
var import_code = require("./code");
|
|
30
32
|
const externals = {
|
|
31
33
|
"react-dom": "react-dom",
|
|
32
34
|
react: "react"
|
|
@@ -45,11 +47,33 @@ function getDefaultMicroFrontedConfig(microFrontend) {
|
|
|
45
47
|
...microFrontend
|
|
46
48
|
};
|
|
47
49
|
}
|
|
48
|
-
const
|
|
50
|
+
const appendEntryCode = (0, import_core.createAsyncWorkflow)();
|
|
51
|
+
const garfishPlugin = () => ({
|
|
49
52
|
name: "@modern-js/plugin-garfish",
|
|
50
|
-
|
|
51
|
-
|
|
53
|
+
pre: [
|
|
54
|
+
"@modern-js/runtime"
|
|
55
|
+
],
|
|
56
|
+
registerHook: {
|
|
57
|
+
appendEntryCode
|
|
58
|
+
},
|
|
59
|
+
setup: (api) => {
|
|
52
60
|
return {
|
|
61
|
+
_internalRuntimePlugins({ entrypoint, plugins }) {
|
|
62
|
+
const userConfig = api.useResolvedConfigContext();
|
|
63
|
+
const { packageName, metaName } = api.useAppContext();
|
|
64
|
+
const runtimeConfig = (0, import_utils.getEntryOptions)(entrypoint.entryName, entrypoint.isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName);
|
|
65
|
+
if (runtimeConfig === null || runtimeConfig === void 0 ? void 0 : runtimeConfig.masterApp) {
|
|
66
|
+
plugins.push({
|
|
67
|
+
name: "garfish",
|
|
68
|
+
path: `@${metaName}/plugin-garfish/runtime`,
|
|
69
|
+
config: (runtimeConfig === null || runtimeConfig === void 0 ? void 0 : runtimeConfig.masterApp) || {}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
entrypoint,
|
|
74
|
+
plugins
|
|
75
|
+
};
|
|
76
|
+
},
|
|
53
77
|
resolvedConfig: async (config) => {
|
|
54
78
|
const { resolved } = config;
|
|
55
79
|
const { masterApp, router } = (0, import_utils2.getRuntimeConfig)(resolved);
|
|
@@ -60,7 +84,7 @@ const garfishPlugin = ({ pluginName = "@modern-js/plugin-garfish", runtimePlugin
|
|
|
60
84
|
};
|
|
61
85
|
if (masterApp) {
|
|
62
86
|
var _useConfig_server, _router_historyOptions;
|
|
63
|
-
const useConfig = useConfigContext();
|
|
87
|
+
const useConfig = api.useConfigContext();
|
|
64
88
|
const baseUrl = useConfig === null || useConfig === void 0 ? void 0 : (_useConfig_server = useConfig.server) === null || _useConfig_server === void 0 ? void 0 : _useConfig_server.baseUrl;
|
|
65
89
|
if (Array.isArray(baseUrl)) {
|
|
66
90
|
throw new Error("Now Micro-Front-End mode dose not support multiple baseUrl, you can set it as a string");
|
|
@@ -81,10 +105,9 @@ const garfishPlugin = ({ pluginName = "@modern-js/plugin-garfish", runtimePlugin
|
|
|
81
105
|
},
|
|
82
106
|
config() {
|
|
83
107
|
var _useConfig_output, _useConfig_deploy;
|
|
84
|
-
const useConfig = useConfigContext();
|
|
108
|
+
const useConfig = api.useConfigContext();
|
|
109
|
+
const { metaName, packageName } = api.useAppContext();
|
|
85
110
|
(0, import_util.logger)("useConfig", useConfig);
|
|
86
|
-
const config = useAppContext();
|
|
87
|
-
pluginsExportsUtils = (0, import_utils.createRuntimeExportsUtils)(config.internalDirectory, "plugins");
|
|
88
111
|
let disableCssExtract = ((_useConfig_output = useConfig.output) === null || _useConfig_output === void 0 ? void 0 : _useConfig_output.disableCssExtract) || false;
|
|
89
112
|
if ((_useConfig_deploy = useConfig.deploy) === null || _useConfig_deploy === void 0 ? void 0 : _useConfig_deploy.microFrontend) {
|
|
90
113
|
var _useConfig_deploy1;
|
|
@@ -99,8 +122,7 @@ const garfishPlugin = ({ pluginName = "@modern-js/plugin-garfish", runtimePlugin
|
|
|
99
122
|
},
|
|
100
123
|
source: {
|
|
101
124
|
alias: {
|
|
102
|
-
|
|
103
|
-
"@modern-js/runtime/garfish": "@modern-js/plugin-garfish/runtime"
|
|
125
|
+
[`@${metaName}/runtime/garfish`]: `@${metaName}/plugin-garfish/runtime`
|
|
104
126
|
}
|
|
105
127
|
},
|
|
106
128
|
tools: {
|
|
@@ -118,7 +140,7 @@ const garfishPlugin = ({ pluginName = "@modern-js/plugin-garfish", runtimePlugin
|
|
|
118
140
|
}
|
|
119
141
|
]);
|
|
120
142
|
}
|
|
121
|
-
const resolveOptions = useResolvedConfigContext();
|
|
143
|
+
const resolveOptions = api.useResolvedConfigContext();
|
|
122
144
|
if (resolveOptions === null || resolveOptions === void 0 ? void 0 : (_resolveOptions_deploy = resolveOptions.deploy) === null || _resolveOptions_deploy === void 0 ? void 0 : _resolveOptions_deploy.microFrontend) {
|
|
123
145
|
var _resolveOptions_dev, _useConfig_dev, _resolveOptions_server, _resolveOptions_deploy1;
|
|
124
146
|
chain.output.libraryTarget("umd");
|
|
@@ -143,7 +165,7 @@ const garfishPlugin = ({ pluginName = "@modern-js/plugin-garfish", runtimePlugin
|
|
|
143
165
|
}
|
|
144
166
|
const uniqueName = chain.output.get("uniqueName");
|
|
145
167
|
if (!uniqueName) {
|
|
146
|
-
chain.output.uniqueName(
|
|
168
|
+
chain.output.uniqueName(packageName);
|
|
147
169
|
}
|
|
148
170
|
const resolveConfig = chain.toConfig();
|
|
149
171
|
(0, import_util.logger)("bundlerConfig", {
|
|
@@ -158,125 +180,25 @@ const garfishPlugin = ({ pluginName = "@modern-js/plugin-garfish", runtimePlugin
|
|
|
158
180
|
};
|
|
159
181
|
},
|
|
160
182
|
addRuntimeExports() {
|
|
161
|
-
const config = useResolvedConfigContext();
|
|
183
|
+
const config = api.useResolvedConfigContext();
|
|
162
184
|
const { masterApp } = (0, import_utils2.getRuntimeConfig)(config);
|
|
185
|
+
const { internalDirectory, metaName } = api.useAppContext();
|
|
186
|
+
const pluginsExportsUtils = (0, import_utils.createRuntimeExportsUtils)(internalDirectory, "plugins");
|
|
163
187
|
if (masterApp) {
|
|
164
|
-
const addExportStatement = `export { default as garfish, default as masterApp } from '${
|
|
188
|
+
const addExportStatement = `export { default as garfish, default as masterApp } from '${metaName}/plugin-garfish/runtime'`;
|
|
165
189
|
(0, import_util.logger)("exportStatement", addExportStatement);
|
|
166
190
|
pluginsExportsUtils.addExport(addExportStatement);
|
|
167
191
|
}
|
|
168
|
-
const otherExportStatement = `export { hoistNonReactStatics } from '${pluginName}/deps'`;
|
|
169
|
-
(0, import_util.logger)("otherExportStatement", otherExportStatement);
|
|
170
|
-
pluginsExportsUtils.addExport(otherExportStatement);
|
|
171
|
-
},
|
|
172
|
-
modifyEntryImports({ entrypoint, imports }) {
|
|
173
|
-
const config = useResolvedConfigContext();
|
|
174
|
-
const { masterApp } = (0, import_utils2.getRuntimeConfig)(config);
|
|
175
|
-
if (masterApp) {
|
|
176
|
-
imports.push({
|
|
177
|
-
value: runtimePluginName,
|
|
178
|
-
specifiers: [
|
|
179
|
-
{
|
|
180
|
-
imported: "garfish"
|
|
181
|
-
}
|
|
182
|
-
]
|
|
183
|
-
});
|
|
184
|
-
imports.push({
|
|
185
|
-
value: runtimePluginName,
|
|
186
|
-
specifiers: [
|
|
187
|
-
{
|
|
188
|
-
imported: "masterApp"
|
|
189
|
-
}
|
|
190
|
-
]
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
imports.push({
|
|
194
|
-
value: runtimePluginName,
|
|
195
|
-
specifiers: [
|
|
196
|
-
{
|
|
197
|
-
imported: "hoistNonReactStatics"
|
|
198
|
-
}
|
|
199
|
-
]
|
|
200
|
-
});
|
|
201
|
-
imports.push({
|
|
202
|
-
value: "react-dom",
|
|
203
|
-
specifiers: [
|
|
204
|
-
{
|
|
205
|
-
imported: "unmountComponentAtNode"
|
|
206
|
-
},
|
|
207
|
-
{
|
|
208
|
-
imported: "createPortal"
|
|
209
|
-
}
|
|
210
|
-
]
|
|
211
|
-
});
|
|
212
|
-
return {
|
|
213
|
-
imports,
|
|
214
|
-
entrypoint
|
|
215
|
-
};
|
|
216
|
-
},
|
|
217
|
-
modifyEntryRuntimePlugins({ entrypoint, plugins }) {
|
|
218
|
-
const config = useResolvedConfigContext();
|
|
219
|
-
const { masterApp } = (0, import_utils2.getRuntimeConfig)(config);
|
|
220
|
-
if (masterApp) {
|
|
221
|
-
(0, import_util.logger)("garfishPlugin options", masterApp);
|
|
222
|
-
plugins.push({
|
|
223
|
-
name: "garfish",
|
|
224
|
-
args: "masterApp",
|
|
225
|
-
options: masterApp === true ? JSON.stringify({}) : JSON.stringify(masterApp)
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
return {
|
|
229
|
-
entrypoint,
|
|
230
|
-
plugins
|
|
231
|
-
};
|
|
232
|
-
},
|
|
233
|
-
modifyEntryRenderFunction({ entrypoint, code }) {
|
|
234
|
-
var _config_deploy;
|
|
235
|
-
const config = useResolvedConfigContext();
|
|
236
|
-
if (!(config === null || config === void 0 ? void 0 : (_config_deploy = config.deploy) === null || _config_deploy === void 0 ? void 0 : _config_deploy.microFrontend)) {
|
|
237
|
-
return {
|
|
238
|
-
entrypoint,
|
|
239
|
-
code
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
const nCode = (0, import_utils2.makeRenderFunction)(code);
|
|
243
|
-
(0, import_util.logger)("makeRenderFunction", nCode);
|
|
244
|
-
return {
|
|
245
|
-
entrypoint,
|
|
246
|
-
code: nCode
|
|
247
|
-
};
|
|
248
|
-
},
|
|
249
|
-
modifyAsyncEntry({ entrypoint, code }) {
|
|
250
|
-
var _config_deploy, _config_source;
|
|
251
|
-
const config = useResolvedConfigContext();
|
|
252
|
-
let finalCode = code;
|
|
253
|
-
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)) {
|
|
254
|
-
finalCode = (0, import_utils2.generateAsyncEntry)(code);
|
|
255
|
-
return {
|
|
256
|
-
entrypoint,
|
|
257
|
-
code: `${finalCode}`
|
|
258
|
-
};
|
|
259
|
-
}
|
|
260
|
-
return {
|
|
261
|
-
entrypoint,
|
|
262
|
-
code: finalCode
|
|
263
|
-
};
|
|
264
192
|
},
|
|
265
|
-
|
|
266
|
-
var
|
|
267
|
-
const
|
|
268
|
-
if (
|
|
269
|
-
const
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
exportStatement: exportStatementCode
|
|
274
|
-
};
|
|
193
|
+
async generateEntryCode({ entrypoints }) {
|
|
194
|
+
var _resolveOptions_deploy;
|
|
195
|
+
const resolveOptions = api.useResolvedConfigContext();
|
|
196
|
+
if (resolveOptions === null || resolveOptions === void 0 ? void 0 : (_resolveOptions_deploy = resolveOptions.deploy) === null || _resolveOptions_deploy === void 0 ? void 0 : _resolveOptions_deploy.microFrontend) {
|
|
197
|
+
const appContext = api.useAppContext();
|
|
198
|
+
const resolvedConfig = api.useResolvedConfigContext();
|
|
199
|
+
const { appendEntryCode: appendEntryCode2 } = api.useHookRunners();
|
|
200
|
+
await (0, import_code.generateCode)(entrypoints, appContext, resolvedConfig, appendEntryCode2);
|
|
275
201
|
}
|
|
276
|
-
return {
|
|
277
|
-
entrypoint,
|
|
278
|
-
exportStatement
|
|
279
|
-
};
|
|
280
202
|
}
|
|
281
203
|
};
|
|
282
204
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
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 template_exports = {};
|
|
20
|
+
__export(template_exports, {
|
|
21
|
+
index: () => index
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(template_exports);
|
|
24
|
+
var import_utils = require("@modern-js/utils");
|
|
25
|
+
const genRenderCode = ({ srcDirectory, internalSrcAlias, metaName, entry, customEntry, customBootstrap, mountId }) => customEntry ? `import '${entry.replace(srcDirectory, internalSrcAlias)}'
|
|
26
|
+
export * from '${entry.replace(srcDirectory, internalSrcAlias)}'` : `import { garfishRender, createProvider } from '@${metaName}/plugin-garfish/runtime';
|
|
27
|
+
|
|
28
|
+
${customBootstrap ? `import customBootstrap from '${(0, import_utils.formatImportPath)(customBootstrap.replace(srcDirectory, internalSrcAlias))}';` : "let customBootstrap;"}
|
|
29
|
+
garfishRender('${mountId || "root"}', customBootstrap)
|
|
30
|
+
|
|
31
|
+
export const provider = createProvider(undefined, ${customBootstrap ? "customBootstrap" : void 0});
|
|
32
|
+
`;
|
|
33
|
+
const index = ({ srcDirectory, internalSrcAlias, metaName, entry, entryName, customEntry, customBootstrap, mountId, appendCode = [] }) => `import '@${metaName}/runtime/registry/${entryName}';
|
|
34
|
+
${genRenderCode({
|
|
35
|
+
srcDirectory,
|
|
36
|
+
internalSrcAlias,
|
|
37
|
+
metaName,
|
|
38
|
+
entry,
|
|
39
|
+
customEntry,
|
|
40
|
+
customBootstrap,
|
|
41
|
+
mountId
|
|
42
|
+
})}
|
|
43
|
+
${appendCode.join("\n")}
|
|
44
|
+
`;
|
|
45
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
46
|
+
0 && (module.exports = {
|
|
47
|
+
index
|
|
48
|
+
});
|
package/dist/cjs/cli/utils.js
CHANGED
|
@@ -18,103 +18,11 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var utils_exports = {};
|
|
20
20
|
__export(utils_exports, {
|
|
21
|
-
|
|
21
|
+
generateAsyncEntryCode: () => generateAsyncEntryCode,
|
|
22
22
|
getRuntimeConfig: () => getRuntimeConfig,
|
|
23
|
-
makeProvider: () => makeProvider,
|
|
24
|
-
makeRenderFunction: () => makeRenderFunction,
|
|
25
23
|
setRuntimeConfig: () => setRuntimeConfig
|
|
26
24
|
});
|
|
27
25
|
module.exports = __toCommonJS(utils_exports);
|
|
28
|
-
const makeProvider = () => `
|
|
29
|
-
export const provider = function ({basename, dom}) {
|
|
30
|
-
return {
|
|
31
|
-
render({basename, dom, props, appName}) {
|
|
32
|
-
render({ props, basename, dom, appName });
|
|
33
|
-
},
|
|
34
|
-
destroy({ dom }) {
|
|
35
|
-
const node = dom.querySelector('#' + MOUNT_ID) || dom;
|
|
36
|
-
|
|
37
|
-
if (node) {
|
|
38
|
-
if (IS_REACT18) {
|
|
39
|
-
root.unmount();
|
|
40
|
-
} else {
|
|
41
|
-
unmountComponentAtNode(node);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
SubModuleComponent: (props) => {
|
|
46
|
-
const SubApp = render({props, basename});
|
|
47
|
-
|
|
48
|
-
return createPortal(<SubApp />, dom.querySelector('#' + MOUNT_ID) || dom);
|
|
49
|
-
},
|
|
50
|
-
jupiter_submodule_app_key: (props) => {
|
|
51
|
-
const SubApp = render({props, basename});
|
|
52
|
-
|
|
53
|
-
return createPortal(<SubApp />, dom.querySelector('#' + MOUNT_ID) || dom);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
if (typeof __GARFISH_EXPORTS__ !== 'undefined') {
|
|
59
|
-
__GARFISH_EXPORTS__.provider = provider;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function canContinueRender ({ dom, appName }) {
|
|
63
|
-
var renderByGarfish =
|
|
64
|
-
typeof __GARFISH_EXPORTS__ !== 'undefined'
|
|
65
|
-
|| typeof window !== 'undefined' && window.Garfish && window.Garfish.activeApps && window.Garfish.activeApps.some((app)=>app.appInfo.name === appName);
|
|
66
|
-
let renderByProvider = dom || appName;
|
|
67
|
-
if (renderByGarfish) {
|
|
68
|
-
// Runs in the Garfish environment and is rendered by the provider
|
|
69
|
-
if (renderByProvider) {
|
|
70
|
-
return true;
|
|
71
|
-
} else {
|
|
72
|
-
// Runs in the Garfish environment and is not rendered by the provider
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
} else {
|
|
76
|
-
// Running in a non-Garfish environment
|
|
77
|
-
return true;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function generateRouterPlugin (basename,routerConfig) {
|
|
82
|
-
if (basename) {
|
|
83
|
-
routerConfig.originalBaseUrl = basename.replace(/^\\/*/, "/");
|
|
84
|
-
// for compatibility with react router v5
|
|
85
|
-
routerConfig.basename = basename;
|
|
86
|
-
if (routerConfig.supportHtml5History !== false) {
|
|
87
|
-
if (!routerConfig.historyOptions) {
|
|
88
|
-
routerConfig.historyOptions = {
|
|
89
|
-
basename: basename
|
|
90
|
-
};
|
|
91
|
-
} else {
|
|
92
|
-
routerConfig.historyOptions.basename = basename;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return router(routerConfig);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function generateRootDom ({ dom, props, basename }) {
|
|
100
|
-
const mountNode = dom ? (dom.querySelector('#' + MOUNT_ID) || dom) : document.getElementById(MOUNT_ID);
|
|
101
|
-
const mergedProps = {
|
|
102
|
-
...props,
|
|
103
|
-
basename,
|
|
104
|
-
}
|
|
105
|
-
return { mountNode, props: mergedProps }
|
|
106
|
-
}
|
|
107
|
-
`;
|
|
108
|
-
const makeRenderFunction = (code) => {
|
|
109
|
-
const inGarfishToRender = `
|
|
110
|
-
let { basename, props, dom, appName } = typeof arguments[0] === 'object' && arguments[0] || {};
|
|
111
|
-
if (!canContinueRender({ dom, appName })) return null;
|
|
112
|
-
const rootDomInfo = generateRootDom({dom, props, basename});
|
|
113
|
-
let mountNode = rootDomInfo.mountNode;
|
|
114
|
-
props = rootDomInfo.props;
|
|
115
|
-
`;
|
|
116
|
-
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)");
|
|
117
|
-
};
|
|
118
26
|
function getRuntimeConfig(config) {
|
|
119
27
|
var _config_runtime;
|
|
120
28
|
if (config === null || config === void 0 ? void 0 : (_config_runtime = config.runtime) === null || _config_runtime === void 0 ? void 0 : _config_runtime.features) {
|
|
@@ -135,24 +43,23 @@ function setRuntimeConfig(config, key, value) {
|
|
|
135
43
|
}
|
|
136
44
|
return void 0;
|
|
137
45
|
}
|
|
138
|
-
const
|
|
139
|
-
const transformCode = code.replace(`import('./bootstrap.jsx');`, `if (!window.__GARFISH__) { import('./bootstrap.jsx'); }`);
|
|
46
|
+
const generateAsyncEntryCode = (appendCode = []) => {
|
|
140
47
|
return `
|
|
141
48
|
export const provider = async (...args) => {
|
|
142
|
-
const exports = await import('./
|
|
49
|
+
const exports = await import('./index.jsx');
|
|
143
50
|
return exports.provider.apply(null, args);
|
|
144
51
|
};
|
|
145
|
-
|
|
52
|
+
if (!window.__GARFISH__) { import('./index.jsx'); }
|
|
146
53
|
if (typeof __GARFISH_EXPORTS__ !== 'undefined') {
|
|
147
54
|
__GARFISH_EXPORTS__.provider = provider;
|
|
148
55
|
}
|
|
56
|
+
|
|
57
|
+
${appendCode.join("\n")}
|
|
149
58
|
`;
|
|
150
59
|
};
|
|
151
60
|
// Annotate the CommonJS export names for ESM import in node:
|
|
152
61
|
0 && (module.exports = {
|
|
153
|
-
|
|
62
|
+
generateAsyncEntryCode,
|
|
154
63
|
getRuntimeConfig,
|
|
155
|
-
makeProvider,
|
|
156
|
-
makeRenderFunction,
|
|
157
64
|
setRuntimeConfig
|
|
158
65
|
});
|
|
@@ -29,8 +29,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
29
29
|
var runtime_exports = {};
|
|
30
30
|
__export(runtime_exports, {
|
|
31
31
|
Garfish: () => import_garfish.default,
|
|
32
|
+
createProvider: () => import_provider.createProvider,
|
|
32
33
|
default: () => import_plugin.default,
|
|
33
34
|
garfish: () => import_garfish.default,
|
|
35
|
+
garfishPlugin: () => import_plugin.garfishPlugin,
|
|
36
|
+
garfishRender: () => import_render.garfishRender,
|
|
34
37
|
useModuleApp: () => import_useModuleApps.useModuleApp,
|
|
35
38
|
useModuleApps: () => import_useModuleApps.useModuleApps
|
|
36
39
|
});
|
|
@@ -38,10 +41,15 @@ module.exports = __toCommonJS(runtime_exports);
|
|
|
38
41
|
var import_plugin = __toESM(require("./plugin"));
|
|
39
42
|
var import_useModuleApps = require("./useModuleApps");
|
|
40
43
|
var import_garfish = __toESM(require("garfish"));
|
|
44
|
+
var import_render = require("./render");
|
|
45
|
+
var import_provider = require("./provider");
|
|
41
46
|
// Annotate the CommonJS export names for ESM import in node:
|
|
42
47
|
0 && (module.exports = {
|
|
43
48
|
Garfish,
|
|
49
|
+
createProvider,
|
|
44
50
|
garfish,
|
|
51
|
+
garfishPlugin,
|
|
52
|
+
garfishRender,
|
|
45
53
|
useModuleApp,
|
|
46
54
|
useModuleApps
|
|
47
55
|
});
|
|
@@ -28,13 +28,13 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
var plugin_exports = {};
|
|
30
30
|
__export(plugin_exports, {
|
|
31
|
-
default: () => plugin_default
|
|
31
|
+
default: () => plugin_default,
|
|
32
|
+
garfishPlugin: () => garfishPlugin
|
|
32
33
|
});
|
|
33
34
|
module.exports = __toCommonJS(plugin_exports);
|
|
34
35
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
35
36
|
var import_garfish = __toESM(require("garfish"));
|
|
36
37
|
var import_react = __toESM(require("react"));
|
|
37
|
-
var import_hoist_non_react_statics = __toESM(require("hoist-non-react-statics"));
|
|
38
38
|
var import_util = require("../util");
|
|
39
39
|
var import_Context = require("./utils/Context");
|
|
40
40
|
var import_setExternal = __toESM(require("./utils/setExternal"));
|
|
@@ -66,7 +66,7 @@ async function initOptions(manifest = {}, options) {
|
|
|
66
66
|
apps
|
|
67
67
|
};
|
|
68
68
|
}
|
|
69
|
-
|
|
69
|
+
const garfishPlugin = (config) => ({
|
|
70
70
|
name: "@modern-js/garfish-plugin",
|
|
71
71
|
setup: () => {
|
|
72
72
|
(0, import_setExternal.default)();
|
|
@@ -131,10 +131,15 @@ var plugin_default = (config) => ({
|
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
133
|
return next({
|
|
134
|
-
App:
|
|
134
|
+
App: GetMicroFrontendApp,
|
|
135
135
|
config: config2
|
|
136
136
|
});
|
|
137
137
|
}
|
|
138
138
|
};
|
|
139
139
|
}
|
|
140
140
|
});
|
|
141
|
+
var plugin_default = garfishPlugin;
|
|
142
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
143
|
+
0 && (module.exports = {
|
|
144
|
+
garfishPlugin
|
|
145
|
+
});
|
|
@@ -0,0 +1,79 @@
|
|
|
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 provider_exports = {};
|
|
20
|
+
__export(provider_exports, {
|
|
21
|
+
createProvider: () => createProvider
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(provider_exports);
|
|
24
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
25
|
+
var import_react = require("@modern-js/runtime/react");
|
|
26
|
+
var import_react_dom = require("react-dom");
|
|
27
|
+
var import_render = require("./render");
|
|
28
|
+
function createProvider(id, customBootstrap) {
|
|
29
|
+
return ({ basename, dom }) => {
|
|
30
|
+
let root = null;
|
|
31
|
+
return {
|
|
32
|
+
async render({ basename: basename2, dom: dom2, props, appName }) {
|
|
33
|
+
root = await (0, import_render.garfishRender)(id || "root", customBootstrap, {
|
|
34
|
+
basename: basename2,
|
|
35
|
+
dom: dom2,
|
|
36
|
+
props,
|
|
37
|
+
appName
|
|
38
|
+
});
|
|
39
|
+
},
|
|
40
|
+
destroy({ dom: dom2 }) {
|
|
41
|
+
const node = dom2.querySelector(`#${id || "root"}`) || dom2;
|
|
42
|
+
if (node) {
|
|
43
|
+
if (process.env.IS_REACT18 === "true") {
|
|
44
|
+
root.unmount();
|
|
45
|
+
} else {
|
|
46
|
+
(0, import_react_dom.unmountComponentAtNode)(node);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
// 兼容旧版本
|
|
51
|
+
SubModuleComponent: (props) => {
|
|
52
|
+
const ModernRoot = (0, import_react.createRoot)(null, {
|
|
53
|
+
router: {
|
|
54
|
+
basename
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
return /* @__PURE__ */ (0, import_react_dom.createPortal)(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(ModernRoot, {
|
|
58
|
+
basename,
|
|
59
|
+
...props
|
|
60
|
+
}), dom.querySelector(`#${id || "root"}`) || dom);
|
|
61
|
+
},
|
|
62
|
+
jupiter_submodule_app_key: (props) => {
|
|
63
|
+
const ModernRoot = (0, import_react.createRoot)(null, {
|
|
64
|
+
router: {
|
|
65
|
+
basename
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
return /* @__PURE__ */ (0, import_react_dom.createPortal)(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(ModernRoot, {
|
|
69
|
+
basename,
|
|
70
|
+
...props
|
|
71
|
+
}), dom.querySelector(`#${id || "root"}`) || dom);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
77
|
+
0 && (module.exports = {
|
|
78
|
+
createProvider
|
|
79
|
+
});
|