@module-federation/runtime-core 0.0.0-next-20250323051630 → 0.0.0-next-20250324033412

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 CHANGED
@@ -196,7 +196,7 @@ function getGlobalFederationConstructor() {
196
196
  function setGlobalFederationConstructor(FederationConstructor, isDebug = sdk.isDebugMode()) {
197
197
  if (isDebug) {
198
198
  CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
199
- CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.10.0";
199
+ CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.11.1";
200
200
  }
201
201
  }
202
202
  // eslint-disable-next-line @typescript-eslint/ban-types
@@ -1227,23 +1227,14 @@ let Module = class Module {
1227
1227
  const remoteEntryExports = await this.getEntry();
1228
1228
  if (!this.inited) {
1229
1229
  const localShareScopeMap = this.host.shareScopeMap;
1230
- const shareScopeKeys = Array.isArray(this.remoteInfo.shareScope) ? this.remoteInfo.shareScope : [
1231
- this.remoteInfo.shareScope
1232
- ];
1233
- if (!shareScopeKeys.length) {
1234
- shareScopeKeys.push('default');
1230
+ const remoteShareScope = this.remoteInfo.shareScope || 'default';
1231
+ if (!localShareScopeMap[remoteShareScope]) {
1232
+ localShareScopeMap[remoteShareScope] = {};
1235
1233
  }
1236
- shareScopeKeys.forEach((shareScopeKey)=>{
1237
- if (!localShareScopeMap[shareScopeKey]) {
1238
- localShareScopeMap[shareScopeKey] = {};
1239
- }
1240
- });
1241
- // TODO: compate legacy init params, should use shareScopeMap if exist
1242
- const shareScope = localShareScopeMap[shareScopeKeys[0]];
1234
+ const shareScope = localShareScopeMap[remoteShareScope];
1243
1235
  const initScope = [];
1244
1236
  const remoteEntryInitOptions = {
1245
- version: this.remoteInfo.version || '',
1246
- shareScopeKeys: Array.isArray(this.remoteInfo.shareScope) ? shareScopeKeys : this.remoteInfo.shareScope || 'default'
1237
+ version: this.remoteInfo.version || ''
1247
1238
  };
1248
1239
  // Help to find host instance
1249
1240
  Object.defineProperty(remoteEntryInitOptions, 'shareScopeMap', {
@@ -1777,6 +1768,9 @@ function traverseModuleInfo(globalSnapshot, remoteInfo, traverse, isRoot, memo =
1777
1768
  }
1778
1769
  }
1779
1770
  }
1771
+ const isExisted = (type, url)=>{
1772
+ return document.querySelector(`${type}[${type === 'link' ? 'href' : 'src'}="${url}"]`);
1773
+ };
1780
1774
  // eslint-disable-next-line max-lines-per-function
1781
1775
  function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, remoteSnapshot) {
1782
1776
  const cssAssets = [];
@@ -1905,12 +1899,12 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
1905
1899
  });
1906
1900
  });
1907
1901
  }
1908
- const needPreloadJsAssets = jsAssets.filter((asset)=>!loadedSharedJsAssets.has(asset));
1909
- const needPreloadCssAssets = cssAssets.filter((asset)=>!loadedSharedCssAssets.has(asset));
1902
+ const needPreloadJsAssets = jsAssets.filter((asset)=>!loadedSharedJsAssets.has(asset) && !isExisted('script', asset));
1903
+ const needPreloadCssAssets = cssAssets.filter((asset)=>!loadedSharedCssAssets.has(asset) && !isExisted('link', asset));
1910
1904
  return {
1911
1905
  cssAssets: needPreloadCssAssets,
1912
1906
  jsAssetsWithoutEntry: needPreloadJsAssets,
1913
- entryAssets
1907
+ entryAssets: entryAssets.filter((entry)=>!isExisted('script', entry.url))
1914
1908
  };
1915
1909
  }
1916
1910
  const generatePreloadAssetsPlugin = function() {
@@ -1918,6 +1912,13 @@ const generatePreloadAssetsPlugin = function() {
1918
1912
  name: 'generate-preload-assets-plugin',
1919
1913
  async generatePreloadAssets (args) {
1920
1914
  const { origin, preloadOptions, remoteInfo, remote, globalSnapshot, remoteSnapshot } = args;
1915
+ if (!sdk.isBrowserEnv()) {
1916
+ return {
1917
+ cssAssets: [],
1918
+ jsAssetsWithoutEntry: [],
1919
+ entryAssets: []
1920
+ };
1921
+ }
1921
1922
  if (isRemoteInfoWithEntry(remote) && isPureRemoteEntry(remote)) {
1922
1923
  return {
1923
1924
  cssAssets: [],
@@ -2970,7 +2971,7 @@ class FederationHost {
2970
2971
  // maybe will change, temporarily for internal use only
2971
2972
  initContainer: new AsyncWaterfallHook('initContainer')
2972
2973
  });
2973
- this.version = "0.10.0";
2974
+ this.version = "0.11.1";
2974
2975
  this.moduleCache = new Map();
2975
2976
  this.loaderHook = new PluginSystem({
2976
2977
  // FIXME: may not be suitable , not open to the public yet
@@ -195,7 +195,7 @@ function getGlobalFederationConstructor() {
195
195
  function setGlobalFederationConstructor(FederationConstructor, isDebug = isDebugMode()) {
196
196
  if (isDebug) {
197
197
  CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
198
- CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.10.0";
198
+ CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.11.1";
199
199
  }
200
200
  }
201
201
  // eslint-disable-next-line @typescript-eslint/ban-types
@@ -1226,23 +1226,14 @@ let Module = class Module {
1226
1226
  const remoteEntryExports = await this.getEntry();
1227
1227
  if (!this.inited) {
1228
1228
  const localShareScopeMap = this.host.shareScopeMap;
1229
- const shareScopeKeys = Array.isArray(this.remoteInfo.shareScope) ? this.remoteInfo.shareScope : [
1230
- this.remoteInfo.shareScope
1231
- ];
1232
- if (!shareScopeKeys.length) {
1233
- shareScopeKeys.push('default');
1229
+ const remoteShareScope = this.remoteInfo.shareScope || 'default';
1230
+ if (!localShareScopeMap[remoteShareScope]) {
1231
+ localShareScopeMap[remoteShareScope] = {};
1234
1232
  }
1235
- shareScopeKeys.forEach((shareScopeKey)=>{
1236
- if (!localShareScopeMap[shareScopeKey]) {
1237
- localShareScopeMap[shareScopeKey] = {};
1238
- }
1239
- });
1240
- // TODO: compate legacy init params, should use shareScopeMap if exist
1241
- const shareScope = localShareScopeMap[shareScopeKeys[0]];
1233
+ const shareScope = localShareScopeMap[remoteShareScope];
1242
1234
  const initScope = [];
1243
1235
  const remoteEntryInitOptions = {
1244
- version: this.remoteInfo.version || '',
1245
- shareScopeKeys: Array.isArray(this.remoteInfo.shareScope) ? shareScopeKeys : this.remoteInfo.shareScope || 'default'
1236
+ version: this.remoteInfo.version || ''
1246
1237
  };
1247
1238
  // Help to find host instance
1248
1239
  Object.defineProperty(remoteEntryInitOptions, 'shareScopeMap', {
@@ -1776,6 +1767,9 @@ function traverseModuleInfo(globalSnapshot, remoteInfo, traverse, isRoot, memo =
1776
1767
  }
1777
1768
  }
1778
1769
  }
1770
+ const isExisted = (type, url)=>{
1771
+ return document.querySelector(`${type}[${type === 'link' ? 'href' : 'src'}="${url}"]`);
1772
+ };
1779
1773
  // eslint-disable-next-line max-lines-per-function
1780
1774
  function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, remoteSnapshot) {
1781
1775
  const cssAssets = [];
@@ -1904,12 +1898,12 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
1904
1898
  });
1905
1899
  });
1906
1900
  }
1907
- const needPreloadJsAssets = jsAssets.filter((asset)=>!loadedSharedJsAssets.has(asset));
1908
- const needPreloadCssAssets = cssAssets.filter((asset)=>!loadedSharedCssAssets.has(asset));
1901
+ const needPreloadJsAssets = jsAssets.filter((asset)=>!loadedSharedJsAssets.has(asset) && !isExisted('script', asset));
1902
+ const needPreloadCssAssets = cssAssets.filter((asset)=>!loadedSharedCssAssets.has(asset) && !isExisted('link', asset));
1909
1903
  return {
1910
1904
  cssAssets: needPreloadCssAssets,
1911
1905
  jsAssetsWithoutEntry: needPreloadJsAssets,
1912
- entryAssets
1906
+ entryAssets: entryAssets.filter((entry)=>!isExisted('script', entry.url))
1913
1907
  };
1914
1908
  }
1915
1909
  const generatePreloadAssetsPlugin = function() {
@@ -1917,6 +1911,13 @@ const generatePreloadAssetsPlugin = function() {
1917
1911
  name: 'generate-preload-assets-plugin',
1918
1912
  async generatePreloadAssets (args) {
1919
1913
  const { origin, preloadOptions, remoteInfo, remote, globalSnapshot, remoteSnapshot } = args;
1914
+ if (!isBrowserEnv()) {
1915
+ return {
1916
+ cssAssets: [],
1917
+ jsAssetsWithoutEntry: [],
1918
+ entryAssets: []
1919
+ };
1920
+ }
1920
1921
  if (isRemoteInfoWithEntry(remote) && isPureRemoteEntry(remote)) {
1921
1922
  return {
1922
1923
  cssAssets: [],
@@ -2969,7 +2970,7 @@ class FederationHost {
2969
2970
  // maybe will change, temporarily for internal use only
2970
2971
  initContainer: new AsyncWaterfallHook('initContainer')
2971
2972
  });
2972
- this.version = "0.10.0";
2973
+ this.version = "0.11.1";
2973
2974
  this.moduleCache = new Map();
2974
2975
  this.loaderHook = new PluginSystem({
2975
2976
  // FIXME: may not be suitable , not open to the public yet
@@ -6,7 +6,7 @@ export type PartialOptional<T, K extends keyof T> = Omit<T, K> & {
6
6
  };
7
7
  export interface RemoteInfoCommon {
8
8
  alias?: string;
9
- shareScope?: string | string[];
9
+ shareScope?: string;
10
10
  type?: RemoteEntryType;
11
11
  entryGlobalName?: string;
12
12
  }
@@ -26,7 +26,7 @@ export interface RemoteInfo {
26
26
  entry: string;
27
27
  type: RemoteEntryType;
28
28
  entryGlobalName: string;
29
- shareScope: string | string[];
29
+ shareScope: string;
30
30
  }
31
31
  export type HostInfo = Pick<Options, 'name' | 'version' | 'remotes' | 'version'>;
32
32
  export interface SharedConfig {
@@ -34,7 +34,6 @@ export interface SharedConfig {
34
34
  requiredVersion: false | string;
35
35
  eager?: boolean;
36
36
  strictVersion?: boolean;
37
- layer?: string | null;
38
37
  }
39
38
  type SharedBaseArgs = {
40
39
  version?: string;
@@ -101,8 +100,7 @@ export type LoadModuleOptions = {
101
100
  };
102
101
  export type RemoteEntryInitOptions = {
103
102
  version: string;
104
- shareScopeMap?: ShareScopeMap;
105
- shareScopeKeys: string | string[];
103
+ shareScopeMap: ShareScopeMap;
106
104
  };
107
105
  export type InitTokens = Record<string, Record<string, any>>;
108
106
  export type InitScope = InitTokens[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/runtime-core",
3
- "version": "0.0.0-next-20250323051630",
3
+ "version": "0.0.0-next-20250324033412",
4
4
  "author": "zhouxiao <codingzx@gmail.com>",
5
5
  "main": "./dist/index.cjs.js",
6
6
  "module": "./dist/index.esm.mjs",
@@ -36,7 +36,7 @@
36
36
  }
37
37
  },
38
38
  "dependencies": {
39
- "@module-federation/sdk": "0.0.0-next-20250323051630",
40
- "@module-federation/error-codes": "0.0.0-next-20250323051630"
39
+ "@module-federation/sdk": "0.0.0-next-20250324033412",
40
+ "@module-federation/error-codes": "0.0.0-next-20250324033412"
41
41
  }
42
42
  }