@module-federation/runtime-core 0.9.1 → 0.11.0

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.9.1";
199
+ CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.11.0";
200
200
  }
201
201
  }
202
202
  // eslint-disable-next-line @typescript-eslint/ban-types
@@ -1768,6 +1768,9 @@ function traverseModuleInfo(globalSnapshot, remoteInfo, traverse, isRoot, memo =
1768
1768
  }
1769
1769
  }
1770
1770
  }
1771
+ const isExisted = (type, url)=>{
1772
+ return document.querySelector(`${type}[${type === 'link' ? 'href' : 'src'}="${url}"]`);
1773
+ };
1771
1774
  // eslint-disable-next-line max-lines-per-function
1772
1775
  function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, remoteSnapshot) {
1773
1776
  const cssAssets = [];
@@ -1896,12 +1899,12 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
1896
1899
  });
1897
1900
  });
1898
1901
  }
1899
- const needPreloadJsAssets = jsAssets.filter((asset)=>!loadedSharedJsAssets.has(asset));
1900
- 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));
1901
1904
  return {
1902
1905
  cssAssets: needPreloadCssAssets,
1903
1906
  jsAssetsWithoutEntry: needPreloadJsAssets,
1904
- entryAssets
1907
+ entryAssets: entryAssets.filter((entry)=>!isExisted('script', entry.url))
1905
1908
  };
1906
1909
  }
1907
1910
  const generatePreloadAssetsPlugin = function() {
@@ -1909,6 +1912,13 @@ const generatePreloadAssetsPlugin = function() {
1909
1912
  name: 'generate-preload-assets-plugin',
1910
1913
  async generatePreloadAssets (args) {
1911
1914
  const { origin, preloadOptions, remoteInfo, remote, globalSnapshot, remoteSnapshot } = args;
1915
+ if (!sdk.isBrowserEnv()) {
1916
+ return {
1917
+ cssAssets: [],
1918
+ jsAssetsWithoutEntry: [],
1919
+ entryAssets: []
1920
+ };
1921
+ }
1912
1922
  if (isRemoteInfoWithEntry(remote) && isPureRemoteEntry(remote)) {
1913
1923
  return {
1914
1924
  cssAssets: [],
@@ -2092,7 +2102,7 @@ class SnapshotHandler {
2092
2102
  } catch (err) {
2093
2103
  manifestJson = await this.HostInstance.remoteHandler.hooks.lifecycle.errorLoadRemote.emit({
2094
2104
  id: manifestUrl,
2095
- error,
2105
+ error: err,
2096
2106
  from: 'runtime',
2097
2107
  lifecycle: 'afterResolve',
2098
2108
  origin: this.HostInstance
@@ -2961,7 +2971,7 @@ class FederationHost {
2961
2971
  // maybe will change, temporarily for internal use only
2962
2972
  initContainer: new AsyncWaterfallHook('initContainer')
2963
2973
  });
2964
- this.version = "0.9.1";
2974
+ this.version = "0.11.0";
2965
2975
  this.moduleCache = new Map();
2966
2976
  this.loaderHook = new PluginSystem({
2967
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.9.1";
198
+ CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.11.0";
199
199
  }
200
200
  }
201
201
  // eslint-disable-next-line @typescript-eslint/ban-types
@@ -1767,6 +1767,9 @@ function traverseModuleInfo(globalSnapshot, remoteInfo, traverse, isRoot, memo =
1767
1767
  }
1768
1768
  }
1769
1769
  }
1770
+ const isExisted = (type, url)=>{
1771
+ return document.querySelector(`${type}[${type === 'link' ? 'href' : 'src'}="${url}"]`);
1772
+ };
1770
1773
  // eslint-disable-next-line max-lines-per-function
1771
1774
  function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, remoteSnapshot) {
1772
1775
  const cssAssets = [];
@@ -1895,12 +1898,12 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
1895
1898
  });
1896
1899
  });
1897
1900
  }
1898
- const needPreloadJsAssets = jsAssets.filter((asset)=>!loadedSharedJsAssets.has(asset));
1899
- 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));
1900
1903
  return {
1901
1904
  cssAssets: needPreloadCssAssets,
1902
1905
  jsAssetsWithoutEntry: needPreloadJsAssets,
1903
- entryAssets
1906
+ entryAssets: entryAssets.filter((entry)=>!isExisted('script', entry.url))
1904
1907
  };
1905
1908
  }
1906
1909
  const generatePreloadAssetsPlugin = function() {
@@ -1908,6 +1911,13 @@ const generatePreloadAssetsPlugin = function() {
1908
1911
  name: 'generate-preload-assets-plugin',
1909
1912
  async generatePreloadAssets (args) {
1910
1913
  const { origin, preloadOptions, remoteInfo, remote, globalSnapshot, remoteSnapshot } = args;
1914
+ if (!isBrowserEnv()) {
1915
+ return {
1916
+ cssAssets: [],
1917
+ jsAssetsWithoutEntry: [],
1918
+ entryAssets: []
1919
+ };
1920
+ }
1911
1921
  if (isRemoteInfoWithEntry(remote) && isPureRemoteEntry(remote)) {
1912
1922
  return {
1913
1923
  cssAssets: [],
@@ -2091,7 +2101,7 @@ class SnapshotHandler {
2091
2101
  } catch (err) {
2092
2102
  manifestJson = await this.HostInstance.remoteHandler.hooks.lifecycle.errorLoadRemote.emit({
2093
2103
  id: manifestUrl,
2094
- error,
2104
+ error: err,
2095
2105
  from: 'runtime',
2096
2106
  lifecycle: 'afterResolve',
2097
2107
  origin: this.HostInstance
@@ -2960,7 +2970,7 @@ class FederationHost {
2960
2970
  // maybe will change, temporarily for internal use only
2961
2971
  initContainer: new AsyncWaterfallHook('initContainer')
2962
2972
  });
2963
- this.version = "0.9.1";
2973
+ this.version = "0.11.0";
2964
2974
  this.moduleCache = new Map();
2965
2975
  this.loaderHook = new PluginSystem({
2966
2976
  // FIXME: may not be suitable , not open to the public yet
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/runtime-core",
3
- "version": "0.9.1",
3
+ "version": "0.11.0",
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.9.1",
40
- "@module-federation/error-codes": "0.9.1"
39
+ "@module-federation/sdk": "0.11.0",
40
+ "@module-federation/error-codes": "0.11.0"
41
41
  }
42
42
  }