Skip to content

Commit

Permalink
fix(angular): normalize and handle dev remotes correctly (#26320)
Browse files Browse the repository at this point in the history
<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

## Current Behavior
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #26169
  • Loading branch information
leosvelperez authored Jun 3, 2024
1 parent 1ea0589 commit ccd16b1
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,13 @@ export function executeModuleFederationDevSSRBuilder(
);
}

validateDevRemotes(options, workspaceProjects);
const devServeRemotes = !options.devRemotes
? []
: Array.isArray(options.devRemotes)
? options.devRemotes
: [options.devRemotes];

validateDevRemotes({ devRemotes: devServeRemotes }, workspaceProjects);

const remotesToSkip = new Set(options.skipRemotes ?? []);
const staticRemotes = getStaticRemotes(
Expand All @@ -72,12 +78,6 @@ export function executeModuleFederationDevSSRBuilder(
);
const remotes = [...staticRemotes, ...dynamicRemotes];

const devServeRemotes = !options.devRemotes
? []
: Array.isArray(options.devRemotes)
? options.devRemotes
: [options.devRemotes];

const remoteProcessPromises = [];
for (const remote of remotes) {
const isDev = devServeRemotes.includes(remote);
Expand Down
14 changes: 6 additions & 8 deletions packages/angular/src/builders/utilities/module-federation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import { existsSync, readFileSync } from 'fs';
import { logger, ProjectConfiguration } from '@nx/devkit';
import { registerTsProject } from '@nx/js/src/internal';

export type DevRemoteDefinition =
| string
| { remoteName: string; configuration: string };

export function getDynamicRemotes(
project: ProjectConfiguration,
context: import('@angular-devkit/architect').BuilderContext,
Expand Down Expand Up @@ -157,18 +161,12 @@ export function getStaticRemotes(

export function validateDevRemotes(
options: {
devRemotes?: (
| string
| {
remoteName: string;
configuration: string;
}
)[];
devRemotes: DevRemoteDefinition[];
},
workspaceProjects: Record<string, ProjectConfiguration>
): void {
const invalidDevRemotes =
options.devRemotes?.filter(
options.devRemotes.filter(
(remote) =>
!(typeof remote === 'string'
? workspaceProjects[remote]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export function normalizeOptions(schema: Schema): NormalizedSchema {
return {
...schema,
buildTarget,
devRemotes: schema.devRemotes ?? [],
host: schema.host ?? 'localhost',
port: schema.port ?? 4200,
liveReload: schema.liveReload ?? true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export async function* moduleFederationDevServerExecutor(
'angular'
);

const remoteNames = options.devRemotes?.map((r) =>
const remoteNames = options.devRemotes.map((r) =>
typeof r === 'string' ? r : r.remoteName
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { DevRemoteDefinition } from '../../builders/utilities/module-federation';

interface BaseSchema {
port?: number;
host?: string;
Expand All @@ -16,13 +18,7 @@ interface BaseSchema {
hmr?: boolean;
watch?: boolean;
poll?: number;
devRemotes?: (
| string
| {
remoteName: string;
configuration: string;
}
)[];
devRemotes?: DevRemoteDefinition[];
skipRemotes?: string[];
pathToManifestFile?: string;
static?: boolean;
Expand All @@ -43,6 +39,7 @@ export type SchemaWithBuildTarget = BaseSchema & {
export type Schema = SchemaWithBrowserTarget | SchemaWithBuildTarget;

export type NormalizedSchema = SchemaWithBuildTarget & {
devRemotes: DevRemoteDefinition[];
liveReload: boolean;
open: boolean;
ssl: boolean;
Expand Down

0 comments on commit ccd16b1

Please sign in to comment.