@modern-js/plugin-garfish 2.15.0 → 2.16.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/CHANGELOG.md +15 -0
- package/dist/cjs/cli/index.js +224 -236
- package/dist/cjs/cli/utils.js +24 -48
- package/dist/cjs/deps/index.js +12 -35
- package/dist/cjs/index.js +26 -36
- package/dist/cjs/runtime/index.js +24 -44
- package/dist/cjs/runtime/loadable.js +46 -58
- package/dist/cjs/runtime/plugin.js +86 -82
- package/dist/cjs/runtime/useModuleApps.js +70 -56
- package/dist/cjs/runtime/utils/Context.js +18 -36
- package/dist/cjs/runtime/utils/MApp.js +88 -87
- package/dist/cjs/runtime/utils/apps.js +114 -94
- package/dist/cjs/runtime/utils/setExternal.js +23 -41
- package/dist/cjs/util.js +21 -40
- package/dist/esm/cli/index.js +409 -402
- package/dist/esm/cli/utils.js +25 -26
- package/dist/esm/deps/index.js +1 -2
- package/dist/esm/index.js +1 -2
- package/dist/esm/runtime/index.js +3 -4
- package/dist/esm/runtime/loadable.js +226 -210
- package/dist/esm/runtime/plugin.js +456 -426
- package/dist/esm/runtime/useModuleApps.js +49 -50
- package/dist/esm/runtime/utils/Context.js +1 -1
- package/dist/esm/runtime/utils/MApp.js +337 -316
- package/dist/esm/runtime/utils/apps.js +468 -442
- package/dist/esm/runtime/utils/setExternal.js +9 -9
- package/dist/esm/util.js +4 -5
- package/dist/esm-node/cli/index.js +209 -219
- package/dist/esm-node/cli/utils.js +15 -30
- package/dist/esm-node/deps/index.js +1 -4
- package/dist/esm-node/index.js +1 -4
- package/dist/esm-node/runtime/index.js +3 -10
- package/dist/esm-node/runtime/loadable.js +34 -31
- package/dist/esm-node/runtime/plugin.js +50 -33
- package/dist/esm-node/runtime/useModuleApps.js +12 -19
- package/dist/esm-node/runtime/utils/Context.js +2 -5
- package/dist/esm-node/runtime/utils/MApp.js +61 -40
- package/dist/esm-node/runtime/utils/apps.js +38 -44
- package/dist/esm-node/runtime/utils/setExternal.js +5 -5
- package/dist/esm-node/util.js +4 -9
- package/package.json +15 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @modern-js/plugin-garfish
|
|
2
2
|
|
|
3
|
+
## 2.16.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 4e876ab: chore: package.json include the monorepo-relative directory
|
|
8
|
+
|
|
9
|
+
chore: 在 package.json 中声明 monorepo 的子路径
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [02e9c5d]
|
|
12
|
+
- Updated dependencies [5954330]
|
|
13
|
+
- Updated dependencies [7596520]
|
|
14
|
+
- Updated dependencies [4e876ab]
|
|
15
|
+
- @modern-js/runtime@2.16.0
|
|
16
|
+
- @modern-js/utils@2.16.0
|
|
17
|
+
|
|
3
18
|
## 2.15.0
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/dist/cjs/cli/index.js
CHANGED
|
@@ -1,31 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
6
|
for (var name in all)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var cli_exports = {};
|
|
19
|
-
__export(cli_exports, {
|
|
20
|
-
default: () => cli_default,
|
|
7
|
+
Object.defineProperty(target, name, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: all[name]
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
_export(exports, {
|
|
21
13
|
externals: () => externals,
|
|
22
|
-
getDefaultMicroFrontedConfig: () => getDefaultMicroFrontedConfig
|
|
14
|
+
getDefaultMicroFrontedConfig: () => getDefaultMicroFrontedConfig,
|
|
15
|
+
default: () => _default
|
|
23
16
|
});
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
17
|
+
const _utils = require("@modern-js/utils");
|
|
18
|
+
const _util = require("../util");
|
|
19
|
+
const _utils1 = require("./utils");
|
|
20
|
+
const externals = {
|
|
21
|
+
"react-dom": "react-dom",
|
|
22
|
+
react: "react"
|
|
23
|
+
};
|
|
29
24
|
function getDefaultMicroFrontedConfig(microFrontend) {
|
|
30
25
|
if (microFrontend === true) {
|
|
31
26
|
return {
|
|
@@ -40,244 +35,237 @@ function getDefaultMicroFrontedConfig(microFrontend) {
|
|
|
40
35
|
...microFrontend
|
|
41
36
|
};
|
|
42
37
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
38
|
+
const _default = ({ pluginName = "@modern-js/plugin-garfish", runtimePluginName = "@modern-js/runtime/plugins" } = {}) => {
|
|
39
|
+
return {
|
|
40
|
+
name: "@modern-js/plugin-garfish",
|
|
41
|
+
setup: ({ useAppContext, useResolvedConfigContext, useConfigContext }) => {
|
|
42
|
+
let pluginsExportsUtils;
|
|
43
|
+
return {
|
|
44
|
+
validateSchema() {
|
|
45
|
+
return _utils.PLUGIN_SCHEMAS["@modern-js/plugin-garfish"];
|
|
46
|
+
},
|
|
47
|
+
resolvedConfig: async (config) => {
|
|
48
|
+
const { resolved } = config;
|
|
49
|
+
const { masterApp, router } = (0, _utils1.getRuntimeConfig)(resolved);
|
|
50
|
+
const nConfig = {
|
|
51
|
+
resolved: {
|
|
52
|
+
...resolved
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
if (masterApp) {
|
|
56
|
+
var _useConfig_server, _router_historyOptions;
|
|
57
|
+
const useConfig = useConfigContext();
|
|
58
|
+
const baseUrl = useConfig === null || useConfig === void 0 ? void 0 : (_useConfig_server = useConfig.server) === null || _useConfig_server === void 0 ? void 0 : _useConfig_server.baseUrl;
|
|
59
|
+
if (Array.isArray(baseUrl)) {
|
|
60
|
+
throw new Error("Now Micro-Front-End mode dose not support multiple baseUrl, you can set it as a string");
|
|
61
|
+
}
|
|
62
|
+
(0, _utils1.setRuntimeConfig)(nConfig.resolved, "masterApp", Object.assign(typeof masterApp === "object" ? {
|
|
63
|
+
...masterApp
|
|
64
|
+
} : {}, {
|
|
65
|
+
basename: baseUrl || (router === null || router === void 0 ? void 0 : (_router_historyOptions = router.historyOptions) === null || _router_historyOptions === void 0 ? void 0 : _router_historyOptions.basename) || (router === null || router === void 0 ? void 0 : router.basename) || "/"
|
|
66
|
+
}));
|
|
61
67
|
}
|
|
62
|
-
|
|
63
|
-
|
|
68
|
+
(0, _util.logger)(`resolvedConfig`, {
|
|
69
|
+
output: nConfig.resolved.output,
|
|
70
|
+
runtime: nConfig.resolved.runtime,
|
|
71
|
+
deploy: nConfig.resolved.deploy,
|
|
72
|
+
server: nConfig.resolved.server
|
|
73
|
+
});
|
|
74
|
+
return nConfig;
|
|
75
|
+
},
|
|
76
|
+
config() {
|
|
77
|
+
var _useConfig_output, _useConfig_deploy;
|
|
64
78
|
const useConfig = useConfigContext();
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
Object.assign(
|
|
75
|
-
typeof masterApp === "object" ? { ...masterApp } : {},
|
|
76
|
-
{
|
|
77
|
-
basename: baseUrl || ((_b = router == null ? void 0 : router.historyOptions) == null ? void 0 : _b.basename) || (router == null ? void 0 : router.basename) || "/"
|
|
78
|
-
}
|
|
79
|
-
)
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
(0, import_util.logger)(`resolvedConfig`, {
|
|
83
|
-
output: nConfig.resolved.output,
|
|
84
|
-
runtime: nConfig.resolved.runtime,
|
|
85
|
-
deploy: nConfig.resolved.deploy,
|
|
86
|
-
server: nConfig.resolved.server
|
|
87
|
-
});
|
|
88
|
-
return nConfig;
|
|
89
|
-
},
|
|
90
|
-
config() {
|
|
91
|
-
var _a, _b, _c;
|
|
92
|
-
const useConfig = useConfigContext();
|
|
93
|
-
(0, import_util.logger)("useConfig", useConfig);
|
|
94
|
-
const config = useAppContext();
|
|
95
|
-
pluginsExportsUtils = (0, import_utils.createRuntimeExportsUtils)(
|
|
96
|
-
config.internalDirectory,
|
|
97
|
-
"plugins"
|
|
98
|
-
);
|
|
99
|
-
let disableCssExtract = ((_a = useConfig.output) == null ? void 0 : _a.disableCssExtract) || false;
|
|
100
|
-
if ((_b = useConfig.deploy) == null ? void 0 : _b.microFrontend) {
|
|
101
|
-
const { enableHtmlEntry } = getDefaultMicroFrontedConfig(
|
|
102
|
-
(_c = useConfig.deploy) == null ? void 0 : _c.microFrontend
|
|
103
|
-
);
|
|
104
|
-
if (!enableHtmlEntry) {
|
|
105
|
-
disableCssExtract = true;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
return {
|
|
109
|
-
output: {
|
|
110
|
-
disableCssExtract
|
|
111
|
-
},
|
|
112
|
-
source: {
|
|
113
|
-
alias: {
|
|
114
|
-
"@modern-js/runtime/plugins": pluginsExportsUtils.getPath(),
|
|
115
|
-
"@modern-js/runtime/garfish": "@modern-js/plugin-garfish/runtime"
|
|
79
|
+
(0, _util.logger)("useConfig", useConfig);
|
|
80
|
+
const config = useAppContext();
|
|
81
|
+
pluginsExportsUtils = (0, _utils.createRuntimeExportsUtils)(config.internalDirectory, "plugins");
|
|
82
|
+
let disableCssExtract = ((_useConfig_output = useConfig.output) === null || _useConfig_output === void 0 ? void 0 : _useConfig_output.disableCssExtract) || false;
|
|
83
|
+
if ((_useConfig_deploy = useConfig.deploy) === null || _useConfig_deploy === void 0 ? void 0 : _useConfig_deploy.microFrontend) {
|
|
84
|
+
var _useConfig_deploy1;
|
|
85
|
+
const { enableHtmlEntry } = getDefaultMicroFrontedConfig((_useConfig_deploy1 = useConfig.deploy) === null || _useConfig_deploy1 === void 0 ? void 0 : _useConfig_deploy1.microFrontend);
|
|
86
|
+
if (!enableHtmlEntry) {
|
|
87
|
+
disableCssExtract = true;
|
|
116
88
|
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
output: {
|
|
92
|
+
disableCssExtract
|
|
93
|
+
},
|
|
94
|
+
source: {
|
|
95
|
+
alias: {
|
|
96
|
+
"@modern-js/runtime/plugins": pluginsExportsUtils.getPath(),
|
|
97
|
+
"@modern-js/runtime/garfish": "@modern-js/plugin-garfish/runtime"
|
|
122
98
|
}
|
|
123
99
|
},
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
chain.output.libraryTarget("umd");
|
|
129
|
-
if (!((_b2 = useConfig.dev) == null ? void 0 : _b2.assetPrefix) && ((_c2 = resolveOptions == null ? void 0 : resolveOptions.server) == null ? void 0 : _c2.port) && env === "development") {
|
|
130
|
-
chain.output.publicPath(
|
|
131
|
-
`//localhost:${resolveOptions.server.port}/`
|
|
132
|
-
);
|
|
100
|
+
tools: {
|
|
101
|
+
devServer: {
|
|
102
|
+
headers: {
|
|
103
|
+
"Access-Control-Allow-Origin": "*"
|
|
133
104
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
105
|
+
},
|
|
106
|
+
webpackChain: (chain, { webpack, env, CHAIN_ID }) => {
|
|
107
|
+
var _resolveOptions_deploy, _resolveWebpackConfig_resolve;
|
|
108
|
+
const resolveOptions = useResolvedConfigContext();
|
|
109
|
+
if (resolveOptions === null || resolveOptions === void 0 ? void 0 : (_resolveOptions_deploy = resolveOptions.deploy) === null || _resolveOptions_deploy === void 0 ? void 0 : _resolveOptions_deploy.microFrontend) {
|
|
110
|
+
var _useConfig_dev, _resolveOptions_server, _resolveOptions_deploy1;
|
|
111
|
+
chain.output.libraryTarget("umd");
|
|
112
|
+
if (!((_useConfig_dev = useConfig.dev) === null || _useConfig_dev === void 0 ? void 0 : _useConfig_dev.assetPrefix) && (resolveOptions === null || resolveOptions === void 0 ? void 0 : (_resolveOptions_server = resolveOptions.server) === null || _resolveOptions_server === void 0 ? void 0 : _resolveOptions_server.port) && env === "development") {
|
|
113
|
+
chain.output.publicPath(`//localhost:${resolveOptions.server.port}/`);
|
|
114
|
+
}
|
|
115
|
+
if (webpack.BannerPlugin) {
|
|
116
|
+
chain.plugin(CHAIN_ID.PLUGIN.BANNER).use(webpack.BannerPlugin, [
|
|
117
|
+
{
|
|
118
|
+
banner: "Micro front-end"
|
|
119
|
+
}
|
|
120
|
+
]);
|
|
121
|
+
}
|
|
122
|
+
const { enableHtmlEntry, externalBasicLibrary } = getDefaultMicroFrontedConfig((_resolveOptions_deploy1 = resolveOptions.deploy) === null || _resolveOptions_deploy1 === void 0 ? void 0 : _resolveOptions_deploy1.microFrontend);
|
|
123
|
+
if (externalBasicLibrary) {
|
|
124
|
+
chain.externals(externals);
|
|
125
|
+
}
|
|
126
|
+
if (!enableHtmlEntry) {
|
|
127
|
+
chain.output.filename("index.js");
|
|
128
|
+
chain.plugins.delete(`${CHAIN_ID.PLUGIN.HTML}-main`);
|
|
129
|
+
chain.optimization.runtimeChunk(false);
|
|
130
|
+
chain.optimization.splitChunks({
|
|
131
|
+
chunks: "async"
|
|
132
|
+
});
|
|
133
|
+
}
|
|
150
134
|
}
|
|
135
|
+
const resolveWebpackConfig = chain.toConfig();
|
|
136
|
+
(0, _util.logger)("webpackConfig", {
|
|
137
|
+
output: resolveWebpackConfig.output,
|
|
138
|
+
externals: resolveWebpackConfig.externals,
|
|
139
|
+
env,
|
|
140
|
+
alias: (_resolveWebpackConfig_resolve = resolveWebpackConfig.resolve) === null || _resolveWebpackConfig_resolve === void 0 ? void 0 : _resolveWebpackConfig_resolve.alias,
|
|
141
|
+
plugins: resolveWebpackConfig.plugins
|
|
142
|
+
});
|
|
151
143
|
}
|
|
152
|
-
const resolveWebpackConfig = chain.toConfig();
|
|
153
|
-
(0, import_util.logger)("webpackConfig", {
|
|
154
|
-
output: resolveWebpackConfig.output,
|
|
155
|
-
externals: resolveWebpackConfig.externals,
|
|
156
|
-
env,
|
|
157
|
-
alias: (_e = resolveWebpackConfig.resolve) == null ? void 0 : _e.alias,
|
|
158
|
-
plugins: resolveWebpackConfig.plugins
|
|
159
|
-
});
|
|
160
144
|
}
|
|
145
|
+
};
|
|
146
|
+
},
|
|
147
|
+
addRuntimeExports() {
|
|
148
|
+
const config = useResolvedConfigContext();
|
|
149
|
+
const { masterApp } = (0, _utils1.getRuntimeConfig)(config);
|
|
150
|
+
if (masterApp) {
|
|
151
|
+
const addExportStatement = `export { default as garfish, default as masterApp } from '${pluginName}/runtime'`;
|
|
152
|
+
(0, _util.logger)("exportStatement", addExportStatement);
|
|
153
|
+
pluginsExportsUtils.addExport(addExportStatement);
|
|
154
|
+
}
|
|
155
|
+
const otherExportStatement = `export { hoistNonReactStatics } from '${pluginName}/deps'`;
|
|
156
|
+
(0, _util.logger)("otherExportStatement", otherExportStatement);
|
|
157
|
+
pluginsExportsUtils.addExport(otherExportStatement);
|
|
158
|
+
},
|
|
159
|
+
modifyEntryImports({ entrypoint, imports }) {
|
|
160
|
+
const config = useResolvedConfigContext();
|
|
161
|
+
const { masterApp } = (0, _utils1.getRuntimeConfig)(config);
|
|
162
|
+
if (masterApp) {
|
|
163
|
+
imports.push({
|
|
164
|
+
value: runtimePluginName,
|
|
165
|
+
specifiers: [
|
|
166
|
+
{
|
|
167
|
+
imported: "garfish"
|
|
168
|
+
}
|
|
169
|
+
]
|
|
170
|
+
});
|
|
171
|
+
imports.push({
|
|
172
|
+
value: runtimePluginName,
|
|
173
|
+
specifiers: [
|
|
174
|
+
{
|
|
175
|
+
imported: "masterApp"
|
|
176
|
+
}
|
|
177
|
+
]
|
|
178
|
+
});
|
|
161
179
|
}
|
|
162
|
-
};
|
|
163
|
-
},
|
|
164
|
-
addRuntimeExports() {
|
|
165
|
-
const config = useResolvedConfigContext();
|
|
166
|
-
const { masterApp } = (0, import_utils2.getRuntimeConfig)(config);
|
|
167
|
-
if (masterApp) {
|
|
168
|
-
const addExportStatement = `export { default as garfish, default as masterApp } from '${pluginName}/runtime'`;
|
|
169
|
-
(0, import_util.logger)("exportStatement", addExportStatement);
|
|
170
|
-
pluginsExportsUtils.addExport(addExportStatement);
|
|
171
|
-
}
|
|
172
|
-
const otherExportStatement = `export { hoistNonReactStatics } from '${pluginName}/deps'`;
|
|
173
|
-
(0, import_util.logger)("otherExportStatement", otherExportStatement);
|
|
174
|
-
pluginsExportsUtils.addExport(otherExportStatement);
|
|
175
|
-
},
|
|
176
|
-
modifyEntryImports({ entrypoint, imports }) {
|
|
177
|
-
const config = useResolvedConfigContext();
|
|
178
|
-
const { masterApp } = (0, import_utils2.getRuntimeConfig)(config);
|
|
179
|
-
if (masterApp) {
|
|
180
180
|
imports.push({
|
|
181
181
|
value: runtimePluginName,
|
|
182
182
|
specifiers: [
|
|
183
183
|
{
|
|
184
|
-
imported: "
|
|
184
|
+
imported: "hoistNonReactStatics"
|
|
185
185
|
}
|
|
186
186
|
]
|
|
187
187
|
});
|
|
188
188
|
imports.push({
|
|
189
|
-
value:
|
|
189
|
+
value: "react-dom",
|
|
190
190
|
specifiers: [
|
|
191
191
|
{
|
|
192
|
-
imported: "
|
|
192
|
+
imported: "unmountComponentAtNode"
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
imported: "createPortal"
|
|
193
196
|
}
|
|
194
197
|
]
|
|
195
198
|
});
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
imported: "createPortal"
|
|
213
|
-
}
|
|
214
|
-
]
|
|
215
|
-
});
|
|
216
|
-
return { imports, entrypoint };
|
|
217
|
-
},
|
|
218
|
-
modifyEntryRuntimePlugins({ entrypoint, plugins }) {
|
|
219
|
-
const config = useResolvedConfigContext();
|
|
220
|
-
const { masterApp } = (0, import_utils2.getRuntimeConfig)(config);
|
|
221
|
-
if (masterApp) {
|
|
222
|
-
(0, import_util.logger)("garfishPlugin options", masterApp);
|
|
223
|
-
plugins.push({
|
|
224
|
-
name: "garfish",
|
|
225
|
-
args: "masterApp",
|
|
226
|
-
options: masterApp === true ? JSON.stringify({}) : JSON.stringify(masterApp)
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
return { entrypoint, plugins };
|
|
230
|
-
},
|
|
231
|
-
modifyEntryRenderFunction({ entrypoint, code }) {
|
|
232
|
-
var _a;
|
|
233
|
-
const config = useResolvedConfigContext();
|
|
234
|
-
if (!((_a = config == null ? void 0 : config.deploy) == null ? void 0 : _a.microFrontend)) {
|
|
235
|
-
return { entrypoint, code };
|
|
236
|
-
}
|
|
237
|
-
const nCode = (0, import_utils2.makeRenderFunction)(code);
|
|
238
|
-
(0, import_util.logger)("makeRenderFunction", nCode);
|
|
239
|
-
return {
|
|
240
|
-
entrypoint,
|
|
241
|
-
code: nCode
|
|
242
|
-
};
|
|
243
|
-
},
|
|
244
|
-
modifyAsyncEntry({ entrypoint, code }) {
|
|
245
|
-
var _a, _b;
|
|
246
|
-
const config = useResolvedConfigContext();
|
|
247
|
-
let finalCode = code;
|
|
248
|
-
if (((_a = config == null ? void 0 : config.deploy) == null ? void 0 : _a.microFrontend) && ((_b = config == null ? void 0 : config.source) == null ? void 0 : _b.enableAsyncEntry)) {
|
|
249
|
-
finalCode = (0, import_utils2.generateAsyncEntry)(code);
|
|
199
|
+
return {
|
|
200
|
+
imports,
|
|
201
|
+
entrypoint
|
|
202
|
+
};
|
|
203
|
+
},
|
|
204
|
+
modifyEntryRuntimePlugins({ entrypoint, plugins }) {
|
|
205
|
+
const config = useResolvedConfigContext();
|
|
206
|
+
const { masterApp } = (0, _utils1.getRuntimeConfig)(config);
|
|
207
|
+
if (masterApp) {
|
|
208
|
+
(0, _util.logger)("garfishPlugin options", masterApp);
|
|
209
|
+
plugins.push({
|
|
210
|
+
name: "garfish",
|
|
211
|
+
args: "masterApp",
|
|
212
|
+
options: masterApp === true ? JSON.stringify({}) : JSON.stringify(masterApp)
|
|
213
|
+
});
|
|
214
|
+
}
|
|
250
215
|
return {
|
|
251
216
|
entrypoint,
|
|
252
|
-
|
|
217
|
+
plugins
|
|
253
218
|
};
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
const
|
|
265
|
-
(0,
|
|
219
|
+
},
|
|
220
|
+
modifyEntryRenderFunction({ entrypoint, code }) {
|
|
221
|
+
var _config_deploy;
|
|
222
|
+
const config = useResolvedConfigContext();
|
|
223
|
+
if (!(config === null || config === void 0 ? void 0 : (_config_deploy = config.deploy) === null || _config_deploy === void 0 ? void 0 : _config_deploy.microFrontend)) {
|
|
224
|
+
return {
|
|
225
|
+
entrypoint,
|
|
226
|
+
code
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
const nCode = (0, _utils1.makeRenderFunction)(code);
|
|
230
|
+
(0, _util.logger)("makeRenderFunction", nCode);
|
|
266
231
|
return {
|
|
267
232
|
entrypoint,
|
|
268
|
-
|
|
233
|
+
code: nCode
|
|
234
|
+
};
|
|
235
|
+
},
|
|
236
|
+
modifyAsyncEntry({ entrypoint, code }) {
|
|
237
|
+
var _config_deploy, _config_source;
|
|
238
|
+
const config = useResolvedConfigContext();
|
|
239
|
+
let finalCode = code;
|
|
240
|
+
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)) {
|
|
241
|
+
finalCode = (0, _utils1.generateAsyncEntry)(code);
|
|
242
|
+
return {
|
|
243
|
+
entrypoint,
|
|
244
|
+
code: `${finalCode}`
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
return {
|
|
248
|
+
entrypoint,
|
|
249
|
+
code: finalCode
|
|
250
|
+
};
|
|
251
|
+
},
|
|
252
|
+
modifyEntryExport({ entrypoint, exportStatement }) {
|
|
253
|
+
var _config_deploy;
|
|
254
|
+
const config = useResolvedConfigContext();
|
|
255
|
+
if (config === null || config === void 0 ? void 0 : (_config_deploy = config.deploy) === null || _config_deploy === void 0 ? void 0 : _config_deploy.microFrontend) {
|
|
256
|
+
const exportStatementCode = (0, _utils1.makeProvider)();
|
|
257
|
+
(0, _util.logger)("exportStatement", exportStatementCode);
|
|
258
|
+
return {
|
|
259
|
+
entrypoint,
|
|
260
|
+
exportStatement: exportStatementCode
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
return {
|
|
264
|
+
entrypoint,
|
|
265
|
+
exportStatement
|
|
269
266
|
};
|
|
270
267
|
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
}
|
|
276
|
-
};
|
|
277
|
-
}
|
|
278
|
-
});
|
|
279
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
280
|
-
0 && (module.exports = {
|
|
281
|
-
externals,
|
|
282
|
-
getDefaultMicroFrontedConfig
|
|
283
|
-
});
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
};
|
package/dist/cjs/cli/utils.js
CHANGED
|
@@ -1,29 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
6
|
for (var name in all)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var utils_exports = {};
|
|
19
|
-
__export(utils_exports, {
|
|
20
|
-
generateAsyncEntry: () => generateAsyncEntry,
|
|
21
|
-
getRuntimeConfig: () => getRuntimeConfig,
|
|
7
|
+
Object.defineProperty(target, name, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: all[name]
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
_export(exports, {
|
|
22
13
|
makeProvider: () => makeProvider,
|
|
23
14
|
makeRenderFunction: () => makeRenderFunction,
|
|
24
|
-
|
|
15
|
+
getRuntimeConfig: () => getRuntimeConfig,
|
|
16
|
+
setRuntimeConfig: () => setRuntimeConfig,
|
|
17
|
+
generateAsyncEntry: () => generateAsyncEntry
|
|
25
18
|
});
|
|
26
|
-
module.exports = __toCommonJS(utils_exports);
|
|
27
19
|
const makeProvider = () => `
|
|
28
20
|
export const provider = function ({basename, dom}) {
|
|
29
21
|
return {
|
|
@@ -110,38 +102,30 @@ const makeRenderFunction = (code) => {
|
|
|
110
102
|
let mountNode = rootDomInfo.mountNode;
|
|
111
103
|
props = rootDomInfo.props;
|
|
112
104
|
`;
|
|
113
|
-
return inGarfishToRender + code.replace(`router(`, `generateRouterPlugin(basename,`).replace(/MOUNT_ID/g, "mountNode").replace(`createApp({`, "createApp({ props,").replace(
|
|
114
|
-
`bootstrap(AppWrapper, mountNode, root`,
|
|
115
|
-
"bootstrap(AppWrapper, mountNode, root = IS_REACT18 ? ReactDOM.createRoot(mountNode) : null"
|
|
116
|
-
).replace(
|
|
117
|
-
`customBootstrap(AppWrapper`,
|
|
118
|
-
"customBootstrap(AppWrapper, mountNode"
|
|
119
|
-
);
|
|
105
|
+
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");
|
|
120
106
|
};
|
|
121
107
|
function getRuntimeConfig(config) {
|
|
122
|
-
var
|
|
123
|
-
if (
|
|
124
|
-
|
|
108
|
+
var _config_runtime;
|
|
109
|
+
if (config === null || config === void 0 ? void 0 : (_config_runtime = config.runtime) === null || _config_runtime === void 0 ? void 0 : _config_runtime.features) {
|
|
110
|
+
var _config_runtime1;
|
|
111
|
+
return config === null || config === void 0 ? void 0 : (_config_runtime1 = config.runtime) === null || _config_runtime1 === void 0 ? void 0 : _config_runtime1.features;
|
|
125
112
|
}
|
|
126
|
-
return (config
|
|
113
|
+
return (config === null || config === void 0 ? void 0 : config.runtime) || {};
|
|
127
114
|
}
|
|
128
115
|
function setRuntimeConfig(config, key, value) {
|
|
129
|
-
var
|
|
130
|
-
if ((
|
|
116
|
+
var _config_runtime, _config_runtime1;
|
|
117
|
+
if ((config === null || config === void 0 ? void 0 : (_config_runtime = config.runtime) === null || _config_runtime === void 0 ? void 0 : _config_runtime.features) && (config === null || config === void 0 ? void 0 : (_config_runtime1 = config.runtime) === null || _config_runtime1 === void 0 ? void 0 : _config_runtime1.features[key])) {
|
|
131
118
|
config.runtime.features[key] = value;
|
|
132
119
|
return void 0;
|
|
133
120
|
}
|
|
134
|
-
if ((config
|
|
121
|
+
if ((config === null || config === void 0 ? void 0 : config.runtime) && (config === null || config === void 0 ? void 0 : config.runtime[key])) {
|
|
135
122
|
config.runtime[key] = value;
|
|
136
123
|
return void 0;
|
|
137
124
|
}
|
|
138
125
|
return void 0;
|
|
139
126
|
}
|
|
140
127
|
const generateAsyncEntry = (code) => {
|
|
141
|
-
const transformCode = code.replace(
|
|
142
|
-
`import('./bootstrap.js');`,
|
|
143
|
-
`if (!window.__GARFISH__) { import('./bootstrap.js'); }`
|
|
144
|
-
);
|
|
128
|
+
const transformCode = code.replace(`import('./bootstrap.js');`, `if (!window.__GARFISH__) { import('./bootstrap.js'); }`);
|
|
145
129
|
return `
|
|
146
130
|
export const provider = async (...args) => {
|
|
147
131
|
const exports = await import('./bootstrap');
|
|
@@ -153,11 +137,3 @@ const generateAsyncEntry = (code) => {
|
|
|
153
137
|
}
|
|
154
138
|
`;
|
|
155
139
|
};
|
|
156
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
157
|
-
0 && (module.exports = {
|
|
158
|
-
generateAsyncEntry,
|
|
159
|
-
getRuntimeConfig,
|
|
160
|
-
makeProvider,
|
|
161
|
-
makeRenderFunction,
|
|
162
|
-
setRuntimeConfig
|
|
163
|
-
});
|