fix(module-federation): handle remote output paths (#30119)
## Current Behavior `parseRemotesConfig` is naively handling detection of remote output paths needed for standing up the single file server. ## Expected Behavior Provide better detection of remote output paths that covers inference and executor usage with fallback behaviour
This commit is contained in:
parent
46e5dcefb0
commit
e643899a57
@ -8,4 +8,10 @@ export interface NxModuleFederationDevServerConfig {
|
|||||||
sslCert?: string;
|
sslCert?: string;
|
||||||
sslKey?: string;
|
sslKey?: string;
|
||||||
parallel?: number;
|
parallel?: number;
|
||||||
|
devRemoteFindOptions?: DevRemoteFindOptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface DevRemoteFindOptions {
|
||||||
|
retries?: number;
|
||||||
|
retryDelay?: number;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,8 +16,6 @@ export class NxModuleFederationPlugin implements RspackPluginInstance {
|
|||||||
private configOverride?: NxModuleFederationConfigOverride
|
private configOverride?: NxModuleFederationConfigOverride
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
// Do nothing
|
|
||||||
|
|
||||||
apply(compiler: Compiler) {
|
apply(compiler: Compiler) {
|
||||||
if (global.NX_GRAPH_CREATION) {
|
if (global.NX_GRAPH_CREATION) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -1,8 +1,10 @@
|
|||||||
import { waitForPortOpen } from '@nx/web/src/utils/wait-for-port-open';
|
import { waitForPortOpen } from '@nx/web/src/utils/wait-for-port-open';
|
||||||
import { StaticRemoteConfig } from '../../utils';
|
import { StaticRemoteConfig } from '../../utils';
|
||||||
|
import { DevRemoteFindOptions } from '../models';
|
||||||
|
|
||||||
export async function getStaticRemotes(
|
export async function getStaticRemotes(
|
||||||
remotesConfig: Record<string, StaticRemoteConfig>
|
remotesConfig: Record<string, StaticRemoteConfig>,
|
||||||
|
devRemoteFindOptions?: DevRemoteFindOptions
|
||||||
) {
|
) {
|
||||||
const remotes = Object.keys(remotesConfig);
|
const remotes = Object.keys(remotesConfig);
|
||||||
const findStaticRemotesPromises: Promise<string | undefined>[] = [];
|
const findStaticRemotesPromises: Promise<string | undefined>[] = [];
|
||||||
@ -10,8 +12,8 @@ export async function getStaticRemotes(
|
|||||||
findStaticRemotesPromises.push(
|
findStaticRemotesPromises.push(
|
||||||
new Promise<string>((resolve, reject) => {
|
new Promise<string>((resolve, reject) => {
|
||||||
waitForPortOpen(remotesConfig[remote].port, {
|
waitForPortOpen(remotesConfig[remote].port, {
|
||||||
retries: 5,
|
retries: devRemoteFindOptions?.retries ?? 3,
|
||||||
retryDelay: 1000,
|
retryDelay: devRemoteFindOptions?.retryDelay ?? 1000,
|
||||||
}).then(
|
}).then(
|
||||||
(res) => {
|
(res) => {
|
||||||
resolve(undefined);
|
resolve(undefined);
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import { ProjectGraph } from '@nx/devkit';
|
|
||||||
import { StaticRemoteConfig } from '../../utils';
|
|
||||||
import { basename, dirname } from 'path';
|
import { basename, dirname } from 'path';
|
||||||
|
import { interpolate } from 'nx/src/devkit-internals';
|
||||||
|
import { joinPathFragments, ProjectGraph } from '@nx/devkit';
|
||||||
|
import { StaticRemoteConfig } from '../../utils';
|
||||||
|
|
||||||
export function parseRemotesConfig(
|
export function parseRemotesConfig(
|
||||||
remotes: string[] | undefined,
|
remotes: string[] | undefined,
|
||||||
@ -12,11 +13,22 @@ export function parseRemotesConfig(
|
|||||||
}
|
}
|
||||||
const config: Record<string, StaticRemoteConfig> = {};
|
const config: Record<string, StaticRemoteConfig> = {};
|
||||||
for (const app of remotes) {
|
for (const app of remotes) {
|
||||||
const outputPath =
|
const projectRoot = projectGraph.nodes[app].data.root;
|
||||||
projectGraph.nodes[app].data.targets?.['build']?.options.outputPath ??
|
let outputPath = interpolate(
|
||||||
`${workspaceRoot ? `${workspaceRoot}/` : ''}${
|
projectGraph.nodes[app].data.targets?.['build']?.options?.outputPath ??
|
||||||
projectGraph.nodes[app].data.root
|
projectGraph.nodes[app].data.targets?.['build']?.outputs?.[0] ??
|
||||||
}/dist`; // this needs replaced with better logic for finding the output path
|
`${workspaceRoot ? `${workspaceRoot}/` : ''}${
|
||||||
|
projectGraph.nodes[app].data.root
|
||||||
|
}/dist`,
|
||||||
|
{
|
||||||
|
projectName: projectGraph.nodes[app].data.name,
|
||||||
|
projectRoot,
|
||||||
|
workspaceRoot,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
if (outputPath.startsWith(projectRoot)) {
|
||||||
|
outputPath = joinPathFragments(workspaceRoot, outputPath);
|
||||||
|
}
|
||||||
const basePath = dirname(outputPath);
|
const basePath = dirname(outputPath);
|
||||||
const urlSegment = app;
|
const urlSegment = app;
|
||||||
const port = projectGraph.nodes[app].data.targets?.['serve']?.options.port;
|
const port = projectGraph.nodes[app].data.targets?.['serve']?.options.port;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user