@module-federation/sdk 0.19.1 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.cjs +400 -252
- package/dist/index.cjs.cjs.map +1 -1
- package/dist/index.esm.js +398 -253
- package/dist/index.esm.js.map +1 -1
- package/dist/normalize-webpack-path.cjs.cjs +15 -16
- package/dist/normalize-webpack-path.cjs.cjs.map +1 -1
- package/dist/normalize-webpack-path.esm.js +15 -16
- package/dist/normalize-webpack-path.esm.js.map +1 -1
- package/dist/src/constant.d.ts +3 -3
- package/dist/src/index.d.ts +2 -2
- package/dist/src/logger.d.ts +19 -3
- package/dist/src/types/plugins/ContainerPlugin.d.ts +2 -2
- package/dist/src/types/plugins/ModuleFederationPlugin.d.ts +2 -2
- package/package.json +1 -1
- package/dist/polyfills.cjs.cjs +0 -15
- package/dist/polyfills.cjs.cjs.map +0 -1
- package/dist/polyfills.esm.js +0 -13
- package/dist/polyfills.esm.js.map +0 -1
package/dist/index.esm.js
CHANGED
|
@@ -1,29 +1,27 @@
|
|
|
1
|
-
import { _ as _extends } from './polyfills.esm.js';
|
|
2
|
-
|
|
3
1
|
const FederationModuleManifest = 'federation-manifest.json';
|
|
4
2
|
const MANIFEST_EXT = '.json';
|
|
5
3
|
const BROWSER_LOG_KEY = 'FEDERATION_DEBUG';
|
|
6
4
|
const NameTransformSymbol = {
|
|
7
5
|
AT: '@',
|
|
8
6
|
HYPHEN: '-',
|
|
9
|
-
SLASH: '/'
|
|
7
|
+
SLASH: '/',
|
|
10
8
|
};
|
|
11
9
|
const NameTransformMap = {
|
|
12
10
|
[NameTransformSymbol.AT]: 'scope_',
|
|
13
11
|
[NameTransformSymbol.HYPHEN]: '_',
|
|
14
|
-
[NameTransformSymbol.SLASH]: '__'
|
|
12
|
+
[NameTransformSymbol.SLASH]: '__',
|
|
15
13
|
};
|
|
16
14
|
const EncodedNameTransformMap = {
|
|
17
15
|
[NameTransformMap[NameTransformSymbol.AT]]: NameTransformSymbol.AT,
|
|
18
16
|
[NameTransformMap[NameTransformSymbol.HYPHEN]]: NameTransformSymbol.HYPHEN,
|
|
19
|
-
[NameTransformMap[NameTransformSymbol.SLASH]]: NameTransformSymbol.SLASH
|
|
17
|
+
[NameTransformMap[NameTransformSymbol.SLASH]]: NameTransformSymbol.SLASH,
|
|
20
18
|
};
|
|
21
19
|
const SEPARATOR = ':';
|
|
22
20
|
const ManifestFileName = 'mf-manifest.json';
|
|
23
21
|
const StatsFileName = 'mf-stats.json';
|
|
24
22
|
const MFModuleType = {
|
|
25
23
|
NPM: 'npm',
|
|
26
|
-
APP: 'app'
|
|
24
|
+
APP: 'app',
|
|
27
25
|
};
|
|
28
26
|
const MODULE_DEVTOOL_IDENTIFIER = '__MF_DEVTOOLS_MODULE_INFO__';
|
|
29
27
|
const ENCODE_NAME_PREFIX = 'ENCODE_NAME_PREFIX';
|
|
@@ -33,13 +31,25 @@ const MFPrefetchCommon = {
|
|
|
33
31
|
globalKey: '__PREFETCH__',
|
|
34
32
|
library: 'mf-data-prefetch',
|
|
35
33
|
exportsKey: '__PREFETCH_EXPORTS__',
|
|
36
|
-
fileName: 'bootstrap.js'
|
|
34
|
+
fileName: 'bootstrap.js',
|
|
37
35
|
};
|
|
38
36
|
|
|
37
|
+
/*
|
|
38
|
+
* This file was automatically generated.
|
|
39
|
+
* DO NOT MODIFY BY HAND.
|
|
40
|
+
* Run `yarn special-lint-fix` to update
|
|
41
|
+
*/
|
|
42
|
+
|
|
39
43
|
var ContainerPlugin = /*#__PURE__*/Object.freeze({
|
|
40
44
|
__proto__: null
|
|
41
45
|
});
|
|
42
46
|
|
|
47
|
+
/*
|
|
48
|
+
* This file was automatically generated.
|
|
49
|
+
* DO NOT MODIFY BY HAND.
|
|
50
|
+
* Run `yarn special-lint-fix` to update
|
|
51
|
+
*/
|
|
52
|
+
|
|
43
53
|
var ContainerReferencePlugin = /*#__PURE__*/Object.freeze({
|
|
44
54
|
__proto__: null
|
|
45
55
|
});
|
|
@@ -48,29 +58,37 @@ var ModuleFederationPlugin = /*#__PURE__*/Object.freeze({
|
|
|
48
58
|
__proto__: null
|
|
49
59
|
});
|
|
50
60
|
|
|
61
|
+
/*
|
|
62
|
+
* This file was automatically generated.
|
|
63
|
+
* DO NOT MODIFY BY HAND.
|
|
64
|
+
* Run `yarn special-lint-fix` to update
|
|
65
|
+
*/
|
|
66
|
+
|
|
51
67
|
var SharePlugin = /*#__PURE__*/Object.freeze({
|
|
52
68
|
__proto__: null
|
|
53
69
|
});
|
|
54
70
|
|
|
55
71
|
function isBrowserEnv() {
|
|
56
|
-
return typeof window !== 'undefined' && typeof window.document !== 'undefined';
|
|
72
|
+
return (typeof window !== 'undefined' && typeof window.document !== 'undefined');
|
|
57
73
|
}
|
|
58
74
|
function isReactNativeEnv() {
|
|
59
|
-
|
|
60
|
-
return typeof navigator !== 'undefined' && ((_navigator = navigator) == null ? void 0 : _navigator.product) === 'ReactNative';
|
|
75
|
+
return (typeof navigator !== 'undefined' && navigator?.product === 'ReactNative');
|
|
61
76
|
}
|
|
62
77
|
function isBrowserDebug() {
|
|
63
78
|
try {
|
|
64
79
|
if (isBrowserEnv() && window.localStorage) {
|
|
65
80
|
return Boolean(localStorage.getItem(BROWSER_LOG_KEY));
|
|
66
81
|
}
|
|
67
|
-
}
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
68
84
|
return false;
|
|
69
85
|
}
|
|
70
86
|
return false;
|
|
71
87
|
}
|
|
72
88
|
function isDebugMode() {
|
|
73
|
-
if (typeof process !== 'undefined' &&
|
|
89
|
+
if (typeof process !== 'undefined' &&
|
|
90
|
+
process.env &&
|
|
91
|
+
process.env['FEDERATION_DEBUG']) {
|
|
74
92
|
return Boolean(process.env['FEDERATION_DEBUG']);
|
|
75
93
|
}
|
|
76
94
|
if (typeof FEDERATION_DEBUG !== 'undefined' && Boolean(FEDERATION_DEBUG)) {
|
|
@@ -78,18 +96,18 @@ function isDebugMode() {
|
|
|
78
96
|
}
|
|
79
97
|
return isBrowserDebug();
|
|
80
98
|
}
|
|
81
|
-
const getProcessEnv = function() {
|
|
99
|
+
const getProcessEnv = function () {
|
|
82
100
|
return typeof process !== 'undefined' && process.env ? process.env : {};
|
|
83
101
|
};
|
|
84
102
|
|
|
85
103
|
const LOG_CATEGORY = '[ Federation Runtime ]';
|
|
86
104
|
// entry: name:version version : 1.0.0 | ^1.2.3
|
|
87
105
|
// entry: name:entry entry: https://localhost:9000/federation-manifest.json
|
|
88
|
-
const parseEntry = (str, devVerOrUrl, separator = SEPARATOR)=>{
|
|
106
|
+
const parseEntry = (str, devVerOrUrl, separator = SEPARATOR) => {
|
|
89
107
|
const strSplit = str.split(separator);
|
|
90
108
|
const devVersionOrUrl = getProcessEnv()['NODE_ENV'] === 'development' && devVerOrUrl;
|
|
91
109
|
const defaultVersion = '*';
|
|
92
|
-
const isEntry = (s)=>s.startsWith('http') || s.includes(MANIFEST_EXT);
|
|
110
|
+
const isEntry = (s) => s.startsWith('http') || s.includes(MANIFEST_EXT);
|
|
93
111
|
// Check if the string starts with a type
|
|
94
112
|
if (strSplit.length >= 2) {
|
|
95
113
|
let [name, ...versionOrEntryArr] = strSplit;
|
|
@@ -97,44 +115,47 @@ const parseEntry = (str, devVerOrUrl, separator = SEPARATOR)=>{
|
|
|
97
115
|
if (str.startsWith(separator)) {
|
|
98
116
|
name = strSplit.slice(0, 2).join(separator);
|
|
99
117
|
versionOrEntryArr = [
|
|
100
|
-
devVersionOrUrl || strSplit.slice(2).join(separator)
|
|
118
|
+
devVersionOrUrl || strSplit.slice(2).join(separator),
|
|
101
119
|
];
|
|
102
120
|
}
|
|
103
121
|
let versionOrEntry = devVersionOrUrl || versionOrEntryArr.join(separator);
|
|
104
122
|
if (isEntry(versionOrEntry)) {
|
|
105
123
|
return {
|
|
106
124
|
name,
|
|
107
|
-
entry: versionOrEntry
|
|
125
|
+
entry: versionOrEntry,
|
|
108
126
|
};
|
|
109
|
-
}
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
110
129
|
// Apply version rule
|
|
111
130
|
// devVersionOrUrl => inputVersion => defaultVersion
|
|
112
131
|
return {
|
|
113
132
|
name,
|
|
114
|
-
version: versionOrEntry || defaultVersion
|
|
133
|
+
version: versionOrEntry || defaultVersion,
|
|
115
134
|
};
|
|
116
135
|
}
|
|
117
|
-
}
|
|
136
|
+
}
|
|
137
|
+
else if (strSplit.length === 1) {
|
|
118
138
|
const [name] = strSplit;
|
|
119
139
|
if (devVersionOrUrl && isEntry(devVersionOrUrl)) {
|
|
120
140
|
return {
|
|
121
141
|
name,
|
|
122
|
-
entry: devVersionOrUrl
|
|
142
|
+
entry: devVersionOrUrl,
|
|
123
143
|
};
|
|
124
144
|
}
|
|
125
145
|
return {
|
|
126
146
|
name,
|
|
127
|
-
version: devVersionOrUrl || defaultVersion
|
|
147
|
+
version: devVersionOrUrl || defaultVersion,
|
|
128
148
|
};
|
|
129
|
-
}
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
130
151
|
throw `Invalid entry value: ${str}`;
|
|
131
152
|
}
|
|
132
153
|
};
|
|
133
|
-
const composeKeyWithSeparator = function(...args) {
|
|
154
|
+
const composeKeyWithSeparator = function (...args) {
|
|
134
155
|
if (!args.length) {
|
|
135
156
|
return '';
|
|
136
157
|
}
|
|
137
|
-
return args.reduce((sum, cur)=>{
|
|
158
|
+
return args.reduce((sum, cur) => {
|
|
138
159
|
if (!cur) {
|
|
139
160
|
return sum;
|
|
140
161
|
}
|
|
@@ -144,15 +165,19 @@ const composeKeyWithSeparator = function(...args) {
|
|
|
144
165
|
return `${sum}${SEPARATOR}${cur}`;
|
|
145
166
|
}, '');
|
|
146
167
|
};
|
|
147
|
-
const encodeName = function(name, prefix = '', withExt = false) {
|
|
168
|
+
const encodeName = function (name, prefix = '', withExt = false) {
|
|
148
169
|
try {
|
|
149
170
|
const ext = withExt ? '.js' : '';
|
|
150
|
-
return `${prefix}${name
|
|
151
|
-
|
|
171
|
+
return `${prefix}${name
|
|
172
|
+
.replace(new RegExp(`${NameTransformSymbol.AT}`, 'g'), NameTransformMap[NameTransformSymbol.AT])
|
|
173
|
+
.replace(new RegExp(`${NameTransformSymbol.HYPHEN}`, 'g'), NameTransformMap[NameTransformSymbol.HYPHEN])
|
|
174
|
+
.replace(new RegExp(`${NameTransformSymbol.SLASH}`, 'g'), NameTransformMap[NameTransformSymbol.SLASH])}${ext}`;
|
|
175
|
+
}
|
|
176
|
+
catch (err) {
|
|
152
177
|
throw err;
|
|
153
178
|
}
|
|
154
179
|
};
|
|
155
|
-
const decodeName = function(name, prefix, withExt) {
|
|
180
|
+
const decodeName = function (name, prefix, withExt) {
|
|
156
181
|
try {
|
|
157
182
|
let decodedName = name;
|
|
158
183
|
if (prefix) {
|
|
@@ -161,16 +186,20 @@ const decodeName = function(name, prefix, withExt) {
|
|
|
161
186
|
}
|
|
162
187
|
decodedName = decodedName.replace(new RegExp(prefix, 'g'), '');
|
|
163
188
|
}
|
|
164
|
-
decodedName = decodedName
|
|
189
|
+
decodedName = decodedName
|
|
190
|
+
.replace(new RegExp(`${NameTransformMap[NameTransformSymbol.AT]}`, 'g'), EncodedNameTransformMap[NameTransformMap[NameTransformSymbol.AT]])
|
|
191
|
+
.replace(new RegExp(`${NameTransformMap[NameTransformSymbol.SLASH]}`, 'g'), EncodedNameTransformMap[NameTransformMap[NameTransformSymbol.SLASH]])
|
|
192
|
+
.replace(new RegExp(`${NameTransformMap[NameTransformSymbol.HYPHEN]}`, 'g'), EncodedNameTransformMap[NameTransformMap[NameTransformSymbol.HYPHEN]]);
|
|
165
193
|
if (withExt) {
|
|
166
194
|
decodedName = decodedName.replace('.js', '');
|
|
167
195
|
}
|
|
168
196
|
return decodedName;
|
|
169
|
-
}
|
|
197
|
+
}
|
|
198
|
+
catch (err) {
|
|
170
199
|
throw err;
|
|
171
200
|
}
|
|
172
201
|
};
|
|
173
|
-
const generateExposeFilename = (exposeName, withExt)=>{
|
|
202
|
+
const generateExposeFilename = (exposeName, withExt) => {
|
|
174
203
|
if (!exposeName) {
|
|
175
204
|
return '';
|
|
176
205
|
}
|
|
@@ -183,47 +212,51 @@ const generateExposeFilename = (exposeName, withExt)=>{
|
|
|
183
212
|
}
|
|
184
213
|
return encodeName(expose, '__federation_expose_', withExt);
|
|
185
214
|
};
|
|
186
|
-
const generateShareFilename = (pkgName, withExt)=>{
|
|
215
|
+
const generateShareFilename = (pkgName, withExt) => {
|
|
187
216
|
if (!pkgName) {
|
|
188
217
|
return '';
|
|
189
218
|
}
|
|
190
219
|
return encodeName(pkgName, '__federation_shared_', withExt);
|
|
191
220
|
};
|
|
192
|
-
const getResourceUrl = (module, sourceUrl)=>{
|
|
221
|
+
const getResourceUrl = (module, sourceUrl) => {
|
|
193
222
|
if ('getPublicPath' in module) {
|
|
194
223
|
let publicPath;
|
|
195
224
|
if (!module.getPublicPath.startsWith('function')) {
|
|
196
225
|
publicPath = new Function(module.getPublicPath)();
|
|
197
|
-
}
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
198
228
|
publicPath = new Function('return ' + module.getPublicPath)()();
|
|
199
229
|
}
|
|
200
230
|
return `${publicPath}${sourceUrl}`;
|
|
201
|
-
}
|
|
231
|
+
}
|
|
232
|
+
else if ('publicPath' in module) {
|
|
202
233
|
if (!isBrowserEnv() && !isReactNativeEnv() && 'ssrPublicPath' in module) {
|
|
203
234
|
return `${module.ssrPublicPath}${sourceUrl}`;
|
|
204
235
|
}
|
|
205
236
|
return `${module.publicPath}${sourceUrl}`;
|
|
206
|
-
}
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
207
239
|
console.warn('Cannot get resource URL. If in debug mode, please ignore.', module, sourceUrl);
|
|
208
240
|
return '';
|
|
209
241
|
}
|
|
210
242
|
};
|
|
211
243
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
212
|
-
const assert = (condition, msg)=>{
|
|
244
|
+
const assert = (condition, msg) => {
|
|
213
245
|
if (!condition) {
|
|
214
246
|
error(msg);
|
|
215
247
|
}
|
|
216
248
|
};
|
|
217
|
-
const error = (msg)=>{
|
|
249
|
+
const error = (msg) => {
|
|
218
250
|
throw new Error(`${LOG_CATEGORY}: ${msg}`);
|
|
219
251
|
};
|
|
220
|
-
const warn = (msg)=>{
|
|
252
|
+
const warn = (msg) => {
|
|
221
253
|
console.warn(`${LOG_CATEGORY}: ${msg}`);
|
|
222
254
|
};
|
|
223
255
|
function safeToString(info) {
|
|
224
256
|
try {
|
|
225
257
|
return JSON.stringify(info, null, 2);
|
|
226
|
-
}
|
|
258
|
+
}
|
|
259
|
+
catch (e) {
|
|
227
260
|
return '';
|
|
228
261
|
}
|
|
229
262
|
}
|
|
@@ -233,11 +266,11 @@ function isRequiredVersion(str) {
|
|
|
233
266
|
return VERSION_PATTERN_REGEXP.test(str);
|
|
234
267
|
}
|
|
235
268
|
|
|
236
|
-
const simpleJoinRemoteEntry = (rPath, rName)=>{
|
|
269
|
+
const simpleJoinRemoteEntry = (rPath, rName) => {
|
|
237
270
|
if (!rPath) {
|
|
238
271
|
return rName;
|
|
239
272
|
}
|
|
240
|
-
const transformPath = (str)=>{
|
|
273
|
+
const transformPath = (str) => {
|
|
241
274
|
if (str === '.') {
|
|
242
275
|
return '';
|
|
243
276
|
}
|
|
@@ -263,22 +296,25 @@ const simpleJoinRemoteEntry = (rPath, rName)=>{
|
|
|
263
296
|
return `${transformedPath}/${rName}`;
|
|
264
297
|
};
|
|
265
298
|
function inferAutoPublicPath(url) {
|
|
266
|
-
return url
|
|
299
|
+
return url
|
|
300
|
+
.replace(/#.*$/, '')
|
|
301
|
+
.replace(/\?.*$/, '')
|
|
302
|
+
.replace(/\/[^\/]+$/, '/');
|
|
267
303
|
}
|
|
268
304
|
// Priority: overrides > remotes
|
|
269
305
|
// eslint-disable-next-line max-lines-per-function
|
|
270
306
|
function generateSnapshotFromManifest(manifest, options = {}) {
|
|
271
|
-
var _manifest_metaData, _manifest_metaData1;
|
|
272
307
|
const { remotes = {}, overrides = {}, version } = options;
|
|
273
308
|
let remoteSnapshot;
|
|
274
|
-
const getPublicPath = ()=>{
|
|
309
|
+
const getPublicPath = () => {
|
|
275
310
|
if ('publicPath' in manifest.metaData) {
|
|
276
311
|
if (manifest.metaData.publicPath === 'auto' && version) {
|
|
277
312
|
// use same implementation as publicPath auto runtime module implements
|
|
278
313
|
return inferAutoPublicPath(version);
|
|
279
314
|
}
|
|
280
315
|
return manifest.metaData.publicPath;
|
|
281
|
-
}
|
|
316
|
+
}
|
|
317
|
+
else {
|
|
282
318
|
return manifest.metaData.getPublicPath;
|
|
283
319
|
}
|
|
284
320
|
};
|
|
@@ -286,32 +322,36 @@ function generateSnapshotFromManifest(manifest, options = {}) {
|
|
|
286
322
|
let remotesInfo = {};
|
|
287
323
|
// If remotes are not provided, only the remotes in the manifest will be read
|
|
288
324
|
if (!Object.keys(remotes).length) {
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
} else {
|
|
297
|
-
if ('version' in next) {
|
|
298
|
-
matchedVersion = next.version;
|
|
299
|
-
} else {
|
|
300
|
-
matchedVersion = next.entry;
|
|
325
|
+
remotesInfo =
|
|
326
|
+
manifest.remotes?.reduce((res, next) => {
|
|
327
|
+
let matchedVersion;
|
|
328
|
+
const name = next.federationContainerName;
|
|
329
|
+
// overrides have higher priority
|
|
330
|
+
if (overridesKeys.includes(name)) {
|
|
331
|
+
matchedVersion = overrides[name];
|
|
301
332
|
}
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
333
|
+
else {
|
|
334
|
+
if ('version' in next) {
|
|
335
|
+
matchedVersion = next.version;
|
|
336
|
+
}
|
|
337
|
+
else {
|
|
338
|
+
matchedVersion = next.entry;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
res[name] = {
|
|
342
|
+
matchedVersion,
|
|
343
|
+
};
|
|
344
|
+
return res;
|
|
345
|
+
}, {}) || {};
|
|
308
346
|
}
|
|
309
347
|
// If remotes (deploy scenario) are specified, they need to be traversed again
|
|
310
|
-
Object.keys(remotes).forEach((key)=>remotesInfo[key] = {
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
348
|
+
Object.keys(remotes).forEach((key) => (remotesInfo[key] = {
|
|
349
|
+
// overrides will override dependencies
|
|
350
|
+
matchedVersion: overridesKeys.includes(key)
|
|
351
|
+
? overrides[key]
|
|
352
|
+
: remotes[key],
|
|
353
|
+
}));
|
|
354
|
+
const { remoteEntry: { path: remoteEntryPath, name: remoteEntryName, type: remoteEntryType, }, types: remoteTypes, buildInfo: { buildVersion }, globalName, ssrRemoteEntry, } = manifest.metaData;
|
|
315
355
|
const { exposes } = manifest;
|
|
316
356
|
let basicRemoteSnapshot = {
|
|
317
357
|
version: version ? version : '',
|
|
@@ -323,98 +363,178 @@ function generateSnapshotFromManifest(manifest, options = {}) {
|
|
|
323
363
|
remoteTypesZip: remoteTypes.zip || '',
|
|
324
364
|
remoteTypesAPI: remoteTypes.api || '',
|
|
325
365
|
remotesInfo,
|
|
326
|
-
shared: manifest
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
modules: exposes
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
366
|
+
shared: manifest?.shared.map((item) => ({
|
|
367
|
+
assets: item.assets,
|
|
368
|
+
sharedName: item.name,
|
|
369
|
+
version: item.version,
|
|
370
|
+
})),
|
|
371
|
+
modules: exposes?.map((expose) => ({
|
|
372
|
+
moduleName: expose.name,
|
|
373
|
+
modulePath: expose.path,
|
|
374
|
+
assets: expose.assets,
|
|
375
|
+
})),
|
|
336
376
|
};
|
|
337
|
-
if (
|
|
377
|
+
if (manifest.metaData?.prefetchInterface) {
|
|
338
378
|
const prefetchInterface = manifest.metaData.prefetchInterface;
|
|
339
|
-
basicRemoteSnapshot =
|
|
340
|
-
|
|
341
|
-
|
|
379
|
+
basicRemoteSnapshot = {
|
|
380
|
+
...basicRemoteSnapshot,
|
|
381
|
+
prefetchInterface,
|
|
382
|
+
};
|
|
342
383
|
}
|
|
343
|
-
if (
|
|
384
|
+
if (manifest.metaData?.prefetchEntry) {
|
|
344
385
|
const { path, name, type } = manifest.metaData.prefetchEntry;
|
|
345
|
-
basicRemoteSnapshot =
|
|
386
|
+
basicRemoteSnapshot = {
|
|
387
|
+
...basicRemoteSnapshot,
|
|
346
388
|
prefetchEntry: simpleJoinRemoteEntry(path, name),
|
|
347
|
-
prefetchEntryType: type
|
|
348
|
-
}
|
|
389
|
+
prefetchEntryType: type,
|
|
390
|
+
};
|
|
349
391
|
}
|
|
350
392
|
if ('publicPath' in manifest.metaData) {
|
|
351
|
-
remoteSnapshot =
|
|
393
|
+
remoteSnapshot = {
|
|
394
|
+
...basicRemoteSnapshot,
|
|
352
395
|
publicPath: getPublicPath(),
|
|
353
|
-
ssrPublicPath: manifest.metaData.ssrPublicPath
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
396
|
+
ssrPublicPath: manifest.metaData.ssrPublicPath,
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
else {
|
|
400
|
+
remoteSnapshot = {
|
|
401
|
+
...basicRemoteSnapshot,
|
|
402
|
+
getPublicPath: getPublicPath(),
|
|
403
|
+
};
|
|
359
404
|
}
|
|
360
405
|
if (ssrRemoteEntry) {
|
|
361
406
|
const fullSSRRemoteEntry = simpleJoinRemoteEntry(ssrRemoteEntry.path, ssrRemoteEntry.name);
|
|
362
407
|
remoteSnapshot.ssrRemoteEntry = fullSSRRemoteEntry;
|
|
363
|
-
remoteSnapshot.ssrRemoteEntryType =
|
|
408
|
+
remoteSnapshot.ssrRemoteEntryType =
|
|
409
|
+
ssrRemoteEntry.type || 'commonjs-module';
|
|
364
410
|
}
|
|
365
411
|
return remoteSnapshot;
|
|
366
412
|
}
|
|
367
413
|
function isManifestProvider(moduleInfo) {
|
|
368
|
-
if ('remoteEntry' in moduleInfo &&
|
|
414
|
+
if ('remoteEntry' in moduleInfo &&
|
|
415
|
+
moduleInfo.remoteEntry.includes(MANIFEST_EXT)) {
|
|
369
416
|
return true;
|
|
370
|
-
}
|
|
417
|
+
}
|
|
418
|
+
else {
|
|
371
419
|
return false;
|
|
372
420
|
}
|
|
373
421
|
}
|
|
374
422
|
|
|
375
423
|
const PREFIX = '[ Module Federation ]';
|
|
376
|
-
|
|
424
|
+
const DEFAULT_DELEGATE = console;
|
|
425
|
+
class Logger {
|
|
426
|
+
constructor(prefix, delegate = DEFAULT_DELEGATE) {
|
|
427
|
+
this.prefix = prefix;
|
|
428
|
+
this.delegate = delegate ?? DEFAULT_DELEGATE;
|
|
429
|
+
}
|
|
377
430
|
setPrefix(prefix) {
|
|
378
431
|
this.prefix = prefix;
|
|
379
432
|
}
|
|
433
|
+
setDelegate(delegate) {
|
|
434
|
+
this.delegate = delegate ?? DEFAULT_DELEGATE;
|
|
435
|
+
}
|
|
436
|
+
emit(method, args) {
|
|
437
|
+
const delegate = this.delegate;
|
|
438
|
+
const order = (() => {
|
|
439
|
+
switch (method) {
|
|
440
|
+
case 'log':
|
|
441
|
+
return ['log', 'info'];
|
|
442
|
+
case 'info':
|
|
443
|
+
return ['info', 'log'];
|
|
444
|
+
case 'warn':
|
|
445
|
+
return ['warn', 'info', 'log'];
|
|
446
|
+
case 'error':
|
|
447
|
+
return ['error', 'warn', 'log'];
|
|
448
|
+
case 'debug':
|
|
449
|
+
default:
|
|
450
|
+
return ['debug', 'log'];
|
|
451
|
+
}
|
|
452
|
+
})();
|
|
453
|
+
for (const candidate of order) {
|
|
454
|
+
const handler = delegate[candidate];
|
|
455
|
+
if (typeof handler === 'function') {
|
|
456
|
+
handler.call(delegate, this.prefix, ...args);
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
for (const candidate of order) {
|
|
461
|
+
const handler = DEFAULT_DELEGATE[candidate];
|
|
462
|
+
if (typeof handler === 'function') {
|
|
463
|
+
handler.call(DEFAULT_DELEGATE, this.prefix, ...args);
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
}
|
|
380
468
|
log(...args) {
|
|
381
|
-
|
|
469
|
+
this.emit('log', args);
|
|
382
470
|
}
|
|
383
471
|
warn(...args) {
|
|
384
|
-
|
|
472
|
+
this.emit('warn', args);
|
|
385
473
|
}
|
|
386
474
|
error(...args) {
|
|
387
|
-
|
|
475
|
+
this.emit('error', args);
|
|
388
476
|
}
|
|
389
477
|
success(...args) {
|
|
390
|
-
|
|
478
|
+
this.emit('info', args);
|
|
391
479
|
}
|
|
392
480
|
info(...args) {
|
|
393
|
-
|
|
481
|
+
this.emit('info', args);
|
|
394
482
|
}
|
|
395
483
|
ready(...args) {
|
|
396
|
-
|
|
484
|
+
this.emit('info', args);
|
|
397
485
|
}
|
|
398
486
|
debug(...args) {
|
|
399
487
|
if (isDebugMode()) {
|
|
400
|
-
|
|
488
|
+
this.emit('debug', args);
|
|
401
489
|
}
|
|
402
490
|
}
|
|
403
|
-
|
|
404
|
-
this.prefix = prefix;
|
|
405
|
-
}
|
|
406
|
-
};
|
|
491
|
+
}
|
|
407
492
|
function createLogger(prefix) {
|
|
408
493
|
return new Logger(prefix);
|
|
409
494
|
}
|
|
495
|
+
function createInfrastructureLogger(prefix) {
|
|
496
|
+
const infrastructureLogger = new Logger(prefix);
|
|
497
|
+
Object.defineProperty(infrastructureLogger, '__mf_infrastructure_logger__', {
|
|
498
|
+
value: true,
|
|
499
|
+
enumerable: false,
|
|
500
|
+
configurable: false,
|
|
501
|
+
});
|
|
502
|
+
return infrastructureLogger;
|
|
503
|
+
}
|
|
504
|
+
function bindLoggerToCompiler(loggerInstance, compiler, name) {
|
|
505
|
+
if (!loggerInstance
|
|
506
|
+
.__mf_infrastructure_logger__) {
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
if (!compiler?.getInfrastructureLogger) {
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
512
|
+
try {
|
|
513
|
+
const infrastructureLogger = compiler.getInfrastructureLogger(name);
|
|
514
|
+
if (infrastructureLogger &&
|
|
515
|
+
typeof infrastructureLogger === 'object' &&
|
|
516
|
+
(typeof infrastructureLogger.log === 'function' ||
|
|
517
|
+
typeof infrastructureLogger.info === 'function' ||
|
|
518
|
+
typeof infrastructureLogger.warn === 'function' ||
|
|
519
|
+
typeof infrastructureLogger.error === 'function')) {
|
|
520
|
+
loggerInstance.setDelegate(infrastructureLogger);
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
catch {
|
|
524
|
+
// If the bundler throws (older versions), fall back to default console logger.
|
|
525
|
+
loggerInstance.setDelegate(undefined);
|
|
526
|
+
}
|
|
527
|
+
}
|
|
410
528
|
const logger = createLogger(PREFIX);
|
|
529
|
+
const infrastructureLogger = createInfrastructureLogger(PREFIX);
|
|
411
530
|
|
|
412
531
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
413
532
|
async function safeWrapper(callback, disableWarn) {
|
|
414
533
|
try {
|
|
415
534
|
const res = await callback();
|
|
416
535
|
return res;
|
|
417
|
-
}
|
|
536
|
+
}
|
|
537
|
+
catch (e) {
|
|
418
538
|
!disableWarn && warn(e);
|
|
419
539
|
return;
|
|
420
540
|
}
|
|
@@ -434,7 +554,7 @@ function createScript(info) {
|
|
|
434
554
|
let timeout = 20000;
|
|
435
555
|
let timeoutId;
|
|
436
556
|
const scripts = document.getElementsByTagName('script');
|
|
437
|
-
for(let i = 0; i < scripts.length; i++){
|
|
557
|
+
for (let i = 0; i < scripts.length; i++) {
|
|
438
558
|
const s = scripts[i];
|
|
439
559
|
const scriptSrc = s.getAttribute('src');
|
|
440
560
|
if (scriptSrc && isStaticResourcesEqual(scriptSrc, info.url)) {
|
|
@@ -446,13 +566,14 @@ function createScript(info) {
|
|
|
446
566
|
if (!script) {
|
|
447
567
|
const attrs = info.attrs;
|
|
448
568
|
script = document.createElement('script');
|
|
449
|
-
script.type =
|
|
569
|
+
script.type = attrs?.['type'] === 'module' ? 'module' : 'text/javascript';
|
|
450
570
|
let createScriptRes = undefined;
|
|
451
571
|
if (info.createScriptHook) {
|
|
452
572
|
createScriptRes = info.createScriptHook(info.url, info.attrs);
|
|
453
573
|
if (createScriptRes instanceof HTMLScriptElement) {
|
|
454
574
|
script = createScriptRes;
|
|
455
|
-
}
|
|
575
|
+
}
|
|
576
|
+
else if (typeof createScriptRes === 'object') {
|
|
456
577
|
if ('script' in createScriptRes && createScriptRes.script) {
|
|
457
578
|
script = createScriptRes.script;
|
|
458
579
|
}
|
|
@@ -465,36 +586,39 @@ function createScript(info) {
|
|
|
465
586
|
script.src = info.url;
|
|
466
587
|
}
|
|
467
588
|
if (attrs && !createScriptRes) {
|
|
468
|
-
Object.keys(attrs).forEach((name)=>{
|
|
589
|
+
Object.keys(attrs).forEach((name) => {
|
|
469
590
|
if (script) {
|
|
470
591
|
if (name === 'async' || name === 'defer') {
|
|
471
592
|
script[name] = attrs[name];
|
|
472
|
-
|
|
473
|
-
}
|
|
593
|
+
// Attributes that do not exist are considered overridden
|
|
594
|
+
}
|
|
595
|
+
else if (!script.getAttribute(name)) {
|
|
474
596
|
script.setAttribute(name, attrs[name]);
|
|
475
597
|
}
|
|
476
598
|
}
|
|
477
599
|
});
|
|
478
600
|
}
|
|
479
601
|
}
|
|
480
|
-
const onScriptComplete = async (prev,
|
|
481
|
-
|
|
602
|
+
const onScriptComplete = async (prev,
|
|
603
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
604
|
+
event) => {
|
|
482
605
|
clearTimeout(timeoutId);
|
|
483
|
-
const onScriptCompleteCallback = ()=>{
|
|
484
|
-
if (
|
|
485
|
-
|
|
486
|
-
}
|
|
487
|
-
|
|
606
|
+
const onScriptCompleteCallback = () => {
|
|
607
|
+
if (event?.type === 'error') {
|
|
608
|
+
info?.onErrorCallback && info?.onErrorCallback(event);
|
|
609
|
+
}
|
|
610
|
+
else {
|
|
611
|
+
info?.cb && info?.cb();
|
|
488
612
|
}
|
|
489
613
|
};
|
|
490
614
|
// Prevent memory leaks in IE.
|
|
491
615
|
if (script) {
|
|
492
616
|
script.onerror = null;
|
|
493
617
|
script.onload = null;
|
|
494
|
-
safeWrapper(()=>{
|
|
618
|
+
safeWrapper(() => {
|
|
495
619
|
const { needDeleteScript = true } = info;
|
|
496
620
|
if (needDeleteScript) {
|
|
497
|
-
|
|
621
|
+
script?.parentNode && script.parentNode.removeChild(script);
|
|
498
622
|
}
|
|
499
623
|
});
|
|
500
624
|
if (prev && typeof prev === 'function') {
|
|
@@ -512,13 +636,10 @@ function createScript(info) {
|
|
|
512
636
|
};
|
|
513
637
|
script.onerror = onScriptComplete.bind(null, script.onerror);
|
|
514
638
|
script.onload = onScriptComplete.bind(null, script.onload);
|
|
515
|
-
timeoutId = setTimeout(()=>{
|
|
639
|
+
timeoutId = setTimeout(() => {
|
|
516
640
|
onScriptComplete(null, new Error(`Remote script "${info.url}" time-outed.`));
|
|
517
641
|
}, timeout);
|
|
518
|
-
return {
|
|
519
|
-
script,
|
|
520
|
-
needAttach
|
|
521
|
-
};
|
|
642
|
+
return { script, needAttach };
|
|
522
643
|
}
|
|
523
644
|
function createLink(info) {
|
|
524
645
|
// <link rel="preload" href="script.js" as="script">
|
|
@@ -526,11 +647,13 @@ function createLink(info) {
|
|
|
526
647
|
let link = null;
|
|
527
648
|
let needAttach = true;
|
|
528
649
|
const links = document.getElementsByTagName('link');
|
|
529
|
-
for(let i = 0; i < links.length; i++){
|
|
650
|
+
for (let i = 0; i < links.length; i++) {
|
|
530
651
|
const l = links[i];
|
|
531
652
|
const linkHref = l.getAttribute('href');
|
|
532
653
|
const linkRel = l.getAttribute('rel');
|
|
533
|
-
if (linkHref &&
|
|
654
|
+
if (linkHref &&
|
|
655
|
+
isStaticResourcesEqual(linkHref, info.url) &&
|
|
656
|
+
linkRel === info.attrs['rel']) {
|
|
534
657
|
link = l;
|
|
535
658
|
needAttach = false;
|
|
536
659
|
break;
|
|
@@ -548,30 +671,32 @@ function createLink(info) {
|
|
|
548
671
|
}
|
|
549
672
|
}
|
|
550
673
|
if (attrs && !createLinkRes) {
|
|
551
|
-
Object.keys(attrs).forEach((name)=>{
|
|
674
|
+
Object.keys(attrs).forEach((name) => {
|
|
552
675
|
if (link && !link.getAttribute(name)) {
|
|
553
676
|
link.setAttribute(name, attrs[name]);
|
|
554
677
|
}
|
|
555
678
|
});
|
|
556
679
|
}
|
|
557
680
|
}
|
|
558
|
-
const onLinkComplete = (prev,
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
681
|
+
const onLinkComplete = (prev,
|
|
682
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
683
|
+
event) => {
|
|
684
|
+
const onLinkCompleteCallback = () => {
|
|
685
|
+
if (event?.type === 'error') {
|
|
686
|
+
info?.onErrorCallback && info?.onErrorCallback(event);
|
|
687
|
+
}
|
|
688
|
+
else {
|
|
689
|
+
info?.cb && info?.cb();
|
|
565
690
|
}
|
|
566
691
|
};
|
|
567
692
|
// Prevent memory leaks in IE.
|
|
568
693
|
if (link) {
|
|
569
694
|
link.onerror = null;
|
|
570
695
|
link.onload = null;
|
|
571
|
-
safeWrapper(()=>{
|
|
696
|
+
safeWrapper(() => {
|
|
572
697
|
const { needDeleteLink = true } = info;
|
|
573
698
|
if (needDeleteLink) {
|
|
574
|
-
|
|
699
|
+
link?.parentNode && link.parentNode.removeChild(link);
|
|
575
700
|
}
|
|
576
701
|
});
|
|
577
702
|
if (prev) {
|
|
@@ -585,23 +710,21 @@ function createLink(info) {
|
|
|
585
710
|
};
|
|
586
711
|
link.onerror = onLinkComplete.bind(null, link.onerror);
|
|
587
712
|
link.onload = onLinkComplete.bind(null, link.onload);
|
|
588
|
-
return {
|
|
589
|
-
link,
|
|
590
|
-
needAttach
|
|
591
|
-
};
|
|
713
|
+
return { link, needAttach };
|
|
592
714
|
}
|
|
593
715
|
function loadScript(url, info) {
|
|
594
716
|
const { attrs = {}, createScriptHook } = info;
|
|
595
|
-
return new Promise((resolve, reject)=>{
|
|
717
|
+
return new Promise((resolve, reject) => {
|
|
596
718
|
const { script, needAttach } = createScript({
|
|
597
719
|
url,
|
|
598
720
|
cb: resolve,
|
|
599
721
|
onErrorCallback: reject,
|
|
600
|
-
attrs:
|
|
601
|
-
fetchpriority: 'high'
|
|
602
|
-
|
|
722
|
+
attrs: {
|
|
723
|
+
fetchpriority: 'high',
|
|
724
|
+
...attrs,
|
|
725
|
+
},
|
|
603
726
|
createScriptHook,
|
|
604
|
-
needDeleteScript: true
|
|
727
|
+
needDeleteScript: true,
|
|
605
728
|
});
|
|
606
729
|
needAttach && document.head.appendChild(script);
|
|
607
730
|
});
|
|
@@ -617,7 +740,9 @@ function importNodeModule(name) {
|
|
|
617
740
|
return sdkImportCache.get(name);
|
|
618
741
|
}
|
|
619
742
|
const importModule = new Function('name', `return import(name)`);
|
|
620
|
-
const promise = importModule(name)
|
|
743
|
+
const promise = importModule(name)
|
|
744
|
+
.then((res) => res)
|
|
745
|
+
.catch((error) => {
|
|
621
746
|
console.error(`Error importing module ${name}:`, error);
|
|
622
747
|
// Remove from cache on error so it can be retried
|
|
623
748
|
sdkImportCache.delete(name);
|
|
@@ -627,12 +752,12 @@ function importNodeModule(name) {
|
|
|
627
752
|
sdkImportCache.set(name, promise);
|
|
628
753
|
return promise;
|
|
629
754
|
}
|
|
630
|
-
const loadNodeFetch = async ()=>{
|
|
755
|
+
const loadNodeFetch = async () => {
|
|
631
756
|
const fetchModule = await importNodeModule('node-fetch');
|
|
632
|
-
return fetchModule.default || fetchModule;
|
|
757
|
+
return (fetchModule.default || fetchModule);
|
|
633
758
|
};
|
|
634
|
-
const lazyLoaderHookFetch = async (input, init, loaderHook)=>{
|
|
635
|
-
const hook = (url, init)=>{
|
|
759
|
+
const lazyLoaderHookFetch = async (input, init, loaderHook) => {
|
|
760
|
+
const hook = (url, init) => {
|
|
636
761
|
return loaderHook.lifecycle.fetch.emit(url, init);
|
|
637
762
|
};
|
|
638
763
|
const res = await hook(input, init || {});
|
|
@@ -642,116 +767,132 @@ const lazyLoaderHookFetch = async (input, init, loaderHook)=>{
|
|
|
642
767
|
}
|
|
643
768
|
return res;
|
|
644
769
|
};
|
|
645
|
-
const createScriptNode = typeof ENV_TARGET === 'undefined' || ENV_TARGET !== 'web'
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
urlObj = new URL(url);
|
|
655
|
-
} catch (e) {
|
|
656
|
-
console.error('Error constructing URL:', e);
|
|
657
|
-
cb(new Error(`Invalid URL: ${e}`));
|
|
658
|
-
return;
|
|
659
|
-
}
|
|
660
|
-
const getFetch = async ()=>{
|
|
661
|
-
if (loaderHook == null ? void 0 : loaderHook.fetch) {
|
|
662
|
-
return (input, init)=>lazyLoaderHookFetch(input, init, loaderHook);
|
|
770
|
+
const createScriptNode = typeof ENV_TARGET === 'undefined' || ENV_TARGET !== 'web'
|
|
771
|
+
? (url, cb, attrs, loaderHook) => {
|
|
772
|
+
if (loaderHook?.createScriptHook) {
|
|
773
|
+
const hookResult = loaderHook.createScriptHook(url);
|
|
774
|
+
if (hookResult &&
|
|
775
|
+
typeof hookResult === 'object' &&
|
|
776
|
+
'url' in hookResult) {
|
|
777
|
+
url = hookResult.url;
|
|
778
|
+
}
|
|
663
779
|
}
|
|
664
|
-
|
|
665
|
-
};
|
|
666
|
-
const handleScriptFetch = async (f, urlObj)=>{
|
|
780
|
+
let urlObj;
|
|
667
781
|
try {
|
|
668
|
-
|
|
669
|
-
_vm_constants;
|
|
670
|
-
const res = await f(urlObj.href);
|
|
671
|
-
const data = await res.text();
|
|
672
|
-
const [path, vm] = await Promise.all([
|
|
673
|
-
importNodeModule('path'),
|
|
674
|
-
importNodeModule('vm')
|
|
675
|
-
]);
|
|
676
|
-
const scriptContext = {
|
|
677
|
-
exports: {},
|
|
678
|
-
module: {
|
|
679
|
-
exports: {}
|
|
680
|
-
}
|
|
681
|
-
};
|
|
682
|
-
const urlDirname = urlObj.pathname.split('/').slice(0, -1).join('/');
|
|
683
|
-
const filename = path.basename(urlObj.pathname);
|
|
684
|
-
var _vm_constants_USE_MAIN_CONTEXT_DEFAULT_LOADER;
|
|
685
|
-
const script = new vm.Script(`(function(exports, module, require, __dirname, __filename) {${data}\n})`, {
|
|
686
|
-
filename,
|
|
687
|
-
importModuleDynamically: (_vm_constants_USE_MAIN_CONTEXT_DEFAULT_LOADER = (_vm_constants = vm.constants) == null ? void 0 : _vm_constants.USE_MAIN_CONTEXT_DEFAULT_LOADER) != null ? _vm_constants_USE_MAIN_CONTEXT_DEFAULT_LOADER : importNodeModule
|
|
688
|
-
});
|
|
689
|
-
script.runInThisContext()(scriptContext.exports, scriptContext.module, eval('require'), urlDirname, filename);
|
|
690
|
-
const exportedInterface = scriptContext.module.exports || scriptContext.exports;
|
|
691
|
-
if (attrs && exportedInterface && attrs['globalName']) {
|
|
692
|
-
const container = exportedInterface[attrs['globalName']] || exportedInterface;
|
|
693
|
-
cb(undefined, container);
|
|
694
|
-
return;
|
|
695
|
-
}
|
|
696
|
-
cb(undefined, exportedInterface);
|
|
697
|
-
} catch (e) {
|
|
698
|
-
cb(e instanceof Error ? e : new Error(`Script execution error: ${e}`));
|
|
782
|
+
urlObj = new URL(url);
|
|
699
783
|
}
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
return
|
|
704
|
-
fetch: f,
|
|
705
|
-
vm: await importNodeModule('vm')
|
|
706
|
-
}).then(async (module)=>{
|
|
707
|
-
await module.evaluate();
|
|
708
|
-
cb(undefined, module.namespace);
|
|
709
|
-
}).catch((e)=>{
|
|
710
|
-
cb(e instanceof Error ? e : new Error(`Script execution error: ${e}`));
|
|
711
|
-
});
|
|
784
|
+
catch (e) {
|
|
785
|
+
console.error('Error constructing URL:', e);
|
|
786
|
+
cb(new Error(`Invalid URL: ${e}`));
|
|
787
|
+
return;
|
|
712
788
|
}
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
});
|
|
717
|
-
} : (url, cb, attrs, loaderHook)=>{
|
|
718
|
-
cb(new Error('createScriptNode is disabled in non-Node.js environment'));
|
|
719
|
-
};
|
|
720
|
-
const loadScriptNode = typeof ENV_TARGET === 'undefined' || ENV_TARGET !== 'web' ? (url, info)=>{
|
|
721
|
-
return new Promise((resolve, reject)=>{
|
|
722
|
-
createScriptNode(url, (error, scriptContext)=>{
|
|
723
|
-
if (error) {
|
|
724
|
-
reject(error);
|
|
725
|
-
} else {
|
|
726
|
-
var _info_attrs, _info_attrs1;
|
|
727
|
-
const remoteEntryKey = (info == null ? void 0 : (_info_attrs = info.attrs) == null ? void 0 : _info_attrs['globalName']) || `__FEDERATION_${info == null ? void 0 : (_info_attrs1 = info.attrs) == null ? void 0 : _info_attrs1['name']}:custom__`;
|
|
728
|
-
const entryExports = globalThis[remoteEntryKey] = scriptContext;
|
|
729
|
-
resolve(entryExports);
|
|
789
|
+
const getFetch = async () => {
|
|
790
|
+
if (loaderHook?.fetch) {
|
|
791
|
+
return (input, init) => lazyLoaderHookFetch(input, init, loaderHook);
|
|
730
792
|
}
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
793
|
+
return typeof fetch === 'undefined' ? loadNodeFetch() : fetch;
|
|
794
|
+
};
|
|
795
|
+
const handleScriptFetch = async (f, urlObj) => {
|
|
796
|
+
try {
|
|
797
|
+
const res = await f(urlObj.href);
|
|
798
|
+
const data = await res.text();
|
|
799
|
+
const [path, vm] = await Promise.all([
|
|
800
|
+
importNodeModule('path'),
|
|
801
|
+
importNodeModule('vm'),
|
|
802
|
+
]);
|
|
803
|
+
const scriptContext = { exports: {}, module: { exports: {} } };
|
|
804
|
+
const urlDirname = urlObj.pathname
|
|
805
|
+
.split('/')
|
|
806
|
+
.slice(0, -1)
|
|
807
|
+
.join('/');
|
|
808
|
+
const filename = path.basename(urlObj.pathname);
|
|
809
|
+
const script = new vm.Script(`(function(exports, module, require, __dirname, __filename) {${data}\n})`, {
|
|
810
|
+
filename,
|
|
811
|
+
importModuleDynamically:
|
|
812
|
+
//@ts-ignore
|
|
813
|
+
vm.constants?.USE_MAIN_CONTEXT_DEFAULT_LOADER ??
|
|
814
|
+
importNodeModule,
|
|
815
|
+
});
|
|
816
|
+
script.runInThisContext()(scriptContext.exports, scriptContext.module, eval('require'), urlDirname, filename);
|
|
817
|
+
const exportedInterface = scriptContext.module.exports || scriptContext.exports;
|
|
818
|
+
if (attrs && exportedInterface && attrs['globalName']) {
|
|
819
|
+
const container = exportedInterface[attrs['globalName']] || exportedInterface;
|
|
820
|
+
cb(undefined, container);
|
|
821
|
+
return;
|
|
822
|
+
}
|
|
823
|
+
cb(undefined, exportedInterface);
|
|
824
|
+
}
|
|
825
|
+
catch (e) {
|
|
826
|
+
cb(e instanceof Error
|
|
827
|
+
? e
|
|
828
|
+
: new Error(`Script execution error: ${e}`));
|
|
829
|
+
}
|
|
830
|
+
};
|
|
831
|
+
getFetch()
|
|
832
|
+
.then(async (f) => {
|
|
833
|
+
if (attrs?.['type'] === 'esm' || attrs?.['type'] === 'module') {
|
|
834
|
+
return loadModule(urlObj.href, {
|
|
835
|
+
fetch: f,
|
|
836
|
+
vm: await importNodeModule('vm'),
|
|
837
|
+
})
|
|
838
|
+
.then(async (module) => {
|
|
839
|
+
await module.evaluate();
|
|
840
|
+
cb(undefined, module.namespace);
|
|
841
|
+
})
|
|
842
|
+
.catch((e) => {
|
|
843
|
+
cb(e instanceof Error
|
|
844
|
+
? e
|
|
845
|
+
: new Error(`Script execution error: ${e}`));
|
|
846
|
+
});
|
|
847
|
+
}
|
|
848
|
+
handleScriptFetch(f, urlObj);
|
|
849
|
+
})
|
|
850
|
+
.catch((err) => {
|
|
851
|
+
cb(err);
|
|
852
|
+
});
|
|
853
|
+
}
|
|
854
|
+
: (url, cb, attrs, loaderHook) => {
|
|
855
|
+
cb(new Error('createScriptNode is disabled in non-Node.js environment'));
|
|
856
|
+
};
|
|
857
|
+
const loadScriptNode = typeof ENV_TARGET === 'undefined' || ENV_TARGET !== 'web'
|
|
858
|
+
? (url, info) => {
|
|
859
|
+
return new Promise((resolve, reject) => {
|
|
860
|
+
createScriptNode(url, (error, scriptContext) => {
|
|
861
|
+
if (error) {
|
|
862
|
+
reject(error);
|
|
863
|
+
}
|
|
864
|
+
else {
|
|
865
|
+
const remoteEntryKey = info?.attrs?.['globalName'] ||
|
|
866
|
+
`__FEDERATION_${info?.attrs?.['name']}:custom__`;
|
|
867
|
+
const entryExports = (globalThis[remoteEntryKey] =
|
|
868
|
+
scriptContext);
|
|
869
|
+
resolve(entryExports);
|
|
870
|
+
}
|
|
871
|
+
}, info.attrs, info.loaderHook);
|
|
872
|
+
});
|
|
873
|
+
}
|
|
874
|
+
: (url, info) => {
|
|
875
|
+
throw new Error('loadScriptNode is disabled in non-Node.js environment');
|
|
876
|
+
};
|
|
736
877
|
const esmModuleCache = new Map();
|
|
737
878
|
async function loadModule(url, options) {
|
|
738
879
|
// Check cache to prevent infinite recursion in ESM loading
|
|
739
880
|
if (esmModuleCache.has(url)) {
|
|
740
881
|
return esmModuleCache.get(url);
|
|
741
882
|
}
|
|
742
|
-
const { fetch
|
|
743
|
-
const response = await
|
|
883
|
+
const { fetch, vm } = options;
|
|
884
|
+
const response = await fetch(url);
|
|
744
885
|
const code = await response.text();
|
|
745
886
|
const module = new vm.SourceTextModule(code, {
|
|
746
887
|
// @ts-ignore
|
|
747
|
-
importModuleDynamically: async (specifier, script)=>{
|
|
888
|
+
importModuleDynamically: async (specifier, script) => {
|
|
748
889
|
const resolvedUrl = new URL(specifier, url).href;
|
|
749
890
|
return loadModule(resolvedUrl, options);
|
|
750
|
-
}
|
|
891
|
+
},
|
|
751
892
|
});
|
|
752
893
|
// Cache the module before linking to prevent cycles
|
|
753
894
|
esmModuleCache.set(url, module);
|
|
754
|
-
await module.link(async (specifier)=>{
|
|
895
|
+
await module.link(async (specifier) => {
|
|
755
896
|
const resolvedUrl = new URL(specifier, url).href;
|
|
756
897
|
const module = await loadModule(resolvedUrl, options);
|
|
757
898
|
return module;
|
|
@@ -760,14 +901,15 @@ async function loadModule(url, options) {
|
|
|
760
901
|
}
|
|
761
902
|
|
|
762
903
|
function normalizeOptions(enableDefault, defaultOptions, key) {
|
|
763
|
-
return function(options) {
|
|
904
|
+
return function (options) {
|
|
764
905
|
if (options === false) {
|
|
765
906
|
return false;
|
|
766
907
|
}
|
|
767
908
|
if (typeof options === 'undefined') {
|
|
768
909
|
if (enableDefault) {
|
|
769
910
|
return defaultOptions;
|
|
770
|
-
}
|
|
911
|
+
}
|
|
912
|
+
else {
|
|
771
913
|
return false;
|
|
772
914
|
}
|
|
773
915
|
}
|
|
@@ -775,15 +917,18 @@ function normalizeOptions(enableDefault, defaultOptions, key) {
|
|
|
775
917
|
return defaultOptions;
|
|
776
918
|
}
|
|
777
919
|
if (options && typeof options === 'object') {
|
|
778
|
-
return
|
|
920
|
+
return {
|
|
921
|
+
...defaultOptions,
|
|
922
|
+
...options,
|
|
923
|
+
};
|
|
779
924
|
}
|
|
780
925
|
throw new Error(`Unexpected type for \`${key}\`, expect boolean/undefined/object, got: ${typeof options}`);
|
|
781
926
|
};
|
|
782
927
|
}
|
|
783
928
|
|
|
784
|
-
const createModuleFederationConfig = (options)=>{
|
|
929
|
+
const createModuleFederationConfig = (options) => {
|
|
785
930
|
return options;
|
|
786
931
|
};
|
|
787
932
|
|
|
788
|
-
export { BROWSER_LOG_KEY, ENCODE_NAME_PREFIX, EncodedNameTransformMap, FederationModuleManifest, MANIFEST_EXT, MFModuleType, MFPrefetchCommon, MODULE_DEVTOOL_IDENTIFIER, ManifestFileName, NameTransformMap, NameTransformSymbol, SEPARATOR, StatsFileName, TEMP_DIR, assert, composeKeyWithSeparator, ContainerPlugin as containerPlugin, ContainerReferencePlugin as containerReferencePlugin, createLink, createLogger, createModuleFederationConfig, createScript, createScriptNode, decodeName, encodeName, error, generateExposeFilename, generateShareFilename, generateSnapshotFromManifest, getProcessEnv, getResourceUrl, inferAutoPublicPath, isBrowserEnv, isDebugMode, isManifestProvider, isReactNativeEnv, isRequiredVersion, isStaticResourcesEqual, loadScript, loadScriptNode, logger, ModuleFederationPlugin as moduleFederationPlugin, normalizeOptions, parseEntry, safeToString, safeWrapper, SharePlugin as sharePlugin, simpleJoinRemoteEntry, warn };
|
|
933
|
+
export { BROWSER_LOG_KEY, ENCODE_NAME_PREFIX, EncodedNameTransformMap, FederationModuleManifest, MANIFEST_EXT, MFModuleType, MFPrefetchCommon, MODULE_DEVTOOL_IDENTIFIER, ManifestFileName, NameTransformMap, NameTransformSymbol, SEPARATOR, StatsFileName, TEMP_DIR, assert, bindLoggerToCompiler, composeKeyWithSeparator, ContainerPlugin as containerPlugin, ContainerReferencePlugin as containerReferencePlugin, createInfrastructureLogger, createLink, createLogger, createModuleFederationConfig, createScript, createScriptNode, decodeName, encodeName, error, generateExposeFilename, generateShareFilename, generateSnapshotFromManifest, getProcessEnv, getResourceUrl, inferAutoPublicPath, infrastructureLogger, isBrowserEnv, isDebugMode, isManifestProvider, isReactNativeEnv, isRequiredVersion, isStaticResourcesEqual, loadScript, loadScriptNode, logger, ModuleFederationPlugin as moduleFederationPlugin, normalizeOptions, parseEntry, safeToString, safeWrapper, SharePlugin as sharePlugin, simpleJoinRemoteEntry, warn };
|
|
789
934
|
//# sourceMappingURL=index.esm.js.map
|