diff --git a/packages/enhanced/src/lib/container/AsyncBoundaryPlugin.ts b/packages/enhanced/src/lib/container/AsyncBoundaryPlugin.ts index 644c68597bb..77244104332 100644 --- a/packages/enhanced/src/lib/container/AsyncBoundaryPlugin.ts +++ b/packages/enhanced/src/lib/container/AsyncBoundaryPlugin.ts @@ -1,3 +1,7 @@ +/* + MIT License http://www.opensource.org/licenses/mit-license.php + Author Zackary Jackson @ScriptedAlchemy +*/ import { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path'; import { moduleFederationPlugin } from '@module-federation/sdk'; import type { diff --git a/packages/enhanced/src/lib/container/ModuleFederationPlugin.ts b/packages/enhanced/src/lib/container/ModuleFederationPlugin.ts index a10bd6a4d98..e03f8bdbb14 100644 --- a/packages/enhanced/src/lib/container/ModuleFederationPlugin.ts +++ b/packages/enhanced/src/lib/container/ModuleFederationPlugin.ts @@ -122,6 +122,7 @@ class ModuleFederationPlugin implements WebpackPluginInstance { ) { compiler.options.output.enabledLibraryTypes?.push(library.type); } + compiler.hooks.afterPlugins.tap('ModuleFederationPlugin', () => { if (useContainerPlugin) { new ContainerPlugin({ diff --git a/packages/enhanced/src/lib/container/constant.ts b/packages/enhanced/src/lib/container/constant.ts index 7994d851a5f..7a49cf123c0 100644 --- a/packages/enhanced/src/lib/container/constant.ts +++ b/packages/enhanced/src/lib/container/constant.ts @@ -1,3 +1,7 @@ +/* + MIT License http://www.opensource.org/licenses/mit-license.php + Author Zackary Jackson @ScriptedAlchemy +*/ import path from 'path'; import { TEMP_DIR as BasicTempDir } from '@module-federation/sdk'; diff --git a/packages/enhanced/src/lib/container/runtime/ChildCompilationRuntimePlugin.ts b/packages/enhanced/src/lib/container/runtime/ChildCompilationRuntimePlugin.ts index e816ddaa48e..52a6514660f 100644 --- a/packages/enhanced/src/lib/container/runtime/ChildCompilationRuntimePlugin.ts +++ b/packages/enhanced/src/lib/container/runtime/ChildCompilationRuntimePlugin.ts @@ -1,3 +1,8 @@ +/* + MIT License http://www.opensource.org/licenses/mit-license.php + Author Zackary Jackson @ScriptedAlchemy +*/ + // This stores the previous child compilation based solution // it is not currently used diff --git a/packages/enhanced/src/lib/container/runtime/EmbedFederationRuntimeModule.ts b/packages/enhanced/src/lib/container/runtime/EmbedFederationRuntimeModule.ts index 34d00ef947a..4d54d5f19f7 100644 --- a/packages/enhanced/src/lib/container/runtime/EmbedFederationRuntimeModule.ts +++ b/packages/enhanced/src/lib/container/runtime/EmbedFederationRuntimeModule.ts @@ -1,3 +1,7 @@ +/* + MIT License http://www.opensource.org/licenses/mit-license.php + Author Zackary Jackson @ScriptedAlchemy +*/ import { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path'; import ContainerEntryDependency from '../ContainerEntryDependency'; @@ -12,6 +16,7 @@ class EmbedFederationRuntimeModule extends RuntimeModule { private containerEntrySet: Set< ContainerEntryDependency | FederationRuntimeDependency >; + constructor( containerEntrySet: Set< ContainerEntryDependency | FederationRuntimeDependency @@ -20,9 +25,11 @@ class EmbedFederationRuntimeModule extends RuntimeModule { super('embed federation', RuntimeModule.STAGE_ATTACH); this.containerEntrySet = containerEntrySet; } + override identifier() { return 'webpack/runtime/embed/federation'; } + override generate(): string | null { const { compilation, chunk, chunkGraph } = this; if (!chunk || !chunkGraph || !compilation) { diff --git a/packages/enhanced/src/lib/container/runtime/FederationModulesPlugin.ts b/packages/enhanced/src/lib/container/runtime/FederationModulesPlugin.ts index 9c79c0b7c8f..febac13bb97 100644 --- a/packages/enhanced/src/lib/container/runtime/FederationModulesPlugin.ts +++ b/packages/enhanced/src/lib/container/runtime/FederationModulesPlugin.ts @@ -9,10 +9,7 @@ import ContainerEntryDependency from '../ContainerEntryDependency'; import FederationRuntimeDependency from './FederationRuntimeDependency'; /** @type {WeakMap} */ -const compilationHooksMap = new WeakMap< - import('webpack').Compilation, - CompilationHooks ->(); +const compilationHooksMap = new WeakMap(); const PLUGIN_NAME = 'FederationModulesPlugin'; diff --git a/packages/enhanced/src/lib/container/runtime/FederationRuntimePlugin.ts b/packages/enhanced/src/lib/container/runtime/FederationRuntimePlugin.ts index 37dc724f4d7..fac5ff9e300 100644 --- a/packages/enhanced/src/lib/container/runtime/FederationRuntimePlugin.ts +++ b/packages/enhanced/src/lib/container/runtime/FederationRuntimePlugin.ts @@ -1,9 +1,13 @@ +import fs from 'fs'; +import path from 'path'; +import pBtoa from 'btoa'; import type { Compiler, WebpackPluginInstance, Compilation, Chunk, } from 'webpack'; +import type { EntryDescription } from 'webpack/lib/Entrypoint'; import { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path'; import { PrefetchPlugin } from '@module-federation/data-prefetch/cli'; import { moduleFederationPlugin } from '@module-federation/sdk'; @@ -15,13 +19,10 @@ import { createHash, normalizeToPosixPath, } from './utils'; -import fs from 'fs'; -import path from 'path'; import { TEMP_DIR } from '../constant'; import EmbedFederationRuntimePlugin from './EmbedFederationRuntimePlugin'; import FederationModulesPlugin from './FederationModulesPlugin'; import HoistContainerReferences from '../HoistContainerReferencesPlugin'; -import pBtoa from 'btoa'; import FederationRuntimeDependency from './FederationRuntimeDependency'; const ModuleDependency = require( @@ -55,7 +56,7 @@ const EmbeddedRuntimePath = require.resolve( const federationGlobal = getFederationGlobalScope(RuntimeGlobals); -const onceForCompler = new WeakSet(); +const onceForCompler = new WeakSet(); class FederationRuntimePlugin { options?: moduleFederationPlugin.ModuleFederationPluginOptions; @@ -277,7 +278,7 @@ class FederationRuntimePlugin { const entryFilePath = this.getFilePath(compiler); modifyEntry({ compiler, - prependEntry: (entry) => { + prependEntry: (entry: Record) => { Object.keys(entry).forEach((entryName) => { const entryItem = entry[entryName]; if (!entryItem.import) { @@ -397,7 +398,6 @@ class FederationRuntimePlugin { ); if (useModuleFederationPlugin && !this.options) { - // @ts-ignore this.options = useModuleFederationPlugin._options; } diff --git a/packages/enhanced/src/lib/container/runtime/utils.ts b/packages/enhanced/src/lib/container/runtime/utils.ts index b8f1f2ea3ee..18886f0ff01 100644 --- a/packages/enhanced/src/lib/container/runtime/utils.ts +++ b/packages/enhanced/src/lib/container/runtime/utils.ts @@ -1,3 +1,7 @@ +/* + MIT License http://www.opensource.org/licenses/mit-license.php + Author Zackary Jackson @ScriptedAlchemy +*/ import { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path'; import upath from 'upath'; import path from 'path'; diff --git a/packages/enhanced/src/lib/startup/StartupHelpers.ts b/packages/enhanced/src/lib/startup/StartupHelpers.ts index 9bc11cf8e1e..e43b28dd3a2 100644 --- a/packages/enhanced/src/lib/startup/StartupHelpers.ts +++ b/packages/enhanced/src/lib/startup/StartupHelpers.ts @@ -156,6 +156,7 @@ export const generateESMEntryStartup = ( passive: boolean, ): string => { const { chunkHasJs, getChunkFilenameTemplate } = + compilation.compiler.webpack?.javascript?.JavascriptModulesPlugin || compilation.compiler.webpack.JavascriptModulesPlugin; const { ConcatSource } = compilation.compiler.webpack.sources; const hotUpdateChunk = chunk instanceof HotUpdateChunk ? chunk : null; diff --git a/packages/nextjs-mf/src/plugins/container/InvertedContainerRuntimeModule.ts b/packages/nextjs-mf/src/plugins/container/InvertedContainerRuntimeModule.ts index 9300a5bd6a2..b87d149bd55 100644 --- a/packages/nextjs-mf/src/plugins/container/InvertedContainerRuntimeModule.ts +++ b/packages/nextjs-mf/src/plugins/container/InvertedContainerRuntimeModule.ts @@ -19,14 +19,6 @@ class InvertedContainerRuntimeModule extends RuntimeModule { this.options = options; } - private findEntryModuleOfContainer(): Module | undefined { - if (!this.chunk || !this.chunkGraph) return undefined; - const modules = this.chunkGraph.getChunkModules(this.chunk); - return Array.from(modules).find( - (module) => module instanceof container.ContainerEntryModule, - ); - } - override generate(): string { const { compilation, chunk, chunkGraph } = this; if (!compilation || !chunk || !chunkGraph) { @@ -46,6 +38,12 @@ class InvertedContainerRuntimeModule extends RuntimeModule { if (!containerEntryModule) return ''; + if ( + compilation.chunkGraph.isEntryModuleInChunk(containerEntryModule, chunk) + ) { + // dont apply to remote entry itself + return ''; + } const initRuntimeModuleGetter = compilation.runtimeTemplate.moduleRaw({ module: containerEntryModule, chunkGraph,