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