@module-federation/runtime 0.6.0 → 0.6.2

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.
@@ -0,0 +1,2 @@
1
+ declare const FederationHost: any, registerGlobalPlugins: any, getRemoteEntry: any, getRemoteInfo: any, loadScript: any, loadScriptNode: any, init: any, loadRemote: any, loadShare: any, loadShareSync: any, preloadRemote: any, registerRemotes: any, registerPlugins: any, getInstance: any;
2
+ export { FederationHost, registerGlobalPlugins, getRemoteEntry, getRemoteInfo, loadScript, loadScriptNode, init, loadRemote, loadShare, loadShareSync, preloadRemote, registerRemotes, registerPlugins, getInstance, };
@@ -1,4 +1,4 @@
1
- import type { ModuleInfo, GlobalModuleInfo } from '@module-federation/sdk';
1
+ import { ModuleInfo, GlobalModuleInfo } from '@module-federation/sdk';
2
2
  import { Options, UserOptions, PreloadAssets, PreloadOptions, PreloadRemoteArgs, Remote, RemoteInfo, RemoteEntryExports, CallFrom } from '../type';
3
3
  import { FederationHost } from '../core';
4
4
  import { PluginSystem, AsyncHook, AsyncWaterfallHook, SyncHook, SyncWaterfallHook } from '../utils/hooks';
@@ -1,4 +1,3 @@
1
+ export { isBrowserEnv, isDebugMode } from '@module-federation/sdk';
1
2
  export declare function isDevelopmentMode(): boolean;
2
3
  export declare function getBuilderId(): string;
3
- export declare function isDebugMode(): boolean;
4
- export declare function isBrowserEnv(): boolean;
@@ -1,11 +1,10 @@
1
- import type { RemoteWithEntry, ModuleInfo, RemoteEntryType } from '@module-federation/sdk';
1
+ import { RemoteWithEntry, ModuleInfo, RemoteEntryType } from '@module-federation/sdk';
2
2
  import { Remote, RemoteInfoOptionalVersion } from '../type';
3
3
  export declare function addUniqueItem(arr: Array<string>, item: string): Array<string>;
4
4
  export declare function getFMId(remoteInfo: RemoteInfoOptionalVersion | RemoteWithEntry): string;
5
5
  export declare function isRemoteInfoWithEntry(remote: Remote): remote is RemoteWithEntry;
6
6
  export declare function isPureRemoteEntry(remote: RemoteWithEntry): boolean;
7
7
  export declare function safeWrapper<T extends (...args: Array<any>) => any>(callback: T, disableWarn?: boolean): Promise<ReturnType<T> | undefined>;
8
- export declare function safeToString(info: any): string;
9
8
  export declare function isObject(val: any): boolean;
10
9
  export declare const objectToString: () => string;
11
10
  export declare function isPlainObject(val: any): val is object;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/runtime",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "author": "zhouxiao <codingzx@gmail.com>",
5
5
  "main": "./dist/index.cjs.js",
6
6
  "module": "./dist/index.esm.js",
@@ -29,10 +29,10 @@
29
29
  "import": "./dist/types.esm.js",
30
30
  "require": "./dist/types.cjs.js"
31
31
  },
32
- "./retry-plugin": {
33
- "types": "./dist/retry-plugin.cjs.d.ts",
34
- "import": "./dist/retry-plugin.esm.js",
35
- "require": "./dist/retry-plugin.cjs.js"
32
+ "./embedded": {
33
+ "types": "./dist/embedded.cjs.d.ts",
34
+ "import": "./dist/embedded.esm.js",
35
+ "require": "./dist/embedded.cjs.js"
36
36
  },
37
37
  "./*": "./*"
38
38
  },
@@ -46,13 +46,10 @@
46
46
  ],
47
47
  "types": [
48
48
  "./dist/types.cjs.d.ts"
49
- ],
50
- "retry-plugin": [
51
- "./dist/retry-plugin.cjs.d.ts"
52
49
  ]
53
50
  }
54
51
  },
55
52
  "dependencies": {
56
- "@module-federation/sdk": "0.6.0"
53
+ "@module-federation/sdk": "0.6.2"
57
54
  }
58
55
  }
@@ -1,2 +0,0 @@
1
- export * from "./src/plugins/retry-plugin";
2
- export { default } from "./src/plugins/retry-plugin";
@@ -1,68 +0,0 @@
1
- 'use strict';
2
-
3
- function _extends() {
4
- _extends = Object.assign || function(target) {
5
- for(var i = 1; i < arguments.length; i++){
6
- var source = arguments[i];
7
- for(var key in source){
8
- if (Object.prototype.hasOwnProperty.call(source, key)) {
9
- target[key] = source[key];
10
- }
11
- }
12
- }
13
- return target;
14
- };
15
- return _extends.apply(this, arguments);
16
- }
17
- const defaultRetries = 3;
18
- async function fetchWithRetry({ url, options = {}, retryTimes = defaultRetries, fallbackUrl = '' }) {
19
- try {
20
- const response = await fetch(url, options);
21
- // To prevent the response object from being read multiple times and causing errors, clone it
22
- const responseClone = response.clone();
23
- // Network error
24
- if (!response.ok) {
25
- throw new Error(`Server error:${response.status}`);
26
- }
27
- // parse json error
28
- await responseClone.json().catch((error)=>{
29
- throw new Error(`Json parse error: ${error}, url is: ${url}`);
30
- });
31
- return response;
32
- } catch (error) {
33
- if (retryTimes <= 0) {
34
- console.log(`>>>>>>>>> retry failed after ${defaultRetries} times for url: ${url}, now will try fallbackUrl url: ${fallbackUrl} <<<<<<<<<`);
35
- if (fallbackUrl && fallbackUrl !== url) {
36
- return fetchWithRetry({
37
- url: fallbackUrl,
38
- options,
39
- retryTimes: 1,
40
- fallbackUrl
41
- });
42
- }
43
- throw new Error('The request failed three times and has now been abandoned');
44
- }
45
- // If there are remaining times, delay 1 second and try again
46
- await new Promise((resolve)=>setTimeout(resolve, 1000));
47
- console.log(`Trying again. Number of retries available:${retryTimes - 1}`);
48
- return await fetchWithRetry({
49
- url,
50
- options,
51
- retryTimes: retryTimes - 1,
52
- fallbackUrl
53
- });
54
- }
55
- }
56
- const RetryPlugin = (params)=>({
57
- name: 'retry-plugin',
58
- async fetch (url, options) {
59
- return fetchWithRetry({
60
- url,
61
- options: _extends({}, options, params == null ? void 0 : params.options),
62
- retryTimes: params == null ? void 0 : params.retryTimes,
63
- fallbackUrl: params == null ? void 0 : params.fallbackUrl
64
- });
65
- }
66
- });
67
-
68
- module.exports = RetryPlugin;
@@ -1,66 +0,0 @@
1
- function _extends() {
2
- _extends = Object.assign || function(target) {
3
- for(var i = 1; i < arguments.length; i++){
4
- var source = arguments[i];
5
- for(var key in source){
6
- if (Object.prototype.hasOwnProperty.call(source, key)) {
7
- target[key] = source[key];
8
- }
9
- }
10
- }
11
- return target;
12
- };
13
- return _extends.apply(this, arguments);
14
- }
15
- const defaultRetries = 3;
16
- async function fetchWithRetry({ url, options = {}, retryTimes = defaultRetries, fallbackUrl = '' }) {
17
- try {
18
- const response = await fetch(url, options);
19
- // To prevent the response object from being read multiple times and causing errors, clone it
20
- const responseClone = response.clone();
21
- // Network error
22
- if (!response.ok) {
23
- throw new Error(`Server error:${response.status}`);
24
- }
25
- // parse json error
26
- await responseClone.json().catch((error)=>{
27
- throw new Error(`Json parse error: ${error}, url is: ${url}`);
28
- });
29
- return response;
30
- } catch (error) {
31
- if (retryTimes <= 0) {
32
- console.log(`>>>>>>>>> retry failed after ${defaultRetries} times for url: ${url}, now will try fallbackUrl url: ${fallbackUrl} <<<<<<<<<`);
33
- if (fallbackUrl && fallbackUrl !== url) {
34
- return fetchWithRetry({
35
- url: fallbackUrl,
36
- options,
37
- retryTimes: 1,
38
- fallbackUrl
39
- });
40
- }
41
- throw new Error('The request failed three times and has now been abandoned');
42
- }
43
- // If there are remaining times, delay 1 second and try again
44
- await new Promise((resolve)=>setTimeout(resolve, 1000));
45
- console.log(`Trying again. Number of retries available:${retryTimes - 1}`);
46
- return await fetchWithRetry({
47
- url,
48
- options,
49
- retryTimes: retryTimes - 1,
50
- fallbackUrl
51
- });
52
- }
53
- }
54
- const RetryPlugin = (params)=>({
55
- name: 'retry-plugin',
56
- async fetch (url, options) {
57
- return fetchWithRetry({
58
- url,
59
- options: _extends({}, options, params == null ? void 0 : params.options),
60
- retryTimes: params == null ? void 0 : params.retryTimes,
61
- fallbackUrl: params == null ? void 0 : params.fallbackUrl
62
- });
63
- }
64
- });
65
-
66
- export { RetryPlugin as default };
@@ -1,9 +0,0 @@
1
- import { FederationRuntimePlugin } from '../type/plugin';
2
- interface FetchWithRetryOptions {
3
- url: string;
4
- options?: RequestInit;
5
- retryTimes?: number;
6
- fallbackUrl?: string;
7
- }
8
- declare const RetryPlugin: (params?: Omit<FetchWithRetryOptions, 'url'>) => FederationRuntimePlugin;
9
- export default RetryPlugin;