@module-federation/runtime 0.0.0-next-20240411125344 → 0.0.0-next-20240412103714

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/README.md CHANGED
@@ -50,25 +50,9 @@ type InitOptions {
50
50
  // List of dependencies that need to be shared by the current host
51
51
  // When using the build plugin, users can configure the dependencies that need to be shared in the build plugin, and the build plugin will inject the dependencies that need to be shared into the runtime shared configuration.
52
52
  // Shared must be manually passed in the version instance reference when it is passed in at runtime, because it cannot be directly passed in at runtime.
53
- shared?: {
54
- [pkgName: string]: ShareArgs | ShareArgs[];
55
- };
53
+ shared?: ShareInfos;
56
54
  };
57
55
 
58
- type ShareArgs =
59
- | (SharedBaseArgs & { get: SharedGetter })
60
- | (SharedBaseArgs & { lib: () => Module });
61
-
62
- type SharedBaseArgs = {
63
- version: string;
64
- shareConfig?: SharedConfig;
65
- scope?: string | Array<string>;
66
- deps?: Array<string>;
67
- strategy?: 'version-first' | 'loaded-first';
68
- };
69
-
70
- type SharedGetter = (() => () => Module) | (() => Promise<() => Module>);
71
-
72
56
  type RemoteInfo = (RemotesWithEntry | RemotesWithVersion) & {
73
57
  alias?: string;
74
58
  };
@@ -136,7 +120,7 @@ loadRemote('app2/util').then((m) => m.add(1, 2, 3));
136
120
 
137
121
  ### loadShare
138
122
 
139
- - Type: `loadShare(pkgName: string, extraOptions?: { customShareInfo?: Partial<Shared>;resolver?: (sharedOptions: ShareInfos[string]) => Shared;})`
123
+ - Type: `loadShare(pkgName: string)`
140
124
  - Gets the `share` dependency. When there are `share` dependencies that match the current `host` in the global environment, the existing and satisfying `share` dependencies will be reused first. Otherwise, load its own dependencies and store them in the global cache.
141
125
  - This `API` is generally not called directly by users, but is used by build plugins to convert their own dependencies.
142
126
 
@@ -177,50 +161,6 @@ loadShare('react').then((reactFactory) => {
177
161
  });
178
162
  ```
179
163
 
180
- If has set multiple version shared, `loadShare` will return the loaded and has max version shared. The behavior can be controlled by set `extraOptions.resolver`:
181
-
182
- ```js
183
- import { init, loadRemote, loadShare } from '@module-federation/runtime';
184
-
185
- init({
186
- name: '@demo/main-app',
187
- remotes: [],
188
- shared: {
189
- react: [
190
- {
191
- version: '17.0.0',
192
- scope: 'default',
193
- get: async ()=>() => ({ version: '17.0.0)' }),
194
- shareConfig: {
195
- singleton: true,
196
- requiredVersion: '^17.0.0',
197
- },
198
- },
199
- {
200
- version: '18.0.0',
201
- scope: 'default',
202
- // pass lib means the shared has loaded
203
- lib: () => ({ version: '18.0.0)' }),
204
- shareConfig: {
205
- singleton: true,
206
- requiredVersion: '^18.0.0',
207
- },
208
- },
209
- ],
210
- },
211
- });
212
-
213
- loadShare('react', {
214
- resolver: (sharedOptions) => {
215
- return (
216
- sharedOptions.find((i) => i.version === '17.0.0') ?? sharedOptions[0]
217
- );
218
- },
219
- }).then((reactFactory) => {
220
- console.log(reactFactory()); // { version: '17.0.0)' }
221
- });
222
- ```
223
-
224
164
  ### preloadRemote
225
165
 
226
166
  - Type: `preloadRemote(preloadOptions: Array<PreloadRemoteArgs>)`
@@ -1,4 +1,4 @@
1
- import { o as getRegisteredShare, v as getGlobalShareScope, G as Global, J as nativeGlobal, K as resetFederationGlobalInfo, E as getGlobalFederationInstance, H as setGlobalFederationInstance, F as getGlobalFederationConstructor, C as setGlobalFederationConstructor, l as getInfoWithoutType, u as getGlobalSnapshot, L as getTargetSnapshotInfoByModuleInfo, q as getGlobalSnapshotInfoByModuleInfo, t as setGlobalSnapshotInfoByModuleInfo, r as addGlobalSnapshot, c as getRemoteEntryExports, I as registerGlobalPlugins, g as getGlobalHostPlugins, m as getPreloaded, n as setPreloaded } from './share.esm.js';
1
+ import { l as getRegisteredShare, u as getGlobalShareScope, G as Global, H as nativeGlobal, I as resetFederationGlobalInfo, B as getGlobalFederationInstance, E as setGlobalFederationInstance, C as getGlobalFederationConstructor, A as setGlobalFederationConstructor, m as getInfoWithoutType, t as getGlobalSnapshot, J as getTargetSnapshotInfoByModuleInfo, p as getGlobalSnapshotInfoByModuleInfo, r as setGlobalSnapshotInfoByModuleInfo, q as addGlobalSnapshot, c as getRemoteEntryExports, F as registerGlobalPlugins, g as getGlobalHostPlugins, n as getPreloaded, o as setPreloaded } from './share.esm.js';
2
2
 
3
3
  const ShareUtils = {
4
4
  getRegisteredShare,
package/dist/index.cjs.js CHANGED
@@ -813,33 +813,23 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
813
813
  }
814
814
  }, true, memo, remoteSnapshot);
815
815
  if (remoteSnapshot.shared) {
816
- const collectSharedAssets = (shareInfo, snapshotShared)=>{
817
- const registeredShared = share.getRegisteredShare(origin.shareScopeMap, snapshotShared.sharedName, shareInfo, origin.hooks.lifecycle.resolveShare);
816
+ remoteSnapshot.shared.forEach((shared)=>{
817
+ var _options_shared;
818
+ const shareInfo = (_options_shared = options.shared) == null ? void 0 : _options_shared[shared.sharedName];
819
+ // When data is downgraded, the shared configuration may be different.
820
+ if (!shareInfo) {
821
+ return;
822
+ }
823
+ const registeredShared = share.getRegisteredShare(origin.shareScopeMap, shared.sharedName, shareInfo, origin.hooks.lifecycle.resolveShare);
818
824
  // If the global share does not exist, or the lib function does not exist, it means that the shared has not been loaded yet and can be preloaded.
819
825
  if (registeredShared && typeof registeredShared.lib === 'function') {
820
- snapshotShared.assets.js.sync.forEach((asset)=>{
826
+ shared.assets.js.sync.forEach((asset)=>{
821
827
  loadedSharedJsAssets.add(asset);
822
828
  });
823
- snapshotShared.assets.css.sync.forEach((asset)=>{
829
+ shared.assets.css.sync.forEach((asset)=>{
824
830
  loadedSharedCssAssets.add(asset);
825
831
  });
826
832
  }
827
- };
828
- remoteSnapshot.shared.forEach((shared)=>{
829
- var _options_shared;
830
- const shareInfos = (_options_shared = options.shared) == null ? void 0 : _options_shared[shared.sharedName];
831
- if (!shareInfos) {
832
- return;
833
- }
834
- // if no version, preload all shared
835
- const sharedOptions = shared.version ? shareInfos.find((s)=>s.version === shared.version) : shareInfos;
836
- if (!sharedOptions) {
837
- return;
838
- }
839
- const arrayShareInfo = share.arrayOptions(sharedOptions);
840
- arrayShareInfo.forEach((s)=>{
841
- collectSharedAssets(s, shared);
842
- });
843
833
  });
844
834
  }
845
835
  const needPreloadJsAssets = jsAssets.filter((asset)=>!loadedSharedJsAssets.has(asset));
@@ -1124,16 +1114,13 @@ class FederationHost {
1124
1114
  this.options = options;
1125
1115
  return options;
1126
1116
  }
1127
- async loadShare(pkgName, extraOptions) {
1117
+ async loadShare(pkgName, customShareInfo) {
1118
+ var _this_options_shared;
1128
1119
  // This function performs the following steps:
1129
1120
  // 1. Checks if the currently loaded share already exists, if not, it throws an error
1130
1121
  // 2. Searches globally for a matching share, if found, it uses it directly
1131
1122
  // 3. If not found, it retrieves it from the current share and stores the obtained share globally.
1132
- const shareInfo = share.getTargetSharedOptions({
1133
- pkgName,
1134
- extraOptions,
1135
- shareInfos: this.options.shared
1136
- });
1123
+ const shareInfo = Object.assign({}, (_this_options_shared = this.options.shared) == null ? void 0 : _this_options_shared[pkgName], customShareInfo);
1137
1124
  if (shareInfo == null ? void 0 : shareInfo.scope) {
1138
1125
  await Promise.all(shareInfo.scope.map(async (shareScope)=>{
1139
1126
  await Promise.all(this.initializeSharing(shareScope, shareInfo.strategy));
@@ -1192,7 +1179,7 @@ class FederationHost {
1192
1179
  });
1193
1180
  return loading;
1194
1181
  } else {
1195
- if (extraOptions == null ? void 0 : extraOptions.customShareInfo) {
1182
+ if (customShareInfo) {
1196
1183
  return false;
1197
1184
  }
1198
1185
  const asyncLoadProcess = async ()=>{
@@ -1223,12 +1210,9 @@ class FederationHost {
1223
1210
  // 1. If the loaded shared already exists globally, then it will be reused
1224
1211
  // 2. If lib exists in local shared, it will be used directly
1225
1212
  // 3. If the local get returns something other than Promise, then it will be used directly
1226
- loadShareSync(pkgName, extraOptions) {
1227
- const shareInfo = share.getTargetSharedOptions({
1228
- pkgName,
1229
- extraOptions,
1230
- shareInfos: this.options.shared
1231
- });
1213
+ loadShareSync(pkgName, customShareInfo) {
1214
+ var _this_options_shared;
1215
+ const shareInfo = Object.assign({}, (_this_options_shared = this.options.shared) == null ? void 0 : _this_options_shared[pkgName], customShareInfo);
1232
1216
  if (shareInfo == null ? void 0 : shareInfo.scope) {
1233
1217
  shareInfo.scope.forEach((shareScope)=>{
1234
1218
  this.initializeSharing(shareScope, shareInfo.strategy);
@@ -1468,11 +1452,9 @@ class FederationHost {
1468
1452
  };
1469
1453
  Object.keys(this.options.shared).forEach((shareName)=>{
1470
1454
  const shared = this.options.shared[shareName];
1471
- shared.forEach((s)=>{
1472
- if (s.scope.includes(shareScopeName)) {
1473
- register(shareName, s);
1474
- }
1475
- });
1455
+ if (shared.scope.includes(shareScopeName)) {
1456
+ register(shareName, shared);
1457
+ }
1476
1458
  });
1477
1459
  if (strategy === 'version-first') {
1478
1460
  this.options.remotes.forEach((remote)=>{
@@ -1493,19 +1475,7 @@ class FederationHost {
1493
1475
  }
1494
1476
  formatOptions(globalOptions, userOptions) {
1495
1477
  const formatShareOptions = share.formatShareConfigs(userOptions.shared || {}, userOptions.name);
1496
- const shared = _extends({}, globalOptions.shared);
1497
- Object.keys(formatShareOptions).forEach((shareKey)=>{
1498
- if (!shared[shareKey]) {
1499
- shared[shareKey] = formatShareOptions[shareKey];
1500
- } else {
1501
- formatShareOptions[shareKey].forEach((newUserSharedOptions)=>{
1502
- const isSameVersion = shared[shareKey].find((s)=>s.version === newUserSharedOptions.version);
1503
- if (!isSameVersion) {
1504
- shared[shareKey].push(newUserSharedOptions);
1505
- }
1506
- });
1507
- }
1508
- });
1478
+ const shared = _extends({}, globalOptions.shared, formatShareOptions);
1509
1479
  const { userOptions: userOptionsRes, options: globalOptionsRes } = this.hooks.lifecycle.beforeInit.emit({
1510
1480
  origin: this,
1511
1481
  userOptions,
@@ -1523,19 +1493,17 @@ class FederationHost {
1523
1493
  const sharedKeys = Object.keys(formatShareOptions);
1524
1494
  sharedKeys.forEach((sharedKey)=>{
1525
1495
  const sharedVal = formatShareOptions[sharedKey];
1526
- sharedVal.forEach((s)=>{
1527
- const registeredShared = share.getRegisteredShare(this.shareScopeMap, sharedKey, s, this.hooks.lifecycle.resolveShare);
1528
- if (!registeredShared && s && s.lib) {
1529
- this.setShared({
1530
- pkgName: sharedKey,
1531
- lib: s.lib,
1532
- get: s.get,
1533
- loaded: true,
1534
- shared: s,
1535
- from: userOptions.name
1536
- });
1537
- }
1538
- });
1496
+ const registeredShared = share.getRegisteredShare(this.shareScopeMap, sharedKey, sharedVal, this.hooks.lifecycle.resolveShare);
1497
+ if (!registeredShared && sharedVal && sharedVal.lib) {
1498
+ this.setShared({
1499
+ pkgName: sharedKey,
1500
+ lib: sharedVal.lib,
1501
+ get: sharedVal.get,
1502
+ loaded: true,
1503
+ shared: sharedVal,
1504
+ from: userOptions.name
1505
+ });
1506
+ }
1539
1507
  });
1540
1508
  const plugins = [
1541
1509
  ...globalOptionsRes.plugins
package/dist/index.esm.js CHANGED
@@ -1,5 +1,5 @@
1
- import { g as getGlobalHostPlugins, a as globalLoading, D as DEFAULT_REMOTE_TYPE, b as DEFAULT_SCOPE, c as getRemoteEntryExports, d as assert, s as safeToString, e as getFMId, i as isObject, f as error, w as warn, h as isPlainObject, j as isRemoteInfoWithEntry, k as isPureRemoteEntry, l as getInfoWithoutType, m as getPreloaded, n as setPreloaded, o as getRegisteredShare, p as arrayOptions, q as getGlobalSnapshotInfoByModuleInfo, r as addGlobalSnapshot, t as setGlobalSnapshotInfoByModuleInfo, u as getGlobalSnapshot, G as Global, v as getGlobalShareScope, x as getTargetSharedOptions, y as formatShareConfigs, z as getBuilderId, A as isBrowserEnv, B as addUniqueItem, C as setGlobalFederationConstructor, E as getGlobalFederationInstance, F as getGlobalFederationConstructor, H as setGlobalFederationInstance } from './share.esm.js';
2
- export { I as registerGlobalPlugins } from './share.esm.js';
1
+ import { g as getGlobalHostPlugins, a as globalLoading, D as DEFAULT_REMOTE_TYPE, b as DEFAULT_SCOPE, c as getRemoteEntryExports, d as assert, s as safeToString, e as getFMId, i as isObject, f as error, w as warn, h as isPlainObject, j as isRemoteInfoWithEntry, k as isPureRemoteEntry, l as getRegisteredShare, m as getInfoWithoutType, n as getPreloaded, o as setPreloaded, p as getGlobalSnapshotInfoByModuleInfo, q as addGlobalSnapshot, r as setGlobalSnapshotInfoByModuleInfo, t as getGlobalSnapshot, G as Global, u as getGlobalShareScope, v as formatShareConfigs, x as getBuilderId, y as isBrowserEnv, z as addUniqueItem, A as setGlobalFederationConstructor, B as getGlobalFederationInstance, C as getGlobalFederationConstructor, E as setGlobalFederationInstance } from './share.esm.js';
2
+ export { F as registerGlobalPlugins } from './share.esm.js';
3
3
  import { loadScriptNode, loadScript, composeKeyWithSeparator, createLink, getResourceUrl, isManifestProvider, generateSnapshotFromManifest } from '@module-federation/sdk';
4
4
  export { loadScript, loadScriptNode } from '@module-federation/sdk';
5
5
 
@@ -811,33 +811,23 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
811
811
  }
812
812
  }, true, memo, remoteSnapshot);
813
813
  if (remoteSnapshot.shared) {
814
- const collectSharedAssets = (shareInfo, snapshotShared)=>{
815
- const registeredShared = getRegisteredShare(origin.shareScopeMap, snapshotShared.sharedName, shareInfo, origin.hooks.lifecycle.resolveShare);
814
+ remoteSnapshot.shared.forEach((shared)=>{
815
+ var _options_shared;
816
+ const shareInfo = (_options_shared = options.shared) == null ? void 0 : _options_shared[shared.sharedName];
817
+ // When data is downgraded, the shared configuration may be different.
818
+ if (!shareInfo) {
819
+ return;
820
+ }
821
+ const registeredShared = getRegisteredShare(origin.shareScopeMap, shared.sharedName, shareInfo, origin.hooks.lifecycle.resolveShare);
816
822
  // If the global share does not exist, or the lib function does not exist, it means that the shared has not been loaded yet and can be preloaded.
817
823
  if (registeredShared && typeof registeredShared.lib === 'function') {
818
- snapshotShared.assets.js.sync.forEach((asset)=>{
824
+ shared.assets.js.sync.forEach((asset)=>{
819
825
  loadedSharedJsAssets.add(asset);
820
826
  });
821
- snapshotShared.assets.css.sync.forEach((asset)=>{
827
+ shared.assets.css.sync.forEach((asset)=>{
822
828
  loadedSharedCssAssets.add(asset);
823
829
  });
824
830
  }
825
- };
826
- remoteSnapshot.shared.forEach((shared)=>{
827
- var _options_shared;
828
- const shareInfos = (_options_shared = options.shared) == null ? void 0 : _options_shared[shared.sharedName];
829
- if (!shareInfos) {
830
- return;
831
- }
832
- // if no version, preload all shared
833
- const sharedOptions = shared.version ? shareInfos.find((s)=>s.version === shared.version) : shareInfos;
834
- if (!sharedOptions) {
835
- return;
836
- }
837
- const arrayShareInfo = arrayOptions(sharedOptions);
838
- arrayShareInfo.forEach((s)=>{
839
- collectSharedAssets(s, shared);
840
- });
841
831
  });
842
832
  }
843
833
  const needPreloadJsAssets = jsAssets.filter((asset)=>!loadedSharedJsAssets.has(asset));
@@ -1122,16 +1112,13 @@ class FederationHost {
1122
1112
  this.options = options;
1123
1113
  return options;
1124
1114
  }
1125
- async loadShare(pkgName, extraOptions) {
1115
+ async loadShare(pkgName, customShareInfo) {
1116
+ var _this_options_shared;
1126
1117
  // This function performs the following steps:
1127
1118
  // 1. Checks if the currently loaded share already exists, if not, it throws an error
1128
1119
  // 2. Searches globally for a matching share, if found, it uses it directly
1129
1120
  // 3. If not found, it retrieves it from the current share and stores the obtained share globally.
1130
- const shareInfo = getTargetSharedOptions({
1131
- pkgName,
1132
- extraOptions,
1133
- shareInfos: this.options.shared
1134
- });
1121
+ const shareInfo = Object.assign({}, (_this_options_shared = this.options.shared) == null ? void 0 : _this_options_shared[pkgName], customShareInfo);
1135
1122
  if (shareInfo == null ? void 0 : shareInfo.scope) {
1136
1123
  await Promise.all(shareInfo.scope.map(async (shareScope)=>{
1137
1124
  await Promise.all(this.initializeSharing(shareScope, shareInfo.strategy));
@@ -1190,7 +1177,7 @@ class FederationHost {
1190
1177
  });
1191
1178
  return loading;
1192
1179
  } else {
1193
- if (extraOptions == null ? void 0 : extraOptions.customShareInfo) {
1180
+ if (customShareInfo) {
1194
1181
  return false;
1195
1182
  }
1196
1183
  const asyncLoadProcess = async ()=>{
@@ -1221,12 +1208,9 @@ class FederationHost {
1221
1208
  // 1. If the loaded shared already exists globally, then it will be reused
1222
1209
  // 2. If lib exists in local shared, it will be used directly
1223
1210
  // 3. If the local get returns something other than Promise, then it will be used directly
1224
- loadShareSync(pkgName, extraOptions) {
1225
- const shareInfo = getTargetSharedOptions({
1226
- pkgName,
1227
- extraOptions,
1228
- shareInfos: this.options.shared
1229
- });
1211
+ loadShareSync(pkgName, customShareInfo) {
1212
+ var _this_options_shared;
1213
+ const shareInfo = Object.assign({}, (_this_options_shared = this.options.shared) == null ? void 0 : _this_options_shared[pkgName], customShareInfo);
1230
1214
  if (shareInfo == null ? void 0 : shareInfo.scope) {
1231
1215
  shareInfo.scope.forEach((shareScope)=>{
1232
1216
  this.initializeSharing(shareScope, shareInfo.strategy);
@@ -1466,11 +1450,9 @@ class FederationHost {
1466
1450
  };
1467
1451
  Object.keys(this.options.shared).forEach((shareName)=>{
1468
1452
  const shared = this.options.shared[shareName];
1469
- shared.forEach((s)=>{
1470
- if (s.scope.includes(shareScopeName)) {
1471
- register(shareName, s);
1472
- }
1473
- });
1453
+ if (shared.scope.includes(shareScopeName)) {
1454
+ register(shareName, shared);
1455
+ }
1474
1456
  });
1475
1457
  if (strategy === 'version-first') {
1476
1458
  this.options.remotes.forEach((remote)=>{
@@ -1491,19 +1473,7 @@ class FederationHost {
1491
1473
  }
1492
1474
  formatOptions(globalOptions, userOptions) {
1493
1475
  const formatShareOptions = formatShareConfigs(userOptions.shared || {}, userOptions.name);
1494
- const shared = _extends({}, globalOptions.shared);
1495
- Object.keys(formatShareOptions).forEach((shareKey)=>{
1496
- if (!shared[shareKey]) {
1497
- shared[shareKey] = formatShareOptions[shareKey];
1498
- } else {
1499
- formatShareOptions[shareKey].forEach((newUserSharedOptions)=>{
1500
- const isSameVersion = shared[shareKey].find((s)=>s.version === newUserSharedOptions.version);
1501
- if (!isSameVersion) {
1502
- shared[shareKey].push(newUserSharedOptions);
1503
- }
1504
- });
1505
- }
1506
- });
1476
+ const shared = _extends({}, globalOptions.shared, formatShareOptions);
1507
1477
  const { userOptions: userOptionsRes, options: globalOptionsRes } = this.hooks.lifecycle.beforeInit.emit({
1508
1478
  origin: this,
1509
1479
  userOptions,
@@ -1521,19 +1491,17 @@ class FederationHost {
1521
1491
  const sharedKeys = Object.keys(formatShareOptions);
1522
1492
  sharedKeys.forEach((sharedKey)=>{
1523
1493
  const sharedVal = formatShareOptions[sharedKey];
1524
- sharedVal.forEach((s)=>{
1525
- const registeredShared = getRegisteredShare(this.shareScopeMap, sharedKey, s, this.hooks.lifecycle.resolveShare);
1526
- if (!registeredShared && s && s.lib) {
1527
- this.setShared({
1528
- pkgName: sharedKey,
1529
- lib: s.lib,
1530
- get: s.get,
1531
- loaded: true,
1532
- shared: s,
1533
- from: userOptions.name
1534
- });
1535
- }
1536
- });
1494
+ const registeredShared = getRegisteredShare(this.shareScopeMap, sharedKey, sharedVal, this.hooks.lifecycle.resolveShare);
1495
+ if (!registeredShared && sharedVal && sharedVal.lib) {
1496
+ this.setShared({
1497
+ pkgName: sharedKey,
1498
+ lib: sharedVal.lib,
1499
+ get: sharedVal.get,
1500
+ loaded: true,
1501
+ shared: sharedVal,
1502
+ from: userOptions.name
1503
+ });
1504
+ }
1537
1505
  });
1538
1506
  const plugins = [
1539
1507
  ...globalOptionsRes.plugins
package/dist/package.json CHANGED
@@ -15,19 +15,19 @@
15
15
  ],
16
16
  "exports": {
17
17
  ".": {
18
+ "types": "./dist/index.cjs.d.ts",
18
19
  "import": "./dist/index.esm.js",
19
- "require": "./dist/index.cjs.js",
20
- "types": "./dist/index.cjs.d.ts"
20
+ "require": "./dist/index.cjs.js"
21
21
  },
22
22
  "./helpers": {
23
+ "types": "./dist/helpers.cjs.d.ts",
23
24
  "import": "./dist/helpers.esm.js",
24
- "require": "./dist/helpers.cjs.js",
25
- "types": "./dist/helpers.cjs.d.ts"
25
+ "require": "./dist/helpers.cjs.js"
26
26
  },
27
27
  "./types": {
28
+ "types": "./dist/types.cjs.d.ts",
28
29
  "import": "./dist/types.esm.js",
29
- "require": "./dist/types.cjs.js",
30
- "types": "./dist/types.cjs.d.ts"
30
+ "require": "./dist/types.cjs.js"
31
31
  },
32
32
  "./*": "./*"
33
33
  },
package/dist/share.cjs.js CHANGED
@@ -71,11 +71,6 @@ const objectToString = Object.prototype.toString;
71
71
  function isPlainObject(val) {
72
72
  return objectToString.call(val) === '[object Object]';
73
73
  }
74
- function arrayOptions(options) {
75
- return Array.isArray(options) ? options : [
76
- options
77
- ];
78
- }
79
74
 
80
75
  function _extends$1() {
81
76
  _extends$1 = Object.assign || function(target) {
@@ -679,11 +674,7 @@ function formatShareConfigs(shareArgs, from) {
679
674
  return {};
680
675
  }
681
676
  return Object.keys(shareArgs).reduce((res, pkgName)=>{
682
- const arrayShareArgs = arrayOptions(shareArgs[pkgName]);
683
- res[pkgName] = res[pkgName] || [];
684
- arrayShareArgs.forEach((shareConfig)=>{
685
- res[pkgName].push(formatShare(shareConfig, from));
686
- });
677
+ res[pkgName] = formatShare(shareArgs[pkgName], from);
687
678
  return res;
688
679
  }, {});
689
680
  }
@@ -706,11 +697,12 @@ function versionLt(a, b) {
706
697
  return false;
707
698
  }
708
699
  }
709
- const findVersion = (shareVersionMap, cb)=>{
700
+ const findVersion = (shareScopeMap, scope, pkgName, cb)=>{
701
+ const versions = shareScopeMap[scope][pkgName];
710
702
  const callback = cb || function(prev, cur) {
711
703
  return versionLt(prev, cur);
712
704
  };
713
- return Object.keys(shareVersionMap).reduce((prev, cur)=>{
705
+ return Object.keys(versions).reduce((prev, cur)=>{
714
706
  if (!prev) {
715
707
  return cur;
716
708
  }
@@ -732,7 +724,7 @@ function findSingletonVersionOrderByVersion(shareScopeMap, scope, pkgName) {
732
724
  const callback = function(prev, cur) {
733
725
  return !isLoaded(versions[prev]) && versionLt(prev, cur);
734
726
  };
735
- return findVersion(shareScopeMap[scope][pkgName], callback);
727
+ return findVersion(shareScopeMap, scope, pkgName, callback);
736
728
  }
737
729
  function findSingletonVersionOrderByLoaded(shareScopeMap, scope, pkgName) {
738
730
  const versions = shareScopeMap[scope][pkgName];
@@ -749,7 +741,7 @@ function findSingletonVersionOrderByLoaded(shareScopeMap, scope, pkgName) {
749
741
  }
750
742
  return versionLt(prev, cur);
751
743
  };
752
- return findVersion(shareScopeMap[scope][pkgName], callback);
744
+ return findVersion(shareScopeMap, scope, pkgName, callback);
753
745
  }
754
746
  function getFindShareFunction(strategy) {
755
747
  if (strategy === 'loaded-first') {
@@ -812,33 +804,12 @@ function getRegisteredShare(localShareScopeMap, pkgName, shareInfo, resolveShare
812
804
  function getGlobalShareScope() {
813
805
  return Global.__FEDERATION__.__SHARE__;
814
806
  }
815
- function getTargetSharedOptions(options) {
816
- const { pkgName, extraOptions, shareInfos } = options;
817
- const defaultResolver = (sharedOptions)=>{
818
- if (!sharedOptions) {
819
- return undefined;
820
- }
821
- const shareVersionMap = {};
822
- sharedOptions.forEach((shared)=>{
823
- shareVersionMap[shared.version] = shared;
824
- });
825
- const callback = function(prev, cur) {
826
- return !isLoaded(shareVersionMap[prev]) && versionLt(prev, cur);
827
- };
828
- const maxVersion = findVersion(shareVersionMap, callback);
829
- return shareVersionMap[maxVersion];
830
- };
831
- var _extraOptions_resolver;
832
- const resolver = (_extraOptions_resolver = extraOptions == null ? void 0 : extraOptions.resolver) != null ? _extraOptions_resolver : defaultResolver;
833
- return Object.assign({}, resolver(shareInfos[pkgName]), extraOptions == null ? void 0 : extraOptions.customShareInfo);
834
- }
835
807
 
836
808
  exports.DEFAULT_REMOTE_TYPE = DEFAULT_REMOTE_TYPE;
837
809
  exports.DEFAULT_SCOPE = DEFAULT_SCOPE;
838
810
  exports.Global = Global;
839
811
  exports.addGlobalSnapshot = addGlobalSnapshot;
840
812
  exports.addUniqueItem = addUniqueItem;
841
- exports.arrayOptions = arrayOptions;
842
813
  exports.assert = assert;
843
814
  exports.error = error;
844
815
  exports.formatShareConfigs = formatShareConfigs;
@@ -854,7 +825,6 @@ exports.getInfoWithoutType = getInfoWithoutType;
854
825
  exports.getPreloaded = getPreloaded;
855
826
  exports.getRegisteredShare = getRegisteredShare;
856
827
  exports.getRemoteEntryExports = getRemoteEntryExports;
857
- exports.getTargetSharedOptions = getTargetSharedOptions;
858
828
  exports.getTargetSnapshotInfoByModuleInfo = getTargetSnapshotInfoByModuleInfo;
859
829
  exports.globalLoading = globalLoading;
860
830
  exports.isBrowserEnv = isBrowserEnv;
package/dist/share.esm.js CHANGED
@@ -69,11 +69,6 @@ const objectToString = Object.prototype.toString;
69
69
  function isPlainObject(val) {
70
70
  return objectToString.call(val) === '[object Object]';
71
71
  }
72
- function arrayOptions(options) {
73
- return Array.isArray(options) ? options : [
74
- options
75
- ];
76
- }
77
72
 
78
73
  function _extends$1() {
79
74
  _extends$1 = Object.assign || function(target) {
@@ -677,11 +672,7 @@ function formatShareConfigs(shareArgs, from) {
677
672
  return {};
678
673
  }
679
674
  return Object.keys(shareArgs).reduce((res, pkgName)=>{
680
- const arrayShareArgs = arrayOptions(shareArgs[pkgName]);
681
- res[pkgName] = res[pkgName] || [];
682
- arrayShareArgs.forEach((shareConfig)=>{
683
- res[pkgName].push(formatShare(shareConfig, from));
684
- });
675
+ res[pkgName] = formatShare(shareArgs[pkgName], from);
685
676
  return res;
686
677
  }, {});
687
678
  }
@@ -704,11 +695,12 @@ function versionLt(a, b) {
704
695
  return false;
705
696
  }
706
697
  }
707
- const findVersion = (shareVersionMap, cb)=>{
698
+ const findVersion = (shareScopeMap, scope, pkgName, cb)=>{
699
+ const versions = shareScopeMap[scope][pkgName];
708
700
  const callback = cb || function(prev, cur) {
709
701
  return versionLt(prev, cur);
710
702
  };
711
- return Object.keys(shareVersionMap).reduce((prev, cur)=>{
703
+ return Object.keys(versions).reduce((prev, cur)=>{
712
704
  if (!prev) {
713
705
  return cur;
714
706
  }
@@ -730,7 +722,7 @@ function findSingletonVersionOrderByVersion(shareScopeMap, scope, pkgName) {
730
722
  const callback = function(prev, cur) {
731
723
  return !isLoaded(versions[prev]) && versionLt(prev, cur);
732
724
  };
733
- return findVersion(shareScopeMap[scope][pkgName], callback);
725
+ return findVersion(shareScopeMap, scope, pkgName, callback);
734
726
  }
735
727
  function findSingletonVersionOrderByLoaded(shareScopeMap, scope, pkgName) {
736
728
  const versions = shareScopeMap[scope][pkgName];
@@ -747,7 +739,7 @@ function findSingletonVersionOrderByLoaded(shareScopeMap, scope, pkgName) {
747
739
  }
748
740
  return versionLt(prev, cur);
749
741
  };
750
- return findVersion(shareScopeMap[scope][pkgName], callback);
742
+ return findVersion(shareScopeMap, scope, pkgName, callback);
751
743
  }
752
744
  function getFindShareFunction(strategy) {
753
745
  if (strategy === 'loaded-first') {
@@ -810,25 +802,5 @@ function getRegisteredShare(localShareScopeMap, pkgName, shareInfo, resolveShare
810
802
  function getGlobalShareScope() {
811
803
  return Global.__FEDERATION__.__SHARE__;
812
804
  }
813
- function getTargetSharedOptions(options) {
814
- const { pkgName, extraOptions, shareInfos } = options;
815
- const defaultResolver = (sharedOptions)=>{
816
- if (!sharedOptions) {
817
- return undefined;
818
- }
819
- const shareVersionMap = {};
820
- sharedOptions.forEach((shared)=>{
821
- shareVersionMap[shared.version] = shared;
822
- });
823
- const callback = function(prev, cur) {
824
- return !isLoaded(shareVersionMap[prev]) && versionLt(prev, cur);
825
- };
826
- const maxVersion = findVersion(shareVersionMap, callback);
827
- return shareVersionMap[maxVersion];
828
- };
829
- var _extraOptions_resolver;
830
- const resolver = (_extraOptions_resolver = extraOptions == null ? void 0 : extraOptions.resolver) != null ? _extraOptions_resolver : defaultResolver;
831
- return Object.assign({}, resolver(shareInfos[pkgName]), extraOptions == null ? void 0 : extraOptions.customShareInfo);
832
- }
833
805
 
834
- export { isBrowserEnv as A, addUniqueItem as B, setGlobalFederationConstructor as C, DEFAULT_REMOTE_TYPE as D, getGlobalFederationInstance as E, getGlobalFederationConstructor as F, Global as G, setGlobalFederationInstance as H, registerGlobalPlugins as I, nativeGlobal as J, resetFederationGlobalInfo as K, getTargetSnapshotInfoByModuleInfo as L, globalLoading as a, DEFAULT_SCOPE as b, getRemoteEntryExports as c, assert as d, getFMId as e, error as f, getGlobalHostPlugins as g, isPlainObject as h, isObject as i, isRemoteInfoWithEntry as j, isPureRemoteEntry as k, getInfoWithoutType as l, getPreloaded as m, setPreloaded as n, getRegisteredShare as o, arrayOptions as p, getGlobalSnapshotInfoByModuleInfo as q, addGlobalSnapshot as r, safeToString as s, setGlobalSnapshotInfoByModuleInfo as t, getGlobalSnapshot as u, getGlobalShareScope as v, warn as w, getTargetSharedOptions as x, formatShareConfigs as y, getBuilderId as z };
806
+ export { setGlobalFederationConstructor as A, getGlobalFederationInstance as B, getGlobalFederationConstructor as C, DEFAULT_REMOTE_TYPE as D, setGlobalFederationInstance as E, registerGlobalPlugins as F, Global as G, nativeGlobal as H, resetFederationGlobalInfo as I, getTargetSnapshotInfoByModuleInfo as J, globalLoading as a, DEFAULT_SCOPE as b, getRemoteEntryExports as c, assert as d, getFMId as e, error as f, getGlobalHostPlugins as g, isPlainObject as h, isObject as i, isRemoteInfoWithEntry as j, isPureRemoteEntry as k, getRegisteredShare as l, getInfoWithoutType as m, getPreloaded as n, setPreloaded as o, getGlobalSnapshotInfoByModuleInfo as p, addGlobalSnapshot as q, setGlobalSnapshotInfoByModuleInfo as r, safeToString as s, getGlobalSnapshot as t, getGlobalShareScope as u, formatShareConfigs as v, warn as w, getBuilderId as x, isBrowserEnv as y, addUniqueItem as z };
@@ -136,14 +136,8 @@ export declare class FederationHost {
136
136
  constructor(userOptions: UserOptions);
137
137
  private _setGlobalShareScopeMap;
138
138
  initOptions(userOptions: UserOptions): Options;
139
- loadShare<T>(pkgName: string, extraOptions?: {
140
- customShareInfo?: Partial<Shared>;
141
- resolver?: (sharedOptions: ShareInfos[string]) => Shared;
142
- }): Promise<false | (() => T | undefined)>;
143
- loadShareSync<T>(pkgName: string, extraOptions?: {
144
- customShareInfo?: Partial<Shared>;
145
- resolver?: (sharedOptions: ShareInfos[string]) => Shared;
146
- }): () => T | never;
139
+ loadShare<T>(pkgName: string, customShareInfo?: Partial<Shared>): Promise<false | (() => T | undefined)>;
140
+ loadShareSync<T>(pkgName: string, customShareInfo?: Partial<Shared>): () => T | never;
147
141
  initRawContainer(name: string, url: string, container: RemoteEntryExports): Module;
148
142
  private _getRemoteModuleAndOptions;
149
143
  loadRemote<T>(id: string, options?: {
@@ -15,10 +15,6 @@ export type RemoteInfoOptionalVersion = {
15
15
  version?: string;
16
16
  } & RemoteInfoCommon;
17
17
  export type Remote = (RemoteWithEntry | RemoteWithVersion) & RemoteInfoCommon;
18
- export type LoadShareExtraOptions = {
19
- customShareInfo?: Partial<Shared>;
20
- resolver?: (sharedOptions: ShareInfos[string]) => Shared;
21
- };
22
18
  export interface RemoteInfo {
23
19
  name: string;
24
20
  version?: string;
@@ -73,7 +69,7 @@ export type GlobalShareScopeMap = {
73
69
  [instanceName: string]: ShareScopeMap;
74
70
  };
75
71
  export type ShareInfos = {
76
- [pkgName: string]: Shared[];
72
+ [pkgName: string]: Shared;
77
73
  };
78
74
  export interface Options {
79
75
  id?: string;
@@ -86,7 +82,7 @@ export interface Options {
86
82
  }
87
83
  export type UserOptions = Omit<Optional<Options, 'plugins'>, 'shared' | 'inBrowser'> & {
88
84
  shared?: {
89
- [pkgName: string]: ShareArgs | ShareArgs[];
85
+ [pkgName: string]: ShareArgs;
90
86
  };
91
87
  };
92
88
  export type LoadModuleOptions = {
@@ -1,12 +1,11 @@
1
1
  import { Federation } from '../global';
2
- import { GlobalShareScopeMap, Shared, ShareArgs, ShareInfos, ShareScopeMap, LoadShareExtraOptions, UserOptions } from '../type';
2
+ import { GlobalShareScopeMap, Shared, ShareArgs, ShareInfos, ShareScopeMap } from '../type';
3
3
  import { SyncWaterfallHook } from './hooks';
4
4
  export declare function formatShare(shareArgs: ShareArgs, from: string): Shared;
5
- export declare function formatShareConfigs(shareArgs: UserOptions['shared'], from: string): ShareInfos;
6
- export declare function versionLt(a: string, b: string): boolean;
7
- export declare const findVersion: (shareVersionMap: ShareScopeMap[string][string], cb?: ((prev: string, cur: string) => boolean) | undefined) => string;
8
- export declare const isLoaded: (shared: Shared) => boolean;
9
- export declare function getRegisteredShare(localShareScopeMap: ShareScopeMap, pkgName: string, shareInfo: Shared, resolveShare: SyncWaterfallHook<{
5
+ export declare function formatShareConfigs(shareArgs: {
6
+ [pkgName: string]: ShareArgs;
7
+ }, from: string): ShareInfos;
8
+ export declare function getRegisteredShare(localShareScopeMap: ShareScopeMap, pkgName: string, shareInfo: ShareInfos[keyof ShareInfos], resolveShare: SyncWaterfallHook<{
10
9
  shareScopeMap: ShareScopeMap;
11
10
  scope: string;
12
11
  pkgName: string;
@@ -15,8 +14,3 @@ export declare function getRegisteredShare(localShareScopeMap: ShareScopeMap, pk
15
14
  resolver: () => Shared | undefined;
16
15
  }>): Shared | void;
17
16
  export declare function getGlobalShareScope(): GlobalShareScopeMap;
18
- export declare function getTargetSharedOptions(options: {
19
- pkgName: string;
20
- extraOptions?: LoadShareExtraOptions;
21
- shareInfos: ShareInfos;
22
- }): Shared & Partial<Shared>;
@@ -10,4 +10,3 @@ export declare function isObject(val: any): boolean;
10
10
  export declare const objectToString: () => string;
11
11
  export declare function isPlainObject(val: any): val is object;
12
12
  export declare function isStaticResourcesEqual(url1: string, url2: string): boolean;
13
- export declare function arrayOptions<T>(options: T | Array<T>): Array<T>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/runtime",
3
- "version": "0.0.0-next-20240411125344",
3
+ "version": "0.0.0-next-20240412103714",
4
4
  "author": "zhouxiao <codingzx@gmail.com>",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.esm.js",
@@ -15,19 +15,19 @@
15
15
  ],
16
16
  "exports": {
17
17
  ".": {
18
+ "types": "./dist/index.cjs.d.ts",
18
19
  "import": "./dist/index.esm.js",
19
- "require": "./dist/index.cjs.js",
20
- "types": "./dist/index.cjs.d.ts"
20
+ "require": "./dist/index.cjs.js"
21
21
  },
22
22
  "./helpers": {
23
+ "types": "./dist/helpers.cjs.d.ts",
23
24
  "import": "./dist/helpers.esm.js",
24
- "require": "./dist/helpers.cjs.js",
25
- "types": "./dist/helpers.cjs.d.ts"
25
+ "require": "./dist/helpers.cjs.js"
26
26
  },
27
27
  "./types": {
28
+ "types": "./dist/types.cjs.d.ts",
28
29
  "import": "./dist/types.esm.js",
29
- "require": "./dist/types.cjs.js",
30
- "types": "./dist/types.cjs.d.ts"
30
+ "require": "./dist/types.cjs.js"
31
31
  },
32
32
  "./*": "./*"
33
33
  },
@@ -45,6 +45,6 @@
45
45
  }
46
46
  },
47
47
  "dependencies": {
48
- "@module-federation/sdk": "0.0.0-next-20240411125344"
48
+ "@module-federation/sdk": "0.0.0-next-20240412103714"
49
49
  }
50
50
  }