@module-federation/sdk 0.0.0-next-20241212123451 → 0.0.0-next-20241213035216

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
@@ -422,7 +422,7 @@ function createScript(info) {
422
422
  // Retrieve the existing script element by its src attribute
423
423
  let script = null;
424
424
  let needAttach = true;
425
- let timeout = 60000;
425
+ let timeout = 20000;
426
426
  let timeoutId;
427
427
  const scripts = document.getElementsByTagName('script');
428
428
  for(let i = 0; i < scripts.length; i++){
@@ -470,14 +470,8 @@ function createScript(info) {
470
470
  }
471
471
  const onScriptComplete = async (prev, // eslint-disable-next-line @typescript-eslint/no-explicit-any
472
472
  event)=>{
473
+ var _info_cb;
473
474
  clearTimeout(timeoutId);
474
- const onScriptCompleteCallback = ()=>{
475
- if (event.type === 'error') {
476
- (info == null ? void 0 : info.onErrorCallback) && (info == null ? void 0 : info.onErrorCallback(event));
477
- } else {
478
- (info == null ? void 0 : info.cb) && (info == null ? void 0 : info.cb());
479
- }
480
- };
481
475
  // Prevent memory leaks in IE.
482
476
  if (script) {
483
477
  script.onerror = null;
@@ -489,17 +483,19 @@ function createScript(info) {
489
483
  }
490
484
  });
491
485
  if (prev && typeof prev === 'function') {
486
+ var _info_cb1;
492
487
  const result = prev(event);
493
488
  if (result instanceof Promise) {
489
+ var _info_cb2;
494
490
  const res = await result;
495
- onScriptCompleteCallback();
491
+ info == null ? void 0 : (_info_cb2 = info.cb) == null ? void 0 : _info_cb2.call(info);
496
492
  return res;
497
493
  }
498
- onScriptCompleteCallback();
494
+ info == null ? void 0 : (_info_cb1 = info.cb) == null ? void 0 : _info_cb1.call(info);
499
495
  return result;
500
496
  }
501
497
  }
502
- onScriptCompleteCallback();
498
+ info == null ? void 0 : (_info_cb = info.cb) == null ? void 0 : _info_cb.call(info);
503
499
  };
504
500
  script.onerror = onScriptComplete.bind(null, script.onerror);
505
501
  script.onload = onScriptComplete.bind(null, script.onload);
@@ -548,13 +544,6 @@ function createLink(info) {
548
544
  }
549
545
  const onLinkComplete = (prev, // eslint-disable-next-line @typescript-eslint/no-explicit-any
550
546
  event)=>{
551
- const onLinkCompleteCallback = ()=>{
552
- if (event.type === 'error') {
553
- (info == null ? void 0 : info.onErrorCallback) && (info == null ? void 0 : info.onErrorCallback(event));
554
- } else {
555
- (info == null ? void 0 : info.cb) && (info == null ? void 0 : info.cb());
556
- }
557
- };
558
547
  // Prevent memory leaks in IE.
559
548
  if (link) {
560
549
  link.onerror = null;
@@ -568,11 +557,11 @@ function createLink(info) {
568
557
  if (prev) {
569
558
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
570
559
  const res = prev(event);
571
- onLinkCompleteCallback();
560
+ info.cb();
572
561
  return res;
573
562
  }
574
563
  }
575
- onLinkCompleteCallback();
564
+ info.cb();
576
565
  };
577
566
  link.onerror = onLinkComplete.bind(null, link.onerror);
578
567
  link.onload = onLinkComplete.bind(null, link.onload);
@@ -583,11 +572,10 @@ function createLink(info) {
583
572
  }
584
573
  function loadScript(url, info) {
585
574
  const { attrs = {}, createScriptHook } = info;
586
- return new Promise((resolve, reject)=>{
575
+ return new Promise((resolve, _reject)=>{
587
576
  const { script, needAttach } = createScript({
588
577
  url,
589
578
  cb: resolve,
590
- onErrorCallback: reject,
591
579
  attrs: polyfills._extends({
592
580
  fetchpriority: 'high'
593
581
  }, attrs),
@@ -420,7 +420,7 @@ function createScript(info) {
420
420
  // Retrieve the existing script element by its src attribute
421
421
  let script = null;
422
422
  let needAttach = true;
423
- let timeout = 60000;
423
+ let timeout = 20000;
424
424
  let timeoutId;
425
425
  const scripts = document.getElementsByTagName('script');
426
426
  for(let i = 0; i < scripts.length; i++){
@@ -468,14 +468,8 @@ function createScript(info) {
468
468
  }
469
469
  const onScriptComplete = async (prev, // eslint-disable-next-line @typescript-eslint/no-explicit-any
470
470
  event)=>{
471
+ var _info_cb;
471
472
  clearTimeout(timeoutId);
472
- const onScriptCompleteCallback = ()=>{
473
- if (event.type === 'error') {
474
- (info == null ? void 0 : info.onErrorCallback) && (info == null ? void 0 : info.onErrorCallback(event));
475
- } else {
476
- (info == null ? void 0 : info.cb) && (info == null ? void 0 : info.cb());
477
- }
478
- };
479
473
  // Prevent memory leaks in IE.
480
474
  if (script) {
481
475
  script.onerror = null;
@@ -487,17 +481,19 @@ function createScript(info) {
487
481
  }
488
482
  });
489
483
  if (prev && typeof prev === 'function') {
484
+ var _info_cb1;
490
485
  const result = prev(event);
491
486
  if (result instanceof Promise) {
487
+ var _info_cb2;
492
488
  const res = await result;
493
- onScriptCompleteCallback();
489
+ info == null ? void 0 : (_info_cb2 = info.cb) == null ? void 0 : _info_cb2.call(info);
494
490
  return res;
495
491
  }
496
- onScriptCompleteCallback();
492
+ info == null ? void 0 : (_info_cb1 = info.cb) == null ? void 0 : _info_cb1.call(info);
497
493
  return result;
498
494
  }
499
495
  }
500
- onScriptCompleteCallback();
496
+ info == null ? void 0 : (_info_cb = info.cb) == null ? void 0 : _info_cb.call(info);
501
497
  };
502
498
  script.onerror = onScriptComplete.bind(null, script.onerror);
503
499
  script.onload = onScriptComplete.bind(null, script.onload);
@@ -546,13 +542,6 @@ function createLink(info) {
546
542
  }
547
543
  const onLinkComplete = (prev, // eslint-disable-next-line @typescript-eslint/no-explicit-any
548
544
  event)=>{
549
- const onLinkCompleteCallback = ()=>{
550
- if (event.type === 'error') {
551
- (info == null ? void 0 : info.onErrorCallback) && (info == null ? void 0 : info.onErrorCallback(event));
552
- } else {
553
- (info == null ? void 0 : info.cb) && (info == null ? void 0 : info.cb());
554
- }
555
- };
556
545
  // Prevent memory leaks in IE.
557
546
  if (link) {
558
547
  link.onerror = null;
@@ -566,11 +555,11 @@ function createLink(info) {
566
555
  if (prev) {
567
556
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
568
557
  const res = prev(event);
569
- onLinkCompleteCallback();
558
+ info.cb();
570
559
  return res;
571
560
  }
572
561
  }
573
- onLinkCompleteCallback();
562
+ info.cb();
574
563
  };
575
564
  link.onerror = onLinkComplete.bind(null, link.onerror);
576
565
  link.onload = onLinkComplete.bind(null, link.onload);
@@ -581,11 +570,10 @@ function createLink(info) {
581
570
  }
582
571
  function loadScript(url, info) {
583
572
  const { attrs = {}, createScriptHook } = info;
584
- return new Promise((resolve, reject)=>{
573
+ return new Promise((resolve, _reject)=>{
585
574
  const { script, needAttach } = createScript({
586
575
  url,
587
576
  cb: resolve,
588
- onErrorCallback: reject,
589
577
  attrs: _extends({
590
578
  fetchpriority: 'high'
591
579
  }, attrs),
package/dist/src/dom.d.ts CHANGED
@@ -4,7 +4,6 @@ export declare function isStaticResourcesEqual(url1: string, url2: string): bool
4
4
  export declare function createScript(info: {
5
5
  url: string;
6
6
  cb?: (value: void | PromiseLike<void>) => void;
7
- onErrorCallback?: (error: Error) => void;
8
7
  attrs?: Record<string, any>;
9
8
  needDeleteScript?: boolean;
10
9
  createScriptHook?: CreateScriptHookDom;
@@ -14,8 +13,7 @@ export declare function createScript(info: {
14
13
  };
15
14
  export declare function createLink(info: {
16
15
  url: string;
17
- cb?: (value: void | PromiseLike<void>) => void;
18
- onErrorCallback?: (error: Error) => void;
16
+ cb: (value: void | PromiseLike<void>) => void;
19
17
  attrs: Record<string, string>;
20
18
  needDeleteLink?: boolean;
21
19
  createLinkHook?: (url: string, attrs?: Record<string, any>) => HTMLLinkElement | void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/sdk",
3
- "version": "0.0.0-next-20241212123451",
3
+ "version": "0.0.0-next-20241213035216",
4
4
  "license": "MIT",
5
5
  "description": "A sdk for support module federation",
6
6
  "keywords": [
@@ -11,6 +11,11 @@
11
11
  "dist/",
12
12
  "README.md"
13
13
  ],
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/module-federation/core/",
17
+ "directory": "packages/sdk"
18
+ },
14
19
  "publishConfig": {
15
20
  "access": "public"
16
21
  },