@module-federation/runtime-core 0.0.0-next-20241118100312 → 0.0.0-next-20241231075249

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.6.14";
199
+ CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.6.15";
200
200
  }
201
201
  }
202
202
  // eslint-disable-next-line @typescript-eslint/ban-types
@@ -1015,7 +1015,14 @@ async function loadEsmEntry({ entry, remoteEntryExports }) {
1015
1015
  return new Promise((resolve, reject)=>{
1016
1016
  try {
1017
1017
  if (!remoteEntryExports) {
1018
- import(/* webpackIgnore: true */ entry).then(resolve).catch(reject);
1018
+ if (typeof FEDERATION_ALLOW_NEW_FUNCTION !== 'undefined') {
1019
+ new Function('callbacks', `import("${entry}").then(callbacks[0]).catch(callbacks[1])`)([
1020
+ resolve,
1021
+ reject
1022
+ ]);
1023
+ } else {
1024
+ import(/* webpackIgnore: true */ /* @vite-ignore */ entry).then(resolve).catch(reject);
1025
+ }
1019
1026
  } else {
1020
1027
  resolve(remoteEntryExports);
1021
1028
  }
@@ -1076,6 +1083,10 @@ async function loadEntryScript({ name, globalName, entry, loaderHook }) {
1076
1083
  }));
1077
1084
  return entryExports;
1078
1085
  }).catch((e)=>{
1086
+ assert(undefined, errorCodes.getShortErrorMsg(errorCodes.RUNTIME_008, errorCodes.runtimeDescMap, {
1087
+ remoteName: name,
1088
+ resourceUrl: entry
1089
+ }));
1079
1090
  throw e;
1080
1091
  });
1081
1092
  }
@@ -1150,7 +1161,6 @@ async function getRemoteEntry({ origin, remoteEntryExports, remoteInfo }) {
1150
1161
  }
1151
1162
  if (!globalLoading[uniqueKey]) {
1152
1163
  const loadEntryHook = origin.remoteHandler.hooks.lifecycle.loadEntry;
1153
- origin.loaderHook.lifecycle.createScript;
1154
1164
  const loaderHook = origin.loaderHook;
1155
1165
  globalLoading[uniqueKey] = loadEntryHook.emit({
1156
1166
  loaderHook,
@@ -1186,12 +1196,24 @@ let Module = class Module {
1186
1196
  if (this.remoteEntryExports) {
1187
1197
  return this.remoteEntryExports;
1188
1198
  }
1189
- // Get remoteEntry.js
1190
- const remoteEntryExports = await getRemoteEntry({
1191
- origin: this.host,
1192
- remoteInfo: this.remoteInfo,
1193
- remoteEntryExports: this.remoteEntryExports
1194
- });
1199
+ let remoteEntryExports;
1200
+ try {
1201
+ remoteEntryExports = await getRemoteEntry({
1202
+ origin: this.host,
1203
+ remoteInfo: this.remoteInfo,
1204
+ remoteEntryExports: this.remoteEntryExports
1205
+ });
1206
+ } catch (err) {
1207
+ const uniqueKey = getRemoteEntryUniqueKey(this.remoteInfo);
1208
+ remoteEntryExports = await this.host.loaderHook.lifecycle.loadEntryError.emit({
1209
+ getRemoteEntry,
1210
+ origin: this.host,
1211
+ remoteInfo: this.remoteInfo,
1212
+ remoteEntryExports: this.remoteEntryExports,
1213
+ globalLoading,
1214
+ uniqueKey
1215
+ });
1216
+ }
1195
1217
  assert(remoteEntryExports, `remoteEntryExports is undefined \n ${sdk.safeToString(this.remoteInfo)}`);
1196
1218
  this.remoteEntryExports = remoteEntryExports;
1197
1219
  return this.remoteEntryExports;
@@ -2688,7 +2710,7 @@ class RemoteHandler {
2688
2710
  } else {
2689
2711
  const messages = [
2690
2712
  `The remote "${remote.name}" is already registered.`,
2691
- (options == null ? void 0 : options.force) ? 'Hope you have known that OVERRIDE it may have some unexpected errors' : 'If you want to merge the remote, you can set "force: true".'
2713
+ 'Please note that overriding it may cause unexpected errors.'
2692
2714
  ];
2693
2715
  if (options == null ? void 0 : options.force) {
2694
2716
  // remove registered remote
@@ -2699,8 +2721,8 @@ class RemoteHandler {
2699
2721
  remote,
2700
2722
  origin: host
2701
2723
  });
2724
+ sdk.warn(messages.join(' '));
2702
2725
  }
2703
- sdk.warn(messages.join(' '));
2704
2726
  }
2705
2727
  }
2706
2728
  removeRemote(remote) {
@@ -2930,15 +2952,15 @@ class FederationHost {
2930
2952
  // maybe will change, temporarily for internal use only
2931
2953
  initContainer: new AsyncWaterfallHook('initContainer')
2932
2954
  });
2933
- this.version = "0.6.14";
2955
+ this.version = "0.6.15";
2934
2956
  this.moduleCache = new Map();
2935
2957
  this.loaderHook = new PluginSystem({
2936
2958
  // FIXME: may not be suitable , not open to the public yet
2937
2959
  getModuleInfo: new SyncHook(),
2938
2960
  createScript: new SyncHook(),
2939
2961
  createLink: new SyncHook(),
2940
- // only work for manifest , so not open to the public yet
2941
2962
  fetch: new AsyncHook(),
2963
+ loadEntryError: new AsyncHook(),
2942
2964
  getModuleFactory: new AsyncHook()
2943
2965
  });
2944
2966
  this.bridgeHook = new PluginSystem({
@@ -1,7 +1,7 @@
1
- import { _ as _extends, a as _object_without_properties_loose } from './polyfills.esm.js';
1
+ import { _ as _extends, a as _object_without_properties_loose } from './polyfills.esm.mjs';
2
2
  import { createLogger, isBrowserEnv, isDebugMode, loadScriptNode, composeKeyWithSeparator, loadScript, safeToString, createLink, createScript, getResourceUrl, isManifestProvider, generateSnapshotFromManifest, warn as warn$1 } from '@module-federation/sdk';
3
3
  export { loadScript, loadScriptNode } from '@module-federation/sdk';
4
- import { getShortErrorMsg, RUNTIME_001, runtimeDescMap, RUNTIME_002, RUNTIME_007, RUNTIME_003, RUNTIME_005, RUNTIME_006, RUNTIME_004 } from '@module-federation/error-codes';
4
+ import { getShortErrorMsg, RUNTIME_001, runtimeDescMap, RUNTIME_008, RUNTIME_002, RUNTIME_007, RUNTIME_003, RUNTIME_005, RUNTIME_006, RUNTIME_004 } from '@module-federation/error-codes';
5
5
 
6
6
  const LOG_CATEGORY = '[ Federation Runtime ]';
7
7
  // FIXME: pre-bundle ?
@@ -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.6.14";
198
+ CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.6.15";
199
199
  }
200
200
  }
201
201
  // eslint-disable-next-line @typescript-eslint/ban-types
@@ -1014,7 +1014,14 @@ async function loadEsmEntry({ entry, remoteEntryExports }) {
1014
1014
  return new Promise((resolve, reject)=>{
1015
1015
  try {
1016
1016
  if (!remoteEntryExports) {
1017
- import(/* webpackIgnore: true */ entry).then(resolve).catch(reject);
1017
+ if (typeof FEDERATION_ALLOW_NEW_FUNCTION !== 'undefined') {
1018
+ new Function('callbacks', `import("${entry}").then(callbacks[0]).catch(callbacks[1])`)([
1019
+ resolve,
1020
+ reject
1021
+ ]);
1022
+ } else {
1023
+ import(/* webpackIgnore: true */ /* @vite-ignore */ entry).then(resolve).catch(reject);
1024
+ }
1018
1025
  } else {
1019
1026
  resolve(remoteEntryExports);
1020
1027
  }
@@ -1075,6 +1082,10 @@ async function loadEntryScript({ name, globalName, entry, loaderHook }) {
1075
1082
  }));
1076
1083
  return entryExports;
1077
1084
  }).catch((e)=>{
1085
+ assert(undefined, getShortErrorMsg(RUNTIME_008, runtimeDescMap, {
1086
+ remoteName: name,
1087
+ resourceUrl: entry
1088
+ }));
1078
1089
  throw e;
1079
1090
  });
1080
1091
  }
@@ -1149,7 +1160,6 @@ async function getRemoteEntry({ origin, remoteEntryExports, remoteInfo }) {
1149
1160
  }
1150
1161
  if (!globalLoading[uniqueKey]) {
1151
1162
  const loadEntryHook = origin.remoteHandler.hooks.lifecycle.loadEntry;
1152
- origin.loaderHook.lifecycle.createScript;
1153
1163
  const loaderHook = origin.loaderHook;
1154
1164
  globalLoading[uniqueKey] = loadEntryHook.emit({
1155
1165
  loaderHook,
@@ -1185,12 +1195,24 @@ let Module = class Module {
1185
1195
  if (this.remoteEntryExports) {
1186
1196
  return this.remoteEntryExports;
1187
1197
  }
1188
- // Get remoteEntry.js
1189
- const remoteEntryExports = await getRemoteEntry({
1190
- origin: this.host,
1191
- remoteInfo: this.remoteInfo,
1192
- remoteEntryExports: this.remoteEntryExports
1193
- });
1198
+ let remoteEntryExports;
1199
+ try {
1200
+ remoteEntryExports = await getRemoteEntry({
1201
+ origin: this.host,
1202
+ remoteInfo: this.remoteInfo,
1203
+ remoteEntryExports: this.remoteEntryExports
1204
+ });
1205
+ } catch (err) {
1206
+ const uniqueKey = getRemoteEntryUniqueKey(this.remoteInfo);
1207
+ remoteEntryExports = await this.host.loaderHook.lifecycle.loadEntryError.emit({
1208
+ getRemoteEntry,
1209
+ origin: this.host,
1210
+ remoteInfo: this.remoteInfo,
1211
+ remoteEntryExports: this.remoteEntryExports,
1212
+ globalLoading,
1213
+ uniqueKey
1214
+ });
1215
+ }
1194
1216
  assert(remoteEntryExports, `remoteEntryExports is undefined \n ${safeToString(this.remoteInfo)}`);
1195
1217
  this.remoteEntryExports = remoteEntryExports;
1196
1218
  return this.remoteEntryExports;
@@ -2687,7 +2709,7 @@ class RemoteHandler {
2687
2709
  } else {
2688
2710
  const messages = [
2689
2711
  `The remote "${remote.name}" is already registered.`,
2690
- (options == null ? void 0 : options.force) ? 'Hope you have known that OVERRIDE it may have some unexpected errors' : 'If you want to merge the remote, you can set "force: true".'
2712
+ 'Please note that overriding it may cause unexpected errors.'
2691
2713
  ];
2692
2714
  if (options == null ? void 0 : options.force) {
2693
2715
  // remove registered remote
@@ -2698,8 +2720,8 @@ class RemoteHandler {
2698
2720
  remote,
2699
2721
  origin: host
2700
2722
  });
2723
+ warn$1(messages.join(' '));
2701
2724
  }
2702
- warn$1(messages.join(' '));
2703
2725
  }
2704
2726
  }
2705
2727
  removeRemote(remote) {
@@ -2929,15 +2951,15 @@ class FederationHost {
2929
2951
  // maybe will change, temporarily for internal use only
2930
2952
  initContainer: new AsyncWaterfallHook('initContainer')
2931
2953
  });
2932
- this.version = "0.6.14";
2954
+ this.version = "0.6.15";
2933
2955
  this.moduleCache = new Map();
2934
2956
  this.loaderHook = new PluginSystem({
2935
2957
  // FIXME: may not be suitable , not open to the public yet
2936
2958
  getModuleInfo: new SyncHook(),
2937
2959
  createScript: new SyncHook(),
2938
2960
  createLink: new SyncHook(),
2939
- // only work for manifest , so not open to the public yet
2940
2961
  fetch: new AsyncHook(),
2962
+ loadEntryError: new AsyncHook(),
2941
2963
  getModuleFactory: new AsyncHook()
2942
2964
  });
2943
2965
  this.bridgeHook = new PluginSystem({
@@ -1,5 +1,6 @@
1
1
  import type { CreateScriptHookReturn, ModuleInfo } from '@module-federation/sdk';
2
2
  import { Options, PreloadRemoteArgs, RemoteEntryExports, Remote, Shared, ShareInfos, UserOptions, RemoteInfo, ShareScopeMap, InitScope, RemoteEntryInitOptions, CallFrom } from './type';
3
+ import { getRemoteEntry } from './utils';
3
4
  import { Module } from './module';
4
5
  import { AsyncHook, AsyncWaterfallHook, PluginSystem, SyncHook, SyncWaterfallHook } from './utils/hooks';
5
6
  import { SnapshotHandler } from './plugins/snapshot/SnapshotHandler';
@@ -60,6 +61,14 @@ export declare class FederationHost {
60
61
  attrs?: Record<string, any>;
61
62
  }], void | HTMLLinkElement>;
62
63
  fetch: AsyncHook<[string, RequestInit], false | void | Promise<Response>>;
64
+ loadEntryError: AsyncHook<[{
65
+ getRemoteEntry: typeof getRemoteEntry;
66
+ origin: FederationHost;
67
+ remoteInfo: RemoteInfo;
68
+ remoteEntryExports?: RemoteEntryExports | undefined;
69
+ globalLoading: Record<string, Promise<void | RemoteEntryExports> | undefined>;
70
+ uniqueKey: string;
71
+ }], Promise<(() => Promise<RemoteEntryExports | undefined>) | undefined>>;
63
72
  getModuleFactory: AsyncHook<[{
64
73
  remoteEntryExports: RemoteEntryExports;
65
74
  expose: string;
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@module-federation/runtime-core",
3
- "version": "0.0.0-next-20241118100312",
3
+ "version": "0.0.0-next-20241231075249",
4
4
  "author": "zhouxiao <codingzx@gmail.com>",
5
5
  "main": "./dist/index.cjs.js",
6
- "module": "./dist/index.esm.js",
6
+ "module": "./dist/index.esm.mjs",
7
7
  "types": "./dist/index.cjs.d.ts",
8
8
  "license": "MIT",
9
9
  "publishConfig": {
@@ -16,12 +16,12 @@
16
16
  "exports": {
17
17
  ".": {
18
18
  "types": "./dist/index.cjs.d.ts",
19
- "import": "./dist/index.esm.js",
19
+ "import": "./dist/index.esm.mjs",
20
20
  "require": "./dist/index.cjs.js"
21
21
  },
22
22
  "./types": {
23
23
  "types": "./dist/types.cjs.d.ts",
24
- "import": "./dist/types.esm.js",
24
+ "import": "./dist/types.esm.mjs",
25
25
  "require": "./dist/types.cjs.js"
26
26
  }
27
27
  },
@@ -36,7 +36,7 @@
36
36
  }
37
37
  },
38
38
  "dependencies": {
39
- "@module-federation/sdk": "0.0.0-next-20241118100312",
40
- "@module-federation/error-codes": "0.0.0-next-20241118100312"
39
+ "@module-federation/sdk": "0.0.0-next-20241231075249",
40
+ "@module-federation/error-codes": "0.0.0-next-20241231075249"
41
41
  }
42
42
  }
package/dist/package.json DELETED
@@ -1,42 +0,0 @@
1
- {
2
- "name": "@module-federation/runtime-core",
3
- "version": "0.6.14",
4
- "author": "zhouxiao <codingzx@gmail.com>",
5
- "main": "./index.cjs.js",
6
- "module": "./index.esm.js",
7
- "types": "./dist/index.cjs.d.ts",
8
- "license": "MIT",
9
- "publishConfig": {
10
- "access": "public"
11
- },
12
- "files": [
13
- "dist/",
14
- "README.md"
15
- ],
16
- "exports": {
17
- ".": {
18
- "types": "./dist/index.cjs.d.ts",
19
- "import": "./dist/index.esm.js",
20
- "require": "./dist/index.cjs.js"
21
- },
22
- "./types": {
23
- "types": "./dist/types.cjs.d.ts",
24
- "import": "./dist/types.esm.js",
25
- "require": "./dist/types.cjs.js"
26
- }
27
- },
28
- "typesVersions": {
29
- "*": {
30
- ".": [
31
- "./dist/index.cjs.d.ts"
32
- ],
33
- "types": [
34
- "./dist/types.cjs.d.ts"
35
- ]
36
- }
37
- },
38
- "dependencies": {
39
- "@module-federation/sdk": "workspace:*",
40
- "@module-federation/error-codes": "workspace:*"
41
- }
42
- }
File without changes
File without changes