@module-federation/runtime 1.0.0-canary.1 → 1.0.0-canary.3
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/index.cjs.js +100 -99
- package/index.esm.js +100 -99
- package/package.json +2 -3
- package/share.cjs.js +23 -28
- package/share.esm.js +23 -28
- package/src/core.d.ts +3 -3
- package/src/utils/hooks/syncWaterfallHook.d.ts +1 -1
package/share.cjs.js
CHANGED
|
@@ -97,19 +97,19 @@ function isPlainObject(val) {
|
|
|
97
97
|
}
|
|
98
98
|
function isStaticResourcesEqual(url1, url2) {
|
|
99
99
|
const REG_EXP = /^(https?:)?\/\//i;
|
|
100
|
-
//
|
|
100
|
+
// Transform url1 and url2 into relative paths
|
|
101
101
|
const relativeUrl1 = url1.replace(REG_EXP, '').replace(/\/$/, '');
|
|
102
102
|
const relativeUrl2 = url2.replace(REG_EXP, '').replace(/\/$/, '');
|
|
103
|
-
//
|
|
103
|
+
// Check if the relative paths are identical
|
|
104
104
|
return relativeUrl1 === relativeUrl2;
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
var _nativeGlobal___FEDERATION__, _nativeGlobal___FEDERATION__1, _nativeGlobal___FEDERATION__2, _nativeGlobal___FEDERATION__3, _nativeGlobal___FEDERATION__4, _nativeGlobal___FEDERATION__5, _nativeGlobal___FEDERATION__6;
|
|
108
108
|
// export const nativeGlobal: typeof global = new Function('return this')();
|
|
109
109
|
const nativeGlobal = new Function('return this')();
|
|
110
|
-
//
|
|
111
|
-
// The sandbox in the
|
|
112
|
-
// If no loading content
|
|
110
|
+
// This section is to prevent encapsulation by certain microfrontend frameworks. Due to reuse policies, sandbox escapes.
|
|
111
|
+
// The sandbox in the microfrontend does not replicate the value of 'configurable'.
|
|
112
|
+
// If there is no loading content on the global object, this section defines the loading object.
|
|
113
113
|
if (!Object.hasOwnProperty.call(globalThis, '__GLOBAL_LOADING_REMOTE_ENTRY__')) {
|
|
114
114
|
Object.defineProperty(globalThis, '__GLOBAL_LOADING_REMOTE_ENTRY__', {
|
|
115
115
|
value: {},
|
|
@@ -184,23 +184,15 @@ function getGlobalFederationConstructor() {
|
|
|
184
184
|
function setGlobalFederationConstructor(FederationConstructor) {
|
|
185
185
|
if (isDebugMode()) {
|
|
186
186
|
Global.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
|
|
187
|
-
Global.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = '0.0.
|
|
187
|
+
Global.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = '1.0.0-canary.2';
|
|
188
188
|
}
|
|
189
189
|
}
|
|
190
190
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
191
191
|
function getInfoWithoutType(target, key, getModuleInfoHook) {
|
|
192
|
-
let res
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
key: key
|
|
197
|
-
};
|
|
198
|
-
} else {
|
|
199
|
-
res = {
|
|
200
|
-
value: undefined,
|
|
201
|
-
key: key
|
|
202
|
-
};
|
|
203
|
-
}
|
|
192
|
+
let res = {
|
|
193
|
+
value: target[key],
|
|
194
|
+
key: key
|
|
195
|
+
};
|
|
204
196
|
if (getModuleInfoHook) {
|
|
205
197
|
const hookRes = getModuleInfoHook(target, key);
|
|
206
198
|
res = hookRes || res;
|
|
@@ -209,18 +201,17 @@ function getInfoWithoutType(target, key, getModuleInfoHook) {
|
|
|
209
201
|
}
|
|
210
202
|
const getGlobalSnapshot = ()=>Global.__FEDERATION__.moduleInfo;
|
|
211
203
|
const getTargetSnapshotInfoByModuleInfo = (moduleInfo, snapshot, getModuleInfoHook)=>{
|
|
212
|
-
// remote
|
|
204
|
+
// Check if the remote is included in the hostSnapshot
|
|
213
205
|
const moduleKey = getFMId(moduleInfo);
|
|
214
206
|
const getModuleInfo = getInfoWithoutType(snapshot, moduleKey, getModuleInfoHook).value;
|
|
215
|
-
// remoteSnapshot
|
|
207
|
+
// The remoteSnapshot might not include a version
|
|
216
208
|
if (getModuleInfo && !getModuleInfo.version && 'version' in moduleInfo && moduleInfo['version']) {
|
|
217
209
|
getModuleInfo.version = moduleInfo['version'];
|
|
218
210
|
}
|
|
219
211
|
if (getModuleInfo) {
|
|
220
212
|
return getModuleInfo;
|
|
221
213
|
}
|
|
222
|
-
// remote
|
|
223
|
-
// deploy micro app snapshot
|
|
214
|
+
// If the remote is not included in the hostSnapshot, deploy a micro app snapshot
|
|
224
215
|
if ('version' in moduleInfo && moduleInfo['version']) {
|
|
225
216
|
const { version } = moduleInfo, resModuleInfo = _object_without_properties_loose(moduleInfo, [
|
|
226
217
|
"version"
|
|
@@ -242,9 +233,10 @@ const setGlobalSnapshotInfoByModuleInfo = (remoteInfo, moduleDetailInfo)=>{
|
|
|
242
233
|
const addGlobalSnapshot = (moduleInfos)=>{
|
|
243
234
|
Global.__FEDERATION__.moduleInfo = _extends({}, Global.__FEDERATION__.moduleInfo, moduleInfos);
|
|
244
235
|
return ()=>{
|
|
245
|
-
Object.keys(moduleInfos)
|
|
236
|
+
const keys = Object.keys(moduleInfos);
|
|
237
|
+
for (const key of keys){
|
|
246
238
|
delete Global.__FEDERATION__.moduleInfo[key];
|
|
247
|
-
}
|
|
239
|
+
}
|
|
248
240
|
};
|
|
249
241
|
};
|
|
250
242
|
const getRemoteEntryExports = (name, globalName)=>{
|
|
@@ -255,7 +247,10 @@ const getRemoteEntryExports = (name, globalName)=>{
|
|
|
255
247
|
entryExports
|
|
256
248
|
};
|
|
257
249
|
};
|
|
258
|
-
// global
|
|
250
|
+
// This function is used to register global plugins.
|
|
251
|
+
// It iterates over the provided plugins and checks if they are already registered.
|
|
252
|
+
// If a plugin is not registered, it is added to the global plugins.
|
|
253
|
+
// If a plugin is already registered, a warning message is logged.
|
|
259
254
|
const registerGlobalPlugins = (plugins)=>{
|
|
260
255
|
const { __GLOBAL_PLUGIN__ } = Global.__FEDERATION__;
|
|
261
256
|
plugins.forEach((plugin)=>{
|
|
@@ -696,8 +691,8 @@ function findSingletonVersionOrderByLoaded(scope, pkgName) {
|
|
|
696
691
|
};
|
|
697
692
|
return findVersion(scope, pkgName, callback);
|
|
698
693
|
}
|
|
699
|
-
//
|
|
700
|
-
// TODO:
|
|
694
|
+
// Details about shared resources
|
|
695
|
+
// TODO: Implement strictVersion for alignment with module federation.
|
|
701
696
|
function getGlobalShare(pkgName, shareInfo) {
|
|
702
697
|
const globalShares = Global.__FEDERATION__.__SHARE__;
|
|
703
698
|
const { shareConfig, scope = DEFAULT_SCOPE, strategy } = shareInfo;
|
|
@@ -712,7 +707,7 @@ function getGlobalShare(pkgName, shareInfo) {
|
|
|
712
707
|
const singletonVersion = strategy === 'loaded-first' ? findSingletonVersionOrderByLoaded(sc, pkgName) : findSingletonVersionOrderByVersion(sc, pkgName);
|
|
713
708
|
// eslint-disable-next-line max-depth
|
|
714
709
|
if (typeof requiredVersion === 'string' && !satisfy(singletonVersion, requiredVersion)) {
|
|
715
|
-
warn(`
|
|
710
|
+
warn(`Version ${singletonVersion} from ${singletonVersion && globalShares[sc][pkgName][singletonVersion].from} of shared singleton module ${pkgName} does not satisfy the requirement of ${shareInfo.from} which needs ${requiredVersion})`);
|
|
716
711
|
}
|
|
717
712
|
return globalShares[sc][pkgName][singletonVersion];
|
|
718
713
|
} else {
|
package/share.esm.js
CHANGED
|
@@ -95,19 +95,19 @@ function isPlainObject(val) {
|
|
|
95
95
|
}
|
|
96
96
|
function isStaticResourcesEqual(url1, url2) {
|
|
97
97
|
const REG_EXP = /^(https?:)?\/\//i;
|
|
98
|
-
//
|
|
98
|
+
// Transform url1 and url2 into relative paths
|
|
99
99
|
const relativeUrl1 = url1.replace(REG_EXP, '').replace(/\/$/, '');
|
|
100
100
|
const relativeUrl2 = url2.replace(REG_EXP, '').replace(/\/$/, '');
|
|
101
|
-
//
|
|
101
|
+
// Check if the relative paths are identical
|
|
102
102
|
return relativeUrl1 === relativeUrl2;
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
var _nativeGlobal___FEDERATION__, _nativeGlobal___FEDERATION__1, _nativeGlobal___FEDERATION__2, _nativeGlobal___FEDERATION__3, _nativeGlobal___FEDERATION__4, _nativeGlobal___FEDERATION__5, _nativeGlobal___FEDERATION__6;
|
|
106
106
|
// export const nativeGlobal: typeof global = new Function('return this')();
|
|
107
107
|
const nativeGlobal = new Function('return this')();
|
|
108
|
-
//
|
|
109
|
-
// The sandbox in the
|
|
110
|
-
// If no loading content
|
|
108
|
+
// This section is to prevent encapsulation by certain microfrontend frameworks. Due to reuse policies, sandbox escapes.
|
|
109
|
+
// The sandbox in the microfrontend does not replicate the value of 'configurable'.
|
|
110
|
+
// If there is no loading content on the global object, this section defines the loading object.
|
|
111
111
|
if (!Object.hasOwnProperty.call(globalThis, '__GLOBAL_LOADING_REMOTE_ENTRY__')) {
|
|
112
112
|
Object.defineProperty(globalThis, '__GLOBAL_LOADING_REMOTE_ENTRY__', {
|
|
113
113
|
value: {},
|
|
@@ -182,23 +182,15 @@ function getGlobalFederationConstructor() {
|
|
|
182
182
|
function setGlobalFederationConstructor(FederationConstructor) {
|
|
183
183
|
if (isDebugMode()) {
|
|
184
184
|
Global.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
|
|
185
|
-
Global.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = '0.0.
|
|
185
|
+
Global.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = '1.0.0-canary.2';
|
|
186
186
|
}
|
|
187
187
|
}
|
|
188
188
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
189
189
|
function getInfoWithoutType(target, key, getModuleInfoHook) {
|
|
190
|
-
let res
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
key: key
|
|
195
|
-
};
|
|
196
|
-
} else {
|
|
197
|
-
res = {
|
|
198
|
-
value: undefined,
|
|
199
|
-
key: key
|
|
200
|
-
};
|
|
201
|
-
}
|
|
190
|
+
let res = {
|
|
191
|
+
value: target[key],
|
|
192
|
+
key: key
|
|
193
|
+
};
|
|
202
194
|
if (getModuleInfoHook) {
|
|
203
195
|
const hookRes = getModuleInfoHook(target, key);
|
|
204
196
|
res = hookRes || res;
|
|
@@ -207,18 +199,17 @@ function getInfoWithoutType(target, key, getModuleInfoHook) {
|
|
|
207
199
|
}
|
|
208
200
|
const getGlobalSnapshot = ()=>Global.__FEDERATION__.moduleInfo;
|
|
209
201
|
const getTargetSnapshotInfoByModuleInfo = (moduleInfo, snapshot, getModuleInfoHook)=>{
|
|
210
|
-
// remote
|
|
202
|
+
// Check if the remote is included in the hostSnapshot
|
|
211
203
|
const moduleKey = getFMId(moduleInfo);
|
|
212
204
|
const getModuleInfo = getInfoWithoutType(snapshot, moduleKey, getModuleInfoHook).value;
|
|
213
|
-
// remoteSnapshot
|
|
205
|
+
// The remoteSnapshot might not include a version
|
|
214
206
|
if (getModuleInfo && !getModuleInfo.version && 'version' in moduleInfo && moduleInfo['version']) {
|
|
215
207
|
getModuleInfo.version = moduleInfo['version'];
|
|
216
208
|
}
|
|
217
209
|
if (getModuleInfo) {
|
|
218
210
|
return getModuleInfo;
|
|
219
211
|
}
|
|
220
|
-
// remote
|
|
221
|
-
// deploy micro app snapshot
|
|
212
|
+
// If the remote is not included in the hostSnapshot, deploy a micro app snapshot
|
|
222
213
|
if ('version' in moduleInfo && moduleInfo['version']) {
|
|
223
214
|
const { version } = moduleInfo, resModuleInfo = _object_without_properties_loose(moduleInfo, [
|
|
224
215
|
"version"
|
|
@@ -240,9 +231,10 @@ const setGlobalSnapshotInfoByModuleInfo = (remoteInfo, moduleDetailInfo)=>{
|
|
|
240
231
|
const addGlobalSnapshot = (moduleInfos)=>{
|
|
241
232
|
Global.__FEDERATION__.moduleInfo = _extends({}, Global.__FEDERATION__.moduleInfo, moduleInfos);
|
|
242
233
|
return ()=>{
|
|
243
|
-
Object.keys(moduleInfos)
|
|
234
|
+
const keys = Object.keys(moduleInfos);
|
|
235
|
+
for (const key of keys){
|
|
244
236
|
delete Global.__FEDERATION__.moduleInfo[key];
|
|
245
|
-
}
|
|
237
|
+
}
|
|
246
238
|
};
|
|
247
239
|
};
|
|
248
240
|
const getRemoteEntryExports = (name, globalName)=>{
|
|
@@ -253,7 +245,10 @@ const getRemoteEntryExports = (name, globalName)=>{
|
|
|
253
245
|
entryExports
|
|
254
246
|
};
|
|
255
247
|
};
|
|
256
|
-
// global
|
|
248
|
+
// This function is used to register global plugins.
|
|
249
|
+
// It iterates over the provided plugins and checks if they are already registered.
|
|
250
|
+
// If a plugin is not registered, it is added to the global plugins.
|
|
251
|
+
// If a plugin is already registered, a warning message is logged.
|
|
257
252
|
const registerGlobalPlugins = (plugins)=>{
|
|
258
253
|
const { __GLOBAL_PLUGIN__ } = Global.__FEDERATION__;
|
|
259
254
|
plugins.forEach((plugin)=>{
|
|
@@ -694,8 +689,8 @@ function findSingletonVersionOrderByLoaded(scope, pkgName) {
|
|
|
694
689
|
};
|
|
695
690
|
return findVersion(scope, pkgName, callback);
|
|
696
691
|
}
|
|
697
|
-
//
|
|
698
|
-
// TODO:
|
|
692
|
+
// Details about shared resources
|
|
693
|
+
// TODO: Implement strictVersion for alignment with module federation.
|
|
699
694
|
function getGlobalShare(pkgName, shareInfo) {
|
|
700
695
|
const globalShares = Global.__FEDERATION__.__SHARE__;
|
|
701
696
|
const { shareConfig, scope = DEFAULT_SCOPE, strategy } = shareInfo;
|
|
@@ -710,7 +705,7 @@ function getGlobalShare(pkgName, shareInfo) {
|
|
|
710
705
|
const singletonVersion = strategy === 'loaded-first' ? findSingletonVersionOrderByLoaded(sc, pkgName) : findSingletonVersionOrderByVersion(sc, pkgName);
|
|
711
706
|
// eslint-disable-next-line max-depth
|
|
712
707
|
if (typeof requiredVersion === 'string' && !satisfy(singletonVersion, requiredVersion)) {
|
|
713
|
-
warn(`
|
|
708
|
+
warn(`Version ${singletonVersion} from ${singletonVersion && globalShares[sc][pkgName][singletonVersion].from} of shared singleton module ${pkgName} does not satisfy the requirement of ${shareInfo.from} which needs ${requiredVersion})`);
|
|
714
709
|
}
|
|
715
710
|
return globalShares[sc][pkgName][singletonVersion];
|
|
716
711
|
} else {
|
package/src/core.d.ts
CHANGED
|
@@ -101,9 +101,9 @@ export declare class FederationHost {
|
|
|
101
101
|
}): Promise<T | null>;
|
|
102
102
|
preloadRemote(preloadOptions: Array<PreloadRemoteArgs>): Promise<void>;
|
|
103
103
|
/**
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
104
|
+
* This function initializes the sharing sequence (executed only once per share scope).
|
|
105
|
+
* It accepts one argument, the name of the share scope.
|
|
106
|
+
* If the share scope does not exist, it creates one.
|
|
107
107
|
*/
|
|
108
108
|
initializeSharing(shareScopeName?: string): boolean | Promise<boolean>;
|
|
109
109
|
private formatOptions;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SyncHook } from './syncHook';
|
|
2
|
-
export declare function checkReturnData(
|
|
2
|
+
export declare function checkReturnData(originalData: any, returnedData: any): boolean;
|
|
3
3
|
export declare class SyncWaterfallHook<T extends Record<string, any>> extends SyncHook<[
|
|
4
4
|
T
|
|
5
5
|
], T> {
|