Skip to content

Commit

Permalink
feat(module-federation): expose API for users to override module fede…
Browse files Browse the repository at this point in the history
…ration plugin options
  • Loading branch information
Coly010 committed Jul 2, 2024
1 parent f4788e0 commit 681605c
Show file tree
Hide file tree
Showing 13 changed files with 84 additions and 15 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"@jest/test-result": "^29.4.1",
"@jest/types": "^29.4.1",
"@module-federation/enhanced": "^0.2.3",
"@module-federation/sdk": "^0.2.3",
"@monodon/rust": "1.3.3",
"@napi-rs/cli": "2.14.0",
"@nestjs/cli": "^10.0.2",
Expand Down
9 changes: 9 additions & 0 deletions packages/angular/migrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -1933,6 +1933,15 @@
"alwaysAddToPackageJson": false
}
}
},
"19.4.0-module-federation": {
"version": "19.4.0-rc.2",
"packages": {
"@module-federation/node": {
"version": "^2.3.0",
"alwaysAddToPackageJson": false
}
}
}
}
}
4 changes: 2 additions & 2 deletions packages/angular/src/utils/backward-compatible-versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const backwardCompatibleVersions: VersionMap = {
expressVersion: '~4.18.2',
typesExpressVersion: '4.17.14',
browserSyncVersion: '^3.0.0',
moduleFederationNodeVersion: '~1.0.5',
moduleFederationNodeVersion: '~2.3.0',
moduleFederationEnhancedVersion: '~0.2.3',
angularEslintVersion: '~16.0.0',
tailwindVersion: '^3.0.2',
Expand All @@ -75,7 +75,7 @@ export const backwardCompatibleVersions: VersionMap = {
expressVersion: '~4.18.2',
typesExpressVersion: '4.17.14',
browserSyncVersion: '^3.0.0',
moduleFederationNodeVersion: '~1.0.5',
moduleFederationNodeVersion: '~2.3.0',
moduleFederationEnhancedVersion: '~0.2.3',
angularEslintVersion: '~17.3.0',
tailwindVersion: '^3.0.2',
Expand Down
12 changes: 10 additions & 2 deletions packages/angular/src/utils/mf/with-module-federation-ssr.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { ModuleFederationConfig } from '@nx/webpack/src/utils/module-federation';
import type {
ModuleFederationConfig,
NxModuleFederationConfigOverride,
} from '@nx/webpack/src/utils/module-federation';
import { getModuleFederationConfig } from './utils';

export async function withModuleFederationForSSR(
options: ModuleFederationConfig
options: ModuleFederationConfig,
configOverride?: NxModuleFederationConfigOverride
) {
if (global.NX_GRAPH_CREATION) {
return (config) => config;
Expand Down Expand Up @@ -45,6 +49,10 @@ export async function withModuleFederationForSSR(
type: 'commonjs-module',
},
isServer: true,
/**
* Apply user-defined config override
*/
...(configOverride ? configOverride : {}),
},
{}
),
Expand Down
14 changes: 12 additions & 2 deletions packages/angular/src/utils/mf/with-module-federation.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { ModuleFederationConfig } from '@nx/webpack/src/utils/module-federation';
import type {
ModuleFederationConfig,
NxModuleFederationConfigOverride,
} from '@nx/webpack/src/utils/module-federation';
import { getModuleFederationConfig } from './utils';
import { ModuleFederationPlugin } from '@module-federation/enhanced/webpack';

export async function withModuleFederation(options: ModuleFederationConfig) {
export async function withModuleFederation(
options: ModuleFederationConfig,
configOverride?: NxModuleFederationConfigOverride
) {
if (global.NX_GRAPH_CREATION) {
return (config) => config;
}
Expand Down Expand Up @@ -44,6 +50,10 @@ export async function withModuleFederation(options: ModuleFederationConfig) {
library: {
type: 'module',
},
/**
* Apply user-defined config override
*/
...(configOverride ? configOverride : {}),
}),
sharedLibraries.getReplacementPlugin(),
],
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/src/utils/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const typesCorsVersion = '~2.8.5';
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 moduleFederationNodeVersion = '^2.3.0';
export const moduleFederationEnhancedVersion = '~0.2.3';

export const angularEslintVersion = '^18.0.1';
Expand Down
9 changes: 9 additions & 0 deletions packages/react/migrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,15 @@
"alwaysAddToPackageJson": false
}
}
},
"19.4.0-module-federation": {
"version": "19.4.0-rc.2",
"packages": {
"@module-federation/node": {
"version": "^2.3.0",
"alwaysAddToPackageJson": false
}
}
}
}
}
12 changes: 10 additions & 2 deletions packages/react/src/module-federation/with-module-federation-ssr.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { ModuleFederationConfig } from '@nx/webpack/src/utils/module-federation';
import {
ModuleFederationConfig,
NxModuleFederationConfigOverride,
} from '@nx/webpack/src/utils/module-federation';
import { getModuleFederationConfig } from './utils';

export async function withModuleFederationForSSR(
options: ModuleFederationConfig
options: ModuleFederationConfig,
configOverride?: NxModuleFederationConfigOverride
) {
if (global.NX_GRAPH_CREATION) {
return (config) => config;
Expand Down Expand Up @@ -34,6 +38,10 @@ export async function withModuleFederationForSSR(
type: 'commonjs-module',
},
isServer: true,
/**
* Apply user-defined config overrides
*/
...(configOverride ? configOverride : {}),
},
{}
),
Expand Down
12 changes: 10 additions & 2 deletions packages/react/src/module-federation/with-module-federation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { ModuleFederationConfig } from '@nx/webpack/src/utils/module-federation';
import {
ModuleFederationConfig,
NxModuleFederationConfigOverride,
} from '@nx/webpack/src/utils/module-federation';
import { getModuleFederationConfig } from './utils';
import type { AsyncNxComposableWebpackPlugin } from '@nx/webpack';
import { ModuleFederationPlugin } from '@module-federation/enhanced/webpack';
Expand All @@ -11,7 +14,8 @@ const isVarOrWindow = (libType?: string) =>
* @return {Promise<AsyncNxComposableWebpackPlugin>}
*/
export async function withModuleFederation(
options: ModuleFederationConfig
options: ModuleFederationConfig,
configOverride?: NxModuleFederationConfigOverride
): Promise<AsyncNxComposableWebpackPlugin> {
if (global.NX_GRAPH_CREATION) {
return (config) => config;
Expand Down Expand Up @@ -62,6 +66,10 @@ export async function withModuleFederation(
* { appY: 'appY@http://localhost:3002/remoteEntry.js' }
*/
...(isGlobal ? { remoteType: 'script' } : {}),
/**
* Apply user-defined config overrides
*/
...(configOverride ? configOverride : {}),
}),
sharedLibraries.getReplacementPlugin()
);
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/utils/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ 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 = '~1.0.5';
export const moduleFederationNodeVersion = '^2.3.0';
export const moduleFederationEnhancedVersion = '~0.2.3';

// style preprocessors
Expand Down
1 change: 1 addition & 0 deletions packages/webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"dependencies": {
"@babel/core": "^7.23.2",
"@phenomnomnominal/tsquery": "~5.0.1",
"@module-federation/sdk": "^0.2.3",
"ajv": "^8.12.0",
"autoprefixer": "^10.4.9",
"babel-loader": "^9.1.2",
Expand Down
12 changes: 12 additions & 0 deletions packages/webpack/src/utils/module-federation/models/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { NormalModuleReplacementPlugin } from 'webpack';
import type { moduleFederationPlugin } from '@module-federation/sdk';

export type ModuleFederationLibrary = { type: string; name: string };

Expand Down Expand Up @@ -46,6 +47,17 @@ export interface ModuleFederationConfig {
additionalShared?: AdditionalSharedConfig;
}

export type NxModuleFederationConfigOverride = Omit<
moduleFederationPlugin.ModuleFederationPluginOptions,
| 'exposes'
| 'remotes'
| 'name'
| 'library'
| 'shared'
| 'filename'
| 'remoteType'
>;

export type WorkspaceLibrarySecondaryEntryPoint = {
name: string;
path: string;
Expand Down
9 changes: 6 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 681605c

Please sign in to comment.