@module-federation/node
Advanced tools
Comparing version 0.14.7-rc.4 to 0.14.7-rc.5x
{ | ||
"public": true, | ||
"name": "@module-federation/node", | ||
"version": "0.14.7-rc.4", | ||
"version": "0.14.7-rc.5x", | ||
"type": "commonjs", | ||
@@ -6,0 +6,0 @@ "main": "src/index.js", |
@@ -185,9 +185,9 @@ "use strict"; | ||
return flatMap(stats.chunks.filter((chunk) => { | ||
if (!stats.entrypoints[federationPlugin._options.name]) { | ||
if (!stats.entrypoints[federationPlugin.name]) { | ||
return false; | ||
} | ||
return stats.entrypoints[federationPlugin._options.name].chunks.some((id) => chunk.id === id); | ||
return stats.entrypoints[federationPlugin.name].chunks.some((id) => chunk.id === id); | ||
}), (chunk) => flatMap(chunk.children, (id) => stats.chunks.filter((c) => c.id === id && | ||
c.files.length > 0 && | ||
c.parents.some((p) => stats.entrypoints[federationPlugin._options.name].chunks.some((c) => c === p)) && | ||
c.parents.some((p) => stats.entrypoints[federationPlugin.name].chunks.some((c) => c === p)) && | ||
c.modules.some((m) => searchIssuer(m, (issuer) => issuer?.startsWith('consume-shared-module')))))) | ||
@@ -233,4 +233,4 @@ .map((chunk) => ({ | ||
*/ | ||
function getFederationStats(stats, federationPlugin) { | ||
const exposedModules = Object.entries(federationPlugin._options.exposes).reduce((exposedModules, [exposedAs, exposedFile]) => Object.assign(exposedModules, { | ||
function getFederationStats(stats, federationPluginOptions) { | ||
const exposedModules = Object.entries(federationPluginOptions.exposes).reduce((exposedModules, [exposedAs, exposedFile]) => Object.assign(exposedModules, { | ||
[exposedAs]: getExposedModules(stats, exposedFile), | ||
@@ -243,4 +243,4 @@ }), {}); | ||
/** @type {string} */ | ||
const remote = federationPlugin._options.library?.name || federationPlugin._options.name; | ||
const sharedModules = getSharedModules(stats, federationPlugin); | ||
const remote = federationPluginOptions.library?.name || federationPluginOptions.name; | ||
const sharedModules = getSharedModules(stats, federationPluginOptions); | ||
const remoteModules = getRemoteModules(stats); | ||
@@ -252,3 +252,3 @@ return { | ||
? stats.assetsByChunkName[remote][0] | ||
: federationPlugin._options.filename}`, | ||
: federationPluginOptions.filename}`, | ||
sharedModules, | ||
@@ -294,12 +294,57 @@ exposes, | ||
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => { | ||
compilation.hooks.processAssets.tapPromise({ | ||
compilation.hooks.processAssets.tap({ | ||
name: PLUGIN_NAME, | ||
stage: compilation.constructor.PROCESS_ASSETS_STAGE_SUMMARIZE, | ||
stage: compilation.constructor.PROCESS_ASSETS_STAGE_REPORT, | ||
}, | ||
// PLUGIN_NAME, | ||
async () => { | ||
if (alreadyRun) { | ||
const [federationOpts] = federationPlugins.map((federationPlugin) => { | ||
return federationPlugin?._options; | ||
}); | ||
let container; | ||
for (const [name, entry] of compilation.entrypoints) { | ||
if (container) | ||
break; | ||
federationOpts.name.includes(name) && (container = entry); | ||
} | ||
if (!container) | ||
return; | ||
container = container?.getEntrypointChunk(); | ||
const [containerEntryModule] = Array.from(compilation.chunkGraph.getChunkEntryModulesIterable(container)); | ||
const exposedObj = Object.fromEntries(containerEntryModule._exposes); | ||
const moduleMap = {}; | ||
for (let mod of compilation.modules) { | ||
if (mod.rawRequest) | ||
moduleMap[mod.rawRequest] = mod; | ||
} | ||
alreadyRun = true; | ||
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), | ||
]; | ||
}); | ||
} | ||
} | ||
}); | ||
const stats = compilation.getStats().toJson({ | ||
@@ -323,3 +368,4 @@ all: false, | ||
}); | ||
const federatedModules = federationPlugins.map((federationPlugin) => getFederationStats(stats, federationPlugin)); | ||
const federatedModules = getFederationStats(stats, federationOpts); | ||
federatedModules.exposes = builtExposes; | ||
const sharedModules = getMainSharedModules(stats); | ||
@@ -332,35 +378,5 @@ const vendorChunks = new Set(); | ||
}); | ||
const enhancedModuleLookup = federatedModules.map((mod) => { | ||
const remapped = Object.entries(mod.exposes).reduce((acc, [key, value]) => { | ||
acc[key] = acc[key] || []; | ||
value.map((chunk) => { | ||
return Object.keys(chunk).map((chunkId) => { | ||
const foundRootChunk = compilation.chunks.find((chunk) => { | ||
return chunk.id == chunkId; | ||
}); | ||
Array.from(foundRootChunk.getAllReferencedChunks()).forEach((c) => { | ||
const trueChunk = stats.chunks.find((chunkStats) => { | ||
return chunkStats.id == c.id; | ||
}); | ||
const isSharedModuleChunk = trueChunk.modules.every((m) => { | ||
return m.moduleType === 'consume-shared-module'; | ||
}); | ||
if (!isSharedModuleChunk && | ||
!trueChunk.files.every((f) => vendorChunks.has(f))) { | ||
acc[key].push({ | ||
[trueChunk.id]: { files: trueChunk.files }, | ||
}); | ||
} | ||
}); | ||
}); | ||
}); | ||
return acc; | ||
}, {}); | ||
return { ...mod, exposes: remapped }; | ||
}); | ||
const exposeKey = Object.keys(enhancedModuleLookup[0].exposes); | ||
console.log(enhancedModuleLookup[0].exposes); | ||
const statsResult = { | ||
sharedModules, | ||
federatedModules: enhancedModuleLookup, | ||
federatedModules: [federatedModules], | ||
}; | ||
@@ -367,0 +383,0 @@ const statsJson = JSON.stringify(statsResult); |
@@ -125,3 +125,3 @@ 'use strict'; | ||
? `${uniqueName}.js` | ||
: `.[chunkhash].js`; | ||
: `.[fullhash].js`; | ||
compiler.options.output.chunkFilename = chunkFileName.replace('.js', suffix); | ||
@@ -128,0 +128,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
158373
1613