Skip to content

Commit

Permalink
Revert "chore(enhanced): adjust add federation init process (#2035)"
Browse files Browse the repository at this point in the history
This reverts commit df3ef24
  • Loading branch information
ScriptedAlchemy committed Apr 3, 2024
1 parent f9335c7 commit 9f21893
Show file tree
Hide file tree
Showing 11 changed files with 343 additions and 552 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ class ContainerEntryModule extends Module {
// @ts-ignore
new EntryDependency(this._injectRuntimeEntry),
);

callback();
}

Expand Down
66 changes: 15 additions & 51 deletions packages/enhanced/src/lib/container/ContainerPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,6 @@ class ContainerPlugin {

if (!useModuleFederationPlugin) {
ContainerPlugin.patchChunkSplit(compiler, this._options.name);
ContainerPlugin.patchChunkSplit(compiler, 'federation-runtime');
ContainerPlugin.patchChunkSplit(compiler, 'mfp-runtime-plugins');
}
const federationRuntimePluginInstance = new FederationRuntimePlugin();
federationRuntimePluginInstance.apply(compiler);
Expand All @@ -166,16 +164,6 @@ class ContainerPlugin {
) {
compiler.options.output.enabledLibraryTypes.push(library.type);
}
const hasSingleRuntimeChunk = compiler.options?.optimization?.runtimeChunk;

new compiler.webpack.EntryPlugin(
compiler.options.context || '',
federationRuntimePluginInstance.entryFilePath,
{
name,
runtime: hasSingleRuntimeChunk ? false : runtime,
},
).apply(compiler);

compiler.hooks.make.tapAsync(PLUGIN_NAME, (compilation, callback) => {
const dep = new ContainerEntryDependency(
Expand Down Expand Up @@ -211,45 +199,21 @@ class ContainerPlugin {
);

// Function to add entry for undefined runtime
const addEntryToSingleRuntimeChunk = async () => {
const entries =
typeof compiler.options.entry === 'function'
? await compiler.options.entry()
: compiler.options.entry;
const runtimes: Set<undefined | string | false> = new Set();

Object.keys(entries).forEach((key) => {
if (entries[key].runtime) {
runtimes.add(entries[key].runtime);
} else if (entries[key].runtime === undefined) {
runtimes.add(undefined);
}
});

//Add container entry for each runtime that exists
for (const runtime of runtimes) {
const name = runtime
? 'federation-runtime-' + runtime
: 'federation-runtime';
await new Promise((resolve, reject) => {
compilation.addEntry(
compilation.options.context || '',
//@ts-ignore
dep,
{
name: name, // merge container into federation entrypoint added to compilation
runtime: runtime,
library,
},
(error: WebpackError | null | undefined) => {
if (error) return reject(error);
resolve(true);
},
);
}).catch(callback);
}

callback();
const addEntryToSingleRuntimeChunk = () => {
compilation.addEntry(
compilation.options.context || '',
//@ts-ignore
dep,
{
name: name ? name + '_partial' : undefined, // give unique name name
runtime: undefined,
library,
},
(error: WebpackError | null | undefined) => {
if (error) return callback(error);
callback();
},
);
};
});

Expand Down
Loading

0 comments on commit 9f21893

Please sign in to comment.