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-next-20240102063242 to 0.0.0-next-20240103032717

142

dist/index.cjs.js
'use strict';
var runtime = require('@module-federation/runtime');
var sdk = require('@module-federation/sdk');
var constant = require('./constant.cjs.js');

@@ -27,13 +25,4 @@ function _interopNamespace(e) {

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

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

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

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

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

@@ -105,7 +96,5 @@ var onFactory = function(factory) {

try {
var remoteName = sdk.decodeName(remoteInfos[0].name, constant.ENCODE_NAME_PREFIX);
var remoteModuleName = remoteName + data[1].slice(1);
var remoteModuleName = data[4] + data[1].slice(1);
return webpackRequire.federation.instance.loadRemote(remoteModuleName, {
loadFactory: false,
from: "build"
loadFactory: false
});

@@ -116,5 +105,2 @@ } catch (error) {

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

@@ -129,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)) {

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

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 (!constant.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);
}

@@ -267,36 +216,2 @@

function isLegacyHost(shareScope) {
if ("version" in shareScope && typeof shareScope["version"] !== "object") {
return true;
}
if ("region" in shareScope && typeof shareScope["region"] !== "object") {
return true;
}
return false;
}
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: []
});
if (isLegacyHost(shareScope)) {
var prevShareScope = globalThis.__FEDERATION__.__SHARE__["default"];
if (prevShareScope) {
webpackRequire.federation.instance.initShareScopeMap(name, prevShareScope);
}
} else {
webpackRequire.federation.instance.initShareScopeMap(name, shareScope);
}
webpackRequire.S[name] = shareScope;
if (webpackRequire.federation.attachShareScopeMap) {
webpackRequire.federation.attachShareScopeMap(webpackRequire);
}
// @ts-ignore
return webpackRequire.I(name, initScope);
}
var federation = {

@@ -311,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';
import { decodeName } from '@module-federation/sdk';
import { ENCODE_NAME_PREFIX, FEDERATION_SUPPORTED_TYPES } from './constant.esm.js';
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 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)) {

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

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

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

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

@@ -82,7 +73,5 @@ var onFactory = function(factory) {

try {
var remoteName = decodeName(remoteInfos[0].name, ENCODE_NAME_PREFIX);
var remoteModuleName = remoteName + data[1].slice(1);
var remoteModuleName = data[4] + data[1].slice(1);
return webpackRequire.federation.instance.loadRemote(remoteModuleName, {
loadFactory: false,
from: "build"
loadFactory: false
});

@@ -93,5 +82,2 @@ } catch (error) {

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

@@ -106,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)) {

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

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);
}

@@ -244,36 +193,2 @@

function isLegacyHost(shareScope) {
if ("version" in shareScope && typeof shareScope["version"] !== "object") {
return true;
}
if ("region" in shareScope && typeof shareScope["region"] !== "object") {
return true;
}
return false;
}
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: []
});
if (isLegacyHost(shareScope)) {
var prevShareScope = globalThis.__FEDERATION__.__SHARE__["default"];
if (prevShareScope) {
webpackRequire.federation.instance.initShareScopeMap(name, prevShareScope);
}
} else {
webpackRequire.federation.instance.initShareScopeMap(name, shareScope);
}
webpackRequire.S[name] = shareScope;
if (webpackRequire.federation.attachShareScopeMap) {
webpackRequire.federation.attachShareScopeMap(webpackRequire);
}
// @ts-ignore
return webpackRequire.I(name, initScope);
}
var federation = {

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

S: {},
installInitialConsumes: installInitialConsumes,
initContainerEntry: initContainerEntry
},
attachShareScopeMap: attachShareScopeMap,
bundlerRuntimeOptions: {}
installInitialConsumes: installInitialConsumes
}
};
export { federation as default };

@@ -21,28 +21,6 @@ {

"module": "./index.esm.js",
"types": "./dist/index.cjs.d.ts",
"types": "./index.cjs.d.ts",
"dependencies": {
"@module-federation/runtime": "workspace:*",
"@module-federation/sdk": "workspace:*"
},
"exports": {
".": {
"import": "./dist/index.esm.js",
"require": "./dist/index.cjs.js"
},
"./constant": {
"import": "./dist/constant.esm.js",
"require": "./dist/constant.cjs.js"
},
"./*": "./*"
},
"typesVersions": {
"*": {
".": [
"./dist/index.cjs.d.ts"
],
"constant": [
"./dist/constant.cjs.d.ts"
]
}
"@module-federation/runtime": "workspace:*"
}
}
import { Federation } from './types';
export * from './types';
declare const federation: Federation;
export default federation;

4

dist/src/initializeSharing.d.ts

@@ -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,7 +51,2 @@ federation: Federation;

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

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

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

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

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

@@ -105,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 {};
{
"public": true,
"name": "@module-federation/webpack-bundler-runtime",
"version": "0.0.0-next-20240102063242",
"version": "0.0.0-next-20240103032717",
"license": "MIT",

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

"author": "zhanghang <hanric.zhang@gmail.com>",
"main": "./dist/index.cjs.js",
"module": "./dist/index.esm.js",
"types": "./dist/index.cjs.d.ts",
"main": "./index.cjs.js",
"module": "./index.esm.js",
"types": "./index.cjs.d.ts",
"dependencies": {
"@module-federation/runtime": "0.0.0-next-20240102063242",
"@module-federation/sdk": "0.0.0-next-20240102063242"
},
"exports": {
".": {
"import": "./dist/index.esm.js",
"require": "./dist/index.cjs.js"
},
"./constant": {
"import": "./dist/constant.esm.js",
"require": "./dist/constant.cjs.js"
},
"./*": "./*"
},
"typesVersions": {
"*": {
".": [
"./dist/index.cjs.d.ts"
],
"constant": [
"./dist/constant.cjs.d.ts"
]
}
"@module-federation/runtime": "0.0.0-next-20240103032717"
}
}
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