Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@module-federation/runtime

Package Overview
Dependencies
Maintainers
8
Versions
616
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@module-federation/runtime - npm Package Compare versions

Comparing version 0.0.0-next-20240904030559 to 0.0.0-next-20240905014927

dist/embedded.cjs.d.ts

2

dist/helpers.cjs.js
'use strict';
var share = require('./share.cjs.js');
require('@swc/helpers/_/_extends');
require('@swc/helpers/_/_object_without_properties_loose');
require('@module-federation/sdk');

@@ -5,0 +7,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';

@@ -3,0 +5,0 @@

@@ -37,2 +37,7 @@ {

},
"./embedded": {
"types": "./dist/embedded.cjs.d.ts",
"import": "./dist/embedded.esm.js",
"require": "./dist/embedded.cjs.js"
},
"./*": "./*"

@@ -39,0 +44,0 @@ },

4

dist/retry-plugin.cjs.d.ts

@@ -1,2 +0,2 @@

export * from "./src/plugins/retry-plugin/index";
export { default } from "./src/plugins/retry-plugin/index";
export * from "./src/plugins/retry-plugin";
export { default } from "./src/plugins/retry-plugin";
'use strict';
var _extends = require('@swc/helpers/_/_extends');
const defaultRetries = 3;
const defaultRetryDelay = 1000;
async function fetchWithRetry({ url, options = {}, retryTimes = defaultRetries, retryDelay = defaultRetryDelay, fallback }) {
async function fetchWithRetry({ url, options = {}, retryTimes = defaultRetries, fallbackUrl = '' }) {
try {

@@ -22,153 +22,33 @@ const response = await fetch(url, options);

if (retryTimes <= 0) {
console.log(`>>>>>>>>> retry failed after ${retryTimes} times for url: ${url}, now will try fallbackUrl url <<<<<<<<<`);
if (fallback && typeof fallback === 'function') {
console.log(`>>>>>>>>> retry failed after ${defaultRetries} times for url: ${url}, now will try fallbackUrl url: ${fallbackUrl} <<<<<<<<<`);
if (fallbackUrl && fallbackUrl !== url) {
return fetchWithRetry({
url: fallback(),
url: fallbackUrl,
options,
retryTimes: 0,
retryDelay: 0
retryTimes: 1,
fallbackUrl
});
}
if (error instanceof Error && error.message.includes('Json parse error')) {
throw error;
}
throw new Error('The request failed three times and has now been abandoned');
} else {
// If there are remaining times, delay 1 second and try again
retryDelay > 0 && await new Promise((resolve)=>setTimeout(resolve, retryDelay));
console.log(`Trying again. Number of retries available:${retryTimes - 1}`);
return await fetchWithRetry({
url,
options,
retryTimes: retryTimes - 1,
retryDelay,
fallback
});
}
}
}
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 = defaultRetryDelay, 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 = ()=>{
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
retryDelay > 0 && setTimeout(()=>{
resolve(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);
// If there are remaining times, delay 1 second and try again
await new Promise((resolve)=>setTimeout(resolve, 1000));
console.log(`Trying again. Number of retries available:${retryTimes - 1}`);
return await fetchWithRetry({
url,
options,
retryTimes: retryTimes - 1,
fallbackUrl
});
}
return attemptLoad();
}
function scriptWithRetry({ url, attrs = {}, retryTimes = defaultRetries, retryDelay = defaultRetryDelay, 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, retryDelay, 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 })=>({
const RetryPlugin = (params)=>({
name: 'retry-plugin',
async fetch (url, options) {
// if fetch retry rule is configured
if (fetchOption) {
if (fetchOption.url) {
if (url === (fetchOption == null ? void 0 : fetchOption.url)) {
return fetchWithRetry({
url,
options,
retryTimes: fetchOption == null ? void 0 : fetchOption.retryTimes,
fallback: fetchOption == null ? void 0 : fetchOption.fallback
});
}
} else {
return fetchWithRetry({
url,
options: _extends({}, options, fetchOption == null ? void 0 : fetchOption.options),
retryTimes: fetchOption == null ? void 0 : fetchOption.retryTimes,
fallback: fetchOption == null ? void 0 : fetchOption.fallback
});
}
}
// return default fetch
return fetch(url, options);
},
createScript ({ url, attrs }) {
const scriptAttrs = (scriptOption == null ? void 0 : scriptOption.attrs) ? _extends({}, attrs, scriptOption.attrs) : attrs;
if (scriptOption) {
if (scriptOption == null ? void 0 : scriptOption.url) {
if (url === (scriptOption == null ? void 0 : scriptOption.url)) {
return scriptWithRetry({
url: scriptOption == null ? void 0 : scriptOption.url,
attrs: scriptAttrs,
retryTimes: scriptOption == null ? void 0 : scriptOption.retryTimes,
customCreateScript: (scriptOption == null ? void 0 : scriptOption.customCreateScript) ? scriptOption.customCreateScript : undefined
});
}
} else {
return scriptWithRetry({
url,
attrs: scriptAttrs,
retryTimes: scriptOption == null ? void 0 : scriptOption.retryTimes,
customCreateScript: (scriptOption == null ? void 0 : scriptOption.customCreateScript) ? scriptOption.customCreateScript : undefined
});
}
}
return {};
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
});
}

@@ -175,0 +55,0 @@ });

@@ -0,5 +1,5 @@

import { _ } from '@swc/helpers/_/_extends';
const defaultRetries = 3;
const defaultRetryDelay = 1000;
async function fetchWithRetry({ url, options = {}, retryTimes = defaultRetries, retryDelay = defaultRetryDelay, fallback }) {
async function fetchWithRetry({ url, options = {}, retryTimes = defaultRetries, fallbackUrl = '' }) {
try {

@@ -20,153 +20,33 @@ const response = await fetch(url, options);

if (retryTimes <= 0) {
console.log(`>>>>>>>>> retry failed after ${retryTimes} times for url: ${url}, now will try fallbackUrl url <<<<<<<<<`);
if (fallback && typeof fallback === 'function') {
console.log(`>>>>>>>>> retry failed after ${defaultRetries} times for url: ${url}, now will try fallbackUrl url: ${fallbackUrl} <<<<<<<<<`);
if (fallbackUrl && fallbackUrl !== url) {
return fetchWithRetry({
url: fallback(),
url: fallbackUrl,
options,
retryTimes: 0,
retryDelay: 0
retryTimes: 1,
fallbackUrl
});
}
if (error instanceof Error && error.message.includes('Json parse error')) {
throw error;
}
throw new Error('The request failed three times and has now been abandoned');
} else {
// If there are remaining times, delay 1 second and try again
retryDelay > 0 && await new Promise((resolve)=>setTimeout(resolve, retryDelay));
console.log(`Trying again. Number of retries available:${retryTimes - 1}`);
return await fetchWithRetry({
url,
options,
retryTimes: retryTimes - 1,
retryDelay,
fallback
});
}
}
}
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 = defaultRetryDelay, 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 = ()=>{
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
retryDelay > 0 && setTimeout(()=>{
resolve(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);
// If there are remaining times, delay 1 second and try again
await new Promise((resolve)=>setTimeout(resolve, 1000));
console.log(`Trying again. Number of retries available:${retryTimes - 1}`);
return await fetchWithRetry({
url,
options,
retryTimes: retryTimes - 1,
fallbackUrl
});
}
return attemptLoad();
}
function scriptWithRetry({ url, attrs = {}, retryTimes = defaultRetries, retryDelay = defaultRetryDelay, 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, retryDelay, 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 })=>({
const RetryPlugin = (params)=>({
name: 'retry-plugin',
async fetch (url, options) {
// if fetch retry rule is configured
if (fetchOption) {
if (fetchOption.url) {
if (url === (fetchOption == null ? void 0 : fetchOption.url)) {
return fetchWithRetry({
url,
options,
retryTimes: fetchOption == null ? void 0 : fetchOption.retryTimes,
fallback: fetchOption == null ? void 0 : fetchOption.fallback
});
}
} else {
return fetchWithRetry({
url,
options: _extends({}, options, fetchOption == null ? void 0 : fetchOption.options),
retryTimes: fetchOption == null ? void 0 : fetchOption.retryTimes,
fallback: fetchOption == null ? void 0 : fetchOption.fallback
});
}
}
// return default fetch
return fetch(url, options);
},
createScript ({ url, attrs }) {
const scriptAttrs = (scriptOption == null ? void 0 : scriptOption.attrs) ? _extends({}, attrs, scriptOption.attrs) : attrs;
if (scriptOption) {
if (scriptOption == null ? void 0 : scriptOption.url) {
if (url === (scriptOption == null ? void 0 : scriptOption.url)) {
return scriptWithRetry({
url: scriptOption == null ? void 0 : scriptOption.url,
attrs: scriptAttrs,
retryTimes: scriptOption == null ? void 0 : scriptOption.retryTimes,
customCreateScript: (scriptOption == null ? void 0 : scriptOption.customCreateScript) ? scriptOption.customCreateScript : undefined
});
}
} else {
return scriptWithRetry({
url,
attrs: scriptAttrs,
retryTimes: scriptOption == null ? void 0 : scriptOption.retryTimes,
customCreateScript: (scriptOption == null ? void 0 : scriptOption.customCreateScript) ? scriptOption.customCreateScript : undefined
});
}
}
return {};
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
});
}

@@ -173,0 +53,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');

@@ -90,28 +92,2 @@

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 = (()=>{

@@ -252,3 +228,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"

@@ -271,3 +247,3 @@ ]);

const addGlobalSnapshot = (moduleInfos)=>{
nativeGlobal.__FEDERATION__.moduleInfo = _extends$1({}, nativeGlobal.__FEDERATION__.moduleInfo, moduleInfos);
nativeGlobal.__FEDERATION__.moduleInfo = _extends._({}, nativeGlobal.__FEDERATION__.moduleInfo, moduleInfos);
return ()=>{

@@ -665,16 +641,2 @@ 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) {

@@ -696,3 +658,3 @@ let get;

var _shareArgs_version, _shareArgs_scope, _shareArgs_strategy;
return _extends({
return _extends._({
deps: [],

@@ -703,3 +665,3 @@ useIn: [],

}, shareArgs, {
shareConfig: _extends({
shareConfig: _extends._({
requiredVersion: `^${shareArgs.version}`,

@@ -730,3 +692,3 @@ singleton: false,

}, {});
const shared = _extends({}, globalOptions.shared);
const shared = _extends._({}, globalOptions.shared);
Object.keys(shareInfos).forEach((shareKey)=>{

@@ -733,0 +695,0 @@ if (!shared[shareKey]) {

@@ -0,1 +1,3 @@

import { _ as _$1 } from '@swc/helpers/_/_extends';
import { _ } from '@swc/helpers/_/_object_without_properties_loose';
import { isBrowserEnv, isDebugMode } from '@module-federation/sdk';

@@ -88,28 +90,2 @@

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 = (()=>{

@@ -250,3 +226,3 @@ try {

if ('version' in moduleInfo && moduleInfo['version']) {
const { version } = moduleInfo, resModuleInfo = _object_without_properties_loose(moduleInfo, [
const { version } = moduleInfo, resModuleInfo = _(moduleInfo, [
"version"

@@ -269,3 +245,3 @@ ]);

const addGlobalSnapshot = (moduleInfos)=>{
nativeGlobal.__FEDERATION__.moduleInfo = _extends$1({}, nativeGlobal.__FEDERATION__.moduleInfo, moduleInfos);
nativeGlobal.__FEDERATION__.moduleInfo = _$1({}, nativeGlobal.__FEDERATION__.moduleInfo, moduleInfos);
return ()=>{

@@ -663,16 +639,2 @@ 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) {

@@ -694,3 +656,3 @@ let get;

var _shareArgs_version, _shareArgs_scope, _shareArgs_strategy;
return _extends({
return _$1({
deps: [],

@@ -701,3 +663,3 @@ useIn: [],

}, shareArgs, {
shareConfig: _extends({
shareConfig: _$1({
requiredVersion: `^${shareArgs.version}`,

@@ -728,3 +690,3 @@ singleton: false,

}, {});
const shared = _extends({}, globalOptions.shared);
const shared = _$1({}, globalOptions.shared);
Object.keys(shareInfos).forEach((shareKey)=>{

@@ -731,0 +693,0 @@ if (!shared[shareKey]) {

@@ -0,2 +1,3 @@

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-20240904030559",
"version": "0.0.0-next-20240905014927",
"author": "zhouxiao <codingzx@gmail.com>",

@@ -37,2 +37,7 @@ "main": "./dist/index.cjs.js",

},
"./embedded": {
"types": "./dist/embedded.cjs.d.ts",
"import": "./dist/embedded.esm.js",
"require": "./dist/embedded.cjs.js"
},
"./*": "./*"

@@ -57,4 +62,4 @@ },

"dependencies": {
"@module-federation/sdk": "0.0.0-next-20240904030559"
"@module-federation/sdk": "0.0.0-next-20240905014927"
}
}

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc