@module-federation/runtime
Advanced tools
Comparing version 0.0.0-next-20240902023803 to 0.0.0-next-20240902075042
'use strict'; | ||
var share = require('./share.cjs.js'); | ||
require('@swc/helpers/_/_extends'); | ||
require('@swc/helpers/_/_object_without_properties_loose'); | ||
require('@module-federation/sdk'); | ||
@@ -7,0 +5,0 @@ |
import { o as getRegisteredShare, y as getGlobalShareScope, G as Global, I as nativeGlobal, J as resetFederationGlobalInfo, C as getGlobalFederationInstance, F as setGlobalFederationInstance, E as getGlobalFederationConstructor, B as setGlobalFederationConstructor, m as getInfoWithoutType, u as getGlobalSnapshot, K as getTargetSnapshotInfoByModuleInfo, q as getGlobalSnapshotInfoByModuleInfo, t as setGlobalSnapshotInfoByModuleInfo, r as addGlobalSnapshot, c as getRemoteEntryExports, H as registerGlobalPlugins, g as getGlobalHostPlugins, n as getPreloaded, s as setPreloaded } from './share.esm.js'; | ||
import '@swc/helpers/_/_extends'; | ||
import '@swc/helpers/_/_object_without_properties_loose'; | ||
import '@module-federation/sdk'; | ||
@@ -5,0 +3,0 @@ |
@@ -37,7 +37,2 @@ { | ||
}, | ||
"./embedded": { | ||
"types": "./dist/embedded.cjs.d.ts", | ||
"import": "./dist/embedded.esm.js", | ||
"require": "./dist/embedded.cjs.js" | ||
}, | ||
"./*": "./*" | ||
@@ -44,0 +39,0 @@ }, |
@@ -1,2 +0,2 @@ | ||
export * from "./src/plugins/retry-plugin"; | ||
export { default } from "./src/plugins/retry-plugin"; | ||
export * from "./src/plugins/retry-plugin/index"; | ||
export { default } from "./src/plugins/retry-plugin/index"; |
'use strict'; | ||
var _extends = require('@swc/helpers/_/_extends'); | ||
const defaultRetries = 3; | ||
const defaultRetries = 3; | ||
async function fetchWithRetry({ url, options = {}, retryTimes = defaultRetries, fallbackUrl = '' }) { | ||
async function fetchWithRetry({ url, options = {}, retryTimes = defaultRetries, fallback }) { | ||
try { | ||
@@ -22,9 +21,8 @@ const response = await fetch(url, options); | ||
if (retryTimes <= 0) { | ||
console.log(`>>>>>>>>> retry failed after ${defaultRetries} times for url: ${url}, now will try fallbackUrl url: ${fallbackUrl} <<<<<<<<<`); | ||
if (fallbackUrl && fallbackUrl !== url) { | ||
console.log(`>>>>>>>>> retry failed after ${defaultRetries} times for url: ${url}, now will try fallbackUrl url <<<<<<<<<`); | ||
if (fallback && typeof fallback === 'function') { | ||
return fetchWithRetry({ | ||
url: fallbackUrl, | ||
url: fallback(), | ||
options, | ||
retryTimes: 1, | ||
fallbackUrl | ||
retryTimes: 1 | ||
}); | ||
@@ -41,15 +39,109 @@ } | ||
retryTimes: retryTimes - 1, | ||
fallbackUrl | ||
fallback | ||
}); | ||
} | ||
} | ||
const RetryPlugin = (params)=>({ | ||
const defaultCreateScript = (url, attrs)=>{ | ||
let script = document.createElement('script'); | ||
script.src = url; | ||
Object.keys(attrs).forEach((key)=>{ | ||
if (key === 'async' || key === 'defer') { | ||
script[key] = attrs[key]; | ||
// Attributes that do not exist are considered overridden | ||
} else if (!script.getAttribute(key)) { | ||
script.setAttribute(key, attrs[key]); | ||
} | ||
}); | ||
return script; | ||
}; | ||
const getScript = (url, attrs, customCreateScript)=>{ | ||
let script = null; | ||
if (customCreateScript && typeof customCreateScript === 'function') { | ||
script = customCreateScript(url, attrs); | ||
} | ||
if (!script) { | ||
script = defaultCreateScript(url, attrs); | ||
} | ||
return script; | ||
}; | ||
async function loadScript(url, attrs, maxRetries = defaultRetries, retryDelay = 1000, customCreateScript) { | ||
let retries = 0; | ||
function attemptLoad() { | ||
return new Promise((resolve, reject)=>{ | ||
const script = getScript(url, attrs, customCreateScript); | ||
// when the script is successfully loaded, call resolve | ||
script.onload = ()=>{ | ||
console.log('Script loaded successfully.'); | ||
resolve(script); | ||
}; | ||
// when script fails to load, retry after a delay | ||
script.onerror = ()=>{ | ||
if (retries < maxRetries) { | ||
retries++; | ||
console.warn(`Failed to load script. Retrying... (${retries}/${maxRetries})`); | ||
// reload after a delay | ||
setTimeout(()=>{ | ||
resolve(attemptLoad()); // recursively call attemptLoad | ||
}, retryDelay); | ||
} else { | ||
console.error('Failed to load script after maximum retries. the url is:', url); | ||
resolve('Failed to load script after maximum retries.'); | ||
} | ||
}; | ||
// load script | ||
document.head.appendChild(script); | ||
}); | ||
} | ||
return attemptLoad(); // begin the first attempt to load the script | ||
} | ||
function scriptWithRetry({ url, attrs = {}, retryTimes = defaultRetries, customCreateScript }) { | ||
const script = getScript(url, attrs, customCreateScript); | ||
script.onerror = async (event)=>{ | ||
console.warn(`Script load failed, retrying (${retryTimes + 1}/${defaultRetries}): ${url}`); | ||
return await loadScript(url, attrs, retryTimes, 1000, customCreateScript); | ||
}; | ||
return script; | ||
} | ||
function _extends() { | ||
_extends = Object.assign || function(target) { | ||
for(var i = 1; i < arguments.length; i++){ | ||
var source = arguments[i]; | ||
for(var key in source){ | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
return _extends.apply(this, arguments); | ||
} | ||
const RetryPlugin = ({ fetch: fetchOption, script: scriptOption })=>({ | ||
name: 'retry-plugin', | ||
async fetch (url, options) { | ||
return fetchWithRetry({ | ||
url, | ||
options: _extends._({}, options, params == null ? void 0 : params.options), | ||
retryTimes: params == null ? void 0 : params.retryTimes, | ||
fallbackUrl: params == null ? void 0 : params.fallbackUrl | ||
}); | ||
// 如果配置了 fetch 重试规则 | ||
if (fetchOption) { | ||
return fetchWithRetry({ | ||
url: (fetchOption == null ? void 0 : fetchOption.url) || url, | ||
options: _extends({}, options, fetchOption == null ? void 0 : fetchOption.options), | ||
retryTimes: fetchOption == null ? void 0 : fetchOption.retryTimes, | ||
fallback: fetchOption == null ? void 0 : fetchOption.fallback | ||
}); | ||
} | ||
// 未配置 fecth 重试规则,则直接请求 | ||
return fetch(url, options); | ||
}, | ||
createScript ({ url, attrs }) { | ||
const scriptAttrs = (scriptOption == null ? void 0 : scriptOption.attrs) ? _extends({}, attrs, scriptOption.attrs) : attrs; | ||
if (scriptOption) { | ||
return scriptWithRetry({ | ||
url: (scriptOption == null ? void 0 : scriptOption.url) || url, | ||
attrs: scriptAttrs, | ||
retryTimes: scriptOption == null ? void 0 : scriptOption.retryTimes, | ||
customCreateScript: (scriptOption == null ? void 0 : scriptOption.customCreateScript) ? scriptOption.customCreateScript : undefined | ||
}); | ||
} | ||
return {}; | ||
} | ||
@@ -56,0 +148,0 @@ }); |
@@ -1,5 +0,4 @@ | ||
import { _ } from '@swc/helpers/_/_extends'; | ||
const defaultRetries = 3; | ||
const defaultRetries = 3; | ||
async function fetchWithRetry({ url, options = {}, retryTimes = defaultRetries, fallbackUrl = '' }) { | ||
async function fetchWithRetry({ url, options = {}, retryTimes = defaultRetries, fallback }) { | ||
try { | ||
@@ -20,9 +19,8 @@ const response = await fetch(url, options); | ||
if (retryTimes <= 0) { | ||
console.log(`>>>>>>>>> retry failed after ${defaultRetries} times for url: ${url}, now will try fallbackUrl url: ${fallbackUrl} <<<<<<<<<`); | ||
if (fallbackUrl && fallbackUrl !== url) { | ||
console.log(`>>>>>>>>> retry failed after ${defaultRetries} times for url: ${url}, now will try fallbackUrl url <<<<<<<<<`); | ||
if (fallback && typeof fallback === 'function') { | ||
return fetchWithRetry({ | ||
url: fallbackUrl, | ||
url: fallback(), | ||
options, | ||
retryTimes: 1, | ||
fallbackUrl | ||
retryTimes: 1 | ||
}); | ||
@@ -39,15 +37,109 @@ } | ||
retryTimes: retryTimes - 1, | ||
fallbackUrl | ||
fallback | ||
}); | ||
} | ||
} | ||
const RetryPlugin = (params)=>({ | ||
const defaultCreateScript = (url, attrs)=>{ | ||
let script = document.createElement('script'); | ||
script.src = url; | ||
Object.keys(attrs).forEach((key)=>{ | ||
if (key === 'async' || key === 'defer') { | ||
script[key] = attrs[key]; | ||
// Attributes that do not exist are considered overridden | ||
} else if (!script.getAttribute(key)) { | ||
script.setAttribute(key, attrs[key]); | ||
} | ||
}); | ||
return script; | ||
}; | ||
const getScript = (url, attrs, customCreateScript)=>{ | ||
let script = null; | ||
if (customCreateScript && typeof customCreateScript === 'function') { | ||
script = customCreateScript(url, attrs); | ||
} | ||
if (!script) { | ||
script = defaultCreateScript(url, attrs); | ||
} | ||
return script; | ||
}; | ||
async function loadScript(url, attrs, maxRetries = defaultRetries, retryDelay = 1000, customCreateScript) { | ||
let retries = 0; | ||
function attemptLoad() { | ||
return new Promise((resolve, reject)=>{ | ||
const script = getScript(url, attrs, customCreateScript); | ||
// when the script is successfully loaded, call resolve | ||
script.onload = ()=>{ | ||
console.log('Script loaded successfully.'); | ||
resolve(script); | ||
}; | ||
// when script fails to load, retry after a delay | ||
script.onerror = ()=>{ | ||
if (retries < maxRetries) { | ||
retries++; | ||
console.warn(`Failed to load script. Retrying... (${retries}/${maxRetries})`); | ||
// reload after a delay | ||
setTimeout(()=>{ | ||
resolve(attemptLoad()); // recursively call attemptLoad | ||
}, retryDelay); | ||
} else { | ||
console.error('Failed to load script after maximum retries. the url is:', url); | ||
resolve('Failed to load script after maximum retries.'); | ||
} | ||
}; | ||
// load script | ||
document.head.appendChild(script); | ||
}); | ||
} | ||
return attemptLoad(); // begin the first attempt to load the script | ||
} | ||
function scriptWithRetry({ url, attrs = {}, retryTimes = defaultRetries, customCreateScript }) { | ||
const script = getScript(url, attrs, customCreateScript); | ||
script.onerror = async (event)=>{ | ||
console.warn(`Script load failed, retrying (${retryTimes + 1}/${defaultRetries}): ${url}`); | ||
return await loadScript(url, attrs, retryTimes, 1000, customCreateScript); | ||
}; | ||
return script; | ||
} | ||
function _extends() { | ||
_extends = Object.assign || function(target) { | ||
for(var i = 1; i < arguments.length; i++){ | ||
var source = arguments[i]; | ||
for(var key in source){ | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
return _extends.apply(this, arguments); | ||
} | ||
const RetryPlugin = ({ fetch: fetchOption, script: scriptOption })=>({ | ||
name: 'retry-plugin', | ||
async fetch (url, options) { | ||
return fetchWithRetry({ | ||
url, | ||
options: _({}, options, params == null ? void 0 : params.options), | ||
retryTimes: params == null ? void 0 : params.retryTimes, | ||
fallbackUrl: params == null ? void 0 : params.fallbackUrl | ||
}); | ||
// 如果配置了 fetch 重试规则 | ||
if (fetchOption) { | ||
return fetchWithRetry({ | ||
url: (fetchOption == null ? void 0 : fetchOption.url) || url, | ||
options: _extends({}, options, fetchOption == null ? void 0 : fetchOption.options), | ||
retryTimes: fetchOption == null ? void 0 : fetchOption.retryTimes, | ||
fallback: fetchOption == null ? void 0 : fetchOption.fallback | ||
}); | ||
} | ||
// 未配置 fecth 重试规则,则直接请求 | ||
return fetch(url, options); | ||
}, | ||
createScript ({ url, attrs }) { | ||
const scriptAttrs = (scriptOption == null ? void 0 : scriptOption.attrs) ? _extends({}, attrs, scriptOption.attrs) : attrs; | ||
if (scriptOption) { | ||
return scriptWithRetry({ | ||
url: (scriptOption == null ? void 0 : scriptOption.url) || url, | ||
attrs: scriptAttrs, | ||
retryTimes: scriptOption == null ? void 0 : scriptOption.retryTimes, | ||
customCreateScript: (scriptOption == null ? void 0 : scriptOption.customCreateScript) ? scriptOption.customCreateScript : undefined | ||
}); | ||
} | ||
return {}; | ||
} | ||
@@ -54,0 +146,0 @@ }); |
'use strict'; | ||
var _extends = require('@swc/helpers/_/_extends'); | ||
var _object_without_properties_loose = require('@swc/helpers/_/_object_without_properties_loose'); | ||
var sdk = require('@module-federation/sdk'); | ||
@@ -92,2 +90,28 @@ | ||
function _extends$1() { | ||
_extends$1 = Object.assign || function(target) { | ||
for(var i = 1; i < arguments.length; i++){ | ||
var source = arguments[i]; | ||
for(var key in source){ | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
return _extends$1.apply(this, arguments); | ||
} | ||
function _object_without_properties_loose(source, excluded) { | ||
if (source == null) return {}; | ||
var target = {}; | ||
var sourceKeys = Object.keys(source); | ||
var key, i; | ||
for(i = 0; i < sourceKeys.length; i++){ | ||
key = sourceKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; | ||
target[key] = source[key]; | ||
} | ||
return target; | ||
} | ||
const nativeGlobal = (()=>{ | ||
@@ -228,3 +252,3 @@ try { | ||
if ('version' in moduleInfo && moduleInfo['version']) { | ||
const { version } = moduleInfo, resModuleInfo = _object_without_properties_loose._(moduleInfo, [ | ||
const { version } = moduleInfo, resModuleInfo = _object_without_properties_loose(moduleInfo, [ | ||
"version" | ||
@@ -247,3 +271,3 @@ ]); | ||
const addGlobalSnapshot = (moduleInfos)=>{ | ||
nativeGlobal.__FEDERATION__.moduleInfo = _extends._({}, nativeGlobal.__FEDERATION__.moduleInfo, moduleInfos); | ||
nativeGlobal.__FEDERATION__.moduleInfo = _extends$1({}, nativeGlobal.__FEDERATION__.moduleInfo, moduleInfos); | ||
return ()=>{ | ||
@@ -641,2 +665,16 @@ const keys = Object.keys(moduleInfos); | ||
function _extends() { | ||
_extends = Object.assign || function(target) { | ||
for(var i = 1; i < arguments.length; i++){ | ||
var source = arguments[i]; | ||
for(var key in source){ | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
return _extends.apply(this, arguments); | ||
} | ||
function formatShare(shareArgs, from, name, shareStrategy) { | ||
@@ -658,3 +696,3 @@ let get; | ||
var _shareArgs_version, _shareArgs_scope, _shareArgs_strategy; | ||
return _extends._({ | ||
return _extends({ | ||
deps: [], | ||
@@ -665,3 +703,3 @@ useIn: [], | ||
}, shareArgs, { | ||
shareConfig: _extends._({ | ||
shareConfig: _extends({ | ||
requiredVersion: `^${shareArgs.version}`, | ||
@@ -692,3 +730,3 @@ singleton: false, | ||
}, {}); | ||
const shared = _extends._({}, globalOptions.shared); | ||
const shared = _extends({}, globalOptions.shared); | ||
Object.keys(shareInfos).forEach((shareKey)=>{ | ||
@@ -695,0 +733,0 @@ if (!shared[shareKey]) { |
@@ -1,3 +0,1 @@ | ||
import { _ as _$1 } from '@swc/helpers/_/_extends'; | ||
import { _ } from '@swc/helpers/_/_object_without_properties_loose'; | ||
import { isBrowserEnv, isDebugMode } from '@module-federation/sdk'; | ||
@@ -90,2 +88,28 @@ | ||
function _extends$1() { | ||
_extends$1 = Object.assign || function(target) { | ||
for(var i = 1; i < arguments.length; i++){ | ||
var source = arguments[i]; | ||
for(var key in source){ | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
return _extends$1.apply(this, arguments); | ||
} | ||
function _object_without_properties_loose(source, excluded) { | ||
if (source == null) return {}; | ||
var target = {}; | ||
var sourceKeys = Object.keys(source); | ||
var key, i; | ||
for(i = 0; i < sourceKeys.length; i++){ | ||
key = sourceKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; | ||
target[key] = source[key]; | ||
} | ||
return target; | ||
} | ||
const nativeGlobal = (()=>{ | ||
@@ -226,3 +250,3 @@ try { | ||
if ('version' in moduleInfo && moduleInfo['version']) { | ||
const { version } = moduleInfo, resModuleInfo = _(moduleInfo, [ | ||
const { version } = moduleInfo, resModuleInfo = _object_without_properties_loose(moduleInfo, [ | ||
"version" | ||
@@ -245,3 +269,3 @@ ]); | ||
const addGlobalSnapshot = (moduleInfos)=>{ | ||
nativeGlobal.__FEDERATION__.moduleInfo = _$1({}, nativeGlobal.__FEDERATION__.moduleInfo, moduleInfos); | ||
nativeGlobal.__FEDERATION__.moduleInfo = _extends$1({}, nativeGlobal.__FEDERATION__.moduleInfo, moduleInfos); | ||
return ()=>{ | ||
@@ -639,2 +663,16 @@ const keys = Object.keys(moduleInfos); | ||
function _extends() { | ||
_extends = Object.assign || function(target) { | ||
for(var i = 1; i < arguments.length; i++){ | ||
var source = arguments[i]; | ||
for(var key in source){ | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
return _extends.apply(this, arguments); | ||
} | ||
function formatShare(shareArgs, from, name, shareStrategy) { | ||
@@ -656,3 +694,3 @@ let get; | ||
var _shareArgs_version, _shareArgs_scope, _shareArgs_strategy; | ||
return _$1({ | ||
return _extends({ | ||
deps: [], | ||
@@ -663,3 +701,3 @@ useIn: [], | ||
}, shareArgs, { | ||
shareConfig: _$1({ | ||
shareConfig: _extends({ | ||
requiredVersion: `^${shareArgs.version}`, | ||
@@ -690,3 +728,3 @@ singleton: false, | ||
}, {}); | ||
const shared = _$1({}, globalOptions.shared); | ||
const shared = _extends({}, globalOptions.shared); | ||
Object.keys(shareInfos).forEach((shareKey)=>{ | ||
@@ -693,0 +731,0 @@ if (!shared[shareKey]) { |
@@ -1,3 +0,2 @@ | ||
export { isBrowserEnv, isDebugMode } from '@module-federation/sdk'; | ||
export declare function isDevelopmentMode(): boolean; | ||
export declare function getBuilderId(): string; |
{ | ||
"name": "@module-federation/runtime", | ||
"version": "0.0.0-next-20240902023803", | ||
"version": "0.0.0-next-20240902075042", | ||
"author": "zhouxiao <codingzx@gmail.com>", | ||
@@ -37,7 +37,2 @@ "main": "./dist/index.cjs.js", | ||
}, | ||
"./embedded": { | ||
"types": "./dist/embedded.cjs.d.ts", | ||
"import": "./dist/embedded.esm.js", | ||
"require": "./dist/embedded.cjs.js" | ||
}, | ||
"./*": "./*" | ||
@@ -62,4 +57,4 @@ }, | ||
"dependencies": { | ||
"@module-federation/sdk": "0.0.0-next-20240902023803" | ||
"@module-federation/sdk": "0.0.0-next-20240902075042" | ||
} | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
315583
7338
59
12
+ Added@module-federation/sdk@0.0.0-next-20240902075042(transitive)
- Removed@module-federation/sdk@0.0.0-next-20240902023803(transitive)