@modern-js/plugin-garfish 1.3.0 → 1.3.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 +12 -0
- package/dist/js/modern/cli/index.js +190 -209
- package/dist/js/modern/cli/utils.js +1 -6
- 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 +14 -17
- package/dist/js/modern/runtime/utils/MApp.js +7 -10
- package/dist/js/modern/runtime/utils/apps.js +1 -4
- package/dist/js/node/cli/index.js +192 -213
- package/dist/js/node/cli/utils.js +1 -6
- 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 +11 -16
- package/dist/js/node/runtime/utils/MApp.js +7 -10
- package/dist/js/node/runtime/utils/apps.js +1 -4
- package/dist/js/treeshaking/cli/index.js +183 -199
- package/dist/js/treeshaking/cli/utils.js +2 -2
- 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 +15 -19
- package/dist/js/treeshaking/runtime/utils/MApp.js +23 -31
- package/dist/js/treeshaking/runtime/utils/apps.js +1 -2
- package/dist/types/cli/index.d.ts +1 -9
- package/dist/types/cli/utils.d.ts +1 -1
- 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 +20 -8
- package/tests/cli.test.tsx +21 -43
- 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
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
var _excluded = ["validateSchema", "externals", "componentKey"];
|
|
2
|
-
|
|
3
1
|
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
2
|
|
|
5
3
|
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,10 +6,6 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
8
6
|
|
|
9
7
|
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; }
|
|
10
8
|
|
|
11
|
-
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; }
|
|
12
|
-
|
|
13
|
-
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; }
|
|
14
|
-
|
|
15
9
|
import path from 'path';
|
|
16
10
|
import { createRuntimeExportsUtils, getEntryOptions, PLUGIN_SCHEMAS } from '@modern-js/utils';
|
|
17
11
|
import { createPlugin, useAppContext, useResolvedConfigContext } from '@modern-js/core';
|
|
@@ -42,230 +36,220 @@ function setRuntimeConfig(config, key, value) {
|
|
|
42
36
|
}
|
|
43
37
|
}
|
|
44
38
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}));
|
|
72
|
-
}
|
|
39
|
+
var externals = {
|
|
40
|
+
'react-dom': 'react-dom',
|
|
41
|
+
react: 'react'
|
|
42
|
+
};
|
|
43
|
+
export default createPlugin(function () {
|
|
44
|
+
var configMap = new Map();
|
|
45
|
+
var pluginsExportsUtils;
|
|
46
|
+
var runtimeExportsUtils;
|
|
47
|
+
return {
|
|
48
|
+
resolvedConfig: function resolvedConfig(config) {
|
|
49
|
+
var resolved = config.resolved;
|
|
50
|
+
|
|
51
|
+
var _getRuntimeConfig = getRuntimeConfig(resolved),
|
|
52
|
+
masterApp = _getRuntimeConfig.masterApp,
|
|
53
|
+
router = _getRuntimeConfig.router;
|
|
54
|
+
|
|
55
|
+
var nConfig = {
|
|
56
|
+
resolved: _objectSpread({}, resolved)
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
if (masterApp) {
|
|
60
|
+
// basename does not exist use router's basename
|
|
61
|
+
setRuntimeConfig(nConfig.resolved, 'masterApp', Object.assign(_typeof(masterApp) === 'object' ? _objectSpread({}, masterApp) : {}, {
|
|
62
|
+
basename: (router === null || router === void 0 ? void 0 : router.basename) || '/'
|
|
63
|
+
}));
|
|
64
|
+
}
|
|
73
65
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
66
|
+
logger("resolvedConfig", {
|
|
67
|
+
runtime: nConfig.resolved.runtime,
|
|
68
|
+
deploy: nConfig.resolved.deploy,
|
|
69
|
+
server: nConfig.resolved.server
|
|
70
|
+
});
|
|
71
|
+
return nConfig;
|
|
72
|
+
},
|
|
73
|
+
config: function config() {
|
|
74
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
75
|
+
var config = useAppContext();
|
|
76
|
+
pluginsExportsUtils = createRuntimeExportsUtils(config.internalDirectory, 'plugins');
|
|
77
|
+
runtimeExportsUtils = createRuntimeExportsUtils(config.internalDirectory, 'index');
|
|
78
|
+
return {
|
|
79
|
+
source: {
|
|
80
|
+
alias: {
|
|
81
|
+
'@modern-js/runtime/plugins': pluginsExportsUtils.getPath()
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
tools: {
|
|
85
|
+
webpack: function webpack(webpackConfig, _ref) {
|
|
86
|
+
var _resolvedConfig$deplo, _resolveWebpackConfig;
|
|
95
87
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
88
|
+
var chain = _ref.chain,
|
|
89
|
+
_webpack = _ref.webpack;
|
|
90
|
+
var env = process.env.NODE_ENV; // eslint-disable-next-line react-hooks/rules-of-hooks
|
|
99
91
|
|
|
100
|
-
|
|
92
|
+
var resolvedConfig = useResolvedConfigContext();
|
|
101
93
|
|
|
102
|
-
|
|
103
|
-
|
|
94
|
+
if (resolvedConfig !== null && resolvedConfig !== void 0 && (_resolvedConfig$deplo = resolvedConfig.deploy) !== null && _resolvedConfig$deplo !== void 0 && _resolvedConfig$deplo.microFrontend) {
|
|
95
|
+
var _resolvedConfig$deplo2, _resolvedConfig$deplo3;
|
|
104
96
|
|
|
105
|
-
|
|
97
|
+
chain.output.libraryTarget('umd');
|
|
106
98
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
99
|
+
if (resolvedConfig.server.port) {
|
|
100
|
+
chain.output.publicPath(env === 'development' ? "//localhost:".concat(resolvedConfig.server.port, "/") : webpackConfig.output.publicPath);
|
|
101
|
+
} // add comments avoid sourcemap abnormal
|
|
110
102
|
|
|
111
103
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
104
|
+
chain.plugin('banner').use(_webpack.BannerPlugin, [{
|
|
105
|
+
banner: 'Micro front-end'
|
|
106
|
+
}]);
|
|
115
107
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
108
|
+
var _ref2 = _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 : {},
|
|
109
|
+
_ref2$enableHtmlEntry = _ref2.enableHtmlEntry,
|
|
110
|
+
enableHtmlEntry = _ref2$enableHtmlEntry === void 0 ? true : _ref2$enableHtmlEntry,
|
|
111
|
+
_ref2$externalBasicLi = _ref2.externalBasicLibrary,
|
|
112
|
+
externalBasicLibrary = _ref2$externalBasicLi === void 0 ? true : _ref2$externalBasicLi; // external
|
|
121
113
|
|
|
122
114
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
115
|
+
if (externalBasicLibrary) {
|
|
116
|
+
chain.externals(externals);
|
|
117
|
+
} // use html mode
|
|
126
118
|
|
|
127
119
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}
|
|
120
|
+
if (!enableHtmlEntry) {
|
|
121
|
+
chain.output.filename('index.js');
|
|
122
|
+
chain.plugins["delete"]('html-main');
|
|
123
|
+
chain.optimization.runtimeChunk(false);
|
|
124
|
+
chain.optimization.splitChunks({
|
|
125
|
+
chunks: 'async'
|
|
126
|
+
});
|
|
136
127
|
}
|
|
137
|
-
|
|
138
|
-
var resolveWebpackConfig = chain.toConfig();
|
|
139
|
-
logger('webpackConfig', {
|
|
140
|
-
output: resolveWebpackConfig.output,
|
|
141
|
-
externals: resolveWebpackConfig.externals,
|
|
142
|
-
env: env
|
|
143
|
-
});
|
|
144
128
|
}
|
|
129
|
+
|
|
130
|
+
var resolveWebpackConfig = chain.toConfig();
|
|
131
|
+
logger('webpackConfig', {
|
|
132
|
+
output: resolveWebpackConfig.output,
|
|
133
|
+
externals: resolveWebpackConfig.externals,
|
|
134
|
+
env: env,
|
|
135
|
+
alias: (_resolveWebpackConfig = resolveWebpackConfig.resolve) === null || _resolveWebpackConfig === void 0 ? void 0 : _resolveWebpackConfig.alias
|
|
136
|
+
});
|
|
145
137
|
}
|
|
146
|
-
};
|
|
147
|
-
},
|
|
148
|
-
addRuntimeExports: function addRuntimeExports() {
|
|
149
|
-
var mfPackage = path.resolve(__dirname, '../../../../');
|
|
150
|
-
var addExportStatement = "export { default as garfish } from '".concat(mfPackage, "'");
|
|
151
|
-
logger('exportStatement', addExportStatement);
|
|
152
|
-
pluginsExportsUtils.addExport(addExportStatement);
|
|
153
|
-
runtimeExportsUtils.addExport("export * from '".concat(mfPackage, "'"));
|
|
154
|
-
},
|
|
155
|
-
validateSchema: validateSchema,
|
|
156
|
-
modifyEntryImports: function modifyEntryImports(_ref4) {
|
|
157
|
-
var entrypoint = _ref4.entrypoint,
|
|
158
|
-
imports = _ref4.imports;
|
|
159
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
160
|
-
var resolvedConfig = useResolvedConfigContext(); // support legacy config
|
|
161
|
-
|
|
162
|
-
var _getRuntimeConfig2 = getRuntimeConfig(resolvedConfig),
|
|
163
|
-
masterApp = _getRuntimeConfig2.masterApp; // eslint-disable-next-line react-hooks/rules-of-hooks
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
var _useAppContext = useAppContext(),
|
|
167
|
-
packageName = _useAppContext.packageName;
|
|
168
|
-
|
|
169
|
-
var masterAppConfig = getEntryOptions(entrypoint.entryName, masterApp, resolvedConfig.runtimeByEntries, packageName);
|
|
170
|
-
configMap.set(entrypoint.entryName, masterAppConfig);
|
|
171
|
-
|
|
172
|
-
if (masterAppConfig) {
|
|
173
|
-
imports.push({
|
|
174
|
-
value: '@modern-js/runtime/plugins',
|
|
175
|
-
specifiers: [{
|
|
176
|
-
imported: 'garfish'
|
|
177
|
-
}]
|
|
178
|
-
});
|
|
179
138
|
}
|
|
180
|
-
|
|
139
|
+
};
|
|
140
|
+
},
|
|
141
|
+
addRuntimeExports: function addRuntimeExports() {
|
|
142
|
+
var mfPackage = path.resolve(__dirname, '../../../../');
|
|
143
|
+
var addExportStatement = "export { default as garfish } from '".concat(mfPackage, "'");
|
|
144
|
+
logger('exportStatement', addExportStatement);
|
|
145
|
+
pluginsExportsUtils.addExport(addExportStatement);
|
|
146
|
+
runtimeExportsUtils.addExport("export * from '".concat(mfPackage, "'"));
|
|
147
|
+
},
|
|
148
|
+
validateSchema: function validateSchema() {
|
|
149
|
+
return PLUGIN_SCHEMAS['@modern-js/plugin-garfish'];
|
|
150
|
+
},
|
|
151
|
+
modifyEntryImports: function modifyEntryImports(_ref3) {
|
|
152
|
+
var entrypoint = _ref3.entrypoint,
|
|
153
|
+
imports = _ref3.imports;
|
|
154
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
155
|
+
var resolvedConfig = useResolvedConfigContext(); // support legacy config
|
|
156
|
+
|
|
157
|
+
var _getRuntimeConfig2 = getRuntimeConfig(resolvedConfig),
|
|
158
|
+
masterApp = _getRuntimeConfig2.masterApp; // eslint-disable-next-line react-hooks/rules-of-hooks
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
var _useAppContext = useAppContext(),
|
|
162
|
+
packageName = _useAppContext.packageName;
|
|
163
|
+
|
|
164
|
+
var masterAppConfig = getEntryOptions(entrypoint.entryName, masterApp, resolvedConfig.runtimeByEntries, packageName);
|
|
165
|
+
configMap.set(entrypoint.entryName, masterAppConfig);
|
|
166
|
+
|
|
167
|
+
if (masterAppConfig) {
|
|
181
168
|
imports.push({
|
|
182
|
-
value: '
|
|
169
|
+
value: '@modern-js/runtime/plugins',
|
|
183
170
|
specifiers: [{
|
|
184
|
-
imported: '
|
|
185
|
-
}, {
|
|
186
|
-
imported: 'createPortal'
|
|
171
|
+
imported: 'garfish'
|
|
187
172
|
}]
|
|
188
173
|
});
|
|
189
|
-
|
|
190
|
-
imports: imports,
|
|
191
|
-
entrypoint: entrypoint
|
|
192
|
-
};
|
|
193
|
-
},
|
|
194
|
-
modifyEntryRuntimePlugins: function modifyEntryRuntimePlugins(_ref5) {
|
|
195
|
-
var entrypoint = _ref5.entrypoint,
|
|
196
|
-
plugins = _ref5.plugins;
|
|
197
|
-
var masterAppConfig = configMap.get(entrypoint.entryName);
|
|
198
|
-
|
|
199
|
-
if (masterAppConfig) {
|
|
200
|
-
logger('garfishPlugin options', masterAppConfig);
|
|
201
|
-
plugins.push({
|
|
202
|
-
name: 'garfish',
|
|
203
|
-
args: 'masterApp',
|
|
204
|
-
options: JSON.stringify(masterAppConfig)
|
|
205
|
-
});
|
|
206
|
-
}
|
|
174
|
+
}
|
|
207
175
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
176
|
+
imports.push({
|
|
177
|
+
value: 'react-dom',
|
|
178
|
+
specifiers: [{
|
|
179
|
+
imported: 'unmountComponentAtNode'
|
|
180
|
+
}, {
|
|
181
|
+
imported: 'createPortal'
|
|
182
|
+
}]
|
|
183
|
+
});
|
|
184
|
+
return {
|
|
185
|
+
imports: imports,
|
|
186
|
+
entrypoint: entrypoint
|
|
187
|
+
};
|
|
188
|
+
},
|
|
189
|
+
modifyEntryRuntimePlugins: function modifyEntryRuntimePlugins(_ref4) {
|
|
190
|
+
var entrypoint = _ref4.entrypoint,
|
|
191
|
+
plugins = _ref4.plugins;
|
|
192
|
+
var masterAppConfig = configMap.get(entrypoint.entryName);
|
|
193
|
+
|
|
194
|
+
if (masterAppConfig) {
|
|
195
|
+
logger('garfishPlugin options', masterAppConfig);
|
|
196
|
+
plugins.push({
|
|
197
|
+
name: 'garfish',
|
|
198
|
+
args: 'masterApp',
|
|
199
|
+
options: JSON.stringify(masterAppConfig)
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return {
|
|
204
|
+
entrypoint: entrypoint,
|
|
205
|
+
plugins: plugins
|
|
206
|
+
};
|
|
207
|
+
},
|
|
208
|
+
modifyEntryRenderFunction: function modifyEntryRenderFunction(_ref5) {
|
|
209
|
+
var _config$deploy;
|
|
210
|
+
|
|
211
|
+
var entrypoint = _ref5.entrypoint,
|
|
212
|
+
code = _ref5.code;
|
|
213
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
214
|
+
var config = useResolvedConfigContext();
|
|
227
215
|
|
|
228
|
-
|
|
229
|
-
logger('makeRenderFunction', nCode);
|
|
216
|
+
if (!(config !== null && config !== void 0 && (_config$deploy = config.deploy) !== null && _config$deploy !== void 0 && _config$deploy.microFrontend)) {
|
|
230
217
|
return {
|
|
231
218
|
entrypoint: entrypoint,
|
|
232
|
-
code:
|
|
219
|
+
code: code
|
|
233
220
|
};
|
|
234
|
-
}
|
|
235
|
-
modifyEntryExport: function modifyEntryExport(_ref7) {
|
|
236
|
-
var _resolvedConfig$deplo4;
|
|
237
|
-
|
|
238
|
-
var entrypoint = _ref7.entrypoint,
|
|
239
|
-
exportStatement = _ref7.exportStatement;
|
|
240
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
241
|
-
var resolvedConfig = useResolvedConfigContext();
|
|
242
|
-
|
|
243
|
-
if (resolvedConfig !== null && resolvedConfig !== void 0 && (_resolvedConfig$deplo4 = resolvedConfig.deploy) !== null && _resolvedConfig$deplo4 !== void 0 && _resolvedConfig$deplo4.microFrontend) {
|
|
244
|
-
var exportStatementCode = makeProvider(componentKey);
|
|
245
|
-
logger('exportStatement', exportStatementCode);
|
|
246
|
-
return {
|
|
247
|
-
entrypoint: entrypoint,
|
|
248
|
-
exportStatement: exportStatementCode
|
|
249
|
-
};
|
|
250
|
-
}
|
|
221
|
+
}
|
|
251
222
|
|
|
223
|
+
var nCode = makeRenderFunction(code);
|
|
224
|
+
logger('makeRenderFunction', nCode);
|
|
225
|
+
return {
|
|
226
|
+
entrypoint: entrypoint,
|
|
227
|
+
code: nCode
|
|
228
|
+
};
|
|
229
|
+
},
|
|
230
|
+
modifyEntryExport: function modifyEntryExport(_ref6) {
|
|
231
|
+
var _resolvedConfig$deplo4;
|
|
232
|
+
|
|
233
|
+
var entrypoint = _ref6.entrypoint,
|
|
234
|
+
exportStatement = _ref6.exportStatement;
|
|
235
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
236
|
+
var resolvedConfig = useResolvedConfigContext();
|
|
237
|
+
|
|
238
|
+
if (resolvedConfig !== null && resolvedConfig !== void 0 && (_resolvedConfig$deplo4 = resolvedConfig.deploy) !== null && _resolvedConfig$deplo4 !== void 0 && _resolvedConfig$deplo4.microFrontend) {
|
|
239
|
+
var exportStatementCode = makeProvider();
|
|
240
|
+
logger('exportStatement', exportStatementCode);
|
|
252
241
|
return {
|
|
253
242
|
entrypoint: entrypoint,
|
|
254
|
-
exportStatement:
|
|
243
|
+
exportStatement: exportStatementCode
|
|
255
244
|
};
|
|
256
245
|
}
|
|
257
|
-
|
|
246
|
+
|
|
247
|
+
return {
|
|
248
|
+
entrypoint: entrypoint,
|
|
249
|
+
exportStatement: exportStatement
|
|
250
|
+
};
|
|
251
|
+
}
|
|
258
252
|
};
|
|
259
|
-
}
|
|
260
|
-
export default createPlugin(initializer({
|
|
261
|
-
validateSchema: function validateSchema() {
|
|
262
|
-
return PLUGIN_SCHEMAS['@modern-js/plugin-garfish'];
|
|
263
|
-
},
|
|
264
|
-
externals: {
|
|
265
|
-
'react-dom': 'react-dom',
|
|
266
|
-
react: 'react'
|
|
267
|
-
},
|
|
268
|
-
componentKey: 'dynamicComponent'
|
|
269
|
-
}), {
|
|
253
|
+
}, {
|
|
270
254
|
name: '@modern-js/plugin-garfish'
|
|
271
255
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export var makeProvider = function makeProvider(
|
|
2
|
-
return "\n export const provider = function ({basename, dom, ...props}) {\n return {\n render({basename, dom}) {\n const SubApp = render(props, basename);\n const node = dom.querySelector('#' + MOUNT_ID) || dom;\n\n bootstrap(SubApp, node);\n },\n destroy({ dom }) {\n const node = dom.querySelector('#' + MOUNT_ID) || dom;\n\n if (node) {\n unmountComponentAtNode(node);\n }\n },\n SubModuleComponent: (props) => {\n const SubApp = render(props, basename);\n\n return createPortal(<SubApp />, dom.querySelector('#' + MOUNT_ID) || dom);\n }
|
|
1
|
+
export var makeProvider = function makeProvider() {
|
|
2
|
+
return "\n export const provider = function ({basename, dom, ...props}) {\n return {\n render({basename, dom}) {\n const SubApp = render(props, basename);\n const node = dom.querySelector('#' + MOUNT_ID) || dom;\n\n bootstrap(SubApp, node);\n },\n destroy({ dom }) {\n const node = dom.querySelector('#' + MOUNT_ID) || dom;\n\n if (node) {\n unmountComponentAtNode(node);\n }\n },\n SubModuleComponent: (props) => {\n const SubApp = render(props, basename);\n\n return createPortal(<SubApp />, dom.querySelector('#' + MOUNT_ID) || dom);\n }\n }\n };\n if (typeof __GARFISH_EXPORTS__ !== 'undefined') {\n __GARFISH_EXPORTS__.provider = provider;\n }\n";
|
|
3
3
|
};
|
|
4
4
|
export var makeRenderFunction = function makeRenderFunction(code) {
|
|
5
5
|
return code.replace('IS_BROWSER', "\n IS_BROWSER &&\n typeof __GARFISH_EXPORTS__ === 'undefined'\n ").replace('(App)', '(() => <App {...(arguments[0] || {})} />)').replace('"basename":"/"', '"basename":arguments[1] || "/"');
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { default } from "./
|
|
1
|
+
export { default } from "./runtime";
|
|
2
|
+
export * from "./runtime";
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
2
|
|
|
3
|
+
var _excluded = ["loadable"];
|
|
4
|
+
|
|
3
5
|
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
6
|
|
|
5
7
|
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
8
|
|
|
7
9
|
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
10
|
|
|
11
|
+
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; }
|
|
12
|
+
|
|
13
|
+
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; }
|
|
14
|
+
|
|
9
15
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
10
16
|
|
|
11
17
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
@@ -33,7 +39,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
33
39
|
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
34
40
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
35
41
|
export function Loadable(WrapComponent) {
|
|
36
|
-
return function (
|
|
42
|
+
return function (defaultLoadable) {
|
|
37
43
|
return /*#__PURE__*/function (_React$Component) {
|
|
38
44
|
_inherits(LoadableComponent, _React$Component);
|
|
39
45
|
|
|
@@ -50,9 +56,6 @@ export function Loadable(WrapComponent) {
|
|
|
50
56
|
|
|
51
57
|
_this = _super.call.apply(_super, [this].concat(args));
|
|
52
58
|
_this.state = {
|
|
53
|
-
LoadingComponent: defaultLoadingComponent,
|
|
54
|
-
timeout: 10000,
|
|
55
|
-
delay: 200,
|
|
56
59
|
error: null,
|
|
57
60
|
pastDelay: false,
|
|
58
61
|
timedOut: false,
|
|
@@ -82,17 +85,14 @@ export function Loadable(WrapComponent) {
|
|
|
82
85
|
var _this2 = this;
|
|
83
86
|
|
|
84
87
|
this.mounted = true;
|
|
85
|
-
var
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
var _this$state = this.state,
|
|
94
|
-
delay = _this$state.delay,
|
|
95
|
-
timeout = _this$state.timeout;
|
|
88
|
+
var _this$props$loadable = this.props.loadable,
|
|
89
|
+
loadable = _this$props$loadable === void 0 ? defaultLoadable || {
|
|
90
|
+
delay: 200,
|
|
91
|
+
timeout: 10000,
|
|
92
|
+
loading: null
|
|
93
|
+
} : _this$props$loadable;
|
|
94
|
+
var delay = loadable.delay,
|
|
95
|
+
timeout = loadable.timeout;
|
|
96
96
|
|
|
97
97
|
if (typeof delay === 'number') {
|
|
98
98
|
if (delay === 0) {
|
|
@@ -133,7 +133,6 @@ export function Loadable(WrapComponent) {
|
|
|
133
133
|
return;
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
-
logger('Loadable state', this.state);
|
|
137
136
|
this.setState(newState);
|
|
138
137
|
}
|
|
139
138
|
}, {
|
|
@@ -147,16 +146,31 @@ export function Loadable(WrapComponent) {
|
|
|
147
146
|
value: function render() {
|
|
148
147
|
var _this3 = this;
|
|
149
148
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
149
|
+
var _this$state = this.state,
|
|
150
|
+
isLoading = _this$state.isLoading,
|
|
151
|
+
error = _this$state.error,
|
|
152
|
+
pastDelay = _this$state.pastDelay,
|
|
153
|
+
timedOut = _this$state.timedOut;
|
|
154
|
+
|
|
155
|
+
var _this$props = this.props,
|
|
156
|
+
_this$props$loadable2 = _this$props.loadable,
|
|
157
|
+
loadable = _this$props$loadable2 === void 0 ? defaultLoadable || {
|
|
158
|
+
delay: 200,
|
|
159
|
+
timeout: 10000,
|
|
160
|
+
loading: null
|
|
161
|
+
} : _this$props$loadable2,
|
|
162
|
+
otherProps = _objectWithoutProperties(_this$props, _excluded);
|
|
163
|
+
|
|
164
|
+
var LoadingComponent = loadable.loading;
|
|
165
|
+
logger('Loadable render state', {
|
|
166
|
+
state: this.state,
|
|
167
|
+
props: otherProps,
|
|
168
|
+
loadable: loadable,
|
|
169
|
+
defaultLoadable: defaultLoadable
|
|
170
|
+
});
|
|
157
171
|
var showLoading = (isLoading || error) && LoadingComponent;
|
|
158
172
|
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
159
|
-
children: [showLoading &&
|
|
173
|
+
children: [showLoading && /*#__PURE__*/_jsx(LoadingComponent, {
|
|
160
174
|
isLoading: isLoading,
|
|
161
175
|
pastDelay: pastDelay,
|
|
162
176
|
timedOut: timedOut,
|
|
@@ -169,7 +183,7 @@ export function Loadable(WrapComponent) {
|
|
|
169
183
|
setLoadingState: function setLoadingState(props) {
|
|
170
184
|
return _this3.setStateWithMountCheck(props);
|
|
171
185
|
}
|
|
172
|
-
},
|
|
186
|
+
}, otherProps))]
|
|
173
187
|
});
|
|
174
188
|
}
|
|
175
189
|
}]);
|