Skip to content

Commit

Permalink
feat(module-federation): use @module-federation/enhanced for withModu…
Browse files Browse the repository at this point in the history
…leFederation
  • Loading branch information
Coly010 committed Jul 2, 2024
1 parent cf396f7 commit f4788e0
Show file tree
Hide file tree
Showing 14 changed files with 499 additions and 12 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"@jest/reporters": "^29.4.1",
"@jest/test-result": "^29.4.1",
"@jest/types": "^29.4.1",
"@module-federation/enhanced": "^0.2.3",
"@monodon/rust": "1.3.3",
"@napi-rs/cli": "2.14.0",
"@nestjs/cli": "^10.0.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/ng-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"@nx/",
"@angular-devkit",
"@angular-eslint/",
"@module-federation/enhanced",
"@schematics",
"@phenomnomnominal/tsquery",
"@typescript-eslint/",
Expand All @@ -20,7 +21,6 @@
"ts-node",
"tsconfig-paths",
"semver",
"webpack",
"http-server",
"magic-string",
"enquirer",
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@
"minimatch": "9.0.3",
"semver": "^7.5.3",
"tslib": "^2.3.0",
"webpack": "^5.80.0",
"webpack-merge": "^5.8.0",
"@module-federation/enhanced": "~0.2.3",
"@nx/devkit": "file:../devkit",
"@nx/js": "file:../js",
"@nx/eslint": "file:../eslint",
Expand Down
16 changes: 13 additions & 3 deletions packages/angular/src/generators/setup-mf/setup-mf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ import {
updateHostAppRoutes,
updateTsConfig,
} from './lib';
import { nxVersion } from '../../utils/versions';
import {
moduleFederationEnhancedVersion,
nxVersion,
} from '../../utils/versions';

export async function setupMf(tree: Tree, rawOptions: Schema) {
const options = normalizeOptions(tree, rawOptions);
Expand All @@ -43,7 +46,11 @@ export async function setupMf(tree: Tree, rawOptions: Schema) {
installTask = addDependenciesToPackageJson(
tree,
{},
{ '@nx/web': nxVersion, '@nx/webpack': nxVersion }
{
'@nx/web': nxVersion,
'@nx/webpack': nxVersion,
'@module-federation/enhanced': moduleFederationEnhancedVersion,
}
);
}
}
Expand Down Expand Up @@ -71,7 +78,10 @@ export async function setupMf(tree: Tree, rawOptions: Schema) {
installTask = addDependenciesToPackageJson(
tree,
{},
{ '@nx/webpack': nxVersion }
{
'@nx/webpack': nxVersion,
'@module-federation/enhanced': moduleFederationEnhancedVersion,
}
);
}
}
Expand Down
2 changes: 2 additions & 0 deletions packages/angular/src/utils/backward-compatible-versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const backwardCompatibleVersions: VersionMap = {
typesExpressVersion: '4.17.14',
browserSyncVersion: '^3.0.0',
moduleFederationNodeVersion: '~1.0.5',
moduleFederationEnhancedVersion: '~0.2.3',
angularEslintVersion: '~16.0.0',
tailwindVersion: '^3.0.2',
postcssVersion: '^8.4.5',
Expand All @@ -75,6 +76,7 @@ export const backwardCompatibleVersions: VersionMap = {
typesExpressVersion: '4.17.14',
browserSyncVersion: '^3.0.0',
moduleFederationNodeVersion: '~1.0.5',
moduleFederationEnhancedVersion: '~0.2.3',
angularEslintVersion: '~17.3.0',
tailwindVersion: '^3.0.2',
postcssVersion: '^8.4.5',
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/src/utils/mf/with-module-federation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ModuleFederationConfig } from '@nx/webpack/src/utils/module-federation';
import { getModuleFederationConfig } from './utils';
import ModuleFederationPlugin from 'webpack/lib/container/ModuleFederationPlugin';
import { ModuleFederationPlugin } from '@module-federation/enhanced/webpack';

export async function withModuleFederation(options: ModuleFederationConfig) {
if (global.NX_GRAPH_CREATION) {
Expand Down
1 change: 1 addition & 0 deletions packages/angular/src/utils/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const expressVersion = '~4.18.2';
export const typesExpressVersion = '4.17.14';
export const browserSyncVersion = '^3.0.0';
export const moduleFederationNodeVersion = '~1.0.5';
export const moduleFederationEnhancedVersion = '~0.2.3';

export const angularEslintVersion = '^18.0.1';
export const typescriptEslintVersion = '^8.0.0-alpha.28';
Expand Down
1 change: 1 addition & 0 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"file-loader": "^6.2.0",
"minimatch": "9.0.3",
"tslib": "^2.3.0",
"@module-federation/enhanced": "~0.2.3",
"@nx/devkit": "file:../devkit",
"@nx/js": "file:../js",
"@nx/eslint": "file:../eslint",
Expand Down
9 changes: 9 additions & 0 deletions packages/react/src/generators/host/host.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
addDependenciesToPackageJson,
formatFiles,
GeneratorCallback,
joinPathFragments,
Expand All @@ -22,6 +23,7 @@ import { updateModuleFederationE2eProject } from './lib/update-module-federation
import { NormalizedSchema, Schema } from './schema';
import { addMfEnvToTargetDefaultInputs } from '../../utils/add-mf-env-to-inputs';
import { isValidVariable } from '@nx/js';
import { moduleFederationEnhancedVersion } from '../../utils/versions';

export async function hostGenerator(
host: Tree,
Expand Down Expand Up @@ -137,6 +139,13 @@ export async function hostGeneratorInternal(

addMfEnvToTargetDefaultInputs(host);

const installTask = addDependenciesToPackageJson(
host,
{},
{ '@module-federation/enhanced': moduleFederationEnhancedVersion }
);
tasks.push(installTask);

if (!options.skipFormat) {
await formatFiles(host);
}
Expand Down
9 changes: 9 additions & 0 deletions packages/react/src/generators/remote/remote.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { join } from 'path';
import {
addDependenciesToPackageJson,
formatFiles,
generateFiles,
GeneratorCallback,
Expand All @@ -24,6 +25,7 @@ import { addRemoteToDynamicHost } from './lib/add-remote-to-dynamic-host';
import { addMfEnvToTargetDefaultInputs } from '../../utils/add-mf-env-to-inputs';
import { maybeJs } from '../../utils/maybe-js';
import { isValidVariable } from '@nx/js';
import { moduleFederationEnhancedVersion } from '../../utils/versions';

export function addModuleFederationFiles(
host: Tree,
Expand Down Expand Up @@ -171,6 +173,13 @@ export async function remoteGeneratorInternal(host: Tree, schema: Schema) {

addMfEnvToTargetDefaultInputs(host);

const installTask = addDependenciesToPackageJson(
host,
{},
{ '@module-federation/enhanced': moduleFederationEnhancedVersion }
);
tasks.push(installTask);

if (!options.skipFormat) {
await formatFiles(host);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ModuleFederationConfig } from '@nx/webpack/src/utils/module-federation';
import { getModuleFederationConfig } from './utils';
import type { AsyncNxComposableWebpackPlugin } from '@nx/webpack';
import ModuleFederationPlugin = require('webpack/lib/container/ModuleFederationPlugin');
import { ModuleFederationPlugin } from '@module-federation/enhanced/webpack';

const isVarOrWindow = (libType?: string) =>
libType === 'var' || libType === 'window';
Expand Down
3 changes: 2 additions & 1 deletion packages/react/src/utils/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ export const typesExpressVersion = '4.17.17';
export const isbotVersion = '^3.6.5';
export const corsVersion = '~2.8.5';
export const typesCorsVersion = '~2.8.12';
export const moduleFederationNodeVersion = '~0.9.9';
export const moduleFederationNodeVersion = '~1.0.5';
export const moduleFederationEnhancedVersion = '~0.2.3';

// style preprocessors
export const lessVersion = '3.12.2';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
getOutputsForTargetAndConfiguration,
parseTargetString,
} from '@nx/devkit';
import { interpolate } from 'nx/src/tasks-runner/utils';

export function getDependentPackagesForProject(
projectGraph: ProjectGraph,
Expand Down
Loading

0 comments on commit f4788e0

Please sign in to comment.