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