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 21805ed
Show file tree
Hide file tree
Showing 60 changed files with 463 additions and 1,123 deletions.
1 change: 0 additions & 1 deletion apps/3000-home/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"tapable": "2.2.1",
"terser-webpack-plugin": "5.3.10",
"typescript": "5.3.3",
"upath": "2.0.1",
"url": "0.11.3",
"util": "0.12.5",
"webpack-sources": "3.2.3"
Expand Down
1 change: 0 additions & 1 deletion apps/3001-shop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"tapable": "2.2.1",
"terser-webpack-plugin": "5.3.10",
"typescript": "5.3.3",
"upath": "2.0.1",
"url": "0.11.3",
"util": "0.12.5",
"webpack-sources": "3.2.3"
Expand Down
7 changes: 3 additions & 4 deletions apps/3002-checkout/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,15 @@
"styled-jsx": "5.1.2",
"tapable": "2.2.1",
"terser-webpack-plugin": "5.3.10",
"typescript": "5.3.3",
"upath": "2.0.1",
"url": "0.11.3",
"util": "0.12.5",
"webpack-sources": "3.2.3"
"webpack-sources": "3.2.3",
"typescript": "5.3.3"
},
"devDependencies": {
"@module-federation/nextjs-mf": "workspace:*",
"@module-federation/runtime": "workspace:*",
"@module-federation/sdk": "workspace:*",
"@module-federation/runtime": "workspace:*",
"@module-federation/utilities": "workspace:*"
},
"scripts": {
Expand Down
6 changes: 3 additions & 3 deletions apps/modernjs/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"commands": [
{
"command": "cd apps/modernjs; pnpm run dev",
"forwardAllArgs": false
"forwardAllArgs": true
}
]
}
Expand Down Expand Up @@ -61,11 +61,11 @@
"parallel": true,
"commands": [
{
"command": "lsof -i :8080 || nx run modernjs:serve & echo 'done'",
"command": "lsof -i :8080 || nx run modernjs:serve && echo 'done'",
"forwardAllArgs": false
},
{
"command": "sleep 20 && nx run modernjs:e2e",
"command": "sleep 4 && nx run modernjs:e2e",
"forwardAllArgs": true
}
]
Expand Down
10 changes: 7 additions & 3 deletions apps/node-host/src/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,27 @@

import express from 'express';
import * as path from 'path';
import node_local_remote from 'node_local_remote/test';

const remoteMsg = import('node_remote/test').then((m) => {
console.log('\x1b[32m%s\x1b[0m', m.default || m);
return m.default || m;
});
console.log('\x1b[32m%s\x1b[0m', node_local_remote);

const app = express();

app.use('/assets', express.static(path.join(__dirname, 'assets')));

app.get('/api', async (req, res) => {
const localRemoteMsg = import('node_local_remote/test').then((m) => {
console.log('\x1b[32m%s\x1b[0m', m.default || m);
return m.default || m;
});

res.send({
message: 'Welcome to node-host!',
remotes: {
node_remote: await remoteMsg,
node_local_remote,
node_local_remote: await localRemoteMsg,
},
});
});
Expand Down
1 change: 1 addition & 0 deletions apps/node-remote/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module.exports = composePlugins(withNx(), (config) => {
exposes: {
'./test': './src/expose.js',
},
experiments: {},
}),
);
return config;
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
"app:ts:dev": "nx run-many --target=serve -p react_ts_host,react_ts_nested_remote,react_ts_remote",
"commitlint": "commitlint --edit",
"prepare": "husky install",
"changeset": "changeset",
"build:packages": "npx nx affected -t build --parallel=10 --exclude='*,!tag:package'"
"changeset": "changeset"
},
"dependencies": {
"adm-zip": "0.5.10",
Expand All @@ -68,7 +67,6 @@
"unplugin": "1.9.0"
},
"devDependencies": {
"terser-webpack-plugin": "^5.3.10",
"@antora/cli": "3.1.5",
"@antora/lunr-extension": "1.0.0-alpha.8",
"@antora/site-generator": "3.1.7",
Expand Down
6 changes: 1 addition & 5 deletions packages/enhanced/jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable */
import { readFileSync, rmdirSync, existsSync } from 'fs';
import { readFileSync } from 'fs';
import path from 'path';

// Reading the SWC compilation config and remove the "exclude"
Expand All @@ -8,10 +8,6 @@ const { exclude: _, ...swcJestConfig } = JSON.parse(
readFileSync(`${__dirname}/.swcrc`, 'utf-8'),
);

if (existsSync(__dirname + '/test/js')) {
rmdirSync(__dirname + '/test/js', { recursive: true });
}

// disable .swcrc look-up by SWC core because we're passing in swcJestConfig ourselves.
// If we do not disable this, SWC Core will read .swcrc and won't transform our test files due to "exclude"
if (swcJestConfig.swcrc === undefined) {
Expand Down
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 21805ed

Please sign in to comment.