@module-federation/sdk 0.1.12 → 0.1.13
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.js +104 -96
- package/dist/index.esm.js +104 -97
- package/dist/normalize-webpack-path.cjs.js +16 -16
- package/dist/normalize-webpack-path.esm.js +16 -16
- package/dist/package.json +1 -1
- package/dist/src/generateSnapshotFromManifest.d.ts +1 -0
- package/dist/src/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -15,27 +15,27 @@ function _define_property$3(obj, key, value) {
|
|
|
15
15
|
}
|
|
16
16
|
return obj;
|
|
17
17
|
}
|
|
18
|
-
var FederationModuleManifest =
|
|
19
|
-
var MANIFEST_EXT =
|
|
20
|
-
var BROWSER_LOG_KEY =
|
|
21
|
-
var BROWSER_LOG_VALUE =
|
|
18
|
+
var FederationModuleManifest = 'federation-manifest.json';
|
|
19
|
+
var MANIFEST_EXT = '.json';
|
|
20
|
+
var BROWSER_LOG_KEY = 'FEDERATION_DEBUG';
|
|
21
|
+
var BROWSER_LOG_VALUE = '1';
|
|
22
22
|
var NameTransformSymbol = {
|
|
23
|
-
AT:
|
|
24
|
-
HYPHEN:
|
|
25
|
-
SLASH:
|
|
23
|
+
AT: '@',
|
|
24
|
+
HYPHEN: '-',
|
|
25
|
+
SLASH: '/'
|
|
26
26
|
};
|
|
27
27
|
var _obj;
|
|
28
|
-
var NameTransformMap = (_obj = {}, _define_property$3(_obj, NameTransformSymbol.AT,
|
|
28
|
+
var NameTransformMap = (_obj = {}, _define_property$3(_obj, NameTransformSymbol.AT, 'scope_'), _define_property$3(_obj, NameTransformSymbol.HYPHEN, '_'), _define_property$3(_obj, NameTransformSymbol.SLASH, '__'), _obj);
|
|
29
29
|
var _obj1;
|
|
30
30
|
var EncodedNameTransformMap = (_obj1 = {}, _define_property$3(_obj1, NameTransformMap[NameTransformSymbol.AT], NameTransformSymbol.AT), _define_property$3(_obj1, NameTransformMap[NameTransformSymbol.HYPHEN], NameTransformSymbol.HYPHEN), _define_property$3(_obj1, NameTransformMap[NameTransformSymbol.SLASH], NameTransformSymbol.SLASH), _obj1);
|
|
31
|
-
var SEPARATOR =
|
|
32
|
-
var ManifestFileName =
|
|
33
|
-
var StatsFileName =
|
|
31
|
+
var SEPARATOR = ':';
|
|
32
|
+
var ManifestFileName = 'mf-manifest.json';
|
|
33
|
+
var StatsFileName = 'mf-stats.json';
|
|
34
34
|
var MFModuleType = {
|
|
35
|
-
NPM:
|
|
36
|
-
APP:
|
|
35
|
+
NPM: 'npm',
|
|
36
|
+
APP: 'app'
|
|
37
37
|
};
|
|
38
|
-
var MODULE_DEVTOOL_IDENTIFIER =
|
|
38
|
+
var MODULE_DEVTOOL_IDENTIFIER = '__MF_DEVTOOLS_MODULE_INFO__';
|
|
39
39
|
|
|
40
40
|
var ContainerPlugin = /*#__PURE__*/Object.freeze({
|
|
41
41
|
__proto__: null
|
|
@@ -54,16 +54,16 @@ var SharePlugin = /*#__PURE__*/Object.freeze({
|
|
|
54
54
|
});
|
|
55
55
|
|
|
56
56
|
function isBrowserEnv() {
|
|
57
|
-
return typeof window !==
|
|
57
|
+
return typeof window !== 'undefined';
|
|
58
58
|
}
|
|
59
59
|
function isDebugMode() {
|
|
60
|
-
if (typeof process !==
|
|
61
|
-
return Boolean(process.env[
|
|
60
|
+
if (typeof process !== 'undefined' && process.env && process.env['FEDERATION_DEBUG']) {
|
|
61
|
+
return Boolean(process.env['FEDERATION_DEBUG']);
|
|
62
62
|
}
|
|
63
|
-
return typeof FEDERATION_DEBUG !==
|
|
63
|
+
return typeof FEDERATION_DEBUG !== 'undefined' && Boolean(FEDERATION_DEBUG);
|
|
64
64
|
}
|
|
65
65
|
var getProcessEnv = function getProcessEnv() {
|
|
66
|
-
return typeof process !==
|
|
66
|
+
return typeof process !== 'undefined' && process.env ? process.env : {};
|
|
67
67
|
};
|
|
68
68
|
|
|
69
69
|
function _array_like_to_array$2(arr, len) {
|
|
@@ -127,17 +127,17 @@ function safeToString(info) {
|
|
|
127
127
|
try {
|
|
128
128
|
return JSON.stringify(info, null, 2);
|
|
129
129
|
} catch (e) {
|
|
130
|
-
return
|
|
130
|
+
return '';
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
|
-
var DEBUG_LOG =
|
|
133
|
+
var DEBUG_LOG = '[ FEDERATION DEBUG ]';
|
|
134
134
|
function safeGetLocalStorageItem() {
|
|
135
135
|
try {
|
|
136
|
-
if (typeof window !==
|
|
136
|
+
if (typeof window !== 'undefined' && window.localStorage) {
|
|
137
137
|
return localStorage.getItem(BROWSER_LOG_KEY) === BROWSER_LOG_VALUE;
|
|
138
138
|
}
|
|
139
139
|
} catch (error) {
|
|
140
|
-
return typeof document !==
|
|
140
|
+
return typeof document !== 'undefined';
|
|
141
141
|
}
|
|
142
142
|
return false;
|
|
143
143
|
}
|
|
@@ -158,11 +158,11 @@ var Logger = /*#__PURE__*/ function() {
|
|
|
158
158
|
key: "info",
|
|
159
159
|
value: function info(msg, info) {
|
|
160
160
|
if (this.enable) {
|
|
161
|
-
var argsToString = safeToString(info) ||
|
|
161
|
+
var argsToString = safeToString(info) || '';
|
|
162
162
|
if (isBrowserEnv()) {
|
|
163
|
-
console.info("%c ".concat(this.identifier, ": ").concat(msg, " ").concat(argsToString),
|
|
163
|
+
console.info("%c ".concat(this.identifier, ": ").concat(msg, " ").concat(argsToString), 'color:#3300CC');
|
|
164
164
|
} else {
|
|
165
|
-
console.info(
|
|
165
|
+
console.info('\x1b[34m%s', "".concat(this.identifier, ": ").concat(msg, " ").concat(argsToString ? "\n".concat(argsToString) : ''));
|
|
166
166
|
}
|
|
167
167
|
}
|
|
168
168
|
}
|
|
@@ -176,11 +176,11 @@ var Logger = /*#__PURE__*/ function() {
|
|
|
176
176
|
if (this.enable) {
|
|
177
177
|
if (isBrowserEnv()) {
|
|
178
178
|
var _console;
|
|
179
|
-
console.info("%c ".concat(this.identifier, ": OriginalInfo"),
|
|
179
|
+
console.info("%c ".concat(this.identifier, ": OriginalInfo"), 'color:#3300CC');
|
|
180
180
|
(_console = console).log.apply(_console, _to_consumable_array(args));
|
|
181
181
|
} else {
|
|
182
182
|
var _console1;
|
|
183
|
-
console.info("%c ".concat(this.identifier, ": OriginalInfo"),
|
|
183
|
+
console.info("%c ".concat(this.identifier, ": OriginalInfo"), 'color:#3300CC');
|
|
184
184
|
(_console1 = console).log.apply(_console1, _to_consumable_array(args));
|
|
185
185
|
}
|
|
186
186
|
}
|
|
@@ -242,16 +242,16 @@ function _unsupported_iterable_to_array$1(o, minLen) {
|
|
|
242
242
|
if (n === "Map" || n === "Set") return Array.from(n);
|
|
243
243
|
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$1(o, minLen);
|
|
244
244
|
}
|
|
245
|
-
var LOG_CATEGORY =
|
|
245
|
+
var LOG_CATEGORY = '[ Federation Runtime ]';
|
|
246
246
|
// entry: name:version version : 1.0.0 | ^1.2.3
|
|
247
247
|
// entry: name:entry entry: https://localhost:9000/federation-manifest.json
|
|
248
248
|
var parseEntry = function(str, devVerOrUrl) {
|
|
249
249
|
var separator = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : SEPARATOR;
|
|
250
250
|
var strSplit = str.split(separator);
|
|
251
|
-
var devVersionOrUrl = getProcessEnv()[
|
|
252
|
-
var defaultVersion =
|
|
251
|
+
var devVersionOrUrl = getProcessEnv()['NODE_ENV'] === 'development' && devVerOrUrl;
|
|
252
|
+
var defaultVersion = '*';
|
|
253
253
|
var isEntry = function(s) {
|
|
254
|
-
return s.startsWith(
|
|
254
|
+
return s.startsWith('http') || s.includes(MANIFEST_EXT);
|
|
255
255
|
};
|
|
256
256
|
// Check if the string starts with a type
|
|
257
257
|
if (strSplit.length >= 2) {
|
|
@@ -292,7 +292,7 @@ var composeKeyWithSeparator = function composeKeyWithSeparator() {
|
|
|
292
292
|
args[_key] = arguments[_key];
|
|
293
293
|
}
|
|
294
294
|
if (!args.length) {
|
|
295
|
-
return
|
|
295
|
+
return '';
|
|
296
296
|
}
|
|
297
297
|
return args.reduce(function(sum, cur) {
|
|
298
298
|
if (!cur) {
|
|
@@ -302,13 +302,13 @@ var composeKeyWithSeparator = function composeKeyWithSeparator() {
|
|
|
302
302
|
return cur;
|
|
303
303
|
}
|
|
304
304
|
return "".concat(sum).concat(SEPARATOR).concat(cur);
|
|
305
|
-
},
|
|
305
|
+
}, '');
|
|
306
306
|
};
|
|
307
307
|
var encodeName = function encodeName(name) {
|
|
308
|
-
var prefix = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] :
|
|
308
|
+
var prefix = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : '', withExt = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
|
|
309
309
|
try {
|
|
310
|
-
var ext = withExt ?
|
|
311
|
-
return "".concat(prefix).concat(name.replace(new RegExp("".concat(NameTransformSymbol.AT),
|
|
310
|
+
var ext = withExt ? '.js' : '';
|
|
311
|
+
return "".concat(prefix).concat(name.replace(new RegExp("".concat(NameTransformSymbol.AT), 'g'), NameTransformMap[NameTransformSymbol.AT]).replace(new RegExp("".concat(NameTransformSymbol.HYPHEN), 'g'), NameTransformMap[NameTransformSymbol.HYPHEN]).replace(new RegExp("".concat(NameTransformSymbol.SLASH), 'g'), NameTransformMap[NameTransformSymbol.SLASH])).concat(ext);
|
|
312
312
|
} catch (err) {
|
|
313
313
|
throw err;
|
|
314
314
|
}
|
|
@@ -320,11 +320,11 @@ var decodeName = function decodeName(name, prefix, withExt) {
|
|
|
320
320
|
if (!decodedName.startsWith(prefix)) {
|
|
321
321
|
return decodedName;
|
|
322
322
|
}
|
|
323
|
-
decodedName = decodedName.replace(new RegExp(prefix,
|
|
323
|
+
decodedName = decodedName.replace(new RegExp(prefix, 'g'), '');
|
|
324
324
|
}
|
|
325
|
-
decodedName = decodedName.replace(new RegExp("".concat(NameTransformMap[NameTransformSymbol.AT]),
|
|
325
|
+
decodedName = decodedName.replace(new RegExp("".concat(NameTransformMap[NameTransformSymbol.AT]), 'g'), EncodedNameTransformMap[NameTransformMap[NameTransformSymbol.AT]]).replace(new RegExp("".concat(NameTransformMap[NameTransformSymbol.SLASH]), 'g'), EncodedNameTransformMap[NameTransformMap[NameTransformSymbol.SLASH]]).replace(new RegExp("".concat(NameTransformMap[NameTransformSymbol.HYPHEN]), 'g'), EncodedNameTransformMap[NameTransformMap[NameTransformSymbol.HYPHEN]]);
|
|
326
326
|
if (withExt) {
|
|
327
|
-
decodedName = decodedName.replace(
|
|
327
|
+
decodedName = decodedName.replace('.js', '');
|
|
328
328
|
}
|
|
329
329
|
return decodedName;
|
|
330
330
|
} catch (err) {
|
|
@@ -333,32 +333,32 @@ var decodeName = function decodeName(name, prefix, withExt) {
|
|
|
333
333
|
};
|
|
334
334
|
var generateExposeFilename = function(exposeName, withExt) {
|
|
335
335
|
if (!exposeName) {
|
|
336
|
-
return
|
|
336
|
+
return '';
|
|
337
337
|
}
|
|
338
338
|
var expose = exposeName;
|
|
339
|
-
if (expose ===
|
|
340
|
-
expose =
|
|
339
|
+
if (expose === '.') {
|
|
340
|
+
expose = 'default_export';
|
|
341
341
|
}
|
|
342
|
-
if (expose.startsWith(
|
|
343
|
-
expose = expose.replace(
|
|
342
|
+
if (expose.startsWith('./')) {
|
|
343
|
+
expose = expose.replace('./', '');
|
|
344
344
|
}
|
|
345
|
-
return encodeName(expose,
|
|
345
|
+
return encodeName(expose, '__federation_expose_', withExt);
|
|
346
346
|
};
|
|
347
347
|
var generateShareFilename = function(pkgName, withExt) {
|
|
348
348
|
if (!pkgName) {
|
|
349
|
-
return
|
|
349
|
+
return '';
|
|
350
350
|
}
|
|
351
|
-
return encodeName(pkgName,
|
|
351
|
+
return encodeName(pkgName, '__federation_shared_', withExt);
|
|
352
352
|
};
|
|
353
353
|
var getResourceUrl = function(module, sourceUrl) {
|
|
354
|
-
if (
|
|
354
|
+
if ('getPublicPath' in module) {
|
|
355
355
|
var publicPath = new Function(module.getPublicPath)();
|
|
356
356
|
return "".concat(publicPath).concat(sourceUrl);
|
|
357
|
-
} else if (
|
|
357
|
+
} else if ('publicPath' in module) {
|
|
358
358
|
return "".concat(module.publicPath).concat(sourceUrl);
|
|
359
359
|
} else {
|
|
360
|
-
console.warn(
|
|
361
|
-
return
|
|
360
|
+
console.warn('Can not get resource url, if in debug mode, please ignore', module, sourceUrl);
|
|
361
|
+
return '';
|
|
362
362
|
}
|
|
363
363
|
};
|
|
364
364
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
@@ -431,15 +431,15 @@ var simpleJoinRemoteEntry = function(rPath, rName) {
|
|
|
431
431
|
return rName;
|
|
432
432
|
}
|
|
433
433
|
var transformPath = function(str) {
|
|
434
|
-
if (str ===
|
|
435
|
-
return
|
|
434
|
+
if (str === '.') {
|
|
435
|
+
return '';
|
|
436
436
|
}
|
|
437
|
-
if (str.startsWith(
|
|
438
|
-
return str.replace(
|
|
437
|
+
if (str.startsWith('./')) {
|
|
438
|
+
return str.replace('./', '');
|
|
439
439
|
}
|
|
440
|
-
if (str.startsWith(
|
|
440
|
+
if (str.startsWith('/')) {
|
|
441
441
|
var strWithoutSlash = str.slice(1);
|
|
442
|
-
if (strWithoutSlash.endsWith(
|
|
442
|
+
if (strWithoutSlash.endsWith('/')) {
|
|
443
443
|
return strWithoutSlash.slice(0, -1);
|
|
444
444
|
}
|
|
445
445
|
return strWithoutSlash;
|
|
@@ -450,11 +450,14 @@ var simpleJoinRemoteEntry = function(rPath, rName) {
|
|
|
450
450
|
if (!transformedPath) {
|
|
451
451
|
return rName;
|
|
452
452
|
}
|
|
453
|
-
if (transformedPath.endsWith(
|
|
453
|
+
if (transformedPath.endsWith('/')) {
|
|
454
454
|
return "".concat(transformedPath).concat(rName);
|
|
455
455
|
}
|
|
456
456
|
return "".concat(transformedPath, "/").concat(rName);
|
|
457
457
|
};
|
|
458
|
+
function inferAutoPublicPath(url) {
|
|
459
|
+
return url.replace(/#.*$/, '').replace(/\?.*$/, '').replace(/\/[^\/]+$/, '/');
|
|
460
|
+
}
|
|
458
461
|
// Priority: overrides > remotes
|
|
459
462
|
// eslint-disable-next-line max-lines-per-function
|
|
460
463
|
function generateSnapshotFromManifest(manifest) {
|
|
@@ -463,7 +466,11 @@ function generateSnapshotFromManifest(manifest) {
|
|
|
463
466
|
var _options_remotes = options.remotes, remotes = _options_remotes === void 0 ? {} : _options_remotes, _options_overrides = options.overrides, overrides = _options_overrides === void 0 ? {} : _options_overrides, version = options.version;
|
|
464
467
|
var remoteSnapshot;
|
|
465
468
|
var getPublicPath = function() {
|
|
466
|
-
if (
|
|
469
|
+
if ('publicPath' in manifest.metaData) {
|
|
470
|
+
if (manifest.metaData.publicPath === 'auto' && version) {
|
|
471
|
+
// use same implementation as publicPath auto runtime module implements
|
|
472
|
+
return inferAutoPublicPath(version);
|
|
473
|
+
}
|
|
467
474
|
return manifest.metaData.publicPath;
|
|
468
475
|
} else {
|
|
469
476
|
return manifest.metaData.getPublicPath;
|
|
@@ -481,7 +488,7 @@ function generateSnapshotFromManifest(manifest) {
|
|
|
481
488
|
if (overridesKeys.includes(name)) {
|
|
482
489
|
matchedVersion = overrides[name];
|
|
483
490
|
} else {
|
|
484
|
-
if (
|
|
491
|
+
if ('version' in next) {
|
|
485
492
|
matchedVersion = next.version;
|
|
486
493
|
} else {
|
|
487
494
|
matchedVersion = next.entry;
|
|
@@ -503,14 +510,14 @@ function generateSnapshotFromManifest(manifest) {
|
|
|
503
510
|
var _manifest_metaData2 = manifest.metaData, _manifest_metaData_remoteEntry = _manifest_metaData2.remoteEntry, remoteEntryPath = _manifest_metaData_remoteEntry.path, remoteEntryName = _manifest_metaData_remoteEntry.name, remoteEntryType = _manifest_metaData_remoteEntry.type, remoteTypes = _manifest_metaData2.types, buildVersion = _manifest_metaData2.buildInfo.buildVersion, globalName = _manifest_metaData2.globalName;
|
|
504
511
|
var exposes = manifest.exposes;
|
|
505
512
|
var basicRemoteSnapshot = {
|
|
506
|
-
version: version ? version :
|
|
513
|
+
version: version ? version : '',
|
|
507
514
|
buildVersion: buildVersion,
|
|
508
515
|
globalName: globalName,
|
|
509
516
|
remoteEntry: simpleJoinRemoteEntry(remoteEntryPath, remoteEntryName),
|
|
510
517
|
remoteEntryType: remoteEntryType,
|
|
511
518
|
remoteTypes: simpleJoinRemoteEntry(remoteTypes.path, remoteTypes.name),
|
|
512
|
-
remoteTypesZip: remoteTypes.zip ||
|
|
513
|
-
remoteTypesAPI: remoteTypes.api ||
|
|
519
|
+
remoteTypesZip: remoteTypes.zip || '',
|
|
520
|
+
remoteTypesAPI: remoteTypes.api || '',
|
|
514
521
|
remotesInfo: remotesInfo,
|
|
515
522
|
shared: manifest === null || manifest === void 0 ? void 0 : manifest.shared.map(function(item) {
|
|
516
523
|
return {
|
|
@@ -540,7 +547,7 @@ function generateSnapshotFromManifest(manifest) {
|
|
|
540
547
|
prefetchEntryType: type
|
|
541
548
|
});
|
|
542
549
|
}
|
|
543
|
-
if (
|
|
550
|
+
if ('publicPath' in manifest.metaData) {
|
|
544
551
|
remoteSnapshot = _object_spread_props(_object_spread$1({}, basicRemoteSnapshot), {
|
|
545
552
|
publicPath: getPublicPath()
|
|
546
553
|
});
|
|
@@ -552,7 +559,7 @@ function generateSnapshotFromManifest(manifest) {
|
|
|
552
559
|
return remoteSnapshot;
|
|
553
560
|
}
|
|
554
561
|
function isManifestProvider(moduleInfo) {
|
|
555
|
-
if (
|
|
562
|
+
if ('remoteEntry' in moduleInfo && moduleInfo.remoteEntry.includes(MANIFEST_EXT)) {
|
|
556
563
|
return true;
|
|
557
564
|
} else {
|
|
558
565
|
return false;
|
|
@@ -734,8 +741,8 @@ function _safeWrapper() {
|
|
|
734
741
|
function isStaticResourcesEqual(url1, url2) {
|
|
735
742
|
var REG_EXP = /^(https?:)?\/\//i;
|
|
736
743
|
// Transform url1 and url2 into relative paths
|
|
737
|
-
var relativeUrl1 = url1.replace(REG_EXP,
|
|
738
|
-
var relativeUrl2 = url2.replace(REG_EXP,
|
|
744
|
+
var relativeUrl1 = url1.replace(REG_EXP, '').replace(/\/$/, '');
|
|
745
|
+
var relativeUrl2 = url2.replace(REG_EXP, '').replace(/\/$/, '');
|
|
739
746
|
// Check if the relative paths are identical
|
|
740
747
|
return relativeUrl1 === relativeUrl2;
|
|
741
748
|
}
|
|
@@ -743,10 +750,10 @@ function createScript(url, cb, attrs, createScriptHook) {
|
|
|
743
750
|
// Retrieve the existing script element by its src attribute
|
|
744
751
|
var script = null;
|
|
745
752
|
var needAttach = true;
|
|
746
|
-
var scripts = document.getElementsByTagName(
|
|
753
|
+
var scripts = document.getElementsByTagName('script');
|
|
747
754
|
for(var i = 0; i < scripts.length; i++){
|
|
748
755
|
var s = scripts[i];
|
|
749
|
-
var scriptSrc = s.getAttribute(
|
|
756
|
+
var scriptSrc = s.getAttribute('src');
|
|
750
757
|
if (scriptSrc && isStaticResourcesEqual(scriptSrc, url)) {
|
|
751
758
|
script = s;
|
|
752
759
|
needAttach = false;
|
|
@@ -754,8 +761,8 @@ function createScript(url, cb, attrs, createScriptHook) {
|
|
|
754
761
|
}
|
|
755
762
|
}
|
|
756
763
|
if (!script) {
|
|
757
|
-
script = document.createElement(
|
|
758
|
-
script.type =
|
|
764
|
+
script = document.createElement('script');
|
|
765
|
+
script.type = 'text/javascript';
|
|
759
766
|
script.src = url;
|
|
760
767
|
if (createScriptHook) {
|
|
761
768
|
var createScriptRes = createScriptHook(url);
|
|
@@ -767,7 +774,7 @@ function createScript(url, cb, attrs, createScriptHook) {
|
|
|
767
774
|
if (attrs) {
|
|
768
775
|
Object.keys(attrs).forEach(function(name) {
|
|
769
776
|
if (script) {
|
|
770
|
-
if (name ===
|
|
777
|
+
if (name === 'async' || name === 'defer') {
|
|
771
778
|
script[name] = attrs[name];
|
|
772
779
|
} else {
|
|
773
780
|
script.setAttribute(name, attrs[name]);
|
|
@@ -806,20 +813,20 @@ function createLink(url, cb) {
|
|
|
806
813
|
// Retrieve the existing script element by its src attribute
|
|
807
814
|
var link = null;
|
|
808
815
|
var needAttach = true;
|
|
809
|
-
var links = document.getElementsByTagName(
|
|
816
|
+
var links = document.getElementsByTagName('link');
|
|
810
817
|
for(var i = 0; i < links.length; i++){
|
|
811
818
|
var l = links[i];
|
|
812
|
-
var linkHref = l.getAttribute(
|
|
813
|
-
var linkRef = l.getAttribute(
|
|
814
|
-
if (linkHref && isStaticResourcesEqual(linkHref, url) && linkRef === attrs[
|
|
819
|
+
var linkHref = l.getAttribute('href');
|
|
820
|
+
var linkRef = l.getAttribute('ref');
|
|
821
|
+
if (linkHref && isStaticResourcesEqual(linkHref, url) && linkRef === attrs['ref']) {
|
|
815
822
|
link = l;
|
|
816
823
|
needAttach = false;
|
|
817
824
|
break;
|
|
818
825
|
}
|
|
819
826
|
}
|
|
820
827
|
if (!link) {
|
|
821
|
-
link = document.createElement(
|
|
822
|
-
link.setAttribute(
|
|
828
|
+
link = document.createElement('link');
|
|
829
|
+
link.setAttribute('href', url);
|
|
823
830
|
if (createLinkHook) {
|
|
824
831
|
var createLinkRes = createLinkHook(url);
|
|
825
832
|
if (_instanceof(createLinkRes, HTMLLinkElement)) {
|
|
@@ -863,7 +870,7 @@ function loadScript(url, info) {
|
|
|
863
870
|
var attrs = info.attrs, createScriptHook = info.createScriptHook;
|
|
864
871
|
return new Promise(function(resolve, _reject) {
|
|
865
872
|
var _createScript = createScript(url, resolve, attrs, createScriptHook), script = _createScript.script, needAttach = _createScript.needAttach;
|
|
866
|
-
needAttach && document.getElementsByTagName(
|
|
873
|
+
needAttach && document.getElementsByTagName('head')[0].appendChild(script);
|
|
867
874
|
});
|
|
868
875
|
}
|
|
869
876
|
|
|
@@ -1039,9 +1046,9 @@ function _ts_generator(thisArg, body) {
|
|
|
1039
1046
|
}
|
|
1040
1047
|
function importNodeModule(name) {
|
|
1041
1048
|
if (!name) {
|
|
1042
|
-
throw new Error(
|
|
1049
|
+
throw new Error('import specifier is required');
|
|
1043
1050
|
}
|
|
1044
|
-
var importModule = new Function(
|
|
1051
|
+
var importModule = new Function('name', "return import(name)");
|
|
1045
1052
|
return importModule(name).then(function(res) {
|
|
1046
1053
|
return res.default;
|
|
1047
1054
|
}).catch(function(error) {
|
|
@@ -1052,7 +1059,7 @@ function importNodeModule(name) {
|
|
|
1052
1059
|
function createScriptNode(url, cb, attrs, createScriptHook) {
|
|
1053
1060
|
if (createScriptHook) {
|
|
1054
1061
|
var hookResult = createScriptHook(url);
|
|
1055
|
-
if (hookResult && typeof hookResult ===
|
|
1062
|
+
if (hookResult && typeof hookResult === 'object' && 'url' in hookResult) {
|
|
1056
1063
|
url = hookResult.url;
|
|
1057
1064
|
}
|
|
1058
1065
|
}
|
|
@@ -1060,7 +1067,7 @@ function createScriptNode(url, cb, attrs, createScriptHook) {
|
|
|
1060
1067
|
try {
|
|
1061
1068
|
urlObj = new URL(url);
|
|
1062
1069
|
} catch (e) {
|
|
1063
|
-
console.error(
|
|
1070
|
+
console.error('Error constructing URL:', e);
|
|
1064
1071
|
cb(new Error("Invalid URL: ".concat(e)));
|
|
1065
1072
|
return;
|
|
1066
1073
|
}
|
|
@@ -1070,13 +1077,13 @@ function createScriptNode(url, cb, attrs, createScriptHook) {
|
|
|
1070
1077
|
return _ts_generator(this, function(_state) {
|
|
1071
1078
|
switch(_state.label){
|
|
1072
1079
|
case 0:
|
|
1073
|
-
if (!(typeof fetch ===
|
|
1080
|
+
if (!(typeof fetch === 'undefined')) return [
|
|
1074
1081
|
3,
|
|
1075
1082
|
2
|
|
1076
1083
|
];
|
|
1077
1084
|
return [
|
|
1078
1085
|
4,
|
|
1079
|
-
importNodeModule(
|
|
1086
|
+
importNodeModule('node-fetch')
|
|
1080
1087
|
];
|
|
1081
1088
|
case 1:
|
|
1082
1089
|
fetchModule = _state.sent();
|
|
@@ -1101,7 +1108,7 @@ function createScriptNode(url, cb, attrs, createScriptHook) {
|
|
|
1101
1108
|
return _ref.apply(this, arguments);
|
|
1102
1109
|
};
|
|
1103
1110
|
}();
|
|
1104
|
-
console.log(
|
|
1111
|
+
console.log('fetching', urlObj.href);
|
|
1105
1112
|
getFetch().then(function(f) {
|
|
1106
1113
|
f(urlObj.href).then(function(res) {
|
|
1107
1114
|
return res.text();
|
|
@@ -1114,8 +1121,8 @@ function createScriptNode(url, cb, attrs, createScriptHook) {
|
|
|
1114
1121
|
return [
|
|
1115
1122
|
4,
|
|
1116
1123
|
Promise.all([
|
|
1117
|
-
importNodeModule(
|
|
1118
|
-
importNodeModule(
|
|
1124
|
+
importNodeModule('path'),
|
|
1125
|
+
importNodeModule('vm')
|
|
1119
1126
|
])
|
|
1120
1127
|
];
|
|
1121
1128
|
case 1:
|
|
@@ -1129,14 +1136,14 @@ function createScriptNode(url, cb, attrs, createScriptHook) {
|
|
|
1129
1136
|
exports: {}
|
|
1130
1137
|
}
|
|
1131
1138
|
};
|
|
1132
|
-
urlDirname = urlObj.pathname.split(
|
|
1139
|
+
urlDirname = urlObj.pathname.split('/').slice(0, -1).join('/');
|
|
1133
1140
|
filename = path.basename(urlObj.pathname);
|
|
1134
1141
|
try {
|
|
1135
1142
|
script = new vm.Script("(function(exports, module, require, __dirname, __filename) {".concat(data, "\n})"), filename);
|
|
1136
|
-
script.runInThisContext()(scriptContext.exports, scriptContext.module, eval(
|
|
1143
|
+
script.runInThisContext()(scriptContext.exports, scriptContext.module, eval('require'), urlDirname, filename);
|
|
1137
1144
|
exportedInterface = scriptContext.module.exports || scriptContext.exports;
|
|
1138
|
-
if (attrs && exportedInterface && attrs[
|
|
1139
|
-
container = exportedInterface[attrs[
|
|
1145
|
+
if (attrs && exportedInterface && attrs['globalName']) {
|
|
1146
|
+
container = exportedInterface[attrs['globalName']] || exportedInterface;
|
|
1140
1147
|
cb(undefined, container);
|
|
1141
1148
|
return [
|
|
1142
1149
|
2
|
|
@@ -1169,7 +1176,7 @@ function loadScriptNode(url, info) {
|
|
|
1169
1176
|
reject(error);
|
|
1170
1177
|
} else {
|
|
1171
1178
|
var _info_attrs, _info_attrs1;
|
|
1172
|
-
var remoteEntryKey = (info === null || info === void 0 ? void 0 : (_info_attrs = info.attrs) === null || _info_attrs === void 0 ? void 0 : _info_attrs[
|
|
1179
|
+
var remoteEntryKey = (info === null || info === void 0 ? void 0 : (_info_attrs = info.attrs) === null || _info_attrs === void 0 ? void 0 : _info_attrs['globalName']) || "__FEDERATION_".concat(info === null || info === void 0 ? void 0 : (_info_attrs1 = info.attrs) === null || _info_attrs1 === void 0 ? void 0 : _info_attrs1['name'], ":custom__");
|
|
1173
1180
|
var entryExports = globalThis[remoteEntryKey] = scriptContext;
|
|
1174
1181
|
resolve(entryExports);
|
|
1175
1182
|
}
|
|
@@ -1214,7 +1221,7 @@ function normalizeOptions(enableDefault, defaultOptions, key) {
|
|
|
1214
1221
|
if (options === false) {
|
|
1215
1222
|
return false;
|
|
1216
1223
|
}
|
|
1217
|
-
if (typeof options ===
|
|
1224
|
+
if (typeof options === 'undefined') {
|
|
1218
1225
|
if (enableDefault) {
|
|
1219
1226
|
return defaultOptions;
|
|
1220
1227
|
} else {
|
|
@@ -1224,7 +1231,7 @@ function normalizeOptions(enableDefault, defaultOptions, key) {
|
|
|
1224
1231
|
if (options === true) {
|
|
1225
1232
|
return defaultOptions;
|
|
1226
1233
|
}
|
|
1227
|
-
if (options && typeof options ===
|
|
1234
|
+
if (options && typeof options === 'object') {
|
|
1228
1235
|
return _object_spread({}, defaultOptions, options);
|
|
1229
1236
|
}
|
|
1230
1237
|
throw new Error("Unexpected type for `".concat(key, "`, expect boolean/undefined/object, got: ").concat(typeof options === "undefined" ? "undefined" : _type_of(options)));
|
|
@@ -1259,6 +1266,7 @@ exports.generateShareFilename = generateShareFilename;
|
|
|
1259
1266
|
exports.generateSnapshotFromManifest = generateSnapshotFromManifest;
|
|
1260
1267
|
exports.getProcessEnv = getProcessEnv;
|
|
1261
1268
|
exports.getResourceUrl = getResourceUrl;
|
|
1269
|
+
exports.inferAutoPublicPath = inferAutoPublicPath;
|
|
1262
1270
|
exports.isBrowserEnv = isBrowserEnv;
|
|
1263
1271
|
exports.isDebugMode = isDebugMode;
|
|
1264
1272
|
exports.isManifestProvider = isManifestProvider;
|
package/dist/index.esm.js
CHANGED
|
@@ -11,27 +11,27 @@ function _define_property$3(obj, key, value) {
|
|
|
11
11
|
}
|
|
12
12
|
return obj;
|
|
13
13
|
}
|
|
14
|
-
var FederationModuleManifest =
|
|
15
|
-
var MANIFEST_EXT =
|
|
16
|
-
var BROWSER_LOG_KEY =
|
|
17
|
-
var BROWSER_LOG_VALUE =
|
|
14
|
+
var FederationModuleManifest = 'federation-manifest.json';
|
|
15
|
+
var MANIFEST_EXT = '.json';
|
|
16
|
+
var BROWSER_LOG_KEY = 'FEDERATION_DEBUG';
|
|
17
|
+
var BROWSER_LOG_VALUE = '1';
|
|
18
18
|
var NameTransformSymbol = {
|
|
19
|
-
AT:
|
|
20
|
-
HYPHEN:
|
|
21
|
-
SLASH:
|
|
19
|
+
AT: '@',
|
|
20
|
+
HYPHEN: '-',
|
|
21
|
+
SLASH: '/'
|
|
22
22
|
};
|
|
23
23
|
var _obj;
|
|
24
|
-
var NameTransformMap = (_obj = {}, _define_property$3(_obj, NameTransformSymbol.AT,
|
|
24
|
+
var NameTransformMap = (_obj = {}, _define_property$3(_obj, NameTransformSymbol.AT, 'scope_'), _define_property$3(_obj, NameTransformSymbol.HYPHEN, '_'), _define_property$3(_obj, NameTransformSymbol.SLASH, '__'), _obj);
|
|
25
25
|
var _obj1;
|
|
26
26
|
var EncodedNameTransformMap = (_obj1 = {}, _define_property$3(_obj1, NameTransformMap[NameTransformSymbol.AT], NameTransformSymbol.AT), _define_property$3(_obj1, NameTransformMap[NameTransformSymbol.HYPHEN], NameTransformSymbol.HYPHEN), _define_property$3(_obj1, NameTransformMap[NameTransformSymbol.SLASH], NameTransformSymbol.SLASH), _obj1);
|
|
27
|
-
var SEPARATOR =
|
|
28
|
-
var ManifestFileName =
|
|
29
|
-
var StatsFileName =
|
|
27
|
+
var SEPARATOR = ':';
|
|
28
|
+
var ManifestFileName = 'mf-manifest.json';
|
|
29
|
+
var StatsFileName = 'mf-stats.json';
|
|
30
30
|
var MFModuleType = {
|
|
31
|
-
NPM:
|
|
32
|
-
APP:
|
|
31
|
+
NPM: 'npm',
|
|
32
|
+
APP: 'app'
|
|
33
33
|
};
|
|
34
|
-
var MODULE_DEVTOOL_IDENTIFIER =
|
|
34
|
+
var MODULE_DEVTOOL_IDENTIFIER = '__MF_DEVTOOLS_MODULE_INFO__';
|
|
35
35
|
|
|
36
36
|
var ContainerPlugin = /*#__PURE__*/Object.freeze({
|
|
37
37
|
__proto__: null
|
|
@@ -50,16 +50,16 @@ var SharePlugin = /*#__PURE__*/Object.freeze({
|
|
|
50
50
|
});
|
|
51
51
|
|
|
52
52
|
function isBrowserEnv() {
|
|
53
|
-
return typeof window !==
|
|
53
|
+
return typeof window !== 'undefined';
|
|
54
54
|
}
|
|
55
55
|
function isDebugMode() {
|
|
56
|
-
if (typeof process !==
|
|
57
|
-
return Boolean(process.env[
|
|
56
|
+
if (typeof process !== 'undefined' && process.env && process.env['FEDERATION_DEBUG']) {
|
|
57
|
+
return Boolean(process.env['FEDERATION_DEBUG']);
|
|
58
58
|
}
|
|
59
|
-
return typeof FEDERATION_DEBUG !==
|
|
59
|
+
return typeof FEDERATION_DEBUG !== 'undefined' && Boolean(FEDERATION_DEBUG);
|
|
60
60
|
}
|
|
61
61
|
var getProcessEnv = function getProcessEnv() {
|
|
62
|
-
return typeof process !==
|
|
62
|
+
return typeof process !== 'undefined' && process.env ? process.env : {};
|
|
63
63
|
};
|
|
64
64
|
|
|
65
65
|
function _array_like_to_array$2(arr, len) {
|
|
@@ -123,17 +123,17 @@ function safeToString(info) {
|
|
|
123
123
|
try {
|
|
124
124
|
return JSON.stringify(info, null, 2);
|
|
125
125
|
} catch (e) {
|
|
126
|
-
return
|
|
126
|
+
return '';
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
|
-
var DEBUG_LOG =
|
|
129
|
+
var DEBUG_LOG = '[ FEDERATION DEBUG ]';
|
|
130
130
|
function safeGetLocalStorageItem() {
|
|
131
131
|
try {
|
|
132
|
-
if (typeof window !==
|
|
132
|
+
if (typeof window !== 'undefined' && window.localStorage) {
|
|
133
133
|
return localStorage.getItem(BROWSER_LOG_KEY) === BROWSER_LOG_VALUE;
|
|
134
134
|
}
|
|
135
135
|
} catch (error) {
|
|
136
|
-
return typeof document !==
|
|
136
|
+
return typeof document !== 'undefined';
|
|
137
137
|
}
|
|
138
138
|
return false;
|
|
139
139
|
}
|
|
@@ -154,11 +154,11 @@ var Logger = /*#__PURE__*/ function() {
|
|
|
154
154
|
key: "info",
|
|
155
155
|
value: function info(msg, info) {
|
|
156
156
|
if (this.enable) {
|
|
157
|
-
var argsToString = safeToString(info) ||
|
|
157
|
+
var argsToString = safeToString(info) || '';
|
|
158
158
|
if (isBrowserEnv()) {
|
|
159
|
-
console.info("%c ".concat(this.identifier, ": ").concat(msg, " ").concat(argsToString),
|
|
159
|
+
console.info("%c ".concat(this.identifier, ": ").concat(msg, " ").concat(argsToString), 'color:#3300CC');
|
|
160
160
|
} else {
|
|
161
|
-
console.info(
|
|
161
|
+
console.info('\x1b[34m%s', "".concat(this.identifier, ": ").concat(msg, " ").concat(argsToString ? "\n".concat(argsToString) : ''));
|
|
162
162
|
}
|
|
163
163
|
}
|
|
164
164
|
}
|
|
@@ -172,11 +172,11 @@ var Logger = /*#__PURE__*/ function() {
|
|
|
172
172
|
if (this.enable) {
|
|
173
173
|
if (isBrowserEnv()) {
|
|
174
174
|
var _console;
|
|
175
|
-
console.info("%c ".concat(this.identifier, ": OriginalInfo"),
|
|
175
|
+
console.info("%c ".concat(this.identifier, ": OriginalInfo"), 'color:#3300CC');
|
|
176
176
|
(_console = console).log.apply(_console, _to_consumable_array(args));
|
|
177
177
|
} else {
|
|
178
178
|
var _console1;
|
|
179
|
-
console.info("%c ".concat(this.identifier, ": OriginalInfo"),
|
|
179
|
+
console.info("%c ".concat(this.identifier, ": OriginalInfo"), 'color:#3300CC');
|
|
180
180
|
(_console1 = console).log.apply(_console1, _to_consumable_array(args));
|
|
181
181
|
}
|
|
182
182
|
}
|
|
@@ -238,16 +238,16 @@ function _unsupported_iterable_to_array$1(o, minLen) {
|
|
|
238
238
|
if (n === "Map" || n === "Set") return Array.from(n);
|
|
239
239
|
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$1(o, minLen);
|
|
240
240
|
}
|
|
241
|
-
var LOG_CATEGORY =
|
|
241
|
+
var LOG_CATEGORY = '[ Federation Runtime ]';
|
|
242
242
|
// entry: name:version version : 1.0.0 | ^1.2.3
|
|
243
243
|
// entry: name:entry entry: https://localhost:9000/federation-manifest.json
|
|
244
244
|
var parseEntry = function(str, devVerOrUrl) {
|
|
245
245
|
var separator = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : SEPARATOR;
|
|
246
246
|
var strSplit = str.split(separator);
|
|
247
|
-
var devVersionOrUrl = getProcessEnv()[
|
|
248
|
-
var defaultVersion =
|
|
247
|
+
var devVersionOrUrl = getProcessEnv()['NODE_ENV'] === 'development' && devVerOrUrl;
|
|
248
|
+
var defaultVersion = '*';
|
|
249
249
|
var isEntry = function(s) {
|
|
250
|
-
return s.startsWith(
|
|
250
|
+
return s.startsWith('http') || s.includes(MANIFEST_EXT);
|
|
251
251
|
};
|
|
252
252
|
// Check if the string starts with a type
|
|
253
253
|
if (strSplit.length >= 2) {
|
|
@@ -288,7 +288,7 @@ var composeKeyWithSeparator = function composeKeyWithSeparator() {
|
|
|
288
288
|
args[_key] = arguments[_key];
|
|
289
289
|
}
|
|
290
290
|
if (!args.length) {
|
|
291
|
-
return
|
|
291
|
+
return '';
|
|
292
292
|
}
|
|
293
293
|
return args.reduce(function(sum, cur) {
|
|
294
294
|
if (!cur) {
|
|
@@ -298,13 +298,13 @@ var composeKeyWithSeparator = function composeKeyWithSeparator() {
|
|
|
298
298
|
return cur;
|
|
299
299
|
}
|
|
300
300
|
return "".concat(sum).concat(SEPARATOR).concat(cur);
|
|
301
|
-
},
|
|
301
|
+
}, '');
|
|
302
302
|
};
|
|
303
303
|
var encodeName = function encodeName(name) {
|
|
304
|
-
var prefix = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] :
|
|
304
|
+
var prefix = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : '', withExt = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
|
|
305
305
|
try {
|
|
306
|
-
var ext = withExt ?
|
|
307
|
-
return "".concat(prefix).concat(name.replace(new RegExp("".concat(NameTransformSymbol.AT),
|
|
306
|
+
var ext = withExt ? '.js' : '';
|
|
307
|
+
return "".concat(prefix).concat(name.replace(new RegExp("".concat(NameTransformSymbol.AT), 'g'), NameTransformMap[NameTransformSymbol.AT]).replace(new RegExp("".concat(NameTransformSymbol.HYPHEN), 'g'), NameTransformMap[NameTransformSymbol.HYPHEN]).replace(new RegExp("".concat(NameTransformSymbol.SLASH), 'g'), NameTransformMap[NameTransformSymbol.SLASH])).concat(ext);
|
|
308
308
|
} catch (err) {
|
|
309
309
|
throw err;
|
|
310
310
|
}
|
|
@@ -316,11 +316,11 @@ var decodeName = function decodeName(name, prefix, withExt) {
|
|
|
316
316
|
if (!decodedName.startsWith(prefix)) {
|
|
317
317
|
return decodedName;
|
|
318
318
|
}
|
|
319
|
-
decodedName = decodedName.replace(new RegExp(prefix,
|
|
319
|
+
decodedName = decodedName.replace(new RegExp(prefix, 'g'), '');
|
|
320
320
|
}
|
|
321
|
-
decodedName = decodedName.replace(new RegExp("".concat(NameTransformMap[NameTransformSymbol.AT]),
|
|
321
|
+
decodedName = decodedName.replace(new RegExp("".concat(NameTransformMap[NameTransformSymbol.AT]), 'g'), EncodedNameTransformMap[NameTransformMap[NameTransformSymbol.AT]]).replace(new RegExp("".concat(NameTransformMap[NameTransformSymbol.SLASH]), 'g'), EncodedNameTransformMap[NameTransformMap[NameTransformSymbol.SLASH]]).replace(new RegExp("".concat(NameTransformMap[NameTransformSymbol.HYPHEN]), 'g'), EncodedNameTransformMap[NameTransformMap[NameTransformSymbol.HYPHEN]]);
|
|
322
322
|
if (withExt) {
|
|
323
|
-
decodedName = decodedName.replace(
|
|
323
|
+
decodedName = decodedName.replace('.js', '');
|
|
324
324
|
}
|
|
325
325
|
return decodedName;
|
|
326
326
|
} catch (err) {
|
|
@@ -329,32 +329,32 @@ var decodeName = function decodeName(name, prefix, withExt) {
|
|
|
329
329
|
};
|
|
330
330
|
var generateExposeFilename = function(exposeName, withExt) {
|
|
331
331
|
if (!exposeName) {
|
|
332
|
-
return
|
|
332
|
+
return '';
|
|
333
333
|
}
|
|
334
334
|
var expose = exposeName;
|
|
335
|
-
if (expose ===
|
|
336
|
-
expose =
|
|
335
|
+
if (expose === '.') {
|
|
336
|
+
expose = 'default_export';
|
|
337
337
|
}
|
|
338
|
-
if (expose.startsWith(
|
|
339
|
-
expose = expose.replace(
|
|
338
|
+
if (expose.startsWith('./')) {
|
|
339
|
+
expose = expose.replace('./', '');
|
|
340
340
|
}
|
|
341
|
-
return encodeName(expose,
|
|
341
|
+
return encodeName(expose, '__federation_expose_', withExt);
|
|
342
342
|
};
|
|
343
343
|
var generateShareFilename = function(pkgName, withExt) {
|
|
344
344
|
if (!pkgName) {
|
|
345
|
-
return
|
|
345
|
+
return '';
|
|
346
346
|
}
|
|
347
|
-
return encodeName(pkgName,
|
|
347
|
+
return encodeName(pkgName, '__federation_shared_', withExt);
|
|
348
348
|
};
|
|
349
349
|
var getResourceUrl = function(module, sourceUrl) {
|
|
350
|
-
if (
|
|
350
|
+
if ('getPublicPath' in module) {
|
|
351
351
|
var publicPath = new Function(module.getPublicPath)();
|
|
352
352
|
return "".concat(publicPath).concat(sourceUrl);
|
|
353
|
-
} else if (
|
|
353
|
+
} else if ('publicPath' in module) {
|
|
354
354
|
return "".concat(module.publicPath).concat(sourceUrl);
|
|
355
355
|
} else {
|
|
356
|
-
console.warn(
|
|
357
|
-
return
|
|
356
|
+
console.warn('Can not get resource url, if in debug mode, please ignore', module, sourceUrl);
|
|
357
|
+
return '';
|
|
358
358
|
}
|
|
359
359
|
};
|
|
360
360
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
@@ -427,15 +427,15 @@ var simpleJoinRemoteEntry = function(rPath, rName) {
|
|
|
427
427
|
return rName;
|
|
428
428
|
}
|
|
429
429
|
var transformPath = function(str) {
|
|
430
|
-
if (str ===
|
|
431
|
-
return
|
|
430
|
+
if (str === '.') {
|
|
431
|
+
return '';
|
|
432
432
|
}
|
|
433
|
-
if (str.startsWith(
|
|
434
|
-
return str.replace(
|
|
433
|
+
if (str.startsWith('./')) {
|
|
434
|
+
return str.replace('./', '');
|
|
435
435
|
}
|
|
436
|
-
if (str.startsWith(
|
|
436
|
+
if (str.startsWith('/')) {
|
|
437
437
|
var strWithoutSlash = str.slice(1);
|
|
438
|
-
if (strWithoutSlash.endsWith(
|
|
438
|
+
if (strWithoutSlash.endsWith('/')) {
|
|
439
439
|
return strWithoutSlash.slice(0, -1);
|
|
440
440
|
}
|
|
441
441
|
return strWithoutSlash;
|
|
@@ -446,11 +446,14 @@ var simpleJoinRemoteEntry = function(rPath, rName) {
|
|
|
446
446
|
if (!transformedPath) {
|
|
447
447
|
return rName;
|
|
448
448
|
}
|
|
449
|
-
if (transformedPath.endsWith(
|
|
449
|
+
if (transformedPath.endsWith('/')) {
|
|
450
450
|
return "".concat(transformedPath).concat(rName);
|
|
451
451
|
}
|
|
452
452
|
return "".concat(transformedPath, "/").concat(rName);
|
|
453
453
|
};
|
|
454
|
+
function inferAutoPublicPath(url) {
|
|
455
|
+
return url.replace(/#.*$/, '').replace(/\?.*$/, '').replace(/\/[^\/]+$/, '/');
|
|
456
|
+
}
|
|
454
457
|
// Priority: overrides > remotes
|
|
455
458
|
// eslint-disable-next-line max-lines-per-function
|
|
456
459
|
function generateSnapshotFromManifest(manifest) {
|
|
@@ -459,7 +462,11 @@ function generateSnapshotFromManifest(manifest) {
|
|
|
459
462
|
var _options_remotes = options.remotes, remotes = _options_remotes === void 0 ? {} : _options_remotes, _options_overrides = options.overrides, overrides = _options_overrides === void 0 ? {} : _options_overrides, version = options.version;
|
|
460
463
|
var remoteSnapshot;
|
|
461
464
|
var getPublicPath = function() {
|
|
462
|
-
if (
|
|
465
|
+
if ('publicPath' in manifest.metaData) {
|
|
466
|
+
if (manifest.metaData.publicPath === 'auto' && version) {
|
|
467
|
+
// use same implementation as publicPath auto runtime module implements
|
|
468
|
+
return inferAutoPublicPath(version);
|
|
469
|
+
}
|
|
463
470
|
return manifest.metaData.publicPath;
|
|
464
471
|
} else {
|
|
465
472
|
return manifest.metaData.getPublicPath;
|
|
@@ -477,7 +484,7 @@ function generateSnapshotFromManifest(manifest) {
|
|
|
477
484
|
if (overridesKeys.includes(name)) {
|
|
478
485
|
matchedVersion = overrides[name];
|
|
479
486
|
} else {
|
|
480
|
-
if (
|
|
487
|
+
if ('version' in next) {
|
|
481
488
|
matchedVersion = next.version;
|
|
482
489
|
} else {
|
|
483
490
|
matchedVersion = next.entry;
|
|
@@ -499,14 +506,14 @@ function generateSnapshotFromManifest(manifest) {
|
|
|
499
506
|
var _manifest_metaData2 = manifest.metaData, _manifest_metaData_remoteEntry = _manifest_metaData2.remoteEntry, remoteEntryPath = _manifest_metaData_remoteEntry.path, remoteEntryName = _manifest_metaData_remoteEntry.name, remoteEntryType = _manifest_metaData_remoteEntry.type, remoteTypes = _manifest_metaData2.types, buildVersion = _manifest_metaData2.buildInfo.buildVersion, globalName = _manifest_metaData2.globalName;
|
|
500
507
|
var exposes = manifest.exposes;
|
|
501
508
|
var basicRemoteSnapshot = {
|
|
502
|
-
version: version ? version :
|
|
509
|
+
version: version ? version : '',
|
|
503
510
|
buildVersion: buildVersion,
|
|
504
511
|
globalName: globalName,
|
|
505
512
|
remoteEntry: simpleJoinRemoteEntry(remoteEntryPath, remoteEntryName),
|
|
506
513
|
remoteEntryType: remoteEntryType,
|
|
507
514
|
remoteTypes: simpleJoinRemoteEntry(remoteTypes.path, remoteTypes.name),
|
|
508
|
-
remoteTypesZip: remoteTypes.zip ||
|
|
509
|
-
remoteTypesAPI: remoteTypes.api ||
|
|
515
|
+
remoteTypesZip: remoteTypes.zip || '',
|
|
516
|
+
remoteTypesAPI: remoteTypes.api || '',
|
|
510
517
|
remotesInfo: remotesInfo,
|
|
511
518
|
shared: manifest === null || manifest === void 0 ? void 0 : manifest.shared.map(function(item) {
|
|
512
519
|
return {
|
|
@@ -536,7 +543,7 @@ function generateSnapshotFromManifest(manifest) {
|
|
|
536
543
|
prefetchEntryType: type
|
|
537
544
|
});
|
|
538
545
|
}
|
|
539
|
-
if (
|
|
546
|
+
if ('publicPath' in manifest.metaData) {
|
|
540
547
|
remoteSnapshot = _object_spread_props(_object_spread$1({}, basicRemoteSnapshot), {
|
|
541
548
|
publicPath: getPublicPath()
|
|
542
549
|
});
|
|
@@ -548,7 +555,7 @@ function generateSnapshotFromManifest(manifest) {
|
|
|
548
555
|
return remoteSnapshot;
|
|
549
556
|
}
|
|
550
557
|
function isManifestProvider(moduleInfo) {
|
|
551
|
-
if (
|
|
558
|
+
if ('remoteEntry' in moduleInfo && moduleInfo.remoteEntry.includes(MANIFEST_EXT)) {
|
|
552
559
|
return true;
|
|
553
560
|
} else {
|
|
554
561
|
return false;
|
|
@@ -730,8 +737,8 @@ function _safeWrapper() {
|
|
|
730
737
|
function isStaticResourcesEqual(url1, url2) {
|
|
731
738
|
var REG_EXP = /^(https?:)?\/\//i;
|
|
732
739
|
// Transform url1 and url2 into relative paths
|
|
733
|
-
var relativeUrl1 = url1.replace(REG_EXP,
|
|
734
|
-
var relativeUrl2 = url2.replace(REG_EXP,
|
|
740
|
+
var relativeUrl1 = url1.replace(REG_EXP, '').replace(/\/$/, '');
|
|
741
|
+
var relativeUrl2 = url2.replace(REG_EXP, '').replace(/\/$/, '');
|
|
735
742
|
// Check if the relative paths are identical
|
|
736
743
|
return relativeUrl1 === relativeUrl2;
|
|
737
744
|
}
|
|
@@ -739,10 +746,10 @@ function createScript(url, cb, attrs, createScriptHook) {
|
|
|
739
746
|
// Retrieve the existing script element by its src attribute
|
|
740
747
|
var script = null;
|
|
741
748
|
var needAttach = true;
|
|
742
|
-
var scripts = document.getElementsByTagName(
|
|
749
|
+
var scripts = document.getElementsByTagName('script');
|
|
743
750
|
for(var i = 0; i < scripts.length; i++){
|
|
744
751
|
var s = scripts[i];
|
|
745
|
-
var scriptSrc = s.getAttribute(
|
|
752
|
+
var scriptSrc = s.getAttribute('src');
|
|
746
753
|
if (scriptSrc && isStaticResourcesEqual(scriptSrc, url)) {
|
|
747
754
|
script = s;
|
|
748
755
|
needAttach = false;
|
|
@@ -750,8 +757,8 @@ function createScript(url, cb, attrs, createScriptHook) {
|
|
|
750
757
|
}
|
|
751
758
|
}
|
|
752
759
|
if (!script) {
|
|
753
|
-
script = document.createElement(
|
|
754
|
-
script.type =
|
|
760
|
+
script = document.createElement('script');
|
|
761
|
+
script.type = 'text/javascript';
|
|
755
762
|
script.src = url;
|
|
756
763
|
if (createScriptHook) {
|
|
757
764
|
var createScriptRes = createScriptHook(url);
|
|
@@ -763,7 +770,7 @@ function createScript(url, cb, attrs, createScriptHook) {
|
|
|
763
770
|
if (attrs) {
|
|
764
771
|
Object.keys(attrs).forEach(function(name) {
|
|
765
772
|
if (script) {
|
|
766
|
-
if (name ===
|
|
773
|
+
if (name === 'async' || name === 'defer') {
|
|
767
774
|
script[name] = attrs[name];
|
|
768
775
|
} else {
|
|
769
776
|
script.setAttribute(name, attrs[name]);
|
|
@@ -802,20 +809,20 @@ function createLink(url, cb) {
|
|
|
802
809
|
// Retrieve the existing script element by its src attribute
|
|
803
810
|
var link = null;
|
|
804
811
|
var needAttach = true;
|
|
805
|
-
var links = document.getElementsByTagName(
|
|
812
|
+
var links = document.getElementsByTagName('link');
|
|
806
813
|
for(var i = 0; i < links.length; i++){
|
|
807
814
|
var l = links[i];
|
|
808
|
-
var linkHref = l.getAttribute(
|
|
809
|
-
var linkRef = l.getAttribute(
|
|
810
|
-
if (linkHref && isStaticResourcesEqual(linkHref, url) && linkRef === attrs[
|
|
815
|
+
var linkHref = l.getAttribute('href');
|
|
816
|
+
var linkRef = l.getAttribute('ref');
|
|
817
|
+
if (linkHref && isStaticResourcesEqual(linkHref, url) && linkRef === attrs['ref']) {
|
|
811
818
|
link = l;
|
|
812
819
|
needAttach = false;
|
|
813
820
|
break;
|
|
814
821
|
}
|
|
815
822
|
}
|
|
816
823
|
if (!link) {
|
|
817
|
-
link = document.createElement(
|
|
818
|
-
link.setAttribute(
|
|
824
|
+
link = document.createElement('link');
|
|
825
|
+
link.setAttribute('href', url);
|
|
819
826
|
if (createLinkHook) {
|
|
820
827
|
var createLinkRes = createLinkHook(url);
|
|
821
828
|
if (_instanceof(createLinkRes, HTMLLinkElement)) {
|
|
@@ -859,7 +866,7 @@ function loadScript(url, info) {
|
|
|
859
866
|
var attrs = info.attrs, createScriptHook = info.createScriptHook;
|
|
860
867
|
return new Promise(function(resolve, _reject) {
|
|
861
868
|
var _createScript = createScript(url, resolve, attrs, createScriptHook), script = _createScript.script, needAttach = _createScript.needAttach;
|
|
862
|
-
needAttach && document.getElementsByTagName(
|
|
869
|
+
needAttach && document.getElementsByTagName('head')[0].appendChild(script);
|
|
863
870
|
});
|
|
864
871
|
}
|
|
865
872
|
|
|
@@ -1035,9 +1042,9 @@ function _ts_generator(thisArg, body) {
|
|
|
1035
1042
|
}
|
|
1036
1043
|
function importNodeModule(name) {
|
|
1037
1044
|
if (!name) {
|
|
1038
|
-
throw new Error(
|
|
1045
|
+
throw new Error('import specifier is required');
|
|
1039
1046
|
}
|
|
1040
|
-
var importModule = new Function(
|
|
1047
|
+
var importModule = new Function('name', "return import(name)");
|
|
1041
1048
|
return importModule(name).then(function(res) {
|
|
1042
1049
|
return res.default;
|
|
1043
1050
|
}).catch(function(error) {
|
|
@@ -1048,7 +1055,7 @@ function importNodeModule(name) {
|
|
|
1048
1055
|
function createScriptNode(url, cb, attrs, createScriptHook) {
|
|
1049
1056
|
if (createScriptHook) {
|
|
1050
1057
|
var hookResult = createScriptHook(url);
|
|
1051
|
-
if (hookResult && typeof hookResult ===
|
|
1058
|
+
if (hookResult && typeof hookResult === 'object' && 'url' in hookResult) {
|
|
1052
1059
|
url = hookResult.url;
|
|
1053
1060
|
}
|
|
1054
1061
|
}
|
|
@@ -1056,7 +1063,7 @@ function createScriptNode(url, cb, attrs, createScriptHook) {
|
|
|
1056
1063
|
try {
|
|
1057
1064
|
urlObj = new URL(url);
|
|
1058
1065
|
} catch (e) {
|
|
1059
|
-
console.error(
|
|
1066
|
+
console.error('Error constructing URL:', e);
|
|
1060
1067
|
cb(new Error("Invalid URL: ".concat(e)));
|
|
1061
1068
|
return;
|
|
1062
1069
|
}
|
|
@@ -1066,13 +1073,13 @@ function createScriptNode(url, cb, attrs, createScriptHook) {
|
|
|
1066
1073
|
return _ts_generator(this, function(_state) {
|
|
1067
1074
|
switch(_state.label){
|
|
1068
1075
|
case 0:
|
|
1069
|
-
if (!(typeof fetch ===
|
|
1076
|
+
if (!(typeof fetch === 'undefined')) return [
|
|
1070
1077
|
3,
|
|
1071
1078
|
2
|
|
1072
1079
|
];
|
|
1073
1080
|
return [
|
|
1074
1081
|
4,
|
|
1075
|
-
importNodeModule(
|
|
1082
|
+
importNodeModule('node-fetch')
|
|
1076
1083
|
];
|
|
1077
1084
|
case 1:
|
|
1078
1085
|
fetchModule = _state.sent();
|
|
@@ -1097,7 +1104,7 @@ function createScriptNode(url, cb, attrs, createScriptHook) {
|
|
|
1097
1104
|
return _ref.apply(this, arguments);
|
|
1098
1105
|
};
|
|
1099
1106
|
}();
|
|
1100
|
-
console.log(
|
|
1107
|
+
console.log('fetching', urlObj.href);
|
|
1101
1108
|
getFetch().then(function(f) {
|
|
1102
1109
|
f(urlObj.href).then(function(res) {
|
|
1103
1110
|
return res.text();
|
|
@@ -1110,8 +1117,8 @@ function createScriptNode(url, cb, attrs, createScriptHook) {
|
|
|
1110
1117
|
return [
|
|
1111
1118
|
4,
|
|
1112
1119
|
Promise.all([
|
|
1113
|
-
importNodeModule(
|
|
1114
|
-
importNodeModule(
|
|
1120
|
+
importNodeModule('path'),
|
|
1121
|
+
importNodeModule('vm')
|
|
1115
1122
|
])
|
|
1116
1123
|
];
|
|
1117
1124
|
case 1:
|
|
@@ -1125,14 +1132,14 @@ function createScriptNode(url, cb, attrs, createScriptHook) {
|
|
|
1125
1132
|
exports: {}
|
|
1126
1133
|
}
|
|
1127
1134
|
};
|
|
1128
|
-
urlDirname = urlObj.pathname.split(
|
|
1135
|
+
urlDirname = urlObj.pathname.split('/').slice(0, -1).join('/');
|
|
1129
1136
|
filename = path.basename(urlObj.pathname);
|
|
1130
1137
|
try {
|
|
1131
1138
|
script = new vm.Script("(function(exports, module, require, __dirname, __filename) {".concat(data, "\n})"), filename);
|
|
1132
|
-
script.runInThisContext()(scriptContext.exports, scriptContext.module, eval(
|
|
1139
|
+
script.runInThisContext()(scriptContext.exports, scriptContext.module, eval('require'), urlDirname, filename);
|
|
1133
1140
|
exportedInterface = scriptContext.module.exports || scriptContext.exports;
|
|
1134
|
-
if (attrs && exportedInterface && attrs[
|
|
1135
|
-
container = exportedInterface[attrs[
|
|
1141
|
+
if (attrs && exportedInterface && attrs['globalName']) {
|
|
1142
|
+
container = exportedInterface[attrs['globalName']] || exportedInterface;
|
|
1136
1143
|
cb(undefined, container);
|
|
1137
1144
|
return [
|
|
1138
1145
|
2
|
|
@@ -1165,7 +1172,7 @@ function loadScriptNode(url, info) {
|
|
|
1165
1172
|
reject(error);
|
|
1166
1173
|
} else {
|
|
1167
1174
|
var _info_attrs, _info_attrs1;
|
|
1168
|
-
var remoteEntryKey = (info === null || info === void 0 ? void 0 : (_info_attrs = info.attrs) === null || _info_attrs === void 0 ? void 0 : _info_attrs[
|
|
1175
|
+
var remoteEntryKey = (info === null || info === void 0 ? void 0 : (_info_attrs = info.attrs) === null || _info_attrs === void 0 ? void 0 : _info_attrs['globalName']) || "__FEDERATION_".concat(info === null || info === void 0 ? void 0 : (_info_attrs1 = info.attrs) === null || _info_attrs1 === void 0 ? void 0 : _info_attrs1['name'], ":custom__");
|
|
1169
1176
|
var entryExports = globalThis[remoteEntryKey] = scriptContext;
|
|
1170
1177
|
resolve(entryExports);
|
|
1171
1178
|
}
|
|
@@ -1210,7 +1217,7 @@ function normalizeOptions(enableDefault, defaultOptions, key) {
|
|
|
1210
1217
|
if (options === false) {
|
|
1211
1218
|
return false;
|
|
1212
1219
|
}
|
|
1213
|
-
if (typeof options ===
|
|
1220
|
+
if (typeof options === 'undefined') {
|
|
1214
1221
|
if (enableDefault) {
|
|
1215
1222
|
return defaultOptions;
|
|
1216
1223
|
} else {
|
|
@@ -1220,11 +1227,11 @@ function normalizeOptions(enableDefault, defaultOptions, key) {
|
|
|
1220
1227
|
if (options === true) {
|
|
1221
1228
|
return defaultOptions;
|
|
1222
1229
|
}
|
|
1223
|
-
if (options && typeof options ===
|
|
1230
|
+
if (options && typeof options === 'object') {
|
|
1224
1231
|
return _object_spread({}, defaultOptions, options);
|
|
1225
1232
|
}
|
|
1226
1233
|
throw new Error("Unexpected type for `".concat(key, "`, expect boolean/undefined/object, got: ").concat(typeof options === "undefined" ? "undefined" : _type_of(options)));
|
|
1227
1234
|
};
|
|
1228
1235
|
}
|
|
1229
1236
|
|
|
1230
|
-
export { BROWSER_LOG_KEY, BROWSER_LOG_VALUE, EncodedNameTransformMap, FederationModuleManifest, Logger, MANIFEST_EXT, MFModuleType, MODULE_DEVTOOL_IDENTIFIER, ManifestFileName, NameTransformMap, NameTransformSymbol, SEPARATOR, StatsFileName, assert, composeKeyWithSeparator, ContainerPlugin as containerPlugin, ContainerReferencePlugin as containerReferencePlugin, createLink, createScript, createScriptNode, decodeName, encodeName, error, generateExposeFilename, generateShareFilename, generateSnapshotFromManifest, getProcessEnv, getResourceUrl, isBrowserEnv, isDebugMode, isManifestProvider, isStaticResourcesEqual, loadScript, loadScriptNode, logger, ModuleFederationPlugin as moduleFederationPlugin, normalizeOptions, parseEntry, safeWrapper, SharePlugin as sharePlugin, simpleJoinRemoteEntry, warn };
|
|
1237
|
+
export { BROWSER_LOG_KEY, BROWSER_LOG_VALUE, EncodedNameTransformMap, FederationModuleManifest, Logger, MANIFEST_EXT, MFModuleType, MODULE_DEVTOOL_IDENTIFIER, ManifestFileName, NameTransformMap, NameTransformSymbol, SEPARATOR, StatsFileName, assert, composeKeyWithSeparator, ContainerPlugin as containerPlugin, ContainerReferencePlugin as containerReferencePlugin, createLink, createScript, createScriptNode, decodeName, encodeName, error, generateExposeFilename, generateShareFilename, generateSnapshotFromManifest, getProcessEnv, getResourceUrl, inferAutoPublicPath, isBrowserEnv, isDebugMode, isManifestProvider, isStaticResourcesEqual, loadScript, loadScriptNode, logger, ModuleFederationPlugin as moduleFederationPlugin, normalizeOptions, parseEntry, safeWrapper, SharePlugin as sharePlugin, simpleJoinRemoteEntry, warn };
|
|
@@ -10,27 +10,27 @@ var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
|
10
10
|
|
|
11
11
|
function getWebpackPath(compiler) {
|
|
12
12
|
var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {
|
|
13
|
-
framework:
|
|
13
|
+
framework: 'other'
|
|
14
14
|
};
|
|
15
15
|
try {
|
|
16
16
|
// @ts-ignore just throw err
|
|
17
17
|
compiler.webpack();
|
|
18
|
-
return
|
|
18
|
+
return '';
|
|
19
19
|
} catch (err) {
|
|
20
20
|
var _err_stack;
|
|
21
|
-
var trace = ((_err_stack = err.stack) === null || _err_stack === void 0 ? void 0 : _err_stack.split(
|
|
21
|
+
var trace = ((_err_stack = err.stack) === null || _err_stack === void 0 ? void 0 : _err_stack.split('\n')) || [];
|
|
22
22
|
var webpackErrLocation = trace.find(function(item) {
|
|
23
|
-
return item.includes(
|
|
24
|
-
}) ||
|
|
25
|
-
var webpackLocationWithDetail = webpackErrLocation.replace(/[^\(\)]+/,
|
|
26
|
-
var webpackPath = webpackLocationWithDetail.split(
|
|
27
|
-
if ((options === null || options === void 0 ? void 0 : options.framework) ===
|
|
28
|
-
if (webpackPath.endsWith(
|
|
29
|
-
return webpackPath.replace(
|
|
23
|
+
return item.includes('at webpack');
|
|
24
|
+
}) || '';
|
|
25
|
+
var webpackLocationWithDetail = webpackErrLocation.replace(/[^\(\)]+/, '').slice(1, -1);
|
|
26
|
+
var webpackPath = webpackLocationWithDetail.split(':').slice(0, -2).join(':');
|
|
27
|
+
if ((options === null || options === void 0 ? void 0 : options.framework) === 'nextjs') {
|
|
28
|
+
if (webpackPath.endsWith('webpack.js')) {
|
|
29
|
+
return webpackPath.replace('webpack.js', 'index.js');
|
|
30
30
|
}
|
|
31
|
-
return
|
|
31
|
+
return '';
|
|
32
32
|
}
|
|
33
|
-
return require.resolve(
|
|
33
|
+
return require.resolve('webpack', {
|
|
34
34
|
paths: [
|
|
35
35
|
webpackPath
|
|
36
36
|
]
|
|
@@ -38,11 +38,11 @@ function getWebpackPath(compiler) {
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
var normalizeWebpackPath = function(fullPath) {
|
|
41
|
-
if (fullPath ===
|
|
42
|
-
return process.env[
|
|
41
|
+
if (fullPath === 'webpack') {
|
|
42
|
+
return process.env['FEDERATION_WEBPACK_PATH'] || fullPath;
|
|
43
43
|
}
|
|
44
|
-
if (process.env[
|
|
45
|
-
return path__default["default"].resolve(process.env[
|
|
44
|
+
if (process.env['FEDERATION_WEBPACK_PATH']) {
|
|
45
|
+
return path__default["default"].resolve(process.env['FEDERATION_WEBPACK_PATH'], fullPath.replace('webpack', '../../'));
|
|
46
46
|
}
|
|
47
47
|
return fullPath;
|
|
48
48
|
};
|
|
@@ -2,27 +2,27 @@ import path from 'path';
|
|
|
2
2
|
|
|
3
3
|
function getWebpackPath(compiler) {
|
|
4
4
|
var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {
|
|
5
|
-
framework:
|
|
5
|
+
framework: 'other'
|
|
6
6
|
};
|
|
7
7
|
try {
|
|
8
8
|
// @ts-ignore just throw err
|
|
9
9
|
compiler.webpack();
|
|
10
|
-
return
|
|
10
|
+
return '';
|
|
11
11
|
} catch (err) {
|
|
12
12
|
var _err_stack;
|
|
13
|
-
var trace = ((_err_stack = err.stack) === null || _err_stack === void 0 ? void 0 : _err_stack.split(
|
|
13
|
+
var trace = ((_err_stack = err.stack) === null || _err_stack === void 0 ? void 0 : _err_stack.split('\n')) || [];
|
|
14
14
|
var webpackErrLocation = trace.find(function(item) {
|
|
15
|
-
return item.includes(
|
|
16
|
-
}) ||
|
|
17
|
-
var webpackLocationWithDetail = webpackErrLocation.replace(/[^\(\)]+/,
|
|
18
|
-
var webpackPath = webpackLocationWithDetail.split(
|
|
19
|
-
if ((options === null || options === void 0 ? void 0 : options.framework) ===
|
|
20
|
-
if (webpackPath.endsWith(
|
|
21
|
-
return webpackPath.replace(
|
|
15
|
+
return item.includes('at webpack');
|
|
16
|
+
}) || '';
|
|
17
|
+
var webpackLocationWithDetail = webpackErrLocation.replace(/[^\(\)]+/, '').slice(1, -1);
|
|
18
|
+
var webpackPath = webpackLocationWithDetail.split(':').slice(0, -2).join(':');
|
|
19
|
+
if ((options === null || options === void 0 ? void 0 : options.framework) === 'nextjs') {
|
|
20
|
+
if (webpackPath.endsWith('webpack.js')) {
|
|
21
|
+
return webpackPath.replace('webpack.js', 'index.js');
|
|
22
22
|
}
|
|
23
|
-
return
|
|
23
|
+
return '';
|
|
24
24
|
}
|
|
25
|
-
return require.resolve(
|
|
25
|
+
return require.resolve('webpack', {
|
|
26
26
|
paths: [
|
|
27
27
|
webpackPath
|
|
28
28
|
]
|
|
@@ -30,11 +30,11 @@ function getWebpackPath(compiler) {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
var normalizeWebpackPath = function(fullPath) {
|
|
33
|
-
if (fullPath ===
|
|
34
|
-
return process.env[
|
|
33
|
+
if (fullPath === 'webpack') {
|
|
34
|
+
return process.env['FEDERATION_WEBPACK_PATH'] || fullPath;
|
|
35
35
|
}
|
|
36
|
-
if (process.env[
|
|
37
|
-
return path.resolve(process.env[
|
|
36
|
+
if (process.env['FEDERATION_WEBPACK_PATH']) {
|
|
37
|
+
return path.resolve(process.env['FEDERATION_WEBPACK_PATH'], fullPath.replace('webpack', '../../'));
|
|
38
38
|
}
|
|
39
39
|
return fullPath;
|
|
40
40
|
};
|
package/dist/package.json
CHANGED
|
@@ -5,6 +5,7 @@ interface IOptions {
|
|
|
5
5
|
version?: string;
|
|
6
6
|
}
|
|
7
7
|
export declare const simpleJoinRemoteEntry: (rPath: string, rName: string) => string;
|
|
8
|
+
export declare function inferAutoPublicPath(url: string): string;
|
|
8
9
|
export declare function generateSnapshotFromManifest(manifest: Manifest, options?: IOptions): ProviderModuleInfo;
|
|
9
10
|
export declare function isManifestProvider(moduleInfo: ModuleInfo | ManifestProvider): moduleInfo is ManifestProvider;
|
|
10
11
|
export {};
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export * from './constant';
|
|
2
2
|
export * from './types';
|
|
3
3
|
export * from './utils';
|
|
4
|
-
export { generateSnapshotFromManifest, isManifestProvider, simpleJoinRemoteEntry, } from './generateSnapshotFromManifest';
|
|
4
|
+
export { generateSnapshotFromManifest, isManifestProvider, simpleJoinRemoteEntry, inferAutoPublicPath, } from './generateSnapshotFromManifest';
|
|
5
5
|
export * from './logger';
|
|
6
6
|
export * from './env';
|
|
7
7
|
export * from './dom';
|