@module-federation/utilities 3.1.82 → 3.1.84
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/cjs/Logger.js +60 -0
- package/dist/cjs/components/ErrorBoundary.js +96 -0
- package/dist/cjs/components/FederationBoundary.js +101 -0
- package/dist/cjs/index.js +170 -0
- package/dist/cjs/plugins/DelegateModulesPlugin.js +130 -0
- package/dist/cjs/types/index.js +33 -0
- package/dist/cjs/utils/common.js +173 -0
- package/dist/cjs/utils/getRuntimeRemotes.js +102 -0
- package/dist/cjs/utils/getRuntimeRemotes.test.js +98 -0
- package/dist/cjs/utils/importDelegateModule.test.js +101 -0
- package/dist/cjs/utils/importDelegatedModule.js +124 -0
- package/dist/cjs/utils/importRemote.js +174 -0
- package/dist/cjs/utils/isEmpty.js +56 -0
- package/dist/cjs/utils/pure.js +212 -0
- package/dist/cjs/utils/react.js +71 -0
- package/dist/esm/Logger.mjs +14 -0
- package/dist/esm/components/ErrorBoundary.mjs +33 -0
- package/dist/esm/components/FederationBoundary.mjs +38 -0
- package/dist/esm/index.mjs +34 -0
- package/dist/esm/plugins/DelegateModulesPlugin.mjs +84 -0
- package/dist/esm/types/index.mjs +6 -0
- package/dist/esm/utils/common.mjs +126 -0
- package/dist/esm/utils/getRuntimeRemotes.mjs +52 -0
- package/dist/esm/utils/getRuntimeRemotes.test.mjs +87 -0
- package/dist/esm/utils/importDelegateModule.test.mjs +90 -0
- package/dist/esm/utils/importDelegatedModule.mjs +74 -0
- package/dist/esm/utils/importRemote.mjs +137 -0
- package/dist/esm/utils/isEmpty.mjs +10 -0
- package/dist/esm/utils/pure.mjs +164 -0
- package/dist/esm/utils/react.mjs +8 -0
- package/package.json +2 -2
- package/dist/index.cjs.js +0 -555
- package/dist/index.d.ts +0 -1
- package/dist/index.esm.js +0 -543
- /package/dist/{src → types}/Logger.d.ts +0 -0
- /package/dist/{src → types}/components/ErrorBoundary.d.ts +0 -0
- /package/dist/{src → types}/components/FederationBoundary.d.ts +0 -0
- /package/dist/{src → types}/index.d.ts +0 -0
- /package/dist/{src → types}/plugins/DelegateModulesPlugin.d.ts +0 -0
- /package/dist/{src → types}/types/index.d.ts +0 -0
- /package/dist/{src → types}/utils/common.d.ts +0 -0
- /package/dist/{src → types}/utils/getRuntimeRemotes.d.ts +0 -0
- /package/dist/{src → types}/utils/importDelegatedModule.d.ts +0 -0
- /package/dist/{src → types}/utils/importRemote.d.ts +0 -0
- /package/dist/{src → types}/utils/isEmpty.d.ts +0 -0
- /package/dist/{src → types}/utils/pure.d.ts +0 -0
- /package/dist/{src → types}/utils/react.d.ts +0 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
var __webpack_modules__ = ({});
|
|
2
|
+
/************************************************************************/
|
|
3
|
+
// The module cache
|
|
4
|
+
var __webpack_module_cache__ = {};
|
|
5
|
+
|
|
6
|
+
// The require function
|
|
7
|
+
function __webpack_require__(moduleId) {
|
|
8
|
+
|
|
9
|
+
// Check if module is in cache
|
|
10
|
+
var cachedModule = __webpack_module_cache__[moduleId];
|
|
11
|
+
if (cachedModule !== undefined) {
|
|
12
|
+
return cachedModule.exports;
|
|
13
|
+
}
|
|
14
|
+
// Create a new module (and put it into the cache)
|
|
15
|
+
var module = (__webpack_module_cache__[moduleId] = {
|
|
16
|
+
exports: {}
|
|
17
|
+
});
|
|
18
|
+
// Execute the module function
|
|
19
|
+
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
20
|
+
|
|
21
|
+
// Return the exports of the module
|
|
22
|
+
return module.exports;
|
|
23
|
+
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/************************************************************************/
|
|
27
|
+
|
|
28
|
+
;// CONCATENATED MODULE: ./src/utils/pure.ts
|
|
29
|
+
const pure = typeof process !== 'undefined' ? process.env['REMOTES'] || {} : {};
|
|
30
|
+
const remoteVars = pure;
|
|
31
|
+
const extractUrlAndGlobal = (urlAndGlobal)=>{
|
|
32
|
+
const index = urlAndGlobal.indexOf('@');
|
|
33
|
+
if (index <= 0 || index === urlAndGlobal.length - 1) {
|
|
34
|
+
throw new Error(`Invalid request "${urlAndGlobal}"`);
|
|
35
|
+
}
|
|
36
|
+
return [
|
|
37
|
+
urlAndGlobal.substring(index + 1),
|
|
38
|
+
urlAndGlobal.substring(0, index)
|
|
39
|
+
];
|
|
40
|
+
};
|
|
41
|
+
const loadScript = (keyOrRuntimeRemoteItem)=>{
|
|
42
|
+
const runtimeRemotes = getRuntimeRemotes();
|
|
43
|
+
// 1) Load remote container if needed
|
|
44
|
+
let asyncContainer;
|
|
45
|
+
const reference = typeof keyOrRuntimeRemoteItem === 'string' ? runtimeRemotes[keyOrRuntimeRemoteItem] : keyOrRuntimeRemoteItem;
|
|
46
|
+
if (reference.asyncContainer) {
|
|
47
|
+
asyncContainer = typeof reference.asyncContainer.then === 'function' ? reference.asyncContainer : reference.asyncContainer();
|
|
48
|
+
} else {
|
|
49
|
+
// This casting is just to satisfy typescript,
|
|
50
|
+
// In reality remoteGlobal will always be a string;
|
|
51
|
+
const remoteGlobal = reference.global;
|
|
52
|
+
// Check if theres an override for container key if not use remote global
|
|
53
|
+
const containerKey = reference.uniqueKey ? reference.uniqueKey : remoteGlobal;
|
|
54
|
+
const __webpack_error__ = new Error();
|
|
55
|
+
// @ts-ignore
|
|
56
|
+
const globalScope = // @ts-ignore
|
|
57
|
+
typeof window !== 'undefined' ? window : globalThis.__remote_scope__;
|
|
58
|
+
if (typeof window === 'undefined') {
|
|
59
|
+
//@ts-ignore
|
|
60
|
+
globalScope['_config'][containerKey] = reference.url;
|
|
61
|
+
} else {
|
|
62
|
+
// to match promise template system, can be removed once promise template is gone
|
|
63
|
+
//@ts-ignore
|
|
64
|
+
if (!globalScope['remoteLoading']) {
|
|
65
|
+
//@ts-ignore
|
|
66
|
+
globalScope['remoteLoading'] = {};
|
|
67
|
+
}
|
|
68
|
+
//@ts-ignore
|
|
69
|
+
if (globalScope['remoteLoading'][containerKey]) {
|
|
70
|
+
//@ts-ignore
|
|
71
|
+
return globalScope['remoteLoading'][containerKey];
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
// @ts-ignore
|
|
75
|
+
asyncContainer = new Promise(function(resolve, reject) {
|
|
76
|
+
function resolveRemoteGlobal() {
|
|
77
|
+
//@ts-ignore
|
|
78
|
+
const asyncContainer = globalScope[remoteGlobal];
|
|
79
|
+
return resolve(asyncContainer);
|
|
80
|
+
}
|
|
81
|
+
//@ts-ignore
|
|
82
|
+
if (typeof globalScope[remoteGlobal] !== 'undefined') {
|
|
83
|
+
return resolveRemoteGlobal();
|
|
84
|
+
}
|
|
85
|
+
__webpack_require__.l(reference.url, function(event) {
|
|
86
|
+
//@ts-ignore
|
|
87
|
+
if (typeof globalScope[remoteGlobal] !== 'undefined') {
|
|
88
|
+
return resolveRemoteGlobal();
|
|
89
|
+
}
|
|
90
|
+
const errorType = event && (event.type === 'load' ? 'missing' : event.type);
|
|
91
|
+
const realSrc = event && event.target && event.target.src;
|
|
92
|
+
__webpack_error__.message = 'Loading script failed.\n(' + errorType + ': ' + realSrc + ' or global var ' + remoteGlobal + ')';
|
|
93
|
+
__webpack_error__.name = 'ScriptExternalLoadError';
|
|
94
|
+
__webpack_error__.type = errorType;
|
|
95
|
+
__webpack_error__.request = realSrc;
|
|
96
|
+
reject(__webpack_error__);
|
|
97
|
+
}, containerKey);
|
|
98
|
+
}).catch(function(err) {
|
|
99
|
+
console.error('container is offline, returning fake remote');
|
|
100
|
+
console.error(err);
|
|
101
|
+
return {
|
|
102
|
+
fake: true,
|
|
103
|
+
// @ts-ignore
|
|
104
|
+
get: (arg)=>{
|
|
105
|
+
console.warn('faking', arg, 'module on, its offline');
|
|
106
|
+
return Promise.resolve(()=>{
|
|
107
|
+
return {
|
|
108
|
+
__esModule: true,
|
|
109
|
+
default: ()=>{
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
});
|
|
114
|
+
},
|
|
115
|
+
//eslint-disable-next-line
|
|
116
|
+
init: ()=>{}
|
|
117
|
+
};
|
|
118
|
+
});
|
|
119
|
+
if (typeof window !== 'undefined') {
|
|
120
|
+
//@ts-ignore
|
|
121
|
+
globalScope['remoteLoading'][containerKey] = asyncContainer;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return asyncContainer;
|
|
125
|
+
};
|
|
126
|
+
const getRuntimeRemotes = ()=>{
|
|
127
|
+
return Object.entries(remoteVars).reduce((acc, [key, value])=>{
|
|
128
|
+
if (typeof value === 'object' && typeof value.then === 'function') {
|
|
129
|
+
acc[key] = {
|
|
130
|
+
asyncContainer: value
|
|
131
|
+
};
|
|
132
|
+
} else if (typeof value === 'function') {
|
|
133
|
+
acc[key] = {
|
|
134
|
+
asyncContainer: Promise.resolve(value())
|
|
135
|
+
};
|
|
136
|
+
} else if (typeof value === 'string') {
|
|
137
|
+
if (value.startsWith('internal ')) {
|
|
138
|
+
const [request, query] = value.replace('internal ', '').split('?');
|
|
139
|
+
if (query) {
|
|
140
|
+
const remoteSyntax = new URLSearchParams(query).get('remote');
|
|
141
|
+
if (remoteSyntax) {
|
|
142
|
+
const [url, global] = extractUrlAndGlobal(remoteSyntax);
|
|
143
|
+
acc[key] = {
|
|
144
|
+
global,
|
|
145
|
+
url
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
} else {
|
|
150
|
+
const [url, global] = extractUrlAndGlobal(value);
|
|
151
|
+
acc[key] = {
|
|
152
|
+
global,
|
|
153
|
+
url
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
} else {
|
|
157
|
+
console.warn('remotes process', process.env['REMOTES']);
|
|
158
|
+
throw new Error(`[mf] Invalid value received for runtime_remote "${key}"`);
|
|
159
|
+
}
|
|
160
|
+
return acc;
|
|
161
|
+
}, {});
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
export { extractUrlAndGlobal, getRuntimeRemotes, loadScript, remoteVars };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/utilities",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.84",
|
|
4
4
|
"main": "./dist/index.cjs.js",
|
|
5
5
|
"module": "./dist/index.esm.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"@types/react": "^18.3.11"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@module-federation/sdk": "0.
|
|
25
|
+
"@module-federation/sdk": "2.0.1"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"react": "^16 || ^17 || ^18",
|