Socket
Socket
Sign inDemoInstall

@module-federation/node

Package Overview
Dependencies
Maintainers
5
Versions
617
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@module-federation/node - npm Package Compare versions

Comparing version 0.15.2-rc1.0 to 0.15.2-rc3.0

13

CHANGELOG.md

@@ -5,2 +5,15 @@ # Changelog

## [0.15.2-rc3.0](https://github.com/module-federation/nextjs-mf/compare/node-0.15.2-beta.0...node-0.15.2-rc3.0) (2023-06-09)
## [0.15.2-beta.0](https://github.com/module-federation/nextjs-mf/compare/node-0.15.2-rc1.0...node-0.15.2-beta.0) (2023-05-26)
### Bug Fixes
* Improve chunk correlation ([#936](https://github.com/module-federation/nextjs-mf/issues/936)) ([4dad1eb](https://github.com/module-federation/nextjs-mf/commit/4dad1eb370feacd6ecb4c1726c435d5c579f424d))
## [0.15.2-rc1.0](https://github.com/module-federation/nextjs-mf/compare/node-0.15.2-rc.0...node-0.15.2-rc1.0) (2023-05-25)

@@ -7,0 +20,0 @@

4

package.json
{
"public": true,
"name": "@module-federation/node",
"version": "0.15.2-rc1.0",
"version": "0.15.2-rc3.0",
"main": "src/index.js",

@@ -37,3 +37,3 @@ "exports": {

"node-fetch": "^2.6.7",
"@module-federation/utilities": "1.8.1-rc1.0",
"@module-federation/utilities": "1.8.2-rc3.0",
"webpack-sources": "3.2.3"

@@ -40,0 +40,0 @@ },

@@ -288,14 +288,16 @@ "use strict";

}
let alreadyRun = false;
// This is where the plugin is tapping into the Webpack compilation lifecycle.
// It's listening to the 'thisCompilation' event, which is triggered once for each new compilation.
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
// 'processAssets' is a hook that gets triggered when Webpack has finished the compilation
// and is about to generate the final assets. It allows plugins to do additional processing on the assets.
compilation.hooks.processAssets.tap({
name: PLUGIN_NAME,
stage: compilation.constructor.PROCESS_ASSETS_STAGE_REPORT,
},
// PLUGIN_NAME,
async () => {
const [federationOpts] = federationPlugins.map((federationPlugin) => {
return federationPlugin?._options;
});
}, async () => {
// Extract the options from the federation plugins.
const [federationOpts] = federationPlugins.map((federationPlugin) => federationPlugin?._options);
let container;
// Loop through all entry points and if one matches the name of a federation plugin,
// store the entry point in the 'container' variable.
for (const [name, entry] of compilation.entrypoints) {

@@ -306,42 +308,49 @@ if (container)

}
// If no matching entry point was found, exit the function early.
if (!container)
return;
// Get the chunk associated with the entry point.
container = container?.getEntrypointChunk();
// Get the module associated with the chunk.
const [containerEntryModule] = Array.from(compilation.chunkGraph.getChunkEntryModulesIterable(container));
// Construct an object where the keys are the names of the exposed modules and the values are their options.
const exposedObj = Object.fromEntries(containerEntryModule._exposes);
const moduleMap = {};
for (let mod of compilation.modules) {
if (mod.rawRequest)
moduleMap[mod.rawRequest] = mod;
}
const blocks = containerEntryModule.blocks;
const exposedResolved = {};
for (let exposed in exposedObj) {
exposedResolved[exposed] = moduleMap[exposedObj[exposed].import];
}
const builtExposes = {};
container.getAllAsyncChunks().forEach((chunk) => {
for (let expose in exposedResolved) {
const rootModulesInChunk = compilation.chunkGraph.getChunkRootModules(chunk);
if (rootModulesInChunk.includes(exposedResolved[expose])) {
const referencedChunks = chunk.getAllReferencedChunks();
const currentModule = exposedResolved[expose];
if (!builtExposes[expose])
builtExposes[expose] = [];
referencedChunks.forEach((chunk) => {
const rootReferencesInChunk = compilation.chunkGraph.getChunkRootModules(chunk);
const isNodeModule = rootReferencesInChunk.some((mod) => {
if (mod.rootModule)
mod = mod.rootModule;
return mod?.resource?.includes('node_modules');
});
if (isNodeModule)
return;
builtExposes[expose] = [
...builtExposes[expose],
...Array.from(chunk.files),
];
});
// Iterate over each dependency block associated with the entry module.
for (let block of blocks) {
const blockmodule = block;
// Iterate over each dependency within the block.
for (const dep of blockmodule.dependencies) {
// Get the module that corresponds to the dependency.
const { module } = compilation.moduleGraph.getConnection(dep);
const moduleChunks = compilation.chunkGraph.getModuleChunksIterable(module);
// Iterate over each chunk associated with the module.
for (let exposedChunk of moduleChunks) {
// Determine the runtime for the chunk.
const runtime = typeof exposedChunk.runtime === 'string'
? new Set([exposedChunk.runtime])
: exposedChunk.runtime;
// Check if the chunk is meant for the same runtime as the entry module.
const isForThisRuntime = runtime.has(containerEntryModule._name);
// Get the root modules for the chunk.
const rootModules = compilation.chunkGraph.getChunkRootModules(exposedChunk);
// Check if the module associated with the dependency is one of the root modules for the chunk.
const moduleActuallyNeedsChunk = rootModules.includes(module);
// If the chunk is not meant for this runtime or the module doesn't need the chunk, skip the rest of this iteration.
if (!isForThisRuntime || !moduleActuallyNeedsChunk)
continue;
// Add the files associated with the chunk to the 'builtExposes' object under the name of the exposed module.
builtExposes[dep.exposedName] = [
...(builtExposes[dep.exposedName] || []),
...(exposedChunk.files || []),
];
}
// Add the module to the 'exposedResolved' object under the name of the exposed module.
exposedResolved[dep.exposedName] = module;
}
});
}
// Generate a JSON object that contains detailed information about the compilation.
const stats = compilation.getStats().toJson({

@@ -365,11 +374,20 @@ all: false,

});
// Apply a function 'getFederationStats' on the stats with the federation plugin options as the second argument.
const federatedModules = getFederationStats(stats, federationOpts);
// Assign the 'builtExposes' object to the 'exposes' property of the 'federatedModules' object.
federatedModules.exposes = builtExposes;
// Apply a function 'getMainSharedModules' on the stats.
const sharedModules = getMainSharedModules(stats);
// Create a Set to hold the vendor chunks.
const vendorChunks = new Set();
sharedModules.forEach((share) => {
share?.chunks?.forEach((file) => {
vendorChunks.add(file);
});
});
// Iterate over the shared modules.
for (const share of sharedModules) {
if (share?.chunks) {
// If a shared module has chunks, add them to the 'vendorChunks' Set.
for (const file of share.chunks) {
vendorChunks.add(file);
}
}
}
// Construct an object that contains the shared and federated modules.
const statsResult = {

@@ -379,4 +397,7 @@ sharedModules,

};
// Convert the 'statsResult' object to a JSON string.
const statsJson = JSON.stringify(statsResult);
// Convert the JSON string to a buffer.
const statsBuffer = Buffer.from(statsJson, 'utf-8');
// Construct an object that represents the source of the final asset.
const statsSource = {

@@ -386,4 +407,7 @@ source: () => statsBuffer,

};
// Get the filename of the final asset from the plugin options.
const { filename } = this._options;
// Check if an asset with the same filename already exists.
const asset = compilation.getAsset(filename);
// If an asset with the same filename already exists, update it. Otherwise, create a new asset.
if (asset) {

@@ -390,0 +414,0 @@ compilation.updateAsset(filename, statsSource);

@@ -232,3 +232,3 @@ /* eslint-disable @typescript-eslint/no-var-requires */

*/
"console.log('global.__remote_scope__', global.__remote_scope__['checkout'])",
"console.debug('global.__remote_scope__', global.__remote_scope__['checkout'])",
this._getLogger(`'remotes keyed by global name'`, JSON.stringify(remotesByType.normal)),

@@ -264,3 +264,3 @@ this._getLogger(`'remote scope configs'`, 'global.__remote_scope__._config'),

// there may still be a use case for that with promise new promise, depending on how we design it.
`console.log('requestedRemote',requestedRemote, "CURRENT NAME",${JSON.stringify(name)});`,
`console.debug('requestedRemote',requestedRemote, "CURRENT NAME",${JSON.stringify(name)});`,
`var scriptUrl = new URL(requestedRemote);`,

@@ -308,3 +308,3 @@ this._getLogger(`'global.__remote_scope__'`, `global.__remote_scope__`),

`${webpack_1.RuntimeGlobals.externalInstallChunk} = function(){
console.log('node: webpack installing to install chunk id:', arguments['0'].id);
console.debug('node: webpack installing to install chunk id:', arguments['0'].id);
return installChunk.apply(this, arguments)

@@ -311,0 +311,0 @@ };`,

@@ -7,2 +7,2 @@ /**

export default _default;
export declare const executeLoadTemplate = "\n function executeLoad(url, callback, name) {\n if(!name) {\n throw new Error('__webpack_require__.l name is required for ' + url);\n }\n\n if (typeof global.__remote_scope__[name] !== 'undefined') return callback(global.__remote_scope__[name]);\n console.log('executeLoad', url, name);\n const vm = require('vm');\n (global.webpackChunkLoad || global.fetch || require(\"node-fetch\"))(url).then(function (res) {\n return res.text();\n }).then(function (scriptContent) {\n try {\n // TODO: remove conditional in v7, this is to prevent breaking change between v6.0.x and v6.1.x\n const vmContext = typeof URLSearchParams === 'undefined' ?{exports, require, module, global, __filename, __dirname, URL, URLSearchParams, console, process,Buffer, ...global, remoteEntryName: name}:\n {exports, require, module, global, __filename, __dirname, URL, URLSearchParams, console, process,Buffer, ...global, remoteEntryName: name};\n const remote = vm.runInNewContext(scriptContent + '\\nmodule.exports', vmContext, {filename: 'node-federation-loader-' + name + '.vm'});\n const foundContainer = remote[name] || remote\n\n if(!global.__remote_scope__[name]) {\n global.__remote_scope__[name] = foundContainer;\n global.__remote_scope__._config[name] = url;\n }\n callback(global.__remote_scope__[name]);\n } catch (e) {\n console.error('executeLoad hit catch block');\n e.target = {src: url};\n callback(e);\n }\n }).catch((e) => {\n e.target = {src: url};\n callback(e);\n });\n }\n";
export declare const executeLoadTemplate = "\n function executeLoad(url, callback, name) {\n if(!name) {\n throw new Error('__webpack_require__.l name is required for ' + url);\n }\n\n if (typeof global.__remote_scope__[name] !== 'undefined') return callback(global.__remote_scope__[name]);\n console.log('executing network resource load', url, name);\n const vm = require('vm');\n (global.webpackChunkLoad || global.fetch || require(\"node-fetch\"))(url).then(function (res) {\n return res.text();\n }).then(function (scriptContent) {\n try {\n // TODO: remove conditional in v7, this is to prevent breaking change between v6.0.x and v6.1.x\n const vmContext = typeof URLSearchParams === 'undefined' ?{exports, require, module, global, __filename, __dirname, URL, URLSearchParams, console, process,Buffer, ...global, remoteEntryName: name}:\n {exports, require, module, global, __filename, __dirname, URL, URLSearchParams, console, process,Buffer, ...global, remoteEntryName: name};\n const remote = vm.runInNewContext(scriptContent + '\\nmodule.exports', vmContext, {filename: 'node-federation-loader-' + name + '.vm'});\n const foundContainer = remote[name] || remote\n\n if(!global.__remote_scope__[name]) {\n global.__remote_scope__[name] = foundContainer;\n global.__remote_scope__._config[name] = url;\n }\n callback(global.__remote_scope__[name]);\n } catch (e) {\n console.error('executeLoad hit catch block');\n e.target = {src: url};\n callback(e);\n }\n }).catch((e) => {\n e.target = {src: url};\n callback(e);\n });\n }\n";

@@ -52,3 +52,3 @@ "use strict";

if (typeof global.__remote_scope__[name] !== 'undefined') return callback(global.__remote_scope__[name]);
console.log('executeLoad', url, name);
console.log('executing network resource load', url, name);
const vm = require('vm');

@@ -55,0 +55,0 @@ (global.webpackChunkLoad || global.fetch || require("node-fetch"))(url).then(function (res) {

@@ -65,3 +65,3 @@ 'use strict';

get: (arg) => {
console.log('faking', arg, 'module on', ${JSON.stringify(global)});
console.warn('faking', arg, 'module on', ${JSON.stringify(global)});

@@ -68,0 +68,0 @@ return Promise.resolve(() => {

@@ -48,3 +48,3 @@ "use strict";

if (remoteScope[property].fake) {
console.log('unreachable remote found', property, 'hot reloading to refetch');
console.error('unreachable remote found', property, 'hot reloading to refetch');
res(true);

@@ -51,0 +51,0 @@ break;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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