@modern-js/plugin-garfish 2.0.0-beta.0 → 2.0.0-beta.2
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 +83 -0
- package/dist/js/modern/cli/index.js +35 -48
- package/dist/js/modern/cli/utils.js +15 -9
- package/dist/js/modern/runtime/loadable.js +3 -17
- package/dist/js/modern/runtime/plugin.js +11 -33
- package/dist/js/modern/runtime/useModuleApps.js +0 -5
- package/dist/js/modern/runtime/utils/MApp.js +9 -42
- package/dist/js/modern/runtime/utils/apps.js +12 -41
- package/dist/js/node/cli/index.js +34 -56
- package/dist/js/node/cli/utils.js +17 -15
- package/dist/js/node/index.js +0 -4
- package/dist/js/node/runtime/index.js +0 -5
- package/dist/js/node/runtime/loadable.js +3 -22
- package/dist/js/node/runtime/plugin.js +11 -47
- package/dist/js/node/runtime/useModuleApps.js +0 -12
- package/dist/js/node/runtime/utils/Context.js +0 -4
- package/dist/js/node/runtime/utils/MApp.js +7 -49
- package/dist/js/node/runtime/utils/apps.js +8 -46
- package/dist/js/node/runtime/utils/setExternal.js +0 -9
- package/dist/js/node/util.js +1 -4
- package/dist/js/treeshaking/cli/index.js +54 -64
- package/dist/js/treeshaking/cli/utils.js +9 -9
- package/dist/js/treeshaking/runtime/loadable.js +29 -39
- package/dist/js/treeshaking/runtime/plugin.js +9 -42
- package/dist/js/treeshaking/runtime/useModuleApps.js +4 -7
- package/dist/js/treeshaking/runtime/utils/MApp.js +13 -46
- package/dist/js/treeshaking/runtime/utils/apps.js +16 -56
- package/dist/types/cli/index.d.ts +4 -9
- package/dist/types/cli/utils.d.ts +4 -3
- package/dist/types/runtime/plugin.d.ts +0 -2
- package/dist/types/runtime/utils/setExternal.d.ts +0 -1
- package/package.json +15 -14
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,88 @@
|
|
|
1
1
|
# @modern-js/plugin-garfish
|
|
2
2
|
|
|
3
|
+
## 2.0.0-beta.2
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- dda38c9c3e: chore: v2
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- 21d2ddb: feat: support async export provider for module federation
|
|
12
|
+
支持模块联邦场景异步导出 provider
|
|
13
|
+
- 2344eb2: fix: loadApp when dom is mount
|
|
14
|
+
修复 dom 未渲染时挂载子应用行为
|
|
15
|
+
- Updated dependencies [2344eb2]
|
|
16
|
+
- Updated dependencies [a11fcf8]
|
|
17
|
+
- Updated dependencies [b18fa8f3ed]
|
|
18
|
+
- Updated dependencies [c9e800d39a]
|
|
19
|
+
- Updated dependencies [3e57f2b]
|
|
20
|
+
- Updated dependencies [fbf5eed]
|
|
21
|
+
- Updated dependencies [a2509bfbdb]
|
|
22
|
+
- Updated dependencies [e4357f1]
|
|
23
|
+
- Updated dependencies [4369648ae2]
|
|
24
|
+
- Updated dependencies [92f0ead]
|
|
25
|
+
- Updated dependencies [92c0994]
|
|
26
|
+
- Updated dependencies [edd1cfb1af]
|
|
27
|
+
- Updated dependencies [cc971eabfc]
|
|
28
|
+
- Updated dependencies [5b9049f2e9]
|
|
29
|
+
- Updated dependencies [6bda14ed71]
|
|
30
|
+
- Updated dependencies [92004d1]
|
|
31
|
+
- Updated dependencies [b8bbe036c7]
|
|
32
|
+
- Updated dependencies [40ed587]
|
|
33
|
+
- Updated dependencies [60d5378632]
|
|
34
|
+
- Updated dependencies [d5a31df781]
|
|
35
|
+
- Updated dependencies [dda38c9c3e]
|
|
36
|
+
- Updated dependencies [8b8e1bb571]
|
|
37
|
+
- Updated dependencies [3bbea92b2a]
|
|
38
|
+
- Updated dependencies [18aaf42]
|
|
39
|
+
- Updated dependencies [fcace5b5b9]
|
|
40
|
+
- Updated dependencies [abf3421a75]
|
|
41
|
+
- Updated dependencies [543be9558e]
|
|
42
|
+
- Updated dependencies [14b712da84]
|
|
43
|
+
- @modern-js/runtime@2.0.0-beta.2
|
|
44
|
+
- @modern-js/utils@2.0.0-beta.2
|
|
45
|
+
|
|
46
|
+
## 2.0.0-beta.1
|
|
47
|
+
|
|
48
|
+
### Major Changes
|
|
49
|
+
|
|
50
|
+
- dda38c9: chore: v2
|
|
51
|
+
|
|
52
|
+
### Patch Changes
|
|
53
|
+
|
|
54
|
+
- 2344eb2: fix: loadApp when dom is mount
|
|
55
|
+
修复 dom 未渲染时挂载子应用行为
|
|
56
|
+
- Updated dependencies [2344eb2]
|
|
57
|
+
- Updated dependencies [a11fcf8]
|
|
58
|
+
- Updated dependencies [b18fa8f]
|
|
59
|
+
- Updated dependencies [c9e800d39a]
|
|
60
|
+
- Updated dependencies [3e57f2b]
|
|
61
|
+
- Updated dependencies [fbf5eed]
|
|
62
|
+
- Updated dependencies [a2509bfbdb]
|
|
63
|
+
- Updated dependencies [4369648ae2]
|
|
64
|
+
- Updated dependencies [92f0ead]
|
|
65
|
+
- Updated dependencies [92c0994]
|
|
66
|
+
- Updated dependencies [edd1cfb1af]
|
|
67
|
+
- Updated dependencies [cc971eabfc]
|
|
68
|
+
- Updated dependencies [5b9049f]
|
|
69
|
+
- Updated dependencies [6bda14ed71]
|
|
70
|
+
- Updated dependencies [92004d1]
|
|
71
|
+
- Updated dependencies [b8bbe036c7]
|
|
72
|
+
- Updated dependencies [40ed587]
|
|
73
|
+
- Updated dependencies [60d5378632]
|
|
74
|
+
- Updated dependencies [d5a31df781]
|
|
75
|
+
- Updated dependencies [dda38c9]
|
|
76
|
+
- Updated dependencies [8b8e1bb571]
|
|
77
|
+
- Updated dependencies [3bbea92b2a]
|
|
78
|
+
- Updated dependencies [18aaf42]
|
|
79
|
+
- Updated dependencies [fcace5b5b9]
|
|
80
|
+
- Updated dependencies [abf3421]
|
|
81
|
+
- Updated dependencies [543be9558e]
|
|
82
|
+
- Updated dependencies [14b712d]
|
|
83
|
+
- @modern-js/runtime@2.0.0-beta.1
|
|
84
|
+
- @modern-js/utils@2.0.0-beta.1
|
|
85
|
+
|
|
3
86
|
## 2.0.0-beta.0
|
|
4
87
|
|
|
5
88
|
### Major Changes
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
2
|
-
|
|
3
2
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
-
|
|
5
3
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
-
|
|
7
4
|
import path from 'path';
|
|
8
5
|
import { createRuntimeExportsUtils, PLUGIN_SCHEMAS } from '@modern-js/utils';
|
|
9
6
|
import { logger } from "../util";
|
|
10
|
-
import { getRuntimeConfig, makeProvider, makeRenderFunction, setRuntimeConfig } from "./utils";
|
|
7
|
+
import { getRuntimeConfig, makeProvider, makeRenderFunction, setRuntimeConfig, generateAsyncEntry } from "./utils";
|
|
11
8
|
export const externals = {
|
|
12
9
|
'react-dom': 'react-dom',
|
|
13
10
|
react: 'react'
|
|
@@ -20,7 +17,6 @@ export function getDefaultMicroFrontedConfig(microFrontend) {
|
|
|
20
17
|
moduleApp: ''
|
|
21
18
|
};
|
|
22
19
|
}
|
|
23
|
-
|
|
24
20
|
return _objectSpread({
|
|
25
21
|
enableHtmlEntry: true,
|
|
26
22
|
externalBasicLibrary: false
|
|
@@ -43,7 +39,6 @@ export default (({
|
|
|
43
39
|
validateSchema() {
|
|
44
40
|
return PLUGIN_SCHEMAS['@modern-js/plugin-garfish'];
|
|
45
41
|
},
|
|
46
|
-
|
|
47
42
|
resolvedConfig: async config => {
|
|
48
43
|
const {
|
|
49
44
|
resolved
|
|
@@ -55,16 +50,13 @@ export default (({
|
|
|
55
50
|
const nConfig = {
|
|
56
51
|
resolved: _objectSpread({}, resolved)
|
|
57
52
|
};
|
|
58
|
-
|
|
59
53
|
if (masterApp) {
|
|
60
54
|
var _router$historyOption;
|
|
61
|
-
|
|
62
55
|
// basename does not exist use router's basename
|
|
63
56
|
setRuntimeConfig(nConfig.resolved, 'masterApp', Object.assign(typeof masterApp === 'object' ? _objectSpread({}, masterApp) : {}, {
|
|
64
57
|
basename: (router === null || router === void 0 ? void 0 : (_router$historyOption = router.historyOptions) === null || _router$historyOption === void 0 ? void 0 : _router$historyOption.basename) || (router === null || router === void 0 ? void 0 : router.basename) || '/'
|
|
65
58
|
}));
|
|
66
59
|
}
|
|
67
|
-
|
|
68
60
|
logger(`resolvedConfig`, {
|
|
69
61
|
output: nConfig.resolved.output,
|
|
70
62
|
runtime: nConfig.resolved.runtime,
|
|
@@ -73,31 +65,29 @@ export default (({
|
|
|
73
65
|
});
|
|
74
66
|
return nConfig;
|
|
75
67
|
},
|
|
76
|
-
|
|
77
68
|
config() {
|
|
78
|
-
var _useConfig$output
|
|
79
|
-
|
|
69
|
+
var _useConfig$output, _useConfig$deploy;
|
|
80
70
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
81
71
|
const useConfig = useConfigContext();
|
|
82
|
-
logger('useConfig', useConfig);
|
|
72
|
+
logger('useConfig', useConfig);
|
|
83
73
|
|
|
74
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
84
75
|
const config = useAppContext();
|
|
85
76
|
pluginsExportsUtils = createRuntimeExportsUtils(config.internalDirectory, 'plugins');
|
|
86
77
|
runtimeExportsUtils = createRuntimeExportsUtils(config.internalDirectory, 'index');
|
|
87
|
-
let disableCssExtract = (
|
|
78
|
+
let disableCssExtract = ((_useConfig$output = useConfig.output) === null || _useConfig$output === void 0 ? void 0 : _useConfig$output.disableCssExtract) || false;
|
|
88
79
|
|
|
80
|
+
// When the micro-frontend application js entry, there is no need to extract css, close cssExtract
|
|
89
81
|
if ((_useConfig$deploy = useConfig.deploy) !== null && _useConfig$deploy !== void 0 && _useConfig$deploy.microFrontend) {
|
|
90
82
|
var _useConfig$deploy2;
|
|
91
|
-
|
|
92
83
|
const {
|
|
93
84
|
enableHtmlEntry
|
|
94
85
|
} = getDefaultMicroFrontedConfig((_useConfig$deploy2 = useConfig.deploy) === null || _useConfig$deploy2 === void 0 ? void 0 : _useConfig$deploy2.microFrontend);
|
|
95
|
-
|
|
96
86
|
if (!enableHtmlEntry) {
|
|
87
|
+
// FIXME: the handle the `disableCssExtract` config
|
|
97
88
|
disableCssExtract = true;
|
|
98
89
|
}
|
|
99
90
|
}
|
|
100
|
-
|
|
101
91
|
return {
|
|
102
92
|
output: {
|
|
103
93
|
disableCssExtract
|
|
@@ -120,36 +110,30 @@ export default (({
|
|
|
120
110
|
CHAIN_ID
|
|
121
111
|
}) => {
|
|
122
112
|
var _resolveOptions$deplo, _resolveWebpackConfig;
|
|
123
|
-
|
|
124
113
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
125
114
|
const resolveOptions = useResolvedConfigContext();
|
|
126
|
-
|
|
127
115
|
if (resolveOptions !== null && resolveOptions !== void 0 && (_resolveOptions$deplo = resolveOptions.deploy) !== null && _resolveOptions$deplo !== void 0 && _resolveOptions$deplo.microFrontend) {
|
|
128
116
|
var _resolveOptions$serve, _resolveOptions$deplo2;
|
|
129
|
-
|
|
130
117
|
chain.output.libraryTarget('umd');
|
|
131
|
-
|
|
132
118
|
if (resolveOptions !== null && resolveOptions !== void 0 && (_resolveOptions$serve = resolveOptions.server) !== null && _resolveOptions$serve !== void 0 && _resolveOptions$serve.port && _env === 'development') {
|
|
133
119
|
chain.output.publicPath(`//localhost:${resolveOptions.server.port}/`);
|
|
134
|
-
}
|
|
135
|
-
|
|
120
|
+
}
|
|
136
121
|
|
|
122
|
+
// add comments avoid sourcemap abnormal
|
|
137
123
|
if (webpack.BannerPlugin) {
|
|
138
124
|
chain.plugin(CHAIN_ID.PLUGIN.BANNER).use(webpack.BannerPlugin, [{
|
|
139
125
|
banner: 'Micro front-end'
|
|
140
126
|
}]);
|
|
141
127
|
}
|
|
142
|
-
|
|
143
128
|
const {
|
|
144
129
|
enableHtmlEntry,
|
|
145
130
|
externalBasicLibrary
|
|
146
|
-
} = getDefaultMicroFrontedConfig((_resolveOptions$deplo2 = resolveOptions.deploy) === null || _resolveOptions$deplo2 === void 0 ? void 0 : _resolveOptions$deplo2.microFrontend);
|
|
147
|
-
|
|
131
|
+
} = getDefaultMicroFrontedConfig((_resolveOptions$deplo2 = resolveOptions.deploy) === null || _resolveOptions$deplo2 === void 0 ? void 0 : _resolveOptions$deplo2.microFrontend);
|
|
132
|
+
// external
|
|
148
133
|
if (externalBasicLibrary) {
|
|
149
134
|
chain.externals(externals);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
|
|
135
|
+
}
|
|
136
|
+
// use html mode
|
|
153
137
|
if (!enableHtmlEntry) {
|
|
154
138
|
chain.output.filename('index.js');
|
|
155
139
|
chain.plugins.delete(`${CHAIN_ID.PLUGIN.HTML}-main`);
|
|
@@ -159,7 +143,6 @@ export default (({
|
|
|
159
143
|
});
|
|
160
144
|
}
|
|
161
145
|
}
|
|
162
|
-
|
|
163
146
|
const resolveWebpackConfig = chain.toConfig();
|
|
164
147
|
logger('webpackConfig', {
|
|
165
148
|
output: resolveWebpackConfig.output,
|
|
@@ -172,14 +155,12 @@ export default (({
|
|
|
172
155
|
}
|
|
173
156
|
};
|
|
174
157
|
},
|
|
175
|
-
|
|
176
158
|
addRuntimeExports() {
|
|
177
159
|
const addExportStatement = `export { default as garfish, default as masterApp, hoistNonReactStatics } from '${_pluginName}'`;
|
|
178
160
|
logger('exportStatement', addExportStatement);
|
|
179
161
|
pluginsExportsUtils.addExport(addExportStatement);
|
|
180
162
|
runtimeExportsUtils.addExport(`export * from '${_mfPackagePath}'`);
|
|
181
163
|
},
|
|
182
|
-
|
|
183
164
|
modifyEntryImports({
|
|
184
165
|
entrypoint,
|
|
185
166
|
imports
|
|
@@ -189,7 +170,6 @@ export default (({
|
|
|
189
170
|
const {
|
|
190
171
|
masterApp
|
|
191
172
|
} = getRuntimeConfig(config);
|
|
192
|
-
|
|
193
173
|
if (masterApp) {
|
|
194
174
|
imports.push({
|
|
195
175
|
value: _runtimePluginName,
|
|
@@ -204,7 +184,6 @@ export default (({
|
|
|
204
184
|
}]
|
|
205
185
|
});
|
|
206
186
|
}
|
|
207
|
-
|
|
208
187
|
imports.push({
|
|
209
188
|
value: _runtimePluginName,
|
|
210
189
|
specifiers: [{
|
|
@@ -224,7 +203,6 @@ export default (({
|
|
|
224
203
|
entrypoint
|
|
225
204
|
};
|
|
226
205
|
},
|
|
227
|
-
|
|
228
206
|
modifyEntryRuntimePlugins({
|
|
229
207
|
entrypoint,
|
|
230
208
|
plugins
|
|
@@ -234,7 +212,6 @@ export default (({
|
|
|
234
212
|
const {
|
|
235
213
|
masterApp
|
|
236
214
|
} = getRuntimeConfig(config);
|
|
237
|
-
|
|
238
215
|
if (masterApp) {
|
|
239
216
|
logger('garfishPlugin options', masterApp);
|
|
240
217
|
plugins.push({
|
|
@@ -243,29 +220,24 @@ export default (({
|
|
|
243
220
|
options: masterApp === true ? JSON.stringify({}) : JSON.stringify(masterApp)
|
|
244
221
|
});
|
|
245
222
|
}
|
|
246
|
-
|
|
247
223
|
return {
|
|
248
224
|
entrypoint,
|
|
249
225
|
plugins
|
|
250
226
|
};
|
|
251
227
|
},
|
|
252
|
-
|
|
253
228
|
modifyEntryRenderFunction({
|
|
254
229
|
entrypoint,
|
|
255
230
|
code
|
|
256
231
|
}) {
|
|
257
232
|
var _config$deploy;
|
|
258
|
-
|
|
259
233
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
260
234
|
const config = useResolvedConfigContext();
|
|
261
|
-
|
|
262
235
|
if (!(config !== null && config !== void 0 && (_config$deploy = config.deploy) !== null && _config$deploy !== void 0 && _config$deploy.microFrontend)) {
|
|
263
236
|
return {
|
|
264
237
|
entrypoint,
|
|
265
238
|
code
|
|
266
239
|
};
|
|
267
240
|
}
|
|
268
|
-
|
|
269
241
|
const nCode = makeRenderFunction(code);
|
|
270
242
|
logger('makeRenderFunction', nCode);
|
|
271
243
|
return {
|
|
@@ -273,17 +245,34 @@ export default (({
|
|
|
273
245
|
code: nCode
|
|
274
246
|
};
|
|
275
247
|
},
|
|
276
|
-
|
|
248
|
+
modifyAsyncEntry({
|
|
249
|
+
entrypoint,
|
|
250
|
+
code
|
|
251
|
+
}) {
|
|
252
|
+
var _config$deploy2, _config$source;
|
|
253
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
254
|
+
const config = useResolvedConfigContext();
|
|
255
|
+
let finalCode = code;
|
|
256
|
+
if (config !== null && config !== void 0 && (_config$deploy2 = config.deploy) !== null && _config$deploy2 !== void 0 && _config$deploy2.microFrontend && config !== null && config !== void 0 && (_config$source = config.source) !== null && _config$source !== void 0 && _config$source.enableAsyncEntry) {
|
|
257
|
+
finalCode = generateAsyncEntry(code);
|
|
258
|
+
return {
|
|
259
|
+
entrypoint,
|
|
260
|
+
code: `${finalCode}`
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
return {
|
|
264
|
+
entrypoint,
|
|
265
|
+
code: finalCode
|
|
266
|
+
};
|
|
267
|
+
},
|
|
277
268
|
modifyEntryExport({
|
|
278
269
|
entrypoint,
|
|
279
270
|
exportStatement
|
|
280
271
|
}) {
|
|
281
|
-
var _config$
|
|
282
|
-
|
|
272
|
+
var _config$deploy3;
|
|
283
273
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
284
274
|
const config = useResolvedConfigContext();
|
|
285
|
-
|
|
286
|
-
if (config !== null && config !== void 0 && (_config$deploy2 = config.deploy) !== null && _config$deploy2 !== void 0 && _config$deploy2.microFrontend) {
|
|
275
|
+
if (config !== null && config !== void 0 && (_config$deploy3 = config.deploy) !== null && _config$deploy3 !== void 0 && _config$deploy3.microFrontend) {
|
|
287
276
|
const exportStatementCode = makeProvider();
|
|
288
277
|
logger('exportStatement', exportStatementCode);
|
|
289
278
|
return {
|
|
@@ -291,13 +280,11 @@ export default (({
|
|
|
291
280
|
exportStatement: exportStatementCode
|
|
292
281
|
};
|
|
293
282
|
}
|
|
294
|
-
|
|
295
283
|
return {
|
|
296
284
|
entrypoint,
|
|
297
285
|
exportStatement
|
|
298
286
|
};
|
|
299
287
|
}
|
|
300
|
-
|
|
301
288
|
};
|
|
302
289
|
}
|
|
303
290
|
}));
|
|
@@ -86,32 +86,38 @@ export const makeRenderFunction = code => {
|
|
|
86
86
|
let { AppWrapper, mountNode } = generateAppWrapperAndRootDom({App, props, dom});
|
|
87
87
|
`;
|
|
88
88
|
return inGarfishToRender + code.replace(`router(`, `generateRouterPlugin(basename,`).replace('(App)', `(AppWrapper)`).replace(/MOUNT_ID/g, 'mountNode').replace(`bootstrap(AppWrapper, mountNode, root`, 'bootstrap(AppWrapper, mountNode, root = IS_REACT18 ? ReactDOM.createRoot(mountNode) : null');
|
|
89
|
-
};
|
|
89
|
+
};
|
|
90
90
|
|
|
91
|
+
// support legacy config
|
|
91
92
|
export function getRuntimeConfig(config) {
|
|
92
93
|
var _config$runtime;
|
|
93
|
-
|
|
94
94
|
if (config !== null && config !== void 0 && (_config$runtime = config.runtime) !== null && _config$runtime !== void 0 && _config$runtime.features) {
|
|
95
95
|
var _config$runtime2;
|
|
96
|
-
|
|
97
96
|
return config === null || config === void 0 ? void 0 : (_config$runtime2 = config.runtime) === null || _config$runtime2 === void 0 ? void 0 : _config$runtime2.features;
|
|
98
97
|
}
|
|
99
|
-
|
|
100
98
|
return (config === null || config === void 0 ? void 0 : config.runtime) || {};
|
|
101
|
-
}
|
|
99
|
+
}
|
|
102
100
|
|
|
101
|
+
// support legacy config
|
|
103
102
|
export function setRuntimeConfig(config, key, value) {
|
|
104
103
|
var _config$runtime3, _config$runtime4;
|
|
105
|
-
|
|
106
104
|
if (config !== null && config !== void 0 && (_config$runtime3 = config.runtime) !== null && _config$runtime3 !== void 0 && _config$runtime3.features && config !== null && config !== void 0 && (_config$runtime4 = config.runtime) !== null && _config$runtime4 !== void 0 && _config$runtime4.features[key]) {
|
|
107
105
|
config.runtime.features[key] = value;
|
|
108
106
|
return undefined;
|
|
109
107
|
}
|
|
110
|
-
|
|
111
108
|
if (config !== null && config !== void 0 && config.runtime && config !== null && config !== void 0 && config.runtime[key]) {
|
|
112
109
|
config.runtime[key] = value;
|
|
113
110
|
return undefined;
|
|
114
111
|
}
|
|
115
|
-
|
|
116
112
|
return undefined;
|
|
117
|
-
}
|
|
113
|
+
}
|
|
114
|
+
export const generateAsyncEntry = code => {
|
|
115
|
+
const transformCode = code.replace(`import('./bootstrap.js');`, `if (!window.__GARFISH__) { import('./bootstrap.js'); }`);
|
|
116
|
+
return `
|
|
117
|
+
export const provider = async (...args) => {
|
|
118
|
+
const exports = await import('./bootstrap');
|
|
119
|
+
return exports.provider.apply(null, args);
|
|
120
|
+
};
|
|
121
|
+
${transformCode}
|
|
122
|
+
`;
|
|
123
|
+
};
|
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
const _excluded = ["loadable"];
|
|
2
|
-
|
|
3
2
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
4
|
-
|
|
5
3
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
6
|
-
|
|
7
4
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
8
|
-
|
|
9
5
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
10
|
-
|
|
11
6
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
12
|
-
|
|
13
7
|
// logical reference to https://github.com/jamiebuilds/react-loadable/blob/6201c5837b212d6244c57f3748f2b1375096beeb/src/index.js
|
|
14
8
|
import { useState, useEffect, useCallback } from 'react';
|
|
15
9
|
import { logger } from "../util";
|
|
@@ -25,12 +19,10 @@ export function Loadable(WrapComponent) {
|
|
|
25
19
|
return function (defaultLoadable) {
|
|
26
20
|
return function Lodable(props) {
|
|
27
21
|
var _props$loadable;
|
|
28
|
-
|
|
29
22
|
const {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
23
|
+
loadable = defaultLoadable !== null && defaultLoadable !== void 0 ? defaultLoadable : DEFAULT_LOADABLE
|
|
24
|
+
} = props,
|
|
25
|
+
otherProps = _objectWithoutProperties(props, _excluded);
|
|
34
26
|
let delayTimer = null;
|
|
35
27
|
let timeoutTimer = null;
|
|
36
28
|
const [state, setState] = useState(() => {
|
|
@@ -44,7 +36,6 @@ export function Loadable(WrapComponent) {
|
|
|
44
36
|
timedOut: false,
|
|
45
37
|
isLoading: false
|
|
46
38
|
};
|
|
47
|
-
|
|
48
39
|
if (typeof delay === 'number') {
|
|
49
40
|
if (delay === 0) {
|
|
50
41
|
initState.pastDelay = true;
|
|
@@ -56,7 +47,6 @@ export function Loadable(WrapComponent) {
|
|
|
56
47
|
}, delay);
|
|
57
48
|
}
|
|
58
49
|
}
|
|
59
|
-
|
|
60
50
|
if (typeof timeout === 'number') {
|
|
61
51
|
timeoutTimer = setTimeout(() => {
|
|
62
52
|
setStateWithMountCheck({
|
|
@@ -64,7 +54,6 @@ export function Loadable(WrapComponent) {
|
|
|
64
54
|
});
|
|
65
55
|
}, timeout);
|
|
66
56
|
}
|
|
67
|
-
|
|
68
57
|
return initState;
|
|
69
58
|
});
|
|
70
59
|
const LoadingComponent = (_props$loadable = props.loadable) === null || _props$loadable === void 0 ? void 0 : _props$loadable.loading;
|
|
@@ -80,12 +69,10 @@ export function Loadable(WrapComponent) {
|
|
|
80
69
|
isLoading: false,
|
|
81
70
|
error: null
|
|
82
71
|
});
|
|
83
|
-
|
|
84
72
|
if (delayTimer) {
|
|
85
73
|
clearTimeout(delayTimer);
|
|
86
74
|
delayTimer = null;
|
|
87
75
|
}
|
|
88
|
-
|
|
89
76
|
if (timeoutTimer) {
|
|
90
77
|
clearTimeout(timeoutTimer);
|
|
91
78
|
timeoutTimer = null;
|
|
@@ -119,7 +106,6 @@ export function Loadable(WrapComponent) {
|
|
|
119
106
|
if (props.error && !LoadingComponent) {
|
|
120
107
|
throw props.error;
|
|
121
108
|
}
|
|
122
|
-
|
|
123
109
|
setStateWithMountCheck(props);
|
|
124
110
|
}
|
|
125
111
|
}, otherProps))]
|
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
const _excluded = ["manifest"];
|
|
2
|
-
|
|
3
2
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
4
|
-
|
|
5
3
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
6
|
-
|
|
7
4
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
8
|
-
|
|
9
5
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
10
|
-
|
|
11
6
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
12
|
-
|
|
13
7
|
import GarfishInstance from 'garfish';
|
|
14
8
|
import React from 'react';
|
|
15
9
|
import hoistNonReactStatics from 'hoist-non-react-statics';
|
|
@@ -19,55 +13,47 @@ import setExternal from "./utils/setExternal";
|
|
|
19
13
|
import { generateMApp } from "./utils/MApp";
|
|
20
14
|
import { generateApps } from "./utils/apps";
|
|
21
15
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
22
|
-
|
|
23
16
|
async function initOptions(manifest = {}, options) {
|
|
24
17
|
var _window, _window$modern_manife, _window2, _window2$modern_manif;
|
|
18
|
+
let apps = options.apps || [];
|
|
25
19
|
|
|
26
|
-
|
|
27
|
-
|
|
20
|
+
// use manifest modules
|
|
28
21
|
if (manifest !== null && manifest !== void 0 && manifest.modules) {
|
|
29
22
|
if ((manifest === null || manifest === void 0 ? void 0 : manifest.modules.length) > 0) {
|
|
30
23
|
apps = manifest === null || manifest === void 0 ? void 0 : manifest.modules;
|
|
31
24
|
}
|
|
32
|
-
|
|
33
25
|
logger('manifest modules', apps);
|
|
34
|
-
}
|
|
35
|
-
|
|
26
|
+
}
|
|
36
27
|
|
|
28
|
+
// get module list
|
|
37
29
|
if (manifest !== null && manifest !== void 0 && manifest.getAppList) {
|
|
38
30
|
const getAppList = await (manifest === null || manifest === void 0 ? void 0 : manifest.getAppList(manifest));
|
|
39
|
-
|
|
40
31
|
if (getAppList.length > 0) {
|
|
41
32
|
apps = getAppList;
|
|
42
33
|
}
|
|
43
|
-
|
|
44
34
|
logger('getAppList modules', apps);
|
|
45
|
-
}
|
|
46
|
-
|
|
35
|
+
}
|
|
47
36
|
|
|
37
|
+
// get inject modules list
|
|
48
38
|
if ((_window = window) !== null && _window !== void 0 && (_window$modern_manife = _window.modern_manifest) !== null && _window$modern_manife !== void 0 && _window$modern_manife.modules && ((_window2 = window) === null || _window2 === void 0 ? void 0 : (_window2$modern_manif = _window2.modern_manifest) === null || _window2$modern_manif === void 0 ? void 0 : _window2$modern_manif.modules.length) > 0) {
|
|
49
39
|
var _window3, _window3$modern_manif;
|
|
50
|
-
|
|
51
40
|
apps = (_window3 = window) === null || _window3 === void 0 ? void 0 : (_window3$modern_manif = _window3.modern_manifest) === null || _window3$modern_manif === void 0 ? void 0 : _window3$modern_manif.modules;
|
|
52
41
|
logger('modern_manifest', apps);
|
|
53
42
|
}
|
|
54
|
-
|
|
55
43
|
return _objectSpread(_objectSpread({}, options), {}, {
|
|
56
44
|
apps
|
|
57
45
|
});
|
|
58
|
-
}
|
|
59
|
-
|
|
46
|
+
}
|
|
60
47
|
|
|
48
|
+
// export default GarfishPlugin;
|
|
61
49
|
export default (config => ({
|
|
62
50
|
name: '@modern-js/garfish-plugin',
|
|
63
51
|
setup: () => {
|
|
64
52
|
setExternal();
|
|
65
|
-
|
|
66
53
|
const {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
54
|
+
manifest
|
|
55
|
+
} = config,
|
|
56
|
+
options = _objectWithoutProperties(config, _excluded);
|
|
71
57
|
logger('createPlugin', config);
|
|
72
58
|
const promise = initOptions(manifest, options);
|
|
73
59
|
return {
|
|
@@ -77,7 +63,6 @@ export default (config => ({
|
|
|
77
63
|
class GetMicroFrontendApp extends React.Component {
|
|
78
64
|
constructor(props) {
|
|
79
65
|
super(props);
|
|
80
|
-
|
|
81
66
|
_defineProperty(this, "state", {
|
|
82
67
|
MApp: () => {
|
|
83
68
|
logger('MApp init Component Render');
|
|
@@ -87,11 +72,9 @@ export default (config => ({
|
|
|
87
72
|
get() {
|
|
88
73
|
return () => /*#__PURE__*/React.createElement('div');
|
|
89
74
|
}
|
|
90
|
-
|
|
91
75
|
}),
|
|
92
76
|
appInfoList: []
|
|
93
77
|
});
|
|
94
|
-
|
|
95
78
|
const load = async () => {
|
|
96
79
|
GarfishInstance.setOptions(_objectSpread(_objectSpread({}, options), {}, {
|
|
97
80
|
insulationVariable: [...(options.insulationVariable || []), '_SERVER_DATA'],
|
|
@@ -119,10 +102,8 @@ export default (config => ({
|
|
|
119
102
|
appInfoList
|
|
120
103
|
});
|
|
121
104
|
};
|
|
122
|
-
|
|
123
105
|
load();
|
|
124
106
|
}
|
|
125
|
-
|
|
126
107
|
render() {
|
|
127
108
|
logger('GarfishProvider state', this.state);
|
|
128
109
|
return /*#__PURE__*/_jsx(GarfishProvider, {
|
|
@@ -130,14 +111,11 @@ export default (config => ({
|
|
|
130
111
|
children: /*#__PURE__*/_jsx(App, _objectSpread(_objectSpread({}, this.props), this.state))
|
|
131
112
|
});
|
|
132
113
|
}
|
|
133
|
-
|
|
134
114
|
}
|
|
135
|
-
|
|
136
115
|
return next({
|
|
137
116
|
App: hoistNonReactStatics(GetMicroFrontendApp, App)
|
|
138
117
|
});
|
|
139
118
|
}
|
|
140
|
-
|
|
141
119
|
};
|
|
142
120
|
}
|
|
143
121
|
}));
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
2
|
-
|
|
3
2
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
-
|
|
5
3
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
-
|
|
7
4
|
import React, { useContext } from 'react';
|
|
8
5
|
import { logger } from "../util";
|
|
9
6
|
import { GarfishContext } from "./utils/Context";
|
|
@@ -25,10 +22,8 @@ export function useModuleApps() {
|
|
|
25
22
|
if (typeof p === 'string' && p in target) {
|
|
26
23
|
return Reflect.get(target, p, receiver);
|
|
27
24
|
}
|
|
28
|
-
|
|
29
25
|
return () => /*#__PURE__*/React.createElement('div');
|
|
30
26
|
}
|
|
31
|
-
|
|
32
27
|
});
|
|
33
28
|
return Info;
|
|
34
29
|
}
|