@module-federation/sdk 0.0.0-next-20250925034616 → 0.0.0-refactor-manifest-20251013103938
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 +429 -252
- package/dist/index.cjs.cjs.map +1 -1
- package/dist/index.esm.js +426 -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/generateSnapshotFromManifest.d.ts +5 -1
- package/dist/src/index.d.ts +3 -3
- 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.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,206 @@ 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
|
}
|
|
424
|
+
function getManifestFileName(manifestOptions) {
|
|
425
|
+
if (!manifestOptions) {
|
|
426
|
+
return {
|
|
427
|
+
statsFileName: StatsFileName,
|
|
428
|
+
manifestFileName: ManifestFileName,
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
let filePath = typeof manifestOptions === 'boolean' ? '' : manifestOptions.filePath || '';
|
|
432
|
+
let fileName = typeof manifestOptions === 'boolean' ? '' : manifestOptions.fileName || '';
|
|
433
|
+
const JSON_EXT = '.json';
|
|
434
|
+
const addExt = (name) => {
|
|
435
|
+
if (name.endsWith(JSON_EXT)) {
|
|
436
|
+
return name;
|
|
437
|
+
}
|
|
438
|
+
return `${name}${JSON_EXT}`;
|
|
439
|
+
};
|
|
440
|
+
const insertSuffix = (name, suffix) => {
|
|
441
|
+
return name.replace(JSON_EXT, `${suffix}${JSON_EXT}`);
|
|
442
|
+
};
|
|
443
|
+
const manifestFileName = fileName ? addExt(fileName) : ManifestFileName;
|
|
444
|
+
const statsFileName = fileName
|
|
445
|
+
? insertSuffix(manifestFileName, '-stats')
|
|
446
|
+
: StatsFileName;
|
|
447
|
+
return {
|
|
448
|
+
statsFileName: simpleJoinRemoteEntry(filePath, statsFileName),
|
|
449
|
+
manifestFileName: simpleJoinRemoteEntry(filePath, manifestFileName),
|
|
450
|
+
};
|
|
451
|
+
}
|
|
376
452
|
|
|
377
453
|
const PREFIX = '[ Module Federation ]';
|
|
378
|
-
|
|
454
|
+
const DEFAULT_DELEGATE = console;
|
|
455
|
+
class Logger {
|
|
456
|
+
constructor(prefix, delegate = DEFAULT_DELEGATE) {
|
|
457
|
+
this.prefix = prefix;
|
|
458
|
+
this.delegate = delegate ?? DEFAULT_DELEGATE;
|
|
459
|
+
}
|
|
379
460
|
setPrefix(prefix) {
|
|
380
461
|
this.prefix = prefix;
|
|
381
462
|
}
|
|
463
|
+
setDelegate(delegate) {
|
|
464
|
+
this.delegate = delegate ?? DEFAULT_DELEGATE;
|
|
465
|
+
}
|
|
466
|
+
emit(method, args) {
|
|
467
|
+
const delegate = this.delegate;
|
|
468
|
+
const order = (() => {
|
|
469
|
+
switch (method) {
|
|
470
|
+
case 'log':
|
|
471
|
+
return ['log', 'info'];
|
|
472
|
+
case 'info':
|
|
473
|
+
return ['info', 'log'];
|
|
474
|
+
case 'warn':
|
|
475
|
+
return ['warn', 'info', 'log'];
|
|
476
|
+
case 'error':
|
|
477
|
+
return ['error', 'warn', 'log'];
|
|
478
|
+
case 'debug':
|
|
479
|
+
default:
|
|
480
|
+
return ['debug', 'log'];
|
|
481
|
+
}
|
|
482
|
+
})();
|
|
483
|
+
for (const candidate of order) {
|
|
484
|
+
const handler = delegate[candidate];
|
|
485
|
+
if (typeof handler === 'function') {
|
|
486
|
+
handler.call(delegate, this.prefix, ...args);
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
for (const candidate of order) {
|
|
491
|
+
const handler = DEFAULT_DELEGATE[candidate];
|
|
492
|
+
if (typeof handler === 'function') {
|
|
493
|
+
handler.call(DEFAULT_DELEGATE, this.prefix, ...args);
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
}
|
|
382
498
|
log(...args) {
|
|
383
|
-
|
|
499
|
+
this.emit('log', args);
|
|
384
500
|
}
|
|
385
501
|
warn(...args) {
|
|
386
|
-
|
|
502
|
+
this.emit('warn', args);
|
|
387
503
|
}
|
|
388
504
|
error(...args) {
|
|
389
|
-
|
|
505
|
+
this.emit('error', args);
|
|
390
506
|
}
|
|
391
507
|
success(...args) {
|
|
392
|
-
|
|
508
|
+
this.emit('info', args);
|
|
393
509
|
}
|
|
394
510
|
info(...args) {
|
|
395
|
-
|
|
511
|
+
this.emit('info', args);
|
|
396
512
|
}
|
|
397
513
|
ready(...args) {
|
|
398
|
-
|
|
514
|
+
this.emit('info', args);
|
|
399
515
|
}
|
|
400
516
|
debug(...args) {
|
|
401
517
|
if (isDebugMode()) {
|
|
402
|
-
|
|
518
|
+
this.emit('debug', args);
|
|
403
519
|
}
|
|
404
520
|
}
|
|
405
|
-
|
|
406
|
-
this.prefix = prefix;
|
|
407
|
-
}
|
|
408
|
-
};
|
|
521
|
+
}
|
|
409
522
|
function createLogger(prefix) {
|
|
410
523
|
return new Logger(prefix);
|
|
411
524
|
}
|
|
525
|
+
function createInfrastructureLogger(prefix) {
|
|
526
|
+
const infrastructureLogger = new Logger(prefix);
|
|
527
|
+
Object.defineProperty(infrastructureLogger, '__mf_infrastructure_logger__', {
|
|
528
|
+
value: true,
|
|
529
|
+
enumerable: false,
|
|
530
|
+
configurable: false,
|
|
531
|
+
});
|
|
532
|
+
return infrastructureLogger;
|
|
533
|
+
}
|
|
534
|
+
function bindLoggerToCompiler(loggerInstance, compiler, name) {
|
|
535
|
+
if (!loggerInstance
|
|
536
|
+
.__mf_infrastructure_logger__) {
|
|
537
|
+
return;
|
|
538
|
+
}
|
|
539
|
+
if (!compiler?.getInfrastructureLogger) {
|
|
540
|
+
return;
|
|
541
|
+
}
|
|
542
|
+
try {
|
|
543
|
+
const infrastructureLogger = compiler.getInfrastructureLogger(name);
|
|
544
|
+
if (infrastructureLogger &&
|
|
545
|
+
typeof infrastructureLogger === 'object' &&
|
|
546
|
+
(typeof infrastructureLogger.log === 'function' ||
|
|
547
|
+
typeof infrastructureLogger.info === 'function' ||
|
|
548
|
+
typeof infrastructureLogger.warn === 'function' ||
|
|
549
|
+
typeof infrastructureLogger.error === 'function')) {
|
|
550
|
+
loggerInstance.setDelegate(infrastructureLogger);
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
catch {
|
|
554
|
+
// If the bundler throws (older versions), fall back to default console logger.
|
|
555
|
+
loggerInstance.setDelegate(undefined);
|
|
556
|
+
}
|
|
557
|
+
}
|
|
412
558
|
const logger = createLogger(PREFIX);
|
|
559
|
+
const infrastructureLogger = createInfrastructureLogger(PREFIX);
|
|
413
560
|
|
|
414
561
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
415
562
|
async function safeWrapper(callback, disableWarn) {
|
|
416
563
|
try {
|
|
417
564
|
const res = await callback();
|
|
418
565
|
return res;
|
|
419
|
-
}
|
|
566
|
+
}
|
|
567
|
+
catch (e) {
|
|
420
568
|
!disableWarn && warn(e);
|
|
421
569
|
return;
|
|
422
570
|
}
|
|
@@ -436,7 +584,7 @@ function createScript(info) {
|
|
|
436
584
|
let timeout = 20000;
|
|
437
585
|
let timeoutId;
|
|
438
586
|
const scripts = document.getElementsByTagName('script');
|
|
439
|
-
for(let i = 0; i < scripts.length; i++){
|
|
587
|
+
for (let i = 0; i < scripts.length; i++) {
|
|
440
588
|
const s = scripts[i];
|
|
441
589
|
const scriptSrc = s.getAttribute('src');
|
|
442
590
|
if (scriptSrc && isStaticResourcesEqual(scriptSrc, info.url)) {
|
|
@@ -448,13 +596,14 @@ function createScript(info) {
|
|
|
448
596
|
if (!script) {
|
|
449
597
|
const attrs = info.attrs;
|
|
450
598
|
script = document.createElement('script');
|
|
451
|
-
script.type =
|
|
599
|
+
script.type = attrs?.['type'] === 'module' ? 'module' : 'text/javascript';
|
|
452
600
|
let createScriptRes = undefined;
|
|
453
601
|
if (info.createScriptHook) {
|
|
454
602
|
createScriptRes = info.createScriptHook(info.url, info.attrs);
|
|
455
603
|
if (createScriptRes instanceof HTMLScriptElement) {
|
|
456
604
|
script = createScriptRes;
|
|
457
|
-
}
|
|
605
|
+
}
|
|
606
|
+
else if (typeof createScriptRes === 'object') {
|
|
458
607
|
if ('script' in createScriptRes && createScriptRes.script) {
|
|
459
608
|
script = createScriptRes.script;
|
|
460
609
|
}
|
|
@@ -467,36 +616,39 @@ function createScript(info) {
|
|
|
467
616
|
script.src = info.url;
|
|
468
617
|
}
|
|
469
618
|
if (attrs && !createScriptRes) {
|
|
470
|
-
Object.keys(attrs).forEach((name)=>{
|
|
619
|
+
Object.keys(attrs).forEach((name) => {
|
|
471
620
|
if (script) {
|
|
472
621
|
if (name === 'async' || name === 'defer') {
|
|
473
622
|
script[name] = attrs[name];
|
|
474
|
-
|
|
475
|
-
}
|
|
623
|
+
// Attributes that do not exist are considered overridden
|
|
624
|
+
}
|
|
625
|
+
else if (!script.getAttribute(name)) {
|
|
476
626
|
script.setAttribute(name, attrs[name]);
|
|
477
627
|
}
|
|
478
628
|
}
|
|
479
629
|
});
|
|
480
630
|
}
|
|
481
631
|
}
|
|
482
|
-
const onScriptComplete = async (prev,
|
|
483
|
-
|
|
632
|
+
const onScriptComplete = async (prev,
|
|
633
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
634
|
+
event) => {
|
|
484
635
|
clearTimeout(timeoutId);
|
|
485
|
-
const onScriptCompleteCallback = ()=>{
|
|
486
|
-
if (
|
|
487
|
-
|
|
488
|
-
}
|
|
489
|
-
|
|
636
|
+
const onScriptCompleteCallback = () => {
|
|
637
|
+
if (event?.type === 'error') {
|
|
638
|
+
info?.onErrorCallback && info?.onErrorCallback(event);
|
|
639
|
+
}
|
|
640
|
+
else {
|
|
641
|
+
info?.cb && info?.cb();
|
|
490
642
|
}
|
|
491
643
|
};
|
|
492
644
|
// Prevent memory leaks in IE.
|
|
493
645
|
if (script) {
|
|
494
646
|
script.onerror = null;
|
|
495
647
|
script.onload = null;
|
|
496
|
-
safeWrapper(()=>{
|
|
648
|
+
safeWrapper(() => {
|
|
497
649
|
const { needDeleteScript = true } = info;
|
|
498
650
|
if (needDeleteScript) {
|
|
499
|
-
|
|
651
|
+
script?.parentNode && script.parentNode.removeChild(script);
|
|
500
652
|
}
|
|
501
653
|
});
|
|
502
654
|
if (prev && typeof prev === 'function') {
|
|
@@ -514,13 +666,10 @@ function createScript(info) {
|
|
|
514
666
|
};
|
|
515
667
|
script.onerror = onScriptComplete.bind(null, script.onerror);
|
|
516
668
|
script.onload = onScriptComplete.bind(null, script.onload);
|
|
517
|
-
timeoutId = setTimeout(()=>{
|
|
669
|
+
timeoutId = setTimeout(() => {
|
|
518
670
|
onScriptComplete(null, new Error(`Remote script "${info.url}" time-outed.`));
|
|
519
671
|
}, timeout);
|
|
520
|
-
return {
|
|
521
|
-
script,
|
|
522
|
-
needAttach
|
|
523
|
-
};
|
|
672
|
+
return { script, needAttach };
|
|
524
673
|
}
|
|
525
674
|
function createLink(info) {
|
|
526
675
|
// <link rel="preload" href="script.js" as="script">
|
|
@@ -528,11 +677,13 @@ function createLink(info) {
|
|
|
528
677
|
let link = null;
|
|
529
678
|
let needAttach = true;
|
|
530
679
|
const links = document.getElementsByTagName('link');
|
|
531
|
-
for(let i = 0; i < links.length; i++){
|
|
680
|
+
for (let i = 0; i < links.length; i++) {
|
|
532
681
|
const l = links[i];
|
|
533
682
|
const linkHref = l.getAttribute('href');
|
|
534
683
|
const linkRel = l.getAttribute('rel');
|
|
535
|
-
if (linkHref &&
|
|
684
|
+
if (linkHref &&
|
|
685
|
+
isStaticResourcesEqual(linkHref, info.url) &&
|
|
686
|
+
linkRel === info.attrs['rel']) {
|
|
536
687
|
link = l;
|
|
537
688
|
needAttach = false;
|
|
538
689
|
break;
|
|
@@ -550,30 +701,32 @@ function createLink(info) {
|
|
|
550
701
|
}
|
|
551
702
|
}
|
|
552
703
|
if (attrs && !createLinkRes) {
|
|
553
|
-
Object.keys(attrs).forEach((name)=>{
|
|
704
|
+
Object.keys(attrs).forEach((name) => {
|
|
554
705
|
if (link && !link.getAttribute(name)) {
|
|
555
706
|
link.setAttribute(name, attrs[name]);
|
|
556
707
|
}
|
|
557
708
|
});
|
|
558
709
|
}
|
|
559
710
|
}
|
|
560
|
-
const onLinkComplete = (prev,
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
711
|
+
const onLinkComplete = (prev,
|
|
712
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
713
|
+
event) => {
|
|
714
|
+
const onLinkCompleteCallback = () => {
|
|
715
|
+
if (event?.type === 'error') {
|
|
716
|
+
info?.onErrorCallback && info?.onErrorCallback(event);
|
|
717
|
+
}
|
|
718
|
+
else {
|
|
719
|
+
info?.cb && info?.cb();
|
|
567
720
|
}
|
|
568
721
|
};
|
|
569
722
|
// Prevent memory leaks in IE.
|
|
570
723
|
if (link) {
|
|
571
724
|
link.onerror = null;
|
|
572
725
|
link.onload = null;
|
|
573
|
-
safeWrapper(()=>{
|
|
726
|
+
safeWrapper(() => {
|
|
574
727
|
const { needDeleteLink = true } = info;
|
|
575
728
|
if (needDeleteLink) {
|
|
576
|
-
|
|
729
|
+
link?.parentNode && link.parentNode.removeChild(link);
|
|
577
730
|
}
|
|
578
731
|
});
|
|
579
732
|
if (prev) {
|
|
@@ -587,23 +740,21 @@ function createLink(info) {
|
|
|
587
740
|
};
|
|
588
741
|
link.onerror = onLinkComplete.bind(null, link.onerror);
|
|
589
742
|
link.onload = onLinkComplete.bind(null, link.onload);
|
|
590
|
-
return {
|
|
591
|
-
link,
|
|
592
|
-
needAttach
|
|
593
|
-
};
|
|
743
|
+
return { link, needAttach };
|
|
594
744
|
}
|
|
595
745
|
function loadScript(url, info) {
|
|
596
746
|
const { attrs = {}, createScriptHook } = info;
|
|
597
|
-
return new Promise((resolve, reject)=>{
|
|
747
|
+
return new Promise((resolve, reject) => {
|
|
598
748
|
const { script, needAttach } = createScript({
|
|
599
749
|
url,
|
|
600
750
|
cb: resolve,
|
|
601
751
|
onErrorCallback: reject,
|
|
602
|
-
attrs:
|
|
603
|
-
fetchpriority: 'high'
|
|
604
|
-
|
|
752
|
+
attrs: {
|
|
753
|
+
fetchpriority: 'high',
|
|
754
|
+
...attrs,
|
|
755
|
+
},
|
|
605
756
|
createScriptHook,
|
|
606
|
-
needDeleteScript: true
|
|
757
|
+
needDeleteScript: true,
|
|
607
758
|
});
|
|
608
759
|
needAttach && document.head.appendChild(script);
|
|
609
760
|
});
|
|
@@ -619,7 +770,9 @@ function importNodeModule(name) {
|
|
|
619
770
|
return sdkImportCache.get(name);
|
|
620
771
|
}
|
|
621
772
|
const importModule = new Function('name', `return import(name)`);
|
|
622
|
-
const promise = importModule(name)
|
|
773
|
+
const promise = importModule(name)
|
|
774
|
+
.then((res) => res)
|
|
775
|
+
.catch((error) => {
|
|
623
776
|
console.error(`Error importing module ${name}:`, error);
|
|
624
777
|
// Remove from cache on error so it can be retried
|
|
625
778
|
sdkImportCache.delete(name);
|
|
@@ -629,12 +782,12 @@ function importNodeModule(name) {
|
|
|
629
782
|
sdkImportCache.set(name, promise);
|
|
630
783
|
return promise;
|
|
631
784
|
}
|
|
632
|
-
const loadNodeFetch = async ()=>{
|
|
785
|
+
const loadNodeFetch = async () => {
|
|
633
786
|
const fetchModule = await importNodeModule('node-fetch');
|
|
634
|
-
return fetchModule.default || fetchModule;
|
|
787
|
+
return (fetchModule.default || fetchModule);
|
|
635
788
|
};
|
|
636
|
-
const lazyLoaderHookFetch = async (input, init, loaderHook)=>{
|
|
637
|
-
const hook = (url, init)=>{
|
|
789
|
+
const lazyLoaderHookFetch = async (input, init, loaderHook) => {
|
|
790
|
+
const hook = (url, init) => {
|
|
638
791
|
return loaderHook.lifecycle.fetch.emit(url, init);
|
|
639
792
|
};
|
|
640
793
|
const res = await hook(input, init || {});
|
|
@@ -644,116 +797,132 @@ const lazyLoaderHookFetch = async (input, init, loaderHook)=>{
|
|
|
644
797
|
}
|
|
645
798
|
return res;
|
|
646
799
|
};
|
|
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);
|
|
800
|
+
const createScriptNode = typeof ENV_TARGET === 'undefined' || ENV_TARGET !== 'web'
|
|
801
|
+
? (url, cb, attrs, loaderHook) => {
|
|
802
|
+
if (loaderHook?.createScriptHook) {
|
|
803
|
+
const hookResult = loaderHook.createScriptHook(url);
|
|
804
|
+
if (hookResult &&
|
|
805
|
+
typeof hookResult === 'object' &&
|
|
806
|
+
'url' in hookResult) {
|
|
807
|
+
url = hookResult.url;
|
|
808
|
+
}
|
|
665
809
|
}
|
|
666
|
-
|
|
667
|
-
};
|
|
668
|
-
const handleScriptFetch = async (f, urlObj)=>{
|
|
810
|
+
let urlObj;
|
|
669
811
|
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}`));
|
|
812
|
+
urlObj = new URL(url);
|
|
701
813
|
}
|
|
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
|
-
});
|
|
814
|
+
catch (e) {
|
|
815
|
+
console.error('Error constructing URL:', e);
|
|
816
|
+
cb(new Error(`Invalid URL: ${e}`));
|
|
817
|
+
return;
|
|
714
818
|
}
|
|
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);
|
|
819
|
+
const getFetch = async () => {
|
|
820
|
+
if (loaderHook?.fetch) {
|
|
821
|
+
return (input, init) => lazyLoaderHookFetch(input, init, loaderHook);
|
|
732
822
|
}
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
823
|
+
return typeof fetch === 'undefined' ? loadNodeFetch() : fetch;
|
|
824
|
+
};
|
|
825
|
+
const handleScriptFetch = async (f, urlObj) => {
|
|
826
|
+
try {
|
|
827
|
+
const res = await f(urlObj.href);
|
|
828
|
+
const data = await res.text();
|
|
829
|
+
const [path, vm] = await Promise.all([
|
|
830
|
+
importNodeModule('path'),
|
|
831
|
+
importNodeModule('vm'),
|
|
832
|
+
]);
|
|
833
|
+
const scriptContext = { exports: {}, module: { exports: {} } };
|
|
834
|
+
const urlDirname = urlObj.pathname
|
|
835
|
+
.split('/')
|
|
836
|
+
.slice(0, -1)
|
|
837
|
+
.join('/');
|
|
838
|
+
const filename = path.basename(urlObj.pathname);
|
|
839
|
+
const script = new vm.Script(`(function(exports, module, require, __dirname, __filename) {${data}\n})`, {
|
|
840
|
+
filename,
|
|
841
|
+
importModuleDynamically:
|
|
842
|
+
//@ts-ignore
|
|
843
|
+
vm.constants?.USE_MAIN_CONTEXT_DEFAULT_LOADER ??
|
|
844
|
+
importNodeModule,
|
|
845
|
+
});
|
|
846
|
+
script.runInThisContext()(scriptContext.exports, scriptContext.module, eval('require'), urlDirname, filename);
|
|
847
|
+
const exportedInterface = scriptContext.module.exports || scriptContext.exports;
|
|
848
|
+
if (attrs && exportedInterface && attrs['globalName']) {
|
|
849
|
+
const container = exportedInterface[attrs['globalName']] || exportedInterface;
|
|
850
|
+
cb(undefined, container);
|
|
851
|
+
return;
|
|
852
|
+
}
|
|
853
|
+
cb(undefined, exportedInterface);
|
|
854
|
+
}
|
|
855
|
+
catch (e) {
|
|
856
|
+
cb(e instanceof Error
|
|
857
|
+
? e
|
|
858
|
+
: new Error(`Script execution error: ${e}`));
|
|
859
|
+
}
|
|
860
|
+
};
|
|
861
|
+
getFetch()
|
|
862
|
+
.then(async (f) => {
|
|
863
|
+
if (attrs?.['type'] === 'esm' || attrs?.['type'] === 'module') {
|
|
864
|
+
return loadModule(urlObj.href, {
|
|
865
|
+
fetch: f,
|
|
866
|
+
vm: await importNodeModule('vm'),
|
|
867
|
+
})
|
|
868
|
+
.then(async (module) => {
|
|
869
|
+
await module.evaluate();
|
|
870
|
+
cb(undefined, module.namespace);
|
|
871
|
+
})
|
|
872
|
+
.catch((e) => {
|
|
873
|
+
cb(e instanceof Error
|
|
874
|
+
? e
|
|
875
|
+
: new Error(`Script execution error: ${e}`));
|
|
876
|
+
});
|
|
877
|
+
}
|
|
878
|
+
handleScriptFetch(f, urlObj);
|
|
879
|
+
})
|
|
880
|
+
.catch((err) => {
|
|
881
|
+
cb(err);
|
|
882
|
+
});
|
|
883
|
+
}
|
|
884
|
+
: (url, cb, attrs, loaderHook) => {
|
|
885
|
+
cb(new Error('createScriptNode is disabled in non-Node.js environment'));
|
|
886
|
+
};
|
|
887
|
+
const loadScriptNode = typeof ENV_TARGET === 'undefined' || ENV_TARGET !== 'web'
|
|
888
|
+
? (url, info) => {
|
|
889
|
+
return new Promise((resolve, reject) => {
|
|
890
|
+
createScriptNode(url, (error, scriptContext) => {
|
|
891
|
+
if (error) {
|
|
892
|
+
reject(error);
|
|
893
|
+
}
|
|
894
|
+
else {
|
|
895
|
+
const remoteEntryKey = info?.attrs?.['globalName'] ||
|
|
896
|
+
`__FEDERATION_${info?.attrs?.['name']}:custom__`;
|
|
897
|
+
const entryExports = (globalThis[remoteEntryKey] =
|
|
898
|
+
scriptContext);
|
|
899
|
+
resolve(entryExports);
|
|
900
|
+
}
|
|
901
|
+
}, info.attrs, info.loaderHook);
|
|
902
|
+
});
|
|
903
|
+
}
|
|
904
|
+
: (url, info) => {
|
|
905
|
+
throw new Error('loadScriptNode is disabled in non-Node.js environment');
|
|
906
|
+
};
|
|
738
907
|
const esmModuleCache = new Map();
|
|
739
908
|
async function loadModule(url, options) {
|
|
740
909
|
// Check cache to prevent infinite recursion in ESM loading
|
|
741
910
|
if (esmModuleCache.has(url)) {
|
|
742
911
|
return esmModuleCache.get(url);
|
|
743
912
|
}
|
|
744
|
-
const { fetch
|
|
745
|
-
const response = await
|
|
913
|
+
const { fetch, vm } = options;
|
|
914
|
+
const response = await fetch(url);
|
|
746
915
|
const code = await response.text();
|
|
747
916
|
const module = new vm.SourceTextModule(code, {
|
|
748
917
|
// @ts-ignore
|
|
749
|
-
importModuleDynamically: async (specifier, script)=>{
|
|
918
|
+
importModuleDynamically: async (specifier, script) => {
|
|
750
919
|
const resolvedUrl = new URL(specifier, url).href;
|
|
751
920
|
return loadModule(resolvedUrl, options);
|
|
752
|
-
}
|
|
921
|
+
},
|
|
753
922
|
});
|
|
754
923
|
// Cache the module before linking to prevent cycles
|
|
755
924
|
esmModuleCache.set(url, module);
|
|
756
|
-
await module.link(async (specifier)=>{
|
|
925
|
+
await module.link(async (specifier) => {
|
|
757
926
|
const resolvedUrl = new URL(specifier, url).href;
|
|
758
927
|
const module = await loadModule(resolvedUrl, options);
|
|
759
928
|
return module;
|
|
@@ -762,14 +931,15 @@ async function loadModule(url, options) {
|
|
|
762
931
|
}
|
|
763
932
|
|
|
764
933
|
function normalizeOptions(enableDefault, defaultOptions, key) {
|
|
765
|
-
return function(options) {
|
|
934
|
+
return function (options) {
|
|
766
935
|
if (options === false) {
|
|
767
936
|
return false;
|
|
768
937
|
}
|
|
769
938
|
if (typeof options === 'undefined') {
|
|
770
939
|
if (enableDefault) {
|
|
771
940
|
return defaultOptions;
|
|
772
|
-
}
|
|
941
|
+
}
|
|
942
|
+
else {
|
|
773
943
|
return false;
|
|
774
944
|
}
|
|
775
945
|
}
|
|
@@ -777,13 +947,16 @@ function normalizeOptions(enableDefault, defaultOptions, key) {
|
|
|
777
947
|
return defaultOptions;
|
|
778
948
|
}
|
|
779
949
|
if (options && typeof options === 'object') {
|
|
780
|
-
return
|
|
950
|
+
return {
|
|
951
|
+
...defaultOptions,
|
|
952
|
+
...options,
|
|
953
|
+
};
|
|
781
954
|
}
|
|
782
955
|
throw new Error(`Unexpected type for \`${key}\`, expect boolean/undefined/object, got: ${typeof options}`);
|
|
783
956
|
};
|
|
784
957
|
}
|
|
785
958
|
|
|
786
|
-
const createModuleFederationConfig = (options)=>{
|
|
959
|
+
const createModuleFederationConfig = (options) => {
|
|
787
960
|
return options;
|
|
788
961
|
};
|
|
789
962
|
|
|
@@ -802,9 +975,11 @@ exports.SEPARATOR = SEPARATOR;
|
|
|
802
975
|
exports.StatsFileName = StatsFileName;
|
|
803
976
|
exports.TEMP_DIR = TEMP_DIR;
|
|
804
977
|
exports.assert = assert;
|
|
978
|
+
exports.bindLoggerToCompiler = bindLoggerToCompiler;
|
|
805
979
|
exports.composeKeyWithSeparator = composeKeyWithSeparator;
|
|
806
980
|
exports.containerPlugin = ContainerPlugin;
|
|
807
981
|
exports.containerReferencePlugin = ContainerReferencePlugin;
|
|
982
|
+
exports.createInfrastructureLogger = createInfrastructureLogger;
|
|
808
983
|
exports.createLink = createLink;
|
|
809
984
|
exports.createLogger = createLogger;
|
|
810
985
|
exports.createModuleFederationConfig = createModuleFederationConfig;
|
|
@@ -816,9 +991,11 @@ exports.error = error;
|
|
|
816
991
|
exports.generateExposeFilename = generateExposeFilename;
|
|
817
992
|
exports.generateShareFilename = generateShareFilename;
|
|
818
993
|
exports.generateSnapshotFromManifest = generateSnapshotFromManifest;
|
|
994
|
+
exports.getManifestFileName = getManifestFileName;
|
|
819
995
|
exports.getProcessEnv = getProcessEnv;
|
|
820
996
|
exports.getResourceUrl = getResourceUrl;
|
|
821
997
|
exports.inferAutoPublicPath = inferAutoPublicPath;
|
|
998
|
+
exports.infrastructureLogger = infrastructureLogger;
|
|
822
999
|
exports.isBrowserEnv = isBrowserEnv;
|
|
823
1000
|
exports.isDebugMode = isDebugMode;
|
|
824
1001
|
exports.isManifestProvider = isManifestProvider;
|