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

@module-federation/webpack-bundler-runtime

Package Overview
Dependencies
Maintainers
8
Versions
669
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@module-federation/webpack-bundler-runtime - npm Package Compare versions

Comparing version 0.0.0-canary-1701669627295 to 0.0.0-canary-1701680335968

src/constant.d.ts

162

index.cjs.js

@@ -25,4 +25,59 @@ 'use strict';

function proxyShareScopeMap(webpackRequire) {
if (!webpackRequire.S || webpackRequire.federation.hasProxyShareScopeMap || !webpackRequire.federation.initOptions || !webpackRequire.federation.initOptions.name) {
return;
}
webpackRequire.S = webpackRequire.g["__FEDERATION__"].__SHARE__[webpackRequire.federation.initOptions.name];
webpackRequire.federation.hasProxyShareScopeMap = true;
}
function _array_like_to_array(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
return arr2;
}
function _array_with_holes(arr) {
if (Array.isArray(arr)) return arr;
}
function _iterable_to_array_limit(arr, i) {
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
if (_i == null) return;
var _arr = [];
var _n = true;
var _d = false;
var _s, _e;
try {
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
_arr.push(_s.value);
if (i && _arr.length === i) break;
}
} catch (err) {
_d = true;
_e = err;
} finally{
try {
if (!_n && _i["return"] != null) _i["return"]();
} finally{
if (_d) throw _e;
}
}
return _arr;
}
function _non_iterable_rest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _sliced_to_array(arr, i) {
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
}
function _unsupported_iterable_to_array(o, minLen) {
if (!o) return;
if (typeof o === "string") return _array_like_to_array(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(n);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
}
function remotes(options) {
var chunkId = options.chunkId, promises = options.promises, chunkMapping = options.chunkMapping, idToExternalAndNameMapping = options.idToExternalAndNameMapping, webpackRequire = options.webpackRequire;
var chunkId = options.chunkId, promises = options.promises, chunkMapping = options.chunkMapping, idToExternalAndNameMapping = options.idToExternalAndNameMapping, webpackRequire = options.webpackRequire, idToRemoteMap = options.idToRemoteMap;
proxyShareScopeMap(webpackRequire);
if (webpackRequire.o(chunkMapping, chunkId)) {

@@ -35,2 +90,3 @@ chunkMapping[chunkId].forEach(function(id) {

var data = idToExternalAndNameMapping[id];
var remoteInfos = idToRemoteMap[id];
// @ts-ignore seems not work

@@ -83,5 +139,2 @@ if (getScope.indexOf(data) >= 0) {

};
var useRuntimeLoad = [
"script"
].includes(data[3]) && data[4];
// eslint-disable-next-line no-var

@@ -94,5 +147,20 @@ var onFactory = function(factory) {

};
var extractUrlAndGlobal = function(urlAndGlobal) {
var index = urlAndGlobal.indexOf("@");
if (index <= 0 || index === urlAndGlobal.length - 1) {
throw new Error('Invalid request "'.concat(urlAndGlobal, '"'));
}
return [
urlAndGlobal.substring(index + 1),
urlAndGlobal.substring(0, index)
];
};
var onRemoteLoaded = function() {
try {
var remoteModuleName = data[4] + data[1].slice(1);
var remoteName = remoteInfos[0].remoteName;
if (!remoteName) {
var _extractUrlAndGlobal = _sliced_to_array(extractUrlAndGlobal(remoteInfos[0].request), 2), globalName = _extractUrlAndGlobal[0], _entryUrl = _extractUrlAndGlobal[1];
remoteName = globalName;
}
var remoteModuleName = remoteName + data[1].slice(1);
return webpackRequire.federation.instance.loadRemote(remoteModuleName, {

@@ -105,2 +173,5 @@ loadFactory: false

};
var useRuntimeLoad = remoteInfos.length === 1 && [
"script"
].includes(remoteInfos[0].externalType) && remoteInfos[0].request;
if (useRuntimeLoad) {

@@ -115,18 +186,2 @@ handleFunction(onRemoteLoaded, data[2], 0, 0, onFactory, 1);

function proxyShareScopeMap(__webpack_require__) {
if (!__webpack_require__.S) {
return;
}
// @ts-ignore FIXME: ideal situation is import type from @module-federation/runtime/type ,but the compile will throw error
__webpack_require__.S = new Proxy(globalThis.__VMOK__.__SHARE__, {
get: function get(target, prop, receiver) {
return globalThis.__VMOK__.__SHARE__[prop];
},
set: function set(target, prop, value) {
globalThis.__VMOK__.__SHARE__[prop] = value;
return true;
}
});
}
function consumes(options) {

@@ -179,4 +234,61 @@ var chunkId = options.chunkId, promises = options.promises, chunkMapping = options.chunkMapping, installedModules = options.installedModules, moduleToHandlerMapping = options.moduleToHandlerMapping, webpackRequire = options.webpackRequire;

function initializeSharing(shareScopeName, webpackRequire) {
return webpackRequire.federation.instance.initializeSharing(shareScopeName);
var FEDERATION_SUPPORTED_TYPES = [
"script"
];
function initializeSharing(param) {
var shareScopeName = param.shareScopeName, webpackRequire = param.webpackRequire, initPromises = param.initPromises, initTokens = param.initTokens, initScope = param.initScope;
proxyShareScopeMap(webpackRequire);
if (!initScope) initScope = [];
// handling circular init calls
var initToken = initTokens[shareScopeName];
if (!initToken) initToken = initTokens[shareScopeName] = {};
if (initScope.indexOf(initToken) >= 0) return;
initScope.push(initToken);
var promise = initPromises[shareScopeName];
if (promise) return promise;
var warn = function(msg) {
return typeof console !== "undefined" && console.warn && console.warn(msg);
};
var initExternal = function(id) {
var handleError = function(err) {
return warn("Initialization of sharing external failed: " + err);
};
try {
var module = webpackRequire(id);
if (!module) return;
var initFn = function(module) {
return module && module.init && module.init(webpackRequire.S[shareScopeName], initScope);
};
if (module.then) return promises.push(module.then(initFn, handleError));
var initResult = initFn(module);
// @ts-ignore
if (initResult && typeof initResult !== "boolean" && initResult.then) // @ts-ignore
return promises.push(initResult["catch"](handleError));
} catch (err) {
handleError(err);
}
};
var promises = webpackRequire.federation.instance.initializeSharing(shareScopeName);
var bundlerRuntimeRemotesOptions = webpackRequire.federation.bundlerRuntimeOptions.remotes;
if (bundlerRuntimeRemotesOptions) {
Object.keys(bundlerRuntimeRemotesOptions.idToRemoteMap).forEach(function(moduleId) {
var info = bundlerRuntimeRemotesOptions.idToRemoteMap[moduleId];
var externalModuleId = bundlerRuntimeRemotesOptions.idToExternalAndNameMapping[moduleId][2];
if (info.length > 1) {
initExternal(externalModuleId);
} else if (info.length === 1) {
var remoteInfo = info[0];
if (!FEDERATION_SUPPORTED_TYPES.includes(remoteInfo.externalType)) {
initExternal(externalModuleId);
}
}
});
}
if (!promises.length) {
return initPromises[shareScopeName] = true;
}
return initPromises[shareScopeName] = Promise.all(promises).then(function() {
return initPromises[shareScopeName] = true;
});
}

@@ -226,5 +338,7 @@

installInitialConsumes: installInitialConsumes
}
},
proxyShareScopeMap: proxyShareScopeMap,
bundlerRuntimeOptions: {}
};
module.exports = federation;
import * as runtime from '@module-federation/runtime';
function proxyShareScopeMap(webpackRequire) {
if (!webpackRequire.S || webpackRequire.federation.hasProxyShareScopeMap || !webpackRequire.federation.initOptions || !webpackRequire.federation.initOptions.name) {
return;
}
webpackRequire.S = webpackRequire.g["__FEDERATION__"].__SHARE__[webpackRequire.federation.initOptions.name];
webpackRequire.federation.hasProxyShareScopeMap = true;
}
function _array_like_to_array(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
return arr2;
}
function _array_with_holes(arr) {
if (Array.isArray(arr)) return arr;
}
function _iterable_to_array_limit(arr, i) {
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
if (_i == null) return;
var _arr = [];
var _n = true;
var _d = false;
var _s, _e;
try {
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
_arr.push(_s.value);
if (i && _arr.length === i) break;
}
} catch (err) {
_d = true;
_e = err;
} finally{
try {
if (!_n && _i["return"] != null) _i["return"]();
} finally{
if (_d) throw _e;
}
}
return _arr;
}
function _non_iterable_rest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _sliced_to_array(arr, i) {
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
}
function _unsupported_iterable_to_array(o, minLen) {
if (!o) return;
if (typeof o === "string") return _array_like_to_array(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(n);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
}
function remotes(options) {
var chunkId = options.chunkId, promises = options.promises, chunkMapping = options.chunkMapping, idToExternalAndNameMapping = options.idToExternalAndNameMapping, webpackRequire = options.webpackRequire;
var chunkId = options.chunkId, promises = options.promises, chunkMapping = options.chunkMapping, idToExternalAndNameMapping = options.idToExternalAndNameMapping, webpackRequire = options.webpackRequire, idToRemoteMap = options.idToRemoteMap;
proxyShareScopeMap(webpackRequire);
if (webpackRequire.o(chunkMapping, chunkId)) {

@@ -12,2 +67,3 @@ chunkMapping[chunkId].forEach(function(id) {

var data = idToExternalAndNameMapping[id];
var remoteInfos = idToRemoteMap[id];
// @ts-ignore seems not work

@@ -60,5 +116,2 @@ if (getScope.indexOf(data) >= 0) {

};
var useRuntimeLoad = [
"script"
].includes(data[3]) && data[4];
// eslint-disable-next-line no-var

@@ -71,5 +124,20 @@ var onFactory = function(factory) {

};
var extractUrlAndGlobal = function(urlAndGlobal) {
var index = urlAndGlobal.indexOf("@");
if (index <= 0 || index === urlAndGlobal.length - 1) {
throw new Error('Invalid request "'.concat(urlAndGlobal, '"'));
}
return [
urlAndGlobal.substring(index + 1),
urlAndGlobal.substring(0, index)
];
};
var onRemoteLoaded = function() {
try {
var remoteModuleName = data[4] + data[1].slice(1);
var remoteName = remoteInfos[0].remoteName;
if (!remoteName) {
var _extractUrlAndGlobal = _sliced_to_array(extractUrlAndGlobal(remoteInfos[0].request), 2), globalName = _extractUrlAndGlobal[0], _entryUrl = _extractUrlAndGlobal[1];
remoteName = globalName;
}
var remoteModuleName = remoteName + data[1].slice(1);
return webpackRequire.federation.instance.loadRemote(remoteModuleName, {

@@ -82,2 +150,5 @@ loadFactory: false

};
var useRuntimeLoad = remoteInfos.length === 1 && [
"script"
].includes(remoteInfos[0].externalType) && remoteInfos[0].request;
if (useRuntimeLoad) {

@@ -92,18 +163,2 @@ handleFunction(onRemoteLoaded, data[2], 0, 0, onFactory, 1);

function proxyShareScopeMap(__webpack_require__) {
if (!__webpack_require__.S) {
return;
}
// @ts-ignore FIXME: ideal situation is import type from @module-federation/runtime/type ,but the compile will throw error
__webpack_require__.S = new Proxy(globalThis.__VMOK__.__SHARE__, {
get: function get(target, prop, receiver) {
return globalThis.__VMOK__.__SHARE__[prop];
},
set: function set(target, prop, value) {
globalThis.__VMOK__.__SHARE__[prop] = value;
return true;
}
});
}
function consumes(options) {

@@ -156,4 +211,61 @@ var chunkId = options.chunkId, promises = options.promises, chunkMapping = options.chunkMapping, installedModules = options.installedModules, moduleToHandlerMapping = options.moduleToHandlerMapping, webpackRequire = options.webpackRequire;

function initializeSharing(shareScopeName, webpackRequire) {
return webpackRequire.federation.instance.initializeSharing(shareScopeName);
var FEDERATION_SUPPORTED_TYPES = [
"script"
];
function initializeSharing(param) {
var shareScopeName = param.shareScopeName, webpackRequire = param.webpackRequire, initPromises = param.initPromises, initTokens = param.initTokens, initScope = param.initScope;
proxyShareScopeMap(webpackRequire);
if (!initScope) initScope = [];
// handling circular init calls
var initToken = initTokens[shareScopeName];
if (!initToken) initToken = initTokens[shareScopeName] = {};
if (initScope.indexOf(initToken) >= 0) return;
initScope.push(initToken);
var promise = initPromises[shareScopeName];
if (promise) return promise;
var warn = function(msg) {
return typeof console !== "undefined" && console.warn && console.warn(msg);
};
var initExternal = function(id) {
var handleError = function(err) {
return warn("Initialization of sharing external failed: " + err);
};
try {
var module = webpackRequire(id);
if (!module) return;
var initFn = function(module) {
return module && module.init && module.init(webpackRequire.S[shareScopeName], initScope);
};
if (module.then) return promises.push(module.then(initFn, handleError));
var initResult = initFn(module);
// @ts-ignore
if (initResult && typeof initResult !== "boolean" && initResult.then) // @ts-ignore
return promises.push(initResult["catch"](handleError));
} catch (err) {
handleError(err);
}
};
var promises = webpackRequire.federation.instance.initializeSharing(shareScopeName);
var bundlerRuntimeRemotesOptions = webpackRequire.federation.bundlerRuntimeOptions.remotes;
if (bundlerRuntimeRemotesOptions) {
Object.keys(bundlerRuntimeRemotesOptions.idToRemoteMap).forEach(function(moduleId) {
var info = bundlerRuntimeRemotesOptions.idToRemoteMap[moduleId];
var externalModuleId = bundlerRuntimeRemotesOptions.idToExternalAndNameMapping[moduleId][2];
if (info.length > 1) {
initExternal(externalModuleId);
} else if (info.length === 1) {
var remoteInfo = info[0];
if (!FEDERATION_SUPPORTED_TYPES.includes(remoteInfo.externalType)) {
initExternal(externalModuleId);
}
}
});
}
if (!promises.length) {
return initPromises[shareScopeName] = true;
}
return initPromises[shareScopeName] = Promise.all(promises).then(function() {
return initPromises[shareScopeName] = true;
});
}

@@ -203,5 +315,7 @@

installInitialConsumes: installInitialConsumes
}
},
proxyShareScopeMap: proxyShareScopeMap,
bundlerRuntimeOptions: {}
};
export { federation as default };

4

package.json
{
"public": true,
"name": "@module-federation/webpack-bundler-runtime",
"version": "0.0.0-canary-1701669627295",
"version": "0.0.0-canary-1701680335968",
"license": "MIT",

@@ -19,5 +19,5 @@ "description": "Module Federation Runtime for webpack",

"dependencies": {
"@module-federation/runtime": "0.0.0-canary-1701669627295"
"@module-federation/runtime": "0.0.0-canary-1701680335968"
},
"peerDependencies": {}
}
import { Federation } from './types';
export * from './types';
declare const federation: Federation;
export default federation;
import { WebpackRequire } from './types';
export declare function initializeSharing(shareScopeName: string, webpackRequire: WebpackRequire): Promise<boolean> | boolean;
type InitToken = Record<string, Record<string, any>>;
interface Options {
shareScopeName: string;
webpackRequire: WebpackRequire;
initPromises: Record<string, Promise<boolean> | boolean>;
initTokens: InitToken;
initScope: InitToken[];
}
export declare function initializeSharing({ shareScopeName, webpackRequire, initPromises, initTokens, initScope, }: Options): Promise<boolean> | boolean | void;
export {};
import { WebpackRequire } from './types';
export declare function proxyShareScopeMap(__webpack_require__: WebpackRequire): void;
export declare function proxyShareScopeMap(webpackRequire: WebpackRequire): void;
import * as runtime from '@module-federation/runtime';
import { initializeSharing } from './initializeSharing';
import { proxyShareScopeMap } from './proxyShareScopeMap';
type ExcludeUndefined<T> = T extends undefined ? never : T;

@@ -19,9 +20,3 @@ type NonUndefined<T = Shared> = ExcludeUndefined<T>;

};
type IdToExternalAndNameMappingItem = [
string,
string,
string | number,
string,
string
];
type IdToExternalAndNameMappingItem = [string, string, string | number];
interface IdToExternalAndNameMappingItemWithPromise extends IdToExternalAndNameMappingItem {

@@ -39,2 +34,3 @@ p?: Promise<any> | number;

federation: Federation;
g: typeof globalThis;
}

@@ -50,2 +46,8 @@ interface ShareInfo {

}
interface IdToRemoteMapItem {
externalType: string;
request: string;
remoteName?: string;
externalModuleId?: string | number;
}
export interface RemotesOptions {

@@ -56,2 +58,3 @@ chunkId: string | number;

idToExternalAndNameMapping: Record<string, IdToExternalAndNameMappingItemWithPromise>;
idToRemoteMap: Record<string, IdToRemoteMapItem[]>;
webpackRequire: WebpackRequire;

@@ -86,7 +89,12 @@ }

consumes: (options: ConsumesOptions) => void;
I: (name: string, webpackRequire: WebpackRequire) => Promise<boolean> | boolean;
I: typeof initializeSharing;
S: InferredGlobalShareScope;
installInitialConsumes: (options: InstallInitialConsumesOptions) => any;
};
bundlerRuntimeOptions: {
remotes?: Exclude<RemotesOptions, 'chunkId' | 'promises'>;
};
proxyShareScopeMap?: typeof proxyShareScopeMap;
hasProxyShareScopeMap?: boolean;
}
export {};
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