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