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