@module-federation/runtime 1.0.0-canary.4 → 1.0.1-canary.1

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/package.json CHANGED
@@ -1,17 +1,18 @@
1
1
  {
2
2
  "name": "@module-federation/runtime",
3
- "version": "1.0.0-canary.4",
3
+ "version": "1.0.1-canary.1",
4
4
  "author": "zhouxiao <codingzx@gmail.com>",
5
5
  "main": "./index.cjs.js",
6
6
  "module": "./index.esm.js",
7
7
  "types": "./index.cjs.d.ts",
8
+ "license": "MIT",
8
9
  "publishConfig": {
9
10
  "access": "public"
10
11
  },
11
12
  "exports": {
12
13
  ".": {
13
- "import": "./index.cjs.js",
14
- "require": "./index.esm.js"
14
+ "import": "./index.esm.js",
15
+ "require": "./index.cjs.js"
15
16
  },
16
17
  "./helpers": {
17
18
  "import": "./helpers.esm.js",
@@ -33,7 +34,7 @@
33
34
  }
34
35
  },
35
36
  "dependencies": {
36
- "@module-federation/sdk": "1.0.0-canary.3"
37
+ "@module-federation/sdk": "1.1.0-canary.1"
37
38
  },
38
39
  "peerDependencies": {}
39
40
  }
package/share.cjs.js CHANGED
@@ -1,29 +1,5 @@
1
1
  'use strict';
2
2
 
3
- function _extends() {
4
- _extends = Object.assign || function assign(target) {
5
- for(var i = 1; i < arguments.length; i++){
6
- var source = arguments[i];
7
- for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
8
- }
9
- return target;
10
- };
11
- return _extends.apply(this, arguments);
12
- }
13
-
14
- function _object_without_properties_loose(source, excluded) {
15
- if (source == null) return {};
16
- var target = {};
17
- var sourceKeys = Object.keys(source);
18
- var key, i;
19
- for(i = 0; i < sourceKeys.length; i++){
20
- key = sourceKeys[i];
21
- if (excluded.indexOf(key) >= 0) continue;
22
- target[key] = source[key];
23
- }
24
- return target;
25
- }
26
-
27
3
  function getBuilderId() {
28
4
  return typeof FEDERATION_BUILD_IDENTIFIER !== 'undefined' ? FEDERATION_BUILD_IDENTIFIER : '';
29
5
  }
@@ -69,16 +45,6 @@ function isRemoteInfoWithEntry(remote) {
69
45
  function isPureRemoteEntry(remote) {
70
46
  return remote.entry.endsWith('.js');
71
47
  }
72
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
73
- async function safeWrapper(callback, disableWarn) {
74
- try {
75
- const res = await callback();
76
- return res;
77
- } catch (e) {
78
- !disableWarn && warn(e);
79
- return;
80
- }
81
- }
82
48
  // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
83
49
  function safeToString(info) {
84
50
  try {
@@ -95,15 +61,33 @@ const objectToString = Object.prototype.toString;
95
61
  function isPlainObject(val) {
96
62
  return objectToString.call(val) === '[object Object]';
97
63
  }
98
- function isStaticResourcesEqual(url1, url2) {
99
- const REG_EXP = /^(https?:)?\/\//i;
100
- // Transform url1 and url2 into relative paths
101
- const relativeUrl1 = url1.replace(REG_EXP, '').replace(/\/$/, '');
102
- const relativeUrl2 = url2.replace(REG_EXP, '').replace(/\/$/, '');
103
- // Check if the relative paths are identical
104
- return relativeUrl1 === relativeUrl2;
105
- }
106
64
 
65
+ function _extends$1() {
66
+ _extends$1 = Object.assign || function(target) {
67
+ for(var i = 1; i < arguments.length; i++){
68
+ var source = arguments[i];
69
+ for(var key in source){
70
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
71
+ target[key] = source[key];
72
+ }
73
+ }
74
+ }
75
+ return target;
76
+ };
77
+ return _extends$1.apply(this, arguments);
78
+ }
79
+ function _object_without_properties_loose(source, excluded) {
80
+ if (source == null) return {};
81
+ var target = {};
82
+ var sourceKeys = Object.keys(source);
83
+ var key, i;
84
+ for(i = 0; i < sourceKeys.length; i++){
85
+ key = sourceKeys[i];
86
+ if (excluded.indexOf(key) >= 0) continue;
87
+ target[key] = source[key];
88
+ }
89
+ return target;
90
+ }
107
91
  var _nativeGlobal___FEDERATION__, _nativeGlobal___FEDERATION__1, _nativeGlobal___FEDERATION__2, _nativeGlobal___FEDERATION__3, _nativeGlobal___FEDERATION__4, _nativeGlobal___FEDERATION__5, _nativeGlobal___FEDERATION__6;
108
92
  // export const nativeGlobal: typeof global = new Function('return this')();
109
93
  const nativeGlobal = new Function('return this')();
@@ -184,7 +168,7 @@ function getGlobalFederationConstructor() {
184
168
  function setGlobalFederationConstructor(FederationConstructor) {
185
169
  if (isDebugMode()) {
186
170
  Global.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
187
- Global.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = '1.0.0-canary.3';
171
+ Global.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = '1.0.0-canary.1';
188
172
  }
189
173
  }
190
174
  // eslint-disable-next-line @typescript-eslint/ban-types
@@ -231,7 +215,7 @@ const setGlobalSnapshotInfoByModuleInfo = (remoteInfo, moduleDetailInfo)=>{
231
215
  return Global.__FEDERATION__.moduleInfo;
232
216
  };
233
217
  const addGlobalSnapshot = (moduleInfos)=>{
234
- Global.__FEDERATION__.moduleInfo = _extends({}, Global.__FEDERATION__.moduleInfo, moduleInfos);
218
+ Global.__FEDERATION__.moduleInfo = _extends$1({}, Global.__FEDERATION__.moduleInfo, moduleInfos);
235
219
  return ()=>{
236
220
  const keys = Object.keys(moduleInfos);
237
221
  for (const key of keys){
@@ -606,6 +590,20 @@ function satisfy(version, range) {
606
590
  return true;
607
591
  }
608
592
 
593
+ function _extends() {
594
+ _extends = Object.assign || function(target) {
595
+ for(var i = 1; i < arguments.length; i++){
596
+ var source = arguments[i];
597
+ for(var key in source){
598
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
599
+ target[key] = source[key];
600
+ }
601
+ }
602
+ }
603
+ return target;
604
+ };
605
+ return _extends.apply(this, arguments);
606
+ }
609
607
  function formatShare(shareArgs, from) {
610
608
  let get;
611
609
  if ('get' in shareArgs) {
@@ -738,8 +736,6 @@ function getGlobalShareScope() {
738
736
  exports.DEFAULT_REMOTE_TYPE = DEFAULT_REMOTE_TYPE;
739
737
  exports.DEFAULT_SCOPE = DEFAULT_SCOPE;
740
738
  exports.Global = Global;
741
- exports._extends = _extends;
742
- exports._object_without_properties_loose = _object_without_properties_loose;
743
739
  exports.addGlobalSnapshot = addGlobalSnapshot;
744
740
  exports.addUniqueItem = addUniqueItem;
745
741
  exports.assert = assert;
@@ -764,12 +760,10 @@ exports.isObject = isObject;
764
760
  exports.isPlainObject = isPlainObject;
765
761
  exports.isPureRemoteEntry = isPureRemoteEntry;
766
762
  exports.isRemoteInfoWithEntry = isRemoteInfoWithEntry;
767
- exports.isStaticResourcesEqual = isStaticResourcesEqual;
768
763
  exports.nativeGlobal = nativeGlobal;
769
764
  exports.registerGlobalPlugins = registerGlobalPlugins;
770
765
  exports.resetFederationGlobalInfo = resetFederationGlobalInfo;
771
766
  exports.safeToString = safeToString;
772
- exports.safeWrapper = safeWrapper;
773
767
  exports.setGlobalFederationConstructor = setGlobalFederationConstructor;
774
768
  exports.setGlobalFederationInstance = setGlobalFederationInstance;
775
769
  exports.setGlobalSnapshotInfoByModuleInfo = setGlobalSnapshotInfoByModuleInfo;
package/share.esm.js CHANGED
@@ -1,27 +1,3 @@
1
- function _extends() {
2
- _extends = Object.assign || function assign(target) {
3
- for(var i = 1; i < arguments.length; i++){
4
- var source = arguments[i];
5
- for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
6
- }
7
- return target;
8
- };
9
- return _extends.apply(this, arguments);
10
- }
11
-
12
- function _object_without_properties_loose(source, excluded) {
13
- if (source == null) return {};
14
- var target = {};
15
- var sourceKeys = Object.keys(source);
16
- var key, i;
17
- for(i = 0; i < sourceKeys.length; i++){
18
- key = sourceKeys[i];
19
- if (excluded.indexOf(key) >= 0) continue;
20
- target[key] = source[key];
21
- }
22
- return target;
23
- }
24
-
25
1
  function getBuilderId() {
26
2
  return typeof FEDERATION_BUILD_IDENTIFIER !== 'undefined' ? FEDERATION_BUILD_IDENTIFIER : '';
27
3
  }
@@ -67,16 +43,6 @@ function isRemoteInfoWithEntry(remote) {
67
43
  function isPureRemoteEntry(remote) {
68
44
  return remote.entry.endsWith('.js');
69
45
  }
70
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
71
- async function safeWrapper(callback, disableWarn) {
72
- try {
73
- const res = await callback();
74
- return res;
75
- } catch (e) {
76
- !disableWarn && warn(e);
77
- return;
78
- }
79
- }
80
46
  // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
81
47
  function safeToString(info) {
82
48
  try {
@@ -93,15 +59,33 @@ const objectToString = Object.prototype.toString;
93
59
  function isPlainObject(val) {
94
60
  return objectToString.call(val) === '[object Object]';
95
61
  }
96
- function isStaticResourcesEqual(url1, url2) {
97
- const REG_EXP = /^(https?:)?\/\//i;
98
- // Transform url1 and url2 into relative paths
99
- const relativeUrl1 = url1.replace(REG_EXP, '').replace(/\/$/, '');
100
- const relativeUrl2 = url2.replace(REG_EXP, '').replace(/\/$/, '');
101
- // Check if the relative paths are identical
102
- return relativeUrl1 === relativeUrl2;
103
- }
104
62
 
63
+ function _extends$1() {
64
+ _extends$1 = Object.assign || function(target) {
65
+ for(var i = 1; i < arguments.length; i++){
66
+ var source = arguments[i];
67
+ for(var key in source){
68
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
69
+ target[key] = source[key];
70
+ }
71
+ }
72
+ }
73
+ return target;
74
+ };
75
+ return _extends$1.apply(this, arguments);
76
+ }
77
+ function _object_without_properties_loose(source, excluded) {
78
+ if (source == null) return {};
79
+ var target = {};
80
+ var sourceKeys = Object.keys(source);
81
+ var key, i;
82
+ for(i = 0; i < sourceKeys.length; i++){
83
+ key = sourceKeys[i];
84
+ if (excluded.indexOf(key) >= 0) continue;
85
+ target[key] = source[key];
86
+ }
87
+ return target;
88
+ }
105
89
  var _nativeGlobal___FEDERATION__, _nativeGlobal___FEDERATION__1, _nativeGlobal___FEDERATION__2, _nativeGlobal___FEDERATION__3, _nativeGlobal___FEDERATION__4, _nativeGlobal___FEDERATION__5, _nativeGlobal___FEDERATION__6;
106
90
  // export const nativeGlobal: typeof global = new Function('return this')();
107
91
  const nativeGlobal = new Function('return this')();
@@ -182,7 +166,7 @@ function getGlobalFederationConstructor() {
182
166
  function setGlobalFederationConstructor(FederationConstructor) {
183
167
  if (isDebugMode()) {
184
168
  Global.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
185
- Global.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = '1.0.0-canary.3';
169
+ Global.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = '1.0.0-canary.1';
186
170
  }
187
171
  }
188
172
  // eslint-disable-next-line @typescript-eslint/ban-types
@@ -229,7 +213,7 @@ const setGlobalSnapshotInfoByModuleInfo = (remoteInfo, moduleDetailInfo)=>{
229
213
  return Global.__FEDERATION__.moduleInfo;
230
214
  };
231
215
  const addGlobalSnapshot = (moduleInfos)=>{
232
- Global.__FEDERATION__.moduleInfo = _extends({}, Global.__FEDERATION__.moduleInfo, moduleInfos);
216
+ Global.__FEDERATION__.moduleInfo = _extends$1({}, Global.__FEDERATION__.moduleInfo, moduleInfos);
233
217
  return ()=>{
234
218
  const keys = Object.keys(moduleInfos);
235
219
  for (const key of keys){
@@ -604,6 +588,20 @@ function satisfy(version, range) {
604
588
  return true;
605
589
  }
606
590
 
591
+ function _extends() {
592
+ _extends = Object.assign || function(target) {
593
+ for(var i = 1; i < arguments.length; i++){
594
+ var source = arguments[i];
595
+ for(var key in source){
596
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
597
+ target[key] = source[key];
598
+ }
599
+ }
600
+ }
601
+ return target;
602
+ };
603
+ return _extends.apply(this, arguments);
604
+ }
607
605
  function formatShare(shareArgs, from) {
608
606
  let get;
609
607
  if ('get' in shareArgs) {
@@ -733,4 +731,4 @@ function getGlobalShareScope() {
733
731
  return Global.__FEDERATION__.__SHARE__;
734
732
  }
735
733
 
736
- export { _object_without_properties_loose as A, getBuilderId 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, addGlobalSnapshot as M, _extends as _, DEFAULT_SCOPE as a, globalLoading as b, getRemoteEntryExports as c, assert as d, safeToString as e, getFMId as f, getGlobalHostPlugins as g, isObject as h, isStaticResourcesEqual as i, error as j, isPlainObject as k, isRemoteInfoWithEntry as l, isPureRemoteEntry as m, getGlobalShare as n, getInfoWithoutType as o, getPreloaded as p, setPreloaded as q, getGlobalSnapshotInfoByModuleInfo as r, safeWrapper as s, setGlobalSnapshotInfoByModuleInfo as t, getGlobalSnapshot as u, addUniqueItem as v, warn as w, formatShareConfigs as x, isBrowserEnv as y, getGlobalShareScope as z };
734
+ export { getGlobalFederationInstance as A, getGlobalFederationConstructor as B, setGlobalFederationInstance as C, DEFAULT_REMOTE_TYPE as D, registerGlobalPlugins as E, nativeGlobal as F, Global as G, resetFederationGlobalInfo as H, getTargetSnapshotInfoByModuleInfo as I, addGlobalSnapshot as J, DEFAULT_SCOPE as a, globalLoading 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, getGlobalShare as l, getInfoWithoutType as m, getPreloaded as n, setPreloaded as o, getGlobalSnapshotInfoByModuleInfo as p, setGlobalSnapshotInfoByModuleInfo as q, getGlobalSnapshot as r, safeToString as s, addUniqueItem as t, formatShareConfigs as u, isBrowserEnv as v, warn as w, getGlobalShareScope as x, getBuilderId as y, setGlobalFederationConstructor as z };
package/src/core.d.ts CHANGED
@@ -11,6 +11,7 @@ interface LoadRemoteMatch {
11
11
  options: Options;
12
12
  origin: FederationHost;
13
13
  remoteInfo: RemoteInfo;
14
+ remoteSnapshot?: ModuleInfo;
14
15
  }
15
16
  export declare class FederationHost {
16
17
  options: Options;
@@ -42,6 +43,12 @@ export declare class FederationHost {
42
43
  exposeModuleFactory: any;
43
44
  moduleInstance: Module;
44
45
  }], void>;
46
+ handlePreloadModule: SyncHook<{
47
+ id: string;
48
+ name: string;
49
+ remoteSnapshot: ModuleInfo;
50
+ preloadConfig: PreloadRemoteArgs;
51
+ }, void>;
45
52
  errorLoadRemote: AsyncHook<[{
46
53
  id: string;
47
54
  error: unknown;
package/src/global.d.ts CHANGED
@@ -3,7 +3,7 @@ import { FederationHost } from './core';
3
3
  import { RemoteEntryExports, GlobalShareScope, Remote, Optional } from './type';
4
4
  import { GlobalModuleInfo, ModuleInfo } from '@module-federation/sdk';
5
5
  import { FederationRuntimePlugin } from './type/plugin';
6
- export type Federation = {
6
+ export interface Federation {
7
7
  __GLOBAL_PLUGIN__: Array<FederationRuntimePlugin>;
8
8
  __DEBUG_CONSTRUCTOR_VERSION__?: string;
9
9
  moduleInfo: GlobalModuleInfo;
@@ -13,7 +13,7 @@ export type Federation = {
13
13
  __MANIFEST_LOADING__: Record<string, Promise<ModuleInfo>>;
14
14
  __SHARE_SCOPE_LOADING__: Record<string, boolean | Promise<boolean>>;
15
15
  __PRELOADED_MAP__: Map<string, boolean>;
16
- };
16
+ }
17
17
  export declare const nativeGlobal: typeof global;
18
18
  declare global {
19
19
  var __FEDERATION__: Federation, __VMOK__: Federation, __GLOBAL_LOADING_REMOTE_ENTRY__: Record<string, undefined | Promise<RemoteEntryExports | void>>;
package/src/index.d.ts CHANGED
@@ -2,7 +2,7 @@ import { FederationHost } from './core';
2
2
  import { UserOptions } from './type';
3
3
  export { FederationHost } from './core';
4
4
  export { registerGlobalPlugins } from './global';
5
- export { loadScript } from './utils';
5
+ export type { Federation } from './global';
6
6
  export declare function init(options: UserOptions): FederationHost;
7
7
  export declare function loadRemote(...args: Parameters<FederationHost['loadRemote']>): ReturnType<FederationHost['loadRemote']>;
8
8
  export declare function loadShare(...args: Parameters<FederationHost['loadShare']>): ReturnType<FederationHost['loadShare']>;
@@ -1,5 +1,5 @@
1
- import { FederationRuntimePlugin } from '../../type/plugin';
2
1
  import { ModuleInfo } from '@module-federation/sdk';
2
+ import { FederationRuntimePlugin } from '../../type/plugin';
3
3
  import { RemoteInfo } from '../../type';
4
4
  export declare function assignRemoteInfo(remoteInfo: RemoteInfo, remoteSnapshot: ModuleInfo): void;
5
5
  export declare function snapshotPlugin(): FederationRuntimePlugin;
@@ -7,6 +7,7 @@ export interface PreloadRemoteArgs {
7
7
  share?: boolean;
8
8
  depsRemote?: boolean | Array<depsPreloadArg>;
9
9
  filter?: (assetUrl: string) => boolean;
10
+ prefetchInterface?: boolean;
10
11
  }
11
12
  export type PreloadConfig = PreloadRemoteArgs;
12
13
  export type PreloadOptions = Array<{
@@ -2,5 +2,4 @@ export * from './env';
2
2
  export * from './tool';
3
3
  export * from './manifest';
4
4
  export * from './logger';
5
- export * from './dom';
6
5
  export * from './plugin';
@@ -1,6 +1,4 @@
1
- import { ModuleInfo } from '@module-federation/sdk';
2
1
  import { Remote } from '../type';
3
- export declare function getResourceUrl(module: ModuleInfo, sourceUrl: string): string;
4
2
  export declare function matchRemoteWithNameAndExpose(remotes: Array<Remote>, id: string): {
5
3
  pkgNameOrAlias: string;
6
4
  expose: string;
@@ -1,8 +0,0 @@
1
- export declare function createScript(url: string, cb: (value: void | PromiseLike<void>) => void, attrs?: Record<string, any>, createScriptHook?: (url: string) => HTMLScriptElement | void): {
2
- script: HTMLScriptElement;
3
- needAttach: boolean;
4
- };
5
- export declare function loadScript(url: string, info: {
6
- attrs?: Record<string, any>;
7
- createScriptHook?: (url: string) => HTMLScriptElement | void;
8
- }): Promise<void>;