remote-reload-utils 1.0.0 → 1.0.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/CHANGELOG.md CHANGED
@@ -13,6 +13,13 @@
13
13
 
14
14
  ## [未发布]
15
15
 
16
+ ## [1.0.1] - 2026-03-20
17
+
18
+ ### Release
19
+
20
+ - Published version 1.0.1 with patch bump
21
+
22
+
16
23
  ## [0.0.17] - 2026-03-19
17
24
 
18
25
  ### Release
@@ -21,11 +21,14 @@ export interface LoadResult {
21
21
  mf: ReturnType<typeof createInstance>;
22
22
  }
23
23
  export type RuntimeRemote = Parameters<ReturnType<typeof createInstance>['registerRemotes']>[0][number];
24
+ declare const mfInstanceCache: Map<string, import("@module-federation/enhanced/runtime").ModuleFederation>;
25
+ declare const mfInstanceLoadingCache: Map<string, Promise<LoadResult>>;
26
+ export { mfInstanceCache, mfInstanceLoadingCache };
24
27
  /**
25
28
  * 尝试加载单个远程模块 URL
26
29
  * 注意:实际的重试机制在外层 loadRemoteMultiVersion 的 URL 遍历中实现
27
30
  */
28
- export declare function tryLoadRemote(scopeName: string, url: string, _retries: number, _delay: number, sharedConfig: Record<string, any>, plugins: ModuleFederationRuntimePlugin[], extraRemotes?: RuntimeRemote[], registerOptions?: {
31
+ export declare function tryLoadRemote(scopeName: string, url: string, retries: number, delay: number, sharedConfig: Record<string, any>, plugins: ModuleFederationRuntimePlugin[], extraRemotes?: RuntimeRemote[], registerOptions?: {
29
32
  force?: boolean;
30
33
  }): Promise<LoadResult>;
31
34
  /**
package/dist/main.cjs CHANGED
@@ -335,7 +335,7 @@ function buildRemotesIdentity(remotes) {
335
335
  entryGlobalName: remote.entryGlobalName || ''
336
336
  })).sort().join('|');
337
337
  }
338
- async function tryLoadRemote(scopeName, url, _retries, _delay, sharedConfig, plugins, extraRemotes = [], registerOptions = {}) {
338
+ async function tryLoadRemote(scopeName, url, retries, delay, sharedConfig, plugins, extraRemotes = [], registerOptions = {}) {
339
339
  const remotesIdentity = buildRemotesIdentity(extraRemotes);
340
340
  const cacheKey = `${scopeName}::${url}::${remotesIdentity}::${registerOptions.force ? 'force' : 'normal'}`;
341
341
  const cachedMfs = mfInstanceCache.get(cacheKey);
@@ -345,28 +345,35 @@ async function tryLoadRemote(scopeName, url, _retries, _delay, sharedConfig, plu
345
345
  };
346
346
  const loadingMfs = mfInstanceLoadingCache.get(cacheKey);
347
347
  if (loadingMfs) return loadingMfs;
348
- const loadPromise = Promise.resolve().then(()=>{
349
- const mf = (0, runtime_namespaceObject.createInstance)({
350
- name: 'host',
351
- remotes: [
352
- {
353
- name: scopeName,
354
- entry: url
355
- }
356
- ],
357
- shared: sharedConfig,
358
- plugins: [
359
- ...plugins,
360
- fallbackPlugin()
361
- ]
362
- });
363
- if (extraRemotes.length > 0) mf.registerRemotes(extraRemotes, registerOptions);
364
- const result = {
365
- scopeName,
366
- mf
367
- };
368
- mfInstanceCache.set(cacheKey, mf);
369
- return result;
348
+ const loadPromise = Promise.resolve().then(async ()=>{
349
+ let lastError;
350
+ for(let attempt = 0; attempt < retries; attempt++)try {
351
+ if (attempt > 0) await new Promise((resolve)=>setTimeout(resolve, delay));
352
+ const mf = (0, runtime_namespaceObject.createInstance)({
353
+ name: 'host',
354
+ remotes: [
355
+ {
356
+ name: scopeName,
357
+ entry: url
358
+ }
359
+ ],
360
+ shared: sharedConfig,
361
+ plugins: [
362
+ ...plugins,
363
+ fallbackPlugin()
364
+ ]
365
+ });
366
+ if (extraRemotes.length > 0) mf.registerRemotes(extraRemotes, registerOptions);
367
+ const result = {
368
+ scopeName,
369
+ mf
370
+ };
371
+ mfInstanceCache.set(cacheKey, mf);
372
+ return result;
373
+ } catch (e) {
374
+ lastError = e;
375
+ }
376
+ throw lastError || new Error('Unknown error');
370
377
  });
371
378
  mfInstanceLoadingCache.set(cacheKey, loadPromise);
372
379
  try {
package/dist/main.js CHANGED
@@ -267,7 +267,7 @@ function buildRemotesIdentity(remotes) {
267
267
  entryGlobalName: remote.entryGlobalName || ''
268
268
  })).sort().join('|');
269
269
  }
270
- async function tryLoadRemote(scopeName, url, _retries, _delay, sharedConfig, plugins, extraRemotes = [], registerOptions = {}) {
270
+ async function tryLoadRemote(scopeName, url, retries, delay, sharedConfig, plugins, extraRemotes = [], registerOptions = {}) {
271
271
  const remotesIdentity = buildRemotesIdentity(extraRemotes);
272
272
  const cacheKey = `${scopeName}::${url}::${remotesIdentity}::${registerOptions.force ? 'force' : 'normal'}`;
273
273
  const cachedMfs = mfInstanceCache.get(cacheKey);
@@ -277,28 +277,35 @@ async function tryLoadRemote(scopeName, url, _retries, _delay, sharedConfig, plu
277
277
  };
278
278
  const loadingMfs = mfInstanceLoadingCache.get(cacheKey);
279
279
  if (loadingMfs) return loadingMfs;
280
- const loadPromise = Promise.resolve().then(()=>{
281
- const mf = createInstance({
282
- name: 'host',
283
- remotes: [
284
- {
285
- name: scopeName,
286
- entry: url
287
- }
288
- ],
289
- shared: sharedConfig,
290
- plugins: [
291
- ...plugins,
292
- fallbackPlugin()
293
- ]
294
- });
295
- if (extraRemotes.length > 0) mf.registerRemotes(extraRemotes, registerOptions);
296
- const result = {
297
- scopeName,
298
- mf
299
- };
300
- mfInstanceCache.set(cacheKey, mf);
301
- return result;
280
+ const loadPromise = Promise.resolve().then(async ()=>{
281
+ let lastError;
282
+ for(let attempt = 0; attempt < retries; attempt++)try {
283
+ if (attempt > 0) await new Promise((resolve)=>setTimeout(resolve, delay));
284
+ const mf = createInstance({
285
+ name: 'host',
286
+ remotes: [
287
+ {
288
+ name: scopeName,
289
+ entry: url
290
+ }
291
+ ],
292
+ shared: sharedConfig,
293
+ plugins: [
294
+ ...plugins,
295
+ fallbackPlugin()
296
+ ]
297
+ });
298
+ if (extraRemotes.length > 0) mf.registerRemotes(extraRemotes, registerOptions);
299
+ const result = {
300
+ scopeName,
301
+ mf
302
+ };
303
+ mfInstanceCache.set(cacheKey, mf);
304
+ return result;
305
+ } catch (e) {
306
+ lastError = e;
307
+ }
308
+ throw lastError || new Error('Unknown error');
302
309
  });
303
310
  mfInstanceLoadingCache.set(cacheKey, loadPromise);
304
311
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remote-reload-utils",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "type": "module",
5
5
  "description": "Utilities for remote reload in Module Federation & React Component",
6
6
  "exports": {