@modern-js/plugin-garfish 2.54.6 → 2.56.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 +47 -123
- package/dist/cjs/cli/template.js +52 -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 +92 -0
- package/dist/cjs/{deps/index.js → runtime/utils.js} +8 -16
- package/dist/esm/cli/code.js +80 -0
- package/dist/esm/cli/index.js +73 -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 +113 -0
- package/dist/esm/runtime/utils.js +6 -0
- package/dist/esm-node/cli/code.js +40 -0
- package/dist/esm-node/cli/index.js +49 -125
- package/dist/esm-node/cli/template.js +28 -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 +68 -0
- package/dist/esm-node/runtime/utils.js +6 -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 +23 -0
- package/dist/types/runtime/utils.d.ts +1 -0
- package/package.json +13 -23
- package/type.d.ts +8 -1
- 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,9 @@ const garfishPlugin = ({ pluginName = "@modern-js/plugin-garfish", runtimePlugin
|
|
|
99
122
|
},
|
|
100
123
|
source: {
|
|
101
124
|
alias: {
|
|
102
|
-
|
|
103
|
-
"@
|
|
125
|
+
[`@${metaName}/runtime/garfish`]: `@${metaName}/plugin-garfish/runtime`,
|
|
126
|
+
"@meta/runtime/browser": "@modern-js/runtime/browser",
|
|
127
|
+
"@meta/runtime/react": "@modern-js/runtime/react"
|
|
104
128
|
}
|
|
105
129
|
},
|
|
106
130
|
tools: {
|
|
@@ -118,7 +142,7 @@ const garfishPlugin = ({ pluginName = "@modern-js/plugin-garfish", runtimePlugin
|
|
|
118
142
|
}
|
|
119
143
|
]);
|
|
120
144
|
}
|
|
121
|
-
const resolveOptions = useResolvedConfigContext();
|
|
145
|
+
const resolveOptions = api.useResolvedConfigContext();
|
|
122
146
|
if (resolveOptions === null || resolveOptions === void 0 ? void 0 : (_resolveOptions_deploy = resolveOptions.deploy) === null || _resolveOptions_deploy === void 0 ? void 0 : _resolveOptions_deploy.microFrontend) {
|
|
123
147
|
var _resolveOptions_dev, _useConfig_dev, _resolveOptions_server, _resolveOptions_deploy1;
|
|
124
148
|
chain.output.libraryTarget("umd");
|
|
@@ -143,7 +167,7 @@ const garfishPlugin = ({ pluginName = "@modern-js/plugin-garfish", runtimePlugin
|
|
|
143
167
|
}
|
|
144
168
|
const uniqueName = chain.output.get("uniqueName");
|
|
145
169
|
if (!uniqueName) {
|
|
146
|
-
chain.output.uniqueName(
|
|
170
|
+
chain.output.uniqueName(packageName);
|
|
147
171
|
}
|
|
148
172
|
const resolveConfig = chain.toConfig();
|
|
149
173
|
(0, import_util.logger)("bundlerConfig", {
|
|
@@ -158,125 +182,25 @@ const garfishPlugin = ({ pluginName = "@modern-js/plugin-garfish", runtimePlugin
|
|
|
158
182
|
};
|
|
159
183
|
},
|
|
160
184
|
addRuntimeExports() {
|
|
161
|
-
const config = useResolvedConfigContext();
|
|
185
|
+
const config = api.useResolvedConfigContext();
|
|
162
186
|
const { masterApp } = (0, import_utils2.getRuntimeConfig)(config);
|
|
187
|
+
const { internalDirectory, metaName } = api.useAppContext();
|
|
188
|
+
const pluginsExportsUtils = (0, import_utils.createRuntimeExportsUtils)(internalDirectory, "plugins");
|
|
163
189
|
if (masterApp) {
|
|
164
|
-
const addExportStatement = `export { default as garfish, default as masterApp } from '${
|
|
190
|
+
const addExportStatement = `export { default as garfish, default as masterApp } from '${metaName}/plugin-garfish/runtime'`;
|
|
165
191
|
(0, import_util.logger)("exportStatement", addExportStatement);
|
|
166
192
|
pluginsExportsUtils.addExport(addExportStatement);
|
|
167
193
|
}
|
|
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
194
|
},
|
|
265
|
-
|
|
266
|
-
var
|
|
267
|
-
const
|
|
268
|
-
if (
|
|
269
|
-
const
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
exportStatement: exportStatementCode
|
|
274
|
-
};
|
|
195
|
+
async generateEntryCode({ entrypoints }) {
|
|
196
|
+
var _resolveOptions_deploy;
|
|
197
|
+
const resolveOptions = api.useResolvedConfigContext();
|
|
198
|
+
if (resolveOptions === null || resolveOptions === void 0 ? void 0 : (_resolveOptions_deploy = resolveOptions.deploy) === null || _resolveOptions_deploy === void 0 ? void 0 : _resolveOptions_deploy.microFrontend) {
|
|
199
|
+
const appContext = api.useAppContext();
|
|
200
|
+
const resolvedConfig = api.useResolvedConfigContext();
|
|
201
|
+
const { appendEntryCode: appendEntryCode2 } = api.useHookRunners();
|
|
202
|
+
await (0, import_code.generateCode)(entrypoints, appContext, resolvedConfig, appendEntryCode2);
|
|
275
203
|
}
|
|
276
|
-
return {
|
|
277
|
-
entrypoint,
|
|
278
|
-
exportStatement
|
|
279
|
-
};
|
|
280
204
|
}
|
|
281
205
|
};
|
|
282
206
|
}
|
|
@@ -0,0 +1,52 @@
|
|
|
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 { createRoot } from '@${metaName}/runtime/react';
|
|
27
|
+
import { render } from '@${metaName}/runtime/browser';
|
|
28
|
+
import { isRenderGarfish, createProvider } from '@${metaName}/plugin-garfish/runtime';
|
|
29
|
+
${customBootstrap ? `import customBootstrap from '${(0, import_utils.formatImportPath)(customBootstrap.replace(srcDirectory, internalSrcAlias))}';` : "let customBootstrap;"}
|
|
30
|
+
if (!isRenderGarfish()) {
|
|
31
|
+
const ModernRoot = createRoot();
|
|
32
|
+
${customBootstrap ? `customBootstrap(ModernRoot, () => render(<ModernRoot />, '${mountId || "root"}'));` : `render(<ModernRoot />, '${mountId || "root"}');`};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const provider = createProvider('${mountId || "root"}', { customBootstrap });
|
|
36
|
+
`;
|
|
37
|
+
const index = ({ srcDirectory, internalSrcAlias, metaName, entry, entryName, customEntry, customBootstrap, mountId, appendCode = [] }) => `import '@${metaName}/runtime/registry/${entryName}';
|
|
38
|
+
${genRenderCode({
|
|
39
|
+
srcDirectory,
|
|
40
|
+
internalSrcAlias,
|
|
41
|
+
metaName,
|
|
42
|
+
entry,
|
|
43
|
+
customEntry,
|
|
44
|
+
customBootstrap,
|
|
45
|
+
mountId
|
|
46
|
+
})}
|
|
47
|
+
${appendCode.join("\n")}
|
|
48
|
+
`;
|
|
49
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
50
|
+
0 && (module.exports = {
|
|
51
|
+
index
|
|
52
|
+
});
|
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
|
+
isRenderGarfish: () => import_utils.isRenderGarfish,
|
|
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_utils = require("./utils");
|
|
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
|
+
isRenderGarfish,
|
|
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,92 @@
|
|
|
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("@meta/runtime/react");
|
|
26
|
+
var import_browser = require("@meta/runtime/browser");
|
|
27
|
+
var import_react_dom = require("react-dom");
|
|
28
|
+
function createProvider(id, { customBootstrap, beforeRender } = {}) {
|
|
29
|
+
return ({ basename, dom }) => {
|
|
30
|
+
let root = null;
|
|
31
|
+
return {
|
|
32
|
+
async render({ basename: basename2, dom: dom2, props }) {
|
|
33
|
+
const ModernRoot = (0, import_react.createRoot)(null, {
|
|
34
|
+
router: {
|
|
35
|
+
basename: basename2
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
if (customBootstrap) {
|
|
39
|
+
root = await customBootstrap(ModernRoot, () => (0, import_browser.render)(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(ModernRoot, {
|
|
40
|
+
basename: basename2,
|
|
41
|
+
...props
|
|
42
|
+
}), dom2));
|
|
43
|
+
} else {
|
|
44
|
+
if (beforeRender) {
|
|
45
|
+
await beforeRender(ModernRoot);
|
|
46
|
+
}
|
|
47
|
+
root = await (0, import_browser.render)(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(ModernRoot, {
|
|
48
|
+
basename: basename2,
|
|
49
|
+
...props
|
|
50
|
+
}), dom2);
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
destroy({ dom: dom2 }) {
|
|
54
|
+
const node = dom2.querySelector(`#${id || "root"}`) || dom2;
|
|
55
|
+
if (node) {
|
|
56
|
+
if (process.env.IS_REACT18 === "true") {
|
|
57
|
+
root.unmount();
|
|
58
|
+
} else {
|
|
59
|
+
(0, import_react_dom.unmountComponentAtNode)(node);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
// 兼容旧版本
|
|
64
|
+
SubModuleComponent: (props) => {
|
|
65
|
+
const ModernRoot = (0, import_react.createRoot)(null, {
|
|
66
|
+
router: {
|
|
67
|
+
basename
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
return /* @__PURE__ */ (0, import_react_dom.createPortal)(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(ModernRoot, {
|
|
71
|
+
basename,
|
|
72
|
+
...props
|
|
73
|
+
}), dom.querySelector(`#${id || "root"}`) || dom);
|
|
74
|
+
},
|
|
75
|
+
jupiter_submodule_app_key: (props) => {
|
|
76
|
+
const ModernRoot = (0, import_react.createRoot)(null, {
|
|
77
|
+
router: {
|
|
78
|
+
basename
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
return /* @__PURE__ */ (0, import_react_dom.createPortal)(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(ModernRoot, {
|
|
82
|
+
basename,
|
|
83
|
+
...props
|
|
84
|
+
}), dom.querySelector(`#${id || "root"}`) || dom);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
90
|
+
0 && (module.exports = {
|
|
91
|
+
createProvider
|
|
92
|
+
});
|