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
684
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-1702465394222 to 0.0.0-canary-1702467548140

src/proxyShareScopeMap.d.ts

189

index.cjs.js

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

function attachShareScopeMap(webpackRequire) {
if (!webpackRequire.S || webpackRequire.federation.hasAttachShareScopeMap || !webpackRequire.federation.instance || !webpackRequire.federation.instance.shareScopeMap) {
return;
}
webpackRequire.S = webpackRequire.federation.instance.shareScopeMap;
webpackRequire.federation.hasAttachShareScopeMap = 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, idToRemoteMap = options.idToRemoteMap;
attachShareScopeMap(webpackRequire);
var chunkId = options.chunkId, promises = options.promises, chunkMapping = options.chunkMapping, idToExternalAndNameMapping = options.idToExternalAndNameMapping, webpackRequire = options.webpackRequire;
if (webpackRequire.o(chunkMapping, chunkId)) {

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

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

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

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

@@ -147,20 +94,5 @@ 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 remoteName = remoteInfos[0].remoteName;
if (!remoteName) {
var _extractUrlAndGlobal = _sliced_to_array(extractUrlAndGlobal(remoteInfos[0].request), 2), _entryUrl = _extractUrlAndGlobal[0], globalName = _extractUrlAndGlobal[1];
remoteName = globalName;
}
var remoteModuleName = remoteName + data[1].slice(1);
var remoteModuleName = data[4] + data[1].slice(1);
return webpackRequire.federation.instance.loadRemote(remoteModuleName, {

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

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

@@ -186,5 +115,21 @@ 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) {
var chunkId = options.chunkId, promises = options.promises, chunkMapping = options.chunkMapping, installedModules = options.installedModules, moduleToHandlerMapping = options.moduleToHandlerMapping, webpackRequire = options.webpackRequire;
attachShareScopeMap(webpackRequire);
proxyShareScopeMap(webpackRequire);
if (webpackRequire.o(chunkMapping, chunkId)) {

@@ -234,61 +179,4 @@ chunkMapping[chunkId].forEach(function(id) {

var FEDERATION_SUPPORTED_TYPES = [
"script"
];
function initializeSharing(param) {
var shareScopeName = param.shareScopeName, webpackRequire = param.webpackRequire, initPromises = param.initPromises, initTokens = param.initTokens, initScope = param.initScope;
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);
attachShareScopeMap(webpackRequire);
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;
});
function initializeSharing(shareScopeName, webpackRequire) {
return webpackRequire.federation.instance.initializeSharing(shareScopeName);
}

@@ -328,24 +216,2 @@

function initContainerEntry(options) {
var webpackRequire = options.webpackRequire, shareScope = options.shareScope, initScope = options.initScope, shareScopeKey = options.shareScopeKey;
if (!webpackRequire.S) return;
if (!webpackRequire.federation || !webpackRequire.federation.instance || !webpackRequire.federation.initOptions) return;
var name = shareScopeKey || "default";
webpackRequire.federation.instance.initOptions({
name: webpackRequire.federation.initOptions.name,
remotes: []
});
webpackRequire.federation.instance.initShareScopeMap(name, shareScope);
var prevShareScope = globalThis.__FEDERATION__.__SHARE__["default"];
if (prevShareScope) {
webpackRequire.federation.instance.initShareScopeMap(name, prevShareScope);
}
webpackRequire.S[name] = shareScope;
if (webpackRequire.federation.attachShareScopeMap) {
webpackRequire.federation.attachShareScopeMap(webpackRequire);
}
// @ts-ignore
return webpackRequire.I(name, initScope);
}
var federation = {

@@ -360,9 +226,6 @@ runtime: runtime__namespace,

S: {},
installInitialConsumes: installInitialConsumes,
initContainerEntry: initContainerEntry
},
attachShareScopeMap: attachShareScopeMap,
bundlerRuntimeOptions: {}
installInitialConsumes: installInitialConsumes
}
};
module.exports = federation;
import * as runtime from '@module-federation/runtime';
function attachShareScopeMap(webpackRequire) {
if (!webpackRequire.S || webpackRequire.federation.hasAttachShareScopeMap || !webpackRequire.federation.instance || !webpackRequire.federation.instance.shareScopeMap) {
return;
}
webpackRequire.S = webpackRequire.federation.instance.shareScopeMap;
webpackRequire.federation.hasAttachShareScopeMap = 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, idToRemoteMap = options.idToRemoteMap;
attachShareScopeMap(webpackRequire);
var chunkId = options.chunkId, promises = options.promises, chunkMapping = options.chunkMapping, idToExternalAndNameMapping = options.idToExternalAndNameMapping, webpackRequire = options.webpackRequire;
if (webpackRequire.o(chunkMapping, chunkId)) {

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

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

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

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

@@ -124,20 +71,5 @@ 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 remoteName = remoteInfos[0].remoteName;
if (!remoteName) {
var _extractUrlAndGlobal = _sliced_to_array(extractUrlAndGlobal(remoteInfos[0].request), 2), _entryUrl = _extractUrlAndGlobal[0], globalName = _extractUrlAndGlobal[1];
remoteName = globalName;
}
var remoteModuleName = remoteName + data[1].slice(1);
var remoteModuleName = data[4] + data[1].slice(1);
return webpackRequire.federation.instance.loadRemote(remoteModuleName, {

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

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

@@ -163,5 +92,21 @@ 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) {
var chunkId = options.chunkId, promises = options.promises, chunkMapping = options.chunkMapping, installedModules = options.installedModules, moduleToHandlerMapping = options.moduleToHandlerMapping, webpackRequire = options.webpackRequire;
attachShareScopeMap(webpackRequire);
proxyShareScopeMap(webpackRequire);
if (webpackRequire.o(chunkMapping, chunkId)) {

@@ -211,61 +156,4 @@ chunkMapping[chunkId].forEach(function(id) {

var FEDERATION_SUPPORTED_TYPES = [
"script"
];
function initializeSharing(param) {
var shareScopeName = param.shareScopeName, webpackRequire = param.webpackRequire, initPromises = param.initPromises, initTokens = param.initTokens, initScope = param.initScope;
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);
attachShareScopeMap(webpackRequire);
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;
});
function initializeSharing(shareScopeName, webpackRequire) {
return webpackRequire.federation.instance.initializeSharing(shareScopeName);
}

@@ -305,24 +193,2 @@

function initContainerEntry(options) {
var webpackRequire = options.webpackRequire, shareScope = options.shareScope, initScope = options.initScope, shareScopeKey = options.shareScopeKey;
if (!webpackRequire.S) return;
if (!webpackRequire.federation || !webpackRequire.federation.instance || !webpackRequire.federation.initOptions) return;
var name = shareScopeKey || "default";
webpackRequire.federation.instance.initOptions({
name: webpackRequire.federation.initOptions.name,
remotes: []
});
webpackRequire.federation.instance.initShareScopeMap(name, shareScope);
var prevShareScope = globalThis.__FEDERATION__.__SHARE__["default"];
if (prevShareScope) {
webpackRequire.federation.instance.initShareScopeMap(name, prevShareScope);
}
webpackRequire.S[name] = shareScope;
if (webpackRequire.federation.attachShareScopeMap) {
webpackRequire.federation.attachShareScopeMap(webpackRequire);
}
// @ts-ignore
return webpackRequire.I(name, initScope);
}
var federation = {

@@ -337,9 +203,6 @@ runtime: runtime,

S: {},
installInitialConsumes: installInitialConsumes,
initContainerEntry: initContainerEntry
},
attachShareScopeMap: attachShareScopeMap,
bundlerRuntimeOptions: {}
installInitialConsumes: installInitialConsumes
}
};
export { federation as default };
{
"public": true,
"name": "@module-federation/webpack-bundler-runtime",
"version": "0.0.0-canary-1702465394222",
"version": "0.0.0-canary-1702467548140",
"license": "MIT",

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

"dependencies": {
"@module-federation/runtime": "0.0.0-canary-1702465394222"
"@module-federation/runtime": "1.0.1-canary.1"
},
"peerDependencies": {}
}
import { Federation } from './types';
export * from './types';
declare const federation: Federation;
export default federation;

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

import { InitializeSharingOptions } from './types';
export declare function initializeSharing({ shareScopeName, webpackRequire, initPromises, initTokens, initScope, }: InitializeSharingOptions): Promise<boolean> | boolean | void;
import { WebpackRequire } from './types';
export declare function initializeSharing(shareScopeName: string, webpackRequire: WebpackRequire): Promise<boolean> | boolean;
import * as runtime from '@module-federation/runtime';
import { initializeSharing } from './initializeSharing';
import { attachShareScopeMap } from './attachShareScopeMap';
import { initContainerEntry } from './initContainerEntry';
type ExcludeUndefined<T> = T extends undefined ? never : T;

@@ -13,11 +11,2 @@ type NonUndefined<T = Shared> = ExcludeUndefined<T>;

type InferredModule = InferModule<ModuleCache>;
export type ShareScopeMap = runtime.FederationHost['shareScopeMap'];
type InitToken = Record<string, Record<string, any>>;
export interface InitializeSharingOptions {
shareScopeName: string;
webpackRequire: WebpackRequire;
initPromises: Record<string, Promise<boolean> | boolean>;
initTokens: InitToken;
initScope: InitToken[];
}
export type RemoteEntryExports = NonUndefined<InferredModule['remoteEntryExports']>;

@@ -31,3 +20,9 @@ type ExtractInitParameters<T> = T extends {

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

@@ -42,3 +37,3 @@ p?: Promise<any> | number;

c: Record<string, any>;
I: (scopeName: string, initScope?: InitializeSharingOptions['initScope']) => ReturnType<typeof initializeSharing>;
I: typeof initializeSharing;
S?: InferredGlobalShareScope;

@@ -56,8 +51,2 @@ federation: Federation;

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

@@ -68,3 +57,2 @@ chunkId: string | number;

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

@@ -91,8 +79,2 @@ }

}
export interface InitContainerEntryOptions {
shareScope: ShareScopeMap[string];
shareScopeKey: string;
webpackRequire: WebpackRequire;
initScope?: InitializeSharingOptions['initScope'];
}
export interface Federation {

@@ -106,13 +88,7 @@ runtime?: typeof runtime;

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