@module-federation/sdk 0.0.12 → 0.0.14
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 +70 -2
- package/dist/index.esm.js +70 -3
- package/dist/package.json +1 -1
- package/dist/src/dom.d.ts +4 -0
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -108,13 +108,23 @@ function safeToString(info) {
|
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
var DEBUG_LOG = "[ FEDERATION DEBUG ]";
|
|
111
|
+
function safeGetLocalStorageItem() {
|
|
112
|
+
try {
|
|
113
|
+
if (typeof window !== "undefined" && window.localStorage) {
|
|
114
|
+
return localStorage.getItem(BROWSER_LOG_KEY) === BROWSER_LOG_VALUE;
|
|
115
|
+
}
|
|
116
|
+
} catch (error) {
|
|
117
|
+
return typeof document !== "undefined";
|
|
118
|
+
}
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
111
121
|
var Logger = /*#__PURE__*/ function() {
|
|
112
122
|
function Logger(identifier) {
|
|
113
123
|
_class_call_check(this, Logger);
|
|
114
124
|
_define_property$1(this, "enable", false);
|
|
115
125
|
_define_property$1(this, "identifier", void 0);
|
|
116
126
|
this.identifier = identifier || DEBUG_LOG;
|
|
117
|
-
if (isBrowserEnv() &&
|
|
127
|
+
if (isBrowserEnv() && safeGetLocalStorageItem()) {
|
|
118
128
|
this.enable = true;
|
|
119
129
|
} else if (isDebugMode()) {
|
|
120
130
|
this.enable = true;
|
|
@@ -757,6 +767,63 @@ function createScript(url, cb, attrs, createScriptHook) {
|
|
|
757
767
|
needAttach: needAttach
|
|
758
768
|
};
|
|
759
769
|
}
|
|
770
|
+
function createLink(url, cb, attrs, createLinkHook) {
|
|
771
|
+
// <link rel="preload" href="script.js" as="script">
|
|
772
|
+
// Retrieve the existing script element by its src attribute
|
|
773
|
+
var link = null;
|
|
774
|
+
var needAttach = true;
|
|
775
|
+
var links = document.getElementsByTagName("link");
|
|
776
|
+
for(var i = 0; i < links.length; i++){
|
|
777
|
+
var l = links[i];
|
|
778
|
+
var linkHref = l.getAttribute("href");
|
|
779
|
+
if (linkHref && isStaticResourcesEqual(linkHref, url)) {
|
|
780
|
+
link = l;
|
|
781
|
+
needAttach = false;
|
|
782
|
+
break;
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
if (!link) {
|
|
786
|
+
link = document.createElement("link");
|
|
787
|
+
link.setAttribute("href", url);
|
|
788
|
+
if (createLinkHook) {
|
|
789
|
+
var createLinkRes = createLinkHook(url);
|
|
790
|
+
if (_instanceof(createLinkRes, HTMLLinkElement)) {
|
|
791
|
+
link = createLinkRes;
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
if (attrs) {
|
|
796
|
+
Object.keys(attrs).forEach(function(name) {
|
|
797
|
+
if (link) {
|
|
798
|
+
link.setAttribute(name, attrs[name]);
|
|
799
|
+
}
|
|
800
|
+
});
|
|
801
|
+
}
|
|
802
|
+
var onLinkComplete = function(prev, // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
803
|
+
event) {
|
|
804
|
+
// Prevent memory leaks in IE.
|
|
805
|
+
if (link) {
|
|
806
|
+
link.onerror = null;
|
|
807
|
+
link.onload = null;
|
|
808
|
+
safeWrapper(function() {
|
|
809
|
+
(link === null || link === void 0 ? void 0 : link.parentNode) && link.parentNode.removeChild(link);
|
|
810
|
+
});
|
|
811
|
+
if (prev) {
|
|
812
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
813
|
+
var res = prev(event);
|
|
814
|
+
cb();
|
|
815
|
+
return res;
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
cb();
|
|
819
|
+
};
|
|
820
|
+
link.onerror = onLinkComplete.bind(null, link.onerror);
|
|
821
|
+
link.onload = onLinkComplete.bind(null, link.onload);
|
|
822
|
+
return {
|
|
823
|
+
link: link,
|
|
824
|
+
needAttach: needAttach
|
|
825
|
+
};
|
|
826
|
+
}
|
|
760
827
|
function loadScript(url, info) {
|
|
761
828
|
var attrs = info.attrs, createScriptHook = info.createScriptHook;
|
|
762
829
|
return new Promise(function(resolve, _reject) {
|
|
@@ -1036,7 +1103,7 @@ function createScriptNode(url, cb, attrs, createScriptHook) {
|
|
|
1036
1103
|
script.runInThisContext()(scriptContext.exports, scriptContext.module, eval("require"), urlDirname, filename);
|
|
1037
1104
|
exportedInterface = scriptContext.module.exports || scriptContext.exports;
|
|
1038
1105
|
if (attrs && exportedInterface && attrs["globalName"]) {
|
|
1039
|
-
container = exportedInterface[attrs["globalName"]];
|
|
1106
|
+
container = exportedInterface[attrs["globalName"]] || exportedInterface;
|
|
1040
1107
|
cb(undefined, container);
|
|
1041
1108
|
return [
|
|
1042
1109
|
2
|
|
@@ -1088,6 +1155,7 @@ exports.NameTransformSymbol = NameTransformSymbol;
|
|
|
1088
1155
|
exports.SEPARATOR = SEPARATOR;
|
|
1089
1156
|
exports.assert = assert;
|
|
1090
1157
|
exports.composeKeyWithSeparator = composeKeyWithSeparator;
|
|
1158
|
+
exports.createLink = createLink;
|
|
1091
1159
|
exports.createScript = createScript;
|
|
1092
1160
|
exports.createScriptNode = createScriptNode;
|
|
1093
1161
|
exports.decodeName = decodeName;
|
package/dist/index.esm.js
CHANGED
|
@@ -104,13 +104,23 @@ function safeToString(info) {
|
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
var DEBUG_LOG = "[ FEDERATION DEBUG ]";
|
|
107
|
+
function safeGetLocalStorageItem() {
|
|
108
|
+
try {
|
|
109
|
+
if (typeof window !== "undefined" && window.localStorage) {
|
|
110
|
+
return localStorage.getItem(BROWSER_LOG_KEY) === BROWSER_LOG_VALUE;
|
|
111
|
+
}
|
|
112
|
+
} catch (error) {
|
|
113
|
+
return typeof document !== "undefined";
|
|
114
|
+
}
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
107
117
|
var Logger = /*#__PURE__*/ function() {
|
|
108
118
|
function Logger(identifier) {
|
|
109
119
|
_class_call_check(this, Logger);
|
|
110
120
|
_define_property$1(this, "enable", false);
|
|
111
121
|
_define_property$1(this, "identifier", void 0);
|
|
112
122
|
this.identifier = identifier || DEBUG_LOG;
|
|
113
|
-
if (isBrowserEnv() &&
|
|
123
|
+
if (isBrowserEnv() && safeGetLocalStorageItem()) {
|
|
114
124
|
this.enable = true;
|
|
115
125
|
} else if (isDebugMode()) {
|
|
116
126
|
this.enable = true;
|
|
@@ -753,6 +763,63 @@ function createScript(url, cb, attrs, createScriptHook) {
|
|
|
753
763
|
needAttach: needAttach
|
|
754
764
|
};
|
|
755
765
|
}
|
|
766
|
+
function createLink(url, cb, attrs, createLinkHook) {
|
|
767
|
+
// <link rel="preload" href="script.js" as="script">
|
|
768
|
+
// Retrieve the existing script element by its src attribute
|
|
769
|
+
var link = null;
|
|
770
|
+
var needAttach = true;
|
|
771
|
+
var links = document.getElementsByTagName("link");
|
|
772
|
+
for(var i = 0; i < links.length; i++){
|
|
773
|
+
var l = links[i];
|
|
774
|
+
var linkHref = l.getAttribute("href");
|
|
775
|
+
if (linkHref && isStaticResourcesEqual(linkHref, url)) {
|
|
776
|
+
link = l;
|
|
777
|
+
needAttach = false;
|
|
778
|
+
break;
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
if (!link) {
|
|
782
|
+
link = document.createElement("link");
|
|
783
|
+
link.setAttribute("href", url);
|
|
784
|
+
if (createLinkHook) {
|
|
785
|
+
var createLinkRes = createLinkHook(url);
|
|
786
|
+
if (_instanceof(createLinkRes, HTMLLinkElement)) {
|
|
787
|
+
link = createLinkRes;
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
if (attrs) {
|
|
792
|
+
Object.keys(attrs).forEach(function(name) {
|
|
793
|
+
if (link) {
|
|
794
|
+
link.setAttribute(name, attrs[name]);
|
|
795
|
+
}
|
|
796
|
+
});
|
|
797
|
+
}
|
|
798
|
+
var onLinkComplete = function(prev, // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
799
|
+
event) {
|
|
800
|
+
// Prevent memory leaks in IE.
|
|
801
|
+
if (link) {
|
|
802
|
+
link.onerror = null;
|
|
803
|
+
link.onload = null;
|
|
804
|
+
safeWrapper(function() {
|
|
805
|
+
(link === null || link === void 0 ? void 0 : link.parentNode) && link.parentNode.removeChild(link);
|
|
806
|
+
});
|
|
807
|
+
if (prev) {
|
|
808
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
809
|
+
var res = prev(event);
|
|
810
|
+
cb();
|
|
811
|
+
return res;
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
cb();
|
|
815
|
+
};
|
|
816
|
+
link.onerror = onLinkComplete.bind(null, link.onerror);
|
|
817
|
+
link.onload = onLinkComplete.bind(null, link.onload);
|
|
818
|
+
return {
|
|
819
|
+
link: link,
|
|
820
|
+
needAttach: needAttach
|
|
821
|
+
};
|
|
822
|
+
}
|
|
756
823
|
function loadScript(url, info) {
|
|
757
824
|
var attrs = info.attrs, createScriptHook = info.createScriptHook;
|
|
758
825
|
return new Promise(function(resolve, _reject) {
|
|
@@ -1032,7 +1099,7 @@ function createScriptNode(url, cb, attrs, createScriptHook) {
|
|
|
1032
1099
|
script.runInThisContext()(scriptContext.exports, scriptContext.module, eval("require"), urlDirname, filename);
|
|
1033
1100
|
exportedInterface = scriptContext.module.exports || scriptContext.exports;
|
|
1034
1101
|
if (attrs && exportedInterface && attrs["globalName"]) {
|
|
1035
|
-
container = exportedInterface[attrs["globalName"]];
|
|
1102
|
+
container = exportedInterface[attrs["globalName"]] || exportedInterface;
|
|
1036
1103
|
cb(undefined, container);
|
|
1037
1104
|
return [
|
|
1038
1105
|
2
|
|
@@ -1073,4 +1140,4 @@ function loadScriptNode(url, info) {
|
|
|
1073
1140
|
});
|
|
1074
1141
|
}
|
|
1075
1142
|
|
|
1076
|
-
export { BROWSER_LOG_KEY, BROWSER_LOG_VALUE, EncodedNameTransformMap, FederationModuleManifest, Logger, MANIFEST_EXT, NameTransformMap, NameTransformSymbol, SEPARATOR, assert, composeKeyWithSeparator, createScript, createScriptNode, decodeName, encodeName, error, generateExposeFilename, generateShareFilename, generateSnapshotFromManifest, getProcessEnv, getResourceUrl, isBrowserEnv, isDebugMode, isManifestProvider, isStaticResourcesEqual, loadScript, loadScriptNode, logger, parseEntry, safeWrapper, simpleJoinRemoteEntry, warn };
|
|
1143
|
+
export { BROWSER_LOG_KEY, BROWSER_LOG_VALUE, EncodedNameTransformMap, FederationModuleManifest, Logger, MANIFEST_EXT, NameTransformMap, NameTransformSymbol, SEPARATOR, assert, composeKeyWithSeparator, createLink, createScript, createScriptNode, decodeName, encodeName, error, generateExposeFilename, generateShareFilename, generateSnapshotFromManifest, getProcessEnv, getResourceUrl, isBrowserEnv, isDebugMode, isManifestProvider, isStaticResourcesEqual, loadScript, loadScriptNode, logger, parseEntry, safeWrapper, simpleJoinRemoteEntry, warn };
|
package/dist/package.json
CHANGED
package/dist/src/dom.d.ts
CHANGED
|
@@ -4,6 +4,10 @@ export declare function createScript(url: string, cb: (value: void | PromiseLike
|
|
|
4
4
|
script: HTMLScriptElement;
|
|
5
5
|
needAttach: boolean;
|
|
6
6
|
};
|
|
7
|
+
export declare function createLink(url: string, cb: (value: void | PromiseLike<void>) => void, attrs?: Record<string, any>, createLinkHook?: (url: string) => HTMLLinkElement | void): {
|
|
8
|
+
link: HTMLLinkElement;
|
|
9
|
+
needAttach: boolean;
|
|
10
|
+
};
|
|
7
11
|
export declare function loadScript(url: string, info: {
|
|
8
12
|
attrs?: Record<string, any>;
|
|
9
13
|
createScriptHook?: (url: string) => HTMLScriptElement | void;
|