@modern-js/plugin-garfish 1.3.0 → 1.4.1
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/.eslintrc.js +1 -1
- package/CHANGELOG.md +35 -0
- package/dist/js/modern/cli/index.js +204 -225
- package/dist/js/modern/cli/utils.js +85 -31
- package/dist/js/modern/index.js +2 -1
- package/dist/js/modern/runtime/index.js +2 -1
- package/dist/js/modern/runtime/loadable.js +36 -19
- package/dist/js/modern/runtime/plugin.js +24 -19
- package/dist/js/modern/runtime/utils/MApp.js +7 -10
- package/dist/js/modern/runtime/utils/apps.js +3 -9
- package/dist/js/node/cli/index.js +207 -222
- package/dist/js/node/cli/utils.js +89 -31
- package/dist/js/node/index.js +18 -3
- package/dist/js/node/runtime/index.js +25 -12
- package/dist/js/node/runtime/loadable.js +36 -19
- package/dist/js/node/runtime/plugin.js +21 -18
- package/dist/js/node/runtime/utils/MApp.js +7 -10
- package/dist/js/node/runtime/utils/apps.js +3 -9
- package/dist/js/treeshaking/cli/index.js +124 -121
- package/dist/js/treeshaking/cli/utils.js +33 -4
- package/dist/js/treeshaking/index.js +2 -1
- package/dist/js/treeshaking/runtime/index.js +2 -1
- package/dist/js/treeshaking/runtime/loadable.js +39 -25
- package/dist/js/treeshaking/runtime/plugin.js +29 -24
- package/dist/js/treeshaking/runtime/utils/MApp.js +23 -31
- package/dist/js/treeshaking/runtime/utils/apps.js +22 -24
- package/dist/types/cli/index.d.ts +18 -10
- package/dist/types/cli/utils.d.ts +5 -2
- package/dist/types/index.d.ts +2 -1
- package/dist/types/runtime/index.d.ts +3 -1
- package/dist/types/runtime/loadable.d.ts +2 -8
- package/dist/types/runtime/plugin.d.ts +29 -3
- package/dist/types/runtime/useModuleApps.d.ts +7 -9
- package/dist/types/runtime/utils/MApp.d.ts +1 -15
- package/dist/types/runtime/utils/apps.d.ts +1 -1
- package/package.json +21 -9
- package/tests/cli.test.tsx +203 -33
- package/tests/hooks.test.tsx +1 -0
- package/tests/index.test.tsx +6 -3
- package/tsconfig.json +3 -2
- package/tests/__snapshots__/cli.test.tsx.snap +0 -71
package/.eslintrc.js
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,40 @@
|
|
|
1
1
|
# @modern-js/plugin-garfish
|
|
2
2
|
|
|
3
|
+
## 1.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 4c792f68: feat(plugin-garfish): Sub-applications automatically increment basename
|
|
8
|
+
feat(plugin-garfish): export common generate code function
|
|
9
|
+
fix(plugin-garfish): modify plugin-garfish schema config
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 55e18278: chore: remove unused dependencies and devDependencies
|
|
14
|
+
- Updated dependencies [969f172f]
|
|
15
|
+
- Updated dependencies [4c792f68]
|
|
16
|
+
- Updated dependencies [4b5d4bf4]
|
|
17
|
+
- Updated dependencies [62f5b8c8]
|
|
18
|
+
- Updated dependencies [55e18278]
|
|
19
|
+
- Updated dependencies [4499a674]
|
|
20
|
+
- Updated dependencies [403f5169]
|
|
21
|
+
- Updated dependencies [a7f42f48]
|
|
22
|
+
- @modern-js/core@1.4.4
|
|
23
|
+
- @modern-js/utils@1.3.3
|
|
24
|
+
- @modern-js/runtime-core@1.2.4
|
|
25
|
+
|
|
26
|
+
## 1.3.1
|
|
27
|
+
|
|
28
|
+
### Patch Changes
|
|
29
|
+
|
|
30
|
+
- 53aca274: modify garfish-plugin config type
|
|
31
|
+
- Updated dependencies [53aca274]
|
|
32
|
+
- Updated dependencies [78279953]
|
|
33
|
+
- Updated dependencies [e116ace5]
|
|
34
|
+
- Updated dependencies [4d72edea]
|
|
35
|
+
- @modern-js/core@1.4.1
|
|
36
|
+
- @modern-js/utils@1.3.1
|
|
37
|
+
|
|
3
38
|
## 1.3.0
|
|
4
39
|
|
|
5
40
|
### Minor Changes
|
|
@@ -1,283 +1,262 @@
|
|
|
1
|
-
const _excluded = ["validateSchema", "externals", "componentKey"];
|
|
2
|
-
|
|
3
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; }
|
|
4
2
|
|
|
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
4
|
|
|
7
5
|
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
6
|
|
|
9
|
-
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
|
-
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
|
import path from 'path';
|
|
14
|
-
import { createRuntimeExportsUtils,
|
|
8
|
+
import { createRuntimeExportsUtils, PLUGIN_SCHEMAS } from '@modern-js/utils';
|
|
15
9
|
import { createPlugin, useAppContext, useResolvedConfigContext } from '@modern-js/core';
|
|
16
10
|
import { logger } from "../util";
|
|
17
|
-
import { makeProvider, makeRenderFunction } from "./utils";
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
11
|
+
import { getRuntimeConfig, makeProvider, makeRenderFunction, setRuntimeConfig } from "./utils";
|
|
12
|
+
export const externals = {
|
|
13
|
+
'react-dom': 'react-dom',
|
|
14
|
+
react: 'react'
|
|
15
|
+
};
|
|
16
|
+
export const resolvedConfig = async config => {
|
|
17
|
+
const {
|
|
18
|
+
resolved
|
|
19
|
+
} = config;
|
|
20
|
+
const {
|
|
21
|
+
masterApp,
|
|
22
|
+
router
|
|
23
|
+
} = getRuntimeConfig(resolved);
|
|
24
|
+
const nConfig = {
|
|
25
|
+
resolved: _objectSpread({}, resolved)
|
|
26
|
+
};
|
|
30
27
|
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
if (masterApp) {
|
|
29
|
+
var _router$historyOption;
|
|
33
30
|
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
// basename does not exist use router's basename
|
|
32
|
+
setRuntimeConfig(nConfig.resolved, 'masterApp', Object.assign(typeof masterApp === 'object' ? _objectSpread({}, masterApp) : {}, {
|
|
33
|
+
basename: (router === null || router === void 0 ? void 0 : (_router$historyOption = router.historyOptions) === null || _router$historyOption === void 0 ? void 0 : _router$historyOption.basename) || '/'
|
|
34
|
+
}));
|
|
36
35
|
}
|
|
37
36
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
37
|
+
logger(`resolvedConfig`, {
|
|
38
|
+
runtime: nConfig.resolved.runtime,
|
|
39
|
+
deploy: nConfig.resolved.deploy,
|
|
40
|
+
server: nConfig.resolved.server
|
|
41
|
+
});
|
|
42
|
+
return nConfig;
|
|
43
|
+
};
|
|
44
|
+
export const initializer = ( // eslint-disable-next-line @typescript-eslint/no-shadow
|
|
45
|
+
{
|
|
46
|
+
resolvedConfig,
|
|
47
|
+
validateSchema
|
|
48
|
+
}, {
|
|
49
|
+
runtimePluginName: _runtimePluginName = '@modern-js/runtime/plugins',
|
|
50
|
+
defaultEnableHtmlEntry: _defaultEnableHtmlEntry = true,
|
|
51
|
+
defaultExternalBasicLibrary: _defaultExternalBasicLibrary = false
|
|
52
|
+
}) => () => {
|
|
53
|
+
let pluginsExportsUtils;
|
|
54
|
+
let runtimeExportsUtils;
|
|
55
|
+
return {
|
|
45
56
|
validateSchema,
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
if (masterApp) {
|
|
69
|
-
// basename does not exist use router's basename
|
|
70
|
-
setRuntimeConfig(nConfig.resolved, 'masterApp', Object.assign(typeof masterApp === 'object' ? _objectSpread({}, masterApp) : {}, {
|
|
71
|
-
basename: (router === null || router === void 0 ? void 0 : router.basename) || '/'
|
|
72
|
-
}));
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
logger(`resolvedConfig`, {
|
|
76
|
-
runtime: nConfig.resolved.runtime,
|
|
77
|
-
deploy: nConfig.resolved.deploy,
|
|
78
|
-
server: nConfig.resolved.server
|
|
79
|
-
});
|
|
80
|
-
return nConfig;
|
|
81
|
-
},
|
|
82
|
-
|
|
83
|
-
config() {
|
|
84
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
85
|
-
const config = useAppContext();
|
|
86
|
-
pluginsExportsUtils = createRuntimeExportsUtils(config.internalDirectory, 'plugins');
|
|
87
|
-
runtimeExportsUtils = createRuntimeExportsUtils(config.internalDirectory, 'index');
|
|
88
|
-
return {
|
|
89
|
-
source: {
|
|
90
|
-
alias: {
|
|
91
|
-
'@modern-js/runtime/plugins': pluginsExportsUtils.getPath()
|
|
92
|
-
}
|
|
93
|
-
},
|
|
94
|
-
tools: {
|
|
95
|
-
webpack: (webpackConfig, {
|
|
96
|
-
chain,
|
|
97
|
-
webpack
|
|
98
|
-
}) => {
|
|
99
|
-
var _resolvedConfig$deplo;
|
|
100
|
-
|
|
101
|
-
const env = process.env.NODE_ENV; // eslint-disable-next-line react-hooks/rules-of-hooks
|
|
57
|
+
resolvedConfig,
|
|
58
|
+
|
|
59
|
+
config() {
|
|
60
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
61
|
+
const config = useAppContext();
|
|
62
|
+
pluginsExportsUtils = createRuntimeExportsUtils(config.internalDirectory, 'plugins');
|
|
63
|
+
runtimeExportsUtils = createRuntimeExportsUtils(config.internalDirectory, 'index');
|
|
64
|
+
return {
|
|
65
|
+
source: {
|
|
66
|
+
alias: {
|
|
67
|
+
'@modern-js/runtime/plugins': pluginsExportsUtils.getPath()
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
tools: {
|
|
71
|
+
webpack: (webpackConfig, {
|
|
72
|
+
chain,
|
|
73
|
+
webpack,
|
|
74
|
+
env: _env = process.env.NODE_ENV || 'development'
|
|
75
|
+
}) => {
|
|
76
|
+
var _resolveOptions$deplo, _resolveWebpackConfig;
|
|
102
77
|
|
|
103
|
-
|
|
78
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
79
|
+
const resolveOptions = useResolvedConfigContext();
|
|
104
80
|
|
|
105
|
-
|
|
106
|
-
|
|
81
|
+
if (resolveOptions !== null && resolveOptions !== void 0 && (_resolveOptions$deplo = resolveOptions.deploy) !== null && _resolveOptions$deplo !== void 0 && _resolveOptions$deplo.microFrontend) {
|
|
82
|
+
var _resolveOptions$serve, _resolveOptions$deplo2, _resolveOptions$deplo3;
|
|
107
83
|
|
|
108
|
-
|
|
84
|
+
chain.output.libraryTarget('umd');
|
|
109
85
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
86
|
+
if (resolveOptions !== null && resolveOptions !== void 0 && (_resolveOptions$serve = resolveOptions.server) !== null && _resolveOptions$serve !== void 0 && _resolveOptions$serve.port) {
|
|
87
|
+
chain.output.publicPath(_env === 'development' ? `//localhost:${resolveOptions.server.port}/` : webpackConfig.output.publicPath);
|
|
88
|
+
} // add comments avoid sourcemap abnormal
|
|
113
89
|
|
|
114
90
|
|
|
91
|
+
if (webpack.BannerPlugin) {
|
|
115
92
|
chain.plugin('banner').use(webpack.BannerPlugin, [{
|
|
116
93
|
banner: 'Micro front-end'
|
|
117
94
|
}]);
|
|
118
|
-
const {
|
|
119
|
-
enableHtmlEntry = true,
|
|
120
|
-
externalBasicLibrary = true
|
|
121
|
-
} = typeof (resolvedConfig === null || resolvedConfig === void 0 ? void 0 : (_resolvedConfig$deplo2 = resolvedConfig.deploy) === null || _resolvedConfig$deplo2 === void 0 ? void 0 : _resolvedConfig$deplo2.microFrontend) === 'object' ? resolvedConfig === null || resolvedConfig === void 0 ? void 0 : (_resolvedConfig$deplo3 = resolvedConfig.deploy) === null || _resolvedConfig$deplo3 === void 0 ? void 0 : _resolvedConfig$deplo3.microFrontend : {}; // external
|
|
122
|
-
|
|
123
|
-
if (externalBasicLibrary) {
|
|
124
|
-
chain.externals(externals);
|
|
125
|
-
} // use html mode
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
if (!enableHtmlEntry) {
|
|
129
|
-
chain.output.filename('index.js');
|
|
130
|
-
chain.plugins.delete('html-main');
|
|
131
|
-
chain.optimization.runtimeChunk(false);
|
|
132
|
-
chain.optimization.splitChunks({
|
|
133
|
-
chunks: 'async'
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
95
|
}
|
|
137
96
|
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
env
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
},
|
|
97
|
+
const {
|
|
98
|
+
enableHtmlEntry = _defaultEnableHtmlEntry,
|
|
99
|
+
externalBasicLibrary = _defaultExternalBasicLibrary
|
|
100
|
+
} = typeof (resolveOptions === null || resolveOptions === void 0 ? void 0 : (_resolveOptions$deplo2 = resolveOptions.deploy) === null || _resolveOptions$deplo2 === void 0 ? void 0 : _resolveOptions$deplo2.microFrontend) === 'object' ? resolveOptions === null || resolveOptions === void 0 ? void 0 : (_resolveOptions$deplo3 = resolveOptions.deploy) === null || _resolveOptions$deplo3 === void 0 ? void 0 : _resolveOptions$deplo3.microFrontend : {}; // external
|
|
148
101
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
logger('exportStatement', addExportStatement);
|
|
153
|
-
pluginsExportsUtils.addExport(addExportStatement);
|
|
154
|
-
runtimeExportsUtils.addExport(`export * from '${mfPackage}'`);
|
|
155
|
-
},
|
|
102
|
+
if (externalBasicLibrary) {
|
|
103
|
+
chain.externals(externals);
|
|
104
|
+
} // use html mode
|
|
156
105
|
|
|
157
|
-
validateSchema,
|
|
158
106
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
} = getRuntimeConfig(resolvedConfig); // eslint-disable-next-line react-hooks/rules-of-hooks
|
|
169
|
-
|
|
170
|
-
const {
|
|
171
|
-
packageName
|
|
172
|
-
} = useAppContext();
|
|
173
|
-
const masterAppConfig = getEntryOptions(entrypoint.entryName, masterApp, resolvedConfig.runtimeByEntries, packageName);
|
|
174
|
-
configMap.set(entrypoint.entryName, masterAppConfig);
|
|
175
|
-
|
|
176
|
-
if (masterAppConfig) {
|
|
177
|
-
imports.push({
|
|
178
|
-
value: '@modern-js/runtime/plugins',
|
|
179
|
-
specifiers: [{
|
|
180
|
-
imported: 'garfish'
|
|
181
|
-
}]
|
|
182
|
-
});
|
|
183
|
-
}
|
|
107
|
+
if (!enableHtmlEntry) {
|
|
108
|
+
chain.output.filename('index.js');
|
|
109
|
+
chain.plugins.delete('html-main');
|
|
110
|
+
chain.optimization.runtimeChunk(false);
|
|
111
|
+
chain.optimization.splitChunks({
|
|
112
|
+
chunks: 'async'
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
184
116
|
|
|
117
|
+
const resolveWebpackConfig = chain.toConfig();
|
|
118
|
+
logger('webpackConfig', {
|
|
119
|
+
output: resolveWebpackConfig.output,
|
|
120
|
+
externals: resolveWebpackConfig.externals,
|
|
121
|
+
env: _env,
|
|
122
|
+
alias: (_resolveWebpackConfig = resolveWebpackConfig.resolve) === null || _resolveWebpackConfig === void 0 ? void 0 : _resolveWebpackConfig.alias
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
},
|
|
128
|
+
|
|
129
|
+
addRuntimeExports() {
|
|
130
|
+
const mfPackage = path.resolve(__dirname, '../../../../');
|
|
131
|
+
const addExportStatement = `export { default as garfish, default as masterApp } from '${mfPackage}'`;
|
|
132
|
+
logger('exportStatement', addExportStatement);
|
|
133
|
+
pluginsExportsUtils.addExport(addExportStatement);
|
|
134
|
+
runtimeExportsUtils.addExport(`export * from '${mfPackage}'`);
|
|
135
|
+
},
|
|
136
|
+
|
|
137
|
+
modifyEntryImports({
|
|
138
|
+
entrypoint,
|
|
139
|
+
imports
|
|
140
|
+
}) {
|
|
141
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
142
|
+
const config = useResolvedConfigContext();
|
|
143
|
+
const {
|
|
144
|
+
masterApp
|
|
145
|
+
} = getRuntimeConfig(config);
|
|
146
|
+
|
|
147
|
+
if (masterApp) {
|
|
185
148
|
imports.push({
|
|
186
|
-
value:
|
|
149
|
+
value: _runtimePluginName,
|
|
187
150
|
specifiers: [{
|
|
188
|
-
imported: '
|
|
189
|
-
}, {
|
|
190
|
-
imported: 'createPortal'
|
|
151
|
+
imported: 'garfish'
|
|
191
152
|
}]
|
|
192
153
|
});
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
154
|
+
imports.push({
|
|
155
|
+
value: _runtimePluginName,
|
|
156
|
+
specifiers: [{
|
|
157
|
+
imported: 'masterApp'
|
|
158
|
+
}]
|
|
159
|
+
});
|
|
160
|
+
}
|
|
198
161
|
|
|
199
|
-
|
|
162
|
+
imports.push({
|
|
163
|
+
value: 'react-dom',
|
|
164
|
+
specifiers: [{
|
|
165
|
+
imported: 'unmountComponentAtNode'
|
|
166
|
+
}, {
|
|
167
|
+
imported: 'createPortal'
|
|
168
|
+
}]
|
|
169
|
+
});
|
|
170
|
+
return {
|
|
171
|
+
imports,
|
|
172
|
+
entrypoint
|
|
173
|
+
};
|
|
174
|
+
},
|
|
175
|
+
|
|
176
|
+
modifyEntryRuntimePlugins({
|
|
177
|
+
entrypoint,
|
|
178
|
+
plugins
|
|
179
|
+
}) {
|
|
180
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
181
|
+
const config = useResolvedConfigContext();
|
|
182
|
+
const {
|
|
183
|
+
masterApp
|
|
184
|
+
} = getRuntimeConfig(config);
|
|
185
|
+
|
|
186
|
+
if (masterApp) {
|
|
187
|
+
logger('garfishPlugin options', masterApp);
|
|
188
|
+
plugins.push({
|
|
189
|
+
name: 'garfish',
|
|
190
|
+
args: 'masterApp',
|
|
191
|
+
options: masterApp === true ? JSON.stringify({}) : JSON.stringify(masterApp)
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return {
|
|
200
196
|
entrypoint,
|
|
201
197
|
plugins
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
if (masterAppConfig) {
|
|
206
|
-
logger('garfishPlugin options', masterAppConfig);
|
|
207
|
-
plugins.push({
|
|
208
|
-
name: 'garfish',
|
|
209
|
-
args: 'masterApp',
|
|
210
|
-
options: JSON.stringify(masterAppConfig)
|
|
211
|
-
});
|
|
212
|
-
}
|
|
198
|
+
};
|
|
199
|
+
},
|
|
213
200
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
201
|
+
modifyEntryRenderFunction({
|
|
202
|
+
entrypoint,
|
|
203
|
+
code
|
|
204
|
+
}) {
|
|
205
|
+
var _config$deploy;
|
|
219
206
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
code
|
|
223
|
-
}) {
|
|
224
|
-
var _config$deploy;
|
|
225
|
-
|
|
226
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
227
|
-
const config = useResolvedConfigContext();
|
|
228
|
-
|
|
229
|
-
if (!(config !== null && config !== void 0 && (_config$deploy = config.deploy) !== null && _config$deploy !== void 0 && _config$deploy.microFrontend)) {
|
|
230
|
-
return {
|
|
231
|
-
entrypoint,
|
|
232
|
-
code
|
|
233
|
-
};
|
|
234
|
-
}
|
|
207
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
208
|
+
const config = useResolvedConfigContext();
|
|
235
209
|
|
|
236
|
-
|
|
237
|
-
logger('makeRenderFunction', nCode);
|
|
210
|
+
if (!(config !== null && config !== void 0 && (_config$deploy = config.deploy) !== null && _config$deploy !== void 0 && _config$deploy.microFrontend)) {
|
|
238
211
|
return {
|
|
239
212
|
entrypoint,
|
|
240
|
-
code
|
|
213
|
+
code
|
|
241
214
|
};
|
|
242
|
-
}
|
|
215
|
+
}
|
|
243
216
|
|
|
244
|
-
|
|
217
|
+
const nCode = makeRenderFunction(code);
|
|
218
|
+
logger('makeRenderFunction', nCode);
|
|
219
|
+
return {
|
|
245
220
|
entrypoint,
|
|
246
|
-
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
221
|
+
code: nCode
|
|
222
|
+
};
|
|
223
|
+
},
|
|
224
|
+
|
|
225
|
+
modifyEntryExport({
|
|
226
|
+
entrypoint,
|
|
227
|
+
exportStatement
|
|
228
|
+
}) {
|
|
229
|
+
var _config$deploy2;
|
|
230
|
+
|
|
231
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
232
|
+
const config = useResolvedConfigContext();
|
|
233
|
+
|
|
234
|
+
if (config !== null && config !== void 0 && (_config$deploy2 = config.deploy) !== null && _config$deploy2 !== void 0 && _config$deploy2.microFrontend) {
|
|
235
|
+
const exportStatementCode = makeProvider();
|
|
236
|
+
logger('exportStatement', exportStatementCode);
|
|
262
237
|
return {
|
|
263
238
|
entrypoint,
|
|
264
|
-
exportStatement
|
|
239
|
+
exportStatement: exportStatementCode
|
|
265
240
|
};
|
|
266
241
|
}
|
|
267
242
|
|
|
268
|
-
|
|
243
|
+
return {
|
|
244
|
+
entrypoint,
|
|
245
|
+
exportStatement
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
|
|
269
249
|
};
|
|
270
250
|
};
|
|
271
251
|
export default createPlugin(initializer({
|
|
252
|
+
resolvedConfig,
|
|
253
|
+
|
|
272
254
|
validateSchema() {
|
|
273
255
|
return PLUGIN_SCHEMAS['@modern-js/plugin-garfish'];
|
|
274
|
-
}
|
|
256
|
+
}
|
|
275
257
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
react: 'react'
|
|
279
|
-
},
|
|
280
|
-
componentKey: 'dynamicComponent'
|
|
258
|
+
}, {
|
|
259
|
+
runtimePluginName: '@modern-js/runtime/plugins'
|
|
281
260
|
}), {
|
|
282
261
|
name: '@modern-js/plugin-garfish'
|
|
283
262
|
});
|
|
@@ -1,36 +1,90 @@
|
|
|
1
|
-
export const makeProvider =
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
if (node) {
|
|
14
|
-
unmountComponentAtNode(node);
|
|
15
|
-
}
|
|
16
|
-
},
|
|
17
|
-
SubModuleComponent: (props) => {
|
|
18
|
-
const SubApp = render(props, basename);
|
|
19
|
-
|
|
20
|
-
return createPortal(<SubApp />, dom.querySelector('#' + MOUNT_ID) || dom);
|
|
21
|
-
},
|
|
22
|
-
${componentKey}: () => {
|
|
23
|
-
const SubApp = render(props, basename);
|
|
1
|
+
export const makeProvider = () => `
|
|
2
|
+
export const provider = function ({basename, dom, ...props}) {
|
|
3
|
+
return {
|
|
4
|
+
render({basename, dom}) {
|
|
5
|
+
console.log('App.config', App.config);
|
|
6
|
+
const SubApp = render({props, basename});
|
|
7
|
+
const node = dom.querySelector('#' + MOUNT_ID) || dom;
|
|
8
|
+
bootstrap(SubApp, node);
|
|
9
|
+
},
|
|
10
|
+
destroy({ dom }) {
|
|
11
|
+
const node = dom.querySelector('#' + MOUNT_ID) || dom;
|
|
24
12
|
|
|
25
|
-
|
|
13
|
+
if (node) {
|
|
14
|
+
unmountComponentAtNode(node);
|
|
26
15
|
}
|
|
16
|
+
},
|
|
17
|
+
SubModuleComponent: (props) => {
|
|
18
|
+
const SubApp = render({props, basename});
|
|
19
|
+
|
|
20
|
+
return createPortal(<SubApp />, dom.querySelector('#' + MOUNT_ID) || dom);
|
|
21
|
+
},
|
|
22
|
+
jupiter_submodule_app_key: (props) => {
|
|
23
|
+
const SubApp = render({props, basename});
|
|
24
|
+
|
|
25
|
+
return createPortal(<SubApp />, dom.querySelector('#' + MOUNT_ID) || dom);
|
|
27
26
|
}
|
|
28
|
-
};
|
|
29
|
-
if (typeof __GARFISH_EXPORTS__ !== 'undefined') {
|
|
30
|
-
__GARFISH_EXPORTS__.provider = provider;
|
|
31
27
|
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
if (typeof __GARFISH_EXPORTS__ !== 'undefined') {
|
|
31
|
+
__GARFISH_EXPORTS__.provider = provider;
|
|
32
|
+
}
|
|
32
33
|
`;
|
|
33
|
-
export const makeRenderFunction = code =>
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
export const makeRenderFunction = code => {
|
|
35
|
+
const inGarfishToRender = `
|
|
36
|
+
const { basename, props } = arguments[0] || {};
|
|
37
|
+
let renderByGarfish = false;
|
|
38
|
+
const renderByProvider = !!basename;
|
|
39
|
+
|
|
40
|
+
if (IS_BROWSER && window.Garfish && window.Garfish.activeApps && window.Garfish.activeApps.length !== 0) renderByGarfish = true;
|
|
41
|
+
if (IS_BROWSER && window.Garfish && window.Garfish.apps && Object.keys(window.Garfish.apps).length !== 0) renderByGarfish = true;
|
|
42
|
+
if (typeof __GARFISH_EXPORTS__ !== 'undefined') renderByGarfish = true;
|
|
43
|
+
if (renderByGarfish && !renderByProvider) return null;
|
|
44
|
+
|
|
45
|
+
function RouterPlugin (routerConfig) {
|
|
46
|
+
if (basename) {
|
|
47
|
+
routerConfig.basename = basename;
|
|
48
|
+
if (routerConfig.supportHtml5History !== false) {
|
|
49
|
+
if (!routerConfig.historyOptions) {
|
|
50
|
+
routerConfig.historyOptions = {
|
|
51
|
+
basename: basename
|
|
52
|
+
};
|
|
53
|
+
} else {
|
|
54
|
+
routerConfig.historyOptions.basename = basename;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return router(routerConfig);
|
|
59
|
+
}
|
|
60
|
+
`;
|
|
61
|
+
return inGarfishToRender + code.replace(`router(`, `RouterPlugin(`).replace('IS_BROWSER', `IS_BROWSER && !renderByGarfish`);
|
|
62
|
+
}; // support legacy config
|
|
63
|
+
|
|
64
|
+
export function getRuntimeConfig(config) {
|
|
65
|
+
var _config$runtime;
|
|
66
|
+
|
|
67
|
+
if (config !== null && config !== void 0 && (_config$runtime = config.runtime) !== null && _config$runtime !== void 0 && _config$runtime.features) {
|
|
68
|
+
var _config$runtime2;
|
|
69
|
+
|
|
70
|
+
return config === null || config === void 0 ? void 0 : (_config$runtime2 = config.runtime) === null || _config$runtime2 === void 0 ? void 0 : _config$runtime2.features;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return config === null || config === void 0 ? void 0 : config.runtime;
|
|
74
|
+
} // support legacy config
|
|
75
|
+
|
|
76
|
+
export function setRuntimeConfig(config, key, value) {
|
|
77
|
+
var _config$runtime3, _config$runtime4;
|
|
78
|
+
|
|
79
|
+
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]) {
|
|
80
|
+
config.runtime.features[key] = value;
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (config !== null && config !== void 0 && config.runtime && config !== null && config !== void 0 && config.runtime[key]) {
|
|
85
|
+
config.runtime[key] = value;
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
package/dist/js/modern/index.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { default } from "./
|
|
1
|
+
export { default } from "./runtime";
|
|
2
|
+
export * from "./runtime";
|